linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jeongjun Park <aha310510@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: akpm@linux-foundation.org, kasong@tencent.com,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	 syzbot+fa43f1b63e3aa6f66329@syzkaller.appspotmail.com
Subject: Re: [PATCH] mm: swap: prevent possible data-race in __try_to_reclaim_swap
Date: Fri, 4 Oct 2024 23:50:12 +0900	[thread overview]
Message-ID: <CAO9qdTEZW74N_XDM0N1UkRy9BfrKE1SL-S4h2bvtEJ9QROTETA@mail.gmail.com> (raw)
In-Reply-To: <Zv_87TBZnh2lIwyH@casper.infradead.org>

Matthew Wilcox <willy@infradead.org> wrote:
>
> On Fri, Oct 04, 2024 at 11:25:04PM +0900, Jeongjun Park wrote:
> > A report [1] was uploaded from syzbot.
> >
> > In the previous commit 862590ac3708 ("mm: swap: allow cache reclaim to skip
> > slot cache"), the __try_to_reclaim_swap() function reads offset and nr_pages
> > from folio without folio_lock protection.
>
> Umm.  You don't need folio_lock to read nr_pages.  Holding a refcount
> is sufficient to stabilise nr_pages.  I cannot speak to folio->swap
> though (and the KCSAN report does appear to be pointing to folio->swap).
>

That's right. It looks like KCSAN log occurs when reading folio->swap.
In fact, since most of the code reads folio->swap under the protection
of folio_lock, it is possible to modify only the part that reads folio->swap
and the code that reads offset to operate under the protection of
folio_lock.

However, even if reading nr_pages does not require folio_lock, I don't
think it is very desirable to modify only this code to not be protected
by folio_lock.

Regards,
Jeongjun Park


  reply	other threads:[~2024-10-04 14:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-04 14:25 Jeongjun Park
2024-10-04 14:34 ` Matthew Wilcox
2024-10-04 14:50   ` Jeongjun Park [this message]
2024-10-06 20:15 ` Kairui Song
2024-10-07  0:49   ` Jeongjun Park
2024-10-07  5:06 ` kernel test robot
2024-10-08  1:30   ` Andrew Morton
2024-10-08  2:35     ` Jeongjun Park

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=CAO9qdTEZW74N_XDM0N1UkRy9BfrKE1SL-S4h2bvtEJ9QROTETA@mail.gmail.com \
    --to=aha310510@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=syzbot+fa43f1b63e3aa6f66329@syzkaller.appspotmail.com \
    --cc=willy@infradead.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