Skip to contentSkip to conversation

riscv: Sparse-Memory/vmemmap out-of-bounds fix

PATCH Superseded Dimitris Vlachos 2 participants 2 messages Feb 29, 2024 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: Sparse-Memory/vmemmap out-of-bounds fix

Offset vmemmap so that the first page of vmemmap will be mapped to the first page of physical memory in order to ensure that vmemmap’s bounds will be respected during pfn_to_page()/page_to_pfn() operations.
The conversion macros will produce correct SV39/48/57 addresses for every possible/valid DRAM_BASE inside the physical memory limits.

This is the link to the relevant conversation and bug report.

---
 arch/riscv/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/pgtable.h +1 -1
index 0c94260b5..875c9a079 100644
@@ -84,7 +84,7 @@
  * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
  * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
  */
-#define vmemmap		((struct page *)VMEMMAP_START)
+#define vmemmap		((struct page *)VMEMMAP_START - (phys_ram_base >> PAGE_SHIFT))
 
 #define PCI_IO_SIZE      SZ_16M
 #define PCI_IO_END       VMEMMAP_START
Signature · 1 line
2.39.2
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Dimitri,

Quoted 11 lines · Dimitris Vlachos

Offset vmemmap so that the first page of vmemmap will be mapped to the first page of physical memory in order to ensure that vmemmap’s bounds will be respected during pfn_to_page()/page_to_pfn() operations.
The conversion macros will produce correct SV39/48/57 addresses for every possible/valid DRAM_BASE inside the physical memory limits.

This is the link to the relevant conversation and bug report.

You can switch that to a Suggested-by, I did not write the code nor test anything :)

Quoted 2 lines

I think checkpatch will complain that a Link or Closes tag should follow a Reported-by: I would move the Link tag in your commit message here.

And we miss a Fixes tag too, I would go for:

Fixes d95f1a542c3d ("RISC-V: Implement sparsemem")
Quoted 9 lines
---
  arch/riscv/include/asm/pgtable.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/pgtable.h +0 -0
index 0c94260b5..875c9a079 100644

arch/riscv/include/asm/pgtable.h line 90

Quoted 8 lines
arch/riscv/include/asm/pgtable.h +1 -1
@@ -84,7 +84,7 @@
   * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
   * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
   */
-#define vmemmap		((struct page *)VMEMMAP_START)
+#define vmemmap		((struct page *)VMEMMAP_START - (phys_ram_base >> PAGE_SHIFT))
 
  #define PCI_IO_SIZE      SZ_16M
  #define PCI_IO_END       VMEMMAP_START

You can add:

Thanks,

Alex