diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2014-10-14 19:52:33 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2014-10-14 19:55:12 -0400 |
commit | e67423c7b4f20c327de533b068907aab33720482 (patch) | |
tree | 48c0db846c0d9ca6bea32f87adfbfebb5b385c2c /drivers/scsi | |
parent | 1fa5b2a784dc52d929432bcc963a0bfb3a74608f (diff) |
virtio_scsi: fix race on device removal
We cancel event work on device removal, but an interrupt
could trigger immediately after this, and queue it
again.
To fix, set a flag.
Loosely based on patch by Paolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/virtio_scsi.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 29fd44a5d4dd..0227d39f45f0 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c | |||
@@ -110,6 +110,9 @@ struct virtio_scsi { | |||
110 | /* CPU hotplug notifier */ | 110 | /* CPU hotplug notifier */ |
111 | struct notifier_block nb; | 111 | struct notifier_block nb; |
112 | 112 | ||
113 | /* Protected by event_vq lock */ | ||
114 | bool stop_events; | ||
115 | |||
113 | struct virtio_scsi_vq ctrl_vq; | 116 | struct virtio_scsi_vq ctrl_vq; |
114 | struct virtio_scsi_vq event_vq; | 117 | struct virtio_scsi_vq event_vq; |
115 | struct virtio_scsi_vq req_vqs[]; | 118 | struct virtio_scsi_vq req_vqs[]; |
@@ -303,6 +306,11 @@ static void virtscsi_cancel_event_work(struct virtio_scsi *vscsi) | |||
303 | { | 306 | { |
304 | int i; | 307 | int i; |
305 | 308 | ||
309 | /* Stop scheduling work before calling cancel_work_sync. */ | ||
310 | spin_lock_irq(&vscsi->event_vq.vq_lock); | ||
311 | vscsi->stop_events = true; | ||
312 | spin_unlock_irq(&vscsi->event_vq.vq_lock); | ||
313 | |||
306 | for (i = 0; i < VIRTIO_SCSI_EVENT_LEN; i++) | 314 | for (i = 0; i < VIRTIO_SCSI_EVENT_LEN; i++) |
307 | cancel_work_sync(&vscsi->event_list[i].work); | 315 | cancel_work_sync(&vscsi->event_list[i].work); |
308 | } | 316 | } |
@@ -390,7 +398,8 @@ static void virtscsi_complete_event(struct virtio_scsi *vscsi, void *buf) | |||
390 | { | 398 | { |
391 | struct virtio_scsi_event_node *event_node = buf; | 399 | struct virtio_scsi_event_node *event_node = buf; |
392 | 400 | ||
393 | queue_work(system_freezable_wq, &event_node->work); | 401 | if (!vscsi->stop_events) |
402 | queue_work(system_freezable_wq, &event_node->work); | ||
394 | } | 403 | } |
395 | 404 | ||
396 | static void virtscsi_event_done(struct virtqueue *vq) | 405 | static void virtscsi_event_done(struct virtqueue *vq) |