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 DD3704555B; Wed, 3 Jul 2024 10:21:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B94224029B; Wed, 3 Jul 2024 10:21:28 +0200 (CEST) Received: from lf-2-31.ptr.blmpb.com (lf-2-31.ptr.blmpb.com [101.36.218.31]) by mails.dpdk.org (Postfix) with ESMTP id A6E974003C for ; Wed, 3 Jul 2024 07:42:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=dayudpu-com.20200927.dkim.feishu.cn; t=1719985327; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=e777oHddi+zWtpGV/mh0TaPkfjfzN58pnauizQIrz1w=; b=x75Cg8ZXyuoLzcS++yil0Oii7cFZy7PZe6XqIvSAaIDIaFb8xoJjbVVAprJUkkLQ3x5dU4 DCU1+oW1INiuJZnEKgklUFSfmHbvPs+r+oFYpV6dpvGTSHViHG4PGN67PsQphUzJlOLWBg lNeGKJ/cQQADqcKGQQlBx1wOwX4eYRYRajj4kumA0gdHI13EVazJt2TT299SFNrY1nffVE jpMtxzZ8mXZXRl01J6GX1WW8kvZQH2RkGBIPRJHmMubk9y07QKDM1OGRvFhpLlRy0fexrb ltJMstP8Ix2kn1sQ4tCERJFqZMeJMpuykKclRg2pYy3WGDblqJKy8OlTDkAXHg== X-Lms-Return-Path: Content-Type: text/plain; charset=UTF-8 X-Original-From: xiangwencheng@dayudpu.com Cc: , "BillXiang" From: "BillXiang" Subject: [PATCH] vfio: combine container_create and group_bind Message-Id: <20240703054124.89490-1-xiangwencheng@dayudpu.com> Received: from localhost.localdomain ([124.64.23.180]) by smtp.feishu.cn with ESMTPS; Wed, 03 Jul 2024 13:42:06 +0800 Date: Wed, 3 Jul 2024 13:41:24 +0800 X-Mailer: git-send-email 2.30.0 To: "Tyler Retzlaff" , "Anatoly Burakov" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Wed, 03 Jul 2024 10:21:28 +0200 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: BillXiang For multi-devices in one group we can only create and bind to one container. With this new function, device driver does not need to save the binding info additionally between different devices. Signed-off-by: BillXiang --- lib/eal/include/rte_vfio.h | 16 ++++++++++++++++ lib/eal/linux/eal_vfio.c | 24 ++++++++++++++++++++++++ lib/eal/version.map | 1 + 3 files changed, 41 insertions(+) diff --git a/lib/eal/include/rte_vfio.h b/lib/eal/include/rte_vfio.h index b774625d9f..4ad4e256ed 100644 --- a/lib/eal/include/rte_vfio.h +++ b/lib/eal/include/rte_vfio.h @@ -407,6 +407,22 @@ int rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len); +/** + * Get vfio group fd bound with container fd for certain iommu group. + * + * @param iommu_group_num + * iommu group num + * @param vfio_group_fd + * vfio group fd of the iommu group. + * @param vfio_container_fd + * vfio container fd of the iommu group. + * @return + * 0 if successful + * <0 if failed + */ +int +rte_vfio_get_fd(int iommu_group_num, int *vfio_group_fd, int *vfio_container_fd); + #ifdef __cplusplus } #endif diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c index 4e69e72e3b..b22502a930 100644 --- a/lib/eal/linux/eal_vfio.c +++ b/lib/eal/linux/eal_vfio.c @@ -2196,3 +2196,27 @@ rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, return container_dma_unmap(vfio_cfg, vaddr, iova, len); } + +int +rte_vfio_get_fd(int iommu_group_num, int *vfio_group_fd, int *vfio_container_fd) +{ + struct vfio_config *vfio_cfg; + vfio_cfg = get_vfio_cfg_by_group_num(iommu_group_num); + /* do not create new container if the group has bound with one */ + if (vfio_cfg) { + *vfio_container_fd = vfio_cfg->vfio_container_fd; + } else { + *vfio_container_fd = rte_vfio_container_create(); + if (*vfio_container_fd < 0) + goto err; + + vfio_cfg = get_vfio_cfg_by_container_fd(*vfio_container_fd); + } + *vfio_group_fd = vfio_get_group_fd(vfio_cfg, iommu_group_num); + if (*vfio_group_fd < 0) + goto err; + + return 0; +err: + return -1; +} diff --git a/lib/eal/version.map b/lib/eal/version.map index 3df50c3fbb..447fdd0af2 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -338,6 +338,7 @@ DPDK_24 { rte_vfio_noiommu_is_enabled; # WINDOWS_NO_EXPORT rte_vfio_release_device; # WINDOWS_NO_EXPORT rte_vfio_setup_device; # WINDOWS_NO_EXPORT + rte_vfio_get_fd; rte_zmalloc; rte_zmalloc_socket; -- 2.30.0