linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: me@felipebalbi.com
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	felipe.balbi@nokia.com, dmitry.torokhov@gmail.com,
	sameo@openedhand.com, Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: lockdep and threaded IRQs (was: [PATCH 1/2] input: misc: add twl4030-pwrbutton driver)
Date: Fri, 27 Feb 2009 13:50:32 -0800	[thread overview]
Message-ID: <200902271350.32380.david-b@pacbell.net> (raw)
In-Reply-To: <20090227203717.GL16801@frodo>

On Friday 27 February 2009, Felipe Balbi wrote:
> 
> > > +static irqreturn_t powerbutton_irq(int irq, void *dev_id)
> > > +{
> > > +   int err;
> > > +   u8 value;
> > > +
> > > +#ifdef CONFIG_LOCKDEP
> > > +   /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which
> > > +    * we don't want and can't tolerate.  Although it might be
> > > +    * friendlier not to borrow this thread context...
> > > +    */
> > > +   local_irq_enable();
> > > +#endif
> > > +
> > > +   err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value,
> > > +                             STS_HW_CONDITIONS);

And right there is the reason we can't tolerate IRQF_DISABLED:
this IRQ handler must run in a thread, since it needs to make
sleeping calls through the I2C stack.  (Typically using high
speed I2C -- 2.6 MHz or more -- so it's not pokey slow; but
this IRQ handler thread must still sleep.)


> > > +   ...
> > 
> > Tell us some more about this lockdep thing ;)

See kernel/irq/manage.c ... it forces IRQF_DISABLED on.

That periodically hiddes locking bugs, because it makes
debug kernels (with lockdep) act *very* differently
from normal ones "in the field" (no lockdep).

It also prevents some drivers from working with lockdep.
Two that come immediatly to mind are the AT91 and OMAP1
MMC/SD drivers.  (Though I suppose they might work if
they grow an #ifdef like above.)


The root cause is that the lock dependency analysis is
currently making a troublesome simplifying assumption:
all IRQ handlers disable IRQs.  At this point I think
it's fair to say most do NOT disable IRQs.

Peter Zijlstra was really hoping to Tom-Sawyer a fix
to this issue out of someone, but I think he gave up
on that approach a while back.  :)

I'd still like to see the appended patch merge, so
that developers at least get a heads-up when lockdep
introduces adds such gremlins to system testing.  Or,
various drivers could depend on !LOCKDEP ... but that
would only help (a little) *after* bugs get tracked
down to "root cause == lockdep", wasting much time.


> David Brownell can comment better about it, that came from him when we
> were converting twl4030 driver(s) to a more readable form :-)
> 
> If you take a look at all twl4030's children, you'll all of them needed
> that.
> 
> Dave, could you comment, please ?

There are actually two issues.  The lockdep issue is
one ... the above #ifdef suffices to work around it
for all the TWL4030 (family) IRQs.

The other is that Linux needs real support for threaded
interrupts.  Almost every I2C (or SPI) device that raises
an IRQ needs its IRQ handler to run in a thread, and most
of them have the same type of workqueue-based hack to
get such a thread.  (Some others have bugs instead...)

Obviously, if any threaded IRQ handler grabs a mutex,
but lockdep has disabled IRQs, trouble ensues...

I've lost track of the status of the threaded IRQ stuff,
but the last proposal I saw from Thomas Gleixner looked
like it omitted IRQ chaining support that TWL4030 type
chips need.  See drivers/mfd/twl4030-irq.c for what
AFAIK is the only in-tree example of an irq_chip where
the guts of the irq_chip methods themselves must run in
threads (to mask/ack/... IRQs using i2c registers).
Presumably the threaded IRQ support will offer cleaner
ways to handle such stuff.

- Dave


======== CUT HERE
From: David Brownell <dbrownell@users.sourceforge.net>

When lockdep turns on IRQF_DISABLED, emit a warning to make it
easier to track down problems this introduces in drivers that
expect handlers to run with IRQs enabled.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
---
 kernel/irq/manage.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -689,7 +689,11 @@ int request_irq(unsigned int irq, irq_ha
 	/*
 	 * Lockdep wants atomic interrupt handlers:
 	 */
-	irqflags |= IRQF_DISABLED;
+	if (!(irqflags & IRQF_DISABLED)) {
+		pr_warning("IRQ %d/%s: lockdep sets IRQF_DISABLED\n",
+				irq, devname);
+		irqflags |= IRQF_DISABLED;
+	}
 #endif
 	/*
 	 * Sanity-check: shared interrupts must pass in a real dev-ID,

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2009-02-27 21:50 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-27 19:28 [PATCH 1/2] input: misc: add twl4030-pwrbutton driver Felipe Balbi
2009-02-27 19:28 ` [PATCH 2/2] mfd: twl4030: add twl4030-pwrbutton as our child Felipe Balbi
2009-02-27 20:36   ` Andrew Morton
2009-02-27 21:58     ` David Brownell
2009-02-27 22:09       ` Felipe Balbi
2009-02-27 22:12       ` Andrew Morton
2009-02-27 23:20         ` David Brownell
2009-02-27 23:42           ` Andrew Morton
2009-07-22 19:27             ` Trilok Soni
2009-07-22 22:25               ` David Brownell
2009-02-27 20:33 ` [PATCH 1/2] input: misc: add twl4030-pwrbutton driver Andrew Morton
2009-02-27 20:37   ` Felipe Balbi
2009-02-27 21:50     ` David Brownell [this message]
2009-02-27 22:09       ` lockdep and threaded IRQs (was: [PATCH 1/2] input: misc: add twl4030-pwrbutton driver) Andrew Morton
2009-02-27 23:18         ` lockdep and threaded IRQs (was: ...) David Brownell
2009-02-27 23:32           ` Andrew Morton
2009-02-28  0:01             ` Andrew Morton
2009-02-28  2:30               ` David Brownell
2009-02-28  2:39                 ` Andrew Morton
2009-02-28  4:46                   ` David Brownell
2009-02-28  5:12                     ` Andrew Morton
2009-02-28  6:17                       ` David Brownell
2009-02-28 11:13                     ` Thomas Gleixner
2009-02-28 12:16                       ` David Brownell
2009-02-28 16:42                         ` Thomas Gleixner
2009-02-28 20:02                           ` David Brownell
2009-02-28 20:55                             ` Thomas Gleixner
2009-02-28 21:13                               ` Thomas Gleixner
2009-02-28 22:37                                 ` David Brownell
2009-02-28 22:05                               ` David Brownell
2009-03-01  9:43                                 ` Thomas Gleixner
2009-03-01 22:54                                   ` David Brownell
2009-03-02 13:16                                     ` Peter Zijlstra
2009-03-02 21:04                                       ` David Brownell
2009-03-02 21:16                                         ` Peter Zijlstra
2009-03-02 21:29                                           ` Andrew Morton
2009-03-02 21:37                                           ` David Brownell
2009-03-02 21:41                                             ` Peter Zijlstra
2009-03-02 22:09                                               ` David Brownell
2009-03-02 22:19                                                 ` Peter Zijlstra
2009-03-02 22:40                                                   ` David Brownell
2009-03-02 22:51                                                     ` Peter Zijlstra
2009-03-02 23:29                                                       ` David Brownell
2009-03-03  7:45                                                         ` Peter Zijlstra
2009-03-02 22:46                                                   ` lockdep and threaded IRQs David Miller
2009-03-02 22:57                                                     ` Andrew Morton
2009-03-02 23:07                                                       ` Peter Zijlstra
2009-03-02 23:02                                                     ` Peter Zijlstra
2009-03-02 23:35                                           ` lockdep and threaded IRQs (was: ...) Alan Cox
2009-03-01 22:11                               ` David Brownell
2009-02-28 11:48                     ` lockdep and threaded IRQs Stefan Richter
2009-02-28 20:19                       ` David Brownell
2009-02-28 21:10                         ` Stefan Richter
2009-03-02 13:16           ` lockdep and threaded IRQs (was: ...) Peter Zijlstra
2009-03-02 22:10             ` David Brownell
2009-03-02 22:25               ` Peter Zijlstra
2009-03-02 23:20                 ` David Brownell
2009-03-02 23:26                   ` Ingo Molnar
2009-03-02 23:42                     ` David Brownell
2009-03-02 23:53                       ` Ingo Molnar
2009-03-03  0:33                         ` David Brownell
2009-03-03  0:44                           ` Ingo Molnar
2009-03-03  2:37                             ` David Brownell
2009-03-03  9:27                               ` Peter Zijlstra
2009-03-03  9:45                                 ` Ingo Molnar
2009-03-03  9:47                                 ` Alan Cox
2009-03-03 10:03                                   ` Ingo Molnar
2009-03-03 10:30                                     ` Alan Cox
2009-03-03 10:39                                       ` Peter Zijlstra
2009-03-03 10:48                                       ` Ingo Molnar
2009-03-03 11:13                                         ` Alan Cox
2009-03-03 11:33                                           ` Ingo Molnar
2009-03-03 11:19                                         ` Ingo Molnar
2009-03-18  1:04                                         ` David Brownell
2009-03-18  2:00                             ` David Brownell
2009-03-03 11:53                       ` Thomas Gleixner
2009-03-05  2:49                         ` David Brownell
2009-03-06 14:40                           ` Thomas Gleixner
2009-03-18  3:06                             ` David Brownell
2009-03-02 23:48                     ` David Brownell
2009-03-02 23:58                       ` Ingo Molnar
2009-03-02 15:13           ` [PATCH] genirq: assert that irq handlers are indeed run in hardirq context Peter Zijlstra
2009-03-02 19:48             ` David Brownell
2009-02-28 11:20       ` lockdep and threaded IRQs Stefan Richter
2009-02-28 20:10         ` David Brownell
2009-02-28  5:51 ` [PATCH 1/2] input: misc: add twl4030-pwrbutton driver Trilok Soni
2009-02-28 12:05   ` [PATCH] mfd: twl4030: add twl4030-pwrbutton as our child Felipe Balbi
2009-02-28 22:23 ` [PATCH 1/2] input: misc: add twl4030-pwrbutton driver Dmitry Torokhov
2009-03-01  0:30   ` Felipe Balbi
2009-03-01  0:58     ` Dmitry Torokhov
2009-03-01 14:40       ` Felipe Balbi
2009-03-04  9:00         ` Dmitry Torokhov
2009-03-04 10:12           ` Felipe Balbi
2009-03-05  1:38             ` David Brownell
2009-03-05 23:54           ` David Brownell
2009-03-06  9:43             ` Dmitry Torokhov

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=200902271350.32380.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=felipe.balbi@nokia.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@felipebalbi.com \
    --cc=sameo@openedhand.com \
    --cc=tglx@linutronix.de \
    /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).