diff options
| author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-10-22 23:26:25 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-23 12:01:31 -0400 |
| commit | a98ce5c6feead6bfedefabd46cb3d7f5be148d9a (patch) | |
| tree | 7bbd027e40805966ad908e40f09ffd412a72a88b /kernel | |
| parent | 48d2268473a66fe3aa78fb13b09ee59d6ee95073 (diff) | |
Fix synchronize_irq races with IRQ handler
As it is some callers of synchronize_irq rely on memory barriers
to provide synchronisation against the IRQ handlers. For example,
the tg3 driver does
tp->irq_sync = 1;
smp_mb();
synchronize_irq();
and then in the IRQ handler:
if (!tp->irq_sync)
netif_rx_schedule(dev, &tp->napi);
Unfortunately memory barriers only work well when they come in
pairs. Because we don't actually have memory barriers on the
IRQ path, the memory barrier before the synchronize_irq() doesn't
actually protect us.
In particular, synchronize_irq() may return followed by the
result of netif_rx_schedule being made visible.
This patch (mostly written by Linus) fixes this by using spin
locks instead of memory barries on the synchronize_irq() path.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/irq/manage.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 80eab7a04205..1f314221d534 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c | |||
| @@ -29,12 +29,28 @@ | |||
| 29 | void synchronize_irq(unsigned int irq) | 29 | void synchronize_irq(unsigned int irq) |
| 30 | { | 30 | { |
| 31 | struct irq_desc *desc = irq_desc + irq; | 31 | struct irq_desc *desc = irq_desc + irq; |
| 32 | unsigned int status; | ||
| 32 | 33 | ||
| 33 | if (irq >= NR_IRQS) | 34 | if (irq >= NR_IRQS) |
| 34 | return; | 35 | return; |
| 35 | 36 | ||
| 36 | while (desc->status & IRQ_INPROGRESS) | 37 | do { |
| 37 | cpu_relax(); | 38 | unsigned long flags; |
| 39 | |||
| 40 | /* | ||
| 41 | * Wait until we're out of the critical section. This might | ||
| 42 | * give the wrong answer due to the lack of memory barriers. | ||
| 43 | */ | ||
| 44 | while (desc->status & IRQ_INPROGRESS) | ||
| 45 | cpu_relax(); | ||
| 46 | |||
| 47 | /* Ok, that indicated we're done: double-check carefully. */ | ||
| 48 | spin_lock_irqsave(&desc->lock, flags); | ||
| 49 | status = desc->status; | ||
| 50 | spin_unlock_irqrestore(&desc->lock, flags); | ||
| 51 | |||
| 52 | /* Oops, that failed? */ | ||
| 53 | } while (status & IRQ_INPROGRESS); | ||
| 38 | } | 54 | } |
| 39 | EXPORT_SYMBOL(synchronize_irq); | 55 | EXPORT_SYMBOL(synchronize_irq); |
| 40 | 56 | ||
