diff mbox series

riscv: Don't use hugepage mappings for vmemmap if it's not supported

Message ID 20240508173116.2866192-1-namcao@linutronix.de (mailing list archive)
State New
Headers show
Series riscv: Don't use hugepage mappings for vmemmap if it's not supported | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR fail PR summary
conchuod/patch-1-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh
conchuod/patch-1-test-2 fail .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh
conchuod/patch-1-test-3 fail .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 success .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

Nam Cao May 8, 2024, 5:31 p.m. UTC
Commit ff172d4818ad ("riscv: Use hugepage mappings for vmemmap") broke XIP
kernel, because huge pages are not supported on XIP kernel.

Only use hugepage mapping if it is supported.

Fixes: ff172d4818ad ("riscv: Use hugepage mappings for vmemmap")
Signed-off-by: Nam Cao <namcao@linutronix.de>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: <stable@vger.kernel.org>
---
 arch/riscv/mm/init.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Alexandre Ghiti May 8, 2024, 6:22 p.m. UTC | #1
Hi Nam,

On 08/05/2024 19:31, Nam Cao wrote:
> Commit ff172d4818ad ("riscv: Use hugepage mappings for vmemmap") broke XIP
> kernel, because huge pages are not supported on XIP kernel.


I don't understand why XIP kernels can't support huge vmalloc mappings, 
so I think the right fix would be to enable such mappings on XIP. WDYT?

Thanks,

Alex


>
> Only use hugepage mapping if it is supported.
>
> Fixes: ff172d4818ad ("riscv: Use hugepage mappings for vmemmap")
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
> Cc: <stable@vger.kernel.org>
> ---
>   arch/riscv/mm/init.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 968761843203..c081e7d349b1 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -1414,6 +1414,8 @@ int __meminit vmemmap_check_pmd(pmd_t *pmdp, int node,
>   int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
>   			       struct vmem_altmap *altmap)
>   {
> +	if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP))
> +		return vmemmap_populate_basepages(start, end, node, NULL);
>   	/*
>   	 * Note that SPARSEMEM_VMEMMAP is only selected for rv64 and that we
>   	 * can't use hugepage mappings for 2-level page table because in case of
Nam Cao May 8, 2024, 6:46 p.m. UTC | #2
On Wed, May 08, 2024 at 08:22:43PM +0200, Alexandre Ghiti wrote:
> Hi Nam,
Hi Alex,

> > Commit ff172d4818ad ("riscv: Use hugepage mappings for vmemmap") broke XIP
> > kernel, because huge pages are not supported on XIP kernel.
> 
> I don't understand why XIP kernels can't support huge vmalloc mappings,

Me neither.

> so I
> think the right fix would be to enable such mappings on XIP. WDYT?

I agree that is the ideal solution. But I don't want to send any new
feature to the stable trees (stable folks may even reject such patch).
So I intend that to be in another patch.

Best regards,
Nam
Alexandre Ghiti May 24, 2024, 8:07 p.m. UTC | #3
Hi Nam,

On 08/05/2024 20:46, Nam Cao wrote:
> On Wed, May 08, 2024 at 08:22:43PM +0200, Alexandre Ghiti wrote:
>> Hi Nam,
> Hi Alex,
>
>>> Commit ff172d4818ad ("riscv: Use hugepage mappings for vmemmap") broke XIP
>>> kernel, because huge pages are not supported on XIP kernel.
>> I don't understand why XIP kernels can't support huge vmalloc mappings,
> Me neither.
>
>> so I
>> think the right fix would be to enable such mappings on XIP. WDYT?
> I agree that is the ideal solution. But I don't want to send any new
> feature to the stable trees (stable folks may even reject such patch).
> So I intend that to be in another patch.


I have been thinking about that, and I actually think that the real fix 
is enabling huge vmalloc mappings for XIP as it was an oversight/mistake 
in the first place. On 64-bit kernels, there are no reasons we can't use 
PMD mappings for vmalloc. So I'd rather not go with this fix.

Thanks,

Alex


>
> Best regards,
> Nam
Nam Cao May 24, 2024, 8:51 p.m. UTC | #4
On Fri, May 24, 2024 at 10:07:40PM +0200, Alexandre Ghiti wrote:
> Hi Nam,
Hi Alex,

> On 08/05/2024 20:46, Nam Cao wrote:
> > On Wed, May 08, 2024 at 08:22:43PM +0200, Alexandre Ghiti wrote:
> > > > Commit ff172d4818ad ("riscv: Use hugepage mappings for vmemmap") broke XIP
> > > > kernel, because huge pages are not supported on XIP kernel.
> > > I don't understand why XIP kernels can't support huge vmalloc mappings,
> > Me neither.
> > 
> > > so I
> > > think the right fix would be to enable such mappings on XIP. WDYT?
> > I agree that is the ideal solution. But I don't want to send any new
> > feature to the stable trees (stable folks may even reject such patch).
> > So I intend that to be in another patch.
> 
> 
> I have been thinking about that, and I actually think that the real fix is
> enabling huge vmalloc mappings for XIP as it was an oversight/mistake in the
> first place. On 64-bit kernels, there are no reasons we can't use PMD
> mappings for vmalloc. So I'd rather not go with this fix.

If you have strong preference for that approach, then we can go that way.

I don't like this patch that much anyway. The only upside is that it is
safer to backport, because it is obvious that it won't break anything else.

I will do some testing with PMD mapping on XIP, and come back later.

Best regards,
Nam
diff mbox series

Patch

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 968761843203..c081e7d349b1 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -1414,6 +1414,8 @@  int __meminit vmemmap_check_pmd(pmd_t *pmdp, int node,
 int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
 			       struct vmem_altmap *altmap)
 {
+	if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP))
+		return vmemmap_populate_basepages(start, end, node, NULL);
 	/*
 	 * Note that SPARSEMEM_VMEMMAP is only selected for rv64 and that we
 	 * can't use hugepage mappings for 2-level page table because in case of