From nobody Tue Sep 2 09:48:12 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 CEE4B230BEC for ; Thu, 7 Aug 2025 11:58:09 +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=1754567891; cv=none; b=OP9Clc/5LM/Q/MC5eRgW2/8tHhNlh0T50c8Acc0PxsU2/ouypG/+BHLVYv0uVX9+N5U3w2MBNyNmXh8YrsmsQTgYZ88iCg2WLossXkMsYoo+CumRNPLzMESCPkri/owx96U39lwF0tbQatPFK+7CrSvvn84NIGk76xJiOwyw2/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754567891; c=relaxed/simple; bh=Mq/AfDbkzeahYi6sN3Rcg3Dlb4puLIjsK36j9gN6tVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iik9VrOiQ/1xyqdvdSj8O9+A9NajOpRy9wcZW7vxrwPLKDBysQArp6I7OxpnWGkfmIk3h9VyTOqEo33fQY5mXLGy5+jC2nZ4WET67invmvZ2C9vk6wznJDnC54k0/IpK1PD6PFCvtGv+FT/+bDN2Oie1yhWDRoEaqevzclyDehY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=EOfYhPj9; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="EOfYhPj9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754567888; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ahzdshQiL3Xzni/Jqm6kcPlFcj6smcBvlHHrtbsnZWI=; b=EOfYhPj9RVQopygMmMtrPqZ1XyaGhdNwm3WQVy2zoLjYmjjdvtuVjZHS1EvY8a0L9jiZgV NF2ZyEQLW/Pp/W3Lqpskh1ibKgLuo4AkfI9pkpCbLw3iEWCdW0nh3FpoGVr5P/RuqkoSAH iQ8VzcdLJYQodNAHWvi129xMMwcNuHk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-Oag-_5MMOTyREqWSAkLCtA-1; Thu, 07 Aug 2025 07:58:05 -0400 X-MC-Unique: Oag-_5MMOTyREqWSAkLCtA-1 X-Mimecast-MFC-AGG-ID: Oag-_5MMOTyREqWSAkLCtA_1754567884 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2C68E1956095; Thu, 7 Aug 2025 11:58:04 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.48]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 343C230001A5; Thu, 7 Aug 2025 11:57:58 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Cindy Lu , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Yongji Xie , Stefano Garzarella , virtualization@lists.linux.dev, Laurent Vivier , linux-kernel@vger.kernel.org, Xuan Zhuo , jasowang@redhat.com, Maxime Coquelin Subject: [RFC v2 1/7] vduse: add v1 API definition Date: Thu, 7 Aug 2025 13:57:46 +0200 Message-ID: <20250807115752.1663383-2-eperezma@redhat.com> In-Reply-To: <20250807115752.1663383-1-eperezma@redhat.com> References: <20250807115752.1663383-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.30.177.4 This allows the kernel to detect whether the userspace VDUSE device supports the VQ group and ASID features. VDUSE devices that don't set the V1 API will not receive the new messages, and vdpa device will be created with only one vq group and asid. The next patches implement the new feature incrementally, only enabling the VDUSE device to set the V1 API version by the end of the series. Signed-off-by: Eugenio P=C3=A9rez --- include/uapi/linux/vduse.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/uapi/linux/vduse.h b/include/uapi/linux/vduse.h index 68a627d04afa..9a56d0416bfe 100644 --- a/include/uapi/linux/vduse.h +++ b/include/uapi/linux/vduse.h @@ -10,6 +10,10 @@ =20 #define VDUSE_API_VERSION 0 =20 +/* VQ groups and ASID support */ + +#define VDUSE_API_VERSION_1 1 + /* * Get the version of VDUSE API that kernel supported (VDUSE_API_VERSION). * This is used for future extension. --=20 2.50.1 From nobody Tue Sep 2 09:48:12 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 61BDE23D2B4 for ; Thu, 7 Aug 2025 11:58:12 +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=1754567894; cv=none; b=bK1KDJiKEiC7sCS1lepgZ1bFTkz6pIGLDEOlaakvWuJK0yp8hA5HtEdGwCw1uZpVDw85dXTohIdbW5XmYSdjYaRz9buH64Nx9dePgvK4A+ltwZC+XkkfoXH80WOdHnX/9zSw4UxMpkbkllsZXbkCIKQ5UVqhqkFKXkMOSCPgBSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754567894; c=relaxed/simple; bh=lFbTJHKpLGgRGxz1nfJ4cngDaeFwCqjUdDFdG0qkBsw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r9XMi7QLuVuvdfOHLs9qFoRE0NVf3ijrTsGk5CcwrJsBglo1F8JWZuBp0hZN1ZuOU+yVcYbD/97Qai4hZeQVq9PfRr2uHxUj5H3901qtBQ1OFh1pEm+ePHkNfMMbGv5F2MuUxmkEftPUQ0obSAmFKBttUqL4RKgStWseyBOI8hQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=KT4fobQF; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="KT4fobQF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754567891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pGiIUzD9X5QD5dRQeSDFEtRhGWKy0hYTxpY/PFA5TqM=; b=KT4fobQFxqmJUG1aTl0gUu/g122BT+p7P2h95QgwRe6qd2VE0tJJ4tIB6pna7Nh09YiKE6 41WysxGbbWdyJj13zqDORC9uYiL5DEJYvCJDuB/GdzXbc8Aa0l7jiZk97eVcOe+lrbY9/2 QqfN47gtJW0aeo4nhjwSUENXY2cnLjY= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-604-scn3ZyX5PsuVXQC152AUYQ-1; Thu, 07 Aug 2025 07:58:09 -0400 X-MC-Unique: scn3ZyX5PsuVXQC152AUYQ-1 X-Mimecast-MFC-AGG-ID: scn3ZyX5PsuVXQC152AUYQ_1754567888 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8F141195608B; Thu, 7 Aug 2025 11:58:08 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.48]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B33823001453; Thu, 7 Aug 2025 11:58:04 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Cindy Lu , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Yongji Xie , Stefano Garzarella , virtualization@lists.linux.dev, Laurent Vivier , linux-kernel@vger.kernel.org, Xuan Zhuo , jasowang@redhat.com, Maxime Coquelin Subject: [RFC v2 2/7] vduse: add vq group support Date: Thu, 7 Aug 2025 13:57:47 +0200 Message-ID: <20250807115752.1663383-3-eperezma@redhat.com> In-Reply-To: <20250807115752.1663383-1-eperezma@redhat.com> References: <20250807115752.1663383-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.30.177.4 This allows sepparate the different virtqueues in groups that shares the same address space. Asking the VDUSE device for the groups of the vq at the beginning as they're needed for the DMA API. Allocating 3 vq groups as net is the device that need the most groups: * Dataplane (guest passthrough) * CVQ * Shadowed vrings. Future versions of the series can include dynamic allocation of the groups array so VDUSE can declare more groups. Signed-off-by: Eugenio P=C3=A9rez --- v2: * Cache group information in kernel, as we need to provide the vq map tokens properly. * Add descs vq group to optimize SVQ forwarding and support indirect descriptors out of the box. --- drivers/vdpa/vdpa_user/vduse_dev.c | 71 +++++++++++++++++++++++++++++- include/uapi/linux/vduse.h | 19 +++++++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index d858c4389cc1..d1f6d00a9c71 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -46,6 +46,11 @@ #define VDUSE_IOVA_SIZE (VDUSE_MAX_BOUNCE_SIZE + 128 * 1024 * 1024) #define VDUSE_MSG_DEFAULT_TIMEOUT 30 =20 +/* + * Let's make it 3 for simplicity. + */ +#define VDUSE_MAX_VQ_GROUPS 3 + #define IRQ_UNBOUND -1 =20 struct vduse_virtqueue { @@ -58,6 +63,8 @@ struct vduse_virtqueue { struct vdpa_vq_state state; bool ready; bool kicked; + u32 vq_group; + u32 vq_desc_group; spinlock_t kick_lock; spinlock_t irq_lock; struct eventfd_ctx *kickfd; @@ -114,6 +121,7 @@ struct vduse_dev { u8 status; u32 vq_num; u32 vq_align; + u32 ngroups; struct vduse_umem *umem; struct mutex mem_lock; unsigned int bounce_size; @@ -592,6 +600,20 @@ static int vduse_vdpa_set_vq_state(struct vdpa_device = *vdpa, u16 idx, return 0; } =20 +static u32 vduse_get_vq_group(struct vdpa_device *vdpa, u16 idx) +{ + struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); + + return dev->vqs[idx]->vq_group; +} + +static u32 vduse_get_vq_desc_group(struct vdpa_device *vdpa, u16 idx) +{ + struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); + + return dev->vqs[idx]->vq_desc_group; +} + static int vduse_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 idx, struct vdpa_vq_state *state) { @@ -678,13 +700,48 @@ static u8 vduse_vdpa_get_status(struct vdpa_device *v= dpa) return dev->status; } =20 +static int vduse_fill_vq_groups(struct vduse_dev *dev) +{ + if (dev->api_version < VDUSE_API_VERSION_1) + return 0; + + for (int i =3D 0; i < dev->vdev->vdpa.nvqs; ++i) { + struct vduse_dev_msg msg =3D { 0 }; + int ret; + + msg.req.type =3D VDUSE_GET_VQ_GROUP; + msg.req.vq_group.index =3D i; + ret =3D vduse_dev_msg_sync(dev, &msg); + if (ret) + return ret; + + dev->vqs[i]->vq_group =3D msg.resp.vq_group.num; + + msg.req.type =3D VDUSE_GET_VRING_DESC_GROUP; + ret =3D vduse_dev_msg_sync(dev, &msg); + if (ret) + return ret; + + dev->vqs[i]->vq_desc_group =3D msg.resp.vq_group.num; + } + + return 0; +} + static void vduse_vdpa_set_status(struct vdpa_device *vdpa, u8 status) { struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); + u8 previous_status =3D dev->status; =20 if (vduse_dev_set_status(dev, status)) return; =20 + if ((dev->status ^ previous_status) & + BIT_ULL(VIRTIO_CONFIG_S_FEATURES_OK) && + status & (1ULL << VIRTIO_CONFIG_S_FEATURES_OK)) + if (vduse_fill_vq_groups(dev)) + return; + dev->status =3D status; } =20 @@ -789,6 +846,8 @@ static const struct vdpa_config_ops vduse_vdpa_config_o= ps =3D { .set_vq_cb =3D vduse_vdpa_set_vq_cb, .set_vq_num =3D vduse_vdpa_set_vq_num, .get_vq_size =3D vduse_vdpa_get_vq_size, + .get_vq_group =3D vduse_get_vq_group, + .get_vq_desc_group =3D vduse_get_vq_desc_group, .set_vq_ready =3D vduse_vdpa_set_vq_ready, .get_vq_ready =3D vduse_vdpa_get_vq_ready, .set_vq_state =3D vduse_vdpa_set_vq_state, @@ -1856,6 +1915,16 @@ static int vduse_create_dev(struct vduse_dev_config = *config, dev->device_features =3D config->features; dev->device_id =3D config->device_id; dev->vendor_id =3D config->vendor_id; + if (dev->api_version >=3D 1) { + if (config->ngroups > VDUSE_MAX_VQ_GROUPS) { + pr_err("Not creating a VDUSE device with %u vq groups. Max: %u", + config->ngroups, VDUSE_MAX_VQ_GROUPS); + goto err; + } + dev->ngroups =3D config->ngroups ?: 1; + } else { + dev->ngroups =3D 1; + } dev->name =3D kstrdup(config->name, GFP_KERNEL); if (!dev->name) goto err_str; @@ -2016,7 +2085,7 @@ static int vduse_dev_init_vdpa(struct vduse_dev *dev,= const char *name) =20 vdev =3D vdpa_alloc_device(struct vduse_vdpa, vdpa, dev->dev, &vduse_vdpa_config_ops, &vduse_map_ops, - 1, 1, name, true); + dev->ngroups, 1, name, true); if (IS_ERR(vdev)) return PTR_ERR(vdev); =20 diff --git a/include/uapi/linux/vduse.h b/include/uapi/linux/vduse.h index 9a56d0416bfe..b4b139dc76bb 100644 --- a/include/uapi/linux/vduse.h +++ b/include/uapi/linux/vduse.h @@ -31,6 +31,7 @@ * @features: virtio features * @vq_num: the number of virtqueues * @vq_align: the allocation alignment of virtqueue's metadata + * @ngroups: number of vq groups that VDUSE device declares * @reserved: for future use, needs to be initialized to zero * @config_size: the size of the configuration space * @config: the buffer of the configuration space @@ -45,7 +46,8 @@ struct vduse_dev_config { __u64 features; __u32 vq_num; __u32 vq_align; - __u32 reserved[13]; + __u32 ngroups; /* if VDUSE_API_VERSION >=3D 1 */ + __u32 reserved[12]; __u32 config_size; __u8 config[]; }; @@ -160,6 +162,16 @@ struct vduse_vq_state_packed { __u16 last_used_idx; }; =20 +/** + * struct vduse_vq_group - virtqueue group + * @num: Index of the virtqueue group + * @num: Group + */ +struct vduse_vq_group { + __u32 index; + __u32 num; +}; + /** * struct vduse_vq_info - information of a virtqueue * @index: virtqueue index @@ -182,6 +194,7 @@ struct vduse_vq_info { union { struct vduse_vq_state_split split; struct vduse_vq_state_packed packed; + struct vduse_vq_group group; }; __u8 ready; }; @@ -274,6 +287,8 @@ enum vduse_req_type { VDUSE_GET_VQ_STATE, VDUSE_SET_STATUS, VDUSE_UPDATE_IOTLB, + VDUSE_GET_VQ_GROUP, + VDUSE_GET_VRING_DESC_GROUP, }; =20 /** @@ -328,6 +343,7 @@ struct vduse_dev_request { struct vduse_vq_state vq_state; struct vduse_dev_status s; struct vduse_iova_range iova; + struct vduse_vq_group vq_group; /* Only if vduse api version >=3D 1 */ __u32 padding[32]; }; }; @@ -350,6 +366,7 @@ struct vduse_dev_response { __u32 reserved[4]; union { struct vduse_vq_state vq_state; + struct vduse_vq_group vq_group; /* Only if vduse api version >=3D 1 */ __u32 padding[32]; }; }; --=20 2.50.1 From nobody Tue Sep 2 09:48:12 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 D5F4D23C4F3 for ; Thu, 7 Aug 2025 11:58:17 +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=1754567899; cv=none; b=W9YOa66K2h8KBAKkqWEIfm2GKwGjiTE3mwkvktTEoyRnIqIFWJxXu3GRC+9J3p+csfjlQP4SOTxJ0f075cUTcsNMu+86sc/yodoOVui6MtkFmHYZfSw6Xc4WdJcMGU0xcyFDGE0aZmVguzm/NN+eYvh/RJZGi0SOgeL1xgfaE6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754567899; c=relaxed/simple; bh=8D8rIYRVZgKyL2guUQErRnu+k5Of3gzVxEjH0MYjlJQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U/7+pe9Zqmsatl2Yme5mJAIKmAD1BXj6aP3mrUUZubj33AgC8AawfhAIbxsi2r6OeyINuTbijqQl9pRQdTcXHr9J3ThiYec0LgIXACFId/u1v0jG6I8VUcblRUL+nzjzbckVF83ZVG95QAyCuAcgBPGdB3/+GWKHvhAGiQD3WyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=T8a8OjMw; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="T8a8OjMw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754567897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iR7lP8+A2xwbfvrWFyABp9IJvnMz9zYp8kx8LB/R+t0=; b=T8a8OjMwKgjpxaz8oK32reaN4ybYy9+yGV95at+H2kyIxbz8whabYymgW40JSGc+J2DoTN qMc3E4pHTTOTiT4CatO3lRH9zn9CoOnpLqiGWm9IRU3SEJHo017NpuYdXW04XopDq1yzAy 4R0hzMWNNwwvq5KD49WEt/MdJZBmxMY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-JkcvbLJ1PK--3wlTQhrfow-1; Thu, 07 Aug 2025 07:58:14 -0400 X-MC-Unique: JkcvbLJ1PK--3wlTQhrfow-1 X-Mimecast-MFC-AGG-ID: JkcvbLJ1PK--3wlTQhrfow_1754567893 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D5991180036F; Thu, 7 Aug 2025 11:58:12 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.48]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 21F6430001A5; Thu, 7 Aug 2025 11:58:08 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Cindy Lu , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Yongji Xie , Stefano Garzarella , virtualization@lists.linux.dev, Laurent Vivier , linux-kernel@vger.kernel.org, Xuan Zhuo , jasowang@redhat.com, Maxime Coquelin Subject: [RFC v2 3/7] vdpa: change get_vq_map_token type to void *(*cb) Date: Thu, 7 Aug 2025 13:57:48 +0200 Message-ID: <20250807115752.1663383-4-eperezma@redhat.com> In-Reply-To: <20250807115752.1663383-1-eperezma@redhat.com> References: <20250807115752.1663383-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.30.177.4 Mail list requested a better (safer) return type in the DMA rework series so this is just temporal workaround to develop this RFC. Signed-off-by: Eugenio P=C3=A9rez --- drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- include/linux/vdpa.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5= _vnet.c index 78421fc709c6..ef39841e6e96 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -3395,7 +3395,7 @@ static int mlx5_vdpa_reset_map(struct vdpa_device *vd= ev, unsigned int asid) return err; } =20 -static struct device *mlx5_get_vq_map_token(struct vdpa_device *vdev, u16 = idx) +static void *mlx5_get_vq_map_token(struct vdpa_device *vdev, u16 idx) { struct mlx5_vdpa_dev *mvdev =3D to_mvdev(vdev); =20 diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index cb51b7e2e569..3846791f6868 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -438,7 +438,7 @@ struct vdpa_config_ops { int (*reset_map)(struct vdpa_device *vdev, unsigned int asid); int (*set_group_asid)(struct vdpa_device *vdev, unsigned int group, unsigned int asid); - struct device *(*get_vq_map_token)(struct vdpa_device *vdev, u16 idx); + void *(*get_vq_map_token)(struct vdpa_device *vdev, u16 idx); int (*bind_mm)(struct vdpa_device *vdev, struct mm_struct *mm); void (*unbind_mm)(struct vdpa_device *vdev); =20 --=20 2.50.1 From nobody Tue Sep 2 09:48:12 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 16FAC246335 for ; Thu, 7 Aug 2025 11:58:20 +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=1754567902; cv=none; b=KUIWpbAfzyawg5bOxacmik2nhORK2Nn+seunT9D0gXiFbxAxtsyt5xrJQQGLho8sj7xrvX1d3XnMjq/P9twBEn54ssWZUBXBKjBj6k+OqWkRQbX8Po8jCUkM9q/pjneg6D55Np/GOzO8qWVJ75c11/Ng3Q5NsKt1Bq8DcOoK0n8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754567902; c=relaxed/simple; bh=OlgcjKZEoocgp8URLTA8IUW5kt7t2SqKtJHyK26iYcc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Klc5UJIiss6u2Ovo59nsbjIW1DMEO49LeODLGxf3EhGbsQ7JzYGqQER8FfQqZXowqqigTV8Qf2J8HtzDiccCAui8DKAqhAez/ysKNoGeXANKKfoMgZ6u0EqkvfELvRJWlJuzx9Tnzx7IOoIw1gMAE8/Z215CJYUFv65kbWRFN6s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=WkJEtITE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="WkJEtITE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754567899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fha0KzHMPOcDj2AbK1PHLwLWx6br+bmZq+WqPZof6SM=; b=WkJEtITEuik/ZCGJUgj8/awKiW9ZfA4A+IW0k+vaKK3md0rDWkkVa2Nc3fjFvxjpqGppha AziRXgjHu/LwILI1Lt81TTb6DPmTNswBjfESN1PBsHriMWFmoZlWqx+AVdRUHHdho3Qsdl N22xlhiSpWDeXLGoVSQJVH2kMC1AesM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-3-SduvGxPYS4va4z7JCCQA-1; Thu, 07 Aug 2025 07:58:18 -0400 X-MC-Unique: 3-SduvGxPYS4va4z7JCCQA-1 X-Mimecast-MFC-AGG-ID: 3-SduvGxPYS4va4z7JCCQA_1754567897 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 71A53180034D; Thu, 7 Aug 2025 11:58:17 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.48]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 86A1530001A5; Thu, 7 Aug 2025 11:58:13 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Cindy Lu , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Yongji Xie , Stefano Garzarella , virtualization@lists.linux.dev, Laurent Vivier , linux-kernel@vger.kernel.org, Xuan Zhuo , jasowang@redhat.com, Maxime Coquelin Subject: [RFC v2 4/7] vduse: return internal vq group struct as map token Date: Thu, 7 Aug 2025 13:57:49 +0200 Message-ID: <20250807115752.1663383-5-eperezma@redhat.com> In-Reply-To: <20250807115752.1663383-1-eperezma@redhat.com> References: <20250807115752.1663383-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.30.177.4 Return the internal struct that represents the vq group as virtqueue map token, instead of the device. This allows the DMA functions to access the information per group. At this moment all the virtqueues share the same vq group, that only can point to ASID 0. This change prepares the infrastructure for actual per-group address space handling Signed-off-by: Eugenio P=C3=A9rez --- drivers/vdpa/vdpa_user/vduse_dev.c | 44 ++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index d1f6d00a9c71..a7a2749f5818 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -90,6 +90,10 @@ struct vduse_umem { struct mm_struct *mm; }; =20 +struct vduse_vq_group_int { + struct vduse_dev *dev; +}; + struct vduse_dev { struct vduse_vdpa *vdev; struct device *dev; @@ -123,6 +127,7 @@ struct vduse_dev { u32 vq_align; u32 ngroups; struct vduse_umem *umem; + struct vduse_vq_group_int groups[VDUSE_MAX_VQ_GROUPS]; struct mutex mem_lock; unsigned int bounce_size; struct mutex domain_lock; @@ -614,6 +619,14 @@ static u32 vduse_get_vq_desc_group(struct vdpa_device = *vdpa, u16 idx) return dev->vqs[idx]->vq_desc_group; } =20 +static void *vduse_get_vq_map_token(struct vdpa_device *vdpa, u16 idx) +{ + struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); + u32 vq_group =3D dev->vqs[idx]->vq_group; + + return &dev->groups[vq_group]; +} + static int vduse_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 idx, struct vdpa_vq_state *state) { @@ -870,6 +883,7 @@ static const struct vdpa_config_ops vduse_vdpa_config_o= ps =3D { .get_vq_affinity =3D vduse_vdpa_get_vq_affinity, .reset =3D vduse_vdpa_reset, .set_map =3D vduse_vdpa_set_map, + .get_vq_map_token =3D vduse_get_vq_map_token, .free =3D vduse_vdpa_free, }; =20 @@ -877,8 +891,8 @@ static void vduse_dev_sync_single_for_device(void *toke= n, dma_addr_t dma_addr, size_t size, enum dma_data_direction dir) { - struct device *dev =3D token; - struct vduse_dev *vdev =3D dev_to_vduse(dev); + struct vduse_vq_group_int *group =3D token; + struct vduse_dev *vdev =3D group->dev; struct vduse_iova_domain *domain =3D vdev->domain; =20 vduse_domain_sync_single_for_device(domain, dma_addr, size, dir); @@ -888,8 +902,8 @@ static void vduse_dev_sync_single_for_cpu(void *token, dma_addr_t dma_addr, size_t size, enum dma_data_direction dir) { - struct device *dev =3D token; - struct vduse_dev *vdev =3D dev_to_vduse(dev); + struct vduse_vq_group_int *group =3D token; + struct vduse_dev *vdev =3D group->dev; struct vduse_iova_domain *domain =3D vdev->domain; =20 vduse_domain_sync_single_for_cpu(domain, dma_addr, size, dir); @@ -900,8 +914,8 @@ static dma_addr_t vduse_dev_map_page(void *token, struc= t page *page, enum dma_data_direction dir, unsigned long attrs) { - struct device *dev =3D token; - struct vduse_dev *vdev =3D dev_to_vduse(dev); + struct vduse_vq_group_int *group =3D token; + struct vduse_dev *vdev =3D group->dev; struct vduse_iova_domain *domain =3D vdev->domain; =20 return vduse_domain_map_page(domain, page, offset, size, dir, attrs); @@ -911,8 +925,8 @@ static void vduse_dev_unmap_page(void *token, dma_addr_= t dma_addr, size_t size, enum dma_data_direction dir, unsigned long attrs) { - struct device *dev =3D token; - struct vduse_dev *vdev =3D dev_to_vduse(dev); + struct vduse_vq_group_int *group =3D token; + struct vduse_dev *vdev =3D group->dev; struct vduse_iova_domain *domain =3D vdev->domain; =20 return vduse_domain_unmap_page(domain, dma_addr, size, dir, attrs); @@ -921,8 +935,8 @@ static void vduse_dev_unmap_page(void *token, dma_addr_= t dma_addr, static void *vduse_dev_alloc_coherent(void *token, size_t size, dma_addr_t *dma_addr, gfp_t flag) { - struct device *dev =3D token; - struct vduse_dev *vdev =3D dev_to_vduse(dev); + struct vduse_vq_group_int *group =3D token; + struct vduse_dev *vdev =3D group->dev; struct vduse_iova_domain *domain =3D vdev->domain; unsigned long iova; void *addr; @@ -942,8 +956,8 @@ static void vduse_dev_free_coherent(void *token, size_t= size, void *vaddr, dma_addr_t dma_addr, unsigned long attrs) { - struct device *dev =3D token; - struct vduse_dev *vdev =3D dev_to_vduse(dev); + struct vduse_vq_group_int *group =3D token; + struct vduse_dev *vdev =3D group->dev; struct vduse_iova_domain *domain =3D vdev->domain; =20 vduse_domain_free_coherent(domain, size, vaddr, dma_addr, attrs); @@ -951,8 +965,8 @@ static void vduse_dev_free_coherent(void *token, size_t= size, =20 static size_t vduse_dev_max_mapping_size(void *token) { - struct device *dev =3D token; - struct vduse_dev *vdev =3D dev_to_vduse(dev); + struct vduse_vq_group_int *group =3D token; + struct vduse_dev *vdev =3D group->dev; struct vduse_iova_domain *domain =3D vdev->domain; =20 return domain->bounce_size; @@ -1925,6 +1939,8 @@ static int vduse_create_dev(struct vduse_dev_config *= config, } else { dev->ngroups =3D 1; } + for (u32 i =3D 0; i < dev->ngroups; ++i) + dev->groups[i].dev =3D dev; dev->name =3D kstrdup(config->name, GFP_KERNEL); if (!dev->name) goto err_str; --=20 2.50.1 From nobody Tue Sep 2 09:48:12 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 4196724728B for ; Thu, 7 Aug 2025 11:58:25 +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=1754567907; cv=none; b=I/Pw0X1AJcN9BxBvi/R03dHl2GM2mG3cjFY5isV7d5i+HfVXdqg79RsDJW4E81ZOkDeoLwiYLH95CQGWU2ydV3XXkzBUc1WnDSr/XLYuziw8vJ7BnhtzdvnEUitlO6fjqkMMpc0qKZfb7K0WnOHH3HGVpvQl7mJT5CQcJRyOfeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754567907; c=relaxed/simple; bh=4GqqtD6r/J+qJYTCtvusDSzd9AUifqrR9yMkqBkYBCU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HFy48nL1serjIWkoW9QmV53kPM4VJt6kmAFPoCbnvSzwZYB1+qLp9RUMxt/7ZucmBPQ69ZQkNMIfXk9Ubpm2o6zEf7fPhOU8dpmhFBYQ7l9RbRuX15ekg5DnQ5DZTX+qxHXADgWWwRC5vmHYcjKmwEc48D8kyc21GwBaKjMlv/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=B88poinw; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="B88poinw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754567904; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=30olQZNnCwbIJcZghnvNoky1fgd4ygoIyrsrUZJTwig=; b=B88poinwjEhgjR3qYYTh42jxERdZOBij3MlTG2vRCg3y+xlt+l+PAgOqmwyN6vdcATvF9M 2iP9P4/PwwwysM+AZ80wGb2qFbKwkacUPL0xSFPrK/6W8AeVlcmxMkCS0tMScYY1nfhgvO US+Wrm2UGrWzjr4b2DtL5Q9wgBa3E18= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-513-KWz9ZUurNiKZJeivLS0bRw-1; Thu, 07 Aug 2025 07:58:23 -0400 X-MC-Unique: KWz9ZUurNiKZJeivLS0bRw-1 X-Mimecast-MFC-AGG-ID: KWz9ZUurNiKZJeivLS0bRw_1754567902 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2AFBD1956089; Thu, 7 Aug 2025 11:58:22 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.48]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D597E30001A5; Thu, 7 Aug 2025 11:58:17 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Cindy Lu , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Yongji Xie , Stefano Garzarella , virtualization@lists.linux.dev, Laurent Vivier , linux-kernel@vger.kernel.org, Xuan Zhuo , jasowang@redhat.com, Maxime Coquelin Subject: [RFC v2 5/7] vduse: add vq group asid support Date: Thu, 7 Aug 2025 13:57:50 +0200 Message-ID: <20250807115752.1663383-6-eperezma@redhat.com> In-Reply-To: <20250807115752.1663383-1-eperezma@redhat.com> References: <20250807115752.1663383-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.30.177.4 Add support for assigning Address Space Identifiers (ASIDs) to each VQ group. This enables mapping each group into a distinct memory space. Signed-off-by: Eugenio P=C3=A9rez --- v2: Make iotlb entry the last one of vduse_iotlb_entry_v2 so the first part of the struct is the same. --- drivers/vdpa/vdpa_user/vduse_dev.c | 259 ++++++++++++++++++++++------- include/uapi/linux/vduse.h | 36 +++- 2 files changed, 230 insertions(+), 65 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index a7a2749f5818..145147c49930 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -51,6 +51,12 @@ */ #define VDUSE_MAX_VQ_GROUPS 3 =20 +/* + * We can do ASID thanks to (ab)using the vduse device and the vdpa one. S= o no + * more than 2. + */ +#define VDUSE_MAX_ASID 2 + #define IRQ_UNBOUND -1 =20 struct vduse_virtqueue { @@ -91,6 +97,7 @@ struct vduse_umem { }; =20 struct vduse_vq_group_int { + struct vduse_iova_domain *domain; struct vduse_dev *dev; }; =20 @@ -98,7 +105,7 @@ struct vduse_dev { struct vduse_vdpa *vdev; struct device *dev; struct vduse_virtqueue **vqs; - struct vduse_iova_domain *domain; + struct vduse_iova_domain *domain[VDUSE_MAX_ASID]; char *name; struct mutex lock; spinlock_t msg_lock; @@ -126,7 +133,8 @@ struct vduse_dev { u32 vq_num; u32 vq_align; u32 ngroups; - struct vduse_umem *umem; + u32 nas; + struct vduse_umem *umem[VDUSE_MAX_ASID]; struct vduse_vq_group_int groups[VDUSE_MAX_VQ_GROUPS]; struct mutex mem_lock; unsigned int bounce_size; @@ -440,14 +448,28 @@ static __poll_t vduse_dev_poll(struct file *file, pol= l_table *wait) return mask; } =20 +/* Force set the asid to a vq group without a message to the VDUSE device = */ +static void vduse_set_group_asid_nomsg(struct vduse_dev *dev, + unsigned int group, unsigned int asid) +{ + guard(mutex)(&dev->domain_lock); + dev->groups[group].domain =3D dev->domain[asid]; +} + static void vduse_dev_reset(struct vduse_dev *dev) { int i; - struct vduse_iova_domain *domain =3D dev->domain; =20 /* The coherent mappings are handled in vduse_dev_free_coherent() */ - if (domain && domain->bounce_map) - vduse_domain_reset_bounce_map(domain); + for (i =3D 0; i < dev->nas; i++) { + struct vduse_iova_domain *domain =3D dev->domain[i]; + + if (domain && domain->bounce_map) + vduse_domain_reset_bounce_map(domain); + } + + for (i =3D 0; i < dev->ngroups; i++) + vduse_set_group_asid_nomsg(dev, i, 0); =20 down_write(&dev->rwsem); =20 @@ -619,6 +641,29 @@ static u32 vduse_get_vq_desc_group(struct vdpa_device = *vdpa, u16 idx) return dev->vqs[idx]->vq_desc_group; } =20 +static int vduse_set_group_asid(struct vdpa_device *vdpa, unsigned int gro= up, + unsigned int asid) +{ + struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); + struct vduse_dev_msg msg =3D { 0 }; + int r; + + if (dev->api_version < VDUSE_API_VERSION_1 || + group > dev->ngroups || asid > dev->nas) + return -EINVAL; + + msg.req.type =3D VDUSE_SET_VQ_GROUP_ASID; + msg.req.vq_group_asid.group =3D group; + msg.req.vq_group_asid.asid =3D asid; + + r =3D vduse_dev_msg_sync(dev, &msg); + if (r < 0) + return r; + + vduse_set_group_asid_nomsg(dev, group, asid); + return 0; +} + static void *vduse_get_vq_map_token(struct vdpa_device *vdpa, u16 idx) { struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); @@ -833,13 +878,13 @@ static int vduse_vdpa_set_map(struct vdpa_device *vdp= a, struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); int ret; =20 - ret =3D vduse_domain_set_map(dev->domain, iotlb); + ret =3D vduse_domain_set_map(dev->domain[asid], iotlb); if (ret) return ret; =20 ret =3D vduse_dev_update_iotlb(dev, 0ULL, ULLONG_MAX); if (ret) { - vduse_domain_clear_map(dev->domain, iotlb); + vduse_domain_clear_map(dev->domain[asid], iotlb); return ret; } =20 @@ -883,6 +928,7 @@ static const struct vdpa_config_ops vduse_vdpa_config_o= ps =3D { .get_vq_affinity =3D vduse_vdpa_get_vq_affinity, .reset =3D vduse_vdpa_reset, .set_map =3D vduse_vdpa_set_map, + .set_group_asid =3D vduse_set_group_asid, .get_vq_map_token =3D vduse_get_vq_map_token, .free =3D vduse_vdpa_free, }; @@ -893,8 +939,10 @@ static void vduse_dev_sync_single_for_device(void *tok= en, { struct vduse_vq_group_int *group =3D token; struct vduse_dev *vdev =3D group->dev; - struct vduse_iova_domain *domain =3D vdev->domain; + struct vduse_iova_domain *domain; =20 + guard(mutex)(&vdev->domain_lock); + domain =3D group->domain; vduse_domain_sync_single_for_device(domain, dma_addr, size, dir); } =20 @@ -904,8 +952,10 @@ static void vduse_dev_sync_single_for_cpu(void *token, { struct vduse_vq_group_int *group =3D token; struct vduse_dev *vdev =3D group->dev; - struct vduse_iova_domain *domain =3D vdev->domain; + struct vduse_iova_domain *domain; =20 + guard(mutex)(&vdev->domain_lock); + domain =3D group->domain; vduse_domain_sync_single_for_cpu(domain, dma_addr, size, dir); } =20 @@ -916,8 +966,10 @@ static dma_addr_t vduse_dev_map_page(void *token, stru= ct page *page, { struct vduse_vq_group_int *group =3D token; struct vduse_dev *vdev =3D group->dev; - struct vduse_iova_domain *domain =3D vdev->domain; + struct vduse_iova_domain *domain; =20 + guard(mutex)(&vdev->domain_lock); + domain =3D group->domain; return vduse_domain_map_page(domain, page, offset, size, dir, attrs); } =20 @@ -927,8 +979,10 @@ static void vduse_dev_unmap_page(void *token, dma_addr= _t dma_addr, { struct vduse_vq_group_int *group =3D token; struct vduse_dev *vdev =3D group->dev; - struct vduse_iova_domain *domain =3D vdev->domain; + struct vduse_iova_domain *domain; =20 + guard(mutex)(&vdev->domain_lock); + domain =3D group->domain; return vduse_domain_unmap_page(domain, dma_addr, size, dir, attrs); } =20 @@ -937,11 +991,13 @@ static void *vduse_dev_alloc_coherent(void *token, si= ze_t size, { struct vduse_vq_group_int *group =3D token; struct vduse_dev *vdev =3D group->dev; - struct vduse_iova_domain *domain =3D vdev->domain; + struct vduse_iova_domain *domain; unsigned long iova; void *addr; =20 *dma_addr =3D DMA_MAPPING_ERROR; + guard(mutex)(&vdev->domain_lock); + domain =3D group->domain; addr =3D vduse_domain_alloc_coherent(domain, size, (dma_addr_t *)&iova, flag); if (!addr) @@ -958,8 +1014,10 @@ static void vduse_dev_free_coherent(void *token, size= _t size, { struct vduse_vq_group_int *group =3D token; struct vduse_dev *vdev =3D group->dev; - struct vduse_iova_domain *domain =3D vdev->domain; + struct vduse_iova_domain *domain; =20 + guard(mutex)(&vdev->domain_lock); + domain =3D group->domain; vduse_domain_free_coherent(domain, size, vaddr, dma_addr, attrs); } =20 @@ -967,8 +1025,10 @@ static size_t vduse_dev_max_mapping_size(void *token) { struct vduse_vq_group_int *group =3D token; struct vduse_dev *vdev =3D group->dev; - struct vduse_iova_domain *domain =3D vdev->domain; + struct vduse_iova_domain *domain; =20 + guard(mutex)(&vdev->domain_lock); + domain =3D group->domain; return domain->bounce_size; } =20 @@ -1107,31 +1167,32 @@ static int vduse_dev_queue_irq_work(struct vduse_de= v *dev, return ret; } =20 -static int vduse_dev_dereg_umem(struct vduse_dev *dev, +static int vduse_dev_dereg_umem(struct vduse_dev *dev, u32 asid, u64 iova, u64 size) { int ret; =20 mutex_lock(&dev->mem_lock); ret =3D -ENOENT; - if (!dev->umem) + if (!dev->umem[asid]) goto unlock; =20 ret =3D -EINVAL; - if (!dev->domain) + if (!dev->domain[asid]) goto unlock; =20 - if (dev->umem->iova !=3D iova || size !=3D dev->domain->bounce_size) + if (dev->umem[asid]->iova !=3D iova || + size !=3D dev->domain[asid]->bounce_size) goto unlock; =20 - vduse_domain_remove_user_bounce_pages(dev->domain); - unpin_user_pages_dirty_lock(dev->umem->pages, - dev->umem->npages, true); - atomic64_sub(dev->umem->npages, &dev->umem->mm->pinned_vm); - mmdrop(dev->umem->mm); - vfree(dev->umem->pages); - kfree(dev->umem); - dev->umem =3D NULL; + vduse_domain_remove_user_bounce_pages(dev->domain[asid]); + unpin_user_pages_dirty_lock(dev->umem[asid]->pages, + dev->umem[asid]->npages, true); + atomic64_sub(dev->umem[asid]->npages, &dev->umem[asid]->mm->pinned_vm); + mmdrop(dev->umem[asid]->mm); + vfree(dev->umem[asid]->pages); + kfree(dev->umem[asid]); + dev->umem[asid] =3D NULL; ret =3D 0; unlock: mutex_unlock(&dev->mem_lock); @@ -1139,7 +1200,7 @@ static int vduse_dev_dereg_umem(struct vduse_dev *dev, } =20 static int vduse_dev_reg_umem(struct vduse_dev *dev, - u64 iova, u64 uaddr, u64 size) + u32 asid, u64 iova, u64 uaddr, u64 size) { struct page **page_list =3D NULL; struct vduse_umem *umem =3D NULL; @@ -1147,14 +1208,14 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, unsigned long npages, lock_limit; int ret; =20 - if (!dev->domain || !dev->domain->bounce_map || - size !=3D dev->domain->bounce_size || + if (!dev->domain[asid] || !dev->domain[asid]->bounce_map || + size !=3D dev->domain[asid]->bounce_size || iova !=3D 0 || uaddr & ~PAGE_MASK) return -EINVAL; =20 mutex_lock(&dev->mem_lock); ret =3D -EEXIST; - if (dev->umem) + if (dev->umem[asid]) goto unlock; =20 ret =3D -ENOMEM; @@ -1178,7 +1239,7 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, goto out; } =20 - ret =3D vduse_domain_add_user_bounce_pages(dev->domain, + ret =3D vduse_domain_add_user_bounce_pages(dev->domain[asid], page_list, pinned); if (ret) goto out; @@ -1191,7 +1252,7 @@ static int vduse_dev_reg_umem(struct vduse_dev *dev, umem->mm =3D current->mm; mmgrab(current->mm); =20 - dev->umem =3D umem; + dev->umem[asid] =3D umem; out: if (ret && pinned > 0) unpin_user_pages(page_list, pinned); @@ -1234,26 +1295,43 @@ static long vduse_dev_ioctl(struct file *file, unsi= gned int cmd, =20 switch (cmd) { case VDUSE_IOTLB_GET_FD: { - struct vduse_iotlb_entry entry; + struct vduse_iotlb_entry_v2 entry; + struct vduse_iotlb_entry entry_old; struct vhost_iotlb_map *map; struct vdpa_map_file *map_file; struct file *f =3D NULL; =20 ret =3D -EFAULT; - if (copy_from_user(&entry, argp, sizeof(entry))) - break; + if (dev->api_version >=3D VDUSE_API_VERSION_1) { + if (copy_from_user(&entry, argp, sizeof(entry))) + break; + } else { + if (copy_from_user(&entry_old, argp, + sizeof(entry_old))) + break; + + entry.offset =3D entry_old.offset; + entry.start =3D entry_old.start; + entry.last =3D entry_old.last; + entry.asid =3D 0; + entry.perm =3D entry_old.perm; + } =20 ret =3D -EINVAL; if (entry.start > entry.last) break; =20 + if (entry.asid > dev->nas) + break; + mutex_lock(&dev->domain_lock); - if (!dev->domain) { + /* TODO accessing an array with idx from userspace, mitigations? */ + if (!dev->domain[entry.asid]) { mutex_unlock(&dev->domain_lock); break; } - spin_lock(&dev->domain->iotlb_lock); - map =3D vhost_iotlb_itree_first(dev->domain->iotlb, + spin_lock(&dev->domain[entry.asid]->iotlb_lock); + map =3D vhost_iotlb_itree_first(dev->domain[entry.asid]->iotlb, entry.start, entry.last); if (map) { map_file =3D (struct vdpa_map_file *)map->opaque; @@ -1263,7 +1341,7 @@ static long vduse_dev_ioctl(struct file *file, unsign= ed int cmd, entry.last =3D map->last; entry.perm =3D map->perm; } - spin_unlock(&dev->domain->iotlb_lock); + spin_unlock(&dev->domain[entry.asid]->iotlb_lock); mutex_unlock(&dev->domain_lock); ret =3D -EINVAL; if (!f) @@ -1413,12 +1491,16 @@ static long vduse_dev_ioctl(struct file *file, unsi= gned int cmd, break; =20 ret =3D -EINVAL; + /* TODO: Using asid from userspace, need to mitigate? */ if (!is_mem_zero((const char *)umem.reserved, - sizeof(umem.reserved))) + sizeof(umem.reserved)) || + (dev->api_version < VDUSE_API_VERSION_1 && + umem.asid !=3D 0) || + umem.asid > dev->nas) break; =20 mutex_lock(&dev->domain_lock); - ret =3D vduse_dev_reg_umem(dev, umem.iova, + ret =3D vduse_dev_reg_umem(dev, umem.asid, umem.iova, umem.uaddr, umem.size); mutex_unlock(&dev->domain_lock); break; @@ -1431,15 +1513,24 @@ static long vduse_dev_ioctl(struct file *file, unsi= gned int cmd, break; =20 ret =3D -EINVAL; + /* TODO: Using asid from userspace, need to mitigate? */ if (!is_mem_zero((const char *)umem.reserved, - sizeof(umem.reserved))) + sizeof(umem.reserved)) || + (dev->api_version < VDUSE_API_VERSION_1 && + umem.asid !=3D 0) || + umem.asid > dev->nas) + break; + + + if (umem.asid > dev->nas) break; mutex_lock(&dev->domain_lock); - ret =3D vduse_dev_dereg_umem(dev, umem.iova, + ret =3D vduse_dev_dereg_umem(dev, umem.asid, umem.iova, umem.size); mutex_unlock(&dev->domain_lock); break; } + /* TODO can we merge this with GET_FD? */ case VDUSE_IOTLB_GET_INFO: { struct vduse_iova_info info; struct vhost_iotlb_map *map; @@ -1452,27 +1543,32 @@ static long vduse_dev_ioctl(struct file *file, unsi= gned int cmd, if (info.start > info.last) break; =20 + if (info.asid > dev->nas) + break; + if (!is_mem_zero((const char *)info.reserved, sizeof(info.reserved))) break; =20 mutex_lock(&dev->domain_lock); - if (!dev->domain) { + /* TODO asid comes from userspace. mitigations? */ + if (!dev->domain[info.asid]) { mutex_unlock(&dev->domain_lock); break; } - spin_lock(&dev->domain->iotlb_lock); - map =3D vhost_iotlb_itree_first(dev->domain->iotlb, + spin_lock(&dev->domain[info.asid]->iotlb_lock); + map =3D vhost_iotlb_itree_first(dev->domain[info.asid]->iotlb, info.start, info.last); if (map) { info.start =3D map->start; info.last =3D map->last; info.capability =3D 0; - if (dev->domain->bounce_map && map->start =3D=3D 0 && - map->last =3D=3D dev->domain->bounce_size - 1) + if (dev->domain[info.asid]->bounce_map && + map->start =3D=3D 0 && + map->last =3D=3D dev->domain[info.asid]->bounce_size - 1) info.capability |=3D VDUSE_IOVA_CAP_UMEM; } - spin_unlock(&dev->domain->iotlb_lock); + spin_unlock(&dev->domain[info.asid]->iotlb_lock); mutex_unlock(&dev->domain_lock); if (!map) break; @@ -1497,8 +1593,13 @@ static int vduse_dev_release(struct inode *inode, st= ruct file *file) struct vduse_dev *dev =3D file->private_data; =20 mutex_lock(&dev->domain_lock); - if (dev->domain) - vduse_dev_dereg_umem(dev, 0, dev->domain->bounce_size); + for (int i =3D 0; i < dev->nas; i++) { + if (dev->domain[i]) { + vduse_dev_dereg_umem(dev, i, 0, + dev->domain[i]->bounce_size); + dev->domain[i] =3D NULL; + } + } mutex_unlock(&dev->domain_lock); spin_lock(&dev->msg_lock); /* Make sure the inflight messages can processed after reconncection */ @@ -1768,9 +1869,12 @@ static int vduse_destroy_dev(char *name) idr_remove(&vduse_idr, dev->minor); kvfree(dev->config); vduse_dev_deinit_vqs(dev); - if (dev->domain) - vduse_domain_destroy(dev->domain); + for (int i =3D 0; i < dev->nas; i++) { + if (dev->domain[i]) + vduse_domain_destroy(dev->domain[i]); + } kfree(dev->name); + kfree(dev->umem); vduse_dev_destroy(dev); module_put(THIS_MODULE); =20 @@ -1877,7 +1981,8 @@ static ssize_t bounce_size_store(struct device *devic= e, =20 ret =3D -EPERM; mutex_lock(&dev->domain_lock); - if (dev->domain) + /* Assuming that if the first domain is allocated, all are allocated */ + if (dev->domain[0]) goto unlock; =20 ret =3D kstrtouint(buf, 10, &bounce_size); @@ -1933,11 +2038,20 @@ static int vduse_create_dev(struct vduse_dev_config= *config, if (config->ngroups > VDUSE_MAX_VQ_GROUPS) { pr_err("Not creating a VDUSE device with %u vq groups. Max: %u", config->ngroups, VDUSE_MAX_VQ_GROUPS); + /* TODO: Need to destroy dev here too! */ goto err; } + if (config->nas > VDUSE_MAX_ASID) { + pr_err("Not creating a VDUSE device with %u asid. Max: %u", + config->nas, VDUSE_MAX_ASID); + goto err_nas; + } + dev->ngroups =3D config->ngroups ?: 1; + dev->nas =3D config->nas ?: 1; } else { dev->ngroups =3D 1; + dev->nas =3D 1; } for (u32 i =3D 0; i < dev->ngroups; ++i) dev->groups[i].dev =3D dev; @@ -1977,6 +2091,7 @@ static int vduse_create_dev(struct vduse_dev_config *= config, err_idr: kfree(dev->name); err_str: +err_nas: vduse_dev_destroy(dev); err: return ret; @@ -2069,7 +2184,6 @@ static int vduse_open(struct inode *inode, struct fil= e *file) if (!control) return -ENOMEM; =20 - control->api_version =3D VDUSE_API_VERSION; file->private_data =3D control; =20 return 0; @@ -2101,7 +2215,7 @@ static int vduse_dev_init_vdpa(struct vduse_dev *dev,= const char *name) =20 vdev =3D vdpa_alloc_device(struct vduse_vdpa, vdpa, dev->dev, &vduse_vdpa_config_ops, &vduse_map_ops, - dev->ngroups, 1, name, true); + dev->ngroups, dev->nas, name, true); if (IS_ERR(vdev)) return PTR_ERR(vdev); =20 @@ -2137,11 +2251,23 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev,= const char *name, return ret; =20 mutex_lock(&dev->domain_lock); - if (!dev->domain) - dev->domain =3D vduse_domain_create(VDUSE_IOVA_SIZE - 1, - dev->bounce_size); + ret =3D 0; + + /* TODO we could delay the creation of the domain */ + for (int i =3D 0; i < dev->nas; ++i) { + if (!dev->domain[i]) + dev->domain[i] =3D vduse_domain_create(VDUSE_IOVA_SIZE - 1, + dev->bounce_size); + if (!dev->domain[i]) { + ret =3D -ENOMEM; + for (int j =3D 0; j < i; ++j) + vduse_domain_destroy(dev->domain[j]); + goto err_domain; + } + } + mutex_unlock(&dev->domain_lock); - if (!dev->domain) { + if (ret =3D=3D -ENOMEM) { put_device(&dev->vdev->vdpa.dev); return -ENOMEM; } @@ -2150,13 +2276,22 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev,= const char *name, if (ret) { put_device(&dev->vdev->vdpa.dev); mutex_lock(&dev->domain_lock); - vduse_domain_destroy(dev->domain); - dev->domain =3D NULL; + for (int i =3D 0; i < dev->nas; i++) { + if (dev->domain[i]) { + vduse_domain_destroy(dev->domain[i]); + dev->domain[i] =3D NULL; + } + } mutex_unlock(&dev->domain_lock); return ret; } =20 return 0; + +err_domain: + /* TODO do I need to call put_device? */ + mutex_unlock(&dev->domain_lock); + return ret; } =20 static void vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *d= ev) diff --git a/include/uapi/linux/vduse.h b/include/uapi/linux/vduse.h index b4b139dc76bb..d300fd5f867f 100644 --- a/include/uapi/linux/vduse.h +++ b/include/uapi/linux/vduse.h @@ -47,7 +47,8 @@ struct vduse_dev_config { __u32 vq_num; __u32 vq_align; __u32 ngroups; /* if VDUSE_API_VERSION >=3D 1 */ - __u32 reserved[12]; + __u32 nas; /* if VDUSE_API_VERSION >=3D 1 */ + __u32 reserved[11]; __u32 config_size; __u8 config[]; }; @@ -82,6 +83,17 @@ struct vduse_iotlb_entry { __u8 perm; }; =20 +struct vduse_iotlb_entry_v2 { + __u64 offset; + __u64 start; + __u64 last; +#define VDUSE_ACCESS_RO 0x1 +#define VDUSE_ACCESS_WO 0x2 +#define VDUSE_ACCESS_RW 0x3 + __u8 perm; + __u32 asid; +}; + /* * Find the first IOVA region that overlaps with the range [start, last] * and return the corresponding file descriptor. Return -EINVAL means the @@ -172,6 +184,16 @@ struct vduse_vq_group { __u32 num; }; =20 +/** + * struct vduse_vq_group - virtqueue group + @ @group: Index of the virtqueue group + * @asid: Address space ID of the group + */ +struct vduse_vq_group_asid { + __u32 group; + __u32 asid; +}; + /** * struct vduse_vq_info - information of a virtqueue * @index: virtqueue index @@ -232,6 +254,7 @@ struct vduse_vq_eventfd { * @uaddr: start address of userspace memory, it must be aligned to page s= ize * @iova: start of the IOVA region * @size: size of the IOVA region + * @asid: Address space ID of the IOVA region * @reserved: for future use, needs to be initialized to zero * * Structure used by VDUSE_IOTLB_REG_UMEM and VDUSE_IOTLB_DEREG_UMEM @@ -241,7 +264,8 @@ struct vduse_iova_umem { __u64 uaddr; __u64 iova; __u64 size; - __u64 reserved[3]; + __u32 asid; + __u32 reserved[5]; }; =20 /* Register userspace memory for IOVA regions */ @@ -265,7 +289,8 @@ struct vduse_iova_info { __u64 last; #define VDUSE_IOVA_CAP_UMEM (1 << 0) __u64 capability; - __u64 reserved[3]; + __u32 asid; /* Only if device API version >=3D 1 */ + __u32 reserved[5]; }; =20 /* @@ -289,6 +314,7 @@ enum vduse_req_type { VDUSE_UPDATE_IOTLB, VDUSE_GET_VQ_GROUP, VDUSE_GET_VRING_DESC_GROUP, + VDUSE_SET_VQ_GROUP_ASID, }; =20 /** @@ -344,6 +370,8 @@ struct vduse_dev_request { struct vduse_dev_status s; struct vduse_iova_range iova; struct vduse_vq_group vq_group; /* Only if vduse api version >=3D 1 */ + /* Only if vduse api version >=3D 1 */ + struct vduse_vq_group_asid vq_group_asid; __u32 padding[32]; }; }; @@ -367,6 +395,8 @@ struct vduse_dev_response { union { struct vduse_vq_state vq_state; struct vduse_vq_group vq_group; /* Only if vduse api version >=3D 1 */ + /* Only if vduse api version >=3D 1 */ + struct vduse_vq_group_asid vq_group_asid; __u32 padding[32]; }; }; --=20 2.50.1 From nobody Tue Sep 2 09:48:12 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 E4A2F23ED6A for ; Thu, 7 Aug 2025 11:58:29 +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=1754567911; cv=none; b=kw+wrwsSKpBfijmdMDl1dQ0HkmjIm05/bd7SrHTOwPzO/MNAV5O0hkNQxU6IxQTMPh8o/a+Fv1exCh5eEgnTEgT/U/6/ufd47oQTnbpHpvIcUgPvFFR9jqBCp3dPoOm0nxPS3zAypA1ltyjQ2Nw6M7NIPqm05dENdvRymmOjy3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754567911; c=relaxed/simple; bh=bw4QieCdPyUE1mT+QXJIz6RfMf6JFswO943BPFYtrzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KR1apLl/dVlN9kIsmOlOHztdovt2A4cU0jkytWoPUuujEXDpFsif0LZiJvBDOw+yG7cMqiQxuzPxOBHwyWBNeFVe8PNue0JNz3P69Syd/Q9J16swei+7cV3ZAc4/p8i3eXYXEccNoAmjbymHWFqtE/TiWQ2Q6UB6Wkz6k4z21Zs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=HBIMWibA; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="HBIMWibA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754567908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uAWEzypwFXNY0V+CvTxfSM1d3goRg1trlUIPl5R5TMM=; b=HBIMWibAcwXXBGlWVh2LKXJuNIMMyEkkwkjNgrr4KgDUkQ4e6to6QSnhPOanABqNzroFOB rUmn6HB5H2DPdb0xUdkt4gqNjme1rnOuo35hTeRqzl00a4On5sxLpLdZAjZKXa0/nwxL27 +0ra/9HgPWSTSV+Y2xr0QHU6c5UWDGM= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-79-N8vLL0QbNjaVgUTx4rtwyA-1; Thu, 07 Aug 2025 07:58:27 -0400 X-MC-Unique: N8vLL0QbNjaVgUTx4rtwyA-1 X-Mimecast-MFC-AGG-ID: N8vLL0QbNjaVgUTx4rtwyA_1754567906 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 846E019560AA; Thu, 7 Aug 2025 11:58:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.48]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B2D713001456; Thu, 7 Aug 2025 11:58:22 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Cindy Lu , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Yongji Xie , Stefano Garzarella , virtualization@lists.linux.dev, Laurent Vivier , linux-kernel@vger.kernel.org, Xuan Zhuo , jasowang@redhat.com, Maxime Coquelin Subject: [RFC v2 6/7] vduse: send update_iotlb_v2 message Date: Thu, 7 Aug 2025 13:57:51 +0200 Message-ID: <20250807115752.1663383-7-eperezma@redhat.com> In-Reply-To: <20250807115752.1663383-1-eperezma@redhat.com> References: <20250807115752.1663383-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.30.177.4 This message lets the kernel notify userspace VDUSE backends about updated IOTLB mappings for a specific ASID. Signed-off-by: Eugenio P=C3=A9rez --- drivers/vdpa/vdpa_user/vduse_dev.c | 14 ++++++++++---- include/uapi/linux/vduse.h | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 145147c49930..ac7897068222 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -326,7 +326,7 @@ static int vduse_dev_set_status(struct vduse_dev *dev, = u8 status) return vduse_dev_msg_sync(dev, &msg); } =20 -static int vduse_dev_update_iotlb(struct vduse_dev *dev, +static int vduse_dev_update_iotlb(struct vduse_dev *dev, u32 asid, u64 start, u64 last) { struct vduse_dev_msg msg =3D { 0 }; @@ -335,8 +335,14 @@ static int vduse_dev_update_iotlb(struct vduse_dev *de= v, return -EINVAL; =20 msg.req.type =3D VDUSE_UPDATE_IOTLB; - msg.req.iova.start =3D start; - msg.req.iova.last =3D last; + if (dev->api_version < VDUSE_API_VERSION_1) { + msg.req.iova.start =3D start; + msg.req.iova.last =3D last; + } else { + msg.req.iova_v2.start =3D start; + msg.req.iova_v2.last =3D last; + msg.req.iova_v2.asid =3D asid; + } =20 return vduse_dev_msg_sync(dev, &msg); } @@ -882,7 +888,7 @@ static int vduse_vdpa_set_map(struct vdpa_device *vdpa, if (ret) return ret; =20 - ret =3D vduse_dev_update_iotlb(dev, 0ULL, ULLONG_MAX); + ret =3D vduse_dev_update_iotlb(dev, asid, 0ULL, ULLONG_MAX); if (ret) { vduse_domain_clear_map(dev->domain[asid], iotlb); return ret; diff --git a/include/uapi/linux/vduse.h b/include/uapi/linux/vduse.h index d300fd5f867f..a5f7a5edb8e0 100644 --- a/include/uapi/linux/vduse.h +++ b/include/uapi/linux/vduse.h @@ -349,6 +349,12 @@ struct vduse_iova_range { __u64 last; }; =20 +struct vduse_iova_range_v2 { + __u64 start; + __u64 last; + __u32 asid; +}; + /** * struct vduse_dev_request - control request * @type: request type @@ -369,6 +375,7 @@ struct vduse_dev_request { struct vduse_vq_state vq_state; struct vduse_dev_status s; struct vduse_iova_range iova; + struct vduse_iova_range_v2 iova_v2; struct vduse_vq_group vq_group; /* Only if vduse api version >=3D 1 */ /* Only if vduse api version >=3D 1 */ struct vduse_vq_group_asid vq_group_asid; --=20 2.50.1 From nobody Tue Sep 2 09:48:12 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 247E8252286 for ; Thu, 7 Aug 2025 11:58:36 +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=1754567919; cv=none; b=b7br5i3xJdCCObo2+WvQ7hKZ3ox9MhGlrLG6q1bE88hWanIEUCtAgtU0e9Ig8kPK6vipQsKLQk0XZqiQbAqJNeuVlVCdwfnxIbVm8+pjofa1SmmtwJtEmNbjhcs0NUCZFouGYwdTyidQFvHOn8FwxHFBwLLnhYC/hBSEKbYwLCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754567919; c=relaxed/simple; bh=7rSADgOu2+trUFzpxtJiFbpGsKxuatFOD7dqqDEe+4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oR/gr33HM28ljjWXlX8WggQ8jc1srzKsV30Mk4Tlho8Y6+29PsnSezd0JaUR8rFpru/mhXoDfDRFOjfi0pYoTKLXQC0ch3X709OhJw/YIQ/8qUoUC+4YJ9QpEylr1JAucBQVXQlv4EvLEytj6t0cFREMcff/q5DDpc1NwjzAVJs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=Q5q70vjv; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="Q5q70vjv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754567916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q3n2gIYs/JPJEOH+G25oxIwl1cnHRA2ZoDvWNB5kxAI=; b=Q5q70vjvOWpqd8bFukG4LEd+spNaxLnZqInd0R55COISevedETpcxTKIa/1cCtI1OPrTAh FF0ayVLtz2uEwcMAOiRUbs5lx3K9hmHyi0ZvR4n9m2bzXqNh3rmJAkh+CDj94gezED47FE bdqY+MaoQoZjhMlkgGMX48AcBr/p+ZA= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-pBBw4Gq7PO-lUcSFn_mgxg-1; Thu, 07 Aug 2025 07:58:32 -0400 X-MC-Unique: pBBw4Gq7PO-lUcSFn_mgxg-1 X-Mimecast-MFC-AGG-ID: pBBw4Gq7PO-lUcSFn_mgxg_1754567911 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.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 mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5BAA2180036E; Thu, 7 Aug 2025 11:58:31 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.48]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 16B793001452; Thu, 7 Aug 2025 11:58:26 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Cindy Lu , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Yongji Xie , Stefano Garzarella , virtualization@lists.linux.dev, Laurent Vivier , linux-kernel@vger.kernel.org, Xuan Zhuo , jasowang@redhat.com, Maxime Coquelin Subject: [RFC v2 7/7] vduse: bump version number Date: Thu, 7 Aug 2025 13:57:52 +0200 Message-ID: <20250807115752.1663383-8-eperezma@redhat.com> In-Reply-To: <20250807115752.1663383-1-eperezma@redhat.com> References: <20250807115752.1663383-1-eperezma@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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.30.177.4 Finalize the series by advertising VDUSE API v1 support to userspace. Now that all required infrastructure for v1 (ASIDs, VQ groups, update_iotlb_v2) is in place, VDUSE devices can opt in to the new features. Signed-off-by: Eugenio P=C3=A9rez --- drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index ac7897068222..cbbbaafa79a1 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -2123,7 +2123,7 @@ static long vduse_ioctl(struct file *file, unsigned i= nt cmd, break; =20 ret =3D -EINVAL; - if (api_version > VDUSE_API_VERSION) + if (api_version > VDUSE_API_VERSION_1) break; =20 ret =3D 0; @@ -2190,6 +2190,7 @@ static int vduse_open(struct inode *inode, struct fil= e *file) if (!control) return -ENOMEM; =20 + control->api_version =3D VDUSE_API_VERSION_1; file->private_data =3D control; =20 return 0; --=20 2.50.1