[PATCH v2] block: Don't register a registered bdi device

2017-01-17 Thread Yijing Wang
bles ip6table_filter ip6_tables intel_rapl sb_edac 
edac_core x86_pkg_temp_pclmul joydev ghash_clmulni_intel iTCO_wdt ipmi_ssif 
mei_me pcspkr mei iTCO_vendor_support ipmi_si i2c_i801 lpc_ich mfd_corema 
acpi_pad wmi acpi_power_meter nfsd auth_rpcgss nfs_acl lockd grace binfmt_misc 
sunrpc xfs libcrc32c ast i2c_algo_bit drm_kore raid_class nvme_core 
scsi_transport_sas dca
[  +0.080566] CPU: 17 PID: 281 Comm: kworker/u49:5 Tainted: GW   
4.9.0-rc2 #1
[  +0.009472] Hardware name: Supermicro SYS-2028U-TNRT+/X10DRU-i+, BIOS 1.1 
07/22/2015
[  +0.009169] Workqueue: events_unbound async_run_entry_fn
[  +0.007340] RIP: 0010:[]  [] 
sysfs_do_create_link_sd.isra.2+0x34/0xb0
[  +0.010294] Call Trace:
[  +0.005269]  [] sysfs_create_link+0x25/0x40
[  +0.008568]  [] device_add_disk+0x1fc/0x480
[  +0.008551]  [] sd_probe_async+0x110/0x1c0
[  +0.008456]  [] async_run_entry_fn+0x39/0x140
[  +0.010021]  [] process_one_work+0x15f/0x430
[  +0.009623]  [] worker_thread+0x4e/0x490
[  +0.007422]  [] ? process_one_work+0x430/0x430
[  +0.008728]  [] kthread+0xd9/0xf0
[  +0.007578]  [] ? kthread_park+0x60/0x60
[  +0.006816]  [] ret_from_fork+0x25/0x30
[  +0.006814] Code: 75 48 85 ff 74 70 55 48 89 e5 41 57 41 56 41 55 41 54 49 89 
fe 53 48 c7 c7 90 74 01 82 48 89 f3 41 89 cc  c5 ff ff c6 05 15 48 d5
[  +0.022853] RIP  [] sysfs_do_create_link_sd.isra.2+0x34/0xb0
[  +0.008679]  RSP 
[  +0.006129] BUG: unable to handle kernel

While create the first raid disk, we hide first raid disk's PD devices
(remove sdx device), but leave the bdi device in kernel, we won't call
bdi_unregister() in del_gendisk. So if we cancal the raid, and create
second raid disk, kernel try to register the bdi device again, then
the warning calltrace dump, bcause the bdi device already exist in kernel.
This patch check the bdi device state before register a new bdi device,
avoid register a registered bdi device again.

-v2: remove the spin lock protect, because the sd_probe caller should
 guarantee the scsi_device valid, and the bdi device is unregister
 when scsi_device/block queue removed.

Signed-off-by: Yijing Wang 
---
 block/genhd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/genhd.c b/block/genhd.c
index fcd6d4f..fbb2a96 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -614,7 +614,8 @@ void device_add_disk(struct device *parent, struct gendisk 
*disk)
 
/* Register BDI before referencing it from bdev */
bdi = &disk->queue->backing_dev_info;
-   bdi_register_owner(bdi, disk_to_dev(disk));
+   if (!test_bit(WB_registered, &bdi->wb.state))
+   bdi_register_owner(bdi, disk_to_dev(disk));
 
blk_register_region(disk_devt(disk), disk->minors, NULL,
exact_match, exact_lock, disk);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] block: Don't register a registered bdi device

2017-01-10 Thread Yijing Wang
p6table_filter ip6_tables intel_rapl sb_edac 
edac_core x86_pkg_temp_pclmul joydev ghash_clmulni_intel iTCO_wdt ipmi_ssif 
mei_me pcspkr mei iTCO_vendor_support ipmi_si i2c_i801 lpc_ich mfd_corema 
acpi_pad wmi acpi_power_meter nfsd auth_rpcgss nfs_acl lockd grace binfmt_misc 
sunrpc xfs libcrc32c ast i2c_algo_bit drm_kore raid_class nvme_core 
scsi_transport_sas dca
[  +0.080566] CPU: 17 PID: 281 Comm: kworker/u49:5 Tainted: GW   
4.9.0-rc2 #1
[  +0.009472] Hardware name: Supermicro SYS-2028U-TNRT+/X10DRU-i+, BIOS 1.1 
07/22/2015
[  +0.009169] Workqueue: events_unbound async_run_entry_fn
[  +0.007340] RIP: 0010:[]  [] 
sysfs_do_create_link_sd.isra.2+0x34/0xb0
[  +0.010294] Call Trace:
[  +0.005269]  [] sysfs_create_link+0x25/0x40
[  +0.008568]  [] device_add_disk+0x1fc/0x480
[  +0.008551]  [] sd_probe_async+0x110/0x1c0
[  +0.008456]  [] async_run_entry_fn+0x39/0x140
[  +0.010021]  [] process_one_work+0x15f/0x430
[  +0.009623]  [] worker_thread+0x4e/0x490
[  +0.007422]  [] ? process_one_work+0x430/0x430
[  +0.008728]  [] kthread+0xd9/0xf0
[  +0.007578]  [] ? kthread_park+0x60/0x60
[  +0.006816]  [] ret_from_fork+0x25/0x30
[  +0.006814] Code: 75 48 85 ff 74 70 55 48 89 e5 41 57 41 56 41 55 41 54 49 89 
fe 53 48 c7 c7 90 74 01 82 48 89 f3 41 89 cc  c5 ff ff c6 05 15 48 d5
[  +0.022853] RIP  [] sysfs_do_create_link_sd.isra.2+0x34/0xb0
[  +0.008679]  RSP 
[  +0.006129] BUG: unable to handle kernel

While create the first raid disk, we hide first raid disk's PD devices
(remove sdx device), but leave the bdi device in kernel, we won't call
bdi_unregister() in del_gendisk, we will do it when we cleanup request
queue. Then we cancal the raid, and create second raid disk based same
disks, then kernel try to probe the sdx device and register the bdi device
again in device_add_disk(), then the warning calltrace dump, bcause the
bdi device already exist in kernel.

This patch check the bdi device state before register a new bdi device to
avoid register a registered bdi device again.

Signed-off-by: Yijing Wang 
---
 block/genhd.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/block/genhd.c b/block/genhd.c
index fcd6d4f..2c2f95e 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -614,7 +614,10 @@ void device_add_disk(struct device *parent, struct gendisk 
*disk)
 
/* Register BDI before referencing it from bdev */
bdi = &disk->queue->backing_dev_info;
-   bdi_register_owner(bdi, disk_to_dev(disk));
+   spin_lock_bh(&bdi->wb.work_lock);
+   if (!test_bit(WB_registered, &bdi->wb.state))
+   bdi_register_owner(bdi, disk_to_dev(disk));
+   spin_unlock_bh(&bdi->wb.work_lock);
 
blk_register_region(disk_devt(disk), disk->minors, NULL,
exact_match, exact_lock, disk);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html