From: Jason Baron <jbaron@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: gleb@redhat.com, a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] jump label: close race in jump_label_inc() vs. jump_label_dec()
Date: Thu, 5 Jan 2012 10:30:42 -0500 [thread overview]
Message-ID: <20120105153041.GA10850@redhat.com> (raw)
In-Reply-To: <1325774396.12696.49.camel@gandalf.stny.rr.com>
On Thu, Jan 05, 2012 at 09:39:56AM -0500, Steven Rostedt wrote:
> On Wed, 2012-01-04 at 10:32 -0500, Jason Baron wrote:
> > The previous fix to ensure that jump_label_inc() does not return until the jump
> > is completely patched, opened up a race in the inc/dec path. The scenario is:
>
> You forgot something:
>
>
> >
> > key->enabled = 0;
> >
> > CPU 0 CPU 1
> > ----- -----
>
> jump_label_lock();
>
> >
> > jump_label_inc(): jump_label_dec():
> >
> > 1) if (atomic_read(&key->enabled) == 0)
> > jump_label_update(key, JUMP_LABEL_ENABLE);
> >
> > 2) if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex))
> > return;
> >
> > 3) atomic_inc(&key->enabled);
>
> jump_label_unlock();
>
>
>
> >
> > So now, key->enabled = 0, but the jump has been enabled, which is an invalid
> > state.
>
> How does key->enabled end up == 0?
>
> As Gleb said, it's a higher level bug if we do a jump_label_dec() when
> key->enabled already is zero.
>
I was worried about exactly that case. Part of my thinking is based on
'static_branch_def_true()' that I am looking to introduce, see:
https://lkml.org/lkml/2011/12/21/359. In that case, key->enabled starts
at 1, and we need to do a jump_label_dec(key), in order to make the
branch false and change the branch from its initial state. So, if we don't allow
negative 'enabled' values, the api doesn't feel symmetrical.
That said, until we have a use-case that would excercise this race,
I'm ok with having it be a higher level bug as Gleb pointed out. So how about a
WARN() for this case. I'll send as a separate patch, if people are ok
with it.
Thanks,
-Jason
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -75,8 +75,11 @@ void jump_label_inc(struct jump_label_key *key)
static void __jump_label_dec(struct jump_label_key *key,
unsigned long rate_limit, struct delayed_work *work)
{
- if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex))
+ if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
+ WARN(atomic_read(&key->enabled) < 0,
+ "jump label: negative count!\n");
return;
+ }
if (rate_limit) {
atomic_inc(&key->enabled);
> Thus, in this scenario, we enter jump_label_inc() with key->enabled=1,
> and 1) will not be true. When we hit 2), it will have to grab the
> jump_label_mutex, which will be held, thus it will block until CPU 0 is
> finished, in which case, key->enabled=1 and the
> atomic_dec_and_mutex_lock() will fail and return.
>
> The end result is key->enabled=1 and we have jump labels enabled.
>
> What's the invalid state?
>
> -- Steve
>
>
next prev parent reply other threads:[~2012-01-05 15:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-04 15:32 [PATCH] jump label: close race in jump_label_inc() vs. jump_label_dec() Jason Baron
2012-01-05 7:20 ` Gleb Natapov
2012-01-05 14:39 ` Steven Rostedt
2012-01-05 15:30 ` Jason Baron [this message]
2012-01-05 15:34 ` Steven Rostedt
2012-01-05 15:38 ` Jason Baron
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=20120105153041.GA10850@redhat.com \
--to=jbaron@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=gleb@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.