From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0A00948B4D; Wed, 19 Nov 2025 12:08:53 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF2F540687; Wed, 19 Nov 2025 12:08:32 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by mails.dpdk.org (Postfix) with ESMTP id 93D3040265 for ; Wed, 19 Nov 2025 12:08:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763550510; x=1795086510; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=RAC/x9wNmuqq7xYeMaQVsDNiNMVPZHgy7KHh5LP5i2s=; b=Es58MBnU/07CsdscyslUcbvPB37iVkKxh126LvbSfzSMeu6B5lV5Q5wU RFYP0kx1YwSA2tissqDxtCeyNoMBRdKQtBGP02SpK4mG0Y7lRKOcybRNm WmLi2YP1J2+FOsJ0MYVySxp6080Q7IjTz7SpnhhQcZMEaVSdDlXL8UrLu dNEuyiA+Oj95XA/IATgiISM7v86csQMB/rLvuv9DRyt9z+VxTR50rSE0X XI90moPG8ARL3gyPmoa0UFyMXENb6yPA8eh8GizZVcHN6/c0Ihv/V0bJW IJ5fEKB4M8g7AxqoFsVBMBLH7s4rsVfGtUlsWjfFpXBrTSqlPwpD5u3Th g==; X-CSE-ConnectionGUID: ENwL/GMGRreP9GM5nDL4oA== X-CSE-MsgGUID: 2mPQIy6eT1KYCLjxwzUXuA== X-IronPort-AV: E=McAfee;i="6800,10657,11617"; a="65744947" X-IronPort-AV: E=Sophos;i="6.19,315,1754982000"; d="scan'208";a="65744947" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2025 03:08:29 -0800 X-CSE-ConnectionGUID: bSobV5JYQbq59SWgV4Su7w== X-CSE-MsgGUID: 2NrPJZLwSGC9b45IIJdWkw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,315,1754982000"; d="scan'208";a="191158185" Received: from silpixa00401119.ir.intel.com ([10.20.224.206]) by orviesa008.jf.intel.com with ESMTP; 19 Nov 2025 03:08:28 -0800 From: Anatoly Burakov To: dev@dpdk.org, Bruce Richardson Subject: [PATCH v5 04/18] vfio: add container device assignment API Date: Wed, 19 Nov 2025 11:08:02 +0000 Message-ID: X-Mailer: git-send-email 2.47.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 `rte_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/freebsd/eal.c | 10 ++++++++++ lib/eal/include/rte_vfio.h | 26 ++++++++++++++++++++++++++ lib/eal/linux/eal_vfio.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index dea32ae428..a7360db7a7 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -936,3 +936,13 @@ rte_vfio_container_dma_unmap(__rte_unused int container_fd, rte_errno = ENOTSUP; return -1; } + +RTE_EXPORT_INTERNAL_SYMBOL(rte_vfio_container_assign_device) +int +rte_vfio_container_assign_device(__rte_unused int vfio_container_fd, + __rte_unused const char *sysfs_base, + __rte_unused const char *dev_addr) +{ + rte_errno = ENOTSUP; + return -1; +} diff --git a/lib/eal/include/rte_vfio.h b/lib/eal/include/rte_vfio.h index fb666141f6..e7e2ee950b 100644 --- a/lib/eal/include/rte_vfio.h +++ b/lib/eal/include/rte_vfio.h @@ -271,6 +271,32 @@ __rte_internal int rte_vfio_container_destroy(int container_fd); +/** + * @internal + * + * Assign a device to a VFIO container. + * + * Doing so will cause `rte_vfio_setup_device()` to set up the device with the VFIO container + * specified in this assign operation. + * + * This function is only relevant on Linux. + * + * @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_errno is set. + */ +__rte_internal +int +rte_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base, + const char *dev_addr); + /** * @internal * Bind a IOMMU group to a container. diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c index 47c973e49a..02fec64658 100644 --- a/lib/eal/linux/eal_vfio.c +++ b/lib/eal/linux/eal_vfio.c @@ -2102,6 +2102,38 @@ rte_vfio_container_destroy(int container_fd) return 0; } +RTE_EXPORT_INTERNAL_SYMBOL(rte_vfio_container_assign_device) +int +rte_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base, + const char *dev_addr) +{ + int iommu_group_num; + int ret; + + ret = rte_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 = rte_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(rte_vfio_container_group_bind) int rte_vfio_container_group_bind(int container_fd, int iommu_group_num) -- 2.47.3