From: Oliver Sang <oliver.sang@intel.com>
To: Dennis Zhou <dennis@kernel.org>
Cc: "Boqun Feng" <boqun.feng@gmail.com>, "Tejun Heo" <tj@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
oe-lkp@lists.linux.dev, lkp@intel.com,
linux-kernel@vger.kernel.org,
"Andrew Morton" <akpm@linux-foundation.org>,
"Kent Overstreet" <kent.overstreet@linux.dev>,
"Kees Cook" <keescook@chromium.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Christoph Lameter" <cl@linux.com>, "Gary Guo" <gary@garyguo.net>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Pasha Tatashin" <pasha.tatashin@soleen.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
linux-mm@kvack.org, lkmm@lists.linux.dev, oliver.sang@intel.com
Subject: Re: [linus:master] [mm] 24e44cc22a: BUG:KCSAN:data-race_in_pcpu_alloc_noprof/pcpu_block_update_hint_alloc
Date: Wed, 24 Jul 2024 15:10:36 +0800 [thread overview]
Message-ID: <ZqCo7H2gcA1dvIr4@xsang-OptiPlex-9020> (raw)
In-Reply-To: <Zp9J9t-KP17P-OFR@snowbird>
hi, Dannis,
On Mon, Jul 22, 2024 at 11:13:10PM -0700, Dennis Zhou wrote:
> Hi Oliver,
>
> On Tue, Jul 23, 2024 at 02:09:38PM +0800, Oliver Sang wrote:
> > hi, Dennis Zhou,
> >
> > On Mon, Jul 22, 2024 at 10:50:53PM -0700, Dennis Zhou wrote:
> > > On Mon, Jul 22, 2024 at 01:53:52PM -0700, Boqun Feng wrote:
> > > > On Mon, Jul 22, 2024 at 11:27:48AM -0700, Dennis Zhou wrote:
> > > > > Hello,
> > > > >
> > > > > On Mon, Jul 22, 2024 at 11:03:00AM -0700, Boqun Feng wrote:
> > > > > > On Mon, Jul 22, 2024 at 07:52:22AM -1000, Tejun Heo wrote:
> > > > > > > On Mon, Jul 22, 2024 at 10:47:30AM -0700, Boqun Feng wrote:
> > > > > > > > This looks like a data race because we read pcpu_nr_empty_pop_pages out
> > > > > > > > of the lock for a best effort checking, @Tejun, maybe you could confirm
> > > > > > > > on this?
> > > > > > >
> > > > > > > That does sound plausible.
> > > > > > >
> > > > > > > > - if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW)
> > > > > > > > + /*
> > > > > > > > + * Checks pcpu_nr_empty_pop_pages out of the pcpu_lock, data races may
> > > > > > > > + * occur but this is just a best-effort checking, everything is synced
> > > > > > > > + * in pcpu_balance_work.
> > > > > > > > + */
> > > > > > > > + if (data_race(pcpu_nr_empty_pop_pages) < PCPU_EMPTY_POP_PAGES_LOW)
> > > > > > > > pcpu_schedule_balance_work();
> > > > > > >
> > > > > > > Would it be better to use READ/WRITE_ONCE() for the variable?
> > > > > > >
> > > > > >
> > > > > > For READ/WRITE_ONCE(), we will need to replace all write accesses and
> > > > > > all out-of-lock read accesses to pcpu_nr_empty_pop_pages, like below.
> > > > > > It's better in the sense that it doesn't rely on compiler behaviors on
> > > > > > data races, not sure about the performance impact though.
> > > > > >
> > > > >
> > > > > I think a better alternative is we can move it up into the lock under
> > > > > area_found. The value gets updated as part of pcpu_alloc_area() as the
> > > > > code above populates percpu memory that is already allocated.
> > > > >
> > > >
> > > > Not sure I followed what exactly you suggested here because I'm not
> > > > familiar with the logic, but a simpler version would be:
> > > >
> > > >
> > >
> > > I believe that's the only naked access of pcpu_nr_empty_pop_pages. So
> > > I was thinking this'll fix this problem.
> > >
> > > I also don't know how to rerun this CI tho..
> >
> > we could test this patch. what's the base? could we apply it directly upon
> > 24e44cc22a?
> >
> > BTW, our bot is not so clever so far to auto test fix patches, so this is kind
> > of manual effort. due to resource constraint, it will be hard for us to test
> > each patch (we saw several patches in this thread already) or test very fast.
> >
>
> Ah yeah that makes sense. If you don't mind testing the last one I sent,
> the one below, that applies cleanly to 24e44cc22a.
in our tests, you patch could solve the KCSAN issues. thanks
=========================================================================================
compiler/group/kconfig/nr_groups/rootfs/runtime/tbox_group/testcase:
gcc-13/group-04/x86_64-randconfig-013-20240713/5/debian-11.1-i386-20220923.cgz/300s/vm-snb/trinity
commit:
60fa4a9e23231 ("mm: percpu: add codetag reference into pcpuobj_ext")
24e44cc22aa31 ("mm: percpu: enable per-cpu allocation tagging")
dcfbb68202759 <--- your patch
60fa4a9e23231721 24e44cc22aa3112082f2ee23137 dcfbb6820275994e92a9dcf309e
---------------- --------------------------- ---------------------------
fail:runs %reproduction fail:runs %reproduction fail:runs
| | | | |
281:999 -28% :998 -28% :999 dmesg.BUG:KCSAN:data-race_in_pcpu_alloc/pcpu_block_update_hint_alloc
296:999 -30% :998 -30% :999 dmesg.BUG:KCSAN:data-race_in_pcpu_alloc/pcpu_block_update_hint_free
25:999 -3% :998 -3% :999 dmesg.BUG:KCSAN:data-race_in_pcpu_alloc/pcpu_chunk_populated
:999 29% 292:998 0% :999 dmesg.BUG:KCSAN:data-race_in_pcpu_alloc_noprof/pcpu_block_update_hint_alloc
:999 27% 269:998 0% :999 dmesg.BUG:KCSAN:data-race_in_pcpu_alloc_noprof/pcpu_block_update_hint_free
:999 4% 44:998 0% :999 dmesg.BUG:KCSAN:data-race_in_pcpu_alloc_noprof/pcpu_chunk_populated
>
> Thanks,
> Dennis
>
> > >
> > > ---
> > > diff --git a/mm/percpu.c b/mm/percpu.c
> > > index 20d91af8c033..325fb8412e90 100644
> > > --- a/mm/percpu.c
> > > +++ b/mm/percpu.c
> > > @@ -1864,6 +1864,10 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
> > >
> > > area_found:
> > > pcpu_stats_area_alloc(chunk, size);
> > > +
> > > + if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW)
> > > + pcpu_schedule_balance_work();
> > > +
> > > spin_unlock_irqrestore(&pcpu_lock, flags);
> > >
> > > /* populate if not all pages are already there */
> > > @@ -1891,9 +1895,6 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved,
> > > mutex_unlock(&pcpu_alloc_mutex);
> > > }
> > >
> > > - if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_LOW)
> > > - pcpu_schedule_balance_work();
> > > -
> > > /* clear the areas and return address relative to base address */
> > > for_each_possible_cpu(cpu)
> > > memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);
next prev parent reply other threads:[~2024-07-24 7:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-22 7:30 kernel test robot
2024-07-22 17:47 ` Boqun Feng
2024-07-22 17:52 ` Tejun Heo
2024-07-22 18:03 ` Boqun Feng
2024-07-22 18:15 ` Tejun Heo
2024-07-22 18:27 ` Dennis Zhou
2024-07-22 20:53 ` Boqun Feng
2024-07-23 5:50 ` Dennis Zhou
2024-07-23 6:09 ` Oliver Sang
2024-07-23 6:13 ` Dennis Zhou
2024-07-24 7:10 ` Oliver Sang [this message]
2024-07-23 21:14 ` Boqun Feng
2024-07-27 3:15 ` Dennis Zhou
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=ZqCo7H2gcA1dvIr4@xsang-OptiPlex-9020 \
--to=oliver.sang@intel.com \
--cc=a.hindborg@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=gary@garyguo.net \
--cc=keescook@chromium.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lkmm@lists.linux.dev \
--cc=lkp@intel.com \
--cc=oe-lkp@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=pasha.tatashin@soleen.com \
--cc=peterz@infradead.org \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=wedsonaf@gmail.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