Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive
Geert Uytterhoeven <[email protected]>
| Newsgroups | gmane.linux.ports.ppc64.devel,gmane.linux.kernel,gmane.linux.ports.alpha,gmane.linux.ports.arm.kernel,gmane.linux.ports.hexagon,gmane.linux.ports.mips,gmane.linux.ports.parisc,gmane.linux.ports.riscv,gmane.linux.ports.sh.devel,gmane.linux.kernel.arc,gmane.linux.uml.devel,gmane.linux.ports.sparc |
|---|---|
| Message-ID | <CAMuHMdWLVw8aUY8aCowgOz+puxjrDqcbUXUAoVXGi8=FpTHwrA@mail.gmail.com> |
Hi Adrian, On Sat, 5 Apr 2025 at 19:22, John Paul Adrian Glaubitz <[email protected]> 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 <[email protected]> > > --- 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 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds