Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Chris Down <chris@chrisdown.name>
Cc: Matt Salsamendi <matthewsalsamendi@gmail.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	 Vlastimil Babka <vbabka@kernel.org>,
	Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>,
	 Muhammad Usama Anjum <usama.anjum@arm.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] fs/proc/task_mmu: fix stale walk_end after a completed scan
Date: Mon, 16 Nov 2026 15:38:09 +0000	[thread overview]
Message-ID: <avsjPSUup6pnsZrR@gremlin> (raw)
In-Reply-To: <20261112203351.7d5bf7d0f78d652d@chrisdown.name>

On Thu, Nov 12, 2026 at 08:33:51PM -0800, Chris Down wrote:
> Hi Matt,
>
> This patch doesn't apply as sent, because your mail client mangled it. It
> wrapped long lines, including the hunk header and the Fixes tag, and took
> the leading space off the blank context lines. git am rejects it as
> corrupt.
>
> Please send the next version with git send-email or b4 send rather than
> through Gmail, or set your client up as
> Documentation/process/email-clients.rst describes. It's worth sending it to
> yourself first and checking that git am takes it.
>
> Matt Salsamendi writes:
> > +	/* A completed walk may follow an earlier full bounce buffer. */
> > +	if (!ret || !p.arg.walk_end)
> > +		p.arg.walk_end = p.arg.end;
>
> While this fixes the refill case, ret being 0 doesn't always mean the walk
> got to the end of the range. pagemap_scan_hugetlb_entry() can't
> write-protect only part of a huge page. So with PM_SCAN_WP_MATCHING, when
> only part of a written huge page fits in what's left of max_pages, it backs
> that page out. It sets walk_end to the start of the page and returns 0 on
> purpose.
>
> Before this patch, the caller got walk_end pointing at that page. With it,
> walk_end comes back as end, so the caller is told the whole range was
> scanned. But the page was neither returned nor write-protected. From a
> quick test with a single written 2M hugetlb page, PM_SCAN_WP_MATCHING and
> max_pages = 1, the ioctl returns 0 with walk_end at the start of the page
> before this patch, and at the end of the range with it.
>
> Maybe it would be simpler to clear walk_end before each walk_page_range()
> call, and keep the existing check after the loop as it is? Then that check
> only sees what the last walk set. In the same quick test, that fixes the
> refill case too, and the hugetlb case behaves as it did before. It would be
> good for the selftest Andrew asked for to cover the hugetlb case as well.
>
> Thanks!
>
> Chris

Following on from Chris's comments, I think something like this should work
OK? It's also nicely simple :>) And obviously avoids the hugetlb stuff.

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 22361607020d..1b87cc635a34 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -3160,6 +3160,7 @@ static long do_pagemap_scan(struct mm_struct *mm, unsigned long uarg)
 			mmu_notifier_invalidate_range_start(&range);
 		}

+		p.arg.walk_end = 0; /* Reset partial walks. */
 		ret = walk_page_range(mm, walk_start, p.arg.end,
 				      &pagemap_scan_ops, &p);



--
Cheers, Lorenzo


      reply	other threads:[~2026-11-16 15:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 17:41 [PATCH] fs/proc/task_mmu: fix stale walk_end after a completed scan Matt Salsamendi
2026-11-13  1:05 ` Andrew Morton
2026-11-13  4:33 ` Chris Down
2026-11-16 15:38   ` Lorenzo Stoakes (ARM) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avsjPSUup6pnsZrR@gremlin \
    --to=ljs@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chris@chrisdown.name \
    --cc=jannh@google.com \
    --cc=liam@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthewsalsamendi@gmail.com \
    --cc=pfalcato@suse.de \
    --cc=usama.anjum@arm.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox