Skip to contentSkip to conversation

Pre-emptable lock debug

DISCUSSION Andrew Morton 2 participants 2 messages Apr 29, 2005 1 message not in the archive netfilter

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 27 lines · Andrew McNamara

Suspect this is "not your problem", but... when installing 2.6.11.7, I (probably foolishly?) enabled:

CONFIG_PREEMPT=y
CONFIG_PREEMPT_BKL=y
CONFIG_DEBUG_PREEMPT=y

So now I'm getting debug (just like I asked for). The following occured late in the boot process (after root is mounted RW, apparently when interfaces are brought up). Another batch occur very late in the shutdown process, although I haven't been able to catch these.

This is a bog standard kernel 2.6.11.7 - although NV module is loaded later.

BUG: using smp_processor_id() in preemptible [00000001] code: ifconfig/1606
caller is get_next_corpse+0x14/0x280
 [<c021a348>] smp_processor_id+0xa8/0xc0
 [<c03fcfb4>] get_next_corpse+0x14/0x280
 [<c03fcfb4>] get_next_corpse+0x14/0x280
 [<c0429aff>] _spin_unlock_irqrestore+0xf/0x30
 [<c03a78bd>] skb_dequeue+0x4d/0x60
 [<c03fd254>] ip_ct_iterate_cleanup+0x34/0xd0
 [<c040d3c0>] device_cmp+0x0/0x110
 [<c040d388>] masq_inet_event+0x38/0x70
 [<c040d3c0>] device_cmp+0x0/0x110
 [<c012db0d>] notifier_call_chain+0x2d/0x50
Quoted 8 lines
 [<c03eb8ec>] inet_del_ifa+0x8c/0x150
 [<c03ec5b9>] devinet_ioctl+0x4d9/0x5b0
 [<c03ee876>] inet_ioctl+0x66/0xb0
 [<c03a2219>] sock_ioctl+0xc9/0x250
 [<c01717ae>] do_ioctl+0x8e/0xa0
 [<c01719c5>] vfs_ioctl+0x65/0x1f0
 [<c0171bb7>] sys_ioctl+0x67/0x90
 [<c010328f>] syscall_call+0x7/0xb

That's a bug in MUST_BE_WRITE_LOCKED(), doing smp_processor_id() outside preempt_disable().

Like this, I think:

Avoid smp_processor_id() in premptible code in the netfilter lock debugging code.

---

 include/linux/netfilter_ipv4/lockhelp.h |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
include/linux/netfilter_ipv4/lockhelp.h renamed from include/linux/netfilter_ipv4/lockhelp.h~netfilter-debug-locking-fix +11 -5
diff -puN include/linux/netfilter_ipv4/lockhelp.h~netfilter-debug-locking-fix include/linux/netfilter_ipv4/lockhelp.h
@@ -63,9 +63,11 @@ do { if ((l)->read_locked_map & (1UL << 
 
 #define LOCK_BH(lk)						\
 do {								\
+	preempt_disable();					\
 	MUST_BE_UNLOCKED(lk);					\
 	spin_lock_bh(&(lk)->l);					\
 	atomic_set(&(lk)->locked_by, smp_processor_id());	\
+	preempt_enable();					\
 } while(0)
 
 #define UNLOCK_BH(lk)				\
@@ -77,16 +79,20 @@ do {						\
 
 #define READ_LOCK(lk) 						\
 do {								\
+	preempt_disable();					\
 	MUST_BE_READ_WRITE_UNLOCKED(lk);			\
 	read_lock_bh(&(lk)->l);					\
 	set_bit(smp_processor_id(), &(lk)->read_locked_map);	\
+	preempt_enable();					\
 } while(0)
 
-#define WRITE_LOCK(lk)							  \
-do {									  \
-	MUST_BE_READ_WRITE_UNLOCKED(lk);				  \
-	write_lock_bh(&(lk)->l);					  \
-	set_bit(smp_processor_id(), &(lk)->write_locked_map);		  \
+#define WRITE_LOCK(lk)						\
+do {								\
+	preempt_disable();					\
+	MUST_BE_READ_WRITE_UNLOCKED(lk);			\
+	write_lock_bh(&(lk)->l);				\
+	set_bit(smp_processor_id(), &(lk)->write_locked_map);	\
+	preempt_enable();					\
 } while(0)
 
 #define READ_UNLOCK(lk)							\

_

#2 lore raw
Quoted 21 lines
Quoted 12 lines
BUG: using smp_processor_id() in preemptible [00000001] code: ifconfig/1606
caller is get_next_corpse+0x14/0x280
 [<c021a348>] smp_processor_id+0xa8/0xc0
 [<c03fcfb4>] get_next_corpse+0x14/0x280
 [<c03fcfb4>] get_next_corpse+0x14/0x280
 [<c0429aff>] _spin_unlock_irqrestore+0xf/0x30
 [<c03a78bd>] skb_dequeue+0x4d/0x60
 [<c03fd254>] ip_ct_iterate_cleanup+0x34/0xd0
 [<c040d3c0>] device_cmp+0x0/0x110
 [<c040d388>] masq_inet_event+0x38/0x70
 [<c040d3c0>] device_cmp+0x0/0x110
 [<c012db0d>] notifier_call_chain+0x2d/0x50
Quoted 8 lines
 [<c03eb8ec>] inet_del_ifa+0x8c/0x150
 [<c03ec5b9>] devinet_ioctl+0x4d9/0x5b0
 [<c03ee876>] inet_ioctl+0x66/0xb0
 [<c03a2219>] sock_ioctl+0xc9/0x250
 [<c01717ae>] do_ioctl+0x8e/0xa0
 [<c01719c5>] vfs_ioctl+0x65/0x1f0
 [<c0171bb7>] sys_ioctl+0x67/0x90
 [<c010328f>] syscall_call+0x7/0xb
Quoted 7 lines

That's a bug in MUST_BE_WRITE_LOCKED(), doing smp_processor_id() outside preempt_disable().

Like this, I think:

Avoid smp_processor_id() in premptible code in the netfilter lock debugging code.

Thanks - your patch fixed it for me.

Signature · 2 lines
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/