From: Andrea Parri <parri.andrea@gmail.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
Will Deacon <will@kernel.org>, Marco Elver <elver@google.com>,
kasan-dev <kasan-dev@googlegroups.com>,
LKML <linux-kernel@vger.kernel.org>,
Andrey Konovalov <andreyknvl@google.com>,
Alexander Potapenko <glider@google.com>,
"Paul E. McKenney" <paulmck@linux.ibm.com>,
Paul Turner <pjt@google.com>, Daniel Axtens <dja@axtens.net>,
Anatol Pomazau <anatol@google.com>,
Alan Stern <stern@rowland.harvard.edu>,
LKMM Maintainers -- Akira Yokosawa <akiyks@gmail.com>,
Nicholas Piggin <npiggin@gmail.com>,
Boqun Feng <boqun.feng@gmail.com>,
Daniel Lustig <dlustig@nvidia.com>,
Jade Alglave <j.alglave@ucl.ac.uk>,
Luc Maranget <luc.maranget@inria.fr>
Subject: Re: Kernel Concurrency Sanitizer (KCSAN)
Date: Wed, 9 Oct 2019 22:17:06 +0200 [thread overview]
Message-ID: <20191009201706.GA3755@andrea> (raw)
In-Reply-To: <CACT4Y+Z+rX_cvDLwkzCvmudR6brCNM-8yA+hx9V6nXe159tf6A@mail.gmail.com>
On Wed, Oct 09, 2019 at 09:45:50AM +0200, Dmitry Vyukov wrote:
> On Sat, Oct 5, 2019 at 6:16 AM Dmitry Vyukov <dvyukov@google.com> wrote:
> >
> > On Sat, Oct 5, 2019 at 2:58 AM Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > > > This one is tricky. What I think we need to avoid is an onslaught of
> > > > patches adding READ_ONCE/WRITE_ONCE without a concrete analysis of the
> > > > code being modified. My worry is that Joe Developer is eager to get their
> > > > first patch into the kernel, so runs this tool and starts spamming
> > > > maintainers with these things to the point that they start ignoring KCSAN
> > > > reports altogether because of the time they take up.
> > > >
> > > > I suppose one thing we could do is to require each new READ_ONCE/WRITE_ONCE
> > > > to have a comment describing the racy access, a bit like we do for memory
> > > > barriers. Another possibility would be to use atomic_t more widely if
> > > > there is genuine concurrency involved.
> > > >
> > >
> > > About READ_ONCE() and WRITE_ONCE(), we will probably need
> > >
> > > ADD_ONCE(var, value) for arches that can implement the RMW in a single instruction.
> > >
> > > WRITE_ONCE(var, var + value) does not look pretty, and increases register pressure.
> >
> > FWIW modern compilers can handle this if we tell them what we are trying to do:
> >
> > void foo(int *p, int x)
> > {
> > x += __atomic_load_n(p, __ATOMIC_RELAXED);
> > __atomic_store_n(p, x, __ATOMIC_RELAXED);
> > }
> >
> > $ clang test.c -c -O2 && objdump -d test.o
> >
> > 0000000000000000 <foo>:
> > 0: 01 37 add %esi,(%rdi)
> > 2: c3 retq
> >
> > We can have syntactic sugar on top of this of course.
>
> An interesting precedent come up in another KCSAN bug report. Namely,
> it may be reasonable for a compiler to use different optimization
> heuristics for concurrent and non-concurrent code. Consider there are
> some legal code transformations, but it's unclear if they are
> profitable or not. It may be the case that for non-concurrent code the
> expectation is that it's a profitable transformation, but for
> concurrent code it is not. So that may be another reason to
> communicate to compiler what we want to do, rather than trying to
> trick and play against each other. I've added the concrete example
> here:
> https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE#it-may-improve-performance
Unrelated, but maybe worth pointing out/for reference: I think that
the section discussing the LKMM,
https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE#it-is-required-for-kernel-memory-model ,
might benefit from a revision/an update, in particular, the statement
"The Kernel Memory Consistency Model requires marking of all shared
accesses" seems now quite inaccurate to me, c.f., e.g.,
d1a84ab190137 ("tools/memory-model: Add definitions of plain and marked accesses")
0031e38adf387 ("tools/memory-model: Add data-race detection")
and
https://lkml.kernel.org/r/Pine.LNX.4.44L0.1910011338240.1991-100000@iolanthe.rowland.org .
Thanks,
Andrea
next prev parent reply other threads:[~2019-10-09 20:17 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-20 14:18 Kernel Concurrency Sanitizer (KCSAN) Marco Elver
2019-09-20 15:54 ` Will Deacon
2019-09-20 17:50 ` Marco Elver
2019-09-23 4:31 ` Boqun Feng
2019-09-23 8:21 ` Dmitry Vyukov
2019-09-23 8:54 ` Boqun Feng
2019-09-23 8:59 ` Dmitry Vyukov
2019-09-23 11:01 ` Marco Elver
2019-09-23 12:32 ` Boqun Feng
2019-10-05 0:58 ` Eric Dumazet
2019-10-05 4:16 ` Dmitry Vyukov
2019-10-09 7:45 ` Dmitry Vyukov
2019-10-09 16:39 ` Eric Dumazet
2019-10-09 20:17 ` Andrea Parri [this message]
2019-09-20 16:31 ` Mark Rutland
2019-09-20 16:46 ` Dmitry Vyukov
2019-09-20 17:51 ` Marco Elver
2019-10-03 16:12 ` Mark Rutland
2019-10-03 19:27 ` Marco Elver
2019-10-01 14:50 ` Daniel Axtens
2019-10-02 19:42 ` Marco Elver
2019-10-11 3:45 ` Daniel Axtens
2019-10-01 21:19 ` Joel Fernandes
2019-10-02 19:51 ` Marco Elver
2019-10-03 13:13 ` Dmitry Vyukov
2019-10-03 16:00 ` Dmitry Vyukov
2019-10-03 19:39 ` Christian Brauner
2019-10-04 16:48 ` Joel Fernandes
2019-10-04 16:52 ` Dmitry Vyukov
2019-10-04 16:57 ` Joel Fernandes
2019-10-04 17:01 ` Dmitry Vyukov
2019-10-04 18:08 ` Joel Fernandes
2019-10-04 18:28 ` Dmitry Vyukov
[not found] ` <CADyx2V6j+do+CmmSYEUr0iP7TUWD7xHLP2ZJPrqB1Y+QEAwzhw@mail.gmail.com>
2019-12-12 20:53 ` Marco Elver
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=20191009201706.GA3755@andrea \
--to=parri.andrea@gmail.com \
--cc=akiyks@gmail.com \
--cc=anatol@google.com \
--cc=andreyknvl@google.com \
--cc=boqun.feng@gmail.com \
--cc=dja@axtens.net \
--cc=dlustig@nvidia.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=eric.dumazet@gmail.com \
--cc=glider@google.com \
--cc=j.alglave@ucl.ac.uk \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luc.maranget@inria.fr \
--cc=npiggin@gmail.com \
--cc=paulmck@linux.ibm.com \
--cc=pjt@google.com \
--cc=stern@rowland.harvard.edu \
--cc=will@kernel.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