[v2,4/5] vduse: update the vq_info in ioctl

Message ID 20231121073050.287080-5-lulu@redhat.com
State New
Headers
Series vduse: Add support for reconnection |

Commit Message

Cindy Lu Nov. 21, 2023, 7:30 a.m. UTC
  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 <lulu@redhat.com>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
  

Comments

Jason Wang Nov. 22, 2023, 7:12 a.m. UTC | #1
On Tue, Nov 21, 2023 at 3:31 PM Cindy Lu <lulu@redhat.com> 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
  
Cindy Lu Nov. 25, 2023, 7:43 a.m. UTC | #2
On Wed, Nov 22, 2023 at 3:12 PM Jason Wang <jasowang@redhat.com> wrote:
>
> On Tue, Nov 21, 2023 at 3:31 PM Cindy Lu <lulu@redhat.com> 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
>
  

Patch

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;