* [PATCH 0/2] Fix the init path of generic vhost-vdpa device
@ 2022-12-24 11:48 Longpeng(Mike) via
2022-12-24 11:48 ` [PATCH 1/2] vdpa-dev: get iova range explicitly Longpeng(Mike) via
2022-12-24 11:48 ` [PATCH 2/2] vdpa: harden the error path if get_iova_range failed Longpeng(Mike) via
0 siblings, 2 replies; 5+ messages in thread
From: Longpeng(Mike) via @ 2022-12-24 11:48 UTC (permalink / raw)
To: stefanha, mst, jasowang, sgarzare
Cc: cohuck, pbonzini, arei.gonglei, yechuan, huangzhichao,
qemu-devel, eperezma, Longpeng
From: Longpeng <longpeng2@huawei.com>
The generic vhost-vdpa device and the commit a585fad26b ("vdpa: request
iova_range only once") are merged in the same pull request, and the later
would cause the generic vhost-vdpa device work improperly.
Patch 1 fixes the problem and patch 2 hardens the error path of vdpa/net.
Longpeng (Mike) (2):
vdpa-dev: get iova range explicitly
vdpa: harden the error path if get_iova_range failed
hw/virtio/vdpa-dev.c | 9 +++++++++
hw/virtio/vhost-vdpa.c | 7 +++++++
include/hw/virtio/vhost-vdpa.h | 2 ++
net/vhost-vdpa.c | 16 +++++++---------
4 files changed, 25 insertions(+), 9 deletions(-)
--
2.23.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] vdpa-dev: get iova range explicitly
2022-12-24 11:48 [PATCH 0/2] Fix the init path of generic vhost-vdpa device Longpeng(Mike) via
@ 2022-12-24 11:48 ` Longpeng(Mike) via
2022-12-28 6:46 ` Jason Wang
2022-12-24 11:48 ` [PATCH 2/2] vdpa: harden the error path if get_iova_range failed Longpeng(Mike) via
1 sibling, 1 reply; 5+ messages in thread
From: Longpeng(Mike) via @ 2022-12-24 11:48 UTC (permalink / raw)
To: stefanha, mst, jasowang, sgarzare
Cc: cohuck, pbonzini, arei.gonglei, yechuan, huangzhichao,
qemu-devel, eperezma, Longpeng
From: Longpeng <longpeng2@huawei.com>
In commit a585fad26b ("vdpa: request iova_range only once") we remove
GET_IOVA_RANGE form vhost_vdpa_init, the generic vdpa device will start
without iova_range populated, so the device won't work. Let's call
GET_IOVA_RANGE ioctl explicitly.
Fixes: a585fad26b2e6ccc ("vdpa: request iova_range only once")
Signed-off-by: Longpeng <longpeng2@huawei.com>
---
hw/virtio/vdpa-dev.c | 9 +++++++++
hw/virtio/vhost-vdpa.c | 7 +++++++
include/hw/virtio/vhost-vdpa.h | 2 ++
net/vhost-vdpa.c | 8 --------
4 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c
index db6ba61152..01b41eb0f1 100644
--- a/hw/virtio/vdpa-dev.c
+++ b/hw/virtio/vdpa-dev.c
@@ -53,6 +53,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VhostVdpaDevice *v = VHOST_VDPA_DEVICE(vdev);
+ struct vhost_vdpa_iova_range iova_range;
uint16_t max_queue_size;
struct vhost_virtqueue *vqs;
int i, ret;
@@ -108,6 +109,14 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp)
v->dev.backend_features = 0;
v->started = false;
+ ret = vhost_vdpa_get_iova_range(v->vhostfd, &iova_range);
+ if (ret < 0) {
+ error_setg(errp, "vhost-vdpa-device: get iova range failed: %s",
+ strerror(-ret));
+ goto free_vqs;
+ }
+ v->vdpa.iova_range = iova_range;
+
ret = vhost_dev_init(&v->dev, &v->vdpa, VHOST_BACKEND_TYPE_VDPA, 0, NULL);
if (ret < 0) {
error_setg(errp, "vhost-vdpa-device: vhost initialization failed: %s",
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 870265188a..109a2ee3bf 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -378,6 +378,13 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
return 0;
}
+int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range)
+{
+ int ret = ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range);
+
+ return ret < 0 ? -errno : 0;
+}
+
/*
* The use of this function is for requests that only need to be
* applied once. Typically such request occurs at the beginning
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
index 45b969a311..7997f09a8d 100644
--- a/include/hw/virtio/vhost-vdpa.h
+++ b/include/hw/virtio/vhost-vdpa.h
@@ -51,6 +51,8 @@ typedef struct vhost_vdpa {
VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
} VhostVDPA;
+int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range);
+
int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
hwaddr size, void *vaddr, bool readonly);
int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index d36664f33a..ffdc435d19 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -702,14 +702,6 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
return nc;
}
-static int vhost_vdpa_get_iova_range(int fd,
- struct vhost_vdpa_iova_range *iova_range)
-{
- int ret = ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range);
-
- return ret < 0 ? -errno : 0;
-}
-
static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **errp)
{
int ret = ioctl(fd, VHOST_GET_FEATURES, features);
--
2.23.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] vdpa: harden the error path if get_iova_range failed
2022-12-24 11:48 [PATCH 0/2] Fix the init path of generic vhost-vdpa device Longpeng(Mike) via
2022-12-24 11:48 ` [PATCH 1/2] vdpa-dev: get iova range explicitly Longpeng(Mike) via
@ 2022-12-24 11:48 ` Longpeng(Mike) via
2022-12-28 6:47 ` Jason Wang
1 sibling, 1 reply; 5+ messages in thread
From: Longpeng(Mike) via @ 2022-12-24 11:48 UTC (permalink / raw)
To: stefanha, mst, jasowang, sgarzare
Cc: cohuck, pbonzini, arei.gonglei, yechuan, huangzhichao,
qemu-devel, eperezma, Longpeng
From: Longpeng <longpeng2@huawei.com>
We should stop if the GET_IOVA_RANGE ioctl failed.
Signed-off-by: Longpeng <longpeng2@huawei.com>
---
net/vhost-vdpa.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index ffdc435d19..e65023d013 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -797,7 +797,13 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
return queue_pairs;
}
- vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range);
+ r = vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range);
+ if (unlikely(r < 0)) {
+ error_setg(errp, "vhost-vdpa: get iova range failed: %s",
+ strerror(-r));
+ goto err;
+ }
+
if (opts->x_svq) {
if (!vhost_vdpa_net_valid_svq_features(features, errp)) {
goto err_svq;
--
2.23.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] vdpa-dev: get iova range explicitly
2022-12-24 11:48 ` [PATCH 1/2] vdpa-dev: get iova range explicitly Longpeng(Mike) via
@ 2022-12-28 6:46 ` Jason Wang
0 siblings, 0 replies; 5+ messages in thread
From: Jason Wang @ 2022-12-28 6:46 UTC (permalink / raw)
To: Longpeng(Mike)
Cc: stefanha, mst, sgarzare, cohuck, pbonzini, arei.gonglei, yechuan,
huangzhichao, qemu-devel, eperezma
On Sat, Dec 24, 2022 at 7:49 PM Longpeng(Mike) <longpeng2@huawei.com> wrote:
>
> From: Longpeng <longpeng2@huawei.com>
>
> In commit a585fad26b ("vdpa: request iova_range only once") we remove
> GET_IOVA_RANGE form vhost_vdpa_init, the generic vdpa device will start
> without iova_range populated, so the device won't work. Let's call
> GET_IOVA_RANGE ioctl explicitly.
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
>
> Fixes: a585fad26b2e6ccc ("vdpa: request iova_range only once")
> Signed-off-by: Longpeng <longpeng2@huawei.com>
> ---
> hw/virtio/vdpa-dev.c | 9 +++++++++
> hw/virtio/vhost-vdpa.c | 7 +++++++
> include/hw/virtio/vhost-vdpa.h | 2 ++
> net/vhost-vdpa.c | 8 --------
> 4 files changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c
> index db6ba61152..01b41eb0f1 100644
> --- a/hw/virtio/vdpa-dev.c
> +++ b/hw/virtio/vdpa-dev.c
> @@ -53,6 +53,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp)
> {
> VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> VhostVdpaDevice *v = VHOST_VDPA_DEVICE(vdev);
> + struct vhost_vdpa_iova_range iova_range;
> uint16_t max_queue_size;
> struct vhost_virtqueue *vqs;
> int i, ret;
> @@ -108,6 +109,14 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp)
> v->dev.backend_features = 0;
> v->started = false;
>
> + ret = vhost_vdpa_get_iova_range(v->vhostfd, &iova_range);
> + if (ret < 0) {
> + error_setg(errp, "vhost-vdpa-device: get iova range failed: %s",
> + strerror(-ret));
> + goto free_vqs;
> + }
> + v->vdpa.iova_range = iova_range;
> +
> ret = vhost_dev_init(&v->dev, &v->vdpa, VHOST_BACKEND_TYPE_VDPA, 0, NULL);
> if (ret < 0) {
> error_setg(errp, "vhost-vdpa-device: vhost initialization failed: %s",
> diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
> index 870265188a..109a2ee3bf 100644
> --- a/hw/virtio/vhost-vdpa.c
> +++ b/hw/virtio/vhost-vdpa.c
> @@ -378,6 +378,13 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
> return 0;
> }
>
> +int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range)
> +{
> + int ret = ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range);
> +
> + return ret < 0 ? -errno : 0;
> +}
> +
> /*
> * The use of this function is for requests that only need to be
> * applied once. Typically such request occurs at the beginning
> diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
> index 45b969a311..7997f09a8d 100644
> --- a/include/hw/virtio/vhost-vdpa.h
> +++ b/include/hw/virtio/vhost-vdpa.h
> @@ -51,6 +51,8 @@ typedef struct vhost_vdpa {
> VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
> } VhostVDPA;
>
> +int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range);
> +
> int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
> hwaddr size, void *vaddr, bool readonly);
> int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index d36664f33a..ffdc435d19 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -702,14 +702,6 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
> return nc;
> }
>
> -static int vhost_vdpa_get_iova_range(int fd,
> - struct vhost_vdpa_iova_range *iova_range)
> -{
> - int ret = ioctl(fd, VHOST_VDPA_GET_IOVA_RANGE, iova_range);
> -
> - return ret < 0 ? -errno : 0;
> -}
> -
> static int vhost_vdpa_get_features(int fd, uint64_t *features, Error **errp)
> {
> int ret = ioctl(fd, VHOST_GET_FEATURES, features);
> --
> 2.23.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] vdpa: harden the error path if get_iova_range failed
2022-12-24 11:48 ` [PATCH 2/2] vdpa: harden the error path if get_iova_range failed Longpeng(Mike) via
@ 2022-12-28 6:47 ` Jason Wang
0 siblings, 0 replies; 5+ messages in thread
From: Jason Wang @ 2022-12-28 6:47 UTC (permalink / raw)
To: Longpeng(Mike)
Cc: stefanha, mst, sgarzare, cohuck, pbonzini, arei.gonglei, yechuan,
huangzhichao, qemu-devel, eperezma
On Sat, Dec 24, 2022 at 7:49 PM Longpeng(Mike) <longpeng2@huawei.com> wrote:
>
> From: Longpeng <longpeng2@huawei.com>
>
> We should stop if the GET_IOVA_RANGE ioctl failed.
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
>
> Signed-off-by: Longpeng <longpeng2@huawei.com>
> ---
> net/vhost-vdpa.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index ffdc435d19..e65023d013 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -797,7 +797,13 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
> return queue_pairs;
> }
>
> - vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range);
> + r = vhost_vdpa_get_iova_range(vdpa_device_fd, &iova_range);
> + if (unlikely(r < 0)) {
> + error_setg(errp, "vhost-vdpa: get iova range failed: %s",
> + strerror(-r));
> + goto err;
> + }
> +
> if (opts->x_svq) {
> if (!vhost_vdpa_net_valid_svq_features(features, errp)) {
> goto err_svq;
> --
> 2.23.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-12-28 6:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-24 11:48 [PATCH 0/2] Fix the init path of generic vhost-vdpa device Longpeng(Mike) via
2022-12-24 11:48 ` [PATCH 1/2] vdpa-dev: get iova range explicitly Longpeng(Mike) via
2022-12-28 6:46 ` Jason Wang
2022-12-24 11:48 ` [PATCH 2/2] vdpa: harden the error path if get_iova_range failed Longpeng(Mike) via
2022-12-28 6:47 ` Jason Wang
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.