From nobody Thu Oct 2 14:24:04 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 70DCC315D4F for ; Tue, 16 Sep 2025 13:09:05 +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=1758028147; cv=none; b=pewXLULGmDeCZiKS68DKFsHtjq3rJ/hRmrXy2LZFFMco8YYI2BDCwCx03RY31NbUEAzqsjEGn/9H8+9sAhe9AU6j4RlQNt3co1ZBFXJ/TH6+dIXhyW2itTgCKvtcC6ZCuhdInbwAfCeSk9EOrhCLUFisrdyeiwKXYpZmSak3D9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758028147; c=relaxed/simple; bh=zMKnyo4BN62BGD/izcadd9bdD37sncHp2t+/amkV5dM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a/FiAzZZvRLMo8Sk8yRi/1vUpFeXNQplOrYAFXsPVphcxT/YZqwB7uDXhXXbrZjf6K5etxqC0Ib5/akKeeIKXVfHBS25PNh8LpqQZ6MaTlfGJGoOPZFv/7UpcZXmGalVoRMbU2axpdXR/uvQx/UUJf0VreBW1FoeuCtJ7ECZFsg= 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=cIZa3K8f; 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="cIZa3K8f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758028144; 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=ggikySRi5r73RkJ4ALYw3GYJq0PuR1mbjE1EBaHQaMA=; b=cIZa3K8ffSJYZ3qprZgg+MZluACpz32q/ZQ6JlBiPAAshf4v/aqT93FGz5LeVU6UZy0RnN YS8+62fGScdjhli3zUirDA3dxPKFV+pgxFSR+hQ5dGqUY7CI60LZzwNM0LWBn8pJk9HIih wv38IMZGaGH2PS4cUoIVBcm+NzmyThk= 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-367-pjDG12efPxKZv4DlrkMKGg-1; Tue, 16 Sep 2025 09:09:02 -0400 X-MC-Unique: pjDG12efPxKZv4DlrkMKGg-1 X-Mimecast-MFC-AGG-ID: pjDG12efPxKZv4DlrkMKGg_1758028142 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 B3523180058A; Tue, 16 Sep 2025 13:09:01 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.34.12]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5165819560B8; Tue, 16 Sep 2025 13:08:57 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S . Tsirkin " Cc: Stefano Garzarella , jasowang@redhat.com, Xuan Zhuo , linux-kernel@vger.kernel.org, Maxime Coquelin , Yongji Xie , Cindy Lu , Laurent Vivier , virtualization@lists.linux.dev, =?UTF-8?q?Eugenio=20P=C3=A9rez?= Subject: [PATCH v2 4/7] vduse: return internal vq group struct as map token Date: Tue, 16 Sep 2025 15:08:30 +0200 Message-ID: <20250916130833.329087-5-eperezma@redhat.com> In-Reply-To: <20250916130833.329087-1-eperezma@redhat.com> References: <20250916130833.329087-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.0 on 10.30.177.12 Return the internal struct that represents the vq group as virtqueue map token, instead of the device. This allows the map 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 --- RFC v3: * Make the vq groups a dynamic array to support an arbitrary number of them. --- drivers/vdpa/vdpa_user/vduse_dev.c | 52 ++++++++++++++++++++++++------ include/linux/virtio.h | 6 ++-- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vd= use_dev.c index 42f8807911d4..9c12ae72abc2 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -85,6 +86,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; @@ -118,6 +123,7 @@ struct vduse_dev { u32 vq_align; u32 ngroups; struct vduse_umem *umem; + struct vduse_vq_group_int *groups; struct mutex mem_lock; unsigned int bounce_size; rwlock_t domain_lock; @@ -602,6 +608,15 @@ static u32 vduse_get_vq_group(struct vdpa_device *vdpa= , u16 idx) return dev->vqs[idx]->vq_group; } =20 +static union virtio_map vduse_get_vq_map(struct vdpa_device *vdpa, u16 idx) +{ + struct vduse_dev *dev =3D vdpa_to_vduse(vdpa); + u32 vq_group =3D dev->vqs[idx]->vq_group; + union virtio_map ret =3D { .group =3D &dev->groups[vq_group] }; + + return ret; +} + static int vduse_vdpa_get_vq_state(struct vdpa_device *vdpa, u16 idx, struct vdpa_vq_state *state) { @@ -822,6 +837,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 =3D vduse_get_vq_map, .free =3D vduse_vdpa_free, }; =20 @@ -829,7 +845,8 @@ static void vduse_dev_sync_single_for_device(union virt= io_map token, dma_addr_t dma_addr, size_t size, enum dma_data_direction dir) { - struct vduse_iova_domain *domain =3D token.iova_domain; + struct vduse_dev *vdev =3D token.group->dev; + struct vduse_iova_domain *domain =3D vdev->domain; =20 vduse_domain_sync_single_for_device(domain, dma_addr, size, dir); } @@ -838,7 +855,8 @@ static void vduse_dev_sync_single_for_cpu(union virtio_= map token, dma_addr_t dma_addr, size_t size, enum dma_data_direction dir) { - struct vduse_iova_domain *domain =3D token.iova_domain; + struct vduse_dev *vdev =3D token.group->dev; + struct vduse_iova_domain *domain =3D vdev->domain; =20 vduse_domain_sync_single_for_cpu(domain, dma_addr, size, dir); } @@ -848,7 +866,8 @@ static dma_addr_t vduse_dev_map_page(union virtio_map t= oken, struct page *page, enum dma_data_direction dir, unsigned long attrs) { - struct vduse_iova_domain *domain =3D token.iova_domain; + struct vduse_dev *vdev =3D token.group->dev; + struct vduse_iova_domain *domain =3D vdev->domain; =20 return vduse_domain_map_page(domain, page, offset, size, dir, attrs); } @@ -857,7 +876,8 @@ static void vduse_dev_unmap_page(union virtio_map token= , dma_addr_t dma_addr, size_t size, enum dma_data_direction dir, unsigned long attrs) { - struct vduse_iova_domain *domain =3D token.iova_domain; + struct vduse_dev *vdev =3D token.group->dev; + struct vduse_iova_domain *domain =3D vdev->domain; =20 return vduse_domain_unmap_page(domain, dma_addr, size, dir, attrs); } @@ -865,7 +885,8 @@ static void vduse_dev_unmap_page(union virtio_map token= , dma_addr_t dma_addr, static void *vduse_dev_alloc_coherent(union virtio_map token, size_t size, dma_addr_t *dma_addr, gfp_t flag) { - struct vduse_iova_domain *domain =3D token.iova_domain; + struct vduse_dev *vdev =3D token.group->dev; + struct vduse_iova_domain *domain =3D vdev->domain; unsigned long iova; void *addr; =20 @@ -884,14 +905,16 @@ static void vduse_dev_free_coherent(union virtio_map = token, size_t size, void *vaddr, dma_addr_t dma_addr, unsigned long attrs) { - struct vduse_iova_domain *domain =3D token.iova_domain; + struct vduse_dev *vdev =3D token.group->dev; + struct vduse_iova_domain *domain =3D vdev->domain; =20 vduse_domain_free_coherent(domain, size, vaddr, dma_addr, attrs); } =20 static bool vduse_dev_need_sync(union virtio_map token, dma_addr_t dma_add= r) { - struct vduse_iova_domain *domain =3D token.iova_domain; + struct vduse_dev *vdev =3D token.group->dev; + struct vduse_iova_domain *domain =3D vdev->domain; =20 return dma_addr < domain->bounce_size; } @@ -905,7 +928,8 @@ static int vduse_dev_mapping_error(union virtio_map tok= en, dma_addr_t dma_addr) =20 static size_t vduse_dev_max_mapping_size(union virtio_map token) { - struct vduse_iova_domain *domain =3D token.iova_domain; + struct vduse_dev *vdev =3D token.group->dev; + struct vduse_iova_domain *domain =3D vdev->domain; =20 return domain->bounce_size; } @@ -1720,6 +1744,7 @@ static int vduse_destroy_dev(char *name) if (dev->domain) vduse_domain_destroy(dev->domain); kfree(dev->name); + kfree(dev->groups); vduse_dev_destroy(dev); module_put(THIS_MODULE); =20 @@ -1885,7 +1910,15 @@ 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; + dev->ngroups =3D (dev->api_version < 1) ? 1 : (config->ngroups ?: 1); + dev->groups =3D kcalloc(dev->ngroups, sizeof(dev->groups[0]), + GFP_KERNEL); + if (!dev->groups) + goto err_vq_groups; + 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; @@ -1922,6 +1955,8 @@ static int vduse_create_dev(struct vduse_dev_config *= config, err_idr: kfree(dev->name); err_str: + kfree(dev->groups); +err_vq_groups: vduse_dev_destroy(dev); err: return ret; @@ -2083,7 +2118,6 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, c= onst char *name, return -ENOMEM; } =20 - dev->vdev->vdpa.vmap.iova_domain =3D dev->domain; ret =3D _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num); if (ret) { put_device(&dev->vdev->vdpa.dev); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 96c66126c074..5f8db75f7833 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -41,13 +41,13 @@ struct virtqueue { void *priv; }; =20 -struct vduse_iova_domain; +struct vduse_vq_group_int; =20 union virtio_map { /* Device that performs DMA */ struct device *dma_dev; - /* VDUSE specific mapping data */ - struct vduse_iova_domain *iova_domain; + /* VDUSE specific virtqueue group for doing map */ + struct vduse_vq_group_int *group; }; =20 int virtqueue_add_outbuf(struct virtqueue *vq, --=20 2.51.0