virtio: features, cleanups
The following changes since commit 16884391c750d0c5e863f55ad7aaaa146fc5181e:
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2019-10-29' into staging (2019-10-29 20:06:08 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
for you to fetch changes up to b5f53d04a5a567ac70d33ec95628d35583eba600:
virtio: Use auto rcu_read macros (2019-10-29 18:56:45 -0400)
----------------------------------------------------------------
virtio: features, cleanups
virtio net failover
rcu cleanup
----------------------------------------------------------------
Dr. David Alan Gilbert (3):
virtio/vhost: Use auto_rcu_read macros
virtio_net: use RCU_READ_LOCK_GUARD
virtio: Use auto rcu_read macros
Jens Freimann (11):
qdev/qbus: add hidden device support
pci: add option for net failover
pci: mark devices partially unplugged
pci: mark device having guest unplug request pending
qapi: add unplug primary event
qapi: add failover negotiated event
migration: allow unplug during migration for failover devices
migration: add new migration state wait-unplug
libqos: tolerate wait-unplug migration state net/virtio: add failover support
vfio: unplug failover primary device before migration
qapi/migration.json | 24 +++- qapi/net.json | 19 +++ hw/vfio/pci.h | 1 + include/hw/pci/pci.h | 4 + include/hw/qdev-core.h | 30 ++++ include/hw/virtio/virtio-net.h | 12 ++ include/hw/virtio/virtio.h | 1 + include/migration/vmstate.h | 2 + migration/migration.h | 3 + migration/savevm.h | 2 + hw/core/qdev.c | 25 ++++ hw/net/virtio-net.c | 309 ++++++++++++++++++++++++++++++++++++++++- hw/pci/pci.c | 32 +++++ hw/pci/pcie.c | 6 + hw/vfio/pci.c | 26 +++- hw/virtio/vhost.c | 4 +- hw/virtio/virtio.c | 65 +++------ migration/migration.c | 21 +++ migration/savevm.c | 31 +++++ qdev-monitor.c | 43 +++++- tests/libqos/libqos.c | 3 +- vl.c | 6 +- MAINTAINERS | 1 + docs/virtio-net-failover.rst | 68 +++++++++ 24 files changed, 673 insertions(+), 65 deletions(-) create mode 100644 docs/virtio-net-failover.rst
[PULL 04/14] pci: mark device having guest unplug request pending
From: Jens Freimann <[email protected]>
Set pending_deleted_event in DeviceState for failover primary devices that were successfully unplugged by the Guest OS.
Message-Id: <[email protected]>
--- hw/pci/pcie.c | 3 +++ 1 file changed, 3 insertions(+)
hw/pci/pcie.c +3 -0
@@ -457,6 +457,7 @@ static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque)HotplugHandler *hotplug_ctrl =qdev_get_hotplug_handler (DEVICE (dev));if (dev->partially_hotplugged) { + dev->qdev.pending_deleted_event = false;return ; }hotplug_handler_unplug (hotplug_ctrl,DEVICE (dev), &error_abort);
@@ -476,6 +477,8 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,return ; } + dev->pending_deleted_event = true; +/* In case user cancel the operation of multi-function hot-add, * remove the function that is unexposed to guest individually, * without interaction with guest.
Signature · 1 line
MST
[PULL 05/14] qapi: add unplug primary event
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
This event is emitted when we sent a request to unplug a failover primary device from the Guest OS and it includes the device id of the primary device.
Message-Id: <[email protected]>
--- qapi/migration.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
qapi/migration.json +19 -0
@@ -1448,3 +1448,22 @@ # Since: 3.0 ## { 'command': 'migrate-pause', 'allow-oob': true } + +## +# @UNPLUG_PRIMARY: +# +# Emitted from source side of a migration when migration state is +# WAIT_UNPLUG. Device was unplugged by guest operating system. +# Device resources in QEMU are kept on standby to be able to re-plug it in case +# of migration failure. +# +# @device-id: QEMU device id of the unplugged device +# +# Since: 4.2 +# +# Example: +# {"event": "UNPLUG_PRIMARY", "data": {"device-id": "hostdev0"} } +# +## +{ 'event': 'UNPLUG_PRIMARY', + 'data': { 'device-id': 'str' } }
Signature · 1 line
MST
Re: [PULL 05/14] qapi: add unplug primary event
Quoted 17 lines · Michael S. Tsirkin
From: Jens Freimann <[email protected]>
This event is emitted when we sent a request to unplug a failover primary device from the Guest OS and it includes the device id of the primary device.
Signed-off-by Jens Freimann <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>--- qapi/migration.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)qapi/migration.json +1
-0+##
qapi/migration.json line 1462
Quoted 10 lines
qapi/migration.json +10
-0+# @UNPLUG_PRIMARY: +# +# Emitted from source side of a migration when migration state is +# WAIT_UNPLUG. Device was unplugged by guest operating system. +# Device resources in QEMU are kept on standby to be able to re-plug it in case +# of migration failure. +# +# @device-id: QEMU device id of the unplugged device +# +# Since: 4.2
s/4.2/5.1/
I'm not sure if the pull request will be respun for other reasons; if not, fixing this in a followup patch may be the way to go.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PULL 05/14] qapi: add unplug primary event
Quoted 32 lines · Eric Blake
Quoted 23 lines · Michael S. Tsirkin
From: Jens Freimann <[email protected]>
This event is emitted when we sent a request to unplug a failover primary device from the Guest OS and it includes the device id of the primary device.
Signed-off-by Jens Freimann <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
qapi/migration.json| 19 +++++++++++++++++++1 file changed, 19 insertions(+)qapi/migration.json +6
-0+## +# @UNPLUG_PRIMARY: +# +# Emitted from source side of a migration when migration state is +# WAIT_UNPLUG. Device was unplugged by guest operating system. +# Device resources in QEMU are kept on standby to be able to re-plugit in case
qapi/migration.json line 1462
Quoted 5 lines
qapi/migration.json +5
-0+# of migration failure. +# +# @device-id: QEMU device id of the unplugged device +# +# Since: 4.2s/4.2/5.1/
Quoted 1 line
I'm not sure if the pull request will be respun for other reasons; if not, fixing this in a followup patch may be the way to go.
Sorry, my bad for not checking the dates. The thread moved to the top of my queue due to the belated report of a Coverity incident; but I now see that this really was included in the tree during 4.2.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
[PULL 06/14] qapi: add failover negotiated event
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
This event is sent to let libvirt know that VIRTIO_NET_F_STANDBY feature is enabled. The primary device this virtio-net (standby) device is associated with, is now hotplugged by the virtio-net device.
Message-Id: <[email protected]>
--- qapi/net.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
qapi/net.json +19 -0
@@ -735,3 +735,22 @@ ## { 'command': 'announce-self', 'boxed': true, 'data' : 'AnnounceParameters'} + +## +# @FAILOVER_NEGOTIATED: +# +# Emitted when VIRTIO_NET_F_STANDBY was enabled during feature negotiation. +# Failover primary devices which were hidden (not hotplugged when requested) +# before will now be hotplugged by the virtio-net standby device. +# +# device-id: QEMU device id of the unplugged device +# Since: 4.2 +# +# Example: +# +# <- { "event": "FAILOVER_NEGOTIATED", +# "data": "net1" } +# +## +{ 'event': 'FAILOVER_NEGOTIATED', + 'data': {'device-id': 'str'} }
Signature · 1 line
MST
[PULL 08/14] migration: add new migration state wait-unplug
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
This patch adds a new migration state called wait-unplug. It is entered after the SETUP state if failover devices are present. It will transition into ACTIVE once all devices were succesfully unplugged from the guest.
So if a guest doesn't respond or takes long to honor the unplug request the user will see the migration state 'wait-unplug'.
In the migration thread we query failover devices if they're are still pending the guest unplug. When all are unplugged the migration continues. If one device won't unplug migration will stay in wait_unplug state.
Message-Id: <[email protected]>
--- include/migration/vmstate.h | 2 ++ migration/migration.c | 21 +++++++++++++++++++++ migration/migration.h | 3 +++ migration/savevm.c | 31 +++++++++++++++++++++++++++++++ migration/savevm.h | 2 ++ qapi/migration.json | 5 ++++- 6 files changed, 63 insertions(+), 1 deletion(-)
include/migration/vmstate.h +2 -0
@@ -186,6 +186,8 @@ struct VMStateDescription {int (*pre_save)(void *opaque);int (*post_save)(void *opaque);bool (*needed)(void *opaque); +bool (*dev_unplug_pending)(void *opaque); +const VMStateField *fields;const VMStateDescription **subsections; };
migration/migration.c +21 -0
@@ -52,6 +52,7 @@#include "hw/qdev-properties.h" #include "monitor/monitor.h" #include "net/announce.h" +#include "qemu/queue.h" #define MAX_THROTTLE (32 << 20)/* Migration transfer speed throttling */
@@ -819,6 +820,7 @@ bool migration_is_setup_or_active(int state)case MIGRATION_STATUS_SETUP :case MIGRATION_STATUS_PRE_SWITCHOVER :case MIGRATION_STATUS_DEVICE : +case MIGRATION_STATUS_WAIT_UNPLUG :return true;default :
@@ -954,6 +956,9 @@ static void fill_source_migration_info(MigrationInfo *info)case MIGRATION_STATUS_CANCELLED : info->has_status = true;break ; +case MIGRATION_STATUS_WAIT_UNPLUG : + info->has_status = true; +break ; } info->status = s->state; }
@@ -1694,6 +1699,7 @@ bool migration_is_idle(void)case MIGRATION_STATUS_COLO :case MIGRATION_STATUS_PRE_SWITCHOVER :case MIGRATION_STATUS_DEVICE : +case MIGRATION_STATUS_WAIT_UNPLUG :return false;case MIGRATION_STATUS__MAX :g_assert_not_reached ();
@@ -3264,6 +3270,19 @@ static void *migration_thread(void *opaque)qemu_savevm_state_setup (s->to_dst_file); +if (qemu_savevm_nr_failover_devices ()) { +migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , +MIGRATION_STATUS_WAIT_UNPLUG ); + +while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && +qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 ); + } + +migrate_set_state (&s->state,MIGRATION_STATUS_WAIT_UNPLUG , +MIGRATION_STATUS_ACTIVE ); + } + s->setup_time =qemu_clock_get_ms (QEMU_CLOCK_HOST ) - setup_start;migrate_set_state (&s->state,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );
@@ -3511,6 +3530,7 @@ static void migration_instance_finalize(Object *obj)qemu_mutex_destroy (&ms->qemu_file_lock);g_free (params->tls_hostname);g_free (params->tls_creds); +qemu_sem_destroy (&ms->wait_unplug_sem);qemu_sem_destroy (&ms->rate_limit_sem);qemu_sem_destroy (&ms->pause_sem);qemu_sem_destroy (&ms->postcopy_pause_sem);
@@ -3556,6 +3576,7 @@ static void migration_instance_init(Object *obj)qemu_sem_init (&ms->postcopy_pause_rp_sem,0 );qemu_sem_init (&ms->rp_state.rp_sem,0 );qemu_sem_init (&ms->rate_limit_sem,0 ); +qemu_sem_init (&ms->wait_unplug_sem,0 );qemu_mutex_init (&ms->qemu_file_lock); }
migration/migration.h +3 -0
@@ -206,6 +206,9 @@ struct MigrationState/* Flag set once the migration thread called bdrv_inactivate_all */ bool block_inactive; +/* Migration is waiting for guest to unplug device */ +QemuSemaphore wait_unplug_sem; +/* Migration is paused due to pause-before-switchover */ QemuSemaphore pause_sem;
migration/savevm.c +31 -0
@@ -1113,6 +1113,37 @@ void qemu_savevm_state_header(QEMUFile *f) } } +int qemu_savevm_nr_failover_devices (void ) +{ +SaveStateEntry *se; +int n =0 ; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (se->vmsd && se->vmsd->dev_unplug_pending) { + n++; + } + } + +return n; +} + +bool qemu_savevm_state_guest_unplug_pending (void ) +{ +SaveStateEntry *se; +int n =0 ; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->vmsd || !se->vmsd->dev_unplug_pending) { +continue ; + } +if (se->vmsd->dev_unplug_pending (se->opaque)) { + n++; + } + } + +return n >0 ; +} +void qemu_savevm_state_setup (QEMUFile *f) {SaveStateEntry *se;
migration/savevm.h +2 -0
@@ -31,6 +31,8 @@bool qemu_savevm_state_blocked (Error **errp);void qemu_savevm_state_setup (QEMUFile *f); +int qemu_savevm_nr_failover_devices (void ); +bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_state_header (QEMUFile *f);int qemu_savevm_state_iterate (QEMUFile *f,bool postcopy);
qapi/migration.json +4 -1
@@ -133,6 +133,9 @@ # @device: During device serialisation when pause-before-switchover is enabled # (since 2.11) # +# @wait-unplug: wait for device unplug request by guest OS to be completed. +# (since 4.2) +# # Since: 2.3 # ##
@@ -140,7 +143,7 @@ 'data': [ 'none', 'setup', 'cancelling', 'cancelled', 'active', 'postcopy-active', 'postcopy-paused', 'postcopy-recover', 'completed', 'failed', 'colo', - 'pre-switchover', 'device' ] } + 'pre-switchover', 'device', 'wait-unplug' ] } ## # @MigrationInfo:
Signature · 1 line
MST
Re: [PULL 08/14] migration: add new migration state wait-unplug
Quoted 15 lines · Michael S. Tsirkin
From: Jens Freimann <[email protected]>
This patch adds a new migration state called wait-unplug. It is entered after the SETUP state if failover devices are present. It will transition into ACTIVE once all devices were succesfully unplugged from the guest.
So if a guest doesn't respond or takes long to honor the unplug request the user will see the migration state 'wait-unplug'.
In the migration thread we query failover devices if they're are still pending the guest unplug. When all are unplugged the migration continues. If one device won't unplug migration will stay in
wait_unplugstate.
Quoted 6 lines
Signed-off-by Jens Freimann <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
Hi; Coverity has just (rather belatedly) noticed a possible issue in this code (CID 1429995):
migration/migration.c static void *migration_thread(void *opaque) · line 3279
Quoted 11 lines
migration/migration.c +7
-0@@ -3264,6 +3270,19 @@ static void *migration_thread(void *opaque)qemu_savevm_state_setup (s->to_dst_file); +if (qemu_savevm_nr_failover_devices ()) { +migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , +MIGRATION_STATUS_WAIT_UNPLUG ); + +while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && +qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 );
Here we call qemu_sem_timedwait() but ignore the return value, whereas all the other callsites for that function do something with the return value. Is the code correct? (This is just a heuristic Coverity has, and it's wrong a fair amount of the time, so if it's wrong here too I can just mark it as a false-positive in the Coverity UI.)
thanks
-- PMM
Re: [PULL 08/14] migration: add new migration state wait-unplug
Quoted 30 lines · * Peter Maydell ([email protected]) wrote:
Quoted 15 lines · Michael S. Tsirkin
From: Jens Freimann <[email protected]>
This patch adds a new migration state called wait-unplug. It is entered after the SETUP state if failover devices are present. It will transition into ACTIVE once all devices were succesfully unplugged from the guest.
So if a guest doesn't respond or takes long to honor the unplug request the user will see the migration state 'wait-unplug'.
In the migration thread we query failover devices if they're are still pending the guest unplug. When all are unplugged the migration continues. If one device won't unplug migration will stay in
wait_unplugstate.Quoted 6 lines
Signed-off-by Jens Freimann <[email protected]>Reviewed-by Dr. David Alan Gilbert <[email protected]>Message-Id: <[email protected]>
Reviewed-by Michael S. Tsirkin <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
Hi; Coverity has just (rather belatedly) noticed a possible issue in this code (CID 1429995):
Quoted 4 lines
migration/migration.c +0
-0@@ -3264,6 +3270,19 @@ static void *migration_thread(void *opaque)qemu_savevm_state_setup (s->to_dst_file);
Quoted 14 lines
migration/migration.c static void *migration_thread(void *opaque) · line 3279
Quoted 7 lines
migration/migration.c +7
-0+if (qemu_savevm_nr_failover_devices ()) { +migrate_set_state (&s->state,MIGRATION_STATUS_SETUP , +MIGRATION_STATUS_WAIT_UNPLUG ); + +while (s->state ==MIGRATION_STATUS_WAIT_UNPLUG && +qemu_savevm_state_guest_unplug_pending ()) { +qemu_sem_timedwait (&s->wait_unplug_sem,250 );Here we call
qemu_sem_timedwait()but ignore the return value, whereas all the other callsites for that function do something with the return value. Is the code correct? (This is just a heuristic Coverity has, and it's wrong a fair amount of the time, so if it's wrong here too I can just mark it as a false-positive in the Coverity UI.)
Hmm it's OK; that semaphore isn't really used at the moment, so it's pretty much just a sleep. And the loop always calls the qemu_savevm_state_guest_unplug_pending() before it goes around again; so it doesn't care if the return value indicates timeout or not.
Dave
Quoted 3 lines
thanks
-- PMM
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PULL 08/14] migration: add new migration state wait-unplug
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 6 lines · * Peter Maydell ([email protected]) wrote:
Here we call
qemu_sem_timedwait()but ignore the return value, whereas all the other callsites for that function do something with the return value. Is the code correct? (This is just a heuristic Coverity has, and it's wrong a fair amount of the time, so if it's wrong here too I can just mark it as a false-positive in the Coverity UI.)
Quoted 5 lines
Hmm it's OK; that semaphore isn't really used at the moment, so it's pretty much just a sleep. And the loop always calls the
qemu_savevm_state_guest_unplug_pending()before it goes around again; so it doesn't care if the return value indicates timeout or not.
Thanks; have marked it as a false-positive in the UI.
-- PMM
[PULL 03/14] pci: mark devices partially unplugged
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
Only the guest unplug request was triggered. This is needed for the failover feature. In case of a failed migration we need to plug the device back to the guest.
Message-Id: <[email protected]>
--- hw/pci/pcie.c | 3 +++ include/hw/pci/pci.h | 1 + 2 files changed, 4 insertions(+)
hw/pci/pcie.c +3 -0
@@ -456,6 +456,9 @@ static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque) {HotplugHandler *hotplug_ctrl =qdev_get_hotplug_handler (DEVICE (dev)); +if (dev->partially_hotplugged) { +return ; + }hotplug_handler_unplug (hotplug_ctrl,DEVICE (dev), &error_abort);object_unparent (OBJECT (dev)); }
include/hw/pci/pci.h +1 -0
@@ -265,6 +265,7 @@ typedef struct PCIReqIDCache PCIReqIDCache;struct PCIDevice {DeviceState qdev; +bool partially_hotplugged;/* PCI config space */ uint8_t *config;
Signature · 1 line
MST
[PULL 12/14] virtio/vhost: Use auto_rcu_read macros
In reply to Michael S. TsirkinFrom: "Dr. David Alan Gilbert" <[email protected]>
Use RCU_READ_LOCK_GUARD instead of manual rcu_read_(un)lock
Message-Id: <[email protected]>
--- hw/virtio/vhost.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/virtio/vhost.c +1 -3
@@ -924,7 +924,7 @@ int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write)uint64_t uaddr, len;int ret = -EFAULT ; -rcu_read_lock (); +RCU_READ_LOCK_GUARD ();trace_vhost_iotlb_miss (dev,1 );
@@ -956,8 +956,6 @@ int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write)trace_vhost_iotlb_miss (dev,2 ); out: -rcu_read_unlock (); -return ret; }
Signature · 1 line
MST
[PULL 01/14] qdev/qbus: add hidden device support
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
This adds support for hiding a device to the qbus and qdev APIs. The first user of this will be the virtio-net failover feature but the API introduced with this patch could be used to implement other features as well, for example hiding pci devices when a pci bus is powered off.
qdev_device_add() is modified to check for a failover_pair_id argument in the option string. A DeviceListener callback should_be_hidden() is added. It can be used by a standby device to inform qdev that this device should not be added now. The standby device handler can store the device options to plug the device in at a later point in time.
One reason for hiding the device is that we don't want to expose both devices to the guest kernel until the respective virtio feature bit VIRTIO_NET_F_STANDBY was negotiated and we know that the devices will be handled correctly by the guest.
More information on the kernel feature this is using:
https://www.kernel.org/doc/html/latest/networking/net_failover.html
An example where the primary device is a vfio-pci device and the standby device is a virtio-net device:
A device is hidden when it has an "failover_pair_id" option, e.g.
-device virtio-net-pci,...,failover=on,...
-device vfio-pci,...,failover_pair_id=net1,...
Message-Id: <[email protected]>
--- hw/core/qdev.c | 24 ++++++++++++++++++++++++ include/hw/qdev-core.h | 29 +++++++++++++++++++++++++++++ qdev-monitor.c | 41 +++++++++++++++++++++++++++++++++++++---- vl.c | 6 ++++-- 4 files changed, 94 insertions(+), 6 deletions(-)
hw/core/qdev.c +24 -0
@@ -212,6 +212,30 @@ void device_listener_unregister(DeviceListener *listener)QTAILQ_REMOVE (&device_listeners, listener, link); } +bool qdev_should_hide_device (QemuOpts *opts) +{ +int rc =-1 ; +DeviceListener *listener; + + QTAILQ_FOREACH(listener, &device_listeners, link) { +if (listener->should_be_hidden) { +/* +* should_be_hidden_will return +* 1 if device matches opts and it should be hidden +* 0 if device matches opts and should not be hidden +* -1 if device doesn't match ops +*/ + rc = listener->should_be_hidden (listener, opts); + } + +if (rc >0 ) { +break ; + } + } + +return rc >0 ; +} +void qdev_set_legacy_instance_id (DeviceState *dev,int alias_id,int required_for_version) {
include/hw/qdev-core.h +29 -0
@@ -78,6 +78,19 @@ typedef void (*BusUnrealize)(BusState *bus, Error **errp);* respective parent types. * </para> * </note> +* +* # Hiding a device # +* To hide a device, a DeviceListener function should_be_hidden() needs to +* be registered. +* It can be used to defer adding a device and therefore hide it from the +* guest. The handler registering to this DeviceListener can save the QOpts +* passed to it for re-using it later and must return that it wants the device +* to be/remain hidden or not. When the handler function decides the device +* shall not be hidden it will be added in qdev_device_add() and +* realized as any other device. Otherwise qdev_device_add() will return early +* without adding the device. The guest will not see a "hidden" device +* until it was marked don't hide and qdev_device_add called again. +* */ typedef struct DeviceClass { /*< private >*/
@@ -154,6 +167,12 @@ struct DeviceState {struct DeviceListener {void (*realize)(DeviceListener *listener,DeviceState *dev);void (*unrealize)(DeviceListener *listener,DeviceState *dev); +/* +* This callback is called upon init of the DeviceState and allows to +* inform qdev that a device should be hidden, depending on the device +* opts, for example, to hide a standby device. +*/ +int (*should_be_hidden)(DeviceListener *listener,QemuOpts *device_opts);QTAILQ_ENTRY (DeviceListener) link; };
@@ -451,4 +470,14 @@ static inline bool qbus_is_hotpluggable(BusState *bus)void device_listener_register (DeviceListener *listener);void device_listener_unregister (DeviceListener *listener); +/** +* @qdev_should_hide_device: +* @opts: QemuOpts as passed on cmdline. +* +* Check if a device should be added. +* When a device is added via qdev_device_add() this will be called, +* and return if the device should be added now or not. +*/ +bool qdev_should_hide_device (QemuOpts *opts); +#endif
qdev-monitor.c +37 -4
78 lines not on this page · raw message
vl.c +4 -2
@@ -2207,10 +2207,12 @@ static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)DeviceState *dev; dev =qdev_device_add (opts, errp); -if (!dev) { +if (!dev && *errp) { +error_report_err (*errp);return -1 ; + }else if (dev) { +object_unref (OBJECT (dev)); } -object_unref (OBJECT (dev));return 0 ; }
Signature · 1 line
MST
[PULL 07/14] migration: allow unplug during migration for failover devices
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
In "b06424de62 migration: Disable hotplug/unplug during migration" we added a check to disable unplug for all devices until we have figured out what works. For failover primary devices qdev_unplug() is called from the migration handler, i.e. during migration.
This patch adds a flag to DeviceState which is set to false for all devices and makes an exception for PCI devices that are also primary devices in a failover pair.
Message-Id: <[email protected]>
--- hw/core/qdev.c | 1 + hw/pci/pci.c | 1 + include/hw/qdev-core.h | 1 + qdev-monitor.c | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-)
hw/core/qdev.c +1 -0
@@ -996,6 +996,7 @@ static void device_initfn(Object *obj) dev->instance_id_alias =-1 ; dev->realized = false; + dev->allow_unplug_during_migration = false;object_property_add_bool (obj,"realized" , device_get_realized, device_set_realized,NULL );
hw/pci/pci.c +1 -0
@@ -2130,6 +2130,7 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)pci_qdev_unrealize (DEVICE (pci_dev),NULL );return ; } + qdev->allow_unplug_during_migration = true; }/* rom loading */
include/hw/qdev-core.h +1 -0
@@ -156,6 +156,7 @@ struct DeviceState {bool pending_deleted_event;QemuOpts *opts;int hotplugged; +bool allow_unplug_during_migration;BusState *parent_bus; QLIST_HEAD(, NamedGPIOList) gpios; QLIST_HEAD(, BusState) child_bus;
qdev-monitor.c +1 -1
@@ -851,7 +851,7 @@ void qdev_unplug(DeviceState *dev, Error **errp)return ; } -if (!migration_is_idle ()) { +if (!migration_is_idle () && !dev->allow_unplug_during_migration) {error_setg (errp,"device_del not allowed while migrating" );return ; }
Signature · 1 line
MST
[PULL 13/14] virtio_net: use RCU_READ_LOCK_GUARD
In reply to Michael S. TsirkinFrom: "Dr. David Alan Gilbert" <[email protected]>
Use RCU_READ_LOCK_GUARD rather than the manual rcu_read_(un)lock call.
Message-Id: <[email protected]>
--- hw/net/virtio-net.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/net/virtio-net.c +2 -5
@@ -1490,12 +1490,9 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,static ssize_t virtio_net_do_receive (NetClientState *nc,const uint8_t *buf,size_t size) { -ssize_t r; +RCU_READ_LOCK_GUARD (); -rcu_read_lock (); - r =virtio_net_receive_rcu (nc, buf, size); -rcu_read_unlock (); -return r; +return virtio_net_receive_rcu (nc, buf, size); } static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain,
Signature · 1 line
MST
[PULL 02/14] pci: add option for net failover
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
This patch adds a failover_pair_id property to PCIDev which is used to link the primary device in a failover pair (the PCI dev) to a standby (a virtio-net-pci) device.
It only supports ethernet devices. Also currently it only supports PCIe devices. The requirement for PCIe is because it doesn't support other hotplug controllers at the moment. The failover functionality can be added to other hotplug controllers like ACPI, SHCP,... later on.
Message-Id: <[email protected]>
--- hw/pci/pci.c | 31 +++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 3 +++ 2 files changed, 34 insertions(+)
hw/pci/pci.c +31 -0
@@ -75,6 +75,8 @@ static Property pci_props[] = { QEMU_PCIE_LNKSTA_DLLLA_BITNR, true),DEFINE_PROP_BIT ("x-pcie-extcap-init" , PCIDevice, cap_present,QEMU_PCIE_EXTCAP_INIT_BITNR , true), +DEFINE_PROP_STRING ("failover_pair_id" , PCIDevice, + failover_pair_id), DEFINE_PROP_END_OF_LIST() };
@@ -2077,6 +2079,7 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)ObjectClass *klass =OBJECT_CLASS (pc);Error *local_err =NULL ;bool is_default_rom; +uint16_t class_id;/* initialize cap_present for pci_is_express() and pci_config_size(), * Note that hybrid PCIs are not set automatically and need to manage
@@ -2101,6 +2104,34 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp) } } +if (pci_dev->failover_pair_id) { +if (!pci_bus_is_express (pci_get_bus (pci_dev))) { +error_setg (errp,"failover primary device must be on " +"PCIExpress bus" ); +error_propagate (errp, local_err); +pci_qdev_unrealize (DEVICE (pci_dev),NULL ); +return ; + } + class_id =pci_get_word (pci_dev->config +PCI_CLASS_DEVICE ); +if (class_id !=PCI_CLASS_NETWORK_ETHERNET ) { +error_setg (errp,"failover primary device is not an " +"Ethernet device" ); +error_propagate (errp, local_err); +pci_qdev_unrealize (DEVICE (pci_dev),NULL ); +return ; + } +if (!(pci_dev->cap_present &QEMU_PCI_CAP_MULTIFUNCTION ) + && (PCI_FUNC (pci_dev->devfn) ==0 )) { + qdev->allow_unplug_during_migration = true; + }else { +error_setg (errp,"failover: primary device must be in its own " +"PCI slot" ); +error_propagate (errp, local_err); +pci_qdev_unrealize (DEVICE (pci_dev),NULL ); +return ; + } + } +/* rom loading */ is_default_rom = false;if (pci_dev->romfile ==NULL && pc->romfile !=NULL ) {
include/hw/pci/pci.h +3 -0
@@ -352,6 +352,9 @@ struct PCIDevice {MSIVectorUseNotifier msix_vector_use_notifier;MSIVectorReleaseNotifier msix_vector_release_notifier;MSIVectorPollNotifier msix_vector_poll_notifier; + +/* ID of standby device in net_failover pair */ +char *failover_pair_id; }; void pci_register_bar(PCIDevice *pci_dev, int region_num,
Signature · 1 line
MST
[PULL 09/14] libqos: tolerate wait-unplug migration state
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
Message-Id: <[email protected]>
--- tests/libqos/libqos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/libqos/libqos.c +2 -1
@@ -125,7 +125,8 @@ void migrate(QOSState *from, QOSState *to, const char *uri)break ; } -if ((strcmp (st,"setup" ) ==0 ) || (strcmp (st,"active" ) ==0 )) { +if ((strcmp (st,"setup" ) ==0 ) || (strcmp (st,"active" ) ==0 ) + || (strcmp (st,"wait-unplug" ) ==0 )) {qobject_unref (rsp);g_usleep (5000 );continue ;
Signature · 1 line
MST
[PULL 10/14] net/virtio: add failover support
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
This patch adds support to handle failover device pairs of a virtio-net device and a (vfio-)pci device, where the virtio-net acts as the standby device and the (vfio-)pci device as the primary.
The general idea is that we have a pair of devices, a (vfio-)pci and a emulated (virtio-net) device. Before migration the vfio device is unplugged and data flows to the emulated device, on the target side another (vfio-)pci device is plugged in to take over the data-path. In the guest the net_failover module will pair net devices with the same MAC address.
To achieve this we need:
1. Provide a callback function for the should_be_hidden DeviceListener. It is called when the primary device is plugged in. Evaluate the QOpt passed in to check if it is the matching primary device. It returns if the device should be hidden or not.
When it should be hidden it stores the device options in the VirtioNet struct and the device is added once the VIRTIO_NET_F_STANDBY feature is negotiated during virtio feature negotiation.
If the virtio-net devices are not realized at the time the (vfio-)pci devices are realized, we need to connect the devices later. This way we make sure primary and standby devices can be specified in any order.
2. Register a callback for migration status notifier. When called it will unplug its primary device before the migration happens.
3. Register a callback for the migration code that checks if a device needs to be unplugged from the guest.
Message-Id: <[email protected]>
--- MAINTAINERS | 1 + docs/virtio-net-failover.rst | 68 ++++++++ hw/net/virtio-net.c | 302 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-net.h | 12 ++ include/hw/virtio/virtio.h | 1 + 5 files changed, 384 insertions(+) create mode 100644 docs/virtio-net-failover.rst
MAINTAINERS +1 -0
@@ -1435,6 +1435,7 @@ S: Odd Fixes F: hw/net/ F: include/hw/net/ F: tests/virtio-net-test.c +F: docs/virtio-net-failover.rst T: git https://github.com/jasowang/qemu.git net Parallel NOR Flash devices
docs/virtio-net-failover.rst new file +68 -0
68 lines not on this page · raw message
hw/net/virtio-net.c +302 -0
382 lines not on this page · raw message
include/hw/virtio/virtio-net.h +12 -0
@@ -18,6 +18,7 @@#include "standard-headers/linux/virtio_net.h" #include "hw/virtio/virtio.h" #include "net/announce.h" +#include "qemu/option_int.h" #define TYPE_VIRTIO_NET "virtio-net-device"#define VIRTIO_NET (obj) \
@@ -43,6 +44,7 @@ typedef struct virtio_net_confint32_t speed;char *duplex_str;uint8_t duplex; +char *primary_id_str; } virtio_net_conf;/* Coalesced packets type & status */
@@ -187,6 +189,16 @@ struct VirtIONet {AnnounceTimer announce_timer;bool needs_vnet_hdr_swap;bool mtu_bypass_backend; +QemuOpts *primary_device_opts; +QDict *primary_device_dict; +DeviceState *primary_dev; +BusState *primary_bus; +char *primary_device_id; +char *standby_id; +bool primary_should_be_hidden; +bool failover; +DeviceListener primary_listener; +Notifier migration_state; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
include/hw/virtio/virtio.h +1 -0
@@ -160,6 +160,7 @@ typedef struct VirtioDeviceClass {*/ int (*post_load)(VirtIODevice *vdev);const VMStateDescription *vmsd; +bool (*primary_unplug_pending)(void *opaque); } VirtioDeviceClass; void virtio_instance_init_common(Object *proxy_obj, void *data,
Signature · 1 line
MST
Re: [PULL 10/14] net/virtio: add failover support
Quoted 6 lines · Michael S. Tsirkin
From: Jens Freimann <[email protected]>
This patch adds support to handle failover device pairs of a virtio-net device and a (vfio-)pci device, where the virtio-net acts as the standby device and the (vfio-)pci device as the primary.
Hi; Coverity reports some dereference-before-NULL-check errors in this commit:
Quoted 5 lines
hw/net/virtio-net.c +5
-0+static bool failover_replug_primary (VirtIONet *n,Error **errp) +{ +HotplugHandler *hotplug_ctrl; +PCIDevice *pdev =PCI_DEVICE (n->primary_dev); +
hw/net/virtio-net.c void virtio_net_set_netclient_name(VirtIONet *n, const char *name, · line 2809
Quoted 10 lines
hw/net/virtio-net.c +10
-0+if (!pdev->partially_hotplugged) { +return true; + } +if (!n->primary_device_opts) { + n->primary_device_opts =qemu_opts_from_qdict ( +qemu_find_opts ("device" ), + n->primary_device_dict, errp); + } +if (n->primary_device_opts) { +if (n->primary_dev) {
Here we check whether n->primary_dev is NULL...
hw/net/virtio-net.c void virtio_net_set_netclient_name(VirtIONet *n, const char *name, · line 2812
Quoted 3 lines
hw/net/virtio-net.c +3
-0+ n->primary_bus = n->primary_dev->parent_bus; + } +qdev_set_parent_bus (n->primary_dev, n->primary_bus);
...but qdev_set_parent_bus unconditionally dereferences its first argument, so it can't be NULL...
hw/net/virtio-net.c void virtio_net_set_netclient_name(VirtIONet *n, const char *name, · line 2821
Quoted 9 lines
hw/net/virtio-net.c +9
-0+ n->primary_should_be_hidden = false; +qemu_opt_set_bool (n->primary_device_opts, +"partially_hotplugged" , true, errp); + hotplug_ctrl =qdev_get_hotplug_handler (n->primary_dev); +if (hotplug_ctrl) { +hotplug_handler_pre_plug (hotplug_ctrl, n->primary_dev, errp); +hotplug_handler_plug (hotplug_ctrl, n->primary_dev, errp); + } +if (!n->primary_dev) {
...and we do another NULL check here.
Either we don't need the NULL checks, or we need to avoid calling qdev_set_parent_bus(NULL, ...).
(This is CID 1407224.)
Quoted 6 lines
hw/net/virtio-net.c +5
-0+error_setg (errp,"virtio_net: couldn't find primary device" ); + } + } +return *errp !=NULL ; +}
hw/net/virtio-net.c void virtio_net_set_netclient_name(VirtIONet *n, const char *name, · line 2878
Quoted 10 lines
hw/net/virtio-net.c +9
-0+static int virtio_net_primary_should_be_hidden (DeviceListener *listener, +QemuOpts *device_opts) +{ +VirtIONet *n =container_of (listener, VirtIONet, primary_listener); +bool match_found; +bool hide; + + n->primary_device_dict =qemu_opts_to_qdict (device_opts, + n->primary_device_dict);
Here we pass device_optns to qemu_opts_to_qdict(), which must take a non-NULL pointer (it always dereferences it)...
hw/net/virtio-net.c void virtio_net_set_netclient_name(VirtIONet *n, const char *name, · line 2884
Quoted 6 lines
hw/net/virtio-net.c +6
-0+if (n->primary_device_dict) { +g_free (n->standby_id); + n->standby_id =g_strdup (qdict_get_try_str (n->primary_device_dict, +"failover_pair_id" )); + } +if (device_opts &&g_strcmp0 (n->standby_id, n->netclient_name) ==0 ) {
...but here we check whether device_opts is NULL.
Again, either the check or the call must be wrong.
(This is CID 1407222.)
hw/net/virtio-net.c void virtio_net_set_netclient_name(VirtIONet *n, const char *name, · line 2892
Quoted 8 lines
hw/net/virtio-net.c +8
-0+ match_found = true; + }else { + match_found = false; + hide = false; +g_free (n->standby_id); + n->primary_device_dict =NULL ; + goto out; + }
thanks
-- PMM
[PULL 11/14] vfio: unplug failover primary device before migration
In reply to Michael S. TsirkinFrom: Jens Freimann <[email protected]>
As usual block all vfio-pci devices from being migrated, but make an exception for failover primary devices. This is achieved by setting unmigratable to 0 but also add a migration blocker for all vfio-pci devices except failover primary devices. These will be unplugged before migration happens by the migration handler of the corresponding virtio-net standby device.
Message-Id: <[email protected]>
--- hw/vfio/pci.c | 26 ++++++++++++++++++++------ hw/vfio/pci.h | 1 + 2 files changed, 21 insertions(+), 6 deletions(-)
hw/vfio/pci.c +20 -6
@@ -40,6 +40,7 @@#include "pci.h" #include "trace.h" #include "qapi/error.h" +#include "migration/blocker.h" #define TYPE_VFIO_PCI "vfio-pci"#define PCI_VFIO (obj) OBJECT_CHECK(VFIOPCIDevice, obj, TYPE_VFIO_PCI)
@@ -2732,6 +2733,17 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)return ; } +if (!pdev->failover_pair_id) { +error_setg (&vdev->migration_blocker, +"VFIO device doesn't support migration" ); + ret =migrate_add_blocker (vdev->migration_blocker, &err); +if (err) { +error_propagate (errp, err); +error_free (vdev->migration_blocker); +return ; + } + } + vdev->vbasedev.name =g_path_get_basename (vdev->vbasedev.sysfsdev); vdev->vbasedev.ops = &vfio_pci_ops; vdev->vbasedev.type =VFIO_DEVICE_TYPE_PCI ;
@@ -3008,6 +3020,10 @@ out_teardown:vfio_bars_exit (vdev); error:error_prepend (errp,VFIO_MSG_PREFIX , vdev->vbasedev.name); +if (vdev->migration_blocker) { +migrate_del_blocker (vdev->migration_blocker); +error_free (vdev->migration_blocker); + } }static void vfio_instance_finalize (Object *obj)
@@ -3019,6 +3035,10 @@ static void vfio_instance_finalize(Object *obj)vfio_bars_finalize (vdev);g_free (vdev->emulated_config_bits);g_free (vdev->rom); +if (vdev->migration_blocker) { +migrate_del_blocker (vdev->migration_blocker); +error_free (vdev->migration_blocker); + }/* * XXX Leaking igd_opregion is not an oversight, we can't remove the * fw_cfg entry therefore leaking this allocation seems like the safest
@@ -3151,11 +3171,6 @@ static Property vfio_pci_dev_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static const VMStateDescription vfio_pci_vmstate = { - .name ="vfio-pci" , - .unmigratable =1 , -}; -static void vfio_pci_dev_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -3163,7 +3178,6 @@ static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) dc->reset = vfio_pci_reset; dc->props = vfio_pci_dev_properties; - dc->vmsd = &vfio_pci_vmstate; dc->desc ="VFIO-based PCI device assignment" ;set_bit (DEVICE_CATEGORY_MISC , dc->categories); pdc->realize = vfio_realize;
hw/vfio/pci.h +1 -0
@@ -168,6 +168,7 @@ typedef struct VFIOPCIDevice {bool no_vfio_ioeventfd;bool enable_ramfb;VFIODisplay *dpy; +Error *migration_blocker; } VFIOPCIDevice;uint32_t vfio_pci_read_config (PCIDevice *pdev,uint32_t addr,int len);
Signature · 1 line
MST
Re: [PULL 11/14] vfio: unplug failover primary device before migration
Quoted 9 lines · Michael S. Tsirkin
From: Jens Freimann <[email protected]>
As usual block all vfio-pci devices from being migrated, but make an exception for failover primary devices. This is achieved by setting unmigratable to 0 but also add a migration blocker for all vfio-pci devices except failover primary devices. These will be unplugged before migration happens by the migration handler of the corresponding virtio-net standby device.
Hi; Coverity reports a 'value written to variable but never used' issue here (CID 1407219):
Quoted 13 lines
hw/vfio/pci.c +1
-0@@ -40,6 +40,7 @@#include "pci.h" #include "trace.h" #include "qapi/error.h" +#include "migration/blocker.h" #define TYPE_VFIO_PCI "vfio-pci"#define PCI_VFIO (obj) OBJECT_CHECK(VFIOPCIDevice, obj, TYPE_VFIO_PCI)
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error **errp) · line 2739
Quoted 7 lines
hw/vfio/pci.c +4
-0@@ -2732,6 +2733,17 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)return ; } +if (!pdev->failover_pair_id) { +error_setg (&vdev->migration_blocker, +"VFIO device doesn't support migration" ); + ret =migrate_add_blocker (vdev->migration_blocker, &err);
Here we assign to 'ret', but we never use it on the 'if (err)' path, and on the success case we don't look at it either; it's just overwritten by the later 'ret = vfio_get_device(...)'.
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error **errp) · line 2745
Quoted 6 lines
hw/vfio/pci.c +6
-0+if (err) { +error_propagate (errp, err); +error_free (vdev->migration_blocker); +return ; + } + }
thanks
-- PMM
[PULL 14/14] virtio: Use auto rcu_read macros
In reply to Michael S. TsirkinFrom: "Dr. David Alan Gilbert" <[email protected]>
Use RCU_READ_LOCK_GUARD and WITH_RCU_READ_LOCK_GUARD to replace the manual rcu_read_(un)lock calls.
I think the only change is virtio_load which was missing unlocks in error paths; those end up being fatal errors so it's not that important anyway.
Message-Id: <[email protected]>
--- hw/virtio/virtio.c | 65 ++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 42 deletions(-)
hw/virtio/virtio.c +23 -42
@@ -387,7 +387,8 @@ static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)static void virtio_queue_split_set_notification (VirtQueue *vq,int enable) { -rcu_read_lock (); +RCU_READ_LOCK_GUARD (); +if (virtio_vdev_has_feature (vq->vdev,VIRTIO_RING_F_EVENT_IDX )) {vring_set_avail_event (vq,vring_avail_idx (vq)); }else if (enable) {
@@ -399,7 +400,6 @@ static void virtio_queue_split_set_notification(VirtQueue *vq, int enable)/* Expose avail event/used flags before caller checks the avail idx. */ smp_mb (); } -rcu_read_unlock (); }static void virtio_queue_packed_set_notification (VirtQueue *vq,int enable)
@@ -408,7 +408,7 @@ static void virtio_queue_packed_set_notification(VirtQueue *vq, int enable)VRingPackedDescEvent e;VRingMemoryRegionCaches *caches; -rcu_read_lock (); +RCU_READ_LOCK_GUARD (); caches =vring_get_region_caches (vq);vring_packed_event_read (vq->vdev, &caches->used, &e);
@@ -429,7 +429,6 @@ static void virtio_queue_packed_set_notification(VirtQueue *vq, int enable)/* Expose avail event/used flags before caller checks the avail idx. */ smp_mb (); } -rcu_read_unlock (); }void virtio_queue_set_notification (VirtQueue *vq,int enable)
@@ -577,9 +576,8 @@ static int virtio_queue_split_empty(VirtQueue *vq)return 0 ; } -rcu_read_lock (); +RCU_READ_LOCK_GUARD (); empty =vring_avail_idx (vq) == vq->last_avail_idx; -rcu_read_unlock ();return empty; }
@@ -601,12 +599,8 @@ static int virtio_queue_packed_empty_rcu(VirtQueue *vq)static int virtio_queue_packed_empty (VirtQueue *vq) { -bool empty; - -rcu_read_lock (); - empty =virtio_queue_packed_empty_rcu (vq); -rcu_read_unlock (); -return empty; +RCU_READ_LOCK_GUARD (); +return virtio_queue_packed_empty_rcu (vq); }int virtio_queue_empty (VirtQueue *vq)
@@ -859,10 +853,9 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count)void virtqueue_push (VirtQueue *vq,const VirtQueueElement *elem,unsigned int len) { -rcu_read_lock (); +RCU_READ_LOCK_GUARD ();virtqueue_fill (vq, elem, len,0 );virtqueue_flush (vq,1 ); -rcu_read_unlock (); }/* Called within rcu_read_lock(). */
@@ -943,7 +936,8 @@ static void virtqueue_split_get_avail_bytes(VirtQueue *vq,int64_t len =0 ;int rc; -rcu_read_lock (); +RCU_READ_LOCK_GUARD (); + idx = vq->last_avail_idx; total_bufs = in_total = out_total =0 ;
@@ -1033,7 +1027,6 @@ done:if (out_bytes) { *out_bytes = out_total; } -rcu_read_unlock ();return ; err:
@@ -1083,7 +1076,7 @@ static void virtqueue_packed_get_avail_bytes(VirtQueue *vq,VRingPackedDesc desc;bool wrap_counter; -rcu_read_lock (); +RCU_READ_LOCK_GUARD (); idx = vq->last_avail_idx; wrap_counter = vq->last_avail_wrap_counter; total_bufs = in_total = out_total =0 ;
@@ -1176,7 +1169,6 @@ done:if (out_bytes) { *out_bytes = out_total; } -rcu_read_unlock ();return ; err:
@@ -1360,7 +1352,7 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_t sz)VRingDesc desc;int rc; -rcu_read_lock (); +RCU_READ_LOCK_GUARD ();if (virtio_queue_empty_rcu (vq)) { goto done; }
@@ -1469,7 +1461,6 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_t sz)trace_virtqueue_pop (vq, elem, elem->in_num, elem->out_num); done:address_space_cache_destroy (&indirect_desc_cache); -rcu_read_unlock ();return elem;
@@ -1494,7 +1485,7 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t sz)uint16_t id;int rc; -rcu_read_lock (); +RCU_READ_LOCK_GUARD ();if (virtio_queue_packed_empty_rcu (vq)) { goto done; }
@@ -1600,7 +1591,6 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t sz)trace_virtqueue_pop (vq, elem, elem->in_num, elem->out_num); done:address_space_cache_destroy (&indirect_desc_cache); -rcu_read_unlock ();return elem;
@@ -2437,13 +2427,10 @@ static bool virtio_should_notify(VirtIODevice *vdev, VirtQueue *vq)void virtio_notify_irqfd (VirtIODevice *vdev,VirtQueue *vq) { -bool should_notify; -rcu_read_lock (); - should_notify =virtio_should_notify (vdev, vq); -rcu_read_unlock (); - -if (!should_notify) { -return ; + WITH_RCU_READ_LOCK_GUARD() { +if (!virtio_should_notify (vdev, vq)) { +return ; + } }trace_virtio_notify_irqfd (vdev, vq);
@@ -2475,13 +2462,10 @@ static void virtio_irq(VirtQueue *vq)void virtio_notify (VirtIODevice *vdev,VirtQueue *vq) { -bool should_notify; -rcu_read_lock (); - should_notify =virtio_should_notify (vdev, vq); -rcu_read_unlock (); - -if (!should_notify) { -return ; + WITH_RCU_READ_LOCK_GUARD() { +if (!virtio_should_notify (vdev, vq)) { +return ; + } }trace_virtio_notify (vdev, vq);
@@ -3032,7 +3016,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) vdev->start_on_kick = true; } -rcu_read_lock (); +RCU_READ_LOCK_GUARD ();for (i =0 ; i < num; i++) {if (vdev->vq[i].vring.desc) {uint16_t nheads;
@@ -3087,7 +3071,6 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) } } } -rcu_read_unlock ();if (vdc->post_load) { ret = vdc->post_load (vdev);
@@ -3297,12 +3280,11 @@ static void virtio_queue_packed_restore_last_avail_idx(VirtIODevice *vdev,static void virtio_queue_split_restore_last_avail_idx (VirtIODevice *vdev,int n) { -rcu_read_lock (); +RCU_READ_LOCK_GUARD ();if (vdev->vq[n].vring.desc) { vdev->vq[n].last_avail_idx =vring_used_idx (&vdev->vq[n]); vdev->vq[n].shadow_avail_idx = vdev->vq[n].last_avail_idx; } -rcu_read_unlock (); }void virtio_queue_restore_last_avail_idx (VirtIODevice *vdev,int n)
@@ -3322,11 +3304,10 @@ static void virtio_queue_packed_update_used_idx(VirtIODevice *vdev, int n)static void virtio_split_packed_update_used_idx (VirtIODevice *vdev,int n) { -rcu_read_lock (); +RCU_READ_LOCK_GUARD ();if (vdev->vq[n].vring.desc) { vdev->vq[n].used_idx =vring_used_idx (&vdev->vq[n]); } -rcu_read_unlock (); }void virtio_queue_update_used_idx (VirtIODevice *vdev,int n)
Signature · 1 line
MST
Peter Maydell
AppliedQuoted 13 lines · Michael S. Tsirkin
The following changes since commit
16884391c750d0c5e863f55ad7aaaa146fc5181e:Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2019-10-29' into staging (2019-10-29 20:06:08 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gittags/for_upstreamfor you to fetch changes up to
b5f53d04a5a567ac70d33ec95628d35583eba600:virtio: Use auto
rcu_readmacros (2019-10-29 18:56:45 -0400)
Quoted 8 lines
----------------------------------------------------------------
virtio: features, cleanupsvirtio net failover
rcu cleanupSigned-off-by Michael S. Tsirkin <[email protected]>
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/4.2
for any user-visible changes.
-- PMM