From: "Christoph Lameter (Ampere)" <cl@gentwo.org>
To: Vlad Dumitrescu <vdumitrescu@nvidia.com>
Cc: Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
Baoquan He <bhe@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] percpu: fix race on alloc failed warning limit
Date: Tue, 2 Sep 2025 14:41:12 -0700 (PDT) [thread overview]
Message-ID: <070d9527-0852-e71b-78db-bd9768ba7525@gentwo.org> (raw)
In-Reply-To: <84bbc996-27c7-4f83-a8c2-4f88b439bd23@nvidia.com>
On Tue, 2 Sep 2025, Vlad Dumitrescu wrote:
> On 9/2/25 10:39, Christoph Lameter (Ampere) wrote:
> > On Fri, 22 Aug 2025, Vlad Dumitrescu wrote:
> >
> >> + if (do_warn && atomic_read(&warn_limit) > 0) {
> >> + int remaining = atomic_dec_return(&warn_limit);
> >
> >
> > The code creates a race condition since another atomic_dec_return() can
> > happen on another cpu between these two lines. warn_limit can go negative.
>
> Yes, which is why I mentioned it in the description. But compared to before,
> it should be benign.
>
> > Use a single atomic operation instead?
>
> Did you have something like this in mind?
>
> - if (do_warn && atomic_read(&warn_limit) > 0) {
> - int remaining = atomic_dec_return(&warn_limit);
> + if (do_warn) {
> + int remaining = atomic_dec_if_positive(&warn_limit);
Something like it... Maybe
if (do_warn && (atomic_dec_if_positive(&warn_limit)) ) {
pr_warn ...
}
prev parent reply other threads:[~2025-09-02 21:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 22:55 Vlad Dumitrescu
2025-08-24 3:07 ` Baoquan He
2025-09-02 17:39 ` Christoph Lameter (Ampere)
2025-09-02 21:06 ` Vlad Dumitrescu
2025-09-02 21:41 ` Christoph Lameter (Ampere) [this message]
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=070d9527-0852-e71b-78db-bd9768ba7525@gentwo.org \
--to=cl@gentwo.org \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=dennis@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tj@kernel.org \
--cc=vdumitrescu@nvidia.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