108 lines
3.4 KiB
Diff
108 lines
3.4 KiB
Diff
|
|
From 69fdbac8d37a02cfc91e6c849a768e58e57dd15f Mon Sep 17 00:00:00 2001
|
||
|
|
From: fangyi <eric.fangyi@huawei.com>
|
||
|
|
Date: Thu, 16 Nov 2023 09:54:55 +0800
|
||
|
|
Subject: [PATCH] vhost-vdpa: stick to -errno error return convention
|
||
|
|
|
||
|
|
Almost all VhostOps methods in vdpa_ops follow the convention of
|
||
|
|
returning negated errno on error.
|
||
|
|
|
||
|
|
Adjust the few that don't. To that end, rework vhost_vdpa_add_status to
|
||
|
|
check if setting of the requested status bits has succeeded and return
|
||
|
|
the respective error code it hasn't, and propagate the error codes
|
||
|
|
wherever it's appropriate.
|
||
|
|
|
||
|
|
Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
|
||
|
|
Message-Id: <20211111153354.18807-8-rvkagan@yandex-team.ru>
|
||
|
|
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
||
|
|
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
||
|
|
Signed-off-by: fangyi <eric.fangyi@huawei.com>
|
||
|
|
---
|
||
|
|
hw/virtio/vhost-vdpa.c | 37 +++++++++++++++++++++++--------------
|
||
|
|
1 file changed, 23 insertions(+), 14 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
|
||
|
|
index b7bbd65cdd..d8fba0b714 100644
|
||
|
|
--- a/hw/virtio/vhost-vdpa.c
|
||
|
|
+++ b/hw/virtio/vhost-vdpa.c
|
||
|
|
@@ -294,18 +294,34 @@ static int vhost_vdpa_call(struct vhost_dev *dev, unsigned long int request,
|
||
|
|
return ret < 0 ? -errno : ret;
|
||
|
|
}
|
||
|
|
|
||
|
|
-static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
|
||
|
|
+static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
|
||
|
|
{
|
||
|
|
uint8_t s;
|
||
|
|
+ int ret;
|
||
|
|
|
||
|
|
trace_vhost_vdpa_add_status(dev, status);
|
||
|
|
- if (vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s)) {
|
||
|
|
- return;
|
||
|
|
+ ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s);
|
||
|
|
+ if (ret < 0) {
|
||
|
|
+ return ret;
|
||
|
|
}
|
||
|
|
|
||
|
|
s |= status;
|
||
|
|
|
||
|
|
- vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s);
|
||
|
|
+ ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &s);
|
||
|
|
+ if (ret < 0) {
|
||
|
|
+ return ret;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &s);
|
||
|
|
+ if (ret < 0) {
|
||
|
|
+ return ret;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ if (!(s & status)) {
|
||
|
|
+ return -EIO;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static void vhost_vdpa_get_iova_range(struct vhost_vdpa *v)
|
||
|
|
@@ -487,7 +503,7 @@ static int vhost_vdpa_set_mem_table(struct vhost_dev *dev,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (mem->padding) {
|
||
|
|
- return -1;
|
||
|
|
+ return -EINVAL;
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
@@ -504,14 +520,11 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,
|
||
|
|
|
||
|
|
trace_vhost_vdpa_set_features(dev, features);
|
||
|
|
ret = vhost_vdpa_call(dev, VHOST_SET_FEATURES, &features);
|
||
|
|
- uint8_t status = 0;
|
||
|
|
if (ret) {
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
- vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
|
||
|
|
- vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
|
||
|
|
|
||
|
|
- return !(status & VIRTIO_CONFIG_S_FEATURES_OK);
|
||
|
|
+ return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
|
||
|
|
}
|
||
|
|
|
||
|
|
static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev)
|
||
|
|
@@ -653,12 +666,8 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
|
||
|
|
}
|
||
|
|
|
||
|
|
if (started) {
|
||
|
|
- uint8_t status = 0;
|
||
|
|
memory_listener_register(&v->listener, &address_space_memory);
|
||
|
|
- vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
|
||
|
|
- vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
|
||
|
|
-
|
||
|
|
- return !(status & VIRTIO_CONFIG_S_DRIVER_OK);
|
||
|
|
+ return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
|
||
|
|
} else {
|
||
|
|
vhost_vdpa_reset_device(dev);
|
||
|
|
vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|