Skip to contentSkip to conversation

linux-next: manual merge of the risc-v tree with the mm tree

PATCH In review Mark Brown 4 participants 6 messages Oct 12 – Nov 2

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author maintainer
#0 lore raw

Hi 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
diff --combined arch/riscv/mm/init.c
index 6f6b04795bb23,e2b738ca90cf3..0000000000000
@@@ -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>
@@@ -22,7 -27,6 +27,7 @@@
  #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>
@@@ -53,10 -57,8 +58,8 @@@ u64 satp_mode __ro_after_init = SATP_MO
  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;
@@@ -186,7 -188,7 +189,7 @@@ void __init arch_mm_preinit(void
  		 */
  		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;
  	}
@@@ -653,23 -655,23 +656,23 @@@ static void __meminit create_p4d_mappin
  }
  
  #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_t
@@@ -714,11 -716,11 +717,11 @@@ static uintptr_t __meminit best_map_siz
  	if (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;
  
@@@ -770,14 -772,14 +773,14 @@@ u64 __pi_set_satp_mode_from_fdt(uintptr
  
  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;
  }
@@@ -840,6 -842,14 +843,14 @@@ static __init void set_satp_mode(uintpt
  
  	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) {
@@@ -868,7 -878,7 +879,7 @@@ retry
  
  	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);
  
@@@ -880,7 -890,7 +891,7 @@@
  	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;
@@@ -893,6 -903,10 +904,10 @@@ out
  	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
  
@@@ -1121,11 -1135,11 +1136,11 @@@ asmlinkage void __init setup_vm(uintptr
  
  #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,
@@@ -1133,10 -1147,10 +1148,10 @@@
  	/* 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,
@@@ -1407,7 -1421,7 +1422,7 @@@ static void __init preallocate_pgd_page
  		if (!p4d)
  			goto failed;
  
- 		if (pgtable_l5_enabled)
+ 		if (pgtable_l5_enabled())
  			continue;
  
  		lvl = "pud";
@@@ -1415,7 -1429,7 +1430,7 @@@
  		if (!pud)
  			goto failed;
  
- 		if (pgtable_l4_enabled)
+ 		if (pgtable_l4_enabled())
  			continue;
  
  		lvl = "pmd";
@@@ -1486,17 -1500,10 +1501,17 @@@ struct execmem_info __init *execmem_arc
  #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;
  
@@@ -1506,13 -1513,18 +1521,13 @@@
  			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;
  
@@@ -1522,7 -1534,12 +1537,7 @@@
  			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);
  }
  
@@@ -1538,7 -1555,10 +1553,7 @@@ static void __meminit free_pud_table(pu
  			return;
  	}
  
 -	if (PageReserved(page))
 -		free_reserved_page(page);
 -	else
 -		__free_pages(page, 0);
 +	free_pgtable_page(page);
  	p4d_clear(p4d);
  }
  
@@@ -1621,13 -1641,13 +1636,13 @@@ static void __meminit remove_pud_mappin
  
  	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);
@@@ -1638,8 -1658,8 +1653,8 @@@
  		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);
  	}
  }
  
@@@ -1652,13 -1672,13 +1667,13 @@@ static void __meminit remove_p4d_mappin
  
  	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);
@@@ -1669,7 -1689,7 +1684,7 @@@
  		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);
  	}
  }
maintainer
#1 lore raw
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.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")

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
diff --combined arch/riscv/mm/init.c
index 6f6b04795bb23,e2b738ca90cf3..0000000000000

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.

#2 lore raw
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.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")

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
diff --combined arch/riscv/mm/init.c
index 6f6b04795bb23,e2b738ca90cf3..0000000000000

Well 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.

#3 lore raw

PATCH 1/1 riscv/mm: fix up the mm-fixes merge of free_pmd_table()

In reply to Mark Brown

The 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.

Fixes f383866da287 ("Merge branch 'for-next-fixes' of https://git.kernel.org/pub/scm/linux/kernel/git/mm/linux.git")

---
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
index 2400537a01215..e822fce0af4b0 100644
@@ -1654,7 +1654,7 @@ static void __meminit remove_pud_mapping(pud_t *pud_base, unsigned long addr, un
 		remove_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
maintainer
#4 lore raw

Re: [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 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

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.

author maintainer
#5 lore raw

Re: [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.