From patchwork Tue Mar 5 13:59:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahaf Shuler X-Patchwork-Id: 50814 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 42D5D2BF2; Tue, 5 Mar 2019 15:00:02 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id B3C152B9E for ; Tue, 5 Mar 2019 15:00:00 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 5 Mar 2019 15:59:56 +0200 Received: from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx [10.7.12.62]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x25DxtO9012489; Tue, 5 Mar 2019 15:59:55 +0200 From: Shahaf Shuler To: anatoly.burakov@intel.com, yskoh@mellanox.com, thomas@monjalon.net, ferruh.yigit@intel.com, nhorman@tuxdriver.com, gaetan.rivet@6wind.com Cc: dev@dpdk.org Date: Tue, 5 Mar 2019 15:59:41 +0200 Message-Id: X-Mailer: git-send-email 2.12.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 1/6] vfio: allow DMA map of memory for the default vfio fd X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Enable users the option to call rte_vfio_dma_map with request to map to the default vfio fd. Signed-off-by: Shahaf Shuler Acked-by: Anatoly Burakov --- doc/guides/rel_notes/release_19_05.rst | 3 +++ lib/librte_eal/common/include/rte_vfio.h | 8 ++++++-- lib/librte_eal/linuxapp/eal/eal_vfio.c | 10 ++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/guides/rel_notes/release_19_05.rst b/doc/guides/rel_notes/release_19_05.rst index 4a3e2a7f31..b02753bbc4 100644 --- a/doc/guides/rel_notes/release_19_05.rst +++ b/doc/guides/rel_notes/release_19_05.rst @@ -122,6 +122,9 @@ ABI Changes Also, make sure to start the actual text at the margin. ========================================================= +* vfio: Functions ``rte_vfio_container_dma_map`` and + ``rte_vfio_container_dma_unmap`` have been extended with an option to + request mapping or un-mapping to the default vfio container fd. Shared Library Versions ----------------------- diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index cae96fab90..cdfbedc1f9 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -80,6 +80,8 @@ struct vfio_device_info; #endif /* VFIO_PRESENT */ +#define RTE_VFIO_DEFAULT_CONTAINER_FD (-1) + /** * Setup vfio_cfg for the device identified by its address. * It discovers the configured I/O MMU groups or sets a new one for the device. @@ -347,7 +349,8 @@ rte_vfio_container_group_unbind(int container_fd, int iommu_group_num); * Perform DMA mapping for devices in a container. * * @param container_fd - * the specified container fd + * the specified container fd. Use RTE_VFIO_DEFAULT_CONTAINER_FD to + * use the default container. * * @param vaddr * Starting virtual address of memory to be mapped. @@ -370,7 +373,8 @@ rte_vfio_container_dma_map(int container_fd, uint64_t vaddr, * Perform DMA unmapping for devices in a container. * * @param container_fd - * the specified container fd + * the specified container fd. Use RTE_VFIO_DEFAULT_CONTAINER_FD to + * use the default container. * * @param vaddr * Starting virtual address of memory to be unmapped. diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index c821e83826..9adbda8bb7 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -1897,7 +1897,10 @@ rte_vfio_container_dma_map(int container_fd, uint64_t vaddr, uint64_t iova, return -1; } - vfio_cfg = get_vfio_cfg_by_container_fd(container_fd); + if (container_fd == RTE_VFIO_DEFAULT_CONTAINER_FD) + vfio_cfg = default_vfio_cfg; + else + vfio_cfg = get_vfio_cfg_by_container_fd(container_fd); if (vfio_cfg == NULL) { RTE_LOG(ERR, EAL, "Invalid container fd\n"); return -1; @@ -1917,7 +1920,10 @@ rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, return -1; } - vfio_cfg = get_vfio_cfg_by_container_fd(container_fd); + if (container_fd == RTE_VFIO_DEFAULT_CONTAINER_FD) + vfio_cfg = default_vfio_cfg; + else + vfio_cfg = get_vfio_cfg_by_container_fd(container_fd); if (vfio_cfg == NULL) { RTE_LOG(ERR, EAL, "Invalid container fd\n"); return -1;