Skip to contentSkip to conversation

virtio_blk: fix race at module removal

PATCH Applied Michael S. Tsirkin 3 participants 3 messages Oct 23, 2014 – Oct 28, 2014

Subsystems (3)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 virtio_blk: fix race at module removal

If a device appears while module is being removed, driver will get a callback after we've given up on the major number.

In theory this means this major number can get reused by something else, resulting in a conflict.

To fix, cleanup in reverse order of initialization.

---
 drivers/block/virtio_blk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/virtio_blk.c +1 -1
index 56aadbc..adfba9f 100644
@@ -883,8 +883,8 @@ out_destroy_workqueue:
 
 static void __exit fini(void)
 {
-	unregister_blkdev(major, "virtblk");
 	unregister_virtio_driver(&virtio_blk);
+	unregister_blkdev(major, "virtblk");
 	destroy_workqueue(virtblk_wq);
 }
 module_init(init);
Signature · 1 line
MST
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Michael S. Tsirkin

If a device appears while module is being removed, driver will get a callback after we've given up on the major number.

In theory this means this major number can get reused by something else, resulting in a conflict.

Yes, there is a tiny race window.

Quoted 2 lines

To fix, cleanup in reverse order of initialization.

Quoted 10 lines
---
 drivers/block/virtio_blk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/virtio_blk.c +0 -0
index 56aadbc..adfba9f 100644

drivers/block/virtio_blk.c out_destroy_workqueue: · line 890

Quoted 9 lines
drivers/block/virtio_blk.c +1 -1
@@ -883,8 +883,8 @@ out_destroy_workqueue:
 
 static void __exit fini(void)
 {
-       unregister_blkdev(major, "virtblk");
        unregister_virtio_driver(&virtio_blk);
+       unregister_blkdev(major, "virtblk");
        destroy_workqueue(virtblk_wq);
 }
 module_init(init);

Thanks,

Signature · 1 line
Ming Lei
#2 lore raw
Quoted 9 lines · Ming Lei
Quoted 6 lines · Michael S. Tsirkin

If a device appears while module is being removed, driver will get a callback after we've given up on the major number.

In theory this means this major number can get reused by something else, resulting in a conflict.

Yes, there is a tiny race window.

Applied.

Thanks,
Rusty.