Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hirotaka Yamagata" <hiro@pisnp.net>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: "Liam R. Howlett" <liam@infradead.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"David Hildenbrand" <david@kernel.org>,
	"Chris Li" <chrisl@kernel.org>,
	"Kairui Song" <kasong@tencent.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Hocko" <mhocko@kernel.org>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org,
	"John Stultz" <jstultz@google.com>,
	"Minchan Kim" <minchan@kernel.org>,
	"Alexandre Marciano Gimenez" <raging@google.com>,
	"Tatsuyuki Ishi" <ishitatsuyuki@google.com>,
	tj@kernel.org, mkoutny@suse.com
Subject: Re: [RFC PATCH v1 2/4] mm: add PTE_MARKER_PURGED and TTU_PURGE for purged volatile pages
Date: Tue, 01 Dec 2026 08:36:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-242854@kernel.org> (raw)
In-Reply-To: <20261130083407.2669584-3-hiro@pisnp.net>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm/rmap: missing vma_is_volatile() check under PTL in
  try_to_unmap_one()
--

commit 72bf3612b141f201ae09c715262c4297b55bbf46
Author: Hirotaka Yamagata <hiro@pisnp.net>

mm: add PTE_MARKER_PURGED and TTU_PURGE for purged volatile pages

This commit introduces the PTE_MARKER_PURGED marker and TTU_PURGE flag to
record when volatile anonymous pages are discarded under memory pressure.

> diff --git a/mm/rmap.c b/mm/rmap.c
> index d1819fd699380..a3273a9a7d22d 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -2359,6 +2359,20 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
>  			pteval = swp_entry_to_pte(make_hwpoison_entry(page));
>  			dec_mm_counter(mm, mm_counter(folio));
>  			set_pte_at(mm, address, pvmw.pte, pteval);
> +		} else if (flags & TTU_PURGE) {
> +			/*
> +			 * Like swap-out, back off if the page may be pinned.
> +			 * See folio_try_share_anon_rmap(): clear PTE first.
> +			 */
> +			if (PageAnonExclusive(page) &&
> +			    folio_try_share_anon_rmap_pte(folio, page)) {
> +				set_ptes(mm, address, pvmw.pte, pteval, nr_pages);
> +				goto walk_abort;
> +			}
> +			pteval = make_purged_entry();
> +			dec_mm_counter(mm, mm_counter(folio));
> +			set_pte_at(mm, address, pvmw.pte, pteval);
> +
>  		} else if (likely(pte_present(pteval)) && pte_unused(pteval) &&
>  			   !userfaultfd_armed(vma)) {
>  			/*

[Severity: High]
Can try_to_unmap_one() install a PTE_MARKER_PURGED entry into a VMA after
madvise(MADV_NONVOLATILE) has already cleared VMA_VOLATILE_BIT and scanned
its PTEs?

In the follow-up commit "mm/volatile: purge volatile anonymous folios
during reclaim", __purge_volatile_folio() checks vma_is_volatile(vma)
under the anon_vma read lock, drops that lock, and then calls
try_to_unmap(folio, TTU_PURGE | TTU_SYNC).  Meanwhile, madvise_volatile()
with MADV_NONVOLATILE clears VMA_VOLATILE_BIT without taking folio_lock
(or anon_vma->root->rwsem when no VMA split or merge is needed) and walks
the page tables under PTL:

CPU0 (reclaim)                    CPU1 (MADV_NONVOLATILE)
__purge_volatile_folio()
  folio_lock_anon_vma_read()
  vma_is_volatile(vma) == true
  anon_vma_unlock_read()
                                  madvise_volatile()
                                    vma_clear_flags(..., VMA_VOLATILE_BIT)
                                    mvolatile_check_purged()
                                      lock(ptl)
                                      /* sees present PTE, returns 0 */
                                      unlock(ptl)
  try_to_unmap(..., TTU_PURGE)
    try_to_unmap_one()
      lock(pvmw.ptl)
      set_pte_at(..., make_purged_entry())
                                  /* later access to non-volatile VMA */
                                  handle_pte_marker()  <-- unexpected SIGBUS

Because try_to_unmap_one() does not recheck vma_is_volatile(vma) after
acquiring pvmw.ptl, MADV_NONVOLATILE reports that no pages were purged
while the page is discarded right afterward, causing later accesses to the
non-volatile mapping to raise SIGBUS.  Checking !vma_is_volatile(vma) under
pvmw.ptl in the TTU_PURGE branch (restoring the PTE and aborting the walk)
would close the race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130083407.2669584-1-hiro@pisnp.net?part=2

  reply	other threads:[~2026-12-01  8:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  8:34 [RFC PATCH v1 0/4] mm: port MADV_VOLATILE and MADV_NONVOLATILE to v7.3-rc1 Hirotaka Yamagata
2026-11-30  8:34 ` [RFC PATCH v1 1/4] mm: introduce VM_VOLATILE and MADV_VOLATILE/MADV_NONVOLATILE VMA handling Hirotaka Yamagata
2026-12-01  8:36   ` sashiko-bot
2026-11-30  8:34 ` [RFC PATCH v1 2/4] mm: add PTE_MARKER_PURGED and TTU_PURGE for purged volatile pages Hirotaka Yamagata
2026-12-01  8:36   ` sashiko-bot [this message]
2026-11-30  8:34 ` [RFC PATCH v1 3/4] mm/volatile: purge volatile anonymous folios during reclaim Hirotaka Yamagata
2026-12-01  8:36   ` sashiko-bot
2026-11-30  8:34 ` [RFC PATCH v1 4/4] mm/volatile: add PGPURGE vmstat counter and purge tracepoint Hirotaka Yamagata
2026-12-01  8:36   ` sashiko-bot
2026-11-30 10:39 ` [RFC PATCH v1 0/4] mm: port MADV_VOLATILE and MADV_NONVOLATILE to v7.3-rc1 David Hildenbrand (Arm)
2026-11-30 18:18   ` Lorenzo Stoakes (ARM)

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=sashiko-outbox-242854@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hiro@pisnp.net \
    --cc=ishitatsuyuki@google.com \
    --cc=jstultz@google.com \
    --cc=kasong@tencent.com \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=minchan@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=raging@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@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