* [PATCH 0/6] change young flag check functions to return bool
@ 2026-03-19 3:23 Baolin Wang
2026-03-19 3:24 ` [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young() Baolin Wang
` (7 more replies)
0 siblings, 8 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-19 3:23 UTC (permalink / raw)
To: akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
This is a cleanup patchset to change all young flag check functions to
return bool, as discussed with David in the previous thread[1]. Since
callers only care about whether the young flag was set, returning bool
makes the intention clearer. No functional changes intended.
Ran mm selftests on Arm64 and x86 machines, and no issues were found.
Note that I only CC'd the arch mailing lists to avoid disturbing too
many people.
[1] https://lore.kernel.org/all/d172d6bf-c60c-4cf5-9da9-f30de38cdfed@kernel.org/
Baolin Wang (6):
mm: change to return bool for ptep_test_and_clear_young()
mm: change to return bool for
ptep_clear_flush_young()/clear_flush_young_ptes()
mm: change to return bool for pmdp_test_and_clear_young()
mm: change to return bool for pmdp_clear_flush_young()
mm: change to return bool for pudp_test_and_clear_young()
mm: change to return bool for the MMU notifier's young flag check
arch/arm64/include/asm/pgtable.h | 29 ++++----
arch/arm64/mm/contpte.c | 8 +--
arch/microblaze/include/asm/pgtable.h | 2 +-
arch/parisc/include/asm/pgtable.h | 8 +--
arch/parisc/kernel/cache.c | 8 +--
arch/powerpc/include/asm/book3s/32/pgtable.h | 4 +-
arch/powerpc/include/asm/book3s/64/pgtable.h | 26 +++----
arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
arch/powerpc/include/asm/nohash/pgtable.h | 4 +-
arch/powerpc/mm/book3s64/pgtable.c | 8 +--
arch/riscv/include/asm/pgtable.h | 14 ++--
arch/riscv/mm/pgtable.c | 8 +--
arch/s390/include/asm/pgtable.h | 16 ++---
arch/x86/include/asm/pgtable.h | 20 +++---
arch/x86/mm/pgtable.c | 28 ++++----
arch/xtensa/include/asm/pgtable.h | 6 +-
include/linux/mmu_notifier.h | 76 +++++++++-----------
include/linux/pgtable.h | 53 +++++++-------
mm/internal.h | 16 ++---
mm/mmu_notifier.c | 20 +++---
mm/pgtable-generic.c | 14 ++--
virt/kvm/kvm_main.c | 40 +++++------
22 files changed, 201 insertions(+), 209 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young()
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
@ 2026-03-19 3:24 ` Baolin Wang
2026-03-19 11:28 ` Lorenzo Stoakes (Oracle)
2026-03-20 5:57 ` Ritesh Harjani
2026-03-19 3:24 ` [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes() Baolin Wang
` (6 subsequent siblings)
7 siblings, 2 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-19 3:24 UTC (permalink / raw)
To: akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
Callers use ptep_test_and_clear_young() to clear the young flag and check
whether it was set. Change the return type to bool to make the intention
clearer.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
arch/arm64/include/asm/pgtable.h | 8 ++++----
arch/arm64/mm/contpte.c | 4 ++--
arch/microblaze/include/asm/pgtable.h | 2 +-
arch/parisc/include/asm/pgtable.h | 6 +++---
arch/powerpc/include/asm/book3s/32/pgtable.h | 4 ++--
arch/powerpc/include/asm/book3s/64/pgtable.h | 6 +++---
arch/powerpc/include/asm/nohash/pgtable.h | 4 ++--
arch/riscv/include/asm/pgtable.h | 4 ++--
arch/riscv/mm/pgtable.c | 8 ++++----
arch/s390/include/asm/pgtable.h | 4 ++--
arch/x86/include/asm/pgtable.h | 4 ++--
arch/x86/mm/pgtable.c | 6 +++---
arch/xtensa/include/asm/pgtable.h | 6 +++---
include/linux/pgtable.h | 16 ++++++++--------
14 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index ab451d20e4c5..8c651695204c 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -1282,7 +1282,7 @@ static inline void __pte_clear(struct mm_struct *mm,
__set_pte(ptep, __pte(0));
}
-static inline int __ptep_test_and_clear_young(struct vm_area_struct *vma,
+static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
unsigned long address,
pte_t *ptep)
{
@@ -1646,7 +1646,7 @@ extern void contpte_clear_full_ptes(struct mm_struct *mm, unsigned long addr,
extern pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm,
unsigned long addr, pte_t *ptep,
unsigned int nr, int full);
-int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
+bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep, unsigned int nr);
int contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep, unsigned int nr);
@@ -1813,7 +1813,7 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
}
#define test_and_clear_young_ptes test_and_clear_young_ptes
-static inline int test_and_clear_young_ptes(struct vm_area_struct *vma,
+static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep,
unsigned int nr)
{
@@ -1824,7 +1824,7 @@ static inline int test_and_clear_young_ptes(struct vm_area_struct *vma,
}
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
-static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
+static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep)
{
return test_and_clear_young_ptes(vma, addr, ptep, 1);
diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c
index 1519d090d5ea..0b88278927a4 100644
--- a/arch/arm64/mm/contpte.c
+++ b/arch/arm64/mm/contpte.c
@@ -508,7 +508,7 @@ pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm,
}
EXPORT_SYMBOL_GPL(contpte_get_and_clear_full_ptes);
-int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
+bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep,
unsigned int nr)
{
@@ -525,7 +525,7 @@ int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
*/
unsigned long end = addr + nr * PAGE_SIZE;
- int young = 0;
+ bool young = false;
ptep = contpte_align_addr_ptep(&addr, &end, ptep, nr);
for (; addr != end; ptep++, addr += PAGE_SIZE)
diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h
index ea72291de553..7678c040a2fd 100644
--- a/arch/microblaze/include/asm/pgtable.h
+++ b/arch/microblaze/include/asm/pgtable.h
@@ -318,7 +318,7 @@ static inline void set_pte(pte_t *ptep, pte_t pte)
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
struct vm_area_struct;
-static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
+static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
unsigned long address, pte_t *ptep)
{
return (pte_update(ptep, _PAGE_ACCESSED, 0) & _PAGE_ACCESSED) != 0;
diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
index f6fb99cb94d9..d5e39f2eb415 100644
--- a/arch/parisc/include/asm/pgtable.h
+++ b/arch/parisc/include/asm/pgtable.h
@@ -438,16 +438,16 @@ static inline pte_t ptep_get(pte_t *ptep)
}
#define ptep_get ptep_get
-static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
+static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
{
pte_t pte;
pte = ptep_get(ptep);
if (!pte_young(pte)) {
- return 0;
+ return false;
}
set_pte_at(vma->vm_mm, addr, ptep, pte_mkold(pte));
- return 1;
+ return true;
}
int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h
index 001e28f9eabc..2a889e2093e8 100644
--- a/arch/powerpc/include/asm/book3s/32/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
@@ -295,8 +295,8 @@ static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, p
* for our hash-based implementation, we fix that up here.
*/
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
-static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
- unsigned long addr, pte_t *ptep)
+static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
+ unsigned long addr, pte_t *ptep)
{
unsigned long old;
old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 1a91762b455d..25e3a86943e2 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -349,13 +349,13 @@ static inline unsigned long pte_update(struct mm_struct *mm, unsigned long addr,
* For radix: H_PAGE_HASHPTE should be zero. Hence we can use the same
* function for both hash and radix.
*/
-static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
- unsigned long addr, pte_t *ptep)
+static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
+ unsigned long addr, pte_t *ptep)
{
unsigned long old;
if ((pte_raw(*ptep) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
- return 0;
+ return false;
old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
return (old & _PAGE_ACCESSED) != 0;
}
diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/include/asm/nohash/pgtable.h
index e6da5eaccff6..43cf52f0c7d6 100644
--- a/arch/powerpc/include/asm/nohash/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/pgtable.h
@@ -101,8 +101,8 @@ static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, p
}
#endif
-static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pte_t *ptep)
+static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep)
{
unsigned long old;
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index ab4ce1cc9d9c..fb010dcdf343 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -659,8 +659,8 @@ static inline void pte_clear(struct mm_struct *mm,
extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
pte_t *ptep, pte_t entry, int dirty);
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG /* defined in mm/pgtable.c */
-extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address,
- pte_t *ptep);
+extern bool ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address,
+ pte_t *ptep);
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c
index b1ed2f14dc3a..de24a19e8ebd 100644
--- a/arch/riscv/mm/pgtable.c
+++ b/arch/riscv/mm/pgtable.c
@@ -29,12 +29,12 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
return true;
}
-int ptep_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address,
- pte_t *ptep)
+bool ptep_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address,
+ pte_t *ptep)
{
if (!pte_young(ptep_get(ptep)))
- return 0;
+ return false;
return test_and_clear_bit(_PAGE_ACCESSED_OFFSET, &pte_val(*ptep));
}
EXPORT_SYMBOL_GPL(ptep_test_and_clear_young);
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 1c3c3be93be9..da1a7a31fa22 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1164,8 +1164,8 @@ pte_t ptep_xchg_direct(struct mm_struct *, unsigned long, pte_t *, pte_t);
pte_t ptep_xchg_lazy(struct mm_struct *, unsigned long, pte_t *, pte_t);
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
-static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pte_t *ptep)
+static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep)
{
pte_t pte = *ptep;
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 54289f4587a4..563a6289ea44 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1232,8 +1232,8 @@ extern int ptep_set_access_flags(struct vm_area_struct *vma,
pte_t entry, int dirty);
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
-extern int ptep_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pte_t *ptep);
+extern bool ptep_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep);
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
extern int ptep_clear_flush_young(struct vm_area_struct *vma,
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 2e5ecfdce73c..c594976afc5c 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -443,10 +443,10 @@ int pudp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
}
#endif
-int ptep_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pte_t *ptep)
+bool ptep_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep)
{
- int ret = 0;
+ bool ret = false;
if (pte_young(*ptep))
ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
diff --git a/arch/xtensa/include/asm/pgtable.h b/arch/xtensa/include/asm/pgtable.h
index 61f07d981a94..b962ef4652f5 100644
--- a/arch/xtensa/include/asm/pgtable.h
+++ b/arch/xtensa/include/asm/pgtable.h
@@ -304,15 +304,15 @@ set_pmd(pmd_t *pmdp, pmd_t pmdval)
struct vm_area_struct;
-static inline int
+static inline bool
ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr,
pte_t *ptep)
{
pte_t pte = *ptep;
if (!pte_young(pte))
- return 0;
+ return false;
update_pte(ptep, pte_mkold(pte));
- return 1;
+ return true;
}
static inline pte_t
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 17d961c612fc..8e75dc9f7932 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -491,17 +491,17 @@ static inline pgd_t pgdp_get(pgd_t *pgdp)
#endif
#ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
-static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address,
- pte_t *ptep)
+static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
{
pte_t pte = ptep_get(ptep);
- int r = 1;
+ bool young = true;
+
if (!pte_young(pte))
- r = 0;
+ young = false;
else
set_pte_at(vma->vm_mm, address, ptep, pte_mkold(pte));
- return r;
+ return young;
}
#endif
@@ -1123,10 +1123,10 @@ static inline int clear_flush_young_ptes(struct vm_area_struct *vma,
*
* Returns: whether any PTE was young.
*/
-static inline int test_and_clear_young_ptes(struct vm_area_struct *vma,
+static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep, unsigned int nr)
{
- int young = 0;
+ bool young = false;
for (;;) {
young |= ptep_test_and_clear_young(vma, addr, ptep);
--
2.47.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes()
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
2026-03-19 3:24 ` [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young() Baolin Wang
@ 2026-03-19 3:24 ` Baolin Wang
2026-03-19 11:30 ` Lorenzo Stoakes (Oracle)
2026-03-21 5:18 ` Ritesh Harjani
2026-03-19 3:24 ` [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young() Baolin Wang
` (5 subsequent siblings)
7 siblings, 2 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-19 3:24 UTC (permalink / raw)
To: akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
The ptep_clear_flush_young() and clear_flush_young_ptes() are used to clear
the young flag and flush the TLB, returning whether the young flag was set.
Change the return type to bool to make the intention clearer.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
arch/arm64/include/asm/pgtable.h | 15 +++++++--------
arch/arm64/mm/contpte.c | 4 ++--
arch/parisc/include/asm/pgtable.h | 2 +-
arch/parisc/kernel/cache.c | 8 ++++----
arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
arch/riscv/include/asm/pgtable.h | 4 ++--
arch/s390/include/asm/pgtable.h | 4 ++--
arch/x86/include/asm/pgtable.h | 4 ++--
arch/x86/mm/pgtable.c | 4 ++--
include/linux/pgtable.h | 8 ++++----
mm/pgtable-generic.c | 7 ++++---
11 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 8c651695204c..393a9d1873f6 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -1299,10 +1299,10 @@ static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
return pte_young(pte);
}
-static inline int __ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep)
+static inline bool __ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
{
- int young = __ptep_test_and_clear_young(vma, address, ptep);
+ bool young = __ptep_test_and_clear_young(vma, address, ptep);
if (young) {
/*
@@ -1648,7 +1648,7 @@ extern pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm,
unsigned int nr, int full);
bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep, unsigned int nr);
-int contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
+bool contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep, unsigned int nr);
extern void contpte_wrprotect_ptes(struct mm_struct *mm, unsigned long addr,
pte_t *ptep, unsigned int nr);
@@ -1831,7 +1831,7 @@ static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
}
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
-static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
+static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep)
{
pte_t orig_pte = __ptep_get(ptep);
@@ -1843,9 +1843,8 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
}
#define clear_flush_young_ptes clear_flush_young_ptes
-static inline int clear_flush_young_ptes(struct vm_area_struct *vma,
- unsigned long addr, pte_t *ptep,
- unsigned int nr)
+static inline bool clear_flush_young_ptes(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep, unsigned int nr)
{
if (likely(nr == 1 && !pte_cont(__ptep_get(ptep))))
return __ptep_clear_flush_young(vma, addr, ptep);
diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c
index 0b88278927a4..2ef4bff3b998 100644
--- a/arch/arm64/mm/contpte.c
+++ b/arch/arm64/mm/contpte.c
@@ -535,11 +535,11 @@ bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
}
EXPORT_SYMBOL_GPL(contpte_test_and_clear_young_ptes);
-int contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
+bool contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep,
unsigned int nr)
{
- int young;
+ bool young;
young = contpte_test_and_clear_young_ptes(vma, addr, ptep, nr);
diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
index d5e39f2eb415..f6984b3ba531 100644
--- a/arch/parisc/include/asm/pgtable.h
+++ b/arch/parisc/include/asm/pgtable.h
@@ -450,7 +450,7 @@ static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, unsigne
return true;
}
-int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
+bool ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
struct mm_struct;
diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
index 4c5240d3a3c7..268530eb107d 100644
--- a/arch/parisc/kernel/cache.c
+++ b/arch/parisc/kernel/cache.c
@@ -781,18 +781,18 @@ void flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned lon
__flush_cache_page(vma, vmaddr, PFN_PHYS(page_to_pfn(page)));
}
-int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr,
- pte_t *ptep)
+bool ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr,
+ pte_t *ptep)
{
pte_t pte = ptep_get(ptep);
if (!pte_young(pte))
- return 0;
+ return false;
set_pte(ptep, pte_mkold(pte));
#if CONFIG_FLUSH_PAGE_ACCESSED
__flush_cache_page(vma, addr, PFN_PHYS(pte_pfn(pte)));
#endif
- return 1;
+ return true;
}
/*
diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h b/arch/powerpc/include/asm/nohash/64/pgtable.h
index 2deb955b7bc8..661eb3820d12 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -155,7 +155,7 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
#define ptep_clear_flush_young(__vma, __address, __ptep) \
({ \
- int __young = ptep_test_and_clear_young(__vma, __address, __ptep);\
+ bool __young = ptep_test_and_clear_young(__vma, __address, __ptep);\
__young; \
})
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index fb010dcdf343..11f57ccf6dc9 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -695,8 +695,8 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm,
}
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
-static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep)
+static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
{
/*
* This comment is borrowed from x86, but applies equally to RISC-V:
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index da1a7a31fa22..c9ab81caaf75 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1174,8 +1174,8 @@ static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
}
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
-static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep)
+static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
{
return ptep_test_and_clear_young(vma, address, ptep);
}
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 563a6289ea44..554dea93eb99 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1236,8 +1236,8 @@ extern bool ptep_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep);
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
-extern int ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep);
+extern bool ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep);
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index c594976afc5c..0007dc3d739e 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -483,8 +483,8 @@ int pudp_test_and_clear_young(struct vm_area_struct *vma,
}
#endif
-int ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep)
+bool ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
{
/*
* On x86 CPUs, clearing the accessed bit without a TLB flush
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 8e75dc9f7932..1198e216fde3 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -531,8 +531,8 @@ static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
#endif
#ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
-int ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep);
+bool ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep);
#endif
#ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
@@ -1086,10 +1086,10 @@ static inline void wrprotect_ptes(struct mm_struct *mm, unsigned long addr,
* Context: The caller holds the page table lock. The PTEs map consecutive
* pages that belong to the same folio. The PTEs are all in the same PMD.
*/
-static inline int clear_flush_young_ptes(struct vm_area_struct *vma,
+static inline bool clear_flush_young_ptes(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep, unsigned int nr)
{
- int young = 0;
+ bool young = false;
for (;;) {
young |= ptep_clear_flush_young(vma, addr, ptep);
diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
index af7966169d69..db0ee918b08a 100644
--- a/mm/pgtable-generic.c
+++ b/mm/pgtable-generic.c
@@ -81,10 +81,11 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
#endif
#ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
-int ptep_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pte_t *ptep)
+bool ptep_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
{
- int young;
+ bool young;
+
young = ptep_test_and_clear_young(vma, address, ptep);
if (young)
flush_tlb_page(vma, address);
--
2.47.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young()
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
2026-03-19 3:24 ` [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young() Baolin Wang
2026-03-19 3:24 ` [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes() Baolin Wang
@ 2026-03-19 3:24 ` Baolin Wang
2026-03-19 11:31 ` Lorenzo Stoakes (Oracle)
2026-03-21 5:24 ` Ritesh Harjani
2026-03-19 3:24 ` [PATCH 4/6] mm: change to return bool for pmdp_clear_flush_young() Baolin Wang
` (4 subsequent siblings)
7 siblings, 2 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-19 3:24 UTC (permalink / raw)
To: akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
Callers use pmdp_test_and_clear_young() to clear the young flag and check
whether it was set for this PMD entry. Change the return type to bool to
make the intention clearer.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
arch/arm64/include/asm/pgtable.h | 6 +++---
arch/powerpc/include/asm/book3s/64/pgtable.h | 10 +++++-----
arch/powerpc/mm/book3s64/pgtable.c | 4 ++--
arch/riscv/include/asm/pgtable.h | 2 +-
arch/s390/include/asm/pgtable.h | 4 ++--
arch/x86/include/asm/pgtable.h | 4 ++--
arch/x86/mm/pgtable.c | 6 +++---
include/linux/pgtable.h | 19 +++++++++----------
8 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 393a9d1873f6..7ea16f6ad564 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -1321,9 +1321,9 @@ static inline bool __ptep_clear_flush_young(struct vm_area_struct *vma,
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
-static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address,
- pmd_t *pmdp)
+static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address,
+ pmd_t *pmdp)
{
/* Operation applies to PMD table entry only if FEAT_HAFT is enabled */
VM_WARN_ON(pmd_table(READ_ONCE(*pmdp)) && !system_supports_haft());
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 25e3a86943e2..0f34011665a6 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1161,13 +1161,13 @@ pud_hugepage_update(struct mm_struct *mm, unsigned long addr, pud_t *pudp,
* For radix we should always find H_PAGE_HASHPTE zero. Hence
* the below will work for radix too
*/
-static inline int __pmdp_test_and_clear_young(struct mm_struct *mm,
- unsigned long addr, pmd_t *pmdp)
+static inline bool __pmdp_test_and_clear_young(struct mm_struct *mm,
+ unsigned long addr, pmd_t *pmdp)
{
unsigned long old;
if ((pmd_raw(*pmdp) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
- return 0;
+ return false;
old = pmd_hugepage_update(mm, addr, pmdp, _PAGE_ACCESSED, 0);
return ((old & _PAGE_ACCESSED) != 0);
}
@@ -1300,8 +1300,8 @@ extern int pudp_set_access_flags(struct vm_area_struct *vma,
pud_t entry, int dirty);
#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
-extern int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp);
+extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp);
#define __HAVE_ARCH_PUDP_TEST_AND_CLEAR_YOUNG
extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long address, pud_t *pudp);
diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/pgtable.c
index 4b09c04654a8..aed39bba891e 100644
--- a/arch/powerpc/mm/book3s64/pgtable.c
+++ b/arch/powerpc/mm/book3s64/pgtable.c
@@ -98,8 +98,8 @@ int pudp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
}
-int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp)
+bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp)
{
return __pmdp_test_and_clear_young(vma->vm_mm, address, pmdp);
}
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 11f57ccf6dc9..bac559d29036 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -1015,7 +1015,7 @@ static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
}
#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
-static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
+static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long address, pmd_t *pmdp)
{
return ptep_test_and_clear_young(vma, address, (pte_t *)pmdp);
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index c9ab81caaf75..1f5efb7be71d 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1683,8 +1683,8 @@ static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
}
#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
-static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmdp)
+static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pmd_t *pmdp)
{
pmd_t pmd = *pmdp;
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 554dea93eb99..bd02ee730a23 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1295,8 +1295,8 @@ extern int pudp_set_access_flags(struct vm_area_struct *vma,
pud_t entry, int dirty);
#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
-extern int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmdp);
+extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pmd_t *pmdp);
extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pud_t *pudp);
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 0007dc3d739e..10a5e0b2be36 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -456,10 +456,10 @@ bool ptep_test_and_clear_young(struct vm_area_struct *vma,
}
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
-int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmdp)
+bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pmd_t *pmdp)
{
- int ret = 0;
+ bool ret = false;
if (pmd_young(*pmdp))
ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 1198e216fde3..e53220b0a9a3 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -507,25 +507,24 @@ static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
#ifndef __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
-static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address,
- pmd_t *pmdp)
+static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp)
{
pmd_t pmd = *pmdp;
- int r = 1;
+ bool young = true;
+
if (!pmd_young(pmd))
- r = 0;
+ young = false;
else
set_pmd_at(vma->vm_mm, address, pmdp, pmd_mkold(pmd));
- return r;
+ return young;
}
#else
-static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address,
- pmd_t *pmdp)
+static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp)
{
BUILD_BUG();
- return 0;
+ return false;
}
#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG */
#endif
--
2.47.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 4/6] mm: change to return bool for pmdp_clear_flush_young()
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
` (2 preceding siblings ...)
2026-03-19 3:24 ` [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young() Baolin Wang
@ 2026-03-19 3:24 ` Baolin Wang
2026-03-19 11:33 ` Lorenzo Stoakes (Oracle)
2026-03-19 3:24 ` [PATCH 5/6] mm: change to return bool for pudp_test_and_clear_young() Baolin Wang
` (3 subsequent siblings)
7 siblings, 1 reply; 27+ messages in thread
From: Baolin Wang @ 2026-03-19 3:24 UTC (permalink / raw)
To: akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
The pmdp_clear_flush_young() is used to clear the young flag and flush the
TLB, returning whether the young flag was set for this PMD entry. Change
the return type to bool to make the intention clearer.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
arch/s390/include/asm/pgtable.h | 4 ++--
arch/x86/include/asm/pgtable.h | 4 ++--
arch/x86/mm/pgtable.c | 6 +++---
include/linux/pgtable.h | 10 +++++-----
mm/pgtable-generic.c | 7 ++++---
5 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 1f5efb7be71d..90bba85ca4b8 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1693,8 +1693,8 @@ static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
}
#define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
-static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmdp)
+static inline bool pmdp_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long addr, pmd_t *pmdp)
{
VM_BUG_ON(addr & ~HPAGE_MASK);
return pmdp_test_and_clear_young(vma, addr, pmdp);
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index bd02ee730a23..f9439449c9bd 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1301,8 +1301,8 @@ extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pud_t *pudp);
#define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
-extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp);
+extern bool pmdp_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp);
#define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 10a5e0b2be36..8c336edf0e65 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -503,10 +503,10 @@ bool ptep_clear_flush_young(struct vm_area_struct *vma,
}
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-int pmdp_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp)
+bool pmdp_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp)
{
- int young;
+ bool young;
VM_BUG_ON(address & ~HPAGE_PMD_MASK);
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index e53220b0a9a3..8b8838f19af3 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -536,18 +536,18 @@ bool ptep_clear_flush_young(struct vm_area_struct *vma,
#ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp);
+bool pmdp_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp);
#else
/*
* Despite relevant to THP only, this API is called from generic rmap code
* under PageTransHuge(), hence needs a dummy implementation for !THP
*/
-static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp)
+static inline bool pmdp_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp)
{
BUILD_BUG();
- return 0;
+ return false;
}
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
#endif
diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
index db0ee918b08a..b91b1a98029c 100644
--- a/mm/pgtable-generic.c
+++ b/mm/pgtable-generic.c
@@ -124,10 +124,11 @@ int pmdp_set_access_flags(struct vm_area_struct *vma,
#endif
#ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
-int pmdp_clear_flush_young(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmdp)
+bool pmdp_clear_flush_young(struct vm_area_struct *vma,
+ unsigned long address, pmd_t *pmdp)
{
- int young;
+ bool young;
+
VM_BUG_ON(address & ~HPAGE_PMD_MASK);
young = pmdp_test_and_clear_young(vma, address, pmdp);
if (young)
--
2.47.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 5/6] mm: change to return bool for pudp_test_and_clear_young()
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
` (3 preceding siblings ...)
2026-03-19 3:24 ` [PATCH 4/6] mm: change to return bool for pmdp_clear_flush_young() Baolin Wang
@ 2026-03-19 3:24 ` Baolin Wang
2026-03-19 11:34 ` Lorenzo Stoakes (Oracle)
2026-03-21 5:30 ` Ritesh Harjani
2026-03-19 3:24 ` [PATCH 6/6] mm: change to return bool for the MMU notifier's young flag check Baolin Wang
` (2 subsequent siblings)
7 siblings, 2 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-19 3:24 UTC (permalink / raw)
To: akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
The pudp_test_and_clear_young() is used to clear the young flag,
returning whether the young flag was set for this PUD entry. Change
the return type to bool to make the intention clearer.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
arch/powerpc/include/asm/book3s/64/pgtable.h | 10 +++++-----
arch/powerpc/mm/book3s64/pgtable.c | 4 ++--
arch/riscv/include/asm/pgtable.h | 4 ++--
arch/x86/include/asm/pgtable.h | 4 ++--
arch/x86/mm/pgtable.c | 6 +++---
5 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 0f34011665a6..083c4b9ed5b3 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1172,13 +1172,13 @@ static inline bool __pmdp_test_and_clear_young(struct mm_struct *mm,
return ((old & _PAGE_ACCESSED) != 0);
}
-static inline int __pudp_test_and_clear_young(struct mm_struct *mm,
- unsigned long addr, pud_t *pudp)
+static inline bool __pudp_test_and_clear_young(struct mm_struct *mm,
+ unsigned long addr, pud_t *pudp)
{
unsigned long old;
if ((pud_raw(*pudp) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
- return 0;
+ return false;
old = pud_hugepage_update(mm, addr, pudp, _PAGE_ACCESSED, 0);
return ((old & _PAGE_ACCESSED) != 0);
}
@@ -1303,8 +1303,8 @@ extern int pudp_set_access_flags(struct vm_area_struct *vma,
extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long address, pmd_t *pmdp);
#define __HAVE_ARCH_PUDP_TEST_AND_CLEAR_YOUNG
-extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address, pud_t *pudp);
+extern bool pudp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address, pud_t *pudp);
#define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/pgtable.c
index aed39bba891e..838cb4a8e2cf 100644
--- a/arch/powerpc/mm/book3s64/pgtable.c
+++ b/arch/powerpc/mm/book3s64/pgtable.c
@@ -104,8 +104,8 @@ bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
return __pmdp_test_and_clear_young(vma->vm_mm, address, pmdp);
}
-int pudp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address, pud_t *pudp)
+bool pudp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address, pud_t *pudp)
{
return __pudp_test_and_clear_young(vma->vm_mm, address, pudp);
}
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index bac559d29036..88fa63186ca5 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -1109,8 +1109,8 @@ static inline int pudp_set_access_flags(struct vm_area_struct *vma,
return ptep_set_access_flags(vma, address, (pte_t *)pudp, pud_pte(entry), dirty);
}
-static inline int pudp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long address, pud_t *pudp)
+static inline bool pudp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long address, pud_t *pudp)
{
return ptep_test_and_clear_young(vma, address, (pte_t *)pudp);
}
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index f9439449c9bd..6ca1fdd25191 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1297,8 +1297,8 @@ extern int pudp_set_access_flags(struct vm_area_struct *vma,
#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmdp);
-extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pud_t *pudp);
+extern bool pudp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pud_t *pudp);
#define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
extern bool pmdp_clear_flush_young(struct vm_area_struct *vma,
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 8c336edf0e65..2677dcf0bbce 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -470,10 +470,10 @@ bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
#endif
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-int pudp_test_and_clear_young(struct vm_area_struct *vma,
- unsigned long addr, pud_t *pudp)
+bool pudp_test_and_clear_young(struct vm_area_struct *vma,
+ unsigned long addr, pud_t *pudp)
{
- int ret = 0;
+ bool ret = false;
if (pud_young(*pudp))
ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
--
2.47.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 6/6] mm: change to return bool for the MMU notifier's young flag check
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
` (4 preceding siblings ...)
2026-03-19 3:24 ` [PATCH 5/6] mm: change to return bool for pudp_test_and_clear_young() Baolin Wang
@ 2026-03-19 3:24 ` Baolin Wang
2026-03-19 11:39 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:18 ` [PATCH 0/6] change young flag check functions to return bool Andrew Morton
2026-03-21 5:31 ` Ritesh Harjani
7 siblings, 1 reply; 27+ messages in thread
From: Baolin Wang @ 2026-03-19 3:24 UTC (permalink / raw)
To: akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
The MMU notifier young flag check related functions only return whether
the young flag was set. Change the return type to bool to make the
intention clearer.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
include/linux/mmu_notifier.h | 76 +++++++++++++++++-------------------
mm/internal.h | 16 ++++----
mm/mmu_notifier.c | 20 +++++-----
virt/kvm/kvm_main.c | 40 +++++++++----------
4 files changed, 72 insertions(+), 80 deletions(-)
diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
index 3705d350c863..17f2cdc77dd5 100644
--- a/include/linux/mmu_notifier.h
+++ b/include/linux/mmu_notifier.h
@@ -97,20 +97,20 @@ struct mmu_notifier_ops {
* Start-end is necessary in case the secondary MMU is mapping the page
* at a smaller granularity than the primary MMU.
*/
- int (*clear_flush_young)(struct mmu_notifier *subscription,
- struct mm_struct *mm,
- unsigned long start,
- unsigned long end);
+ bool (*clear_flush_young)(struct mmu_notifier *subscription,
+ struct mm_struct *mm,
+ unsigned long start,
+ unsigned long end);
/*
* clear_young is a lightweight version of clear_flush_young. Like the
* latter, it is supposed to test-and-clear the young/accessed bitflag
* in the secondary pte, but it may omit flushing the secondary tlb.
*/
- int (*clear_young)(struct mmu_notifier *subscription,
- struct mm_struct *mm,
- unsigned long start,
- unsigned long end);
+ bool (*clear_young)(struct mmu_notifier *subscription,
+ struct mm_struct *mm,
+ unsigned long start,
+ unsigned long end);
/*
* test_young is called to check the young/accessed bitflag in
@@ -118,9 +118,9 @@ struct mmu_notifier_ops {
* frequently used without actually clearing the flag or tearing
* down the secondary mapping on the page.
*/
- int (*test_young)(struct mmu_notifier *subscription,
- struct mm_struct *mm,
- unsigned long address);
+ bool (*test_young)(struct mmu_notifier *subscription,
+ struct mm_struct *mm,
+ unsigned long address);
/*
* invalidate_range_start() and invalidate_range_end() must be
@@ -376,14 +376,12 @@ mmu_interval_check_retry(struct mmu_interval_notifier *interval_sub,
extern void __mmu_notifier_subscriptions_destroy(struct mm_struct *mm);
extern void __mmu_notifier_release(struct mm_struct *mm);
-extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
- unsigned long start,
- unsigned long end);
-extern int __mmu_notifier_clear_young(struct mm_struct *mm,
- unsigned long start,
- unsigned long end);
-extern int __mmu_notifier_test_young(struct mm_struct *mm,
- unsigned long address);
+bool __mmu_notifier_clear_flush_young(struct mm_struct *mm,
+ unsigned long start, unsigned long end);
+bool __mmu_notifier_clear_young(struct mm_struct *mm,
+ unsigned long start, unsigned long end);
+bool __mmu_notifier_test_young(struct mm_struct *mm,
+ unsigned long address);
extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r);
extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r);
extern void __mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm,
@@ -403,30 +401,28 @@ static inline void mmu_notifier_release(struct mm_struct *mm)
__mmu_notifier_release(mm);
}
-static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm,
- unsigned long start,
- unsigned long end)
+static inline bool mmu_notifier_clear_flush_young(struct mm_struct *mm,
+ unsigned long start, unsigned long end)
{
if (mm_has_notifiers(mm))
return __mmu_notifier_clear_flush_young(mm, start, end);
- return 0;
+ return false;
}
-static inline int mmu_notifier_clear_young(struct mm_struct *mm,
- unsigned long start,
- unsigned long end)
+static inline bool mmu_notifier_clear_young(struct mm_struct *mm,
+ unsigned long start, unsigned long end)
{
if (mm_has_notifiers(mm))
return __mmu_notifier_clear_young(mm, start, end);
- return 0;
+ return false;
}
-static inline int mmu_notifier_test_young(struct mm_struct *mm,
- unsigned long address)
+static inline bool mmu_notifier_test_young(struct mm_struct *mm,
+ unsigned long address)
{
if (mm_has_notifiers(mm))
return __mmu_notifier_test_young(mm, address);
- return 0;
+ return false;
}
static inline void
@@ -552,24 +548,22 @@ static inline void mmu_notifier_release(struct mm_struct *mm)
{
}
-static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm,
- unsigned long start,
- unsigned long end)
+static inline bool mmu_notifier_clear_flush_young(struct mm_struct *mm,
+ unsigned long start, unsigned long end)
{
- return 0;
+ return false;
}
-static inline int mmu_notifier_clear_young(struct mm_struct *mm,
- unsigned long start,
- unsigned long end)
+static inline bool mmu_notifier_clear_young(struct mm_struct *mm,
+ unsigned long start, unsigned long end)
{
- return 0;
+ return false;
}
-static inline int mmu_notifier_test_young(struct mm_struct *mm,
- unsigned long address)
+static inline bool mmu_notifier_test_young(struct mm_struct *mm,
+ unsigned long address)
{
- return 0;
+ return false;
}
static inline void
diff --git a/mm/internal.h b/mm/internal.h
index 0eaca2f0eb6a..3d6eba216364 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1831,10 +1831,10 @@ static inline int io_remap_pfn_range_complete(struct vm_area_struct *vma,
}
#ifdef CONFIG_MMU_NOTIFIER
-static inline int clear_flush_young_ptes_notify(struct vm_area_struct *vma,
+static inline bool clear_flush_young_ptes_notify(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep, unsigned int nr)
{
- int young;
+ bool young;
young = clear_flush_young_ptes(vma, addr, ptep, nr);
young |= mmu_notifier_clear_flush_young(vma->vm_mm, addr,
@@ -1842,30 +1842,30 @@ static inline int clear_flush_young_ptes_notify(struct vm_area_struct *vma,
return young;
}
-static inline int pmdp_clear_flush_young_notify(struct vm_area_struct *vma,
+static inline bool pmdp_clear_flush_young_notify(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmdp)
{
- int young;
+ bool young;
young = pmdp_clear_flush_young(vma, addr, pmdp);
young |= mmu_notifier_clear_flush_young(vma->vm_mm, addr, addr + PMD_SIZE);
return young;
}
-static inline int test_and_clear_young_ptes_notify(struct vm_area_struct *vma,
+static inline bool test_and_clear_young_ptes_notify(struct vm_area_struct *vma,
unsigned long addr, pte_t *ptep, unsigned int nr)
{
- int young;
+ bool young;
young = test_and_clear_young_ptes(vma, addr, ptep, nr);
young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + nr * PAGE_SIZE);
return young;
}
-static inline int pmdp_test_and_clear_young_notify(struct vm_area_struct *vma,
+static inline bool pmdp_test_and_clear_young_notify(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmdp)
{
- int young;
+ bool young;
young = pmdp_test_and_clear_young(vma, addr, pmdp);
young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + PMD_SIZE);
diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
index 2502474b83b6..3e3e7e727ba2 100644
--- a/mm/mmu_notifier.c
+++ b/mm/mmu_notifier.c
@@ -364,12 +364,11 @@ void __mmu_notifier_release(struct mm_struct *mm)
* unmap the address and return 1 or 0 depending if the mapping previously
* existed or not.
*/
-int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
- unsigned long start,
- unsigned long end)
+bool __mmu_notifier_clear_flush_young(struct mm_struct *mm,
+ unsigned long start, unsigned long end)
{
struct mmu_notifier *subscription;
- int young = 0, id;
+ bool young = false, id;
id = srcu_read_lock(&srcu);
hlist_for_each_entry_srcu(subscription,
@@ -384,12 +383,11 @@ int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
return young;
}
-int __mmu_notifier_clear_young(struct mm_struct *mm,
- unsigned long start,
- unsigned long end)
+bool __mmu_notifier_clear_young(struct mm_struct *mm,
+ unsigned long start, unsigned long end)
{
struct mmu_notifier *subscription;
- int young = 0, id;
+ bool young = false, id;
id = srcu_read_lock(&srcu);
hlist_for_each_entry_srcu(subscription,
@@ -404,11 +402,11 @@ int __mmu_notifier_clear_young(struct mm_struct *mm,
return young;
}
-int __mmu_notifier_test_young(struct mm_struct *mm,
- unsigned long address)
+bool __mmu_notifier_test_young(struct mm_struct *mm,
+ unsigned long address)
{
struct mmu_notifier *subscription;
- int young = 0, id;
+ bool young = false, id;
id = srcu_read_lock(&srcu);
hlist_for_each_entry_srcu(subscription,
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index d0ab29672c71..6bcfc1b3021d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -646,11 +646,11 @@ static __always_inline kvm_mn_ret_t kvm_handle_hva_range(struct kvm *kvm,
return r;
}
-static __always_inline int kvm_age_hva_range(struct mmu_notifier *mn,
- unsigned long start,
- unsigned long end,
- gfn_handler_t handler,
- bool flush_on_ret)
+static __always_inline bool kvm_age_hva_range(struct mmu_notifier *mn,
+ unsigned long start,
+ unsigned long end,
+ gfn_handler_t handler,
+ bool flush_on_ret)
{
struct kvm *kvm = mmu_notifier_to_kvm(mn);
const struct kvm_mmu_notifier_range range = {
@@ -666,10 +666,10 @@ static __always_inline int kvm_age_hva_range(struct mmu_notifier *mn,
return kvm_handle_hva_range(kvm, &range).ret;
}
-static __always_inline int kvm_age_hva_range_no_flush(struct mmu_notifier *mn,
- unsigned long start,
- unsigned long end,
- gfn_handler_t handler)
+static __always_inline bool kvm_age_hva_range_no_flush(struct mmu_notifier *mn,
+ unsigned long start,
+ unsigned long end,
+ gfn_handler_t handler)
{
return kvm_age_hva_range(mn, start, end, handler, false);
}
@@ -829,10 +829,10 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn,
rcuwait_wake_up(&kvm->mn_memslots_update_rcuwait);
}
-static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
- struct mm_struct *mm,
- unsigned long start,
- unsigned long end)
+static bool kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
+ struct mm_struct *mm,
+ unsigned long start,
+ unsigned long end)
{
trace_kvm_age_hva(start, end);
@@ -840,10 +840,10 @@ static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
!IS_ENABLED(CONFIG_KVM_ELIDE_TLB_FLUSH_IF_YOUNG));
}
-static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn,
- struct mm_struct *mm,
- unsigned long start,
- unsigned long end)
+static bool kvm_mmu_notifier_clear_young(struct mmu_notifier *mn,
+ struct mm_struct *mm,
+ unsigned long start,
+ unsigned long end)
{
trace_kvm_age_hva(start, end);
@@ -863,9 +863,9 @@ static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn,
return kvm_age_hva_range_no_flush(mn, start, end, kvm_age_gfn);
}
-static int kvm_mmu_notifier_test_young(struct mmu_notifier *mn,
- struct mm_struct *mm,
- unsigned long address)
+static bool kvm_mmu_notifier_test_young(struct mmu_notifier *mn,
+ struct mm_struct *mm,
+ unsigned long address)
{
trace_kvm_test_age_hva(address);
--
2.47.3
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young()
2026-03-19 3:24 ` [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young() Baolin Wang
@ 2026-03-19 11:28 ` Lorenzo Stoakes (Oracle)
2026-03-20 2:59 ` Baolin Wang
2026-03-20 5:57 ` Ritesh Harjani
1 sibling, 1 reply; 27+ messages in thread
From: Lorenzo Stoakes (Oracle) @ 2026-03-19 11:28 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On Thu, Mar 19, 2026 at 11:24:00AM +0800, Baolin Wang wrote:
> Callers use ptep_test_and_clear_young() to clear the young flag and check
> whether it was set. Change the return type to bool to make the intention
> clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Couple nits about dropping externs below but otherwise LGTM, so:
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> ---
> arch/arm64/include/asm/pgtable.h | 8 ++++----
> arch/arm64/mm/contpte.c | 4 ++--
> arch/microblaze/include/asm/pgtable.h | 2 +-
> arch/parisc/include/asm/pgtable.h | 6 +++---
> arch/powerpc/include/asm/book3s/32/pgtable.h | 4 ++--
> arch/powerpc/include/asm/book3s/64/pgtable.h | 6 +++---
> arch/powerpc/include/asm/nohash/pgtable.h | 4 ++--
> arch/riscv/include/asm/pgtable.h | 4 ++--
> arch/riscv/mm/pgtable.c | 8 ++++----
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/x86/include/asm/pgtable.h | 4 ++--
> arch/x86/mm/pgtable.c | 6 +++---
> arch/xtensa/include/asm/pgtable.h | 6 +++---
> include/linux/pgtable.h | 16 ++++++++--------
> 14 files changed, 41 insertions(+), 41 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index ab451d20e4c5..8c651695204c 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -1282,7 +1282,7 @@ static inline void __pte_clear(struct mm_struct *mm,
> __set_pte(ptep, __pte(0));
> }
>
> -static inline int __ptep_test_and_clear_young(struct vm_area_struct *vma,
> +static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long address,
> pte_t *ptep)
> {
> @@ -1646,7 +1646,7 @@ extern void contpte_clear_full_ptes(struct mm_struct *mm, unsigned long addr,
> extern pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm,
> unsigned long addr, pte_t *ptep,
> unsigned int nr, int full);
> -int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
> +bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep, unsigned int nr);
> int contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep, unsigned int nr);
> @@ -1813,7 +1813,7 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
> }
>
> #define test_and_clear_young_ptes test_and_clear_young_ptes
> -static inline int test_and_clear_young_ptes(struct vm_area_struct *vma,
> +static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep,
> unsigned int nr)
> {
> @@ -1824,7 +1824,7 @@ static inline int test_and_clear_young_ptes(struct vm_area_struct *vma,
> }
>
> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep)
> {
> return test_and_clear_young_ptes(vma, addr, ptep, 1);
> diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c
> index 1519d090d5ea..0b88278927a4 100644
> --- a/arch/arm64/mm/contpte.c
> +++ b/arch/arm64/mm/contpte.c
> @@ -508,7 +508,7 @@ pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm,
> }
> EXPORT_SYMBOL_GPL(contpte_get_and_clear_full_ptes);
>
> -int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
> +bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep,
> unsigned int nr)
> {
> @@ -525,7 +525,7 @@ int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
> */
>
> unsigned long end = addr + nr * PAGE_SIZE;
> - int young = 0;
> + bool young = false;
>
> ptep = contpte_align_addr_ptep(&addr, &end, ptep, nr);
> for (; addr != end; ptep++, addr += PAGE_SIZE)
> diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h
> index ea72291de553..7678c040a2fd 100644
> --- a/arch/microblaze/include/asm/pgtable.h
> +++ b/arch/microblaze/include/asm/pgtable.h
> @@ -318,7 +318,7 @@ static inline void set_pte(pte_t *ptep, pte_t pte)
>
> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
> struct vm_area_struct;
> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long address, pte_t *ptep)
> {
> return (pte_update(ptep, _PAGE_ACCESSED, 0) & _PAGE_ACCESSED) != 0;
> diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
> index f6fb99cb94d9..d5e39f2eb415 100644
> --- a/arch/parisc/include/asm/pgtable.h
> +++ b/arch/parisc/include/asm/pgtable.h
> @@ -438,16 +438,16 @@ static inline pte_t ptep_get(pte_t *ptep)
> }
> #define ptep_get ptep_get
>
> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
> {
> pte_t pte;
>
> pte = ptep_get(ptep);
> if (!pte_young(pte)) {
> - return 0;
> + return false;
> }
> set_pte_at(vma->vm_mm, addr, ptep, pte_mkold(pte));
> - return 1;
> + return true;
> }
>
> int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
> diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h
> index 001e28f9eabc..2a889e2093e8 100644
> --- a/arch/powerpc/include/asm/book3s/32/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
> @@ -295,8 +295,8 @@ static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, p
> * for our hash-based implementation, we fix that up here.
> */
> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
> -static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
> - unsigned long addr, pte_t *ptep)
> +static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
> + unsigned long addr, pte_t *ptep)
> {
> unsigned long old;
> old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index 1a91762b455d..25e3a86943e2 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -349,13 +349,13 @@ static inline unsigned long pte_update(struct mm_struct *mm, unsigned long addr,
> * For radix: H_PAGE_HASHPTE should be zero. Hence we can use the same
> * function for both hash and radix.
> */
> -static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
> - unsigned long addr, pte_t *ptep)
> +static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
> + unsigned long addr, pte_t *ptep)
> {
> unsigned long old;
>
> if ((pte_raw(*ptep) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
> - return 0;
> + return false;
> old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
> return (old & _PAGE_ACCESSED) != 0;
> }
> diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/include/asm/nohash/pgtable.h
> index e6da5eaccff6..43cf52f0c7d6 100644
> --- a/arch/powerpc/include/asm/nohash/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/pgtable.h
> @@ -101,8 +101,8 @@ static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, p
> }
> #endif
>
> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pte_t *ptep)
> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pte_t *ptep)
> {
> unsigned long old;
>
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index ab4ce1cc9d9c..fb010dcdf343 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -659,8 +659,8 @@ static inline void pte_clear(struct mm_struct *mm,
> extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
> pte_t *ptep, pte_t entry, int dirty);
> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG /* defined in mm/pgtable.c */
> -extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address,
> - pte_t *ptep);
> +extern bool ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address,
> + pte_t *ptep);
Let's drop the extern.
>
> #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
> static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
> diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c
> index b1ed2f14dc3a..de24a19e8ebd 100644
> --- a/arch/riscv/mm/pgtable.c
> +++ b/arch/riscv/mm/pgtable.c
> @@ -29,12 +29,12 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
> return true;
> }
>
> -int ptep_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address,
> - pte_t *ptep)
> +bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address,
> + pte_t *ptep)
> {
> if (!pte_young(ptep_get(ptep)))
> - return 0;
> + return false;
> return test_and_clear_bit(_PAGE_ACCESSED_OFFSET, &pte_val(*ptep));
> }
> EXPORT_SYMBOL_GPL(ptep_test_and_clear_young);
> diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
> index 1c3c3be93be9..da1a7a31fa22 100644
> --- a/arch/s390/include/asm/pgtable.h
> +++ b/arch/s390/include/asm/pgtable.h
> @@ -1164,8 +1164,8 @@ pte_t ptep_xchg_direct(struct mm_struct *, unsigned long, pte_t *, pte_t);
> pte_t ptep_xchg_lazy(struct mm_struct *, unsigned long, pte_t *, pte_t);
>
> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pte_t *ptep)
> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pte_t *ptep)
> {
> pte_t pte = *ptep;
>
> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
> index 54289f4587a4..563a6289ea44 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -1232,8 +1232,8 @@ extern int ptep_set_access_flags(struct vm_area_struct *vma,
> pte_t entry, int dirty);
>
> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
> -extern int ptep_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pte_t *ptep);
> +extern bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pte_t *ptep);
Let's drop the extern.
>
> #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
> extern int ptep_clear_flush_young(struct vm_area_struct *vma,
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index 2e5ecfdce73c..c594976afc5c 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -443,10 +443,10 @@ int pudp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
> }
> #endif
>
> -int ptep_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pte_t *ptep)
> +bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pte_t *ptep)
> {
> - int ret = 0;
> + bool ret = false;
>
> if (pte_young(*ptep))
> ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
> diff --git a/arch/xtensa/include/asm/pgtable.h b/arch/xtensa/include/asm/pgtable.h
> index 61f07d981a94..b962ef4652f5 100644
> --- a/arch/xtensa/include/asm/pgtable.h
> +++ b/arch/xtensa/include/asm/pgtable.h
> @@ -304,15 +304,15 @@ set_pmd(pmd_t *pmdp, pmd_t pmdval)
>
> struct vm_area_struct;
>
> -static inline int
> +static inline bool
> ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr,
> pte_t *ptep)
> {
> pte_t pte = *ptep;
> if (!pte_young(pte))
> - return 0;
> + return false;
> update_pte(ptep, pte_mkold(pte));
> - return 1;
> + return true;
> }
>
> static inline pte_t
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index 17d961c612fc..8e75dc9f7932 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -491,17 +491,17 @@ static inline pgd_t pgdp_get(pgd_t *pgdp)
> #endif
>
> #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address,
> - pte_t *ptep)
> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address, pte_t *ptep)
> {
> pte_t pte = ptep_get(ptep);
> - int r = 1;
> + bool young = true;
> +
> if (!pte_young(pte))
> - r = 0;
> + young = false;
> else
> set_pte_at(vma->vm_mm, address, ptep, pte_mkold(pte));
> - return r;
> + return young;
> }
> #endif
>
> @@ -1123,10 +1123,10 @@ static inline int clear_flush_young_ptes(struct vm_area_struct *vma,
> *
> * Returns: whether any PTE was young.
> */
> -static inline int test_and_clear_young_ptes(struct vm_area_struct *vma,
> +static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep, unsigned int nr)
> {
> - int young = 0;
> + bool young = false;
>
> for (;;) {
> young |= ptep_test_and_clear_young(vma, addr, ptep);
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes()
2026-03-19 3:24 ` [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes() Baolin Wang
@ 2026-03-19 11:30 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:05 ` Baolin Wang
2026-03-21 5:18 ` Ritesh Harjani
1 sibling, 1 reply; 27+ messages in thread
From: Lorenzo Stoakes (Oracle) @ 2026-03-19 11:30 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On Thu, Mar 19, 2026 at 11:24:01AM +0800, Baolin Wang wrote:
> The ptep_clear_flush_young() and clear_flush_young_ptes() are used to clear
> the young flag and flush the TLB, returning whether the young flag was set.
> Change the return type to bool to make the intention clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Couple nits but LGTM, so:
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> ---
> arch/arm64/include/asm/pgtable.h | 15 +++++++--------
> arch/arm64/mm/contpte.c | 4 ++--
> arch/parisc/include/asm/pgtable.h | 2 +-
> arch/parisc/kernel/cache.c | 8 ++++----
> arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
> arch/riscv/include/asm/pgtable.h | 4 ++--
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/x86/include/asm/pgtable.h | 4 ++--
> arch/x86/mm/pgtable.c | 4 ++--
> include/linux/pgtable.h | 8 ++++----
> mm/pgtable-generic.c | 7 ++++---
> 11 files changed, 31 insertions(+), 31 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 8c651695204c..393a9d1873f6 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -1299,10 +1299,10 @@ static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
> return pte_young(pte);
> }
>
> -static inline int __ptep_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pte_t *ptep)
> +static inline bool __ptep_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pte_t *ptep)
I mean this is subjective stuff but can we just put 2nd line 2 tabs indented
underneath? Makes it easier for changes like this to not propagate.
Same comment for all of these!
> {
> - int young = __ptep_test_and_clear_young(vma, address, ptep);
> + bool young = __ptep_test_and_clear_young(vma, address, ptep);
>
> if (young) {
> /*
> @@ -1648,7 +1648,7 @@ extern pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm,
> unsigned int nr, int full);
> bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep, unsigned int nr);
> -int contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
> +bool contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep, unsigned int nr);
> extern void contpte_wrprotect_ptes(struct mm_struct *mm, unsigned long addr,
> pte_t *ptep, unsigned int nr);
> @@ -1831,7 +1831,7 @@ static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> }
>
> #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
> -static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
> +static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep)
> {
> pte_t orig_pte = __ptep_get(ptep);
> @@ -1843,9 +1843,8 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
> }
>
> #define clear_flush_young_ptes clear_flush_young_ptes
> -static inline int clear_flush_young_ptes(struct vm_area_struct *vma,
> - unsigned long addr, pte_t *ptep,
> - unsigned int nr)
> +static inline bool clear_flush_young_ptes(struct vm_area_struct *vma,
> + unsigned long addr, pte_t *ptep, unsigned int nr)
> {
> if (likely(nr == 1 && !pte_cont(__ptep_get(ptep))))
> return __ptep_clear_flush_young(vma, addr, ptep);
> diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c
> index 0b88278927a4..2ef4bff3b998 100644
> --- a/arch/arm64/mm/contpte.c
> +++ b/arch/arm64/mm/contpte.c
> @@ -535,11 +535,11 @@ bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
> }
> EXPORT_SYMBOL_GPL(contpte_test_and_clear_young_ptes);
>
> -int contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
> +bool contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep,
> unsigned int nr)
> {
> - int young;
> + bool young;
>
> young = contpte_test_and_clear_young_ptes(vma, addr, ptep, nr);
>
> diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
> index d5e39f2eb415..f6984b3ba531 100644
> --- a/arch/parisc/include/asm/pgtable.h
> +++ b/arch/parisc/include/asm/pgtable.h
> @@ -450,7 +450,7 @@ static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, unsigne
> return true;
> }
>
> -int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
> +bool ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
> pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
>
> struct mm_struct;
> diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
> index 4c5240d3a3c7..268530eb107d 100644
> --- a/arch/parisc/kernel/cache.c
> +++ b/arch/parisc/kernel/cache.c
> @@ -781,18 +781,18 @@ void flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned lon
> __flush_cache_page(vma, vmaddr, PFN_PHYS(page_to_pfn(page)));
> }
>
> -int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr,
> - pte_t *ptep)
> +bool ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr,
> + pte_t *ptep)
> {
> pte_t pte = ptep_get(ptep);
>
> if (!pte_young(pte))
> - return 0;
> + return false;
> set_pte(ptep, pte_mkold(pte));
> #if CONFIG_FLUSH_PAGE_ACCESSED
> __flush_cache_page(vma, addr, PFN_PHYS(pte_pfn(pte)));
> #endif
> - return 1;
> + return true;
> }
>
> /*
> diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h b/arch/powerpc/include/asm/nohash/64/pgtable.h
> index 2deb955b7bc8..661eb3820d12 100644
> --- a/arch/powerpc/include/asm/nohash/64/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
> @@ -155,7 +155,7 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
> #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
> #define ptep_clear_flush_young(__vma, __address, __ptep) \
> ({ \
> - int __young = ptep_test_and_clear_young(__vma, __address, __ptep);\
> + bool __young = ptep_test_and_clear_young(__vma, __address, __ptep);\
> __young; \
> })
>
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index fb010dcdf343..11f57ccf6dc9 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -695,8 +695,8 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm,
> }
>
> #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
> -static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pte_t *ptep)
> +static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pte_t *ptep)
> {
> /*
> * This comment is borrowed from x86, but applies equally to RISC-V:
> diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
> index da1a7a31fa22..c9ab81caaf75 100644
> --- a/arch/s390/include/asm/pgtable.h
> +++ b/arch/s390/include/asm/pgtable.h
> @@ -1174,8 +1174,8 @@ static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> }
>
> #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
> -static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pte_t *ptep)
> +static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pte_t *ptep)
> {
> return ptep_test_and_clear_young(vma, address, ptep);
> }
> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
> index 563a6289ea44..554dea93eb99 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -1236,8 +1236,8 @@ extern bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep);
>
> #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
> -extern int ptep_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pte_t *ptep);
> +extern bool ptep_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pte_t *ptep);
Drop extern please!
>
> #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
> static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index c594976afc5c..0007dc3d739e 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -483,8 +483,8 @@ int pudp_test_and_clear_young(struct vm_area_struct *vma,
> }
> #endif
>
> -int ptep_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pte_t *ptep)
> +bool ptep_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pte_t *ptep)
> {
> /*
> * On x86 CPUs, clearing the accessed bit without a TLB flush
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index 8e75dc9f7932..1198e216fde3 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -531,8 +531,8 @@ static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> #endif
>
> #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
> -int ptep_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pte_t *ptep);
> +bool ptep_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pte_t *ptep);
> #endif
>
> #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
> @@ -1086,10 +1086,10 @@ static inline void wrprotect_ptes(struct mm_struct *mm, unsigned long addr,
> * Context: The caller holds the page table lock. The PTEs map consecutive
> * pages that belong to the same folio. The PTEs are all in the same PMD.
> */
> -static inline int clear_flush_young_ptes(struct vm_area_struct *vma,
> +static inline bool clear_flush_young_ptes(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep, unsigned int nr)
> {
> - int young = 0;
> + bool young = false;
>
> for (;;) {
> young |= ptep_clear_flush_young(vma, addr, ptep);
> diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
> index af7966169d69..db0ee918b08a 100644
> --- a/mm/pgtable-generic.c
> +++ b/mm/pgtable-generic.c
> @@ -81,10 +81,11 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
> #endif
>
> #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
> -int ptep_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pte_t *ptep)
> +bool ptep_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pte_t *ptep)
> {
> - int young;
> + bool young;
> +
> young = ptep_test_and_clear_young(vma, address, ptep);
> if (young)
> flush_tlb_page(vma, address);
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young()
2026-03-19 3:24 ` [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young() Baolin Wang
@ 2026-03-19 11:31 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:07 ` Baolin Wang
2026-03-21 5:24 ` Ritesh Harjani
1 sibling, 1 reply; 27+ messages in thread
From: Lorenzo Stoakes (Oracle) @ 2026-03-19 11:31 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On Thu, Mar 19, 2026 at 11:24:02AM +0800, Baolin Wang wrote:
> Callers use pmdp_test_and_clear_young() to clear the young flag and check
> whether it was set for this PMD entry. Change the return type to bool to
> make the intention clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Some nits similar to before, otherwise LGTM so:
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> ---
> arch/arm64/include/asm/pgtable.h | 6 +++---
> arch/powerpc/include/asm/book3s/64/pgtable.h | 10 +++++-----
> arch/powerpc/mm/book3s64/pgtable.c | 4 ++--
> arch/riscv/include/asm/pgtable.h | 2 +-
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/x86/include/asm/pgtable.h | 4 ++--
> arch/x86/mm/pgtable.c | 6 +++---
> include/linux/pgtable.h | 19 +++++++++----------
> 8 files changed, 27 insertions(+), 28 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index 393a9d1873f6..7ea16f6ad564 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -1321,9 +1321,9 @@ static inline bool __ptep_clear_flush_young(struct vm_area_struct *vma,
>
> #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
> #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
> -static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address,
> - pmd_t *pmdp)
> +static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address,
> + pmd_t *pmdp)
Similar comment as before re: indetation, let's use 2 tabs please, so this would
become:
static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long address, pmd_t *pmdp)
Thanks!
Same comment to all other cases here.
> {
> /* Operation applies to PMD table entry only if FEAT_HAFT is enabled */
> VM_WARN_ON(pmd_table(READ_ONCE(*pmdp)) && !system_supports_haft());
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index 25e3a86943e2..0f34011665a6 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -1161,13 +1161,13 @@ pud_hugepage_update(struct mm_struct *mm, unsigned long addr, pud_t *pudp,
> * For radix we should always find H_PAGE_HASHPTE zero. Hence
> * the below will work for radix too
> */
> -static inline int __pmdp_test_and_clear_young(struct mm_struct *mm,
> - unsigned long addr, pmd_t *pmdp)
> +static inline bool __pmdp_test_and_clear_young(struct mm_struct *mm,
> + unsigned long addr, pmd_t *pmdp)
> {
> unsigned long old;
>
> if ((pmd_raw(*pmdp) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
> - return 0;
> + return false;
> old = pmd_hugepage_update(mm, addr, pmdp, _PAGE_ACCESSED, 0);
> return ((old & _PAGE_ACCESSED) != 0);
> }
> @@ -1300,8 +1300,8 @@ extern int pudp_set_access_flags(struct vm_area_struct *vma,
> pud_t entry, int dirty);
>
> #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
> -extern int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address, pmd_t *pmdp);
> +extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp);
Remove the extern please!
> #define __HAVE_ARCH_PUDP_TEST_AND_CLEAR_YOUNG
> extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long address, pud_t *pudp);
> diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/pgtable.c
> index 4b09c04654a8..aed39bba891e 100644
> --- a/arch/powerpc/mm/book3s64/pgtable.c
> +++ b/arch/powerpc/mm/book3s64/pgtable.c
> @@ -98,8 +98,8 @@ int pudp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
> }
>
>
> -int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address, pmd_t *pmdp)
> +bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp)
> {
> return __pmdp_test_and_clear_young(vma->vm_mm, address, pmdp);
> }
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index 11f57ccf6dc9..bac559d29036 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -1015,7 +1015,7 @@ static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
> }
>
> #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
> -static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> +static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long address, pmd_t *pmdp)
> {
> return ptep_test_and_clear_young(vma, address, (pte_t *)pmdp);
> diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
> index c9ab81caaf75..1f5efb7be71d 100644
> --- a/arch/s390/include/asm/pgtable.h
> +++ b/arch/s390/include/asm/pgtable.h
> @@ -1683,8 +1683,8 @@ static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
> }
>
> #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
> -static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pmd_t *pmdp)
> +static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pmd_t *pmdp)
> {
> pmd_t pmd = *pmdp;
>
> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
> index 554dea93eb99..bd02ee730a23 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -1295,8 +1295,8 @@ extern int pudp_set_access_flags(struct vm_area_struct *vma,
> pud_t entry, int dirty);
>
> #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
> -extern int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pmd_t *pmdp);
> +extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pmd_t *pmdp);
Remove the extern please!
> extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long addr, pud_t *pudp);
>
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index 0007dc3d739e..10a5e0b2be36 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -456,10 +456,10 @@ bool ptep_test_and_clear_young(struct vm_area_struct *vma,
> }
>
> #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
> -int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pmd_t *pmdp)
> +bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pmd_t *pmdp)
> {
> - int ret = 0;
> + bool ret = false;
>
> if (pmd_young(*pmdp))
> ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index 1198e216fde3..e53220b0a9a3 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -507,25 +507,24 @@ static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
>
> #ifndef __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
> #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
> -static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address,
> - pmd_t *pmdp)
> +static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp)
> {
> pmd_t pmd = *pmdp;
> - int r = 1;
> + bool young = true;
> +
> if (!pmd_young(pmd))
> - r = 0;
> + young = false;
> else
> set_pmd_at(vma->vm_mm, address, pmdp, pmd_mkold(pmd));
> - return r;
> + return young;
> }
> #else
> -static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address,
> - pmd_t *pmdp)
> +static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp)
> {
> BUILD_BUG();
> - return 0;
> + return false;
> }
> #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG */
> #endif
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 4/6] mm: change to return bool for pmdp_clear_flush_young()
2026-03-19 3:24 ` [PATCH 4/6] mm: change to return bool for pmdp_clear_flush_young() Baolin Wang
@ 2026-03-19 11:33 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:09 ` Baolin Wang
0 siblings, 1 reply; 27+ messages in thread
From: Lorenzo Stoakes (Oracle) @ 2026-03-19 11:33 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On Thu, Mar 19, 2026 at 11:24:03AM +0800, Baolin Wang wrote:
> The pmdp_clear_flush_young() is used to clear the young flag and flush the
> TLB, returning whether the young flag was set for this PMD entry. Change
> the return type to bool to make the intention clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Some nits, but otherwise LGTM, so:
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> ---
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/x86/include/asm/pgtable.h | 4 ++--
> arch/x86/mm/pgtable.c | 6 +++---
> include/linux/pgtable.h | 10 +++++-----
> mm/pgtable-generic.c | 7 ++++---
> 5 files changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
> index 1f5efb7be71d..90bba85ca4b8 100644
> --- a/arch/s390/include/asm/pgtable.h
> +++ b/arch/s390/include/asm/pgtable.h
> @@ -1693,8 +1693,8 @@ static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> }
>
> #define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
> -static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long addr, pmd_t *pmdp)
> +static inline bool pmdp_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long addr, pmd_t *pmdp)
Same indentation comment as with other patches, 2 tabs you know the drill :)
applies to all such in this patch.
> {
> VM_BUG_ON(addr & ~HPAGE_MASK);
> return pmdp_test_and_clear_young(vma, addr, pmdp);
> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
> index bd02ee730a23..f9439449c9bd 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -1301,8 +1301,8 @@ extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long addr, pud_t *pudp);
>
> #define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
> -extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pmd_t *pmdp);
> +extern bool pmdp_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp);
Drop the extern please!
>
>
> #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index 10a5e0b2be36..8c336edf0e65 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -503,10 +503,10 @@ bool ptep_clear_flush_young(struct vm_area_struct *vma,
> }
>
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> -int pmdp_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pmd_t *pmdp)
> +bool pmdp_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp)
> {
> - int young;
> + bool young;
>
> VM_BUG_ON(address & ~HPAGE_PMD_MASK);
>
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index e53220b0a9a3..8b8838f19af3 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -536,18 +536,18 @@ bool ptep_clear_flush_young(struct vm_area_struct *vma,
>
> #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> -extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pmd_t *pmdp);
> +bool pmdp_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp);
Ahh! Here you drop the extern :) AND use 2 tabs :)) thanks!
> #else
> /*
> * Despite relevant to THP only, this API is called from generic rmap code
> * under PageTransHuge(), hence needs a dummy implementation for !THP
> */
> -static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pmd_t *pmdp)
> +static inline bool pmdp_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp)
> {
> BUILD_BUG();
> - return 0;
> + return false;
> }
> #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
> #endif
> diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
> index db0ee918b08a..b91b1a98029c 100644
> --- a/mm/pgtable-generic.c
> +++ b/mm/pgtable-generic.c
> @@ -124,10 +124,11 @@ int pmdp_set_access_flags(struct vm_area_struct *vma,
> #endif
>
> #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
> -int pmdp_clear_flush_young(struct vm_area_struct *vma,
> - unsigned long address, pmd_t *pmdp)
> +bool pmdp_clear_flush_young(struct vm_area_struct *vma,
> + unsigned long address, pmd_t *pmdp)
> {
> - int young;
> + bool young;
> +
> VM_BUG_ON(address & ~HPAGE_PMD_MASK);
> young = pmdp_test_and_clear_young(vma, address, pmdp);
> if (young)
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 5/6] mm: change to return bool for pudp_test_and_clear_young()
2026-03-19 3:24 ` [PATCH 5/6] mm: change to return bool for pudp_test_and_clear_young() Baolin Wang
@ 2026-03-19 11:34 ` Lorenzo Stoakes (Oracle)
2026-03-21 5:30 ` Ritesh Harjani
1 sibling, 0 replies; 27+ messages in thread
From: Lorenzo Stoakes (Oracle) @ 2026-03-19 11:34 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On Thu, Mar 19, 2026 at 11:24:04AM +0800, Baolin Wang wrote:
> The pudp_test_and_clear_young() is used to clear the young flag,
> returning whether the young flag was set for this PUD entry. Change
> the return type to bool to make the intention clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Some nits but otherwise loogs good so:
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> ---
> arch/powerpc/include/asm/book3s/64/pgtable.h | 10 +++++-----
> arch/powerpc/mm/book3s64/pgtable.c | 4 ++--
> arch/riscv/include/asm/pgtable.h | 4 ++--
> arch/x86/include/asm/pgtable.h | 4 ++--
> arch/x86/mm/pgtable.c | 6 +++---
> 5 files changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index 0f34011665a6..083c4b9ed5b3 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -1172,13 +1172,13 @@ static inline bool __pmdp_test_and_clear_young(struct mm_struct *mm,
> return ((old & _PAGE_ACCESSED) != 0);
> }
>
> -static inline int __pudp_test_and_clear_young(struct mm_struct *mm,
> - unsigned long addr, pud_t *pudp)
> +static inline bool __pudp_test_and_clear_young(struct mm_struct *mm,
> + unsigned long addr, pud_t *pudp)
Formatting yada yada you know the drill, 2 tabs etc. :))
> {
> unsigned long old;
>
> if ((pud_raw(*pudp) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
> - return 0;
> + return false;
> old = pud_hugepage_update(mm, addr, pudp, _PAGE_ACCESSED, 0);
> return ((old & _PAGE_ACCESSED) != 0);
> }
> @@ -1303,8 +1303,8 @@ extern int pudp_set_access_flags(struct vm_area_struct *vma,
> extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long address, pmd_t *pmdp);
> #define __HAVE_ARCH_PUDP_TEST_AND_CLEAR_YOUNG
> -extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address, pud_t *pudp);
> +extern bool pudp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address, pud_t *pudp);
Drop the extern please!
>
>
> #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
> diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/pgtable.c
> index aed39bba891e..838cb4a8e2cf 100644
> --- a/arch/powerpc/mm/book3s64/pgtable.c
> +++ b/arch/powerpc/mm/book3s64/pgtable.c
> @@ -104,8 +104,8 @@ bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> return __pmdp_test_and_clear_young(vma->vm_mm, address, pmdp);
> }
>
> -int pudp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address, pud_t *pudp)
> +bool pudp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address, pud_t *pudp)
> {
> return __pudp_test_and_clear_young(vma->vm_mm, address, pudp);
> }
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index bac559d29036..88fa63186ca5 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -1109,8 +1109,8 @@ static inline int pudp_set_access_flags(struct vm_area_struct *vma,
> return ptep_set_access_flags(vma, address, (pte_t *)pudp, pud_pte(entry), dirty);
> }
>
> -static inline int pudp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long address, pud_t *pudp)
> +static inline bool pudp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long address, pud_t *pudp)
> {
> return ptep_test_and_clear_young(vma, address, (pte_t *)pudp);
> }
> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
> index f9439449c9bd..6ca1fdd25191 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -1297,8 +1297,8 @@ extern int pudp_set_access_flags(struct vm_area_struct *vma,
> #define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
> extern bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> unsigned long addr, pmd_t *pmdp);
> -extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pud_t *pudp);
> +extern bool pudp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pud_t *pudp);
Drop the extern please!
>
> #define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
> extern bool pmdp_clear_flush_young(struct vm_area_struct *vma,
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index 8c336edf0e65..2677dcf0bbce 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -470,10 +470,10 @@ bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
> #endif
>
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> -int pudp_test_and_clear_young(struct vm_area_struct *vma,
> - unsigned long addr, pud_t *pudp)
> +bool pudp_test_and_clear_young(struct vm_area_struct *vma,
> + unsigned long addr, pud_t *pudp)
> {
> - int ret = 0;
> + bool ret = false;
>
> if (pud_young(*pudp))
> ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 6/6] mm: change to return bool for the MMU notifier's young flag check
2026-03-19 3:24 ` [PATCH 6/6] mm: change to return bool for the MMU notifier's young flag check Baolin Wang
@ 2026-03-19 11:39 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:18 ` Baolin Wang
0 siblings, 1 reply; 27+ messages in thread
From: Lorenzo Stoakes (Oracle) @ 2026-03-19 11:39 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On Thu, Mar 19, 2026 at 11:24:05AM +0800, Baolin Wang wrote:
> The MMU notifier young flag check related functions only return whether
> the young flag was set. Change the return type to bool to make the
> intention clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
I can see KVM is the only user for the mmu_notifier_ops clear_flush_young,
clear_young and test_young hooks, which map to
kvm_mmu_notifier_[clear_flush,clear,test]_young() functions, and you have
updated them all.
So this LGTM with nits below, and so (with nits addressed as per the other R-b
tags :):
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Thanks for doing this! Int as bool is a pet peeve of mine :))
Cheers, Lorenzo
> ---
> include/linux/mmu_notifier.h | 76 +++++++++++++++++-------------------
> mm/internal.h | 16 ++++----
> mm/mmu_notifier.c | 20 +++++-----
> virt/kvm/kvm_main.c | 40 +++++++++----------
> 4 files changed, 72 insertions(+), 80 deletions(-)
>
> diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
> index 3705d350c863..17f2cdc77dd5 100644
> --- a/include/linux/mmu_notifier.h
> +++ b/include/linux/mmu_notifier.h
> @@ -97,20 +97,20 @@ struct mmu_notifier_ops {
> * Start-end is necessary in case the secondary MMU is mapping the page
> * at a smaller granularity than the primary MMU.
> */
> - int (*clear_flush_young)(struct mmu_notifier *subscription,
> - struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end);
> + bool (*clear_flush_young)(struct mmu_notifier *subscription,
> + struct mm_struct *mm,
> + unsigned long start,
> + unsigned long end);
>
> /*
> * clear_young is a lightweight version of clear_flush_young. Like the
> * latter, it is supposed to test-and-clear the young/accessed bitflag
> * in the secondary pte, but it may omit flushing the secondary tlb.
> */
> - int (*clear_young)(struct mmu_notifier *subscription,
> - struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end);
> + bool (*clear_young)(struct mmu_notifier *subscription,
> + struct mm_struct *mm,
> + unsigned long start,
> + unsigned long end);
>
> /*
> * test_young is called to check the young/accessed bitflag in
> @@ -118,9 +118,9 @@ struct mmu_notifier_ops {
> * frequently used without actually clearing the flag or tearing
> * down the secondary mapping on the page.
> */
> - int (*test_young)(struct mmu_notifier *subscription,
> - struct mm_struct *mm,
> - unsigned long address);
> + bool (*test_young)(struct mmu_notifier *subscription,
> + struct mm_struct *mm,
> + unsigned long address);
>
> /*
> * invalidate_range_start() and invalidate_range_end() must be
> @@ -376,14 +376,12 @@ mmu_interval_check_retry(struct mmu_interval_notifier *interval_sub,
>
> extern void __mmu_notifier_subscriptions_destroy(struct mm_struct *mm);
> extern void __mmu_notifier_release(struct mm_struct *mm);
> -extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end);
> -extern int __mmu_notifier_clear_young(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end);
> -extern int __mmu_notifier_test_young(struct mm_struct *mm,
> - unsigned long address);
> +bool __mmu_notifier_clear_flush_young(struct mm_struct *mm,
> + unsigned long start, unsigned long end);
> +bool __mmu_notifier_clear_young(struct mm_struct *mm,
> + unsigned long start, unsigned long end);
> +bool __mmu_notifier_test_young(struct mm_struct *mm,
> + unsigned long address);
> extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r);
> extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r);
> extern void __mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm,
I mean damn, at this point maybe it's legit to drop the surrounding externs here
too? But maybe not :))
> @@ -403,30 +401,28 @@ static inline void mmu_notifier_release(struct mm_struct *mm)
> __mmu_notifier_release(mm);
> }
>
> -static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end)
> +static inline bool mmu_notifier_clear_flush_young(struct mm_struct *mm,
> + unsigned long start, unsigned long end)
> {
> if (mm_has_notifiers(mm))
> return __mmu_notifier_clear_flush_young(mm, start, end);
> - return 0;
> + return false;
> }
>
> -static inline int mmu_notifier_clear_young(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end)
> +static inline bool mmu_notifier_clear_young(struct mm_struct *mm,
> + unsigned long start, unsigned long end)
> {
> if (mm_has_notifiers(mm))
> return __mmu_notifier_clear_young(mm, start, end);
> - return 0;
> + return false;
> }
>
> -static inline int mmu_notifier_test_young(struct mm_struct *mm,
> - unsigned long address)
> +static inline bool mmu_notifier_test_young(struct mm_struct *mm,
> + unsigned long address)
> {
> if (mm_has_notifiers(mm))
> return __mmu_notifier_test_young(mm, address);
> - return 0;
> + return false;
> }
>
> static inline void
> @@ -552,24 +548,22 @@ static inline void mmu_notifier_release(struct mm_struct *mm)
> {
> }
>
> -static inline int mmu_notifier_clear_flush_young(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end)
> +static inline bool mmu_notifier_clear_flush_young(struct mm_struct *mm,
> + unsigned long start, unsigned long end)
> {
> - return 0;
> + return false;
> }
>
> -static inline int mmu_notifier_clear_young(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end)
> +static inline bool mmu_notifier_clear_young(struct mm_struct *mm,
> + unsigned long start, unsigned long end)
> {
> - return 0;
> + return false;
> }
>
> -static inline int mmu_notifier_test_young(struct mm_struct *mm,
> - unsigned long address)
> +static inline bool mmu_notifier_test_young(struct mm_struct *mm,
> + unsigned long address)
> {
> - return 0;
> + return false;
> }
>
> static inline void
> diff --git a/mm/internal.h b/mm/internal.h
> index 0eaca2f0eb6a..3d6eba216364 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -1831,10 +1831,10 @@ static inline int io_remap_pfn_range_complete(struct vm_area_struct *vma,
> }
>
> #ifdef CONFIG_MMU_NOTIFIER
> -static inline int clear_flush_young_ptes_notify(struct vm_area_struct *vma,
> +static inline bool clear_flush_young_ptes_notify(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep, unsigned int nr)
> {
> - int young;
> + bool young;
>
> young = clear_flush_young_ptes(vma, addr, ptep, nr);
> young |= mmu_notifier_clear_flush_young(vma->vm_mm, addr,
> @@ -1842,30 +1842,30 @@ static inline int clear_flush_young_ptes_notify(struct vm_area_struct *vma,
> return young;
> }
>
> -static inline int pmdp_clear_flush_young_notify(struct vm_area_struct *vma,
> +static inline bool pmdp_clear_flush_young_notify(struct vm_area_struct *vma,
> unsigned long addr, pmd_t *pmdp)
> {
> - int young;
> + bool young;
>
> young = pmdp_clear_flush_young(vma, addr, pmdp);
> young |= mmu_notifier_clear_flush_young(vma->vm_mm, addr, addr + PMD_SIZE);
> return young;
> }
>
> -static inline int test_and_clear_young_ptes_notify(struct vm_area_struct *vma,
> +static inline bool test_and_clear_young_ptes_notify(struct vm_area_struct *vma,
> unsigned long addr, pte_t *ptep, unsigned int nr)
> {
> - int young;
> + bool young;
>
> young = test_and_clear_young_ptes(vma, addr, ptep, nr);
> young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + nr * PAGE_SIZE);
> return young;
> }
>
> -static inline int pmdp_test_and_clear_young_notify(struct vm_area_struct *vma,
> +static inline bool pmdp_test_and_clear_young_notify(struct vm_area_struct *vma,
> unsigned long addr, pmd_t *pmdp)
> {
> - int young;
> + bool young;
>
> young = pmdp_test_and_clear_young(vma, addr, pmdp);
> young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + PMD_SIZE);
> diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
> index 2502474b83b6..3e3e7e727ba2 100644
> --- a/mm/mmu_notifier.c
> +++ b/mm/mmu_notifier.c
> @@ -364,12 +364,11 @@ void __mmu_notifier_release(struct mm_struct *mm)
> * unmap the address and return 1 or 0 depending if the mapping previously
> * existed or not.
> */
> -int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end)
> +bool __mmu_notifier_clear_flush_young(struct mm_struct *mm,
> + unsigned long start, unsigned long end)
> {
> struct mmu_notifier *subscription;
> - int young = 0, id;
> + bool young = false, id;
>
> id = srcu_read_lock(&srcu);
> hlist_for_each_entry_srcu(subscription,
> @@ -384,12 +383,11 @@ int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
> return young;
> }
>
> -int __mmu_notifier_clear_young(struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end)
> +bool __mmu_notifier_clear_young(struct mm_struct *mm,
> + unsigned long start, unsigned long end)
> {
> struct mmu_notifier *subscription;
> - int young = 0, id;
> + bool young = false, id;
>
> id = srcu_read_lock(&srcu);
> hlist_for_each_entry_srcu(subscription,
> @@ -404,11 +402,11 @@ int __mmu_notifier_clear_young(struct mm_struct *mm,
> return young;
> }
>
> -int __mmu_notifier_test_young(struct mm_struct *mm,
> - unsigned long address)
> +bool __mmu_notifier_test_young(struct mm_struct *mm,
> + unsigned long address)
> {
> struct mmu_notifier *subscription;
> - int young = 0, id;
> + bool young = false, id;
>
> id = srcu_read_lock(&srcu);
> hlist_for_each_entry_srcu(subscription,
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index d0ab29672c71..6bcfc1b3021d 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -646,11 +646,11 @@ static __always_inline kvm_mn_ret_t kvm_handle_hva_range(struct kvm *kvm,
> return r;
> }
>
> -static __always_inline int kvm_age_hva_range(struct mmu_notifier *mn,
> - unsigned long start,
> - unsigned long end,
> - gfn_handler_t handler,
> - bool flush_on_ret)
> +static __always_inline bool kvm_age_hva_range(struct mmu_notifier *mn,
> + unsigned long start,
> + unsigned long end,
> + gfn_handler_t handler,
> + bool flush_on_ret)
Can we please fix this terrrible indentation while we're here :)?
static __always_inline bool kvm_age_hva_range(struct mmu_notifier *mn,
unsigned long start, unsigned long end, gfn_handler_t handler,
bool flush_on_ret)
Would be nicer, thanks!
> {
> struct kvm *kvm = mmu_notifier_to_kvm(mn);
> const struct kvm_mmu_notifier_range range = {
> @@ -666,10 +666,10 @@ static __always_inline int kvm_age_hva_range(struct mmu_notifier *mn,
> return kvm_handle_hva_range(kvm, &range).ret;
> }
>
> -static __always_inline int kvm_age_hva_range_no_flush(struct mmu_notifier *mn,
> - unsigned long start,
> - unsigned long end,
> - gfn_handler_t handler)
> +static __always_inline bool kvm_age_hva_range_no_flush(struct mmu_notifier *mn,
> + unsigned long start,
> + unsigned long end,
> + gfn_handler_t handler)
Same indentation comment here.
> {
> return kvm_age_hva_range(mn, start, end, handler, false);
> }
> @@ -829,10 +829,10 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn,
> rcuwait_wake_up(&kvm->mn_memslots_update_rcuwait);
> }
>
> -static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
> - struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end)
> +static bool kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
> + struct mm_struct *mm,
> + unsigned long start,
> + unsigned long end)
Same indentation comment here.
> {
> trace_kvm_age_hva(start, end);
>
> @@ -840,10 +840,10 @@ static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
> !IS_ENABLED(CONFIG_KVM_ELIDE_TLB_FLUSH_IF_YOUNG));
> }
>
> -static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn,
> - struct mm_struct *mm,
> - unsigned long start,
> - unsigned long end)
> +static bool kvm_mmu_notifier_clear_young(struct mmu_notifier *mn,
> + struct mm_struct *mm,
> + unsigned long start,
> + unsigned long end)
Same indentation comment here.
> {
> trace_kvm_age_hva(start, end);
>
> @@ -863,9 +863,9 @@ static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn,
> return kvm_age_hva_range_no_flush(mn, start, end, kvm_age_gfn);
> }
>
> -static int kvm_mmu_notifier_test_young(struct mmu_notifier *mn,
> - struct mm_struct *mm,
> - unsigned long address)
> +static bool kvm_mmu_notifier_test_young(struct mmu_notifier *mn,
> + struct mm_struct *mm,
> + unsigned long address)
Same indentation comment here.
> {
> trace_kvm_test_age_hva(address);
>
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young()
2026-03-19 11:28 ` Lorenzo Stoakes (Oracle)
@ 2026-03-20 2:59 ` Baolin Wang
0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-20 2:59 UTC (permalink / raw)
To: Lorenzo Stoakes (Oracle)
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On 3/19/26 7:28 PM, Lorenzo Stoakes (Oracle) wrote:
> On Thu, Mar 19, 2026 at 11:24:00AM +0800, Baolin Wang wrote:
>> Callers use ptep_test_and_clear_young() to clear the young flag and check
>> whether it was set. Change the return type to bool to make the intention
>> clearer.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>
> Couple nits about dropping externs below but otherwise LGTM, so:
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Thanks for reviewing.
>> ---
>> arch/arm64/include/asm/pgtable.h | 8 ++++----
>> arch/arm64/mm/contpte.c | 4 ++--
>> arch/microblaze/include/asm/pgtable.h | 2 +-
>> arch/parisc/include/asm/pgtable.h | 6 +++---
>> arch/powerpc/include/asm/book3s/32/pgtable.h | 4 ++--
>> arch/powerpc/include/asm/book3s/64/pgtable.h | 6 +++---
>> arch/powerpc/include/asm/nohash/pgtable.h | 4 ++--
>> arch/riscv/include/asm/pgtable.h | 4 ++--
>> arch/riscv/mm/pgtable.c | 8 ++++----
>> arch/s390/include/asm/pgtable.h | 4 ++--
>> arch/x86/include/asm/pgtable.h | 4 ++--
>> arch/x86/mm/pgtable.c | 6 +++---
>> arch/xtensa/include/asm/pgtable.h | 6 +++---
>> include/linux/pgtable.h | 16 ++++++++--------
>> 14 files changed, 41 insertions(+), 41 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
>> index ab451d20e4c5..8c651695204c 100644
>> --- a/arch/arm64/include/asm/pgtable.h
>> +++ b/arch/arm64/include/asm/pgtable.h
>> @@ -1282,7 +1282,7 @@ static inline void __pte_clear(struct mm_struct *mm,
>> __set_pte(ptep, __pte(0));
>> }
>>
>> -static inline int __ptep_test_and_clear_young(struct vm_area_struct *vma,
>> +static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
>> unsigned long address,
>> pte_t *ptep)
>> {
>> @@ -1646,7 +1646,7 @@ extern void contpte_clear_full_ptes(struct mm_struct *mm, unsigned long addr,
>> extern pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm,
>> unsigned long addr, pte_t *ptep,
>> unsigned int nr, int full);
>> -int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
>> +bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
>> unsigned long addr, pte_t *ptep, unsigned int nr);
>> int contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
>> unsigned long addr, pte_t *ptep, unsigned int nr);
>> @@ -1813,7 +1813,7 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
>> }
>>
>> #define test_and_clear_young_ptes test_and_clear_young_ptes
>> -static inline int test_and_clear_young_ptes(struct vm_area_struct *vma,
>> +static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma,
>> unsigned long addr, pte_t *ptep,
>> unsigned int nr)
>> {
>> @@ -1824,7 +1824,7 @@ static inline int test_and_clear_young_ptes(struct vm_area_struct *vma,
>> }
>>
>> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
>> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
>> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
>> unsigned long addr, pte_t *ptep)
>> {
>> return test_and_clear_young_ptes(vma, addr, ptep, 1);
>> diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c
>> index 1519d090d5ea..0b88278927a4 100644
>> --- a/arch/arm64/mm/contpte.c
>> +++ b/arch/arm64/mm/contpte.c
>> @@ -508,7 +508,7 @@ pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm,
>> }
>> EXPORT_SYMBOL_GPL(contpte_get_and_clear_full_ptes);
>>
>> -int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
>> +bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
>> unsigned long addr, pte_t *ptep,
>> unsigned int nr)
>> {
>> @@ -525,7 +525,7 @@ int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
>> */
>>
>> unsigned long end = addr + nr * PAGE_SIZE;
>> - int young = 0;
>> + bool young = false;
>>
>> ptep = contpte_align_addr_ptep(&addr, &end, ptep, nr);
>> for (; addr != end; ptep++, addr += PAGE_SIZE)
>> diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h
>> index ea72291de553..7678c040a2fd 100644
>> --- a/arch/microblaze/include/asm/pgtable.h
>> +++ b/arch/microblaze/include/asm/pgtable.h
>> @@ -318,7 +318,7 @@ static inline void set_pte(pte_t *ptep, pte_t pte)
>>
>> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
>> struct vm_area_struct;
>> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
>> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
>> unsigned long address, pte_t *ptep)
>> {
>> return (pte_update(ptep, _PAGE_ACCESSED, 0) & _PAGE_ACCESSED) != 0;
>> diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
>> index f6fb99cb94d9..d5e39f2eb415 100644
>> --- a/arch/parisc/include/asm/pgtable.h
>> +++ b/arch/parisc/include/asm/pgtable.h
>> @@ -438,16 +438,16 @@ static inline pte_t ptep_get(pte_t *ptep)
>> }
>> #define ptep_get ptep_get
>>
>> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
>> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
>> {
>> pte_t pte;
>>
>> pte = ptep_get(ptep);
>> if (!pte_young(pte)) {
>> - return 0;
>> + return false;
>> }
>> set_pte_at(vma->vm_mm, addr, ptep, pte_mkold(pte));
>> - return 1;
>> + return true;
>> }
>>
>> int ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
>> diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h
>> index 001e28f9eabc..2a889e2093e8 100644
>> --- a/arch/powerpc/include/asm/book3s/32/pgtable.h
>> +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
>> @@ -295,8 +295,8 @@ static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, p
>> * for our hash-based implementation, we fix that up here.
>> */
>> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
>> -static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
>> - unsigned long addr, pte_t *ptep)
>> +static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
>> + unsigned long addr, pte_t *ptep)
>> {
>> unsigned long old;
>> old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
>> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
>> index 1a91762b455d..25e3a86943e2 100644
>> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
>> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
>> @@ -349,13 +349,13 @@ static inline unsigned long pte_update(struct mm_struct *mm, unsigned long addr,
>> * For radix: H_PAGE_HASHPTE should be zero. Hence we can use the same
>> * function for both hash and radix.
>> */
>> -static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
>> - unsigned long addr, pte_t *ptep)
>> +static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
>> + unsigned long addr, pte_t *ptep)
>> {
>> unsigned long old;
>>
>> if ((pte_raw(*ptep) & cpu_to_be64(_PAGE_ACCESSED | H_PAGE_HASHPTE)) == 0)
>> - return 0;
>> + return false;
>> old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
>> return (old & _PAGE_ACCESSED) != 0;
>> }
>> diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/include/asm/nohash/pgtable.h
>> index e6da5eaccff6..43cf52f0c7d6 100644
>> --- a/arch/powerpc/include/asm/nohash/pgtable.h
>> +++ b/arch/powerpc/include/asm/nohash/pgtable.h
>> @@ -101,8 +101,8 @@ static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, p
>> }
>> #endif
>>
>> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
>> - unsigned long addr, pte_t *ptep)
>> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
>> + unsigned long addr, pte_t *ptep)
>> {
>> unsigned long old;
>>
>> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
>> index ab4ce1cc9d9c..fb010dcdf343 100644
>> --- a/arch/riscv/include/asm/pgtable.h
>> +++ b/arch/riscv/include/asm/pgtable.h
>> @@ -659,8 +659,8 @@ static inline void pte_clear(struct mm_struct *mm,
>> extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
>> pte_t *ptep, pte_t entry, int dirty);
>> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG /* defined in mm/pgtable.c */
>> -extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address,
>> - pte_t *ptep);
>> +extern bool ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address,
>> + pte_t *ptep);
>
> Let's drop the extern.
Yes, I followed the original code style, but dropping the extern looks
reasonable to me. Will do.
>> #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
>> static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
>> diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c
>> index b1ed2f14dc3a..de24a19e8ebd 100644
>> --- a/arch/riscv/mm/pgtable.c
>> +++ b/arch/riscv/mm/pgtable.c
>> @@ -29,12 +29,12 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
>> return true;
>> }
>>
>> -int ptep_test_and_clear_young(struct vm_area_struct *vma,
>> - unsigned long address,
>> - pte_t *ptep)
>> +bool ptep_test_and_clear_young(struct vm_area_struct *vma,
>> + unsigned long address,
>> + pte_t *ptep)
>> {
>> if (!pte_young(ptep_get(ptep)))
>> - return 0;
>> + return false;
>> return test_and_clear_bit(_PAGE_ACCESSED_OFFSET, &pte_val(*ptep));
>> }
>> EXPORT_SYMBOL_GPL(ptep_test_and_clear_young);
>> diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
>> index 1c3c3be93be9..da1a7a31fa22 100644
>> --- a/arch/s390/include/asm/pgtable.h
>> +++ b/arch/s390/include/asm/pgtable.h
>> @@ -1164,8 +1164,8 @@ pte_t ptep_xchg_direct(struct mm_struct *, unsigned long, pte_t *, pte_t);
>> pte_t ptep_xchg_lazy(struct mm_struct *, unsigned long, pte_t *, pte_t);
>>
>> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
>> -static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
>> - unsigned long addr, pte_t *ptep)
>> +static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
>> + unsigned long addr, pte_t *ptep)
>> {
>> pte_t pte = *ptep;
>>
>> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
>> index 54289f4587a4..563a6289ea44 100644
>> --- a/arch/x86/include/asm/pgtable.h
>> +++ b/arch/x86/include/asm/pgtable.h
>> @@ -1232,8 +1232,8 @@ extern int ptep_set_access_flags(struct vm_area_struct *vma,
>> pte_t entry, int dirty);
>>
>> #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
>> -extern int ptep_test_and_clear_young(struct vm_area_struct *vma,
>> - unsigned long addr, pte_t *ptep);
>> +extern bool ptep_test_and_clear_young(struct vm_area_struct *vma,
>> + unsigned long addr, pte_t *ptep);
>
> Let's drop the extern.
Ack.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes()
2026-03-19 11:30 ` Lorenzo Stoakes (Oracle)
@ 2026-03-20 3:05 ` Baolin Wang
0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-20 3:05 UTC (permalink / raw)
To: Lorenzo Stoakes (Oracle)
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On 3/19/26 7:30 PM, Lorenzo Stoakes (Oracle) wrote:
> On Thu, Mar 19, 2026 at 11:24:01AM +0800, Baolin Wang wrote:
>> The ptep_clear_flush_young() and clear_flush_young_ptes() are used to clear
>> the young flag and flush the TLB, returning whether the young flag was set.
>> Change the return type to bool to make the intention clearer.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>
> Couple nits but LGTM, so:
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Thanks.
>> ---
>> arch/arm64/include/asm/pgtable.h | 15 +++++++--------
>> arch/arm64/mm/contpte.c | 4 ++--
>> arch/parisc/include/asm/pgtable.h | 2 +-
>> arch/parisc/kernel/cache.c | 8 ++++----
>> arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
>> arch/riscv/include/asm/pgtable.h | 4 ++--
>> arch/s390/include/asm/pgtable.h | 4 ++--
>> arch/x86/include/asm/pgtable.h | 4 ++--
>> arch/x86/mm/pgtable.c | 4 ++--
>> include/linux/pgtable.h | 8 ++++----
>> mm/pgtable-generic.c | 7 ++++---
>> 11 files changed, 31 insertions(+), 31 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
>> index 8c651695204c..393a9d1873f6 100644
>> --- a/arch/arm64/include/asm/pgtable.h
>> +++ b/arch/arm64/include/asm/pgtable.h
>> @@ -1299,10 +1299,10 @@ static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
>> return pte_young(pte);
>> }
>>
>> -static inline int __ptep_clear_flush_young(struct vm_area_struct *vma,
>> - unsigned long address, pte_t *ptep)
>> +static inline bool __ptep_clear_flush_young(struct vm_area_struct *vma,
>> + unsigned long address, pte_t *ptep)
>
> I mean this is subjective stuff but can we just put 2nd line 2 tabs indented
> underneath? Makes it easier for changes like this to not propagate.
>
> Same comment for all of these!
I usually use 2 tabs for indentation in the mm subsystem, but for other
subsystems, I try to follow the existing style since I'm unsure of other
maintainers' preferences:)
Anyway, I can do this if no other objections.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young()
2026-03-19 11:31 ` Lorenzo Stoakes (Oracle)
@ 2026-03-20 3:07 ` Baolin Wang
0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-20 3:07 UTC (permalink / raw)
To: Lorenzo Stoakes (Oracle)
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On 3/19/26 7:31 PM, Lorenzo Stoakes (Oracle) wrote:
> On Thu, Mar 19, 2026 at 11:24:02AM +0800, Baolin Wang wrote:
>> Callers use pmdp_test_and_clear_young() to clear the young flag and check
>> whether it was set for this PMD entry. Change the return type to bool to
>> make the intention clearer.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>
> Some nits similar to before, otherwise LGTM so:
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Thanks. And all comments acked.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 4/6] mm: change to return bool for pmdp_clear_flush_young()
2026-03-19 11:33 ` Lorenzo Stoakes (Oracle)
@ 2026-03-20 3:09 ` Baolin Wang
0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-20 3:09 UTC (permalink / raw)
To: Lorenzo Stoakes (Oracle)
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On 3/19/26 7:33 PM, Lorenzo Stoakes (Oracle) wrote:
> On Thu, Mar 19, 2026 at 11:24:03AM +0800, Baolin Wang wrote:
>> The pmdp_clear_flush_young() is used to clear the young flag and flush the
>> TLB, returning whether the young flag was set for this PMD entry. Change
>> the return type to bool to make the intention clearer.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>
> Some nits, but otherwise LGTM, so:
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
>
>> ---
>> arch/s390/include/asm/pgtable.h | 4 ++--
>> arch/x86/include/asm/pgtable.h | 4 ++--
>> arch/x86/mm/pgtable.c | 6 +++---
>> include/linux/pgtable.h | 10 +++++-----
>> mm/pgtable-generic.c | 7 ++++---
>> 5 files changed, 16 insertions(+), 15 deletions(-)
>>
>> diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
>> index 1f5efb7be71d..90bba85ca4b8 100644
>> --- a/arch/s390/include/asm/pgtable.h
>> +++ b/arch/s390/include/asm/pgtable.h
>> @@ -1693,8 +1693,8 @@ static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
>> }
>>
>> #define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
>> -static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
>> - unsigned long addr, pmd_t *pmdp)
>> +static inline bool pmdp_clear_flush_young(struct vm_area_struct *vma,
>> + unsigned long addr, pmd_t *pmdp)
>
> Same indentation comment as with other patches, 2 tabs you know the drill :)
> applies to all such in this patch.
>
>> {
>> VM_BUG_ON(addr & ~HPAGE_MASK);
>> return pmdp_test_and_clear_young(vma, addr, pmdp);
>> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
>> index bd02ee730a23..f9439449c9bd 100644
>> --- a/arch/x86/include/asm/pgtable.h
>> +++ b/arch/x86/include/asm/pgtable.h
>> @@ -1301,8 +1301,8 @@ extern int pudp_test_and_clear_young(struct vm_area_struct *vma,
>> unsigned long addr, pud_t *pudp);
>>
>> #define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
>> -extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
>> - unsigned long address, pmd_t *pmdp);
>> +extern bool pmdp_clear_flush_young(struct vm_area_struct *vma,
>> + unsigned long address, pmd_t *pmdp);
>
> Drop the extern please!
Ack.
>> #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
>> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
>> index 10a5e0b2be36..8c336edf0e65 100644
>> --- a/arch/x86/mm/pgtable.c
>> +++ b/arch/x86/mm/pgtable.c
>> @@ -503,10 +503,10 @@ bool ptep_clear_flush_young(struct vm_area_struct *vma,
>> }
>>
>> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>> -int pmdp_clear_flush_young(struct vm_area_struct *vma,
>> - unsigned long address, pmd_t *pmdp)
>> +bool pmdp_clear_flush_young(struct vm_area_struct *vma,
>> + unsigned long address, pmd_t *pmdp)
>> {
>> - int young;
>> + bool young;
>>
>> VM_BUG_ON(address & ~HPAGE_PMD_MASK);
>>
>> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
>> index e53220b0a9a3..8b8838f19af3 100644
>> --- a/include/linux/pgtable.h
>> +++ b/include/linux/pgtable.h
>> @@ -536,18 +536,18 @@ bool ptep_clear_flush_young(struct vm_area_struct *vma,
>>
>> #ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
>> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>> -extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
>> - unsigned long address, pmd_t *pmdp);
>> +bool pmdp_clear_flush_young(struct vm_area_struct *vma,
>> + unsigned long address, pmd_t *pmdp);
>
> Ahh! Here you drop the extern :) AND use 2 tabs :)) thanks!
Right. Because this is the mm subsystem, and I know the maintainers'
preferences:)
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 6/6] mm: change to return bool for the MMU notifier's young flag check
2026-03-19 11:39 ` Lorenzo Stoakes (Oracle)
@ 2026-03-20 3:18 ` Baolin Wang
0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-20 3:18 UTC (permalink / raw)
To: Lorenzo Stoakes (Oracle)
Cc: akpm, david, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On 3/19/26 7:39 PM, Lorenzo Stoakes (Oracle) wrote:
> On Thu, Mar 19, 2026 at 11:24:05AM +0800, Baolin Wang wrote:
>> The MMU notifier young flag check related functions only return whether
>> the young flag was set. Change the return type to bool to make the
>> intention clearer.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>
> I can see KVM is the only user for the mmu_notifier_ops clear_flush_young,
> clear_young and test_young hooks, which map to
> kvm_mmu_notifier_[clear_flush,clear,test]_young() functions, and you have
> updated them all.
Yes.
> So this LGTM with nits below, and so (with nits addressed as per the other R-b
> tags :):
>
> Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
>
> Thanks for doing this! Int as bool is a pet peeve of mine :))
Thanks for reviewing.
>> include/linux/mmu_notifier.h | 76 +++++++++++++++++-------------------
>> mm/internal.h | 16 ++++----
>> mm/mmu_notifier.c | 20 +++++-----
>> virt/kvm/kvm_main.c | 40 +++++++++----------
>> 4 files changed, 72 insertions(+), 80 deletions(-)
>>
>> diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
>> index 3705d350c863..17f2cdc77dd5 100644
>> --- a/include/linux/mmu_notifier.h
>> +++ b/include/linux/mmu_notifier.h
>> @@ -97,20 +97,20 @@ struct mmu_notifier_ops {
>> * Start-end is necessary in case the secondary MMU is mapping the page
>> * at a smaller granularity than the primary MMU.
>> */
>> - int (*clear_flush_young)(struct mmu_notifier *subscription,
>> - struct mm_struct *mm,
>> - unsigned long start,
>> - unsigned long end);
>> + bool (*clear_flush_young)(struct mmu_notifier *subscription,
>> + struct mm_struct *mm,
>> + unsigned long start,
>> + unsigned long end);
>>
>> /*
>> * clear_young is a lightweight version of clear_flush_young. Like the
>> * latter, it is supposed to test-and-clear the young/accessed bitflag
>> * in the secondary pte, but it may omit flushing the secondary tlb.
>> */
>> - int (*clear_young)(struct mmu_notifier *subscription,
>> - struct mm_struct *mm,
>> - unsigned long start,
>> - unsigned long end);
>> + bool (*clear_young)(struct mmu_notifier *subscription,
>> + struct mm_struct *mm,
>> + unsigned long start,
>> + unsigned long end);
>>
>> /*
>> * test_young is called to check the young/accessed bitflag in
>> @@ -118,9 +118,9 @@ struct mmu_notifier_ops {
>> * frequently used without actually clearing the flag or tearing
>> * down the secondary mapping on the page.
>> */
>> - int (*test_young)(struct mmu_notifier *subscription,
>> - struct mm_struct *mm,
>> - unsigned long address);
>> + bool (*test_young)(struct mmu_notifier *subscription,
>> + struct mm_struct *mm,
>> + unsigned long address);
>>
>> /*
>> * invalidate_range_start() and invalidate_range_end() must be
>> @@ -376,14 +376,12 @@ mmu_interval_check_retry(struct mmu_interval_notifier *interval_sub,
>>
>> extern void __mmu_notifier_subscriptions_destroy(struct mm_struct *mm);
>> extern void __mmu_notifier_release(struct mm_struct *mm);
>> -extern int __mmu_notifier_clear_flush_young(struct mm_struct *mm,
>> - unsigned long start,
>> - unsigned long end);
>> -extern int __mmu_notifier_clear_young(struct mm_struct *mm,
>> - unsigned long start,
>> - unsigned long end);
>> -extern int __mmu_notifier_test_young(struct mm_struct *mm,
>> - unsigned long address);
>> +bool __mmu_notifier_clear_flush_young(struct mm_struct *mm,
>> + unsigned long start, unsigned long end);
>> +bool __mmu_notifier_clear_young(struct mm_struct *mm,
>> + unsigned long start, unsigned long end);
>> +bool __mmu_notifier_test_young(struct mm_struct *mm,
>> + unsigned long address);
>> extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r);
>> extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r);
>> extern void __mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm,
>
> I mean damn, at this point maybe it's legit to drop the surrounding externs here
> too? But maybe not :))
I prefer to leave the others as is:)
[snip]
>>
>> -static __always_inline int kvm_age_hva_range(struct mmu_notifier *mn,
>> - unsigned long start,
>> - unsigned long end,
>> - gfn_handler_t handler,
>> - bool flush_on_ret)
>> +static __always_inline bool kvm_age_hva_range(struct mmu_notifier *mn,
>> + unsigned long start,
>> + unsigned long end,
>> + gfn_handler_t handler,
>> + bool flush_on_ret)
>
> Can we please fix this terrrible indentation while we're here :)?
>
> static __always_inline bool kvm_age_hva_range(struct mmu_notifier *mn,
> unsigned long start, unsigned long end, gfn_handler_t handler,
> bool flush_on_ret)
>
> Would be nicer, thanks!
Will do if KVM maintainers are also happy with this.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 0/6] change young flag check functions to return bool
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
` (5 preceding siblings ...)
2026-03-19 3:24 ` [PATCH 6/6] mm: change to return bool for the MMU notifier's young flag check Baolin Wang
@ 2026-03-20 3:18 ` Andrew Morton
2026-03-20 3:21 ` Baolin Wang
2026-03-21 5:31 ` Ritesh Harjani
7 siblings, 1 reply; 27+ messages in thread
From: Andrew Morton @ 2026-03-20 3:18 UTC (permalink / raw)
To: Baolin Wang
Cc: david, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On Thu, 19 Mar 2026 11:23:59 +0800 Baolin Wang <baolin.wang@linux.alibaba.com> wrote:
> This is a cleanup patchset to change all young flag check functions to
> return bool, as discussed with David in the previous thread[1]. Since
> callers only care about whether the young flag was set, returning bool
> makes the intention clearer. No functional changes intended.
One observation from Sashiko. Minorish, worth addressing:
https://sashiko.dev/#/patchset/cover.1773890510.git.baolin.wang%40linux.alibaba.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 0/6] change young flag check functions to return bool
2026-03-20 3:18 ` [PATCH 0/6] change young flag check functions to return bool Andrew Morton
@ 2026-03-20 3:21 ` Baolin Wang
0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-20 3:21 UTC (permalink / raw)
To: Andrew Morton
Cc: david, ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
On 3/20/26 11:18 AM, Andrew Morton wrote:
> On Thu, 19 Mar 2026 11:23:59 +0800 Baolin Wang <baolin.wang@linux.alibaba.com> wrote:
>
>> This is a cleanup patchset to change all young flag check functions to
>> return bool, as discussed with David in the previous thread[1]. Since
>> callers only care about whether the young flag was set, returning bool
>> makes the intention clearer. No functional changes intended.
>
> One observation from Sashiko. Minorish, worth addressing:
> https://sashiko.dev/#/patchset/cover.1773890510.git.baolin.wang%40linux.alibaba.com
Yes, good catch. Will fix in next version. Thanks.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young()
2026-03-19 3:24 ` [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young() Baolin Wang
2026-03-19 11:28 ` Lorenzo Stoakes (Oracle)
@ 2026-03-20 5:57 ` Ritesh Harjani
2026-03-21 5:22 ` Baolin Wang
1 sibling, 1 reply; 27+ messages in thread
From: Ritesh Harjani @ 2026-03-20 5:57 UTC (permalink / raw)
To: Baolin Wang, akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
Baolin Wang <baolin.wang@linux.alibaba.com> writes:
> Callers use ptep_test_and_clear_young() to clear the young flag and check
> whether it was set. Change the return type to bool to make the intention
> clearer.
>
Right I checked all callers of ptep_test_and_clear_young(). I agree, we
only need bool here.
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> arch/arm64/include/asm/pgtable.h | 8 ++++----
> arch/arm64/mm/contpte.c | 4 ++--
> arch/microblaze/include/asm/pgtable.h | 2 +-
> arch/parisc/include/asm/pgtable.h | 6 +++---
> arch/powerpc/include/asm/book3s/32/pgtable.h | 4 ++--
> arch/powerpc/include/asm/book3s/64/pgtable.h | 6 +++---
> arch/powerpc/include/asm/nohash/pgtable.h | 4 ++--
I looked at it because of powerpc changes, but ended up looking into all
call sites anyways. So overall it LGTM (and I agree that we can remove
the unnecessary externs from function declarations)
With that please feel free to add:
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes()
2026-03-19 3:24 ` [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes() Baolin Wang
2026-03-19 11:30 ` Lorenzo Stoakes (Oracle)
@ 2026-03-21 5:18 ` Ritesh Harjani
1 sibling, 0 replies; 27+ messages in thread
From: Ritesh Harjani @ 2026-03-21 5:18 UTC (permalink / raw)
To: Baolin Wang, akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
Baolin Wang <baolin.wang@linux.alibaba.com> writes:
> The ptep_clear_flush_young() and clear_flush_young_ptes() are used to clear
> the young flag and flush the TLB, returning whether the young flag was set.
> Change the return type to bool to make the intention clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> arch/arm64/include/asm/pgtable.h | 15 +++++++--------
> arch/arm64/mm/contpte.c | 4 ++--
> arch/parisc/include/asm/pgtable.h | 2 +-
> arch/parisc/kernel/cache.c | 8 ++++----
> arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
> arch/riscv/include/asm/pgtable.h | 4 ++--
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/x86/include/asm/pgtable.h | 4 ++--
> arch/x86/mm/pgtable.c | 4 ++--
> include/linux/pgtable.h | 8 ++++----
> mm/pgtable-generic.c | 7 ++++---
> 11 files changed, 31 insertions(+), 31 deletions(-)
LGTM. Please feel free to add:
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young()
2026-03-20 5:57 ` Ritesh Harjani
@ 2026-03-21 5:22 ` Baolin Wang
0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-21 5:22 UTC (permalink / raw)
To: Ritesh Harjani (IBM), akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, linux-arm-kernel,
x86, linux-parisc, linuxppc-dev, linux-riscv, linux-s390, kvm,
open, linux-kernel
On 3/20/26 1:57 PM, Ritesh Harjani (IBM) wrote:
> Baolin Wang <baolin.wang@linux.alibaba.com> writes:
>
>> Callers use ptep_test_and_clear_young() to clear the young flag and check
>> whether it was set. Change the return type to bool to make the intention
>> clearer.
>>
>
> Right I checked all callers of ptep_test_and_clear_young(). I agree, we
> only need bool here.
>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> ---
>> arch/arm64/include/asm/pgtable.h | 8 ++++----
>> arch/arm64/mm/contpte.c | 4 ++--
>> arch/microblaze/include/asm/pgtable.h | 2 +-
>> arch/parisc/include/asm/pgtable.h | 6 +++---
>> arch/powerpc/include/asm/book3s/32/pgtable.h | 4 ++--
>> arch/powerpc/include/asm/book3s/64/pgtable.h | 6 +++---
>> arch/powerpc/include/asm/nohash/pgtable.h | 4 ++--
>
> I looked at it because of powerpc changes, but ended up looking into all
> call sites anyways. So overall it LGTM (and I agree that we can remove
> the unnecessary externs from function declarations)
>
> With that please feel free to add:
> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Thanks for reviewing. Will remove externs:)
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young()
2026-03-19 3:24 ` [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young() Baolin Wang
2026-03-19 11:31 ` Lorenzo Stoakes (Oracle)
@ 2026-03-21 5:24 ` Ritesh Harjani
1 sibling, 0 replies; 27+ messages in thread
From: Ritesh Harjani @ 2026-03-21 5:24 UTC (permalink / raw)
To: Baolin Wang, akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
Baolin Wang <baolin.wang@linux.alibaba.com> writes:
> Callers use pmdp_test_and_clear_young() to clear the young flag and check
> whether it was set for this PMD entry. Change the return type to bool to
> make the intention clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> arch/arm64/include/asm/pgtable.h | 6 +++---
> arch/powerpc/include/asm/book3s/64/pgtable.h | 10 +++++-----
> arch/powerpc/mm/book3s64/pgtable.c | 4 ++--
> arch/riscv/include/asm/pgtable.h | 2 +-
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/x86/include/asm/pgtable.h | 4 ++--
> arch/x86/mm/pgtable.c | 6 +++---
> include/linux/pgtable.h | 19 +++++++++----------
> 8 files changed, 27 insertions(+), 28 deletions(-)
>
LGTM. Please feel free to add:
(assuming you will anyway kill the unwanted externs)
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 5/6] mm: change to return bool for pudp_test_and_clear_young()
2026-03-19 3:24 ` [PATCH 5/6] mm: change to return bool for pudp_test_and_clear_young() Baolin Wang
2026-03-19 11:34 ` Lorenzo Stoakes (Oracle)
@ 2026-03-21 5:30 ` Ritesh Harjani
1 sibling, 0 replies; 27+ messages in thread
From: Ritesh Harjani @ 2026-03-21 5:30 UTC (permalink / raw)
To: Baolin Wang, akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
Baolin Wang <baolin.wang@linux.alibaba.com> writes:
> The pudp_test_and_clear_young() is used to clear the young flag,
> returning whether the young flag was set for this PUD entry. Change
> the return type to bool to make the intention clearer.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> arch/powerpc/include/asm/book3s/64/pgtable.h | 10 +++++-----
> arch/powerpc/mm/book3s64/pgtable.c | 4 ++--
> arch/riscv/include/asm/pgtable.h | 4 ++--
> arch/x86/include/asm/pgtable.h | 4 ++--
> arch/x86/mm/pgtable.c | 6 +++---
> 5 files changed, 14 insertions(+), 14 deletions(-)
>
LGTM. Please feel free to add:
(assuming you will anyway kill the unwanted externs)
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 0/6] change young flag check functions to return bool
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
` (6 preceding siblings ...)
2026-03-20 3:18 ` [PATCH 0/6] change young flag check functions to return bool Andrew Morton
@ 2026-03-21 5:31 ` Ritesh Harjani
2026-03-21 13:02 ` Baolin Wang
7 siblings, 1 reply; 27+ messages in thread
From: Ritesh Harjani @ 2026-03-21 5:31 UTC (permalink / raw)
To: Baolin Wang, akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, baolin.wang,
linux-arm-kernel, x86, linux-parisc, linuxppc-dev, linux-riscv,
linux-s390, kvm, open, linux-kernel
Baolin Wang <baolin.wang@linux.alibaba.com> writes:
> This is a cleanup patchset to change all young flag check functions to
> return bool, as discussed with David in the previous thread[1]. Since
> callers only care about whether the young flag was set, returning bool
> makes the intention clearer. No functional changes intended.
>
> Ran mm selftests on Arm64 and x86 machines, and no issues were found.
>
> Note that I only CC'd the arch mailing lists to avoid disturbing too
> many people.
>
> [1] https://lore.kernel.org/all/d172d6bf-c60c-4cf5-9da9-f30de38cdfed@kernel.org/
>
> Baolin Wang (6):
> mm: change to return bool for ptep_test_and_clear_young()
> mm: change to return bool for
> ptep_clear_flush_young()/clear_flush_young_ptes()
> mm: change to return bool for pmdp_test_and_clear_young()
> mm: change to return bool for pmdp_clear_flush_young()
> mm: change to return bool for pudp_test_and_clear_young()
> mm: change to return bool for the MMU notifier's young flag check
>
> arch/arm64/include/asm/pgtable.h | 29 ++++----
> arch/arm64/mm/contpte.c | 8 +--
> arch/microblaze/include/asm/pgtable.h | 2 +-
> arch/parisc/include/asm/pgtable.h | 8 +--
> arch/parisc/kernel/cache.c | 8 +--
> arch/powerpc/include/asm/book3s/32/pgtable.h | 4 +-
> arch/powerpc/include/asm/book3s/64/pgtable.h | 26 +++----
> arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
> arch/powerpc/include/asm/nohash/pgtable.h | 4 +-
> arch/powerpc/mm/book3s64/pgtable.c | 8 +--
I did compile and boot test on powerpc with various configs and overall
it looks good.
-ritesh
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 0/6] change young flag check functions to return bool
2026-03-21 5:31 ` Ritesh Harjani
@ 2026-03-21 13:02 ` Baolin Wang
0 siblings, 0 replies; 27+ messages in thread
From: Baolin Wang @ 2026-03-21 13:02 UTC (permalink / raw)
To: Ritesh Harjani (IBM), akpm, david
Cc: ljs, Liam.Howlett, vbabka, rppt, surenb, mhocko, linux-arm-kernel,
x86, linux-parisc, linuxppc-dev, linux-riscv, linux-s390, kvm,
open, linux-kernel
On 3/21/26 1:31 PM, Ritesh Harjani (IBM) wrote:
> Baolin Wang <baolin.wang@linux.alibaba.com> writes:
>
>> This is a cleanup patchset to change all young flag check functions to
>> return bool, as discussed with David in the previous thread[1]. Since
>> callers only care about whether the young flag was set, returning bool
>> makes the intention clearer. No functional changes intended.
>>
>> Ran mm selftests on Arm64 and x86 machines, and no issues were found.
>>
>> Note that I only CC'd the arch mailing lists to avoid disturbing too
>> many people.
>>
>> [1] https://lore.kernel.org/all/d172d6bf-c60c-4cf5-9da9-f30de38cdfed@kernel.org/
>>
>> Baolin Wang (6):
>> mm: change to return bool for ptep_test_and_clear_young()
>> mm: change to return bool for
>> ptep_clear_flush_young()/clear_flush_young_ptes()
>> mm: change to return bool for pmdp_test_and_clear_young()
>> mm: change to return bool for pmdp_clear_flush_young()
>> mm: change to return bool for pudp_test_and_clear_young()
>> mm: change to return bool for the MMU notifier's young flag check
>>
>> arch/arm64/include/asm/pgtable.h | 29 ++++----
>> arch/arm64/mm/contpte.c | 8 +--
>> arch/microblaze/include/asm/pgtable.h | 2 +-
>> arch/parisc/include/asm/pgtable.h | 8 +--
>> arch/parisc/kernel/cache.c | 8 +--
>> arch/powerpc/include/asm/book3s/32/pgtable.h | 4 +-
>> arch/powerpc/include/asm/book3s/64/pgtable.h | 26 +++----
>> arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
>> arch/powerpc/include/asm/nohash/pgtable.h | 4 +-
>> arch/powerpc/mm/book3s64/pgtable.c | 8 +--
>
> I did compile and boot test on powerpc with various configs and overall
> it looks good.
Really appreciate your help with testing!
^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2026-03-21 13:02 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-19 3:23 [PATCH 0/6] change young flag check functions to return bool Baolin Wang
2026-03-19 3:24 ` [PATCH 1/6] mm: change to return bool for ptep_test_and_clear_young() Baolin Wang
2026-03-19 11:28 ` Lorenzo Stoakes (Oracle)
2026-03-20 2:59 ` Baolin Wang
2026-03-20 5:57 ` Ritesh Harjani
2026-03-21 5:22 ` Baolin Wang
2026-03-19 3:24 ` [PATCH 2/6] mm: change to return bool for ptep_clear_flush_young()/clear_flush_young_ptes() Baolin Wang
2026-03-19 11:30 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:05 ` Baolin Wang
2026-03-21 5:18 ` Ritesh Harjani
2026-03-19 3:24 ` [PATCH 3/6] mm: change to return bool for pmdp_test_and_clear_young() Baolin Wang
2026-03-19 11:31 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:07 ` Baolin Wang
2026-03-21 5:24 ` Ritesh Harjani
2026-03-19 3:24 ` [PATCH 4/6] mm: change to return bool for pmdp_clear_flush_young() Baolin Wang
2026-03-19 11:33 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:09 ` Baolin Wang
2026-03-19 3:24 ` [PATCH 5/6] mm: change to return bool for pudp_test_and_clear_young() Baolin Wang
2026-03-19 11:34 ` Lorenzo Stoakes (Oracle)
2026-03-21 5:30 ` Ritesh Harjani
2026-03-19 3:24 ` [PATCH 6/6] mm: change to return bool for the MMU notifier's young flag check Baolin Wang
2026-03-19 11:39 ` Lorenzo Stoakes (Oracle)
2026-03-20 3:18 ` Baolin Wang
2026-03-20 3:18 ` [PATCH 0/6] change young flag check functions to return bool Andrew Morton
2026-03-20 3:21 ` Baolin Wang
2026-03-21 5:31 ` Ritesh Harjani
2026-03-21 13:02 ` Baolin Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox