mm: pgtable: fix pte_swp_exclusive
Subsystems (23)
Magnus Lindholm
maintainerv2 cover mm: pgtable: fix pte_swp_exclusive
The first version of this patch intended to fix issues with swap memory on alpha, when swapoff fails to writeback exclusive swap pages and gets stuck in an infinite loop trying to do so. This problem appeared after commit a172d5128706028ac07b8db709728379ecc72f6e and as far as I know only affected the alpha architecure.
Changes in v2:
As suggested by Al Viro, rather than doing a bit-shift alpha-only fix this version of the patch makes pte_swp_exclusive return bool instead of int. As Al pointed out, this will also better reflect how pte_swp_exclusive is actually used in the code.
Best regards
Magnus Lindholm [email protected]
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(-)
Magnus Lindholm
maintainerPATCH v2 1/1 mm: pgtable: fix pte_swp_exclusive
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).
--- 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(-)
arch/alpha/include/asm/pgtable.h +1 -1
@@ -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; }
arch/arc/include/asm/pgtable-bits-arcv2.h +1 -1
@@ -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; }
arch/arm/include/asm/pgtable.h +1 -1
@@ -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 ); }
arch/arm64/include/asm/pgtable.h +1 -1
@@ -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 ; }
arch/csky/include/asm/pgtable.h +1 -1
@@ -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; }
arch/hexagon/include/asm/pgtable.h +1 -1
@@ -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; }
arch/loongarch/include/asm/pgtable.h +1 -1
@@ -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; }
arch/m68k/include/asm/mcf_pgtable.h +1 -1
@@ -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; }
arch/m68k/include/asm/motorola_pgtable.h +1 -1
@@ -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; }
arch/m68k/include/asm/sun3_pgtable.h +1 -1
@@ -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; }
arch/microblaze/include/asm/pgtable.h +1 -1
@@ -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; }
arch/mips/include/asm/pgtable.h +2 -2
@@ -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; }
arch/nios2/include/asm/pgtable.h +1 -1
@@ -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; }
arch/openrisc/include/asm/pgtable.h +1 -1
@@ -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; }
arch/parisc/include/asm/pgtable.h +1 -1
@@ -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; }
arch/powerpc/include/asm/book3s/32/pgtable.h +1 -1
@@ -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; }
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -1
@@ -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)); }
arch/powerpc/include/asm/nohash/pgtable.h +1 -1
@@ -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; }
arch/riscv/include/asm/pgtable.h +1 -1
@@ -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; }
arch/s390/include/asm/pgtable.h +1 -1
@@ -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; }
arch/sh/include/asm/pgtable_32.h +1 -1
@@ -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; }
arch/sparc/include/asm/pgtable_32.h +1 -1
@@ -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 ; }
arch/sparc/include/asm/pgtable_64.h +1 -1
@@ -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; }
arch/um/include/asm/pgtable.h +1 -1
@@ -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); }
arch/x86/include/asm/pgtable.h +1 -1
@@ -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; }
arch/xtensa/include/asm/pgtable.h +1 -1
@@ -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; }
Signature · 1 line
2.48.1
Lovely cleanup and a great suggestion from Al.
I'd suggest adding a:
thanks,
sam
Quoted 6 lines · Sam James
Lovely cleanup and a great suggestion from Al.
Reviewed-by Sam James <[email protected]>I'd suggest adding a:
Suggested-by Al Viro <[email protected]>
Al, were you planning on taking this through your tree?
Quoted 3 lines
thanks,
sam
Quoted 10 lines · Sam James
Quoted 6 lines · Sam James
Lovely cleanup and a great suggestion from Al.
Reviewed-by Sam James <[email protected]>I'd suggest adding a:
Suggested-by Al Viro <[email protected]>Al, were you planning on taking this through your tree?
FWIW, I expected it to get sent to Linus as "please, run this sed script before -rc1" kind of thing, script being something like
sed -i -e 's/int pte_swp_exclusive/bool pte_swp_exclusive/' \
git grep -l 'int pte_swp_exclusive'
with suggested commit message... It's absolutely regular and that kind of tree-wide change is easier handled that way.
Oh, well... To restore the context: Magnus had spotted a fun
bug on Alpha back in February - pte_swp_exclusive() there returned pte_val(pte) & _PAGE_SWP_EXCLUSIVE as int. The problem is that _PAGE_SWP_EXCLUSIVE is 1UL<<39 there, with obvious results...
I looked at the originally posted patch and suggested to
make pte_swp_exclusive() return bool instead of int. All users are in explicitly boolean contexts:
include/linux/swapops.h: if (pte_swp_exclusive(pte))
mm/debug_vm_pgtable.c: WARN_ON(pte_swp_exclusive(pte));
mm/debug_vm_pgtable.c: WARN_ON(!pte_swp_exclusive(pte));
mm/debug_vm_pgtable.c: WARN_ON(pte_swp_exclusive(pte));
mm/internal.h: if (pte_swp_exclusive(pte))
mm/memory.c: if (pte_swp_exclusive(orig_pte)) {
mm/memory.c: exclusive = pte_swp_exclusive(vmf->orig_pte);
mm/swapfile.c: if (pte_swp_exclusive(old_pte))
mm/userfaultfd.c: if (!pte_swp_exclusive(orig_src_pte)) { Magnus posted patch of that form (see
https://lore.kernel.org/all/[email protected]/),
got no serious objections and then it went nowhere.
Bug is real and fairly obvious, fix is entirely mechanical and
affects one line in each asm/pgtable.h out there. Linus, could you run that sed script just before -rc1? Commit message from the patch refered above looks sane:
mm: pgtable: fix pte_swp_exclusive
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).
Quoted 16 lines · Al Viro
Quoted 10 lines · Sam James
Quoted 6 lines · Sam James
Lovely cleanup and a great suggestion from Al.
Reviewed-by Sam James <[email protected]>I'd suggest adding a:
Suggested-by Al Viro <[email protected]>Al, were you planning on taking this through your tree?
FWIW, I expected it to get sent to Linus as "please, run this sed script before -rc1" kind of thing, script being something like
Quoted 5 lines
sed -i -e 's/int pte_swp_exclusive/bool pte_swp_exclusive/' \
git grep -l 'int pte_swp_exclusive'with suggested commit message... It's absolutely regular and that kind of tree-wide change is easier handled that way.
Ah, sorry. Both Magnus and I are new and irregular kernel contributors, but I've seen that before and should've thought of it.
Quoted 1 line
[...]
cheers,
sam
John Paul Adrian Glaubitz
maintainerHi Magnus,
Quoted 4 lines · Magnus Lindholm
Make
pte_swp_exclusivereturn bool instead of int. This will better reflect howpte_swp_exclusiveis actually used in the code. This fixes swap/swapoff problems on Alpha duepte_swp_exclusivenot returning correct values when_PAGE_SWP_EXCLUSIVEbit resides in upper 32-bits of PTE (like on alpha).
Minor nitpick:
"when _PAGE_SWP_EXCLUSIVE" => "when the _PAGE_SWP_EXCLUSIVE"
Quoted 370 lines
Signed-off-by Magnus Lindholm <[email protected]>--- 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(-)arch/alpha/include/asm/pgtable.h +1
-1@@ -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; }arch/arc/include/asm/pgtable-bits-arcv2.h +1
-1@@ -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; }arch/arm/include/asm/pgtable.h +1
-1@@ -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 ); }arch/arm64/include/asm/pgtable.h +1
-1@@ -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 ; }arch/csky/include/asm/pgtable.h +1
-1@@ -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; }arch/hexagon/include/asm/pgtable.h +1
-1@@ -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; }arch/loongarch/include/asm/pgtable.h +1
-1@@ -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; }arch/m68k/include/asm/mcf_pgtable.h +1
-1@@ -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; }arch/m68k/include/asm/motorola_pgtable.h +1
-1@@ -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; }arch/m68k/include/asm/sun3_pgtable.h +1
-1@@ -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; }arch/microblaze/include/asm/pgtable.h +1
-1@@ -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; }arch/mips/include/asm/pgtable.h +2
-2@@ -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; }arch/nios2/include/asm/pgtable.h +1
-1@@ -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; }arch/openrisc/include/asm/pgtable.h +1
-1@@ -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; }arch/parisc/include/asm/pgtable.h +1
-1@@ -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; }arch/powerpc/include/asm/book3s/32/pgtable.h +1
-1@@ -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; }arch/powerpc/include/asm/book3s/64/pgtable.h +1
-1@@ -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)); }arch/powerpc/include/asm/nohash/pgtable.h +1
-1@@ -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; }arch/riscv/include/asm/pgtable.h +1
-1@@ -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; }arch/s390/include/asm/pgtable.h +1
-1@@ -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; }arch/sh/include/asm/pgtable_32.h +1
-1@@ -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; }arch/sparc/include/asm/pgtable_32.h +1
-1@@ -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 ; }arch/sparc/include/asm/pgtable_64.h +1
-1@@ -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; }arch/um/include/asm/pgtable.h +1
-1@@ -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); }arch/x86/include/asm/pgtable.h +1
-1@@ -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; }arch/xtensa/include/asm/pgtable.h +0
-0
arch/xtensa/include/asm/pgtable.h ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) · line 361
Quoted 8 lines
arch/xtensa/include/asm/pgtable.h +1
-1@@ -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
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Geert Uytterhoeven
maintainerHi Adrian,
Quoted 39 lines · John Paul Adrian Glaubitz
Quoted 4 lines · Magnus Lindholm
Make
pte_swp_exclusivereturn bool instead of int. This will better reflect howpte_swp_exclusiveis actually used in the code. This fixes swap/swapoff problems on Alpha duepte_swp_exclusivenot returning correct values when_PAGE_SWP_EXCLUSIVEbit resides in upper 32-bits of PTE (like on alpha).Minor nitpick:
"when
_PAGE_SWP_EXCLUSIVE" => "when the_PAGE_SWP_EXCLUSIVE"Quoted 18 lines
Signed-off-by Magnus Lindholm <[email protected]>arch/alpha/include/asm/pgtable.h +1
-1@@ -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; }arch/xtensa/include/asm/pgtable.h ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) · line 361
Quoted 8 lines
arch/xtensa/include/asm/pgtable.h +1
-1@@ -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.
Quoted 1 line
Is this verified to work correctly on all architectures? I wonder why this
Should work fine: any non-zero value is mapped to one.
Quoted 1 line
bug was not caught earlier on alpha on the other hand.
On Alpha, "pte_val(pte) & _PAGE_SWP_EXCLUSIVE" is either _PAGE_SWP_EXCLUSIVE == 0x8000000000UL or zero. Due to the return type being int, the return value was truncated, and the function always returned zero.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds