* [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-02-18 17:55 ` Magnus Lindholm
0 siblings, 0 replies; 24+ messages in thread
From: Magnus Lindholm @ 2025-02-18 17:55 UTC (permalink / raw)
To: linmag7, richard.henderson, mattst88, glaubitz, ink, kees, arnd,
linux-kernel, linux-alpha
Cc: chris, dinguyen, jcmvbkbc, linux-arm-kernel, linux-csky,
linux-hexagon, linux-m68k, linux-mips, linux-openrisc,
linux-parisc, linuxppc-dev, linux-riscv, linux-s390, linux-sh,
linux-snps-arc, linux-um, loongarch, monstr, sparclinux, x86
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).
Signed-off-by: Magnus Lindholm <linmag7@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;
}
--
2.48.1
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-02-18 17:55 ` Magnus Lindholm
0 siblings, 0 replies; 24+ messages in thread
From: Magnus Lindholm @ 2025-02-18 17:55 UTC (permalink / raw)
To: linmag7, richard.henderson, mattst88, glaubitz, ink, kees, arnd,
linux-kernel, linux-alpha
Cc: chris, dinguyen, jcmvbkbc, linux-arm-kernel, linux-csky,
linux-hexagon, linux-m68k, linux-mips, linux-openrisc,
linux-parisc, linuxppc-dev, linux-riscv, linux-s390, linux-sh,
linux-snps-arc, linux-um, loongarch, monstr, sparclinux, x86
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).
Signed-off-by: Magnus Lindholm <linmag7@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;
}
--
2.48.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
2025-02-18 17:55 ` Magnus Lindholm
(?)
@ 2025-02-19 14:06 ` Sam James
-1 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-02-19 14:06 UTC (permalink / raw)
To: linmag7
Cc: arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc, kees, linux-alpha,
linux-arm-kernel, linux-csky, linux-hexagon, linux-kernel,
linux-m68k, linux-mips, linux-openrisc, linux-parisc, linux-riscv,
linux-s390, linux-sh, linux-snps-arc, linux-um, linuxppc-dev,
loongarch, mattst88, monstr, richard.henderson, sparclinux, x86
Lovely cleanup and a great suggestion from Al.
Reviewed-by: Sam James <sam@gentoo.org>
I'd suggest adding a:
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
thanks,
sam
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-02-19 14:06 ` Sam James
0 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-02-19 14:06 UTC (permalink / raw)
To: linmag7
Cc: arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc, kees, linux-alpha,
linux-arm-kernel, linux-csky, linux-hexagon, linux-kernel,
linux-m68k, linux-mips, linux-openrisc, linux-parisc, linux-riscv,
linux-s390, linux-sh, linux-snps-arc, linux-um, linuxppc-dev,
loongarch, mattst88, monstr, richard.henderson, sparclinux, x86
Lovely cleanup and a great suggestion from Al.
Reviewed-by: Sam James <sam@gentoo.org>
I'd suggest adding a:
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
thanks,
sam
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-02-19 14:06 ` Sam James
0 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-02-19 14:06 UTC (permalink / raw)
To: linmag7
Cc: arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc, kees, linux-alpha,
linux-arm-kernel, linux-csky, linux-hexagon, linux-kernel,
linux-m68k, linux-mips, linux-openrisc, linux-parisc, linux-riscv,
linux-s390, linux-sh, linux-snps-arc, linux-um, linuxppc-dev,
loongarch, mattst88, monstr, richard.henderson, sparclinux, x86
Lovely cleanup and a great suggestion from Al.
Reviewed-by: Sam James <sam@gentoo.org>
I'd suggest adding a:
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
thanks,
sam
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
2025-02-19 14:06 ` Sam James
(?)
@ 2025-04-05 17:09 ` Sam James
-1 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-04-05 17:09 UTC (permalink / raw)
To: linmag7, Al Viro
Cc: arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc, kees, linux-alpha,
linux-arm-kernel, linux-csky, linux-hexagon, linux-kernel,
linux-m68k, linux-mips, linux-openrisc, linux-parisc, linux-riscv,
linux-s390, linux-sh, linux-snps-arc, linux-um, linuxppc-dev,
loongarch, mattst88, monstr, richard.henderson, sparclinux, x86
Sam James <sam@gentoo.org> writes:
> Lovely cleanup and a great suggestion from Al.
>
> Reviewed-by: Sam James <sam@gentoo.org>
>
> I'd suggest adding a:
> Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Al, were you planning on taking this through your tree?
>
> thanks,
> sam
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-04-05 17:09 ` Sam James
0 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-04-05 17:09 UTC (permalink / raw)
To: linmag7, Al Viro
Cc: arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc, kees, linux-alpha,
linux-arm-kernel, linux-csky, linux-hexagon, linux-kernel,
linux-m68k, linux-mips, linux-openrisc, linux-parisc, linux-riscv,
linux-s390, linux-sh, linux-snps-arc, linux-um, linuxppc-dev,
loongarch, mattst88, monstr, richard.henderson, sparclinux, x86
Sam James <sam@gentoo.org> writes:
> Lovely cleanup and a great suggestion from Al.
>
> Reviewed-by: Sam James <sam@gentoo.org>
>
> I'd suggest adding a:
> Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Al, were you planning on taking this through your tree?
>
> thanks,
> sam
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-04-05 17:09 ` Sam James
0 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-04-05 17:09 UTC (permalink / raw)
To: linmag7, Al Viro
Cc: arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc, kees, linux-alpha,
linux-arm-kernel, linux-csky, linux-hexagon, linux-kernel,
linux-m68k, linux-mips, linux-openrisc, linux-parisc, linux-riscv,
linux-s390, linux-sh, linux-snps-arc, linux-um, linuxppc-dev,
loongarch, mattst88, monstr, richard.henderson, sparclinux, x86
Sam James <sam@gentoo.org> writes:
> Lovely cleanup and a great suggestion from Al.
>
> Reviewed-by: Sam James <sam@gentoo.org>
>
> I'd suggest adding a:
> Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Al, were you planning on taking this through your tree?
>
> thanks,
> sam
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
2025-04-05 17:09 ` Sam James
(?)
@ 2025-06-02 4:11 ` Al Viro
-1 siblings, 0 replies; 24+ messages in thread
From: Al Viro @ 2025-06-02 4:11 UTC (permalink / raw)
To: Linus Torvalds
Cc: linmag7, Al Viro, arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc,
kees, linux-alpha, linux-arm-kernel, linux-csky, linux-hexagon,
linux-kernel, linux-m68k, linux-mips, linux-openrisc,
linux-parisc, linux-riscv, linux-s390, linux-sh, linux-snps-arc,
linux-um, linuxppc-dev, loongarch, mattst88, monstr,
richard.henderson, sparclinux, x86, Sam James
On Sat, Apr 05, 2025 at 06:09:11PM +0100, Sam James wrote:
> Sam James <sam@gentoo.org> writes:
>
> > Lovely cleanup and a great suggestion from Al.
> >
> > Reviewed-by: Sam James <sam@gentoo.org>
> >
> > I'd suggest adding a:
> > Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
>
> 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/20250218175735.19882-2-linmag7@gmail.com/),
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).
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-06-02 4:11 ` Al Viro
0 siblings, 0 replies; 24+ messages in thread
From: Al Viro @ 2025-06-02 4:11 UTC (permalink / raw)
To: Linus Torvalds
Cc: linmag7, Al Viro, arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc,
kees, linux-alpha, linux-arm-kernel, linux-csky, linux-hexagon,
linux-kernel, linux-m68k, linux-mips, linux-openrisc,
linux-parisc, linux-riscv, linux-s390, linux-sh, linux-snps-arc,
linux-um, linuxppc-dev, loongarch, mattst88, monstr,
richard.henderson, sparclinux, x86, Sam James
On Sat, Apr 05, 2025 at 06:09:11PM +0100, Sam James wrote:
> Sam James <sam@gentoo.org> writes:
>
> > Lovely cleanup and a great suggestion from Al.
> >
> > Reviewed-by: Sam James <sam@gentoo.org>
> >
> > I'd suggest adding a:
> > Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
>
> 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/20250218175735.19882-2-linmag7@gmail.com/),
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).
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-06-02 4:11 ` Al Viro
0 siblings, 0 replies; 24+ messages in thread
From: Al Viro @ 2025-06-02 4:11 UTC (permalink / raw)
To: Linus Torvalds
Cc: linmag7, Al Viro, arnd, chris, dinguyen, glaubitz, ink, jcmvbkbc,
kees, linux-alpha, linux-arm-kernel, linux-csky, linux-hexagon,
linux-kernel, linux-m68k, linux-mips, linux-openrisc,
linux-parisc, linux-riscv, linux-s390, linux-sh, linux-snps-arc,
linux-um, linuxppc-dev, loongarch, mattst88, monstr,
richard.henderson, sparclinux, x86, Sam James
On Sat, Apr 05, 2025 at 06:09:11PM +0100, Sam James wrote:
> Sam James <sam@gentoo.org> writes:
>
> > Lovely cleanup and a great suggestion from Al.
> >
> > Reviewed-by: Sam James <sam@gentoo.org>
> >
> > I'd suggest adding a:
> > Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
>
> 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/20250218175735.19882-2-linmag7@gmail.com/),
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).
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
2025-06-02 4:11 ` Al Viro
(?)
@ 2025-06-02 15:16 ` Sam James
-1 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-06-02 15:16 UTC (permalink / raw)
To: Al Viro
Cc: Linus Torvalds, linmag7, Al Viro, arnd, chris, dinguyen, glaubitz,
ink, jcmvbkbc, kees, linux-alpha, linux-arm-kernel, linux-csky,
linux-hexagon, linux-kernel, linux-m68k, linux-mips,
linux-openrisc, linux-parisc, linux-riscv, linux-s390, linux-sh,
linux-snps-arc, linux-um, linuxppc-dev, loongarch, mattst88,
monstr, richard.henderson, sparclinux, x86
Al Viro <viro@zeniv.linux.org.uk> writes:
> On Sat, Apr 05, 2025 at 06:09:11PM +0100, Sam James wrote:
>> Sam James <sam@gentoo.org> writes:
>>
>> > Lovely cleanup and a great suggestion from Al.
>> >
>> > Reviewed-by: Sam James <sam@gentoo.org>
>> >
>> > I'd suggest adding a:
>> > Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
>>
>> 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.
Ah, sorry. Both Magnus and I are new and irregular kernel contributors,
but I've seen that before and should've thought of it.
> [...]
cheers,
sam
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-06-02 15:16 ` Sam James
0 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-06-02 15:16 UTC (permalink / raw)
To: Al Viro
Cc: Linus Torvalds, linmag7, Al Viro, arnd, chris, dinguyen, glaubitz,
ink, jcmvbkbc, kees, linux-alpha, linux-arm-kernel, linux-csky,
linux-hexagon, linux-kernel, linux-m68k, linux-mips,
linux-openrisc, linux-parisc, linux-riscv, linux-s390, linux-sh,
linux-snps-arc, linux-um, linuxppc-dev, loongarch, mattst88,
monstr, richard.henderson, sparclinux, x86
Al Viro <viro@zeniv.linux.org.uk> writes:
> On Sat, Apr 05, 2025 at 06:09:11PM +0100, Sam James wrote:
>> Sam James <sam@gentoo.org> writes:
>>
>> > Lovely cleanup and a great suggestion from Al.
>> >
>> > Reviewed-by: Sam James <sam@gentoo.org>
>> >
>> > I'd suggest adding a:
>> > Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
>>
>> 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.
Ah, sorry. Both Magnus and I are new and irregular kernel contributors,
but I've seen that before and should've thought of it.
> [...]
cheers,
sam
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-06-02 15:16 ` Sam James
0 siblings, 0 replies; 24+ messages in thread
From: Sam James @ 2025-06-02 15:16 UTC (permalink / raw)
To: Al Viro
Cc: Linus Torvalds, linmag7, Al Viro, arnd, chris, dinguyen, glaubitz,
ink, jcmvbkbc, kees, linux-alpha, linux-arm-kernel, linux-csky,
linux-hexagon, linux-kernel, linux-m68k, linux-mips,
linux-openrisc, linux-parisc, linux-riscv, linux-s390, linux-sh,
linux-snps-arc, linux-um, linuxppc-dev, loongarch, mattst88,
monstr, richard.henderson, sparclinux, x86
Al Viro <viro@zeniv.linux.org.uk> writes:
> On Sat, Apr 05, 2025 at 06:09:11PM +0100, Sam James wrote:
>> Sam James <sam@gentoo.org> writes:
>>
>> > Lovely cleanup and a great suggestion from Al.
>> >
>> > Reviewed-by: Sam James <sam@gentoo.org>
>> >
>> > I'd suggest adding a:
>> > Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
>>
>> 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.
Ah, sorry. Both Magnus and I are new and irregular kernel contributors,
but I've seen that before and should've thought of it.
> [...]
cheers,
sam
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
2025-02-18 17:55 ` Magnus Lindholm
(?)
@ 2025-04-05 17:21 ` John Paul Adrian Glaubitz
-1 siblings, 0 replies; 24+ messages in thread
From: John Paul Adrian Glaubitz @ 2025-04-05 17:21 UTC (permalink / raw)
To: Magnus Lindholm, richard.henderson, mattst88, ink, kees, arnd,
linux-kernel, linux-alpha
Cc: chris, dinguyen, jcmvbkbc, linux-arm-kernel, linux-csky,
linux-hexagon, linux-m68k, linux-mips, linux-openrisc,
linux-parisc, linuxppc-dev, linux-riscv, linux-s390, linux-sh,
linux-snps-arc, linux-um, loongarch, monstr, sparclinux, x86
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 <linmag7@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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-04-05 17:21 ` John Paul Adrian Glaubitz
0 siblings, 0 replies; 24+ messages in thread
From: John Paul Adrian Glaubitz @ 2025-04-05 17:21 UTC (permalink / raw)
To: Magnus Lindholm, richard.henderson, mattst88, ink, kees, arnd,
linux-kernel, linux-alpha
Cc: chris, dinguyen, jcmvbkbc, linux-arm-kernel, linux-csky,
linux-hexagon, linux-m68k, linux-mips, linux-openrisc,
linux-parisc, linuxppc-dev, linux-riscv, linux-s390, linux-sh,
linux-snps-arc, linux-um, loongarch, monstr, sparclinux, x86
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 <linmag7@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
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-04-05 17:21 ` John Paul Adrian Glaubitz
0 siblings, 0 replies; 24+ messages in thread
From: John Paul Adrian Glaubitz @ 2025-04-05 17:21 UTC (permalink / raw)
To: Magnus Lindholm, richard.henderson, mattst88, ink, kees, arnd,
linux-kernel, linux-alpha
Cc: chris, dinguyen, jcmvbkbc, linux-arm-kernel, linux-csky,
linux-hexagon, linux-m68k, linux-mips, linux-openrisc,
linux-parisc, linuxppc-dev, linux-riscv, linux-s390, linux-sh,
linux-snps-arc, linux-um, loongarch, monstr, sparclinux, x86
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 <linmag7@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
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
2025-04-05 17:21 ` John Paul Adrian Glaubitz
(?)
@ 2025-04-07 8:06 ` Geert Uytterhoeven
-1 siblings, 0 replies; 24+ messages in thread
From: Geert Uytterhoeven @ 2025-04-07 8:06 UTC (permalink / raw)
To: John Paul Adrian Glaubitz
Cc: Magnus Lindholm, richard.henderson, mattst88, ink, kees, arnd,
linux-kernel, linux-alpha, chris, dinguyen, jcmvbkbc,
linux-arm-kernel, linux-csky, linux-hexagon, linux-m68k,
linux-mips, linux-openrisc, linux-parisc, linuxppc-dev,
linux-riscv, linux-s390, linux-sh, linux-snps-arc, linux-um,
loongarch, monstr, sparclinux, x86
Hi Adrian,
On Sat, 5 Apr 2025 at 19:22, John Paul Adrian Glaubitz
<glaubitz@physik.fu-berlin.de> wrote:
> 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 <linmag7@gmail.com>
> > --- 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;
> > }
> > --- 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
Should work fine: any non-zero value is mapped to one.
> 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
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-04-07 8:06 ` Geert Uytterhoeven
0 siblings, 0 replies; 24+ messages in thread
From: Geert Uytterhoeven @ 2025-04-07 8:06 UTC (permalink / raw)
To: John Paul Adrian Glaubitz
Cc: Magnus Lindholm, richard.henderson, mattst88, ink, kees, arnd,
linux-kernel, linux-alpha, chris, dinguyen, jcmvbkbc,
linux-arm-kernel, linux-csky, linux-hexagon, linux-m68k,
linux-mips, linux-openrisc, linux-parisc, linuxppc-dev,
linux-riscv, linux-s390, linux-sh, linux-snps-arc, linux-um,
loongarch, monstr, sparclinux, x86
Hi Adrian,
On Sat, 5 Apr 2025 at 19:22, John Paul Adrian Glaubitz
<glaubitz@physik.fu-berlin.de> wrote:
> 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 <linmag7@gmail.com>
> > --- 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;
> > }
> > --- 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
Should work fine: any non-zero value is mapped to one.
> 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
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
@ 2025-04-07 8:06 ` Geert Uytterhoeven
0 siblings, 0 replies; 24+ messages in thread
From: Geert Uytterhoeven @ 2025-04-07 8:06 UTC (permalink / raw)
To: John Paul Adrian Glaubitz
Cc: Magnus Lindholm, richard.henderson, mattst88, ink, kees, arnd,
linux-kernel, linux-alpha, chris, dinguyen, jcmvbkbc,
linux-arm-kernel, linux-csky, linux-hexagon, linux-m68k,
linux-mips, linux-openrisc, linux-parisc, linuxppc-dev,
linux-riscv, linux-s390, linux-sh, linux-snps-arc, linux-um,
loongarch, monstr, sparclinux, x86
Hi Adrian,
On Sat, 5 Apr 2025 at 19:22, John Paul Adrian Glaubitz
<glaubitz@physik.fu-berlin.de> wrote:
> 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 <linmag7@gmail.com>
> > --- 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;
> > }
> > --- 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
Should work fine: any non-zero value is mapped to one.
> 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
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
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
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 24+ messages in thread