locking updates for v2.6.30
Subsystems (9)
Linus,
Please pull the latest locking-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git locking-for-linus
Highlights:
- Spinning mutexes by Peter Zijlstra: mutex_lock() primitives now might behave like spinlocks if the lock is still held by a task (on another CPU)
- GFP_FS tracking: subtly incorrect GFP_FS calls are now detected and reported preemptively.
- timer deadlock tracking
- large lockdep core refactoring/cleanup, to make it easier to extend
Known risks:
- Spinning mutexes have performance regression risks:
ac6e60e: mutex: adaptive spinnning, performance tweaks 0d66bf6: mutex: implement adaptive spinning
- The lockdep core refactoring is intrusive and has caused bugs (lockups) during testing.
- Increased dependency checking coverage caused several new bug sightings, and some false positives as well.
- No known regressions.
Thanks,
Ingo
------------------>
Chris Mason (2):
mutex: adaptive spinnning, performance tweaks
Btrfs: stop spinning on mutex_trylock and let the adaptive code spin for us
Ingo Molnar (2):
lockdep: annotate reclaim context (__GFP_NOFS), fix
lockdep: annotate reclaim context (__GFP_NOFS), fix SLOB
Johannes Berg (1):
timer: implement lockdep deadlock detection
Nick Piggin (1):
lockdep: annotate reclaim context (__GFP_NOFS)
Peter Zijlstra (27):
mutex: small cleanup
mutex: preemption fixes
mutex: implement adaptive spinning
lockdep: sanitize bit names
lockdep: sanitize reclaim bit names
lockdep: lockdep_states.h
lockdep: simplify mark_held_locks
lockdep: simplify mark_lock()
lockdep: move state bit definitions around
lockdep: generate the state bit definitions
lockdep: generate usage strings
lockdep: split up mark_lock_irq()
lockdep: simplify the mark_lock_irq() helpers
lockdep: further simplify mark_lock_irq() helpers
lockdep: simplify mark_lock_irq() helpers #3
lockdep: merge the _READ mark_lock_irq() helpers
lockdep: merge the !_READ mark_lock_irq() helpers
lockdep: fully reduce mark_lock_irq()
lockdep: remove macro usage from mark_held_locks()
lockdep: add comments to mark_lock_irq()
lockdep: simplify get_user_chars()
lockdep: get_user_chars() redo
lockdep: simplify check_prev_add_irq()
lockdep: use stringify.h
lockstat: warn about disabled lock debugging
lockdep: build fix for !PROVE_LOCKING
lockdep: fix deadlock in lockdep_trace_alloc
Documentation/lockdep-design.txt | 30 ++- include/linux/lockdep.h | 50 +--- include/linux/mutex.h | 5 +- include/linux/sched.h | 3 + include/linux/timer.h | 93 ++++++- kernel/lockdep.c | 528 +++++++++++++++++++------------------ kernel/lockdep_internals.h | 45 +++- kernel/lockdep_proc.c | 22 +- kernel/lockdep_states.h | 9 + kernel/mutex-debug.c | 9 +- kernel/mutex-debug.h | 18 +- kernel/mutex.c | 121 ++++++++-- kernel/mutex.h | 22 ++- kernel/sched.c | 71 +++++- kernel/sched_features.h | 1 + kernel/timer.c | 68 ++++- mm/page_alloc.c | 5 + mm/slab.c | 4 + mm/slob.c | 2 + mm/slub.c | 1 + mm/vmscan.c | 2 + 21 files changed, 730 insertions(+), 379 deletions(-) create mode 100644 kernel/lockdep_states.h
Documentation/lockdep-design.txt +17 -13
@@ -27,33 +27,37 @@ lock-class. State ----- -The validator tracks lock-class usage history into 5 separate state bits: +The validator tracks lock-class usage history into 4n + 1 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 held in STATE context' +- 'ever head as readlock in STATE context' +- 'ever head with STATE enabled' +- 'ever head as readlock with STATE enabled' + +Where STATE can be either one of (kernel/lockdep_states.h) + - hardirq + - softirq + - reclaim_fs - 'ever used' [ == !unused ] -When locking rules are violated, these 4 state bits are presented in the -locking error messages, inside curlies. A contrived example: +When locking rules are violated, these state bits are presented in the +locking error messages, inside curlies. A contrived example: modprobe/2287 is trying to acquire lock: - (&sio_locks[i].lock){--..}, at: [<c02867fd>] mutex_lock+0x21/0x24 + (&sio_locks[i].lock){-.-...}, at: [<c02867fd>] mutex_lock+0x21/0x24 but task is already holding lock: - (&sio_locks[i].lock){--..}, at: [<c02867fd>] mutex_lock+0x21/0x24 + (&sio_locks[i].lock){-.-...}, at: [<c02867fd>] mutex_lock+0x21/0x24 -The bit position indicates hardirq, softirq, hardirq-read, -softirq-read respectively, and the character displayed in each -indicates: +The bit position indicates STATE, STATE-read, for each of the states listed +above, and the character displayed in each indicates: '.' acquired while irqs disabled '+' acquired in irq context '-' acquired with irqs enabled - '?' read acquired in irq context with irqs enabled. + '?' acquired in irq context with irqs enabled. Unused mutexes cannot be part of the cause of an error.
include/linux/lockdep.h +12 -38
75 lines not on this page · raw message
include/linux/mutex.h +3 -2
@@ -50,8 +50,10 @@ struct mutex {atomic_t count;spinlock_t wait_lock;struct list_head wait_list; -#ifdef CONFIG_DEBUG_MUTEXES +#if defined(CONFIG_DEBUG_MUTEXES ) || defined(CONFIG_SMP )struct thread_info *owner; +#endif +#ifdef CONFIG_DEBUG_MUTEXES const char *name;void *magic;#endif
@@ -68,7 +70,6 @@ struct mutex_waiter {struct list_head list;struct task_struct *task;#ifdef CONFIG_DEBUG_MUTEXES -struct mutex *lock;void *magic;#endif };
include/linux/sched.h +3 -0
@@ -331,7 +331,9 @@ extern signed long schedule_timeout(signed long timeout);extern signed long schedule_timeout_interruptible (signed long timeout);extern signed long schedule_timeout_killable (signed long timeout);extern signed long schedule_timeout_uninterruptible (signed long timeout); +asmlinkage void __schedule(void); asmlinkage void schedule(void); +extern int mutex_spin_on_owner (struct mutex *lock,struct thread_info *owner);struct nsproxy ;struct user_namespace ;
@@ -1311,6 +1313,7 @@ struct task_struct {int lockdep_depth;unsigned int lockdep_recursion;struct held_lock held_locks[MAX_LOCK_DEPTH ]; +gfp_t lockdep_reclaim_gfp;#endif /* journalling filesystem info */
include/linux/timer.h +84 -9
142 lines not on this page · raw message
kernel/lockdep.c +271 -257
694 lines not on this page · raw message
kernel/lockdep_internals.h +43 -2
57 lines not on this page · raw message
kernel/lockdep_proc.c +13 -9
@@ -84,7 +84,7 @@ static int l_show(struct seq_file *m, void *v) {struct lock_class *class = v;struct lock_list *entry; -char c1, c2, c3, c4; +char usage[LOCK_USAGE_CHARS ];if (v ==SEQ_START_TOKEN ) {seq_printf (m,"all lock classes:\n" );
@@ -100,8 +100,8 @@ static int l_show(struct seq_file *m, void *v)seq_printf (m," BD:%5ld" ,lockdep_count_backward_deps (class));#endif -get_usage_chars (class, &c1, &c2, &c3, &c4); -seq_printf (m," %c%c%c%c" , c1, c2, c3, c4); +get_usage_chars (class, usage); +seq_printf (m," %s" , usage);seq_printf (m,": " );print_name (m, class);
@@ -300,27 +300,27 @@ static int lockdep_stats_show(struct seq_file *m, void *v) nr_uncategorized++;if (class->usage_mask &LOCKF_USED_IN_IRQ ) nr_irq_safe++; -if (class->usage_mask &LOCKF_ENABLED_IRQS ) +if (class->usage_mask &LOCKF_ENABLED_IRQ ) nr_irq_unsafe++;if (class->usage_mask &LOCKF_USED_IN_SOFTIRQ ) nr_softirq_safe++; -if (class->usage_mask &LOCKF_ENABLED_SOFTIRQS ) +if (class->usage_mask &LOCKF_ENABLED_SOFTIRQ ) nr_softirq_unsafe++;if (class->usage_mask &LOCKF_USED_IN_HARDIRQ ) nr_hardirq_safe++; -if (class->usage_mask &LOCKF_ENABLED_HARDIRQS ) +if (class->usage_mask &LOCKF_ENABLED_HARDIRQ ) nr_hardirq_unsafe++;if (class->usage_mask &LOCKF_USED_IN_IRQ_READ ) nr_irq_read_safe++; -if (class->usage_mask &LOCKF_ENABLED_IRQS_READ ) +if (class->usage_mask &LOCKF_ENABLED_IRQ_READ ) nr_irq_read_unsafe++;if (class->usage_mask &LOCKF_USED_IN_SOFTIRQ_READ ) nr_softirq_read_safe++; -if (class->usage_mask &LOCKF_ENABLED_SOFTIRQS_READ ) +if (class->usage_mask &LOCKF_ENABLED_SOFTIRQ_READ ) nr_softirq_read_unsafe++;if (class->usage_mask &LOCKF_USED_IN_HARDIRQ_READ ) nr_hardirq_read_safe++; -if (class->usage_mask &LOCKF_ENABLED_HARDIRQS_READ ) +if (class->usage_mask &LOCKF_ENABLED_HARDIRQ_READ ) nr_hardirq_read_unsafe++;#ifdef CONFIG_PROVE_LOCKING
@@ -601,6 +601,10 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)static void seq_header (struct seq_file *m) {seq_printf (m,"lock_stat version 0.3\n" ); + +if (unlikely (!debug_locks)) +seq_printf (m,"*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n" ); +seq_line (m,'-' ,0 ,40 +1 +10 * (14 +1 )); seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s " "%14s %14s\n",
kernel/lockdep_states.h new file +9 -0
@@ -0,0 +1,9 @@ +/* +* Lockdep states, +* +* please update XXX_LOCK_USAGE_STATES in include/linux/lockdep.h whenever +* you add one, or come up with a nice dynamic solution. +*/ +LOCKDEP_STATE(HARDIRQ) +LOCKDEP_STATE(SOFTIRQ) +LOCKDEP_STATE(RECLAIM_FS)
kernel/mutex-debug.c +1 -8
@@ -26,11 +26,6 @@/* * Must be called with lock->wait_lock held. */ -void debug_mutex_set_owner (struct mutex *lock,struct thread_info *new_owner) -{ - lock->owner = new_owner; -} -void debug_mutex_lock_common (struct mutex *lock,struct mutex_waiter *waiter) {memset (waiter,MUTEX_DEBUG_INIT ,sizeof (*waiter));
@@ -59,7 +54,6 @@ void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,/* Mark the current thread as blocked on the lock: */ ti->task->blocked_on = waiter; - waiter->lock = lock; } void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
@@ -82,7 +76,7 @@ void debug_mutex_unlock(struct mutex *lock)DEBUG_LOCKS_WARN_ON (lock->magic != lock);DEBUG_LOCKS_WARN_ON (lock->owner !=current_thread_info ());DEBUG_LOCKS_WARN_ON (!lock->wait_list.prev && !lock->wait_list.next); -DEBUG_LOCKS_WARN_ON (lock->owner !=current_thread_info ()); +mutex_clear_owner (lock); } void debug_mutex_init(struct mutex *lock, const char *name,
@@ -95,7 +89,6 @@ void debug_mutex_init(struct mutex *lock, const char *name,debug_check_no_locks_freed ((void *)lock,sizeof (*lock));lockdep_init_map (&lock->dep_map, name, key,0 );#endif - lock->owner =NULL ; lock->magic = lock; }
kernel/mutex-debug.h +10 -8
@@ -13,14 +13,6 @@/* * This must be called with lock->wait_lock held. */ -extern void -debug_mutex_set_owner (struct mutex *lock,struct thread_info *new_owner); - -static inline void debug_mutex_clear_owner (struct mutex *lock) -{ - lock->owner =NULL ; -} -extern void debug_mutex_lock_common (struct mutex *lock,struct mutex_waiter *waiter); extern void debug_mutex_wake_waiter(struct mutex *lock,
@@ -35,6 +27,16 @@ extern void debug_mutex_unlock(struct mutex *lock);extern void debug_mutex_init (struct mutex *lock,const char *name,struct lock_class_key *key); +static inline void mutex_set_owner (struct mutex *lock) +{ + lock->owner =current_thread_info (); +} + +static inline void mutex_clear_owner (struct mutex *lock) +{ + lock->owner =NULL ; +} +#define spin_lock_mutex (lock, flags) \ do { \ struct mutex *l = container_of(lock, struct mutex, wait_lock); \
kernel/mutex.c +104 -17
234 lines not on this page · raw message
kernel/mutex.h +20 -2
@@ -16,8 +16,26 @@#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) +#ifdef CONFIG_SMP +static inline void mutex_set_owner (struct mutex *lock) +{ + lock->owner =current_thread_info (); +} + +static inline void mutex_clear_owner (struct mutex *lock) +{ + lock->owner =NULL ; +} +#else +static inline void mutex_set_owner (struct mutex *lock) +{ +} + +static inline void mutex_clear_owner (struct mutex *lock) +{ +} +#endif +#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)
kernel/sched.c +68 -3
96 lines not on this page · raw message
kernel/sched_features.h +1 -0
@@ -13,3 +13,4 @@ SCHED_FEAT(LB_WAKEUP_UPDATE, 1) SCHED_FEAT(ASYM_EFF_LOAD, 1) SCHED_FEAT(WAKEUP_OVERLAP, 0) SCHED_FEAT(LAST_BUDDY, 1) +SCHED_FEAT (OWNER_SPIN ,1 )
kernel/timer.c +57 -11
119 lines not on this page · raw message
mm/page_alloc.c +5 -0
@@ -1479,6 +1479,8 @@ __alloc_pages_internal(gfp_t gfp_mask, unsigned int order,unsigned long did_some_progress;unsigned long pages_reclaimed =0 ; +lockdep_trace_alloc (gfp_mask); +might_sleep_if (wait);if (should_fail_alloc_page (gfp_mask, order))
@@ -1578,12 +1580,15 @@ nofail_alloc:*/ cpuset_update_task_memory_state (); p->flags |=PF_MEMALLOC ; + +lockdep_set_current_reclaim_state (gfp_mask); reclaim_state.reclaimed_slab =0 ; p->reclaim_state = &reclaim_state; did_some_progress =try_to_free_pages (zonelist, order, gfp_mask); p->reclaim_state =NULL ; +lockdep_clear_current_reclaim_state (); p->flags &= ~PF_MEMALLOC ;cond_resched ();
mm/slab.c +4 -0
@@ -3318,6 +3318,8 @@ __cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid,unsigned long save_flags;void *ptr; +lockdep_trace_alloc (flags); +if (slab_should_failslab (cachep, flags))return NULL ;
@@ -3394,6 +3396,8 @@ __cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller)unsigned long save_flags;void *objp; +lockdep_trace_alloc (flags); +if (slab_should_failslab (cachep, flags))return NULL ;
mm/slob.c +2 -0
@@ -464,6 +464,8 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)unsigned int *m;int align =max (ARCH_KMALLOC_MINALIGN ,ARCH_SLAB_MINALIGN ); +lockdep_trace_alloc (gfp); +if (size <PAGE_SIZE - align) {if (!size)return ZERO_SIZE_PTR ;
mm/slub.c +1 -0
@@ -1596,6 +1596,7 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,unsigned long flags;unsigned int objsize; +lockdep_trace_alloc (gfpflags);might_sleep_if (gfpflags & __GFP_WAIT);if (should_failslab (s->objsize, gfpflags))
mm/vmscan.c +2 -0
@@ -1965,6 +1965,8 @@ static int kswapd(void *p) };node_to_cpumask_ptr (cpumask, pgdat->node_id); +lockdep_set_current_reclaim_state (GFP_KERNEL ); +if (!cpumask_empty (cpumask))set_cpus_allowed_ptr (tsk, cpumask); current->reclaim_state = &reclaim_state;