vhost-vdpa: check vhost_vdpa_set_vring_ready() return value
PATCH 1/1 vhost-vdpa: check vhost_vdpa_set_vring_ready() return value
vhost_vdpa_set_vring_ready() could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues before DRIVER_OK when VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK is not negotiated.
So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.
[2] https://lore.kernel.org/qemu-devel/[email protected]/
--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)
hw/virtio/vdpa-dev.c +7 -1
@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;
@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:
net/vhost-vdpa.c +12 -3
@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }
@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);
@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ;
Signature · 1 line
2.43.0
Gentle ping :-)
Quoted 91 lines · Stefano Garzarella
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.[2] https://lore.kernel.org/qemu-devel/[email protected]/
--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +7
-1@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:net/vhost-vdpa.c +12
-4@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ; --2.43.0
Quoted 5 lines · Stefano Garzarella
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.
I wonder what happens if we just leave it as is.
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We do know enabling could be done after driver_ok.
Without VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We don't know whether enabling could be done after driver_ok or not.
Thanks
Quoted 86 lines
So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.[2] https://lore.kernel.org/qemu-devel/[email protected]/
--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +7
-1@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:net/vhost-vdpa.c +12
-4@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ; --2.43.0
Quoted 8 lines · Jason Wang
Quoted 5 lines · Stefano Garzarella
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.I wonder what happens if we just leave it as is.
Are you referring to this patch or the kernel patch?
Here I'm just checking the return value of vhost_vdpa_set_vring_ready(). It can return an error also without that kernel patch, so IMHO is better to check the return value here in QEMU.
What issue do you see with this patch applied?
Quoted 5 lines
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We do know enabling could be done afterdriver_ok.
WithoutVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We don't know whether enabling could be done afterdriver_okor not.
I see your point, indeed I didn't send a v2 of that patch. Maybe we should document that, because it could be interpreted that if VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK is not negotiated the enabling should always be done before driver_ok (which is true for example in VDUSE).
BTW I think we should discuss it in the kernel patch.
Thanks,
Stefano
Quoted 90 lines
Thanks
Quoted 86 lines
So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.[2] https://lore.kernel.org/qemu-devel/[email protected]/
--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +7
-1@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:net/vhost-vdpa.c +12
-4@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ; --2.43.0
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · Jason Wang
Quoted 1 line · Stefano Garzarella
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.I wonder what happens if we just leave it as is.
Are you referring to this patch or the kernel patch?
This patch.
Quoted 6 lines
Here I'm just checking the return value of
vhost_vdpa_set_vring_ready(). It can return an error also without that kernel patch, so IMHO is better to check the return value here in QEMU.What issue do you see with this patch applied?
For the parent which can enable after driver_ok but not advertise it.
(To say the truth, I'm not sure if we need to care about this)
Quoted 7 lines
Quoted 6 lines
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We do know enabling could be done afterdriver_ok.
WithoutVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We don't know whether enabling could be done afterdriver_okor not.
Quoted 5 lines
I see your point, indeed I didn't send a v2 of that patch. Maybe we should document that, because it could be interpreted that if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated the enabling should always be done beforedriver_ok(which is true for example in VDUSE).
I see, so I think we probably need the fix.
Quoted 19 lines
BTW I think we should discuss it in the kernel patch.
Thanks,
StefanoQuoted 13 lines
Thanks
Quoted 10 lines
So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.
Will go through [2].
Thanks
Quoted 79 lines
Quoted 78 lines
Quoted 77 lines
[2]
https://lore.kernel.org/qemu-devel/[email protected]/--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +7
-1@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:net/vhost-vdpa.c +12
-4@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ; --2.43.0
Quoted 17 lines · Jason Wang
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · Jason Wang
Quoted 1 line · Stefano Garzarella
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.I wonder what happens if we just leave it as is.
Are you referring to this patch or the kernel patch?
This patch.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Here I'm just checking the return value of
vhost_vdpa_set_vring_ready(). It can return an error also without that kernel patch, so IMHO is better to check the return value here in QEMU.What issue do you see with this patch applied?
For the parent which can enable after
driver_okbut not advertise it.
But this patch is not changing anything in that sense, it just controls the return value of the VHOST_VDPA_SET_VRING_ENABLE ioctl.
Why would QEMU ignore an error if it can't activate vrings? If we really want to ignore it we should document it both in QEMU, but also in the kernel, because honestly the way the code is now it shouldn't fail from what I understand.
That said, even if we ignore it, IMHO we should at least print a warning in QEMU.
Quoted 2 lines
(To say the truth, I'm not sure if we need to care about this)
I agree on that, but this is related to the patch in the kernel, not this simple patch to fix QEMU error path, right?
Quoted 30 lines
Quoted 8 lines
Quoted 7 lines
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We do know enabling could be done afterdriver_ok.
WithoutVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We don't know whether enabling could be done afterdriver_okor not.Quoted 5 lines
I see your point, indeed I didn't send a v2 of that patch. Maybe we should document that, because it could be interpreted that if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated the enabling should always be done beforedriver_ok(which is true for example in VDUSE).I see, so I think we probably need the fix.
Quoted 14 lines
BTW I think we should discuss it in the kernel patch.
Thanks,
StefanoQuoted 8 lines
Thanks
Quoted 5 lines
So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.Will go through [2].
Here I meant that the conflict is only in the code touched, because Kevin's patch remove/move some of the code touched by this patch. And rightly he checked the return value of the ioctl as I would like to do in the other places where we call the same ioctl.
So honestly I still don't understand what's wrong with this patch...
Thanks,
Stefano
Quoted 84 lines
Thanks
Quoted 79 lines
Quoted 78 lines
Quoted 77 lines
[2]
https://lore.kernel.org/qemu-devel/[email protected]/--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +7
-1@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:net/vhost-vdpa.c +12
-4@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ; --2.43.0
Jason Wang
Acked-byQuoted 30 lines · Stefano Garzarella
Quoted 17 lines · Jason Wang
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · Jason Wang
Quoted 1 line · Stefano Garzarella
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.I wonder what happens if we just leave it as is.
Are you referring to this patch or the kernel patch?
This patch.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Here I'm just checking the return value of
vhost_vdpa_set_vring_ready(). It can return an error also without that kernel patch, so IMHO is better to check the return value here in QEMU.What issue do you see with this patch applied?
For the parent which can enable after
driver_okbut not advertise it.But this patch is not changing anything in that sense, it just controls the return value of the
VHOST_VDPA_SET_VRING_ENABLEioctl.
Quoted 7 lines
Why would QEMU ignore an error if it can't activate vrings? If we really want to ignore it we should document it both in QEMU, but also in the kernel, because honestly the way the code is now it shouldn't fail from what I understand.
That said, even if we ignore it, IMHO we should at least print a warning in QEMU.
Right.
Quoted 5 lines
Quoted 3 lines
(To say the truth, I'm not sure if we need to care about this)
I agree on that, but this is related to the patch in the kernel, not
.> this simple patch to fix QEMU error path, right?
Or it's the charge of the Qemu vDPA layer to avoid calling set_vq_ready() after driver_ok if no VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK. Or it might be too late.
Quoted 37 lines
Quoted 37 lines
Quoted 9 lines
Quoted 8 lines
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We do know enabling could be done afterdriver_ok.
WithoutVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We don't know whether enabling could be done afterdriver_okor not.Quoted 5 lines
I see your point, indeed I didn't send a v2 of that patch. Maybe we should document that, because it could be interpreted that if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated the enabling should always be done beforedriver_ok(which is true for example in VDUSE).I see, so I think we probably need the fix.
Quoted 19 lines
BTW I think we should discuss it in the kernel patch.
Thanks,
StefanoQuoted 13 lines
Thanks
Quoted 10 lines
So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.
Quoted 8 lines
Quoted 1 line
Will go through [2].
Here I meant that the conflict is only in the code touched, because Kevin's patch remove/move some of the code touched by this patch. And rightly he checked the return value of the ioctl as I would like to do in the other places where we call the same ioctl.
So honestly I still don't understand what's wrong with this patch...
Nothing wrong now.
Thanks
Quoted 89 lines
Thanks,
StefanoQuoted 84 lines
Thanks
Quoted 79 lines
Quoted 78 lines
Quoted 77 lines
[2]
https://lore.kernel.org/qemu-devel/[email protected]/--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +7
-1@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:net/vhost-vdpa.c +12
-4@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ; --2.43.0
Quoted 43 lines · Jason Wang
Quoted 30 lines · Stefano Garzarella
Quoted 17 lines · Jason Wang
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · Jason Wang
Quoted 1 line · Stefano Garzarella
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.I wonder what happens if we just leave it as is.
Are you referring to this patch or the kernel patch?
This patch.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Here I'm just checking the return value of
vhost_vdpa_set_vring_ready(). It can return an error also without that kernel patch, so IMHO is better to check the return value here in QEMU.What issue do you see with this patch applied?
For the parent which can enable after
driver_okbut not advertise it.But this patch is not changing anything in that sense, it just controls the return value of the
VHOST_VDPA_SET_VRING_ENABLEioctl.Quoted 7 lines
Why would QEMU ignore an error if it can't activate vrings? If we really want to ignore it we should document it both in QEMU, but also in the kernel, because honestly the way the code is now it shouldn't fail from what I understand.
That said, even if we ignore it, IMHO we should at least print a warning in QEMU.
Right.
Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
(To say the truth, I'm not sure if we need to care about this)
I agree on that, but this is related to the patch in the kernel, not
.> this simple patch to fix QEMU error path, right?
Or it's the charge of the Qemu vDPA layer to avoid calling
set_vq_ready()afterdriver_okif noVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK. Or it might be too late.
Yeah, maybe is too late. We already released several versions without that.
Quoted 45 lines
Quoted 45 lines
Quoted 32 lines
Quoted 10 lines
Quoted 9 lines
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We do know enabling could be done afterdriver_ok.
WithoutVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We don't know whether enabling could be done afterdriver_okor not.Quoted 5 lines
I see your point, indeed I didn't send a v2 of that patch. Maybe we should document that, because it could be interpreted that if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated the enabling should always be done beforedriver_ok(which is true for example in VDUSE).I see, so I think we probably need the fix.
Quoted 14 lines
BTW I think we should discuss it in the kernel patch.
Thanks,
StefanoQuoted 8 lines
Thanks
Quoted 5 lines
So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.Will go through [2].
Here I meant that the conflict is only in the code touched, because Kevin's patch remove/move some of the code touched by this patch. And rightly he checked the return value of the ioctl as I would like to do in the other places where we call the same ioctl.
Quoted 5 lines
Quoted 1 line
So honestly I still don't understand what's wrong with this patch...
Nothing wrong now.
Acked-by Jason Wang <[email protected]>
Thanks for the review,
I'll send a v2 carrying your and Eugenio acks, rebasing on top of Kevin's patch, so it should be easy to merge.
Stefano
Quoted 35 lines · Jason Wang
Quoted 4 lines · Stefano Garzarella
Quoted 2 lines · Jason Wang
Quoted 1 line · Stefano Garzarella
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.I wonder what happens if we just leave it as is.
Are you referring to this patch or the kernel patch?
This patch.
Quoted 6 lines
Here I'm just checking the return value of
vhost_vdpa_set_vring_ready(). It can return an error also without that kernel patch, so IMHO is better to check the return value here in QEMU.What issue do you see with this patch applied?
For the parent which can enable after
driver_okbut not advertise it.(To say the truth, I'm not sure if we need to care about this)
Quoted 7 lines
Quoted 6 lines
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We do know enabling could be done afterdriver_ok.
WithoutVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK: We don't know whether enabling could be done afterdriver_okor not.
Quoted 8 lines
Quoted 5 lines
I see your point, indeed I didn't send a v2 of that patch. Maybe we should document that, because it could be interpreted that if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated the enabling should always be done beforedriver_ok(which is true for example in VDUSE).I see, so I think we probably need the fix.
A more complete fix is proper checking for VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK. But even with that, checking for failure in the ioctl is also worth it, isn't it?
The only point I see to not checking is to closely mimic virtio behavior, but vDPA can already fail here.
Quoted 105 lines
Quoted 19 lines
BTW I think we should discuss it in the kernel patch.
Thanks,
StefanoQuoted 13 lines
Thanks
Quoted 10 lines
So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.Will go through [2].
Thanks
Quoted 79 lines
Quoted 78 lines
Quoted 77 lines
[2]
https://lore.kernel.org/qemu-devel/[email protected]/--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +7
-1@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:net/vhost-vdpa.c +12
-4@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ; --2.43.0
Quoted 10 lines · Stefano Garzarella
vhost_vdpa_set_vring_ready()could already fail, but if Linux's patch [1] will be merged, it may fail with more chance if userspace does not activate virtqueues beforeDRIVER_OKwhenVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated.So better check its return value anyway.
[1] https://lore.kernel.org/virtualization/[email protected]/T/#u
If any, I'd split the patches in CVQ and generic vdpa device. But I don't think it is a big deal so
Sorry for the long delay!
Quoted 81 lines
Signed-off-by Stefano Garzarella <[email protected]>---
Note: This patch conflicts with [2], but the resolution is simple, so for now I sent a patch for the current master, but I'll rebase this patch if we merge the other one first.[2] https://lore.kernel.org/qemu-devel/[email protected]/
--- hw/virtio/vdpa-dev.c | 8 +++++++- net/vhost-vdpa.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +7
-1@@ -259,7 +259,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) goto err_guest_notifiers; }for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); + ret =vhost_vdpa_set_vring_ready (&s->vdpa, i); +if (ret <0 ) { +error_setg_errno (errp, -ret,"Error starting vring %d" , i); + goto err_dev_stop; + } } s->started = true;@@ -274,6 +278,8 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp)return ret; +err_dev_stop: +vhost_dev_stop (&s->dev, vdev, false); err_guest_notifiers: k->set_guest_notifiers (qbus->parent, s->dev.nvqs, false); err_host_notifiers:net/vhost-vdpa.c +12
-4@@ -381,7 +381,10 @@ static int vhost_vdpa_net_data_load(NetClientState *nc) }for (int i =0 ; i < v->dev->nvqs; ++i) { -vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +int ret =vhost_vdpa_set_vring_ready (v, i + v->dev->vq_index); +if (ret <0 ) { +return ret; + } }return 0 ; }@@ -1213,7 +1216,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc)assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); -vhost_vdpa_set_vring_ready (v, v->dev->vq_index); + r =vhost_vdpa_set_vring_ready (v, v->dev->vq_index); +if (unlikely (r <0 )) { +return r; + }if (v->shadow_vqs_enabled) { n =VIRTIO_NET (v->dev->vdev);@@ -1252,7 +1258,10 @@ static int vhost_vdpa_net_cvq_load(NetClientState *nc) }for (int i =0 ; i < v->dev->vq_index; ++i) { -vhost_vdpa_set_vring_ready (v, i); + r =vhost_vdpa_set_vring_ready (v, i); +if (unlikely (r <0 )) { +return r; + } }return 0 ; --2.43.0