v2
2026-11-02
折叠页表 pXd 获取行为改造 · v2
清理各架构折叠页表定义,移除 pud/pmd 遍历中的栈拷贝地址并统一 pgd 标量处理。
原始补丁链接
子 Patch(21)
1/21
ARM: mm: make nommu pgd_t a scalar
nommu下将pgd_t由数组改为u32标量;因pgd_t需由pgdp_get()等函数按值返回,数组无法返回,而nommu无真实页表,仅为类型和编译需要。
2/21
ARM: mm: make 2-level pgd_t a scalar
2-level ARM将pgd_t数组改为u64标量,并由pgd_val()按索引提取32位值;因pgd_t需作为pgdp_get()返回值,数组不能按值返回,STRICT分支暂留。
3/21
ARM: mm: remove custom pgdp_get()
pgd_t改为标量后,删除ARM自定义pgdp_get(),改用通用代码的static inline版本;避免架构重复实现,保证pgdp_get()按值返回pgd_t。
4/21
LoongArch: mm: define pud_leaf() only when PUD exists
LoongArch仅在__PAGETABLE_PMD_FOLDED未定义时定义pud_leaf();避免与asm-generic/nopmd.h中折叠pud_leaf硬编码false冲突,为后续补define做准备。
5/21
MIPS: mm: define pud_leaf() only when PUD exists
MIPS仅在__PAGETABLE_PMD_FOLDED未定义时定义pud_leaf();避免与asm-generic/nopmd.h中折叠pud_leaf硬编码false冲突,为后续补define做准备。
6/21
mm/pgtable: define (pgd|p4d|pud)_leaf() for folded page tables
在nop4d/nopmd/nopud头中为折叠页表补pgd_leaf/p4d_leaf/pud_leaf(),均返回false;此前pud_leaf缺define可被架构误覆盖,改用static inline bool做类型检查。
7/21
mm/pgtable: define (pgd|p4d|pud)_offset_lockless() for folded page tables
折叠页表新增pgd/p4d/pud_offset_lockless(),不读取传入项、直接按对应offset计算,避免默认实现把栈上pXd地址传入pud_offset();同时删除arm64自定义版本。
8/21
mm: vmscan: remove stack copy address of pud/pmd pass in walk_pud/pmd_range()
vmscan的walk_pud_range/walk_pmd_range不再传栈拷贝pud/pmd地址,而直接传层级指针;适配pXdp_get()折叠语义,避免pXd_same()对栈值恒真而误判并发变化。
9/21
loongarch: kvm: remove stack copy address of pXd in pXd_offset()
LoongArch KVM的host_pfn_mapping_level()不再把栈拷贝pXd传给pXd_offset(),改用pXd_offset_lockless()直接由指针计算;适配折叠页表下pXdp_get()忽略值。
10/21
riscv: kvm: remove stack copy address of pXd in pXd_offset()
The behaviour of pXdp_get() will change with generic compile-time folded page tables. To prepare for that, rework get_hva_mapping_size() to avoid use of a stack copy of a pXd and pass it as argument t
11/21
riscv: mm: use proper set_pXd() for generic compile-time folded patable in vmalloc_fault()
The behaviour of pXdp_get() will change with generic compile-time folded page tables, making it invalid to use set_pXd() with the result of pXdp_get(). Instead, the appropriate first-level set_pXd() m
12/21
mm/pgtable: redefine PGTABLE_LEVEL enum with ascend order from PGD
The PGTABLE_LEVEL enum values appear to be ordered in the opposite direction from their intended usage. Intuitively, higher page table levels should have smaller enum values, but PTE is currently ass
13/21
x86/mm: Introduce helper for checking direct map 1G page support
From: Dave Hansen dave.hansen@linux.intel.com There is an existing variable (direct_gbpages) that says whether the kernel can and should use 1G pages in the direct map. It is driven by a bunch of o
14/21
x86: mm: use pgtable_level enum in effective_prot_pXd()
Instead of using hard-coded integers in effective_prot_pXd(), use the page-table level enum so that architecture code does not need to know the numeric value of each page-table level, while also provi
15/21
x86: mm: carve out the generic compile-time folded pgtable case in effective_prot()
The behaviour of pXdp_get() will change with generic compile-time folded page tables. To prepare for that, rework effective_prot() to ignore any folded page tables entries, as it will unconditionally
16/21
openrisc/pgtable: drop __pmd_offset()
From: “David Hildenbrand (Arm)” david@kernel.org The macro is unused, and will collide with a folded page table helper. Let’s just remove it. Signed-off-by: David Hildenbrand (Arm) <david@kernel.o
17/21
mm/pgtable: optimize pmdp_get() and friends for folded pagetable levels
From: “David Hildenbrand (Arm)” david@kernel.org Using pmdp_get() and friends in common code on a kernel config with folded page tables is suboptimal: they default to a READ_ONCE(), forcing the com
18/21
mm/pgtable: catch abuse of folded dummy pgd_t/p4d_t/pud_t
From: “David Hildenbrand (Arm)” david@kernel.org Catch and prevent all abuse with dummy values on the stack similar to: pud_t pud = pudp_get(pudp); pmd_t *pmdp = pud_offset(&pud, addr); While t
19/21
mm/pgtable: disallow calling (pgd|p4d|pud)_page, pgd_page_vaddr() and (p4d|pud)_pgtable with dummy
From: “David Hildenbrand (Arm)” david@kernel.org These helpers silently fallback to the folded helpers. With e.g., pdgp_get() returning dummy values, pgd_page_vaddr(pgdp_get(pgdp)) will now behave
20/21
mm/pgtable: disallow calling folded set_pgd/set_p4d/set_pud with dummy
From: “David Hildenbrand (Arm)” david@kernel.org pXdp_get() could return a dummy value for a page-table level folded at compile time. Passing this value to set_pXd() could cause unexpected behavior
21/21
Documentation: mm: clarify behaviour of compile-time folded page tables
From: “David Hildenbrand (Arm)” david@kernel.org Compile-time folded page tables are not necessarily easy to understand, and even people the were once familiar with the concept might need to refres