From: Andrew Morton <andrewm@uow.edu.au>
To: "Hen, Shmulik" <shmulik.hen@intel.com>
Cc: "'LKML'" <linux-kernel@vger.kernel.org>
Subject: Re: spinlock help
Date: Thu, 08 Mar 2001 22:34:30 +1100 [thread overview]
Message-ID: <3AA76E46.71B99B7C@uow.edu.au> (raw)
In-Reply-To: <07E6E3B8C072D211AC4100A0C9C5758302B2715F@hasmsx52.iil.intel.com>
"Hen, Shmulik" wrote:
>
> OK guys, you were right. The bug was in our code - sorry for trouble.
> Turns out that while I was away, the problem was solved by someone else. The
> problem is probably related to the fact that when we did
> 'spin_lock_irqsave(c,d)', 'd' was a global variable. The fix was to wrap the
> call with another function and declare 'd' as local. I can't quite explain,
> but I think that changing from a static to automatic variable made the
> difference. My best guess is that since 'd' is passed by value and not by
> reference, the macro expansion of spin_lock_irqsave() relies on the location
> of 'd' in the stack and if 'd' was on the heap instead, it might get
> trashed.
>
Yes, that makes sense.
spin_lock_irqsave() really means "save the current irq mask
on the stack, then disable interrupts". spin_lock_irqrestore()
says "restore the current interrupt mask from the stack". So they
nest, and spin_lock_irqsave() doesn't have to care whether or
not interrupts are currently enabled.
Using a global variable you could get something like:
CPU0: CPU1
__cli();
spin_lock_irqsave(lock, global)
__sti();
spin_lock_irqsave(lock2, global)
spin_lock_irqrestore(lock2, global)
spin_unlock_irqrestore(lock, global)
/* interrupts should be disabled */
Here, CPU1 will set `global' to "interrupts enabled". So when
CPU0 restores its flags from `global' it will be picking up
CPU1's flags, not its own!
There are probably less subtle failure modes than this..
-
next prev parent reply other threads:[~2001-03-08 11:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-08 11:07 spinlock help Hen, Shmulik
2001-03-08 11:34 ` Andrew Morton [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-03-07 16:54 Ofer Fryman
2001-03-07 12:26 Hen, Shmulik
2001-03-07 12:53 ` Andrew Morton
2001-03-07 10:46 Hen, Shmulik
2001-03-07 10:44 Hen, Shmulik
2001-03-07 13:19 ` Alan Cox
2001-03-07 10:31 Ofer Fryman
2001-03-07 9:21 Hen, Shmulik
2001-03-07 10:26 ` Manoj Sontakke
2001-03-06 14:05 Manoj Sontakke
2001-03-06 23:53 ` Nigel Gamble
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=3AA76E46.71B99B7C@uow.edu.au \
--to=andrewm@uow.edu.au \
--cc=linux-kernel@vger.kernel.org \
--cc=shmulik.hen@intel.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