linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: Dev Jain <dev.jain@arm.com>
Cc: akpm@linux-foundation.org, david@kernel.org,
	lorenzo.stoakes@oracle.com,  riel@surriel.com,
	Liam.Howlett@oracle.com, vbabka@kernel.org,
	 harry.yoo@oracle.com, jannh@google.com, linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org, ryan.roberts@arm.com,
	anshuman.khandual@arm.com,  stable <stable@kernel.org>
Subject: Re: [PATCH v2] mm/rmap: fix incorrect pte restoration for lazyfree folios
Date: Mon, 2 Mar 2026 14:37:11 +0800	[thread overview]
Message-ID: <CAGsJ_4w6dT61CSgR5bdnr_xOdgENK8uB9otShJR6_eE2NyPAfg@mail.gmail.com> (raw)
In-Reply-To: <1709a9c1-628d-4cf1-bbc6-00b77fe70f3f@arm.com>

On Mon, Mar 2, 2026 at 12:26 PM Dev Jain <dev.jain@arm.com> wrote:
[...]
> >>
> >> diff --git a/mm/rmap.c b/mm/rmap.c
> >> index bff8f222004e4..fb64829913052 100644
> >> --- a/mm/rmap.c
> >> +++ b/mm/rmap.c
> >> @@ -1955,7 +1955,17 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
> >>         if (userfaultfd_wp(vma))
> >>                 return 1;
> >>
> >> -       return folio_pte_batch(folio, pvmw->pte, pte, max_nr);
> >> +       if (!folio_test_anon(folio))
> >> +               return folio_pte_batch(folio, pvmw->pte, pte, max_nr);
> >> +
> >> +       /*
> >> +        * For anon folios, if unmap fails, we need to restore the ptes.
> >> +        * To avoid accidentally upgrading write permissions for ptes that
> >> +        * were not originally writable, and to avoid losing the soft-dirty
> >> +        * bit, use the appropriate FPB flags.
> >> +        */
> >> +       return folio_pte_batch_flags(folio, vma, pvmw->pte, &pte, max_nr,
> >> +                                    FPB_RESPECT_WRITE | FPB_RESPECT_SOFT_DIRTY);
> >
> > Do we really need to differentiate between file and anon?
> > I’d rather just return unconditionally by removing the
> > if (!folio_test_anon(folio)) check above.
>
> File mappings don't need preservation of writable bit. I really think
> we should differentiate this. It improves understanding of code by
> telling the reader that after clearing ptes for file mappings and
> losing the writable bit, the correctness is ensured in the fault handler.

I understand this is the case for file-backed folios in
the unmap path. However, I’d prefer to keep things
simple. If file folios with inconsistent PTEs account
for only a very small proportion, it may not be worth
worrying about.

On the other hand, when we extend the current batching
code to try_to_migrate_one(), the situation could be
different from the unmap path.

Anyway, I don’t feel strongly about this. If you, David,
Lorenzo, and others think it’s better to differentiate
between file and anon, I’m fine with that.

> >
> > If we do want to keep two branches, why not use a flag variant instead?
> >
> > flag = 0;
> >
> > /* for anon folios .... */
> > if (folio_test_anon(folio))
> >                flag = FPB_RESPECT_WRITE | FPB_RESPECT_SOFT_DIRTY;
> > return folio_pte_batch_flags(...., flag);
>
> Yep this is better.

Yep, that would be more readable, as it makes it clear
that the difference is the flag.

Thanks
Barry


  reply	other threads:[~2026-03-02  6:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28 14:05 Dev Jain
2026-02-28 18:34 ` Barry Song
2026-03-02  4:26   ` Dev Jain
2026-03-02  6:37     ` Barry Song [this message]
2026-03-02  8:44   ` David Hildenbrand (Arm)
2026-03-02  9:06     ` Dev Jain

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=CAGsJ_4w6dT61CSgR5bdnr_xOdgENK8uB9otShJR6_eE2NyPAfg@mail.gmail.com \
    --to=21cnbao@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=harry.yoo@oracle.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=riel@surriel.com \
    --cc=ryan.roberts@arm.com \
    --cc=stable@kernel.org \
    --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