From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DC06CA5FFF for ; Wed, 7 Oct 2026 07:33:16 +0000 (UTC) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D157342DB1; Wed, 7 Oct 2026 09:32:54 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id B163242DDC for ; Wed, 7 Oct 2026 09:32:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791358373; 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=UPr0ZgLiwl1MiOulHC2KbBNU2uvhVzDBdEnezdT87IY=; b=U28Zn7KPjrQdy3Oq4BS/Rw1VFwUTWEO9dUswV6e5lbHtzQINyWESjqkgDWBANFumZXL9gT YkjbBUgnZRWFmgjCfUJPp7HTDd3F+u2OFqL7JI8f5keoA6pRyZ7MmLkcGSojfOJj1uGko/ pAOFfo9OzidFoDPhHyNFnF9AJAF9BdU= 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-685-qSZkRoElN5eU2LCJDMKv2w-1; Wed, 07 Oct 2026 03:32:52 -0400 X-MC-Unique: qSZkRoElN5eU2LCJDMKv2w-1 X-Mimecast-MFC-AGG-ID: qSZkRoElN5eU2LCJDMKv2w_1791358371 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 343121802577; Wed, 7 Oct 2026 07:32:51 +0000 (UTC) Received: from dmarchan.redhat.corp (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3A0303001D2A; Wed, 7 Oct 2026 07:32:50 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Anatoly Burakov Subject: [PATCH v19 10/26] vfio: add container device assignment API Date: Wed, 7 Oct 2026 09:31:48 +0200 Message-ID: <20261007073206.567001-11-david.marchand@redhat.com> In-Reply-To: <20261007073206.567001-1-david.marchand@redhat.com> References: <20261007073206.567001-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: p5dX6Gf2nNgnQVrJmOXJqAbI8Cb8brV1qQxK3CF03lc_1791358371 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Anatoly Burakov Currently, VFIO has explicit group bind API's, but the way they're used is such that no one actually cares about VFIO groups, and the real goal of everyone using VFIO group bind API is to bind devices to particular VFIO container, such that when `dev_vfio_setup_device` call eventually comes, VFIO will pick up the correct container. To remove dependency on group API's, add a new "container assign device" API call that will do the same thing, but will not depend on managing VFIO group fd's. Signed-off-by: Anatoly Burakov --- lib/eal/linux/eal_vfio.c | 27 +++++++++++++++++++++++++++ lib/eal/linux/include/dev_vfio.h | 24 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c index 9148f2c156..d6a6e2d30a 100644 --- a/lib/eal/linux/eal_vfio.c +++ b/lib/eal/linux/eal_vfio.c @@ -2188,6 +2188,33 @@ dev_vfio_container_destroy(int container_fd) return 0; } +RTE_EXPORT_INTERNAL_SYMBOL(dev_vfio_container_assign_device) +int +dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base, + const char *dev_addr) +{ + int iommu_group_num; + int ret; + + ret = dev_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_num); + if (ret < 0) { + EAL_LOG(ERR, "Cannot get IOMMU group number for device %s", dev_addr); + return -1; + } else if (ret == 0) { + EAL_LOG(ERR, "Device %s is not assigned to any IOMMU group", dev_addr); + return -1; + } + + ret = dev_vfio_container_group_bind(vfio_container_fd, iommu_group_num); + if (ret < 0) { + EAL_LOG(ERR, "Cannot bind IOMMU group %d for device %s", iommu_group_num, + dev_addr); + return -1; + } + + return 0; +} + RTE_EXPORT_INTERNAL_SYMBOL(dev_vfio_container_group_bind) int dev_vfio_container_group_bind(int container_fd, int iommu_group_num) diff --git a/lib/eal/linux/include/dev_vfio.h b/lib/eal/linux/include/dev_vfio.h index a0ca51f34c..e7ac17fb9a 100644 --- a/lib/eal/linux/include/dev_vfio.h +++ b/lib/eal/linux/include/dev_vfio.h @@ -264,6 +264,30 @@ __rte_internal int dev_vfio_container_destroy(int container_fd); +/** + * @internal + * + * Assign a device to a VFIO container. + * + * Doing so will cause `dev_vfio_setup_device()` call to set up the device with + * the VFIO container specified in this assign operation. + * + * @param vfio_container_fd + * VFIO container file descriptor. + * @param sysfs_base + * Sysfs path prefix. + * @param dev_addr + * Device identifier. + * + * @return + * 0 on success. + * <0 on failure. + */ +__rte_internal +int +dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base, + const char *dev_addr); + /** * @internal * Bind a IOMMU group to a container. -- 2.54.0