mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [GIT pull] genirq fixes for 2.6.31
Date: Thu, 13 Aug 2009 21:59:34 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0908132157170.1283@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.00.0908132145340.1283@localhost.localdomain>

Sorry, sent out the wrong patch :(

On Thu, 13 Aug 2009, Thomas Gleixner wrote:

> On Thu, 13 Aug 2009, Linus Torvalds wrote:
> > Now, I can see a bug, which is that "action->tsk" may have been set to 
> > NULL. But I can't see a race, and I can't see a reason for all the code 
> > movement. So quite frankly, I think the comments (both in the code and in 
> > the commit message) are just wrong. And the odd "load it first, then do 
> > other things" code looks confused.
> > 
> > So why is this not just a
> > 
> > 	if (action->thread)
> > 		wake_up_process(action->thread);
> > 
> > with appropriate comments?
> 
> What guarantees that the compiler does not dereference action->thread
> twice and the action->thread = NULL; operation happens between the
> check and the wake_up_process() call? I might be paranoid, but ...
> 
> > Or, alternatively, just move all the "clear action->thread" in free_irq() 
> > to after having done the "synchronize_irq()" thing, and then - afaik - 
> > you'll not need that test at all, because you're guaranteed that as long 
> > as you're in an interrupt handler, the thing shouldn't be cleared.
> 
> Right, I looked at that as well, but we need to do it different than
> just calling synchronize_irq(), as we need to keep desc->lock after we
> established that no interrupt is in progress. Otherwise we can run
> into the same problem which we have right now. Patch below.
> 
> Thanks,
> 
> 	tglx

--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -895,7 +907,28 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
 	if (!desc)
 		return NULL;
 
-	spin_lock_irqsave(&desc->lock, flags);
+	while (1) {
+		/*
+		 * Wait until we're out of the critical section.  This might
+		 * give the wrong answer due to the lack of memory barriers.
+		 */
+		while (desc->status & IRQ_INPROGRESS)
+			cpu_relax();
+
+		/*
+		 * Check under the lock again. If irq is not in
+		 * progress we keep the lock held until we removed
+		 * action. We do not care about an already running irq
+		 * thread here. We care about it when we stop the thread.
+		 */
+		spin_lock_irqsave(&desc->lock, flags);
+
+		if (!(desc->status & IRQ_INPROGRESS))
+			break;
+
+		/* Try again */
+		spin_unlock_irqrestore(&desc->lock, flags);
+	}
 
 	/*
 	 * There can be multiple actions per IRQ descriptor, find the right

  reply	other threads:[~2009-08-13 20:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-13 19:02 Thomas Gleixner
2009-08-13 19:24 ` Linus Torvalds
2009-08-13 19:52   ` Thomas Gleixner
2009-08-13 19:59     ` Thomas Gleixner [this message]
2009-08-13 20:05     ` Linus Torvalds
2009-08-13 20:24       ` Thomas Gleixner
  -- strict thread matches above, loose matches on Subject: below --
2009-07-22 14:56 Thomas Gleixner
2009-07-22 23:28 ` Kevin Winchester
2009-07-22 23:33   ` Kevin Winchester

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=alpine.LFD.2.00.0908132157170.1283@localhost.localdomain \
    --to=tglx@linutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®