[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 09/10] vdpa-dev: implement the set_status interface
From: |
Longpeng(Mike) |
Subject: |
[PATCH v3 09/10] vdpa-dev: implement the set_status interface |
Date: |
Sat, 19 Mar 2022 15:20:11 +0800 |
From: Longpeng <longpeng2@huawei.com>
Implements the .set_status interface.
Signed-off-by: Longpeng <longpeng2@huawei.com>
---
hw/virtio/vdpa-dev.c | 100 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 99 insertions(+), 1 deletion(-)
diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c
index 9536982061..c6847df7aa 100644
--- a/hw/virtio/vdpa-dev.c
+++ b/hw/virtio/vdpa-dev.c
@@ -222,9 +222,107 @@ static uint64_t
vhost_vdpa_device_get_features(VirtIODevice *vdev,
return backend_features;
}
+static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)
+{
+ VhostVdpaDevice *s = VHOST_VDPA_DEVICE(vdev);
+ BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+ VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+ int i, ret;
+
+ if (!k->set_guest_notifiers) {
+ error_setg(errp, "binding does not support guest notifiers");
+ return -ENOSYS;
+ }
+
+ ret = vhost_dev_enable_notifiers(&s->dev, vdev);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Error enabling host notifiers");
+ return ret;
+ }
+
+ ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Error binding guest notifier");
+ goto err_host_notifiers;
+ }
+
+ s->dev.acked_features = vdev->guest_features;
+
+ ret = vhost_dev_start(&s->dev, vdev);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Error starting vhost");
+ goto err_guest_notifiers;
+ }
+ s->started = true;
+
+ /*
+ * guest_notifier_mask/pending not used yet, so just unmask
+ * everything here. virtio-pci will do the right thing by
+ * enabling/disabling irqfd.
+ */
+ for (i = 0; i < s->dev.nvqs; i++) {
+ vhost_virtqueue_mask(&s->dev, vdev, i, false);
+ }
+
+ return ret;
+
+err_guest_notifiers:
+ k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
+err_host_notifiers:
+ vhost_dev_disable_notifiers(&s->dev, vdev);
+ return ret;
+}
+
+static void vhost_vdpa_device_stop(VirtIODevice *vdev)
+{
+ VhostVdpaDevice *s = VHOST_VDPA_DEVICE(vdev);
+ BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+ VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+ int ret;
+
+ if (!s->started) {
+ return;
+ }
+ s->started = false;
+
+ if (!k->set_guest_notifiers) {
+ return;
+ }
+
+ vhost_dev_stop(&s->dev, vdev);
+
+ ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
+ if (ret < 0) {
+ error_report("vhost guest notifier cleanup failed: %d", ret);
+ return;
+ }
+
+ vhost_dev_disable_notifiers(&s->dev, vdev);
+}
+
static void vhost_vdpa_device_set_status(VirtIODevice *vdev, uint8_t status)
{
- return;
+ VhostVdpaDevice *s = VHOST_VDPA_DEVICE(vdev);
+ bool should_start = virtio_device_started(vdev, status);
+ Error *local_err = NULL;
+ int ret;
+
+ if (!vdev->vm_running) {
+ should_start = false;
+ }
+
+ if (s->started == should_start) {
+ return;
+ }
+
+ if (should_start) {
+ ret = vhost_vdpa_device_start(vdev, &local_err);
+ if (ret < 0) {
+ error_reportf_err(local_err, "vhost-vdpa-device: start failed: ");
+ }
+ } else {
+ vhost_vdpa_device_stop(vdev);
+ }
}
static Property vhost_vdpa_device_properties[] = {
--
2.23.0
- Re: [PATCH v3 05/10] vdpa-dev: implement the realize interface, (continued)
- [PATCH v3 04/10] vdpa-dev: implement the instance_init/class_init interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 02/10] update linux headers, Longpeng(Mike), 2022/03/19
- [PATCH v3 08/10] vdpa-dev: implement the get_features interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 06/10] vdpa-dev: implement the unrealize interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 03/10] vdpa: add the infrastructure of vdpa-dev, Longpeng(Mike), 2022/03/19
- [PATCH v3 10/10] vdpa-dev: mark the device as unmigratable, Longpeng(Mike), 2022/03/19
- [PATCH v3 07/10] vdpa-dev: implement the get_config/set_config interface, Longpeng(Mike), 2022/03/19
- [PATCH v3 09/10] vdpa-dev: implement the set_status interface,
Longpeng(Mike) <=
- Re: [PATCH v3 00/10] add generic vDPA device support, Stefano Garzarella, 2022/03/28