All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] disable_irq()/enable_irq() semantics and ide-probe.c
@ 2003-10-09  2:00 viro
  2003-10-09  2:29 ` Linus Torvalds
  0 siblings, 1 reply; 25+ messages in thread
From: viro @ 2003-10-09  2:00 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, Marcelo Tosatti, Bartlomiej Zolnierkiewicz

	Current code (at least on x86 and alpha) appears to assume that
you can't call disable_irq()/enable_irq() unless you have registered
that irq.

	However, ide-probe.c::probe_hwif() contains the following:
        /*
         * We must always disable IRQ, as probe_for_drive will assert IRQ, but
         * we'll install our IRQ driver much later...
         */
        irqd = hwif->irq;
        if (irqd)
                disable_irq(hwif->irq);
and later
        /*
         * Use cached IRQ number. It might be (and is...) changed by probe
         * code above
         */
        if (irqd)
                enable_irq(irqd);

That happens *way* before we call register_irq().  Current tree barfs on
that in all sorts of interesting ways.  Most notably, we get irq enabled
and with NULL ->action for a while.  If an interrupt comes during that
time, we'll get IRQ_INPROGRESS set and not reset until later register_irq()
(see handle_irq() for details).  Note that calling disable_irq() after that
will kill us on SMP - it will spin waiting for IRQ_INPROGRESS to go away.

Moreover, if somebody calls register_irq() while we are at it, we'll get
->depth reset to 0.  enable_irq() will try to decrement depth and will get
very unhappy about the situation.

What do we really want to do here?  I see only two variants:
	a) allow enable_irq()/disable_irq() regardless of having the thing
registered.  IRQ_DISABLED would be set iff ->depth is positive or ->action
is NULL.  register_irq() wouldn't touch the ->depth and would enable IRQ
only if ->depth is 0.  enable_irq() would not enable the thing unless ->action
was non-NULL.  That would work, but I wouldn't bet a dime on correctness -
e.g. currently disable_irq() followed by free_irq() works fine and drivers
might very well leave ->depth positive when they are removed.  With new
scheme that would be deadly.
	b) have ide-probe.c register a dummy handler for that period.
Then it would be allowed to do what it does.  Said handler would simply
return IRQ_NONE and be done with that.  Add BUG() to disable_irq()/enable_irq()
for cases when they are called with NULL ->action.

	Note that scenario above is absolutely real - 2.4.21 and later
hang on DS10 since their IDE chipset (alim15x3.c) does generate an interrupt
after the probe code had called enable_irq().  With obvious results -
ide_intr() is never called afterwards.  On 2.6 it doesn't happen only
because register_irq() forcibly drops IRQ_INPROGRESS, which hides that
problem, but doesn't help with other scenarios (e.g. somebody sharing the
same IRQ and doing register_irq() before we call enable_irq()).

Comments?

^ permalink raw reply	[flat|nested] 25+ messages in thread
* Re: [RFC] disable_irq()/enable_irq() semantics and ide-probe.c
@ 2003-10-09 16:10 Manfred Spraul
  2003-10-09 16:38 ` Jeff Garzik
  0 siblings, 1 reply; 25+ messages in thread
From: Manfred Spraul @ 2003-10-09 16:10 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: viro, linux-kernel

Linus wrote:

>Nobody has ever really complained, but if anybody 
>ever wants to do this, then the way to do it would be to
>
> - find out the irq
> - disable it
> - request the irq
> - enable the PCI routing for it
> - set up the device
> - enable the irq
>
I'd like to use that for nic shutdown for natsemi:

    disable_irq();
    shutdown_nic();
    free_irq();
    enable_irq();

The irq handler touches registers that restart the nic. Right now I use 
a np->hands_off variable to avoid that.

But I don't know if all systems can support atomic request_irq/free_irq 
calls. request_irq creates /proc/irq/x/cpu_affinity, and I could imagine 
that on some archs it might have perform IPIs to reconfigure the irq 
controller of a remote node.

--
    Manfred


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

end of thread, other threads:[~2003-10-17 10:33 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-09  2:00 [RFC] disable_irq()/enable_irq() semantics and ide-probe.c viro
2003-10-09  2:29 ` Linus Torvalds
2003-10-09  2:43   ` viro
2003-10-09  2:53     ` Linus Torvalds
2003-10-09  8:03       ` Russell King
2003-10-09 22:46         ` Zwane Mwaikambo
2003-10-09  8:07       ` Benjamin Herrenschmidt
2003-10-09 15:46       ` viro
2003-10-09 16:01         ` Linus Torvalds
2003-10-09 17:46           ` viro
2003-10-09 18:03             ` Linus Torvalds
2003-10-09 18:27               ` viro
2003-10-09 19:05                 ` Linus Torvalds
2003-10-15 17:14               ` Anton Blanchard
2003-10-17  9:19                 ` Russell King
2003-10-17 10:32                   ` Benjamin Herrenschmidt
2003-10-09 12:55   ` Roman Zippel
2003-10-09 16:10 Manfred Spraul
2003-10-09 16:38 ` Jeff Garzik
2003-10-09 16:57   ` Benjamin Herrenschmidt
2003-10-09 17:03     ` Jeff Garzik
2003-10-09 17:07       ` Benjamin Herrenschmidt
2003-10-09 17:16         ` Jeff Garzik
2003-10-09 17:29   ` Linus Torvalds
2003-10-09 17:52     ` Jeff Garzik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.