From: Marco Elver <elver@google.com>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Qian Cai <cai@lca.pw>, Dmitry Vyukov <dvyukov@google.com>,
Michal Hocko <mhocko@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Linux Memory Management List <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm/page_counter: fix various data races
Date: Wed, 29 Jan 2020 13:21:49 +0100 [thread overview]
Message-ID: <CANpmjNOdFsU9gg7FSv7Pue0L2eAQ+5UHHaz9bgZ83r94prA4vQ@mail.gmail.com> (raw)
In-Reply-To: <59f892d0-5fc4-ae32-ce65-5a688d9180c8@I-love.SAKURA.ne.jp>
On Wed, 29 Jan 2020 at 13:13, Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
>
> On 2020/01/29 21:03, Michal Hocko wrote:
> >> Fixes: 3e32cb2e0a12 ("mm: memcontrol: lockless page counters")
> >> Signed-off-by: Qian Cai <cai@lca.pw>
> >
> > Acked-by: Michal Hocko <mhocko@suse.com>
>
> Please include
>
> Reported-by: syzbot+f36cfe60b1006a94f9dc@syzkaller.appspotmail.com
>
> for https://syzkaller.appspot.com/bug?id=744097b8b91cecd8b035a6f746bb12e4efc7669f .
>
> By the way, can READ_ONCE()/WRITE_ONCE() really solve this warning?
> The link above says read/write on the same location ( mm/page_counter.c:129 ).
> I don't know how READ_ONCE()/WRITE_ONCE() can solve the race.
It avoids the *data* race, with *_ONCE telling the compiler to not
optimize the accesses in concurrency-unfriendly ways. Since *_ONCE is
used, it conveys clear intent that the code here is meant to be
concurrent, and KCSAN stops complaining (and assumes that the *logic*
is correct).
The race itself is still there, but as per comment in the file,
apparently fine and not a logic bug.
> >
> >> ---
> >> mm/page_counter.c | 8 ++++----
> >> 1 file changed, 4 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/mm/page_counter.c b/mm/page_counter.c
> >> index de31470655f6..a17841150906 100644
> >> --- a/mm/page_counter.c
> >> +++ b/mm/page_counter.c
> >> @@ -82,8 +82,8 @@ void page_counter_charge(struct page_counter *counter, unsigned long nr_pages)
> >> * This is indeed racy, but we can live with some
> >> * inaccuracy in the watermark.
> >> */
> >> - if (new > c->watermark)
> >> - c->watermark = new;
> >> + if (new > READ_ONCE(c->watermark))
> >> + WRITE_ONCE(c->watermark, new);
> >> }
> >> }
> >>
> >> @@ -135,8 +135,8 @@ bool page_counter_try_charge(struct page_counter *counter,
> >> * Just like with failcnt, we can live with some
> >> * inaccuracy in the watermark.
> >> */
> >> - if (new > c->watermark)
> >> - c->watermark = new;
> >> + if (new > READ_ONCE(c->watermark))
> >> + WRITE_ONCE(c->watermark, new);
> >> }
> >> return true;
> >>
> >> --
> >> 2.21.0 (Apple Git-122.2)
> >
>
next prev parent reply other threads:[~2020-01-29 12:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-29 10:52 Qian Cai
2020-01-29 10:57 ` David Hildenbrand
2020-01-29 10:58 ` David Hildenbrand
2020-01-29 12:03 ` Michal Hocko
2020-01-29 12:13 ` Tetsuo Handa
2020-01-29 12:21 ` Marco Elver [this message]
2020-01-29 13:47 ` Tetsuo Handa
2020-01-29 12:25 ` Qian Cai
2020-01-29 13:09 ` Tetsuo Handa
2020-02-11 12:14 ` Qian Cai
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=CANpmjNOdFsU9gg7FSv7Pue0L2eAQ+5UHHaz9bgZ83r94prA4vQ@mail.gmail.com \
--to=elver@google.com \
--cc=akpm@linux-foundation.org \
--cc=cai@lca.pw \
--cc=dvyukov@google.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
/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