vdpa-dev: Fix initialisation order to restore VDUSE compatibility
PATCH 1/1 vdpa-dev: Fix initialisation order to restore VDUSE compatibility
VDUSE requires that virtqueues are first enabled before the DRIVER_OK status flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit 6c482547 accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.
This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
--- hw/virtio/vdpa-dev.c | 5 +---- hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)
hw/virtio/vdpa-dev.c +1 -4
@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/*
hw/virtio/vhost-vdpa.c +17 -0
@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {
@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable, .vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL,
Signature · 1 line
2.43.0
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.
Yeah, IMHO the VDUSE protocol is missing a VDUSE_SET_VQ_READY message, I'll start another thread about that, but in the meantime I agree that we should fix QEMU since we need to work properly with old kernels as well.
Quoted 9 lines
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
I like this approach and the patch LGTM, but I'm a bit worried about this function in hw/net/vhost_net.c:
int vhost_set_vring_enable(NetClientState *nc, int enable)
{
VHostNetState *net = get_vhost_net(nc);
const VhostOps *vhost_ops = net->dev.vhost_ops;
nc->vring_enable = enable;
if (vhost_ops && vhost_ops->vhost_set_vring_enable) {
return vhost_ops->vhost_set_vring_enable(&net->dev, enable);
}
return 0;
}@Eugenio, @Jason, should we change some things there if vhost-vdpa implements the vhost_set_vring_enable callback?
Do you remember why we didn't implement it from the beginning?
Thanks,
Stefano
Quoted 67 lines
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>---
hw/virtio/vdpa-dev.c| 5 +----hw/virtio/vhost-vdpa.c| 17 +++++++++++++++++2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +17
-0@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable, .vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL,Signature · 1 line
2.43.0
Quoted 79 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>--- hw/virtio/vdpa-dev.c | 5 +---- hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +17
-1@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable, .vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL, --
Quoted 2 lines
2.43.0
vhost-vdpa net enables CVQ before dataplane ones to configure all the device in the destination of a live migration. To go back again to this callback would cause the device to enable the dataplane before virtqueues are configured again.
How does VDUSE userspace knows how many queues should enable? Can't the kernel perform the necessary actions after DRIVER_OK, like configuring the kick etc?
Thanks!
Am 02.02.2024 um 14:25 hat Kevin Wolf geschrieben:
Quoted 55 lines
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>--- hw/virtio/vdpa-dev.c | 5 +---- hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +5
-0@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret;
hw/virtio/vhost-vdpa.c int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx) · line 921
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +}
Oops, this forgets to actually use the @enable parameter, and always enables the queue even if the caller wanted to disable it.
I'll fix this in a v2, but I'd first like to see if something has to change to address Stefano's concern, too.
Kevin
Am 05.02.2024 um 13:22 hat Eugenio Perez Martin geschrieben:
Quoted 76 lines · Kevin Wolf
Quoted 75 lines
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>--- hw/virtio/vdpa-dev.c | 5 +---- hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +17
-0@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable,
Quoted 8 lines
hw/virtio/vhost-vdpa.c const VhostOps vdpa_ops = { · line 1546
Quoted 3 lines
hw/virtio/vhost-vdpa.c +0
-0.vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL,vhost-vdpa net enables CVQ before dataplane ones to configure all the device in the destination of a live migration. To go back again to this callback would cause the device to enable the dataplane before virtqueues are configured again.
Not that it makes a difference, but I don't think it would actually be going back. Even before your commit 6c482547, we were not making use of the generic callback but just called the function in a slightly different place (but less different than after commit 6c482547).
But anyway... Why don't the other vhost backend need the same for vhost-net then? Do they just not support live migration?
I don't know the code well enough to say where the problem is, but if vhost-vdpa networking code relies on the usual vhost operations not being implemented and bypasses VhostOps to replace it, that sounds like a design problem to me. Maybe VhostOps needs a new operation to enable just a single virtqueue that can be used by the networking code instead?
Quoted 3 lines
How does VDUSE userspace knows how many queues should enable? Can't the kernel perform the necessary actions after
DRIVER_OK, like configuring the kick etc?
Not sure if I understand the question. The vdpa kernel interface always enables individual queues, so the VDUSE userspace will enable whatever queues it was asked to enable. The only restriction is that the queues need to be enabled before setting DRIVER_OK.
The interface that enables all virtqueues at once seems to be just .vhost_set_vring_enable in QEMU.
Kevin
Quoted 6 lines · Stefano Garzarella
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.
Did this mean virtio-blk will enable a virtqueue after DRIVER_OK? Sepc is not clear about this and that's why we introduce VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK.
Quoted 2 lines
Yeah, IMHO the VDUSE protocol is missing a
VDUSE_SET_VQ_READYmessage,
I think you meant when VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK is negotiated. If this is truth, it seems a little more complicated, for example the get_backend_features needs to be forward to the userspace? This seems suboptimal to implement this in the spec first and then we can leverage the features. Or we can have another parameter for the ioctl that creates the vduse device.
Quoted 31 lines
I'll start another thread about that, but in the meantime I agree that we should fix QEMU since we need to work properly with old kernels as well.
Quoted 9 lines
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
I like this approach and the patch LGTM, but I'm a bit worried about this function in
hw/net/vhost_net.c:int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops = net->dev.vhost_ops; nc->vring_enable = enable; if (vhost_ops && vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } return 0; }
Quoted 2 lines
@Eugenio, @Jason, should we change some things there if vhost-vdpa implements the
vhost_set_vring_enablecallback?
Eugenio may know more, I remember we need to enable cvq first for shadow virtqueue to restore some states.
Quoted 2 lines
Do you remember why we didn't implement it from the beginning?
It seems the vrings parameter is introduced after vhost-vdpa is implemented.
Thanks
Quoted 72 lines
Thanks,
StefanoQuoted 67 lines
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>---
hw/virtio/vdpa-dev.c| 5 +----hw/virtio/vhost-vdpa.c| 17 +++++++++++++++++2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +17
-1@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable, .vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL, --2.43.0
Quoted 9 lines · Jason Wang
Quoted 6 lines · Stefano Garzarella
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.Did this mean virtio-blk will enable a virtqueue after
DRIVER_OK?
It's not specific to virtio-blk, but to the generic vdpa device we have in QEMU (i.e. vhost-vdpa-device). Yep, after commit 6c4825476a4351530bcac17abab72295b75ffe98, virtqueues are enabled after DRIVER_OK.
Quoted 2 lines
Sepc is not clear about this and that's why we introduce
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK.
Ah, I didn't know about this new feature. So after commit 6c4825476a4351530bcac17abab72295b75ffe98 the vhost-vdpa-device is not complying with the specification, right?
Quoted 6 lines
Quoted 3 lines
Yeah, IMHO the VDUSE protocol is missing a
VDUSE_SET_VQ_READYmessage,I think you meant when
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis negotiated.
At this point yes. But if VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK is not negotiated, should we return an error in vhost-vdpa kernel module if VHOST_VDPA_SET_VRING_ENABLE is called when DRIVER_OK is already set?
Quoted 2 lines
If this is truth, it seems a little more complicated, for example the
get_backend_featuresneeds to be forward to the userspace?
I'm not understanding, don't we already have VHOST_GET_BACKEND_FEATURES for this? Or do you mean userspace on the VDUSE side?
Quoted 3 lines
This seems suboptimal to implement this in the spec first and then we can leverage the features. Or we can have another parameter for the ioctl that creates the vduse device.
I got a little lost, though in vhost-user, the device can always expect a vring_enable/disable, so I thought it was not complicated in VDUSE.
Quoted 35 lines
Quoted 32 lines
I'll start another thread about that, but in the meantime I agree that we should fix QEMU since we need to work properly with old kernels as well.
Quoted 9 lines
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
I like this approach and the patch LGTM, but I'm a bit worried about this function in
hw/net/vhost_net.c:int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops = net->dev.vhost_ops; nc->vring_enable = enable; if (vhost_ops && vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } return 0; }Quoted 2 lines
@Eugenio, @Jason, should we change some things there if vhost-vdpa implements the
vhost_set_vring_enablecallback?
Quoted 7 lines
Eugenio may know more, I remember we need to enable cvq first for shadow virtqueue to restore some states.
Quoted 2 lines
Do you remember why we didn't implement it from the beginning?
It seems the vrings parameter is introduced after vhost-vdpa is implemented.
Sorry, I mean why we didn't implement the vhost_set_vring_enable callback for vhost-vdpa from the beginning.
Thanks,
Stefano
Quoted 26 lines · Stefano Garzarella
Quoted 9 lines · Jason Wang
Quoted 6 lines · Stefano Garzarella
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.Did this mean virtio-blk will enable a virtqueue after
DRIVER_OK?It's not specific to virtio-blk, but to the generic vdpa device we have in QEMU (i.e. vhost-vdpa-device). Yep, after commit
6c4825476a4351530bcac17abab72295b75ffe98, virtqueues are enabled afterDRIVER_OK.Quoted 2 lines
Sepc is not clear about this and that's why we introduce
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK.Ah, I didn't know about this new feature. So after commit
6c4825476a4351530bcac17abab72295b75ffe98the vhost-vdpa-device is not complying with the specification, right?Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Yeah, IMHO the VDUSE protocol is missing a
VDUSE_SET_VQ_READYmessage,I think you meant when
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis negotiated.At this point yes. But if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated, should we return an error in vhost-vdpa kernel module ifVHOST_VDPA_SET_VRING_ENABLEis called whenDRIVER_OKis already set?
I just sent a patch:
https://lore.kernel.org/virtualization/[email protected]/T/#u
Then I discovered that we never check the return value of vhost_vdpa_set_vring_ready() in QEMU.
I'll send a patch for that!
Stefano
Quoted 63 lines
Quoted 3 lines
If this is truth, it seems a little more complicated, for example the
get_backend_featuresneeds to be forward to the userspace?I'm not understanding, don't we already have
VHOST_GET_BACKEND_FEATURESfor this? Or do you mean userspace on the VDUSE side?Quoted 3 lines
This seems suboptimal to implement this in the spec first and then we can leverage the features. Or we can have another parameter for the ioctl that creates the vduse device.
I got a little lost, though in vhost-user, the device can always expect a vring_enable/disable, so I thought it was not complicated in VDUSE.
Quoted 35 lines
Quoted 32 lines
I'll start another thread about that, but in the meantime I agree that we should fix QEMU since we need to work properly with old kernels as well.
Quoted 9 lines
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
I like this approach and the patch LGTM, but I'm a bit worried about this function in
hw/net/vhost_net.c:int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops = net->dev.vhost_ops; nc->vring_enable = enable; if (vhost_ops && vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } return 0; }Quoted 2 lines
@Eugenio, @Jason, should we change some things there if vhost-vdpa implements the
vhost_set_vring_enablecallback?Quoted 8 lines
Eugenio may know more, I remember we need to enable cvq first for shadow virtqueue to restore some states.
Quoted 2 lines
Do you remember why we didn't implement it from the beginning?
It seems the vrings parameter is introduced after vhost-vdpa is implemented.
Sorry, I mean why we didn't implement the
vhost_set_vring_enablecallback for vhost-vdpa from the beginning.Thanks,
Stefano
Quoted 87 lines · Kevin Wolf
Am 05.02.2024 um 13:22 hat Eugenio Perez Martin geschrieben:
Quoted 76 lines · Kevin Wolf
Quoted 75 lines
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>--- hw/virtio/vdpa-dev.c | 5 +---- hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +17
-0@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable,Quoted 8 lines
hw/virtio/vhost-vdpa.c const VhostOps vdpa_ops = { · line 1546
Quoted 3 lines
hw/virtio/vhost-vdpa.c +0
-0.vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL,vhost-vdpa net enables CVQ before dataplane ones to configure all the device in the destination of a live migration. To go back again to this callback would cause the device to enable the dataplane before virtqueues are configured again.
Quoted 8 lines
Not that it makes a difference, but I don't think it would actually be going back. Even before your commit
6c482547, we were not making use of the generic callback but just called the function in a slightly different place (but less different than after commit6c482547).But anyway... Why don't the other vhost backend need the same for vhost-net then? Do they just not support live migration?
They don't support control virtqueue. More specifically, control virtqueue is handled directly in QEMU.
Quoted 4 lines
I don't know the code well enough to say where the problem is, but if vhost-vdpa networking code relies on the usual vhost operations not being implemented and bypasses VhostOps to replace it, that sounds like a design problem to me.
I don't follow this. What vhost operation is expected not to be implemented?
Quoted 7 lines
Maybe VhostOps needs a new operation to enable
just a single virtqueue that can be used by the networking code instead?Quoted 3 lines
How does VDUSE userspace knows how many queues should enable? Can't the kernel perform the necessary actions after
DRIVER_OK, like configuring the kick etc?
Quoted 8 lines
Not sure if I understand the question. The vdpa kernel interface always enables individual queues, so the VDUSE userspace will enable whatever queues it was asked to enable. The only restriction is that the queues need to be enabled before setting
DRIVER_OK.The interface that enables all virtqueues at once seems to be just .vhost_set_vring_enable in QEMU.
It enables all virtqueues of the same vhost device in QEMU, but QEMU creates one vhost_dev per each vhost-net virtqueue pair and another one for CVQ. This goes back to the time where mq vhost-kernel net devices were implemented by mergin many tap devices. net/vhost-vdpa.c only enables the last one, which corresponds to CVQ, and then enables the rest once all messages have been received.
On the other hand, .vhost_set_vring_enable is also used for queue reset (vhost_net_virtqueue_reset and vhost_net_virtqueue_restart). In other words, it is called after the set DRIVER_OK. I guess it is fine for VDUSE as long as it does not offer vring reset capabilities, but future wise should we start going in that direction?
But kernels without VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK should be supported, right. Maybe we can add vhost_vdpa_set_vring_enable and call vhost_dev_start with vrings parameters conditional to the feature flag? That way the caller can enable it later or just enable all the rings altogether.
Thanks!
Quoted 10 lines · Stefano Garzarella
Quoted 8 lines · Jason Wang
Quoted 6 lines · Stefano Garzarella
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.
Quoted 6 lines
Quoted 1 line
Did this mean virtio-blk will enable a virtqueue after
DRIVER_OK?It's not specific to virtio-blk, but to the generic vdpa device we have in QEMU (i.e. vhost-vdpa-device). Yep, after commit
6c4825476a4351530bcac17abab72295b75ffe98, virtqueues are enabled afterDRIVER_OK.
Right.
Quoted 7 lines
Quoted 3 lines
Sepc is not clear about this and that's why we introduce
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK.Ah, I didn't know about this new feature. So after commit
6c4825476a4351530bcac17abab72295b75ffe98the vhost-vdpa-device is not complying with the specification, right?
Kind of, but as stated, it's just because spec is unclear about the behaviour. There's a chance that spec will explicitly support it in the future.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Yeah, IMHO the VDUSE protocol is missing a
VDUSE_SET_VQ_READYmessage,I think you meant when
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis negotiated.At this point yes. But if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated, should we return an error in vhost-vdpa kernel module ifVHOST_VDPA_SET_VRING_ENABLEis called whenDRIVER_OKis already set?
I'm not sure if this can break some setups or not. It might be better to leave it as is?
Without VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we don't know if parent support vq_ready after driver_ok.
With VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we know parent support vq_ready after driver_ok.
Quoted 6 lines
Quoted 3 lines
If this is truth, it seems a little more complicated, for example the
get_backend_featuresneeds to be forward to the userspace?I'm not understanding, don't we already have
VHOST_GET_BACKEND_FEATURESfor this? Or do you mean userspace on the VDUSE side?
Yes, since in this case the parent is in the userspace, there's no way for VDUSE to know if user space supports vq_ready after driver_ok or not.
As you may have noticed, we don't have a message for vq_ready which implies that vq_ready after driver_ok can't be supported.
Quoted 7 lines
Quoted 4 lines
This seems suboptimal to implement this in the spec first and then we can leverage the features. Or we can have another parameter for the ioctl that creates the vduse device.
I got a little lost, though in vhost-user, the device can always expect a vring_enable/disable, so I thought it was not complicated in VDUSE.
Yes, the problem is assuming we have a message for vq_ready, there could be a "legacy" userspace that doesn't support that. So in that case, VDUSE needs to know if the userspace parent can support that or not.
Quoted 40 lines
Quoted 40 lines
Quoted 33 lines
I'll start another thread about that, but in the meantime I agree that we should fix QEMU since we need to work properly with old kernels as well.
Quoted 9 lines
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
I like this approach and the patch LGTM, but I'm a bit worried about this function in
hw/net/vhost_net.c:int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops = net->dev.vhost_ops; nc->vring_enable = enable; if (vhost_ops && vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } return 0; }Quoted 2 lines
@Eugenio, @Jason, should we change some things there if vhost-vdpa implements the
vhost_set_vring_enablecallback?Eugenio may know more, I remember we need to enable cvq first for shadow virtqueue to restore some states.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Do you remember why we didn't implement it from the beginning?
It seems the vrings parameter is introduced after vhost-vdpa is implemented.
Sorry, I mean why we didn't implement the
vhost_set_vring_enablecallback for vhost-vdpa from the beginning.
Adding Cindy who writes those codes for more thoughts.
Thanks
Quoted 4 lines
Thanks,
Stefano
Quoted 122 lines · Jason Wang <[email protected]> 于2024年2月7日周三 11:17写道:
Quoted 10 lines · Stefano Garzarella
Quoted 8 lines · Jason Wang
Quoted 6 lines · Stefano Garzarella
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.Quoted 6 lines
Quoted 1 line
Did this mean virtio-blk will enable a virtqueue after
DRIVER_OK?It's not specific to virtio-blk, but to the generic vdpa device we have in QEMU (i.e. vhost-vdpa-device). Yep, after commit
6c4825476a4351530bcac17abab72295b75ffe98, virtqueues are enabled afterDRIVER_OK.Right.
Quoted 7 lines
Quoted 3 lines
Sepc is not clear about this and that's why we introduce
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK.Ah, I didn't know about this new feature. So after commit
6c4825476a4351530bcac17abab72295b75ffe98the vhost-vdpa-device is not complying with the specification, right?Kind of, but as stated, it's just because spec is unclear about the behaviour. There's a chance that spec will explicitly support it in the future.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Yeah, IMHO the VDUSE protocol is missing a
VDUSE_SET_VQ_READYmessage,I think you meant when
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis negotiated.At this point yes. But if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated, should we return an error in vhost-vdpa kernel module ifVHOST_VDPA_SET_VRING_ENABLEis called whenDRIVER_OKis already set?I'm not sure if this can break some setups or not. It might be better to leave it as is?
Without
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we don't know if parent supportvq_readyafterdriver_ok.
WithVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we know parent supportvq_readyafterdriver_ok.Quoted 6 lines
Quoted 3 lines
If this is truth, it seems a little more complicated, for example the
get_backend_featuresneeds to be forward to the userspace?I'm not understanding, don't we already have
VHOST_GET_BACKEND_FEATURESfor this? Or do you mean userspace on the VDUSE side?Yes, since in this case the parent is in the userspace, there's no way for VDUSE to know if user space supports
vq_readyafterdriver_okor not.As you may have noticed, we don't have a message for
vq_readywhich implies thatvq_readyafterdriver_okcan't be supported.Quoted 7 lines
Quoted 4 lines
This seems suboptimal to implement this in the spec first and then we can leverage the features. Or we can have another parameter for the ioctl that creates the vduse device.
I got a little lost, though in vhost-user, the device can always expect a vring_enable/disable, so I thought it was not complicated in VDUSE.
Yes, the problem is assuming we have a message for
vq_ready, there could be a "legacy" userspace that doesn't support that. So in that case, VDUSE needs to know if the userspace parent can support that or not.Quoted 42 lines
Quoted 42 lines
Quoted 33 lines
I'll start another thread about that, but in the meantime I agree that we should fix QEMU since we need to work properly with old kernels as well.
Quoted 9 lines
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
I like this approach and the patch LGTM, but I'm a bit worried about this function in
hw/net/vhost_net.c:int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops = net->dev.vhost_ops; nc->vring_enable = enable; if (vhost_ops && vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } return 0; }Quoted 2 lines
@Eugenio, @Jason, should we change some things there if vhost-vdpa implements the
vhost_set_vring_enablecallback?Eugenio may know more, I remember we need to enable cvq first for shadow virtqueue to restore some states.
Quoted 2 lines
Do you remember why we didn't implement it from the beginning?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It seems the vrings parameter is introduced after vhost-vdpa is implemented.
Sorry, I mean why we didn't implement the
vhost_set_vring_enablecallback for vhost-vdpa from the beginning.Adding Cindy who writes those codes for more thoughts.
it's a really long time ago, and I can't remember it clearly. It seems like there might be an issue with the sequence being called for dev_start and vhost_set_vring_enable?
I have searched my mail but find nothing. I think we should do a full test if we want to this
Thanks
Cindy
Quoted 7 lines
Thanks
Quoted 4 lines
Thanks,
Stefano
Quoted 40 lines · Jason Wang
Quoted 10 lines · Stefano Garzarella
Quoted 8 lines · Jason Wang
Quoted 6 lines · Stefano Garzarella
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.Quoted 6 lines
Quoted 1 line
Did this mean virtio-blk will enable a virtqueue after
DRIVER_OK?It's not specific to virtio-blk, but to the generic vdpa device we have in QEMU (i.e. vhost-vdpa-device). Yep, after commit
6c4825476a4351530bcac17abab72295b75ffe98, virtqueues are enabled afterDRIVER_OK.Right.
Quoted 7 lines
Quoted 3 lines
Sepc is not clear about this and that's why we introduce
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK.Ah, I didn't know about this new feature. So after commit
6c4825476a4351530bcac17abab72295b75ffe98the vhost-vdpa-device is not complying with the specification, right?Kind of, but as stated, it's just because spec is unclear about the behaviour. There's a chance that spec will explicitly support it in the future.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Yeah, IMHO the VDUSE protocol is missing a
VDUSE_SET_VQ_READYmessage,I think you meant when
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis negotiated.
Quoted 6 lines
Quoted 3 lines
At this point yes. But if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated, should we return an error in vhost-vdpa kernel module ifVHOST_VDPA_SET_VRING_ENABLEis called whenDRIVER_OKis already set?I'm not sure if this can break some setups or not. It might be better to leave it as is?
As I also answered in the kernel patch, IMHO we have to return an error, because any setups are broken anyway (see the problem we're fixing with this patch), so at this point it's better to return an error, so they don't spend time figuring out why the VDUSE device doesn't work.
Quoted 3 lines
Without
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we don't know if parent supportvq_readyafterdriver_ok.
So we have to assume that it doesn't support it, to be more conservative, right?
Quoted 10 lines
With
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we know parent supportvq_readyafterdriver_ok.Quoted 6 lines
Quoted 3 lines
If this is truth, it seems a little more complicated, for example the
get_backend_featuresneeds to be forward to the userspace?I'm not understanding, don't we already have
VHOST_GET_BACKEND_FEATURESfor this? Or do you mean userspace on the VDUSE side?
Quoted 6 lines
Yes, since in this case the parent is in the userspace, there's no way for VDUSE to know if user space supports
vq_readyafterdriver_okor not.As you may have noticed, we don't have a message for
vq_readywhich implies thatvq_readyafterdriver_okcan't be supported.
Yep, I see.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
This seems suboptimal to implement this in the spec first and then we can leverage the features. Or we can have another parameter for the ioctl that creates the vduse device.
Quoted 7 lines
Quoted 2 lines
I got a little lost, though in vhost-user, the device can always expect a vring_enable/disable, so I thought it was not complicated in VDUSE.
Yes, the problem is assuming we have a message for
vq_ready, there could be a "legacy" userspace that doesn't support that. So in that case, VDUSE needs to know if the userspace parent can support that or not.
I think VDUSE needs to negotiate features (if it doesn't already) as vhost-user does with the backend. Also for new future functionality.
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 34 lines
I'll start another thread about that, but in the meantime I agree that we should fix QEMU since we need to work properly with old kernels as well.
Quoted 9 lines
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
I like this approach and the patch LGTM, but I'm a bit worried about this function in
hw/net/vhost_net.c:int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops = net->dev.vhost_ops; nc->vring_enable = enable; if (vhost_ops && vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } return 0; }Quoted 2 lines
@Eugenio, @Jason, should we change some things there if vhost-vdpa implements the
vhost_set_vring_enablecallback?Eugenio may know more, I remember we need to enable cvq first for shadow virtqueue to restore some states.
Quoted 2 lines
Do you remember why we didn't implement it from the beginning?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
It seems the vrings parameter is introduced after vhost-vdpa is implemented.
Sorry, I mean why we didn't implement the
vhost_set_vring_enablecallback for vhost-vdpa from the beginning.Adding Cindy who writes those codes for more thoughts.
Thanks,
Stefano
Quoted 129 lines · Cindy Lu
Quoted 128 lines · Jason Wang <[email protected]> 于2024年2月7日周三 11:17写道:
Quoted 10 lines · Stefano Garzarella
Quoted 8 lines · Jason Wang
Quoted 6 lines · Stefano Garzarella
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.Quoted 6 lines
Quoted 1 line
Did this mean virtio-blk will enable a virtqueue after
DRIVER_OK?It's not specific to virtio-blk, but to the generic vdpa device we have in QEMU (i.e. vhost-vdpa-device). Yep, after commit
6c4825476a4351530bcac17abab72295b75ffe98, virtqueues are enabled afterDRIVER_OK.Right.
Quoted 7 lines
Quoted 3 lines
Sepc is not clear about this and that's why we introduce
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK.Ah, I didn't know about this new feature. So after commit
6c4825476a4351530bcac17abab72295b75ffe98the vhost-vdpa-device is not complying with the specification, right?Kind of, but as stated, it's just because spec is unclear about the behaviour. There's a chance that spec will explicitly support it in the future.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Yeah, IMHO the VDUSE protocol is missing a
VDUSE_SET_VQ_READYmessage,I think you meant when
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis negotiated.At this point yes. But if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated, should we return an error in vhost-vdpa kernel module ifVHOST_VDPA_SET_VRING_ENABLEis called whenDRIVER_OKis already set?I'm not sure if this can break some setups or not. It might be better to leave it as is?
Without
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we don't know if parent supportvq_readyafterdriver_ok.
WithVHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we know parent supportvq_readyafterdriver_ok.Quoted 6 lines
Quoted 3 lines
If this is truth, it seems a little more complicated, for example the
get_backend_featuresneeds to be forward to the userspace?I'm not understanding, don't we already have
VHOST_GET_BACKEND_FEATURESfor this? Or do you mean userspace on the VDUSE side?Yes, since in this case the parent is in the userspace, there's no way for VDUSE to know if user space supports
vq_readyafterdriver_okor not.As you may have noticed, we don't have a message for
vq_readywhich implies thatvq_readyafterdriver_okcan't be supported.Quoted 7 lines
Quoted 4 lines
This seems suboptimal to implement this in the spec first and then we can leverage the features. Or we can have another parameter for the ioctl that creates the vduse device.
I got a little lost, though in vhost-user, the device can always expect a vring_enable/disable, so I thought it was not complicated in VDUSE.
Yes, the problem is assuming we have a message for
vq_ready, there could be a "legacy" userspace that doesn't support that. So in that case, VDUSE needs to know if the userspace parent can support that or not.Quoted 47 lines
Quoted 36 lines
Quoted 33 lines
I'll start another thread about that, but in the meantime I agree that we should fix QEMU since we need to work properly with old kernels as well.
Quoted 9 lines
This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
I like this approach and the patch LGTM, but I'm a bit worried about this function in
hw/net/vhost_net.c:int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops = net->dev.vhost_ops; nc->vring_enable = enable; if (vhost_ops && vhost_ops->vhost_set_vring_enable) { return vhost_ops->vhost_set_vring_enable(&net->dev, enable); } return 0; }Quoted 2 lines
@Eugenio, @Jason, should we change some things there if vhost-vdpa implements the
vhost_set_vring_enablecallback?Quoted 8 lines
Eugenio may know more, I remember we need to enable cvq first for shadow virtqueue to restore some states.
Quoted 2 lines
Do you remember why we didn't implement it from the beginning?
It seems the vrings parameter is introduced after vhost-vdpa is implemented.
Sorry, I mean why we didn't implement the
vhost_set_vring_enablecallback for vhost-vdpa from the beginning.
Quoted 7 lines
Quoted 2 lines
Adding Cindy who writes those codes for more thoughts.
it's a really long time ago, and I can't remember it clearly. It seems like there might be an issue with the sequence being called for
dev_startandvhost_set_vring_enable?
I have searched my mail but find nothing. I think we should do a full test if we want to this
IMHO in hw/net/vhost_net.c we should check the type of backend (e.g. vhost-vdpa) to decide whether to call vhost_ops->vhost_set_vring_enable() or not, instead of just checking whether the callback is implemented or not, because in the future we might have other backends (e.g. a native vdpa-blk driver) that might want that callback implemented.
Something like this (untested):
hw/net/vhost_net.c +2 -1
@@ -543,7 +543,8 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) nc->vring_enable = enable; -if (vhost_ops && vhost_ops->vhost_set_vring_enable) { +if (nc->info->type !=NET_CLIENT_DRIVER_VHOST_VDPA && + vhost_ops && vhost_ops->vhost_set_vring_enable) {return vhost_ops->vhost_set_vring_enable (&net->dev, enable); }
WDYT?
Thanks,
Stefano
Am 06.02.2024 um 17:44 hat Eugenio Perez Martin geschrieben:
Quoted 93 lines · Kevin Wolf
Quoted 92 lines
Am 05.02.2024 um 13:22 hat Eugenio Perez Martin geschrieben:
Quoted 76 lines · Kevin Wolf
Quoted 75 lines
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>--- hw/virtio/vdpa-dev.c | 5 +---- hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +17
-0@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable,Quoted 8 lines
hw/virtio/vhost-vdpa.c const VhostOps vdpa_ops = { · line 1546
Quoted 3 lines
hw/virtio/vhost-vdpa.c +0
-0.vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL,vhost-vdpa net enables CVQ before dataplane ones to configure all the device in the destination of a live migration. To go back again to this callback would cause the device to enable the dataplane before virtqueues are configured again.
Not that it makes a difference, but I don't think it would actually be going back. Even before your commit
6c482547, we were not making use of the generic callback but just called the function in a slightly different place (but less different than after commit6c482547).
Quoted 5 lines
Quoted 2 lines
But anyway... Why don't the other vhost backend need the same for vhost-net then? Do they just not support live migration?
They don't support control virtqueue. More specifically, control virtqueue is handled directly in QEMU.
So the network device already has to special case vdpa instead of using the same code for all vhost backends? :-/
Quoted 6 lines
Quoted 4 lines
I don't know the code well enough to say where the problem is, but if vhost-vdpa networking code relies on the usual vhost operations not being implemented and bypasses VhostOps to replace it, that sounds like a design problem to me.
I don't follow this. What vhost operation is expected not to be implemented?
You were concerned about implementing .vhost_set_vring_enable in vdpa_ops like my patch does. So it seems that the networking code requires that it is not implemented?
On the other hand, for vhost-vdpa, the callback seems to be called in exactly the right place where virtqueues need to be enabled, like for other vhost devices.
Quoted 15 lines
Quoted 7 lines
Maybe VhostOps needs a new operation to enable
just a single virtqueue that can be used by the networking code instead?Quoted 3 lines
How does VDUSE userspace knows how many queues should enable? Can't the kernel perform the necessary actions after
DRIVER_OK, like configuring the kick etc?Quoted 7 lines
Not sure if I understand the question. The vdpa kernel interface always enables individual queues, so the VDUSE userspace will enable whatever queues it was asked to enable. The only restriction is that the queues need to be enabled before setting
DRIVER_OK.The interface that enables all virtqueues at once seems to be just .vhost_set_vring_enable in QEMU.
Quoted 6 lines
It enables all virtqueues of the same vhost device in QEMU, but QEMU creates one
vhost_devper each vhost-net virtqueue pair and another one for CVQ. This goes back to the time where mq vhost-kernel net devices were implemented by mergin many tap devices.net/vhost-vdpa.conly enables the last one, which corresponds to CVQ, and then enables the rest once all messages have been received.
So it's less about the granularity of .vhost_set_vring_enable, which would just be right, but about the order in which it is called for the different vhost_devs?
Can we influence the order in another way than just not implementing the callback at all? I think net specific weirdness should be contained in the net implementation and not affect generic vdpa code.
Quoted 5 lines
On the other hand, .vhost_set_vring_enable is also used for queue reset (
vhost_net_virtqueue_resetandvhost_net_virtqueue_restart). In other words, it is called after the setDRIVER_OK. I guess it is fine for VDUSE as long as it does not offer vring reset capabilities, but future wise should we start going in that direction?
I don't actually know VDUSE very well, but that would probably make sense.
Though for the moment, I just tried to simply attach a VDUSE device and failed, so I'm just trying to fix the regression from your commit.
Quoted 5 lines
But kernels without
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKshould be supported, right. Maybe we can addvhost_vdpa_set_vring_enableand callvhost_dev_startwith vrings parameters conditional to the feature flag? That way the caller can enable it later or just enable all the rings altogether.
Which specific caller do you mean here?
For vdpa-dev, I don't see any problem with just passing vrings=true unconditionally. That is clearly the least problematic order even if another order may in theory be allowed by the spec.
For vhost_net, I don't know. As far as I am concerned, there is no reason to change its call and it could continue to pass vrings=false.
So vhost_dev_start() seems entirely unproblematic.
The only part that changes for net is that vhost_set_vring_enable() now does something where it didn't do anything before. If that is a problem for vdpa based network code, maybe we can just special case vdpa there to not call vhost_ops->vhost_set_vring_enable? (Despite its name, it's a network specific function; it should probably be called something like vhost_net_set_vring_enable.)
With something like the below, net shouldn't see any difference any more, right? (Happy to add a comment before it if you write it for me.)
Kevin
hw/net/vhost_net.c +4 -0
@@ -543,6 +543,10 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) nc->vring_enable = enable; +if (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +return 0 ; + } +if (vhost_ops && vhost_ops->vhost_set_vring_enable) {return vhost_ops->vhost_set_vring_enable (&net->dev, enable); }
Quoted 184 lines · Kevin Wolf
Am 06.02.2024 um 17:44 hat Eugenio Perez Martin geschrieben:
Quoted 93 lines · Kevin Wolf
Quoted 92 lines
Am 05.02.2024 um 13:22 hat Eugenio Perez Martin geschrieben:
Quoted 76 lines · Kevin Wolf
Quoted 75 lines
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>--- hw/virtio/vdpa-dev.c | 5 +---- hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +17
-0@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable,Quoted 8 lines
hw/virtio/vhost-vdpa.c const VhostOps vdpa_ops = { · line 1546
Quoted 3 lines
hw/virtio/vhost-vdpa.c +0
-0.vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL,vhost-vdpa net enables CVQ before dataplane ones to configure all the device in the destination of a live migration. To go back again to this callback would cause the device to enable the dataplane before virtqueues are configured again.
Not that it makes a difference, but I don't think it would actually be going back. Even before your commit
6c482547, we were not making use of the generic callback but just called the function in a slightly different place (but less different than after commit6c482547).Quoted 5 lines
Quoted 2 lines
But anyway... Why don't the other vhost backend need the same for vhost-net then? Do they just not support live migration?
They don't support control virtqueue. More specifically, control virtqueue is handled directly in QEMU.
So the network device already has to special case vdpa instead of using the same code for all vhost backends? :-/
Quoted 6 lines
Quoted 4 lines
I don't know the code well enough to say where the problem is, but if vhost-vdpa networking code relies on the usual vhost operations not being implemented and bypasses VhostOps to replace it, that sounds like a design problem to me.
I don't follow this. What vhost operation is expected not to be implemented?
You were concerned about implementing .vhost_set_vring_enable in
vdpa_opslike my patch does. So it seems that the networking code requires that it is not implemented?On the other hand, for vhost-vdpa, the callback seems to be called in exactly the right place where virtqueues need to be enabled, like for other vhost devices.
Quoted 15 lines
Quoted 7 lines
Maybe VhostOps needs a new operation to enable
just a single virtqueue that can be used by the networking code instead?Quoted 3 lines
How does VDUSE userspace knows how many queues should enable? Can't the kernel perform the necessary actions after
DRIVER_OK, like configuring the kick etc?Quoted 7 lines
Not sure if I understand the question. The vdpa kernel interface always enables individual queues, so the VDUSE userspace will enable whatever queues it was asked to enable. The only restriction is that the queues need to be enabled before setting
DRIVER_OK.The interface that enables all virtqueues at once seems to be just .vhost_set_vring_enable in QEMU.
Quoted 6 lines
It enables all virtqueues of the same vhost device in QEMU, but QEMU creates one
vhost_devper each vhost-net virtqueue pair and another one for CVQ. This goes back to the time where mq vhost-kernel net devices were implemented by mergin many tap devices.net/vhost-vdpa.conly enables the last one, which corresponds to CVQ, and then enables the rest once all messages have been received.So it's less about the granularity of .vhost_set_vring_enable, which would just be right, but about the order in which it is called for the different
vhost_devs?Can we influence the order in another way than just not implementing the callback at all? I think net specific weirdness should be contained in the net implementation and not affect generic vdpa code.
Quoted 5 lines
On the other hand, .vhost_set_vring_enable is also used for queue reset (
vhost_net_virtqueue_resetandvhost_net_virtqueue_restart). In other words, it is called after the setDRIVER_OK. I guess it is fine for VDUSE as long as it does not offer vring reset capabilities, but future wise should we start going in that direction?I don't actually know VDUSE very well, but that would probably make sense.
Though for the moment, I just tried to simply attach a VDUSE device and failed, so I'm just trying to fix the regression from your commit.
Quoted 5 lines
But kernels without
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKshould be supported, right. Maybe we can addvhost_vdpa_set_vring_enableand callvhost_dev_startwith vrings parameters conditional to the feature flag? That way the caller can enable it later or just enable all the rings altogether.Which specific caller do you mean here?
For vdpa-dev, I don't see any problem with just passing vrings=true unconditionally. That is clearly the least problematic order even if another order may in theory be allowed by the spec.
For
vhost_net, I don't know. As far as I am concerned, there is no reason to change its call and it could continue to pass vrings=false.So
vhost_dev_start()seems entirely unproblematic.The only part that changes for net is that
vhost_set_vring_enable()now does something where it didn't do anything before. If that is a problem for vdpa based network code, maybe we can just special case vdpa there to not callvhost_ops->vhost_set_vring_enable? (Despite its name, it's a network specific function; it should probably be called something likevhost_net_set_vring_enable.)
Quoted 2 lines
With something like the below, net shouldn't see any difference any more, right? (Happy to add a comment before it if you write it for me.)
+1 for this.
I proposed something similar, but I prefer your early return which is clearer:
https://lore.kernel.org/qemu-devel/xlk2pspyo4gwguxopm6k534nzjei5y3m6zbh2l6dagmuwpamtk@dtkgca6yppce/
Thanks,
Stefano
Quoted 19 lines
Kevin
hw/net/vhost_net.c +4
-0@@ -543,6 +543,10 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) nc->vring_enable = enable; +if (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +return 0 ; + } +if (vhost_ops && vhost_ops->vhost_set_vring_enable) {return vhost_ops->vhost_set_vring_enable (&net->dev, enable); }
Quoted 46 lines · Stefano Garzarella
Quoted 44 lines · Jason Wang
Quoted 10 lines · Stefano Garzarella
Quoted 8 lines · Jason Wang
Quoted 6 lines · Stefano Garzarella
Quoted 4 lines · Kevin Wolf
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.Quoted 6 lines
Quoted 1 line
Did this mean virtio-blk will enable a virtqueue after
DRIVER_OK?It's not specific to virtio-blk, but to the generic vdpa device we have in QEMU (i.e. vhost-vdpa-device). Yep, after commit
6c4825476a4351530bcac17abab72295b75ffe98, virtqueues are enabled afterDRIVER_OK.Right.
Quoted 7 lines
Quoted 3 lines
Sepc is not clear about this and that's why we introduce
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK.Ah, I didn't know about this new feature. So after commit
6c4825476a4351530bcac17abab72295b75ffe98the vhost-vdpa-device is not complying with the specification, right?Kind of, but as stated, it's just because spec is unclear about the behaviour. There's a chance that spec will explicitly support it in the future.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Yeah, IMHO the VDUSE protocol is missing a
VDUSE_SET_VQ_READYmessage,I think you meant when
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis negotiated.At this point yes. But if
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKis not negotiated, should we return an error in vhost-vdpa kernel module ifVHOST_VDPA_SET_VRING_ENABLEis called whenDRIVER_OKis already set?
Quoted 5 lines
Quoted 2 lines
I'm not sure if this can break some setups or not. It might be better to leave it as is?
As I also answered in the kernel patch, IMHO we have to return an error, because any setups are broken anyway (see the problem we're fixing with
is > this patch),
For VDUSE probably yes, but not for other parents. It's easy to mandate on day 0 but might be hard for now.
For mlx5e, it supports the semantic VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK even before the feature bit is introduced.
And we don't do other checks like for example setting vq address, size after DRIVER_OK.
We can hear from others.
Quoted 38 lines
so at this point it's better to return an error, so they don't spend time figuring out why the VDUSE device doesn't work.
Quoted 3 lines
Without
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we don't know if parent supportvq_readyafterdriver_ok.So we have to assume that it doesn't support it, to be more conservative, right?
Quoted 10 lines
With
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK, we know parent supportvq_readyafterdriver_ok.Quoted 6 lines
Quoted 3 lines
If this is truth, it seems a little more complicated, for example the
get_backend_featuresneeds to be forward to the userspace?I'm not understanding, don't we already have
VHOST_GET_BACKEND_FEATURESfor this? Or do you mean userspace on the VDUSE side?Quoted 6 lines
Yes, since in this case the parent is in the userspace, there's no way for VDUSE to know if user space supports
vq_readyafterdriver_okor not.As you may have noticed, we don't have a message for
vq_readywhich implies thatvq_readyafterdriver_okcan't be supported.Yep, I see.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
This seems suboptimal to implement this in the spec first and then we can leverage the features. Or we can have another parameter for the ioctl that creates the vduse device.
I got a little lost, though in vhost-user, the device can always expect a vring_enable/disable, so I thought it was not complicated in VDUSE.
Quoted 7 lines
Quoted 4 lines
Yes, the problem is assuming we have a message for
vq_ready, there could be a "legacy" userspace that doesn't support that. So in that case, VDUSE needs to know if the userspace parent can support that or not.I think VDUSE needs to negotiate features (if it doesn't already) as vhost-user does with the backend. Also for new future functionality.
It negotiates virtio features but not vhost backend features.
Thanks
Quoted 109 lines · Kevin Wolf
Am 06.02.2024 um 17:44 hat Eugenio Perez Martin geschrieben:
Quoted 93 lines · Kevin Wolf
Quoted 92 lines
Am 05.02.2024 um 13:22 hat Eugenio Perez Martin geschrieben:
Quoted 76 lines · Kevin Wolf
Quoted 75 lines
VDUSE requires that virtqueues are first enabled before the
DRIVER_OKstatus flag is set; with the current API of the kernel module, it is impossible to enable the opposite order in our block export code because userspace is not notified when a virtqueue is enabled.This requirement also mathces the normal initialisation order as done by the generic vhost code in QEMU. However, commit
6c482547accidentally changed the order for vdpa-dev and broke access to VDUSE devices with this.This changes vdpa-dev to use the normal order again and use the standard vhost callback .vhost_set_vring_enable for this. VDUSE devices can be used with vdpa-dev again after this fix.
Fixes 6c4825476a4351530bcac17abab72295b75ffe98Signed-off-by Kevin Wolf <[email protected]>--- hw/virtio/vdpa-dev.c | 5 +---- hw/virtio/vhost-vdpa.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-)hw/virtio/vdpa-dev.c +1
-4@@ -253,14 +253,11 @@ static int vhost_vdpa_device_start(VirtIODevice *vdev, Error **errp) s->dev.acked_features = vdev->guest_features; - ret =vhost_dev_start (&s->dev, vdev, false); + ret =vhost_dev_start (&s->dev, vdev, true);if (ret <0 ) {error_setg_errno (errp, -ret,"Error starting vhost" ); goto err_guest_notifiers; } -for (i =0 ; i < s->dev.nvqs; ++i) { -vhost_vdpa_set_vring_ready (&s->vdpa, i); - } s->started = true;/* hw/virtio/vhost-vdpa.c +17
-0@@ -904,6 +904,22 @@ int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx)return r; } +static int vhost_vdpa_set_vring_enable (struct vhost_dev *dev,int enable) +{ +struct vhost_vdpa *v = dev->opaque; +unsigned int i; +int ret; + +for (i =0 ; i < dev->nvqs; ++i) { + ret =vhost_vdpa_set_vring_ready (v, i); +if (ret <0 ) { +return ret; + } + } + +return 0 ; +} +static int vhost_vdpa_set_config_call (struct vhost_dev *dev,int fd) {@@ -1524,6 +1540,7 @@ const VhostOps vdpa_ops = { .vhost_set_features = vhost_vdpa_set_features, .vhost_reset_device = vhost_vdpa_reset_device, .vhost_get_vq_index = vhost_vdpa_get_vq_index, + .vhost_set_vring_enable = vhost_vdpa_set_vring_enable,Quoted 8 lines
hw/virtio/vhost-vdpa.c const VhostOps vdpa_ops = { · line 1546
Quoted 3 lines
hw/virtio/vhost-vdpa.c +0
-0.vhost_get_config = vhost_vdpa_get_config, .vhost_set_config = vhost_vdpa_set_config, .vhost_requires_shm_log = NULL,vhost-vdpa net enables CVQ before dataplane ones to configure all the device in the destination of a live migration. To go back again to this callback would cause the device to enable the dataplane before virtqueues are configured again.
Not that it makes a difference, but I don't think it would actually be going back. Even before your commit
6c482547, we were not making use of the generic callback but just called the function in a slightly different place (but less different than after commit6c482547).Quoted 5 lines
Quoted 2 lines
But anyway... Why don't the other vhost backend need the same for vhost-net then? Do they just not support live migration?
They don't support control virtqueue. More specifically, control virtqueue is handled directly in QEMU.
So the network device already has to special case vdpa instead of using the same code for all vhost backends? :-/
Quoted 5 lines
Quoted 4 lines
I don't know the code well enough to say where the problem is, but if vhost-vdpa networking code relies on the usual vhost operations not being implemented and bypasses VhostOps to replace it, that sounds like a design problem to me.
Quoted 6 lines
Quoted 1 line
I don't follow this. What vhost operation is expected not to be implemented?
You were concerned about implementing .vhost_set_vring_enable in
vdpa_opslike my patch does. So it seems that the networking code requires that it is not implemented?
Kind of. vdpa_net requires that the enable calls on the dataplane vrings are done after DRIVER_OK. So as you say in your mail, we're good with vhost_dev_start, and changes may be focused to vhost_net.c
Vhost vdpa enable / disable semantics is just different from vhost-user, the one that originally implemented .vhost_set_vring_enable. That is the reason why the vhost vDPA enable was called at vhost_vdpa_dev_start originally.
Vhost-user also calls that function to enable and disable queues. And the vhost kernel does not even implement the vhost_op, but relies on vhost_net_set_backend (not sure about other kinds of devices).
This patch is moving toward making them equal, which is not correct. But maybe it is ok to do that tiny step in that direction to fix generic vhost-vdpa generic dev and fix that later.
Just for completion, I tried to implement it using the vhost_op but it was rejected already [1]. It was before Stefano's patch for selectively disable vrings enable.
Quoted 40 lines
On the other hand, for vhost-vdpa, the callback seems to be called in exactly the right place where virtqueues need to be enabled, like for other vhost devices.
Quoted 15 lines
Quoted 7 lines
Maybe VhostOps needs a new operation to enable
just a single virtqueue that can be used by the networking code instead?Quoted 3 lines
How does VDUSE userspace knows how many queues should enable? Can't the kernel perform the necessary actions after
DRIVER_OK, like configuring the kick etc?Quoted 7 lines
Not sure if I understand the question. The vdpa kernel interface always enables individual queues, so the VDUSE userspace will enable whatever queues it was asked to enable. The only restriction is that the queues need to be enabled before setting
DRIVER_OK.The interface that enables all virtqueues at once seems to be just .vhost_set_vring_enable in QEMU.
Quoted 6 lines
It enables all virtqueues of the same vhost device in QEMU, but QEMU creates one
vhost_devper each vhost-net virtqueue pair and another one for CVQ. This goes back to the time where mq vhost-kernel net devices were implemented by mergin many tap devices.net/vhost-vdpa.conly enables the last one, which corresponds to CVQ, and then enables the rest once all messages have been received.So it's less about the granularity of .vhost_set_vring_enable, which would just be right, but about the order in which it is called for the different
vhost_devs?Can we influence the order in another way than just not implementing the callback at all? I think net specific weirdness should be contained in the net implementation and not affect generic vdpa code.
Quoted 5 lines
On the other hand, .vhost_set_vring_enable is also used for queue reset (
vhost_net_virtqueue_resetandvhost_net_virtqueue_restart). In other words, it is called after the setDRIVER_OK. I guess it is fine for VDUSE as long as it does not offer vring reset capabilities, but future wise should we start going in that direction?
Quoted 6 lines
I don't actually know VDUSE very well, but that would probably make sense.
Though for the moment, I just tried to simply attach a VDUSE device and failed, so I'm just trying to fix the regression from your commit.
Understandable.
Quoted 8 lines
Quoted 5 lines
But kernels without
VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OKshould be supported, right. Maybe we can addvhost_vdpa_set_vring_enableand callvhost_dev_startwith vrings parameters conditional to the feature flag? That way the caller can enable it later or just enable all the rings altogether.Which specific caller do you mean here?
Quoted 9 lines
For vdpa-dev, I don't see any problem with just passing vrings=true unconditionally. That is clearly the least problematic order even if another order may in theory be allowed by the spec.
For
vhost_net, I don't know. As far as I am concerned, there is no reason to change its call and it could continue to pass vrings=false.So
vhost_dev_start()seems entirely unproblematic.
Yes I think the same.
Quoted 10 lines
The only part that changes for net is that
vhost_set_vring_enable()now does something where it didn't do anything before. If that is a problem for vdpa based network code, maybe we can just special case vdpa there to not callvhost_ops->vhost_set_vring_enable? (Despite its name, it's a network specific function; it should probably be called something likevhost_net_set_vring_enable.)With something like the below, net shouldn't see any difference any more, right? (Happy to add a comment before it if you write it for me.)
Early return should work but I'm not sure if that is the most sustainable way. We should remove peer->type conditionals as much as possible :).
To split vhost_ops would be better, yes. But these should be split between the virtio vring enable vs vhost vring enable. The first one does not accept a boolean, as it is only one direction. But this option requires more changes, so I'm happy with the early return for now. Not sure about Jason or MST.
As a draft for the comment:
Net vhost-vdpa devices need to dataplane virtqueues after DRIVER_OK, so it can recover device state before starting dataplane. Because of that, not enabling virtqueues here and leaving it to net/vhost-vdpa.c.
---
And maybe we can add another comment at vhost_dev_start doc? Something in the line of:
* vring = yes means vhost_dev_start will start all vrings. vring = false delegates vring initialization to the caller.
Does that make sense to you?
Thanks!
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 18 lines
Kevin
hw/net/vhost_net.c +4
-0@@ -543,6 +543,10 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) nc->vring_enable = enable; +if (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +return 0 ; + } +if (vhost_ops && vhost_ops->vhost_set_vring_enable) {return vhost_ops->vhost_set_vring_enable (&net->dev, enable); }