From: Steven Rostedt <rostedt@goodmis.org>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Jason Baron <jbaron@akamai.com>,
Sam Sun <samsun1006219@gmail.com>,
linux-kernel@vger.kernel.org, syzkaller@googlegroups.com,
xrivendell7@gmail.com, ardb@kernel.org, peterz@infradead.org,
linux-mm@kvack.org, akpm@linux-foundation.org,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Bug] WARNING in static_key_disable_cpuslocked
Date: Wed, 6 Mar 2024 21:34:53 -0500 [thread overview]
Message-ID: <20240306213453.72f9a925@gandalf.local.home> (raw)
In-Reply-To: <20240307013009.erbnug2mopx5yrnf@treble>
On Wed, 6 Mar 2024 17:30:09 -0800
Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> So, I think we can simplify this nicely by getting rid of the whole -1
> thing altogether:
>
> diff --git a/kernel/jump_label.c b/kernel/jump_label.c
> index d9c822bbffb8..ef7eda7685b2 100644
> --- a/kernel/jump_label.c
> +++ b/kernel/jump_label.c
> @@ -194,20 +194,15 @@ void static_key_enable_cpuslocked(struct static_key *key)
> STATIC_KEY_CHECK_USE(key);
> lockdep_assert_cpus_held();
>
> - if (atomic_read(&key->enabled) > 0) {
> - WARN_ON_ONCE(atomic_read(&key->enabled) != 1);
> + if (atomic_read(&key->enabled) == 1)
> return;
> - }
> -
> jump_label_lock();
> - if (atomic_read(&key->enabled) == 0) {
> - atomic_set(&key->enabled, -1);
> +
> + if (atomic_cmpxchg(&key->enabled, 0, 1) == 0)
> jump_label_update(key);
> - /*
> - * See static_key_slow_inc().
> - */
> - atomic_set_release(&key->enabled, 1);
> - }
> + else
> + WARN_ON_ONCE(atomic_read(&key->enabled) != 1);
> +
> jump_label_unlock();
You may be able to clean it up more with:
int tmp;
tmp = atomic_read(&key->enabled);
if (tmp == 1)
return;
jump_label_lock();
if (!tmp && atomic_try_cmpxchg(&key->enabled, &tmp, 1))
jump_label_update(key);
else
WARN_ON_ONCE(tmp != 1);
jump_label_unlock();
;-)
-- Steve
> }
> EXPORT_SYMBOL_GPL(static_key_enable_cpuslocked);
> @@ -225,14 +220,16 @@ void static_key_disable_cpuslocked(struct static_key *key)
> STATIC_KEY_CHECK_USE(key);
> lockdep_assert_cpus_held();
>
> - if (atomic_read(&key->enabled) != 1) {
> - WARN_ON_ONCE(atomic_read(&key->enabled) != 0);
> + if (atomic_read(&key->enabled) == 0)
> return;
> - }
>
> jump_label_lock();
> - if (atomic_cmpxchg(&key->enabled, 1, 0))
> +
> + if (atomic_cmpxchg(&key->enabled, 1, 0) == 1)
> jump_label_update(key);
> + else
> + WARN_ON_ONCE(atomic_read(&key->enabled) != 0);
> +
> jump_label_unlock();
> }
> EXPORT_SYMBOL_GPL(static_key_disable_cpuslocked);
prev parent reply other threads:[~2024-03-07 2:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-05 7:54 Sam Sun
2024-03-06 15:54 ` Steven Rostedt
2024-03-06 19:31 ` Josh Poimboeuf
2024-03-06 20:12 ` Jason Baron
2024-03-06 22:16 ` Josh Poimboeuf
2024-03-06 22:40 ` Jason Baron
2024-03-06 23:42 ` Josh Poimboeuf
2024-03-07 1:30 ` Josh Poimboeuf
2024-03-07 2:34 ` Steven Rostedt [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=20240306213453.72f9a925@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=jbaron@akamai.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=samsun1006219@gmail.com \
--cc=syzkaller@googlegroups.com \
--cc=xrivendell7@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