All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/7] RFC/WIP: Fix scsi devices plug/unplug races w.r.t virtio-scsi iothread
@ 2020-05-11 16:09 Maxim Levitsky
  2020-05-11 16:09 ` [PATCH v2 1/7] scsi/scsi_bus: switch search direction in scsi_device_find Maxim Levitsky
                   ` (8 more replies)
  0 siblings, 9 replies; 26+ messages in thread
From: Maxim Levitsky @ 2020-05-11 16:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Daniel P. Berrangé,
	Eduardo Habkost, Michael S. Tsirkin, Maxim Levitsky,
	Paolo Bonzini

Hi!

This is a patch series that is a result of my discussion with Paulo on
how to correctly fix the root cause of the BZ #1812399.

The root cause of this bug is the fact that IO thread is running mostly
unlocked versus main thread on which device hotplug is done.

qdev_device_add first creates the device object, then places it on the bus,
and only then realizes it.

However some drivers and currently only virtio-scsi enumerate its child bus
devices on each request that is received from the guest and that can happen on the IO
thread.

Thus we have a window when new device is on the bus but not realized and can be accessed
by the virtio-scsi driver in that state.

Fix that by doing two things:

1. Add partial RCU protection to the list of a bus's child devices.
This allows the scsi IO thread to safely enumerate the child devices
while it races with the hotplug placing the device on the bus.

2. Make the virtio-scsi driver check .realized property of the scsi device
and avoid touching the device if it isn't

Note that in the particular bug report the issue wasn't a race but rather due
to combination of things, the .realize code in the middle managed to trigger IO on the virtqueue
which caused the virtio-scsi driver to access the half realized device. However
since this can happen as well with real IO thread, this patch series was done,
which fixes this as well.

Changes from V1:
  * Patch 2 is new, as suggested by Stefan, added drain_call_rcu() to fix the failing unit test,
    make check pass now

  * Patches 6,7 are new as well: I added scsi_device_get as suggested by Stefan as well, although
    this is more a refactoring that anything else as it doesn't solve
    an existing race.

  * Addressed most of the review feedback from V1
    - still need to decide if we need QTAILQ_FOREACH_WITH_RCU_READ_LOCK

The series were tested with make check and smoke tested by booting a VM and
adding/removing few virtio-scsi disks from it in a loop.

Best regards,
	Maxim Levitsky

Maxim Levitsky (7):
  scsi/scsi_bus: switch search direction in scsi_device_find
  Implement drain_call_rcu and use it in hmp_device_del
  device-core: use RCU for list of childs of a bus
  device-core: use atomic_set on .realized property
  virtio-scsi: don't touch scsi devices that are not yet realized or
    about to be un-realized
  scsi: Add scsi_device_get
  virtio-scsi: use scsi_device_get

 hw/core/bus.c          | 36 ++++++++++++++++++-----------
 hw/core/qdev.c         | 52 ++++++++++++++++++++++++++++++------------
 hw/scsi/scsi-bus.c     | 48 +++++++++++++++++++++++++++++++++-----
 hw/scsi/virtio-scsi.c  | 46 +++++++++++++++++++++++++++++--------
 include/hw/qdev-core.h |  3 +++
 include/hw/scsi/scsi.h |  2 ++
 include/qemu/rcu.h     |  1 +
 qdev-monitor.c         |  3 +++
 util/rcu.c             | 33 +++++++++++++++++++++++++++
 9 files changed, 181 insertions(+), 43 deletions(-)

-- 
2.17.2



^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2020-07-09 12:03 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 16:09 [PATCH v2 0/7] RFC/WIP: Fix scsi devices plug/unplug races w.r.t virtio-scsi iothread Maxim Levitsky
2020-05-11 16:09 ` [PATCH v2 1/7] scsi/scsi_bus: switch search direction in scsi_device_find Maxim Levitsky
2020-05-27 12:53   ` Stefan Hajnoczi
2020-05-11 16:09 ` [PATCH v2 2/7] Implement drain_call_rcu and use it in hmp_device_del Maxim Levitsky
2020-05-27 13:11   ` Stefan Hajnoczi
2020-07-09  9:34     ` Maxim Levitsky
2020-07-09 11:42   ` Markus Armbruster
2020-07-09 11:56     ` Maxim Levitsky
2020-07-09 12:02       ` Paolo Bonzini
2020-05-11 16:09 ` [PATCH v2 3/7] device-core: use RCU for list of childs of a bus Maxim Levitsky
2020-05-27 14:45   ` Stefan Hajnoczi
2020-07-09  9:40     ` Maxim Levitsky
2020-05-11 16:09 ` [PATCH v2 4/7] device-core: use atomic_set on .realized property Maxim Levitsky
2020-05-27 15:00   ` Stefan Hajnoczi
2020-07-09 10:24     ` Maxim Levitsky
2020-05-11 16:09 ` [PATCH v2 5/7] virtio-scsi: don't touch scsi devices that are not yet realized or about to be un-realized Maxim Levitsky
2020-05-27 15:08   ` Stefan Hajnoczi
2020-05-11 16:09 ` [PATCH v2 6/7] scsi: Add scsi_device_get Maxim Levitsky
2020-05-27 15:27   ` Stefan Hajnoczi
2020-07-09 10:35     ` Maxim Levitsky
2020-05-11 16:09 ` [PATCH v2 7/7] virtio-scsi: use scsi_device_get Maxim Levitsky
2020-05-27 15:50   ` Stefan Hajnoczi
2020-07-09 10:43     ` Maxim Levitsky
2020-05-27 15:50   ` Stefan Hajnoczi
2020-05-11 18:03 ` [PATCH v2 0/7] RFC/WIP: Fix scsi devices plug/unplug races w.r.t virtio-scsi iothread no-reply
2020-05-11 18:03 ` no-reply

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.