From nobody Sun Feb 8 05:29:15 2026 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 EE6F71CD1B for ; Wed, 7 Feb 2024 05:47:14 +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=1707284836; cv=none; b=uOeovQ6sz57n0IXL9HI8f+wBFXSAdX7D5tNH9935yfepDeu+LHXCfQWMQ5va68EOlP5T7tQb1rjcebwIay04orFoBT0KAdVyRog9QXFOoYhw4erNnMcUbN4fYU79RuyPCiSUcfgbtQA0ky4BkcwhYUWqCV3PZXYOX3KmLPHEAk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707284836; c=relaxed/simple; bh=/j71C6LLegHXOz3snuWsv0xGmVODLdDmNr+bmnXNKGQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O2011Jv9QAgv18ygmHQVClOndpAJSlwcptQSu2YR2BopMQfV8HiB7YQqpCbd4kBBsAI9KtETV4NUf1lIklGxvPshkIGCeVRSaavk7ppuO3lwAZU9CEXOOnzwa4XEXTXXSdtcR3HHr+rqHUA++C2oT5FWm+rg02zMkfaeHyX8Sdg= 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=LMGVVyqY; 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="LMGVVyqY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707284833; 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=LMGVVyqY+2gP/OVXtD4viCVzO4+YD4TUWKUVEDhHJHs3gc28WojwuTaZVBNbzH7k0jD/mO vbL5l9/dUMyU9BRVnS/hcsRvhZpCGcyynoM7nB49LT5UkHLc/ArJWisx+iT6VEBDRbooRa ygJ4yuZ2MslQbGNXEOt28VLrpOM9P8Q= 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-662-pTo_-G6PNOeBD3YIKSAkdw-1; Wed, 07 Feb 2024 00:47:11 -0500 X-MC-Unique: pTo_-G6PNOeBD3YIKSAkdw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 66E371C04B54; Wed, 7 Feb 2024 05:47:11 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA41CC1690E; Wed, 7 Feb 2024 05:47:08 +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 v4 1/5] vduse: Add new ioctl VDUSE_DEV_GET_CONFIG Date: Wed, 7 Feb 2024 13:43:28 +0800 Message-ID: <20240207054701.616094-2-lulu@redhat.com> In-Reply-To: <20240207054701.616094-1-lulu@redhat.com> References: <20240207054701.616094-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.8 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 Sun Feb 8 05:29:15 2026 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 901161CF92 for ; Wed, 7 Feb 2024 05:47:17 +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=1707284839; cv=none; b=YfCrnWoTkehzVx2y9ofxreLEDWQR0RYM0Mw20LzQt3FZ+bQNzfQ9LyGcfOFrAeMi+e/pvCzV+9EvptM9/kX0xVpuFIOPEB0baBnZC+2WfUNODijuCEiudQPFRluYFt1+phQzyrCor19uBIz9+NNZeG4Nt4ceJoZHomNdvOx6QUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707284839; c=relaxed/simple; bh=j1lCtWf8kQGK0h6m9q3I3l1BoBQdXKPTjFjyW0xeUpg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LwT54F+B9ff/4roH/Dlu8JJZhQefMCnhz8WmYAO06Se9ZjoWC8L73e3YcBY6OjzC83meGU0u6JHdBFwvUL4V0Saz/ZvIO4lVe+YtKS+FCpoAqpuW+2LohCquh+Vfp4LAlfha5aH2YaX/OENDy8q7/PLSPc8n/SpU/FuhxiRm86k= 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=JwnglLS9; 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="JwnglLS9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707284836; 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=JwnglLS9NH/V7kX7W39P1A4wZ2sisDAKL0Bw4qQR32eMDaRQOeBxsYwcvxQgirV7kUzmr2 6EzR0zeV5eI0lsv63/JWiyOvkAcQV8Kmsxi1qPZSHTzRia08eOVvRTXZpciJZ7s+MQxz+r QkfiINwneTYC0O1O07RT4zu7vnu1xKQ= 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-121-DczEB4sWPJKuz0ywDfuvYg-1; Wed, 07 Feb 2024 00:47:14 -0500 X-MC-Unique: DczEB4sWPJKuz0ywDfuvYg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 8902483722F; Wed, 7 Feb 2024 05:47:14 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08522C1D36C; Wed, 7 Feb 2024 05:47:11 +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 v4 2/5] vduse: Add new ioctl VDUSE_DEV_GET_STATUS Date: Wed, 7 Feb 2024 13:43:29 +0800 Message-ID: <20240207054701.616094-3-lulu@redhat.com> In-Reply-To: <20240207054701.616094-1-lulu@redhat.com> References: <20240207054701.616094-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.8 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 Sun Feb 8 05:29:15 2026 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 46D461D557 for ; Wed, 7 Feb 2024 05:47:20 +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=1707284843; cv=none; b=Cl28Pi3kiFG7Obfn4MfhNzMeaEXmNfmwL2wlTi+4f8b+VHVAbzQ1tEq9hId4nPzhWDS21309iC2AfXtzOA+GaAURqJbNiVgdNBx62rzTCbrJIAXDiL2+UxFpamz7GmOrpu7Z/iTkPr/HXbzjAbXET9c37S5SP0sGBtEb9jzTTJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707284843; c=relaxed/simple; bh=cBLjryLsVfu47+tjl5ywQAYVk9Q3xIPJ/WF63oos9zU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ltQ7Yhwe0N10/9Yvr58hTBoi5zpfK3g+e2h+h2Wx3PMCF6iT/wZxRsa2jVhFyNXTUV5W9pMrXqL+8O5LLf3wQxU9kNlrxLV3rmYFMsd33DBCFdScLglojLDt/iRgnZRJC5XpU6UPNZ2FwZv2BDK8dn6Y4SOCKXIXA3hHEUcNOiI= 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=i8seLXJQ; 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="i8seLXJQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707284840; 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=i8seLXJQFjjXGxS32e9vPn2GjccPNCgs4y6B6zF1NQWRhS1ZWBhBRtUKNDFiZ60Yaz196b PLl3QOxKdm70E9GBGse9LGofDFD/EsvGYe7s9u2t2YV6nhREX6J/wpOzRY8vSeNQzJREEF W7grPgZ2tv+Xs38SxVMYAieBkLjPy/0= 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-269-Iw2rWcrUNuqMBJ5bPpkdgA-1; Wed, 07 Feb 2024 00:47:17 -0500 X-MC-Unique: Iw2rWcrUNuqMBJ5bPpkdgA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 A942E85A58B; Wed, 7 Feb 2024 05:47:17 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AC67C07F51; Wed, 7 Feb 2024 05:47:14 +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 v4 3/5] vduse: Add function to get/free the pages for reconnection Date: Wed, 7 Feb 2024 13:43:30 +0800 Message-ID: <20240207054701.616094-4-lulu@redhat.com> In-Reply-To: <20240207054701.616094-1-lulu@redhat.com> References: <20240207054701.616094-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.8 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 Sun Feb 8 05:29:15 2026 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 2AAE41F946 for ; Wed, 7 Feb 2024 05:47:45 +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=1707284866; cv=none; b=qR+tGSuzlQ57Ri4pnicTRT3VYL480D1iGHlSt4nj4TkNY6ez1o10iYExUBXflWJKE2BhpCdMwdxRyM6mPfwQym22qGyPO69K5kBpBmRCq2gji7RQeIxjbwrOn6FUtk8/209m1ezaIzr1FUJ2X9XaoDCCE7Ewik2OSlFqTkrB0cM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707284866; c=relaxed/simple; bh=WXKHRU/uEj6cYAvi50bYRlcQ0ruywm7WIxvBv/gN2jw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CZeWhJw8XReDTeEbaP8+N2HpvbCXoO3wGD6XVtUQW5kbw2lWdntRZiDcgzRinMUFk+d3DaFOgT1O0uXmvi6u6tAT49elpmHzYCEyQIFM3P+7s7gSTqP/owxAqOx1nsYvkCABI8NFCo77h5mwbJTRnzj0DHgczjKeXjYeSan6tvw= 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=KAVrWgRy; 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="KAVrWgRy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707284864; 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=dx4vuXIklQBxh8l06pvXMAeW4Cc8GkKcbpmXFc8So2o=; b=KAVrWgRyXEykUOLAu0jhOuMlhtYEoyN72bjR+qtPzV78S/o5F2ME3nlQLsELdK1X3hGnh1 0CARfeXjyCNflfs7JIwSDSFZtCgG6YKCa98T+LBZrb71UD6CNTAaO4qTsrcuy7xxL6sTde SIAKAZzXp2reaydwshFQ7GWtGfZNySQ= 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-499-5UgG03rVNwC6AlVylbb-5A-1; Wed, 07 Feb 2024 00:47:42 -0500 X-MC-Unique: 5UgG03rVNwC6AlVylbb-5A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 586DA3C0F247; Wed, 7 Feb 2024 05:47:42 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBF64492BC6; Wed, 7 Feb 2024 05:47:39 +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 v4 4/5] vduse: Add file operation for mmap Date: Wed, 7 Feb 2024 13:43:31 +0800 Message-ID: <20240207054701.616094-5-lulu@redhat.com> In-Reply-To: <20240207054701.616094-1-lulu@redhat.com> References: <20240207054701.616094-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.9 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..083fe0047677 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 1+vq_number 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 > dev->vq_num) + return -EINVAL; + + 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 Sun Feb 8 05:29:15 2026 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 8DF96200A8 for ; Wed, 7 Feb 2024 05:47:50 +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=1707284872; cv=none; b=ohQPa59raDocByFa2rZTX2m/VEeqD7ArJvfhBbumoUCf2Hx3GKEp5tP/B2DwYfj/MKuoCdwXRQY0nHbHhAfu8iTwdCVwj4NW2/+Hia9ouwENe8a0PY9wHw6uzQmr7X5P9eCxYoEvD/UTJD4VvTEpsCQqxHEVx0s6SI+sov8BkXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707284872; c=relaxed/simple; bh=6uX9zfQ8cQJ8WnngTxHu/ne5naJ+QAafInm6eyaxJy0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cs2sFLY1F5GkGSBNB32ScPaSvYjbQbPbO8oQz12+4vcN1A1LWlSCUziI+xXqBe71MNkrLNrbWMEJa27OOippbBIFNSAgT698BVir7cLz1kPjz8mUhexEfxMGbrAZ7lyRN9eb4LdPWiWtATryFlUJO2HMj4i9OOjVcoGYwop5e5E= 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=flQ3DrS5; 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="flQ3DrS5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707284869; 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=mxvyLlwFPrOAb4E1s475cmzm9HXLhSgjIXU0tbGtRvE=; b=flQ3DrS54ZCp8VW/C5iohqfH+ufwKd3U+3uuU+lpCH3CxRRSrcDQQC/qjhwbXI5bj/GdIr d9uhc7xY2vHc5IcpdKdvdv4wzOI3qVG9hEO5VnJXHMDW/vxuW/+kCSicf6Bokrj1fyC4d4 Nl85h+naRLbd26T5kXR8AuGK4YXKO6g= 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-6-f3trEO6NNI-I9I6uYGLkcQ-1; Wed, 07 Feb 2024 00:47:45 -0500 X-MC-Unique: f3trEO6NNI-I9I6uYGLkcQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 76D903811F41; Wed, 7 Feb 2024 05:47:45 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECCD7492BC6; Wed, 7 Feb 2024 05:47:42 +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 v4 5/5] Documentation: Add reconnect process for VDUSE Date: Wed, 7 Feb 2024 13:43:32 +0800 Message-ID: <20240207054701.616094-6-lulu@redhat.com> In-Reply-To: <20240207054701.616094-1-lulu@redhat.com> References: <20240207054701.616094-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.9 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 | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Documentation/userspace-api/vduse.rst b/Documentation/userspac= e-api/vduse.rst index bdb880e01132..a2be85e0e516 100644 --- a/Documentation/userspace-api/vduse.rst +++ b/Documentation/userspace-api/vduse.rst @@ -231,3 +231,35 @@ 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 it does not exist, need to create the instance.goto step 1 + If it does exist, it means this is a reconnect and goto step 3. + +1. Create a new VDUSE instance with ioctl(VDUSE_CREATE_DEV) on + /dev/vduse/control. + +2. When the ioctl(VDUSE_CREATE_DEV) function is called, the kernel allocat= es memory + to save the reconnect information. + +3. Userspace App need to mmap the pages to userspace + Userspace App need to map Pages 0 to vq_number for vq status, + Users can define the structure for saving the reconnect information the= mselves + in the userspace. + +4. Check if the infomatin sutiable for reconnect + If this is reconnect: + Before attempting to reconnect, The userspace application need to the + ioctl VDUSE_DEV_GET_CONFIG,VDUSE_DEV_GET_STATUS,VDUSE_DEV_GET_FEATURES.= .. + to get the and confirm if these information are suitable for reconnecti= ng. + +5. Start the userspace App. + While running, the application should store the relevant information ab= out + reconnections in mapped pages. + When calling ioctl VDUSE_VQ_GET_INFO from the userspace APP to get vq i= nformation, it is necessary + to check if this is a reconnection. If a reconnection has occurred, the= vq-related information + must be get from the mapped pages. + +6. When the Userspace App exits, it is necessary to unmap all the reconnec= t pages. --=20 2.43.0