linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kairui Song <ryncsn@gmail.com>
To: SeongJae Park <sj@kernel.org>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	 "Huang, Ying" <ying.huang@intel.com>,
	Chris Li <chrisl@kernel.org>,  Minchan Kim <minchan@kernel.org>,
	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>,
	David Hildenbrand <david@redhat.com>, Yu Zhao <yuzhao@google.com>,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/swap: fix race condition in direct swapin path
Date: Tue, 6 Feb 2024 11:13:01 +0800	[thread overview]
Message-ID: <CAMgjq7BAOohAYpS3n3NFHcji-=oiydJJSO5oqerLqYJSVfCQ9w@mail.gmail.com> (raw)
In-Reply-To: <20240206022409.202536-1-sj@kernel.org>

On Tue, Feb 6, 2024 at 10:24 AM SeongJae Park <sj@kernel.org> wrote:
>
> Hi Kairui,
>
> On Mon,  5 Feb 2024 19:09:59 +0800 Kairui Song <ryncsn@gmail.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.


  reply	other threads:[~2024-02-06  3:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 11:09 Kairui Song
2024-02-05 12:25 ` Barry Song
2024-02-05 14:16   ` Kairui Song
2024-02-06  1:33 ` Huang, Ying
2024-02-06  3:21   ` Kairui Song
2024-02-06  2:24 ` SeongJae Park
2024-02-06  3:13   ` Kairui Song [this message]
2024-02-06  6:02 ` Yu Zhao
2024-02-06  7:38   ` Kairui Song

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='CAMgjq7BAOohAYpS3n3NFHcji-=oiydJJSO5oqerLqYJSVfCQ9w@mail.gmail.com' \
    --to=ryncsn@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=sj@kernel.org \
    --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