ANNOUNCE: lock validator -V1
Subsystems (58)
cover ANNOUNCE: lock validator -V1
We are pleased to announce the first release of the "lock dependency correctness validator" kernel debugging feature, which can be downloaded from:
http://redhat.com/~mingo/lockdep-patches/
The easiest way to try lockdep on a testbox is to apply the combo patch to 2.6.17-rc4-mm3. The patch order is:
http://kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.17-rc4.tar.bz2
http://kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.17-rc4/2.6.17-rc4-mm3/2.6.17-rc4-mm3.bz2
http://redhat.com/~mingo/lockdep-patches/lockdep-combo.patch
do 'make oldconfig' and accept all the defaults for new config options - reboot into the kernel and if everything goes well it should boot up fine and you should have /proc/lockdep and /proc/lockdep_stats files.
Typically if the lock validator finds some problem it will print out voluminous debug output that begins with "BUG: ..." and which syslog output can be used by kernel developers to figure out the precise locking scenario.
What does the lock validator do? It "observes" and maps all locking rules as they occur dynamically (as triggered by the kernel's natural use of spinlocks, rwlocks, mutexes and rwsems). Whenever the lock validator subsystem detects a new locking scenario, it validates this new rule against the existing set of rules. If this new rule is consistent with the existing set of rules then the new rule is added transparently and the kernel continues as normal. If the new rule could create a deadlock scenario then this condition is printed out.
When determining validity of locking, all possible "deadlock scenarios" are considered: assuming arbitrary number of CPUs, arbitrary irq context and task context constellations, running arbitrary combinations of all the existing locking scenarios. In a typical system this means millions of separate scenarios. This is why we call it a "locking correctness" validator - for all rules that are observed the lock validator proves it with mathematical certainty that a deadlock could not occur (assuming that the lock validator implementation itself is correct and its internal data structures are not corrupted by some other kernel subsystem). [see more details and conditionals of this statement in include/linux/lockdep.h and Documentation/lockdep-design.txt]
Furthermore, this "all possible scenarios" property of the validator also enables the finding of complex, highly unlikely multi-CPU multi-context races via single single-context rules, increasing the likelyhood of finding bugs drastically. In practical terms: the lock validator already found a bug in the upstream kernel that could only occur on systems with 3 or more CPUs, and which needed 3 very unlikely code sequences to occur at once on the 3 CPUs. That bug was found and reported on a single-CPU system (!). So in essence a race will be found "piecemail-wise", triggering all the necessary components for the race, without having to reproduce the race scenario itself! In its short existence the lock validator found and reported many bugs before they actually caused a real deadlock.
To further increase the efficiency of the validator, the mapping is not per "lock instance", but per "lock-type". For example, all struct inode objects in the kernel have inode->inotify_mutex. If there are 10,000 inodes cached, then there are 10,000 lock objects. But ->inotify_mutex is a single "lock type", and all locking activities that occur against ->inotify_mutex are "unified" into this single lock-type. The advantage of the lock-type approach is that all historical ->inotify_mutex uses are mapped into a single (and as narrow as possible) set of locking rules - regardless of how many different tasks or inode structures it took to build this set of rules. The set of rules persist during the lifetime of the kernel.
To see the rough magnitude of checking that the lock validator does, here's a portion of /proc/lockdep_stats, fresh after bootup:
lock-types: 694 [max: 2048]
direct dependencies: 1598 [max: 8192]
indirect dependencies: 17896
all direct dependencies: 16206
dependency chains: 1910 [max: 8192]
in-hardirq chains: 17
in-softirq chains: 105
in-process chains: 1065
stack-trace entries: 38761 [max: 131072]
combined max dependencies: 2033928
hardirq-safe locks: 24
hardirq-unsafe locks: 176
softirq-safe locks: 53
softirq-unsafe locks: 137
irq-safe locks: 59
irq-unsafe locks: 176
The lock validator has observed 1598 actual single-thread locking patterns, and has validated all possible 2033928 distinct locking scenarios.
More details about the design of the lock validator can be found in Documentation/lockdep-design.txt, which can also found at:
http://redhat.com/~mingo/lockdep-patches/lockdep-design.txt
The patchqueue consists of 61 patches, and the changes are quite extensive:
215 files changed, 7693 insertions(+), 1247 deletions(-)
So be careful when testing.
We only plan to post the queue to lkml this time, we'll try to not flood lkml with future releases. The finegrained patch-queue can be also seen at:
http://redhat.com/~mingo/lockdep-patches/patches/
(the series file, with explanations about splitup categories of the patches can be found attached below.)
The lock validator has been build-tested with allyesconfig, and booted on x86 and x86_64. (Other architectures probably dont build/work yet.)
Comments, test-results, bug fixes, and improvements are welcome!
Ingo
# locking fixes (for bugs found by lockdep), not yet in mainline or -mm:
floppy-release-fix.patch
forcedeth-deadlock-fix.patch
# fixes for upstream that only triggers on lockdep:
sound_oss_emu10k1_midi-fix.patch
mutex-section-bug.patch
# locking subsystem debugging improvements:
warn-once.patch
add-module-address.patch
generic-lock-debugging.patch
locking-selftests.patch
spinlock-init-cleanups.patch
lock-init-improvement.patch
xfs-improve-mrinit-macro.patch
# stacktrace:
x86_64-beautify-stack-backtrace.patch
x86_64-document-stack-backtrace.patch
stacktrace.patch
x86_64-use-stacktrace-for-backtrace.patch
# irq-flags state tracing:
lockdep-fown-fixes.patch
lockdep-sk-callback-lock-fixes.patch
trace-irqflags.patch
trace-irqflags-cleanups-x86.patch
trace-irqflags-cleanups-x86_64.patch
local-irq-enable-in-hardirq.patch
# percpu subsystem feature needed for lockdep:
add-per-cpu-offset.patch
# lockdep subsystem core bits:
lockdep-core.patch
lockdep-proc.patch
lockdep-docs.patch
# make use of lockdep in locking subsystems:
lockdep-prove-rwsems.patch
lockdep-prove-spin_rwlocks.patch
lockdep-prove-mutexes.patch
# lockdep utility patches:
lockdep-print-types-in-sysrq.patch
lockdep-x86_64-early-init.patch
lockdep-i386-alternatives-off.patch
lockdep-printk-recursion.patch
lockdep-disable-nmi-watchdog.patch
# map all the locking details and quirks to lockdep:
lockdep-blockdev.patch
lockdep-direct-io.patch
lockdep-serial.patch
lockdep-dcache.patch
lockdep-namei.patch
lockdep-super.patch
lockdep-futex.patch
lockdep-genirq.patch
lockdep-kgdb.patch
lockdep-completions.patch
lockdep-waitqueue.patch
lockdep-mm.patch
lockdep-slab.patch
lockdep-skb_queue_head_init.patch
lockdep-timer.patch
lockdep-sched.patch
lockdep-hrtimer.patch
lockdep-sock.patch
lockdep-af_unix.patch
lockdep-lock_sock.patch
lockdep-mmap_sem.patch
lockdep-prune_dcache-workaround.patch
lockdep-jbd.patch
lockdep-posix-timers.patch
lockdep-sch_generic.patch
lockdep-xfrm.patch
lockdep-sound-seq-ports.patch
lockdep-enable-Kconfig.patch
PATCH 1/61 lock validator: floppy.c irq-release fix
From: Ingo Molnar <[email protected]>
floppy.c does alot of irq-unsafe work within floppy_release_irq_and_dma():free_irq(), release_region() ... so when executing in irq context, push the whole function into keventd.
--- drivers/block/floppy.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/block/floppy.c +25 -2
@@ -573,6 +573,21 @@ static int floppy_grab_irq_and_dma(void)static void floppy_release_irq_and_dma (void );/* +* Interrupt, DMA and region freeing must not be done from IRQ +* context - e.g. irq-unregistration means /proc VFS work, region +* release takes an irq-unsafe lock, etc. So we push this work +* into keventd: +*/ +static void fd_release_fn (void *data) +{ +mutex_lock (&open_lock); +floppy_release_irq_and_dma (); +mutex_unlock (&open_lock); +} + +static DECLARE_WORK(floppy_release_irq_and_dma_work, fd_release_fn, NULL); + +/* * The "reset" variable should be tested whenever an interrupt is scheduled, * after the commands have been sent. This is to ensure that the driver doesn't * get wedged when the interrupt doesn't come because of a failed command.
@@ -836,7 +851,7 @@ static int set_dor(int fdc, char mask, cif (newdor &FLOPPY_MOTOR_MASK )floppy_grab_irq_and_dma ();if (olddor &FLOPPY_MOTOR_MASK ) -floppy_release_irq_and_dma (); +schedule_work (&floppy_release_irq_and_dma_work);return olddor; }
@@ -917,6 +932,8 @@ static int _lock_fdc(int drive, int inteset_current_state (TASK_RUNNING );remove_wait_queue (&fdc_wait, &wait); + +flush_scheduled_work (); } command_status =FD_COMMAND_NONE ;
@@ -950,7 +967,7 @@ static inline void unlock_fdc(void)if (elv_next_request (floppy_queue))do_fd_request (floppy_queue);spin_unlock_irqrestore (&floppy_lock, flags); -floppy_release_irq_and_dma (); +schedule_work (&floppy_release_irq_and_dma_work);wake_up (&fdc_wait); }
@@ -4647,6 +4664,12 @@ void cleanup_module(void)del_timer_sync (&fd_timer);blk_cleanup_queue (floppy_queue); +/* +* Wait for any asynchronous floppy_release_irq_and_dma() +* calls to finish first: +*/ +flush_scheduled_work (); +if (usage_count)floppy_release_irq_and_dma ();
Re: [patch 01/61] lock validator: floppy.c irq-release fix
Quoted 3 lines · On Mon, 29 May 2006 23:22:56 +0200 Ingo Molnar <[email protected]> wrote:
floppy.cdoes alot of irq-unsafe work withinfloppy_release_irq_and_dma():free_irq(),release_region()... so when executing in irq context, push the whole function into keventd.
I seem to remember having issues with this - of the "not yet adequate" type. But I forget what they were. Perhaps we have enough flush_scheduled_work()s in there now.
We're glad to see you reassuming floppy.c maintenance.
PATCH 2/61 lock validator: forcedeth.c fix
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
nv_do_nic_poll() is called from timer softirqs, which has interrupts enabled, but np->lock might also be taken by some other interrupt context.
--- drivers/net/forcedeth.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/forcedeth.c +3 -2
@@ -2869,6 +2869,7 @@ static void nv_do_nic_poll(unsigned longstruct net_device *dev = (struct net_device *) data;struct fe_priv *np =netdev_priv (dev);u8 __iomem *base =get_hwbase (dev); +unsigned long flags;u32 mask =0 ;/*
@@ -2897,10 +2898,9 @@ static void nv_do_nic_poll(unsigned long mask |=NVREG_IRQ_OTHER ; } } +local_irq_save (flags); np->nic_poll_irq =0 ; -/* FIXME: Do we need synchronize_irq(dev->irq) here? */ -writel (mask, base + NvRegIrqMask);pci_push (base);
@@ -2924,6 +2924,7 @@ static void nv_do_nic_poll(unsigned longenable_irq (np->msi_x_entry[NV_MSI_X_VECTOR_OTHER ].vector); } } +local_irq_restore (flags); }#ifdef CONFIG_NET_POLL_CONTROLLER
Re: [patch 02/61] lock validator: forcedeth.c fix
Quoted 3 lines · On Mon, 29 May 2006 23:23:13 +0200 Ingo Molnar <[email protected]> wrote:
nv_do_nic_poll()is called from timer softirqs, which has interrupts enabled, butnp->lockmight also be taken by some other interrupt context.
But the driver does disable_irq(), so I'd say this was a false-positive.
And afaict this is not a timer handler - it's a poll_controller handler (although maybe that get called from timer handler somewhere?)
That being said, doing disable_irq() from a poll_controller handler is downright scary.
Anwyay, I'll tentatively mark this as a lockdep workaround, not a bugfix.
Re: [patch 02/61] lock validator: forcedeth.c fix
Quoted 11 lines · Andrew Morton
Quoted 5 lines · On Mon, 29 May 2006 23:23:13 +0200 Ingo Molnar <[email protected]> wrote:
nv_do_nic_poll()is called from timer softirqs, which has interrupts enabled, butnp->lockmight also be taken by some other interrupt context.
Quoted 7 lines
But the driver does
disable_irq(), so I'd say this was a false-positive.And afaict this is not a timer handler - it's a
poll_controllerhandler (although maybe that get called from timer handler somewhere?)
It's both a timer handler and a poll_controller handler:
- if the interrupt handler causes a system overload (gig e without irq mitigation...), then the nic disables the irq on the device and waits one tick and handles the interrupts from a timer. This is nv_do_nic_poll().
- nv_do_nic_poll is also called from the poll_controller handler.
I'll try to remove the disable_irq() calls from the poll_controller handler, but probably not before the week-end.
--
Manfred
PATCH 3/61 lock validator: sound/oss/emu10k1/midi.c cleanup
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
move the __attribute outside of the DEFINE_SPINLOCK() section.
--- sound/oss/emu10k1/midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/oss/emu10k1/midi.c +1 -1
@@ -45,7 +45,7 @@#include "../sound_config.h" #endif -static DEFINE_SPINLOCK(midi_spinlock __attribute((unused))); +static __attribute((unused))DEFINE_SPINLOCK (midi_spinlock);static void init_midi_hdr (struct midi_hdr *midihdr) {
Re: [patch 03/61] lock validator: sound/oss/emu10k1/midi.c cleanup
Quoted 13 lines · On Mon, 29 May 2006 23:23:19 +0200 Ingo Molnar <[email protected]> wrote:
move the
__attributeoutside of theDEFINE_SPINLOCK()section.Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- sound/oss/emu10k1/midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
linux/sound/oss/emu10k1/midi.c
===================================================================
sound/oss/emu10k1/midi.c line 51
Quoted 8 lines
sound/oss/emu10k1/midi.c +1
-1@@ -45,7 +45,7 @@#include "../sound_config.h" #endif -static DEFINE_SPINLOCK(midi_spinlock __attribute((unused))); +static __attribute((unused))DEFINE_SPINLOCK (midi_spinlock);static void init_midi_hdr (struct midi_hdr *midihdr) {
I'll tag this as for-mainline-via-alsa.
Takashi Iwai
Acked-byRe: [patch 03/61] lock validator: sound/oss/emu10k1/midi.c cleanup
At Mon, 29 May 2006 18:33:17 -0700,
Quoted 20 lines · Andrew Morton
Quoted 16 lines · On Mon, 29 May 2006 23:23:19 +0200 Ingo Molnar <[email protected]> wrote:
move the
__attributeoutside of theDEFINE_SPINLOCK()section.Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- sound/oss/emu10k1/midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
linux/sound/oss/emu10k1/midi.c
===================================================================sound/oss/emu10k1/midi.c +0
-0@@ -45,7 +45,7 @@#include "../sound_config.h" #endif
Quoted 7 lines
sound/oss/emu10k1/midi.c line 51
Quoted 5 lines
sound/oss/emu10k1/midi.c +1
-1-static DEFINE_SPINLOCK(midi_spinlock __attribute((unused))); +static __attribute((unused))DEFINE_SPINLOCK (midi_spinlock);static void init_midi_hdr (struct midi_hdr *midihdr) {I'll tag this as for-mainline-via-alsa.
It's OSS stuff, so feel free to push it from your side ;)
thanks,
Takashi
Re: [patch 03/61] lock validator: sound/oss/emu10k1/midi.c cleanup
Quoted 30 lines · Takashi Iwai
At Mon, 29 May 2006 18:33:17 -0700,
Quoted 20 lines · Andrew Morton
Quoted 16 lines · On Mon, 29 May 2006 23:23:19 +0200 Ingo Molnar <[email protected]> wrote:
move the
__attributeoutside of theDEFINE_SPINLOCK()section.Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- sound/oss/emu10k1/midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
linux/sound/oss/emu10k1/midi.c
===================================================================sound/oss/emu10k1/midi.c +0
-0@@ -45,7 +45,7 @@#include "../sound_config.h" #endif Quoted 7 lines
sound/oss/emu10k1/midi.c line 51
Quoted 5 lines
sound/oss/emu10k1/midi.c +1
-1-static DEFINE_SPINLOCK(midi_spinlock __attribute((unused))); +static __attribute((unused))DEFINE_SPINLOCK (midi_spinlock);static void init_midi_hdr (struct midi_hdr *midihdr) {I'll tag this as for-mainline-via-alsa.
Quoted 4 lines
Acked-by Takashi Iwai <[email protected]>It's OSS stuff, so feel free to push it from your side ;)
Why it is marked unused when in fact it's used?
[PATCH] Mark midi_spinlock as used
---
sound/oss/emu10k1/midi.c +1 -1
@@ -45,7 +45,7 @@#include "../sound_config.h" #endif -static DEFINE_SPINLOCK(midi_spinlock __attribute((unused))); +static DEFINE_SPINLOCK (midi_spinlock);static void init_midi_hdr (struct midi_hdr *midihdr) {
PATCH 4/61 lock validator: mutex section binutils workaround
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
work around weird section nesting build bug causing smp-alternatives failures under certain circumstances.
--- kernel/mutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/mutex.c +1 -1
@@ -309,7 +309,7 @@ static inline int __mutex_trylock_slowpa* This function must not be used in interrupt context. The * mutex must be released by the same task that acquired it. */ -int fastcall mutex_trylock(struct mutex *lock) +int fastcall __sched mutex_trylock(struct mutex *lock) {return __mutex_fastpath_trylock (&lock->count, __mutex_trylock_slowpath);
PATCH 5/61 lock validator: introduce WARN_ON_ONCE(cond)
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
add WARN_ON_ONCE(cond) to print once-per-bootup messages.
--- include/asm-generic/bug.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/asm-generic/bug.h +13 -0
@@ -44,4 +44,17 @@# define WARN_ON_SMP (x) do { } while (0)#endif +#define WARN_ON_ONCE (condition) \ +({ \ + static int __warn_once = 1; \ + int __ret = 0; \ + \ + if (unlikely(__warn_once && (condition))) { \ + __warn_once = 0; \ + WARN_ON(1); \ + __ret = 1; \ + } \ + __ret; \ +}) +#endif
Re: [patch 05/61] lock validator: introduce WARN_ON_ONCE(cond)
Quoted 20 lines · On Mon, 29 May 2006 23:23:28 +0200 Ingo Molnar <[email protected]> wrote:
add
WARN_ON_ONCE(cond)to print once-per-bootup messages.Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- include/asm-generic/bug.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)Index:
linux/include/asm-generic/bug.h
===================================================================include/asm-generic/bug.h +4
-0@@ -44,4 +44,17 @@# define WARN_ON_SMP (x) do { } while (0)#endif +#define WARN_ON_ONCE (condition) \ +({ \ + static int __warn_once = 1; \ + int __ret = 0; \
include/asm-generic/bug.h line 60
Quoted 10 lines
include/asm-generic/bug.h +9
-0+ \ +if (unlikely (__warn_once && (condition))) { \ + __warn_once =0 ; \ +WARN_ON (1 ); \ + __ret =1 ; \ + } \ + __ret; \ +}) +#endif
I'll queue this for mainline inclusion.
Steven Rostedt
maintainerRe: [patch 05/61] lock validator: introduce WARN_ON_ONCE(cond)
Quoted 19 lines · Andrew Morton
Quoted 16 lines · On Mon, 29 May 2006 23:23:28 +0200 Ingo Molnar <[email protected]> wrote:
add
WARN_ON_ONCE(cond)to print once-per-bootup messages.Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- include/asm-generic/bug.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)Index:
linux/include/asm-generic/bug.h
===================================================================include/asm-generic/bug.h +0
-0@@ -44,4 +44,17 @@# define WARN_ON_SMP (x) do { } while (0)#endif
Quoted 6 lines
include/asm-generic/bug.h line 52
Quoted 6 lines
include/asm-generic/bug.h +6
-0+#define WARN_ON_ONCE (condition) \ +({ \ + static int __warn_once = 1; \ + int __ret = 0; \ + \ + if (unlikely(__warn_once && (condition))) { \
Since __warn_once is likely to be true, and the condition is likely to be false, wouldn't it be better to switch this around to:
if (unlikely((condition) && __warn_once)) {So the && will fall out before having to check a global variable.
Only after the unlikely condition would the __warn_once be false.
-- Steve
Quoted 10 lines
include/asm-generic/bug.h line 60
Quoted 8 lines
include/asm-generic/bug.h +7
-0+ __warn_once =0 ; \ +WARN_ON (1 ); \ + __ret =1 ; \ + } \ + __ret; \ +}) +#endif I'll queue this for mainline inclusion.
Steven Rostedt
maintainerRe: [patch 05/61] lock validator: introduce WARN_ON_ONCE(cond)
Quoted 30 lines · Steven Rostedt
Quoted 19 lines · Andrew Morton
Quoted 16 lines · On Mon, 29 May 2006 23:23:28 +0200 Ingo Molnar <[email protected]> wrote:
add
WARN_ON_ONCE(cond)to print once-per-bootup messages.Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- include/asm-generic/bug.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)Index:
linux/include/asm-generic/bug.h
===================================================================include/asm-generic/bug.h +0
-0@@ -44,4 +44,17 @@# define WARN_ON_SMP (x) do { } while (0)#endif Quoted 6 lines
include/asm-generic/bug.h line 52
Quoted 6 lines
include/asm-generic/bug.h +6
-0+#define WARN_ON_ONCE (condition) \ +({ \ + static int __warn_once = 1; \ + int __ret = 0; \ + \ + if (unlikely(__warn_once && (condition))) { \Since
__warn_onceis likely to be true, and the condition is likely to be false, wouldn't it be better to switch this around to:
Quoted 5 lines
if (unlikely((condition) && __warn_once)) {So the && will fall out before having to check a global variable.
Only after the unlikely condition would the
__warn_oncebe false.
Hi Ingo,
Not sure if you missed this request or didn't think it mattered. But I just tried out the difference between the two to see what gcc would do to a simple function compiling with -O2.
Here's my code:
----- with the current WARN_ON_ONCE ----
#define unlikely(x) __builtin_expect(!!(x), 0)
#define WARN_ON_ONCE(condition) \
({ \
static int __warn_once = 1; \
int __ret = 0; \
\
if (__warn_once && unlikely((condition))) { \
__warn_once = 0; \
WARN_ON(1); \
__ret = 1; \
} \
__ret; \
})int warn (int x)
{
WARN_ON_ONCE(x==1);
return x+1;
}----- with the version I suggest. ----
#define unlikely(x) __builtin_expect(!!(x), 0)
#define WARN_ON_ONCE(condition) \
({ \
static int __warn_once = 1; \
int __ret = 0; \
\
if (unlikely((condition)) && __warn_once) { \
__warn_once = 0; \
WARN_ON(1); \
__ret = 1; \
} \
__ret; \
})int warn(int x)
{
WARN_ON_ONCE(x==1);
return x+1;
}-------
Compiling these two I get this:
current warn.o:
00000000 <warn>:
0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 53 push %ebx 4: 83 ec 04 sub $0x4,%esp 7: a1 00 00 00 00 mov 0x0,%eax c: 8b 5d 08 mov 0x8(%ebp),%ebx
# here we test the __warn_once first and if it is not zero # it jumps to warn+0x20 to do the condition test f: 85 c0 test %eax,%eax 11: 75 0d jne 20 <warn+0x20> 13: 5a pop %edx 14: 8d 43 01 lea 0x1(%ebx),%eax 17: 5b pop %ebx 18: 5d pop %ebp 19: c3 ret 1a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 20: 83 fb 01 cmp $0x1,%ebx 23: 75 ee jne 13 <warn+0x13> 25: 31 c9 xor %ecx,%ecx 27: 89 0d 00 00 00 00 mov %ecx,0x0 2d: c7 04 24 01 00 00 00 movl $0x1,(%esp) 34: e8 fc ff ff ff call 35 <warn+0x35> 39: eb d8 jmp 13 <warn+0x13> Disassembly of section .data:
My suggested change of doing the condition first:
00000000 <warn>:
0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 53 push %ebx 4: 83 ec 04 sub $0x4,%esp 7: 8b 5d 08 mov 0x8(%ebp),%ebx
# here we test the condition first, and if it the # unlikely condition is true, then we jump to test # the __warn_once. a: 83 fb 01 cmp $0x1,%ebx d: 74 07 je 16 <warn+0x16> f: 5a pop %edx 10: 8d 43 01 lea 0x1(%ebx),%eax 13: 5b pop %ebx 14: 5d pop %ebp 15: c3 ret 16: a1 00 00 00 00 mov 0x0,%eax 1b: 85 c0 test %eax,%eax 1d: 74 f0 je f <warn+0xf> 1f: 31 c9 xor %ecx,%ecx 21: 89 0d 00 00 00 00 mov %ecx,0x0 27: c7 04 24 01 00 00 00 movl $0x1,(%esp) 2e: e8 fc ff ff ff call 2f <warn+0x2f> 33: eb da jmp f <warn+0xf> Disassembly of section .data:
As you can see, because the whole thing is unlikely, the first condition is expected to fail. With the current WARN_ON logic, that means that the __warn_once is expected to fail, but that's not the case. So on a normal system where the WARN_ON_ONCE condition would never happen, you
are always branching. So simply reversing the order to test the
condition before testing the __warn_once variable should improve cache performance.
Below is my recommended patch.
-- Steve
include/asm-generic/bug.h +1 -1
@@ -43,7 +43,7 @@static int __warn_once =1 ; \int __ret =0 ; \ \ -if (unlikely (__warn_once && (condition))) { \ +if (unlikely ((condition) && __warn_once)) { \ __warn_once =0 ; \WARN_ON (1 ); \ __ret =1 ; \
Re: [patch 05/61] lock validator: introduce WARN_ON_ONCE(cond)
Quoted 6 lines · Steven Rostedt
As you can see, because the whole thing is unlikely, the first condition is expected to fail. With the current
WARN_ONlogic, that means that the__warn_onceis expected to fail, but that's not the case. So on a normal system where theWARN_ON_ONCEcondition would never happen, you are always branching.
which is no cost since it's consistent for the branch predictor
include/asm-generic/bug.h line 47
Quoted 6 lines
So simply reversing the order to test the
condition before testing the__warn_oncevariable should improve cache performance.include/asm-generic/bug.h +1
-1-if (unlikely (__warn_once && (condition))) { \ +if (unlikely ((condition) && __warn_once)) { \ __warn_once =0 ; \
I disagree with this; "condition" can be a relatively complex thing, such as a function call. doing the cheaper (and consistent!) test first will be better. __warn_once will be branch predicted correctly ALWAYS, except the exact ONE time you turn hit the backtrace. So it's really really cheap to test, and if the WARN_ON_ONCE is triggering a lot after the first time, you now would have a flapping first condition (which means lots of branch mispredicts) while the original code has a perfect one-check-predicted-exit scenario.
Steven Rostedt
maintainerRe: [patch 05/61] lock validator: introduce WARN_ON_ONCE(cond)
Quoted 11 lines · Arjan van de Ven
Quoted 6 lines · Steven Rostedt
As you can see, because the whole thing is unlikely, the first condition is expected to fail. With the current
WARN_ONlogic, that means that the__warn_onceis expected to fail, but that's not the case. So on a normal system where theWARN_ON_ONCEcondition would never happen, you are always branching.which is no cost since it's consistent for the branch predictor
Quoted 10 lines
include/asm-generic/bug.h line 47
Quoted 6 lines
So simply reversing the order to test the
condition before testing the__warn_oncevariable should improve cache performance.include/asm-generic/bug.h +1
-1-if (unlikely (__warn_once && (condition))) { \ +if (unlikely ((condition) && __warn_once)) { \ __warn_once =0 ; \I disagree with this; "condition" can be a relatively complex thing, such as a function call. doing the cheaper (and consistent!) test first will be better.
Wrong! It's not better, because it is pretty much ALWAYS TRUE! So even if you have branch prediction you will call the condition regardless!
Quoted 6 lines
__warn_oncewill be branch predicted correctly ALWAYS, except the exact ONE time you turn hit the backtrace. So it's really really cheap to test, and if theWARN_ON_ONCEis triggering a lot after the first time, you now would have a flapping first condition (which means lots of branch mispredicts) while the original code has a perfect one-check-predicted-exit scenario.
Who cares? If the WARN_ON_ONCE _is_ triggered a bunch of times, that means the kernel is broken. The WARN_ON is about checking for validity, and the condition should never trigger on a proper setup. The ONCE part is to keep the users logs from getting full and killing performance with printk. And even so. If you have 100 instances of WARN_ON_ONCE in the kernel, only one at time would probably trigger, so you save on the other 99. Your idea is to optimize the broken kernel while punishing the working one.
The analysis wasn't only about the code, but also about the use of WARN_ON_ONCE. The condition should _not_ be too complex and slow since the WARN_ON_ONCE is just a check, and not something that should slow the system down too much.
One other thing that wasn't mentioned. The __warn_once variable is global and not setup as a read_mostly (which maybe it should). Because now it can be placed in the same cache line as some global variable that is modified a lot, so every time you test __warn_once you need to do a cache coherency with other CPUS, thus bringing down the performance further.
-- Steve
PATCH 6/61 lock validator: add __module_address() method
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
add __module_address() method - to be used by lockdep.
--- include/linux/module.h | 6 ++++++ kernel/module.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+)
include/linux/module.h +6 -0
@@ -371,6 +371,7 @@ static inline int module_is_live(struct/* Is this address in a module? (second is with no locks, for oops) */ struct module *module_text_address (unsigned long addr);struct module *__module_text_address (unsigned long addr); +int __module_address (unsigned long addr);/* Returns module and fills in value, defined and namebuf, or NULL if symnum out of range. */
@@ -509,6 +510,11 @@ static inline struct module *__module_tereturn NULL ; } +static inline int __module_address (unsigned long addr) +{ +return 0 ; +} +/* Get/put a kernel symbol (calls should be symmetric) */ #define symbol_get (x) ({ extern typeof(x) x __attribute__((weak)); &(x); })#define symbol_put (x) do { } while(0)
kernel/module.c +14 -0
@@ -2222,6 +2222,20 @@ const struct exception_table_entry *searreturn e; } +/* +* Is this a valid module address? We don't grab the lock. +*/ +int __module_address (unsigned long addr) +{ +struct module *mod; + +list_for_each_entry (mod, &modules, list) +if (within (addr, mod->module_core, mod->core_size)) +return 1 ; +return 0 ; +} + +/* Is this a valid kernel address? We don't grab the lock: we are oopsing. */ struct module *__module_text_address (unsigned long addr) {
Re: [patch 06/61] lock validator: add __module_address() method
kernel/module.c const struct exception_table_entry *sear · line 2236
Quoted 12 lines · On Mon, 29 May 2006 23:23:33 +0200 Ingo Molnar <[email protected]> wrote:
kernel/module.c +12
-0+/* +* Is this a valid module address? We don't grab the lock. +*/ +int __module_address (unsigned long addr) +{ +struct module *mod; + +list_for_each_entry (mod, &modules, list) +if (within (addr, mod->module_core, mod->core_size)) +return 1 ; +return 0 ; +}
Returns a boolean.
Quoted 2 lines
/* Is this a valid kernel address? We don't grab the lock: we are oopsing. */ struct module *__module_text_address(unsigned long addr)
But this returns a module*.
I'd suggest that __module_address() should do the same thing, from an API neatness POV. Although perhaps that's mot very useful if we didn't take a ref on the returned object (but module_text_address() doesn't either).
Also, the name's a bit misleading - it sounds like it returns the address of a module or something. __module_any_address() would be better, perhaps?
Also, how come this doesn't need modlist_lock()?
Steven Rostedt
maintainerRe: [patch 06/61] lock validator: add __module_address() method
Quoted 7 lines · Andrew Morton
I'd suggest that
__module_address()should do the same thing, from an API neatness POV. Although perhaps that's mot very useful if we didn't take a ref on the returned object (butmodule_text_address()doesn't either).Also, the name's a bit misleading - it sounds like it returns the address of a module or something.
__module_any_address()would be better, perhaps?
How about __valid_module_address() so that it describes exactly what it is doing. Or __module_address_valid().
-- Steve
Quoted 2 lines
Also, how come this doesn't need
modlist_lock()?
Re: [patch 06/61] lock validator: add __module_address() method
In reply to Andrew MortonQuoted 23 lines · Andrew Morton
kernel/module.c const struct exception_table_entry *sear · line 2236
Quoted 12 lines · On Mon, 29 May 2006 23:23:33 +0200 Ingo Molnar <[email protected]> wrote:
kernel/module.c +12
-0+/* +* Is this a valid module address? We don't grab the lock. +*/ +int __module_address (unsigned long addr) +{ +struct module *mod; + +list_for_each_entry (mod, &modules, list) +if (within (addr, mod->module_core, mod->core_size)) +return 1 ; +return 0 ; +}Returns a boolean.
Quoted 2 lines
/* Is this a valid kernel address? We don't grab the lock: we are oopsing. */ struct module *__module_text_address(unsigned long addr)
But this returns a module*.
Quoted 8 lines
I'd suggest that
__module_address()should do the same thing, from an API neatness POV. Although perhaps that's mot very useful if we didn't take a ref on the returned object (butmodule_text_address()doesn't either).Also, the name's a bit misleading - it sounds like it returns the address of a module or something.
__module_any_address()would be better, perhaps?
yeah. I changed this to __is_module_address().
Quoted 1 line
Also, how come this doesn't need
modlist_lock()?
indeed. I originally avoided taking that lock due to recursion worries - but in fact we use this only in sections that initialize a lock - hence no recursion problems.
i fixed this and renamed the function to is_module_address() :)
Ingo
PATCH 7/61 lock validator: better lock debugging
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
generic lock debugging:
- generalized lock debugging framework. For example, a bug in one lock subsystem turns off debugging in all lock subsystems.
- got rid of the caller address passing from the mutex/rtmutex debugging
code: it caused way too much prototype hackery, and lockdep will give the same information anyway.
- ability to do silent tests
- check lock freeing in vfree too.
- more finegrained debugging options, to allow distributions to turn off more expensive debugging features.
--- drivers/char/sysrq.c | 2 include/asm-generic/mutex-null.h | 11 - include/linux/debug_locks.h | 62 ++++++++ include/linux/init_task.h | 1 include/linux/mm.h | 8 - include/linux/mutex-debug.h | 12 - include/linux/mutex.h | 6 include/linux/rtmutex.h | 10 - include/linux/sched.h | 4 init/main.c | 9 + kernel/exit.c | 5 kernel/fork.c | 4 kernel/mutex-debug.c | 289 +++---------------------------------- kernel/mutex-debug.h | 87 +---------- kernel/mutex.c | 83 +++++++--- kernel/mutex.h | 18 -- kernel/rtmutex-debug.c | 302 +-------------------------------------- kernel/rtmutex-debug.h | 8 - kernel/rtmutex.c | 45 ++--- kernel/rtmutex.h | 3 kernel/sched.c | 16 +- lib/Kconfig.debug | 26 ++- lib/Makefile | 2 lib/debug_locks.c | 45 +++++ lib/spinlock_debug.c | 60 +++---- mm/vmalloc.c | 2 26 files changed, 329 insertions(+), 791 deletions(-)
drivers/char/sysrq.c +1 -1
@@ -152,7 +152,7 @@ static struct sysrq_key_op sysrq_mountrostatic void sysrq_handle_showlocks (int key,struct pt_regs *pt_regs,struct tty_struct *tty) { -mutex_debug_show_all_locks (); +debug_show_all_locks (); }static struct sysrq_key_op sysrq_showlocks_op = { .handler = sysrq_handle_showlocks,
include/asm-generic/mutex-null.h +3 -8
@@ -10,14 +10,9 @@#ifndef _ASM_GENERIC_MUTEX_NULL_H#define _ASM_GENERIC_MUTEX_NULL_H -/* extra parameter only needed for mutex debugging: */ -#ifndef __IP__ -# define __IP__ -#endif - -#define __mutex_fastpath_lock (count, fail_fn) fail_fn(count __RET_IP__) -#define __mutex_fastpath_lock_retval (count, fail_fn) fail_fn(count __RET_IP__) -#define __mutex_fastpath_unlock (count, fail_fn) fail_fn(count __RET_IP__) +#define __mutex_fastpath_lock (count, fail_fn) fail_fn(count) +#define __mutex_fastpath_lock_retval (count, fail_fn) fail_fn(count) +#define __mutex_fastpath_unlock (count, fail_fn) fail_fn(count)#define __mutex_fastpath_trylock (count, fail_fn) fail_fn(count)#define __mutex_slowpath_needs_to_unlock () 1
include/linux/debug_locks.h new file +62 -0
62 lines not on this page · raw message
include/linux/init_task.h +0 -1
@@ -133,7 +133,6 @@ extern struct group_info init_groups; .journal_info = NULL, \ .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .fs_excl = ATOMIC_INIT(0), \ - INIT_RT_MUTEXES(tsk) \ }
include/linux/mm.h +1 -7
@@ -14,6 +14,7 @@#include <linux/prio_tree.h> #include <linux/fs.h> #include <linux/mutex.h> +#include <linux/debug_locks.h> struct mempolicy ;struct anon_vma ;
@@ -1080,13 +1081,6 @@ static inline void vm_stat_account(struc }#endif /* CONFIG_PROC_FS */ -static inline void -debug_check_no_locks_freed (const void *from,unsigned long len) -{ -mutex_debug_check_no_locks_freed (from, len); -rt_mutex_debug_check_no_locks_freed (from, len); -} -#ifndef CONFIG_DEBUG_PAGEALLOC static inline void kernel_map_pages (struct page *page,int numpages,int enable)
include/linux/mutex-debug.h +3 -9
@@ -7,17 +7,11 @@* Mutexes - debugging helpers: */ -#define __DEBUG_MUTEX_INITIALIZER (lockname) \ - , .held_list = LIST_HEAD_INIT(lockname.held_list), \ - .name = #lockname , .magic = &lockname +#define __DEBUG_MUTEX_INITIALIZER (lockname) \ + , .magic = &lockname -#define mutex_init (sem) __mutex_init(sem, __FUNCTION__) +#define mutex_init (sem) __mutex_init(sem, __FILE__":"#sem)extern void FASTCALL (mutex_destroy (struct mutex *lock)); -extern void mutex_debug_show_all_locks (void ); -extern void mutex_debug_show_held_locks (struct task_struct *filter); -extern void mutex_debug_check_no_locks_held (struct task_struct *task); -extern void mutex_debug_check_no_locks_freed (const void *from,unsigned long len); -#endif
include/linux/mutex.h +0 -6
@@ -50,8 +50,6 @@ struct mutex {struct list_head wait_list;#ifdef CONFIG_DEBUG_MUTEXES struct thread_info *owner; -struct list_head held_list; -unsigned long acquire_ip;const char *name;void *magic;#endif
@@ -76,10 +74,6 @@ struct mutex_waiter {# define __DEBUG_MUTEX_INITIALIZER (lockname)# define mutex_init (mutex) __mutex_init(mutex, NULL)# define mutex_destroy (mutex) do { } while (0) -# define mutex_debug_show_all_locks () do { } while (0) -# define mutex_debug_show_held_locks (p) do { } while (0) -# define mutex_debug_check_no_locks_held (task) do { } while (0) -# define mutex_debug_check_no_locks_freed (from, len) do { } while (0)#endif #define __MUTEX_INITIALIZER (lockname) \
include/linux/rtmutex.h +0 -10
@@ -29,8 +29,6 @@ struct rt_mutex {struct task_struct *owner;#ifdef CONFIG_DEBUG_RT_MUTEXES int save_state; -struct list_head held_list_entry; -unsigned long acquire_ip;const char *name, *file;int line;void *magic;
@@ -98,14 +96,6 @@ extern int rt_mutex_trylock(struct rt_muextern void rt_mutex_unlock (struct rt_mutex *lock); -#ifdef CONFIG_DEBUG_RT_MUTEXES -# define INIT_RT_MUTEX_DEBUG (tsk) \ - .held_list_head = LIST_HEAD_INIT(tsk.held_list_head), \ - .held_list_lock = SPIN_LOCK_UNLOCKED -#else -# define INIT_RT_MUTEX_DEBUG (tsk) -#endif -#ifdef CONFIG_RT_MUTEXES # define INIT_RT_MUTEXES (tsk) \ .pi_waiters = PLIST_HEAD_INIT(tsk.pi_waiters, tsk.pi_lock), \
include/linux/sched.h +0 -4
@@ -910,10 +910,6 @@ struct task_struct {struct plist_head pi_waiters;/* Deadlock detection and priority inheritance handling */ struct rt_mutex_waiter *pi_blocked_on; -# ifdef CONFIG_DEBUG_RT_MUTEXES -spinlock_t held_list_lock; -struct list_head held_list_head; -# endif #endif #ifdef CONFIG_DEBUG_MUTEXES
init/main.c +9 -0
@@ -53,6 +53,7 @@#include <linux/key.h> #include <linux/root_dev.h> #include <linux/buffer_head.h> +#include <linux/debug_locks.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -512,6 +513,14 @@ asmlinkage void __init start_kernel(voidpanic (panic_later, panic_param);profile_init ();local_irq_enable (); + +/* +* Need to run this when irqs are enabled, because it wants +* to self-test [hard/soft]-irqs on/off lock inversion bugs +* too: +*/ +locking_selftest (); +#ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok && initrd_start < min_low_pfn <<PAGE_SHIFT ) {
kernel/exit.c +2 -3
@@ -952,10 +952,9 @@ fastcall NORET_TYPE void do_exit(long coif (unlikely (current->pi_state_cache))kfree (current->pi_state_cache);/* -* If DEBUG_MUTEXES is on, make sure we are holding no locks: +* Make sure we are holding no locks: */ -mutex_debug_check_no_locks_held (tsk); -rt_mutex_debug_check_no_locks_held (tsk); +debug_check_no_locks_held (tsk);if (tsk->io_context)exit_io_context ();
kernel/fork.c +0 -4
@@ -921,10 +921,6 @@ static inline void rt_mutex_init_task(stspin_lock_init (&p->pi_lock);plist_head_init (&p->pi_waiters, &p->pi_lock); p->pi_blocked_on =NULL ; -# ifdef CONFIG_DEBUG_RT_MUTEXES -spin_lock_init (&p->held_list_lock); -INIT_LIST_HEAD (&p->held_list_head); -# endif #endif }
kernel/mutex-debug.c +26 -263
403 lines not on this page · raw message
kernel/mutex-debug.h +10 -77
120 lines not on this page · raw message
kernel/mutex.c +61 -22
193 lines not on this page · raw message
kernel/mutex.h +7 -11
@@ -19,19 +19,15 @@#define DEBUG_WARN_ON (c) do { } while (0)#define debug_mutex_set_owner (lock, new_owner) do { } while (0)#define debug_mutex_clear_owner (lock) do { } while (0) -#define debug_mutex_init_waiter (waiter) do { } while (0)#define debug_mutex_wake_waiter (lock, waiter) do { } while (0)#define debug_mutex_free_waiter (waiter) do { } while (0) -#define debug_mutex_add_waiter (lock, waiter, ti, ip) do { } while (0) +#define debug_mutex_add_waiter (lock, waiter, ti) do { } while (0) +#define mutex_acquire (lock, subtype, trylock) do { } while (0) +#define mutex_release (lock, nested) do { } while (0)#define debug_mutex_unlock (lock) do { } while (0)#define debug_mutex_init (lock, name) do { } while (0) -/* -* Return-address parameters/declarations. They are very useful for -* debugging, but add overhead in the !DEBUG case - so we go the -* trouble of using this not too elegant but zero-cost solution: -*/ -#define __IP_DECL__ -#define __IP__ -#define __RET_IP__ - +static inline void +debug_mutex_lock_common (struct mutex *lock,struct mutex_waiter *waiter) +{ +}
kernel/rtmutex-debug.c +15 -287
364 lines not on this page · raw message
kernel/rtmutex-debug.h +2 -6
@@ -9,20 +9,16 @@* This file contains macros used solely by rtmutex.c. Debug version. */ -#define __IP_DECL__ , unsigned long ip -#define __IP__ , ip -#define __RET_IP__ , (unsigned long)__builtin_return_address(0) -extern void rt_mutex_deadlock_account_lock (struct rt_mutex *lock,struct task_struct *task);extern void rt_mutex_deadlock_account_unlock (struct task_struct *task);extern void debug_rt_mutex_init_waiter (struct rt_mutex_waiter *waiter);extern void debug_rt_mutex_free_waiter (struct rt_mutex_waiter *waiter);extern void debug_rt_mutex_init (struct rt_mutex *lock,const char *name); -extern void debug_rt_mutex_lock(struct rt_mutex *lock __IP_DECL__); +extern void debug_rt_mutex_lock (struct rt_mutex *lock);extern void debug_rt_mutex_unlock (struct rt_mutex *lock);extern void debug_rt_mutex_proxy_lock (struct rt_mutex *lock, - struct task_struct *powner __IP_DECL__); +struct task_struct *powner);extern void debug_rt_mutex_proxy_unlock (struct rt_mutex *lock);extern void debug_rt_mutex_deadlock (int detect,struct rt_mutex_waiter *waiter,struct rt_mutex *lock);
kernel/rtmutex.c +21 -24
166 lines not on this page · raw message
kernel/rtmutex.h +0 -3
@@ -10,9 +10,6 @@* Non-debug version. */ -#define __IP_DECL__ -#define __IP__ -#define __RET_IP__#define rt_mutex_deadlock_check (l) (0)#define rt_mutex_deadlock_account_lock (m, t) do { } while (0)#define rt_mutex_deadlock_account_unlock (l) do { } while (0)
kernel/sched.c +11 -5
@@ -30,6 +30,7 @@#include <linux/capability.h> #include <linux/completion.h> #include <linux/kernel_stat.h> +#include <linux/debug_locks.h> #include <linux/security.h> #include <linux/notifier.h> #include <linux/profile.h>
@@ -3158,12 +3159,13 @@ void fastcall add_preempt_count(int val)/* * Underflow? */ -BUG_ON ((preempt_count () <0 )); +if (DEBUG_WARN_ON ((preempt_count () <0 ))) +return ;preempt_count () += val;/* * Spinlock count overflowing soon? */ -BUG_ON ((preempt_count () &PREEMPT_MASK ) >=PREEMPT_MASK -10 ); +DEBUG_WARN_ON ((preempt_count () &PREEMPT_MASK ) >=PREEMPT_MASK -10 ); }EXPORT_SYMBOL (add_preempt_count);
@@ -3172,11 +3174,15 @@ void fastcall sub_preempt_count(int val)/* * Underflow? */ -BUG_ON (val >preempt_count ()); +if (DEBUG_WARN_ON (val >preempt_count ())) +return ;/* * Is the spinlock portion underflowing? */ -BUG_ON ((val <PREEMPT_MASK ) && !(preempt_count () &PREEMPT_MASK )); +if (DEBUG_WARN_ON ((val <PREEMPT_MASK ) && + !(preempt_count () &PREEMPT_MASK ))) +return ; +preempt_count () -= val; }EXPORT_SYMBOL (sub_preempt_count);
@@ -4715,7 +4721,7 @@ void show_state(void) }while_each_thread (g, p);read_unlock (&tasklist_lock); -mutex_debug_show_all_locks (); +debug_show_all_locks (); }/**
lib/Kconfig.debug +22 -4
@@ -130,12 +130,30 @@ config DEBUG_PREEMPT will detect preemption count underflows. config DEBUG_MUTEXES - bool "Mutex debugging, deadlock detection" - default n + bool "Mutex debugging, basic checks" + default y depends on DEBUG_KERNEL help - This allows mutex semantics violations and mutex related deadlocks - (lockups) to be detected and reported automatically. + This feature allows mutex semantics violations to be detected and + reported. + +config DEBUG_MUTEX_ALLOC + bool "Detect incorrect freeing of live mutexes" + default y + depends on DEBUG_MUTEXES + help + This feature will check whether any held mutex is incorrectly + freed by the kernel, via any of the memory-freeing routines + (kfree(), kmem_cache_free(), free_pages(), vfree(), etc.), + or whether there is any lock held during task exit. + +config DEBUG_MUTEX_DEADLOCKS + bool "Detect mutex related deadlocks" + default y + depends on DEBUG_MUTEXES + help + This feature will automatically detect and report mutex related + deadlocks, as they happen. config DEBUG_RT_MUTEXES bool "RT Mutex debugging, deadlock detection"
lib/Makefile +1 -1
@@ -11,7 +11,7 @@ lib-$(CONFIG_SMP) += cpumask.o lib-y += kobject.o kref.o kobject_uevent.o klist.o -obj-y += sort.o parser.o halfmd4.o iomap_copy.o +obj-y += sort.o parser.o halfmd4.o iomap_copy.o debug_locks.o ifeq ($(CONFIG_DEBUG_KOBJECT),y) CFLAGS_kobject.o += -DDEBUG
lib/debug_locks.c new file +45 -0
45 lines not on this page · raw message
lib/spinlock_debug.c +25 -35
83 lines not on this page · raw message
mm/vmalloc.c +2 -0
@@ -330,6 +330,8 @@ void __vunmap(void *addr, int deallocatereturn ; } +debug_check_no_locks_freed (addr, area->size); +if (deallocate_pages) {int i;
Re: [patch 07/61] lock validator: better lock debugging
Quoted 23 lines · On Mon, 29 May 2006 23:23:37 +0200 Ingo Molnar <[email protected]> wrote:
include/linux/debug_locks.h new file +20
-0@@ -0,0 +1,62 @@ +#ifndef __LINUX_DEBUG_LOCKING_H +#define __LINUX_DEBUG_LOCKING_H + +extern int debug_locks; +extern int debug_locks_silent; + +/* +* Generic 'turn off all lock debugging' function: +*/ +extern int debug_locks_off (void ); + +/* +* In the debug case we carry the caller's instruction pointer into +* other functions, but we dont want the function argument overhead +* in the nondebug case - hence these macros: +*/ +#define _RET_IP_ (unsigned long)__builtin_return_address(0) +#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) + +#define DEBUG_WARN_ON (c) \
include/linux/debug_locks.h line 30
Quoted 10 lines
include/linux/debug_locks.h new file +10
-0+({ \ +int __ret =0 ; \ + \ +if (unlikely (c)) { \ +if (debug_locks_off ()) \ +WARN_ON (1 ); \ + __ret =1 ; \ + } \ + __ret; \ +})
Either the name of this thing is too generic, or we _make_ it generic, in which case it's in the wrong header file.
include/linux/debug_locks.h line 36
Quoted 5 lines
include/linux/debug_locks.h new file +5
-0+#ifdef CONFIG_SMP +# define SMP_DEBUG_WARN_ON (c) DEBUG_WARN_ON(c) +#else +# define SMP_DEBUG_WARN_ON (c) do { } while (0) +#endif
Probably ditto.
Re: [patch 07/61] lock validator: better lock debugging
Quoted 6 lines · Andrew Morton
Quoted 6 lines
include/linux/debug_locks.h new file +6
-0+#define DEBUG_WARN_ON (c) \ +({ \ + int __ret = 0; \ + \ + if (unlikely(c)) { \ + if (debug_locks_off()) \
Quoted 8 lines
include/linux/debug_locks.h line 30
Quoted 5 lines
include/linux/debug_locks.h new file +5
-0+WARN_ON (1 ); \ + __ret =1 ; \ + } \ + __ret; \ +})Either the name of this thing is too generic, or we _make_ it generic, in which case it's in the wrong header file.
this op is only intended to be used only by the lock debugging infrastructure. So it should be renamed - but i fail to find a good name for it. (it's used quite frequently within the lock debugging code, at 60+ places) Maybe INTERNAL_WARN_ON()? [that makes it sound special enough.] DEBUG_LOCKS_WARN_ON() might work too.
Quoted 7 lines
include/linux/debug_locks.h line 36
Quoted 5 lines
include/linux/debug_locks.h new file +5
-0+#ifdef CONFIG_SMP +# define SMP_DEBUG_WARN_ON (c) DEBUG_WARN_ON(c) +#else +# define SMP_DEBUG_WARN_ON (c) do { } while (0) +#endif Probably ditto.
agreed.
Ingo
Re: [patch 07/61] lock validator: better lock debugging
Quoted 18 lines · On Fri, 23 Jun 2006 12:25:23 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
Quoted 6 lines
include/linux/debug_locks.h new file +6
-0+#define DEBUG_WARN_ON (c) \ +({ \ + int __ret = 0; \ + \ + if (unlikely(c)) { \ + if (debug_locks_off()) \Quoted 8 lines
include/linux/debug_locks.h line 30
Quoted 5 lines
include/linux/debug_locks.h new file +5
-0+WARN_ON (1 ); \ + __ret =1 ; \ + } \ + __ret; \ +})Either the name of this thing is too generic, or we _make_ it generic, in which case it's in the wrong header file.
Quoted 5 lines
this op is only intended to be used only by the lock debugging infrastructure. So it should be renamed - but i fail to find a good name for it. (it's used quite frequently within the lock debugging code, at 60+ places) Maybe
INTERNAL_WARN_ON()? [that makes it sound special enough.]DEBUG_LOCKS_WARN_ON()might work too.
Well it has a debug_locks_off() in there, so DEBUG_LOCKS_WARN_ON() seems right.
Re: [patch 07/61] lock validator: better lock debugging
Quoted 11 lines · Andrew Morton
Quoted 8 lines
Quoted 2 lines
Either the name of this thing is too generic, or we _make_ it generic, in which case it's in the wrong header file.
this op is only intended to be used only by the lock debugging infrastructure. So it should be renamed - but i fail to find a good name for it. (it's used quite frequently within the lock debugging code, at 60+ places) Maybe
INTERNAL_WARN_ON()? [that makes it sound special enough.]DEBUG_LOCKS_WARN_ON()might work too.Well it has a
debug_locks_off()in there, soDEBUG_LOCKS_WARN_ON()seems right.
done.
Ingo
PATCH 8/61 lock validator: locking API self-tests
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
introduce DEBUG_LOCKING_API_SELFTESTS, which uses the generic lock debugging code's silent-failure feature to run a matrix of testcases. There are 210 testcases currently:
------------------------
| Locking API testsuite:
----------------------------------------------------------------------------
| spin |wlock |rlock |mutex | wsem | rsem |
--------------------------------------------------------------------------
A-A deadlock: ok | ok | ok | ok | ok | ok |
A-B-B-A deadlock: ok | ok | ok | ok | ok | ok |
A-B-B-C-C-A deadlock: ok | ok | ok | ok | ok | ok |
A-B-C-A-B-C deadlock: ok | ok | ok | ok | ok | ok |
A-B-B-C-C-D-D-A deadlock: ok | ok | ok | ok | ok | ok |
A-B-C-D-B-D-D-A deadlock: ok | ok | ok | ok | ok | ok |
A-B-C-D-B-C-D-A deadlock: ok | ok | ok | ok | ok | ok |
double unlock: ok | ok | ok | ok | ok | ok |
bad unlock order: ok | ok | ok | ok | ok | ok |
--------------------------------------------------------------------------
recursive read-lock: | ok | | ok |
--------------------------------------------------------------------------
non-nested unlock: ok | ok | ok | ok |
------------------------------------------------------------
hard-irqs-on + irq-safe-A/12: ok | ok | ok |
soft-irqs-on + irq-safe-A/12: ok | ok | ok |
hard-irqs-on + irq-safe-A/21: ok | ok | ok |
soft-irqs-on + irq-safe-A/21: ok | ok | ok |
sirq-safe-A => hirqs-on/12: ok | ok | ok |
sirq-safe-A => hirqs-on/21: ok | ok | ok |
hard-safe-A + irqs-on/12: ok | ok | ok |
soft-safe-A + irqs-on/12: ok | ok | ok |
hard-safe-A + irqs-on/21: ok | ok | ok |
soft-safe-A + irqs-on/21: ok | ok | ok |
hard-safe-A + unsafe-B #1/123: ok | ok | ok |
soft-safe-A + unsafe-B #1/123: ok | ok | ok |
hard-safe-A + unsafe-B #1/132: ok | ok | ok |
soft-safe-A + unsafe-B #1/132: ok | ok | ok |
hard-safe-A + unsafe-B #1/213: ok | ok | ok |
soft-safe-A + unsafe-B #1/213: ok | ok | ok |
hard-safe-A + unsafe-B #1/231: ok | ok | ok |
soft-safe-A + unsafe-B #1/231: ok | ok | ok |
hard-safe-A + unsafe-B #1/312: ok | ok | ok |
soft-safe-A + unsafe-B #1/312: ok | ok | ok |
hard-safe-A + unsafe-B #1/321: ok | ok | ok |
soft-safe-A + unsafe-B #1/321: ok | ok | ok |
hard-safe-A + unsafe-B #2/123: ok | ok | ok |
soft-safe-A + unsafe-B #2/123: ok | ok | ok |
hard-safe-A + unsafe-B #2/132: ok | ok | ok |
soft-safe-A + unsafe-B #2/132: ok | ok | ok |
hard-safe-A + unsafe-B #2/213: ok | ok | ok |
soft-safe-A + unsafe-B #2/213: ok | ok | ok |
hard-safe-A + unsafe-B #2/231: ok | ok | ok |
soft-safe-A + unsafe-B #2/231: ok | ok | ok |
hard-safe-A + unsafe-B #2/312: ok | ok | ok |
soft-safe-A + unsafe-B #2/312: ok | ok | ok |
hard-safe-A + unsafe-B #2/321: ok | ok | ok |
soft-safe-A + unsafe-B #2/321: ok | ok | ok |
hard-irq lock-inversion/123: ok | ok | ok |
soft-irq lock-inversion/123: ok | ok | ok |
hard-irq lock-inversion/132: ok | ok | ok |
soft-irq lock-inversion/132: ok | ok | ok |
hard-irq lock-inversion/213: ok | ok | ok |
soft-irq lock-inversion/213: ok | ok | ok |
hard-irq lock-inversion/231: ok | ok | ok |
soft-irq lock-inversion/231: ok | ok | ok |
hard-irq lock-inversion/312: ok | ok | ok |
soft-irq lock-inversion/312: ok | ok | ok |
hard-irq lock-inversion/321: ok | ok | ok |
soft-irq lock-inversion/321: ok | ok | ok |
hard-irq read-recursion/123: ok |
soft-irq read-recursion/123: ok |
hard-irq read-recursion/132: ok |
soft-irq read-recursion/132: ok |
hard-irq read-recursion/213: ok |
soft-irq read-recursion/213: ok |
hard-irq read-recursion/231: ok |
soft-irq read-recursion/231: ok |
hard-irq read-recursion/312: ok |
soft-irq read-recursion/312: ok |
hard-irq read-recursion/321: ok |
soft-irq read-recursion/321: ok |-------------------------------------------------------
Good, all 210 testcases passed! |
---------------------------------
--- Documentation/kernel-parameters.txt | 9 lib/Kconfig.debug | 12 lib/Makefile | 1 lib/locking-selftest-hardirq.h | 9 lib/locking-selftest-mutex.h | 5 lib/locking-selftest-rlock-hardirq.h | 2 lib/locking-selftest-rlock-softirq.h | 2 lib/locking-selftest-rlock.h | 5 lib/locking-selftest-rsem.h | 5 lib/locking-selftest-softirq.h | 9 lib/locking-selftest-spin-hardirq.h | 2 lib/locking-selftest-spin-softirq.h | 2 lib/locking-selftest-spin.h | 5 lib/locking-selftest-wlock-hardirq.h | 2 lib/locking-selftest-wlock-softirq.h | 2 lib/locking-selftest-wlock.h | 5 lib/locking-selftest-wsem.h | 5 lib/locking-selftest.c | 1168 +++++++++++++++++++++++++++++++++++ 18 files changed, 1250 insertions(+)
Documentation/kernel-parameters.txt +9 -0
@@ -436,6 +436,15 @@ running once the system is up. debug [KNL] Enable kernel debugging (events log level). + debug_locks_verbose= + [KNL] verbose self-tests + Format=<0|1> + Print debugging info while doing the locking API + self-tests. + We default to 0 (no extra messages), setting it to + 1 will print _a lot_ more information - normally + only useful to kernel developers. + decnet= [HW,NET] Format: <area>[,<node>] See also Documentation/networking/decnet.txt.
lib/Kconfig.debug +12 -0
@@ -191,6 +191,18 @@ config DEBUG_SPINLOCK_SLEEP If you say Y here, various routines which may sleep will become very noisy if they are called with a spinlock held. +config DEBUG_LOCKING_API_SELFTESTS + bool "Locking API boot-time self-tests" + depends on DEBUG_KERNEL + default y + help + Say Y here if you want the kernel to run a short self-test during + bootup. The self-test checks whether common types of locking bugs + are detected by debugging mechanisms or not. (if you disable + lock debugging then those bugs wont be detected of course.) + The following locking APIs are covered: spinlocks, rwlocks, + mutexes and rwsems. + config DEBUG_KOBJECT bool "kobject debugging" depends on DEBUG_KERNEL
lib/Makefile +1 -0
@@ -18,6 +18,7 @@ CFLAGS_kobject.o += -DDEBUG CFLAGS_kobject_uevent.o += -DDEBUG endif +obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
lib/locking-selftest-hardirq.h new file +9 -0
@@ -0,0 +1,9 @@ +#undef IRQ_DISABLE +#undef IRQ_ENABLE +#undef IRQ_ENTER +#undef IRQ_EXIT + +#define IRQ_ENABLE HARDIRQ_ENABLE +#define IRQ_DISABLE HARDIRQ_DISABLE +#define IRQ_ENTER HARDIRQ_ENTER +#define IRQ_EXIT HARDIRQ_EXIT
lib/locking-selftest-mutex.h new file +5 -0
@@ -0,0 +1,5 @@ +#undef LOCK +#define LOCK ML + +#undef UNLOCK +#define UNLOCK MU
lib/locking-selftest-rlock-hardirq.h new file +2 -0
@@ -0,0 +1,2 @@ +#include "locking-selftest-rlock.h" +#include "locking-selftest-hardirq.h"
lib/locking-selftest-rlock-softirq.h new file +2 -0
@@ -0,0 +1,2 @@ +#include "locking-selftest-rlock.h" +#include "locking-selftest-softirq.h"
lib/locking-selftest-rlock.h new file +5 -0
@@ -0,0 +1,5 @@ +#undef LOCK +#define LOCK RL + +#undef UNLOCK +#define UNLOCK RU
lib/locking-selftest-rsem.h new file +5 -0
@@ -0,0 +1,5 @@ +#undef LOCK +#define LOCK RSL + +#undef UNLOCK +#define UNLOCK RSU
lib/locking-selftest-softirq.h new file +9 -0
@@ -0,0 +1,9 @@ +#undef IRQ_DISABLE +#undef IRQ_ENABLE +#undef IRQ_ENTER +#undef IRQ_EXIT + +#define IRQ_DISABLE SOFTIRQ_DISABLE +#define IRQ_ENABLE SOFTIRQ_ENABLE +#define IRQ_ENTER SOFTIRQ_ENTER +#define IRQ_EXIT SOFTIRQ_EXIT
lib/locking-selftest-spin-hardirq.h new file +2 -0
@@ -0,0 +1,2 @@ +#include "locking-selftest-spin.h" +#include "locking-selftest-hardirq.h"
lib/locking-selftest-spin-softirq.h new file +2 -0
@@ -0,0 +1,2 @@ +#include "locking-selftest-spin.h" +#include "locking-selftest-softirq.h"
lib/locking-selftest-spin.h new file +5 -0
@@ -0,0 +1,5 @@ +#undef LOCK +#define LOCK L + +#undef UNLOCK +#define UNLOCK U
lib/locking-selftest-wlock-hardirq.h new file +2 -0
@@ -0,0 +1,2 @@ +#include "locking-selftest-wlock.h" +#include "locking-selftest-hardirq.h"
lib/locking-selftest-wlock-softirq.h new file +2 -0
@@ -0,0 +1,2 @@ +#include "locking-selftest-wlock.h" +#include "locking-selftest-softirq.h"
lib/locking-selftest-wlock.h new file +5 -0
@@ -0,0 +1,5 @@ +#undef LOCK +#define LOCK WL + +#undef UNLOCK +#define UNLOCK WU
lib/locking-selftest-wsem.h new file +5 -0
@@ -0,0 +1,5 @@ +#undef LOCK +#define LOCK WSL + +#undef UNLOCK +#define UNLOCK WSU
lib/locking-selftest.c new file +1168 -0
1,168 lines not on this page · raw message
PATCH 9/61 lock validator: spin/rwlock init cleanups
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
locking init cleanups:
- convert " = SPIN_LOCK_UNLOCKED" to spin_lock_init() or DEFINE_SPINLOCK()
- convert rwlocks in a similar manner
this patch was generated automatically.
--- arch/ia64/sn/kernel/irq.c | 2 +- arch/mips/kernel/smtc.c | 4 ++-- arch/powerpc/platforms/cell/spufs/switch.c | 2 +- arch/powerpc/platforms/powermac/pfunc_core.c | 2 +- arch/powerpc/platforms/pseries/eeh_event.c | 2 +- arch/powerpc/sysdev/mmio_nvram.c | 2 +- arch/xtensa/kernel/time.c | 2 +- arch/xtensa/kernel/traps.c | 2 +- drivers/char/drm/drm_memory_debug.h | 2 +- drivers/char/drm/via_dmablit.c | 2 +- drivers/char/epca.c | 2 +- drivers/char/moxa.c | 2 +- drivers/char/specialix.c | 2 +- drivers/char/sx.c | 2 +- drivers/isdn/gigaset/common.c | 2 +- drivers/leds/led-core.c | 2 +- drivers/leds/led-triggers.c | 2 +- drivers/message/i2o/exec-osm.c | 2 +- drivers/misc/ibmasm/module.c | 2 +- drivers/pcmcia/m8xx_pcmcia.c | 4 ++-- drivers/rapidio/rio-access.c | 4 ++-- drivers/rtc/rtc-sa1100.c | 2 +- drivers/rtc/rtc-vr41xx.c | 2 +- drivers/s390/block/dasd_eer.c | 2 +- drivers/scsi/libata-core.c | 2 +- drivers/sn/ioc3.c | 2 +- drivers/usb/ip/stub_dev.c | 4 ++-- drivers/usb/ip/vhci_hcd.c | 4 ++-- drivers/video/backlight/hp680_bl.c | 2 +- fs/gfs2/ops_fstype.c | 2 +- fs/nfsd/nfs4state.c | 2 +- fs/ocfs2/cluster/heartbeat.c | 2 +- fs/ocfs2/cluster/tcp.c | 2 +- fs/ocfs2/dlm/dlmdomain.c | 2 +- fs/ocfs2/dlm/dlmlock.c | 2 +- fs/ocfs2/dlm/dlmrecovery.c | 4 ++-- fs/ocfs2/dlmglue.c | 2 +- fs/ocfs2/journal.c | 2 +- fs/reiser4/block_alloc.c | 2 +- fs/reiser4/debug.c | 2 +- fs/reiser4/fsdata.c | 2 +- fs/reiser4/txnmgr.c | 2 +- include/asm-alpha/core_t2.h | 2 +- kernel/audit.c | 2 +- mm/sparse.c | 2 +- net/ipv6/route.c | 2 +- net/sunrpc/auth_gss/gss_krb5_seal.c | 2 +- net/tipc/bcast.c | 4 ++-- net/tipc/bearer.c | 2 +- net/tipc/config.c | 2 +- net/tipc/dbg.c | 2 +- net/tipc/handler.c | 2 +- net/tipc/name_table.c | 4 ++-- net/tipc/net.c | 2 +- net/tipc/node.c | 2 +- net/tipc/port.c | 4 ++-- net/tipc/ref.c | 4 ++-- net/tipc/subscr.c | 2 +- net/tipc/user_reg.c | 2 +- 59 files changed, 69 insertions(+), 69 deletions(-)
arch/ia64/sn/kernel/irq.c +1 -1
@@ -27,7 +27,7 @@ static void unregister_intr_pda(struct sint sn_force_interrupt_flag =1 ;extern int sn_ioif_inited;struct list_head **sn_irq_lh; -static spinlock_t sn_irq_info_lock =SPIN_LOCK_UNLOCKED ;/* non-IRQ lock */ +static DEFINE_SPINLOCK (sn_irq_info_lock);/* non-IRQ lock */ u64 sn_intr_alloc(nasid_t local_nasid, int local_widget, struct sn_irq_info *sn_irq_info,
arch/mips/kernel/smtc.c +2 -2
@@ -367,7 +367,7 @@ void mipsmt_prepare_cpus(void)dvpe ();dmt (); - freeIPIq.lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&freeIPIq.lock);/* * We probably don't have as many VPEs as we do SMP "CPUs",
@@ -375,7 +375,7 @@ void mipsmt_prepare_cpus(void)*/ for (i=0 ; i<NR_CPUS ; i++) {IPIQ [i].head =IPIQ [i].tail =NULL ; -IPIQ [i].lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&IPIQ [i].lock);IPIQ [i].depth =0 ; ipi_timer_latch[i] =0 ; }
arch/powerpc/platforms/cell/spufs/switch.c +1 -1
@@ -2183,7 +2183,7 @@ void spu_init_csa(struct spu_state *csa)memset (lscsa,0 ,sizeof (struct spu_lscsa )); csa->lscsa = lscsa; - csa->register_lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&csa->register_lock);/* Set LS pages reserved to allow for user-space mapping. */ for (p = lscsa->ls; p < lscsa->ls +LS_SIZE ; p +=PAGE_SIZE )
arch/powerpc/platforms/powermac/pfunc_core.c +1 -1
@@ -545,7 +545,7 @@ struct pmf_device { };static LIST_HEAD (pmf_devices); -static spinlock_t pmf_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (pmf_lock);static void pmf_release_device (struct kref *kref) {
arch/powerpc/platforms/pseries/eeh_event.c +1 -1
@@ -35,7 +35,7 @@*/ /* EEH event workqueue setup. */ -static spinlock_t eeh_eventlist_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (eeh_eventlist_lock);LIST_HEAD (eeh_eventlist);static void eeh_thread_launcher (void *);DECLARE_WORK (eeh_event_wq, eeh_thread_launcher,NULL );
arch/powerpc/sysdev/mmio_nvram.c +1 -1
@@ -32,7 +32,7 @@static void __iomem *mmio_nvram_start;static long mmio_nvram_len; -static spinlock_t mmio_nvram_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (mmio_nvram_lock);static ssize_t mmio_nvram_read (char *buf,size_t count,loff_t *index) {
arch/xtensa/kernel/time.c +1 -1
@@ -29,7 +29,7 @@extern volatile unsigned long wall_jiffies; -spinlock_t rtc_lock =SPIN_LOCK_UNLOCKED ; +DEFINE_SPINLOCK (rtc_lock);EXPORT_SYMBOL (rtc_lock);
arch/xtensa/kernel/traps.c +1 -1
@@ -461,7 +461,7 @@ void show_code(unsigned int *pc) } } -spinlock_t die_lock =SPIN_LOCK_UNLOCKED ; +DEFINE_SPINLOCK (die_lock);void die (const char * str,struct pt_regs * regs,long err) {
drivers/char/drm/drm_memory_debug.h +1 -1
@@ -43,7 +43,7 @@ typedef struct drm_mem_stats {unsigned long bytes_freed; } drm_mem_stats_t; -static spinlock_t drm_mem_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (drm_mem_lock);static unsigned long drm_ram_available =0 ;/* In pages */ static unsigned long drm_ram_used =0 ; static drm_mem_stats_t drm_mem_stats[] =
drivers/char/drm/via_dmablit.c +1 -1
@@ -557,7 +557,7 @@ via_init_dmablit(drm_device_t *dev) blitq->num_outstanding =0 ; blitq->is_active =0 ; blitq->aborting =0 ; - blitq->blit_lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&blitq->blit_lock);for (j=0 ; j<VIA_NUM_BLIT_SLOTS ; ++j) {DRM_INIT_WAITQUEUE (blitq->blit_queue + j); }
drivers/char/epca.c +1 -1
@@ -80,7 +80,7 @@ static int invalid_lilo_config;/* The ISA boards do window flipping into the same spaces so its only sane with a single lock. It's still pretty efficient */ -static spinlock_t epca_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (epca_lock);/* ----------------------------------------------------------------------- MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
drivers/char/moxa.c +1 -1
@@ -301,7 +301,7 @@ static struct tty_operations moxa_ops = .tiocmset = moxa_tiocmset, }; -static spinlock_t moxa_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (moxa_lock);#ifdef CONFIG_PCI static int moxa_get_PCI_conf (struct pci_dev *p,int board_type,moxa_board_conf * board)
drivers/char/specialix.c +1 -1
@@ -2477,7 +2477,7 @@ static int __init specialix_init(void)#endif for (i =0 ; i <SX_NBOARD ; i++) - sx_board[i].lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&sx_board[i].lock);if (sx_init_drivers ()) {func_exit ();
drivers/char/sx.c +1 -1
@@ -2320,7 +2320,7 @@ static int sx_init_portstructs (int nboa#ifdef NEW_WRITE_LOCKING port->gs.port_write_mutex =MUTEX ;#endif - port->gs.driver_lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&port->gs.driver_lock);/* * Initializing wait queue */
drivers/isdn/gigaset/common.c +1 -1
@@ -981,7 +981,7 @@ exit:EXPORT_SYMBOL_GPL (gigaset_stop);static LIST_HEAD (drivers); -static spinlock_t driver_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (driver_lock);struct cardstate *gigaset_get_cs_by_id (int id) {
drivers/leds/led-core.c +1 -1
@@ -18,7 +18,7 @@#include <linux/leds.h> #include "leds.h" -rwlock_t leds_list_lock =RW_LOCK_UNLOCKED ; +DEFINE_RWLOCK (leds_list_lock);LIST_HEAD (leds_list);EXPORT_SYMBOL_GPL (leds_list);
drivers/leds/led-triggers.c +1 -1
@@ -26,7 +26,7 @@/* * Nests outside led_cdev->trigger_lock */ -static rwlock_t triggers_list_lock =RW_LOCK_UNLOCKED ; +static DEFINE_RWLOCK (triggers_list_lock);static LIST_HEAD (trigger_list); ssize_t led_trigger_store(struct class_device *dev, const char *buf,
drivers/message/i2o/exec-osm.c +1 -1
@@ -213,7 +213,7 @@ static int i2o_msg_post_wait_complete(st {struct i2o_exec_wait *wait, *tmp;unsigned long flags; -static spinlock_t lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (lock);int rc =1 ;/*
drivers/misc/ibmasm/module.c +1 -1
@@ -85,7 +85,7 @@ static int __devinit ibmasm_init_one(str }memset (sp,0 ,sizeof (struct service_processor )); - sp->lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&sp->lock);INIT_LIST_HEAD (&sp->command_queue);pci_set_drvdata (pdev, (void *)sp);
drivers/pcmcia/m8xx_pcmcia.c +2 -2
@@ -157,7 +157,7 @@ MODULE_LICENSE("Dual MPL/GPL");static int pcmcia_schlvl =PCMCIA_SCHLVL ; -static spinlock_t events_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (events_lock);#define PCMCIA_SOCKET_KEY_5V 1
@@ -644,7 +644,7 @@ static struct platform_device m8xx_devic };static u32 pending_events[PCMCIA_SOCKETS_NO ]; -static spinlock_t pending_event_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (pending_event_lock);static irqreturn_t m8xx_interrupt (int irq,void *dev,struct pt_regs *regs) {
drivers/rapidio/rio-access.c +2 -2
@@ -17,8 +17,8 @@* These interrupt-safe spinlocks protect all accesses to RIO * configuration space and doorbell access. */ -static spinlock_t rio_config_lock =SPIN_LOCK_UNLOCKED ; -static spinlock_t rio_doorbell_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (rio_config_lock); +static DEFINE_SPINLOCK (rio_doorbell_lock);/* * Wrappers for all RIO configuration access functions. They just check
drivers/rtc/rtc-sa1100.c +1 -1
@@ -45,7 +45,7 @@static unsigned long rtc_freq =1024 ;static struct rtc_time rtc_alarm; -static spinlock_t sa1100_rtc_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (sa1100_rtc_lock);static int rtc_update_alarm (struct rtc_time *alrm) {
drivers/rtc/rtc-vr41xx.c +1 -1
@@ -93,7 +93,7 @@ static void __iomem *rtc2_base;static unsigned long epoch =1970 ;/* Jan 1 1970 00:00:00 */ -static spinlock_t rtc_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (rtc_lock);static char rtc_name[] ="RTC" ;static unsigned long periodic_frequency;static unsigned long periodic_count;
drivers/s390/block/dasd_eer.c +1 -1
@@ -89,7 +89,7 @@ struct eerbuffer { };static LIST_HEAD (bufferlist); -static spinlock_t bufferlock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (bufferlock);static DECLARE_WAIT_QUEUE_HEAD (dasd_eer_read_wait_queue);/*
drivers/scsi/libata-core.c +1 -1
@@ -5605,7 +5605,7 @@ module_init(ata_init);module_exit (ata_exit);static unsigned long ratelimit_time; -static spinlock_t ata_ratelimit_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (ata_ratelimit_lock);int ata_ratelimit (void ) {
drivers/sn/ioc3.c +1 -1
@@ -26,7 +26,7 @@ static DECLARE_RWSEM(ioc3_devices_rwsem)static struct ioc3_submodule *ioc3_submodules[IOC3_MAX_SUBMODULES ];static struct ioc3_submodule *ioc3_ethernet; -static rwlock_t ioc3_submodules_lock =RW_LOCK_UNLOCKED ; +static DEFINE_RWLOCK (ioc3_submodules_lock);/* NIC probing code */
drivers/usb/ip/stub_dev.c +2 -2
@@ -285,13 +285,13 @@ static struct stub_device * stub_device_ sdev->ud.side =USBIP_STUB ; sdev->ud.status =SDEV_ST_AVAILABLE ; - sdev->ud.lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&sdev->ud.lock); sdev->ud.tcp_socket =NULL ;INIT_LIST_HEAD (&sdev->priv_init);INIT_LIST_HEAD (&sdev->priv_tx);INIT_LIST_HEAD (&sdev->priv_free); - sdev->priv_lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&sdev->priv_lock); sdev->ud.eh_ops.shutdown = stub_shutdown_connection; sdev->ud.eh_ops.reset = stub_device_reset;
drivers/usb/ip/vhci_hcd.c +2 -2
@@ -768,11 +768,11 @@ static void vhci_device_init(struct vhci vdev->ud.side =USBIP_VHCI ; vdev->ud.status =VDEV_ST_NULL ; - vdev->ud.lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&vdev->ud.lock );INIT_LIST_HEAD (&vdev->priv_rx);INIT_LIST_HEAD (&vdev->priv_tx); - vdev->priv_lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&vdev->priv_lock);init_waitqueue_head (&vdev->waitq);
drivers/video/backlight/hp680_bl.c +1 -1
@@ -27,7 +27,7 @@static int hp680bl_suspended;static int current_intensity =0 ; -static spinlock_t bl_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (bl_lock);static struct backlight_device *hp680_backlight_device;static void hp680bl_send_intensity (struct backlight_device *bd)
fs/gfs2/ops_fstype.c +1 -1
@@ -58,7 +58,7 @@ static struct gfs2_sbd *init_sbd(structgfs2_tune_init (&sdp->sd_tune);for (x =0 ; x <GFS2_GL_HASH_SIZE ; x++) { - sdp->sd_gl_hash[x].hb_lock =RW_LOCK_UNLOCKED ; +rwlock_init (&sdp->sd_gl_hash[x].hb_lock);INIT_LIST_HEAD (&sdp->sd_gl_hash[x].hb_list); }INIT_LIST_HEAD (&sdp->sd_reclaim_list);
fs/nfsd/nfs4state.c +1 -1
@@ -123,7 +123,7 @@ static void release_stateid(struct nfs4_*/ /* recall_lock protects the del_recall_lru */ -static spinlock_t recall_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (recall_lock);static struct list_head del_recall_lru; static void
fs/ocfs2/cluster/heartbeat.c +1 -1
@@ -54,7 +54,7 @@ static DECLARE_RWSEM(o2hb_callback_sem);* multiple hb threads are watching multiple regions. A node is live * whenever any of the threads sees activity from the node in its region. */ -static spinlock_t o2hb_live_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (o2hb_live_lock);static struct list_head o2hb_live_slots[O2NM_MAX_NODES ];static unsigned long o2hb_live_node_bitmap[BITS_TO_LONGS (O2NM_MAX_NODES )];static LIST_HEAD (o2hb_node_events);
fs/ocfs2/cluster/tcp.c +1 -1
@@ -107,7 +107,7 @@ ##args); \ } while (0) -static rwlock_t o2net_handler_lock =RW_LOCK_UNLOCKED ; +static DEFINE_RWLOCK (o2net_handler_lock);static struct rb_root o2net_handler_tree =RB_ROOT ;static struct o2net_node o2net_nodes[O2NM_MAX_NODES ];
fs/ocfs2/dlm/dlmdomain.c +1 -1
@@ -88,7 +88,7 @@ out_free:* */ -spinlock_t dlm_domain_lock =SPIN_LOCK_UNLOCKED ; +DEFINE_SPINLOCK (dlm_domain_lock);LIST_HEAD (dlm_domains);static DECLARE_WAIT_QUEUE_HEAD (dlm_domain_events);
fs/ocfs2/dlm/dlmlock.c +1 -1
@@ -53,7 +53,7 @@#define MLOG_MASK_PREFIX ML_DLM#include "cluster/masklog.h" -static spinlock_t dlm_cookie_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (dlm_cookie_lock);static u64 dlm_next_cookie =1 ; static enum dlm_status dlm_send_remote_lock_request(struct dlm_ctxt *dlm,
fs/ocfs2/dlm/dlmrecovery.c +2 -2
@@ -101,8 +101,8 @@ static int dlm_lockres_master_requery(ststatic u64 dlm_get_next_mig_cookie (void ); -static spinlock_t dlm_reco_state_lock =SPIN_LOCK_UNLOCKED ; -static spinlock_t dlm_mig_cookie_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (dlm_reco_state_lock); +static DEFINE_SPINLOCK (dlm_mig_cookie_lock);static u64 dlm_mig_cookie =1 ;static u64 dlm_get_next_mig_cookie (void )
fs/ocfs2/dlmglue.c +1 -1
@@ -242,7 +242,7 @@ static void ocfs2_build_lock_name(enum omlog_exit_void (); } -static spinlock_t ocfs2_dlm_tracking_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (ocfs2_dlm_tracking_lock);static void ocfs2_add_lockres_tracking (struct ocfs2_lock_res *res,struct ocfs2_dlm_debug *dlm_debug)
fs/ocfs2/journal.c +1 -1
@@ -49,7 +49,7 @@#include "buffer_head_io.h" -spinlock_t trans_inc_lock =SPIN_LOCK_UNLOCKED ; +DEFINE_SPINLOCK (trans_inc_lock);static int ocfs2_force_read_journal (struct inode *inode); static int ocfs2_recover_node(struct ocfs2_super *osb,
fs/reiser4/block_alloc.c +1 -1
@@ -499,7 +499,7 @@ void cluster_reserved2free(int count)spin_unlock_reiser4_super (sbinfo); } -static spinlock_t fake_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (fake_lock);static reiser4_block_nr fake_gen =0 ;/* obtain a block number for new formatted node which will be used to refer
fs/reiser4/debug.c +1 -1
@@ -52,7 +52,7 @@ static char panic_buf[REISER4_PANIC_MSG_/* * lock protecting consistency of panic_buf under concurrent panics */ -static spinlock_t panic_guard =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (panic_guard);/* Your best friend. Call it on each occasion. This is called by fs/reiser4/debug.h:reiser4_panic(). */
fs/reiser4/fsdata.c +1 -1
@@ -17,7 +17,7 @@ static LIST_HEAD(cursor_cache);static unsigned long d_cursor_unused =0 ;/* spinlock protecting manipulations with dir_cursor's hash table and lists */ -spinlock_t d_lock =SPIN_LOCK_UNLOCKED ; +DEFINE_SPINLOCK (d_lock);static reiser4_file_fsdata *create_fsdata (struct file *file);static int file_is_stateless (struct file *file);
fs/reiser4/txnmgr.c +1 -1
@@ -905,7 +905,7 @@ jnode *find_first_dirty_jnode(txn_atom */* this spin lock is used to prevent races during steal on capture. FIXME: should be per filesystem or even per atom */ -spinlock_t scan_lock =SPIN_LOCK_UNLOCKED ; +DEFINE_SPINLOCK (scan_lock);/* Scan atom->writeback_nodes list and dispatch jnodes according to their state: * move dirty and !writeback jnodes to @fq, clean jnodes to atom's clean
include/asm-alpha/core_t2.h +1 -1
@@ -435,7 +435,7 @@ static inline void t2_outl(u32 b, unsignset_hae (msb); \ } -static spinlock_t t2_hae_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (t2_hae_lock); __EXTERN_INLINE u8 t2_readb(const volatile void __iomem *xaddr) {
kernel/audit.c +1 -1
@@ -787,7 +787,7 @@ err:*/ unsigned int audit_serial (void ) { -static spinlock_t serial_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (serial_lock);static unsigned int serial =0 ;unsigned long flags;
mm/sparse.c +1 -1
@@ -45,7 +45,7 @@ static struct mem_section *sparse_index_static int sparse_index_init (unsigned long section_nr,int nid) { -static spinlock_t index_init_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (index_init_lock);unsigned long root =SECTION_NR_TO_ROOT (section_nr);struct mem_section *section;int ret =0 ;
net/ipv6/route.c +1 -1
@@ -343,7 +343,7 @@ static struct rt6_info *rt6_select(struc (strict & RT6_SELECT_F_REACHABLE) && last && last != rt0) {/* no entries matched; do round-robin */ -static spinlock_t lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (lock);spin_lock (&lock); *head = rt0->u.next; rt0->u.next = last->u.next;
net/sunrpc/auth_gss/gss_krb5_seal.c +1 -1
@@ -70,7 +70,7 @@# define RPCDBG_FACILITY RPCDBG_AUTH#endif -spinlock_t krb5_seq_lock =SPIN_LOCK_UNLOCKED ; +DEFINE_SPINLOCK (krb5_seq_lock); u32 gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
net/tipc/bcast.c +2 -2
@@ -102,7 +102,7 @@ struct bclink {static struct bcbearer *bcbearer =NULL ;static struct bclink *bclink =NULL ;static struct link *bcl =NULL ; -static spinlock_t bc_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (bc_lock);char tipc_bclink_name[] ="multicast-link" ;
@@ -783,7 +783,7 @@ int tipc_bclink_init(void)memset (bclink,0 ,sizeof (struct bclink ));INIT_LIST_HEAD (&bcl->waiting_ports); bcl->next_out_no =1 ; - bclink->node.lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&bclink->node.lock); bcl->owner = &bclink->node; bcl->max_pkt =MAX_PKT_DEFAULT_MCAST ;tipc_link_set_queue_limits (bcl,BCLINK_WIN_DEFAULT );
net/tipc/bearer.c +1 -1
@@ -552,7 +552,7 @@ restart: b_ptr->link_req =tipc_disc_init_link_req (b_ptr, &m_ptr->bcast_addr, bcast_scope,2 ); } - b_ptr->publ.lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&b_ptr->publ.lock);write_unlock_bh (&tipc_net_lock);info ("Enabled bearer <%s>, discovery domain %s, priority %u\n" , name,addr_string_fill (addr_string, bcast_scope), priority);
net/tipc/config.c +1 -1
@@ -63,7 +63,7 @@ struct manager {static struct manager mng = {0 }; -static spinlock_t config_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (config_lock);static const void *req_tlv_area;/* request message TLV area */ static int req_tlv_space;/* request message TLV area size */
net/tipc/dbg.c +1 -1
@@ -41,7 +41,7 @@#define MAX_STRING 512static char print_string[MAX_STRING ]; -static spinlock_t print_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (print_lock);static struct print_buf cons_buf = {NULL ,0 ,NULL ,NULL };struct print_buf *TIPC_CONS = &cons_buf;
net/tipc/handler.c +1 -1
@@ -44,7 +44,7 @@ struct queue_item {static kmem_cache_t *tipc_queue_item_cache;static struct list_head signal_queue_head; -static spinlock_t qitem_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (qitem_lock);static int handler_enabled =0 ;static void process_signal_queue (unsigned long dummy);
net/tipc/name_table.c +2 -2
@@ -101,7 +101,7 @@ struct name_table {static struct name_table table = {NULL } ;static atomic_t rsv_publ_ok =ATOMIC_INIT (0 ); -rwlock_t tipc_nametbl_lock =RW_LOCK_UNLOCKED ; +DEFINE_RWLOCK (tipc_nametbl_lock);static int hash (int x)
@@ -172,7 +172,7 @@ static struct name_seq *tipc_nameseq_cre }memset (nseq,0 ,sizeof (*nseq)); - nseq->lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&nseq->lock); nseq->type = type; nseq->sseqs = sseq; dbg("tipc_nameseq_create() nseq = %x type %u, ssseqs %x, ff: %u\n",
net/tipc/net.c +1 -1
@@ -115,7 +115,7 @@* - A local spin_lock protecting the queue of subscriber events. */ -rwlock_t tipc_net_lock =RW_LOCK_UNLOCKED ; +DEFINE_RWLOCK (tipc_net_lock);struct network tipc_net = {NULL };struct node *tipc_net_select_remote_node (u32 addr,u32 ref)
net/tipc/node.c +1 -1
@@ -64,7 +64,7 @@ struct node *tipc_node_create(u32 addr)if (n_ptr !=NULL ) {memset (n_ptr,0 ,sizeof (*n_ptr)); n_ptr->addr = addr; - n_ptr->lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&n_ptr->lock);INIT_LIST_HEAD (&n_ptr->nsub); c_ptr =tipc_cltr_find (addr);
net/tipc/port.c +2 -2
@@ -57,8 +57,8 @@static struct sk_buff *msg_queue_head =NULL ;static struct sk_buff *msg_queue_tail =NULL ; -spinlock_t tipc_port_list_lock =SPIN_LOCK_UNLOCKED ; -static spinlock_t queue_lock =SPIN_LOCK_UNLOCKED ; +DEFINE_SPINLOCK (tipc_port_list_lock); +static DEFINE_SPINLOCK (queue_lock);static LIST_HEAD (ports);static void port_handle_node_down (unsigned long ref);
net/tipc/ref.c +2 -2
@@ -63,7 +63,7 @@struct ref_table tipc_ref_table = {NULL }; -static rwlock_t ref_table_lock =RW_LOCK_UNLOCKED ; +static DEFINE_RWLOCK (ref_table_lock);/** * tipc_ref_table_init - create reference table for objects
@@ -87,7 +87,7 @@ int tipc_ref_table_init(u32 requested_si index_mask = sz -1 ;for (i = sz -1 ; i >=0 ; i--) { table[i].object =NULL ; - table[i].lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&table[i].lock); table[i].data.next_plus_upper = (start & ~index_mask) + i -1 ; } tipc_ref_table.entries = table;
net/tipc/subscr.c +1 -1
@@ -457,7 +457,7 @@ int tipc_subscr_start(void)int res =-1 ;memset (&topsrv,0 ,sizeof (topsrv)); - topsrv.lock =SPIN_LOCK_UNLOCKED ; +spin_lock_init (&topsrv.lock);INIT_LIST_HEAD (&topsrv.subscriber_list);spin_lock_bh (&topsrv.lock);
net/tipc/user_reg.c +1 -1
@@ -67,7 +67,7 @@ struct tipc_user {static struct tipc_user *users =NULL ;static u32 next_free_user =MAX_USERID +1 ; -static spinlock_t reg_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_SPINLOCK (reg_lock);/** * reg_init - create TIPC user registry (but don't activate it)
PATCH 10/61 lock validator: locking init debugging improvement
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
locking init improvement:
- introduce and use __SPIN_LOCK_UNLOCKED for array initializations, to pass in the name string of locks, used by debugging
--- arch/x86_64/kernel/smpboot.c | 3 +++ arch/x86_64/kernel/vsyscall.c | 2 +- block/ll_rw_blk.c | 1 + drivers/char/random.c | 6 +++--- drivers/ide/ide-io.c | 2 ++ drivers/scsi/libata-core.c | 2 ++ drivers/spi/spi.c | 1 + fs/dcache.c | 2 +- include/linux/idr.h | 2 +- include/linux/init_task.h | 10 +++++----- include/linux/notifier.h | 2 +- include/linux/seqlock.h | 12 ++++++++++-- include/linux/spinlock_types.h | 15 +++++++++------ include/linux/wait.h | 2 +- kernel/kmod.c | 2 ++ kernel/rcupdate.c | 4 ++-- kernel/timer.c | 2 +- mm/swap_state.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_minisocks.c | 2 +- net/ipv4/xfrm4_policy.c | 4 ++-- 21 files changed, 51 insertions(+), 29 deletions(-)
arch/x86_64/kernel/smpboot.c +3 -0
@@ -771,8 +771,11 @@ static int __cpuinit do_boot_cpu(int cpu .cpu = cpu, .done = COMPLETION_INITIALIZER(c_idle.done), }; +DECLARE_WORK (work, do_fork_idle, &c_idle); +init_completion (&c_idle.done); +/* allocate memory for gdts of secondary cpus. Hotplug is considered */ if (!cpu_gdt_descr[cpu].address && !(cpu_gdt_descr[cpu].address =get_zeroed_page (GFP_KERNEL ))) {
arch/x86_64/kernel/vsyscall.c +1 -1
@@ -37,7 +37,7 @@#define __vsyscall (nr) __attribute__ ((unused,__section__(".vsyscall_" #nr))) int __sysctl_vsyscall __section_sysctl_vsyscall = 1; -seqlock_t __xtime_lock __section_xtime_lock = SEQLOCK_UNLOCKED; +__section_xtime_lock DEFINE_SEQLOCK (__xtime_lock );#include <asm/unistd.h>
block/ll_rw_blk.c +1 -0
@@ -2529,6 +2529,7 @@ int blk_execute_rq(request_queue_t *q, schar sense[SCSI_SENSE_BUFFERSIZE ];int err =0 ; +init_completion (&wait);/* * we need an extra reference to the request, so we can look at * it after io completion
drivers/char/random.c +3 -3
@@ -417,7 +417,7 @@ static struct entropy_store input_pool = .poolinfo = &poolinfo_table[0], .name = "input", .limit = 1, - .lock = SPIN_LOCK_UNLOCKED, + .lock = __SPIN_LOCK_UNLOCKED(&input_pool.lock), .pool = input_pool_data };
@@ -426,7 +426,7 @@ static struct entropy_store blocking_poo .name = "blocking", .limit = 1, .pull = &input_pool, - .lock = SPIN_LOCK_UNLOCKED, + .lock = __SPIN_LOCK_UNLOCKED(&blocking_pool.lock), .pool = blocking_pool_data };
@@ -434,7 +434,7 @@ static struct entropy_store nonblocking_ .poolinfo = &poolinfo_table[1], .name = "nonblocking", .pull = &input_pool, - .lock = SPIN_LOCK_UNLOCKED, + .lock = __SPIN_LOCK_UNLOCKED(&nonblocking_pool.lock), .pool = nonblocking_pool_data };
drivers/ide/ide-io.c +2 -0
@@ -1700,6 +1700,8 @@ int ide_do_drive_cmd (ide_drive_t *driveint where =ELEVATOR_INSERT_BACK , err;int must_wait = (action == ide_wait || action == ide_head_wait); +init_completion (&wait); + rq->errors =0 ; rq->rq_status =RQ_ACTIVE ;
drivers/scsi/libata-core.c +2 -0
@@ -994,6 +994,8 @@ unsigned ata_exec_internal(struct ata_deunsigned int err_mask;int rc; +init_completion (&wait); +spin_lock_irqsave (&ap->host_set->lock, flags);/* no internal command while frozen */
drivers/spi/spi.c +1 -0
@@ -512,6 +512,7 @@ int spi_sync(struct spi_device *spi, strDECLARE_COMPLETION (done);int status; +init_completion (&done); message->complete = spi_complete; message->context = &done; status =spi_async (spi, message);
fs/dcache.c +1 -1
@@ -39,7 +39,7 @@ int sysctl_vfs_cache_pressure __read_mosEXPORT_SYMBOL_GPL (sysctl_vfs_cache_pressure);__cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_lock ); -static seqlock_t rename_lock __cacheline_aligned_in_smp = SEQLOCK_UNLOCKED; +static __cacheline_aligned_in_smp DEFINE_SEQLOCK (rename_lock );EXPORT_SYMBOL (dcache_lock);
include/linux/idr.h +1 -1
@@ -66,7 +66,7 @@ struct idr { .id_free = NULL, \ .layers = 0, \ .id_free_cnt = 0, \ - .lock = SPIN_LOCK_UNLOCKED, \ + .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ }#define DEFINE_IDR (name) struct idr name = IDR_INIT(name)
include/linux/init_task.h +5 -5
@@ -22,7 +22,7 @@ .count = ATOMIC_INIT(1), \ .fdt = &init_files.fdtab, \ .fdtab = INIT_FDTABLE, \ - .file_lock = SPIN_LOCK_UNLOCKED, \ + .file_lock = __SPIN_LOCK_UNLOCKED(init_task.file_lock), \ .next_fd = 0, \ .close_on_exec_init = { { 0, } }, \ .open_fds_init = { { 0, } }, \
@@ -37,7 +37,7 @@ .user_id = 0, \ .next = NULL, \ .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait), \ - .ctx_lock = SPIN_LOCK_UNLOCKED, \ + .ctx_lock = __SPIN_LOCK_UNLOCKED(name.ctx_lock), \ .reqs_active = 0U, \ .max_reqs = ~0U, \ }
@@ -49,7 +49,7 @@ .mm_users = ATOMIC_INIT(2), \ .mm_count = ATOMIC_INIT(1), \ .mmap_sem = __RWSEM_INITIALIZER(name.mmap_sem), \ - .page_table_lock = SPIN_LOCK_UNLOCKED, \ + .page_table_lock = __SPIN_LOCK_UNLOCKED(name.page_table_lock), \ .mmlist = LIST_HEAD_INIT(name.mmlist), \ .cpu_vm_mask = CPU_MASK_ALL, \ }
@@ -78,7 +78,7 @@ extern struct nsproxy init_nsproxy;#define INIT_SIGHAND (sighand) { \ .count = ATOMIC_INIT(1), \ .action = { { { .sa_handler = NULL, } }, }, \ - .siglock = SPIN_LOCK_UNLOCKED, \ + .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \ }extern struct group_info init_groups;
@@ -129,7 +129,7 @@ extern struct group_info init_groups; .list = LIST_HEAD_INIT(tsk.pending.list), \ .signal = {{0}}}, \ .blocked = {{0}}, \ - .alloc_lock = SPIN_LOCK_UNLOCKED, \ + .alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \ .journal_info = NULL, \ .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .fs_excl = ATOMIC_INIT(0), \
include/linux/notifier.h +1 -1
@@ -65,7 +65,7 @@ struct raw_notifier_head { } while (0)#define ATOMIC_NOTIFIER_INIT (name) { \ - .lock = SPIN_LOCK_UNLOCKED, \ + .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ .head = NULL }#define BLOCKING_NOTIFIER_INIT (name) { \ .rwsem = __RWSEM_INITIALIZER((name).rwsem), \
include/linux/seqlock.h +10 -2
@@ -38,9 +38,17 @@ typedef struct {* These macros triggered gcc-3.x compile-time problems. We think these are * OK now. Be cautious. */ -#define SEQLOCK_UNLOCKED { 0, SPIN_LOCK_UNLOCKED } -#define seqlock_init (x) do { *(x) = (seqlock_t) SEQLOCK_UNLOCKED; } while (0) +#define __SEQLOCK_UNLOCKED (lockname) \ + { 0, __SPIN_LOCK_UNLOCKED(lockname) } +#define SEQLOCK_UNLOCKED \ + __SEQLOCK_UNLOCKED(old_style_seqlock_init) + +#define seqlock_init (x) \ + do { *(x) = (seqlock_t) __SEQLOCK_UNLOCKED(x); } while (0) + +#define DEFINE_SEQLOCK (x) \ + seqlock_t x = __SEQLOCK_UNLOCKED(x)/* Lock out other writers and update the count. * Acts like a normal spin_lock/unlock.
include/linux/spinlock_types.h +9 -6
@@ -44,24 +44,27 @@ typedef struct {#define SPINLOCK_OWNER_INIT ((void *)-1L)#ifdef CONFIG_DEBUG_SPINLOCK -# define SPIN_LOCK_UNLOCKED \ +# define __SPIN_LOCK_UNLOCKED (lockname) \ (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED, \ .magic = SPINLOCK_MAGIC, \ .owner = SPINLOCK_OWNER_INIT, \ .owner_cpu = -1 } -#define RW_LOCK_UNLOCKED \ +#define __RW_LOCK_UNLOCKED (lockname) \ (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED, \ .magic = RWLOCK_MAGIC, \ .owner = SPINLOCK_OWNER_INIT, \ .owner_cpu = -1 }#else -# define SPIN_LOCK_UNLOCKED \ +# define __SPIN_LOCK_UNLOCKED (lockname) \ (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED } -#define RW_LOCK_UNLOCKED \ +#define __RW_LOCK_UNLOCKED (lockname) \ (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED }#endif -#define DEFINE_SPINLOCK (x) spinlock_t x = SPIN_LOCK_UNLOCKED -#define DEFINE_RWLOCK (x) rwlock_t x = RW_LOCK_UNLOCKED +#define SPIN_LOCK_UNLOCKED __SPIN_LOCK_UNLOCKED(old_style_spin_init) +#define RW_LOCK_UNLOCKED __RW_LOCK_UNLOCKED(old_style_rw_init) + +#define DEFINE_SPINLOCK (x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x) +#define DEFINE_RWLOCK (x) rwlock_t x = __RW_LOCK_UNLOCKED(x)#endif /* __LINUX_SPINLOCK_TYPES_H */
include/linux/wait.h +1 -1
@@ -68,7 +68,7 @@ struct task_struct; wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)#define __WAIT_QUEUE_HEAD_INITIALIZER (name) { \ - .lock = SPIN_LOCK_UNLOCKED, \ + .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ .task_list = { &(name).task_list, &(name).task_list } }#define DECLARE_WAIT_QUEUE_HEAD (name) \
kernel/kmod.c +2 -0
@@ -246,6 +246,8 @@ int call_usermodehelper_keys(char *path, };DECLARE_WORK (work, __call_usermodehelper, &sub_info); +init_completion (&done); +if (!khelper_wq)return -EBUSY ;
kernel/rcupdate.c +2 -2
@@ -53,13 +53,13 @@static struct rcu_ctrlblk rcu_ctrlblk = { .cur =-300 , .completed =-300 , - .lock =SPIN_LOCK_UNLOCKED , + .lock =__SPIN_LOCK_UNLOCKED (&rcu_ctrlblk.lock), .cpumask =CPU_MASK_NONE , };static struct rcu_ctrlblk rcu_bh_ctrlblk = { .cur =-300 , .completed =-300 , - .lock =SPIN_LOCK_UNLOCKED , + .lock =__SPIN_LOCK_UNLOCKED (&rcu_bh_ctrlblk.lock), .cpumask =CPU_MASK_NONE , };
kernel/timer.c +1 -1
@@ -1142,7 +1142,7 @@ unsigned long wall_jiffies = INITIAL_JIF* playing with xtime and avenrun. */ #ifndef ARCH_HAVE_XTIME_LOCK -seqlock_t xtime_lock __cacheline_aligned_in_smp = SEQLOCK_UNLOCKED; +__cacheline_aligned_in_smp DEFINE_SEQLOCK (xtime_lock );EXPORT_SYMBOL (xtime_lock);#endif
mm/swap_state.c +1 -1
@@ -39,7 +39,7 @@ static struct backing_dev_info swap_backstruct address_space swapper_space = { .page_tree =RADIX_TREE_INIT (GFP_ATOMIC |__GFP_NOWARN), - .tree_lock =RW_LOCK_UNLOCKED , + .tree_lock =__RW_LOCK_UNLOCKED (swapper_space.tree_lock), .a_ops = &swap_aops, .i_mmap_nonlinear =LIST_HEAD_INIT (swapper_space.i_mmap_nonlinear), .backing_dev_info = &swap_backing_dev_info,
net/ipv4/tcp_ipv4.c +1 -1
@@ -90,7 +90,7 @@ static struct socket *tcp_socket;void tcp_v4_send_check (struct sock *sk,int len,struct sk_buff *skb); struct inet_hashinfo __cacheline_aligned tcp_hashinfo = { - .lhash_lock =RW_LOCK_UNLOCKED , + .lhash_lock =__RW_LOCK_UNLOCKED (tcp_hashinfo.lhash_lock), .lhash_users =ATOMIC_INIT (0 ), .lhash_wait =__WAIT_QUEUE_HEAD_INITIALIZER (tcp_hashinfo.lhash_wait), };
net/ipv4/tcp_minisocks.c +1 -1
@@ -41,7 +41,7 @@ int sysctl_tcp_abort_on_overflow;struct inet_timewait_death_row tcp_death_row = { .sysctl_max_tw_buckets =NR_FILE *2 , .period =TCP_TIMEWAIT_LEN /INET_TWDR_TWKILL_SLOTS , - .death_lock =SPIN_LOCK_UNLOCKED , + .death_lock =__SPIN_LOCK_UNLOCKED (tcp_death_row.death_lock), .hashinfo = &tcp_hashinfo, .tw_timer =TIMER_INITIALIZER (inet_twdr_hangman,0 , (unsigned long )&tcp_death_row),
net/ipv4/xfrm4_policy.c +2 -2
@@ -17,7 +17,7 @@static struct dst_ops xfrm4_dst_ops;static struct xfrm_policy_afinfo xfrm4_policy_afinfo; -static struct xfrm_type_map xfrm4_type_map = { .lock =RW_LOCK_UNLOCKED }; +static struct xfrm_type_map xfrm4_type_map = { .lock =__RW_LOCK_UNLOCKED (xfrm4_type_map.lock) };static int xfrm4_dst_lookup (struct xfrm_dst **dst,struct flowi *fl) {
@@ -299,7 +299,7 @@ static struct dst_ops xfrm4_dst_ops = {static struct xfrm_policy_afinfo xfrm4_policy_afinfo = { .family =AF_INET , - .lock =RW_LOCK_UNLOCKED , + .lock =__RW_LOCK_UNLOCKED (xfrm4_policy_afinfo.lock), .type_map = &xfrm4_type_map, .dst_ops = &xfrm4_dst_ops, .dst_lookup = xfrm4_dst_lookup,
PATCH 11/61 lock validator: lockdep: small xfs init_rwsem() cleanup
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
init_rwsem() has no return value. This is not a problem if init_rwsem() is a function, but it's a problem if it's a do { ... } while (0) macro. (which lockdep introduces)
--- fs/xfs/linux-2.6/mrlock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/linux-2.6/mrlock.h +1 -1
@@ -28,7 +28,7 @@ typedef struct { } mrlock_t;#define mrinit (mrp, name) \ - ( (mrp)->mr_writer = 0, init_rwsem(&(mrp)->mr_lock) ) + do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)#define mrlock_init (mrp, t,n,s) mrinit(mrp, n)#define mrfree (mrp) do { } while (0)#define mraccess (mrp) mraccessf(mrp, 0)
Re: [patch 11/61] lock validator: lockdep: small xfs init_rwsem() cleanup
Quoted 15 lines · On Mon, 29 May 2006 23:23:59 +0200 Ingo Molnar <[email protected]> wrote:
nit_rwsem()has no return value. This is not a problem ifinit_rwsem()is a function, but it's a problem if it's a do { ... } while (0) macro. (which lockdep introduces)Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- fs/xfs/linux-2.6/mrlock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
linux/fs/xfs/linux-2.6/mrlock.h
===================================================================
fs/xfs/linux-2.6/mrlock.h typedef struct { · line 34
Quoted 8 lines
fs/xfs/linux-2.6/mrlock.h +1
-1@@ -28,7 +28,7 @@ typedef struct { } mrlock_t;#define mrinit (mrp, name) \ - ( (mrp)->mr_writer = 0, init_rwsem(&(mrp)->mr_lock) ) + do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)#define mrlock_init (mrp, t,n,s) mrinit(mrp, n)#define mrfree (mrp) do { } while (0)#define mraccess (mrp) mraccessf(mrp, 0)
I'll queue this for mainline, via the XFS tree.
Re: [patch 11/61] lock validator: lockdep: small xfs init_rwsem() cleanup
Quoted 1 line · Andrew Morton
I'll queue this for mainline, via the XFS tree.
Thanks Andrew, its merged in our tree now.
Signature · 1 line
Nathan
PATCH 12/61 lock validator: beautify x86_64 stacktraces
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
beautify x86_64 stacktraces to be more readable.
--- arch/x86_64/kernel/traps.c | 55 ++++++++++++++++++++------------------------ include/asm-x86_64/kdebug.h | 2 - 2 files changed, 27 insertions(+), 30 deletions(-)
arch/x86_64/kernel/traps.c +26 -29
@@ -108,28 +108,30 @@ static inline void preempt_conditional_cstatic int kstack_depth_to_print =10 ;#ifdef CONFIG_KALLSYMS -#include <linux/kallsyms.h> -int printk_address (unsigned long address) -{ +# include <linux/kallsyms.h> +void printk_address (unsigned long address) +{unsigned long offset =0 , symsize;const char *symname;char *modname; -char *delim =":" ; +char *delim =":" ;char namebuf[128 ]; - symname =kallsyms_lookup (address, &symsize, &offset, &modname, namebuf); -if (!symname) -return printk ("[<%016lx>]" , address); -if (!modname) + symname =kallsyms_lookup (address, &symsize, &offset, &modname, namebuf); +if (!symname) { +printk (" [<%016lx>]" , address); +return ; + } +if (!modname) modname = delim ="" ; -return printk ("<%016lx>{%s%s%s%s%+ld}" , - address, delim, modname, delim, symname, offset); -} +printk (" [<%016lx>] %s%s%s%s+0x%lx/0x%lx" , + address, delim, modname, delim, symname, offset, symsize); +}#else -int printk_address (unsigned long address) -{ -return printk ("[<%016lx>]" , address); -} +void printk_address (unsigned long address) +{ +printk (" [<%016lx>]" , address); +}#endif static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
@@ -200,21 +202,14 @@ void show_trace(unsigned long *stack) {const unsigned cpu =safe_smp_processor_id ();unsigned long *irqstack_end = (unsigned long *)cpu_pda (cpu)->irqstackptr; -int i;unsigned used =0 ; -printk ("\nCall Trace:" ); +printk ("\nCall Trace:\n" );#define HANDLE_STACK (cond) \ do while (cond) { \ unsigned long addr = *stack++; \ if (kernel_text_address(addr)) { \ - if (i > 50) { \ - printk("\n "); \ - i = 0; \ - } \ - else \ - i += printk(" "); \/* \ * If the address is either in the text segment of the \ * kernel, or in the region which contains vmalloc'ed \
@@ -223,20 +218,21 @@ void show_trace(unsigned long *stack)* down the cause of the crash will be able to figure \ * out the call path that was taken. \ */ \ - i +=printk_address (addr); \ +printk_address (addr); \ +printk ("\n" ); \ } \ }while (0 ) -for (i =11 ; ; ) { +for ( ; ; ) {const char *id;unsigned long *estack_end; estack_end =in_exception_stack (cpu, (unsigned long )stack, &used, &id);if (estack_end) { - i +=printk (" <%s>" , id); +printk (" <%s>" , id);HANDLE_STACK (stack < estack_end); - i +=printk (" <EOE>" ); +printk (" <EOE>" ); stack = (unsigned long *) estack_end[-2 ];continue ; }
@@ -246,11 +242,11 @@ void show_trace(unsigned long *stack) (IRQSTACKSIZE -64 ) /sizeof (*irqstack);if (stack >= irqstack && stack < irqstack_end) { - i +=printk (" <IRQ>" ); +printk (" <IRQ>" );HANDLE_STACK (stack < irqstack_end); stack = (unsigned long *) (irqstack_end[-1 ]); irqstack_end =NULL ; - i +=printk (" <EOI>" ); +printk (" <EOI>" );continue ; } }
@@ -259,6 +255,7 @@ void show_trace(unsigned long *stack)HANDLE_STACK (((long ) stack & (THREAD_SIZE -1 )) !=0 );#undef HANDLE_STACK +printk ("\n" ); }
include/asm-x86_64/kdebug.h +1 -1
@@ -49,7 +49,7 @@ static inline int notify_die(enum die_vareturn atomic_notifier_call_chain (&die_chain, val, &args); } -extern int printk_address (unsigned long address); +extern void printk_address (unsigned long address);extern void die (const char *,struct pt_regs *,long );extern void __die (const char *,struct pt_regs *,long );extern void show_registers (struct pt_regs *regs);
Re: [patch 12/61] lock validator: beautify x86_64 stacktraces
Quoted 1 line · On Mon, 29 May 2006 23:24:05 +0200 Ingo Molnar <[email protected]> wrote:
beautify
x86_64stacktraces to be more readable.
One reject fixed due to the backtrace changes in Andi's tree.
I'll get all this compiling, but we'll need to review and test the end result please, make sure that it all landed OK.
PATCH 13/61 lock validator: x86_64: document stack frame internals
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
document stack frame nesting internals some more.
--- arch/x86_64/kernel/traps.c | 64 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-)
arch/x86_64/kernel/traps.c +62 -2
@@ -134,8 +134,9 @@ void printk_address(unsigned long addres }#endif -static unsigned long *in_exception_stack (unsigned cpu,unsigned long stack, -unsigned *usedp,const char **idp) +unsigned long * +in_exception_stack (unsigned cpu,unsigned long stack,unsigned *usedp, +const char **idp) {static char ids[][8 ] = { [DEBUG_STACK -1 ] ="#DB" ,
@@ -149,10 +150,22 @@ static unsigned long *in_exception_stack };unsigned k; +/* +* Iterate over all exception stacks, and figure out whether +* 'stack' is in one of them: +*/ for (k =0 ; k <N_EXCEPTION_STACKS ; k++) {unsigned long end; +/* +* set 'end' to the end of the exception stack. +*/ switch (k +1 ) { +/* +* TODO: this block is not needed i think, because +* setup64.c:cpu_init() sets up t->ist[DEBUG_STACK] +* properly too. +*/ #if DEBUG_STKSZ >EXCEPTION_STKSZ case DEBUG_STACK : end =cpu_pda (cpu)->debugstack +DEBUG_STKSZ ;
@@ -162,19 +175,43 @@ static unsigned long *in_exception_stack end =per_cpu (init_tss, cpu).ist[k];break ; } +/* +* Is 'stack' above this exception frame's end? +* If yes then skip to the next frame. +*/ if (stack >= end)continue ; +/* +* Is 'stack' above this exception frame's start address? +* If yes then we found the right frame. +*/ if (stack >= end -EXCEPTION_STKSZ ) { +/* +* Make sure we only iterate through an exception +* stack once. If it comes up for the second time +* then there's something wrong going on - just +* break out and return NULL: +*/ if (*usedp & (1U << k))break ; *usedp |=1U << k; *idp = ids[k];return (unsigned long *)end; } +/* +* If this is a debug stack, and if it has a larger size than +* the usual exception stacks, then 'stack' might still +* be within the lower portion of the debug stack: +*/ #if DEBUG_STKSZ >EXCEPTION_STKSZ if (k ==DEBUG_STACK -1 && stack >= end -DEBUG_STKSZ ) {unsigned j =N_EXCEPTION_STACKS -1 ; +/* +* Black magic. A large debug stack is composed of +* multiple exception stack entries, which we +* iterate through now. Dont look: +*/ do { ++j; end -= EXCEPTION_STKSZ;
@@ -206,6 +243,11 @@ void show_trace(unsigned long *stack)printk ("\nCall Trace:\n" ); +/* +* Print function call entries within a stack. 'cond' is the +* "end of stackframe" condition, that the 'stack++' +* iteration will eventually trigger. +*/ #define HANDLE_STACK (cond) \ do while (cond) { \ unsigned long addr = *stack++; \
@@ -223,6 +265,11 @@ void show_trace(unsigned long *stack) } \ }while (0 ) +/* +* Print function call entries in all stacks, starting at the +* current stack address. If the stacks consist of nested +* exceptions +*/ for ( ; ; ) {const char *id;unsigned long *estack_end;
@@ -233,6 +280,11 @@ void show_trace(unsigned long *stack)printk (" <%s>" , id);HANDLE_STACK (stack < estack_end);printk (" <EOE>" ); +/* +* We link to the next stack via the +* second-to-last pointer (index -2 to end) in the +* exception stack: +*/ stack = (unsigned long *) estack_end[-2 ];continue ; }
@@ -244,6 +296,11 @@ void show_trace(unsigned long *stack)if (stack >= irqstack && stack < irqstack_end) {printk (" <IRQ>" );HANDLE_STACK (stack < irqstack_end); +/* +* We link to the next stack (which would be +* the process stack normally) the last +* pointer (index -1 to end) in the IRQ stack: +*/ stack = (unsigned long *) (irqstack_end[-1 ]); irqstack_end =NULL ;printk (" <EOI>" );
@@ -253,6 +310,9 @@ void show_trace(unsigned long *stack)break ; } +/* +* This prints the process stack: +*/ HANDLE_STACK (((long ) stack & (THREAD_SIZE -1 )) !=0 );#undef HANDLE_STACK
PATCH 14/61 lock validator: stacktrace
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
framework to generate and save stacktraces quickly, without printing anything to the console.
--- arch/i386/kernel/Makefile | 2 arch/i386/kernel/stacktrace.c | 98 +++++++++++++++++ arch/x86_64/kernel/Makefile | 2 arch/x86_64/kernel/stacktrace.c | 219 ++++++++++++++++++++++++++++++++++++++++ include/linux/stacktrace.h | 15 ++ kernel/Makefile | 2 kernel/stacktrace.c | 26 ++++ 7 files changed, 361 insertions(+), 3 deletions(-)
arch/i386/kernel/Makefile +1 -1
@@ -4,7 +4,7 @@ extra-y := head.o init_task.o vmlinux.lds -obj-y := process.o semaphore.o signal.o entry.o traps.o irq.o \ +obj-y := process.o semaphore.o signal.o entry.o traps.o irq.o stacktrace.o \ ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_i386.o \ pci-dma.o i386_ksyms.o i387.o bootflag.o \ quirks.o i8237.o topology.o alternative.o i8253.o tsc.o
arch/i386/kernel/stacktrace.c new file +98 -0
98 lines not on this page · raw message
arch/x86_64/kernel/Makefile +1 -1
@@ -4,7 +4,7 @@ extra-y := head.o head64.o init_task.o vmlinux.lds EXTRA_AFLAGS := -traditional -obj-y := process.o signal.o entry.o traps.o irq.o \ +obj-y := process.o signal.o entry.o traps.o irq.o stacktrace.o \ ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_x86_64.o \ x8664_ksyms.o i387.o syscall.o vsyscall.o \ setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o \
arch/x86_64/kernel/stacktrace.c new file +219 -0
219 lines not on this page · raw message
include/linux/stacktrace.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __LINUX_STACKTRACE_H +#define __LINUX_STACKTRACE_H + +struct stack_trace { +unsigned int nr_entries, max_entries; +unsigned long *entries; +}; + +extern void save_stack_trace (struct stack_trace *trace, +struct task_struct *task,int all_contexts, +unsigned int skip); + +extern void print_stack_trace (struct stack_trace *trace,int spaces); + +#endif
kernel/Makefile +1 -1
@@ -8,7 +8,7 @@ obj-y = sched.o fork.o exec_domain.o signal.o sys.o kmod.o workqueue.o pid.o \ rcupdate.o extable.o params.o posix-timers.o \ kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ - hrtimer.o nsproxy.o + hrtimer.o nsproxy.o stacktrace.o obj-y += time/ obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
kernel/stacktrace.c new file +26 -0
@@ -0,0 +1,26 @@ +/* +* kernel/stacktrace.c +* +* Stack trace management functions +* +* Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <[email protected]> +*/ +#include <linux/sched.h> +#include <linux/kallsyms.h> +#include <linux/stacktrace.h> + +void print_stack_trace (struct stack_trace *trace,int spaces) +{ +int i, j; + +for (i =0 ; i < trace->nr_entries; i++) { +unsigned long ip = trace->entries[i]; + +for (j =0 ; j < spaces +1 ; j++) +printk (" " ); + +printk ("[<%08lx>]" , ip); +print_symbol (" %s\n" , ip); + } +} +
PATCH 15/61 lock validator: x86_64: use stacktrace to generate backtraces
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
this switches x86_64 to use the stacktrace infrastructure when generating backtrace printouts, if CONFIG_FRAME_POINTER=y. (This patch will go away once the dwarf2 stackframe parser in -mm goes upstream.)
--- arch/x86_64/kernel/traps.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
arch/x86_64/kernel/traps.c +33 -2
@@ -235,7 +235,31 @@ in_exception_stack(unsigned cpu, unsigne* severe exception (double fault, nmi, stack fault, debug, mce) hardware stack */ -void show_trace (unsigned long *stack) +#ifdef CONFIG_FRAME_POINTER + +#include <linux/stacktrace.h> + +#define MAX_TRACE_ENTRIES 64 + +static void __show_trace (struct task_struct *task,unsigned long *stack) +{ +unsigned long entries[MAX_TRACE_ENTRIES ]; +struct stack_trace trace; + + trace.nr_entries =0 ; + trace.max_entries =MAX_TRACE_ENTRIES ; + trace.entries = entries; + +save_stack_trace (&trace, task,1 ,0 ); + +pr_debug ("got %d/%d entries.\n" , trace.nr_entries, trace.max_entries); + +print_stack_trace (&trace,4 ); +} + +#else + +void __show_trace (struct task_struct *task,unsigned long *stack) {const unsigned cpu =safe_smp_processor_id ();unsigned long *irqstack_end = (unsigned long *)cpu_pda (cpu)->irqstackptr;
@@ -319,6 +343,13 @@ void show_trace(unsigned long *stack) printk("\n"); } +#endif + +void show_trace (unsigned long *stack) +{ +__show_trace (current, stack); +} +void show_stack (struct task_struct *tsk,unsigned long * rsp) {unsigned long *stack;
@@ -353,7 +384,7 @@ void show_stack(struct task_struct *tsk,printk ("%016lx " , *stack++);touch_nmi_watchdog (); } -show_trace ((unsigned long *)rsp); +__show_trace (tsk, (unsigned long *)rsp); }/*
Re: [patch 15/61] lock validator: x86_64: use stacktrace to generate backtraces
Quoted 3 lines · On Mon, 29 May 2006 23:24:19 +0200 Ingo Molnar <[email protected]> wrote:
this switches
x86_64to use the stacktrace infrastructure when generating backtrace printouts, ifCONFIG_FRAME_POINTER=y. (This patch will go away once the dwarf2 stackframe parser in -mm goes upstream.)
yup, I dropped it.
PATCH 16/61 lock validator: fown locking workaround
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
temporary workaround for the lock validator: make all uses of f_owner.lock irq-safe. (The real solution will be to express to the lock validator that f_owner.lock rules are to be generated per-filesystem.)
--- fs/cifs/file.c | 18 +++++++++--------- fs/fcntl.c | 11 +++++++---- 2 files changed, 16 insertions(+), 13 deletions(-)
fs/cifs/file.c +9 -9
@@ -108,7 +108,7 @@ static inline int cifs_open_inode_helper &pCifsInode->openFileList); }write_unlock (&GlobalSMBSeslock); -write_unlock (&file->f_owner.lock); +write_unlock_irq (&file->f_owner.lock);if (pCifsInode->clientCanCacheRead) {/* we have the inode open somewhere else no need to discard cache data */
@@ -280,7 +280,7 @@ int cifs_open(struct inode *inode, struc goto out; } pCifsFile =cifs_init_private (file->private_data, inode, file, netfid); -write_lock (&file->f_owner.lock); +write_lock_irq (&file->f_owner.lock);write_lock (&GlobalSMBSeslock);list_add (&pCifsFile->tlist, &pTcon->openFileList);
@@ -291,7 +291,7 @@ int cifs_open(struct inode *inode, struc &oplock, buf, full_path, xid); }else {write_unlock (&GlobalSMBSeslock); -write_unlock (&file->f_owner.lock); +write_unlock_irq (&file->f_owner.lock); }if (oplock &CIFS_CREATE_ACTION ) {
@@ -470,7 +470,7 @@ int cifs_close(struct inode *inode, stru pTcon = cifs_sb->tcon;if (pSMBFile) { pSMBFile->closePend = TRUE; -write_lock (&file->f_owner.lock); +write_lock_irq (&file->f_owner.lock);if (pTcon) {/* no sense reconnecting to close a file that is already closed */
@@ -485,23 +485,23 @@ int cifs_close(struct inode *inode, struthe struct would be in each open file, but this should give enough time to clear the socket */ -write_unlock (&file->f_owner.lock); +write_unlock_irq (&file->f_owner.lock);cERROR (1 ,("close with pending writes" ));msleep (timeout); -write_lock (&file->f_owner.lock); +write_lock_irq (&file->f_owner.lock); timeout *=4 ; } -write_unlock (&file->f_owner.lock); +write_unlock_irq (&file->f_owner.lock); rc =CIFSSMBClose (xid, pTcon, pSMBFile->netfid); -write_lock (&file->f_owner.lock); +write_lock_irq (&file->f_owner.lock); } }write_lock (&GlobalSMBSeslock);list_del (&pSMBFile->flist);list_del (&pSMBFile->tlist);write_unlock (&GlobalSMBSeslock); -write_unlock (&file->f_owner.lock); +write_unlock_irq (&file->f_owner.lock);kfree (pSMBFile->search_resume_name);kfree (file->private_data); file->private_data =NULL ;
fs/fcntl.c +7 -4
@@ -470,9 +470,10 @@ static void send_sigio_to_task(struct tavoid send_sigio (struct fown_struct *fown,int fd,int band) {struct task_struct *p; +unsigned long flags;int pid; -read_lock (&fown->lock); +read_lock_irqsave (&fown->lock, flags); pid = fown->pid;if (!pid) goto out_unlock_fown;
@@ -490,7 +491,7 @@ void send_sigio(struct fown_struct *fown }read_unlock (&tasklist_lock); out_unlock_fown: -read_unlock (&fown->lock); +read_unlock_irqrestore (&fown->lock, flags); } static void send_sigurg_to_task(struct task_struct *p,
@@ -503,9 +504,10 @@ static void send_sigurg_to_task(struct tint send_sigurg (struct fown_struct *fown) {struct task_struct *p; +unsigned long flags;int pid, ret =0 ; -read_lock (&fown->lock); +read_lock_irqsave (&fown->lock, flags); pid = fown->pid;if (!pid) goto out_unlock_fown;
@@ -525,7 +527,8 @@ int send_sigurg(struct fown_struct *fown }read_unlock (&tasklist_lock); out_unlock_fown: -read_unlock (&fown->lock); +read_unlock_irqrestore (&fown->lock, flags); +return ret; }
Re: [patch 16/61] lock validator: fown locking workaround
Quoted 4 lines · On Mon, 29 May 2006 23:24:23 +0200 Ingo Molnar <[email protected]> wrote:
temporary workaround for the lock validator: make all uses of f_owner.lock irq-safe. (The real solution will be to express to the lock validator that f_owner.lock rules are to be generated per-filesystem.)
This description forgot to tell us what problem is being worked around.
This patch is a bit of a show-stopper. How hard-n-bad is the real fix?
Re: [patch 16/61] lock validator: fown locking workaround
Quoted 10 lines · Andrew Morton
Quoted 4 lines · On Mon, 29 May 2006 23:24:23 +0200 Ingo Molnar <[email protected]> wrote:
temporary workaround for the lock validator: make all uses of f_owner.lock irq-safe. (The real solution will be to express to the lock validator that f_owner.lock rules are to be generated per-filesystem.)
This description forgot to tell us what problem is being worked around.
f_owner locking rules are per-filesystem: some of them have this lock irq-safe [because they use it in irq-context generated SIGIOs], some of them have it irq-unsafe [because they dont generate SIGIOs in irq context]. The lock validator meshes them together and produces a false positive. The workaround changed all uses of f_owner.lock to be irq-safe.
Quoted 2 lines
This patch is a bit of a show-stopper. How hard-n-bad is the real fix?
the real fix would be to correctly map the 'key' of the f_owner.lock to the filesystem. I.e. to embedd a "lockdep_type_key s_fown_key" in 'struct file_system_type', and to use that key when initializing f_own.lock.
the practical problem is that the initialization site of f_owner.lock does not know about which filesystem this file will belong to.
there might be another way though: the only non-core user of f_own.lock is CIFS, and that use of f_own.lock seems unnecessary - it does not change any fowner state, and its justification for taking that lock seems rather vague as well:
* GlobalSMBSesLock protects:
* list operations on tcp and SMB session lists and tCon lists
* f_owner.lock protects certain per file struct operations
maybe CIFS or VFS people could comment?
that way you could remove the following patch from -mm:
lock-validator-fown-locking-workaround.patch
and add the patch below. (the fcntl.c portion of the above patch is meanwhile moot)
Ingo
--------------------------------------
Subject: CIFS: remove f_owner.lock use
From: Ingo Molnar <[email protected]>
CIFS takes/releases f_owner.lock - why? It does not change anything in the fowner state. Remove this locking.
--- fs/cifs/file.c | 9 --------- 1 file changed, 9 deletions(-)
fs/cifs/file.c +0 -9
@@ -110,7 +110,6 @@ static inline int cifs_open_inode_helper &pCifsInode->openFileList); }write_unlock (&GlobalSMBSeslock); -write_unlock (&file->f_owner.lock);if (pCifsInode->clientCanCacheRead) {/* we have the inode open somewhere else no need to discard cache data */
@@ -287,7 +286,6 @@ int cifs_open(struct inode *inode, struc goto out; } pCifsFile =cifs_init_private (file->private_data, inode, file, netfid); -write_lock (&file->f_owner.lock);write_lock (&GlobalSMBSeslock);list_add (&pCifsFile->tlist, &pTcon->openFileList);
@@ -298,7 +296,6 @@ int cifs_open(struct inode *inode, struc &oplock, buf, full_path, xid); }else {write_unlock (&GlobalSMBSeslock); -write_unlock (&file->f_owner.lock); }if (oplock &CIFS_CREATE_ACTION ) {
@@ -477,7 +474,6 @@ int cifs_close(struct inode *inode, stru pTcon = cifs_sb->tcon;if (pSMBFile) { pSMBFile->closePend = TRUE; -write_lock (&file->f_owner.lock);if (pTcon) {/* no sense reconnecting to close a file that is already closed */
@@ -492,23 +488,18 @@ int cifs_close(struct inode *inode, struthe struct would be in each open file, but this should give enough time to clear the socket */ -write_unlock (&file->f_owner.lock);cERROR (1 ,("close with pending writes" ));msleep (timeout); -write_lock (&file->f_owner.lock); timeout *=4 ; } -write_unlock (&file->f_owner.lock); rc =CIFSSMBClose (xid, pTcon, pSMBFile->netfid); -write_lock (&file->f_owner.lock); } }write_lock (&GlobalSMBSeslock);list_del (&pSMBFile->flist);list_del (&pSMBFile->tlist);write_unlock (&GlobalSMBSeslock); -write_unlock (&file->f_owner.lock);kfree (pSMBFile->search_resume_name);kfree (file->private_data); file->private_data =NULL ;
PATCH 17/61 lock validator: sk_callback_lock workaround
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
temporary workaround for the lock validator: make all uses of sk_callback_lock softirq-safe. (The real solution will be to express to the lock validator that sk_callback_lock rules are to be generated per-address-family.)
--- net/core/sock.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
net/core/sock.c +12 -12
@@ -934,9 +934,9 @@ int sock_i_uid(struct sock *sk) {int uid; -read_lock (&sk->sk_callback_lock); +read_lock_bh (&sk->sk_callback_lock); uid = sk->sk_socket ?SOCK_INODE (sk->sk_socket)->i_uid :0 ; -read_unlock (&sk->sk_callback_lock); +read_unlock_bh (&sk->sk_callback_lock);return uid; }
@@ -944,9 +944,9 @@ unsigned long sock_i_ino(struct sock *sk {unsigned long ino; -read_lock (&sk->sk_callback_lock); +read_lock_bh (&sk->sk_callback_lock); ino = sk->sk_socket ?SOCK_INODE (sk->sk_socket)->i_ino :0 ; -read_unlock (&sk->sk_callback_lock); +read_unlock_bh (&sk->sk_callback_lock);return ino; }
@@ -1306,33 +1306,33 @@ ssize_t sock_no_sendpage(struct socket *static void sock_def_wakeup (struct sock *sk) { -read_lock (&sk->sk_callback_lock); +read_lock_bh (&sk->sk_callback_lock);if (sk->sk_sleep &&waitqueue_active (sk->sk_sleep))wake_up_interruptible_all (sk->sk_sleep); -read_unlock (&sk->sk_callback_lock); +read_unlock_bh (&sk->sk_callback_lock); }static void sock_def_error_report (struct sock *sk) { -read_lock (&sk->sk_callback_lock); +read_lock_bh (&sk->sk_callback_lock);if (sk->sk_sleep &&waitqueue_active (sk->sk_sleep))wake_up_interruptible (sk->sk_sleep);sk_wake_async (sk,0 ,POLL_ERR ); -read_unlock (&sk->sk_callback_lock); +read_unlock_bh (&sk->sk_callback_lock); }static void sock_def_readable (struct sock *sk,int len) { -read_lock (&sk->sk_callback_lock); +read_lock_bh (&sk->sk_callback_lock);if (sk->sk_sleep &&waitqueue_active (sk->sk_sleep))wake_up_interruptible (sk->sk_sleep);sk_wake_async (sk,1 ,POLL_IN ); -read_unlock (&sk->sk_callback_lock); +read_unlock_bh (&sk->sk_callback_lock); }static void sock_def_write_space (struct sock *sk) { -read_lock (&sk->sk_callback_lock); +read_lock_bh (&sk->sk_callback_lock);/* Do not wake up a writer until he can make "significant" * progress. --DaveM
@@ -1346,7 +1346,7 @@ static void sock_def_write_space(structsk_wake_async (sk,2 ,POLL_OUT ); } -read_unlock (&sk->sk_callback_lock); +read_unlock_bh (&sk->sk_callback_lock); }static void sock_def_destruct (struct sock *sk)
Re: [patch 17/61] lock validator: sk_callback_lock workaround
Quoted 4 lines · On Mon, 29 May 2006 23:24:27 +0200 Ingo Molnar <[email protected]> wrote:
temporary workaround for the lock validator: make all uses of
sk_callback_locksoftirq-safe. (The real solution will be to express to the lock validator thatsk_callback_lockrules are to be generated per-address-family.)
Ditto. What's the actual problem being worked around here, and how's the real fix shaping up?
Re: [patch 17/61] lock validator: sk_callback_lock workaround
Quoted 10 lines · Andrew Morton
Quoted 4 lines · On Mon, 29 May 2006 23:24:27 +0200 Ingo Molnar <[email protected]> wrote:
temporary workaround for the lock validator: make all uses of
sk_callback_locksoftirq-safe. (The real solution will be to express to the lock validator thatsk_callback_lockrules are to be generated per-address-family.)Ditto. What's the actual problem being worked around here, and how's the real fix shaping up?
this patch should be moot meanwhile. Earlier versions of the lock validator produced false positives for certain read-locking constructs.
i have undone the patch:
lock-validator-sk_callback_lock-workaround.patch
and there doesnt seem to be any false positives popping up. Please dont remove it from -mm yet, i'll test this some more and will do the removal in the lock validator queue refactoring, ok?
Ingo
PATCH 18/61 lock validator: irqtrace: core
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
accurate hard-IRQ-flags state tracing. This allows us to attach extra functionality to IRQ flags on/off events (such as trace-on/off).
--- arch/i386/kernel/entry.S | 25 ++++++- arch/i386/kernel/irq.c | 6 + arch/x86_64/ia32/ia32entry.S | 19 +++++ arch/x86_64/kernel/entry.S | 54 +++++++++++++++- arch/x86_64/kernel/irq.c | 4 - include/asm-i386/irqflags.h | 56 ++++++++++++++++ include/asm-i386/spinlock.h | 5 + include/asm-i386/system.h | 20 ----- include/asm-powerpc/irqflags.h | 31 +++++++++ include/asm-x86_64/irqflags.h | 54 ++++++++++++++++ include/asm-x86_64/system.h | 38 ----------- include/linux/hardirq.h | 13 +++ include/linux/init_task.h | 1 include/linux/interrupt.h | 11 +-- include/linux/sched.h | 15 ++++ include/linux/trace_irqflags.h | 87 ++++++++++++++++++++++++++ kernel/fork.c | 20 +++++ kernel/sched.c | 4 - kernel/softirq.c | 137 +++++++++++++++++++++++++++++++++++------ lib/locking-selftest.c | 3 20 files changed, 513 insertions(+), 90 deletions(-)
arch/i386/kernel/entry.S +23 -2
@@ -43,6 +43,7 @@ #include <linux/config.h> #include <linux/linkage.h> #include <asm/thread_info.h> +#include <asm/irqflags.h> #include <asm/errno.h> #include <asm/segment.h> #include <asm/smp.h>
@@ -76,7 +77,7 @@ NT_MASK = 0x00004000 VM_MASK = 0x00020000 #ifdef CONFIG_PREEMPT -#define preempt_stop cli +#define preempt_stop cli; TRACE_IRQS_OFF #else #define preempt_stop #define resume_kernel restore_nocheck
@@ -186,6 +187,10 @@ need_resched: ENTRY(sysenter_entry) movl TSS_sysenter_esp0(%esp),%esp sysenter_past_esp: + /* + * No need to follow this irqs on/off section: the syscall + * disabled irqs and here we enable it straight after entry: + */ sti pushl $(__USER_DS) pushl %ebp
@@ -217,6 +222,7 @@ sysenter_past_esp: call *sys_call_table(,%eax,4) movl %eax,EAX(%esp) cli + TRACE_IRQS_OFF movl TI_flags(%ebp), %ecx testw $_TIF_ALLWORK_MASK, %cx jne syscall_exit_work
@@ -224,6 +230,7 @@ sysenter_past_esp: movl EIP(%esp), %edx movl OLDESP(%esp), %ecx xorl %ebp,%ebp + TRACE_IRQS_ON sti sysexit
@@ -250,6 +257,7 @@ syscall_exit: cli # make sure we don't miss an interrupt # setting need_resched or sigpending # between sampling and the iret + TRACE_IRQS_OFF movl TI_flags(%ebp), %ecx testw $_TIF_ALLWORK_MASK, %cx # current->work jne syscall_exit_work
@@ -265,11 +273,14 @@ restore_all: cmpl $((4 << 8) | 3), %eax je ldt_ss # returning to user-space with LDT SS restore_nocheck: + TRACE_IRQS_ON +restore_nocheck_notrace: RESTORE_REGS addl $4, %esp 1: iret .section .fixup,"ax" iret_exc: + TRACE_IRQS_ON sti pushl $0 # no error code pushl $do_iret_error
@@ -293,10 +304,12 @@ ldt_ss: * dosemu and wine happy. */ subl $8, %esp # reserve space for switch16 pointer cli + TRACE_IRQS_OFF movl %esp, %eax /* Set up the 16bit stack frame with switch32 pointer on top, * and a switch16 pointer on top of the current frame. */ call setup_x86_bogus_stack + TRACE_IRQS_ON RESTORE_REGS lss 20+4(%esp), %esp # switch to 16bit stack 1: iret
@@ -315,6 +328,7 @@ work_resched: cli # make sure we don't miss an interrupt # setting need_resched or sigpending # between sampling and the iret + TRACE_IRQS_OFF movl TI_flags(%ebp), %ecx andl $_TIF_WORK_MASK, %ecx # is there any work to be done other # than syscall tracing?
@@ -364,6 +378,7 @@ syscall_trace_entry: syscall_exit_work: testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl jz work_pending + TRACE_IRQS_ON sti # could let do_syscall_trace() call # schedule() instead movl %esp, %eax
@@ -425,9 +440,14 @@ ENTRY(irq_entries_start) vector=vector+1 .endr +/* + * the CPU automatically disables interrupts when executing an IRQ vector, + * so IRQ-flags tracing has to follow that: + */ ALIGN common_interrupt: SAVE_ALL + TRACE_IRQS_OFF movl %esp,%eax call do_IRQ jmp ret_from_intr
@@ -436,6 +456,7 @@ common_interrupt: ENTRY(name) \ pushl $~(nr); \ SAVE_ALL \ + TRACE_IRQS_OFF \ movl %esp,%eax; \ call smp_/**/name; \ jmp ret_from_intr;
@@ -565,7 +586,7 @@ nmi_stack_correct: xorl %edx,%edx # zero error code movl %esp,%eax # pt_regs pointer call do_nmi - jmp restore_all + jmp restore_nocheck_notrace nmi_stack_fixup: FIX_STACK(12,nmi_stack_correct, 1)
arch/i386/kernel/irq.c +5 -1
@@ -147,7 +147,7 @@ void irq_ctx_init(int cpu) irqctx->tinfo.task =NULL ; irqctx->tinfo.exec_domain =NULL ; irqctx->tinfo.cpu = cpu; - irqctx->tinfo.preempt_count =SOFTIRQ_OFFSET ; + irqctx->tinfo.preempt_count =0 ; irqctx->tinfo.addr_limit =MAKE_MM_SEG (0 ); softirq_ctx[cpu] = irqctx;
@@ -192,6 +192,10 @@ asmlinkage void do_softirq(void) : "0"(isp) : "memory", "cc", "edx", "ecx", "eax" ); +/* +* Shouldnt happen, we returned above if in_interrupt(): +*/ +WARN_ON_ONCE (softirq_count ()); }local_irq_restore (flags);
arch/x86_64/ia32/ia32entry.S +18 -1
@@ -13,6 +13,7 @@ #include <asm/thread_info.h> #include <asm/segment.h> #include <asm/vsyscall32.h> +#include <asm/irqflags.h> #include <linux/linkage.h> #define IA32_NR_syscalls ((ia32_syscall_end - ia32_sys_call_table)/8)
@@ -75,6 +76,10 @@ ENTRY(ia32_sysenter_target) swapgs movq %gs:pda_kernelstack, %rsp addq $(PDA_STACKOFFSET),%rsp + /* + * No need to follow this irqs on/off section: the syscall + * disabled irqs, here we enable it straight after entry: + */ sti movl %ebp,%ebp /* zero extension */ pushq $__USER32_DS
@@ -118,6 +123,7 @@ sysenter_do_call: movq %rax,RAX-ARGOFFSET(%rsp) GET_THREAD_INFO(%r10) cli + TRACE_IRQS_OFF testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10) jnz int_ret_from_sys_call andl $~TS_COMPAT,threadinfo_status(%r10)
@@ -132,6 +138,7 @@ sysenter_do_call: CFI_REGISTER rsp,rcx movl $VSYSCALL32_SYSEXIT,%edx /* User %eip */ CFI_REGISTER rip,rdx + TRACE_IRQS_ON swapgs sti /* sti only takes effect after the next instruction */ /* sysexit */
@@ -186,6 +193,10 @@ ENTRY(ia32_cstar_target) movl %esp,%r8d CFI_REGISTER rsp,r8 movq %gs:pda_kernelstack,%rsp + /* + * No need to follow this irqs on/off section: the syscall + * disabled irqs and here we enable it straight after entry: + */ sti SAVE_ARGS 8,1,1 movl %eax,%eax /* zero extension */
@@ -220,6 +231,7 @@ cstar_do_call: movq %rax,RAX-ARGOFFSET(%rsp) GET_THREAD_INFO(%r10) cli + TRACE_IRQS_OFF testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10) jnz int_ret_from_sys_call andl $~TS_COMPAT,threadinfo_status(%r10)
@@ -228,6 +240,7 @@ cstar_do_call: CFI_REGISTER rip,rcx movl EFLAGS-ARGOFFSET(%rsp),%r11d /*CFI_REGISTER rflags,r11*/ + TRACE_IRQS_ON movl RSP-ARGOFFSET(%rsp),%esp CFI_RESTORE rsp swapgs
@@ -286,7 +299,11 @@ ENTRY(ia32_syscall) /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/ /*CFI_REL_OFFSET cs,CS-RIP*/ CFI_REL_OFFSET rip,RIP-RIP - swapgs + swapgs + /* + * No need to follow this irqs on/off section: the syscall + * disabled irqs and here we enable it straight after entry: + */ sti movl %eax,%eax pushq %rax
arch/x86_64/kernel/entry.S +53 -1
218 lines not on this page · raw message
arch/x86_64/kernel/irq.c +3 -1
@@ -145,8 +145,10 @@ asmlinkage void do_softirq(void)local_irq_save (flags); pending =local_softirq_pending ();/* Switch to interrupt stack */ -if (pending) +if (pending) {call_softirq (); +WARN_ON_ONCE (softirq_count ()); + }local_irq_restore (flags); }EXPORT_SYMBOL (do_softirq);
include/asm-i386/irqflags.h new file +56 -0
56 lines not on this page · raw message
include/asm-i386/spinlock.h +5 -0
@@ -31,6 +31,11 @@"jmp 1b\n" \"3:\n\t" +/* +* NOTE: there's an irqs-on section here, which normally would have to be +* irq-traced, but on CONFIG_TRACE_IRQFLAGS we never use +* __raw_spin_lock_string_flags(). +*/ #define __raw_spin_lock_string_flags \"\n1:\t" \"lock ; decb %0\n\t" \
include/asm-i386/system.h +1 -19
@@ -456,25 +456,7 @@ static inline unsigned long long __cmpxc#define set_wmb (var, value) do { var = value; wmb(); } while (0) -/* interrupt control.. */ -#define local_save_flags(x) do { typecheck(unsigned long,x); __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */); } while (0) -#define local_irq_restore(x) do { typecheck(unsigned long,x); __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc"); } while (0) -#define local_irq_disable () __asm__ __volatile__("cli": : :"memory") -#define local_irq_enable () __asm__ __volatile__("sti": : :"memory") -/* used in the idle loop; sti takes one instruction cycle to complete */ -#define safe_halt () __asm__ __volatile__("sti; hlt": : :"memory") -/* used when interrupts are already enabled or to shutdown the processor */ -#define halt () __asm__ __volatile__("hlt": : :"memory") - -#define irqs_disabled () \ -({ \ - unsigned long flags; \ - local_save_flags(flags); \ - !(flags & (1<<9)); \ -}) - -/* For spinlocks etc */ -#define local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory") +#include <linux/trace_irqflags.h> /* * disable hlt during certain critical i/o operations
include/asm-powerpc/irqflags.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* include/asm-powerpc/irqflags.h +* +* IRQ flags handling +* +* This file gets included from lowlevel asm headers too, to provide +* wrapped versions of the local_irq_*() APIs, based on the +* raw_local_irq_*() macros from the lowlevel headers. +*/ +#ifndef _ASM_IRQFLAGS_H +#define _ASM_IRQFLAGS_H + +/* +* Get definitions for raw_local_save_flags(x), etc. +*/ +#include <asm-powerpc/hw_irq.h> + +/* +* Do the CPU's IRQ-state tracing from assembly code. We call a +* C function, so save all the C-clobbered registers: +*/ +#ifdef CONFIG_TRACE_IRQFLAGS + +#error No support on PowerPC yet for CONFIG_TRACE_IRQFLAGS + +#else +# define TRACE_IRQS_ON +# define TRACE_IRQS_OFF +#endif + +#endif
include/asm-x86_64/irqflags.h new file +54 -0
54 lines not on this page · raw message
include/asm-x86_64/system.h +1 -37
@@ -244,43 +244,7 @@ static inline unsigned long __cmpxchg(vo#define warn_if_not_ulong (x) do { unsigned long foo; (void) (&(x) == &foo); } while (0) -/* interrupt control.. */ -#define local_save_flags(x) do { warn_if_not_ulong(x); __asm__ __volatile__("# save_flags \n\t pushfq ; popq %q0":"=g" (x): /* no input */ :"memory"); } while (0) -#define local_irq_restore(x) __asm__ __volatile__("# restore_flags \n\t pushq %0 ; popfq": /* no output */ :"g" (x):"memory", "cc") - -#ifdef CONFIG_X86_VSMP -/* Interrupt control for VSMP architecture */ -#define local_irq_disable () do { unsigned long flags; local_save_flags(flags); local_irq_restore((flags & ~(1 << 9)) | (1 << 18)); } while (0) -#define local_irq_enable () do { unsigned long flags; local_save_flags(flags); local_irq_restore((flags | (1 << 9)) & ~(1 << 18)); } while (0) - -#define irqs_disabled () \ -({ \ - unsigned long flags; \ - local_save_flags(flags); \ - (flags & (1<<18)) || !(flags & (1<<9)); \ -}) - -/* For spinlocks etc */ -#define local_irq_save (x) do { local_save_flags(x); local_irq_restore((x & ~(1 << 9)) | (1 << 18)); } while (0) -#else /* CONFIG_X86_VSMP */ -#define local_irq_disable () __asm__ __volatile__("cli": : :"memory") -#define local_irq_enable () __asm__ __volatile__("sti": : :"memory") - -#define irqs_disabled () \ -({ \ - unsigned long flags; \ - local_save_flags(flags); \ - !(flags & (1<<9)); \ -}) - -/* For spinlocks etc */ -#define local_irq_save(x) do { warn_if_not_ulong(x); __asm__ __volatile__("# local_irq_save \n\t pushfq ; popq %0 ; cli":"=g" (x): /* no input */ :"memory"); } while (0) -#endif - -/* used in the idle loop; sti takes one instruction cycle to complete */ -#define safe_halt () __asm__ __volatile__("sti; hlt": : :"memory") -/* used when interrupts are already enabled or to shutdown the processor */ -#define halt () __asm__ __volatile__("hlt": : :"memory") +#include <linux/trace_irqflags.h> void cpu_idle_wait (void );
include/linux/hardirq.h +12 -1
@@ -87,7 +87,11 @@ extern void synchronize_irq(unsigned int#endif #define nmi_enter () irq_enter() -#define nmi_exit () sub_preempt_count(HARDIRQ_OFFSET) +#define nmi_exit () \ + do { \ + sub_preempt_count(HARDIRQ_OFFSET); \ + trace_hardirq_exit(); \ + } while (0)struct task_struct ;
@@ -97,10 +101,17 @@ static inline void account_system_vtime( }#endif +/* +* It is safe to do non-atomic ops on ->hardirq_context, +* because NMI handlers may not preempt and the ops are +* always balanced, so the interrupted value of ->hardirq_context +* will always be restored. +*/ #define irq_enter () \ do { \ account_system_vtime(current); \ add_preempt_count(HARDIRQ_OFFSET); \ + trace_hardirq_enter(); \ } while (0)extern void irq_exit (void );
include/linux/init_task.h +1 -0
@@ -133,6 +133,7 @@ extern struct group_info init_groups; .journal_info = NULL, \ .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .fs_excl = ATOMIC_INIT(0), \ + INIT_TRACE_IRQFLAGS \ }
include/linux/interrupt.h +5 -6
@@ -10,6 +10,7 @@#include <linux/irqreturn.h> #include <linux/hardirq.h> #include <linux/sched.h> +#include <linux/trace_irqflags.h> #include <asm/atomic.h> #include <asm/ptrace.h> #include <asm/system.h>
@@ -72,13 +73,11 @@ static inline void __deprecated save_and#define save_and_cli (x) save_and_cli(&x)#endif /* CONFIG_SMP */ -/* SoftIRQ primitives. */ -#define local_bh_disable () \ - do { add_preempt_count(SOFTIRQ_OFFSET); barrier(); } while (0) -#define __local_bh_enable () \ - do { barrier(); sub_preempt_count(SOFTIRQ_OFFSET); } while (0) - +extern void local_bh_disable (void ); +extern void __local_bh_enable (void ); +extern void _local_bh_enable (void );extern void local_bh_enable (void ); +extern void local_bh_enable_ip (unsigned long ip);/* PLEASE, avoid to allocate new softirqs, if you need not _really_ high frequency threaded job scheduling. For almost all the purposes
include/linux/sched.h +15 -0
@@ -916,6 +916,21 @@ struct task_struct {/* mutex deadlock detection */ struct mutex_waiter *blocked_on;#endif +#ifdef CONFIG_TRACE_IRQFLAGS +unsigned int irq_events; +int hardirqs_enabled; +unsigned long hardirq_enable_ip; +unsigned int hardirq_enable_event; +unsigned long hardirq_disable_ip; +unsigned int hardirq_disable_event; +int softirqs_enabled; +unsigned long softirq_disable_ip; +unsigned int softirq_disable_event; +unsigned long softirq_enable_ip; +unsigned int softirq_enable_event; +int hardirq_context; +int softirq_context; +#endif /* journalling filesystem info */ void *journal_info;
include/linux/trace_irqflags.h new file +87 -0
87 lines not on this page · raw message
kernel/fork.c +19 -1
@@ -970,6 +970,10 @@ static task_t *copy_process(unsigned lonif (!p) goto fork_out; +#ifdef CONFIG_TRACE_IRQFLAGS +DEBUG_WARN_ON (!p->hardirqs_enabled); +DEBUG_WARN_ON (!p->softirqs_enabled); +#endif retval = -EAGAIN ;if (atomic_read (&p->user->processes) >= p->signal->rlim[RLIMIT_NPROC ].rlim_cur) {
@@ -1051,7 +1055,21 @@ static task_t *copy_process(unsigned lon#ifdef CONFIG_DEBUG_MUTEXES p->blocked_on =NULL ;/* not blocked yet */ #endif - +#ifdef CONFIG_TRACE_IRQFLAGS + p->irq_events =0 ; + p->hardirqs_enabled =0 ; + p->hardirq_enable_ip =0 ; + p->hardirq_enable_event =0 ; + p->hardirq_disable_ip = _THIS_IP_; + p->hardirq_disable_event =0 ; + p->softirqs_enabled =1 ; + p->softirq_enable_ip = _THIS_IP_; + p->softirq_enable_event =0 ; + p->softirq_disable_ip =0 ; + p->softirq_disable_event =0 ; + p->hardirq_context =0 ; + p->softirq_context =0 ; +#endif p->tgid = p->pid;if (clone_flags &CLONE_THREAD ) p->tgid = current->tgid;
kernel/sched.c +3 -1
@@ -4481,7 +4481,9 @@ int __sched cond_resched_softirq(void)BUG_ON (!in_softirq ());if (need_resched ()) { -__local_bh_enable (); +raw_local_irq_disable (); +_local_bh_enable (); +raw_local_irq_enable ();__cond_resched ();local_bh_disable ();return 1 ;
kernel/softirq.c +118 -19
168 lines not on this page · raw message
lib/locking-selftest.c +3 -0
@@ -19,6 +19,7 @@#include <linux/kallsyms.h> #include <linux/interrupt.h> #include <linux/debug_locks.h> +#include <linux/trace_irqflags.h> /* * Change this to 1 if you want to see the failure printouts:
@@ -157,9 +158,11 @@ static void init_shared_types(void)#define SOFTIRQ_ENTER () \ local_bh_disable(); \ local_irq_disable(); \ + trace_softirq_enter(); \ WARN_ON(!in_softirq());#define SOFTIRQ_EXIT () \ + trace_softirq_exit(); \ local_irq_enable(); \ local_bh_enable();
Re: [patch 18/61] lock validator: irqtrace: core
Quoted 2 lines · On Mon, 29 May 2006 23:24:32 +0200 Ingo Molnar <[email protected]> wrote:
accurate hard-IRQ-flags state tracing. This allows us to attach extra functionality to IRQ flags on/off events (such as trace-on/off).
That's a fairly skimpy description of some fairly substantial new infrastructure.
Re: [patch 18/61] lock validator: irqtrace: core
Quoted 9 lines · Andrew Morton
Quoted 3 lines · On Mon, 29 May 2006 23:24:32 +0200 Ingo Molnar <[email protected]> wrote:
accurate hard-IRQ-flags state tracing. This allows us to attach extra functionality to IRQ flags on/off events (such as trace-on/off).
That's a fairly skimpy description of some fairly substantial new infrastructure.
ok, here's some more info (i'll add this to the irq-flags-tracing core patch):
the "irq state tracing" feature "traces" hardirq and softirq state, in that it gives interested subsystems an opportunity to be notified of every hardirqs-off/hardirqs-on, softirqs-off/softirqs-on event that happens in the kernel.
CONFIG_TRACE_IRQFLAGS_SUPPORT is needed for CONFIG_PROVE_SPIN_LOCKING and CONFIG_PROVE_RW_LOCKING to be offered by the generic lock debugging code. Otherwise only CONFIG_PROVE_MUTEX_LOCKING and CONFIG_PROVE_RWSEM_LOCKING will be offered on an architecture - these are locking APIs that are not used in IRQ context. (the one exception for rwsems is worked around)
Right now the only interested subsystem is the lock validator, but things like RTLinux, ADEOS, the -rt tree and the latency tracer would certainly be interested in managing irq-flags state too. (I did not add any expansive (and probably expensive) notifier mechanism yet, before someone actually tries to mix multiple users of this infrastructure and comes up with the right abstraction.)
architecture support for this is certainly not in the "trivial" category, because lots of lowlevel assembly code deal with irq-flags state changes. But an architecture can be irq-flags-tracing enabled in a rather straightforward and risk-free manner.
Architectures that want to support this need to do a couple of code-organizational changes first:
- move their irq-flags manipulation code from their asm/system.h header to asm/irqflags.h
- rename local_irq_disable()/etc to raw_local_irq_disable()/etc. so that the linux/irqflags.h code can inject callbacks and can construct the real local_irq_disable()/etc APIs.
- add and enable TRACE_IRQFLAGS_SUPPORT in their arch level Kconfig file
and then a couple of functional changes are needed as well to implement irq-flags-tracing support:
- in lowlevel entry code add (build-conditional) calls to the trace_hardirqs_off()/trace_hardirqs_on() functions. The lock validator closely guards whether the 'real' irq-flags matches the 'virtual' irq-flags state, and complains loudly (and turns itself off) if the two do not match. Usually most of the time for arch support for irq-flags-tracing is spent in this state: look at the lockdep complaint, try to figure out the assembly code we did not cover yet, fix and repeat. Once the system has booted up and works without a lockdep complaint in the irq-flags-tracing functions arch support is complete.
- if the architecture has non-maskable interrupts then those need to be excluded from the irq-tracing [and lock validation] mechanism via lockdep_off()/lockdep_on().
in general there is no risk from having an incomplete irq-flags-tracing implementation in an architecture: lockdep will detect that and will turn itself off. I.e. the lock validator will still be reliable. There should be no crashes due to irq-tracing bugs. (except if the assembly changes break other code by modifying conditions or registers that shouldnt be)
Ingo
PATCH 19/61 lock validator: irqtrace: cleanup: include/asm-i386/irqflags.h
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
clean up the x86 irqflags.h file:
- macro => inline function transformation
- simplifications
- style fixes
--- include/asm-i386/irqflags.h | 95 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 12 deletions(-)
include/asm-i386/irqflags.h +83 -12
@@ -5,24 +5,95 @@* * This file gets included from lowlevel asm headers too, to provide * wrapped versions of the local_irq_*() APIs, based on the -* raw_local_irq_*() macros from the lowlevel headers. +* raw_local_irq_*() functions from the lowlevel headers. */ #ifndef _ASM_IRQFLAGS_H#define _ASM_IRQFLAGS_H -#define raw_local_save_flags(x) do { typecheck(unsigned long,x); __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */); } while (0) -#define raw_local_irq_restore(x) do { typecheck(unsigned long,x); __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc"); } while (0) -#define raw_local_irq_disable () __asm__ __volatile__("cli": : :"memory") -#define raw_local_irq_enable () __asm__ __volatile__("sti": : :"memory") -/* used in the idle loop; sti takes one instruction cycle to complete */ -#define raw_safe_halt () __asm__ __volatile__("sti; hlt": : :"memory") -/* used when interrupts are already enabled or to shutdown the processor */ -#define halt () __asm__ __volatile__("hlt": : :"memory") +#ifndef __ASSEMBLY__ -#define raw_irqs_disabled_flags (flags) (!((flags) & (1<<9))) +static inline unsigned long __raw_local_save_flags (void ) +{ +unsigned long flags; + + __asm__ __volatile__( +"pushfl ; popl %0" + :"=g" (flags) + :/* no input */ + ); + +return flags; +} + +#define raw_local_save_flags (flags) \ + do { (flags) = __raw_local_save_flags(); } while (0) + +static inline void raw_local_irq_restore (unsigned long flags) +{ + __asm__ __volatile__( +"pushl %0 ; popfl" + :/* no output */ + :"g" (flags) + :"memory" ,"cc" + ); +} + +static inline void raw_local_irq_disable (void ) +{ + __asm__ __volatile__("cli" : : :"memory" ); +} + +static inline void raw_local_irq_enable (void ) +{ + __asm__ __volatile__("sti" : : :"memory" ); +} -/* For spinlocks etc */ -#define raw_local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory") +/* +* Used in the idle loop; sti takes one instruction cycle +* to complete: +*/ +static inline void raw_safe_halt (void ) +{ + __asm__ __volatile__("sti; hlt" : : :"memory" ); +} + +/* +* Used when interrupts are already enabled or to +* shutdown the processor: +*/ +static inline void halt (void ) +{ + __asm__ __volatile__("hlt" : : :"memory" ); +} + +static inline int raw_irqs_disabled_flags (unsigned long flags) +{ +return !(flags & (1 <<9 )); +} + +static inline int raw_irqs_disabled (void ) +{ +unsigned long flags =__raw_local_save_flags (); + +return raw_irqs_disabled_flags (flags); +} + +/* +* For spinlocks, etc: +*/ +static inline unsigned long __raw_local_irq_save (void ) +{ +unsigned long flags =__raw_local_save_flags (); + +raw_local_irq_disable (); + +return flags; +} + +#define raw_local_irq_save (flags) \ + do { (flags) = __raw_local_irq_save(); } while (0) + +#endif /* __ASSEMBLY__ */ /* * Do the CPU's IRQ-state tracing from assembly code. We call a
PATCH 20/61 lock validator: irqtrace: cleanup: include/asm-x86_64/irqflags.h
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
clean up the x86-64 irqflags.h file:
- macro => inline function transformation
- simplifications
- style fixes
--- arch/x86_64/lib/thunk.S | 5 + include/asm-x86_64/irqflags.h | 159 ++++++++++++++++++++++++++++++++---------- 2 files changed, 128 insertions(+), 36 deletions(-)
arch/x86_64/lib/thunk.S +5 -0
@@ -47,6 +47,11 @@ thunk_retrax __down_failed_interruptible,__down_interruptible thunk_retrax __down_failed_trylock,__down_trylock thunk __up_wakeup,__up + +#ifdef CONFIG_TRACE_IRQFLAGS + thunk trace_hardirqs_on_thunk,trace_hardirqs_on + thunk trace_hardirqs_off_thunk,trace_hardirqs_off +#endif /* SAVE_ARGS below is used only for the .cfi directives it contains. */ CFI_STARTPROC
include/asm-x86_64/irqflags.h +123 -36
173 lines not on this page · raw message
PATCH 21/61 lock validator: lockdep: add local_irq_enable_in_hardirq() API.
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
introduce local_irq_enable_in_hardirq() API. It is currently aliased to local_irq_enable(), hence has no functional effects.
This API will be used by lockdep, but even without lockdep this will better document places in the kernel where a hardirq context enables hardirqs.
--- arch/i386/kernel/nmi.c | 3 ++- arch/x86_64/kernel/nmi.c | 3 ++- drivers/ide/ide-io.c | 6 +++--- drivers/ide/ide-taskfile.c | 2 +- include/linux/ide.h | 2 +- include/linux/trace_irqflags.h | 2 ++ kernel/irq/handle.c | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-)
arch/i386/kernel/nmi.c +2 -1
@@ -188,7 +188,8 @@ static __cpuinit inline int nmi_known_cpstatic __init void nmi_cpu_busy (void *data) {volatile int *endflag = data; -local_irq_enable (); + +local_irq_enable_in_hardirq ();/* Intentionally don't use cpu_relax here. This is to make sure that the performance counter really ticks, even if there is a simulator or similar that catches the
arch/x86_64/kernel/nmi.c +2 -1
@@ -186,7 +186,8 @@ void nmi_watchdog_default(void)static __init void nmi_cpu_busy (void *data) {volatile int *endflag = data; -local_irq_enable (); + +local_irq_enable_in_hardirq ();/* Intentionally don't use cpu_relax here. This is to make sure that the performance counter really ticks, even if there is a simulator or similar that catches the
drivers/ide/ide-io.c +3 -3
@@ -689,7 +689,7 @@ static ide_startstop_t drive_cmd_intr (iu8 stat = hwif->INB (IDE_STATUS_REG );int retries =10 ; -local_irq_enable (); +local_irq_enable_in_hardirq ();if ((stat &DRQ_STAT ) && args && args[3 ]) {u8 io_32bit = drive->io_32bit; drive->io_32bit =0 ;
@@ -1273,7 +1273,7 @@ static void ide_do_request (ide_hwgroup_if (masked_irq !=IDE_NO_IRQ && hwif->irq != masked_irq)disable_irq_nosync (hwif->irq);spin_unlock (&ide_lock); -local_irq_enable (); +local_irq_enable_in_hardirq ();/* allow other IRQs while we start this request */ startstop =start_request (drive, rq);spin_lock_irq (&ide_lock);
@@ -1622,7 +1622,7 @@ irqreturn_t ide_intr (int irq, void *devspin_unlock (&ide_lock);if (drive->unmask) -local_irq_enable (); +local_irq_enable_in_hardirq ();/* service this interrupt, may set handler for next interrupt */ startstop =handler (drive);spin_lock_irq (&ide_lock);
drivers/ide/ide-taskfile.c +1 -1
@@ -223,7 +223,7 @@ ide_startstop_t task_no_data_intr (ide_dide_hwif_t *hwif =HWIF (drive);u8 stat; -local_irq_enable (); +local_irq_enable_in_hardirq ();if (!OK_STAT (stat = hwif->INB (IDE_STATUS_REG ),READY_STAT ,BAD_STAT )) {return ide_error (drive,"task_no_data_intr" , stat);/* calls ide_end_drive_cmd */
include/linux/ide.h +1 -1
@@ -1361,7 +1361,7 @@ extern struct semaphore ide_cfg_sem;* ide_drive_t->hwif: constant, no locking */ -#define local_irq_set (flags) do { local_save_flags((flags)); local_irq_enable(); } while (0) +#define local_irq_set (flags) do { local_save_flags((flags)); local_irq_enable_in_hardirq(); } while (0)extern struct bus_type ide_bus_type;
include/linux/trace_irqflags.h +2 -0
@@ -66,6 +66,8 @@ } \ } while (0) +#define local_irq_enable_in_hardirq () local_irq_enable() +#define safe_halt () \ do { \ trace_hardirqs_on(); \
kernel/irq/handle.c +1 -1
@@ -83,7 +83,7 @@ fastcall irqreturn_t handle_IRQ_event(ununsigned int status =0 ;if (!(action->flags &SA_INTERRUPT )) -local_irq_enable (); +local_irq_enable_in_hardirq (); do { ret = action->handler(irq, action->dev_id, regs);
Re: [patch 21/61] lock validator: lockdep: add local_irq_enable_in_hardirq() API.
Quoted 6 lines · On Mon, 29 May 2006 23:24:52 +0200 Ingo Molnar <[email protected]> wrote:
introduce
local_irq_enable_in_hardirq()API. It is currently aliased tolocal_irq_enable(), hence has no functional effects.This API will be used by lockdep, but even without lockdep this will better document places in the kernel where a hardirq context enables hardirqs.
If we expect people to use this then we'd best whack a comment over it.
Also, trace_irqflags.h doesn't seem an appropriate place for it to live.
I trust all the affected files are including trace_irqflags.h by some means. Hopefully a _reliable_ means. No doubt I'm about to find out ;)
Re: [patch 21/61] lock validator: lockdep: add local_irq_enable_in_hardirq() API.
Quoted 6 lines · Andrew Morton
Quoted 3 lines · On Mon, 29 May 2006 23:24:52 +0200 Ingo Molnar <[email protected]> wrote:
introduce
local_irq_enable_in_hardirq()API. It is currently aliased tolocal_irq_enable(), hence has no functional effects.
Quoted 6 lines
Quoted 3 lines
This API will be used by lockdep, but even without lockdep this will better document places in the kernel where a hardirq context enables hardirqs.
If we expect people to use this then we'd best whack a comment over it.
ok, i've improved the comment in trace_irqflags.h.
Quoted 2 lines
Also,
trace_irqflags.hdoesn't seem an appropriate place for it to live.
seems like the most practical place for it. Previously we had no central include file for irq-flags APIs (they used to be included from asm/system.h and other random per-arch places) - trace_irqflags.h has become the central file now. Should i rename it to irqflags.h perhaps, to not tie it to tracing? We have some deprecated irq-flags ops in interrupt.h, maybe this all belongs there. (although i think it's cleaner to have linux/include/irqflags.h and include it from interrupt.h)
Ingo
Re: [patch 21/61] lock validator: lockdep: add local_irq_enable_in_hardirq() API.
Quoted 21 lines · On Fri, 23 Jun 2006 11:28:52 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
Quoted 3 lines · On Mon, 29 May 2006 23:24:52 +0200 Ingo Molnar <[email protected]> wrote:
introduce
local_irq_enable_in_hardirq()API. It is currently aliased tolocal_irq_enable(), hence has no functional effects.Quoted 6 lines
Quoted 3 lines
This API will be used by lockdep, but even without lockdep this will better document places in the kernel where a hardirq context enables hardirqs.
If we expect people to use this then we'd best whack a comment over it.
ok, i've improved the comment in
trace_irqflags.h.Quoted 2 lines
Also,
trace_irqflags.hdoesn't seem an appropriate place for it to live.
Quoted 9 lines
seems like the most practical place for it. Previously we had no central include file for irq-flags APIs (they used to be included from
asm/system.hand other random per-arch places) -trace_irqflags.hhas become the central file now. Should i rename it toirqflags.hperhaps, to not tie it to tracing? We have some deprecated irq-flags ops ininterrupt.h, maybe this all belongs there. (although i think it's cleaner to havelinux/include/irqflags.hand include it frominterrupt.h)
Yes, irqflags.h is nice.
Re: [patch 21/61] lock validator: lockdep: add local_irq_enable_in_hardirq() API.
Quoted 13 lines · Andrew Morton
Quoted 12 lines
Quoted 2 lines
Also,
trace_irqflags.hdoesn't seem an appropriate place for it to live.seems like the most practical place for it. Previously we had no central include file for irq-flags APIs (they used to be included from
asm/system.hand other random per-arch places) -trace_irqflags.hhas become the central file now. Should i rename it toirqflags.hperhaps, to not tie it to tracing? We have some deprecated irq-flags ops ininterrupt.h, maybe this all belongs there. (although i think it's cleaner to havelinux/include/irqflags.hand include it frominterrupt.h)
Quoted 1 line
Yes,
irqflags.his nice.
ok, done.
Ingo
PATCH 22/61 lock validator: add per_cpu_offset()
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
add the per_cpu_offset() generic method. (used by the lock validator)
--- include/asm-generic/percpu.h | 2 ++ include/asm-x86_64/percpu.h | 2 ++ 2 files changed, 4 insertions(+)
include/asm-generic/percpu.h +2 -0
@@ -7,6 +7,8 @@extern unsigned long __per_cpu_offset[NR_CPUS ]; +#define per_cpu_offset (x) (__per_cpu_offset[x]) +/* Separate out the type, so (int[3], foo) works. */ #define DEFINE_PER_CPU (type, name) \ __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
include/asm-x86_64/percpu.h +2 -0
@@ -14,6 +14,8 @@#define __per_cpu_offset (cpu) (cpu_pda(cpu)->data_offset)#define __my_cpu_offset () read_pda(data_offset) +#define per_cpu_offset (x) (__per_cpu_offset(x)) +/* Separate out the type, so (int[3], foo) works. */ #define DEFINE_PER_CPU (type, name) \ __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
Re: [patch 22/61] lock validator: add per_cpu_offset()
Quoted 29 lines · On Mon, 29 May 2006 23:24:57 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
add the
per_cpu_offset()generic method. (used by the lock validator)Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- include/asm-generic/percpu.h | 2 ++ include/asm-x86_64/percpu.h | 2 ++ 2 files changed, 4 insertions(+)Index:
linux/include/asm-generic/percpu.h
===================================================================include/asm-generic/percpu.h +2
-0@@ -7,6 +7,8 @@extern unsigned long __per_cpu_offset[NR_CPUS ]; +#define per_cpu_offset (x) (__per_cpu_offset[x]) +/* Separate out the type, so (int[3], foo) works. */ #define DEFINE_PER_CPU (type, name) \ __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##nameIndex:
linux/include/asm-x86_64/percpu.h
===================================================================
include/asm-x86_64/percpu.h line 21
Quoted 8 lines
include/asm-x86_64/percpu.h +2
-0@@ -14,6 +14,8 @@#define __per_cpu_offset (cpu) (cpu_pda(cpu)->data_offset)#define __my_cpu_offset () read_pda(data_offset) +#define per_cpu_offset (x) (__per_cpu_offset(x)) +/* Separate out the type, so (int[3], foo) works. */ #define DEFINE_PER_CPU (type, name) \ __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
I can tell just looking at it that it'll break various builds.I assume that things still happen to compile because you're presently using it in code which those architectures don't presently compile.
But introducing a "generic" function invites others to start using it. And they will, and they'll ship code which "works" but is broken, because they only tested it on x86 and x86_64.
I'll queue the needed fixups - please check it.
Re: [patch 22/61] lock validator: add per_cpu_offset()
Quoted 10 lines · Andrew Morton
include/asm-x86_64/percpu.h line 21
Quoted 5 lines
include/asm-x86_64/percpu.h +2
-0+#define per_cpu_offset (x) (__per_cpu_offset(x)) +/* Separate out the type, so (int[3], foo) works. */ #define DEFINE_PER_CPU (type, name) \ __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##nameI can tell just looking at it that it'll break various builds.I assume that things still happen to compile because you're presently using it in code which those architectures don't presently compile.
Quoted 5 lines
But introducing a "generic" function invites others to start using it. And they will, and they'll ship code which "works" but is broken, because they only tested it on x86 and
x86_64.I'll queue the needed fixups - please check it.
[belated reply] They look good.
Ingo
PATCH 23/61 lock validator: core
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
lock validator core changes. Not enabled yet.
--- include/linux/init_task.h | 1 include/linux/lockdep.h | 280 ++++ include/linux/sched.h | 12 include/linux/trace_irqflags.h | 13 init/main.c | 16 kernel/Makefile | 1 kernel/fork.c | 5 kernel/irq/manage.c | 6 kernel/lockdep.c | 2633 +++++++++++++++++++++++++++++++++++++++++ kernel/lockdep_internals.h | 93 + kernel/module.c | 3 lib/Kconfig.debug | 2 lib/locking-selftest.c | 4 13 files changed, 3064 insertions(+), 5 deletions(-)
include/linux/init_task.h +1 -0
@@ -134,6 +134,7 @@ extern struct group_info init_groups; .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ .fs_excl =ATOMIC_INIT (0 ), \INIT_TRACE_IRQFLAGS \ + INIT_LOCKDEP \ }
include/linux/lockdep.h new file +280 -0
280 lines not on this page · raw message
include/linux/sched.h +12 -0
@@ -931,6 +931,13 @@ struct task_struct {int hardirq_context;int softirq_context;#endif +#ifdef CONFIG_LOCKDEP +# define MAX_LOCK_DEPTH 30UL +u64 curr_chain_key; +int lockdep_depth; +struct held_lock held_locks[MAX_LOCK_DEPTH ]; +#endif +unsigned int lockdep_recursion;/* journalling filesystem info */ void *journal_info;
@@ -1350,6 +1357,11 @@ static inline void task_lock(struct taskspin_lock (&p->alloc_lock); } +static inline void task_lock_free (struct task_struct *p) +{ +spin_lock_nested (&p->alloc_lock,SINGLE_DEPTH_NESTING ); +} +static inline void task_unlock (struct task_struct *p) {spin_unlock (&p->alloc_lock);
include/linux/trace_irqflags.h +12 -1
@@ -66,7 +66,18 @@ } \ }while (0 ) -#define local_irq_enable_in_hardirq () local_irq_enable() +/* +* On lockdep we dont want to enable hardirqs in hardirq +* context. NOTE: in theory this might break fragile code +* that relies on hardirq delivery - in practice we dont +* seem to have such places left. So the only effect should +* be slightly increased irqs-off latencies. + */ +#ifdef CONFIG_LOCKDEP +# define local_irq_enable_in_hardirq () do { } while (0) +#else +# define local_irq_enable_in_hardirq () local_irq_enable() +#endif #define safe_halt () \ do { \
init/main.c +16 -0
@@ -54,6 +54,7 @@#include <linux/root_dev.h> #include <linux/buffer_head.h> #include <linux/debug_locks.h> +#include <linux/lockdep.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -80,6 +81,7 @@static int init (void *); +extern void early_init_irq_lock_type (void );extern void init_IRQ (void );extern void fork_init (unsigned long );extern void mca_init (void );
@@ -461,6 +463,17 @@ asmlinkage void __init start_kernel(void {char * command_line;extern struct kernel_param __start___param[], __stop___param[]; + +/* +* Need to run as early as possible, to initialize the +* lockdep hash: +*/ +lockdep_init (); + +local_irq_disable (); +early_boot_irqs_off (); +early_init_irq_lock_type (); +/* * Interrupts are still disabled. Do necessary setups, then * enable them
@@ -512,8 +525,11 @@ asmlinkage void __init start_kernel(voidif (panic_later)panic (panic_later, panic_param);profile_init (); +early_boot_irqs_on ();local_irq_enable (); +lockdep_info (); +/* * Need to run this when irqs are enabled, because it wants * to self-test [hard/soft]-irqs on/off lock inversion bugs
kernel/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-y = sched.o fork.o exec_domain.o obj-y += time/ obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o +obj-$(CONFIG_LOCKDEP) += lockdep.o obj-$(CONFIG_FUTEX) += futex.o ifeq ($(CONFIG_COMPAT),y) obj-$(CONFIG_FUTEX) += futex_compat.o
kernel/fork.c +5 -0
@@ -1049,6 +1049,11 @@ static task_t *copy_process(unsigned lon }mpol_fix_fork_child_flag (p);#endif +#ifdef CONFIG_LOCKDEP + p->lockdep_depth =0 ;/* no locks held yet */ + p->curr_chain_key =0 ; + p->lockdep_recursion =0 ; +#endif rt_mutex_init_task (p);
kernel/irq/manage.c +6 -0
@@ -406,6 +406,12 @@ int request_irq(unsigned int irq,immediately, so let's make sure.... We do this before actually registering it, to make sure that a 'real' IRQ doesn't run in parallel with our fake. */ +#ifdef CONFIG_LOCKDEP +/* +* Lockdep wants atomic interrupt handlers: +*/ + irqflags |=SA_INTERRUPT ; +#endif if (irqflags &SA_INTERRUPT ) {unsigned long flags;
kernel/lockdep.c new file +2633 -0
2,598 lines not on this page · raw message
kernel/lockdep_internals.h new file +93 -0
93 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
PATCH 24/61 lock validator: procfs
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
lock validator /proc/lockdep and /proc/lockdep_stats support. (FIXME: should go into debugfs)
--- kernel/Makefile | 3 kernel/lockdep_proc.c | 345 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+)
kernel/Makefile +3 -0
@@ -13,6 +13,9 @@ obj-y = sched.o fork.o exec_domain.o obj-y += time/ obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o obj-$(CONFIG_LOCKDEP) += lockdep.o +ifeq ($(CONFIG_PROC_FS),y) +obj-$(CONFIG_LOCKDEP) += lockdep_proc.o +endif obj-$(CONFIG_FUTEX) += futex.o ifeq ($(CONFIG_COMPAT),y) obj-$(CONFIG_FUTEX) += futex_compat.o
kernel/lockdep_proc.c new file +345 -0
345 lines not on this page · raw message
PATCH 25/61 lock validator: design docs
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
lock validator design documentation.
--- Documentation/lockdep-design.txt | 224 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+)
Documentation/lockdep-design.txt new file +224 -0
@@ -0,0 +1,224 @@ +Runtime locking correctness validator +===================================== + +started by Ingo Molnar <[email protected]> +additions by Arjan van de Ven <[email protected]> + +Lock-type +--------- + +The basic object the validator operates upon is the 'type' or 'class' of +locks. + +A class of locks is a group of locks that are logically the same with +respect to locking rules, even if the locks may have multiple (possibly +tens of thousands of) instantiations. For example a lock in the inode +struct is one class, while each inode has its own instantiation of that +lock class. + +The validator tracks the 'state' of lock-types, and it tracks +dependencies between different lock-types. The validator maintains a +rolling proof that the state and the dependencies are correct. + +Unlike an lock instantiation, the lock-type itself never goes away: when +a lock-type is used for the first time after bootup it gets registered, +and all subsequent uses of that lock-type will be attached to this +lock-type. + +State +----- + +The validator tracks lock-type usage history into 5 separate state bits: + +- 'ever held in hardirq context' [ == hardirq-safe ] +- 'ever held in softirq context' [ == softirq-safe ] +- 'ever held with hardirqs enabled' [ == hardirq-unsafe ] +- 'ever held with softirqs and hardirqs enabled' [ == softirq-unsafe ] + +- 'ever used' [ == !unused ] + +Single-lock state rules: +------------------------ + +A softirq-unsafe lock-type is automatically hardirq-unsafe as well. The +following states are exclusive, and only one of them is allowed to be +set for any lock-type: + + <hardirq-safe> and <hardirq-unsafe> + <softirq-safe> and <softirq-unsafe> + +The validator detects and reports lock usage that violate these +single-lock state rules. + +Multi-lock dependency rules: +---------------------------- + +The same lock-type must not be acquired twice, because this could lead +to lock recursion deadlocks. + +Furthermore, two locks may not be taken in different order: + + <L1> -> <L2> + <L2> -> <L1> + +because this could lead to lock inversion deadlocks. (The validator +finds such dependencies in arbitrary complexity, i.e. there can be any +other locking sequence between the acquire-lock operations, the +validator will still track all dependencies between locks.) + +Furthermore, the following usage based lock dependencies are not allowed +between any two lock-types: + + <hardirq-safe> -> <hardirq-unsafe> + <softirq-safe> -> <softirq-unsafe> + +The first rule comes from the fact the a hardirq-safe lock could be +taken by a hardirq context, interrupting a hardirq-unsafe lock - and +thus could result in a lock inversion deadlock. Likewise, a softirq-safe +lock could be taken by an softirq context, interrupting a softirq-unsafe +lock. + +The above rules are enforced for any locking sequence that occurs in the +kernel: when acquiring a new lock, the validator checks whether there is +any rule violation between the new lock and any of the held locks. + +When a lock-type changes its state, the following aspects of the above +dependency rules are enforced: + +- if a new hardirq-safe lock is discovered, we check whether it + took any hardirq-unsafe lock in the past. + +- if a new softirq-safe lock is discovered, we check whether it took + any softirq-unsafe lock in the past. + +- if a new hardirq-unsafe lock is discovered, we check whether any + hardirq-safe lock took it in the past. + +- if a new softirq-unsafe lock is discovered, we check whether any + softirq-safe lock took it in the past. + +(Again, we do these checks too on the basis that an interrupt context +could interrupt _any_ of the irq-unsafe or hardirq-unsafe locks, which +could lead to a lock inversion deadlock - even if that lock scenario did +not trigger in practice yet.) + +Exception 1: Nested data types leading to nested locking +-------------------------------------------------------- + +There are a few cases where the Linux kernel acquires more than one +instance of the same lock-type. Such cases typically happen when there +is some sort of hierarchy within objects of the same type. In these +cases there is an inherent "natural" ordering between the two objects +(defined by the properties of the hierarchy), and the kernel grabs the +locks in this fixed order on each of the objects. + +An example of such an object hieararchy that results in "nested locking" +is that of a "whole disk" block-dev object and a "partition" block-dev +object; the partition is "part of" the whole device and as long as one +always takes the whole disk lock as a higher lock than the partition +lock, the lock ordering is fully correct. The validator does not +automatically detect this natural ordering, as the locking rule behind +the ordering is not static. + +In order to teach the validator about this correct usage model, new +versions of the various locking primitives were added that allow you to +specify a "nesting level". An example call, for the block device mutex, +looks like this: + +enum bdev_bd_mutex_lock_type +{ + BD_MUTEX_NORMAL, + BD_MUTEX_WHOLE, + BD_MUTEX_PARTITION +}; + + mutex_lock_nested(&bdev->bd_contains->bd_mutex, BD_MUTEX_PARTITION); + +In this case the locking is done on a bdev object that is known to be a +partition. + +The validator treats a lock that is taken in such a nested fasion as a +separate (sub)class for the purposes of validation. + +Note: When changing code to use the _nested() primitives, be careful and +check really thoroughly that the hiearchy is correctly mapped; otherwise +you can get false positives or false negatives. + +Exception 2: Out of order unlocking +----------------------------------- + +In the Linux kernel, locks are released in the opposite order in which +they were taken, with a few exceptions. The validator is optimized for +the common case, and in fact treats an "out of order" unlock as a +locking bug. (the rationale is that the code is doing something rare, +which can be a sign of a bug) + +There are some cases where releasing the locks out of order is +unavoidable and dictated by the algorithm that is being implemented. +Therefore, the validator can be told about this, using a special +unlocking variant of the primitives. An example call looks like this: + + spin_unlock_non_nested(&target->d_lock); + +Here the d_lock is released by the VFS in a different order than it was +taken, as required by the d_move() algorithm. + +Note: the _non_nested() primitives are more expensive than the "normal" +primitives, and in almost all cases it's trivial to use the natural +unlock order. There are gains in doing this that are outside the realm +of the validator regardless so it's strongly suggested to make sure that +unlocking always happens in the natural order whenever reasonable, +rather than blindly changing code to use the _non_nested() variants. + +Proof of 100% correctness: +-------------------------- + +The validator achieves perfect, mathematical 'closure' (proof of locking +correctness) in the sense that for every simple, standalone single-task +locking sequence that occured at least once during the lifetime of the +kernel, the validator proves it with a 100% certainty that no +combination and timing of these locking sequences can cause any type of +lock related deadlock. [*] + +I.e. complex multi-CPU and multi-task locking scenarios do not have to +occur in practice to prove a deadlock: only the simple 'component' +locking chains have to occur at least once (anytime, in any +task/context) for the validator to be able to prove correctness. (For +example, complex deadlocks that would normally need more than 3 CPUs and +a very unlikely constellation of tasks, irq-contexts and timings to +occur, can be detected on a plain, lightly loaded single-CPU system as +well!) + +This radically decreases the complexity of locking related QA of the +kernel: what has to be done during QA is to trigger as many "simple" +single-task locking dependencies in the kernel as possible, at least +once, to prove locking correctness - instead of having to trigger every +possible combination of locking interaction between CPUs, combined with +every possible hardirq and softirq nesting scenario (which is impossible +to do in practice). + +[*] assuming that the validator itself is 100% correct, and no other + part of the system corrupts the state of the validator in any way. + We also assume that all NMI/SMM paths [which could interrupt + even hardirq-disabled codepaths] are correct and do not interfere + with the validator. We also assume that the 64-bit 'chain hash' + value is unique for every lock-chain in the system. Also, lock + recursion must not be higher than 20. + +Performance: +------------ + +The above rules require _massive_ amounts of runtime checking. If we did +that for every lock taken and for every irqs-enable event, it would +render the system practically unusably slow. The complexity of checking +is O(N^2), so even with just a few hundred lock-types we'd have to do +tens of thousands of checks for every event. + +This problem is solved by checking any given 'locking scenario' (unique +sequence of locks taken after each other) only once. A simple stack of +held locks is maintained, and a lightweight 64-bit hash value is +calculated, which hash is unique for every lock chain. The hash value, +when the chain is validated for the first time, is then put into a hash +table, which hash-table can be checked in a lockfree manner. If the +locking chain occurs again later on, the hash table tells us that we +dont have to validate the chain again.
Re: [patch 25/61] lock validator: design docs
Quoted 1 line · Ingo Molnar
From: Ingo Molnar <[email protected]>
[...]
Documentation/lockdep-design.txt line 133
Quoted 7 lines
Documentation/lockdep-design.txt new file +7
-0+ +enum bdev_bd_mutex_lock_type +{ + BD_MUTEX_NORMAL, + BD_MUTEX_WHOLE, + BD_MUTEX_PARTITION +};
In some situations well-defined and finite set of "nesting levels" does not exist. For example, if one has a tree with per-node locking, and algorithms acquire multiple node locks left-to-right in the tree order. Reiser4 does this.
Can nested locking restrictions be weakened for certain lock types?
Nikita.
PATCH 26/61 lock validator: prove rwsem locking correctness
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
add CONFIG_PROVE_RWSEM_LOCKING, which uses the lock validator framework to prove rwsem locking correctness.
--- include/asm-i386/rwsem.h | 38 +++++++++++++++++++-------- include/linux/rwsem-spinlock.h | 23 +++++++++++++++- include/linux/rwsem.h | 56 +++++++++++++++++++++++++++++++++++++++++ lib/rwsem-spinlock.c | 15 ++++++++-- lib/rwsem.c | 19 +++++++++++++ 5 files changed, 135 insertions(+), 16 deletions(-)
include/asm-i386/rwsem.h +27 -11
@@ -40,6 +40,7 @@#include <linux/list.h> #include <linux/spinlock.h> +#include <linux/lockdep.h> struct rwsem_waiter ;
@@ -64,6 +65,9 @@ struct rw_semaphore {#if RWSEM_DEBUG int debug;#endif +#ifdef CONFIG_PROVE_RWSEM_LOCKING +struct lockdep_map dep_map; +#endif };/*
@@ -75,22 +79,29 @@ struct rw_semaphore {#define __RWSEM_DEBUG_INIT/* */ #endif +#ifdef CONFIG_PROVE_RWSEM_LOCKING +# define __RWSEM_DEP_MAP_INIT (lockname) , .dep_map = { .name = #lockname } +#else +# define __RWSEM_DEP_MAP_INIT (lockname) +#endif + +#define __RWSEM_INITIALIZER (name) \ { RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) \ - __RWSEM_DEBUG_INIT } + __RWSEM_DEBUG_INIT __RWSEM_DEP_MAP_INIT(name) }#define DECLARE_RWSEM (name) \ struct rw_semaphore name = __RWSEM_INITIALIZER(name) -static inline void init_rwsem (struct rw_semaphore *sem) -{ - sem->count =RWSEM_UNLOCKED_VALUE ; -spin_lock_init (&sem->wait_lock); -INIT_LIST_HEAD (&sem->wait_list); -#if RWSEM_DEBUG - sem->debug =0 ; -#endif -} +extern void __init_rwsem (struct rw_semaphore *sem,const char *name, +struct lockdep_type_key *key); + +#define init_rwsem (sem) \ +do { \ + static struct lockdep_type_key __key; \ + \ + __init_rwsem((sem), #sem, &__key); \ +} while (0)/* * lock for reading
@@ -143,7 +154,7 @@ LOCK_PREFIX " cmpxchgl %2,%0\n\t"/* * lock for writing */ -static inline void __down_write (struct rw_semaphore *sem) +static inline void __down_write_nested (struct rw_semaphore *sem,int subtype) {int tmp;
@@ -167,6 +178,11 @@ LOCK_PREFIX " xadd %%edx,(%%eax)\n : "memory", "cc"); } +static inline void __down_write (struct rw_semaphore *sem) +{ +__down_write_nested (sem,0 ); +} +/* * trylock for writing -- returns 1 if successful, 0 if contention */
include/linux/rwsem-spinlock.h +21 -2
@@ -35,6 +35,9 @@ struct rw_semaphore {#if RWSEM_DEBUG int debug;#endif +#ifdef CONFIG_PROVE_RWSEM_LOCKING +struct lockdep_map dep_map; +#endif };/*
@@ -46,16 +49,32 @@ struct rw_semaphore {#define __RWSEM_DEBUG_INIT/* */ #endif +#ifdef CONFIG_PROVE_RWSEM_LOCKING +# define __RWSEM_DEP_MAP_INIT (lockname) , .dep_map = { .name = #lockname } +#else +# define __RWSEM_DEP_MAP_INIT (lockname) +#endif +#define __RWSEM_INITIALIZER (name) \ -{ 0, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) __RWSEM_DEBUG_INIT } +{ 0, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) __RWSEM_DEBUG_INIT __RWSEM_DEP_MAP_INIT(name) }#define DECLARE_RWSEM (name) \ struct rw_semaphore name = __RWSEM_INITIALIZER(name) -extern void FASTCALL (init_rwsem (struct rw_semaphore *sem)); +extern void __init_rwsem (struct rw_semaphore *sem,const char *name, +struct lockdep_type_key *key); + +#define init_rwsem (sem) \ +do { \ + static struct lockdep_type_key __key; \ + \ + __init_rwsem((sem), #sem, &__key); \ +} while (0) +extern void FASTCALL (__down_read (struct rw_semaphore *sem));extern int FASTCALL (__down_read_trylock (struct rw_semaphore *sem));extern void FASTCALL (__down_write (struct rw_semaphore *sem)); +extern void FASTCALL (__down_write_nested (struct rw_semaphore *sem,int subtype));extern int FASTCALL (__down_write_trylock (struct rw_semaphore *sem));extern void FASTCALL (__up_read (struct rw_semaphore *sem));extern void FASTCALL (__up_write (struct rw_semaphore *sem));
include/linux/rwsem.h +56 -0
108 lines not on this page · raw message
lib/rwsem-spinlock.c +12 -3
@@ -30,7 +30,8 @@ void rwsemtrace(struct rw_semaphore *sem/* * initialise the semaphore */ -void fastcall init_rwsem(struct rw_semaphore *sem) +void __init_rwsem (struct rw_semaphore *sem,const char *name, +struct lockdep_type_key *key) { sem->activity =0 ;spin_lock_init (&sem->wait_lock);
@@ -38,6 +39,9 @@ void fastcall init_rwsem(struct rw_semap#if RWSEM_DEBUG sem->debug =0 ;#endif +#ifdef CONFIG_PROVE_RWSEM_LOCKING +lockdep_init_map (&sem->dep_map, name, key); +#endif }/*
@@ -204,7 +208,7 @@ int fastcall __down_read_trylock(struct* get a write lock on the semaphore * - we increment the waiting count anyway to indicate an exclusive lock */ -void fastcall __sched __down_write(struct rw_semaphore *sem) +void fastcall __sched __down_write_nested(struct rw_semaphore *sem, int subtype) {struct rwsem_waiter waiter;struct task_struct *tsk;
@@ -247,6 +251,11 @@ void fastcall __sched __down_write(strucrwsemtrace (sem,"Leaving __down_write" ); } +void fastcall __sched __down_write(struct rw_semaphore *sem) +{ +__down_write_nested (sem,0 ); +} +/* * trylock for writing -- returns 1 if successful, 0 if contention */
@@ -331,7 +340,7 @@ void fastcall __downgrade_write(struct rrwsemtrace (sem,"Leaving __downgrade_write" ); } -EXPORT_SYMBOL (init_rwsem); +EXPORT_SYMBOL (__init_rwsem);EXPORT_SYMBOL (__down_read);EXPORT_SYMBOL (__down_read_trylock);EXPORT_SYMBOL (__down_write);
lib/rwsem.c +19 -0
@@ -8,6 +8,25 @@#include <linux/init.h> #include <linux/module.h> +/* +* Initialize an rwsem: +*/ +void __init_rwsem (struct rw_semaphore *sem,const char *name, +struct lockdep_type_key *key) +{ + sem->count =RWSEM_UNLOCKED_VALUE ; +spin_lock_init (&sem->wait_lock); +INIT_LIST_HEAD (&sem->wait_list); +#if RWSEM_DEBUG + sem->debug =0 ; +#endif +#ifdef CONFIG_PROVE_RWSEM_LOCKING +lockdep_init_map (&sem->dep_map, name, key); +#endif +} + +EXPORT_SYMBOL (__init_rwsem); +struct rwsem_waiter {struct list_head list;struct task_struct *task;
PATCH 27/61 lock validator: prove spinlock/rwlock locking correctness
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
add CONFIG_PROVE_SPIN_LOCKING and CONFIG_PROVE_RW_LOCKING, which uses the lock validator framework to prove spinlock and rwlock locking correctness.
--- include/asm-i386/spinlock.h | 2 include/linux/spinlock.h | 96 ++++++++++++++++++++++----- include/linux/spinlock_api_smp.h | 4 + include/linux/spinlock_api_up.h | 3 include/linux/spinlock_types.h | 32 ++++++++- include/linux/spinlock_types_up.h | 10 ++ include/linux/spinlock_up.h | 4 - kernel/Makefile | 2 kernel/sched.c | 10 ++ kernel/spinlock.c | 131 +++++++++++++++++++++++++++++++++++--- lib/kernel_lock.c | 7 +- net/ipv4/route.c | 4 - 12 files changed, 269 insertions(+), 36 deletions(-)
include/asm-i386/spinlock.h +2 -0
@@ -68,6 +68,7 @@ static inline void __raw_spin_lock(raw_s "=m" (lock->slock) : : "memory"); } +#ifndef CONFIG_PROVE_SPIN_LOCKING static inline void __raw_spin_lock_flags (raw_spinlock_t *lock,unsigned long flags) { alternative_smp(
@@ -75,6 +76,7 @@ static inline void __raw_spin_lock_flags __raw_spin_lock_string_up, "=m" (lock->slock) : "r" (flags) : "memory"); } +#endif static inline int __raw_spin_trylock(raw_spinlock_t *lock) {
include/linux/spinlock.h +77 -19
153 lines not on this page · raw message
include/linux/spinlock_api_smp.h +4 -0
@@ -20,6 +20,8 @@ int in_lock_functions(unsigned long addr#define assert_spin_locked (x) BUG_ON(!spin_is_locked(x)) void __lockfunc _spin_lock(spinlock_t *lock) __acquires(spinlock_t); +void __lockfunc _spin_lock_nested(spinlock_t *lock, int subtype) + __acquires(spinlock_t); void __lockfunc _read_lock(rwlock_t *lock) __acquires(rwlock_t); void __lockfunc _write_lock(rwlock_t *lock) __acquires(rwlock_t); void __lockfunc _spin_lock_bh(spinlock_t *lock) __acquires(spinlock_t);
@@ -39,7 +41,9 @@ int __lockfunc _read_trylock(rwlock_t *l int __lockfunc _write_trylock(rwlock_t *lock); int __lockfunc _spin_trylock_bh(spinlock_t *lock); void __lockfunc _spin_unlock(spinlock_t *lock) __releases(spinlock_t); +void __lockfunc _spin_unlock_non_nested(spinlock_t *lock) __releases(spinlock_t); void __lockfunc _read_unlock(rwlock_t *lock) __releases(rwlock_t); +void __lockfunc _read_unlock_non_nested(rwlock_t *lock) __releases(rwlock_t); void __lockfunc _write_unlock(rwlock_t *lock) __releases(rwlock_t); void __lockfunc _spin_unlock_bh(spinlock_t *lock) __releases(spinlock_t); void __lockfunc _read_unlock_bh(rwlock_t *lock) __releases(rwlock_t);
include/linux/spinlock_api_up.h +3 -0
@@ -49,6 +49,7 @@ do { local_irq_restore(flags); __UNLOCK(lock); } while (0)#define _spin_lock (lock) __LOCK(lock) +#define _spin_lock_nested (lock, subtype) __LOCK(lock)#define _read_lock (lock) __LOCK(lock)#define _write_lock (lock) __LOCK(lock)#define _spin_lock_bh (lock) __LOCK_BH(lock)
@@ -65,7 +66,9 @@#define _write_trylock (lock) ({ __LOCK(lock); 1; })#define _spin_trylock_bh (lock) ({ __LOCK_BH(lock); 1; })#define _spin_unlock (lock) __UNLOCK(lock) +#define _spin_unlock_non_nested (lock) __UNLOCK(lock)#define _read_unlock (lock) __UNLOCK(lock) +#define _read_unlock_non_nested (lock) __UNLOCK(lock)#define _write_unlock (lock) __UNLOCK(lock)#define _spin_unlock_bh (lock) __UNLOCK_BH(lock)#define _write_unlock_bh (lock) __UNLOCK_BH(lock)
include/linux/spinlock_types.h +28 -4
@@ -9,6 +9,8 @@* Released under the General Public License (GPL). */ +#include <linux/lockdep.h> +#if defined(CONFIG_SMP )# include <asm/spinlock_types.h> #else
@@ -24,6 +26,9 @@ typedef struct {unsigned int magic, owner_cpu;void *owner;#endif +#ifdef CONFIG_PROVE_SPIN_LOCKING +struct lockdep_map dep_map; +#endif } spinlock_t;#define SPINLOCK_MAGIC 0xdead4ead
@@ -37,28 +42,47 @@ typedef struct {unsigned int magic, owner_cpu;void *owner;#endif +#ifdef CONFIG_PROVE_RW_LOCKING +struct lockdep_map dep_map; +#endif } rwlock_t;#define RWLOCK_MAGIC 0xdeaf1eed#define SPINLOCK_OWNER_INIT ((void *)-1L) +#ifdef CONFIG_PROVE_SPIN_LOCKING +# define SPIN_DEP_MAP_INIT (lockname) .dep_map = { .name = #lockname } +#else +# define SPIN_DEP_MAP_INIT (lockname) +#endif + +#ifdef CONFIG_PROVE_RW_LOCKING +# define RW_DEP_MAP_INIT (lockname) .dep_map = { .name = #lockname } +#else +# define RW_DEP_MAP_INIT (lockname) +#endif +#ifdef CONFIG_DEBUG_SPINLOCK # define __SPIN_LOCK_UNLOCKED (lockname) \ (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED, \ .magic = SPINLOCK_MAGIC, \ .owner = SPINLOCK_OWNER_INIT, \ - .owner_cpu = -1 } + .owner_cpu = -1, \ + SPIN_DEP_MAP_INIT(lockname) }#define __RW_LOCK_UNLOCKED (lockname) \ (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED, \ .magic = RWLOCK_MAGIC, \ .owner = SPINLOCK_OWNER_INIT, \ - .owner_cpu = -1 } + .owner_cpu = -1, \ + RW_DEP_MAP_INIT(lockname) }#else # define __SPIN_LOCK_UNLOCKED (lockname) \ - (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED } + (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED, \ + SPIN_DEP_MAP_INIT(lockname) }#define __RW_LOCK_UNLOCKED (lockname) \ - (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED } + (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED, \ + RW_DEP_MAP_INIT(lockname) }#endif #define SPIN_LOCK_UNLOCKED __SPIN_LOCK_UNLOCKED(old_style_spin_init)
include/linux/spinlock_types_up.h +9 -1
@@ -12,10 +12,15 @@* Released under the General Public License (GPL). */ -#ifdef CONFIG_DEBUG_SPINLOCK +#if defined(CONFIG_DEBUG_SPINLOCK ) || \ + defined(CONFIG_PROVE_SPIN_LOCKING ) || \ + defined(CONFIG_PROVE_RW_LOCKING )typedef struct {volatile unsigned int slock; +#ifdef CONFIG_PROVE_SPIN_LOCKING +struct lockdep_map dep_map; +#endif }raw_spinlock_t ;#define __RAW_SPIN_LOCK_UNLOCKED { 1 }
@@ -30,6 +35,9 @@ typedef struct { } raw_spinlock_t;typedef struct {/* no debug version on UP */ +#ifdef CONFIG_PROVE_RW_LOCKING +struct lockdep_map dep_map; +#endif }raw_rwlock_t ;#define __RAW_RW_LOCK_UNLOCKED { }
include/linux/spinlock_up.h +3 -1
@@ -17,7 +17,9 @@* No atomicity anywhere, we are on UP. */ -#ifdef CONFIG_DEBUG_SPINLOCK +#if defined(CONFIG_DEBUG_SPINLOCK ) || \ + defined(CONFIG_PROVE_SPIN_LOCKING ) || \ + defined(CONFIG_PROVE_RW_LOCKING )#define __raw_spin_is_locked (x) ((x)->slock == 0)
kernel/Makefile +2 -0
@@ -26,6 +26,8 @@ obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o obj-$(CONFIG_SMP) += cpu.o spinlock.o obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o +obj-$(CONFIG_PROVE_SPIN_LOCKING) += spinlock.o +obj-$(CONFIG_PROVE_RW_LOCKING) += spinlock.o obj-$(CONFIG_UID16) += uid16.o obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_KALLSYMS) += kallsyms.o
kernel/sched.c +10 -0
@@ -312,6 +312,13 @@ static inline void finish_lock_switch(ru/* this is a valid case when another task releases the spinlock */ rq->lock.owner = current;#endif +/* +* If we are tracking spinlock dependencies then we have to +* fix up the runqueue lock - which gets 'carried over' from +* prev into current: +*/ +spin_acquire (&rq->lock.dep_map,0 ,0 , _THIS_IP_); +spin_unlock_irq (&rq->lock); }
@@ -1839,6 +1846,7 @@ task_t * context_switch(runqueue_t *rq,WARN_ON (rq->prev_mm); rq->prev_mm = oldmm; } +spin_release (&rq->lock.dep_map,1 , _THIS_IP_);/* Here we just switch the register state and the stack. */ switch_to (prev, next, prev);
@@ -4406,6 +4414,7 @@ asmlinkage long sys_sched_yield(void)* no need to preempt or enable interrupts: */ __release (rq->lock); +spin_release (&rq->lock.dep_map,1 , _THIS_IP_);_raw_spin_unlock (&rq->lock);preempt_enable_no_resched ();
@@ -4465,6 +4474,7 @@ int cond_resched_lock(spinlock_t *lock)spin_lock (lock); }if (need_resched ()) { +spin_release (&lock->dep_map,1 , _THIS_IP_);_raw_spin_unlock (lock);preempt_enable_no_resched ();__cond_resched ();
kernel/spinlock.c +122 -9
326 lines not on this page · raw message
lib/kernel_lock.c +6 -1
@@ -177,7 +177,12 @@ static inline void __lock_kernel(void)static inline void __unlock_kernel (void ) { -spin_unlock (&kernel_flag); +/* +* the BKL is not covered by lockdep, so we open-code the +* unlocking sequence (and thus avoid the dep-chain ops): +*/ +_raw_spin_unlock (&kernel_flag); +preempt_enable (); }/*
net/ipv4/route.c +3 -1
@@ -206,7 +206,9 @@ __u8 ip_tos2prio[16] = {struct rt_hash_bucket {struct rtable *chain; }; -#if defined(CONFIG_SMP ) || defined(CONFIG_DEBUG_SPINLOCK ) +#if defined(CONFIG_SMP ) || defined(CONFIG_DEBUG_SPINLOCK ) || \ + defined(CONFIG_PROVE_SPIN_LOCKING ) || \ + defined(CONFIG_PROVE_RW_LOCKING )/* * Instead of using one spinlock for each rt_hash_bucket, we use a table of spinlocks * The size of this table is a power of two and depends on the number of CPUS.
Re: [patch 27/61] lock validator: prove spinlock/rwlock locking correctness
include/linux/spinlock.h extern int __lockfunc generic__raw_read_ · line 115
Quoted 2 lines · On Mon, 29 May 2006 23:25:23 +0200 Ingo Molnar <[email protected]> wrote:
include/linux/spinlock.h +2
-0+# define spin_lock_init_key (lock, key) \ + __spin_lock_init((lock), #lock, key)
erk. This adds a whole new layer of obfuscation on top of the existing spinlock header files. You already need to run the preprocessor and disassembler to even work out which flavour you're presently using.
Ho hum.
Re: [patch 27/61] lock validator: prove spinlock/rwlock locking correctness
Quoted 11 lines · Andrew Morton
include/linux/spinlock.h extern int __lockfunc generic__raw_read_ · line 115
Quoted 2 lines · On Mon, 29 May 2006 23:25:23 +0200 Ingo Molnar <[email protected]> wrote:
include/linux/spinlock.h +2
-0+# define spin_lock_init_key (lock, key) \ + __spin_lock_init((lock), #lock, key)erk. This adds a whole new layer of obfuscation on top of the existing spinlock header files. You already need to run the preprocessor and disassembler to even work out which flavour you're presently using.
Quoted 1 line
Ho hum.
agreed. I think the API we started using in latest -mm (lockdep_init_key()) is the cleaner approach - that also makes it trivially sure that lockdep doesnt impact non-lockdep code. I'll fix the current lockdep_init_key() shortcomings and i'll get rid of the *_init_key() APIs.
Ingo
PATCH 28/61 lock validator: prove mutex locking correctness
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
add CONFIG_PROVE_MUTEX_LOCKING, which uses the lock validator framework to prove mutex locking correctness.
--- include/linux/mutex-debug.h | 8 +++++++- include/linux/mutex.h | 34 +++++++++++++++++++++++++++++++--- kernel/mutex-debug.c | 8 ++++++++ kernel/mutex-lockdep.h | 40 ++++++++++++++++++++++++++++++++++++++++ kernel/mutex.c | 28 ++++++++++++++++++++++------ kernel/mutex.h | 3 +-- 6 files changed, 109 insertions(+), 12 deletions(-)
include/linux/mutex-debug.h +7 -1
@@ -2,6 +2,7 @@#define __LINUX_MUTEX_DEBUG_H#include <linux/linkage.h> +#include <linux/lockdep.h> /* * Mutexes - debugging helpers:
@@ -10,7 +11,12 @@#define __DEBUG_MUTEX_INITIALIZER (lockname) \ , .magic = &lockname -#define mutex_init (sem) __mutex_init(sem, __FILE__":"#sem) +#define mutex_init (mutex) \ +do { \ + static struct lockdep_type_key __key; \ + \ + __mutex_init((mutex), #mutex, &__key); \ +} while (0)extern void FASTCALL (mutex_destroy (struct mutex *lock));
include/linux/mutex.h +31 -3
@@ -13,6 +13,7 @@#include <linux/list.h> #include <linux/spinlock_types.h> #include <linux/linkage.h> +#include <linux/lockdep.h> #include <asm/atomic.h>
@@ -53,6 +54,9 @@ struct mutex {const char *name;void *magic;#endif +#ifdef CONFIG_PROVE_MUTEX_LOCKING +struct lockdep_map dep_map; +#endif };/*
@@ -72,20 +76,36 @@ struct mutex_waiter {# include <linux/mutex-debug.h> #else # define __DEBUG_MUTEX_INITIALIZER (lockname) -# define mutex_init (mutex) __mutex_init(mutex, NULL) +# define mutex_init (mutex) \ +do { \ + static struct lockdep_type_key __key; \ + \ + __mutex_init((mutex), NULL, &__key); \ +} while (0)# define mutex_destroy (mutex) do { } while (0)#endif +#ifdef CONFIG_PROVE_MUTEX_LOCKING +# define __DEP_MAP_MUTEX_INITIALIZER (lockname) \ + , .dep_map = { .name = #lockname } +#else +# define __DEP_MAP_MUTEX_INITIALIZER (lockname) +#endif +#define __MUTEX_INITIALIZER (lockname) \ { .count = ATOMIC_INIT(1) \ , .wait_lock = SPIN_LOCK_UNLOCKED \ , .wait_list = LIST_HEAD_INIT(lockname.wait_list) \ - __DEBUG_MUTEX_INITIALIZER(lockname) } + __DEBUG_MUTEX_INITIALIZER(lockname) \ + __DEP_MAP_MUTEX_INITIALIZER(lockname) }#define DEFINE_MUTEX (mutexname) \ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) -extern void fastcall __mutex_init(struct mutex *lock, const char *name); +extern void __mutex_init (struct mutex *lock,const char *name, +struct lockdep_type_key *key); + +#define mutex_init_key (mutex, name, key) __mutex_init((mutex), name, key)/*** * mutex_is_locked - is the mutex locked
@@ -104,11 +124,19 @@ static inline int fastcall mutex_is_lock*/ extern void fastcall mutex_lock(struct mutex *lock); extern int fastcall mutex_lock_interruptible(struct mutex *lock); + +#ifdef CONFIG_PROVE_MUTEX_LOCKING +extern void mutex_lock_nested (struct mutex *lock,unsigned int subtype); +#else +# define mutex_lock_nested (lock, subtype) mutex_lock(lock) +#endif +/* * NOTE: mutex_trylock() follows the spin_trylock() convention, * not the down_trylock() convention! */ extern int fastcall mutex_trylock(struct mutex *lock); extern void fastcall mutex_unlock(struct mutex *lock); +extern void fastcall mutex_unlock_non_nested(struct mutex *lock);#endif
kernel/mutex-debug.c +8 -0
@@ -100,6 +100,14 @@ static int check_deadlock(struct mutex *return 0 ; task = ti->task; +/* +* In the PROVE_MUTEX_LOCKING we are tracking all held +* locks already, which allows us to optimize this: +*/ +#ifdef CONFIG_PROVE_MUTEX_LOCKING +if (!task->lockdep_depth) +return 0 ; +#endif lockblk =NULL ;if (task->blocked_on) lockblk = task->blocked_on->lock;
kernel/mutex-lockdep.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Mutexes: blocking mutual exclusion locks +* +* started by Ingo Molnar: +* +* Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <[email protected]> +* +* This file contains mutex debugging related internal prototypes, for the +* !CONFIG_DEBUG_MUTEXES && CONFIG_PROVE_MUTEX_LOCKING case. Most of +* them are NOPs: +*/ + +#define spin_lock_mutex (lock, flags) \ + do { \ + local_irq_save(flags); \ + __raw_spin_lock(&(lock)->raw_lock); \ + } while (0) + +#define spin_unlock_mutex (lock, flags) \ + do { \ + __raw_spin_unlock(&(lock)->raw_lock); \ + local_irq_restore(flags); \ + } while (0) + +#define mutex_remove_waiter (lock, waiter, ti) \ + __list_del((waiter)->list.prev, (waiter)->list.next) + +#define debug_mutex_set_owner (lock, new_owner) do { } while (0) +#define debug_mutex_clear_owner (lock) do { } while (0) +#define debug_mutex_wake_waiter (lock, waiter) do { } while (0) +#define debug_mutex_free_waiter (waiter) do { } while (0) +#define debug_mutex_add_waiter (lock, waiter, ti) do { } while (0) +#define debug_mutex_unlock (lock) do { } while (0) +#define debug_mutex_init (lock, name) do { } while (0) + +static inline void +debug_mutex_lock_common (struct mutex *lock, +struct mutex_waiter *waiter) +{ +}
kernel/mutex.c +22 -6
@@ -27,8 +27,13 @@# include "mutex-debug.h" # include <asm-generic/mutex-null.h> #else -# include "mutex.h" -# include <asm/mutex.h> +# ifdef CONFIG_PROVE_MUTEX_LOCKING +# include "mutex-lockdep.h" +# include <asm-generic/mutex-null.h> +# else +# include "mutex.h" +# include <asm/mutex.h> +# endif #endif /***
@@ -39,13 +44,18 @@* * It is not allowed to initialize an already locked mutex. */ -__always_inline void fastcall __mutex_init(struct mutex *lock, const char *name) +void +__mutex_init (struct mutex *lock,const char *name,struct lockdep_type_key *key) {atomic_set (&lock->count,1 );spin_lock_init (&lock->wait_lock);INIT_LIST_HEAD (&lock->wait_list);debug_mutex_init (lock, name); + +#ifdef CONFIG_PROVE_MUTEX_LOCKING +lockdep_init_map (&lock->dep_map, name, key); +#endif }EXPORT_SYMBOL (__mutex_init);
@@ -146,6 +156,7 @@ __mutex_lock_common(struct mutex *lock,spin_lock_mutex (&lock->wait_lock, flags);debug_mutex_lock_common (lock, &waiter); +mutex_acquire (&lock->dep_map, subtype,0 , _RET_IP_);debug_mutex_add_waiter (lock, &waiter, task->thread_info);/* add waiting tasks to the end of the waitqueue (FIFO): */
@@ -173,6 +184,7 @@ __mutex_lock_common(struct mutex *lock,if (unlikely (state ==TASK_INTERRUPTIBLE &&signal_pending (task))) {mutex_remove_waiter (lock, &waiter, task->thread_info); +mutex_release (&lock->dep_map,1 , _RET_IP_);spin_unlock_mutex (&lock->wait_lock, flags);debug_mutex_free_waiter (&waiter);
@@ -198,7 +210,9 @@ __mutex_lock_common(struct mutex *lock,debug_mutex_free_waiter (&waiter); +#ifdef CONFIG_DEBUG_MUTEXES DEBUG_WARN_ON (lock->owner != task->thread_info); +#endif return 0 ; }
@@ -211,7 +225,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou__mutex_lock_common (lock,TASK_UNINTERRUPTIBLE ,0 ); } -#ifdef CONFIG_DEBUG_MUTEXES +#ifdef CONFIG_PROVE_MUTEX_LOCKING void __schedmutex_lock_nested (struct mutex *lock,unsigned int subtype) {
@@ -232,6 +246,7 @@ __mutex_unlock_common_slowpath(atomic_tunsigned long flags;spin_lock_mutex (&lock->wait_lock, flags); +mutex_release (&lock->dep_map, nested, _RET_IP_);debug_mutex_unlock (lock);/*
@@ -322,9 +337,10 @@ static inline int __mutex_trylock_slowpaspin_lock_mutex (&lock->wait_lock, flags); prev =atomic_xchg (&lock->count,-1 ); -if (likely (prev ==1 )) +if (likely (prev ==1 )) {debug_mutex_set_owner (lock,current_thread_info ()); - +mutex_acquire (&lock->dep_map,0 ,1 , _RET_IP_); + }/* Set it back to 0 if there are no waiters: */ if (likely (list_empty (&lock->wait_list)))atomic_set (&lock->count,0 );
kernel/mutex.h +1 -2
@@ -16,14 +16,13 @@#define mutex_remove_waiter (lock, waiter, ti) \ __list_del((waiter)->list.prev, (waiter)->list.next) +#undef DEBUG_WARN_ON#define DEBUG_WARN_ON (c) do { } while (0)#define debug_mutex_set_owner (lock, new_owner) do { } while (0)#define debug_mutex_clear_owner (lock) do { } while (0)#define debug_mutex_wake_waiter (lock, waiter) do { } while (0)#define debug_mutex_free_waiter (waiter) do { } while (0)#define debug_mutex_add_waiter (lock, waiter, ti) do { } while (0) -#define mutex_acquire (lock, subtype, trylock) do { } while (0) -#define mutex_release (lock, nested) do { } while (0)#define debug_mutex_unlock (lock) do { } while (0)#define debug_mutex_init (lock, name) do { } while (0)
PATCH 29/61 lock validator: print all lock-types on SysRq-D
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
print all lock-types on SysRq-D.
--- drivers/char/sysrq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/sysrq.c +3 -1
@@ -148,12 +148,14 @@ static struct sysrq_key_op sysrq_mountro .enable_mask = SYSRQ_ENABLE_REMOUNT, }; -#ifdef CONFIG_DEBUG_MUTEXES +#ifdef CONFIG_LOCKDEP static void sysrq_handle_showlocks (int key,struct pt_regs *pt_regs,struct tty_struct *tty) {debug_show_all_locks (); +print_lock_types (); } +static struct sysrq_key_op sysrq_showlocks_op = { .handler = sysrq_handle_showlocks, .help_msg = "show-all-locks(D)",
PATCH 30/61 lock validator: x86_64 early init
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
x86_64 uses spinlocks very early - earlier than start_kernel(). So call lockdep_init() from the arch setup code.
--- arch/x86_64/kernel/head64.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86_64/kernel/head64.c +5 -0
@@ -85,6 +85,11 @@ void __init x86_64_start_kernel(char * rclear_bss ();/* +* This must be called really, really early: +*/ +lockdep_init (); + +/* * switch to init_level4_pgt from boot_level4_pgt */ memcpy (init_level4_pgt, boot_level4_pgt,PTRS_PER_PGD *sizeof (pgd_t));
PATCH 31/61 lock validator: SMP alternatives workaround
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
disable SMP alternatives fixups (the patching in of NOPs on 1-CPU systems) if the lock validator is enabled: there is a binutils section handling bug that causes corrupted instructions when UP instructions are patched in.
--- arch/i386/kernel/alternative.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/i386/kernel/alternative.c +10 -0
@@ -301,6 +301,16 @@ void alternatives_smp_switch(int smp)struct smp_alt_module *mod;unsigned long flags; +#ifdef CONFIG_LOCKDEP +/* +* A not yet fixed binutils section handling bug prevents +* alternatives-replacement from working reliably, so turn +* it off: +*/ +printk ("lockdep: not fixing up alternatives.\n" ); +return ; +#endif +if (no_replacement || smp_alt_once)return ;BUG_ON (!smp && (num_online_cpus () >1 ));
PATCH 32/61 lock validator: do not recurse in printk()
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
make printk()-ing from within the lock validation code safer by using the lockdep-recursion counter.
--- kernel/printk.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
kernel/printk.c +16 -4
@@ -516,7 +516,9 @@ asmlinkage int vprintk(const char *fmt,zap_locks ();/* This stops the holder of console_sem just where we want him */ -spin_lock_irqsave (&logbuf_lock, flags); +local_irq_save (flags); + current->lockdep_recursion++; +spin_lock (&logbuf_lock); printk_cpu =smp_processor_id ();/* Emit the output into the temporary buffer */
@@ -586,7 +588,7 @@ asmlinkage int vprintk(const char *fmt,*/ console_locked =1 ; printk_cpu =UINT_MAX ; -spin_unlock_irqrestore (&logbuf_lock, flags); +spin_unlock (&logbuf_lock);/* * Console drivers may assume that per-cpu resources have
@@ -602,6 +604,8 @@ asmlinkage int vprintk(const char *fmt, console_locked =0 ;up (&console_sem); } + current->lockdep_recursion--; +local_irq_restore (flags); }else {/* * Someone else owns the drivers. We drop the spinlock, which
@@ -609,7 +613,9 @@ asmlinkage int vprintk(const char *fmt,* console drivers with the output which we just produced. */ printk_cpu =UINT_MAX ; -spin_unlock_irqrestore (&logbuf_lock, flags); +spin_unlock (&logbuf_lock); + current->lockdep_recursion--; +local_irq_restore (flags); }preempt_enable ();
@@ -783,7 +789,13 @@ void release_console_sem(void)up (&console_sem);spin_unlock_irqrestore (&logbuf_lock, flags);if (wake_klogd && !oops_in_progress &&waitqueue_active (&log_wait)) -wake_up_interruptible (&log_wait); +/* +* If we printk from within the lock dependency code, +* from within the scheduler code, then do not lock +* up due to self-recursion: +*/ +if (current->lockdep_recursion <=1 ) +wake_up_interruptible (&log_wait); }EXPORT_SYMBOL (release_console_sem);
PATCH 33/61 lock validator: disable NMI watchdog if CONFIG_LOCKDEP
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
The NMI watchdog uses spinlocks (notifier chains, etc.), so it's not lockdep-safe at the moment.
--- arch/x86_64/kernel/nmi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/x86_64/kernel/nmi.c +12 -0
@@ -205,6 +205,18 @@ int __init check_nmi_watchdog (void)int *counts;int cpu; +#ifdef CONFIG_LOCKDEP +/* +* The NMI watchdog uses spinlocks (notifier chains, etc.), +* so it's not lockdep-safe: +*/ + nmi_watchdog =0 ; +for_each_online_cpu (cpu) +per_cpu (nmi_watchdog_ctlblk.enabled, cpu) =0 ; + +printk ("lockdep: disabled NMI watchdog.\n" ); +return 0 ; +#endif if ((nmi_watchdog ==NMI_NONE ) || (nmi_watchdog ==NMI_DEFAULT ))return 0 ;
Re: [patch 33/61] lock validator: disable NMI watchdog if CONFIG_LOCKDEP
Quoted 4 lines · Ingo Molnar (on Mon, 29 May 2006 23:25:50 +0200) wrote:
From: Ingo Molnar <[email protected]>
The NMI watchdog uses spinlocks (notifier chains, etc.), so it's not lockdep-safe at the moment.
Fixed in 2.6.17-rc1. notify_die() uses atomic_notifier_call_chain() which uses RCU, not spinlocks.
PATCH 34/61 lock validator: special locking: bdev
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- drivers/md/md.c | 6 +-- fs/block_dev.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++------- include/linux/fs.h | 17 ++++++++ 3 files changed, 112 insertions(+), 16 deletions(-)
drivers/md/md.c +3 -3
@@ -1394,7 +1394,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dstruct block_device *bdev;char b[BDEVNAME_SIZE ]; - bdev =open_by_devnum (dev,FMODE_READ |FMODE_WRITE ); + bdev =open_partition_by_devnum (dev,FMODE_READ |FMODE_WRITE );if (IS_ERR (bdev)) {printk (KERN_ERR "md: could not open %s.\n" ,__bdevname (dev, b));
@@ -1404,7 +1404,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dif (err) {printk (KERN_ERR "md: could not bd_claim %s.\n" ,bdevname (bdev, b)); -blkdev_put (bdev); +blkdev_put_partition (bdev);return err; } rdev->bdev = bdev;
@@ -1418,7 +1418,7 @@ static void unlock_rdev(mdk_rdev_t *rdevif (!bdev)MD_BUG ();bd_release (bdev); -blkdev_put (bdev); +blkdev_put_partition (bdev); }void md_autodetect_dev (dev_t dev);
fs/block_dev.c +92 -13
199 lines not on this page · raw message
include/linux/fs.h +17 -0
@@ -436,6 +436,21 @@ struct block_device { };/* +* bdev->bd_mutex nesting types for the LOCKDEP validator: +* +* 0: normal +* 1: 'whole' +* 2: 'partition' +*/ +enum bdev_bd_mutex_lock_type +{ +BD_MUTEX_NORMAL , +BD_MUTEX_WHOLE , +BD_MUTEX_PARTITION +}; + + +/* * Radix-tree tags, for tagging dirty and writeback pages within the pagecache * radix trees */
@@ -1404,6 +1419,7 @@ extern void bd_set_size(struct block_devextern void bd_forget (struct inode *inode);extern void bdput (struct block_device *);extern struct block_device *open_by_devnum (dev_t ,unsigned ); +extern struct block_device *open_partition_by_devnum (dev_t ,unsigned );extern const struct file_operations def_blk_fops;extern const struct address_space_operations def_blk_aops;extern const struct file_operations def_chr_fops;
@@ -1414,6 +1430,7 @@ extern int blkdev_ioctl(struct inode *,extern long compat_blkdev_ioctl (struct file *,unsigned ,unsigned long );extern int blkdev_get (struct block_device *,mode_t ,unsigned );extern int blkdev_put (struct block_device *); +extern int blkdev_put_partition (struct block_device *);extern int bd_claim (struct block_device *,void *);extern void bd_release (struct block_device *);#ifdef CONFIG_SYSFS
Re: [patch 34/61] lock validator: special locking: bdev
Quoted 5 lines · On Mon, 29 May 2006 23:25:54 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
There's no description here of the problem which is being worked around. This leaves everyone in the dark.
Quoted 8 lines
fs/block_dev.c +8
-0+static int +blkdev_get_whole (struct block_device *bdev,mode_t mode,unsigned flags) +{ +/* +* This crockload is due to bad choice of ->open() type. +* It will go away. +* For now, block device ->open() routine must _not_ +* examine anything in 'inode' argument except ->i_rdev.
fs/block_dev.c int blkdev_get(struct block_device *bdev · line 1043
Quoted 10 lines
fs/block_dev.c +10
-0+*/ +struct file fake_file = {}; +struct dentry fake_dentry = {}; + fake_file.f_mode = mode; + fake_file.f_flags = flags; + fake_file.f_dentry = &fake_dentry; + fake_dentry.d_inode = bdev->bd_inode; + +return do_open (bdev, &fake_file,BD_MUTEX_WHOLE ); +}
"crock" is a decent description ;)
How long will this live, and what will the fix look like?
(This is all a bit of a pain - carrying these patches in -mm will require some effort, and they're not ready to go yet, which will lengthen the pain arbitrarily).
Re: [patch 34/61] lock validator: special locking: bdev
Quoted 11 lines · Andrew Morton
Quoted 5 lines · On Mon, 29 May 2006 23:25:54 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
There's no description here of the problem which is being worked around. This leaves everyone in the dark.
it's not really a workaround, it's a "separate the uses" thing. The real problem is an inherent hierarchy between "disk" and "partition". Where lots of code assumes you can first take the disk mutex, and then the partition mutex, and never deadlock. This patch basically separates the "get me the disk" versus "get me the partition" uses.
Re: [patch 34/61] lock validator: special locking: bdev
In reply to Andrew MortonQuoted 15 lines · Andrew Morton
fs/block_dev.c int blkdev_get(struct block_device *bdev · line 1043
Quoted 12 lines
fs/block_dev.c +12
-0+* For now, block device ->open() routine must _not_ +* examine anything in 'inode' argument except ->i_rdev. +*/ +struct file fake_file = {}; +struct dentry fake_dentry = {}; + fake_file.f_mode = mode; + fake_file.f_flags = flags; + fake_file.f_dentry = &fake_dentry; + fake_dentry.d_inode = bdev->bd_inode; + +return do_open (bdev, &fake_file,BD_MUTEX_WHOLE ); +}"crock" is a decent description ;)
Quoted 1 line
How long will this live, and what will the fix look like?
The comment there is a bit deceptive.
The real problem is with the stuff ->open() uses. Short version of the story:
* everything uses inode->i_bdev. Since we always pass an inode
allocated in block_dev.c along with bdev and its ->i_bdev points to that bdev (i.e. at the constant offset from inode), it doesn't matter whether we pass struct inode or struct block_device.
* many things use file->f_mode. Nobody modifies it.
* some things use file->f_flags. Used flags: O_EXCL and O_NDELAY.
Nobody modifies it.
* one (and only one) weird driver uses something else. That FPOS
is floppy.c and it needs more detailed description.
floppy.c is _weird_. In addition to normally used stuff, it checks for opener having write permissions on file->f_dentry->d_inode. Then it modifies file->private_data to store that information and uses it as permission check in ->ioctl().
The rationale for that crock is a big load of bullshit. It goes like that:
We have priveleged ioctls and can't allow them unless you have
write permissions.
We can't ask to just open() the damn thing for write and let these
be done as usual (and check file->f_mode & FMODE_WRITE) because we might want them on drive that has no disk in it or a write-protected one. Opening it for write would try to check for disk being writable and screw itself.
Passing O_NDELAY would avoid that problem by skipping the checks
for disk being writable, present, etc., but we can't use that. Reasons why we can't? We don't need no stinkin' reasons!
IOW, *all* of that could be avoided if floppy.c
* checked FMODE_WRITE for ability to do priveleged ioctls
* had those who want to issue such ioctls on drive that might have
no disk in it pass O_NDELAY|O_WRONLY (or O_NDELAY|O_RDWR) when they open the fscker. Note that userland code always could have done that - passing O_NDELAY|O_RDWR will do the right thing with any kernel.
That FPOS is the main reason why we pass struct file * there at all *and* care to have ->f_dentry->d_inode in it (normally that wouldn't be even looked at). Again, my prefered solution would be to pass 4-bit flags and either inode or block_device. Flags being FMODE_READ, FMODE_WRITE, O_EXCL and O_NDELAY.
The problem is moronic semantics for ioctl access control in floppy.c, even though the sane API is _already_ present and always had been. In the very same floppy_open()...
Re: [patch 34/61] lock validator: special locking: bdev
In reply to Andrew MortonQuoted 33 lines · Andrew Morton
Quoted 5 lines · On Mon, 29 May 2006 23:25:54 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
There's no description here of the problem which is being worked around. This leaves everyone in the dark.
Quoted 8 lines
fs/block_dev.c +8
-0+static int +blkdev_get_whole (struct block_device *bdev,mode_t mode,unsigned flags) +{ +/* +* This crockload is due to bad choice of ->open() type. +* It will go away. +* For now, block device ->open() routine must _not_ +* examine anything in 'inode' argument except ->i_rdev. fs/block_dev.c int blkdev_get(struct block_device *bdev · line 1043
Quoted 10 lines
fs/block_dev.c +10
-0+*/ +struct file fake_file = {}; +struct dentry fake_dentry = {}; + fake_file.f_mode = mode; + fake_file.f_flags = flags; + fake_file.f_dentry = &fake_dentry; + fake_dentry.d_inode = bdev->bd_inode; + +return do_open (bdev, &fake_file,BD_MUTEX_WHOLE ); +}"crock" is a decent description ;)
Quoted 1 line
How long will this live, and what will the fix look like?
this btw is not new crock; the only new thing is the BD_MUTEX_WHOLE :)
PATCH 35/61 lock validator: special locking: direct-IO
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (rwsem-in-irq) locking code to the lock validator. Has no effect on non-lockdep kernels.
---
--- fs/direct-io.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/direct-io.c +4 -2
@@ -220,7 +220,8 @@ static void dio_complete(struct dio *dioif (dio->end_io && dio->result) dio->end_io (dio->iocb, offset, bytes, dio->map_bh.b_private);if (dio->lock_type ==DIO_LOCKING ) -up_read (&dio->inode->i_alloc_sem); +/* lockdep: non-owner release */ +up_read_non_owner (&dio->inode->i_alloc_sem); }/*
@@ -1261,7 +1262,8 @@ __blockdev_direct_IO(int rw, struct kioc }if (dio_lock_type ==DIO_LOCKING ) -down_read (&inode->i_alloc_sem); +/* lockdep: not the owner will release it */ +down_read_non_owner (&inode->i_alloc_sem); }/*
PATCH 36/61 lock validator: special locking: serial
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (dual-initialized) locking code to the lock validator. Has no effect on non-lockdep kernels.
---
--- drivers/serial/serial_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/serial/serial_core.c +8 -2
@@ -1849,6 +1849,12 @@ static const struct baud_rates baud_rate { 0, B38400 } }; +/* +* lockdep: port->lock is initialized in two places, but we +* want only one lock-type: +*/ +static struct lockdep_type_key port_lock_key; +/** * uart_set_options - setup the serial console parameters * @port: pointer to the serial ports uart_port structure
@@ -1869,7 +1875,7 @@ uart_set_options(struct uart_port *port,* Ensure that the serial console lock is initialised * early. */ -spin_lock_init (&port->lock); +spin_lock_init_key (&port->lock, &port_lock_key);memset (&termios,0 ,sizeof (struct termios ));
@@ -2255,7 +2261,7 @@ int uart_add_one_port(struct uart_driver* initialised. */ if (!(uart_console (port) && (port->cons->flags &CON_ENABLED ))) -spin_lock_init (&port->lock); +spin_lock_init_key (&port->lock, &port_lock_key);uart_configure_port (drv, state, port);
Re: [patch 36/61] lock validator: special locking: serial
Quoted 5 lines · On Mon, 29 May 2006 23:26:04 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (dual-initialized) locking code to the lock validator. Has no effect on non-lockdep kernels.
This isn't an adequate description of the problem which this patch is solving, IMO.
I _assume_ the validator is using the instruction pointer of the spin_lock_init() site (or the file-n-line) as the lock's identifier. Or something?
Quoted 28 lines
Index:
linux/drivers/serial/serial_core.c
===================================================================drivers/serial/serial_core.c +7
-1@@ -1849,6 +1849,12 @@ static const struct baud_rates baud_rate { 0, B38400 } }; +/* +* lockdep: port->lock is initialized in two places, but we +* want only one lock-type: +*/ +static struct lockdep_type_key port_lock_key; +/** * uart_set_options - setup the serial console parameters * @port: pointer to the serial ports uart_port structure @@ -1869,7 +1875,7 @@ uart_set_options(struct uart_port *port,* Ensure that the serial console lock is initialised * early. */ -spin_lock_init (&port->lock); +spin_lock_init_key (&port->lock, &port_lock_key);memset (&termios,0 ,sizeof (struct termios ));
drivers/serial/serial_core.c int uart_add_one_port(struct uart_driver · line 2267
Quoted 8 lines
drivers/serial/serial_core.c +1
-1@@ -2255,7 +2261,7 @@ int uart_add_one_port(struct uart_driver* initialised. */ if (!(uart_console (port) && (port->cons->flags &CON_ENABLED ))) -spin_lock_init (&port->lock); +spin_lock_init_key (&port->lock, &port_lock_key);uart_configure_port (drv, state, port);
Is there a cleaner way of doing this?
Perhaps write a new helper function which initialises the spinlock, call that? Rather than open-coding lockdep stuff?
Re: [patch 36/61] lock validator: special locking: serial
Quoted 25 lines · Andrew Morton
Quoted 25 lines
drivers/serial/serial_core.c +8
-2+/* +* lockdep: port->lock is initialized in two places, but we +* want only one lock-type: +*/ +static struct lockdep_type_key port_lock_key; +/** * uart_set_options - setup the serial console parameters * @port: pointer to the serial ports uart_port structure @@ -1869,7 +1875,7 @@ uart_set_options(struct uart_port *port,* Ensure that the serial console lock is initialised * early. */ -spin_lock_init (&port->lock); +spin_lock_init_key (&port->lock, &port_lock_key);memset (&termios,0 ,sizeof (struct termios ));@@ -2255,7 +2261,7 @@ int uart_add_one_port(struct uart_driver* initialised. */ if (!(uart_console (port) && (port->cons->flags &CON_ENABLED ))) -spin_lock_init (&port->lock); +spin_lock_init_key (&port->lock, &port_lock_key);
Quoted 7 lines
drivers/serial/serial_core.c int uart_add_one_port(struct uart_driver · line 2267
Quoted 2 lines
drivers/serial/serial_core.c +0
-0uart_configure_port (drv, state, port);Is there a cleaner way of doing this?
Perhaps write a new helper function which initialises the spinlock, call that? Rather than open-coding lockdep stuff?
yes, we can do that too - but that would have an effect to non-lockdep kernels too.
Also, the initialization of the 'port' seems a bit twisted here, already initialized and not-yet-initialized ports can be passed in to uard_add_one_port(). So i did not want to touch the structure of the code - hence the open-coded solution.
Ingo
Re: [patch 36/61] lock validator: special locking: serial
Quoted 36 lines · On Fri, 23 Jun 2006 11:49:41 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 25 lines · Andrew Morton
Quoted 25 lines
(quoted diff) +8
-2+/* + * lockdep: port->lock is initialized in two places, but we + * want only one lock-type: + */ +static struct lockdep_type_key port_lock_key; + /** * uart_set_options - setup the serial console parameters * @port: pointer to the serial ports uart_port structure@@ -1869,7 +1875,7 @@ uart_set_options(struct uart_port *port, * Ensure that the serial console lock is initialised * early. */ - spin_lock_init(&port->lock); + spin_lock_init_key(&port->lock, &port_lock_key); memset(&termios, 0, sizeof(struct termios));@@ -2255,7 +2261,7 @@ int uart_add_one_port(struct uart_driver * initialised. */ if (!(uart_console(port) && (port->cons->flags & CON_ENABLED))) - spin_lock_init(&port->lock); + spin_lock_init_key(&port->lock, &port_lock_key);Quoted 7 lines
Review int uart_add_one_port(struct uart_driver · line 2267
Quoted 2 lines
(quoted diff) +0
-0uart_configure_port(drv, state, port);Is there a cleaner way of doing this?
Perhaps write a new helper function which initialises the spinlock, call that? Rather than open-coding lockdep stuff?
Quoted 8 lines
yes, we can do that too - but that would have an effect to non-lockdep kernels too.
Also, the initialization of the 'port' seems a bit twisted here, already initialized and not-yet-initialized ports can be passed in to
uard_add_one_port(). So i did not want to touch the structure of the code - hence the open-coded solution.
btw, I was looking at this change:
drivers/scsi/libata-core.c renamed from drivers/scsi/libata-core.c~lock-validator-locking-init-debugging-improvement +1 -0
@@ -1003,6 +1003,7 @@ unsigned ata_exec_internal(struct ata_deunsigned int err_mask;int rc; +init_completion (&wait);spin_lock_irqsave (ap->lock, flags);/* no internal command while frozen */
That local was already initialised with DEFINE_WAIT(). Am surprised that an init_wait() also was needed?
Re: [patch 36/61] lock validator: special locking: serial
Quoted 11 lines · Andrew Morton
btw, I was looking at this change:
drivers/scsi/libata-core.c renamed from drivers/scsi/libata-core.c~lock-validator-locking-init-debugging-improvement +1
-0@@ -1003,6 +1003,7 @@ unsigned ata_exec_internal(struct ata_deunsigned int err_mask;int rc; +init_completion (&wait);spin_lock_irqsave (ap->lock, flags);/* no internal command while frozen */
Quoted 2 lines
That local was already initialised with
DEFINE_COMPLETION(). Am surprised that aninit_completion()also was needed?
That's a fundamental problem of DECLARE_COMPLETION() done on the kernel stack - it does build-time initialization with no opportunity to inject any runtime logic. (which lockdep would need. Maybe i missed some clever way to add a runtime callback into the initialization? [*])
Btw., there is no danger from missing the initialization of a wait
structure: lockdep will detect "uninitialized" on-stack locks and will complain about it and turn itself off. [this happened a few times during development - that's how those init_completion() calls got added]
But at a minimum these initializations need to become lockdep-specific key-reinits - otherwise there will be impact to non-lockdep kernels too.
Ingo
[*] the only solution i can see is to introduce DECLARE_COMPLETION_ONSTACK(), which could call a function with &wait passed in, where that function would return with a structure. The macro magic would resolve to something like:
struct completion wait = lockdep_init_completion(&wait);
and thus the structure would be initialized. But this method cannot be used for static scope uses of DECLARE_COMPLETION, because it's not a constant initializer. So we'd definitely have to make a distinction in terms of _ONSTACK(). Is there really no compiler feature that could help us out here?
PATCH 37/61 lock validator: special locking: dcache
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- fs/dcache.c | 6 +++--- include/linux/dcache.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-)
fs/dcache.c +3 -3
@@ -1380,10 +1380,10 @@ void d_move(struct dentry * dentry, stru*/ if (target < dentry) {spin_lock (&target->d_lock); -spin_lock (&dentry->d_lock); +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); }else {spin_lock (&dentry->d_lock); -spin_lock (&target->d_lock); +spin_lock_nested (&target->d_lock,DENTRY_D_LOCK_NESTED ); }/* Move the dentry to the target hash queue, if on different bucket */
@@ -1420,7 +1420,7 @@ already_unhashed: }list_add (&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); -spin_unlock (&target->d_lock); +spin_unlock_non_nested (&target->d_lock);fsnotify_d_move (dentry);spin_unlock (&dentry->d_lock);write_sequnlock (&rename_lock);
include/linux/dcache.h +12 -0
@@ -114,6 +114,18 @@ struct dentry {unsigned char d_iname[DNAME_INLINE_LEN_MIN ];/* small names */ }; +/* +* dentry->d_lock spinlock nesting types: +* +* 0: normal +* 1: nested +*/ +enum dentry_d_lock_type +{ +DENTRY_D_LOCK_NORMAL , +DENTRY_D_LOCK_NESTED +}; +struct dentry_operations {int (*d_revalidate)(struct dentry *,struct nameidata *);int (*d_hash) (struct dentry *,struct qstr *);
Re: [patch 37/61] lock validator: special locking: dcache
Quoted 51 lines · On Mon, 29 May 2006 23:26:08 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- fs/dcache.c | 6 +++--- include/linux/dcache.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-)Index:
linux/fs/dcache.c
===================================================================fs/dcache.c +3
-3@@ -1380,10 +1380,10 @@ void d_move(struct dentry * dentry, stru*/ if (target < dentry) {spin_lock (&target->d_lock); -spin_lock (&dentry->d_lock); +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); }else {spin_lock (&dentry->d_lock); -spin_lock (&target->d_lock); +spin_lock_nested (&target->d_lock,DENTRY_D_LOCK_NESTED ); }/* Move the dentry to the target hash queue, if on different bucket */ @@ -1420,7 +1420,7 @@ already_unhashed: }list_add (&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); -spin_unlock (&target->d_lock); +spin_unlock_non_nested (&target->d_lock);fsnotify_d_move (dentry);spin_unlock (&dentry->d_lock);write_sequnlock (&rename_lock);Index:
linux/include/linux/dcache.h
===================================================================include/linux/dcache.h +5
-0@@ -114,6 +114,18 @@ struct dentry {unsigned char d_iname[DNAME_INLINE_LEN_MIN ];/* small names */ }; +/* +* dentry->d_lock spinlock nesting types: +* +* 0: normal +* 1: nested
include/linux/dcache.h struct dentry { · line 131
Quoted 10 lines
include/linux/dcache.h +7
-0+*/ +enum dentry_d_lock_type +{ +DENTRY_D_LOCK_NORMAL , +DENTRY_D_LOCK_NESTED +}; +struct dentry_operations {int (*d_revalidate)(struct dentry *,struct nameidata *);int (*d_hash) (struct dentry *,struct qstr *);
DENTRY_D_LOCK_NORMAL isn't used anywhere.
Steven Rostedt
maintainerRe: [patch 37/61] lock validator: special locking: dcache
Quoted 17 lines · Andrew Morton
Quoted 16 lines
Index:
linux/fs/dcache.c
===================================================================fs/dcache.c +2
-2@@ -1380,10 +1380,10 @@ void d_move(struct dentry * dentry, stru*/ if (target < dentry) {spin_lock (&target->d_lock); -spin_lock (&dentry->d_lock); +spin_lock_nested (&dentry->d_lock,DENTRY_D_LOCK_NESTED ); }else {spin_lock (&dentry->d_lock); -spin_lock (&target->d_lock); +spin_lock_nested (&target->d_lock,DENTRY_D_LOCK_NESTED ); }
[...]
Quoted 9 lines
Quoted 9 lines
fs/dcache.c +9
-0+/* +* dentry->d_lock spinlock nesting types: +* +* 0: normal +* 1: nested +*/ +enum dentry_d_lock_type +{ +DENTRY_D_LOCK_NORMAL ,
Quoted 9 lines
fs/dcache.c
Quoted 6 lines
fs/dcache.c +3
-0+DENTRY_D_LOCK_NESTED +}; +struct dentry_operations {int (*d_revalidate)(struct dentry *,struct nameidata *);int (*d_hash) (struct dentry *,struct qstr *);
DENTRY_D_LOCK_NORMALisn't used anywhere.
I guess it is implied with the normal spin_lock. Since
spin_lock(&target->d_lock) and spin_lock_nested(&target->d_lock, DENTRY_D_LOCK_NORMAL)
are equivalent. (DENTRY_D_LOCK_NORMAL == 0)
Probably this deserves a comment.
-- Steve
Re: [patch 37/61] lock validator: special locking: dcache
Quoted 12 lines · Steven Rostedt
Quoted 11 lines
include/linux/dcache.h struct dentry { · line 131
Quoted 9 lines
include/linux/dcache.h +6
-0+enum dentry_d_lock_type +{ +DENTRY_D_LOCK_NORMAL , +DENTRY_D_LOCK_NESTED +}; +struct dentry_operations {int (*d_revalidate)(struct dentry *,struct nameidata *);int (*d_hash) (struct dentry *,struct qstr *);
DENTRY_D_LOCK_NORMALisn't used anywhere.
Quoted 4 lines
I guess it is implied with the normal
spin_lock. Since
spin_lock(&target->d_lock)andspin_lock_nested(&target->d_lock, DENTRY_D_LOCK_NORMAL)
are equivalent. (DENTRY_D_LOCK_NORMAL== 0)
correct. This is the case for all the subtype enum definitions: 0 means normal spinlock [rwlock, rwsem, mutex] API use.
Ingo
Re: [patch 37/61] lock validator: special locking: dcache
In reply to Steven RostedtQuoted 10 lines · Steven Rostedt
Quoted 1 line · Andrew Morton
DENTRY_D_LOCK_NORMALisn't used anywhere.I guess it is implied with the normal
spin_lock. Since
spin_lock(&target->d_lock)andspin_lock_nested(&target->d_lock, DENTRY_D_LOCK_NORMAL)
are equivalent. (DENTRY_D_LOCK_NORMAL== 0)Probably this deserves a comment.
i have added a comment to dcache.h explaining this better.
Ingo
PATCH 38/61 lock validator: special locking: i_mutex
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- drivers/usb/core/inode.c | 2 +- fs/namei.c | 24 ++++++++++++------------ include/linux/fs.h | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-)
drivers/usb/core/inode.c +1 -1
@@ -201,7 +201,7 @@ static void update_sb(struct super_blockif (!root)return ; -mutex_lock (&root->d_inode->i_mutex); +mutex_lock_nested (&root->d_inode->i_mutex,I_MUTEX_PARENT );list_for_each_entry (bus, &root->d_subdirs, d_u.d_child) {if (bus->d_inode) {
fs/namei.c +12 -12
@@ -1422,7 +1422,7 @@ struct dentry *lock_rename(struct dentrystruct dentry *p;if (p1 == p2) { -mutex_lock (&p1->d_inode->i_mutex); +mutex_lock_nested (&p1->d_inode->i_mutex,I_MUTEX_PARENT );return NULL ; }
@@ -1430,30 +1430,30 @@ struct dentry *lock_rename(struct dentryfor (p = p1; p->d_parent != p; p = p->d_parent) {if (p->d_parent == p2) { -mutex_lock (&p2->d_inode->i_mutex); -mutex_lock (&p1->d_inode->i_mutex); +mutex_lock_nested (&p2->d_inode->i_mutex,I_MUTEX_PARENT ); +mutex_lock_nested (&p1->d_inode->i_mutex,I_MUTEX_CHILD );return p; } }for (p = p2; p->d_parent != p; p = p->d_parent) {if (p->d_parent == p1) { -mutex_lock (&p1->d_inode->i_mutex); -mutex_lock (&p2->d_inode->i_mutex); +mutex_lock_nested (&p1->d_inode->i_mutex,I_MUTEX_PARENT ); +mutex_lock_nested (&p2->d_inode->i_mutex,I_MUTEX_CHILD );return p; } } -mutex_lock (&p1->d_inode->i_mutex); -mutex_lock (&p2->d_inode->i_mutex); +mutex_lock_nested (&p1->d_inode->i_mutex,I_MUTEX_PARENT ); +mutex_lock_nested (&p2->d_inode->i_mutex,I_MUTEX_CHILD );return NULL ; }void unlock_rename (struct dentry *p1,struct dentry *p2) { -mutex_unlock (&p1->d_inode->i_mutex); +mutex_unlock_non_nested (&p1->d_inode->i_mutex);if (p1 != p2) { -mutex_unlock (&p2->d_inode->i_mutex); +mutex_unlock_non_nested (&p2->d_inode->i_mutex);mutex_unlock (&p1->d_inode->i_sb->s_vfs_rename_mutex); } }
@@ -1750,7 +1750,7 @@ struct dentry *lookup_create(struct name {struct dentry *dentry =ERR_PTR (-EEXIST ); -mutex_lock (&nd->dentry->d_inode->i_mutex); +mutex_lock_nested (&nd->dentry->d_inode->i_mutex,I_MUTEX_PARENT );/* * Yucky last component or no last component at all? * (foo/., foo/.., /////)
@@ -2007,7 +2007,7 @@ static long do_rmdir(int dfd, const char error = -EBUSY ; goto exit1; } -mutex_lock (&nd.dentry->d_inode->i_mutex); +mutex_lock_nested (&nd.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); dentry =lookup_hash (&nd); error =PTR_ERR (dentry);if (!IS_ERR (dentry)) {
@@ -2081,7 +2081,7 @@ static long do_unlinkat(int dfd, const c error = -EISDIR ;if (nd.last_type !=LAST_NORM ) goto exit1; -mutex_lock (&nd.dentry->d_inode->i_mutex); +mutex_lock_nested (&nd.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); dentry =lookup_hash (&nd); error =PTR_ERR (dentry);if (!IS_ERR (dentry)) {
include/linux/fs.h +14 -0
@@ -558,6 +558,20 @@ struct inode { };/* +* inode->i_mutex nesting types for the LOCKDEP validator: +* +* 0: the object of the current VFS operation +* 1: parent +* 2: child/target +*/ +enum inode_i_mutex_lock_type +{ +I_MUTEX_NORMAL , +I_MUTEX_PARENT , +I_MUTEX_CHILD +}; + +/* * NOTE: in a 32bit arch with a preemptable kernel and * an UP compile the i_size_read/write must be atomic * with respect to the local cpu (unlike with preempt disabled),
Steven Rostedt
maintainerRe: [patch 38/61] lock validator: special locking: i_mutex
Quoted 6 lines · Ingo Molnar
+ *
inode->i_mutexnesting types for the LOCKDEP validator:
+ *
+ * 0: the object of the current VFS operation
+ * 1: parent
+ * 2: child/target
+ */
include/linux/fs.h struct inode { · line 574
Quoted 8 lines
include/linux/fs.h +8
-0+enum inode_i_mutex_lock_type +{ +I_MUTEX_NORMAL , +I_MUTEX_PARENT , +I_MUTEX_CHILD +}; + +/*
I guess we can say the same about I_MUTEX_NORMAL.
-- Steve
Re: [patch 38/61] lock validator: special locking: i_mutex
Quoted 17 lines · Steven Rostedt
Quoted 6 lines · Ingo Molnar
+ *
inode->i_mutexnesting types for the LOCKDEP validator:
+ *
+ * 0: the object of the current VFS operation
+ * 1: parent
+ * 2: child/target
+ */include/linux/fs.h struct inode { · line 574
Quoted 8 lines
include/linux/fs.h +8
-0+enum inode_i_mutex_lock_type +{ +I_MUTEX_NORMAL , +I_MUTEX_PARENT , +I_MUTEX_CHILD +}; + +/* I guess we can say the same about
I_MUTEX_NORMAL.
yeah. Subtypes start from 1, as 0 is the basic type.
Lock types are keyed via static kernel addresses. This means that we can use the lock address (for DEFINE_SPINLOCK) or the static key embedded in spin_lock_init() as a key in 99% of the cases. The key [struct lockdep_type_key, see include/linux/lockdep.h] occupies enough bytes (of kernel static virtual memory) so that the keys remain automatically unique. Right now MAX_LOKCDEP_SUBTYPES is 8, so the keys take at most 8 bytes. (To save some memory there's another detail: for static locks (DEFINE_SPINLOCK ones) we use the lock address itself as the key.)
Ingo
PATCH 39/61 lock validator: special locking: s_lock
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (per-filesystem) locking code to the lock validator. Has no effect on non-lockdep kernels.
---
--- fs/super.c | 13 +++++++++---- include/linux/fs.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-)
fs/super.c +9 -4
@@ -54,7 +54,7 @@ DEFINE_SPINLOCK(sb_lock);* Allocates and initializes a new &struct super_block. alloc_super() * returns a pointer new superblock or %NULL if allocation had failed. */ -static struct super_block *alloc_super (void ) +static struct super_block *alloc_super (struct file_system_type *type) {struct super_block *s =kzalloc (sizeof (struct super_block ),GFP_USER );static struct super_operations default_op;
@@ -72,7 +72,12 @@ static struct super_block *alloc_super(vINIT_HLIST_HEAD (&s->s_anon);INIT_LIST_HEAD (&s->s_inodes);init_rwsem (&s->s_umount); -mutex_init (&s->s_lock); +/* +* The locking rules for s_lock are up to the +* filesystem. For example ext3fs has different +* lock ordering than usbfs: +*/ +mutex_init_key (&s->s_lock, type->name, &type->s_lock_key);down_write (&s->s_umount); s->s_count =S_BIAS ;atomic_set (&s->s_active,1 );
@@ -297,7 +302,7 @@ retry: }if (!s) {spin_unlock (&sb_lock); - s =alloc_super (); + s =alloc_super (type);if (!s)return ERR_PTR (-ENOMEM ); goto retry;
@@ -696,7 +701,7 @@ struct super_block *get_sb_bdev(struct f*/ mutex_lock (&bdev->bd_mount_mutex); s =sget (fs_type, test_bdev_super, set_bdev_super, bdev); -mutex_unlock (&bdev->bd_mount_mutex); +mutex_unlock_non_nested (&bdev->bd_mount_mutex);if (IS_ERR (s)) goto out;
include/linux/fs.h +1 -0
@@ -1307,6 +1307,7 @@ struct file_system_type {struct module *owner;struct file_system_type * next;struct list_head fs_supers; +struct lockdep_type_key s_lock_key; }; struct super_block *get_sb_bdev(struct file_system_type *fs_type,
PATCH 40/61 lock validator: special locking: futex
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- kernel/futex.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-)
kernel/futex.c +26 -18
@@ -604,6 +604,22 @@ static int unlock_futex_pi(u32 __user *u }/* +* Express the locking dependencies for lockdep: +*/ +static inline void +double_lock_hb (struct futex_hash_bucket *hb1,struct futex_hash_bucket *hb2) +{ +if (hb1 <= hb2) { +spin_lock (&hb1->lock); +if (hb1 < hb2) +spin_lock_nested (&hb2->lock,SINGLE_DEPTH_NESTING ); + }else {/* hb1 > hb2 */ +spin_lock (&hb2->lock); +spin_lock_nested (&hb1->lock,SINGLE_DEPTH_NESTING ); + } +} + +/* * Wake up all waiters hashed on the physical page that is mapped * to this virtual address: */
@@ -669,19 +685,15 @@ retryfull: hb2 =hash_futex (&key2); retry: -if (hb1 < hb2) -spin_lock (&hb1->lock); -spin_lock (&hb2->lock); -if (hb1 > hb2) -spin_lock (&hb1->lock); +double_lock_hb (hb1, hb2); op_ret =futex_atomic_op_inuser (op, uaddr2);if (unlikely (op_ret <0 )) {u32 dummy; -spin_unlock (&hb1->lock); +spin_unlock_non_nested (&hb1->lock);if (hb1 != hb2) -spin_unlock (&hb2->lock); +spin_unlock_non_nested (&hb2->lock);#ifndef CONFIG_MMU /*
@@ -748,9 +760,9 @@ retry: ret += op_ret; } -spin_unlock (&hb1->lock); +spin_unlock_non_nested (&hb1->lock);if (hb1 != hb2) -spin_unlock (&hb2->lock); +spin_unlock_non_nested (&hb2->lock); out:up_read (¤t->mm->mmap_sem);return ret;
@@ -782,11 +794,7 @@ static int futex_requeue(u32 __user *uad hb1 =hash_futex (&key1); hb2 =hash_futex (&key2); -if (hb1 < hb2) -spin_lock (&hb1->lock); -spin_lock (&hb2->lock); -if (hb1 > hb2) -spin_lock (&hb1->lock); +double_lock_hb (hb1, hb2);if (likely (cmpval !=NULL )) {u32 curval;
@@ -794,9 +802,9 @@ static int futex_requeue(u32 __user *uad ret =get_futex_value_locked (&curval, uaddr1);if (unlikely (ret)) { -spin_unlock (&hb1->lock); +spin_unlock_non_nested (&hb1->lock);if (hb1 != hb2) -spin_unlock (&hb2->lock); +spin_unlock_non_nested (&hb2->lock);/* * If we would have faulted, release mmap_sem, fault
@@ -842,9 +850,9 @@ static int futex_requeue(u32 __user *uad } out_unlock: -spin_unlock (&hb1->lock); +spin_unlock_non_nested (&hb1->lock);if (hb1 != hb2) -spin_unlock (&hb2->lock); +spin_unlock_non_nested (&hb2->lock);/* drop_key_refs() must be called outside the spinlocks. */ while (--drop_count >=0 )
PATCH 41/61 lock validator: special locking: genirq
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
---
--- kernel/irq/handle.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
kernel/irq/handle.c +13 -0
@@ -11,6 +11,7 @@#include <linux/random.h> #include <linux/interrupt.h> #include <linux/kernel_stat.h> +#include <linux/kallsyms.h> #include "internals.h"
@@ -193,3 +194,15 @@ out:return 1 ; } +/* +* lockdep: we want to handle all irq_desc locks as a single lock-type: +*/ +static struct lockdep_type_key irq_desc_lock_type; + +void early_init_irq_lock_type (void ) +{ +int i; + +for (i =0 ; i <NR_IRQS ; i++) +spin_lock_init_key (&irq_desc[i].lock, &irq_desc_lock_type); +}
PATCH 42/61 lock validator: special locking: kgdb
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive, non-ordered) locking code to the lock validator. Has no effect on non-lockdep kernels.
---
--- kernel/kgdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kgdb.c +2 -2
@@ -1539,7 +1539,7 @@ int kgdb_handle_exception(int ex_vector,if (!debugger_step || !kgdb_contthread) {for (i =0 ; i <NR_CPUS ; i++) -spin_unlock (&slavecpulocks[i]); +spin_unlock_non_nested (&slavecpulocks[i]);/* Wait till all the processors have quit * from the debugger. */ for (i =0 ; i <NR_CPUS ; i++) {
@@ -1622,7 +1622,7 @@ static void __init kgdb_internal_init(vo/* Initialize our spinlocks. */ for (i =0 ; i <NR_CPUS ; i++) -spin_lock_init (&slavecpulocks[i]); +spin_lock_init_static (&slavecpulocks[i]);for (i =0 ; i <MAX_BREAKPOINTS ; i++) kgdb_break[i].state = bp_none;
PATCH 43/61 lock validator: special locking: completions
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (multi-initialized) locking code to the lock validator. Has no effect on non-lockdep kernels.
---
--- include/linux/completion.h | 6 +----- kernel/sched.c | 8 ++++++++ 2 files changed, 9 insertions(+), 5 deletions(-)
include/linux/completion.h +1 -5
@@ -21,11 +21,7 @@ struct completion {#define DECLARE_COMPLETION (work) \ struct completion work = COMPLETION_INITIALIZER(work) -static inline void init_completion (struct completion *x) -{ - x->done =0 ; -init_waitqueue_head (&x->wait); -} +extern void init_completion (struct completion *x);extern void FASTCALL (wait_for_completion (struct completion *));extern int FASTCALL (wait_for_completion_interruptible (struct completion *x));
kernel/sched.c +8 -0
@@ -3569,6 +3569,14 @@ __wake_up_sync(wait_queue_head_t *q, uns }EXPORT_SYMBOL_GPL (__wake_up_sync);/* For internal use only */ +void init_completion (struct completion *x) +{ + x->done =0 ; +__init_waitqueue_head (&x->wait); +} + +EXPORT_SYMBOL (init_completion); + void fastcall complete(struct completion *x) {unsigned long flags;
PATCH 44/61 lock validator: special locking: waitqueues
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
map special (multi-initialized) locking code to the lock validator. Has no effect on non-lockdep kernels.
---
--- include/linux/wait.h | 11 +++++++++-- kernel/wait.c | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-)
include/linux/wait.h +9 -2
@@ -77,12 +77,19 @@ struct task_struct;#define __WAIT_BIT_KEY_INITIALIZER (word, bit) \ { .flags = word, .bit_nr = bit, } -static inline void init_waitqueue_head (wait_queue_head_t *q) +/* +* lockdep: we want one lock-type for all waitqueue locks. +*/ +extern struct lockdep_type_key waitqueue_lock_key; + +static inline void __init_waitqueue_head (wait_queue_head_t *q) { -spin_lock_init (&q->lock); +spin_lock_init_key (&q->lock, &waitqueue_lock_key);INIT_LIST_HEAD (&q->task_list); } +extern void init_waitqueue_head (wait_queue_head_t *q); +static inline void init_waitqueue_entry (wait_queue_t *q,struct task_struct *p) { q->flags =0 ;
kernel/wait.c +9 -0
@@ -11,6 +11,15 @@#include <linux/wait.h> #include <linux/hash.h> +struct lockdep_type_key waitqueue_lock_key; + +void init_waitqueue_head (wait_queue_head_t *q) +{ +__init_waitqueue_head (q); +} + +EXPORT_SYMBOL (init_waitqueue_head); + void fastcall add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait) {unsigned long flags;
PATCH 45/61 lock validator: special locking: mm
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- mm/memory.c | 2 +- mm/mremap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
mm/memory.c +1 -1
@@ -509,7 +509,7 @@ again:return -ENOMEM ; src_pte =pte_offset_map_nested (src_pmd, addr); src_ptl =pte_lockptr (src_mm, src_pmd); -spin_lock (src_ptl); +spin_lock_nested (src_ptl,SINGLE_DEPTH_NESTING ); do { /*
mm/mremap.c +1 -1
@@ -97,7 +97,7 @@ static void move_ptes(struct vm_area_str new_pte =pte_offset_map_nested (new_pmd, new_addr); new_ptl =pte_lockptr (mm, new_pmd);if (new_ptl != old_ptl) -spin_lock (new_ptl); +spin_lock_nested (new_ptl,SINGLE_DEPTH_NESTING );for (; old_addr < old_end; old_pte++, old_addr +=PAGE_SIZE , new_pte++, new_addr +=PAGE_SIZE ) {
PATCH 46/61 lock validator: special locking: slab
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
fix initialize-locks-via-memcpy assumptions.
--- mm/slab.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 11 deletions(-)
mm/slab.c +48 -11
@@ -1026,7 +1026,8 @@ static void drain_alien_cache(struct kme } } -static inline int cache_free_alien (struct kmem_cache *cachep,void *objp) +static inline int cache_free_alien (struct kmem_cache *cachep,void *objp, +int nesting) {struct slab *slabp =virt_to_slab (objp);int nodeid = slabp->nodeid;
@@ -1044,7 +1045,7 @@ static inline int cache_free_alien(strucSTATS_INC_NODEFREES (cachep);if (l3->alien && l3->alien[nodeid]) { alien = l3->alien[nodeid]; -spin_lock (&alien->lock); +spin_lock_nested (&alien->lock, nesting);if (unlikely (alien->avail == alien->limit)) {STATS_INC_ACOVERFLOW (cachep);__drain_alien_cache (cachep, alien, nodeid);
@@ -1073,7 +1074,8 @@ static inline void free_alien_cache(stru { } -static inline int cache_free_alien (struct kmem_cache *cachep,void *objp) +static inline int cache_free_alien (struct kmem_cache *cachep,void *objp, +int nesting) {return 0 ; }
@@ -1278,6 +1280,11 @@ static void init_list(struct kmem_cachelocal_irq_disable ();memcpy (ptr, list,sizeof (struct kmem_list3 )); +/* +* Do not assume that spinlocks can be initialized via memcpy: +*/ +spin_lock_init (&ptr->list_lock); +MAKE_ALL_LISTS (cachep, ptr, nodeid); cachep->nodelists[nodeid] = ptr;local_irq_enable ();
@@ -1408,7 +1415,7 @@ void __init kmem_cache_init(void) }/* 4) Replace the bootstrap head arrays */ { -void *ptr; +struct array_cache *ptr; ptr =kmalloc (sizeof (struct arraycache_init ),GFP_KERNEL );
@@ -1416,6 +1423,11 @@ void __init kmem_cache_init(void)BUG_ON (cpu_cache_get (&cache_cache) != &initarray_cache.cache);memcpy (ptr,cpu_cache_get (&cache_cache),sizeof (struct arraycache_init )); +/* +* Do not assume that spinlocks can be initialized via memcpy: +*/ +spin_lock_init (&ptr->lock); + cache_cache.array[smp_processor_id ()] = ptr;local_irq_enable ();
@@ -1426,6 +1438,11 @@ void __init kmem_cache_init(void) != &initarray_generic.cache);memcpy (ptr,cpu_cache_get (malloc_sizes[INDEX_AC ].cs_cachep),sizeof (struct arraycache_init )); +/* +* Do not assume that spinlocks can be initialized via memcpy: +*/ +spin_lock_init (&ptr->lock); + malloc_sizes[INDEX_AC ].cs_cachep->array[smp_processor_id ()] = ptr;local_irq_enable ();
@@ -1753,6 +1770,8 @@ static void slab_destroy_objs(struct kme }#endif +static void __cache_free (struct kmem_cache *cachep,void *objp,int nesting); +/** * slab_destroy - destroy and release all objects in a slab * @cachep: cache pointer being destroyed
@@ -1776,8 +1795,17 @@ static void slab_destroy(struct kmem_caccall_rcu (&slab_rcu->head, kmem_rcu_free); }else {kmem_freepages (cachep, addr); -if (OFF_SLAB (cachep)) -kmem_cache_free (cachep->slabp_cache, slabp); +if (OFF_SLAB (cachep)) { +unsigned long flags; + +/* +* lockdep: we may nest inside an already held +* ac->lock, so pass in a nesting flag: +*/ +local_irq_save (flags); +__cache_free (cachep->slabp_cache, slabp,1 ); +local_irq_restore (flags); + } } }
@@ -3062,7 +3090,16 @@ static void free_block(struct kmem_cacheif (slabp->inuse ==0 ) {if (l3->free_objects > l3->free_limit) { l3->free_objects -= cachep->num; +/* +* It is safe to drop the lock. The slab is +* no longer linked to the cache. cachep +* cannot disappear - we are using it and +* all destruction of caches must be +* serialized properly by the user. +*/ +spin_unlock (&l3->list_lock);slab_destroy (cachep, slabp); +spin_lock (&l3->list_lock); }else {list_add (&slabp->list, &l3->slabs_free); }
@@ -3088,7 +3125,7 @@ static void cache_flusharray(struct kmem#endif check_irq_off (); l3 = cachep->nodelists[node]; -spin_lock (&l3->list_lock); +spin_lock_nested (&l3->list_lock,SINGLE_DEPTH_NESTING );if (l3->shared) {struct array_cache *shared_array = l3->shared;int max = shared_array->limit - shared_array->avail;
@@ -3131,14 +3168,14 @@ free_done:* Release an obj back to its cache. If the obj has a constructed state, it must * be in this state _before_ it is released. Called with disabled ints. */ -static inline void __cache_free (struct kmem_cache *cachep,void *objp) +static void __cache_free (struct kmem_cache *cachep,void *objp,int nesting) {struct array_cache *ac =cpu_cache_get (cachep);check_irq_off (); objp =cache_free_debugcheck (cachep, objp,__builtin_return_address (0 )); -if (cache_free_alien (cachep, objp)) +if (cache_free_alien (cachep, objp, nesting))return ;if (likely (ac->avail < ac->limit)) {
@@ -3393,7 +3430,7 @@ void kmem_cache_free(struct kmem_cache *BUG_ON (virt_to_cache (objp) != cachep);local_irq_save (flags); -__cache_free (cachep, objp); +__cache_free (cachep, objp,0 );local_irq_restore (flags); }EXPORT_SYMBOL (kmem_cache_free);
@@ -3418,7 +3455,7 @@ void kfree(const void *objp)kfree_debugcheck (objp); c =virt_to_cache (objp);debug_check_no_locks_freed (objp,obj_size (c)); -__cache_free (c, (void *)objp); +__cache_free (c, (void *)objp,0 );local_irq_restore (flags); }EXPORT_SYMBOL (kfree);
Re: [patch 46/61] lock validator: special locking: slab
mm/slab.c static void init_list(struct kmem_cache · line 1285
Quoted 3 lines · On Mon, 29 May 2006 23:26:49 +0200 Ingo Molnar <[email protected]> wrote:
mm/slab.c +3
-0+/* +* Do not assume that spinlocks can be initialized via memcpy: +*/
I'd view that as something which should be fixed in mainline.
Re: [patch 46/61] lock validator: special locking: slab
Quoted 8 lines · Andrew Morton
mm/slab.c static void init_list(struct kmem_cache · line 1285
Quoted 3 lines · On Mon, 29 May 2006 23:26:49 +0200 Ingo Molnar <[email protected]> wrote:
mm/slab.c +3
-0+/* +* Do not assume that spinlocks can be initialized via memcpy: +*/ I'd view that as something which should be fixed in mainline.
yeah. I got bitten by this (read: pulled hair for hours) when converting the slab spinlocks to rtmutexes in the -rt tree.
Ingo
PATCH 47/61 lock validator: special locking: skb_queue_head_init()
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (multi-initialized) locking code to the lock validator. Has no effect on non-lockdep kernels.
---
--- include/linux/skbuff.h | 7 +------ net/core/skbuff.c | 9 +++++++++ 2 files changed, 10 insertions(+), 6 deletions(-)
include/linux/skbuff.h +1 -6
@@ -584,12 +584,7 @@ static inline __u32 skb_queue_len(constreturn list_->qlen; } -static inline void skb_queue_head_init (struct sk_buff_head *list) -{ -spin_lock_init (&list->lock); - list->prev = list->next = (struct sk_buff *)list; - list->qlen =0 ; -} +extern void skb_queue_head_init (struct sk_buff_head *list);/* * Insert an sk_buff at the start of a list.
net/core/skbuff.c +9 -0
@@ -71,6 +71,15 @@static kmem_cache_t *skbuff_head_cache__read_mostly ;static kmem_cache_t *skbuff_fclone_cache__read_mostly ; +void skb_queue_head_init (struct sk_buff_head *list) +{ +spin_lock_init (&list->lock); + list->prev = list->next = (struct sk_buff *)list; + list->qlen =0 ; +} + +EXPORT_SYMBOL (skb_queue_head_init); +/* * Keep out-of-line to prevent kernel bloat. * __builtin_return_address is not used because it is not always
PATCH 48/61 lock validator: special locking: timer.c
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- kernel/timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/timer.c +8 -1
@@ -1496,6 +1496,13 @@ asmlinkage long sys_sysinfo(struct sysinreturn 0 ; } +/* +* lockdep: we want to track each per-CPU base as a separate lock-type, +* but timer-bases are kmalloc()-ed, so we need to attach separate +* keys to them: +*/ +static struct lockdep_type_key base_lock_keys[NR_CPUS ]; +static int __devinit init_timers_cpu (int cpu) {int j;
@@ -1530,7 +1537,7 @@ static int __devinit init_timers_cpu(int base =per_cpu (tvec_bases, cpu); } -spin_lock_init (&base->lock); +spin_lock_init_key (&base->lock, base_lock_keys + cpu);for (j =0 ; j <TVN_SIZE ; j++) {INIT_LIST_HEAD (base->tv5.vec + j);INIT_LIST_HEAD (base->tv4.vec + j);
PATCH 49/61 lock validator: special locking: sched.c
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- kernel/sched.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
kernel/sched.c +8 -8
@@ -1963,7 +1963,7 @@ static void double_rq_unlock(runqueue_t __releases(rq1->lock) __releases(rq2->lock) { -spin_unlock (&rq1->lock); +spin_unlock_non_nested (&rq1->lock);if (rq1 != rq2)spin_unlock (&rq2->lock);else
@@ -1980,7 +1980,7 @@ static void double_lock_balance(runqueue {if (unlikely (!spin_trylock (&busiest->lock))) {if (busiest->cpu < this_rq->cpu) { -spin_unlock (&this_rq->lock); +spin_unlock_non_nested (&this_rq->lock);spin_lock (&busiest->lock);spin_lock (&this_rq->lock); }else
@@ -2602,7 +2602,7 @@ static int load_balance_newidle(int this nr_moved =move_tasks (this_rq, this_cpu, busiest,minus_1_or_zero (busiest->nr_running), imbalance, sd,NEWLY_IDLE ,NULL ); -spin_unlock (&busiest->lock); +spin_unlock_non_nested (&busiest->lock); }if (!nr_moved) {
@@ -2687,7 +2687,7 @@ static void active_load_balance(runqueueelse schedstat_inc (sd, alb_failed); out: -spin_unlock (&target_rq->lock); +spin_unlock_non_nested (&target_rq->lock); }/*
@@ -3032,7 +3032,7 @@ static void wake_sleeping_dependent(int }for_each_cpu_mask (i, sibling_map) -spin_unlock (&cpu_rq (i)->lock); +spin_unlock_non_nested (&cpu_rq (i)->lock);/* * We exit with this_cpu's rq still held and IRQs * still disabled:
@@ -3068,7 +3068,7 @@ static int dependent_sleeper(int this_cp* The same locking rules and details apply as for * wake_sleeping_dependent(): */ -spin_unlock (&this_rq->lock); +spin_unlock_non_nested (&this_rq->lock); sibling_map = sd->span;for_each_cpu_mask (i, sibling_map)spin_lock (&cpu_rq (i)->lock);
@@ -3146,7 +3146,7 @@ check_smt_task: } out_unlock:for_each_cpu_mask (i, sibling_map) -spin_unlock (&cpu_rq (i)->lock); +spin_unlock_non_nested (&cpu_rq (i)->lock);return ret; }#else
@@ -6680,7 +6680,7 @@ void __init sched_init(void)prio_array_t *array; rq =cpu_rq (i); -spin_lock_init (&rq->lock); +spin_lock_init_static (&rq->lock); rq->nr_running =0 ; rq->active = rq->arrays; rq->expired = rq->arrays +1 ;
PATCH 50/61 lock validator: special locking: hrtimer.c
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- kernel/hrtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/hrtimer.c +1 -1
@@ -786,7 +786,7 @@ static void __devinit init_hrtimers_cpu(int i;for (i =0 ; i <MAX_HRTIMER_BASES ; i++, base++) -spin_lock_init (&base->lock); +spin_lock_init_static (&base->lock); }#ifdef CONFIG_HOTPLUG_CPU
Re: [patch 50/61] lock validator: special locking: hrtimer.c
Quoted 16 lines · On Mon, 29 May 2006 23:27:09 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- kernel/hrtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Index:
linux/kernel/hrtimer.c
===================================================================
kernel/hrtimer.c static void __devinit init_hrtimers_cpu( · line 791
Quoted 7 lines
kernel/hrtimer.c +1
-1@@ -786,7 +786,7 @@ static void __devinit init_hrtimers_cpu(int i;for (i =0 ; i <MAX_HRTIMER_BASES ; i++, base++) -spin_lock_init (&base->lock); +spin_lock_init_static (&base->lock); }
Perhaps the validator core's implementation of spin_lock_init() could look at the address and work out if it's within the static storage sections.
Re: [patch 50/61] lock validator: special locking: hrtimer.c
Quoted 9 lines · Andrew Morton
kernel/hrtimer.c static void __devinit init_hrtimers_cpu( · line 790
Quoted 5 lines
kernel/hrtimer.c +1
-1for (i =0 ; i <MAX_HRTIMER_BASES ; i++, base++) -spin_lock_init (&base->lock); +spin_lock_init_static (&base->lock); }Perhaps the validator core's implementation of
spin_lock_init()could look at the address and work out if it's within the static storage sections.
yeah, but there are two cases: places where we want to 'unify' array locks into a single type, and places where we want to treat them separately. The case where we 'unify' is the more common one: locks embedded into hash-tables for example. So i went for annotating the ones that are rarer. There are 2 right now: scheduler, hrtimers, with the hrtimers one going away in the high-res-timers implementation. (we unified the hrtimers locks into a per-CPU lock) (there's also a kgdb annotation for -mm)
perhaps the naming should be clearer? I had it named spin_lock_init_standalone() originally, then cleaned it up to be spin_lock_init_static(). Maybe the original name is better?
Ingo
Re: [patch 50/61] lock validator: special locking: hrtimer.c
Quoted 22 lines · On Fri, 23 Jun 2006 12:04:39 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 9 lines · Andrew Morton
kernel/hrtimer.c static void __devinit init_hrtimers_cpu( · line 790
Quoted 5 lines
kernel/hrtimer.c +1
-1for (i =0 ; i <MAX_HRTIMER_BASES ; i++, base++) -spin_lock_init (&base->lock); +spin_lock_init_static (&base->lock); }Perhaps the validator core's implementation of
spin_lock_init()could look at the address and work out if it's within the static storage sections.yeah, but there are two cases: places where we want to 'unify' array locks into a single type, and places where we want to treat them separately. The case where we 'unify' is the more common one: locks embedded into hash-tables for example. So i went for annotating the ones that are rarer. There are 2 right now: scheduler, hrtimers, with the hrtimers one going away in the high-res-timers implementation. (we unified the hrtimers locks into a per-CPU lock) (there's also a kgdb annotation for -mm)
Quoted 4 lines
perhaps the naming should be clearer? I had it named
spin_lock_init_standalone()originally, then cleaned it up to bespin_lock_init_static(). Maybe the original name is better?
hm. This is where a "term of art" is needed. What is lockdep's internal term for locks-of-a-different-type? It should have such a term.
"class" would be a good term, although terribly overused. Using that as an example, spin_lock_init_standalone_class()? ug.
<gives up>
You want spin_lock_init_singleton().
Re: [patch 50/61] lock validator: special locking: hrtimer.c
Quoted 8 lines · Andrew Morton
Quoted 4 lines
perhaps the naming should be clearer? I had it named
spin_lock_init_standalone()originally, then cleaned it up to bespin_lock_init_static(). Maybe the original name is better?hm. This is where a "term of art" is needed. What is lockdep's internal term for locks-of-a-different-type? It should have such a term.
'lock type' is what i tried to use consistenty.
Quoted 6 lines
"class" would be a good term, although terribly overused. Using that as an example,
spin_lock_init_standalone_class()? ug.<gives up>
You want
spin_lock_init_singleton().
hehe ;)
singleton wouldnt be enough here as we dont want just one instance of this lock type: we want separate types for each array entry. I.e. we dont want to unify the lock types (as the common spin_lock_init() call suggests), we want to split them along their static addresses.
singleton initialization is what spin_lock_init() itself accomplishes:
the first call to a given spin_lock_init() will register a 'lock type' structure, and all subsequent calls to spin_lock_init() will find this type registered already. (keyed by the lockdep-type-key embedded in the spin_lock_init() macro)
so - spin_lock_init_split_type() might be better i think and expresses the purpose (to split away this type from the other lock types initialized here).
Or we could simply get rid of this static-variables special-case and embedd a lock_type_key in the runqueue and use spin_lock_init_key(&rq->rq_lock_key)? That would unify the 'splitting' of types for static and dynamic locks. (at a minimal cost of .data) Hm?
Ingo
Re: [patch 50/61] lock validator: special locking: hrtimer.c
Quoted 5 lines · Ingo Molnar
Quoted 5 lines
Quoted 4 lines
perhaps the naming should be clearer? I had it named
spin_lock_init_standalone()originally, then cleaned it up to bespin_lock_init_static(). Maybe the original name is better?
Quoted 8 lines
Quoted 3 lines
hm. This is where a "term of art" is needed. What is lockdep's internal term for locks-of-a-different-type? It should have such a term.
'lock type' is what i tried to use consistenty.
Quoted 2 lines
"class" would be a good term, although terribly overused. Using that as an example,
spin_lock_init_standalone_class()? ug.
actually ... 'class' might be an even better term than 'type', mainly because type is even more overloaded in this context than class. "Q:
What type does this lock have?" The natural answer: "it's a spinlock".
so i'm strongly considering the renaming of 'lock type' to 'lock class' and push that through all the APIs (and documentation). (i.e. we'd have 'subclasses' of locks, not 'subtypes'.)
then we could do the annotations (where the call-site heuristics get the class wrong and either do false splits or dont do a split) via:
spin_lock_set_class(&lock, &class_key)
rwlock_set_class(&rwlock, &class_key)
mutex_set_class(&mutex, &class_key)
rwsem_set_class(&rwsem, &class_key)
[And for class-internal nesting, we'd have subclass nesting levels.]
hm?
Ingo
Re: [patch 50/61] lock validator: special locking: hrtimer.c
Quoted 28 lines · On Fri, 23 Jun 2006 13:52:54 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 5 lines · Ingo Molnar
Quoted 5 lines
Quoted 4 lines
perhaps the naming should be clearer? I had it named
spin_lock_init_standalone()originally, then cleaned it up to bespin_lock_init_static(). Maybe the original name is better?Quoted 8 lines
Quoted 3 lines
hm. This is where a "term of art" is needed. What is lockdep's internal term for locks-of-a-different-type? It should have such a term.
'lock type' is what i tried to use consistenty.
Quoted 2 lines
"class" would be a good term, although terribly overused. Using that as an example,
spin_lock_init_standalone_class()? ug.actually ... 'class' might be an even better term than 'type', mainly because type is even more overloaded in this context than class. "Q:
What type does this lock have?" The natural answer: "it's a spinlock".so i'm strongly considering the renaming of 'lock type' to 'lock class' and push that through all the APIs (and documentation). (i.e. we'd have 'subclasses' of locks, not 'subtypes'.)
then we could do the annotations (where the call-site heuristics get the class wrong and either do false splits or dont do a split) via:
Quoted 7 lines
spin_lock_set_class(&lock, &class_key)
rwlock_set_class(&rwlock, &class_key)
mutex_set_class(&mutex, &class_key)
rwsem_set_class(&rwsem, &class_key)[And for class-internal nesting, we'd have subclass nesting levels.]
Works for me.
PATCH 51/61 lock validator: special locking: sock_lock_init()
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (multi-initialized, per-address-family) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- include/net/sock.h | 6 ------ net/core/sock.c | 27 +++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-)
include/net/sock.h +0 -6
@@ -81,12 +81,6 @@ typedef struct {wait_queue_head_t wq; } socket_lock_t; -#define sock_lock_init (__sk) \ -do { spin_lock_init(&((__sk)->sk_lock.slock)); \ - (__sk)->sk_lock.owner = NULL; \ - init_waitqueue_head(&((__sk)->sk_lock.wq)); \ -} while(0) -struct sock ;struct proto ;
net/core/sock.c +23 -4
@@ -739,6 +739,27 @@ lenout:return 0 ; } +/* +* Each address family might have different locking rules, so we have +* one slock key per address family: +*/ +static struct lockdep_type_key af_family_keys[AF_MAX ]; + +static void noinline sock_lock_init(struct sock *sk) +{ +spin_lock_init_key (&sk->sk_lock.slock, af_family_keys + sk->sk_family); + sk->sk_lock.owner =NULL ; +init_waitqueue_head (&sk->sk_lock.wq); +} + +static struct lockdep_type_key af_callback_keys[AF_MAX ]; + +static void noinline sock_rwlock_init(struct sock *sk) +{ +rwlock_init (&sk->sk_dst_lock); +rwlock_init_key (&sk->sk_callback_lock, af_callback_keys + sk->sk_family); +} +/** * sk_alloc - All socket objects are allocated here * @family: protocol family
@@ -833,8 +854,7 @@ struct sock *sk_clone(const struct sockskb_queue_head_init (&newsk->sk_receive_queue);skb_queue_head_init (&newsk->sk_write_queue); -rwlock_init (&newsk->sk_dst_lock); -rwlock_init (&newsk->sk_callback_lock); +sock_rwlock_init (newsk); newsk->sk_dst_cache =NULL ; newsk->sk_wmem_queued =0 ;
@@ -1404,8 +1424,7 @@ void sock_init_data(struct socket *sock, }else sk->sk_sleep =NULL ; -rwlock_init (&sk->sk_dst_lock); -rwlock_init (&sk->sk_callback_lock); +sock_rwlock_init (sk); sk->sk_state_change = sock_def_wakeup; sk->sk_data_ready = sock_def_readable;
Re: [patch 51/61] lock validator: special locking: sock_lock_init()
Quoted 32 lines · On Mon, 29 May 2006 23:27:14 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (multi-initialized, per-address-family) locking code to the lock validator. Has no effect on non-lockdep kernels.
Index:
linux/include/net/sock.h
===================================================================include/net/sock.h +0
-6@@ -81,12 +81,6 @@ typedef struct {wait_queue_head_t wq; } socket_lock_t; -#define sock_lock_init (__sk) \ -do { spin_lock_init(&((__sk)->sk_lock.slock)); \ - (__sk)->sk_lock.owner = NULL; \ - init_waitqueue_head(&((__sk)->sk_lock.wq)); \ -} while(0) -struct sock ;struct proto ;Index:
linux/net/core/sock.c
===================================================================net/core/sock.c +2
-0@@ -739,6 +739,27 @@ lenout:return 0 ; } +/* +* Each address family might have different locking rules, so we have
net/core/sock.c lenout: · line 753
Quoted 10 lines
net/core/sock.c +10
-0+* one slock key per address family: +*/ +static struct lockdep_type_key af_family_keys[AF_MAX ]; + +static void noinline sock_lock_init(struct sock *sk) +{ +spin_lock_init_key (&sk->sk_lock.slock, af_family_keys + sk->sk_family); + sk->sk_lock.owner =NULL ; +init_waitqueue_head (&sk->sk_lock.wq); +}
OK, no code outside net/core/sock.c uses sock_lock_init().
Hopefully the same is true of out-of-tree code...
Re: [patch 51/61] lock validator: special locking: sock_lock_init()
Quoted 6 lines · Andrew Morton
Quoted 6 lines
net/core/sock.c +6
-0+/* +* Each address family might have different locking rules, so we have +* one slock key per address family: +*/ +static struct lockdep_type_key af_family_keys[AF_MAX ]; +
Quoted 8 lines
net/core/sock.c lenout: · line 753
Quoted 6 lines
net/core/sock.c +6
-0+static void noinline sock_lock_init(struct sock *sk) +{ +spin_lock_init_key (&sk->sk_lock.slock, af_family_keys + sk->sk_family); + sk->sk_lock.owner =NULL ; +init_waitqueue_head (&sk->sk_lock.wq); +}OK, no code outside
net/core/sock.cusessock_lock_init().
yeah.
Quoted 1 line
Hopefully the same is true of out-of-tree code...
it wont go unnoticed even if it does: we'll get a nonfatal lockdep message and fix it up. I dont expect out-of-tree code to mess with sk_lock.slock though ...
Ingo
PATCH 52/61 lock validator: special locking: af_unix
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
(includes workaround for sk_receive_queue.lock, which is currently treated globally by the lock validator, but which be switched to per-address-family locking rules.)
--- include/net/af_unix.h | 3 +++ net/unix/af_unix.c | 10 +++++----- net/unix/garbage.c | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-)
include/net/af_unix.h +3 -0
@@ -61,6 +61,9 @@ struct unix_skb_parms {#define unix_state_rlock (s) spin_lock(&unix_sk(s)->lock)#define unix_state_runlock (s) spin_unlock(&unix_sk(s)->lock)#define unix_state_wlock (s) spin_lock(&unix_sk(s)->lock) +#define unix_state_wlock_nested (s) \ + spin_lock_nested(&unix_sk(s)->lock, \ + SINGLE_DEPTH_NESTING)#define unix_state_wunlock (s) spin_unlock(&unix_sk(s)->lock)#ifdef __KERNEL__
net/unix/af_unix.c +5 -5
@@ -1022,7 +1022,7 @@ restart: goto out_unlock; } -unix_state_wlock (sk); +unix_state_wlock_nested (sk);if (sk->sk_state != st) {unix_state_wunlock (sk);
@@ -1073,12 +1073,12 @@ restart:unix_state_wunlock (sk);/* take ten and and send info to listening sock */ -spin_lock (&other->sk_receive_queue.lock); +spin_lock_bh (&other->sk_receive_queue.lock);__skb_queue_tail (&other->sk_receive_queue, skb);/* Undo artificially decreased inflight after embrion * is installed to listening socket. */ atomic_inc (&newu->inflight); -spin_unlock (&other->sk_receive_queue.lock); +spin_unlock_bh (&other->sk_receive_queue.lock);unix_state_runlock (other); other->sk_data_ready (other,0 );sock_put (other);
@@ -1843,7 +1843,7 @@ static int unix_ioctl(struct socket *socbreak ; } -spin_lock (&sk->sk_receive_queue.lock); +spin_lock_bh (&sk->sk_receive_queue.lock);if (sk->sk_type ==SOCK_STREAM || sk->sk_type ==SOCK_SEQPACKET ) {skb_queue_walk (&sk->sk_receive_queue, skb)
@@ -1853,7 +1853,7 @@ static int unix_ioctl(struct socket *socif (skb) amount=skb->len; } -spin_unlock (&sk->sk_receive_queue.lock); +spin_unlock_bh (&sk->sk_receive_queue.lock); err =put_user (amount, (int __user *)arg);break ; }
net/unix/garbage.c +4 -4
@@ -235,7 +235,7 @@ void unix_gc(void)struct sock *x =pop_stack ();struct sock *sk; -spin_lock (&x->sk_receive_queue.lock); +spin_lock_bh (&x->sk_receive_queue.lock); skb =skb_peek (&x->sk_receive_queue);/*
@@ -270,7 +270,7 @@ void unix_gc(void)maybe_unmark_and_push (skb->sk); skb=skb->next; } -spin_unlock (&x->sk_receive_queue.lock); +spin_unlock_bh (&x->sk_receive_queue.lock);sock_put (x); }
@@ -283,7 +283,7 @@ void unix_gc(void)if (u->gc_tree ==GC_ORPHAN ) {struct sk_buff *nextsk; -spin_lock (&s->sk_receive_queue.lock); +spin_lock_bh (&s->sk_receive_queue.lock); skb =skb_peek (&s->sk_receive_queue);while (skb && skb != (struct sk_buff *)&s->sk_receive_queue) {
@@ -298,7 +298,7 @@ void unix_gc(void) } skb = nextsk; } -spin_unlock (&s->sk_receive_queue.lock); +spin_unlock_bh (&s->sk_receive_queue.lock); } u->gc_tree =GC_ORPHAN ; }
Re: [patch 52/61] lock validator: special locking: af_unix
Quoted 12 lines · On Mon, 29 May 2006 23:27:19 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
(includes workaround for sk_receive_queue.lock, which is currently treated globally by the lock validator, but which be switched to per-address-family locking rules.)
...
net/unix/af_unix.c static int unix_ioctl(struct socket *soc · line 1846
Quoted 2 lines
net/unix/af_unix.c +1
-1-spin_lock (&sk->sk_receive_queue.lock); +spin_lock_bh (&sk->sk_receive_queue.lock);
Again, a bit of a show-stopper. Will the real fix be far off?
Re: [patch 52/61] lock validator: special locking: af_unix
Quoted 4 lines · Andrew Morton
net/unix/af_unix.c static int unix_ioctl(struct socket *soc · line 1846
Quoted 2 lines
net/unix/af_unix.c +1
-1-spin_lock (&sk->sk_receive_queue.lock); +spin_lock_bh (&sk->sk_receive_queue.lock);Again, a bit of a show-stopper. Will the real fix be far off?
ok, this should be solved in recent -mm, via:
lock-validator-special-locking-af_unix-undo-af_unix-_bh-locking-changes-and-split-lock-type.patch
Ingo
PATCH 53/61 lock validator: special locking: bh_lock_sock()
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- include/net/sock.h | 3 +++ net/ipv4/tcp_ipv4.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
include/net/sock.h +3 -0
@@ -743,6 +743,9 @@ extern void FASTCALL(release_sock(struct/* BH context may only use the following locking interface. */ #define bh_lock_sock (__sk) spin_lock(&((__sk)->sk_lock.slock)) +#define bh_lock_sock_nested (__sk) \ + spin_lock_nested(&((__sk)->sk_lock.slock), \ + SINGLE_DEPTH_NESTING)#define bh_unlock_sock (__sk) spin_unlock(&((__sk)->sk_lock.slock)) extern struct sock *sk_alloc(int family,
net/ipv4/tcp_ipv4.c +1 -1
@@ -1088,7 +1088,7 @@ process: skb->dev =NULL ; -bh_lock_sock (sk); +bh_lock_sock_nested (sk); ret =0 ;if (!sock_owned_by_user (sk)) {if (!tcp_prequeue (sk, skb))
PATCH 54/61 lock validator: special locking: mmap_sem
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- kernel/exit.c | 2 +- kernel/fork.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)
kernel/exit.c +1 -1
@@ -582,7 +582,7 @@ static void exit_mm(struct task_struct */* more a memory barrier than a real lock */ task_lock (tsk); tsk->mm =NULL ; -up_read (&mm->mmap_sem); +up_read_non_nested (&mm->mmap_sem);enter_lazy_tlb (mm, current);task_unlock (tsk);mmput (mm);
kernel/fork.c +4 -1
@@ -196,7 +196,10 @@ static inline int dup_mmap(struct mm_strdown_write (&oldmm->mmap_sem);flush_cache_mm (oldmm); -down_write (&mm->mmap_sem); +/* +* Not linked in yet - no deadlock potential: +*/ +down_write_nested (&mm->mmap_sem,1 ); mm->locked_vm =0 ; mm->mmap =NULL ;
PATCH 55/61 lock validator: special locking: sb->s_umount
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
workaround for special sb->s_umount locking rule.
s_umount gets held across a series of lock dropping and releasing in prune_one_dentry(), so i changed the order, at the risk of introducing a umount race. FIXME.
i think a better fix would be to do the unlocks as _non_nested in prune_one_dentry(), and to do the up_read() here as
an up_read_non_nested() as well?
--- fs/dcache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dcache.c +2 -1
@@ -470,8 +470,9 @@ static void prune_dcache(int count, stru s_umount = &dentry->d_sb->s_umount;if (down_read_trylock (s_umount)) {if (dentry->d_sb->s_root !=NULL ) { -prune_one_dentry (dentry); +// lockdep hack: do this better! up_read (s_umount); +prune_one_dentry (dentry);continue ; }up_read (s_umount);
Re: [patch 55/61] lock validator: special locking: sb->s_umount
Quoted 23 lines · On Mon, 29 May 2006 23:27:32 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
workaround for special
sb->s_umountlocking rule.
s_umountgets held across a series of lock dropping and releasing inprune_one_dentry(), so i changed the order, at the risk of introducing a umount race. FIXME.i think a better fix would be to do the unlocks as
_non_nestedinprune_one_dentry(), and to do theup_read()here as
anup_read_non_nested()as well?Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- fs/dcache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Index:
linux/fs/dcache.c
===================================================================
fs/dcache.c static void prune_dcache(int count, stru · line 476
Quoted 8 lines
fs/dcache.c +2
-1@@ -470,8 +470,9 @@ static void prune_dcache(int count, stru s_umount = &dentry->d_sb->s_umount;if (down_read_trylock (s_umount)) {if (dentry->d_sb->s_root !=NULL ) { -prune_one_dentry (dentry); +// lockdep hack: do this better! up_read (s_umount); +prune_one_dentry (dentry);continue ;
argh, you broke my kernel!
I'll whack some ifdefs in here so it's only known-broken if CONFIG_LOCKDEP.
Again, we'd need the real fix here.
Re: [patch 55/61] lock validator: special locking: sb->s_umount
Quoted 13 lines · Andrew Morton
fs/dcache.c static void prune_dcache(int count, stru · line 476
Quoted 10 lines
+++
linux/fs/dcache.cfs/dcache.c +2
-1@@ -470,8 +470,9 @@ static void prune_dcache(int count, stru s_umount = &dentry->d_sb->s_umount;if (down_read_trylock (s_umount)) {if (dentry->d_sb->s_root !=NULL ) { -prune_one_dentry (dentry); +// lockdep hack: do this better! up_read (s_umount); +prune_one_dentry (dentry);continue ;argh, you broke my kernel!
Quoted 4 lines
I'll whack some ifdefs in here so it's only known-broken if
CONFIG_LOCKDEP.Again, we'd need the real fix here.
yeah. We should undo this patch for now. This will only be complained about if CONFIG_DEBUG_NON_NESTED_UNLOCKS is enabled. [i'll do this in my refactored queue]
Ingo
PATCH 56/61 lock validator: special locking: jbd
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (non-nested) unlocking code to the lock validator. Has no effect on non-lockdep kernels.
--- fs/jbd/checkpoint.c | 2 +- fs/jbd/commit.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/jbd/checkpoint.c +1 -1
@@ -135,7 +135,7 @@ void __log_wait_for_space(journal_t *joulog_do_checkpoint (journal);spin_lock (&journal->j_state_lock); } -mutex_unlock (&journal->j_checkpoint_mutex); +mutex_unlock_non_nested (&journal->j_checkpoint_mutex); } }
fs/jbd/commit.c +1 -1
@@ -838,7 +838,7 @@ restart_loop:J_ASSERT (commit_transaction == journal->j_committing_transaction); journal->j_commit_sequence = commit_transaction->t_tid; journal->j_committing_transaction =NULL ; -spin_unlock (&journal->j_state_lock); +spin_unlock_non_nested (&journal->j_state_lock);if (commit_transaction->t_checkpoint_list ==NULL ) {__journal_drop_transaction (journal, commit_transaction);
PATCH 57/61 lock validator: special locking: posix-timers
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (non-nested) unlocking code to the lock validator. Has no effect on non-lockdep kernels.
--- kernel/posix-timers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/posix-timers.c +1 -1
@@ -576,7 +576,7 @@ static struct k_itimer * lock_timer(time timr = (struct k_itimer *)idr_find (&posix_timers_id, (int ) timer_id);if (timr) {spin_lock (&timr->it_lock); -spin_unlock (&idr_lock); +spin_unlock_non_nested (&idr_lock);if ((timr->it_id != timer_id) || !(timr->it_process) || timr->it_process->tgid != current->tgid) {
PATCH 58/61 lock validator: special locking: sch_generic.c
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (non-nested) unlocking code to the lock validator. Has no effect on non-lockdep kernels.
--- net/sched/sch_generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_generic.c +1 -1
@@ -132,7 +132,7 @@ int qdisc_restart(struct net_device *dev {/* And release queue */ -spin_unlock (&dev->queue_lock); +spin_unlock_non_nested (&dev->queue_lock);if (!netif_queue_stopped (dev)) {int ret;
PATCH 59/61 lock validator: special locking: xfrm
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (non-nested) unlocking code to the lock validator. Has no effect on non-lockdep kernels.
--- net/xfrm/xfrm_policy.c | 2 +- net/xfrm/xfrm_state.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/xfrm/xfrm_policy.c +1 -1
@@ -1308,7 +1308,7 @@ static struct xfrm_policy_afinfo *xfrm_p afinfo = xfrm_policy_afinfo[family];if (likely (afinfo !=NULL ))read_lock (&afinfo->lock); -read_unlock (&xfrm_policy_afinfo_lock); +read_unlock_non_nested (&xfrm_policy_afinfo_lock);return afinfo; }
net/xfrm/xfrm_state.c +1 -1
@@ -1105,7 +1105,7 @@ static struct xfrm_state_afinfo *xfrm_st afinfo = xfrm_state_afinfo[family];if (likely (afinfo !=NULL ))read_lock (&afinfo->lock); -read_unlock (&xfrm_state_afinfo_lock); +read_unlock_non_nested (&xfrm_state_afinfo_lock);return afinfo; }
Re: [patch 59/61] lock validator: special locking: xfrm
Quoted 30 lines · On Mon, 29 May 2006 23:27:51 +0200 Ingo Molnar <[email protected]> wrote:
From: Ingo Molnar <[email protected]>
teach special (non-nested) unlocking code to the lock validator. Has no effect on non-lockdep kernels.
Signed-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- net/xfrm/xfrm_policy.c | 2 +- net/xfrm/xfrm_state.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)Index:
linux/net/xfrm/xfrm_policy.c
===================================================================net/xfrm/xfrm_policy.c +1
-1@@ -1308,7 +1308,7 @@ static struct xfrm_policy_afinfo *xfrm_p afinfo = xfrm_policy_afinfo[family];if (likely (afinfo !=NULL ))read_lock (&afinfo->lock); -read_unlock (&xfrm_policy_afinfo_lock); +read_unlock_non_nested (&xfrm_policy_afinfo_lock);return afinfo; }Index:
linux/net/xfrm/xfrm_state.c
===================================================================
net/xfrm/xfrm_state.c static struct xfrm_state_afinfo *xfrm_st · line 1111
Quoted 8 lines
net/xfrm/xfrm_state.c +1
-1@@ -1105,7 +1105,7 @@ static struct xfrm_state_afinfo *xfrm_st afinfo = xfrm_state_afinfo[family];if (likely (afinfo !=NULL ))read_lock (&afinfo->lock); -read_unlock (&xfrm_state_afinfo_lock); +read_unlock_non_nested (&xfrm_state_afinfo_lock);return afinfo; }
I got a bunch of rejects here due to changes in git-net.patch. Please verify the result. It could well be wrong (the changes in there are odd).
PATCH 60/61 lock validator: special locking: sound/core/seq/seq_ports.c
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
teach special (recursive) locking code to the lock validator. Has no effect on non-lockdep kernels.
--- sound/core/seq/seq_ports.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/core/seq/seq_ports.c +2 -2
@@ -518,7 +518,7 @@ int snd_seq_port_connect(struct snd_seq_atomic_set (&subs->ref_count,2 );down_write (&src->list_mutex); -down_write (&dest->list_mutex); +down_write_nested (&dest->list_mutex,SINGLE_DEPTH_NESTING ); exclusive = info->flags &SNDRV_SEQ_PORT_SUBS_EXCLUSIVE ?1 :0 ; err = -EBUSY ;
@@ -591,7 +591,7 @@ int snd_seq_port_disconnect(struct snd_sunsigned long flags;down_write (&src->list_mutex); -down_write (&dest->list_mutex); +down_write_nested (&dest->list_mutex,SINGLE_DEPTH_NESTING );/* look for the connection */ list_for_each (p, &src->list_head) {
PATCH 61/61 lock validator: enable lock validator in Kconfig
In reply to Ingo MolnarFrom: Ingo Molnar <[email protected]>
offer the following lock validation options:
CONFIG_PROVE_SPIN_LOCKING
CONFIG_PROVE_RW_LOCKING
CONFIG_PROVE_MUTEX_LOCKING
CONFIG_PROVE_RWSEM_LOCKING
--- lib/Kconfig.debug | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+)
lib/Kconfig.debug +167 -0
@@ -184,6 +184,173 @@ config DEBUG_SPINLOCK best used in conjunction with the NMI watchdog so that spinlock deadlocks are also debuggable. +config PROVE_SPIN_LOCKING + bool "Prove spin-locking correctness" + default y + help + This feature enables the kernel to prove that all spinlock + locking that occurs in the kernel runtime is mathematically + correct: that under no circumstance could an arbitrary (and + not yet triggered) combination of observed spinlock locking + sequences (on an arbitrary number of CPUs, running an + arbitrary number of tasks and interrupt contexts) cause a + deadlock. + + In short, this feature enables the kernel to report spinlock + deadlocks before they actually occur. + + The proof does not depend on how hard and complex a + deadlock scenario would be to trigger: how many + participant CPUs, tasks and irq-contexts would be needed + for it to trigger. The proof also does not depend on + timing: if a race and a resulting deadlock is possible + theoretically (no matter how unlikely the race scenario + is), it will be proven so and will immediately be + reported by the kernel (once the event is observed that + makes the deadlock theoretically possible). + + If a deadlock is impossible (i.e. the locking rules, as + observed by the kernel, are mathematically correct), the + kernel reports nothing. + + NOTE: this feature can also be enabled for rwlocks, mutexes + and rwsems - in which case all dependencies between these + different locking variants are observed and mapped too, and + the proof of observed correctness is also maintained for an + arbitrary combination of these separate locking variants. + + For more details, see Documentation/locking-correctness.txt. + +config PROVE_RW_LOCKING + bool "Prove rw-locking correctness" + default y + help + This feature enables the kernel to prove that all rwlock + locking that occurs in the kernel runtime is mathematically + correct: that under no circumstance could an arbitrary (and + not yet triggered) combination of observed rwlock locking + sequences (on an arbitrary number of CPUs, running an + arbitrary number of tasks and interrupt contexts) cause a + deadlock. + + In short, this feature enables the kernel to report rwlock + deadlocks before they actually occur. + + The proof does not depend on how hard and complex a + deadlock scenario would be to trigger: how many + participant CPUs, tasks and irq-contexts would be needed + for it to trigger. The proof also does not depend on + timing: if a race and a resulting deadlock is possible + theoretically (no matter how unlikely the race scenario + is), it will be proven so and will immediately be + reported by the kernel (once the event is observed that + makes the deadlock theoretically possible). + + If a deadlock is impossible (i.e. the locking rules, as + observed by the kernel, are mathematically correct), the + kernel reports nothing. + + NOTE: this feature can also be enabled for spinlocks, mutexes + and rwsems - in which case all dependencies between these + different locking variants are observed and mapped too, and + the proof of observed correctness is also maintained for an + arbitrary combination of these separate locking variants. + + For more details, see Documentation/locking-correctness.txt. + +config PROVE_MUTEX_LOCKING + bool "Prove mutex-locking correctness" + default y + help + This feature enables the kernel to prove that all mutexlock + locking that occurs in the kernel runtime is mathematically + correct: that under no circumstance could an arbitrary (and + not yet triggered) combination of observed mutexlock locking + sequences (on an arbitrary number of CPUs, running an + arbitrary number of tasks and interrupt contexts) cause a + deadlock. + + In short, this feature enables the kernel to report mutexlock + deadlocks before they actually occur. + + The proof does not depend on how hard and complex a + deadlock scenario would be to trigger: how many + participant CPUs, tasks and irq-contexts would be needed + for it to trigger. The proof also does not depend on + timing: if a race and a resulting deadlock is possible + theoretically (no matter how unlikely the race scenario + is), it will be proven so and will immediately be + reported by the kernel (once the event is observed that + makes the deadlock theoretically possible). + + If a deadlock is impossible (i.e. the locking rules, as + observed by the kernel, are mathematically correct), the + kernel reports nothing. + + NOTE: this feature can also be enabled for spinlock, rwlocks + and rwsems - in which case all dependencies between these + different locking variants are observed and mapped too, and + the proof of observed correctness is also maintained for an + arbitrary combination of these separate locking variants. + + For more details, see Documentation/locking-correctness.txt. + +config PROVE_RWSEM_LOCKING + bool "Prove rwsem-locking correctness" + default y + help + This feature enables the kernel to prove that all rwsemlock + locking that occurs in the kernel runtime is mathematically + correct: that under no circumstance could an arbitrary (and + not yet triggered) combination of observed rwsemlock locking + sequences (on an arbitrary number of CPUs, running an + arbitrary number of tasks and interrupt contexts) cause a + deadlock. + + In short, this feature enables the kernel to report rwsemlock + deadlocks before they actually occur. + + The proof does not depend on how hard and complex a + deadlock scenario would be to trigger: how many + participant CPUs, tasks and irq-contexts would be needed + for it to trigger. The proof also does not depend on + timing: if a race and a resulting deadlock is possible + theoretically (no matter how unlikely the race scenario + is), it will be proven so and will immediately be + reported by the kernel (once the event is observed that + makes the deadlock theoretically possible). + + If a deadlock is impossible (i.e. the locking rules, as + observed by the kernel, are mathematically correct), the + kernel reports nothing. + + NOTE: this feature can also be enabled for spinlocks, rwlocks + and mutexes - in which case all dependencies between these + different locking variants are observed and mapped too, and + the proof of observed correctness is also maintained for an + arbitrary combination of these separate locking variants. + + For more details, see Documentation/locking-correctness.txt. + +config LOCKDEP + bool + default y + depends on PROVE_SPIN_LOCKING || PROVE_RW_LOCKING || PROVE_MUTEX_LOCKING || PROVE_RWSEM_LOCKING + +config DEBUG_LOCKDEP + bool "Lock dependency engine debugging" + depends on LOCKDEP + default y + help + If you say Y here, the lock dependency engine will do + additional runtime checks to debug itself, at the price + of more runtime overhead. + +config TRACE_IRQFLAGS + bool + default y + depends on PROVE_SPIN_LOCKING || PROVE_RW_LOCKING + config DEBUG_SPINLOCK_SLEEP bool "Sleep-inside-spinlock checking" depends on DEBUG_KERNEL
Re: [patch 61/61] lock validator: enable lock validator in Kconfig
Quoted 18 lines · On Mon, 29 May 2006 23:28:12 +0200 Ingo Molnar <[email protected]> wrote:
offer the following lock validation options:
CONFIG_PROVE_SPIN_LOCKING
CONFIG_PROVE_RW_LOCKING
CONFIG_PROVE_MUTEX_LOCKING
CONFIG_PROVE_RWSEM_LOCKINGSigned-off-by Ingo Molnar <[email protected]>Signed-off-by Arjan van de Ven <[email protected]>--- lib/Kconfig.debug | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+)Index: linux/lib/Kconfig.debug
===================================================================
lib/Kconfig.debug config DEBUG_SPINLOCK · line 189
Quoted 6 lines
lib/Kconfig.debug +3
-0@@ -184,6 +184,173 @@ config DEBUG_SPINLOCK best used in conjunction with the NMI watchdog so that spinlock deadlocks are also debuggable. +config PROVE_SPIN_LOCKING + bool "Prove spin-locking correctness" + default y
err, I think I'll be sticking a `depends on X86' in there, thanks very much. I'd prefer that you be the first to test it ;)
Re: [patch 61/61] lock validator: enable lock validator in Kconfig
In reply to Ingo MolnarHi,
lib/Kconfig.debug config DEBUG_SPINLOCK · line 189
Quoted 11 lines · Ingo Molnar
Index: linux/lib/Kconfig.debug
===================================================================lib/Kconfig.debug +3
-0@@ -184,6 +184,173 @@ config DEBUG_SPINLOCK best used in conjunction with the NMI watchdog so that spinlock deadlocks are also debuggable. +config PROVE_SPIN_LOCKING + bool "Prove spin-locking correctness" + default y
Could you please keep all the defaults in a separate -mm-only patch, so it doesn't get merged?
There are also a number of dependencies on DEBUG_KERNEL missing, it completely breaks the debugging menu.
lib/Kconfig.debug config DEBUG_SPINLOCK · line 338
Quoted 4 lines
lib/Kconfig.debug +4
-0+config LOCKDEP + bool + default y + depends on PROVE_SPIN_LOCKING || PROVE_RW_LOCKING || PROVE_MUTEX_LOCKING || PROVE_RWSEM_LOCKING
This can be written shorter as:
config LOCKDEP
def_bool PROVE_SPIN_LOCKING || PROVE_RW_LOCKING || PROVE_MUTEX_LOCKING || PROVE_RWSEM_LOCKING
bye, Roman
Re: [patch 61/61] lock validator: enable lock validator in Kconfig
Quoted 6 lines · Roman Zippel
lib/Kconfig.debug config DEBUG_SPINLOCK · line 189
Quoted 3 lines
lib/Kconfig.debug +3
-0+config PROVE_SPIN_LOCKING + bool "Prove spin-locking correctness" + default yCould you please keep all the defaults in a separate -mm-only patch, so it doesn't get merged?
yep - the default got removed.
Quoted 2 lines
There are also a number of dependencies on
DEBUG_KERNELmissing, it completely breaks the debugging menu.
i have solved this problem in current -mm by making more advanced versions of lock debugging (allocation/exit checks, validator) depend on more basic lock debugging options. All the basic lock debugging options have a DEBUG_KERNEL dependency, which thus gets inherited by the other options as well.
Quoted 9 lines
lib/Kconfig.debug config DEBUG_SPINLOCK · line 338
Quoted 4 lines
lib/Kconfig.debug +4
-0+config LOCKDEP + bool + default y + depends on PROVE_SPIN_LOCKING || PROVE_RW_LOCKING || PROVE_MUTEX_LOCKING || PROVE_RWSEM_LOCKINGThis can be written shorter as:
config LOCKDEP
def_bool PROVE_SPIN_LOCKING || PROVE_RW_LOCKING || PROVE_MUTEX_LOCKING || PROVE_RWSEM_LOCKING
ok, done. (Btw., there's tons of other Kconfig code though that uses the bool + depends syntax though, and def_bool usage is quite rare.)
Ingo
Re: [patch 61/61] lock validator: enable lock validator in Kconfig
Hi,
Quoted 4 lines · Ingo Molnar
Quoted 2 lines
Could you please keep all the defaults in a separate -mm-only patch, so it doesn't get merged?
yep - the default got removed.
Thanks.
Quoted 7 lines
Quoted 7 lines
lib/Kconfig.debug config DEBUG_SPINLOCK · line 338
Quoted 4 lines
lib/Kconfig.debug +4
-0+config LOCKDEP + bool + default y + depends on PROVE_SPIN_LOCKING || PROVE_RW_LOCKING || PROVE_MUTEX_LOCKING || PROVE_RWSEM_LOCKINGThis can be written shorter as:
Quoted 5 lines
Quoted 2 lines
config LOCKDEP
def_bool PROVE_SPIN_LOCKING || PROVE_RW_LOCKING || PROVE_MUTEX_LOCKING || PROVE_RWSEM_LOCKINGok, done. (Btw., there's tons of other
Kconfigcode though that uses the bool + depends syntax though, anddef_boolusage is quite rare.)
The new syntax was added later, so everything that was converted uses the basic syntax and is still copied around a lot (where it's probably also doesn't help that it's not properly documented yet). I'm still planing to go through this and convert most of them...
bye, Roman
Quoted 6 lines · Ingo Molnar
We are pleased to announce the first release of the "lock dependency correctness validator" kernel debugging feature, which can be downloaded from:
[snip]
I get this while loading cpufreq modules
=====================================================
[ BUG: possible circular locking deadlock detected! ]
-----------------------------------------------------
modprobe/1942 is trying to acquire lock:
(&anon_vma->lock){--..}, at: [<c10609cf>] anon_vma_link+0x1d/0xc9
but task is already holding lock:
(&mm->mmap_sem/1){--..}, at: [<c101e5a0>] copy_process+0xbc6/0x1519
which lock already depends on the new lock,
which could lead to circular deadlocks!
the existing dependency chain (in reverse order) is:
-> #1 (cpucontrol){--..}:
[<c10394be>] lockdep_acquire+0x69/0x82
[<c11ed759>] __mutex_lock_slowpath+0xd0/0x347
[<c11ed9ec>] mutex_lock+0x1c/0x1f
[<c103dda5>] __lock_cpu_hotplug+0x36/0x56
[<c103ddde>] lock_cpu_hotplug+0xa/0xc
[<c1199e06>] __cpufreq_driver_target+0x15/0x50
[<c119a1c2>] cpufreq_governor_performance+0x1a/0x20
[<c1198b0a>] __cpufreq_governor+0xa0/0x1a9
[<c1198ce2>] __cpufreq_set_policy+0xcf/0x100
[<c11991c6>] cpufreq_set_policy+0x2d/0x6f
[<c1199cae>] cpufreq_add_dev+0x34f/0x492
[<c114b8c8>] sysdev_driver_register+0x58/0x9b
[<c119a036>] cpufreq_register_driver+0x80/0xf4
[<fd97b02a>] ct_get_next+0x17/0x3f [ip_conntrack]
[<c10410e1>] sys_init_module+0xa6/0x230
[<c11ef9ab>] sysenter_past_esp+0x54/0x8d-> #0 (&anon_vma->lock){--..}:
[<c10394be>] lockdep_acquire+0x69/0x82
[<c11ed759>] __mutex_lock_slowpath+0xd0/0x347
[<c11ed9ec>] mutex_lock+0x1c/0x1f
[<c11990eb>] cpufreq_update_policy+0x34/0xd8
[<fd9ad50b>] cpufreq_stat_cpu_callback+0x1b/0x7c [cpufreq_stats]
[<fd9b007d>] cpufreq_stats_init+0x7d/0x9b [cpufreq_stats]
[<c10410e1>] sys_init_module+0xa6/0x230
[<c11ef9ab>] sysenter_past_esp+0x54/0x8dother info that might help us debug this:
1 locks held by modprobe/1942:
#0: (cpucontrol){--..}, at: [<c11ed9ec>] mutex_lock+0x1c/0x1f
stack backtrace: <c1003f36> show_trace+0xd/0xf <c1004449> dump_stack+0x17/0x19 <c103863e> print_circular_bug_tail+0x59/0x64 <c1038e91> __lockdep_acquire+0x848/0xa39 <c10394be> lockdep_acquire+0x69/0x82 <c11ed759> __mutex_lock_slowpath+0xd0/0x347 <c11ed9ec> mutex_lock+0x1c/0x1f <c11990eb> cpufreq_update_policy+0x34/0xd8 <fd9ad50b> cpufreq_stat_cpu_callback+0x1b/0x7c [cpufreq_stats] <fd9b007d> cpufreq_stats_init+0x7d/0x9b [cpufreq_stats] <c10410e1> sys_init_module+0xa6/0x230 <c11ef9ab> sysenter_past_esp+0x54/0x8d
Here is dmesg http://www.stardust.webpages.pl/files/lockdep/2.6.17-rc4-mm3-lockdep1/lockdep-dmesg3
Here is config
http://www.stardust.webpages.pl/files/lockdep/2.6.17-rc4-mm3-lockdep1/lockdep-config2
BTW I still must revert lockdep-serial.patch - it doesn't compile on my gcc 4.1.1
Regards,
Michal
Signature · 3 lines
Michal K. K. Piotrowski LTG - Linux Testers Group (http://www.stardust.webpages.pl/ltg/wiki/)
Quoted 17 lines · Michal Piotrowski
Quoted 6 lines · Ingo Molnar
We are pleased to announce the first release of the "lock dependency correctness validator" kernel debugging feature, which can be downloaded from:
[snip]
I get this while loading cpufreq modules
=====================================================
[ BUG: possible circular locking deadlock detected! ]
-----------------------------------------------------
modprobe/1942 is trying to acquire lock:
(&anon_vma->lock){--..}, at: [<c10609cf>]anon_vma_link+0x1d/0xc9
Quoted 5 lines
but task is already holding lock:
(&mm->mmap_sem/1){--..}, at: [<c101e5a0>]copy_process+0xbc6/0x1519which lock already depends on the new lock,
which could lead to circular deadlocks!
hm, this one could perhaps be a real bug. Dave: lockdep complains about having observed:
anon_vma->lock => mm->mmap_sem mm->mmap_sem => anon_vma->lock
locking sequences, in the cpufreq code. Is there some special runtime behavior that still makes this safe, or is it a real bug?
Quoted 6 lines
stack backtrace: <c1003f36> show_trace+0xd/0xf <c1004449> dump_stack+0x17/0x19 <c103863e> print_circular_bug_tail+0x59/0x64 <c1038e91> __lockdep_acquire+0x848/0xa39 <c10394be> lockdep_acquire+0x69/0x82 <c11ed759> __mutex_lock_slowpath+0xd0/0x347
there's one small detail to improve future lockdep printouts: please set CONFIG_STACK_BACKTRACE_COLS=1, so that the backtrace is more readable. (i'll change the code to force that when CONFIG_LOCKDEP is enabled)
Quoted 2 lines
BTW I still must revert lockdep-serial.patch - it doesn't compile on my gcc 4.1.1
ok, will check this.
Ingo
Quoted 12 lines · Ingo Molnar
Quoted 11 lines
=====================================================
[ BUG: possible circular locking deadlock detected! ]
-----------------------------------------------------
modprobe/1942 is trying to acquire lock:
(&anon_vma->lock){--..}, at: [<c10609cf>]anon_vma_link+0x1d/0xc9but task is already holding lock:
(&mm->mmap_sem/1){--..}, at: [<c101e5a0>]copy_process+0xbc6/0x1519which lock already depends on the new lock,
which could lead to circular deadlocks!
Quoted 8 lines
hm, this one could perhaps be a real bug. Dave: lockdep complains about having observed:
anon_vma->lock => mm->mmap_sem mm->mmap_sem => anon_vma->locklocking sequences, in the cpufreq code. Is there some special runtime behavior that still makes this safe, or is it a real bug?
I'm feeling a bit overwhelmed by the voluminous output of this checker. Especially as (directly at least) cpufreq doesn't touch vma's, or mmap's.
The first stack trace it shows has us down in the bowels of cpu hotplug, where we're taking the cpucontrol sem. The second stack trace shows us in cpufreq_update_policy taking a per-cpu data->lock semaphore.
Now, I notice this is modprobe triggering this, and this *looks* like we're loading two modules simultaneously (the first trace is from a scaling driver like powernow-k8 or the like, whilst the second trace is from cpufreq-stats).
How on earth did we get into this situation? module loading is supposed to be serialised on the module_mutex no ?
It's been a while since a debug patch has sent me in search of paracetamol ;)
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Quoted 3 lines
I'm feeling a bit overwhelmed by the voluminous output of this checker. Especially as (directly at least) cpufreq doesn't touch vma's, or mmap's.
the reporter doesn't have CONFIG_KALLSYMS_ALL enabled which gives sometimes misleading backtraces (should lockdep just enable KALLSYMS_ALL to get more useful bugreports?)
the problem is this, there are 2 scenarios in this bug:
One
---store_scaling_governor takes policy->lock and then calls __cpufreq_set_policy __cpufreq_set_policy calls __cpufreq_governor__cpufreq_governor calls __cpufreq_driver_target via cpufreq_governor_performance __cpufreq_driver_target calls lock_cpu_hotplug() (which takes the hotplug lock)
Two
---cpufreq_stats_init lock_cpu_hotplug() and then calls cpufreq_stat_cpu_callback cpufreq_stat_cpu_callback calls cpufreq_update_policy cpufreq_update_policy takes the policy->lock
so this looks like a real honest AB-BA deadlock to me...
Hi,
Quoted 7 lines · Arjan van de Ven
Quoted 3 lines
I'm feeling a bit overwhelmed by the voluminous output of this checker. Especially as (directly at least) cpufreq doesn't touch vma's, or mmap's.
the reporter doesn't have
CONFIG_KALLSYMS_ALLenabled which gives sometimes misleading backtraces (should lockdep just enableKALLSYMS_ALLto get more useful bugreports?)
Here is bug with CONFIG_KALLSYMS_ALL enabled.
=====================================================
[ BUG: possible circular locking deadlock detected! ]
-----------------------------------------------------
modprobe/1950 is trying to acquire lock:
(&sighand->siglock){.+..}, at: [<c102b632>] do_notify_parent+0x12b/0x1b9
but task is already holding lock:
(tasklist_lock){..-<B1>}, at: [<c1023473>] do_exit+0x608/0xa43
which lock already depends on the new lock,
which could lead to circular deadlocks!
the existing dependency chain (in reverse order) is:
-> #1 (cpucontrol){--..}:
[<c10394be>] lockdep_acquire+0x69/0x82
[<c11ed729>] __mutex_lock_slowpath+0xd0/0x347
[<c11ed9bc>] mutex_lock+0x1c/0x1f
[<c103dda5>] __lock_cpu_hotplug+0x36/0x56
[<c103ddde>] lock_cpu_hotplug+0xa/0xc
[<c1199dd6>] __cpufreq_driver_target+0x15/0x50
[<c119a192>] cpufreq_governor_performance+0x1a/0x20
[<c1198ada>] __cpufreq_governor+0xa0/0x1a9
[<c1198cb2>] __cpufreq_set_policy+0xcf/0x100
[<c1199196>] cpufreq_set_policy+0x2d/0x6f
[<c1199c7e>] cpufreq_add_dev+0x34f/0x492
[<c114b898>] sysdev_driver_register+0x58/0x9b
[<c119a006>] cpufreq_register_driver+0x80/0xf4
[<fd91402a>] ipt_local_out_hook+0x2a/0x65 [iptable_filter]
[<c10410e1>] sys_init_module+0xa6/0x230
[<c11ef97b>] sysenter_past_esp+0x54/0x8d-> #0 (&sighand->siglock){.+..}:
[<c10394be>] lockdep_acquire+0x69/0x82
[<c11ed729>] __mutex_lock_slowpath+0xd0/0x347
[<c11ed9bc>] mutex_lock+0x1c/0x1f
[<c11990bb>] cpufreq_update_policy+0x34/0xd8
[<fd9a350b>] cpufreq_stat_cpu_callback+0x1b/0x7c [cpufreq_stats]
[<fd9a607d>] cpufreq_stats_init+0x7d/0x9b [cpufreq_stats]
[<c10410e1>] sys_init_module+0xa6/0x230
[<c11ef97b>] sysenter_past_esp+0x54/0x8dother info that might help us debug this:
1 locks held by modprobe/1950:
#0: (cpucontrol){--..}, at: [<c11ed9bc>] mutex_lock+0x1c/0x1f
stack backtrace: [<c1003ed6>] show_trace+0xd/0xf [<c10043e9>] dump_stack+0x17/0x19 [<c103863e>] print_circular_bug_tail+0x59/0x64 [<c1038e91>] __lockdep_acquire+0x848/0xa39 [<c10394be>] lockdep_acquire+0x69/0x82 [<c11ed729>] __mutex_lock_slowpath+0xd0/0x347 [<c11ed9bc>] mutex_lock+0x1c/0x1f [<c11990bb>] cpufreq_update_policy+0x34/0xd8 [<fd9a350b>] cpufreq_stat_cpu_callback+0x1b/0x7c [cpufreq_stats] [<fd9a607d>] cpufreq_stats_init+0x7d/0x9b [cpufreq_stats] [<c10410e1>] sys_init_module+0xa6/0x230 [<c11ef97b>] sysenter_past_esp+0x54/0x8d
Quoted 11 lines
the problem is this, there are 2 scenarios in this bug:
One
---store_scaling_governortakespolicy->lockand then calls__cpufreq_set_policy__cpufreq_set_policycalls__cpufreq_governor__cpufreq_governorcalls__cpufreq_driver_targetviacpufreq_governor_performance__cpufreq_driver_targetcallslock_cpu_hotplug()(which takes the hotplug lock)
Quoted 8 lines
Two
---cpufreq_stats_initlock_cpu_hotplug()and then callscpufreq_stat_cpu_callbackcpufreq_stat_cpu_callbackcallscpufreq_update_policycpufreq_update_policytakes thepolicy->lockso this looks like a real honest AB-BA deadlock to me...
Regards,
Michal
Signature · 3 lines
Michal K. K. Piotrowski LTG - Linux Testers Group (http://www.stardust.webpages.pl/ltg/wiki/)
Quoted 8 lines · Arjan van de Ven
One
---store_scaling_governortakespolicy->lockand then calls__cpufreq_set_policy__cpufreq_set_policycalls__cpufreq_governor__cpufreq_governorcalls__cpufreq_driver_targetviacpufreq_governor_performance__cpufreq_driver_targetcallslock_cpu_hotplug()(which takes the hotplug lock)
Quoted 8 lines
Two
---cpufreq_stats_initlock_cpu_hotplug()and then callscpufreq_stat_cpu_callbackcpufreq_stat_cpu_callbackcallscpufreq_update_policycpufreq_update_policytakes thepolicy->lockso this looks like a real honest AB-BA deadlock to me...
This looks a little clearer this morning. I missed the fact that sys_init_module isn't completely serialised, only the loading part. ->init routines can and will be called in parallel.
I don't see where cpufreq_update_policy takes policy->lock though. In my tree it just takes the per-cpu data->lock.
Time for more wake-up juice? or am I missing something obvious again?
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Quoted 17 lines · Dave Jones
Quoted 15 lines · Arjan van de Ven
One
---store_scaling_governortakespolicy->lockand then calls__cpufreq_set_policy__cpufreq_set_policycalls__cpufreq_governor__cpufreq_governorcalls__cpufreq_driver_targetviacpufreq_governor_performance__cpufreq_driver_targetcallslock_cpu_hotplug()(which takes the hotplug lock)Two
---cpufreq_stats_initlock_cpu_hotplug()and then callscpufreq_stat_cpu_callbackcpufreq_stat_cpu_callbackcallscpufreq_update_policycpufreq_update_policytakes thepolicy->lock
Quoted 8 lines
Quoted 1 line
so this looks like a real honest AB-BA deadlock to me...
This looks a little clearer this morning. I missed the fact that
sys_init_moduleisn't completely serialised, only the loading part. ->init routines can and will be called in parallel.I don't see where
cpufreq_update_policytakespolicy->lockthough. In my tree it just takes the per-cpudata->lock.
isn't that basically the same lock?
Quoted 17 lines · Arjan van de Ven
Quoted 17 lines
Quoted 16 lines
One
---store_scaling_governortakespolicy->lockand then calls__cpufreq_set_policy__cpufreq_set_policycalls__cpufreq_governor__cpufreq_governorcalls__cpufreq_driver_targetviacpufreq_governor_performance__cpufreq_driver_targetcallslock_cpu_hotplug()(which takes the hotplug lock)Two
---cpufreq_stats_initlock_cpu_hotplug()and then callscpufreq_stat_cpu_callbackcpufreq_stat_cpu_callbackcallscpufreq_update_policycpufreq_update_policytakes thepolicy->lockso this looks like a real honest AB-BA deadlock to me...
Quoted 8 lines
Quoted 6 lines
This looks a little clearer this morning. I missed the fact that
sys_init_moduleisn't completely serialised, only the loading part. ->init routines can and will be called in parallel.I don't see where
cpufreq_update_policytakespolicy->lockthough. In my tree it just takes the per-cpudata->lock.isn't that basically the same lock?
Ugh, I've completely forgotten how this stuff fits together.
Dominik, any clues ?
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Dominik Brodowski
maintainerHi,
Quoted 23 lines · Dave Jones
Quoted 21 lines · Arjan van de Ven
Quoted 21 lines
Quoted 8 lines
One
---store_scaling_governortakespolicy->lockand then calls__cpufreq_set_policy__cpufreq_set_policycalls__cpufreq_governor__cpufreq_governorcalls__cpufreq_driver_targetviacpufreq_governor_performance__cpufreq_driver_targetcallslock_cpu_hotplug()(which takes the hotplug lock)Quoted 8 lines
Two
---cpufreq_stats_initlock_cpu_hotplug()and then callscpufreq_stat_cpu_callbackcpufreq_stat_cpu_callbackcallscpufreq_update_policycpufreq_update_policytakes thepolicy->lockso this looks like a real honest AB-BA deadlock to me...
This looks a little clearer this morning. I missed the fact that
sys_init_moduleisn't completely serialised, only the loading part. ->init routines can and will be called in parallel.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I don't see where
cpufreq_update_policytakespolicy->lockthough. In my tree it just takes the per-cpudata->lock.isn't that basically the same lock?
Ugh, I've completely forgotten how this stuff fits together.
Dominik, any clues ?
That's indeed a possible deadlock situation -- what's the cpufreq_update_policy() call needed for in cpufreq_stat_cpu_callback anyway?
Dominik
Quoted 2 lines · Dominik Brodowski
That's indeed a possible deadlock situation -- what's the
cpufreq_update_policy()call needed for incpufreq_stat_cpu_callbackanyway?
I was hoping you could enlighten me :)
I started picking through history with gitk, but my tk install uses fonts that make my eyes bleed. My kingdom for a 'git annotate'..
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Dave> I was hoping you could enlighten me :) I started picking Dave> through history with gitk, but my tk install uses fonts that Dave> make my eyes bleed. My kingdom for a 'git annotate'..
Heh -- try "git annotate" or "git blame". I think you need git 1.3.x for that... details of where to send your kingdom forthcoming...
- R.
Quoted 6 lines · Roland Dreier
Dave> I was hoping you could enlighten me :) I started picking Dave> through history with gitk, but my tk install uses fonts that Dave> make my eyes bleed. My kingdom for a 'git annotate'..
Heh -- try "git annotate" or "git blame". I think you need git 1.3.x for that... details of where to send your kingdom forthcoming...
How on earth did I miss that? Thanks for the pointer.
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Quoted 6 lines · Roland Dreier
Dave> I was hoping you could enlighten me :) I started picking Dave> through history with gitk, but my tk install uses fonts that Dave> make my eyes bleed. My kingdom for a 'git annotate'..
Heh -- try "git annotate" or "git blame". I think you need git 1.3.x for that... details of where to send your kingdom forthcoming...
i use qgit, which is GTK based and thus uses the native desktop fonts.
Ingo
Quoted 11 lines · Ingo Molnar
Quoted 6 lines · Roland Dreier
Dave> I was hoping you could enlighten me :) I started picking Dave> through history with gitk, but my tk install uses fonts that Dave> make my eyes bleed. My kingdom for a 'git annotate'..
Heh -- try "git annotate" or "git blame". I think you need git 1.3.x for that... details of where to send your kingdom forthcoming...
i use qgit, which is GTK based and thus uses the native desktop fonts.
and qgit annotates source files in the background while you are viewing them, and then you can click on lines to jump to the last commit that touched it. It doesnt need latest GIT, qgit always did this (by itself).
Ingo
Quoted 11 lines · Ingo Molnar
Quoted 6 lines · Roland Dreier
Dave> I was hoping you could enlighten me :) I started picking Dave> through history with gitk, but my tk install uses fonts that Dave> make my eyes bleed. My kingdom for a 'git annotate'..
Heh -- try "git annotate" or "git blame". I think you need git 1.3.x for that... details of where to send your kingdom forthcoming...
i use qgit, which is GTK based and thus uses the native desktop fonts.
GTK? A typo, I suppose.
QGit is a git GUI viewer built on Qt/C++ (that I hope will be added to the git.git tree soon).
Ciao,
Signature · 2 lines
Paolo http://paolociarrocchi.googlepages.com
Quoted 1 line · Paolo Ciarrocchi
GTK? A typo, I suppose.
brainfart, sorry :)
Quoted 2 lines
QGit is a git GUI viewer built on Qt/C++ (that I hope will be added to the git.git tree soon).
yeah.
Ingo
Quoted 27 lines · Dominik Brodowski
Quoted 26 lines · Dave Jones
Quoted 24 lines · Arjan van de Ven
Quoted 23 lines
Quoted 8 lines
One
---store_scaling_governortakespolicy->lockand then calls__cpufreq_set_policy__cpufreq_set_policycalls__cpufreq_governor__cpufreq_governorcalls__cpufreq_driver_targetviacpufreq_governor_performance__cpufreq_driver_targetcallslock_cpu_hotplug()(which takes the hotplug lock)Quoted 8 lines
Two
---cpufreq_stats_initlock_cpu_hotplug()and then callscpufreq_stat_cpu_callbackcpufreq_stat_cpu_callbackcallscpufreq_update_policycpufreq_update_policytakes thepolicy->lockso this looks like a real honest AB-BA deadlock to me...
This looks a little clearer this morning. I missed the fact that
sys_init_moduleisn't completely serialised, only the loading part. ->init routines can and will be called in parallel.I don't see where
cpufreq_update_policytakespolicy->lockthough. In my tree it just takes the per-cpudata->lock.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
isn't that basically the same lock?
Ugh, I've completely forgotten how this stuff fits together.
Dominik, any clues ?
That's indeed a possible deadlock situation -- what's the
cpufreq_update_policy()call needed for incpufreq_stat_cpu_callbackanyway?
Oh wow. Reading the commit message of this change rings alarm bells.
change c32b6b8e524d2c337767d312814484d9289550cf has this to say..
[PATCH] create and destroy cpufreq sysfs entries based on cpu notifiers
cpufreq entries in sysfs should only be populated when CPU is online state.
When we either boot with maxcpus=x and then boot the other cpus by echoing
to sysfs online file, these entries should be created and destroyed when CPU_DEAD is notified. Same treatement as cache entries under sysfs.
We place the processor in the lowest frequency, so hw managed P-State transitions can still work on the other threads to save power.
Primary goal was to just make these directories appear/disapper dynamically.
There is one in this patch i had to do, which i really dont like myself but probably best if someone handling the cpufreq infrastructure could give this code right treatment if this is not acceptable. I guess its probably good for the first cut.
- Converting lock_cpu_hotplug()/unlock_cpu_hotplug() to disable/enable preempt. The locking was smack in the middle of the notification path, when the hotplug is already holding the lock. I tried another solution to avoid this so avoid taking locks if we know we are from notification path. The solution was getting very ugly and i decided this was probably good for this iteration until someone who understands cpufreq could do a better job than me.
So, that last part pretty highlights that we knew about this problem, and meant to come back and fix it later. Surprise surprise, no one came back and fixed it.
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Quoted 3 lines · Dave Jones
So, that last part pretty highlights that we knew about this problem, and meant to come back and fix it later. Surprise surprise, no one came back and fixed it.
There was another iteration after his, and currently we keep track of the owner in lock_cpu_hotplug()->__lock_cpu_hotplug(). So if we are in same thread context we dont acquire locks.
if (lock_cpu_hotplug_owner != current) {
if (interruptible)
ret = down_interruptible(&cpucontrol);
else
down(&cpucontrol);
}the lock and unlock kept track of the depth as well, so we know when to release
We didnt hear any better suggestions (from cpufreq folks), so we left it in that state (atlease the same thread doenst try to take the lock twice) that resulted in deadlocks earlier.
Signature · 3 lines
Cheers, Ashok Raj - Open Source Technology Center
Quoted 18 lines · Ashok Raj
Quoted 3 lines · Dave Jones
So, that last part pretty highlights that we knew about this problem, and meant to come back and fix it later. Surprise surprise, no one came back and fixed it.
There was another iteration after his, and currently we keep track of the owner in lock_cpu_hotplug()->__lock_cpu_hotplug(). So if we are in same thread context we dont acquire locks.
if (lock_cpu_hotplug_owner != current) { if (interruptible) ret = down_interruptible(&cpucontrol); else down(&cpucontrol); }
Quoted 1 line
the lock and unlock kept track of the depth as well, so we know when to release
Can we please kill this recursive locking hack in the cpu hotplug code in 2.6.18/soon? It's papering over the real problem, and I worry that if it's allowed to sit there, other users will start to take "advantage" of it. Perhaps, at the very least, cpufreq could be made to handle this itself instead of polluting the core code...
Quoted 3 lines
We didnt hear any better suggestions (from cpufreq folks), so we left it in that state (atlease the same thread doenst try to take the lock twice) that resulted in deadlocks earlier.
Fix (and document!) the ordering of lock acquisitions in cpufreq?
PATCH 1/1 lock validator: select KALLSYMS_ALL
In reply to Arjan van de VenQuoted 3 lines · Arjan van de Ven
the reporter doesn't have
CONFIG_KALLSYMS_ALLenabled which gives sometimes misleading backtraces (should lockdep just enableKALLSYMS_ALLto get more useful bugreports?)
agreed - the patch below does that.
-----------------------
Subject: lock validator: select KALLSYMS_ALL
From: Ingo Molnar <[email protected]>
all the kernel symbol printouts make alot more sense if KALLSYMS_ALL is enabled too - force it on if lockdep is enabled.
--- lib/Kconfig.debug | 1 + 1 file changed, 1 insertion(+)
lib/Kconfig.debug +1 -0
@@ -342,6 +342,7 @@ config LOCKDEP default y select FRAME_POINTER select KALLSYMS + select KALLSYMS_ALL depends on PROVE_SPIN_LOCKING || PROVE_RW_LOCKING || PROVE_MUTEX_LOCKING || PROVE_RWSEM_LOCKING config DEBUG_LOCKDEP
Hi,
Quoted 26 lines · Dave Jones
Quoted 12 lines · Ingo Molnar
Quoted 11 lines
=====================================================
[ BUG: possible circular locking deadlock detected! ]
-----------------------------------------------------
modprobe/1942 is trying to acquire lock:
(&anon_vma->lock){--..}, at: [<c10609cf>]anon_vma_link+0x1d/0xc9but task is already holding lock:
(&mm->mmap_sem/1){--..}, at: [<c101e5a0>]copy_process+0xbc6/0x1519which lock already depends on the new lock,
which could lead to circular deadlocks!Quoted 8 lines
hm, this one could perhaps be a real bug. Dave: lockdep complains about having observed:
anon_vma->lock => mm->mmap_sem mm->mmap_sem => anon_vma->locklocking sequences, in the cpufreq code. Is there some special runtime behavior that still makes this safe, or is it a real bug?
I'm feeling a bit overwhelmed by the voluminous output of this checker. Especially as (directly at least) cpufreq doesn't touch vma's, or mmap's.
Quoted 8 lines
The first stack trace it shows has us down in the bowels of cpu hotplug, where we're taking the cpucontrol sem. The second stack trace shows us in
cpufreq_update_policytaking a per-cpudata->locksemaphore.Now, I notice this is modprobe triggering this, and this *looks* like we're loading two modules simultaneously (the first trace is from a scaling driver like powernow-k8 or the like, whilst the second trace is from cpufreq-stats).
/etc/init.d/cpuspeed starts very early
$ ls /etc/rc5.d/ | grep cpu S06cpuspeed
I have this in my /etc/rc.local
modprobe -i cpufreq_conservative
modprobe -i cpufreq_ondemand
modprobe -i cpufreq_powersave
modprobe -i cpufreq_stats
modprobe -i cpufreq_userspace
modprobe -i freq_table
Quoted 2 lines
How on earth did we get into this situation?
Just before gdm starts, while /etc/rc.local is processed.
Quoted 6 lines
module loading is supposed
to be serialised on themodule_mutexno ?It's been a while since a debug patch has sent me in search of paracetamol ;)
Dave
Regards,
Michal
Signature · 3 lines
Michal K. K. Piotrowski LTG - Linux Testers Group (http://www.stardust.webpages.pl/ltg/wiki/)
Quoted 10 lines · Michal Piotrowski
Quoted 6 lines · Ingo Molnar
We are pleased to announce the first release of the "lock dependency correctness validator" kernel debugging feature, which can be downloaded from:
[snip]
I get this while loading cpufreq modules
can you enable CONFIG_KALLSYMS_ALL ? that will give a more accurate debug output...
Quoted 2 lines · On Mon, 29 May 2006 23:21:09 +0200 Ingo Molnar <[email protected]> wrote:
We are pleased to announce the first release of the "lock dependency correctness validator" kernel debugging feature
What are the runtime speed and space costs of enabling this?
Quoted 4 lines · Andrew Morton
Quoted 2 lines
We are pleased to announce the first release of the "lock dependency correctness validator" kernel debugging feature
What are the runtime speed and space costs of enabling this?
The RAM space costs are estimated in the bootup info printout:
... MAX_LOCKDEP_SUBTYPES: 8 ... MAX_LOCK_DEPTH: 30 ... MAX_LOCKDEP_KEYS: 2048 ... TYPEHASH_SIZE: 1024 ... MAX_LOCKDEP_ENTRIES: 8192 ... MAX_LOCKDEP_CHAINS: 8192 ... CHAINHASH_SIZE: 4096
memory used by lock dependency info: 696 kB
per task-struct memory footprint: 1200 bytes
Plus every lock now embedds the lock_map structure which is 10 pointers. That is the biggest direct dynamic RAM cost.
There are also a few embedded keys in .data but they are small.
The .text overhead mostly comes from the subsystem itself - which is around 20K of .text. The callbacks are not inlined most of the time - there are about 200 of them right now, which should be another +1-2K of .text cost.
The runtime cycle cost is significant if CONFIG_DEBUG_LOCKDEP [lock validator self-consistency checks] is enabled - then we take a global lock from every lock operation which kills scalability.
If DEBUG_LOCKDEP is disabled then it's OK - smaller than DEBUG_SLAB. In this case we have the lock-stack maintainance overhead, the irq-trace callbacks and a lockless hash-lookup per lock operation. All of that overhead is O(1) and lockless so it shouldnt change fundamental characteristics anywhere.
Ingo
Quoted 10 lines · Ingo Molnar
The easiest way to try lockdep on a testbox is to apply the combo patch to 2.6.17-rc4-mm3. The patch order is:
http://kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.17-rc4.tar.bz2
http://kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.17-rc4/2.6.17-rc4-mm3/2.6.17-rc4-mm3.bz2
http://redhat.com/~mingo/lockdep-patches/lockdep-combo.patchdo 'make oldconfig' and accept all the defaults for new config options - reboot into the kernel and if everything goes well it should boot up fine and you should have
/proc/lockdepand/proc/lockdep_statsfiles.
Darn. It said all tests passed, then oopsed.
(have .config all gzipped up if you want it)
-Mike
BUG: unable to handle kernel NULL pointer dereference at virtual address 00000000 printing eip: b103a872 *pde = 00000000 Oops: 0000 [#1] PREEMPT SMP last sysfs file: Modules linked in: CPU: 0 EIP: 0060:[<b103a872>] Not tainted VLI EFLAGS: 00010083 (2.6.17-rc4-mm3-smp #157)
EIP is at count_matching_names+0x5b/0xa2
eax: b15074a8 ebx: 00000000 ecx: b165c430 edx: b165b320
esi: 00000000 edi: b1410423 ebp: dfe20e74 esp: dfe20e68
ds: 007b es: 007b ss: 0068
Process idle (pid: 1, threadinfo=dfe20000 task=effc1470)
Stack: 000139b0 b165c430 00000000 dfe20ec8 b103d442 b1797a6c b1797a64 effc1470
b1797a64 00000004 b1797a50 00000000 b15074a8 effc1470 dfe20ef8 b106da88
b169d0a8 b1797a64 dfe20f52 0000000a b106dec7 00000282 dfe20000 00000000
Call Trace:
<b1003d73> show_stack_log_lvl+0x9e/0xc3 <b1003f80> show_registers+0x1ac/0x237
<b100413d> die+0x132/0x2fb <b101a083> do_page_fault+0x5cf/0x656
<b10038a7> error_code+0x4f/0x54 <b103d442> __lockdep_acquire+0xa6f/0xc32
<b103d9f8> lockdep_acquire+0x61/0x77 <b13d27f3> _spin_lock+0x2e/0x42
<b102b03a> register_sysctl_table+0x4e/0xaa <b15a463a> sched_init_smp+0x411/0x41e
<b100035d> init+0xbd/0x2c6 <b1001005> kernel_thread_helper+0x5/0xb
Code: 92 50 b1 74 5d 8b 41 10 2b 41 14 31 db 39 42 10 75 0d eb 53 8b 41 10 2b 41 14 3b 42 10 74 48 8b b2 a0 00 00 00 8b b9 a0 00 00 00 <ac> ae 75 08 84 c0 75 f8 31 c0 eb 04 19 c0 0c 01 85 c0 75 0b 8b1151 list_for_each_entry(type, &all_lock_types, lock_entry) {
1152 if (new_type->key - new_type->subtype == type->key)
1153 return type->name_version;
1154 if (!strcmp(type->name, new_type->name)) <--kaboom
1155 count = max(count, type->name_version);
1156 }
EIP: [<b103a872>] count_matching_names+0x5b/0xa2 SS:ESP 0068:dfe20e68
Kernel panic - not syncing: Attempted to kill init! BUG: warning at arch/i386/kernel/smp.c:537/smp_call_function() <b1003dd2> show_trace+0xd/0xf <b10044c0> dump_stack+0x17/0x19 <b10129ff> smp_call_function+0x11d/0x122 <b1012a22> smp_send_stop+0x1e/0x31 <b1022f4b> panic+0x60/0x1d5 <b10267fa> do_exit+0x613/0x94f <b1004306> do_trap+0x0/0x9e <b101a083> do_page_fault+0x5cf/0x656 <b10038a7> error_code+0x4f/0x54 <b103d442> __lockdep_acquire+0xa6f/0xc32 <b103d9f8> lockdep_acquire+0x61/0x77 <b13d27f3> _spin_lock+0x2e/0x42 <b102b03a> register_sysctl_table+0x4e/0xaa <b15a463a> sched_init_smp+0x411/0x41e <b100035d> init+0xbd/0x2c6 <b1001005> kernel_thread_helper+0x5/0xb BUG: NMI Watchdog detected LOCKUP on CPU1, eip b103cc64, registers: Modules linked in: CPU: 1 EIP: 0060:[<b103cc64>] Not tainted VLI EFLAGS: 00000086 (2.6.17-rc4-mm3-smp #157)
EIP is at __lockdep_acquire+0x291/0xc32
eax: 00000000 ebx: 000001d7 ecx: b16bf938 edx: 00000000
esi: 00000000 edi: b16bf938 ebp: effc4ea4 esp: effc4e58
ds: 007b es: 007b ss: 0068
Process idle (pid: 0, threadinfo=effc4000 task=effc0a50)
Stack: b101d4ce 00000000 effc0fb8 000001d7 effc0a50 b16bf938 00000000 b29b38c8
effc0a50 effc0fb8 00000001 00000000 00000005 00000000 00000000 00000000
00000096 effc4000 00000000 effc4ecc b103d9f8 00000000 00000001 b101d4ce
Call Trace:
<b1003d73> show_stack_log_lvl+0x9e/0xc3 <b1003f80> show_registers+0x1ac/0x237
<b10050d9> die_nmi+0x93/0xeb <b1015af1> nmi_watchdog_tick+0xff/0x20e
<b1004542> do_nmi+0x80/0x249 <b1003912> nmi_stack_correct+0x1d/0x22
<b103d9f8> lockdep_acquire+0x61/0x77 <b13d27f3> _spin_lock+0x2e/0x42
<b101d4ce> scheduler_tick+0xd0/0x381 <b102d47e> update_process_times+0x42/0x61
<b1014f9f> smp_apic_timer_interrupt+0x67/0x78 <b10037ba> apic_timer_interrupt+0x2a/0x30
<b1001e5b> cpu_idle+0x71/0xb8 <b1013c6e> start_secondary+0x3e5/0x46b
<00000000> _stext+0x4efffd68/0x8 <effc4fb4> 0xeffc4fb4
Code: 18 01 90 39 c7 0f 84 2e 02 00 00 8b 50 0c 31 f2 8b 40 08 31 d8 09 c2 75 e2 f0 ff 05 08 8a 61 b1 f0 fe 0d e4 92 50 b1 79 0d f3 90 <80> 3d e4 92 50 b1 00 7e f5 eb ea 8b 55 d4 8b b2 64 05 00 00 85console shuts up ...
Quoted 8 lines · Mike Galbraith
Quoted 7 lines · Ingo Molnar
The easiest way to try lockdep on a testbox is to apply the combo patch to 2.6.17-rc4-mm3. The patch order is:
http://kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.17-rc4.tar.bz2
http://kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.17-rc4/2.6.17-rc4-mm3/2.6.17-rc4-mm3.bz2
http://redhat.com/~mingo/lockdep-patches/lockdep-combo.patch
Quoted 7 lines
Quoted 3 lines
do 'make oldconfig' and accept all the defaults for new config options - reboot into the kernel and if everything goes well it should boot up fine and you should have
/proc/lockdepand/proc/lockdep_statsfiles.Darn. It said all tests passed, then oopsed.
(have .config all gzipped up if you want it)
yes please get me/Ingo the .config; something odd is going on
Quoted 8 lines · Mike Galbraith
Quoted 7 lines · Ingo Molnar
The easiest way to try lockdep on a testbox is to apply the combo patch to 2.6.17-rc4-mm3. The patch order is:
http://kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.17-rc4.tar.bz2
http://kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.17-rc4/2.6.17-rc4-mm3/2.6.17-rc4-mm3.bz2
http://redhat.com/~mingo/lockdep-patches/lockdep-combo.patch
Quoted 5 lines
Quoted 3 lines
do 'make oldconfig' and accept all the defaults for new config options - reboot into the kernel and if everything goes well it should boot up fine and you should have
/proc/lockdepand/proc/lockdep_statsfiles.Darn. It said all tests passed, then oopsed.
does this fix it?
type->name can be NULL legitimately; all places but one check for this already. Fix this off-by-one.
kernel/lockdep.c renamed from kernel/lockdep.c.org +1 -1
@@ -1151,7 +1151,7 @@ int count_matching_names(struct lock_typlist_for_each_entry (type, &all_lock_types, lock_entry) {if (new_type->key - new_type->subtype == type->key)return type->name_version; -if (!strcmp (type->name, new_type->name)) +if (type->name && !strcmp (type->name, new_type->name)) count =max (count, type->name_version); }
Quoted 6 lines · Arjan van de Ven
Quoted 1 line
Darn. It said all tests passed, then oopsed.
does this fix it?
type->namecan be NULL legitimately; all places but one check for this already. Fix this off-by-one.
that used to be the case, but shouldnt happen anymore - with current lockdep code we always pass some string to the lock init code. (that's what lock-init-improvement.patch achieves in essence.) Worst-case the string should be "old_style_spin_init" or "old_style_rw_init".
So Mike please try the other patch i sent - it also adds a debugging check so that we can see where that NULL name comes from. It could be something benign like me forgetting to pass in a string somewhere in the initialization macros, but it could also be something more nasty like an initialize-by-memset assumption.
Ingo
Quoted 3 lines · Mike Galbraith
Darn. It said all tests passed, then oopsed.
(have .config all gzipped up if you want it)
yeah, please.
Quoted 9 lines
EIP: 0060:[<b103a872>] Not tainted VLI EFLAGS: 00010083 (2.6.17-rc4-mm3-smp #157)EIP is at
count_matching_names+0x5b/0xa21151
list_for_each_entry(type, &all_lock_types, lock_entry){
1152 if (new_type->key-new_type->subtype==type->key)
1153 returntype->name_version;
1154 if (!strcmp(type->name,new_type->name)) <--kaboom
1155 count =max(count, type->name_version);
hm, while most code (except the one above) is prepared for type->name being NULL, it should not be NULL. Maybe an uninitialized lock slipped through? Please try the patch below - it both protects against type->name being NULL in this place, and will warn if it finds a NULL lockname.
Ingo
kernel/lockdep.c +3 -2
@@ -1151,7 +1151,7 @@ int count_matching_names(struct lock_typlist_for_each_entry (type, &all_lock_types, lock_entry) {if (new_type->key - new_type->subtype == type->key)return type->name_version; -if (!strcmp (type->name, new_type->name)) +if (type->name && !strcmp (type->name, new_type->name)) count =max (count, type->name_version); }
@@ -1974,7 +1974,8 @@ void lockdep_init_map(struct lockdep_mapif (DEBUG_WARN_ON (!key))return ; - +if (DEBUG_WARN_ON (!name)) +return ;/* * Sanity check, the lock-type key must be persistent: */
Quoted 7 lines · Ingo Molnar
Quoted 3 lines · Mike Galbraith
Darn. It said all tests passed, then oopsed.
(have .config all gzipped up if you want it)
yeah, please.
(sent off list)
Quoted 10 lines
Quoted 9 lines
EIP: 0060:[<b103a872>] Not tainted VLI EFLAGS: 00010083 (2.6.17-rc4-mm3-smp #157)EIP is at
count_matching_names+0x5b/0xa21151
list_for_each_entry(type, &all_lock_types, lock_entry){
1152 if (new_type->key-new_type->subtype==type->key)
1153 returntype->name_version;
1154 if (!strcmp(type->name,new_type->name)) <--kaboom
1155 count =max(count, type->name_version);
Quoted 5 lines
hm, while most code (except the one above) is prepared for
type->namebeing NULL, it should not be NULL. Maybe an uninitialized lock slipped through? Please try the patch below - it both protects againsttype->namebeing NULL in this place, and will warn if it finds a NULL lockname.
Got the warning. It failed testing, but booted.
Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar
... MAX_LOCKDEP_SUBTYPES: 8 ... MAX_LOCK_DEPTH: 30 ... MAX_LOCKDEP_KEYS: 2048 ... TYPEHASH_SIZE: 1024 ... MAX_LOCKDEP_ENTRIES: 8192 ... MAX_LOCKDEP_CHAINS: 8192 ... CHAINHASH_SIZE: 4096
memory used by lock dependency info: 696 kB
per task-struct memory footprint: 1080 bytes
------------------------
| Locking API testsuite:
----------------------------------------------------------------------------
| spin |wlock |rlock |mutex | wsem | rsem |
--------------------------------------------------------------------------
BUG: warning at kernel/lockdep.c:1977/lockdep_init_map()
<b1003dd2> show_trace+0xd/0xf <b10044c0> dump_stack+0x17/0x19
<b103badf> lockdep_init_map+0x10a/0x10f <b10398d7> __mutex_init+0x3b/0x44
<b11d4601> init_type_X+0x37/0x4d <b11d4638> init_shared_types+0x21/0xaa
<b11dcca3> locking_selftest+0x76/0x1889 <b1597657> start_kernel+0x1e7/0x400
<b1000210> 0xb1000210
A-A deadlock: ok | ok | ok | ok | ok | ok |
A-B-B-A deadlock: ok | ok |FAILED| ok | ok | ok |
A-B-B-C-C-A deadlock: ok | ok |FAILED| ok | ok | ok |
A-B-C-A-B-C deadlock: ok | ok |FAILED| ok | ok | ok |
A-B-B-C-C-D-D-A deadlock: ok | ok |FAILED| ok | ok | ok |
A-B-C-D-B-D-D-A deadlock: ok | ok |FAILED| ok | ok | ok |
A-B-C-D-B-C-D-A deadlock: ok | ok |FAILED| ok | ok | ok |
double unlock: ok | ok | ok | ok | ok | ok |
bad unlock order: ok | ok | ok | ok | ok | ok |
--------------------------------------------------------------------------
recursive read-lock: |FAILED| | ok |
--------------------------------------------------------------------------
non-nested unlock:FAILED|FAILED|FAILED|FAILED|
------------------------------------------------------------
hard-irqs-on + irq-safe-A/12: ok | ok |FAILED|
soft-irqs-on + irq-safe-A/12: ok | ok |FAILED|
hard-irqs-on + irq-safe-A/21: ok | ok |FAILED|
soft-irqs-on + irq-safe-A/21: ok | ok |FAILED|
sirq-safe-A => hirqs-on/12: ok | ok |FAILED|
sirq-safe-A => hirqs-on/21: ok | ok |FAILED|
hard-safe-A + irqs-on/12: ok | ok |FAILED|
soft-safe-A + irqs-on/12: ok | ok |FAILED|
hard-safe-A + irqs-on/21: ok | ok |FAILED|
soft-safe-A + irqs-on/21: ok | ok |FAILED|
hard-safe-A + unsafe-B #1/123: ok | ok |FAILED|
soft-safe-A + unsafe-B #1/123: ok | ok |FAILED|
hard-safe-A + unsafe-B #1/132: ok | ok |FAILED|
soft-safe-A + unsafe-B #1/132: ok | ok |FAILED|
hard-safe-A + unsafe-B #1/213: ok | ok |FAILED|
soft-safe-A + unsafe-B #1/213: ok | ok |FAILED|
hard-safe-A + unsafe-B #1/231: ok | ok |FAILED|
soft-safe-A + unsafe-B #1/231: ok | ok |FAILED|
hard-safe-A + unsafe-B #1/312: ok | ok |FAILED|
soft-safe-A + unsafe-B #1/312: ok | ok |FAILED|
hard-safe-A + unsafe-B #1/321: ok | ok |FAILED|
soft-safe-A + unsafe-B #1/321: ok | ok |FAILED|
hard-safe-A + unsafe-B #2/123: ok | ok |FAILED|
soft-safe-A + unsafe-B #2/123: ok | ok |FAILED|
hard-safe-A + unsafe-B #2/132: ok | ok |FAILED|
soft-safe-A + unsafe-B #2/132: ok | ok |FAILED|
hard-safe-A + unsafe-B #2/213: ok | ok |FAILED|
soft-safe-A + unsafe-B #2/213: ok | ok |FAILED|
hard-safe-A + unsafe-B #2/231: ok | ok |FAILED|
soft-safe-A + unsafe-B #2/231: ok | ok |FAILED|
hard-safe-A + unsafe-B #2/312: ok | ok |FAILED|
soft-safe-A + unsafe-B #2/312: ok | ok |FAILED|
hard-safe-A + unsafe-B #2/321: ok | ok |FAILED|
soft-safe-A + unsafe-B #2/321: ok | ok |FAILED|
hard-irq lock-inversion/123: ok | ok |FAILED|
soft-irq lock-inversion/123: ok | ok |FAILED|
hard-irq lock-inversion/132: ok | ok |FAILED|
soft-irq lock-inversion/132: ok | ok |FAILED|
hard-irq lock-inversion/213: ok | ok |FAILED|
soft-irq lock-inversion/213: ok | ok |FAILED|
hard-irq lock-inversion/231: ok | ok |FAILED|
soft-irq lock-inversion/231: ok | ok |FAILED|
hard-irq lock-inversion/312: ok | ok |FAILED|
soft-irq lock-inversion/312: ok | ok |FAILED|
hard-irq lock-inversion/321: ok | ok |FAILED|
soft-irq lock-inversion/321: ok | ok |FAILED|
hard-irq read-recursion/123:FAILED|
soft-irq read-recursion/123:FAILED|
hard-irq read-recursion/132:FAILED|
soft-irq read-recursion/132:FAILED|
hard-irq read-recursion/213:FAILED|
soft-irq read-recursion/213:FAILED|
hard-irq read-recursion/231:FAILED|
soft-irq read-recursion/231:FAILED|
hard-irq read-recursion/312:FAILED|
soft-irq read-recursion/312:FAILED|
hard-irq read-recursion/321:FAILED|
soft-irq read-recursion/321:FAILED|
-----------------------------------------------------------------
BUG: 69 unexpected failures (out of 210) - debugging disabled! |
-----------------------------------------------------------------Quoted 10 lines · Mike Galbraith
Quoted 7 lines · Ingo Molnar
Quoted 3 lines · Mike Galbraith
Darn. It said all tests passed, then oopsed.
(have .config all gzipped up if you want it)
yeah, please.
(sent off list)
thanks, i managed to reproduce the warning with your .config - i'm debugging the problem now.
Ingo
Quoted 6 lines · Ingo Molnar
We are pleased to announce the first release of the "lock dependency correctness validator" kernel debugging feature, which can be downloaded from:
I get this right after ipw2200 is loaded (it is quite verbose, I probably shoudln't post everything...)
ipw2200: Detected Intel PRO/Wireless 2200BG Network Connection
ipw2200: Detected geography ZZD (13 802.11bg channels, 0 802.11a channels)
======================================================
[ BUG: hard-safe -> hard-unsafe lock order detected! ]
------------------------------------------------------
default.hotplug/3212 [HC0[0]:SC1[1]:HE0:SE0] is trying to acquire:
(nl_table_lock){-.-±}, at: [<c0301efa>] netlink_broadcast+0x7a/0x360
and this task is already holding:
(&priv->lock){++..}, at: [<e1cfe588>] ipw_irq_tasklet+0x18/0x500 [ipw2200] which would create a new lock dependency:
(&priv->lock){++..} -> (nl_table_lock){-.-±}
but this new dependency connects a hard-irq-safe lock:
(&priv->lock){++..}
... which became hard-irq-safe at:
[<c01395da>] lockdep_acquire+0x7a/0xa0 [<c0352583>] _spin_lock+0x23/0x30 [<e1cfdbc1>] ipw_isr+0x21/0xd0 [ipw2200] [<c01466e3>] handle_IRQ_event+0x33/0x80 [<c01467e4>] __do_IRQ+0xb4/0x120 [<c01057c0>] do_IRQ+0x70/0xc0
to a hard-irq-unsafe lock:
(nl_table_lock){-.-±}
... which became hard-irq-unsafe at:
... [<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03520da>] _write_lock_bh+0x2a/0x30 [<c03017d2>] netlink_table_grab+0x12/0xe0 [<c0301bcb>] netlink_insert+0x2b/0x180 [<c030307c>] netlink_kernel_create+0xac/0x140 [<c048f29a>] rtnetlink_init+0x6a/0xc0 [<c048f6b9>] netlink_proto_init+0x169/0x180 [<c010029f>] _stext+0x7f/0x250 [<c0101005>] kernel_thread_helper+0x5/0xb
which could potentially lead to deadlocks!
other info that might help us debug this:
1 locks held by default.hotplug/3212:
#0: (&priv->lock){++..}, at: [<e1cfe588>] ipw_irq_tasklet+0x18/0x500 [ipw2200]
the hard-irq-safe lock's dependencies:
-> (&priv->lock){++..} ops: 102 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<e1cf6a0c>] ipw_load+0x1fc/0xc90 [ipw2200]
[<e1cf74e8>] ipw_up+0x48/0x520 [ipw2200]
[<e1cfda87>] ipw_net_init+0x27/0x50 [ipw2200]
[<c02eeef1>] register_netdevice+0xd1/0x410
[<c02f0609>] register_netdev+0x59/0x70
[<e1cfe4d6>] ipw_pci_probe+0x806/0x8a0 [ipw2200]
[<c023481e>] pci_device_probe+0x5e/0x80
[<c02a86e4>] driver_probe_device+0x44/0xc0
[<c02a888b>] __driver_attach+0x9b/0xa0
[<c02a8039>] bus_for_each_dev+0x49/0x70
[<c02a8629>] driver_attach+0x19/0x20
[<c02a7c64>] bus_add_driver+0x74/0x140
[<c02a8b06>] driver_register+0x56/0x90
[<c0234a10>] __pci_register_driver+0x50/0x70
[<e18b302e>] 0xe18b302e
[<c014034d>] sys_init_module+0xcd/0x1630
[<c035273b>] sysenter_past_esp+0x54/0x8d
in-hardirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<e1cfdbc1>] ipw_isr+0x21/0xd0 [ipw2200]
[<c01466e3>] handle_IRQ_event+0x33/0x80
[<c01467e4>] __do_IRQ+0xb4/0x120
[<c01057c0>] do_IRQ+0x70/0xc0
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<e1cfe588>] ipw_irq_tasklet+0x18/0x500 [ipw2200]
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<e1d0b438>] __key.27363+0x0/0xffff38f6 [ipw2200]
-> (&q->lock){++..} ops: 33353 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352509>] _spin_lock_irq+0x29/0x40
[<c034f084>] wait_for_completion+0x24/0x150
[<c013160e>] keventd_create_kthread+0x2e/0x70
[<c01315d6>] kthread_create+0xe6/0xf0
[<c0121b75>] cpu_callback+0x95/0x110
[<c0481194>] spawn_ksoftirqd+0x14/0x30
[<c010023c>] _stext+0x1c/0x250
[<c0101005>] kernel_thread_helper+0x5/0xb
in-hardirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c011794b>] __wake_up+0x1b/0x50
[<c012dcdd>] __queue_work+0x4d/0x70
[<c012ddaf>] queue_work+0x6f/0x80
[<c0269588>] acpi_os_execute+0xcd/0xe9
[<c026eea1>] acpi_ev_gpe_dispatch+0xbc/0x122
[<c026f106>] acpi_ev_gpe_detect+0x99/0xe0
[<c026d90b>] acpi_ev_sci_xrupt_handler+0x15/0x1d
[<c0268c55>] acpi_irq+0xe/0x18
[<c01466e3>] handle_IRQ_event+0x33/0x80
[<c01467e4>] __do_IRQ+0xb4/0x120
[<c01057c0>] do_IRQ+0x70/0xc0
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c011786b>] complete+0x1b/0x60
[<c012ef0b>] wakeme_after_rcu+0xb/0x10
[<c012f0c9>] __rcu_process_callbacks+0x69/0x1c0
[<c012f232>] rcu_process_callbacks+0x12/0x30
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<c04d47c8>] 0xc04d47c8
-> (&rq->lock){++..} ops: 68824 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c0117bcc>] init_idle+0x4c/0x80
[<c0480ad8>] sched_init+0xa8/0xb0
[<c0473558>] start_kernel+0x58/0x330
[<c0100199>] 0xc0100199
in-hardirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c0117cc7>] scheduler_tick+0xc7/0x310
[<c01270ee>] update_process_times+0x3e/0x70
[<c0106c21>] timer_interrupt+0x41/0xa0
[<c01466e3>] handle_IRQ_event+0x33/0x80
[<c01467e4>] __do_IRQ+0xb4/0x120
[<c01057c0>] do_IRQ+0x70/0xc0
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c01183e0>] try_to_wake_up+0x30/0x170
[<c011854f>] wake_up_process+0xf/0x20
[<c0122413>] __do_softirq+0xb3/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<c04c1400>] 0xc04c1400
... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c01183e0>] try_to_wake_up+0x30/0x170
[<c011852b>] default_wake_function+0xb/0x10
[<c01172d9>] __wake_up_common+0x39/0x70
[<c011788d>] complete+0x3d/0x60
[<c01316d4>] kthread+0x84/0xbc
[<c0101005>] kernel_thread_helper+0x5/0xb... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0 [<c03524c0>] _spin_lock_irqsave+0x30/0x50 [<c011794b>] __wake_up+0x1b/0x50 [<e1cf6a2e>] ipw_load+0x21e/0xc90 [ipw2200] [<e1cf74e8>] ipw_up+0x48/0x520 [ipw2200] [<e1cfda87>] ipw_net_init+0x27/0x50 [ipw2200] [<c02eeef1>] register_netdevice+0xd1/0x410 [<c02f0609>] register_netdev+0x59/0x70 [<e1cfe4d6>] ipw_pci_probe+0x806/0x8a0 [ipw2200] [<c023481e>] pci_device_probe+0x5e/0x80 [<c02a86e4>] driver_probe_device+0x44/0xc0 [<c02a888b>] __driver_attach+0x9b/0xa0 [<c02a8039>] bus_for_each_dev+0x49/0x70 [<c02a8629>] driver_attach+0x19/0x20 [<c02a7c64>] bus_add_driver+0x74/0x140 [<c02a8b06>] driver_register+0x56/0x90 [<c0234a10>] __pci_register_driver+0x50/0x70 [<e18b302e>] 0xe18b302e [<c014034d>] sys_init_module+0xcd/0x1630 [<c035273b>] sysenter_past_esp+0x54/0x8d
-> (&rxq->lock){.+..} ops: 40 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<e1cf66d0>] ipw_rx_queue_replenish+0x20/0x120 [ipw2200]
[<e1cf72e0>] ipw_load+0xad0/0xc90 [ipw2200]
[<e1cf74e8>] ipw_up+0x48/0x520 [ipw2200]
[<e1cfda87>] ipw_net_init+0x27/0x50 [ipw2200]
[<c02eeef1>] register_netdevice+0xd1/0x410
[<c02f0609>] register_netdev+0x59/0x70
[<e1cfe4d6>] ipw_pci_probe+0x806/0x8a0 [ipw2200]
[<c023481e>] pci_device_probe+0x5e/0x80
[<c02a86e4>] driver_probe_device+0x44/0xc0
[<c02a888b>] __driver_attach+0x9b/0xa0
[<c02a8039>] bus_for_each_dev+0x49/0x70
[<c02a8629>] driver_attach+0x19/0x20
[<c02a7c64>] bus_add_driver+0x74/0x140
[<c02a8b06>] driver_register+0x56/0x90
[<c0234a10>] __pci_register_driver+0x50/0x70
[<e18b302e>] 0xe18b302e
[<c014034d>] sys_init_module+0xcd/0x1630
[<c035273b>] sysenter_past_esp+0x54/0x8d
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<e1cf25bf>] ipw_rx_queue_restock+0x1f/0x120 [ipw2200]
[<e1cf80d1>] ipw_rx+0x631/0x1bb0 [ipw2200]
[<e1cfe6ac>] ipw_irq_tasklet+0x13c/0x500 [ipw2200]
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<e1d0b440>] __key.23915+0x0/0xffff38ee [ipw2200]
-> (&parent->list_lock){.+..} ops: 17457 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c0166437>] cache_alloc_refill+0x87/0x650
[<c0166bae>] kmem_cache_zalloc+0xbe/0xd0
[<c01672d4>] kmem_cache_create+0x154/0x540
[<c0483ad9>] kmem_cache_init+0x179/0x3d0
[<c0473638>] start_kernel+0x138/0x330
[<c0100199>] 0xc0100199
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c0166073>] free_block+0x183/0x190
[<c0165bdf>] __cache_free+0x9f/0x120
[<c0165da8>] kmem_cache_free+0x88/0xb0
[<c0119e21>] free_task+0x21/0x30
[<c011b955>] __put_task_struct+0x95/0x156
[<c011db12>] delayed_put_task_struct+0x32/0x60
[<c012f0c9>] __rcu_process_callbacks+0x69/0x1c0
[<c012f232>] rcu_process_callbacks+0x12/0x30
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<c060d00c>] 0xc060d00c
... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c0166437>] cache_alloc_refill+0x87/0x650
[<c0166ab8>] __kmalloc+0xb8/0xf0
[<c02eb3cb>] __alloc_skb+0x4b/0x100
[<e1cf6769>] ipw_rx_queue_replenish+0xb9/0x120 [ipw2200]
[<e1cf72e0>] ipw_load+0xad0/0xc90 [ipw2200]
[<e1cf74e8>] ipw_up+0x48/0x520 [ipw2200]
[<e1cfda87>] ipw_net_init+0x27/0x50 [ipw2200]
[<c02eeef1>] register_netdevice+0xd1/0x410
[<c02f0609>] register_netdev+0x59/0x70
[<e1cfe4d6>] ipw_pci_probe+0x806/0x8a0 [ipw2200]
[<c023481e>] pci_device_probe+0x5e/0x80
[<c02a86e4>] driver_probe_device+0x44/0xc0
[<c02a888b>] __driver_attach+0x9b/0xa0
[<c02a8039>] bus_for_each_dev+0x49/0x70
[<c02a8629>] driver_attach+0x19/0x20
[<c02a7c64>] bus_add_driver+0x74/0x140
[<c02a8b06>] driver_register+0x56/0x90
[<c0234a10>] __pci_register_driver+0x50/0x70
[<e18b302e>] 0xe18b302e
[<c014034d>] sys_init_module+0xcd/0x1630
[<c035273b>] sysenter_past_esp+0x54/0x8d... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0 [<c03524c0>] _spin_lock_irqsave+0x30/0x50 [<e1cf25bf>] ipw_rx_queue_restock+0x1f/0x120 [ipw2200] [<e1cf80d1>] ipw_rx+0x631/0x1bb0 [ipw2200] [<e1cfe6ac>] ipw_irq_tasklet+0x13c/0x500 [ipw2200] [<c0121ea0>] tasklet_action+0x40/0x90 [<c01223b4>] __do_softirq+0x54/0xc0 [<c01056bb>] do_softirq+0x5b/0xf0
-> (&ieee->lock){.+..} ops: 15 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<e1c9d0cf>] ieee80211_process_probe_response+0x1ff/0x790 [ieee80211]
[<e1c9d70f>] ieee80211_rx_mgt+0xaf/0x340 [ieee80211]
[<e1cf8219>] ipw_rx+0x779/0x1bb0 [ipw2200]
[<e1cfe6ac>] ipw_irq_tasklet+0x13c/0x500 [ipw2200]
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<e1c9d0cf>] ieee80211_process_probe_response+0x1ff/0x790 [ieee80211]
[<e1c9d70f>] ieee80211_rx_mgt+0xaf/0x340 [ieee80211]
[<e1cf8219>] ipw_rx+0x779/0x1bb0 [ipw2200]
[<e1cfe6ac>] ipw_irq_tasklet+0x13c/0x500 [ipw2200]
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<e1ca2781>] __key.22782+0x0/0xffffdc00 [ieee80211]
... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<e1c9d0cf>] ieee80211_process_probe_response+0x1ff/0x790 [ieee80211]
[<e1c9d70f>] ieee80211_rx_mgt+0xaf/0x340 [ieee80211]
[<e1cf8219>] ipw_rx+0x779/0x1bb0 [ipw2200]
[<e1cfe6ac>] ipw_irq_tasklet+0x13c/0x500 [ipw2200]
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0 -> (&cwq->lock){++..} ops: 3739 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c012dca8>] __queue_work+0x18/0x70
[<c012ddaf>] queue_work+0x6f/0x80
[<c012d949>] call_usermodehelper_keys+0x139/0x160
[<c0219a2a>] kobject_uevent+0x7a/0x4a0
[<c0219753>] kobject_register+0x43/0x50
[<c02a7687>] sysdev_register+0x67/0x100
[<c02aa950>] register_cpu+0x30/0x70
[<c0108f7a>] arch_register_cpu+0x2a/0x30
[<c047850a>] topology_init+0xa/0x10
[<c010029f>] _stext+0x7f/0x250
[<c0101005>] kernel_thread_helper+0x5/0xb
in-hardirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c012dca8>] __queue_work+0x18/0x70
[<c012ddaf>] queue_work+0x6f/0x80
[<c0269588>] acpi_os_execute+0xcd/0xe9
[<c026eea1>] acpi_ev_gpe_dispatch+0xbc/0x122
[<c026f106>] acpi_ev_gpe_detect+0x99/0xe0
[<c026d90b>] acpi_ev_sci_xrupt_handler+0x15/0x1d
[<c0268c55>] acpi_irq+0xe/0x18
[<c01466e3>] handle_IRQ_event+0x33/0x80
[<c01467e4>] __do_IRQ+0xb4/0x120
[<c01057c0>] do_IRQ+0x70/0xc0
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c012dca8>] __queue_work+0x18/0x70
[<c012dd30>] delayed_work_timer_fn+0x30/0x40
[<c012633e>] run_timer_softirq+0x12e/0x180
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<c04d4334>] 0xc04d4334
-> (&q->lock){++..} ops: 33353 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352509>] _spin_lock_irq+0x29/0x40
[<c034f084>] wait_for_completion+0x24/0x150
[<c013160e>] keventd_create_kthread+0x2e/0x70
[<c01315d6>] kthread_create+0xe6/0xf0
[<c0121b75>] cpu_callback+0x95/0x110
[<c0481194>] spawn_ksoftirqd+0x14/0x30
[<c010023c>] _stext+0x1c/0x250
[<c0101005>] kernel_thread_helper+0x5/0xb
in-hardirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c011794b>] __wake_up+0x1b/0x50
[<c012dcdd>] __queue_work+0x4d/0x70
[<c012ddaf>] queue_work+0x6f/0x80
[<c0269588>] acpi_os_execute+0xcd/0xe9
[<c026eea1>] acpi_ev_gpe_dispatch+0xbc/0x122
[<c026f106>] acpi_ev_gpe_detect+0x99/0xe0
[<c026d90b>] acpi_ev_sci_xrupt_handler+0x15/0x1d
[<c0268c55>] acpi_irq+0xe/0x18
[<c01466e3>] handle_IRQ_event+0x33/0x80
[<c01467e4>] __do_IRQ+0xb4/0x120
[<c01057c0>] do_IRQ+0x70/0xc0
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c011786b>] complete+0x1b/0x60
[<c012ef0b>] wakeme_after_rcu+0xb/0x10
[<c012f0c9>] __rcu_process_callbacks+0x69/0x1c0
[<c012f232>] rcu_process_callbacks+0x12/0x30
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<c04d47c8>] 0xc04d47c8
-> (&rq->lock){++..} ops: 68824 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c0117bcc>] init_idle+0x4c/0x80
[<c0480ad8>] sched_init+0xa8/0xb0
[<c0473558>] start_kernel+0x58/0x330
[<c0100199>] 0xc0100199
in-hardirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c0117cc7>] scheduler_tick+0xc7/0x310
[<c01270ee>] update_process_times+0x3e/0x70
[<c0106c21>] timer_interrupt+0x41/0xa0
[<c01466e3>] handle_IRQ_event+0x33/0x80
[<c01467e4>] __do_IRQ+0xb4/0x120
[<c01057c0>] do_IRQ+0x70/0xc0
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c01183e0>] try_to_wake_up+0x30/0x170
[<c011854f>] wake_up_process+0xf/0x20
[<c0122413>] __do_softirq+0xb3/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<c04c1400>] 0xc04c1400
... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352583>] _spin_lock+0x23/0x30
[<c01183e0>] try_to_wake_up+0x30/0x170
[<c011852b>] default_wake_function+0xb/0x10
[<c01172d9>] __wake_up_common+0x39/0x70
[<c011788d>] complete+0x3d/0x60
[<c01316d4>] kthread+0x84/0xbc
[<c0101005>] kernel_thread_helper+0x5/0xb... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0 [<c03524c0>] _spin_lock_irqsave+0x30/0x50 [<c011794b>] __wake_up+0x1b/0x50 [<c012dcdd>] __queue_work+0x4d/0x70 [<c012ddaf>] queue_work+0x6f/0x80 [<c012d949>] call_usermodehelper_keys+0x139/0x160 [<c0219a2a>] kobject_uevent+0x7a/0x4a0 [<c0219753>] kobject_register+0x43/0x50 [<c02a7687>] sysdev_register+0x67/0x100 [<c02aa950>] register_cpu+0x30/0x70 [<c0108f7a>] arch_register_cpu+0x2a/0x30 [<c047850a>] topology_init+0xa/0x10 [<c010029f>] _stext+0x7f/0x250 [<c0101005>] kernel_thread_helper+0x5/0xb
... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0 [<c03524c0>] _spin_lock_irqsave+0x30/0x50 [<c012dca8>] __queue_work+0x18/0x70 [<c012ddaf>] queue_work+0x6f/0x80 [<e1cf267e>] ipw_rx_queue_restock+0xde/0x120 [ipw2200] [<e1cf80d1>] ipw_rx+0x631/0x1bb0 [ipw2200] [<e1cfe6ac>] ipw_irq_tasklet+0x13c/0x500 [ipw2200] [<c0121ea0>] tasklet_action+0x40/0x90 [<c01223b4>] __do_softirq+0x54/0xc0 [<c01056bb>] do_softirq+0x5b/0xf0
-> (&base->lock){++..} ops: 8140 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c0126e4a>] lock_timer_base+0x3a/0x60
[<c0126f17>] __mod_timer+0x37/0xc0
[<c0127036>] mod_timer+0x36/0x50
[<c048a2e5>] con_init+0x1b5/0x200
[<c0489802>] console_init+0x32/0x40
[<c04735ea>] start_kernel+0xea/0x330
[<c0100199>] 0xc0100199
in-hardirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c0126e4a>] lock_timer_base+0x3a/0x60
[<c0126e9c>] del_timer+0x2c/0x70
[<c02bc619>] ide_intr+0x69/0x1f0
[<c01466e3>] handle_IRQ_event+0x33/0x80
[<c01467e4>] __do_IRQ+0xb4/0x120
[<c01057c0>] do_IRQ+0x70/0xc0
in-softirq-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352509>] _spin_lock_irq+0x29/0x40
[<c0126239>] run_timer_softirq+0x29/0x180
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
}
... key at: [<c04d3af8>] 0xc04d3af8
... acquired at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03524c0>] _spin_lock_irqsave+0x30/0x50
[<c0126e4a>] lock_timer_base+0x3a/0x60
[<c0126e9c>] del_timer+0x2c/0x70
[<e1cf83d9>] ipw_rx+0x939/0x1bb0 [ipw2200]
[<e1cfe6ac>] ipw_irq_tasklet+0x13c/0x500 [ipw2200]
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0the hard-irq-unsafe lock's dependencies:
-> (nl_table_lock){-.-±} ops: 1585 {
initial-use at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03520da>] _write_lock_bh+0x2a/0x30
[<c03017d2>] netlink_table_grab+0x12/0xe0
[<c0301bcb>] netlink_insert+0x2b/0x180
[<c030307c>] netlink_kernel_create+0xac/0x140
[<c048f29a>] rtnetlink_init+0x6a/0xc0
[<c048f6b9>] netlink_proto_init+0x169/0x180
[<c010029f>] _stext+0x7f/0x250
[<c0101005>] kernel_thread_helper+0x5/0xb
hardirq-on-W at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c03520da>] _write_lock_bh+0x2a/0x30
[<c03017d2>] netlink_table_grab+0x12/0xe0
[<c0301bcb>] netlink_insert+0x2b/0x180
[<c030307c>] netlink_kernel_create+0xac/0x140
[<c048f29a>] rtnetlink_init+0x6a/0xc0
[<c048f6b9>] netlink_proto_init+0x169/0x180
[<c010029f>] _stext+0x7f/0x250
[<c0101005>] kernel_thread_helper+0x5/0xb
in-softirq-R at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352130>] _read_lock+0x20/0x30
[<c0301efa>] netlink_broadcast+0x7a/0x360
[<c02fb6a4>] wireless_send_event+0x304/0x340
[<e1cf8e11>] ipw_rx+0x1371/0x1bb0 [ipw2200]
[<e1cfe6ac>] ipw_irq_tasklet+0x13c/0x500 [ipw2200]
[<c0121ea0>] tasklet_action+0x40/0x90
[<c01223b4>] __do_softirq+0x54/0xc0
[<c01056bb>] do_softirq+0x5b/0xf0
softirq-on-R at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352130>] _read_lock+0x20/0x30
[<c0301efa>] netlink_broadcast+0x7a/0x360
[<c02199f0>] kobject_uevent+0x40/0x4a0
[<c0219753>] kobject_register+0x43/0x50
[<c02a7687>] sysdev_register+0x67/0x100
[<c02aa950>] register_cpu+0x30/0x70
[<c0108f7a>] arch_register_cpu+0x2a/0x30
[<c047850a>] topology_init+0xa/0x10
[<c010029f>] _stext+0x7f/0x250
[<c0101005>] kernel_thread_helper+0x5/0xb
hardirq-on-R at:
[<c01395da>] lockdep_acquire+0x7a/0xa0
[<c0352130>] _read_lock+0x20/0x30
[<c0301efa>] netlink_broadcast+0x7a/0x360
[<c02199f0>] kobject_uevent+0x40/0x4a0
[<c0219753>] kobject_register+0x43/0x50
[<c02a7687>] sysdev_register+0x67/0x100
[<c02aa950>] register_cpu+0x30/0x70
[<c0108f7a>] arch_register_cpu+0x2a/0x30
[<c047850a>] topology_init+0xa/0x10
[<c010029f>] _stext+0x7f/0x250
[<c0101005>] kernel_thread_helper+0x5/0xb}
... key at: [<c0438908>] 0xc0438908
stack backtrace: <c010402d> show_trace+0xd/0x10 <c0104687> dump_stack+0x17/0x20 <c0137fe3> check_usage+0x263/0x270 <c0138f06> __lockdep_acquire+0xb96/0xd40 <c01395da> lockdep_acquire+0x7a/0xa0 <c0352130> _read_lock+0x20/0x30 <c0301efa> netlink_broadcast+0x7a/0x360 <c02fb6a4> wireless_send_event+0x304/0x340 <e1cf8e11> ipw_rx+0x1371/0x1bb0 [ipw2200] <e1cfe6ac> ipw_irq_tasklet+0x13c/0x500 [ipw2200] <c0121ea0> tasklet_action+0x40/0x90 <c01223b4> __do_softirq+0x54/0xc0 <c01056bb> do_softirq+0x5b/0xf0 ======================= <c0122455> irq_exit+0x35/0x40 <c01057c7> do_IRQ+0x77/0xc0 <c0103949> common_interrupt+0x25/0x2c
Quoted 8 lines · Benoit Boissinot
Quoted 6 lines · Ingo Molnar
We are pleased to announce the first release of the "lock dependency correctness validator" kernel debugging feature, which can be downloaded from:
Quoted 8 lines
I get this right after ipw2200 is loaded (it is quite verbose, I probably shoudln't post everything...)
ipw2200: Detected Intel PRO/Wireless 2200BG Network Connection
ipw2200: Detected geography ZZD (13 802.11bg channels, 0 802.11a channels)<
c0301efa>netlink_broadcast+0x7a/0x360
this isn't allow to be called from IRQ context, because it takes nl_table_lock for read, but that is taken as
write_lock_bh(&nl_table_lock);
in
static void netlink_table_grab(void)
so without disabling interrupts; which would thus deadlock if this read_lock-from-irq would hit.
Quoted 4 lines
<
c02fb6a4>wireless_send_event+0x304/0x340
<e1cf8e11>ipw_rx+0x1371/0x1bb0[ipw2200]
<e1cfe6ac>ipw_irq_tasklet+0x13c/0x500[ipw2200]
<c0121ea0>tasklet_action+0x40/0x90
but it's more complex than that, since we ARE in BH context. The complexity comes from us holding &priv->lock, which is used in hard irq context.
so the deadlock is like this:
cpu 0: user context cpu1: softirq context
netlink_table_grab takes nl_table_lock as take priv->lock in ipw_irq_tasklet
write_lock_bh, but leaves irqs enabled
hardirq comes in and the isr tries to take in ipw_rx, call wireless_send_event which
priv->lock but has to wait on cpu 1 tries to take nl_table_lock for read
but has to wait for cpu0
and... kaboom kabang deadlock :)