From nobody Wed Dec 17 23:02:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9A37C54FB9 for ; Tue, 21 Nov 2023 07:31:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbjKUHbM (ORCPT ); Tue, 21 Nov 2023 02:31:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjKUHbJ (ORCPT ); Tue, 21 Nov 2023 02:31:09 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B798DF5 for ; Mon, 20 Nov 2023 23:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700551865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3tApwkEnppPf1Qrj7Li8zNPuhfxV/BinwmEu4nnIOfk=; b=fMudZnVcy5CeCrEl5iInr12m0K9RP667vn0SZEdAvkbQD56XKwXDJuLs/QK/aubWR1K/g9 VCF7DF/FlP9A3aUnpYH6E6dc7NEMNPW96R4IfC/BKGpJGHcomSkRTOvF8PRl7r0Uf3i9ku xLLnSNR34ikJ55opHGSY1qc5giqcejs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-feDxu8XYPN2sBP8rRuve5g-1; Tue, 21 Nov 2023 02:31:00 -0500 X-MC-Unique: feDxu8XYPN2sBP8rRuve5g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1CA385AFC0; Tue, 21 Nov 2023 07:30:59 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3238920268CF; Tue, 21 Nov 2023 07:30:56 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, xieyongji@bytedance.com, linux-kernel@vger.kernel.org, maxime.coquelin@redhat.com Subject: [PATCH v2 1/5] vduse: Add function to get/free the pages for reconnection Date: Tue, 21 Nov 2023 15:30:46 +0800 Message-Id: <20231121073050.287080-2-lulu@redhat.com> In-Reply-To: <20231121073050.287080-1-lulu@redhat.com> References: <20231121073050.287080-1-lulu@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the function vduse_alloc_reconnnect_info_mem and vduse_alloc_reconnnect_info_mem In this 2 function, vduse will get/free (vq_num + 1)*page =C2=A0 Page 0 will be used=C2=A0to save the reconnection information, The Userspace App will maintain this. Page 1 ~ vq_num + 1 will save the reconnection information for vqs. Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_user/vduse_dev.c | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 26b7e29cb900..6209e2f00278 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -41,6 +41,16 @@ #define VDUSE_IOVA_SIZE (128 * 1024 * 1024) #define VDUSE_MSG_DEFAULT_TIMEOUT 30 =20 +/* struct vdpa_reconnect_info saved the alloc pages info + * these pages will mmaped to userspace for reconnection + */ +struct vdpa_reconnect_info { + /* Offset (within vm_file) in PAGE_SIZE */ + u32 index; + /* virtual address for this page*/ + unsigned long vaddr; +}; + struct vduse_virtqueue { u16 index; u16 num_max; @@ -57,6 +67,7 @@ struct vduse_virtqueue { struct vdpa_callback cb; struct work_struct inject; struct work_struct kick; + struct vdpa_reconnect_info reconnect_info; }; =20 struct vduse_dev; @@ -106,6 +117,7 @@ struct vduse_dev { u32 vq_align; struct vduse_umem *umem; struct mutex mem_lock; + struct vdpa_reconnect_info reconnect_info; }; =20 struct vduse_dev_msg { @@ -1030,6 +1042,64 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, return ret; } =20 +static int vduse_alloc_reconnnect_info_mem(struct vduse_dev *dev) +{ + struct vdpa_reconnect_info *info; + struct vduse_virtqueue *vq; + + for (int i =3D 0; i < dev->vq_num + 1; i++) { + if (i =3D=3D 0) { + /*page 0 is use to save status,Userland APP will use this to + *save the information needed in reconnection, + *kernel don't need to maintain this + */ + info =3D &dev->reconnect_info; + info->vaddr =3D get_zeroed_page(GFP_KERNEL); + if (info->vaddr =3D=3D 0) + return -ENOMEM; + /* index is vm Offset in PAGE_SIZE */ + info->index =3D 0; + } + + /*page 1~ vq_num + 1 save the reconnect info for vq*/ + vq =3D &dev->vqs[i]; + info =3D &vq->reconnect_info; + info->vaddr =3D get_zeroed_page(GFP_KERNEL); + if (info->vaddr =3D=3D 0) + return -ENOMEM; + + info->index =3D i + 1; + } + + return 0; +} + +static int vduse_free_reconnnect_info_mem(struct vduse_dev *dev) +{ + struct vdpa_reconnect_info *info; + struct vduse_virtqueue *vq; + + for (int i =3D 0; i < dev->vq_num + 1; i++) { + if (i =3D=3D 0) { + info =3D &dev->reconnect_info; + if (info->vaddr) + free_page(info->vaddr); + info->index =3D 0; + info->vaddr =3D 0; + } + + vq =3D &dev->vqs[i]; + info =3D &vq->reconnect_info; + + if (info->vaddr) + free_page(info->vaddr); + info->vaddr =3D 0; + info->index =3D 0; + } + + return 0; +} + static long vduse_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -1390,6 +1460,8 @@ static int vduse_destroy_dev(char *name) mutex_unlock(&dev->lock); return -EBUSY; } + vduse_free_reconnnect_info_mem(dev); + dev->connected =3D true; mutex_unlock(&dev->lock); =20 @@ -1542,9 +1614,17 @@ static int vduse_create_dev(struct vduse_dev_config = *config, ret =3D PTR_ERR(dev->dev); goto err_dev; } + + ret =3D vduse_alloc_reconnnect_info_mem(dev); + if (ret < 0) + goto err_mem; + __module_get(THIS_MODULE); =20 return 0; + +err_mem: + vduse_free_reconnnect_info_mem(dev); err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: --=20 2.34.3 From nobody Wed Dec 17 23:02:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB95AC5ACB3 for ; Tue, 21 Nov 2023 07:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjKUHbQ (ORCPT ); Tue, 21 Nov 2023 02:31:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbjKUHbL (ORCPT ); Tue, 21 Nov 2023 02:31:11 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C5A4F5 for ; Mon, 20 Nov 2023 23:31:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700551865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zVxsZpHEP/sfaMQQhdclVFIY4BoolokQBaiLl5ZMHTY=; b=J0JNd9s3dkuzwcsgucZm3mF+bmX+1nvXczrA8yREFZdnUqlZmZSHNm51yGn4A2V9+9lShL WRuy7/fKngCi4+kk4mKi05+FVJTd5DLxZHO+sHaUTzB4Gv4fejyWSONa2x1Ssofhi+Jk6R 1WqepIeeGuCJ1lWZTvYa1BocMEQHKfM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-191-6p5Rl5WSMAOaFohM4XU9kQ-1; Tue, 21 Nov 2023 02:31:03 -0500 X-MC-Unique: 6p5Rl5WSMAOaFohM4XU9kQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4AC788007B3; Tue, 21 Nov 2023 07:31:03 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E6AA20268CF; Tue, 21 Nov 2023 07:31:00 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, xieyongji@bytedance.com, linux-kernel@vger.kernel.org, maxime.coquelin@redhat.com Subject: [PATCH v2 2/5] vduse: Add file operation for mmap Date: Tue, 21 Nov 2023 15:30:47 +0800 Message-Id: <20231121073050.287080-3-lulu@redhat.com> In-Reply-To: <20231121073050.287080-1-lulu@redhat.com> References: <20231121073050.287080-1-lulu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add the operation for mmap, The user space APP will use this function to map the pages to userspace Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_user/vduse_dev.c | 79 ++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 6209e2f00278..ccb30e98bab5 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1376,6 +1376,83 @@ static struct vduse_dev *vduse_dev_get_from_minor(in= t minor) return dev; } =20 +static vm_fault_t vduse_vm_fault(struct vm_fault *vmf) +{ + struct vduse_dev *dev =3D vmf->vma->vm_file->private_data; + struct vm_area_struct *vma =3D vmf->vma; + u16 index =3D vma->vm_pgoff; + struct vduse_virtqueue *vq; + struct vdpa_reconnect_info *info; + + /* index 0 page reserved for vduse status*/ + if (index =3D=3D 0) { + info =3D &dev->reconnect_info; + } else { + /* index 1+vq_number page reserved for vduse vqs*/ + vq =3D &dev->vqs[index - 1]; + info =3D &vq->reconnect_info; + } + if (remap_pfn_range(vma, vmf->address & PAGE_MASK, + PFN_DOWN(virt_to_phys((void *)info->vaddr)), + PAGE_SIZE, vma->vm_page_prot)) + return VM_FAULT_SIGBUS; + return VM_FAULT_NOPAGE; +} + +static const struct vm_operations_struct vduse_vm_ops =3D { + .fault =3D vduse_vm_fault, +}; + +static int vduse_dev_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct vduse_dev *dev =3D file->private_data; + struct vdpa_reconnect_info *info; + unsigned long index =3D vma->vm_pgoff; + struct vduse_virtqueue *vq; + + if (vma->vm_end - vma->vm_start !=3D PAGE_SIZE) + return -EINVAL; + if ((vma->vm_flags & VM_SHARED) =3D=3D 0) + return -EINVAL; + + /*check if Userspace App map the page number larger than kernel allocated= */ + if (index > dev->vq_num + 1) + return -EINVAL; + + /* index 0 page reserved for vduse status*/ + if (index =3D=3D 0) { + info =3D &dev->reconnect_info; + } else { + /* index 1+vq_number page reserved for vduse vqs*/ + vq =3D &dev->vqs[index - 1]; + info =3D &vq->reconnect_info; + } + /*check if map pages was allocated and inited by kernel */ + if (info->vaddr =3D=3D 0) + return -EOPNOTSUPP; + + /* check if the address is page aligned, if not, + * this address maybe damaged + */ + if (virt_to_phys((void *)info->vaddr) & (PAGE_SIZE - 1)) + return -EINVAL; + + /* check if Userspace App mapped the correct size + * the userspace App should map one page each time + */ + if (vma->vm_end - vma->vm_start !=3D PAGE_SIZE) + return -EOPNOTSUPP; + /* VM_IO: set as a memory-mapped I/O region,This will for vq information + * VM_PFNMAP: only need the pure PFN + * VM_DONTEXPAND: do not need to use mremap() in this function + * VM_DONTDUMP:Do not include in the core dump + */ + vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); + vma->vm_ops =3D &vduse_vm_ops; + + return 0; +} + static int vduse_dev_open(struct inode *inode, struct file *file) { int ret; @@ -1408,6 +1485,8 @@ static const struct file_operations vduse_dev_fops = =3D { .unlocked_ioctl =3D vduse_dev_ioctl, .compat_ioctl =3D compat_ptr_ioctl, .llseek =3D noop_llseek, + .mmap =3D vduse_dev_mmap, + }; =20 static struct vduse_dev *vduse_dev_create(void) --=20 2.34.3 From nobody Wed Dec 17 23:02:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F277DC5ACB3 for ; Tue, 21 Nov 2023 07:31:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbjKUHbV (ORCPT ); Tue, 21 Nov 2023 02:31:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbjKUHbO (ORCPT ); Tue, 21 Nov 2023 02:31:14 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA085C8 for ; Mon, 20 Nov 2023 23:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700551869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0iZa9dT80BCE+foVlf/TZ2RRVWFHn8gNFqGFDP3tw+0=; b=gt3drWoRcXu8WPxeKfUFdVs+nD4H3ojB0l0mA5vva9/fDeL6RoN72+9nFVuCY6J3v39zkg M6k0Wc1EtjtIWZeEfh0mC9NzChWz3WCLwC8a7Pzi3GxoDtJlHWLod0I+nkH2SDBQ5/iER9 uHbEYAkZYUXmzXfQ8O6CqGsOw3oMYDM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-kPUB6VRzNNmmbs2KrBeXsg-1; Tue, 21 Nov 2023 02:31:06 -0500 X-MC-Unique: kPUB6VRzNNmmbs2KrBeXsg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A74B11C0896D; Tue, 21 Nov 2023 07:31:06 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB04E20268CF; Tue, 21 Nov 2023 07:31:03 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, xieyongji@bytedance.com, linux-kernel@vger.kernel.org, maxime.coquelin@redhat.com Subject: [PATCH v2 3/5] vduse: Add new ioctl VDUSE_GET_RECONNECT_INFO Date: Tue, 21 Nov 2023 15:30:48 +0800 Message-Id: <20231121073050.287080-4-lulu@redhat.com> In-Reply-To: <20231121073050.287080-1-lulu@redhat.com> References: <20231121073050.287080-1-lulu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In VDUSE_GET_RECONNECT_INFO, the Userspace App can get the map size and The number of mapping memory pages from the kernel. The userspace App can use this information to map the pages. Add struct vhost_reconnect_data/vhost_reconnect_vring for sync the information in reconnection Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_user/vduse_dev.c | 15 +++++++++ include/uapi/linux/vduse.h | 50 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index ccb30e98bab5..d0fe9a7e86ab 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1343,6 +1343,21 @@ static long vduse_dev_ioctl(struct file *file, unsig= ned int cmd, ret =3D 0; break; } + case VDUSE_GET_RECONNECT_INFO: { + struct vduse_reconnect_mmap_info info; + + ret =3D -EFAULT; + if (copy_from_user(&info, argp, sizeof(info))) + break; + + info.size =3D PAGE_SIZE; + info.max_index =3D dev->vq_num + 1; + + if (copy_to_user(argp, &info, sizeof(info))) + break; + ret =3D 0; + break; + } default: ret =3D -ENOIOCTLCMD; break; diff --git a/include/uapi/linux/vduse.h b/include/uapi/linux/vduse.h index 11bd48c72c6c..c0b7133aebfd 100644 --- a/include/uapi/linux/vduse.h +++ b/include/uapi/linux/vduse.h @@ -3,6 +3,7 @@ #define _UAPI_VDUSE_H_ =20 #include +#include =20 #define VDUSE_BASE 0x81 =20 @@ -350,4 +351,53 @@ struct vduse_dev_response { }; }; =20 +/** + * struct vhost_reconnect_data - saved the reconnect info for device + * @version; version for userspace APP + * @reconnected: indetify if this is reconnected. userspace APP needs set = this bit to 1 + * while reconnecting.kernel will use this bit to indetify i= f this is + * reconnect + * @features; Device features negotiated in the last connect. + * @status; Device status in last reconnect + * @nr_vrings; number of active vqs in last connect + * @struct virtio_net_config config; the config in last connect + */ + +struct vhost_reconnect_data { + __u32 version; + __u32 reconnected; + __u64 features; + __u8 status; + __u32 nr_vrings; + struct virtio_net_config config; +}; + +/** + * struct vhost_reconnect_vring -saved the reconnect info for vqs + * when use split mode will only use last_avail_idx + * when use packed mode will use both last_avail_idx and avail_wrap_counter + * userspace App + * @last_avail_idx: device last available index + * @avail_wrap_counter: Driver ring wrap counter + */ +struct vhost_reconnect_vring { + __u16 last_avail_idx; + __u16 avail_wrap_counter; +}; + +/** + * struct vduse_reconnect_mmap_info + * @size: mapping memory size, here we use page_size + * @max_index: the number of pages allocated in kernel,just + * use for sanity check + */ + +struct vduse_reconnect_mmap_info { + __u32 size; + __u32 max_index; +}; + +#define VDUSE_GET_RECONNECT_INFO \ + _IOWR(VDUSE_BASE, 0x1b, struct vduse_reconnect_mmap_info) + #endif /* _UAPI_VDUSE_H_ */ --=20 2.34.3 From nobody Wed Dec 17 23:02:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 929F4C54FB9 for ; Tue, 21 Nov 2023 07:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230073AbjKUHbp (ORCPT ); Tue, 21 Nov 2023 02:31:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231390AbjKUHbh (ORCPT ); Tue, 21 Nov 2023 02:31:37 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96D9919A for ; Mon, 20 Nov 2023 23:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700551893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OAkVxc3aGCIVy+mum1Tmv8tqRWzijzVSekSFIcVpdTI=; b=A0kMw3TIhs2EbU962e+26T7JKuBRfCzifPBOFlsOEzmydSStpHeyuICM3WnPwWI5mjeGC+ /NSCpogwkqVX10M3U52GfNVpOqshuiQ4vokJJsXDen60k3Q8H+2AiP88jmH1NhDQbpAGvj nc48Mtw/Go18XrupVKr4QXfqCbiFXxU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-CVgMNopqMVOpQb5uC-0KgA-1; Tue, 21 Nov 2023 02:31:32 -0500 X-MC-Unique: CVgMNopqMVOpQb5uC-0KgA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5126857F7A; Tue, 21 Nov 2023 07:31:31 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0087D1C060B0; Tue, 21 Nov 2023 07:31:28 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, xieyongji@bytedance.com, linux-kernel@vger.kernel.org, maxime.coquelin@redhat.com Subject: [PATCH v2 4/5] vduse: update the vq_info in ioctl Date: Tue, 21 Nov 2023 15:30:49 +0800 Message-Id: <20231121073050.287080-5-lulu@redhat.com> In-Reply-To: <20231121073050.287080-1-lulu@redhat.com> References: <20231121073050.287080-1-lulu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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/vd= use_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, unsign= ed 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; =20 ret =3D -EFAULT; if (copy_from_user(&vq_info, argp, sizeof(vq_info))) @@ -1225,6 +1228,12 @@ static long vduse_dev_ioctl(struct file *file, unsig= ned int cmd, vq_info.device_addr =3D vq->device_addr; vq_info.num =3D vq->num; =20 + area =3D &dev->reconnect_info; + dev_reconnect =3D (struct vhost_reconnect_data *)area->vaddr; + + area =3D &vq->reconnect_info; + vq_reconnect =3D (struct vhost_reconnect_vring *)area->vaddr; + if (dev->driver_features & BIT_ULL(VIRTIO_F_RING_PACKED)) { vq_info.packed.last_avail_counter =3D vq->state.packed.last_avail_counter; @@ -1234,9 +1243,22 @@ static long vduse_dev_ioctl(struct file *file, unsig= ned int cmd, vq->state.packed.last_used_counter; vq_info.packed.last_used_idx =3D 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 !=3D 0) { + vq_info.packed.last_avail_idx =3D + vq_reconnect->last_avail_idx; + vq_info.packed.last_avail_counter =3D + vq_reconnect->avail_wrap_counter; + } + } else { vq_info.split.avail_index =3D vq->state.split.avail_index; + /*check if the vq is reconnect, if yes then update the last_avail_idx*/ + if (dev_reconnect->reconnected !=3D 0) { + vq_info.split.avail_index =3D + vq_reconnect->last_avail_idx; + } + } =20 vq_info.ready =3D vq->ready; =20 --=20 2.34.3 From nobody Wed Dec 17 23:02:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A31D5C5ACB3 for ; Tue, 21 Nov 2023 07:31:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230193AbjKUHbv (ORCPT ); Tue, 21 Nov 2023 02:31:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbjKUHbn (ORCPT ); Tue, 21 Nov 2023 02:31:43 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FDBF10E for ; Mon, 20 Nov 2023 23:31:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700551899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=77Bzl/+Kq0+MzNg2uBfJvKrlDQ1jm6M8H9m1x9Ji14Q=; b=G9bNE1EPKLxDZi+B3kkNegL2Jeft7dD1SS7TQiSudQ9jlOXgv29gDnJg2zAb/WFJk4xrhI gSuoq5Uv6Bi4GdiByrtPeHSaPoxwVbN05nFrCSQm7zaXXmhVBrzYCzsLYtAb2iKVnCJi2R egN9LBEvpVy/tfYMNsBUyEY0GfVaYLA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-ETEATdwXPl-IT_04BPdwNQ-1; Tue, 21 Nov 2023 02:31:35 -0500 X-MC-Unique: ETEATdwXPl-IT_04BPdwNQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F6543804A4D; Tue, 21 Nov 2023 07:31:35 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60E281C060B0; Tue, 21 Nov 2023 07:31:32 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, xieyongji@bytedance.com, linux-kernel@vger.kernel.org, maxime.coquelin@redhat.com Subject: [PATCH v2 5/5] Documentation: Add reconnect process for VDUSE Date: Tue, 21 Nov 2023 15:30:50 +0800 Message-Id: <20231121073050.287080-6-lulu@redhat.com> In-Reply-To: <20231121073050.287080-1-lulu@redhat.com> References: <20231121073050.287080-1-lulu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add the document to explained how the reconnect process include how the Userspace App need to do and how it works with kernel Signed-off-by: Cindy Lu --- Documentation/userspace-api/vduse.rst | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Documentation/userspace-api/vduse.rst b/Documentation/userspac= e-api/vduse.rst index bdb880e01132..6e01c21d94df 100644 --- a/Documentation/userspace-api/vduse.rst +++ b/Documentation/userspace-api/vduse.rst @@ -231,3 +231,32 @@ able to start the dataplane processing as follows: after the used ring is filled. =20 For more details on the uAPI, please see include/uapi/linux/vduse.h. + +HOW VDUSE devices reconnectoin works +---------------- +0. Userspace APP checks if the device /dev/vduse/vduse_name exists, if not= create + the device. If yes means this is reconnect, goto 3 + +1. Create a new VDUSE instance with ioctl(VDUSE_CREATE_DEV) on + /dev/vduse/control. + +2. In ioctl(VDUSE_CREATE_DEV), the kernel alloc the memory to sync the rec= onnect + information. + +3. Userspace App will mmap the pages to userspace + + If this first time to connect, userspace App need save the reconnect + information (struct vhost_reconnect_data) in mapped pages + + If this is reconnect, userspace App need to check if the saved informat= ion + OK to reconnect, Also userspace App MUST set the bit reconnected in + struct vhost_reconnect_data to 1. (kernel will use this bit to identify= if the + userAPP is reconnected ) + +4. Successfully start the userspace App. + userspace APP need to call ioctl VDUSE_VQ_GET_INFO to sync the vq infor= mation. also + APP need to save the reconnect information (struct vhost_reconnect_vrin= g) + while running + +5. When the Userspace App exit, Userspace App need to unmap all the reconn= ect + pages --=20 2.34.3