mm: pgtable: fix pte_swp_exclusive
authorMagnus Lindholm <linmag7@gmail.com>
Tue, 18 Feb 2025 17:55:14 +0000 (18:55 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Jun 2025 21:52:08 +0000 (14:52 -0700)
Make pte_swp_exclusive return bool instead of int.  This will better
reflect how pte_swp_exclusive is actually used in the code.

This fixes swap/swapoff problems on Alpha due pte_swp_exclusive not
returning correct values when _PAGE_SWP_EXCLUSIVE bit resides in upper
32-bits of PTE (like on alpha).

Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
Cc: Sam James <sam@gentoo.org>
Link: https://lore.kernel.org/lkml/20250218175735.19882-2-linmag7@gmail.com/
Link: https://lore.kernel.org/lkml/20250602041118.GA2675383@ZenIV/
[ Applied as the 'sed' script Al suggested   - Linus ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
26 files changed:
arch/alpha/include/asm/pgtable.h
arch/arc/include/asm/pgtable-bits-arcv2.h
arch/arm/include/asm/pgtable.h
arch/arm64/include/asm/pgtable.h
arch/csky/include/asm/pgtable.h
arch/hexagon/include/asm/pgtable.h
arch/loongarch/include/asm/pgtable.h
arch/m68k/include/asm/mcf_pgtable.h
arch/m68k/include/asm/motorola_pgtable.h
arch/m68k/include/asm/sun3_pgtable.h
arch/microblaze/include/asm/pgtable.h
arch/mips/include/asm/pgtable.h
arch/nios2/include/asm/pgtable.h
arch/openrisc/include/asm/pgtable.h
arch/parisc/include/asm/pgtable.h
arch/powerpc/include/asm/book3s/32/pgtable.h
arch/powerpc/include/asm/book3s/64/pgtable.h
arch/powerpc/include/asm/nohash/pgtable.h
arch/riscv/include/asm/pgtable.h
arch/s390/include/asm/pgtable.h
arch/sh/include/asm/pgtable_32.h
arch/sparc/include/asm/pgtable_32.h
arch/sparc/include/asm/pgtable_64.h
arch/um/include/asm/pgtable.h
arch/x86/include/asm/pgtable.h
arch/xtensa/include/asm/pgtable.h

index 2676017f42f1759483608e3a5c46beb8625763d0..44e7aedac6e87e9b390fd711ff985d1a235d93d8 100644 (file)
@@ -327,7 +327,7 @@ extern inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 8ebec1b21d246e61aa688c152dba9b5e2e564104..3084c53f402d8fc1df0b82b15151c2167104caae 100644 (file)
@@ -130,7 +130,7 @@ void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma,
 #define __pte_to_swp_entry(pte)                ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)          ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 7f1c3b4e3e0449cc26d41062c4e59c7a42376c41..86378eec77573bf840b0e8aed6c3d7c9d18ada23 100644 (file)
@@ -301,7 +301,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(swp)        __pte((swp).val)
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_isset(pte, L_PTE_SWP_EXCLUSIVE);
 }
index 88db8a0c0b3716ae8d4287a5fc6348c14330983a..192d86e1cc76ea3459f9851bc316cb039e5b8734 100644 (file)
@@ -563,7 +563,7 @@ static inline pte_t pte_swp_mkexclusive(pte_t pte)
        return set_pte_bit(pte, __pgprot(PTE_SWP_EXCLUSIVE));
 }
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & PTE_SWP_EXCLUSIVE;
 }
index b8378431aeff7c5e1705d8fac2981a7123f39c2f..5a394be09c35b6b3117d8b2c26297ec7c7339cf2 100644 (file)
@@ -200,7 +200,7 @@ static inline pte_t pte_mkyoung(pte_t pte)
        return pte;
 }
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 9fbdfdbc539f8539b0377a601b8a1027d6a26212..fbf24d1d1ca6aafc95179cac6af720bf29f10231 100644 (file)
@@ -387,7 +387,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
                (((type & 0x1f) << 1) | \
                 ((offset & 0x3ffff8) << 10) | ((offset & 0x7) << 7)) })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index a3f17914dbab1c54f7adf7f6d9b503de75aaf314..b30185302c07127504e0e26ba3e6ad2d5c4b39ec 100644 (file)
@@ -301,7 +301,7 @@ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
 #define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) })
 #define __swp_entry_to_pmd(x)  ((pmd_t) { (x).val | _PAGE_HUGE })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index f5c596b211d422f8f7c4d9d7387e5cf8203d252d..d79fef609194d6ce92a5a3a8e2ff994a679b10d5 100644 (file)
@@ -268,7 +268,7 @@ extern pgd_t kernel_pg_dir[PTRS_PER_PGD];
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)  (__pte((x).val))
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 040ac3bad713cd2a5e9d3b930f4c47c321937fdf..14fee64d3e605c979d62851bf3d61c2a514f5e10 100644 (file)
@@ -185,7 +185,7 @@ extern pgd_t kernel_pg_dir[128];
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 73745dc0ec0e0f4ba8f86cce875492273617c3ce..858cbe936f5b3f69d6ec1a970bcc7f9ce03b9dd2 100644 (file)
@@ -169,7 +169,7 @@ extern pgd_t kernel_pg_dir[PTRS_PER_PGD];
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index b1bb2c65dd047e0d412a6b81db1447d2b0846060..bae1abfa6f6b863924de9f0cc954ebdb4d09a778 100644 (file)
@@ -398,7 +398,7 @@ extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) >> 2 })
 #define __swp_entry_to_pte(x)  ((pte_t) { (x).val << 2 })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 4852b005a72d3689f216b31c61f2f4e5dafacf22..ae73ecf4c41aacf9bd01911e62b451d115692c42 100644 (file)
@@ -534,7 +534,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 #endif
 
 #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte.pte_low & _PAGE_SWP_EXCLUSIVE;
 }
@@ -551,7 +551,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
        return pte;
 }
 #else
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index e98578e27e26bcb127a66cfc00d11b2197934a1c..844dce55569f34b8a324470d32a9e43ab9b666b3 100644 (file)
@@ -259,7 +259,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
 #define __swp_entry_to_pte(swp)        ((pte_t) { (swp).val })
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 71bfb8c8c482a3b3c31ea48e4311f45c86558307..5bd6463bd514497c56456713eaed3611bb2d0f01 100644 (file)
@@ -411,7 +411,7 @@ static inline void update_mmu_cache_range(struct vm_fault *vmf,
 #define __pte_to_swp_entry(pte)                ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)          ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 80f5e2a2841314e1ee3110e99dfddc46f5db7eeb..1a86a4370b298af1c6904c2f8b37d327b3438076 100644 (file)
@@ -425,7 +425,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 #define __pte_to_swp_entry(pte)                ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)          ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 42c3af90d1f0ff8f23ddd6511a98a68f5751c1d7..92d21c6faf1e57665f7078b8ca3f2c267e1ce9d4 100644 (file)
@@ -365,7 +365,7 @@ static inline void __ptep_set_access_flags(struct vm_area_struct *vma,
 #define __pte_to_swp_entry(pte)                ((swp_entry_t) { pte_val(pte) >> 3 })
 #define __swp_entry_to_pte(x)          ((pte_t) { (x).val << 3 })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 6ed93e290c2feda820f7e47d3d58b862295b6c53..a2ddcbb3fcb94f119de7b9c7afa566985443da80 100644 (file)
@@ -693,7 +693,7 @@ static inline pte_t pte_swp_mkexclusive(pte_t pte)
        return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_SWP_EXCLUSIVE));
 }
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SWP_EXCLUSIVE));
 }
index 8d1f0b7062eb2f11805b6e0f8c9e1202fd6e6723..7d6b9e5b286ef93f49823ee15c5ff93e10b7f159 100644 (file)
@@ -286,7 +286,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
        return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
 }
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index a11816bbf9e7f95bf07c144c47f6821d6945d904..438ce7df24c39707e4ad5fa1c8b33b0d827ed8f9 100644 (file)
@@ -1028,7 +1028,7 @@ static inline pud_t pud_modify(pud_t pud, pgprot_t newprot)
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 1c661ac62ce81b7d57963c6a1f0766b530eec103..6d8bc27a366e4f17abc0e04d01dff5fcf20eb2e7 100644 (file)
@@ -915,7 +915,7 @@ static inline int pmd_protnone(pmd_t pmd)
 }
 #endif
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index 71b18741cc11a7759cc780f23046f74e16886592..5f51af18997b57ff531d13aed53f9119882a0f6c 100644 (file)
@@ -470,7 +470,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
 /* In both cases, we borrow bit 6 to store the exclusive marker in swap PTEs. */
 #define _PAGE_SWP_EXCLUSIVE    _PAGE_USER
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte.pte_low & _PAGE_SWP_EXCLUSIVE;
 }
index 1454ebe915393e7c574b238c9836edac104db03c..7c199c003ffe3b402644407ea6f63b07352e0c19 100644 (file)
@@ -348,7 +348,7 @@ static inline swp_entry_t __swp_entry(unsigned long type, unsigned long offset)
 #define __pte_to_swp_entry(pte)                ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)          ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & SRMMU_SWP_EXCLUSIVE;
 }
index 4af03e3c161b4bdacda6e075bb0c68dc6793f6f3..669cd02469a1d94dd1b0f5941af17afbc690da48 100644 (file)
@@ -1023,7 +1023,7 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
 #define __pte_to_swp_entry(pte)                ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)          ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index ca2a519d53ab1d0fd6b537384c56cd451286bac1..24fdea6f88c37f4672876f76e9d5067610a87c2f 100644 (file)
@@ -314,7 +314,7 @@ extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
        ((swp_entry_t) { pte_val(pte_mkuptodate(pte)) })
 #define __swp_entry_to_pte(x)          ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_get_bits(pte, _PAGE_SWP_EXCLUSIVE);
 }
index 774430c3abff21074865f47b6b608cb81ed3264b..97954c936c5480f2cc7cb22ea62c6fe8a8f772dd 100644 (file)
@@ -1561,7 +1561,7 @@ static inline pte_t pte_swp_mkexclusive(pte_t pte)
        return pte_set_flags(pte, _PAGE_SWP_EXCLUSIVE);
 }
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_flags(pte) & _PAGE_SWP_EXCLUSIVE;
 }
index cb1725c40e369200656e034c8a493064dd074780..d62aa1c316fcb1d8cef18c4734bbe7748276fbbe 100644 (file)
@@ -349,7 +349,7 @@ ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
 
-static inline int pte_swp_exclusive(pte_t pte)
+static inline bool pte_swp_exclusive(pte_t pte)
 {
        return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
 }