Skip to contentSkip to conversation

threaded interrupt handler support breaks (some) irq handling on AVR32

REGRESSION Applied Ben Nizette 4 participants 9 messages Apr 14, 2009 – Apr 16, 2009 1 message not in the archive Input drivers

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 3 lines · Ben Nizette

Note it's that very last line which, when triggered, causes the hang. As you can see, it's the only one connected through the gpio interrupt chip.

Okhayy.. This is probably a red herring. I just connected a button to a gpio irq on that board and it sat there happily interrupting all night long.

If anyone's reading with an ADS7846 on some other arch can they try to reproduce?

If no one beats me to it i'll try and scatter printks and narrow down exactly *where* it all explodes tomorrow.

Thx,

	--Ben.
#2 lore raw
Quoted 2 lines · Ben Nizette

If no one beats me to it i'll try and scatter printks and narrow down exactly *where* it all explodes tomorrow.

static irqreturn_t ads7846_irq(int irq, void *handle)

{
	struct ads7846 *ts = handle;
	unsigned long flags;

	spin_lock_irqsave(&ts->lock, flags);
	if (likely(get_pendown_state(ts))) {
		if (!ts->irq_disabled) {
			/* The ARM do_simple_IRQ() dispatcher doesn't act
			 * like the other dispatchers:  it will report IRQs
			 * even after they've been disabled.  We work around
			 * that here.  (The "generic irq" framework may help...)
			 */
			ts->irq_disabled = 1;
			disable_irq(ts->spi->irq);
			ts->pending = 1;
			hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_DELAY),
					HRTIMER_MODE_REL);
		}
	}
	spin_unlock_irqrestore(&ts->lock, flags);

	return IRQ_HANDLED;
}

Right, a scattering of printks in there shows execution gets at least as far as inside the inner-most code block. A printk directly before the disable_irq() doesn't make it to my console so I'm guessing that the hang is in there somewhere.

Hope this helps,

	--Ben.
#3 lore raw
Quoted 15 lines · Ben Nizette

static irqreturn_t ads7846_irq(int irq, void *handle)

{
	struct ads7846 *ts = handle;
	unsigned long flags;

	spin_lock_irqsave(&ts->lock, flags);
	if (likely(get_pendown_state(ts))) {
		if (!ts->irq_disabled) {
			/* The ARM do_simple_IRQ() dispatcher doesn't act
			 * like the other dispatchers:  it will report IRQs
			 * even after they've been disabled.  We work around
			 * that here.  (The "generic irq" framework may help...)
			 */
			ts->irq_disabled = 1;
			disable_irq(ts->spi->irq);

Shouldn't that be disable_irq_nosync()?

Haavard

#4 lore raw
Quoted 17 lines · Haavard Skinnemoen
Quoted 15 lines · Ben Nizette

static irqreturn_t ads7846_irq(int irq, void *handle)

{
	struct ads7846 *ts = handle;
	unsigned long flags;

	spin_lock_irqsave(&ts->lock, flags);
	if (likely(get_pendown_state(ts))) {
		if (!ts->irq_disabled) {
			/* The ARM do_simple_IRQ() dispatcher doesn't act
			 * like the other dispatchers:  it will report IRQs
			 * even after they've been disabled.  We work around
			 * that here.  (The "generic irq" framework may help...)
			 */
			ts->irq_disabled = 1;
			disable_irq(ts->spi->irq);  
Quoted 1 line

Shouldn't that be disable_irq_nosync()?

Ok, simply stating that without providing an explanation was probably not so helpful...

I think the problem is that disable_irq() calls synchronize_irq(), which waits until the corresponding interrupt handler is no longer running on any CPU. And since we're calling it from the interrupt handler, we'll have a deadlock because the interrupt handler won't return until synchronize_irq() returns, and that won't happen until the interrupt handler returns and so on.

So I think changing disable_irq() into disable_irq_nosync() (which doesn't call synchronize_irq()) will fix it, though I'm not sure what difference the threaded interrupt handling code makes -- AFAICT, this code has always been dangerous.

Haavard

#5 lore raw
Quoted 2 lines · Haavard Skinnemoen

AFAICT, this code has always been dangerous.

Can you propose a better way to handle the problem? It's a case that crops up with a lot of touch screen controllers.

b.g.

Signature · 2 lines
Bill Gatliff
[email protected]
#6 lore raw
Quoted 6 lines · Bill Gatliff
Quoted 2 lines · Haavard Skinnemoen

AFAICT, this code has always been dangerous.

Can you propose a better way to handle the problem? It's a case that crops up with a lot of touch screen controllers.

I thought I already did: Use disable_irq_nosync() instead.

Haavard

#7 lore raw
Quoted 4 lines · Haavard Skinnemoen
Quoted 2 lines · Bill Gatliff

Haavard Skinnemoen wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

AFAICT, this code has always been dangerous.

Can you propose a better way to handle the problem? It's a case that crops up with a lot of touch screen controllers.

I thought I already did: Use disable_irq_nosync() instead.

Aah. I misinterpreted what you wrote. Thanks!

b.g.

Signature · 2 lines
Bill Gatliff
[email protected]
#8 lore raw

PATCH 1/1 ads7846: fix unsafe disable_irq (was [REGRESSION] threaded interrupt handler support breaks (some) irq handling on AVR32)

In reply to Haavard Skinnemoen
Quoted 1 line · Haavard Skinnemoen

Shouldn't that be disable_irq_nosync()?

Indeed, good catch. That fixes it.

--------------8<--------------------

The use of disable_irq inside the handler for the interrupt being disabled has always been dangerous. disable_irq should wait for that handler to complete before returning -> deadlock.

For some reason this wasn't actually the case until 3aa551c9b was merged but since this time, the ads7846 driver has deadlocked the system on first interrupt.

Convert the driver to use the handler-safe _nosync variant.

---

drivers/input/touchscreen/ads7846.c +1 -1
index 61b4a02..f2513e6 100644
@@ -746,7 +746,7 @@ static irqreturn_t ads7846_irq(int irq, void *handle)
 			 * that here.  (The "generic irq" framework may help...)
 			 */
 			ts->irq_disabled = 1;
-			disable_irq(ts->spi->irq);
+			disable_irq_nosync(ts->spi->irq);
 			ts->pending = 1;
 			hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_DELAY),
 					HRTIMER_MODE_REL);
maintainer Applied
#9 lore raw

Re: [PATCH] ads7846: fix unsafe disable_irq (was [REGRESSION] threaded interrupt handler support breaks (some) irq handling on AVR32)

Quoted 11 lines · Ben Nizette
Quoted 1 line · Haavard Skinnemoen

Shouldn't that be disable_irq_nosync()?

Indeed, good catch. That fixes it.

--------------8<--------------------

The use of disable_irq inside the handler for the interrupt being disabled has always been dangerous. disable_irq should wait for that handler to complete before returning -> deadlock.

Quoted 6 lines

For some reason this wasn't actually the case until 3aa551c9b was merged but since this time, the ads7846 driver has deadlocked the system on first interrupt.

Convert the driver to use the handler-safe _nosync variant.

Applied, thank you very much Ben.

Signature · 1 line
Dmitry