Skip to contentSkip to conversation

md: Avoid to call flush_scheduled_work() with BKL held

PATCH In review Alessio Igor Bogani 3 participants 4 messages Apr 23, 2009 – May 7, 2009 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md: Avoid to call flush_scheduled_work() with BKL held

[    1.479872] ------------[ cut here ]------------
[    1.483391] WARNING: at kernel/workqueue.c:408 flush_workqueue+0x7b/0x11f()
[    1.489948] Hardware name:
[    1.491779] Modules linked in:
[    1.493306] Pid: 1, comm: swapper Not tainted 2.6.30-rc1 #67
[    1.495767] Call Trace:
[    1.496974]  [<ffffffff810451a4>] warn_slowpath+0xd8/0x10c
[    1.503432]  [<ffffffff810176d1>] ? save_stack_trace+0x2f/0x4d
[    1.509724]  [<ffffffff8106983d>] ? mark_lock+0x22/0x22c
[    1.515412]  [<ffffffff8106b364>] ? __lock_acquire+0xc36/0xc45
[    1.521448]  [<ffffffff81069e9b>] ? debug_check_no_locks_freed+0x120/0x12f
[    1.525189]  [<ffffffff8106874c>] ? get_lock_stats+0x19/0x4c
[    1.527172]  [<ffffffff810687a7>] ? put_lock_stats+0x28/0x33
[    1.533316]  [<ffffffff81056d7f>] flush_workqueue+0x7b/0x11f
[    1.539224]  [<ffffffff8139ffe8>] ? mddev_find+0xe2/0x2e5
[    1.544826]  [<ffffffff81056e38>] flush_scheduled_work+0x15/0x17
[    1.551262]  [<ffffffff813a0239>] md_alloc+0x4e/0x2b0
[    1.556505]  [<ffffffff813a04ab>] md_probe+0x10/0x14
[    1.561939]  [<ffffffff812c6a90>] kobj_lookup+0x150/0x194
[    1.566607]  [<ffffffff813a049b>] ? md_probe+0x0/0x14
[    1.570519]  [<ffffffff811f6f3c>] get_gendisk+0x30/0xc1
[    1.573948]  [<ffffffff81105821>] __blkdev_get+0x3a/0x338
[    1.577537]  [<ffffffff81105b31>] ? blkdev_open+0x0/0xab
[    1.581293]  [<ffffffff81105b2f>] blkdev_get+0x10/0x12
[    1.584922]  [<ffffffff81105ba7>] blkdev_open+0x76/0xab
[    1.588661]  [<ffffffff810dd7fa>] __dentry_open+0x194/0x2b9
[    1.592615]  [<ffffffff810dd9f6>] nameidata_to_filp+0x46/0x57
[    1.596730]  [<ffffffff810e9f8f>] do_filp_open+0x417/0x83e
[    1.600651]  [<ffffffff8106874c>] ? get_lock_stats+0x19/0x4c
[    1.604597]  [<ffffffff810f3fe7>] ? alloc_fd+0x122/0x133
[    1.608424]  [<ffffffff810dd59a>] do_sys_open+0x58/0xd8
[    1.612233]  [<ffffffff810dd64d>] sys_open+0x20/0x22
[    1.615671]  [<ffffffff818a94f1>] md_run_setup+0x64/0x8e
[    1.619496]  [<ffffffff818a8251>] prepare_namespace+0x3a/0x19d
[    1.623239]  [<ffffffff818a765e>] kernel_init+0x16e/0x17e
[    1.626923]  [<ffffffff8100cf3a>] child_rip+0xa/0x20
[    1.629504]  [<ffffffff8103ba79>] ? finish_task_switch+0x40/0xe8
[    1.642356]  [<ffffffff8100c900>] ? restore_args+0x0/0x30
[    1.643802]  [<ffffffff818a74f0>] ? kernel_init+0x0/0x17e
[    1.645276]  [<ffffffff8100cf30>] ? child_rip+0x0/0x20
[    1.648839] ---[ end trace 6fa921fb3766f01d ]---
---
 drivers/md/md.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/md/md.c +6 -0
index ed5727c..e6c039c 100644
@@ -45,6 +45,7 @@
 #include <linux/reboot.h>
 #include <linux/file.h>
 #include <linux/delay.h>
+#include <linux/smp_lock.h>
 #include <linux/raid/md_p.h>
 #include <linux/raid/md_u.h>
 #include "md.h"
@@ -3830,6 +3831,7 @@ static int md_alloc(dev_t dev, char *name)
 	int shift;
 	int unit;
 	int error;
+	int bkl = kernel_locked();
 
 	if (!mddev)
 		return -ENODEV;
@@ -3841,7 +3843,11 @@ static int md_alloc(dev_t dev, char *name)
 	/* wait for any previous instance if this device
 	 * to be completed removed (mddev_delayed_delete).
 	 */
+	if (bkl)
+		unlock_kernel();
 	flush_scheduled_work();
+	if (bkl)
+		lock_kernel();
 
 	mutex_lock(&disks_mutex);
 	if (mddev->gendisk) {
Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 68 lines · Alessio Igor Bogani
[    1.479872] ------------[ cut here ]------------
[    1.483391] WARNING: at kernel/workqueue.c:408 flush_workqueue+0x7b/0x11f()
[    1.489948] Hardware name:
[    1.491779] Modules linked in:
[    1.493306] Pid: 1, comm: swapper Not tainted 2.6.30-rc1 #67
[    1.495767] Call Trace:
[    1.496974]  [<ffffffff810451a4>] warn_slowpath+0xd8/0x10c
[    1.503432]  [<ffffffff810176d1>] ? save_stack_trace+0x2f/0x4d
[    1.509724]  [<ffffffff8106983d>] ? mark_lock+0x22/0x22c
[    1.515412]  [<ffffffff8106b364>] ? __lock_acquire+0xc36/0xc45
[    1.521448]  [<ffffffff81069e9b>] ? debug_check_no_locks_freed+0x120/0x12f
[    1.525189]  [<ffffffff8106874c>] ? get_lock_stats+0x19/0x4c
[    1.527172]  [<ffffffff810687a7>] ? put_lock_stats+0x28/0x33
[    1.533316]  [<ffffffff81056d7f>] flush_workqueue+0x7b/0x11f
[    1.539224]  [<ffffffff8139ffe8>] ? mddev_find+0xe2/0x2e5
[    1.544826]  [<ffffffff81056e38>] flush_scheduled_work+0x15/0x17
[    1.551262]  [<ffffffff813a0239>] md_alloc+0x4e/0x2b0
[    1.556505]  [<ffffffff813a04ab>] md_probe+0x10/0x14
[    1.561939]  [<ffffffff812c6a90>] kobj_lookup+0x150/0x194
[    1.566607]  [<ffffffff813a049b>] ? md_probe+0x0/0x14
[    1.570519]  [<ffffffff811f6f3c>] get_gendisk+0x30/0xc1
[    1.573948]  [<ffffffff81105821>] __blkdev_get+0x3a/0x338
[    1.577537]  [<ffffffff81105b31>] ? blkdev_open+0x0/0xab
[    1.581293]  [<ffffffff81105b2f>] blkdev_get+0x10/0x12
[    1.584922]  [<ffffffff81105ba7>] blkdev_open+0x76/0xab
[    1.588661]  [<ffffffff810dd7fa>] __dentry_open+0x194/0x2b9
[    1.592615]  [<ffffffff810dd9f6>] nameidata_to_filp+0x46/0x57
[    1.596730]  [<ffffffff810e9f8f>] do_filp_open+0x417/0x83e
[    1.600651]  [<ffffffff8106874c>] ? get_lock_stats+0x19/0x4c
[    1.604597]  [<ffffffff810f3fe7>] ? alloc_fd+0x122/0x133
[    1.608424]  [<ffffffff810dd59a>] do_sys_open+0x58/0xd8
[    1.612233]  [<ffffffff810dd64d>] sys_open+0x20/0x22
[    1.615671]  [<ffffffff818a94f1>] md_run_setup+0x64/0x8e
[    1.619496]  [<ffffffff818a8251>] prepare_namespace+0x3a/0x19d
[    1.623239]  [<ffffffff818a765e>] kernel_init+0x16e/0x17e
[    1.626923]  [<ffffffff8100cf3a>] child_rip+0xa/0x20
[    1.629504]  [<ffffffff8103ba79>] ? finish_task_switch+0x40/0xe8
[    1.642356]  [<ffffffff8100c900>] ? restore_args+0x0/0x30
[    1.643802]  [<ffffffff818a74f0>] ? kernel_init+0x0/0x17e
[    1.645276]  [<ffffffff8100cf30>] ? child_rip+0x0/0x20
[    1.648839] ---[ end trace 6fa921fb3766f01d ]---
---
 drivers/md/md.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/md/md.c +2 -0
index ed5727c..e6c039c 100644
@@ -45,6 +45,7 @@
 #include <linux/reboot.h>
 #include <linux/file.h>
 #include <linux/delay.h>
+#include <linux/smp_lock.h>
 #include <linux/raid/md_p.h>
 #include <linux/raid/md_u.h>
 #include "md.h"
@@ -3830,6 +3831,7 @@ static int md_alloc(dev_t dev, char *name)
 	int shift;
 	int unit;
 	int error;
+	int bkl = kernel_locked();
 
 	if (!mddev)
 		return -ENODEV;

drivers/md/md.c static int md_alloc(dev_t dev, char *name) · line 3850

Quoted 8 lines
drivers/md/md.c +4 -0
@@ -3841,7 +3843,11 @@ static int md_alloc(dev_t dev, char *name)
 	/* wait for any previous instance if this device
 	 * to be completed removed (mddev_delayed_delete).
 	 */
+	if (bkl)
+		unlock_kernel();
 	flush_scheduled_work();
+	if (bkl)
+		lock_kernel();

Hm, couldnt we switch the ioctl in drivers/md/md.c from ->locked_ioctl to ->unlocked_ioctl?

Neil, what do you think?

Ingo

#2 lore raw
Quoted 5 lines · On Sunday April 26, [email protected] wrote:

Hm, couldnt we switch the ioctl in drivers/md/md.c from ->locked_ioctl to ->unlocked_ioctl?

Neil, what do you think?

Yes, definitely. Though it is just 'ioctl', not 'unlocked_ioctl'.

I'll queue a patch for 2.6.31.

NeilBrown

#3 lore raw
Quoted 10 lines · Neil Brown
Quoted 5 lines · On Sunday April 26, [email protected] wrote:

Hm, couldnt we switch the ioctl in drivers/md/md.c from ->locked_ioctl to ->unlocked_ioctl?

Neil, what do you think?

Yes, definitely. Though it is just 'ioctl', not 'unlocked_ioctl'.

I'll queue a patch for 2.6.31.

thanks!

Ingo