mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* racy jump label users
@ 2013-03-22 19:55 Andi Kleen
  2013-04-18 18:26 ` Jason Baron
  0 siblings, 1 reply; 2+ messages in thread
From: Andi Kleen @ 2013-03-22 19:55 UTC (permalink / raw)
  To: jbaron; +Cc: linux-kernel

Jason,

I noticed that a lot of the jump label users are racy,
because they implement something like this

static void sched_feat_disable(int i)
{
        if (static_key_enabled(&sched_feat_keys[i]))
                static_key_slow_dec(&sched_feat_keys[i]);
}

static void sched_feat_enable(int i)
{
        if (!static_key_enabled(&sched_feat_keys[i]))
                static_key_slow_inc(&sched_feat_keys[i]);
}

with no extra locking, controlled by sysfs. If two
CPUs do this in parallel the reference can be set multiple
times, which gives very unexpected semantics for a sysfs boolean.

Most likely you need a static_key_slow_setstate()
that does the check and set inside the jump label lock.

I understand that for inside kernel use reference
counts are the right semantics, but they are not so
good for sysfs interfaces.

-Andi

-- 
ak@linux.intel.com -- Speaking for myself only

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: racy jump label users
  2013-03-22 19:55 racy jump label users Andi Kleen
@ 2013-04-18 18:26 ` Jason Baron
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Baron @ 2013-04-18 18:26 UTC (permalink / raw)
  To: Andi Kleen; +Cc: linux-kernel

Hi Andi,

Agreed. However, other users of 'static_key_enabled()', provide their own
locking. For example, in kernel/tracepoint.c, 'static_key_enabled()',
relies on
the tracepoints_mutex. Were there any other users that are problematic?

I agree a 'setstate' would be nice. Maybe something like:

static_key_slow_set_true();
static_key_slow_set_false();

Thanks,

-Jason

On 03/22/2013 03:55 PM, Andi Kleen wrote:
> Jason,
>
> I noticed that a lot of the jump label users are racy,
> because they implement something like this
>
> static void sched_feat_disable(int i)
> {
>         if (static_key_enabled(&sched_feat_keys[i]))
>                 static_key_slow_dec(&sched_feat_keys[i]);
> }
>
> static void sched_feat_enable(int i)
> {
>         if (!static_key_enabled(&sched_feat_keys[i]))
>                 static_key_slow_inc(&sched_feat_keys[i]);
> }
>
> with no extra locking, controlled by sysfs. If two
> CPUs do this in parallel the reference can be set multiple
> times, which gives very unexpected semantics for a sysfs boolean.
>
> Most likely you need a static_key_slow_setstate()
> that does the check and set inside the jump label lock.
>
> I understand that for inside kernel use reference
> counts are the right semantics, but they are not so
> good for sysfs interfaces.
>
> -Andi
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-04-18 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-22 19:55 racy jump label users Andi Kleen
2013-04-18 18:26 ` Jason Baron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome