public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* in_interrupt race
@ 2002-04-20 10:27 Paul Mackerras
  2002-04-22 19:02 ` Robert Love
  0 siblings, 1 reply; 10+ messages in thread
From: Paul Mackerras @ 2002-04-20 10:27 UTC (permalink / raw)
  To: linux-kernel

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.

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

end of thread, other threads:[~2002-04-24  4:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-20 10:27 in_interrupt race Paul Mackerras
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

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