Re: [PATCH v2 1/1] mm: pgtable: fix pte_swp_exclusive

Al Viro <[email protected]>
Newsgroups gmane.linux.ports.alpha,gmane.linux.ports.arm.kernel,gmane.linux.ports.hexagon,gmane.linux.kernel,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.ppc64.devel,gmane.linux.ports.sparc
Message-ID <20250602041118.GA2675383@ZenIV>
On Sat, Apr 05, 2025 at 06:09:11PM +0100, Sam James wrote:
> Sam James <[email protected]> writes:
> 
> > Lovely cleanup and a great suggestion from Al.
> >
> > Reviewed-by: Sam James <[email protected]>
> >
> > I'd suggest adding a:
> > Suggested-by: Al Viro <[email protected]>
> 
> Al, were you planning on taking this through your tree?

FWIW, I expected it to get sent to Linus as "please, run this
sed script before -rc1" kind of thing, script being something
like

sed -i -e 's/int pte_swp_exclusive/bool pte_swp_exclusive/' \
	`git grep -l 'int pte_swp_exclusive'`

with suggested commit message...  It's absolutely regular and
that kind of tree-wide change is easier handled that way.

	Oh, well...  To restore the context: Magnus had spotted a fun
bug on Alpha back in February - pte_swp_exclusive() there returned
pte_val(pte) & _PAGE_SWP_EXCLUSIVE as int.  The problem is that
_PAGE_SWP_EXCLUSIVE is 1UL<<39 there, with obvious results...

	I looked at the originally posted patch and suggested to
make pte_swp_exclusive() return bool instead of int.  All users
are in explicitly boolean contexts:

include/linux/swapops.h:        if (pte_swp_exclusive(pte))
mm/debug_vm_pgtable.c:  WARN_ON(pte_swp_exclusive(pte));
mm/debug_vm_pgtable.c:  WARN_ON(!pte_swp_exclusive(pte));
mm/debug_vm_pgtable.c:  WARN_ON(pte_swp_exclusive(pte));
mm/internal.h:  if (pte_swp_exclusive(pte))
mm/memory.c:            if (pte_swp_exclusive(orig_pte)) {
mm/memory.c:            exclusive = pte_swp_exclusive(vmf->orig_pte);
mm/swapfile.c:          if (pte_swp_exclusive(old_pte))
mm/userfaultfd.c:               if (!pte_swp_exclusive(orig_src_pte)) {

	Magnus posted patch of that form (see
https://lore.kernel.org/all/[email protected]/),
got no serious objections and then it went nowhere.

	Bug is real and fairly obvious, fix is entirely mechanical and
affects one line in each asm/pgtable.h out there.  Linus, could you
run that sed script just before -rc1?  Commit message from the patch refered
above looks sane:

mm: pgtable: fix pte_swp_exclusive

Make pte_swp_exclusive return bool instead of int. This will better reflect
how pte_swp_exclusive is actually used in the code. This fixes swap/swapoff
problems on Alpha due pte_swp_exclusive not returning correct values when
_PAGE_SWP_EXCLUSIVE bit resides in upper 32-bits of PTE (like on alpha).

Signed-off-by: Magnus Lindholm <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.