linux-next: manual merge of the risc-v tree with the mm tree
Subsystems (3)
Mark Brown
maintainerHi all,
Today's linux-next merge of the risc-v tree got a conflict in:
arch/riscv/mm/init.c
between commit:
f02f1d1437449 ("riscv/mm: fix hotplug page-table destructor handling")
from the mm tree and commit:
79113093e9dc3 ("riscv: convert pgtable_l4|l5_enabled to inline function")
from the risc-v tree.
I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.
arch/riscv/mm/init.c +0 -0
@@@ -6,6 -6,11 +6,11 @@@* Nick Kossifidis <[email protected]> */ +#ifdef CONFIG_64BIT +/* riscv_has_extension_likely() cannot be used this early */ +#define USE_EARLY_PGTABLE_LEVELS +#endif +#include <linux/init.h> #include <linux/mm.h> #include <linux/memblock.h> #include <linux/hugetlb.h> #include <linux/kfence.h> #include <linux/execmem.h> +#include <linux/vmemmap-optimization.h>#include <asm/alternative.h> #include <asm/fixmap.h> EXPORT_SYMBOL (satp_mode);#ifdef CONFIG_64BIT -bool pgtable_l4_enabled__ro_after_init = true; -bool pgtable_l5_enabled__ro_after_init = true; -EXPORT_SYMBOL (pgtable_l4_enabled); -EXPORT_SYMBOL (pgtable_l5_enabled); +bool _pgtable_l4_enabled__ro_after_init = true; +bool _pgtable_l5_enabled__ro_after_init = true;#endif phys_addr_t phys_ram_base__ro_after_init ; */unsigned long size =DIV_ROUND_UP (memblock_phys_mem_size (),1024 ); -swiotlb_adjust_size (min (swiotlb_size_or_default (), size)); +swiotlb_adjust_size (min (swiotlb_default_pool_size (), size)); swiotlb = true; swiotlb_flags |= SWIOTLB_ANY; } }#define pgd_next_t p4d_t -#define alloc_pgd_next (__va) (pgtable_l5_enabled ? \ - pt_ops.alloc_p4d(__va) : (pgtable_l4_enabled ? \ +#define alloc_pgd_next (__va) (pgtable_l5_enabled() ? \ + pt_ops.alloc_p4d(__va) : (pgtable_l4_enabled() ? \ pt_ops.alloc_pud(__va) : pt_ops.alloc_pmd(__va))) -#define get_pgd_next_virt (__pa) (pgtable_l5_enabled ? \ - pt_ops.get_p4d_virt(__pa) : (pgd_next_t *)(pgtable_l4_enabled ? \ +#define get_pgd_next_virt (__pa) (pgtable_l5_enabled() ? \ + pt_ops.get_p4d_virt(__pa) : (pgd_next_t *)(pgtable_l4_enabled() ? \ pt_ops.get_pud_virt(__pa) : (pud_t *)pt_ops.get_pmd_virt(__pa)))#define create_pgd_next_mapping (__nextp, __va, __pa, __sz, __prot) \ - (pgtable_l5_enabled ? \ + (pgtable_l5_enabled() ? \ create_p4d_mapping(__nextp, __va, __pa, __sz, __prot) : \ - (pgtable_l4_enabled ? \ + (pgtable_l4_enabled() ? \ create_pud_mapping((pud_t *)__nextp, __va, __pa, __sz, __prot) : \ create_pmd_mapping((pmd_t *)__nextp, __va, __pa, __sz, __prot))) -#define fixmap_pgd_next (pgtable_l5_enabled ? \ - (uintptr_t)fixmap_p4d : (pgtable_l4_enabled ? \ +#define fixmap_pgd_next (pgtable_l5_enabled() ? \ + (uintptr_t)fixmap_p4d : (pgtable_l4_enabled() ? \ (uintptr_t)fixmap_pud : (uintptr_t)fixmap_pmd)) -#define trampoline_pgd_next (pgtable_l5_enabled ? \ - (uintptr_t)trampoline_p4d : (pgtable_l4_enabled ? \ +#define trampoline_pgd_next (pgtable_l5_enabled() ? \ + (uintptr_t)trampoline_p4d : (pgtable_l4_enabled() ? \ (uintptr_t)trampoline_pud : (uintptr_t)trampoline_pmd))#else #define pgd_next_t pte_tif (debug_pagealloc_enabled ())return PAGE_SIZE ; -if (pgtable_l5_enabled && +if (pgtable_l5_enabled () && !(pa & (P4D_SIZE -1 )) && !(va & (P4D_SIZE -1 )) && size >=P4D_SIZE )return P4D_SIZE ; -if (pgtable_l4_enabled && +if (pgtable_l4_enabled () && !(pa & (PUD_SIZE -1 )) && !(va & (PUD_SIZE -1 )) && size >=PUD_SIZE )return PUD_SIZE ;static void __init disable_pgtable_l5 (void ) { - pgtable_l5_enabled = false; + _pgtable_l5_enabled = false; kernel_map.page_offset =PAGE_OFFSET_L4 ; satp_mode =SATP_MODE_48 ; }static void __init disable_pgtable_l4 (void ) { - pgtable_l4_enabled = false; + _pgtable_l4_enabled = false; kernel_map.page_offset =PAGE_OFFSET_L3 ; satp_mode =SATP_MODE_39 ; } kernel_map.page_offset =PAGE_OFFSET_L5 ; +/* Fall back to SV48 if RISCV_ISA_SV57 isn't enabled */ +if (!IS_ENABLED (CONFIG_RISCV_ISA_SV57 ) && satp_mode_limit ==0 ) + satp_mode_limit =SATP_MODE_48 ; + +/* Fall back to SV39 if RISCV_ISA_SV48 isn't enabled */ +if (!IS_ENABLED (CONFIG_RISCV_ISA_SV48 ) && satp_mode_limit ==SATP_MODE_48 ) + satp_mode_limit =SATP_MODE_39 ; +if (satp_mode_limit ==SATP_MODE_48 ) {disable_pgtable_l5 (); }else if (satp_mode_limit ==SATP_MODE_39 ) {create_pgd_mapping (early_pg_dir, set_satp_mode_pmd, - pgtable_l5_enabled ? +pgtable_l5_enabled () ? (uintptr_t )early_p4d : (uintptr_t )early_pud,PGDIR_SIZE ,PAGE_TABLE );local_flush_tlb_all ();if (hw_satp != identity_satp) { -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {disable_pgtable_l5 ();memset (early_pg_dir,0 ,PAGE_SIZE ); goto retry;memset (early_p4d,0 ,PAGE_SIZE );memset (early_pud,0 ,PAGE_SIZE );memset (early_pmd,0 ,PAGE_SIZE ); +if (pgtable_l4_enabled ()) +set_bit (RISCV_ISA_EXT_SV48 , riscv_isa); +if (pgtable_l5_enabled ()) +set_bit (RISCV_ISA_EXT_SV57 , riscv_isa); }#endif #ifndef __PAGETABLE_PMD_FOLDED/* Setup fixmap P4D and PUD */ -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())create_p4d_mapping (fixmap_p4d,FIXADDR_START , (uintptr_t )fixmap_pud,P4D_SIZE ,PAGE_TABLE );/* Setup fixmap PUD and PMD */ -if (pgtable_l4_enabled) +if (pgtable_l4_enabled ())create_pud_mapping (fixmap_pud,FIXADDR_START , (uintptr_t )fixmap_pmd,PUD_SIZE ,PAGE_TABLE );create_pmd_mapping (fixmap_pmd,FIXADDR_START ,/* Setup trampoline PGD and PMD */ create_pgd_mapping (trampoline_pg_dir, kernel_map.virt_addr, trampoline_pgd_next, PGDIR_SIZE, PAGE_TABLE); -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())create_p4d_mapping (trampoline_p4d, kernel_map.virt_addr, (uintptr_t )trampoline_pud,P4D_SIZE ,PAGE_TABLE ); -if (pgtable_l4_enabled) +if (pgtable_l4_enabled ())create_pud_mapping (trampoline_pud, kernel_map.virt_addr, (uintptr_t )trampoline_pmd,PUD_SIZE ,PAGE_TABLE );create_pmd_mapping (trampoline_pmd, kernel_map.virt_addr, if (!p4d) goto failed; - if (pgtable_l5_enabled) + if (pgtable_l5_enabled()) continue; lvl = "pud";if (!pud) goto failed; -if (pgtable_l4_enabled) +if (pgtable_l4_enabled ())continue ; lvl ="pmd" ;#endif /* CONFIG_EXECMEM */ #ifdef CONFIG_MEMORY_HOTPLUG +static void __meminit free_pgtable_page(struct page *page) +{ + if (PageReserved(page)) +free_reserved_page (page); + else +pagetable_free (page_ptdesc (page)); +} + static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd) {struct page *page =pmd_page (*pmd); - struct ptdesc *ptdesc = page_ptdesc(page);pte_t *pte;int i;return ; } -pagetable_dtor (ptdesc); - if (PageReserved(page)) -free_reserved_page (page); - else -pagetable_free (ptdesc); +free_pgtable_page (page);pmd_clear (pmd); } -static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud, bool is_vmemmap) +static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud) {struct page *page =pud_page (*pud); - struct ptdesc *ptdesc = page_ptdesc(page);pmd_t *pmd;int i;return ; } - if (!is_vmemmap) -pagetable_dtor (ptdesc); - if (PageReserved(page)) -free_reserved_page (page); - else -pagetable_free (ptdesc); +free_pgtable_page (page); pud_clear(pud); }return ; } - if (PageReserved(page)) -free_reserved_page (page); - else -__free_pages (page,0 ); +free_pgtable_page (page);p4d_clear (p4d); }for (; addr < end; addr = next) { next =pud_addr_end (addr, end); - pudp = pgtable_l4_enabled ? pud_base +pud_index (addr) : pud_base; + pudp =pgtable_l4_enabled () ? pud_base +pud_index (addr) : pud_base; pud =pudp_get (pudp);if (!pud_present (pud))continue ;if (pud_leaf (pud)) { -if (pgtable_l4_enabled) { +if (pgtable_l4_enabled ()) {pud_clear (pudp);if (is_vmemmap)free_vmemmap_storage (pud_page (pud),PUD_SIZE , altmap); pmd_base =pmd_offset (pudp,0 );remove_pmd_mapping (pmd_base, addr, next, is_vmemmap, altmap); -if (pgtable_l4_enabled) -free_pmd_table (pmd_base, pudp); +if (pgtable_l4_enabled ()) +free_pmd_table (pmd_base, pudp, is_vmemmap); } }for (; addr < end; addr = next) { next =p4d_addr_end (addr, end); - p4dp = pgtable_l5_enabled ? p4d_base +p4d_index (addr) : p4d_base; + p4dp =pgtable_l5_enabled () ? p4d_base +p4d_index (addr) : p4d_base; p4d =p4dp_get (p4dp);if (!p4d_present (p4d))continue ;if (p4d_leaf (p4d)) { -if (pgtable_l5_enabled) { +if (pgtable_l5_enabled ()) {p4d_clear (p4dp);if (is_vmemmap)free_vmemmap_storage (p4d_page (p4d),P4D_SIZE , altmap); pud_base =pud_offset (p4dp,0 );remove_pud_mapping (pud_base, addr, next, is_vmemmap, altmap); -if (pgtable_l5_enabled) +if (pgtable_l5_enabled ())free_pud_table (pud_base, p4dp); } }
Andrew Morton
maintainerQuoted 14 lines · On Mon, 12 Oct 2026 16:59:22 +0100 Mark Brown <[email protected]> wrote:
Hi all,
Today's linux-next merge of the risc-v tree got a conflict in:
arch/riscv/mm/init.cbetween commit:
f02f1d1437449("riscv/mm: fix hotplug page-table destructor handling")from the mm tree and commit:
79113093e9dc3("riscv: convert pgtable_l4|l5_enabled to inline function")
Quoted 8 lines
from the risc-v tree.
I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.
Thanks.
arch/riscv/mm/init.c
Quoted 4 lines
arch/riscv/mm/init.c +0
-0
Well that's ugly.
I'll disable "riscv/mm: fix hotplug page-table destructor handling" for now to make this go away.
A decent approach would be to add that patch via the riscv tree. Muchun, please confirm that this has no dependencies on anything else?
Otherwise I'll leave it disabled and revisit after -rc1.
Quoted 38 lines · Andrew Morton
Quoted 14 lines · On Mon, 12 Oct 2026 16:59:22 +0100 Mark Brown <[email protected]> wrote:
Hi all,
Today's linux-next merge of the risc-v tree got a conflict in:
arch/riscv/mm/init.cbetween commit:
f02f1d1437449("riscv/mm: fix hotplug page-table destructor handling")from the mm tree and commit:
79113093e9dc3("riscv: convert pgtable_l4|l5_enabled to inline function")Quoted 8 lines
from the risc-v tree.
I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.
Thanks.
arch/riscv/mm/init.c
Quoted 4 lines
arch/riscv/mm/init.c +0
-0Well that's ugly.
Quoted 5 lines
I'll disable "riscv/mm: fix hotplug page-table destructor handling" for now to make this go away.
A decent approach would be to add that patch via the riscv tree. Muchun, please confirm that this has no dependencies on anything else?
Hi Andrew,
Unfortunately, this fix depends on the first patch. So they should go through MM tree together.
Quoted 2 lines
Otherwise I'll leave it disabled and revisit after -rc1.
I think this is OK.
Thanks.
PATCH 1/1 riscv/mm: fix up the mm-fixes merge of free_pmd_table()
In reply to Mark BrownThe mm-fixes merge reuses an older resolution of the conflict in remove_pud_mapping() and keeps the free_pmd_table() call that passes is_vmemmap. Commit f998a21c2ba5 ("riscv/mm: fix hotplug page-table destructor handling") in mm-fixes removed that argument, so a riscv build with CONFIG_MEMORY_HOTPLUG fails:
arch/riscv/mm/init.c:1657:35: error: too many arguments to function call, expected 2, have 3
Drop the argument to match the mm-fixes version of the call.
---
Mark, this applies on top of next-20261030 and is meant to be folded into the mm-fixes merge resolution. Next/merge.log says it was resolved using a previous resolution, I think the one from the risc-v/mm conflict on 2026-10-12, which had the same problem (next-20261012 has it too).
Build tested with clang: riscv defconfig plus MEMORY_HOTPLUG and MEMORY_HOTREMOVE, W=1 build of arch/riscv/mm/ (also mm/memory_hotplug.o and mm/sparse-vmemmap.o), and plain defconfig.
arch/riscv/mm/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -1
@@ -1654,7 +1654,7 @@ static void __meminit remove_pud_mapping(pud_t *pud_base, unsigned long addr, unremove_pmd_mapping (pmd_base, addr, next, is_vmemmap, altmap);if (pgtable_l4_enabled ()) -free_pmd_table (pmd_base, pudp, is_vmemmap); +free_pmd_table (pmd_base, pudp); } }
base-commit: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c
Signature · 1 line
2.53.0
Andrew Morton
maintainerRe: [PATCH linux-next] riscv/mm: fix up the mm-fixes merge of free_pmd_table()
Quoted 8 lines · On Fri, 30 Oct 2026 18:14:01 -0400 Sasha Levin <[email protected]> wrote:
The mm-fixes merge reuses an older resolution of the conflict in
remove_pud_mapping()and keeps thefree_pmd_table()call that passesis_vmemmap. Commitf998a21c2ba5("riscv/mm: fix hotplug page-table destructor handling") in mm-fixes removed that argument, so a riscv build withCONFIG_MEMORY_HOTPLUGfails:
arch/riscv/mm/init.c:1657:35: error: too many arguments to function call, expected 2, have 3
Quoted 7 lines
Drop the argument to match the mm-fixes version of the call.
---
Mark, this applies on top of next-20261030 and is meant to be folded into the mm-fixes merge resolution. Next/merge.log says it was resolved using a previous resolution, I think the one from the risc-v/mm conflict on 2026-10-12, which had the same problem (next-20261012 has it too).
Thanks. The "mm: Fix page-table teardown during memory hot-remove", v3 series was problematic, but I now have all four patches lined up in Muchun's as-sent order in mm-hotfixes-unstable. I'll push that in the next hour or three. Then hopefully any -next merge resolution can just go away.
Mark Brown
maintainerRe: [PATCH linux-next] riscv/mm: fix up the mm-fixes merge of free_pmd_table()
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Fri, 30 Oct 2026 18:14:01 -0400 Sasha Levin <[email protected]> wrote:
Mark, this applies on top of next-20261030 and is meant to be folded into the mm-fixes merge resolution. Next/merge.log says it was resolved using a previous resolution, I think the one from the risc-v/mm conflict on 2026-10-12, which had the same problem (next-20261012 has it too).
Quoted 5 lines
Thanks. The "mm: Fix page-table teardown during memory hot-remove", v3 series was problematic, but I now have all four patches lined up in Muchun's as-sent order in mm-hotfixes-unstable. I'll push that in the next hour or three. Then hopefully any -next merge resolution can just go away.
I skipped Sasha's fixup on the basis that you'd already handled things.