Hi Magnus, On Tue, 2025-02-18 at 18:55 +0100, Magnus Lindholm wrote: > 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).
Minor nitpick: "when _PAGE_SWP_EXCLUSIVE" => "when the _PAGE_SWP_EXCLUSIVE" > > Signed-off-by: Magnus Lindholm <linm...@gmail.com> > --- > arch/alpha/include/asm/pgtable.h | 2 +- > arch/arc/include/asm/pgtable-bits-arcv2.h | 2 +- > arch/arm/include/asm/pgtable.h | 2 +- > arch/arm64/include/asm/pgtable.h | 2 +- > arch/csky/include/asm/pgtable.h | 2 +- > arch/hexagon/include/asm/pgtable.h | 2 +- > arch/loongarch/include/asm/pgtable.h | 2 +- > arch/m68k/include/asm/mcf_pgtable.h | 2 +- > arch/m68k/include/asm/motorola_pgtable.h | 2 +- > arch/m68k/include/asm/sun3_pgtable.h | 2 +- > arch/microblaze/include/asm/pgtable.h | 2 +- > arch/mips/include/asm/pgtable.h | 4 ++-- > arch/nios2/include/asm/pgtable.h | 2 +- > arch/openrisc/include/asm/pgtable.h | 2 +- > arch/parisc/include/asm/pgtable.h | 2 +- > arch/powerpc/include/asm/book3s/32/pgtable.h | 2 +- > arch/powerpc/include/asm/book3s/64/pgtable.h | 2 +- > arch/powerpc/include/asm/nohash/pgtable.h | 2 +- > arch/riscv/include/asm/pgtable.h | 2 +- > arch/s390/include/asm/pgtable.h | 2 +- > arch/sh/include/asm/pgtable_32.h | 2 +- > arch/sparc/include/asm/pgtable_32.h | 2 +- > arch/sparc/include/asm/pgtable_64.h | 2 +- > arch/um/include/asm/pgtable.h | 2 +- > arch/x86/include/asm/pgtable.h | 2 +- > arch/xtensa/include/asm/pgtable.h | 2 +- > 26 files changed, 27 insertions(+), 27 deletions(-) > > diff --git a/arch/alpha/include/asm/pgtable.h > b/arch/alpha/include/asm/pgtable.h > index 02e8817a8921..b0870de4b5b8 100644 > --- a/arch/alpha/include/asm/pgtable.h > +++ b/arch/alpha/include/asm/pgtable.h > @@ -334,7 +334,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; > } > diff --git a/arch/arc/include/asm/pgtable-bits-arcv2.h > b/arch/arc/include/asm/pgtable-bits-arcv2.h > index 8ebec1b21d24..3084c53f402d 100644 > --- a/arch/arc/include/asm/pgtable-bits-arcv2.h > +++ b/arch/arc/include/asm/pgtable-bits-arcv2.h > @@ -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; > } > diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h > index be91e376df79..aa4f3f71789c 100644 > --- a/arch/arm/include/asm/pgtable.h > +++ b/arch/arm/include/asm/pgtable.h > @@ -303,7 +303,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); > } > diff --git a/arch/arm64/include/asm/pgtable.h > b/arch/arm64/include/asm/pgtable.h > index 0b2a2ad1b9e8..b48b70d8d12d 100644 > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -496,7 +496,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; > } > diff --git a/arch/csky/include/asm/pgtable.h b/arch/csky/include/asm/pgtable.h > index a397e1718ab6..e68722eb33d9 100644 > --- a/arch/csky/include/asm/pgtable.h > +++ b/arch/csky/include/asm/pgtable.h > @@ -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; > } > diff --git a/arch/hexagon/include/asm/pgtable.h > b/arch/hexagon/include/asm/pgtable.h > index 8c5b7a1c3d90..fa007eb9aad3 100644 > --- a/arch/hexagon/include/asm/pgtable.h > +++ b/arch/hexagon/include/asm/pgtable.h > @@ -390,7 +390,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; > } > diff --git a/arch/loongarch/include/asm/pgtable.h > b/arch/loongarch/include/asm/pgtable.h > index da346733a1da..bac946693d87 100644 > --- a/arch/loongarch/include/asm/pgtable.h > +++ b/arch/loongarch/include/asm/pgtable.h > @@ -302,7 +302,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; > } > diff --git a/arch/m68k/include/asm/mcf_pgtable.h > b/arch/m68k/include/asm/mcf_pgtable.h > index 48f87a8a8832..7e9748b29c44 100644 > --- a/arch/m68k/include/asm/mcf_pgtable.h > +++ b/arch/m68k/include/asm/mcf_pgtable.h > @@ -274,7 +274,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; > } > diff --git a/arch/m68k/include/asm/motorola_pgtable.h > b/arch/m68k/include/asm/motorola_pgtable.h > index 9866c7acdabe..26da9b985c5f 100644 > --- a/arch/m68k/include/asm/motorola_pgtable.h > +++ b/arch/m68k/include/asm/motorola_pgtable.h > @@ -191,7 +191,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; > } > diff --git a/arch/m68k/include/asm/sun3_pgtable.h > b/arch/m68k/include/asm/sun3_pgtable.h > index 30081aee8164..ac0793f57f31 100644 > --- a/arch/m68k/include/asm/sun3_pgtable.h > +++ b/arch/m68k/include/asm/sun3_pgtable.h > @@ -175,7 +175,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; > } > diff --git a/arch/microblaze/include/asm/pgtable.h > b/arch/microblaze/include/asm/pgtable.h > index e4ea2ec3642f..b281c2bbd6c0 100644 > --- a/arch/microblaze/include/asm/pgtable.h > +++ b/arch/microblaze/include/asm/pgtable.h > @@ -406,7 +406,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; > } > diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h > index c29a551eb0ca..c19da4ab7552 100644 > --- a/arch/mips/include/asm/pgtable.h > +++ b/arch/mips/include/asm/pgtable.h > @@ -540,7 +540,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; > } > @@ -557,7 +557,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; > } > diff --git a/arch/nios2/include/asm/pgtable.h > b/arch/nios2/include/asm/pgtable.h > index eab87c6beacb..64ce06bae8ac 100644 > --- a/arch/nios2/include/asm/pgtable.h > +++ b/arch/nios2/include/asm/pgtable.h > @@ -265,7 +265,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; > } > diff --git a/arch/openrisc/include/asm/pgtable.h > b/arch/openrisc/include/asm/pgtable.h > index 60c6ce7ff2dc..34cad9177a48 100644 > --- a/arch/openrisc/include/asm/pgtable.h > +++ b/arch/openrisc/include/asm/pgtable.h > @@ -413,7 +413,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; > } > diff --git a/arch/parisc/include/asm/pgtable.h > b/arch/parisc/include/asm/pgtable.h > index babf65751e81..dfeba45b6d6f 100644 > --- a/arch/parisc/include/asm/pgtable.h > +++ b/arch/parisc/include/asm/pgtable.h > @@ -431,7 +431,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; > } > diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h > b/arch/powerpc/include/asm/book3s/32/pgtable.h > index 42c3af90d1f0..92d21c6faf1e 100644 > --- a/arch/powerpc/include/asm/book3s/32/pgtable.h > +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h > @@ -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; > } > diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h > b/arch/powerpc/include/asm/book3s/64/pgtable.h > index 6d98e6f08d4d..dbf772bef20d 100644 > --- a/arch/powerpc/include/asm/book3s/64/pgtable.h > +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h > @@ -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)); > } > diff --git a/arch/powerpc/include/asm/nohash/pgtable.h > b/arch/powerpc/include/asm/nohash/pgtable.h > index 8d1f0b7062eb..7d6b9e5b286e 100644 > --- a/arch/powerpc/include/asm/nohash/pgtable.h > +++ b/arch/powerpc/include/asm/nohash/pgtable.h > @@ -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; > } > diff --git a/arch/riscv/include/asm/pgtable.h > b/arch/riscv/include/asm/pgtable.h > index 050fdc49b5ad..433c78c44e02 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -880,7 +880,7 @@ extern pmd_t pmdp_collapse_flush(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; > } > diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h > index 3ca5af4cfe43..cb86dbf7126a 100644 > --- a/arch/s390/include/asm/pgtable.h > +++ b/arch/s390/include/asm/pgtable.h > @@ -913,7 +913,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; > } > diff --git a/arch/sh/include/asm/pgtable_32.h > b/arch/sh/include/asm/pgtable_32.h > index f939f1215232..5f221f3269e3 100644 > --- a/arch/sh/include/asm/pgtable_32.h > +++ b/arch/sh/include/asm/pgtable_32.h > @@ -478,7 +478,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; > } > diff --git a/arch/sparc/include/asm/pgtable_32.h > b/arch/sparc/include/asm/pgtable_32.h > index 62bcafe38b1f..0362f8357371 100644 > --- a/arch/sparc/include/asm/pgtable_32.h > +++ b/arch/sparc/include/asm/pgtable_32.h > @@ -353,7 +353,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; > } > diff --git a/arch/sparc/include/asm/pgtable_64.h > b/arch/sparc/include/asm/pgtable_64.h > index 2b7f358762c1..65e53491fe07 100644 > --- a/arch/sparc/include/asm/pgtable_64.h > +++ b/arch/sparc/include/asm/pgtable_64.h > @@ -1027,7 +1027,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; > } > diff --git a/arch/um/include/asm/pgtable.h b/arch/um/include/asm/pgtable.h > index 5601ca98e8a6..c32309614a15 100644 > --- a/arch/um/include/asm/pgtable.h > +++ b/arch/um/include/asm/pgtable.h > @@ -316,7 +316,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); > } > diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h > index 593f10aabd45..4c7ce40023d3 100644 > --- a/arch/x86/include/asm/pgtable.h > +++ b/arch/x86/include/asm/pgtable.h > @@ -1586,7 +1586,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; > } > diff --git a/arch/xtensa/include/asm/pgtable.h > b/arch/xtensa/include/asm/pgtable.h > index 1647a7cc3fbf..6da0aa0604f1 100644 > --- a/arch/xtensa/include/asm/pgtable.h > +++ b/arch/xtensa/include/asm/pgtable.h > @@ -355,7 +355,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; > } I'm not so sure about this implicit cast from unsigned long to bool though. Is this verified to work correctly on all architectures? I wonder why this bug was not caught earlier on alpha on the other hand. Adrian -- .''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913