public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: David Brownell <david-b@pacbell.net>
Cc: stern@rowland.harvard.edu, tglx@linutronix.de,
	some.nzguy@gmail.com, paulmck@us.ibm.com,
	linux-kernel@vger.kernel.org, gregkh@suse.de,
	a.p.zijlstra@chello.nl, Andrew Morton <akpm@osdl.org>
Subject: Re: [patch] Real-Time Preemption, -RT-2.6.13-rc6-V0.7.53-11
Date: Thu, 18 Aug 2005 06:52:57 +0200	[thread overview]
Message-ID: <20050818045257.GC9768@elte.hu> (raw)
In-Reply-To: <20050817205125.06ABCBF3E9@adsl-69-107-32-110.dsl.pltn13.pacbell.net>


* David Brownell <david-b@pacbell.net> wrote:

> > >   1 ALWAYS complete() with IRQs disabled
> > > 
> > >   2 NEVER complete() with them disabled
> > > 
> > >   3 SOMETIMEs complete() with them disabled.
> > > 
> > > Right now we're with #1 which is simple, consistent and guaranteed.
> > > 
> > > We couldn't switch to #2 with patches that simple.  They'd in fact
> > > be rather involved ...
> >
> > I'm in favor of #2 on general principle.
> 
> Which principle would that be, though?  :)

it's the basic Linux kernel principle of never disabling interrupts, 
unless really, really necessary.

but the main issue isnt with disabling interrupts in general, the issue 
is with "naked" (i.e. lock-less) disabling of interrupts. Let me try to 
explain. Stuff like:

	spin_lock_irq(&lock);
	stuff1();
	spin_unlock(&lock);
	stuff2();
	local_irq_enable();

is outright dangerous, because it could hide SMP bugs that do not 
trigger on UP. SMP systems are becoming the norm these days, so we 
cannot hide behind "most people use UP" arguments anymore. IRQ flags 
management needs to be tightened up. (The good news is that it can be 
done gradually and i'm doing it, so it's no extra work for you.)

so in the process of identifying naked IRQ-flags use i asked why the USB 
code was doing it, and i'm happy that the answer is "no good reason, 
mostly historic". (naked IRQ flags use also happens to be a problem for 
PREEMPT_RT, where i also have a debug warning about such IRQ flags 
assymetries, but you need not worry about that one.)

the only logistical problem with "unifying" the IRQ flags operations 
with their respective spin_lock functions is their transitive nature, 
e.g. in the above example, if stuff2() does:

	stuff2()
	{
		spin_lock(&lock2);
		stuff3();
		spin_unlock(&lock2);
	}

then the irqs-off condition needs to be propagated into the function:

	stuff2()
	{
		spin_lock_irq(&lock2);
		stuff3();
		spin_unlock_irq(&lock2);
	}

IFF 'lock2' can be used from an interrupt or softirq context. Obviously 
the latter code form is much more preferred, because it self-documents 
that lock2 is irq-safe. Nested, implicit irqs-off assumptions are 
another common source of locking bugs.

but fortunately this is a relatively straightforward process, and it 
seems Alan has identified most of the affected functions. I'd be happy 
if you could point out more candidates. In the worst-case, if any 
function is missed by accident then it's easy to debug it. I'm now 
testing the patches posted in this thread in the -RT tree, they are 
looking good so far.

to make such cleanups of irq-flags use easier i'm also thinking about 
automating the process of checking for the irq-safety of spinlocks, by 
adding a new spinlock type via:

	DEFINE_SPINLOCK_IRQSAFE(lock2);

(and a spin_lock_init_irqsafe() function too)

this will be useful for the whole kernel, not properly managing the irq 
flags is a common locking mistake. With this new debug feature enabled, 
the kernel will warn if an irq-safe lock is taken with interrupts still 
enabled.

furthermore, the debug feature will also warn if a spinlock _not_ marked 
irqsafe is used from an interrupt context. This is another common type 
of locking mistake.

the spinlock-consolidation patch currently cooking in -mm (to be merged 
to 2.6.14) makes it easy to add such new spinlock debugging features 
without having to change assembly code in 22 architectures.

[ we could even take this one step further and completely automate 
  irq-safe locks - i.e. not manage irq-flags at all and only have 
  spin_lock() and spin_unlock(). That would cause some minimal runtime 
  overhead for irqsafe locks though. But i digress. ]

	Ingo

  reply	other threads:[~2005-08-18  4:52 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-11 11:00 [patch] Real-Time Preemption, -RT-2.6.13-rc4-V0.7.53-01, High Resolution Timers & RCU-tasklist features Ingo Molnar
2005-08-12  3:07 ` Lee Revell
2005-08-12  3:19   ` Lee Revell
2005-08-12  7:03     ` Ingo Molnar
2005-08-12  7:48     ` Thomas Gleixner
2005-08-12  7:07   ` Ingo Molnar
2005-08-13  0:28 ` Ryan Brown
2005-08-13  0:32   ` Lee Revell
2005-08-13  0:57     ` George Anzinger
2005-08-14  2:12       ` Ingo Molnar
2005-08-15  6:29         ` Ingo Molnar
2005-08-15 23:39           ` George Anzinger
2005-08-16  6:36             ` Thomas Gleixner
2005-08-15 11:18   ` [patch] Real-Time Preemption, -RT-2.6.13-rc6-V0.7.53-11 Ingo Molnar
2005-08-15 20:35     ` Peter Zijlstra
2005-08-16  3:53       ` Ingo Molnar
2005-08-16 14:35         ` Alan Stern
2005-08-16 16:12           ` Ingo Molnar
2005-08-16 16:56             ` Alan Stern
2005-08-16 17:02               ` Ingo Molnar
2005-08-17  2:23               ` David Brownell
2005-08-17 14:10                 ` Alan Stern
2005-08-17 20:51                   ` David Brownell
2005-08-18  4:52                     ` Ingo Molnar [this message]
2005-08-18  6:37                       ` David Brownell
2005-08-18 14:43                         ` Alan Stern
2005-08-22 11:07                         ` Ingo Molnar
2005-08-17  6:31               ` Ingo Molnar
2005-08-16  8:41     ` 2.6.13-rc6-rt1 Ingo Molnar
2005-08-16 12:32       ` 2.6.13-rc6-rt1 Michal Schmidt
2005-08-27  1:15         ` 2.6.13-rc6-rt1 Matt Mackall
2005-08-29 22:36           ` 2.6.13-rc6-rt1 Esben Nielsen
2005-08-17  0:53 ` [patch] KGDB for Real-Time Preemption systems George Anzinger
2005-08-17  6:53   ` Ingo Molnar
2005-08-17 19:16     ` George Anzinger
2005-09-05 12:23   ` Serge Noiraud
2005-09-08  0:37     ` George Anzinger
2005-09-07  8:55   ` Serge Noiraud
2005-09-07 21:16     ` George Anzinger
2005-09-08  8:57       ` Serge Noiraud
2005-09-08 20:47         ` George Anzinger

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=20050818045257.GC9768@elte.hu \
    --to=mingo@elte.hu \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@osdl.org \
    --cc=david-b@pacbell.net \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@us.ibm.com \
    --cc=some.nzguy@gmail.com \
    --cc=stern@rowland.harvard.edu \
    --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