[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <070d9527-0852-e71b-78db-bd9768ba7525@gentwo.org>
Date: Tue, 2 Sep 2025 14:41:12 -0700 (PDT)
From: "Christoph Lameter (Ampere)" <cl@...two.org>
To: Vlad Dumitrescu <vdumitrescu@...dia.com>
cc: Dennis Zhou <dennis@...nel.org>, Tejun Heo <tj@...nel.org>,
Baoquan He <bhe@...hat.com>, Andrew Morton <akpm@...ux-foundation.org>,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] percpu: fix race on alloc failed warning limit
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 ...
}
Powered by blists - more mailing lists