From: Paul Mackerras <paulus@samba.org>
To: linux-kernel@vger.kernel.org
Subject: in_interrupt race
Date: Sat, 20 Apr 2002 20:27:59 +1000 (EST) [thread overview]
Message-ID: <15553.17071.88897.914713@argo.ozlabs.ibm.com> (raw)
Rusty made the suggestion to me the other day that it would be
interesting to put some stuff in smp_processor_id() to BUG() if
preemption isn't disabled, and then see where the kernel breaks. The
idea is that the result of smp_processor_id() is useless if preemption
is enabled, since you could move to another processor before you get
to use the result.
With that in mind, while I was poking around I noticed that
in_interrupt() uses smp_processor_id(). (This is true on all
architectures except ia64, which uses a local_cpu_data pointer
instead, and x86-64, which uses a read_pda function).
Thus if we have CONFIG_SMP and CONFIG_PREEMPT, there is a small but
non-zero probability that in_interrupt() will give the wrong answer if
it is called with preemption enabled. If the process gets scheduled
from cpu A to cpu B between calling smp_processor_id() and evaluating
local_irq_count(cpu) or local_bh_count(), and cpu A then happens to be
in interrupt context at the point where the process resumes on cpu B,
then in_interrupt() will incorrectly return 1.
One idea I had is to use a couple of bits in
current_thread_info()->flags to indicate whether local_irq_count and
local_bh_count are non-zero for the current cpu. These bits could be
tested safely without having to disable preemption.
In fact almost all uses of local_irq_count() and local_bh_count() are
for the current cpu; the exceptions are the irqs_running() function
and some debug printks. Maybe the irq and bh counters themselves
could be put into the thread_info struct, if irqs_running could be
implemented another way.
Paul.
next reply other threads:[~2002-04-20 11:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-20 10:27 Paul Mackerras [this message]
2002-04-22 19:02 ` Robert Love
2002-04-22 21:39 ` george anzinger
2002-04-22 21:54 ` Robert Love
2002-04-22 23:06 ` Paul Mackerras
2002-04-22 23:15 ` Robert Love
2002-04-23 3:25 ` Rusty Russell
2002-04-23 8:31 ` Russell King
2002-04-24 4:43 ` Rusty Russell
2002-04-22 23:22 ` Paul Mackerras
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=15553.17071.88897.914713@argo.ozlabs.ibm.com \
--to=paulus@samba.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®