[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMgjq7BAOohAYpS3n3NFHcji-=oiydJJSO5oqerLqYJSVfCQ9w@mail.gmail.com>
Date: Tue, 6 Feb 2024 11:13:01 +0800
From: Kairui Song <ryncsn@...il.com>
To: SeongJae Park <sj@...nel.org>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
"Huang, Ying" <ying.huang@...el.com>, Chris Li <chrisl@...nel.org>,
Minchan Kim <minchan@...nel.org>, Hugh Dickins <hughd@...gle.com>,
Johannes Weiner <hannes@...xchg.org>, Matthew Wilcox <willy@...radead.org>, Michal Hocko <mhocko@...e.com>,
Yosry Ahmed <yosryahmed@...gle.com>, David Hildenbrand <david@...hat.com>, Yu Zhao <yuzhao@...gle.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm/swap: fix race condition in direct swapin path
On Tue, Feb 6, 2024 at 10:24 AM SeongJae Park <sj@...nel.org> wrote:
>
> Hi Kairui,
>
> On Mon, 5 Feb 2024 19:09:59 +0800 Kairui Song <ryncsn@...il.com> wrote:
>
> [...]
> > mm/memory.c | 19 +++++++++++++++++++
> > mm/swap.h | 5 +++++
> > mm/swapfile.c | 16 ++++++++++++++++
> > 3 files changed, 40 insertions(+)
> >
> > diff --git a/mm/memory.c b/mm/memory.c
> > index 7e1f4849463a..fd7c55a292f1 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -3867,6 +3867,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) {
> > + /*
> > + * With swap count == 1, after we read the entry,
> > + * other threads could finish swapin first, free
> > + * the entry, then swapout the modified page using
> > + * the same entry. Now the content we just read is
> > + * stalled, and it's undetectable as pte_same()
> > + * returns true due to entry reuse.
> > + *
> > + * So pin the swap entry using the cache flag even
> > + * cache is not used.
> > + */
> > + if (swapcache_prepare(entry))
> > + goto out;
> > +
>
> I'm getting below build error after this patch. I guess maybe the code need to
> take care of CONFIG_SWAP unset case?
>
> .../mm/memory.c: In function 'do_swap_page':
> .../mm/memory.c:4004:8: error: implicit declaration of function 'swapcache_prepare'; did you mean 'swapcache_clear'? [-Werror=implicit-function-declaration]
> 4004 | if (swapcache_prepare(entry))
> | ^~~~~~~~~~~~~~~~~
> | swapcache_clear
>
>
Ah, right. Thanks for the feedback.
For the CONFIG_SWAP unset case I added an empty function for
swapcache_clear, but the original swapcache_prepare also needs an
empty placeholder now. Will add that in V2.
Powered by blists - more mailing lists