Skip to content

Commit 7bf530e

Browse files
KAGA-KOKOghaskins
authored andcommitted
Subject: mm: slab: Fix potential deadlock
============================================= [ INFO: possible recursive locking detected ] 3.6.0-rt1+ raspberrypi#49 Not tainted --------------------------------------------- swapper/0/1 is trying to acquire lock: lock_slab_on+0x72/0x77 but task is already holding lock: __local_lock_irq+0x24/0x77 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&per_cpu(slab_lock, __cpu).lock); lock(&per_cpu(slab_lock, __cpu).lock); *** DEADLOCK *** May be due to missing lock nesting notation 2 locks held by swapper/0/1: kmem_cache_create+0x33/0x89 __local_lock_irq+0x24/0x77 stack backtrace: Pid: 1, comm: swapper/0 Not tainted 3.6.0-rt1+ raspberrypi#49 Call Trace: __lock_acquire+0x9a4/0xdc4 ? __local_lock_irq+0x24/0x77 ? lock_slab_on+0x72/0x77 lock_acquire+0xc4/0x108 ? lock_slab_on+0x72/0x77 ? unlock_slab_on+0x5b/0x5b rt_spin_lock+0x36/0x3d ? lock_slab_on+0x72/0x77 ? migrate_disable+0x85/0x93 lock_slab_on+0x72/0x77 do_ccupdate_local+0x19/0x44 slab_on_each_cpu+0x36/0x5a do_tune_cpucache+0xc1/0x305 enable_cpucache+0x8c/0xb5 setup_cpu_cache+0x28/0x182 __kmem_cache_create+0x34b/0x380 ? shmem_mount+0x1a/0x1a kmem_cache_create+0x4a/0x89 ? shmem_mount+0x1a/0x1a shmem_init+0x3e/0xd4 kernel_init+0x11c/0x214 kernel_thread_helper+0x4/0x10 ? retint_restore_args+0x13/0x13 ? start_kernel+0x3bc/0x3bc ? gs_change+0x13/0x13 It's not a missing annotation. It's simply wrong code and needs to be fixed. Instead of nesting the local and the remote cpu lock simply acquire only the remote cpu lock, which is sufficient protection for this procedure. Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected]
1 parent 799c5a4 commit 7bf530e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

include/linux/locallock.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ static inline void __local_lock_irq(struct local_irq_lock *lv)
9696
#define local_lock_irq(lvar) \
9797
do { __local_lock_irq(&get_local_var(lvar)); } while (0)
9898

99+
#define local_lock_irq_on(lvar, cpu) \
100+
do { __local_lock_irq(&per_cpu(lvar, cpu)); } while (0)
101+
99102
static inline void __local_unlock_irq(struct local_irq_lock *lv)
100103
{
101104
LL_WARN(!lv->nestcnt);
@@ -111,6 +114,11 @@ static inline void __local_unlock_irq(struct local_irq_lock *lv)
111114
put_local_var(lvar); \
112115
} while (0)
113116

117+
#define local_unlock_irq_on(lvar, cpu) \
118+
do { \
119+
__local_unlock_irq(&per_cpu(lvar, cpu)); \
120+
} while (0)
121+
114122
static inline int __local_lock_irqsave(struct local_irq_lock *lv)
115123
{
116124
if (lv->owner != current) {

mm/slab.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,18 +728,12 @@ slab_on_each_cpu(void (*func)(void *arg, int this_cpu), void *arg)
728728

729729
static void lock_slab_on(unsigned int cpu)
730730
{
731-
if (cpu == smp_processor_id())
732-
local_lock_irq(slab_lock);
733-
else
734-
local_spin_lock_irq(slab_lock, &per_cpu(slab_lock, cpu).lock);
731+
local_lock_irq_on(slab_lock, cpu);
735732
}
736733

737734
static void unlock_slab_on(unsigned int cpu)
738735
{
739-
if (cpu == smp_processor_id())
740-
local_unlock_irq(slab_lock);
741-
else
742-
local_spin_unlock_irq(slab_lock, &per_cpu(slab_lock, cpu).lock);
736+
local_unlock_irq_on(slab_lock, cpu);
743737
}
744738
#endif
745739

0 commit comments

Comments
 (0)