* [PATCH 0/2] arm64/mm: Standardize printing for pgtable entries
@ 2026-09-01 6:54 Anshuman Khandual
2026-09-01 6:54 ` [PATCH 1/2] arm64/mm: Move __check_safe_pte_update() Anshuman Khandual
2026-09-01 6:54 ` [PATCH 2/2] arm64/mm: Standardize printing for pgtable entries Anshuman Khandual
0 siblings, 2 replies; 5+ messages in thread
From: Anshuman Khandual @ 2026-09-01 6:54 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, David Hildenbrand, Mike Rapoport,
Andrew Morton, Lorenzo Stoakes, Catalin Marinas, Will Deacon,
linux-kernel, linux-mm
Standardize printing for pgtable entries using recently introduced generic
helper ptval_bytes_to_hex_str() in core MM which automatically enables 128
bits entries when added later.
But first move __check_safe_pte_update() outside <asm/pgtable.h> to avoid
a cyclic dependency while accessing these afore mentioned core MM helpers
defined in <linux/pgtable.h>. This replaces the original page table entry
print standardisation proposal which was earlier part of the D128 series.
https://lore.kernel.org/linux-mm/20260729122452.3797443-11-anshuman.khandual@arm.com/
This series applies on v7.3-rc1 but after the following.
https://lore.kernel.org/linux-mm/20260831054331.625505-1-anshuman.khandual@arm.com/
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Anshuman Khandual (2):
arm64/mm: Move __check_safe_pte_update()
arm64/mm: Standardize printing for pgtable entries
arch/arm64/include/asm/pgtable.h | 47 +-----------------------------
arch/arm64/mm/fault.c | 20 +++++++++----
arch/arm64/mm/mmu.c | 49 ++++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 51 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] arm64/mm: Move __check_safe_pte_update()
2026-09-01 6:54 [PATCH 0/2] arm64/mm: Standardize printing for pgtable entries Anshuman Khandual
@ 2026-09-01 6:54 ` Anshuman Khandual
2026-09-07 15:48 ` David Hildenbrand (Arm)
2026-09-01 6:54 ` [PATCH 2/2] arm64/mm: Standardize printing for pgtable entries Anshuman Khandual
1 sibling, 1 reply; 5+ messages in thread
From: Anshuman Khandual @ 2026-09-01 6:54 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, David Hildenbrand, Mike Rapoport,
Andrew Morton, Lorenzo Stoakes, Catalin Marinas, Will Deacon,
linux-kernel, linux-mm
The page table entry print helpers and related macros which are defined in
<linux/pgtable.h> will not be accessible in platform <asm/pgtable.h> which
is basically caused by cycling dependency.
Move __check_safe_pte_update() inside arch/arm64/mm/mmu.c as a preparation
for subsequent usage of the afore mentioned generic MM helpers.
This does not cause any functional change.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
Should __check_safe_pte_update() be wrapped in #ifdef CONFIG_DEBUG_VM
along with dropping off current IS_ENABLED() test. That would ensure
the function never gets called when CONFIG_DEBUG_VM is disabled. That
will preserve current behaviour as the inline function gets dropped
when CONFIG_DEBUG_VM remains disabled.
arch/arm64/include/asm/pgtable.h | 47 +-------------------------------
arch/arm64/mm/mmu.c | 45 ++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 46 deletions(-)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index e89ec5f4787b..61fbfab3e06e 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -387,52 +387,7 @@ static inline pte_t __ptep_get(pte_t *ptep)
extern void __sync_icache_dcache(pte_t pteval);
bool pgattr_change_is_safe(pteval_t old, pteval_t new);
-/*
- * PTE bits configuration in the presence of hardware Dirty Bit Management
- * (PTE_WRITE == PTE_DBM):
- *
- * Dirty Writable | PTE_RDONLY PTE_WRITE PTE_DIRTY (sw)
- * 0 0 | 1 0 0
- * 0 1 | 1 1 0
- * 1 0 | 1 0 1
- * 1 1 | 0 1 x
- *
- * When hardware DBM is not present, the software PTE_DIRTY bit is updated via
- * the page fault mechanism. Checking the dirty status of a pte becomes:
- *
- * PTE_DIRTY || (PTE_WRITE && !PTE_RDONLY)
- */
-
-static inline void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep,
- pte_t pte)
-{
- pte_t old_pte;
-
- if (!IS_ENABLED(CONFIG_DEBUG_VM))
- return;
-
- old_pte = __ptep_get(ptep);
-
- if (!pte_valid(old_pte) || !pte_valid(pte))
- return;
- if (mm != current->active_mm && atomic_read(&mm->mm_users) <= 1)
- return;
-
- /*
- * Check for potential race with hardware updates of the pte
- * (__ptep_set_access_flags safely changes valid ptes without going
- * through an invalid entry).
- */
- VM_WARN_ONCE(!pte_young(pte),
- "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
- VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
- "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
- VM_WARN_ONCE(!pgattr_change_is_safe(pte_val(old_pte), pte_val(pte)),
- "%s: unsafe attribute change: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
-}
+void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte);
static inline void __sync_cache_and_tags(pte_t pte, unsigned int nr_pages)
{
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 79d90226fd5d..e9c66d26bc0a 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -2392,4 +2392,49 @@ int arch_set_user_pkey_access(int pkey, unsigned long init_val)
return 0;
}
+
+/*
+ * PTE bits configuration in the presence of hardware Dirty Bit Management
+ * (PTE_WRITE == PTE_DBM):
+ *
+ * Dirty Writable | PTE_RDONLY PTE_WRITE PTE_DIRTY (sw)
+ * 0 0 | 1 0 0
+ * 0 1 | 1 1 0
+ * 1 0 | 1 0 1
+ * 1 1 | 0 1 x
+ *
+ * When hardware DBM is not present, the software PTE_DIRTY bit is updated via
+ * the page fault mechanism. Checking the dirty status of a pte becomes:
+ *
+ * PTE_DIRTY || (PTE_WRITE && !PTE_RDONLY)
+ */
+void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte)
+{
+ pte_t old_pte;
+
+ if (!IS_ENABLED(CONFIG_DEBUG_VM))
+ return;
+
+ old_pte = __ptep_get(ptep);
+
+ if (!pte_valid(old_pte) || !pte_valid(pte))
+ return;
+ if (mm != current->active_mm && atomic_read(&mm->mm_users) <= 1)
+ return;
+
+ /*
+ * Check for potential race with hardware updates of the pte
+ * (__ptep_set_access_flags safely changes valid ptes without going
+ * through an invalid entry).
+ */
+ VM_WARN_ONCE(!pte_young(pte),
+ "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
+ __func__, pte_val(old_pte), pte_val(pte));
+ VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
+ "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
+ __func__, pte_val(old_pte), pte_val(pte));
+ VM_WARN_ONCE(!pgattr_change_is_safe(pte_val(old_pte), pte_val(pte)),
+ "%s: unsafe attribute change: 0x%016llx -> 0x%016llx",
+ __func__, pte_val(old_pte), pte_val(pte));
+}
#endif
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] arm64/mm: Standardize printing for pgtable entries
2026-09-01 6:54 [PATCH 0/2] arm64/mm: Standardize printing for pgtable entries Anshuman Khandual
2026-09-01 6:54 ` [PATCH 1/2] arm64/mm: Move __check_safe_pte_update() Anshuman Khandual
@ 2026-09-01 6:54 ` Anshuman Khandual
1 sibling, 0 replies; 5+ messages in thread
From: Anshuman Khandual @ 2026-09-01 6:54 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Anshuman Khandual, David Hildenbrand, Mike Rapoport,
Andrew Morton, Lorenzo Stoakes, Catalin Marinas, Will Deacon,
linux-kernel, linux-mm
Standardize printing for pgtable entries using recently introduced generic
helper ptval_bytes_to_hex_str() in core MM which automatically enables 128
bits entries when added later.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
arch/arm64/mm/fault.c | 20 +++++++++++++++-----
arch/arm64/mm/mmu.c | 16 ++++++++++------
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index 0b52557652be..c75bab3c2f4b 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -130,6 +130,11 @@ static inline unsigned long mm_to_pgd_phys(struct mm_struct *mm)
*/
static void show_pte(unsigned long addr)
{
+ char pgd_str[PTVAL_STR_MAX];
+ char p4d_str[PTVAL_STR_MAX];
+ char pud_str[PTVAL_STR_MAX];
+ char pmd_str[PTVAL_STR_MAX];
+ char pte_str[PTVAL_STR_MAX];
struct mm_struct *mm;
pgd_t *pgdp;
pgd_t pgd;
@@ -156,7 +161,8 @@ static void show_pte(unsigned long addr)
vabits_actual, mm_to_pgd_phys(mm));
pgdp = pgd_offset(mm, addr);
pgd = READ_ONCE(*pgdp);
- pr_alert("[%016lx] pgd=%016llx", addr, pgd_val(pgd));
+ ptval_to_str(pgd_str, pgd_val(pgd));
+ pr_alert("[%016lx] pgd=%s", addr, pgd_str);
do {
p4d_t *p4dp, p4d;
@@ -169,19 +175,22 @@ static void show_pte(unsigned long addr)
p4dp = p4d_offset(pgdp, addr);
p4d = READ_ONCE(*p4dp);
- pr_cont(", p4d=%016llx", p4d_val(p4d));
+ ptval_to_str(p4d_str, p4d_val(p4d));
+ pr_cont(", p4d=%s", p4d_str);
if (p4d_none(p4d) || p4d_bad(p4d))
break;
pudp = pud_offset(p4dp, addr);
pud = READ_ONCE(*pudp);
- pr_cont(", pud=%016llx", pud_val(pud));
+ ptval_to_str(pud_str, pud_val(pud));
+ pr_cont(", pud=%s", pud_str);
if (pud_none(pud) || pud_bad(pud))
break;
pmdp = pmd_offset(pudp, addr);
pmd = READ_ONCE(*pmdp);
- pr_cont(", pmd=%016llx", pmd_val(pmd));
+ ptval_to_str(pmd_str, pmd_val(pmd));
+ pr_cont(", pmd=%s", pmd_str);
if (pmd_none(pmd) || pmd_bad(pmd))
break;
@@ -190,7 +199,8 @@ static void show_pte(unsigned long addr)
break;
pte = __ptep_get(ptep);
- pr_cont(", pte=%016llx", pte_val(pte));
+ ptval_to_str(pte_str, pte_val(pte));
+ pr_cont(", pte=%s", pte_str);
pte_unmap(ptep);
} while(0);
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index e9c66d26bc0a..b5de4095d650 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -2410,6 +2410,8 @@ int arch_set_user_pkey_access(int pkey, unsigned long init_val)
*/
void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte)
{
+ char pte_str_old[PTVAL_STR_MAX];
+ char pte_str[PTVAL_STR_MAX];
pte_t old_pte;
if (!IS_ENABLED(CONFIG_DEBUG_VM))
@@ -2427,14 +2429,16 @@ void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte)
* (__ptep_set_access_flags safely changes valid ptes without going
* through an invalid entry).
*/
+ ptval_to_str(pte_str, pte_val(pte));
+ ptval_to_str(pte_str_old, pte_val(old_pte));
VM_WARN_ONCE(!pte_young(pte),
- "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
+ "%s: racy access flag clearing: %s -> %s",
+ __func__, pte_str_old, pte_str);
VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
- "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
+ "%s: racy dirty state clearing: %s -> %s",
+ __func__, pte_str_old, pte_str);
VM_WARN_ONCE(!pgattr_change_is_safe(pte_val(old_pte), pte_val(pte)),
- "%s: unsafe attribute change: 0x%016llx -> 0x%016llx",
- __func__, pte_val(old_pte), pte_val(pte));
+ "%s: unsafe attribute change: %s -> %s",
+ __func__, pte_str_old, pte_str);
}
#endif
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] arm64/mm: Move __check_safe_pte_update()
2026-09-01 6:54 ` [PATCH 1/2] arm64/mm: Move __check_safe_pte_update() Anshuman Khandual
@ 2026-09-07 15:48 ` David Hildenbrand (Arm)
2026-09-08 4:27 ` Anshuman Khandual
0 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-07 15:48 UTC (permalink / raw)
To: Anshuman Khandual, linux-arm-kernel
Cc: Mike Rapoport, Andrew Morton, Lorenzo Stoakes, Catalin Marinas,
Will Deacon, linux-kernel, linux-mm
On 9/1/26 08:54, Anshuman Khandual wrote:
> The page table entry print helpers and related macros which are defined in
> <linux/pgtable.h> will not be accessible in platform <asm/pgtable.h> which
> is basically caused by cycling dependency.
>
> Move __check_safe_pte_update() inside arch/arm64/mm/mmu.c as a preparation
> for subsequent usage of the afore mentioned generic MM helpers.
>
> This does not cause any functional change.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
> Should __check_safe_pte_update() be wrapped in #ifdef CONFIG_DEBUG_VM
> along with dropping off current IS_ENABLED() test. That would ensure
> the function never gets called when CONFIG_DEBUG_VM is disabled. That
> will preserve current behaviour as the inline function gets dropped
> when CONFIG_DEBUG_VM remains disabled.
>
> arch/arm64/include/asm/pgtable.h | 47 +-------------------------------
> arch/arm64/mm/mmu.c | 45 ++++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+), 46 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index e89ec5f4787b..61fbfab3e06e 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -387,52 +387,7 @@ static inline pte_t __ptep_get(pte_t *ptep)
> extern void __sync_icache_dcache(pte_t pteval);
> bool pgattr_change_is_safe(pteval_t old, pteval_t new);
>
> -/*
> - * PTE bits configuration in the presence of hardware Dirty Bit Management
> - * (PTE_WRITE == PTE_DBM):
> - *
> - * Dirty Writable | PTE_RDONLY PTE_WRITE PTE_DIRTY (sw)
> - * 0 0 | 1 0 0
> - * 0 1 | 1 1 0
> - * 1 0 | 1 0 1
> - * 1 1 | 0 1 x
> - *
> - * When hardware DBM is not present, the software PTE_DIRTY bit is updated via
> - * the page fault mechanism. Checking the dirty status of a pte becomes:
> - *
> - * PTE_DIRTY || (PTE_WRITE && !PTE_RDONLY)
> - */
> -
> -static inline void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep,
> - pte_t pte)
> -{
> - pte_t old_pte;
> -
> - if (!IS_ENABLED(CONFIG_DEBUG_VM))
> - return;
> -
> - old_pte = __ptep_get(ptep);
> -
> - if (!pte_valid(old_pte) || !pte_valid(pte))
> - return;
> - if (mm != current->active_mm && atomic_read(&mm->mm_users) <= 1)
> - return;
> -
> - /*
> - * Check for potential race with hardware updates of the pte
> - * (__ptep_set_access_flags safely changes valid ptes without going
> - * through an invalid entry).
> - */
> - VM_WARN_ONCE(!pte_young(pte),
> - "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
> - __func__, pte_val(old_pte), pte_val(pte));
> - VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
> - "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
> - __func__, pte_val(old_pte), pte_val(pte));
> - VM_WARN_ONCE(!pgattr_change_is_safe(pte_val(old_pte), pte_val(pte)),
> - "%s: unsafe attribute change: 0x%016llx -> 0x%016llx",
> - __func__, pte_val(old_pte), pte_val(pte));
> -}
> +void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte);
>
That implies that any __set_ptes_anysz() will invoke another function call that
will not be optimized out.
You should likely keep most of __check_safe_pte_update() in the header as an
inline function (or at least the CONFIG_DEBUG_VM check), and only move the "slow
path" code.
Alternatively, make the whole thing #ifdef CONFIG_DEBUG_VM and provide an empty
inline helper for !CONFIG_DEBUG_VM.
That's probably the cleanest, because performance with CONFIG_DEBUG_VM is not
really relevant.
--
Cheers,
David
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] arm64/mm: Move __check_safe_pte_update()
2026-09-07 15:48 ` David Hildenbrand (Arm)
@ 2026-09-08 4:27 ` Anshuman Khandual
0 siblings, 0 replies; 5+ messages in thread
From: Anshuman Khandual @ 2026-09-08 4:27 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: linux-arm-kernel, Mike Rapoport, Andrew Morton, Lorenzo Stoakes,
Catalin Marinas, Will Deacon, linux-kernel, linux-mm
On Mon, Sep 07, 2026 at 05:48:18PM +0200, David Hildenbrand (Arm) wrote:
> On 9/1/26 08:54, Anshuman Khandual wrote:
> > The page table entry print helpers and related macros which are defined in
> > <linux/pgtable.h> will not be accessible in platform <asm/pgtable.h> which
> > is basically caused by cycling dependency.
> >
> > Move __check_safe_pte_update() inside arch/arm64/mm/mmu.c as a preparation
> > for subsequent usage of the afore mentioned generic MM helpers.
> >
> > This does not cause any functional change.
> >
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > Cc: Will Deacon <will@kernel.org>
> > Cc: linux-arm-kernel@lists.infradead.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> > ---
> > Should __check_safe_pte_update() be wrapped in #ifdef CONFIG_DEBUG_VM
> > along with dropping off current IS_ENABLED() test. That would ensure
> > the function never gets called when CONFIG_DEBUG_VM is disabled. That
> > will preserve current behaviour as the inline function gets dropped
> > when CONFIG_DEBUG_VM remains disabled.
> >
> > arch/arm64/include/asm/pgtable.h | 47 +-------------------------------
> > arch/arm64/mm/mmu.c | 45 ++++++++++++++++++++++++++++++
> > 2 files changed, 46 insertions(+), 46 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> > index e89ec5f4787b..61fbfab3e06e 100644
> > --- a/arch/arm64/include/asm/pgtable.h
> > +++ b/arch/arm64/include/asm/pgtable.h
> > @@ -387,52 +387,7 @@ static inline pte_t __ptep_get(pte_t *ptep)
> > extern void __sync_icache_dcache(pte_t pteval);
> > bool pgattr_change_is_safe(pteval_t old, pteval_t new);
> >
> > -/*
> > - * PTE bits configuration in the presence of hardware Dirty Bit Management
> > - * (PTE_WRITE == PTE_DBM):
> > - *
> > - * Dirty Writable | PTE_RDONLY PTE_WRITE PTE_DIRTY (sw)
> > - * 0 0 | 1 0 0
> > - * 0 1 | 1 1 0
> > - * 1 0 | 1 0 1
> > - * 1 1 | 0 1 x
> > - *
> > - * When hardware DBM is not present, the software PTE_DIRTY bit is updated via
> > - * the page fault mechanism. Checking the dirty status of a pte becomes:
> > - *
> > - * PTE_DIRTY || (PTE_WRITE && !PTE_RDONLY)
> > - */
> > -
> > -static inline void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep,
> > - pte_t pte)
> > -{
> > - pte_t old_pte;
> > -
> > - if (!IS_ENABLED(CONFIG_DEBUG_VM))
> > - return;
> > -
> > - old_pte = __ptep_get(ptep);
> > -
> > - if (!pte_valid(old_pte) || !pte_valid(pte))
> > - return;
> > - if (mm != current->active_mm && atomic_read(&mm->mm_users) <= 1)
> > - return;
> > -
> > - /*
> > - * Check for potential race with hardware updates of the pte
> > - * (__ptep_set_access_flags safely changes valid ptes without going
> > - * through an invalid entry).
> > - */
> > - VM_WARN_ONCE(!pte_young(pte),
> > - "%s: racy access flag clearing: 0x%016llx -> 0x%016llx",
> > - __func__, pte_val(old_pte), pte_val(pte));
> > - VM_WARN_ONCE(pte_write(old_pte) && !pte_dirty(pte),
> > - "%s: racy dirty state clearing: 0x%016llx -> 0x%016llx",
> > - __func__, pte_val(old_pte), pte_val(pte));
> > - VM_WARN_ONCE(!pgattr_change_is_safe(pte_val(old_pte), pte_val(pte)),
> > - "%s: unsafe attribute change: 0x%016llx -> 0x%016llx",
> > - __func__, pte_val(old_pte), pte_val(pte));
> > -}
> > +void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte);
> >
>
> That implies that any __set_ptes_anysz() will invoke another function call that
> will not be optimized out.
Right.
>
> You should likely keep most of __check_safe_pte_update() in the header as an
> inline function (or at least the CONFIG_DEBUG_VM check), and only move the "slow
> path" code.
>
> Alternatively, make the whole thing #ifdef CONFIG_DEBUG_VM and provide an empty
> inline helper for !CONFIG_DEBUG_VM.
>
> That's probably the cleanest, because performance with CONFIG_DEBUG_VM is not
> really relevant.
Agreed, I had asked exact same question earlier as well.
> > Should __check_safe_pte_update() be wrapped in #ifdef CONFIG_DEBUG_VM
> > along with dropping off current IS_ENABLED() test. That would ensure
> > the function never gets called when CONFIG_DEBUG_VM is disabled. That
> > will preserve current behaviour as the inline function gets dropped
> > when CONFIG_DEBUG_VM remains disabled.
Will fold in the following changes.
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 61fbfab3e06e..281a512f1fc6 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -387,7 +387,13 @@ static inline pte_t __ptep_get(pte_t *ptep)
extern void __sync_icache_dcache(pte_t pteval);
bool pgattr_change_is_safe(pteval_t old, pteval_t new);
+#ifdef CONFIG_DEBUG_VM
void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte);
+#else
+static inline void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte)
+{
+}
+#endif
static inline void __sync_cache_and_tags(pte_t pte, unsigned int nr_pages)
{
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index b5de4095d650..26f4cf7b753e 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -2408,15 +2408,13 @@ int arch_set_user_pkey_access(int pkey, unsigned long init_val)
*
* PTE_DIRTY || (PTE_WRITE && !PTE_RDONLY)
*/
+#ifdef CONFIG_DEBUG_VM
void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte)
{
char pte_str_old[PTVAL_STR_MAX];
char pte_str[PTVAL_STR_MAX];
pte_t old_pte;
- if (!IS_ENABLED(CONFIG_DEBUG_VM))
- return;
-
old_pte = __ptep_get(ptep);
if (!pte_valid(old_pte) || !pte_valid(pte))
@@ -2442,3 +2440,4 @@ void __check_safe_pte_update(struct mm_struct *mm, pte_t *ptep, pte_t pte)
__func__, pte_str_old, pte_str);
}
#endif
+#endif
>
>
> --
> Cheers,
>
> David
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-08 4:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-01 6:54 [PATCH 0/2] arm64/mm: Standardize printing for pgtable entries Anshuman Khandual
2026-09-01 6:54 ` [PATCH 1/2] arm64/mm: Move __check_safe_pte_update() Anshuman Khandual
2026-09-07 15:48 ` David Hildenbrand (Arm)
2026-09-08 4:27 ` Anshuman Khandual
2026-09-01 6:54 ` [PATCH 2/2] arm64/mm: Standardize printing for pgtable entries Anshuman Khandual
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®