Skip to contentSkip to conversation

riscv: mm: remove the BUG_ON check of mapping the last 4K bytes of memory

PATCH In review Jisheng Zhang 3 participants 4 messages Jan 25, 2022 – Feb 18, 2022 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: mm: remove the BUG_ON check of mapping the last 4K bytes of memory

remove the BUG_ON check of mapping the last 4K bytes of the addressable memory since "this is true for every kernel actually" as pointed out by Alexandre.

---
 arch/riscv/mm/init.c | 8 --------
 1 file changed, 8 deletions(-)
arch/riscv/mm/init.c +0 -8
index cf4d018b7d66..8347d0fda8cd 100644
@@ -811,14 +811,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
 	BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
 	BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
 
-#ifdef CONFIG_64BIT
-	/*
-	 * The last 4K bytes of the addressable memory can not be mapped because
-	 * of IS_ERR_VALUE macro.
-	 */
-	BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
-#endif
-
 	pt_ops_set_early();
 
 	/* Setup early PGD for fixmap */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 15 lines · Jisheng Zhang

remove the BUG_ON check of mapping the last 4K bytes of the addressable memory since "this is true for every kernel actually" as pointed out by Alexandre.

---
  arch/riscv/mm/init.c | 8 --------
  1 file changed, 8 deletions(-)
arch/riscv/mm/init.c +0 -0
index cf4d018b7d66..8347d0fda8cd 100644

arch/riscv/mm/init.c asmlinkage void __init setup_vm(uintptr_t dtb_pa) · line 820

Quoted 10 lines
arch/riscv/mm/init.c +0 -7
@@ -811,14 +811,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
  	BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
  	BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
 
-#ifdef CONFIG_64BIT
-	/*
-	 * The last 4K bytes of the addressable memory can not be mapped because
-	 * of IS_ERR_VALUE macro.
-	 */
-	BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
-#endif

This BUG_ON seems pretty legit to me: I re-read the exchanges we had, and I see that I didn't notice that in your v2, you actually removed the BUG_ON. So that's my bad, what I meant in the first place was that the BUG_ON is true for 32-bit and 64-bit kernels actually.

Sorry my RB was not right on this one :(

Alex

Quoted 4 lines
arch/riscv/mm/init.c +0 -1
-
  	pt_ops_set_early();
 
  	/* Setup early PGD for fixmap */
maintainer
#2 lore raw
Quoted 20 lines · On Tue, 25 Jan 2022 08:10:41 PST (-0800), [email protected] wrote:
Quoted 18 lines · Jisheng Zhang

remove the BUG_ON check of mapping the last 4K bytes of the addressable memory since "this is true for every kernel actually" as pointed out by Alexandre.

---
  arch/riscv/mm/init.c | 8 --------
  1 file changed, 8 deletions(-)
arch/riscv/mm/init.c +0 -0
index cf4d018b7d66..8347d0fda8cd 100644
@@ -811,14 +811,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
  	BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
  	BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
 
Quoted 13 lines

arch/riscv/mm/init.c asmlinkage void __init setup_vm(uintptr_t dtb_pa) · line 820

Quoted 7 lines
arch/riscv/mm/init.c +0 -7
-#ifdef CONFIG_64BIT
-	/*
-	 * The last 4K bytes of the addressable memory can not be mapped because
-	 * of IS_ERR_VALUE macro.
-	 */
-	BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
-#endif

This BUG_ON seems pretty legit to me: I re-read the exchanges we had, and I see that I didn't notice that in your v2, you actually removed the BUG_ON. So that's my bad, what I meant in the first place was that the BUG_ON is true for 32-bit and 64-bit kernels actually.

There's actually an ifndef 64BIT above that sort of handles this case (though I didn't check to see if we're getting the limits correct, so it may not work properly). That's shrinking the memory, rather than just firing a BUG, and it's not really any more code so we should go that way for both. I could see leaving a BUG in there, maybe just explicitly using IS_ERR_VALUE as that's really what we're checking for (though if that's not 4K a bunch of stuff will break, so maybe it just doesn't matter).

Quoted 9 lines

Sorry my RB was not right on this one :(

Alex

Quoted 4 lines
arch/riscv/mm/init.c +0 -1
-
  	pt_ops_set_early();
 
  	/* Setup early PGD for fixmap */
#3 lore raw

Hi Palmer,

Quoted 37 lines · Palmer Dabbelt
Quoted 20 lines · On Tue, 25 Jan 2022 08:10:41 PST (-0800), [email protected] wrote:
Quoted 18 lines · Jisheng Zhang

remove the BUG_ON check of mapping the last 4K bytes of the addressable memory since "this is true for every kernel actually" as pointed out by Alexandre.

---
  arch/riscv/mm/init.c | 8 --------

  1 file changed, 8 deletions(-)
arch/riscv/mm/init.c +0 -0
index cf4d018b7d66..8347d0fda8cd 100644
@@ -811,14 +811,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
       BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
       BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
 
Quoted 15 lines
Quoted 9 lines
arch/riscv/mm/init.c +0 -3
-#ifdef CONFIG_64BIT
-    /*
-     * The last 4K bytes of the addressable memory can not be 

mapped because
-     * of IS_ERR_VALUE macro.
-     */
-    BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
-#endif

This BUG_ON seems pretty legit to me: I re-read the exchanges we had, and I see that I didn't notice that in your v2, you actually removed the BUG_ON. So that's my bad, what I meant in the first place was that the BUG_ON is true for 32-bit and 64-bit kernels actually.

Quoted 1 line

There's actually an ifndef 64BIT above that sort of handles this case (though I didn't check to see if we're getting the limits correct, so it may not work properly).  That's shrinking the memory, rather than just firing a BUG, and it's not really any more code so we should go that way for both.  I could see leaving a BUG in there, maybe just explicitly using IS_ERR_VALUE as that's really what we're checking for (though if that's not 4K a bunch of stuff will break, so maybe it just doesn't matter).

I think you're talking about:

memory_limit = KERN_VIRT_SIZE - (IS_ENABLED(CONFIG_64BIT) ? SZ_4G : 0);

If yes, that's shrinking the available physical memory we can map in the linear mapping, whereas the BUG_ON here is triggered if the kernel mapping is very (very) large and overlaps the last *4K* of the address space, so I still think the BUG_ON is legit although very unlikely.

However, I'm wondering if the shrinking still holds with the recent move of KASAN, I may be back with a fix for that.

Alex

Quoted 10 lines
Quoted 10 lines

Sorry my RB was not right on this one :(

Alex

Quoted 4 lines

-
      pt_ops_set_early();

      /* Setup early PGD for fixmap */