diff mbox series

[-fixes] riscv: Sparse-Memory/vmemmap out-of-bounds fix

Message ID 20240229143833.107724-1-dvlachos@ics.forth.gr (mailing list archive)
State Superseded
Headers show
Series [-fixes] riscv: Sparse-Memory/vmemmap out-of-bounds fix | expand

Checks

Context Check Description
conchuod/vmtest-fixes-PR success PR summary
conchuod/patch-1-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh
conchuod/patch-1-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh
conchuod/patch-1-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh
conchuod/patch-1-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-1-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-1-test-6 warning .github/scripts/patches/tests/checkpatch.sh
conchuod/patch-1-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh
conchuod/patch-1-test-8 success .github/scripts/patches/tests/header_inline.sh
conchuod/patch-1-test-9 success .github/scripts/patches/tests/kdoc.sh
conchuod/patch-1-test-10 success .github/scripts/patches/tests/module_param.sh
conchuod/patch-1-test-11 success .github/scripts/patches/tests/verify_fixes.sh
conchuod/patch-1-test-12 success .github/scripts/patches/tests/verify_signedoff.sh

Commit Message

Dimitris Vlachos Feb. 29, 2024, 2:38 p.m. UTC
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.
Link :https://lore.kernel.org/linux-riscv/20240202135030.42265-1-csd4492@csd.uoc.gr

Co-developed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Dimitris Vlachos <dvlachos@ics.forth.gr>
Reported-by: Dimitris Vlachos <dvlachos@ics.forth.gr>
---
 arch/riscv/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alexandre Ghiti Feb. 29, 2024, 3:38 p.m. UTC | #1
Hi Dimitri,

On 29/02/2024 15:38, Dimitris Vlachos wrote:
> 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.
> Link :https://lore.kernel.org/linux-riscv/20240202135030.42265-1-csd4492@csd.uoc.gr
>
> Co-developed-by: Alexandre Ghiti <alexghiti@rivosinc.com>


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


> Signed-off-by: Dimitris Vlachos <dvlachos@ics.forth.gr>
> Reported-by: Dimitris Vlachos <dvlachos@ics.forth.gr>


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")


> ---
>   arch/riscv/include/asm/pgtable.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index 0c94260b5..875c9a079 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -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:

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks,

Alex
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 0c94260b5..875c9a079 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -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