lkml.org 
[lkml]   [2013]   [Dec]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: spinlock_irqsave() && flags (Was: pm80xx: Spinlock fix)
On 12/23, Linus Torvalds wrote:
>
> On Mon, Dec 23, 2013 at 9:27 AM, Oleg Nesterov <oleg@redhat.com> wrote:
> >
> > In short, is this code
> >
> > spinlock_t LOCK;
> > unsigned long FLAGS;
> >
> > void my_lock(void)
> > {
> > spin_lock_irqsave(&LOCK, FLAGS);
> > }
> >
> > void my_unlock(void)
> > {
> > spin_unlock_irqrestore(&LOCK, FLAGS);
> > }
> >
> > correct or not?
>
> Hell no. "flags" needs to be a thread-private variable, or at least
> protected some way (ie the above could work if everything is inside a
> bigger lock, to serialize access to FLAGS).

This was my understanding (although, once again, it seems to me this can
suprisingly work with the current implementation).

However, the code above already has the users. Do you think it makes
sense to add something like

void spinlock_irqsave_careful(spinlock_t *lock, unsigned long *flags)
{
unsigned long _flags;
spinlock_irqsave(lock, _flags);
*flags = flags;
}

void spinlock_irqrestore_careful(spinlock_t *lock, unsigned long *flags)
{
unsigned long _flags = *flags;
spinlock_irqrestore(lock, _flags);
}

into include/linux/spinlock.h ?

Oleg.



\
 
 \ /
  Last update: 2013-12-23 20:01    [W:0.124 / U:0.460 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site