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 22:24:56 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0908132219070.1283@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.01.0908131259340.28882@localhost.localdomain>

On Thu, 13 Aug 2009, Linus Torvalds wrote:
> On Thu, 13 Aug 2009, Thomas Gleixner wrote:
> > 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 ...
> 
> Aren't we holding the lock here?

No, we don't. The lock is dropped before handle_IRQ_event() is called.
 
> And if we are _not_ holding the lock, then it's racy anyway, and the right 
> fix is the other one I suggested:
> 
> > > 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.
> 
> But we already _do_ call synchronize_irq().
> 
> And no, we'd better not be running into the same problem, becaue dang it, 
> if we do, then 'action' itself is unreliable (since we'll be doing a 
> 'kfree()' in it in free_irq())

action->thread is the thing which became unreliable due to setting it
to NULL. Yes, I did not think about the fact that we can remove the
action while the interrupt is in progress on another CPU. So setting
action->thread to NULL _before_ calling synchronize_irq() is the cause
for the oops which has been reported.
 
> IOW, why not just make the patch do something like the appended? 
> 
> NOTE! This is UNTESTED. And I also - on purpose - removed the "set 
> action->thread to NULL", because we're going to free 'action', so if 
> anything depends on it, it's already buggy.

Works fine with my test case.

> What am I missing?

Nothing, as far as I can tell.

Acked-by-me.

	tglx

> 
> ---
>  kernel/irq/manage.c |   17 ++++++++---------
>  1 files changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index 61c679d..0747f22 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -809,9 +809,6 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
>  			desc->chip->disable(irq);
>  	}
>  
> -	irqthread = action->thread;
> -	action->thread = NULL;
> -
>  	spin_unlock_irqrestore(&desc->lock, flags);
>  
>  	unregister_handler_proc(irq, action);
> @@ -819,12 +816,6 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
>  	/* Make sure it's not being used on another CPU: */
>  	synchronize_irq(irq);
>  
> -	if (irqthread) {
> -		if (!test_bit(IRQTF_DIED, &action->thread_flags))
> -			kthread_stop(irqthread);
> -		put_task_struct(irqthread);
> -	}
> -
>  #ifdef CONFIG_DEBUG_SHIRQ
>  	/*
>  	 * It's a shared IRQ -- the driver ought to be prepared for an IRQ
> @@ -840,6 +831,14 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
>  		local_irq_restore(flags);
>  	}
>  #endif
> +
> +	irqthread = action->thread;
> +	if (irqthread) {
> +		if (!test_bit(IRQTF_DIED, &action->thread_flags))
> +			kthread_stop(irqthread);
> +		put_task_struct(irqthread);
> +	}
> +
>  	return action;
>  }
>  
> 

  reply	other threads:[~2009-08-13 20:25 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
2009-08-13 20:05     ` Linus Torvalds
2009-08-13 20:24       ` Thomas Gleixner [this message]
  -- 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.0908132219070.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®