From nobody Wed Dec 17 22:44:26 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4919F824BD for ; Fri, 12 Apr 2024 13:30:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928656; cv=none; b=HkClbN8CytGleNGXGgEYUeTo559FIsBHK/tyHcpElkFIRQAnC4tM7PS4l0WDHAGuuM0IrNaXdZvQT1fjTDMWc7sxlQcq+BoKP/j2JPG4jbqnoCwe/vOaIZoHh8+QAHXOnDLhWIbqyZpfURP9raTtiN3c2g4r1hUoIQou7hzeJRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928656; c=relaxed/simple; bh=/j71C6LLegHXOz3snuWsv0xGmVODLdDmNr+bmnXNKGQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J6kydjyQfDgO6fhAccV4N8nIXuN0vqb9jsbPDLRHcZIQoq7cTuHdpabHXA2/uMqsd3xFGaF4XwtyZwRi/2CVECFvwwbNNnkl9ZWNmRd90VwTvxNfWw5J13uEsc7CC+X06FzevP3lhy7PiqYUP4GFudzpWK+dpwimsQpFT28qkng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IlZS93Vw; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IlZS93Vw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712928654; 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=11vsPZmrTyORN2f8NF7cBdxobijSaF6IqQZ7CKve6yA=; b=IlZS93Vw1DFN+H58fNugXQ5/1FxeILVxPS1EtemQw3+C9uXE4kGvZRv2DD8dcGvWBMtfsQ 7byuNk68TpfSAz7coyYy7DwobFtssH5aCXQl9nJydZExyna1/UYuQQYQLGzfBhT1kbI9oK hu2xu5o3WWVZ2Mz72KT75xIwQEwo7Us= 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-616-uELeKrU3Mm-3mm9odQpx1g-1; Fri, 12 Apr 2024 09:30:51 -0400 X-MC-Unique: uELeKrU3Mm-3mm9odQpx1g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 984328032FA; Fri, 12 Apr 2024 13:30:51 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4364840C6CBF; Fri, 12 Apr 2024 13:30:48 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v5 1/5] vduse: Add new ioctl VDUSE_DEV_GET_CONFIG Date: Fri, 12 Apr 2024 21:28:21 +0800 Message-ID: <20240412133017.483407-2-lulu@redhat.com> In-Reply-To: <20240412133017.483407-1-lulu@redhat.com> References: <20240412133017.483407-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Content-Type: text/plain; charset="utf-8" The ioctl VDUSE_DEV_GET_CONFIG is used by the Userspace App to get the device configuration space. Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_user/vduse_dev.c | 21 +++++++++++++++++++++ include/uapi/linux/vduse.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 1c1d71d69026..ab246da27616 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1368,6 +1368,27 @@ static long vduse_dev_ioctl(struct file *file, unsig= ned int cmd, ret =3D 0; break; } + case VDUSE_DEV_GET_CONFIG: { + struct vduse_config_data config; + unsigned long size =3D offsetof(struct vduse_config_data, buffer); + + ret =3D -EFAULT; + if (copy_from_user(&config, argp, size)) + break; + + ret =3D -EINVAL; + if (config.offset > dev->config_size || config.length =3D=3D 0 || + config.length > dev->config_size - config.offset) + break; + + if (copy_to_user(argp + size, dev->config + config.offset, + config.length)) { + ret =3D -EFAULT; + 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..125d7529d91b 100644 --- a/include/uapi/linux/vduse.h +++ b/include/uapi/linux/vduse.h @@ -350,4 +350,7 @@ struct vduse_dev_response { }; }; =20 +/* get device configuration space */ +#define VDUSE_DEV_GET_CONFIG _IOR(VDUSE_BASE, 0x1b, struct vduse_config_da= ta) + #endif /* _UAPI_VDUSE_H_ */ --=20 2.43.0 From nobody Wed Dec 17 22:44:26 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 874908289C for ; Fri, 12 Apr 2024 13:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928659; cv=none; b=kvqq5sQQyKEc3m14UQSN3EXjDoAOgk+ZUiSyYy7O9YuKNpcWec8wH9UMF2Jszdg7IOelsJpu/P4EUijzvm9YlvnRxilwA+jy66j1VWtnOJlY7QdIFPW8pZPgPF4UIGTRZD5BjEp7Px0Kx8TqeQ8m568t1iAom7LXCM2CrceWfZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928659; c=relaxed/simple; bh=j1lCtWf8kQGK0h6m9q3I3l1BoBQdXKPTjFjyW0xeUpg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jMzd4outjcmK3OzY18mLBnCraNYhSP+D1Gymn5KtCmf0Aw2j/QEMP7qAmTJrb6lZUddZLia/CojfZO2NvGVU66wkDpIXMnaOOA6rc3qf1YbrnegdEUWkKD3qq/8hpJtxeD1nyjV6CfFL5p5TR/4X57lGpSzxG9d8Uc6p31DoQuI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gPe7vVNI; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gPe7vVNI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712928656; 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=hwsrIyNME3xvIfwfaV6NG7sB+rLE21QzcYEDoBZyr4Q=; b=gPe7vVNIJo9AYLS7OFEUldniAlaoNy7vH1kcc0lMDyDQ4pvyLe0FATz688zpcJPK/kqiU8 wYyIqOkvQ0mtUaWEpVBpb7hOFUO35Wq3uXcnYQF6E4UPQJsH+7rBziDYegk/lXp+YJYV7u n2NmNob++EAtor34npidsLS9RxdVrq4= 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-503-5sRcogbPOS20FuEZEaFDgQ-1; Fri, 12 Apr 2024 09:30:55 -0400 X-MC-Unique: 5sRcogbPOS20FuEZEaFDgQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 8D4AE28B7403; Fri, 12 Apr 2024 13:30:54 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37C1940C6CBF; Fri, 12 Apr 2024 13:30:51 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v5 2/5] vduse: Add new ioctl VDUSE_DEV_GET_STATUS Date: Fri, 12 Apr 2024 21:28:22 +0800 Message-ID: <20240412133017.483407-3-lulu@redhat.com> In-Reply-To: <20240412133017.483407-1-lulu@redhat.com> References: <20240412133017.483407-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Content-Type: text/plain; charset="utf-8" The ioctl VDUSE_DEV_GET_STATUS is used by the Userspace App to get the device status Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_user/vduse_dev.c | 7 +++++++ include/uapi/linux/vduse.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index ab246da27616..ef3c9681941e 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1389,6 +1389,13 @@ static long vduse_dev_ioctl(struct file *file, unsig= ned int cmd, ret =3D 0; break; } + + case VDUSE_DEV_GET_STATUS: + /* + * Returns the status read from device + */ + ret =3D put_user(dev->status, (u8 __user *)argp); + break; default: ret =3D -ENOIOCTLCMD; break; diff --git a/include/uapi/linux/vduse.h b/include/uapi/linux/vduse.h index 125d7529d91b..f501173a9d69 100644 --- a/include/uapi/linux/vduse.h +++ b/include/uapi/linux/vduse.h @@ -353,4 +353,6 @@ struct vduse_dev_response { /* get device configuration space */ #define VDUSE_DEV_GET_CONFIG _IOR(VDUSE_BASE, 0x1b, struct vduse_config_da= ta) =20 +#define VDUSE_DEV_GET_STATUS _IOR(VDUSE_BASE, 0x1c, __u8) + #endif /* _UAPI_VDUSE_H_ */ --=20 2.43.0 From nobody Wed Dec 17 22:44:26 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED76D824B6 for ; Fri, 12 Apr 2024 13:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928664; cv=none; b=U7akN+LjqwzD6Si6vvaurv1b8uXxw5E805ezlpc7RkAiWn1TmzabQ+tFISvDsafhKMmFOm2vsAVdKJnYBkcsK3hYYh0SZAxAiWfe4+HYs39lW5QkbfDBPnr0WwVIMXN7e4F1wdsEGE8g0VeSHPtFb6ZPrUpkwkrTH8P3Cov+UDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928664; c=relaxed/simple; bh=cBLjryLsVfu47+tjl5ywQAYVk9Q3xIPJ/WF63oos9zU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IFQEQeOjxFRM6lpMTsZk1f1GF9pJV/FmYJLiyJJGy9Bxfkom4iiEWXRhGHurbT7LZMokPioiZ3a+s1+hwY0hSMATC0Y1fUsQy4WiI0U0r5E2UcE1raiZg8ABgrCaSEPz1Mzs7fLvyzim1jMzNvK0cCDmYUHf4uoD7w81W6Yzhr0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Rbaj4AOf; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Rbaj4AOf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712928661; 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=x2Trg27lougTGtlprzjhUTV72eb8EddnblMr0yERIK0=; b=Rbaj4AOfzqhialJtSHzmNCTMwj7wOs+f5+6DdkZk+YOpk/E5nUniGtoJuN8TjZhaK1v76d B+JZ8C8o5fOyI0KX13esDqkTCcCj3oZ/7rO+HRiA+02edvswBCZkg18TKAzhEMNq9V9Dp5 UralVQyLznI6y0jf3k0pQcIwkENC91g= 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-258-uC2OtfNHNf6bhTxSIazRng-1; Fri, 12 Apr 2024 09:30:58 -0400 X-MC-Unique: uC2OtfNHNf6bhTxSIazRng-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 818188007AD; Fri, 12 Apr 2024 13:30:57 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CDDB40C6DAE; Fri, 12 Apr 2024 13:30:54 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v5 3/5] vduse: Add function to get/free the pages for reconnection Date: Fri, 12 Apr 2024 21:28:23 +0800 Message-ID: <20240412133017.483407-4-lulu@redhat.com> In-Reply-To: <20240412133017.483407-1-lulu@redhat.com> References: <20240412133017.483407-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Content-Type: text/plain; charset="utf-8" Add the function vduse_alloc_reconnnect_info_mem and vduse_alloc_reconnnect_info_mem These functions allow vduse to allocate and free memory for reconnection information. The amount of memory allocated is vq_num pages. Each VQS will map its own page where the reconnection information will be s= aved Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_user/vduse_dev.c | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index ef3c9681941e..2da659d5f4a8 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -65,6 +65,7 @@ struct vduse_virtqueue { int irq_effective_cpu; struct cpumask irq_affinity; struct kobject kobj; + unsigned long vdpa_reconnect_vaddr; }; =20 struct vduse_dev; @@ -1105,6 +1106,38 @@ static void vduse_vq_update_effective_cpu(struct vdu= se_virtqueue *vq) =20 vq->irq_effective_cpu =3D curr_cpu; } +static int vduse_alloc_reconnnect_info_mem(struct vduse_dev *dev) +{ + unsigned long vaddr =3D 0; + struct vduse_virtqueue *vq; + + for (int i =3D 0; i < dev->vq_num; i++) { + /*page 0~ vq_num save the reconnect info for vq*/ + vq =3D dev->vqs[i]; + vaddr =3D get_zeroed_page(GFP_KERNEL); + if (vaddr =3D=3D 0) + return -ENOMEM; + + vq->vdpa_reconnect_vaddr =3D vaddr; + } + + return 0; +} + +static int vduse_free_reconnnect_info_mem(struct vduse_dev *dev) +{ + struct vduse_virtqueue *vq; + + for (int i =3D 0; i < dev->vq_num; i++) { + vq =3D dev->vqs[i]; + + if (vq->vdpa_reconnect_vaddr) + free_page(vq->vdpa_reconnect_vaddr); + vq->vdpa_reconnect_vaddr =3D 0; + } + + return 0; +} =20 static long vduse_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) @@ -1672,6 +1705,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 @@ -1855,12 +1890,17 @@ static int vduse_create_dev(struct vduse_dev_config= *config, ret =3D vduse_dev_init_vqs(dev, config->vq_align, config->vq_num); if (ret) goto err_vqs; + ret =3D vduse_alloc_reconnnect_info_mem(dev); + if (ret < 0) + goto err_mem; =20 __module_get(THIS_MODULE); =20 return 0; err_vqs: device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); +err_mem: + vduse_free_reconnnect_info_mem(dev); err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: --=20 2.43.0 From nobody Wed Dec 17 22:44:26 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C822A824A9 for ; Fri, 12 Apr 2024 13:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928690; cv=none; b=NV3V1tqr8zNV/zBGCnE4wlCFQ7OyEe4JYYSJowgPngiJ1t19QKgKJIBoYSfisNv3Wwi6USl4pyOqX2aAU2vANhOX8KoOr78/SjmnmXS7ZcYNhSzzWiHFmF3AFumXnpWPc08SbyC8G9QKK+HsD2pEjna6qC5UK0LU1qBoJiRo3Us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928690; c=relaxed/simple; bh=bKN8UQ9NS8z8CGfSU2og9P/q9mfucOox+qnqy3HOHbs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IjqoMaSLl2vz4HxUQ1ZUnxej1EDgq9MKu6V5eK8CSD9TksB+HKWSDQlJwte9boVGqOqRDgW3I9mJ/8+ITg2QWCJP2Kt8ZevaxGCsF1AAa8Nud3Ew8S+/zUJTYG971c6d5vXjmbPnob3UI413tvzLLMLNjH0y5+ZfmGl2BmaigJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=g4LChcae; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g4LChcae" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712928687; 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=35sWc1yIwO6N5kVcpws/O6LKONaL5+Jtm0fcsW8kNnY=; b=g4LChcaeHUQmXlrds4ho8WCSxAu99al0QyKmxK1BKW+yE2QTgcEx+BW50GdSo2tr3NMpRU 55woQAxJMxYjJwQVXiC6U3wGLU1FGXdw6yLruHjiNBTw9X7yMkH2sbaXtxkTzjud0ErqF2 V3ZhItY4FmeqVI2SAg38OTsnRbsMDTg= 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-338-r1p6kOVmNpGuT-qX4K-ScA-1; Fri, 12 Apr 2024 09:31:26 -0400 X-MC-Unique: r1p6kOVmNpGuT-qX4K-ScA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 0643B80A1B9; Fri, 12 Apr 2024 13:31:26 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id A25CC10E4B; Fri, 12 Apr 2024 13:31:23 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v5 4/5] vduse: Add file operation for mmap Date: Fri, 12 Apr 2024 21:28:24 +0800 Message-ID: <20240412133017.483407-5-lulu@redhat.com> In-Reply-To: <20240412133017.483407-1-lulu@redhat.com> References: <20240412133017.483407-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Content-Type: text/plain; charset="utf-8" Add the operation for mmap, This function will be used by the user space application to map the pages to the user space. Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_user/vduse_dev.c | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 2da659d5f4a8..7abe0c17cf0e 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1465,6 +1465,61 @@ 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; + unsigned long vaddr; + + /* index 0~vq_number-1 page reserved for virtqueue state*/ + vq =3D dev->vqs[index]; + vaddr =3D vq->vdpa_reconnect_vaddr; + if (remap_pfn_range(vma, vmf->address & PAGE_MASK, + PFN_DOWN(virt_to_phys((void *)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; + unsigned long vaddr =3D 0; + 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; + if (index >=3D dev->vq_num) + return -EINVAL; + + index =3D array_index_nospec(index, dev->vq_num); + vq =3D dev->vqs[index]; + vaddr =3D vq->vdpa_reconnect_vaddr; + if (vaddr =3D=3D 0) + return -EOPNOTSUPP; + + if (virt_to_phys((void *)vaddr) & (PAGE_SIZE - 1)) + return -EINVAL; + + /* Check if the Userspace App mapped the correct size */ + if (vma->vm_end - vma->vm_start !=3D PAGE_SIZE) + return -EOPNOTSUPP; + + vm_flags_set(vma, VM_DONTEXPAND); + vma->vm_ops =3D &vduse_vm_ops; + + return 0; +} + static int vduse_dev_open(struct inode *inode, struct file *file) { int ret; @@ -1497,6 +1552,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 ssize_t irq_cb_affinity_show(struct vduse_virtqueue *vq, char *buf) --=20 2.43.0 From nobody Wed Dec 17 22:44:26 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BF8D8287D for ; Fri, 12 Apr 2024 13:31:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928692; cv=none; b=BVOWwCUGoZZFtUZ7zyUa6lt8ChvlOokKG8S/Q++wI2oiUN0OpvUzCr68J/Z41JF19bCu11xVy6dHUENn6RRkOcZLEHVntDjGe5NkGVX7OTmElI1aNp5m3xbHYbY+C+fbfTFj7qx3shGtkw/tpfyu1JrvmMoZ1xvDL12LiSv24/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712928692; c=relaxed/simple; bh=6bmbdoifZb2Jpy0PZiNXlrBy305qSk1zWYVTLBSmB0M=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a7TuahFj5piljeAuQST3lmtSpCC54ldyqcplq2XJWsztIjCrsgopPM3FIYyZPVenVVKgqHP/gpRydxN7BrCvsVK3HnPjYbEiX6KEdI9rXMWDS0nKeJxxyUU5xTuBhxTG83sEfuuz2G97WWPwhI/xYeWQRFAKnwP33Hcf0O6zA8Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PN+DHwX3; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PN+DHwX3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712928690; 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=Vba8fCSuLQZTKX30MTVAeYL8D2lP6F44uKwflbfLdSs=; b=PN+DHwX3v5/GBzSxmN/j6yA9XkwdoV9kDNrT4uxNYuA4+1RcmmWUck3rct1lTdPHXTxyea fOD9JnpfO9rEI5G+2WHgLpg6kU7w0bLuNY+t9EZ3tafXTOsVFGeAB60+U+C6VebPZGV6+u Q4dre0xaK/MeiO9t0MELhZ9X1b/HEx8= 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-286-W-X8IWsyOMeVoJYzPPGdhQ-1; Fri, 12 Apr 2024 09:31:29 -0400 X-MC-Unique: W-X8IWsyOMeVoJYzPPGdhQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 EEACA28C97D1; Fri, 12 Apr 2024 13:31:28 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9935310E47; Fri, 12 Apr 2024 13:31:26 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v5 5/5] Documentation: Add reconnect process for VDUSE Date: Fri, 12 Apr 2024 21:28:25 +0800 Message-ID: <20240412133017.483407-6-lulu@redhat.com> In-Reply-To: <20240412133017.483407-1-lulu@redhat.com> References: <20240412133017.483407-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Content-Type: text/plain; charset="utf-8" Add a document explaining the reconnect process, including what the Userspace App needs to do and how it works with the kernel. Signed-off-by: Cindy Lu --- Documentation/userspace-api/vduse.rst | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Documentation/userspace-api/vduse.rst b/Documentation/userspac= e-api/vduse.rst index bdb880e01132..7faa83462e78 100644 --- a/Documentation/userspace-api/vduse.rst +++ b/Documentation/userspace-api/vduse.rst @@ -231,3 +231,44 @@ 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 reconnection works +------------------------------------ +1. What is reconnection? + + When the userspace application loads, it should establish a connection + to the vduse kernel device. Sometimes,the userspace application exists, + and we want to support its restart and connect to the kernel device aga= in + +2. How can I support reconnection in a userspace application? + +2.1 During initialization, the userspace application should first verify t= he + existence of the device "/dev/vduse/vduse_name". + If it doesn't exist, it means this is the first-time for connection. g= oto step 2.2 + If it exists, it means this is a reconnection, and we should goto step= 2.3 + +2.2 Create a new VDUSE instance with ioctl(VDUSE_CREATE_DEV) on + /dev/vduse/control. + When ioctl(VDUSE_CREATE_DEV) is called, kernel allocates memory for + the reconnect information. The total memory size is PAGE_SIZE*vq_mumbe= r. + +2.3 Check if the information is suitable for reconnect + If this is reconnection : + Before attempting to reconnect, The userspace application needs to use= the + ioctl(VDUSE_DEV_GET_CONFIG, VDUSE_DEV_GET_STATUS, VDUSE_DEV_GET_FEATUR= ES...) + to get the information from kernel. + Please review the information and confirm if it is suitable to reconne= ct. + +2.4 Userspace application needs to mmap the memory to userspace + The userspace application requires mapping one page for every vq. Thes= e pages + should be used to save vq-related information during system running. A= dditionally, + the application must define its own structure to store information for= reconnection. + +2.5 Completed the initialization and running the application. + While the application is running, it is important to store relevant in= formation + about reconnections in mapped pages. When calling the ioctl VDUSE_VQ_G= ET_INFO to + get vq information, it's necessary to check whether it's a reconnectio= n. If it is + a reconnection, the vq-related information must be get from the mapped= pages. + +2.6 When the Userspace application exits, it is necessary to unmap all the + pages for reconnection --=20 2.43.0