2023-11-21 07:32:19

by Cindy Lu

[permalink] [raw]
Subject: [PATCH v2 4/5] vduse: update the vq_info in ioctl

In VDUSE_VQ_GET_INFO, the driver will sync the last_avail_idx
with reconnect info, After mapping the reconnect pages to userspace
The userspace App will update the reconnect_time in
struct vhost_reconnect_vring, If this is not 0 then it means this
vq is reconnected and will update the last_avail_idx

Signed-off-by: Cindy Lu <[email protected]>
---
drivers/vdpa/vdpa_user/vduse_dev.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index d0fe9a7e86ab..6bc5fc2b88cc 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -1209,6 +1209,9 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
struct vduse_vq_info vq_info;
struct vduse_virtqueue *vq;
u32 index;
+ struct vdpa_reconnect_info *area;
+ struct vhost_reconnect_vring *vq_reconnect;
+ struct vhost_reconnect_data *dev_reconnect;

ret = -EFAULT;
if (copy_from_user(&vq_info, argp, sizeof(vq_info)))
@@ -1225,6 +1228,12 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
vq_info.device_addr = vq->device_addr;
vq_info.num = vq->num;

+ area = &dev->reconnect_info;
+ dev_reconnect = (struct vhost_reconnect_data *)area->vaddr;
+
+ area = &vq->reconnect_info;
+ vq_reconnect = (struct vhost_reconnect_vring *)area->vaddr;
+
if (dev->driver_features & BIT_ULL(VIRTIO_F_RING_PACKED)) {
vq_info.packed.last_avail_counter =
vq->state.packed.last_avail_counter;
@@ -1234,9 +1243,22 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
vq->state.packed.last_used_counter;
vq_info.packed.last_used_idx =
vq->state.packed.last_used_idx;
- } else
+ /*check if the vq is reconnect, if yes then update the last_avail_idx*/
+ if (dev_reconnect->reconnected != 0) {
+ vq_info.packed.last_avail_idx =
+ vq_reconnect->last_avail_idx;
+ vq_info.packed.last_avail_counter =
+ vq_reconnect->avail_wrap_counter;
+ }
+ } else {
vq_info.split.avail_index =
vq->state.split.avail_index;
+ /*check if the vq is reconnect, if yes then update the last_avail_idx*/
+ if (dev_reconnect->reconnected != 0) {
+ vq_info.split.avail_index =
+ vq_reconnect->last_avail_idx;
+ }
+ }

vq_info.ready = vq->ready;

--
2.34.3


2023-11-22 07:13:24

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] vduse: update the vq_info in ioctl

On Tue, Nov 21, 2023 at 3:31 PM Cindy Lu <[email protected]> wrote:
>
> In VDUSE_VQ_GET_INFO, the driver will sync the last_avail_idx

For driver, did you mean virtio driver?

> with reconnect info, After mapping the reconnect pages to userspace
> The userspace App will update the reconnect_time in
> struct vhost_reconnect_vring, If this is not 0 then it means this
> vq is reconnected and will update the last_avail_idx

I have a hard time understanding the above.

Thanks

2023-11-25 07:44:48

by Cindy Lu

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] vduse: update the vq_info in ioctl

On Wed, Nov 22, 2023 at 3:12 PM Jason Wang <[email protected]> wrote:
>
> On Tue, Nov 21, 2023 at 3:31 PM Cindy Lu <[email protected]> wrote:
> >
> > In VDUSE_VQ_GET_INFO, the driver will sync the last_avail_idx
>
> For driver, did you mean virtio driver?
>
> > with reconnect info, After mapping the reconnect pages to userspace
> > The userspace App will update the reconnect_time in
> > struct vhost_reconnect_vring, If this is not 0 then it means this
> > vq is reconnected and will update the last_avail_idx
>
> I have a hard time understanding the above.
>
sure, I will re-write this part
thanks
cindy
> Thanks
>