From: TeJun Huh <tejun@aratech.co.kr>
To: linux-kernel@vger.kernel.org
Subject: Possible race condition in i386 global_irq_lock handling.
Date: Thu, 21 Aug 2003 17:48:07 +0900 [thread overview]
Message-ID: <20030821084807.GA29913@atj.dyndns.org> (raw)
I've been reading i386 interrupt handling code for a couple of days
and encountered something that looks like a race condition. It's
between include/asm-i386/hardirq.h:irq_enter() and
arch/i386/kernel/irq.c:get_irqlock(). They seem to be using lockless
synchronization with local_irq_count of each cpu and global_irq_lock
variable.
A. locking CPU
1. Do test_and_set_bit() on global_irq_lock, if fail, repeat.
2. If all local_irq_count's are zero, we're the winner. Check other
stuff; otherwise, clear global_irq_lock and retry.
B. other CPUs
1. Increment local_irq_count
2. test_bit() on global_irq_lock, if zero, continue handling interrupt;
otherwise, wait till it's cleared.
For this to work, the locking CPU should fetch the value of
local_irq_count after global_irq_lock value becomes visible to other
CPUs, and other CPUs should fetch the value of global_irq_lock after
making the incremented local_irq_count visible to other CPUs.
The locking CPU is OK because test_and_set_bit() forces ordering on
x86, but there should be a mb() betweewn step 1 and 2 for other CPUs
because none of ++ and test_bit is ordering. The B part is irq_enter()
in hardirq.h which looks like the following.
static inline void irq_enter(int cpu, int irq)
{
++local_irq_count(cpu);
while (test_bit(0,&global_irq_lock)) {
cpu_relax();
}
}
Is it a race condition or am I getting it horribly wrong? Thx in
advance.
next reply other threads:[~2003-08-21 8:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-21 8:48 TeJun Huh [this message]
2003-08-21 10:07 ` Possible race condition in i386 global_irq_lock handling Zwane Mwaikambo
2003-08-21 16:15 ` TeJun Huh
2003-08-21 17:01 Manfred Spraul
2003-08-21 17:27 ` Andrea Arcangeli
2003-08-21 21:48 ` Stephan von Krawczynski
2003-08-21 22:44 ` Andrea Arcangeli
2003-08-22 1:18 ` TeJun Huh
2003-08-22 10:07 ` Stephan von Krawczynski
2003-08-22 16:25 ` Andrea Arcangeli
2003-08-24 3:06 ` TeJun Huh
2003-08-24 22:03 ` Andrea Arcangeli
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=20030821084807.GA29913@atj.dyndns.org \
--to=tejun@aratech.co.kr \
--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;
as well as URLs for NNTP newsgroup(s).