From: Andrew Morton <akpm@linux-foundation.org>
To: Kairui Song <kasong@tencent.com>
Cc: Kairui Song <ryncsn@gmail.com>,
linux-mm@kvack.org, "Huang, Ying" <ying.huang@intel.com>,
Chris Li <chrisl@kernel.org>, Minchan Kim <minchan@kernel.org>,
Barry Song <v-songbaohua@oppo.com>, Yu Zhao <yuzhao@google.com>,
SeongJae Park <sj@kernel.org>,
David Hildenbrand <david@redhat.com>,
Hugh Dickins <hughd@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Matthew Wilcox <willy@infradead.org>,
Michal Hocko <mhocko@suse.com>,
Yosry Ahmed <yosryahmed@google.com>,
Aaron Lu <aaron.lu@intel.com>,
stable@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] mm/swap: fix race when skipping swapcache
Date: Mon, 19 Feb 2024 17:31:47 -0800 [thread overview]
Message-ID: <20240219173147.3f4b50b7c9ae554008f50b66@linux-foundation.org> (raw)
In-Reply-To: <20240219082040.7495-1-ryncsn@gmail.com>
On Mon, 19 Feb 2024 16:20:40 +0800 Kairui Song <ryncsn@gmail.com> wrote:
> From: Kairui Song <kasong@tencent.com>
>
> When skipping swapcache for SWP_SYNCHRONOUS_IO, if two or more threads
> swapin the same entry at the same time, they get different pages (A, B).
> Before one thread (T0) finishes the swapin and installs page (A)
> to the PTE, another thread (T1) could finish swapin of page (B),
> swap_free the entry, then swap out the possibly modified page
> reusing the same entry. It breaks the pte_same check in (T0) because
> PTE value is unchanged, causing ABA problem. Thread (T0) will
> install a stalled page (A) into the PTE and cause data corruption.
>
> @@ -3867,6 +3868,20 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
> if (!folio) {
> if (data_race(si->flags & SWP_SYNCHRONOUS_IO) &&
> __swap_count(entry) == 1) {
> + /*
> + * Prevent parallel swapin from proceeding with
> + * the cache flag. Otherwise, another thread may
> + * finish swapin first, free the entry, and swapout
> + * reusing the same entry. It's undetectable as
> + * pte_same() returns true due to entry reuse.
> + */
> + if (swapcache_prepare(entry)) {
> + /* Relax a bit to prevent rapid repeated page faults */
> + schedule_timeout_uninterruptible(1);
Well this is unpleasant. How often can we expect this to occur?
> + goto out;
> + }
> + need_clear_cache = true;
> +
> /* skip swapcache */
> folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0,
> vma, vmf->address, false);
next prev parent reply other threads:[~2024-02-20 1:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 8:20 Kairui Song
2024-02-19 8:47 ` Huang, Ying
2024-02-19 9:02 ` David Hildenbrand
2024-02-19 16:37 ` Chris Li
2024-02-19 22:10 ` Barry Song
2024-02-20 1:09 ` Huang, Ying
2024-02-20 4:49 ` Chengming Zhou
2024-02-20 5:32 ` Kairui Song
2024-02-20 5:37 ` Chengming Zhou
2024-02-20 1:31 ` Andrew Morton [this message]
2024-02-20 3:42 ` Kairui Song
2024-02-20 4:01 ` Barry Song
2024-02-20 4:56 ` Kairui Song
2024-02-20 10:26 ` Barry Song
2024-02-20 16:32 ` Chris Li
2024-02-27 18:13 ` Kairui Song
2024-02-27 23:01 ` Chris Li
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=20240219173147.3f4b50b7c9ae554008f50b66@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aaron.lu@intel.com \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=ryncsn@gmail.com \
--cc=sj@kernel.org \
--cc=stable@vger.kernel.org \
--cc=v-songbaohua@oppo.com \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=yosryahmed@google.com \
--cc=yuzhao@google.com \
/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