Skip to content

Commit eba2591

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
mm: Introduce pudp/p4dp/pgdp_get() functions
Instead of directly dereferencing page tables entries, which can cause issues (see commit 20a004e ("arm64: mm: Use READ_ONCE/WRITE_ONCE when accessing page tables"), let's introduce new functions to get the pud/p4d/pgd entries (the pte and pmd versions already exist). Note that arm pgd_t is actually an array so pgdp_get() is defined as a macro to avoid a build error. Those new functions will be used in subsequent commits by the riscv architecture. Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20231213203001.179237-3-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent c30fa83 commit eba2591

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

arch/arm/include/asm/pgtable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
151151

152152
extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
153153

154+
#define pgdp_get(pgpd) READ_ONCE(*pgdp)
155+
154156
#define pud_page(pud) pmd_page(__pmd(pud_val(pud)))
155157
#define pud_write(pud) pmd_write(__pmd(pud_val(pud)))
156158

include/linux/pgtable.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,27 @@ static inline pmd_t pmdp_get(pmd_t *pmdp)
292292
}
293293
#endif
294294

295+
#ifndef pudp_get
296+
static inline pud_t pudp_get(pud_t *pudp)
297+
{
298+
return READ_ONCE(*pudp);
299+
}
300+
#endif
301+
302+
#ifndef p4dp_get
303+
static inline p4d_t p4dp_get(p4d_t *p4dp)
304+
{
305+
return READ_ONCE(*p4dp);
306+
}
307+
#endif
308+
309+
#ifndef pgdp_get
310+
static inline pgd_t pgdp_get(pgd_t *pgdp)
311+
{
312+
return READ_ONCE(*pgdp);
313+
}
314+
#endif
315+
295316
#ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
296317
static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
297318
unsigned long address,

0 commit comments

Comments
 (0)