Support VFIO cdev API in DPDK
Subsystems (5)
PATCH v19 6/26 vfio: make all functions internal
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The VFIO API is an externally exported API because the original intent was to offer DMA mapping facilities to applications. However, practical usage of this API seems to be centered around drivers, so keeping this API exported to applications only creates needless API/ABI stability surface that has no added value.
While at it, this API is still named with an rte_ prefix, which implies public API. To reflect the fact that this API is no longer public, rename all symbols and macros from rte_/RTE_ to dev_/DEV_, and adjust all callers.
---
Changes since v18:
- squashed with the prefix rte_vfio_ -> dev_vfio_ change,
---
doc/api/doxy-api-index.md | 3 +-
doc/guides/rel_notes/deprecation.rst | 6 -
doc/guides/rel_notes/release_26_11.rst | 4 +
drivers/bus/cdx/cdx.c | 6 +-
drivers/bus/cdx/cdx_vfio.c | 14 +--
drivers/bus/fslmc/fslmc_bus.c | 4 +-
drivers/bus/fslmc/fslmc_vfio.c | 12 +-
drivers/bus/pci/linux/pci.c | 8 +-
drivers/bus/pci/linux/pci_vfio.c | 38 +++---
drivers/bus/platform/platform.c | 10 +-
drivers/crypto/bcmfs/bcmfs_vfio.c | 8 +-
drivers/net/hinic3/base/hinic3_hwdev.c | 4 +-
drivers/net/nbl/nbl_common/nbl_userdev.c | 16 +--
drivers/net/ntnic/ntnic_ethdev.c | 4 +-
drivers/net/ntnic/ntnic_vfio.c | 22 ++--
drivers/vdpa/ifc/ifcvf_vdpa.c | 24 ++--
drivers/vdpa/nfp/nfp_vdpa.c | 24 ++--
drivers/vdpa/sfc/sfc_vdpa.c | 16 +--
drivers/vdpa/sfc/sfc_vdpa_hw.c | 12 +-
lib/eal/linux/eal.c | 4 +-
lib/eal/linux/eal_vfio.c | 116 +++++++++---------
lib/eal/linux/eal_vfio_mp_sync.c | 6 +-
.../linux/include/{rte_vfio.h => dev_vfio.h} | 104 ++++++++++------
lib/eal/linux/include/meson.build | 5 +-
lib/vhost/socket.c | 4 +-
lib/vhost/vhost_user.c | 6 +-
26 files changed, 256 insertions(+), 224 deletions(-)
rename lib/eal/linux/include/{rte_vfio.h => dev_vfio.h} (68%)doc/api/doxy-api-index.md +1 -2
@@ -37,8 +37,7 @@ The public API headers are grouped by topics: [latency](@ref rte_latencystats.h), [devargs](@ref rte_devargs.h), [PCI](@ref rte_pci.h), - [vdev](@ref rte_bus_vdev.h), - [vfio](@ref rte_vfio.h) + [vdev](@ref rte_bus_vdev.h) - **device specific**: [softnic](@ref rte_eth_softnic.h),
doc/guides/rel_notes/deprecation.rst +0 -6
@@ -29,12 +29,6 @@ Deprecation Notices Use the ``-S <service-corelist>`` parameter instead to specify the cores to be used for background services in DPDK. -* eal: The entire VFIO API (``rte_vfio_*``) will be made internal only, - and will only be available to EAL and drivers. - Group-based API (``rte_vfio_*_group_*``) will be removed - and replaced with unified container device assignment API. - This change will be made in 26.11 release. - * vdpa: The vDPA driver API will no longer offer ``get_vfio_group_fd`` as part of its internal API. All drivers will be adjusted to use the new unified VFIO container device assignment API.
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -213,6 +213,10 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* eal: The entire VFIO API (``rte_vfio_*``) was made internal. + These functions are now available only to EAL and drivers, + and are no longer part of the public API. + * ethdev: Updated VMDq related API. * At port configuration time, the number of VMDq pools advertised by a driver
drivers/bus/cdx/cdx.c +3 -3
@@ -73,7 +73,7 @@#include <rte_devargs.h> #include <rte_kvargs.h> #include <rte_malloc.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <eal_export.h> #include <eal_filesystem.h>
@@ -403,7 +403,7 @@ cdx_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len) {RTE_SET_USED (dev); -return rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , +return dev_vfio_container_dma_map (DEV_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, iova, len); }
@@ -412,7 +412,7 @@ cdx_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len) {RTE_SET_USED (dev); -return rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , +return dev_vfio_container_dma_unmap (DEV_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, iova, len); }
drivers/bus/cdx/cdx_vfio.c +7 -7
@@ -23,7 +23,7 @@#include <eal_export.h> #include <rte_eal_paging.h> #include <rte_malloc.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "bus_cdx_driver.h" #include "cdx_logs.h"
@@ -121,7 +121,7 @@ cdx_vfio_unmap_resource_primary(struct rte_cdx_device *dev)if (vfio_dev_fd <0 )return -1 ; - ret =rte_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev->device.name, + ret =dev_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev->device.name, vfio_dev_fd);if (ret <0 ) {CDX_BUS_ERR ("Cannot release VFIO device" );
@@ -155,7 +155,7 @@ cdx_vfio_unmap_resource_secondary(struct rte_cdx_device *dev)if (vfio_dev_fd <0 )return -1 ; - ret =rte_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev->device.name, + ret =dev_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev->device.name, vfio_dev_fd);if (ret <0 ) {CDX_BUS_ERR ("Cannot release VFIO device" );
@@ -400,7 +400,7 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev)if (rte_intr_fd_set (dev->intr_handle,-1 ))return -1 ; - ret =rte_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, + ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, &vfio_dev_fd, &device_info);if (ret)return ret;
@@ -477,7 +477,7 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev)cdx_vfio_find_and_unmap_resource (vfio_res_list, dev);rte_free (vfio_res); err_vfio_dev_fd: -rte_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, vfio_dev_fd); +dev_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, vfio_dev_fd);return -1 ; }
@@ -509,7 +509,7 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev)return -1 ; } - ret =rte_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, + ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, &vfio_dev_fd, &device_info);if (ret)return ret;
@@ -535,7 +535,7 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev)return 0 ; err_vfio_dev_fd: -rte_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, vfio_dev_fd); +dev_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, vfio_dev_fd);return -1 ; }
drivers/bus/fslmc/fslmc_bus.c +2 -2
@@ -17,7 +17,7 @@#include <rte_memcpy.h> #include <ethdev_driver.h> #include <rte_mbuf_dyn.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "private.h" #include <fslmc_vfio.h>
@@ -500,7 +500,7 @@ rte_dpaa2_get_iommu_class(void)return RTE_IOVA_DC ;/* check if all devices on the bus support Virtual addressing or not */ -if (fslmc_all_device_support_iova () !=0 &&rte_vfio_noiommu_is_enabled () ==0 ) +if (fslmc_all_device_support_iova () !=0 &&dev_vfio_noiommu_is_enabled () ==0 )return RTE_IOVA_VA ;return RTE_IOVA_PA ;
drivers/bus/fslmc/fslmc_vfio.c +6 -6
@@ -34,7 +34,7 @@#include <rte_kvargs.h> #include <dev_driver.h> #include <rte_eal_memconfig.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "private.h" #include "fslmc_vfio.h"
@@ -204,7 +204,7 @@ fslmc_vfio_add_group(int vfio_group_fd, group->fd = vfio_group_fd; group->groupid = iommu_group_num;rte_strscpy (group->group_name, group_name,sizeof (group->group_name)); -if (rte_vfio_noiommu_is_enabled () >0 ) +if (dev_vfio_noiommu_is_enabled () >0 ) group->iommu_type =VFIO_NOIOMMU_IOMMU ;else group->iommu_type =VFIO_TYPE1_IOMMU ;
@@ -374,7 +374,7 @@ fslmc_get_group_id(const char *group_name,int ret;/* get group number */ - ret =rte_vfio_get_group_num (SYSFS_FSL_MC_DEVICES , + ret =dev_vfio_get_group_num (SYSFS_FSL_MC_DEVICES , group_name, groupid);if (ret <=0 ) {DPAA2_BUS_ERR ("Find %s IOMMU group" , group_name);
@@ -411,7 +411,7 @@ fslmc_vfio_open_group_fd(const char *group_name)/* if primary, try to open the group */ if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) {/* try regular group format */ -snprintf (filename,sizeof (filename),RTE_VFIO_GROUP_FMT , iommu_group_num); +snprintf (filename,sizeof (filename),DEV_VFIO_GROUP_FMT , iommu_group_num); vfio_group_fd =open (filename,O_RDWR ); goto add_vfio_group;
@@ -509,10 +509,10 @@ fslmc_vfio_open_container_fd(void)/* if we're in a primary process, try to open the container */ if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { - vfio_container_fd =open (RTE_VFIO_CONTAINER_PATH ,O_RDWR ); + vfio_container_fd =open (DEV_VFIO_CONTAINER_PATH ,O_RDWR );if (vfio_container_fd <0 ) {DPAA2_BUS_ERR ("Open VFIO container(%s), err(%d)" , -RTE_VFIO_CONTAINER_PATH , vfio_container_fd); +DEV_VFIO_CONTAINER_PATH , vfio_container_fd); ret = vfio_container_fd; goto err_exit; }
drivers/bus/pci/linux/pci.c +4 -4
@@ -12,7 +12,7 @@#include <rte_malloc.h> #include <rte_devargs.h> #include <rte_memcpy.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <eal_export.h> #include "eal_filesystem.h"
@@ -485,7 +485,7 @@ pci_device_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len/* In case driver doesn't provide any specific mapping try fallback to VFIO. */ if (pdev->kdrv ==RTE_PCI_KDRV_VFIO ) - ret =rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , + ret =dev_vfio_container_dma_map (DEV_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, iova, len); }
@@ -502,7 +502,7 @@ pci_device_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t l/* In case driver doesn't provide any specific mapping try fallback to VFIO. */ if (pdev->kdrv ==RTE_PCI_KDRV_VFIO ) -return rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , +return dev_vfio_container_dma_unmap (DEV_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, iova, len); }
@@ -631,7 +631,7 @@ pci_device_iova_mode(const struct rte_pci_driver *pdrv,static int is_vfio_noiommu_enabled =-1 ;if (is_vfio_noiommu_enabled ==-1 ) { -if (rte_vfio_noiommu_is_enabled () ==1 ) +if (dev_vfio_noiommu_is_enabled () ==1 ) is_vfio_noiommu_enabled =1 ;else is_vfio_noiommu_enabled =0 ;
drivers/bus/pci/linux/pci_vfio.c +19 -19
@@ -18,7 +18,7 @@#include <rte_bus_pci.h> #include <rte_eal_paging.h> #include <rte_malloc.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_eal.h> #include <bus_driver.h> #include <rte_spinlock.h>
@@ -29,10 +29,10 @@#include "pci_init.h" #include "private.h" -static struct rte_tailq_elem rte_vfio_tailq = { +static struct rte_tailq_elem dev_vfio_tailq = { .name ="VFIO_RESOURCE_LIST" , }; -EAL_REGISTER_TAILQ(rte_vfio_tailq) +EAL_REGISTER_TAILQ(dev_vfio_tailq) static int pci_vfio_get_region(const struct rte_pci_device *dev, int index,
@@ -418,7 +418,7 @@ pci_vfio_is_ioport_bar(const struct rte_pci_device *dev, int vfio_dev_fd, }static int -pci_rte_vfio_setup_device (struct rte_pci_device *dev,int vfio_dev_fd) +pci_vfio_setup_device (struct rte_pci_device *dev,int vfio_dev_fd) {if (pci_vfio_setup_interrupts (dev, vfio_dev_fd) !=0 ) {PCI_LOG (ERR ,"Error setting up interrupts!" );
@@ -738,7 +738,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)int i, j, ret;struct mapped_pci_resource *vfio_res =NULL ;struct mapped_pci_res_list *vfio_res_list = -RTE_TAILQ_CAST (rte_vfio_tailq.head, mapped_pci_res_list); +RTE_TAILQ_CAST (dev_vfio_tailq.head, mapped_pci_res_list);struct pci_map *maps;
@@ -752,7 +752,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)snprintf (pci_addr,sizeof (pci_addr),PCI_PRI_FMT , loc->domain, loc->bus, loc->devid, loc->function); - ret =rte_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, + ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd, &device_info);if (ret)return ret;
@@ -897,7 +897,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)free (reg); } -if (pci_rte_vfio_setup_device (dev, vfio_dev_fd) <0 ) { +if (pci_vfio_setup_device (dev, vfio_dev_fd) <0 ) {PCI_LOG (ERR ,"%s setup device failed" , pci_addr); goto err_map; }
@@ -920,7 +920,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) err_vfio_res:rte_free (vfio_res); err_vfio_dev_fd: -rte_vfio_release_device (rte_pci_get_sysfs_path (), +dev_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);return -1 ; }
@@ -935,7 +935,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)int j, ret, i =0 ;struct mapped_pci_resource *vfio_res =NULL ;struct mapped_pci_res_list *vfio_res_list = -RTE_TAILQ_CAST (rte_vfio_tailq.head, mapped_pci_res_list); +RTE_TAILQ_CAST (dev_vfio_tailq.head, mapped_pci_res_list);struct pci_map *maps;
@@ -961,7 +961,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)return -1 ; } - ret =rte_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, + ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd, &device_info);if (ret)return ret;
@@ -1006,7 +1006,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)pci_unmap_resource (maps[j].addr, maps[j].size); } err_vfio_dev_fd: -rte_vfio_release_device (rte_pci_get_sysfs_path (), +dev_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);return -1 ; }
@@ -1101,7 +1101,7 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev)return -1 ; } - ret =rte_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, + ret =dev_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);if (ret <0 ) {PCI_LOG (ERR ,"Cannot release VFIO device" );
@@ -1109,7 +1109,7 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev) } vfio_res_list = -RTE_TAILQ_CAST (rte_vfio_tailq.head, mapped_pci_res_list); +RTE_TAILQ_CAST (dev_vfio_tailq.head, mapped_pci_res_list); vfio_res =find_and_unmap_vfio_resource (vfio_res_list, dev, pci_addr);/* if we haven't found our tailq entry, something's wrong */
@@ -1140,7 +1140,7 @@ pci_vfio_unmap_resource_secondary(struct rte_pci_device *dev)if (vfio_dev_fd <0 )return -1 ; - ret =rte_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, + ret =dev_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);if (ret <0 ) {PCI_LOG (ERR ,"Cannot release VFIO device" );
@@ -1148,7 +1148,7 @@ pci_vfio_unmap_resource_secondary(struct rte_pci_device *dev) } vfio_res_list = -RTE_TAILQ_CAST (rte_vfio_tailq.head, mapped_pci_res_list); +RTE_TAILQ_CAST (dev_vfio_tailq.head, mapped_pci_res_list); vfio_res =find_and_unmap_vfio_resource (vfio_res_list, dev, pci_addr);/* if we haven't found our tailq entry, something's wrong */
@@ -1195,7 +1195,7 @@ pci_vfio_ioport_map(struct rte_pci_device *dev, int bar,if (vfio_dev_fd <0 ) {return -1 ; }else if (vfio_dev_fd ==0 ) { -if (rte_vfio_get_device_info (rte_pci_get_sysfs_path (), pci_addr, +if (dev_vfio_get_device_info (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd, &device_info) !=0 )return -1 ;/* save vfio_dev_fd so it can be used during release */
@@ -1300,11 +1300,11 @@ pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar,int pci_vfio_is_enabled (void ) { -int status =rte_vfio_is_enabled ("vfio_pci" ); +int status =dev_vfio_is_enabled ("vfio_pci" );if (!status) { -rte_vfio_enable ("vfio" ); - status =rte_vfio_is_enabled ("vfio_pci" ); +dev_vfio_enable ("vfio" ); + status =dev_vfio_is_enabled ("vfio_pci" ); }return status; }
drivers/bus/platform/platform.c +5 -5
@@ -23,7 +23,7 @@#include <rte_log.h> #include <rte_memory.h> #include <rte_string_fns.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "private.h"
@@ -282,7 +282,7 @@ static void device_cleanup(struct rte_platform_device *pdev) {device_unmap_resources (pdev); -rte_vfio_release_device (PLATFORM_BUS_DEVICES_PATH , pdev->name, pdev->dev_fd); +dev_vfio_release_device (PLATFORM_BUS_DEVICES_PATH , pdev->name, pdev->dev_fd); } static int
@@ -292,7 +292,7 @@ device_setup(struct rte_platform_device *pdev)const char *name = pdev->name;int ret; - ret =rte_vfio_setup_device (PLATFORM_BUS_DEVICES_PATH , name, &pdev->dev_fd, &dev_info); + ret =dev_vfio_setup_device (PLATFORM_BUS_DEVICES_PATH , name, &pdev->dev_fd, &dev_info);if (ret) {PLATFORM_LOG_LINE (ERR ,"failed to setup %s" , name);return -ENODEV ;
@@ -458,7 +458,7 @@ platform_bus_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t lif (pdrv->dma_map !=NULL )return pdrv->dma_map (pdev, addr, iova, len); -return rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , (uint64_t )addr, iova, len); +return dev_vfio_container_dma_map (DEV_VFIO_DEFAULT_CONTAINER_FD , (uint64_t )addr, iova, len); } static int
@@ -470,7 +470,7 @@ platform_bus_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_tif (pdrv->dma_unmap !=NULL )return pdrv->dma_unmap (pdev, addr, iova, len); -return rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , (uint64_t )addr, iova, +return dev_vfio_container_dma_unmap (DEV_VFIO_DEFAULT_CONTAINER_FD , (uint64_t )addr, iova, len); }
drivers/crypto/bcmfs/bcmfs_vfio.c +4 -4
@@ -9,7 +9,7 @@#include <sys/mman.h> #include <sys/ioctl.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "bcmfs_device.h" #include "bcmfs_logs.h"
@@ -25,7 +25,7 @@ vfio_map_dev_obj(const char *path, const char *dev_obj,struct vfio_device_info d_info = { .argsz =sizeof (d_info) };struct vfio_region_info reg_info = { .argsz =sizeof (reg_info) }; - ret =rte_vfio_setup_device (path, dev_obj, dev_fd, &d_info); + ret =dev_vfio_setup_device (path, dev_obj, dev_fd, &d_info);if (ret) {BCMFS_LOG (ERR ,"VFIO Setting for device failed" );return ret;
@@ -51,7 +51,7 @@ vfio_map_dev_obj(const char *path, const char *dev_obj,return 0 ; map_failed: -rte_vfio_release_device (path, dev_obj, *dev_fd); +dev_vfio_release_device (path, dev_obj, *dev_fd);return ret; }
@@ -87,7 +87,7 @@ bcmfs_release_vfio(struct bcmfs_device *dev)/* unmap the addr */ munmap (dev->mmap_addr, dev->mmap_size);/* release the device */ - ret =rte_vfio_release_device (dev->dirname, dev->name, + ret =dev_vfio_release_device (dev->dirname, dev->name, dev->vfio_dev_fd);if (ret <0 ) {BCMFS_LOG (ERR ,"cannot release device" );
drivers/net/hinic3/base/hinic3_hwdev.c +2 -2
@@ -2,7 +2,7 @@* Copyright(c) 2025 Huawei Technologies Co., Ltd */ -#include <rte_vfio.h> +#include <dev_vfio.h> #include "hinic3_compat.h" #include "hinic3_cmd.h"
@@ -78,7 +78,7 @@ hinic3_is_vfio_iommu_enable(const struct rte_eth_dev *eth_dev) {struct rte_pci_device *pci_dev =RTE_CLASS_TO_BUS_DEVICE (eth_dev, *pci_dev); -return pci_dev->kdrv ==RTE_PCI_KDRV_VFIO &&rte_vfio_noiommu_is_enabled () !=1 ; +return pci_dev->kdrv ==RTE_PCI_KDRV_VFIO &&dev_vfio_noiommu_is_enabled () !=1 ; }int
drivers/net/nbl/nbl_common/nbl_userdev.c +8 -8
@@ -5,7 +5,7 @@#include <uapi/linux/vfio.h> #include "nbl_userdev.h" -#include <rte_vfio.h> +#include <dev_vfio.h> #define NBL_USERDEV_EVENT_CLB_NAME "nbl_userspace_mem_event_clb"#define NBL_USERDEV_BAR0_SIZE 65536
@@ -406,7 +406,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter)snprintf (pathname,sizeof (pathname),"%s/%s/" ,rte_pci_get_sysfs_path (), dev_name); - ret =rte_vfio_get_group_num (pathname, dev_name, &common->iommu_group_num); + ret =dev_vfio_get_group_num (pathname, dev_name, &common->iommu_group_num);if (ret <=0 ) {NBL_LOG (ERR ,"nbl vfio group number failed" );return -1 ;
@@ -415,7 +415,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter)NBL_LOG (DEBUG ,"nbl vfio group number %d" , common->iommu_group_num);/* vfio_container */ if (nbl_default_container <0 ) { - container =rte_vfio_container_create (); + container =dev_vfio_container_create (); container_create =1 ;if (container <0 ) {
@@ -425,7 +425,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) }NBL_LOG (DEBUG ,"nbl vfio container %d" , container); - vfio_group_fd =rte_vfio_container_group_bind (container, common->iommu_group_num); + vfio_group_fd =dev_vfio_container_group_bind (container, common->iommu_group_num);if (vfio_group_fd <0 ) {NBL_LOG (ERR ,"nbl vfio group bind failed, %d" , vfio_group_fd); goto free_container;
@@ -536,10 +536,10 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) } free_group:close (vfio_group_fd); -rte_vfio_clear_group (vfio_group_fd); +dev_vfio_clear_group (vfio_group_fd); free_container:if (container_create) -rte_vfio_container_destroy (container); +dev_vfio_container_destroy (container);return -1 ; }
@@ -551,7 +551,7 @@ static int nbl_mdev_unmap_device(struct nbl_adapter *adapter)rte_mcfg_mem_read_lock ();TAILQ_REMOVE (&nbl_adapter_list, adapter, next);close (common->devfd); - vfio_group_fd =rte_vfio_container_group_bind (nbl_default_container, + vfio_group_fd =dev_vfio_container_group_bind (nbl_default_container, common->iommu_group_num);NBL_LOG (DEBUG ,"close vfio_group_fd %d" , vfio_group_fd); ret =ioctl (vfio_group_fd,VFIO_GROUP_UNSET_CONTAINER , &nbl_default_container);
@@ -559,7 +559,7 @@ static int nbl_mdev_unmap_device(struct nbl_adapter *adapter)NBL_LOG (ERR ,"unset container, error %i (%s) %d" , errno,strerror (errno), ret); nbl_group_count--; - ret =rte_vfio_container_group_unbind (nbl_default_container, common->iommu_group_num); + ret =dev_vfio_container_group_unbind (nbl_default_container, common->iommu_group_num);if (ret)NBL_LOG (ERR ,"vfio container group unbind failed %d" , ret);if (!nbl_group_count) {
drivers/net/ntnic/ntnic_ethdev.c +2 -2
@@ -7,7 +7,7 @@#include <rte_eal.h> #include <rte_dev.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_ethdev.h> #include <rte_bus_pci.h> #include <ethdev_pci.h>
@@ -2729,7 +2729,7 @@ nthw_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) (pci_dev->device.devargs->data ? pci_dev->device.devargs->data : "NULL")); } -const int n_rte_vfio_no_io_mmu_enabled =rte_vfio_noiommu_is_enabled (); +const int n_rte_vfio_no_io_mmu_enabled =dev_vfio_noiommu_is_enabled ();NT_LOG (DBG ,NTNIC ,"vfio_no_iommu_enabled=%d" , n_rte_vfio_no_io_mmu_enabled);if (n_rte_vfio_no_io_mmu_enabled) {
drivers/net/ntnic/ntnic_vfio.c +11 -11
@@ -6,7 +6,7 @@#include <rte_malloc.h> #include <rte_memory.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_dev.h> #include <rte_bus_pci.h> #include <rte_spinlock.h>
@@ -70,16 +70,16 @@ nthw_vfio_setup(struct rte_pci_device *dev) vfio->iova_addr =START_VF_IOVA ;rte_pci_device_name (&dev->addr, devname,RTE_DEV_NAME_MAX_LEN ); - ret =rte_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, &iommu_group_num); + ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, &iommu_group_num);if (ret <=0 )return -1 ;if (vf_num ==0 ) {/* use default container for pf0 */ - vfio->container_fd =RTE_VFIO_DEFAULT_CONTAINER_FD ; + vfio->container_fd =DEV_VFIO_DEFAULT_CONTAINER_FD ; }else { - vfio->container_fd =rte_vfio_container_create (); + vfio->container_fd =dev_vfio_container_create ();if (vfio->container_fd <0 ) { NT_LOG(ERR, NTNIC,
@@ -88,7 +88,7 @@ nthw_vfio_setup(struct rte_pci_device *dev) } } - vfio->group_fd =rte_vfio_container_group_bind (vfio->container_fd, iommu_group_num); + vfio->group_fd =dev_vfio_container_group_bind (vfio->container_fd, iommu_group_num);if (vfio->group_fd <0 ) { NT_LOG(ERR, NTNIC,
@@ -115,8 +115,8 @@ nthw_vfio_setup(struct rte_pci_device *dev) err: -if (vfio->container_fd !=RTE_VFIO_DEFAULT_CONTAINER_FD ) -rte_vfio_container_destroy (vfio->container_fd); +if (vfio->container_fd !=DEV_VFIO_DEFAULT_CONTAINER_FD ) +dev_vfio_container_destroy (vfio->container_fd);return -1 ; }
@@ -135,7 +135,7 @@ nthw_vfio_remove(int vf_num)return -1 ; } -rte_vfio_container_destroy (vfio->container_fd); +dev_vfio_container_destroy (vfio->container_fd);return 0 ; }
@@ -169,14 +169,14 @@ nthw_vfio_dma_map(int vf_num, void *virt_addr, uint64_t *iova_addr, uint64_t siz vf_num, virt_addr,rte_malloc_virt2iova (virt_addr), gp_virt_base, vfio->iova_addr, size); -int res =rte_vfio_container_dma_map (vfio->container_fd, gp_virt_base, vfio->iova_addr, +int res =dev_vfio_container_dma_map (vfio->container_fd, gp_virt_base, vfio->iova_addr, size);NT_LOG (DBG ,NTNIC ,"VFIO MMAP res %i, container_fd %i, vf_num %i" , res, vfio->container_fd, vf_num);if (res) { -NT_LOG (ERR ,NTNIC ,"rte_vfio_container_dma_map failed: res %d" , res); +NT_LOG (ERR ,NTNIC ,"dev_vfio_container_dma_map failed: res %d" , res);return -1 ; }
@@ -210,7 +210,7 @@ nthw_vfio_dma_unmap(int vf_num, void *virt_addr, uint64_t iova_addr, uint64_t sireturn -1 ; } -int res =rte_vfio_container_dma_unmap (vfio->container_fd, gp_virt_base, iova_addr, size); +int res =dev_vfio_container_dma_unmap (vfio->container_fd, gp_virt_base, iova_addr, size);if (res !=0 ) { NT_LOG(ERR, NTNIC,
drivers/vdpa/ifc/ifcvf_vdpa.c +12 -12
@@ -20,7 +20,7 @@#include <rte_vhost.h> #include <rte_vdpa.h> #include <vdpa_driver.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_spinlock.h> #include <rte_log.h> #include <rte_kvargs.h>
@@ -183,18 +183,18 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal) internal->vfio_container_fd =-1 ;rte_pci_device_name (&dev->addr, devname,RTE_DEV_NAME_MAX_LEN ); - ret =rte_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, + ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, &iommu_group_num);if (ret <=0 ) {DRV_LOG (ERR ,"%s failed to get IOMMU group" , devname);return -1 ; } - internal->vfio_container_fd =rte_vfio_container_create (); + internal->vfio_container_fd =dev_vfio_container_create ();if (internal->vfio_container_fd <0 )return -1 ; - internal->vfio_group_fd =rte_vfio_container_group_bind ( + internal->vfio_group_fd =dev_vfio_container_group_bind ( internal->vfio_container_fd, iommu_group_num);if (internal->vfio_group_fd <0 ) goto err;
@@ -217,7 +217,7 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal)return 0 ; err: -rte_vfio_container_destroy (internal->vfio_container_fd); +dev_vfio_container_destroy (internal->vfio_container_fd);return -1 ; }
@@ -247,7 +247,7 @@ ifcvf_dma_map(struct ifcvf_internal *internal, bool do_map) reg->host_user_addr, reg->guest_phys_addr, reg->size);if (do_map) { - ret =rte_vfio_container_dma_map (vfio_container_fd, + ret =dev_vfio_container_dma_map (vfio_container_fd, reg->host_user_addr, reg->guest_phys_addr, reg->size);if (ret <0 ) {
@@ -255,7 +255,7 @@ ifcvf_dma_map(struct ifcvf_internal *internal, bool do_map) goto exit; } }else { - ret =rte_vfio_container_dma_unmap (vfio_container_fd, + ret =dev_vfio_container_dma_unmap (vfio_container_fd, reg->host_user_addr, reg->guest_phys_addr, reg->size);if (ret <0 ) {
@@ -389,7 +389,7 @@ vdpa_ifcvf_stop(struct ifcvf_internal *internal)if (RTE_VHOST_NEED_LOG (features)) {ifcvf_disable_logging (hw);rte_vhost_get_log_base (internal->vid, &log_base, &log_size); -rte_vfio_container_dma_unmap (internal->vfio_container_fd, +dev_vfio_container_dma_unmap (internal->vfio_container_fd, log_base,IFCVF_LOG_BASE , log_size);/* * IFCVF marks dirty memory pages for only packet buffer,
@@ -792,7 +792,7 @@ m_ifcvf_start(struct ifcvf_internal *internal)vring_init (&internal->m_vring[i], vq.size, vring_buf,rte_mem_page_size ()); - ret =rte_vfio_container_dma_map (internal->vfio_container_fd, + ret =dev_vfio_container_dma_map (internal->vfio_container_fd, (uint64_t )(uintptr_t )vring_buf, m_vring_iova, size);if (ret <0 ) {DRV_LOG (ERR ,"mediated vring DMA map failed." );
@@ -901,7 +901,7 @@ m_ifcvf_stop(struct ifcvf_internal *internal) size =RTE_ALIGN_CEIL (vring_size (vq.size,rte_mem_page_size ()),rte_mem_page_size ()); -rte_vfio_container_dma_unmap (internal->vfio_container_fd, +dev_vfio_container_dma_unmap (internal->vfio_container_fd, (uint64_t )(uintptr_t )internal->m_vring[i].desc, m_vring_iova, size);
@@ -1206,7 +1206,7 @@ ifcvf_set_features(int vid)ifcvf_sw_fallback_switchover (internal); }else {rte_vhost_get_log_base (vid, &log_base, &log_size); -rte_vfio_container_dma_map (internal->vfio_container_fd, +dev_vfio_container_dma_map (internal->vfio_container_fd, log_base,IFCVF_LOG_BASE , log_size);ifcvf_enable_logging (&internal->hw,IFCVF_LOG_BASE , log_size); }
@@ -1825,7 +1825,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev)DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name);rte_pci_unmap_device (internal->pdev); -rte_vfio_container_destroy (internal->vfio_container_fd); +dev_vfio_container_destroy (internal->vfio_container_fd);rte_vdpa_unregister_device (internal->vdev);pthread_mutex_lock (&internal_list_lock);
drivers/vdpa/nfp/nfp_vdpa.c +12 -12
@@ -12,7 +12,7 @@#include <nfp_common_pci.h> #include <nfp_dev.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_eal_paging.h> #include <rte_malloc.h> #include <vdpa_driver.h>
@@ -120,16 +120,16 @@ nfp_vdpa_vfio_setup(struct nfp_vdpa_dev *device)struct rte_pci_device *pci_dev = device->pci_dev;rte_pci_device_name (&pci_dev->addr, dev_name,RTE_DEV_NAME_MAX_LEN ); - ret =rte_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, + ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, &device->iommu_group);if (ret <=0 )return -1 ; - device->vfio_container_fd =rte_vfio_container_create (); + device->vfio_container_fd =dev_vfio_container_create ();if (device->vfio_container_fd <0 )return -1 ; - device->vfio_group_fd =rte_vfio_container_group_bind ( + device->vfio_group_fd =dev_vfio_container_group_bind ( device->vfio_container_fd, device->iommu_group);if (device->vfio_group_fd <0 ) goto container_destroy;
@@ -146,9 +146,9 @@ nfp_vdpa_vfio_setup(struct nfp_vdpa_dev *device)return 0 ; group_unbind: -rte_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); +dev_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); container_destroy: -rte_vfio_container_destroy (device->vfio_container_fd); +dev_vfio_container_destroy (device->vfio_container_fd);return -1 ; }
@@ -157,8 +157,8 @@ static void nfp_vdpa_vfio_teardown(struct nfp_vdpa_dev *device) {rte_pci_unmap_device (device->pci_dev); -rte_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); -rte_vfio_container_destroy (device->vfio_container_fd); +dev_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); +dev_vfio_container_destroy (device->vfio_container_fd); } static int
@@ -173,7 +173,7 @@ nfp_vdpa_dma_do_unmap(struct rte_vhost_memory *mem,for (i =0 ; i < times; i++) { region = &mem->regions[i]; - ret =rte_vfio_container_dma_unmap (vfio_container_fd, + ret =dev_vfio_container_dma_unmap (vfio_container_fd, region->host_user_addr, region->guest_phys_addr, region->size);if (ret <0 ) {
@@ -197,7 +197,7 @@ nfp_vdpa_dma_do_map(struct rte_vhost_memory *mem,for (i =0 ; i < times; i++) { region = &mem->regions[i]; - ret =rte_vfio_container_dma_map (vfio_container_fd, + ret =dev_vfio_container_dma_map (vfio_container_fd, region->host_user_addr, region->guest_phys_addr, region->size);if (ret <0 ) {
@@ -282,7 +282,7 @@ nfp_vdpa_relay_vring_free(struct nfp_vdpa_dev *device, size =RTE_ALIGN_CEIL (vring_size (vring.size,rte_mem_page_size ()),rte_mem_page_size ()); -rte_vfio_container_dma_unmap (device->vfio_container_fd, +dev_vfio_container_dma_unmap (device->vfio_container_fd, (uint64_t )(uintptr_t )device->hw.m_vring[i].desc, m_vring_iova, size);
@@ -315,7 +315,7 @@ nfp_vdpa_relay_vring_alloc(struct nfp_vdpa_dev *device)vring_init (&vdpa_hw->m_vring[i], vring.size, vring_buf, page_size); - ret =rte_vfio_container_dma_map (device->vfio_container_fd, + ret =dev_vfio_container_dma_map (device->vfio_container_fd, (uint64_t )(uintptr_t )vring_buf, m_vring_iova, size);if (ret !=0 ) {DRV_VDPA_LOG (ERR ,"vDPA vring relay dma map failed." );
drivers/vdpa/sfc/sfc_vdpa.c +8 -8
@@ -12,7 +12,7 @@#include <rte_errno.h> #include <rte_kvargs.h> #include <rte_string_fns.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_vhost.h> #include "efx.h"
@@ -74,13 +74,13 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva)rte_pci_device_name (&dev->addr, dev_name,RTE_DEV_NAME_MAX_LEN ); - sva->vfio_container_fd =rte_vfio_container_create (); + sva->vfio_container_fd =dev_vfio_container_create ();if (sva->vfio_container_fd <0 ) {sfc_vdpa_err (sva,"failed to create VFIO container" ); goto fail_container_create; } - rc =rte_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, + rc =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, &sva->iommu_group_num);if (rc <=0 ) { sfc_vdpa_err(sva, "failed to get IOMMU group for %s : %s",
@@ -89,7 +89,7 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva) } sva->vfio_group_fd = -rte_vfio_container_group_bind (sva->vfio_container_fd, +dev_vfio_container_group_bind (sva->vfio_container_fd, sva->iommu_group_num);if (sva->vfio_group_fd <0 ) { sfc_vdpa_err(sva,
@@ -109,7 +109,7 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva)return 0 ; fail_pci_map_device: -if (rte_vfio_container_group_unbind (sva->vfio_container_fd, +if (dev_vfio_container_group_unbind (sva->vfio_container_fd, sva->iommu_group_num) !=0 ) { sfc_vdpa_err(sva, "failed to unbind IOMMU group %d from container %d",
@@ -118,7 +118,7 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva) fail_group_bind: fail_get_group_num: -if (rte_vfio_container_destroy (sva->vfio_container_fd) !=0 ) { +if (dev_vfio_container_destroy (sva->vfio_container_fd) !=0 ) {sfc_vdpa_err (sva,"failed to destroy container %d" , sva->vfio_container_fd); }
@@ -132,14 +132,14 @@ sfc_vdpa_vfio_teardown(struct sfc_vdpa_adapter *sva) {rte_pci_unmap_device (sva->pdev); -if (rte_vfio_container_group_unbind (sva->vfio_container_fd, +if (dev_vfio_container_group_unbind (sva->vfio_container_fd, sva->iommu_group_num) !=0 ) {sfc_vdpa_err (sva,"failed to unbind IOMMU group %d from container %d" , sva->iommu_group_num, sva->vfio_container_fd); } -if (rte_vfio_container_destroy (sva->vfio_container_fd) !=0 ) { +if (dev_vfio_container_destroy (sva->vfio_container_fd) !=0 ) {sfc_vdpa_err (sva,"failed to destroy container %d" , sva->vfio_container_fd);
drivers/vdpa/sfc/sfc_vdpa_hw.c +6 -6
@@ -6,7 +6,7 @@#include <rte_common.h> #include <rte_errno.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_vhost.h> #include "efx.h"
@@ -64,7 +64,7 @@ sfc_vdpa_dma_alloc(struct sfc_vdpa_adapter *sva, const char *name, mcdi_iova =SFC_VDPA_DEFAULT_MCDI_IOVA ;for (;;) { - ret =rte_vfio_container_dma_map (sva->vfio_container_fd, + ret =dev_vfio_container_dma_map (sva->vfio_container_fd, (uint64_t )mz->addr, mcdi_iova, mcdi_buff_size);if (ret ==0 )
@@ -98,7 +98,7 @@ sfc_vdpa_dma_free(struct sfc_vdpa_adapter *sva, efsys_mem_t *esmp)sfc_vdpa_log_init (sva,"name=%s" , esmp->esm_mz->name); - ret =rte_vfio_container_dma_unmap (sva->vfio_container_fd, + ret =dev_vfio_container_dma_unmap (sva->vfio_container_fd, (uint64_t )esmp->esm_base, esmp->esm_addr, sva->mcdi_buff_size);if (ret <0 )
@@ -140,7 +140,7 @@ sfc_vdpa_dma_map(struct sfc_vdpa_ops_data *ops_data, bool do_map) mem_reg = &vhost_mem->regions[i];if (do_map) { - rc =rte_vfio_container_dma_map (vfio_container_fd, + rc =dev_vfio_container_dma_map (vfio_container_fd, mem_reg->host_user_addr, mem_reg->guest_phys_addr, mem_reg->size);
@@ -151,7 +151,7 @@ sfc_vdpa_dma_map(struct sfc_vdpa_ops_data *ops_data, bool do_map) goto failed_vfio_dma_map; } }else { - rc =rte_vfio_container_dma_unmap (vfio_container_fd, + rc =dev_vfio_container_dma_unmap (vfio_container_fd, mem_reg->host_user_addr, mem_reg->guest_phys_addr, mem_reg->size);
@@ -171,7 +171,7 @@ sfc_vdpa_dma_map(struct sfc_vdpa_ops_data *ops_data, bool do_map) failed_vfio_dma_map:for (j =0 ; j < i; j++) { mem_reg = &vhost_mem->regions[j]; -rte_vfio_container_dma_unmap (vfio_container_fd, +dev_vfio_container_dma_unmap (vfio_container_fd, mem_reg->host_user_addr, mem_reg->guest_phys_addr, mem_reg->size);
lib/eal/linux/eal.c +2 -2
@@ -41,7 +41,7 @@#include <rte_bus.h> #include <rte_version.h> #include <malloc_heap.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <telemetry_internal.h> #include <eal_export.h>
@@ -772,7 +772,7 @@ rte_eal_init(int argc, char **argv)#endif } -if (rte_vfio_enable ("vfio" )) { +if (dev_vfio_enable ("vfio" )) {rte_eal_init_alert ("Cannot init VFIO" ); rte_errno =EAGAIN ; goto err_out;
lib/eal/linux/eal_vfio.c +58 -58
370 lines not on this page · raw message
lib/eal/linux/eal_vfio_mp_sync.c +3 -3
@@ -8,7 +8,7 @@#include <rte_errno.h> #include <rte_log.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_eal.h> #include "eal_private.h"
@@ -34,7 +34,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)case SOCKET_REQ_GROUP : r->req =SOCKET_REQ_GROUP ; r->group_num = m->group_num; - fd =rte_vfio_get_group_fd (m->group_num); + fd =dev_vfio_get_group_fd (m->group_num);if (fd <0 && fd != -ENOENT ) r->result =SOCKET_ERR ;else if (fd == -ENOENT )
@@ -49,7 +49,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)break ;case SOCKET_REQ_CONTAINER : r->req =SOCKET_REQ_CONTAINER ; - fd =rte_vfio_get_container_fd (); + fd =dev_vfio_get_container_fd ();if (fd <0 ) r->result =SOCKET_ERR ;else {
lib/eal/linux/include/dev_vfio.h renamed from lib/eal/linux/include/rte_vfio.h +68 -36
273 lines not on this page · raw message
lib/eal/linux/include/meson.build +4 -1
@@ -5,5 +5,8 @@ includes += include_directories('.') headers += files( 'rte_os.h', - 'rte_vfio.h', +) + +driver_sdk_headers += files( + 'dev_vfio.h', )
lib/vhost/socket.c +2 -2
@@ -17,7 +17,7 @@#include <eal_export.h> #include <rte_thread.h> #include <rte_log.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "fd_man.h" #include "vduse.h"
@@ -245,7 +245,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)if (dev !=NULL ) { dev->async_copy =1 ; - dev->dma_map_available =rte_vfio_is_enabled ("vfio" ); + dev->dma_map_available =dev_vfio_is_enabled ("vfio" ); } }
lib/vhost/vhost_user.c +3 -3
@@ -42,7 +42,7 @@#include <rte_common.h> #include <rte_malloc.h> #include <rte_log.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_errno.h> #include "iotlb.h"
@@ -191,7 +191,7 @@ async_dma_map_region(struct virtio_net *dev, struct rte_vhost_mem_region *reg, bcontinue ;if (do_map) { - ret =rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , + ret =dev_vfio_container_dma_map (DEV_VFIO_DEFAULT_CONTAINER_FD , page->host_user_addr, page->host_iova, page->size);
@@ -216,7 +216,7 @@ async_dma_map_region(struct virtio_net *dev, struct rte_vhost_mem_region *reg, breturn -1 ; } }else { - ret =rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , + ret =dev_vfio_container_dma_unmap (DEV_VFIO_DEFAULT_CONTAINER_FD , page->host_user_addr, page->host_iova, page->size);
Signature · 1 line
2.54.0
PATCH v19 7/26 vfio: add module check API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
All VFIO initialization always happens with "vfio" module, and now that the API is not public, having a way to override the module name seems redundant as there is not going to be a use case that calls into rte_vfio_enable that isn't coming from EAL init.
On the other hand, there are a few users of VFIO API that depend on checking if a specific kernel module is loaded. This call is coupled with checking if VFIO is enabled (which should not be the case, as these are orthogonal), and depending on context different modules are checked with a string literal (which is suboptimal as well).
Provide a new API in VFIO to check for whether a specific VFIO-related kernel module is loaded, decouple it from "enabled" check, and adjust all callers accordingly.
With this change, there is no user left for the EAL function, remove it.
---
Changes since v18:
- squashed all kmod checks into a single patch,
--- drivers/bus/pci/linux/pci_vfio.c | 11 +++--- lib/eal/common/eal_private.h | 14 -------- lib/eal/linux/eal.c | 37 +------------------ lib/eal/linux/eal_vfio.c | 61 +++++++++++++++++++++++++++++--- lib/eal/linux/include/dev_vfio.h | 39 ++++++++++++++------ lib/vhost/socket.c | 2 +- 6 files changed, 93 insertions(+), 71 deletions(-)
drivers/bus/pci/linux/pci_vfio.c +6 -5
@@ -1300,11 +1300,12 @@ pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar,int pci_vfio_is_enabled (void ) { -int status =dev_vfio_is_enabled ("vfio_pci" ); +int status; -if (!status) { -dev_vfio_enable ("vfio" ); - status =dev_vfio_is_enabled ("vfio_pci" ); - } +if (dev_vfio_enable () <0 ) +return 0 ; + + status =dev_vfio_is_enabled () && +dev_vfio_module_is_loaded (DEV_VFIO_MODULE_VFIO_PCI );return status; }
lib/eal/common/eal_private.h +0 -14
@@ -206,20 +206,6 @@ int rte_eal_alarm_init(void);*/ void rte_eal_alarm_cleanup (void ); -/** -* Function is to check if the kernel module(like, vfio, vfio_iommu_type1, -* etc.) loaded. -* -* @param module_name -* The module's name which need to be checked -* -* @return -* -1 means some error happens(NULL pointer or open failure) -* 0 means the module not loaded -* 1 means the module loaded -*/ -int rte_eal_check_module (const char *module_name); -/** * Memory reservation flags. */
lib/eal/linux/eal.c +1 -36
@@ -17,9 +17,7 @@#include <fnmatch.h> #include <stddef.h> #include <errno.h> -#include <limits.h> #include <sys/mman.h> -#include <sys/stat.h> #if defined(RTE_ARCH_X86 )#include <sys/io.h> #endif
@@ -772,7 +770,7 @@ rte_eal_init(int argc, char **argv)#endif } -if (dev_vfio_enable ("vfio" )) { +if (dev_vfio_enable ()) {rte_eal_init_alert ("Cannot init VFIO" ); rte_errno =EAGAIN ; goto err_out;
@@ -1029,36 +1027,3 @@ rte_eal_vfio_get_vf_token(rte_uuid_t vf_token)rte_uuid_copy (vf_token, cfg->vfio_vf_token); } -int -rte_eal_check_module (const char *module_name) -{ -char sysfs_mod_name[PATH_MAX ]; -struct stat st; -int n; - -if (NULL == module_name) -return -1 ; - -/* Check if there is sysfs mounted */ -if (stat ("/sys/module" , &st) !=0 ) { -EAL_LOG (DEBUG ,"sysfs is not mounted! error %i (%s)" , - errno,strerror (errno)); -return -1 ; - } - -/* A module might be built-in, therefore try sysfs */ - n =snprintf (sysfs_mod_name,PATH_MAX ,"/sys/module/%s" , module_name); -if (n <0 || n >PATH_MAX ) { -EAL_LOG (DEBUG ,"Could not format module path" ); -return -1 ; - } - -if (stat (sysfs_mod_name, &st) !=0 ) { -EAL_LOG (DEBUG ,"Module %s not found! error %i (%s)" , - sysfs_mod_name, errno,strerror (errno)); -return 0 ; - } - -/* Module has been found */ -return 1 ; -}
lib/eal/linux/eal_vfio.c +56 -5
97 lines not on this page · raw message
lib/eal/linux/include/dev_vfio.h +29 -10
@@ -35,6 +35,17 @@ struct vfio_device_info;#define DEV_VFIO_DEFAULT_CONTAINER_FD (-1) +/** +* @enum dev_vfio_module +* VFIO kernel modules. +* +* These values identify kernel modules used by VFIO. +*/ +enum dev_vfio_module { +DEV_VFIO_MODULE_VFIO ,/**< Core VFIO module. */ +DEV_VFIO_MODULE_VFIO_PCI ,/**< VFIO PCI module. */ +}; +/** * @internal * Setup vfio_cfg for the device identified by its address.
@@ -84,31 +95,39 @@ int dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd/** * @internal -* Enable a VFIO-related kmod. -* -* @param modname -* kernel module name. +* Initialize VFIO. * * @return * 0 on success. * <0 on failure. */ __rte_internal -int dev_vfio_enable(const char *modname); +int dev_vfio_enable(void);/** * @internal -* Check whether a VFIO-related kmod is enabled. +* Check whether a VFIO module is loaded. * -* @param modname -* kernel module name. +* @param module +* VFIO module to check. * * @return -* 1 if true. +* 1 if the requested module is loaded. +* 0 otherwise. +*/ +__rte_internal +int dev_vfio_module_is_loaded(enum dev_vfio_module module); + +/** +* @internal +* Check whether VFIO was initialized. +* +* @return +* 1 if VFIO was initialized. * 0 otherwise. */ __rte_internal -int dev_vfio_is_enabled(const char *modname); +int dev_vfio_is_enabled(void);/** * @internal
lib/vhost/socket.c +1 -1
@@ -245,7 +245,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)if (dev !=NULL ) { dev->async_copy =1 ; - dev->dma_map_available =dev_vfio_is_enabled ("vfio" ); + dev->dma_map_available =dev_vfio_is_enabled (); } }
Signature · 1 line
2.54.0
PATCH v19 8/26 vfio: teardown internals on VFIO cleanup
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Currently, VFIO cleanup only unregisters multiprocess callback, but does not destroy containers, groups, and user mem maps. Do all of that on VFIO cleanup. We don't actually need a per-config enabled flag, as container fd should be enough to determine whether the config is active.
While we're at it, also harden the API against repeated initialization and attempts at using the API without having VFIO initialized.
---
Changes since v18:
- squashed with introduction of dev_vfio_cleanup(),
- removed rte_errno = ENODEV updates since most of them are dropped later in the series,
--- lib/eal/linux/eal.c | 3 +- lib/eal/linux/eal_vfio.c | 136 +++++++++++++++++++++++++++++-- lib/eal/linux/include/dev_vfio.h | 7 ++ 3 files changed, 139 insertions(+), 7 deletions(-)
lib/eal/linux/eal.c +1 -2
@@ -52,7 +52,6 @@#include "eal_memcfg.h" #include "eal_trace.h" #include "eal_options.h" -#include "eal_vfio.h" #include "hotplug_mp.h" #include "log_internal.h"
@@ -984,7 +983,7 @@ rte_eal_cleanup(void)rte_service_finalize ();eal_bus_cleanup (); -vfio_mp_sync_cleanup (); +dev_vfio_cleanup ();rte_mp_channel_cleanup ();rte_eal_alarm_cleanup ();rte_trace_save ();
lib/eal/linux/eal_vfio.c +131 -5
258 lines not on this page · raw message
lib/eal/linux/include/dev_vfio.h +7 -0
@@ -104,6 +104,13 @@ int dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd__rte_internal int dev_vfio_enable(void); +/** +* @internal +* Cleanup VFIO resources. +*/ +__rte_internal +void dev_vfio_cleanup(void); +/** * @internal * Check whether a VFIO module is loaded.
Signature · 1 line
2.54.0
PATCH v19 9/26 vfio: split get device info from setup
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Currently, setup gets device info as part of setup, while the separate get device info API also calls setup if the fd is zero. Untangle these two APIs and make each do one thing, and adjust all existing callers.
--- drivers/bus/cdx/cdx_vfio.c | 13 +++++++--- drivers/bus/pci/linux/pci_vfio.c | 20 +++++++++++----- drivers/bus/platform/platform.c | 9 ++++++- drivers/crypto/bcmfs/bcmfs_vfio.c | 8 ++++++- lib/eal/linux/eal_vfio.c | 40 ++++++++----------------------- lib/eal/linux/include/dev_vfio.h | 24 +++++++------------ 6 files changed, 57 insertions(+), 57 deletions(-)
drivers/bus/cdx/cdx_vfio.c +10 -3
@@ -401,10 +401,14 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev)return -1 ; ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, - &vfio_dev_fd, &device_info); + &vfio_dev_fd);if (ret)return ret; + ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info); +if (ret) + goto err_vfio_dev_fd; +/* allocate vfio_res and get region info */ vfio_res =rte_zmalloc ("VFIO_RES" ,sizeof (*vfio_res),0 );if (vfio_res ==NULL ) {
@@ -509,11 +513,14 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev)return -1 ; } - ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, - &vfio_dev_fd, &device_info); + ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, &vfio_dev_fd);if (ret)return ret; + ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info); +if (ret) + goto err_vfio_dev_fd; +/* map MMIO regions */ maps = vfio_res->maps;
drivers/bus/pci/linux/pci_vfio.c +14 -6
@@ -752,11 +752,14 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)snprintf (pci_addr,sizeof (pci_addr),PCI_PRI_FMT , loc->domain, loc->bus, loc->devid, loc->function); - ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, - &vfio_dev_fd, &device_info); + ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd);if (ret)return ret; + ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info); +if (ret) + goto err_vfio_dev_fd; +if (rte_intr_dev_fd_set (dev->intr_handle, vfio_dev_fd)) goto err_vfio_dev_fd;
@@ -961,11 +964,14 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)return -1 ; } - ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, - &vfio_dev_fd, &device_info); + ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd);if (ret)return ret; + ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info); +if (ret) + goto err_vfio_dev_fd; + ret =pci_vfio_fill_regions (dev, vfio_dev_fd, &device_info);if (ret) goto err_vfio_dev_fd;
@@ -1195,12 +1201,14 @@ pci_vfio_ioport_map(struct rte_pci_device *dev, int bar,if (vfio_dev_fd <0 ) {return -1 ; }else if (vfio_dev_fd ==0 ) { -if (dev_vfio_get_device_info (rte_pci_get_sysfs_path (), pci_addr, - &vfio_dev_fd, &device_info) !=0 ) +if (dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, + &vfio_dev_fd) !=0 )return -1 ;/* save vfio_dev_fd so it can be used during release */ if (rte_intr_dev_fd_set (dev->intr_handle, vfio_dev_fd) !=0 )return -1 ; +if (dev_vfio_get_device_info (vfio_dev_fd, &device_info) !=0 ) +return -1 ;if (pci_vfio_fill_regions (dev, vfio_dev_fd, &device_info) !=0 )return -1 ;
drivers/bus/platform/platform.c +8 -1
@@ -292,12 +292,19 @@ device_setup(struct rte_platform_device *pdev)const char *name = pdev->name;int ret; - ret =dev_vfio_setup_device (PLATFORM_BUS_DEVICES_PATH , name, &pdev->dev_fd, &dev_info); + ret =dev_vfio_setup_device (PLATFORM_BUS_DEVICES_PATH , name, &pdev->dev_fd);if (ret) {PLATFORM_LOG_LINE (ERR ,"failed to setup %s" , name);return -ENODEV ; } + ret =dev_vfio_get_device_info (pdev->dev_fd, &dev_info); +if (ret) { +PLATFORM_LOG_LINE (ERR ,"failed to get device info for %s" , name); + ret = -ENODEV ; + goto out; + } +/* This is an extra check to confirm that platform device was initialized * by a kernel vfio-platform driver. On kernels that predate vfio-platform * driver this flag obviously does not exist. In such scenarios this
drivers/crypto/bcmfs/bcmfs_vfio.c +7 -1
@@ -25,12 +25,18 @@ vfio_map_dev_obj(const char *path, const char *dev_obj,struct vfio_device_info d_info = { .argsz =sizeof (d_info) };struct vfio_region_info reg_info = { .argsz =sizeof (reg_info) }; - ret =dev_vfio_setup_device (path, dev_obj, dev_fd, &d_info); + ret =dev_vfio_setup_device (path, dev_obj, dev_fd);if (ret) {BCMFS_LOG (ERR ,"VFIO Setting for device failed" );return ret; } + ret =dev_vfio_get_device_info (*dev_fd, &d_info); +if (ret) { +BCMFS_LOG (ERR ,"VFIO Getting device info failed" ); + goto map_failed; + } +/* getting device region info*/ ret =ioctl (*dev_fd,VFIO_DEVICE_GET_REGION_INFO , ®_info);if (ret <0 ) {
lib/eal/linux/eal_vfio.c +10 -30
@@ -810,8 +810,7 @@ dev_vfio_clear_group(int vfio_group_fd)RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_setup_device) int -dev_vfio_setup_device (const char *sysfs_base,const char *dev_addr, -int *vfio_dev_fd,struct vfio_device_info *device_info) +dev_vfio_setup_device (const char *sysfs_base,const char *dev_addr,int *vfio_dev_fd) {struct vfio_group_status group_status = { .argsz =sizeof (group_status)
@@ -1031,7 +1030,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, *vfio_dev_fd =ioctl (vfio_group_fd,VFIO_GROUP_GET_DEVICE_FD , dev);if (*vfio_dev_fd >=0 ) - goto dev_get_info; + goto out; }/* get a file descriptor for the device */
@@ -1048,18 +1047,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr,return -1 ; } -/* test and setup the device */ -dev_get_info: - ret =ioctl (*vfio_dev_fd,VFIO_DEVICE_GET_INFO , device_info); -if (ret) { -EAL_LOG (ERR ,"%s cannot get device info, " -"error %i (%s)" , dev_addr, errno, -strerror (errno)); -close (*vfio_dev_fd); -close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); -return -1 ; - } +/* device is now set up */ +out:vfio_group_device_get (vfio_group_fd);return 0 ;
@@ -1288,29 +1277,20 @@ vfio_set_iommu_type(int vfio_container_fd)RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_device_info) int -dev_vfio_get_device_info (const char *sysfs_base,const char *dev_addr, -int *vfio_dev_fd,struct vfio_device_info *device_info) +dev_vfio_get_device_info (int vfio_dev_fd,struct vfio_device_info *device_info) {int ret;if (!vfio_enabled)return -1 ; -if (device_info ==NULL || *vfio_dev_fd <0 ) +if (device_info ==NULL || vfio_dev_fd <0 )return -1 ; -if (*vfio_dev_fd ==0 ) { - ret =dev_vfio_setup_device (sysfs_base, dev_addr, - vfio_dev_fd, device_info); -if (ret) -return -1 ; - }else { - ret =ioctl (*vfio_dev_fd,VFIO_DEVICE_GET_INFO , device_info); -if (ret) { -EAL_LOG (ERR ,"%s cannot get device info, error %i (%s)" , - dev_addr, errno,strerror (errno)); -return -1 ; - } + ret =ioctl (vfio_dev_fd,VFIO_DEVICE_GET_INFO , device_info); +if (ret) { +EAL_LOG (ERR ,"Cannot get device info, error %i (%s)" , errno,strerror (errno)); +return -1 ; }return 0 ;
lib/eal/linux/include/dev_vfio.h +8 -16
@@ -59,10 +59,7 @@ enum dev_vfio_module {* device location. * * @param vfio_dev_fd -* VFIO fd. -* -* @param device_info -* Device information. +* Pointer to VFIO fd, will be set to the opened device fd on success. * * @return * 0 on success.
@@ -70,8 +67,7 @@ enum dev_vfio_module {* >1 if the device cannot be managed this way. */ __rte_internal -int dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, -int *vfio_dev_fd,struct vfio_device_info *device_info); +int dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dev_fd);/** * @internal
@@ -189,26 +185,22 @@ dev_vfio_get_group_num(const char *sysfs_base, const char *dev_addr, int *iommu_* @internal * Get device information. * -* @param sysfs_base -* sysfs path prefix. -* -* @param dev_addr -* device location. +* This function retrieves VFIO device information from an already opened +* device. The device must be opened with `dev_vfio_setup_device()` first. * * @param vfio_dev_fd -* VFIO fd. +* VFIO device fd (must be a valid, already opened fd). * * @param device_info -* Device information. +* Pointer to device information structure to be filled. * * @return * 0 on success. -* <0 on failure. +* <0 on failure. */ __rte_internal int -dev_vfio_get_device_info (const char *sysfs_base,const char *dev_addr, -int *vfio_dev_fd,struct vfio_device_info *device_info); +dev_vfio_get_device_info (int vfio_dev_fd,struct vfio_device_info *device_info);/** * @internal
Signature · 1 line
2.54.0
PATCH v19 10/26 vfio: add container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
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.
--- lib/eal/linux/eal_vfio.c | 27 +++++++++++++++++++++++++++ lib/eal/linux/include/dev_vfio.h | 24 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
lib/eal/linux/eal_vfio.c +27 -0
@@ -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) intdev_vfio_container_group_bind (int container_fd,int iommu_group_num)
lib/eal/linux/include/dev_vfio.h +24 -0
@@ -264,6 +264,30 @@ __rte_internalint 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.
Signature · 1 line
2.54.0
PATCH v19 11/26 net/nbl: do not use VFIO group bind API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The NBL driver currently uses group bind API, but it is using it only to get group fd and nothing else. In context of NBL driver, this is the only usage of VFIO API's in the driver, and it is not necessary to use it for what NBL driver is trying to accomplish.
Use a direct open() call instead, store the group fd in common structure, and find group fd's opened earlier to prevent us from opening the same group fd twice.
--- drivers/net/nbl/nbl_common/nbl_userdev.c | 63 +++++++++++++++++------ drivers/net/nbl/nbl_common/nbl_userdev.h | 1 + drivers/net/nbl/nbl_include/nbl_include.h | 1 + 3 files changed, 50 insertions(+), 15 deletions(-)
drivers/net/nbl/nbl_common/nbl_userdev.c +48 -15
@@ -388,6 +388,28 @@ nbl_userdev_mem_event_callback(enum rte_mem_event type, const void *addr, size_t } } +static int +nbl_open_group_fd (int iommu_group_num) +{ +char path[PATH_MAX ]; + +snprintf (path,sizeof (path),DEV_VFIO_GROUP_FMT , iommu_group_num); +return open (path,O_RDWR ); +} + +static int +nbl_find_group_fd (int iommu_group_num) +{ +struct nbl_adapter *adapter; + + TAILQ_FOREACH(adapter, &nbl_adapter_list, next) { +if (adapter->common.iommu_group_num == iommu_group_num) +return adapter->common.groupfd; + } + +return -1 ; +} +static int nbl_mdev_map_device (struct nbl_adapter *adapter) {const struct rte_pci_device *pci_dev = adapter->pci_dev;
@@ -401,6 +423,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter)u64 dma_limit =NBL_USERDEV_DMA_LIMIT ;int ret, container_create =0 , container_set =0 ;int vfio_group_fd, container = nbl_default_container; +bool new_group = false;rte_pci_device_name (&pci_dev->addr, dev_name,RTE_DEV_NAME_MAX_LEN ); snprintf(pathname, sizeof(pathname),
@@ -425,11 +448,18 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) }NBL_LOG (DEBUG ,"nbl vfio container %d" , container); - vfio_group_fd =dev_vfio_container_group_bind (container, common->iommu_group_num); +rte_mcfg_mem_read_lock (); + vfio_group_fd =nbl_find_group_fd (common->iommu_group_num); +rte_mcfg_mem_read_unlock (); +if (vfio_group_fd <0 ) { + vfio_group_fd =nbl_open_group_fd (common->iommu_group_num); + new_group = true; + }if (vfio_group_fd <0 ) {NBL_LOG (ERR ,"nbl vfio group bind failed, %d" , vfio_group_fd); goto free_container; } + common->groupfd = vfio_group_fd;/* check if the group is viable */ ret =ioctl (vfio_group_fd,VFIO_GROUP_GET_STATUS , &group_status);
@@ -518,13 +548,13 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) close_fd:close (common->devfd); unregister_mem_event: -if (nbl_group_count ==1 ) { +if (container_set && nbl_group_count ==1 ) {rte_mcfg_mem_read_lock ();rte_mem_event_callback_unregister (NBL_USERDEV_EVENT_CLB_NAME ,NULL );rte_mcfg_mem_read_unlock (); } free_dma_map: -if (nbl_group_count ==1 ) { +if (container_set && nbl_group_count ==1 ) {rte_mcfg_mem_read_lock ();nbl_userdev_dma_free ();rte_mcfg_mem_read_unlock ();
@@ -535,8 +565,8 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) nbl_group_count--; } free_group: -close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +if (new_group) +close (vfio_group_fd); free_container:if (container_create)dev_vfio_container_destroy (container);
@@ -547,21 +577,24 @@ static int nbl_mdev_unmap_device(struct nbl_adapter *adapter) {struct nbl_common_info *common = &adapter->common;int vfio_group_fd, ret; +bool last_group_user;rte_mcfg_mem_read_lock ();TAILQ_REMOVE (&nbl_adapter_list, adapter, next);close (common->devfd); - vfio_group_fd =dev_vfio_container_group_bind (nbl_default_container, - common->iommu_group_num); + common->devfd =-1 ; + vfio_group_fd = common->groupfd; + last_group_user =nbl_find_group_fd (common->iommu_group_num) <0 ;NBL_LOG (DEBUG ,"close vfio_group_fd %d" , vfio_group_fd); - ret =ioctl (vfio_group_fd,VFIO_GROUP_UNSET_CONTAINER , &nbl_default_container); -if (ret) -NBL_LOG (ERR ,"unset container, error %i (%s) %d" , - errno,strerror (errno), ret); - nbl_group_count--; - ret =dev_vfio_container_group_unbind (nbl_default_container, common->iommu_group_num); -if (ret) -NBL_LOG (ERR ,"vfio container group unbind failed %d" , ret); +if (last_group_user) { + ret =ioctl (vfio_group_fd,VFIO_GROUP_UNSET_CONTAINER , &nbl_default_container); +if (ret) +NBL_LOG (ERR ,"unset container, error %i (%s) %d" , + errno,strerror (errno), ret); + nbl_group_count--; +close (vfio_group_fd); + common->groupfd =-1 ; + }if (!nbl_group_count) {rte_mem_event_callback_unregister (NBL_USERDEV_EVENT_CLB_NAME ,NULL );nbl_userdev_dma_free ();
drivers/net/nbl/nbl_common/nbl_userdev.h +1 -0
@@ -11,6 +11,7 @@#define NBL_USERDEV_INIT_COMMON (common) do { \ typeof(common) _comm = (common); \ _comm->devfd = -1; \ + _comm->groupfd = -1; \ _comm->eventfd = -1; \ _comm->specific_dma = false; \ _comm->dma_set_msb = false; \
drivers/net/nbl/nbl_include/nbl_include.h +1 -0
@@ -132,6 +132,7 @@ struct nbl_common_info {u16 vsi_id;u16 instance_id;int devfd; +int groupfd;int eventfd;int ifindex;int iommu_group_num;
Signature · 1 line
2.54.0
PATCH v19 12/26 net/ntnic: use container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The NTNIC driver uses VFIO group bind/unbind functionality for container device assignment purposes. Use the new container device assignment API instead to provide clearer semantics.
--- drivers/net/ntnic/ntnic_vfio.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/net/ntnic/ntnic_vfio.c +9 -21
@@ -28,7 +28,6 @@ nt_vfio_vf_num(const struct rte_pci_device *pdev)/* Internal API */ struct vfio_dev {int container_fd; -int group_fd;int dev_fd;uint64_t iova_addr; };
@@ -50,7 +49,6 @@ nthw_vfio_setup(struct rte_pci_device *dev) {int ret;char devname[RTE_DEV_NAME_MAX_LEN ] = {0 }; -int iommu_group_num;int vf_num;struct vfio_dev *vfio;
@@ -66,14 +64,9 @@ nthw_vfio_setup(struct rte_pci_device *dev) } vfio->dev_fd =-1 ; - vfio->group_fd =-1 ; vfio->iova_addr =START_VF_IOVA ;rte_pci_device_name (&dev->addr, devname,RTE_DEV_NAME_MAX_LEN ); - ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, &iommu_group_num); -if (ret <=0 ) -return -1 ; -if (vf_num ==0 ) {/* use default container for pf0 */ vfio->container_fd =DEV_VFIO_DEFAULT_CONTAINER_FD ;
@@ -86,17 +79,14 @@ nthw_vfio_setup(struct rte_pci_device *dev) "VFIO device setup failed. VFIO container creation failed.");return -1 ; } - } - - vfio->group_fd =dev_vfio_container_group_bind (vfio->container_fd, iommu_group_num); - -if (vfio->group_fd <0 ) { -NT_LOG (ERR ,NTNIC , -"VFIO device setup failed. VFIO container group bind failed." ); - goto err; - } + ret =dev_vfio_container_assign_device (vfio->container_fd, +rte_pci_get_sysfs_path (), devname); +if (ret <0 ) { +NT_LOG (ERR ,NTNIC , +"VFIO device setup failed. Assign device to container failed." ); + goto err; + } -if (vf_num >0 ) {if (rte_pci_map_device (dev)) {NT_LOG (ERR ,NTNIC ,"Map VFIO device failed. is the vfio-pci driver loaded?" );
@@ -106,10 +96,8 @@ nthw_vfio_setup(struct rte_pci_device *dev) vfio->dev_fd =rte_intr_dev_fd_get (dev->intr_handle); -NT_LOG (DBG ,NTNIC , -"%s: VFIO id=%d, dev_fd=%d, container_fd=%d, group_fd=%d, iommu_group_num=%d" , - dev->name, vf_num, vfio->dev_fd, vfio->container_fd, vfio->group_fd, - iommu_group_num); +NT_LOG (DBG ,NTNIC ,"%s: VFIO id=%d, dev_fd=%d, container_fd=%d" , + dev->name, vf_num, vfio->dev_fd, vfio->container_fd);return vf_num;
Signature · 1 line
2.54.0
PATCH v19 13/26 vdpa/ifc: use container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The IFC vDPA driver uses VFIO group bind/unbind functionality for container device assignment purposes. Use the new container device assignment API instead to provide clearer semantics. Since group API is no longer used after these changes, remove its implementation.
--- drivers/vdpa/ifc/ifcvf_vdpa.c | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-)
drivers/vdpa/ifc/ifcvf_vdpa.c +3 -31
@@ -59,7 +59,6 @@ struct ifcvf_internal {struct ifcvf_hw hw;int configured;int vfio_container_fd; -int vfio_group_fd;int vfio_dev_fd;rte_thread_t tid;/* thread for notify relay */ rte_thread_t intr_tid;/* thread for config space change interrupt relay */
@@ -175,28 +174,19 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal) {struct rte_pci_device *dev = internal->pdev;char devname[RTE_DEV_NAME_MAX_LEN ] = {0 }; -int iommu_group_num; -int i, ret; +int i; internal->vfio_dev_fd =-1 ; - internal->vfio_group_fd =-1 ; internal->vfio_container_fd =-1 ;rte_pci_device_name (&dev->addr, devname,RTE_DEV_NAME_MAX_LEN ); - ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, - &iommu_group_num); -if (ret <=0 ) { -DRV_LOG (ERR ,"%s failed to get IOMMU group" , devname); -return -1 ; - } internal->vfio_container_fd =dev_vfio_container_create ();if (internal->vfio_container_fd <0 )return -1 ; - internal->vfio_group_fd =dev_vfio_container_group_bind ( - internal->vfio_container_fd, iommu_group_num); -if (internal->vfio_group_fd <0 ) +if (dev_vfio_container_assign_device (internal->vfio_container_fd, +rte_pci_get_sysfs_path (), devname) <0 ) goto err;if (rte_pci_map_device (dev))
@@ -1214,22 +1204,6 @@ ifcvf_set_features(int vid)return 0 ; } -static int -ifcvf_get_vfio_group_fd (int vid) -{ -struct rte_vdpa_device *vdev; -struct internal_list *list; - - vdev =rte_vhost_get_vdpa_device (vid); - list =find_internal_resource_by_vdev (vdev); -if (list ==NULL ) { -DRV_LOG (ERR ,"Invalid vDPA device: %p" , vdev); -return -1 ; - } - -return list->internal->vfio_group_fd; -} -static int ifcvf_get_vfio_device_fd (int vid) {
@@ -1475,7 +1449,6 @@ static struct rte_vdpa_dev_ops ifcvf_net_ops = { .set_vring_state = ifcvf_set_vring_state, .set_features = ifcvf_set_features, .migration_done = NULL, - .get_vfio_group_fd = ifcvf_get_vfio_group_fd, .get_vfio_device_fd = ifcvf_get_vfio_device_fd, .get_notify_area = ifcvf_get_notify_area, .get_dev_type = ifcvf_get_device_type,
@@ -1606,7 +1579,6 @@ static struct rte_vdpa_dev_ops ifcvf_blk_ops = { .dev_close = ifcvf_dev_close, .set_vring_state = ifcvf_set_vring_state, .migration_done = NULL, - .get_vfio_group_fd = ifcvf_get_vfio_group_fd, .get_vfio_device_fd = ifcvf_get_vfio_device_fd, .get_notify_area = ifcvf_get_notify_area, .get_config = ifcvf_blk_get_config,
Signature · 1 line
2.54.0
PATCH v19 14/26 vdpa/nfp: use container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The NFP vDPA driver uses VFIO group bind/unbind functionality for container device assignment purposes. Use the new container device assignment API instead to provide clearer semantics. Since group API is no longer used after these changes, remove its implementation.
--- drivers/vdpa/nfp/nfp_vdpa.c | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-)
drivers/vdpa/nfp/nfp_vdpa.c +5 -32
@@ -36,9 +36,7 @@ struct nfp_vdpa_dev {struct nfp_vdpa_hw hw;int vfio_container_fd; -int vfio_group_fd;int vfio_dev_fd; -int iommu_group;rte_thread_t tid;/**< Thread for notify relay */ int epoll_fd;
@@ -120,33 +118,26 @@ nfp_vdpa_vfio_setup(struct nfp_vdpa_dev *device)struct rte_pci_device *pci_dev = device->pci_dev;rte_pci_device_name (&pci_dev->addr, dev_name,RTE_DEV_NAME_MAX_LEN ); - ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, - &device->iommu_group); -if (ret <=0 ) -return -1 ; device->vfio_container_fd =dev_vfio_container_create ();if (device->vfio_container_fd <0 )return -1 ; - device->vfio_group_fd =dev_vfio_container_group_bind ( - device->vfio_container_fd, device->iommu_group); -if (device->vfio_group_fd <0 ) + ret =dev_vfio_container_assign_device (device->vfio_container_fd, +rte_pci_get_sysfs_path (), dev_name); +if (ret <0 ) goto container_destroy; -DRV_VDPA_LOG (DEBUG ,"The container_fd=%d, group_fd=%d." , - device->vfio_container_fd, device->vfio_group_fd); +DRV_VDPA_LOG (DEBUG ,"container_fd=%d" , device->vfio_container_fd); ret =rte_pci_map_device (pci_dev);if (ret !=0 ) - goto group_unbind; + goto container_destroy; device->vfio_dev_fd =rte_intr_dev_fd_get (pci_dev->intr_handle);return 0 ; -group_unbind: -dev_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); container_destroy:dev_vfio_container_destroy (device->vfio_container_fd);
@@ -157,7 +148,6 @@ static void nfp_vdpa_vfio_teardown(struct nfp_vdpa_dev *device) {rte_pci_unmap_device (device->pci_dev); -dev_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group);dev_vfio_container_destroy (device->vfio_container_fd); }
@@ -1023,22 +1013,6 @@ nfp_vdpa_dev_close(int vid)return 0 ; } -static int -nfp_vdpa_get_vfio_group_fd (int vid) -{ -struct rte_vdpa_device *vdev; -struct nfp_vdpa_dev_node *node; - - vdev =rte_vhost_get_vdpa_device (vid); - node =nfp_vdpa_find_node_by_vdev (vdev); -if (node ==NULL ) { -DRV_VDPA_LOG (ERR ,"Invalid vDPA device: %p." , vdev); -return -ENODEV ; - } - -return node->device->vfio_group_fd; -} -static int nfp_vdpa_get_vfio_device_fd (int vid) {
@@ -1190,7 +1164,6 @@ struct rte_vdpa_dev_ops nfp_vdpa_ops = { .dev_close = nfp_vdpa_dev_close, .set_vring_state = nfp_vdpa_set_vring_state, .set_features = nfp_vdpa_set_features, - .get_vfio_group_fd = nfp_vdpa_get_vfio_group_fd, .get_vfio_device_fd = nfp_vdpa_get_vfio_device_fd, .get_notify_area = nfp_vdpa_get_notify_area, };
Signature · 1 line
2.54.0
PATCH v19 15/26 vdpa/sfc: use container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The SFC vDPA driver uses VFIO group bind/unbind functionality for container device assignment purposes. Use the new container device assignment API instead to provide clearer semantics.
--- drivers/vdpa/sfc/sfc_vdpa.c | 39 +++++++------------------------------ drivers/vdpa/sfc/sfc_vdpa.h | 2 -- 2 files changed, 7 insertions(+), 34 deletions(-)
drivers/vdpa/sfc/sfc_vdpa.c +7 -32
@@ -80,22 +80,12 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva) goto fail_container_create; } - rc =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, - &sva->iommu_group_num); -if (rc <=0 ) { -sfc_vdpa_err (sva,"failed to get IOMMU group for %s : %s" , - dev_name,rte_strerror (-rc)); - goto fail_get_group_num; - } - - sva->vfio_group_fd = -dev_vfio_container_group_bind (sva->vfio_container_fd, - sva->iommu_group_num); -if (sva->vfio_group_fd <0 ) { -sfc_vdpa_err (sva, -"failed to bind IOMMU group %d to container %d" , - sva->iommu_group_num, sva->vfio_container_fd); - goto fail_group_bind; + rc =dev_vfio_container_assign_device (sva->vfio_container_fd, +rte_pci_get_sysfs_path (), dev_name); +if (rc <0 ) { +sfc_vdpa_err (sva,"failed to assign device %s to container %d" , + dev_name, sva->vfio_container_fd); + goto fail_device_assign; }if (rte_pci_map_device (dev) !=0 ) {
@@ -109,15 +99,7 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva)return 0 ; fail_pci_map_device: -if (dev_vfio_container_group_unbind (sva->vfio_container_fd, - sva->iommu_group_num) !=0 ) { -sfc_vdpa_err (sva, -"failed to unbind IOMMU group %d from container %d" , - sva->iommu_group_num, sva->vfio_container_fd); - } - -fail_group_bind: -fail_get_group_num: +fail_device_assign:if (dev_vfio_container_destroy (sva->vfio_container_fd) !=0 ) {sfc_vdpa_err (sva,"failed to destroy container %d" , sva->vfio_container_fd);
@@ -132,13 +114,6 @@ sfc_vdpa_vfio_teardown(struct sfc_vdpa_adapter *sva) {rte_pci_unmap_device (sva->pdev); -if (dev_vfio_container_group_unbind (sva->vfio_container_fd, - sva->iommu_group_num) !=0 ) { -sfc_vdpa_err (sva, -"failed to unbind IOMMU group %d from container %d" , - sva->iommu_group_num, sva->vfio_container_fd); - } -if (dev_vfio_container_destroy (sva->vfio_container_fd) !=0 ) { sfc_vdpa_err(sva, "failed to destroy container %d",
drivers/vdpa/sfc/sfc_vdpa.h +0 -2
@@ -70,10 +70,8 @@ struct sfc_vdpa_adapter {sfc_vdpa_filter_t filters; -int vfio_group_fd;int vfio_dev_fd;int vfio_container_fd; -int iommu_group_num;struct sfc_vdpa_ops_data *ops_data; };
Signature · 1 line
2.54.0
PATCH v19 16/26 vhost: remove group-related API from driver
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The vDPA driver API has "get_vfio_group_fd" in its ops structure, but no driver is using it any more, as better API's were added and implemented. Remove this API from vDPA ops structure.
---
Changes since v18:
- squashed vdpa/mlx5 update,
--- doc/guides/prog_guide/vhost_lib.rst | 4 ---- doc/guides/rel_notes/deprecation.rst | 4 ---- doc/guides/rel_notes/release_26_11.rst | 3 +++ drivers/vdpa/mlx5/mlx5_vdpa.c | 1 - lib/vhost/vdpa_driver.h | 3 --- 5 files changed, 3 insertions(+), 12 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +0 -4
@@ -471,10 +471,6 @@ Finally, a set of device ops is defined for device specific operations: Called to allow the device to respond to RARP sending. -* ``get_vfio_group_fd`` - - Called to get the VFIO group fd of the device. - * ``get_vfio_device_fd`` Called to get the VFIO device fd of the device.
doc/guides/rel_notes/deprecation.rst +0 -4
@@ -29,10 +29,6 @@ Deprecation Notices Use the ``-S <service-corelist>`` parameter instead to specify the cores to be used for background services in DPDK. -* vdpa: The vDPA driver API will no longer offer ``get_vfio_group_fd`` - as part of its internal API. All drivers will be adjusted - to use the new unified VFIO container device assignment API. - * rte_smp_*mb: These APIs provide full barrier functionality. However, many use cases do not require full barriers. To support such use cases, DPDK has adopted atomic operations from
doc/guides/rel_notes/release_26_11.rst +3 -0
@@ -317,6 +317,9 @@ API Changes ``rte_reorder_seqn``, ``rte_reorder_drain_up_to_seqn``, ``rte_reorder_min_seqn_set`` and ``rte_reorder_memory_footprint_get``. +* vhost: Removed ``get_vfio_group_fd`` from ``struct rte_vdpa_dev_ops``. + vDPA drivers should now use the VFIO container device assignment API. + * telemetry: Promoted the following API from experimental to stable: * ``rte_tel_data_add_array_uint_hex``
drivers/vdpa/mlx5/mlx5_vdpa.c +0 -1
@@ -523,7 +523,6 @@ static struct rte_vdpa_dev_ops mlx5_vdpa_ops = { .set_vring_state = mlx5_vdpa_set_vring_state, .set_features = mlx5_vdpa_features_set, .migration_done = NULL, - .get_vfio_group_fd = NULL, .get_vfio_device_fd = mlx5_vdpa_get_device_fd, .get_notify_area = mlx5_vdpa_get_notify_area, .get_stats_names = mlx5_vdpa_get_stats_names,
lib/vhost/vdpa_driver.h +0 -3
@@ -50,9 +50,6 @@ struct rte_vdpa_dev_ops {/** Destination operations when migration done */ int (*migration_done)(int vid); -/** Get the vfio group fd */ -int (*get_vfio_group_fd)(int vid); -/** Get the vfio device fd */ int (*get_vfio_device_fd)(int vid);
Signature · 1 line
2.54.0
PATCH v19 17/26 vfio: remove group-based API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
All drivers have been adjusted to not use the VFIO group API directly and instead rely on container device assignment model, so the group API is no longer useful and can be removed.
--- lib/eal/linux/eal_vfio.c | 48 +++++++++++------------ lib/eal/linux/eal_vfio.h | 2 + lib/eal/linux/eal_vfio_mp_sync.c | 2 +- lib/eal/linux/include/dev_vfio.h | 66 -------------------------------- 4 files changed, 26 insertions(+), 92 deletions(-)
lib/eal/linux/eal_vfio.c +23 -25
@@ -114,6 +114,9 @@ static int vfio_noiommu_dma_mem_map(int, uint64_t, uint64_t, uint64_t, int);static int vfio_dma_mem_map (struct vfio_config *vfio_cfg,uint64_t vaddr,uint64_t iova,uint64_t len,int do_map); +static int vfio_container_group_bind (int container_fd,int iommu_group_num); +static int vfio_container_group_unbind (int container_fd,int iommu_group_num); +/* IOMMU types we support */ static const struct vfio_iommu_type iommu_types[] = {/* x86 IOMMU, otherwise known as type 1 */
@@ -579,9 +582,8 @@ get_vfio_cfg_by_container_fd(int container_fd)return NULL ; } -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_group_fd)int -dev_vfio_get_group_fd (int iommu_group_num) +vfio_get_group_fd_by_num (int iommu_group_num) {struct vfio_config *vfio_cfg;
@@ -781,9 +783,8 @@ vfio_sync_default_container(void)return -1 ; } -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_clear_group) -int -dev_vfio_clear_group (int vfio_group_fd) +static int +vfio_clear_group (int vfio_group_fd) {int i;struct vfio_config *vfio_cfg;
@@ -842,7 +843,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ;/* get the actual group fd */ - vfio_group_fd =dev_vfio_get_group_fd (iommu_group_num); + vfio_group_fd =vfio_get_group_fd_by_num (iommu_group_num);if (vfio_group_fd <0 && vfio_group_fd != -ENOENT )return -1 ;
@@ -868,14 +869,14 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deEAL_LOG (ERR ,"%s cannot get VFIO group status, " "error %i (%s)" , dev_addr, errno,strerror (errno));close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }else if (!(group_status.flags &VFIO_GROUP_FLAGS_VIABLE )) {EAL_LOG (ERR ,"%s VFIO group is not viable! " "Not all devices in IOMMU group bound to VFIO or unbound" , dev_addr);close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }
@@ -896,7 +897,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de"%s cannot add VFIO group to container, error " "%i (%s)", dev_addr, errno, strerror(errno));close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }
@@ -920,7 +921,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de"%s failed to select IOMMU type" , dev_addr);close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }/* lock memory hotplug before mapping and release it
@@ -937,7 +938,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de"%i (%s)" , dev_addr, errno, strerror(errno));close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);rte_mcfg_mem_read_unlock ();return -1 ; }
@@ -1006,7 +1007,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deif (ret <0 ) {EAL_LOG (ERR ,"Could not sync default VFIO container" );close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }/* we have successfully initialized VFIO, notify user */
@@ -1043,7 +1044,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deEAL_LOG (WARNING ,"Getting a vfio_dev_fd for %s failed" , dev_addr);close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }
@@ -1084,10 +1085,9 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, }/* get the actual group fd */ - vfio_group_fd =dev_vfio_get_group_fd (iommu_group_num); + vfio_group_fd =vfio_get_group_fd_by_num (iommu_group_num);if (vfio_group_fd <0 ) { -EAL_LOG (INFO ,"dev_vfio_get_group_fd failed for %s" , - dev_addr); +EAL_LOG (INFO ,"vfio_get_group_fd_by_num failed for %s" , dev_addr); ret = vfio_group_fd; goto out; }
@@ -1122,7 +1122,7 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, goto out; } -if (dev_vfio_clear_group (vfio_group_fd) <0 ) { +if (vfio_clear_group (vfio_group_fd) <0 ) {EAL_LOG (INFO ,"Error when clearing group for %s" , dev_addr); ret =-1 ;
@@ -2177,7 +2177,7 @@ dev_vfio_container_destroy(int container_fd)for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++)if (vfio_cfg->vfio_groups[i].group_num !=-1 ) -dev_vfio_container_group_unbind (container_fd, +vfio_container_group_unbind (container_fd, vfio_cfg->vfio_groups[i].group_num);close (container_fd);
@@ -2205,7 +2205,7 @@ dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base,return -1 ; } - ret =dev_vfio_container_group_bind (vfio_container_fd, iommu_group_num); + ret =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);
@@ -2215,9 +2215,8 @@ dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base,return 0 ; } -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_container_group_bind) -int -dev_vfio_container_group_bind (int container_fd,int iommu_group_num) +static int +vfio_container_group_bind (int container_fd,int iommu_group_num) {struct vfio_config *vfio_cfg;
@@ -2233,9 +2232,8 @@ dev_vfio_container_group_bind(int container_fd, int iommu_group_num)return vfio_get_group_fd (vfio_cfg, iommu_group_num); } -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_container_group_unbind) -int -dev_vfio_container_group_unbind (int container_fd,int iommu_group_num) +static int +vfio_container_group_unbind (int container_fd,int iommu_group_num) {struct vfio_group *cur_grp =NULL ;struct vfio_config *vfio_cfg;
lib/eal/linux/eal_vfio.h +2 -0
@@ -51,6 +51,8 @@ vfio_set_iommu_type(int vfio_container_fd);int vfio_get_iommu_type (void ); +int vfio_get_group_fd_by_num (int iommu_group_num); +/* check if we have any supported extensions */ int vfio_has_supported_extensions (int vfio_container_fd);
lib/eal/linux/eal_vfio_mp_sync.c +1 -1
@@ -34,7 +34,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)case SOCKET_REQ_GROUP : r->req =SOCKET_REQ_GROUP ; r->group_num = m->group_num; - fd =dev_vfio_get_group_fd (m->group_num); + fd =vfio_get_group_fd_by_num (m->group_num);if (fd <0 && fd != -ENOENT ) r->result =SOCKET_ERR ;else if (fd == -ENOENT )
lib/eal/linux/include/dev_vfio.h +0 -66
84 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v19 18/26 vfio: rename some internal types and macros
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Some types and macros will be used in multiple code units in later commits.
Prefix them with vfio_/VFIO_.
Rename vfio_config as vfio_container and pass it instead of the container FD.
--- lib/eal/linux/eal_vfio.c | 548 ++++++++++++++----------------- lib/eal/linux/eal_vfio.h | 50 ++- lib/eal/linux/eal_vfio_mp_sync.c | 26 +- 3 files changed, 298 insertions(+), 326 deletions(-)
lib/eal/linux/eal_vfio.c +245 -303
@@ -29,36 +29,9 @@#define VFIO_MEM_EVENT_CLB_NAME "vfio_mem_event_clb" -/* hot plug/unplug of VFIO groups may cause all DMA maps to be dropped. we can -* recreate the mappings for DPDK segments, but we cannot do so for memory that -* was registered by the user themselves, so we need to store the user mappings -* somewhere, to recreate them later. -*/ -#define EAL_VFIO_MAX_USER_MEM_MAPS 256 -struct user_mem_map { -uint64_t addr;/**< start VA */ -uint64_t iova;/**< start IOVA */ -uint64_t len;/**< total length of the mapping */ -uint64_t chunk;/**< this mapping can be split in chunks of this size */ -}; - -struct user_mem_maps { -rte_spinlock_recursive_t lock; -int n_maps; -struct user_mem_map maps[EAL_VFIO_MAX_USER_MEM_MAPS ]; -}; - -struct vfio_config { -int vfio_container_fd; -int vfio_active_groups; -const struct vfio_iommu_type *vfio_iommu_type; -struct vfio_group vfio_groups[RTE_MAX_VFIO_GROUPS ]; -struct user_mem_maps mem_maps; -}; -/* per-process VFIO config */ -static struct vfio_config vfio_cfgs[RTE_MAX_VFIO_CONTAINERS ]; -static struct vfio_config *default_vfio_cfg = &vfio_cfgs[0 ]; +static struct vfio_container vfio_containers[RTE_MAX_VFIO_CONTAINERS ]; +static struct vfio_container *default_vfio_cfg = &vfio_containers[0 ];/* whether VFIO is enabled (usable) in this process */ static bool vfio_enabled;
@@ -105,14 +78,14 @@ vfio_check_module(enum dev_vfio_module module)return 1 ; } -static int vfio_type1_dma_map (int ); -static int vfio_type1_dma_mem_map (int ,uint64_t ,uint64_t ,uint64_t ,int ); -static int vfio_spapr_dma_map (int ); -static int vfio_spapr_dma_mem_map (int ,uint64_t ,uint64_t ,uint64_t ,int ); -static int vfio_noiommu_dma_map (int ); -static int vfio_noiommu_dma_mem_map (int ,uint64_t ,uint64_t ,uint64_t ,int ); -static int vfio_dma_mem_map (struct vfio_config *vfio_cfg,uint64_t vaddr, -uint64_t iova,uint64_t len,int do_map); +static int vfio_type1_dma_map (struct vfio_container *); +static int vfio_type1_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int ); +static int vfio_spapr_dma_map (struct vfio_container *); +static int vfio_spapr_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int ); +static int vfio_noiommu_dma_map (struct vfio_container *); +static int vfio_noiommu_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int ); +static int vfio_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova, +uint64_t len,int do_map);static int vfio_container_group_bind (int container_fd,int iommu_group_num);static int vfio_container_group_unbind (int container_fd,int iommu_group_num);
@@ -146,10 +119,9 @@ static const struct vfio_iommu_type iommu_types[] = { };static int -is_null_map (const struct user_mem_map *map) +is_null_map (const struct vfio_user_mem_map *map) { -return map->addr ==0 && map->iova ==0 && - map->len ==0 && map->chunk ==0 ; +return map->addr ==0 && map->iova ==0 && map->len ==0 && map->chunk ==0 ; }/* we may need to merge user mem maps together in case of user mapping/unmapping
@@ -158,8 +130,8 @@ is_null_map(const struct user_mem_map *map)static int user_mem_map_cmp (const void *a,const void *b) { -const struct user_mem_map *umm_a = a; -const struct user_mem_map *umm_b = b; +const struct vfio_user_mem_map *umm_a = a; +const struct vfio_user_mem_map *umm_b = b;/* move null entries to end */ if (is_null_map (umm_a))
@@ -196,14 +168,14 @@ user_mem_map_cmp(const void *a, const void *b)* mappings that will be kept. */ static int -process_maps (struct user_mem_map *src,size_t src_len, -struct user_mem_map newmap[2 ],uint64_t vaddr,uint64_t len) +process_maps (struct vfio_user_mem_map *src,size_t src_len,struct vfio_user_mem_map newmap[2 ], +uint64_t vaddr,uint64_t len) { -struct user_mem_map *src_first = &src[0 ]; -struct user_mem_map *src_last = &src[src_len -1 ]; -struct user_mem_map *dst_first = &newmap[0 ]; +struct vfio_user_mem_map *src_first = &src[0 ]; +struct vfio_user_mem_map *src_last = &src[src_len -1 ]; +struct vfio_user_mem_map *dst_first = &newmap[0 ];/* we can get at most two new segments */ -struct user_mem_map *dst_last = &newmap[1 ]; +struct vfio_user_mem_map *dst_last = &newmap[1 ];uint64_t first_off = vaddr - src_first->addr;uint64_t last_off = (src_last->addr + src_last->len) - (vaddr + len);int newmap_len =0 ;
@@ -218,8 +190,8 @@ process_maps(struct user_mem_map *src, size_t src_len, }if (last_off !=0 ) {/* if we had start offset, we have two segments */ -struct user_mem_map *last = - first_off ==0 ? dst_first : dst_last; +struct vfio_user_mem_map *last = first_off ==0 ? dst_first : dst_last; + last->addr = (src_last->addr + src_last->len) - last_off; last->iova = (src_last->iova + src_last->len) - last_off; last->len = last_off;
@@ -232,15 +204,15 @@ process_maps(struct user_mem_map *src, size_t src_len,/* erase certain maps from the list */ static void -delete_maps (struct user_mem_maps *user_mem_maps,struct user_mem_map *del_maps, +delete_maps (struct vfio_user_mem_maps *user_mem_maps,struct vfio_user_mem_map *del_maps,size_t n_del) {unsigned int i;size_t j;for (i =0 , j =0 ; i <RTE_DIM (user_mem_maps->maps) && j < n_del; i++) { -struct user_mem_map *left = &user_mem_maps->maps[i]; -struct user_mem_map *right = &del_maps[j]; +struct vfio_user_mem_map *left = &user_mem_maps->maps[i]; +struct vfio_user_mem_map *right = &del_maps[j];if (user_mem_map_cmp (left, right) ==0 ) {memset (left,0 ,sizeof (*left));
@@ -251,15 +223,15 @@ delete_maps(struct user_mem_maps *user_mem_maps, struct user_mem_map *del_maps, }static void -copy_maps (struct user_mem_maps *user_mem_maps,struct user_mem_map *add_maps, +copy_maps (struct vfio_user_mem_maps *user_mem_maps,struct vfio_user_mem_map *add_maps,size_t n_add) {unsigned int i;size_t j;for (i =0 , j =0 ; i <RTE_DIM (user_mem_maps->maps) && j < n_add; i++) { -struct user_mem_map *left = &user_mem_maps->maps[i]; -struct user_mem_map *right = &add_maps[j]; +struct vfio_user_mem_map *left = &user_mem_maps->maps[i]; +struct vfio_user_mem_map *right = &add_maps[j];/* insert into empty space */ if (is_null_map (left)) {
@@ -272,10 +244,10 @@ copy_maps(struct user_mem_maps *user_mem_maps, struct user_mem_map *add_maps,/* try merging two maps into one, return 1 if succeeded */ static int -merge_map (struct user_mem_map *left,struct user_mem_map *right) +merge_map (struct vfio_user_mem_map *left,struct vfio_user_mem_map *right) {/* merge the same maps into one */ -if (memcmp (left, right,sizeof (struct user_mem_map )) ==0 ) +if (memcmp (left, right,sizeof (struct vfio_user_mem_map )) ==0 ) goto out;if (left->addr + left->len != right->addr)
@@ -293,13 +265,12 @@ merge_map(struct user_mem_map *left, struct user_mem_map *right) }static bool -addr_is_chunk_aligned (struct user_mem_map *maps,size_t n_maps, -uint64_t vaddr,uint64_t iova) +addr_is_chunk_aligned (struct vfio_user_mem_map *maps,size_t n_maps,uint64_t vaddr,uint64_t iova) {unsigned int i;for (i =0 ; i < n_maps; i++) { -struct user_mem_map *map = &maps[i]; +struct vfio_user_mem_map *map = &maps[i];uint64_t map_va_end = map->addr + map->len;uint64_t map_iova_end = map->iova + map->len;uint64_t map_va_off = vaddr - map->addr;
@@ -312,17 +283,15 @@ addr_is_chunk_aligned(struct user_mem_map *maps, size_t n_maps,bool addr_is_aligned = (map_va_off % map->chunk) ==0 ;bool iova_is_aligned = (map_iova_off % map->chunk) ==0 ; -if (addr_in_map && iova_in_map && - addr_is_aligned && iova_is_aligned) +if (addr_in_map && iova_in_map && addr_is_aligned && iova_is_aligned)return true; }return false; }static int -find_user_mem_maps (struct user_mem_maps *user_mem_maps,uint64_t addr, -uint64_t iova,uint64_t len,struct user_mem_map *dst, -size_t dst_len) +find_user_mem_maps (struct vfio_user_mem_maps *user_mem_maps,uint64_t addr,uint64_t iova, +uint64_t len,struct vfio_user_mem_map *dst,size_t dst_len) {uint64_t va_end = addr + len;uint64_t iova_end = iova + len;
@@ -331,18 +300,14 @@ find_user_mem_maps(struct user_mem_maps *user_mem_maps, uint64_t addr,int i, ret;for (i =0 , j =0 ; i < user_mem_maps->n_maps; i++) { -struct user_mem_map *map = &user_mem_maps->maps[i]; +struct vfio_user_mem_map *map = &user_mem_maps->maps[i];uint64_t map_va_end = map->addr + map->len;uint64_t map_iova_end = map->iova + map->len; -bool start_addr_in_map = (addr >= map->addr) && - (addr < map_va_end); -bool end_addr_in_map = (va_end > map->addr) && - (va_end <= map_va_end); -bool start_iova_in_map = (iova >= map->iova) && - (iova < map_iova_end); -bool end_iova_in_map = (iova_end > map->iova) && - (iova_end <= map_iova_end); +bool start_addr_in_map = (addr >= map->addr) && (addr < map_va_end); +bool end_addr_in_map = (va_end > map->addr) && (va_end <= map_va_end); +bool start_iova_in_map = (iova >= map->iova) && (iova < map_iova_end); +bool end_iova_in_map = (iova_end > map->iova) && (iova_end <= map_iova_end);/* do we have space in temporary map? */ if (j == dst_len) {
@@ -371,16 +336,16 @@ find_user_mem_maps(struct user_mem_maps *user_mem_maps, uint64_t addr,/* this will sort all user maps, and merge/compact any adjacent maps */ static void -compact_user_maps (struct user_mem_maps *user_mem_maps) +compact_user_maps (struct vfio_user_mem_maps *user_mem_maps) {unsigned int i; -qsort (user_mem_maps->maps,RTE_DIM (user_mem_maps->maps), -sizeof (user_mem_maps->maps[0 ]), user_mem_map_cmp); +qsort (user_mem_maps->maps,RTE_DIM (user_mem_maps->maps),sizeof (user_mem_maps->maps[0 ]), + user_mem_map_cmp);/* we'll go over the list backwards when merging */ for (i =RTE_DIM (user_mem_maps->maps) -2 ; i !=0 ; i--) { -struct user_mem_map *l, *r; +struct vfio_user_mem_map *l, *r; l = &user_mem_maps->maps[i]; r = &user_mem_maps->maps[i +1 ];
@@ -396,8 +361,8 @@ compact_user_maps(struct user_mem_maps *user_mem_maps)/* the entries are still sorted, but now they have holes in them, so * sort the list again. */ -qsort (user_mem_maps->maps,RTE_DIM (user_mem_maps->maps), -sizeof (user_mem_maps->maps[0 ]), user_mem_map_cmp); +qsort (user_mem_maps->maps,RTE_DIM (user_mem_maps->maps),sizeof (user_mem_maps->maps[0 ]), + user_mem_map_cmp); } static int
@@ -444,7 +409,7 @@ vfio_open_group_fd(int iommu_group_num, bool mp_request)/* if we're in a secondary process, request group fd from the primary * process via mp channel. */ - p->req =SOCKET_REQ_GROUP ; + p->req =VFIO_SOCKET_REQ_GROUP ; p->group_num = iommu_group_num;strcpy (mp_req.name,EAL_VFIO_MP ); mp_req.len_param =sizeof (*p);
@@ -455,9 +420,9 @@ vfio_open_group_fd(int iommu_group_num, bool mp_request) mp_reply.nb_received == 1) { mp_rep = &mp_reply.msgs[0 ]; p = (struct vfio_mp_param *)mp_rep->param; -if (p->result ==SOCKET_OK && mp_rep->num_fds ==1 ) { +if (p->result ==VFIO_SOCKET_OK && mp_rep->num_fds ==1 ) { vfio_group_fd = mp_rep->fds[0 ]; - }else if (p->result ==SOCKET_NO_FD ) { + }else if (p->result ==VFIO_SOCKET_NO_FD ) {EAL_LOG (ERR ,"Bad VFIO group fd" ); vfio_group_fd = -ENOENT ; }
@@ -469,18 +434,18 @@ vfio_open_group_fd(int iommu_group_num, bool mp_request)return vfio_group_fd; } -static struct vfio_config * +static struct vfio_container *get_vfio_cfg_by_group_num (int iommu_group_num) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i, j; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { - vfio_cfg = &vfio_cfgs[i]; -for (j =0 ; j <RTE_DIM (vfio_cfg->vfio_groups); j++) { -if (vfio_cfg->vfio_groups[j].group_num == +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { + cfg = &vfio_containers[i]; +for (j =0 ; j <RTE_DIM (cfg->vfio_groups); j++) { +if (cfg->vfio_groups[j].group_num == iommu_group_num) -return vfio_cfg; +return cfg; } }
@@ -488,28 +453,27 @@ get_vfio_cfg_by_group_num(int iommu_group_num) }static int -vfio_get_group_fd (struct vfio_config *vfio_cfg, -int iommu_group_num) +vfio_get_group_fd (struct vfio_container *cfg,int iommu_group_num) {struct vfio_group *cur_grp =NULL ;int vfio_group_fd;unsigned int i;/* check if we already have the group descriptor open */ -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) -if (vfio_cfg->vfio_groups[i].group_num == iommu_group_num) -return vfio_cfg->vfio_groups[i].fd; +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) +if (cfg->vfio_groups[i].group_num == iommu_group_num) +return cfg->vfio_groups[i].fd;/* Lets see first if there is room for a new group */ -if (vfio_cfg->vfio_active_groups ==RTE_DIM (vfio_cfg->vfio_groups)) { +if (cfg->vfio_active_groups ==RTE_DIM (cfg->vfio_groups)) {EAL_LOG (ERR ,"Maximum number of VFIO groups reached!" );return -1 ; }/* Now lets get an index for the new group */ -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) -if (vfio_cfg->vfio_groups[i].group_num ==-1 ) { - cur_grp = &vfio_cfg->vfio_groups[i]; +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) +if (cfg->vfio_groups[i].group_num ==-1 ) { + cur_grp = &cfg->vfio_groups[i];break ; }
@@ -534,7 +498,7 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg,*/ const struct internal_config *internal_conf =eal_get_internal_configuration ();bool mp_request = (internal_conf->process_type ==RTE_PROC_SECONDARY ) && - (vfio_cfg == default_vfio_cfg); + (cfg == default_vfio_cfg); vfio_group_fd =vfio_open_group_fd (iommu_group_num, mp_request);if (vfio_group_fd <0 ) {
@@ -545,28 +509,28 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg, cur_grp->group_num = iommu_group_num; cur_grp->fd = vfio_group_fd; - vfio_cfg->vfio_active_groups++; + cfg->vfio_active_groups++;return vfio_group_fd; } -static struct vfio_config * +static struct vfio_container *get_vfio_cfg_by_group_fd (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i, j; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { - vfio_cfg = &vfio_cfgs[i]; -for (j =0 ; j <RTE_DIM (vfio_cfg->vfio_groups); j++) -if (vfio_cfg->vfio_groups[j].fd == vfio_group_fd) -return vfio_cfg; +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { + cfg = &vfio_containers[i]; +for (j =0 ; j <RTE_DIM (cfg->vfio_groups); j++) +if (cfg->vfio_groups[j].fd == vfio_group_fd) +return cfg; }return NULL ; } -static struct vfio_config * +static struct vfio_container *get_vfio_cfg_by_container_fd (int container_fd) {unsigned int i;
@@ -574,9 +538,9 @@ get_vfio_cfg_by_container_fd(int container_fd)if (container_fd ==DEV_VFIO_DEFAULT_CONTAINER_FD )return default_vfio_cfg; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { -if (vfio_cfgs[i].vfio_container_fd == container_fd) -return &vfio_cfgs[i]; +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { +if (vfio_containers[i].container_fd == container_fd) +return &vfio_containers[i]; }return NULL ;
@@ -585,28 +549,28 @@ get_vfio_cfg_by_container_fd(int container_fd)int vfio_get_group_fd_by_num (int iommu_group_num) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;if (!vfio_enabled)return -1 ; -/* get the vfio_config it belongs to */ - vfio_cfg =get_vfio_cfg_by_group_num (iommu_group_num); - vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg; +/* get the vfio_container it belongs to */ + cfg =get_vfio_cfg_by_group_num (iommu_group_num); + cfg = cfg ? cfg : default_vfio_cfg; -return vfio_get_group_fd (vfio_cfg, iommu_group_num); +return vfio_get_group_fd (cfg, iommu_group_num); }static int get_vfio_group_idx (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i, j; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { - vfio_cfg = &vfio_cfgs[i]; -for (j =0 ; j <RTE_DIM (vfio_cfg->vfio_groups); j++) -if (vfio_cfg->vfio_groups[j].fd == vfio_group_fd) +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { + cfg = &vfio_containers[i]; +for (j =0 ; j <RTE_DIM (cfg->vfio_groups); j++) +if (cfg->vfio_groups[j].fd == vfio_group_fd)return j; }
@@ -616,11 +580,11 @@ get_vfio_group_idx(int vfio_group_fd)static void vfio_group_device_get (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;int i; - vfio_cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO group fd!" );return ; }
@@ -629,17 +593,17 @@ vfio_group_device_get(int vfio_group_fd)if (i <0 )EAL_LOG (ERR ,"Wrong VFIO group index (%d)" , i);else - vfio_cfg->vfio_groups[i].devices++; + cfg->vfio_groups[i].devices++; }static void vfio_group_device_put (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;int i; - vfio_cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO group fd!" );return ; }
@@ -648,17 +612,17 @@ vfio_group_device_put(int vfio_group_fd)if (i <0 )EAL_LOG (ERR ,"Wrong VFIO group index (%d)" , i);else - vfio_cfg->vfio_groups[i].devices--; + cfg->vfio_groups[i].devices--; }static int vfio_group_device_count (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;int i; - vfio_cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO group fd!" );return -1 ; }
@@ -669,7 +633,7 @@ vfio_group_device_count(int vfio_group_fd)return -1 ; } -return vfio_cfg->vfio_groups[i].devices; +return cfg->vfio_groups[i].devices; } static void
@@ -738,14 +702,13 @@ vfio_sync_default_container(void)return -1 ;/* default container fd should have been opened in dev_vfio_enable() */ -if (!vfio_enabled || - default_vfio_cfg->vfio_container_fd <0 ) { +if (!vfio_enabled || default_vfio_cfg->container_fd <0 ) {EAL_LOG (ERR ,"VFIO support is not initialized" );return -1 ; }/* find default container's IOMMU type */ - p->req =SOCKET_REQ_IOMMU_TYPE ; + p->req =VFIO_SOCKET_REQ_IOMMU_TYPE ;strcpy (mp_req.name,EAL_VFIO_MP ); mp_req.len_param =sizeof (*p); mp_req.num_fds =0 ;
@@ -755,7 +718,7 @@ vfio_sync_default_container(void) mp_reply.nb_received == 1) { mp_rep = &mp_reply.msgs[0 ]; p = (struct vfio_mp_param *)mp_rep->param; -if (p->result ==SOCKET_OK ) +if (p->result ==VFIO_SOCKET_OK ) iommu_type_id = p->iommu_type_id; }free (mp_reply.msgs);
@@ -787,13 +750,13 @@ static int vfio_clear_group(int vfio_group_fd) {int i; -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;if (!vfio_enabled)return -1 ; - vfio_cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO group fd!" );return -1 ; }
@@ -801,10 +764,10 @@ vfio_clear_group(int vfio_group_fd) i =get_vfio_group_idx (vfio_group_fd);if (i <0 )return -1 ; - vfio_cfg->vfio_groups[i].group_num =-1 ; - vfio_cfg->vfio_groups[i].fd =-1 ; - vfio_cfg->vfio_groups[i].devices =0 ; - vfio_cfg->vfio_active_groups--; + cfg->vfio_groups[i].group_num =-1 ; + cfg->vfio_groups[i].fd =-1 ; + cfg->vfio_groups[i].devices =0 ; + cfg->vfio_active_groups--;return 0 ; }
@@ -816,8 +779,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_destruct vfio_group_status group_status = { .argsz =sizeof (group_status) }; -struct vfio_config *vfio_cfg; -struct user_mem_maps *user_mem_maps; +struct vfio_container *cfg; +struct vfio_user_mem_maps *user_mem_maps;int vfio_container_fd;int vfio_group_fd;int iommu_group_num;
@@ -880,18 +843,17 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ; } -/* get the vfio_config it belongs to */ - vfio_cfg =get_vfio_cfg_by_group_num (iommu_group_num); - vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg; - vfio_container_fd = vfio_cfg->vfio_container_fd; - user_mem_maps = &vfio_cfg->mem_maps; +/* get the vfio_container it belongs to */ + cfg =get_vfio_cfg_by_group_num (iommu_group_num); + cfg = cfg ? cfg : default_vfio_cfg; + vfio_container_fd = cfg->container_fd; + user_mem_maps = &cfg->mem_maps;/* check if group does not have a container yet */ if (!(group_status.flags &VFIO_GROUP_FLAGS_CONTAINER_SET )) {/* add group to a container */ - ret =ioctl (vfio_group_fd,VFIO_GROUP_SET_CONTAINER , - &vfio_container_fd); + ret =ioctl (vfio_group_fd,VFIO_GROUP_SET_CONTAINER , &vfio_container_fd);if (ret) {EAL_LOG (ERR , "%s cannot add VFIO group to container, error "
@@ -910,7 +872,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* functionality. */ if (internal_conf->process_type ==RTE_PROC_PRIMARY && - vfio_cfg->vfio_active_groups ==1 && + cfg->vfio_active_groups ==1 &&vfio_group_device_count (vfio_group_fd) ==0 ) {const struct vfio_iommu_type *t;
@@ -928,8 +890,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* after registering callback, to prevent races */ rte_mcfg_mem_read_lock (); -if (vfio_cfg == default_vfio_cfg) - ret = t->dma_map_func (vfio_container_fd); +if (cfg == default_vfio_cfg) + ret = t->dma_map_func (cfg);else ret =0 ;if (ret) {
@@ -943,7 +905,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ; } - vfio_cfg->vfio_iommu_type = t; + cfg->vfio_iommu_type = t;/* re-map all user-mapped segments */ rte_spinlock_recursive_lock (&user_mem_maps->lock);
@@ -954,13 +916,10 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* be sure that DMA mapping is supported. */ for (i =0 ; i < user_mem_maps->n_maps; i++) { -struct user_mem_map *map; +struct vfio_user_mem_map *map; map = &user_mem_maps->maps[i]; - ret = t->dma_user_map_func ( - vfio_container_fd, - map->addr, map->iova, map->len, -1 ); + ret = t->dma_user_map_func (cfg, map->addr, map->iova, map->len,1 );if (ret) {EAL_LOG (ERR ,"Couldn't map user memory for DMA: " "va: 0x%" PRIx64 " "
@@ -977,7 +936,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_derte_spinlock_recursive_unlock (&user_mem_maps->lock);/* register callback for mem events */ -if (vfio_cfg == default_vfio_cfg) +if (cfg == default_vfio_cfg) ret =rte_mem_event_callback_register (VFIO_MEM_EVENT_CLB_NAME , vfio_mem_event_callback,NULL );
@@ -996,8 +955,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deEAL_LOG (DEBUG ,"Installed memory event callback for VFIO" ); } }else if (rte_eal_process_type () !=RTE_PROC_PRIMARY && - vfio_cfg == default_vfio_cfg && - vfio_cfg->vfio_iommu_type ==NULL ) { + cfg == default_vfio_cfg && + cfg->vfio_iommu_type ==NULL ) {/* if we're not a primary process, we do not set up the VFIO * container because it's already been set up by the primary * process. instead, we simply ask the primary about VFIO type
@@ -1060,7 +1019,7 @@ int dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, int vfio_dev_fd) { - struct vfio_config *vfio_cfg; + struct vfio_container *cfg;int vfio_group_fd;int iommu_group_num;int ret;
@@ -1092,9 +1051,9 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, goto out; } -/* get the vfio_config it belongs to */ - vfio_cfg =get_vfio_cfg_by_group_num (iommu_group_num); - vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg; +/* get the vfio_container it belongs to */ + cfg =get_vfio_cfg_by_group_num (iommu_group_num); + cfg = cfg ? cfg : default_vfio_cfg;/* At this point we got an active group. Closing it will make the * container detachment. If this is the last active group, VFIO kernel
@@ -1133,7 +1092,7 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr,/* if there are no active device groups, unregister the callback to * avoid spurious attempts to map/unmap memory from VFIO. */ -if (vfio_cfg == default_vfio_cfg && vfio_cfg->vfio_active_groups ==0 && +if (cfg == default_vfio_cfg && cfg->vfio_active_groups ==0 &&rte_eal_process_type () !=RTE_PROC_SECONDARY )rte_mem_event_callback_unregister (VFIO_MEM_EVENT_CLB_NAME ,NULL );
@@ -1162,16 +1121,16 @@ dev_vfio_enable(void)if (vfio_enabled)return 0 ; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { - vfio_cfgs[i].vfio_container_fd =-1 ; - vfio_cfgs[i].vfio_active_groups =0 ; - vfio_cfgs[i].vfio_iommu_type =NULL ; - vfio_cfgs[i].mem_maps.lock = lock; +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { + vfio_containers[i].container_fd =-1 ; + vfio_containers[i].vfio_active_groups =0 ; + vfio_containers[i].vfio_iommu_type =NULL ; + vfio_containers[i].mem_maps.lock = lock; -for (j =0 ; j <RTE_DIM (vfio_cfgs[i].vfio_groups); j++) { - vfio_cfgs[i].vfio_groups[j].fd =-1 ; - vfio_cfgs[i].vfio_groups[j].group_num =-1 ; - vfio_cfgs[i].vfio_groups[j].devices =0 ; +for (j =0 ; j <RTE_DIM (vfio_containers[i].vfio_groups); j++) { + vfio_containers[i].vfio_groups[j].fd =-1 ; + vfio_containers[i].vfio_groups[j].group_num =-1 ; + vfio_containers[i].vfio_groups[j].devices =0 ; } }
@@ -1204,19 +1163,18 @@ dev_vfio_enable(void)if (internal_conf->process_type ==RTE_PROC_PRIMARY ) {if (vfio_mp_sync_setup () ==-1 ) { - default_vfio_cfg->vfio_container_fd =-1 ; + default_vfio_cfg->container_fd =-1 ; }else {/* open a default container */ - default_vfio_cfg->vfio_container_fd =vfio_open_container_fd (false); + default_vfio_cfg->container_fd =vfio_open_container_fd (false); } }else {/* get the default container from the primary process */ - default_vfio_cfg->vfio_container_fd = -vfio_open_container_fd (true); + default_vfio_cfg->container_fd =vfio_open_container_fd (true); }/* check if we have VFIO driver enabled */ -if (default_vfio_cfg->vfio_container_fd !=-1 ) { +if (default_vfio_cfg->container_fd !=-1 ) {EAL_LOG (INFO ,"VFIO support initialized" ); vfio_enabled = true; }else {
@@ -1381,7 +1339,7 @@ vfio_open_container_fd(bool mp_request)* if we're in a secondary process, request container fd from the * primary process via mp channel */ - p->req =SOCKET_REQ_CONTAINER ; + p->req =VFIO_SOCKET_REQ_CONTAINER ;strcpy (mp_req.name,EAL_VFIO_MP ); mp_req.len_param =sizeof (*p); mp_req.num_fds =0 ;
@@ -1391,7 +1349,7 @@ vfio_open_container_fd(bool mp_request) mp_reply.nb_received == 1) { mp_rep = &mp_reply.msgs[0 ]; p = (struct vfio_mp_param *)mp_rep->param; -if (p->result ==SOCKET_OK && mp_rep->num_fds ==1 ) { +if (p->result ==VFIO_SOCKET_OK && mp_rep->num_fds ==1 ) { vfio_container_fd = mp_rep->fds[0 ];free (mp_reply.msgs);return vfio_container_fd;
@@ -1414,7 +1372,7 @@ dev_vfio_get_container_fd(void)if (!vfio_enabled)return -1 ; -return default_vfio_cfg->vfio_container_fd; +return default_vfio_cfg->container_fd; }RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_group_num)
@@ -1465,10 +1423,9 @@ dev_vfio_get_group_num(const char *sysfs_base, }static int -type1_map (const struct rte_memseg_list *msl,const struct rte_memseg *ms, -void *arg) +type1_map (const struct rte_memseg_list *msl,const struct rte_memseg *ms,void *arg) { -int *vfio_container_fd = arg; +struct vfio_container *cfg = arg;/* skip external memory that isn't a heap */ if (msl->external && !msl->heap)
@@ -1478,13 +1435,12 @@ type1_map(const struct rte_memseg_list *msl, const struct rte_memseg *ms,if (ms->iova ==RTE_BAD_IOVA )return 0 ; -return vfio_type1_dma_mem_map (*vfio_container_fd, ms->addr_64, ms->iova, - ms->len,1 ); +return vfio_type1_dma_mem_map (cfg, ms->addr_64, ms->iova, ms->len,1 ); }static int -vfio_type1_dma_mem_map (int vfio_container_fd,uint64_t vaddr,uint64_t iova, -uint64_t len,int do_map) +vfio_type1_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, +int do_map) {struct vfio_iommu_type1_dma_map dma_map;struct vfio_iommu_type1_dma_unmap dma_unmap;
@@ -1499,7 +1455,7 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, dma_map.flags =VFIO_DMA_MAP_FLAG_READ |VFIO_DMA_MAP_FLAG_WRITE ; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_MAP_DMA , &dma_map); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_MAP_DMA , &dma_map);if (ret) {/** * In case the mapping was already done EEXIST will be
@@ -1521,8 +1477,7 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, dma_unmap.size = len; dma_unmap.iova = iova; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_UNMAP_DMA , - &dma_unmap); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_UNMAP_DMA , &dma_unmap);if (ret) {EAL_LOG (ERR ,"Cannot clear DMA remapping, error " "%i (%s)" , errno,strerror (errno));
@@ -1540,9 +1495,9 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, }static int -vfio_type1_dma_map (int vfio_container_fd) +vfio_type1_dma_map (struct vfio_container *cfg) { -return rte_memseg_walk (type1_map, &vfio_container_fd); +return rte_memseg_walk (type1_map, cfg); }/* Track the size of the statically allocated DMA window for SPAPR */
@@ -1550,8 +1505,8 @@ uint64_t spapr_dma_win_len;uint64_t spapr_dma_win_page_sz;static int -vfio_spapr_dma_do_map (int vfio_container_fd,uint64_t vaddr,uint64_t iova, -uint64_t len,int do_map) +vfio_spapr_dma_do_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, +int do_map) {struct vfio_iommu_spapr_register_memory reg = { .argsz =sizeof (reg),
@@ -1569,8 +1524,7 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,return -1 ; } - ret =ioctl (vfio_container_fd, -VFIO_IOMMU_SPAPR_REGISTER_MEMORY , ®); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_REGISTER_MEMORY , ®);if (ret) {EAL_LOG (ERR , "Cannot register vaddr for IOMMU, error "
@@ -1586,7 +1540,7 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, dma_map.flags =VFIO_DMA_MAP_FLAG_READ |VFIO_DMA_MAP_FLAG_WRITE ; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_MAP_DMA , &dma_map); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_MAP_DMA , &dma_map);if (ret) {EAL_LOG (ERR ,"Cannot map vaddr for IOMMU, error " "%i (%s)" , errno,strerror (errno));
@@ -1601,16 +1555,14 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, dma_unmap.size = len; dma_unmap.iova = iova; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_UNMAP_DMA , - &dma_unmap); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_UNMAP_DMA , &dma_unmap);if (ret) {EAL_LOG (ERR ,"Cannot unmap vaddr for IOMMU, error " "%i (%s)" , errno,strerror (errno));return -1 ; } - ret =ioctl (vfio_container_fd, -VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY , ®); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY , ®);if (ret) {EAL_LOG (ERR , "Cannot unregister vaddr for IOMMU, error "
@@ -1623,10 +1575,9 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, }static int -vfio_spapr_map_walk (const struct rte_memseg_list *msl, -const struct rte_memseg *ms,void *arg) +vfio_spapr_map_walk (const struct rte_memseg_list *msl,const struct rte_memseg *ms,void *arg) { -int *vfio_container_fd = arg; +struct vfio_container *cfg = arg;/* skip external memory that isn't a heap */ if (msl->external && !msl->heap)
@@ -1636,8 +1587,7 @@ vfio_spapr_map_walk(const struct rte_memseg_list *msl,if (ms->iova ==RTE_BAD_IOVA )return 0 ; -return vfio_spapr_dma_do_map (*vfio_container_fd, - ms->addr_64, ms->iova, ms->len,1 ); +return vfio_spapr_dma_do_map (cfg, ms->addr_64, ms->iova, ms->len,1 ); }struct spapr_size_walk_param {
@@ -1782,7 +1732,7 @@ spapr_dma_win_size(void) }static int -vfio_spapr_create_dma_window (int vfio_container_fd) +vfio_spapr_create_dma_window (struct vfio_container *cfg) {struct vfio_iommu_spapr_tce_create create = { .argsz =sizeof (create), };
@@ -1796,7 +1746,7 @@ vfio_spapr_create_dma_window(int vfio_container_fd)if (ret <0 )return ret; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_SPAPR_TCE_GET_INFO , &info); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_GET_INFO , &info);if (ret) {EAL_LOG (ERR ,"Cannot get IOMMU info, error %i (%s)" , errno,strerror (errno));
@@ -1809,7 +1759,7 @@ vfio_spapr_create_dma_window(int vfio_container_fd)* supports v2, remove the default DMA window so it can be resized. */ remove.start_addr = info.dma32_window_start; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_SPAPR_TCE_REMOVE , &remove); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_REMOVE , &remove);if (ret)return -1 ;
@@ -1817,7 +1767,7 @@ vfio_spapr_create_dma_window(int vfio_container_fd) create.window_size = spapr_dma_win_len; create.page_shift =rte_ctz64 (spapr_dma_win_page_sz); create.levels =1 ; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_SPAPR_TCE_CREATE , &create); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_CREATE , &create);#ifdef VFIO_IOMMU_SPAPR_INFO_DDW /* * The vfio_iommu_spapr_tce_info structure was modified in
@@ -1833,8 +1783,7 @@ vfio_spapr_create_dma_window(int vfio_container_fd)for (levels = create.levels +1 ; ret && levels <= info.ddw.levels; levels++) { create.levels = levels; - ret =ioctl (vfio_container_fd, -VFIO_IOMMU_SPAPR_TCE_CREATE , &create); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_CREATE , &create); } }#endif /* VFIO_IOMMU_SPAPR_INFO_DDW */
@@ -1856,20 +1805,18 @@ vfio_spapr_create_dma_window(int vfio_container_fd) }static int -vfio_spapr_dma_mem_map (int vfio_container_fd,uint64_t vaddr, -uint64_t iova,uint64_t len,int do_map) +vfio_spapr_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, +int do_map) {int ret =0 ;if (do_map) { -if (vfio_spapr_dma_do_map (vfio_container_fd, - vaddr, iova, len,1 )) { +if (vfio_spapr_dma_do_map (cfg, vaddr, iova, len,1 )) {EAL_LOG (ERR ,"Failed to map DMA" ); ret =-1 ; } }else { -if (vfio_spapr_dma_do_map (vfio_container_fd, - vaddr, iova, len,0 )) { +if (vfio_spapr_dma_do_map (cfg, vaddr, iova, len,0 )) {EAL_LOG (ERR ,"Failed to unmap DMA" ); ret =-1 ; }
@@ -1879,42 +1826,40 @@ vfio_spapr_dma_mem_map(int vfio_container_fd, uint64_t vaddr, }static int -vfio_spapr_dma_map (int vfio_container_fd) +vfio_spapr_dma_map (struct vfio_container *cfg) { -if (vfio_spapr_create_dma_window (vfio_container_fd) <0 ) { +if (vfio_spapr_create_dma_window (cfg) <0 ) {EAL_LOG (ERR ,"Could not create new DMA window!" );return -1 ; }/* map all existing DPDK segments for DMA */ -if (rte_memseg_walk (vfio_spapr_map_walk, &vfio_container_fd) <0 ) +if (rte_memseg_walk (vfio_spapr_map_walk, cfg) <0 )return -1 ;return 0 ; }static int -vfio_noiommu_dma_map(int __rte_unused vfio_container_fd) +vfio_noiommu_dma_map(struct vfio_container *cfg __rte_unused) {/* No-IOMMU mode does not need DMA mapping */ return 0 ; }static int -vfio_noiommu_dma_mem_map(int __rte_unused vfio_container_fd, - uint64_t __rte_unused vaddr, - uint64_t __rte_unused iova, uint64_t __rte_unused len, - int __rte_unused do_map) +vfio_noiommu_dma_mem_map(struct vfio_container *cfg __rte_unused, uint64_t vaddr __rte_unused, + uint64_t iova __rte_unused, uint64_t len __rte_unused, int do_map __rte_unused) {/* No-IOMMU mode does not need DMA mapping */ return 0 ; }static int -vfio_dma_mem_map (struct vfio_config *vfio_cfg,uint64_t vaddr,uint64_t iova, -uint64_t len,int do_map) +vfio_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, +int do_map) { -const struct vfio_iommu_type *t = vfio_cfg->vfio_iommu_type; +const struct vfio_iommu_type *t = cfg->vfio_iommu_type;if (!t) {EAL_LOG (ERR ,"VFIO support not initialized" );
@@ -1930,20 +1875,18 @@ vfio_dma_mem_map(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova,return -1 ; } -return t->dma_user_map_func (vfio_cfg->vfio_container_fd, vaddr, iova, - len, do_map); +return t->dma_user_map_func (cfg, vaddr, iova, len, do_map); }static int -container_dma_map (struct vfio_config *vfio_cfg,uint64_t vaddr,uint64_t iova, -uint64_t len) +container_dma_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len) { -struct user_mem_map *new_map; -struct user_mem_maps *user_mem_maps; +struct vfio_user_mem_map *new_map; +struct vfio_user_mem_maps *user_mem_maps;bool has_partial_unmap;int ret =0 ; - user_mem_maps = &vfio_cfg->mem_maps; + user_mem_maps = &cfg->mem_maps;rte_spinlock_recursive_lock (&user_mem_maps->lock);if (user_mem_maps->n_maps ==RTE_DIM (user_mem_maps->maps)) {EAL_LOG (ERR ,"No more space for user mem maps" );
@@ -1952,7 +1895,7 @@ container_dma_map(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, goto out; }/* map the entry */ -if (vfio_dma_mem_map (vfio_cfg, vaddr, iova, len,1 )) { +if (vfio_dma_mem_map (cfg, vaddr, iova, len,1 )) {/* technically, this will fail if there are currently no devices * plugged in, even if a device were added later, this mapping * might have succeeded. however, since we cannot verify if this
@@ -1965,7 +1908,7 @@ container_dma_map(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, goto out; }/* do we have partial unmap support? */ - has_partial_unmap = vfio_cfg->vfio_iommu_type->partial_unmap; + has_partial_unmap = cfg->vfio_iommu_type->partial_unmap;/* create new user mem map entry */ new_map = &user_mem_maps->maps[user_mem_maps->n_maps++];
@@ -1982,17 +1925,16 @@ container_dma_map(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, }static int -container_dma_unmap (struct vfio_config *vfio_cfg,uint64_t vaddr,uint64_t iova, -uint64_t len) +container_dma_unmap (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len) { -struct user_mem_map orig_maps[RTE_DIM (vfio_cfg->mem_maps.maps)]; -struct user_mem_map new_maps[2 ];/* can be at most 2 */ -struct user_mem_maps *user_mem_maps; +struct vfio_user_mem_map orig_maps[RTE_DIM (cfg->mem_maps.maps)]; +struct vfio_user_mem_map new_maps[2 ];/* can be at most 2 */ +struct vfio_user_mem_maps *user_mem_maps;int n_orig, n_new, ret =0 ;bool has_partial_unmap;unsigned int newlen; - user_mem_maps = &vfio_cfg->mem_maps; + user_mem_maps = &cfg->mem_maps;rte_spinlock_recursive_lock (&user_mem_maps->lock);/*
@@ -2024,7 +1966,7 @@ container_dma_unmap(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, }/* do we have partial unmap capability? */ - has_partial_unmap = vfio_cfg->vfio_iommu_type->partial_unmap; + has_partial_unmap = cfg->vfio_iommu_type->partial_unmap;/* * if we don't support partial unmap, we must check if start and end of
@@ -2064,7 +2006,7 @@ container_dma_unmap(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, }/* unmap the entry */ -if (vfio_dma_mem_map (vfio_cfg, vaddr, iova, len,0 )) { +if (vfio_dma_mem_map (cfg, vaddr, iova, len,0 )) {/* there may not be any devices plugged in, so unmapping will * fail with ENODEV/ENOTSUP rte_errno values, but that doesn't * stop us from removing the mapping, as the assumption is we
@@ -2134,31 +2076,31 @@ dev_vfio_container_create(void)return -1 ;/* Find an empty slot to store new vfio config */ -for (i =1 ; i <RTE_DIM (vfio_cfgs); i++) { -if (vfio_cfgs[i].vfio_container_fd ==-1 ) +for (i =1 ; i <RTE_DIM (vfio_containers); i++) { +if (vfio_containers[i].container_fd ==-1 )break ; } -if (i ==RTE_DIM (vfio_cfgs)) { +if (i ==RTE_DIM (vfio_containers)) {EAL_LOG (ERR ,"Exceed max VFIO container limit" );return -1 ; }/* Create a new container fd */ - vfio_cfgs[i].vfio_container_fd =vfio_open_container_fd (false); -if (vfio_cfgs[i].vfio_container_fd <0 ) { + vfio_containers[i].container_fd =vfio_open_container_fd (false); +if (vfio_containers[i].container_fd <0 ) {EAL_LOG (NOTICE ,"Fail to create a new VFIO container" );return -1 ; } -return vfio_cfgs[i].vfio_container_fd; +return vfio_containers[i].container_fd; }RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_container_destroy) intdev_vfio_container_destroy (int container_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i;if (!vfio_enabled)
@@ -2169,21 +2111,21 @@ dev_vfio_container_destroy(int container_fd)return -1 ; } - vfio_cfg =get_vfio_cfg_by_container_fd (container_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) -if (vfio_cfg->vfio_groups[i].group_num !=-1 ) +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) +if (cfg->vfio_groups[i].group_num !=-1 )vfio_container_group_unbind (container_fd, - vfio_cfg->vfio_groups[i].group_num); + cfg->vfio_groups[i].group_num);close (container_fd); - vfio_cfg->vfio_container_fd =-1 ; - vfio_cfg->vfio_active_groups =0 ; - vfio_cfg->vfio_iommu_type =NULL ; + cfg->container_fd =-1 ; + cfg->vfio_active_groups =0 ; + cfg->vfio_iommu_type =NULL ;return 0 ; }
@@ -2218,39 +2160,39 @@ dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base,static int vfio_container_group_bind (int container_fd,int iommu_group_num) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;if (!vfio_enabled)return -1 ; - vfio_cfg =get_vfio_cfg_by_container_fd (container_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -return vfio_get_group_fd (vfio_cfg, iommu_group_num); +return vfio_get_group_fd (cfg, iommu_group_num); }static int vfio_container_group_unbind (int container_fd,int iommu_group_num) {struct vfio_group *cur_grp =NULL ; -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i;if (!vfio_enabled)return -1 ; - vfio_cfg =get_vfio_cfg_by_container_fd (container_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) { -if (vfio_cfg->vfio_groups[i].group_num == iommu_group_num) { - cur_grp = &vfio_cfg->vfio_groups[i]; +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) { +if (cfg->vfio_groups[i].group_num == iommu_group_num) { + cur_grp = &cfg->vfio_groups[i];break ; } }
@@ -2270,7 +2212,7 @@ vfio_container_group_unbind(int container_fd, int iommu_group_num) cur_grp->group_num =-1 ; cur_grp->fd =-1 ; cur_grp->devices =0 ; - vfio_cfg->vfio_active_groups--; + cfg->vfio_active_groups--;return 0 ; }
@@ -2280,7 +2222,7 @@ int dev_vfio_container_dma_map(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len) { - struct vfio_config *vfio_cfg; + struct vfio_container *cfg;if (!vfio_enabled)return -1 ;
@@ -2290,13 +2232,13 @@ dev_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 (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -return container_dma_map (vfio_cfg, vaddr, iova, len); +return container_dma_map (cfg, vaddr, iova, len); }RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_container_dma_unmap)
@@ -2304,7 +2246,7 @@ int dev_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len) { - struct vfio_config *vfio_cfg; + struct vfio_container *cfg;if (!vfio_enabled)return -1 ;
@@ -2314,22 +2256,22 @@ dev_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 (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -return container_dma_unmap (vfio_cfg, vaddr, iova, len); +return container_dma_unmap (cfg, vaddr, iova, len); }static int -vfio_cleanup_config (struct vfio_config *vfio_cfg) +vfio_cleanup_config (struct vfio_container *cfg) {unsigned int i; -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) { -struct vfio_group *group = &vfio_cfg->vfio_groups[i]; +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) { +struct vfio_group *group = &cfg->vfio_groups[i];if (group->group_num ==-1 )continue ;
@@ -2347,26 +2289,26 @@ vfio_cleanup_config(struct vfio_config *vfio_cfg) group->group_num =-1 ; group->fd =-1 ; group->devices =0 ; - vfio_cfg->vfio_active_groups--; + cfg->vfio_active_groups--; }/* if there are still active groups, we cannot cleanup the container */ -if (vfio_cfg->vfio_active_groups !=0 ) { +if (cfg->vfio_active_groups !=0 ) {EAL_LOG (ERR ,"Cannot cleanup VFIO container with %d active groups" , - vfio_cfg->vfio_active_groups); + cfg->vfio_active_groups);return -1 ; } -if (vfio_cfg->vfio_container_fd >=0 &&close (vfio_cfg->vfio_container_fd) <0 ) { +if (cfg->container_fd >=0 &&close (cfg->container_fd) <0 ) {EAL_LOG (ERR ,"Cannot close VFIO container: %s" ,strerror (errno));return -1 ; } - vfio_cfg->vfio_container_fd =-1 ; - vfio_cfg->vfio_iommu_type =NULL ; + cfg->container_fd =-1 ; + cfg->vfio_iommu_type =NULL ; - vfio_cfg->mem_maps.n_maps =0 ; -memset (vfio_cfg->mem_maps.maps,0 ,sizeof (vfio_cfg->mem_maps.maps)); + cfg->mem_maps.n_maps =0 ; +memset (cfg->mem_maps.maps,0 ,sizeof (cfg->mem_maps.maps));return 0 ; }
@@ -2388,9 +2330,9 @@ dev_vfio_cleanup(void)rte_mem_event_callback_unregister (VFIO_MEM_EVENT_CLB_NAME ,NULL );/* cleanup all initialized configs */ -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { -if (vfio_cfgs[i].vfio_container_fd !=-1 ) - stuck |=vfio_cleanup_config (&vfio_cfgs[i]) !=0 ; +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { +if (vfio_containers[i].container_fd !=-1 ) + stuck |=vfio_cleanup_config (&vfio_containers[i]) !=0 ; }/* failed to deinitialize some configs, so don't set VFIO as disabled */
lib/eal/linux/eal_vfio.h +40 -10
76 lines not on this page · raw message
lib/eal/linux/eal_vfio_mp_sync.c +13 -13
@@ -31,46 +31,46 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)memset (&reply,0 ,sizeof (reply));switch (m->req) { -case SOCKET_REQ_GROUP : - r->req =SOCKET_REQ_GROUP ; +case VFIO_SOCKET_REQ_GROUP : + r->req =VFIO_SOCKET_REQ_GROUP ; r->group_num = m->group_num; fd =vfio_get_group_fd_by_num (m->group_num);if (fd <0 && fd != -ENOENT ) - r->result =SOCKET_ERR ; + r->result =VFIO_SOCKET_ERR ;else if (fd == -ENOENT )/* if VFIO group exists but isn't bound to VFIO driver */ - r->result =SOCKET_NO_FD ; + r->result =VFIO_SOCKET_NO_FD ;else {/* if group exists and is bound to VFIO driver */ - r->result =SOCKET_OK ; + r->result =VFIO_SOCKET_OK ; reply.num_fds =1 ; reply.fds[0 ] = fd; }break ; -case SOCKET_REQ_CONTAINER : - r->req =SOCKET_REQ_CONTAINER ; +case VFIO_SOCKET_REQ_CONTAINER : + r->req =VFIO_SOCKET_REQ_CONTAINER ; fd =dev_vfio_get_container_fd ();if (fd <0 ) - r->result =SOCKET_ERR ; + r->result =VFIO_SOCKET_ERR ;else { - r->result =SOCKET_OK ; + r->result =VFIO_SOCKET_OK ; reply.num_fds =1 ; reply.fds[0 ] = fd; }break ; -case SOCKET_REQ_IOMMU_TYPE : +case VFIO_SOCKET_REQ_IOMMU_TYPE : {int iommu_type_id; - r->req =SOCKET_REQ_IOMMU_TYPE ; + r->req =VFIO_SOCKET_REQ_IOMMU_TYPE ; iommu_type_id =vfio_get_iommu_type ();if (iommu_type_id <0 ) - r->result =SOCKET_ERR ; + r->result =VFIO_SOCKET_ERR ;else { r->iommu_type_id = iommu_type_id; - r->result =SOCKET_OK ; + r->result =VFIO_SOCKET_OK ; }break ; }
Signature · 1 line
2.54.0
PATCH v19 19/26 vfio: declare global configuration
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Move containers under a single global variable.
Rename the IOMMU callbacks structure and have a single global ops.
--- lib/eal/linux/eal_vfio.c | 85 ++++++++++++++++++---------------------- lib/eal/linux/eal_vfio.h | 16 ++++++-- 2 files changed, 51 insertions(+), 50 deletions(-)
lib/eal/linux/eal_vfio.c +39 -46
@@ -31,7 +31,10 @@/* per-process VFIO config */ static struct vfio_container vfio_containers[RTE_MAX_VFIO_CONTAINERS ]; -static struct vfio_container *default_vfio_cfg = &vfio_containers[0 ]; + +struct vfio_config vfio_global_cfg = { + .default_cfg = &vfio_containers[0 ] +};/* whether VFIO is enabled (usable) in this process */ static bool vfio_enabled;
@@ -91,7 +94,7 @@ static int vfio_container_group_bind(int container_fd, int iommu_group_num);static int vfio_container_group_unbind (int container_fd,int iommu_group_num);/* IOMMU types we support */ -static const struct vfio_iommu_type iommu_types[] = { +static const struct vfio_iommu_ops iommu_types[] = {/* x86 IOMMU, otherwise known as type 1 */ { .type_id =VFIO_TYPE1_IOMMU ,
@@ -498,7 +501,7 @@ vfio_get_group_fd(struct vfio_container *cfg, int iommu_group_num)*/ const struct internal_config *internal_conf =eal_get_internal_configuration ();bool mp_request = (internal_conf->process_type ==RTE_PROC_SECONDARY ) && - (cfg == default_vfio_cfg); + (cfg == vfio_global_cfg.default_cfg); vfio_group_fd =vfio_open_group_fd (iommu_group_num, mp_request);if (vfio_group_fd <0 ) {
@@ -536,7 +539,7 @@ get_vfio_cfg_by_container_fd(int container_fd)unsigned int i;if (container_fd ==DEV_VFIO_DEFAULT_CONTAINER_FD ) -return default_vfio_cfg; +return vfio_global_cfg.default_cfg;for (i =0 ; i <RTE_DIM (vfio_containers); i++) {if (vfio_containers[i].container_fd == container_fd)
@@ -556,7 +559,7 @@ vfio_get_group_fd_by_num(int iommu_group_num)/* get the vfio_container it belongs to */ cfg =get_vfio_cfg_by_group_num (iommu_group_num); - cfg = cfg ? cfg : default_vfio_cfg; + cfg = cfg ? cfg : vfio_global_cfg.default_cfg;return vfio_get_group_fd (cfg, iommu_group_num); }
@@ -640,6 +643,7 @@ static void vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len, void *arg __rte_unused) { + struct vfio_container *cfg = vfio_global_cfg.default_cfg;struct rte_memseg_list *msl;struct rte_memseg *ms;size_t cur_len =0 ;
@@ -654,11 +658,9 @@ vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len,/* Maintain granularity of DMA map/unmap to memseg size */ for (; cur_len < len; cur_len += page_sz) {if (type ==RTE_MEM_EVENT_ALLOC ) -vfio_dma_mem_map (default_vfio_cfg, vfio_va, - vfio_va, page_sz,1 ); +vfio_dma_mem_map (cfg, vfio_va, vfio_va, page_sz,1 );else -vfio_dma_mem_map (default_vfio_cfg, vfio_va, - vfio_va, page_sz,0 ); +vfio_dma_mem_map (cfg, vfio_va, vfio_va, page_sz,0 ); vfio_va += page_sz; }
@@ -676,11 +678,9 @@ vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len, goto next; }if (type ==RTE_MEM_EVENT_ALLOC ) -vfio_dma_mem_map (default_vfio_cfg, ms->addr_64, - ms->iova, ms->len,1 ); +vfio_dma_mem_map (cfg, ms->addr_64, ms->iova, ms->len,1 );else -vfio_dma_mem_map (default_vfio_cfg, ms->addr_64, - ms->iova, ms->len,0 ); +vfio_dma_mem_map (cfg, ms->addr_64, ms->iova, ms->len,0 ); next: cur_len += ms->len; ++ms;
@@ -702,7 +702,7 @@ vfio_sync_default_container(void)return -1 ;/* default container fd should have been opened in dev_vfio_enable() */ -if (!vfio_enabled || default_vfio_cfg->container_fd <0 ) { +if (!vfio_enabled || vfio_global_cfg.default_cfg->container_fd <0 ) {EAL_LOG (ERR ,"VFIO support is not initialized" );return -1 ; }
@@ -732,12 +732,12 @@ vfio_sync_default_container(void)* now, set up default VFIO container config to match. */ for (i =0 ; i <RTE_DIM (iommu_types); i++) { -const struct vfio_iommu_type *t = &iommu_types[i]; +const struct vfio_iommu_ops *t = &iommu_types[i];if (t->type_id != iommu_type_id)continue ;/* we found our IOMMU type */ - default_vfio_cfg->vfio_iommu_type = t; + vfio_global_cfg.ops = t;return 0 ; }
@@ -845,7 +845,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de/* get the vfio_container it belongs to */ cfg =get_vfio_cfg_by_group_num (iommu_group_num); - cfg = cfg ? cfg : default_vfio_cfg; + cfg = cfg ? cfg : vfio_global_cfg.default_cfg; vfio_container_fd = cfg->container_fd; user_mem_maps = &cfg->mem_maps;
@@ -874,7 +874,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deif (internal_conf->process_type ==RTE_PROC_PRIMARY && cfg->vfio_active_groups ==1 &&vfio_group_device_count (vfio_group_fd) ==0 ) { -const struct vfio_iommu_type *t; +const struct vfio_iommu_ops *t;/* select an IOMMU type which we will be using */ t =vfio_set_iommu_type (vfio_container_fd);
@@ -890,7 +890,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* after registering callback, to prevent races */ rte_mcfg_mem_read_lock (); -if (cfg == default_vfio_cfg) +if (cfg == vfio_global_cfg.default_cfg) ret = t->dma_map_func (cfg);else ret =0 ;
@@ -905,8 +905,6 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ; } - cfg->vfio_iommu_type = t; -/* re-map all user-mapped segments */ rte_spinlock_recursive_lock (&user_mem_maps->lock);
@@ -936,7 +934,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_derte_spinlock_recursive_unlock (&user_mem_maps->lock);/* register callback for mem events */ -if (cfg == default_vfio_cfg) +if (cfg == vfio_global_cfg.default_cfg) ret =rte_mem_event_callback_register (VFIO_MEM_EVENT_CLB_NAME , vfio_mem_event_callback,NULL );
@@ -955,8 +953,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deEAL_LOG (DEBUG ,"Installed memory event callback for VFIO" ); } }else if (rte_eal_process_type () !=RTE_PROC_PRIMARY && - cfg == default_vfio_cfg && - cfg->vfio_iommu_type ==NULL ) { + cfg == vfio_global_cfg.default_cfg && + vfio_global_cfg.ops ==NULL ) {/* if we're not a primary process, we do not set up the VFIO * container because it's already been set up by the primary * process. instead, we simply ask the primary about VFIO type
@@ -970,10 +968,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ; }/* we have successfully initialized VFIO, notify user */ -const struct vfio_iommu_type *t = - default_vfio_cfg->vfio_iommu_type; -EAL_LOG (INFO ,"Using IOMMU type %d (%s)" , - t->type_id, t->name); +const struct vfio_iommu_ops *t = vfio_global_cfg.ops; +EAL_LOG (INFO ,"Using IOMMU type %d (%s)" , t->type_id, t->name); }rte_eal_vfio_get_vf_token (vf_token);
@@ -1053,7 +1049,7 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr,/* get the vfio_container it belongs to */ cfg =get_vfio_cfg_by_group_num (iommu_group_num); - cfg = cfg ? cfg : default_vfio_cfg; + cfg = cfg ? cfg : vfio_global_cfg.default_cfg;/* At this point we got an active group. Closing it will make the * container detachment. If this is the last active group, VFIO kernel
@@ -1092,7 +1088,7 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr,/* if there are no active device groups, unregister the callback to * avoid spurious attempts to map/unmap memory from VFIO. */ -if (cfg == default_vfio_cfg && cfg->vfio_active_groups ==0 && +if (cfg == vfio_global_cfg.default_cfg && cfg->vfio_active_groups ==0 &&rte_eal_process_type () !=RTE_PROC_SECONDARY )rte_mem_event_callback_unregister (VFIO_MEM_EVENT_CLB_NAME ,NULL );
@@ -1124,7 +1120,6 @@ dev_vfio_enable(void)for (i =0 ; i <RTE_DIM (vfio_containers); i++) { vfio_containers[i].container_fd =-1 ; vfio_containers[i].vfio_active_groups =0 ; - vfio_containers[i].vfio_iommu_type =NULL ; vfio_containers[i].mem_maps.lock = lock;for (j =0 ; j <RTE_DIM (vfio_containers[i].vfio_groups); j++) {
@@ -1163,18 +1158,18 @@ dev_vfio_enable(void)if (internal_conf->process_type ==RTE_PROC_PRIMARY ) {if (vfio_mp_sync_setup () ==-1 ) { - default_vfio_cfg->container_fd =-1 ; + vfio_global_cfg.default_cfg->container_fd =-1 ; }else {/* open a default container */ - default_vfio_cfg->container_fd =vfio_open_container_fd (false); + vfio_global_cfg.default_cfg->container_fd =vfio_open_container_fd (false); } }else {/* get the default container from the primary process */ - default_vfio_cfg->container_fd =vfio_open_container_fd (true); + vfio_global_cfg.default_cfg->container_fd =vfio_open_container_fd (true); }/* check if we have VFIO driver enabled */ -if (default_vfio_cfg->container_fd !=-1 ) { +if (vfio_global_cfg.default_cfg->container_fd !=-1 ) {EAL_LOG (INFO ,"VFIO support initialized" ); vfio_enabled = true; }else {
@@ -1204,18 +1199,18 @@ vfio_get_iommu_type(void)if (!vfio_enabled)return -1 ; -if (default_vfio_cfg->vfio_iommu_type ==NULL ) +if (vfio_global_cfg.ops ==NULL )return -1 ; -return default_vfio_cfg->vfio_iommu_type->type_id; +return vfio_global_cfg.ops->type_id; } -const struct vfio_iommu_type * +const struct vfio_iommu_ops *vfio_set_iommu_type (int vfio_container_fd) {unsigned idx;for (idx =0 ; idx <RTE_DIM (iommu_types); idx++) { -const struct vfio_iommu_type *t = &iommu_types[idx]; +const struct vfio_iommu_ops *t = &iommu_types[idx];int ret =ioctl (vfio_container_fd,VFIO_SET_IOMMU , t->type_id);
@@ -1260,7 +1255,7 @@ vfio_has_supported_extensions(int vfio_container_fd)int ret;unsigned idx, n_extensions =0 ;for (idx =0 ; idx <RTE_DIM (iommu_types); idx++) { -const struct vfio_iommu_type *t = &iommu_types[idx]; +const struct vfio_iommu_ops *t = &iommu_types[idx]; ret =ioctl (vfio_container_fd,VFIO_CHECK_EXTENSION , t->type_id);
@@ -1372,7 +1367,7 @@ dev_vfio_get_container_fd(void)if (!vfio_enabled)return -1 ; -return default_vfio_cfg->container_fd; +return vfio_global_cfg.default_cfg->container_fd; }RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_group_num)
@@ -1859,7 +1854,7 @@ static int vfio_dma_mem_map(struct vfio_container *cfg, uint64_t vaddr, uint64_t iova, uint64_t len, int do_map) { - const struct vfio_iommu_type *t = cfg->vfio_iommu_type; + const struct vfio_iommu_ops *t = vfio_global_cfg.ops;if (!t) {EAL_LOG (ERR ,"VFIO support not initialized" );
@@ -1908,7 +1903,7 @@ container_dma_map(struct vfio_container *cfg, uint64_t vaddr, uint64_t iova, uin goto out; }/* do we have partial unmap support? */ - has_partial_unmap = cfg->vfio_iommu_type->partial_unmap; + has_partial_unmap = vfio_global_cfg.ops->partial_unmap;/* create new user mem map entry */ new_map = &user_mem_maps->maps[user_mem_maps->n_maps++];
@@ -1966,7 +1961,7 @@ container_dma_unmap(struct vfio_container *cfg, uint64_t vaddr, uint64_t iova, u }/* do we have partial unmap capability? */ - has_partial_unmap = cfg->vfio_iommu_type->partial_unmap; + has_partial_unmap = vfio_global_cfg.ops->partial_unmap;/* * if we don't support partial unmap, we must check if start and end of
@@ -2125,7 +2120,6 @@ dev_vfio_container_destroy(int container_fd)close (container_fd); cfg->container_fd =-1 ; cfg->vfio_active_groups =0 ; - cfg->vfio_iommu_type =NULL ;return 0 ; }
@@ -2305,7 +2299,6 @@ vfio_cleanup_config(struct vfio_container *cfg) } cfg->container_fd =-1 ; - cfg->vfio_iommu_type =NULL ; cfg->mem_maps.n_maps =0 ;memset (cfg->mem_maps.maps,0 ,sizeof (cfg->mem_maps.maps));
lib/eal/linux/eal_vfio.h +12 -4
@@ -44,7 +44,6 @@ struct vfio_group {struct vfio_container {int container_fd;int vfio_active_groups; -const struct vfio_iommu_type *vfio_iommu_type;struct vfio_group vfio_groups[RTE_MAX_VFIO_GROUPS ];struct vfio_user_mem_maps mem_maps; };
@@ -63,7 +62,7 @@ typedef int (*vfio_dma_func_t)(struct vfio_container *cfg);typedef int (*vfio_dma_user_func_t )(struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len,int do_map); -struct vfio_iommu_type { +struct vfio_iommu_ops {int type_id;const char *name;bool partial_unmap;
@@ -74,8 +73,17 @@ struct vfio_iommu_type {/* get the vfio container that devices are bound to by default */ int vfio_open_container_fd (bool mp_request); -/* pick IOMMU type. returns a pointer to vfio_iommu_type or NULL for error */ -const struct vfio_iommu_type * +/* global configuration */ +struct vfio_config { +struct vfio_container *default_cfg; +const struct vfio_iommu_ops *ops; +}; + +/* current configuration */ +extern struct vfio_config vfio_global_cfg; + +/* pick IOMMU type. returns a pointer to vfio_iommu_ops or NULL for error */ +const struct vfio_iommu_ops *vfio_set_iommu_type (int vfio_container_fd);int
Signature · 1 line
2.54.0
PATCH v19 20/26 vfio: separate group-based IOMMU types
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Move group-based IOMMU types to a new file.
Notes:
- vfio_has_supported_extensions won't close vfio_container_fd anymore, this is consolidated in its caller,
- as we switched to an imported uapi header for VFIO some time ago, there is no need to check VFIO_IOMMU_SPAPR_INFO_DDW anymore,
--- lib/eal/linux/eal_vfio.c | 524 +-------------------------------- lib/eal/linux/eal_vfio.h | 2 + lib/eal/linux/eal_vfio_group.c | 521 ++++++++++++++++++++++++++++++++ lib/eal/linux/meson.build | 1 + 4 files changed, 525 insertions(+), 523 deletions(-) create mode 100644 lib/eal/linux/eal_vfio_group.c
lib/eal/linux/eal_vfio.c +1 -523
@@ -81,46 +81,12 @@ vfio_check_module(enum dev_vfio_module module)return 1 ; } -static int vfio_type1_dma_map (struct vfio_container *); -static int vfio_type1_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int ); -static int vfio_spapr_dma_map (struct vfio_container *); -static int vfio_spapr_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int ); -static int vfio_noiommu_dma_map (struct vfio_container *); -static int vfio_noiommu_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int );static int vfio_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len,int do_map);static int vfio_container_group_bind (int container_fd,int iommu_group_num);static int vfio_container_group_unbind (int container_fd,int iommu_group_num); -/* IOMMU types we support */ -static const struct vfio_iommu_ops iommu_types[] = { -/* x86 IOMMU, otherwise known as type 1 */ - { - .type_id =VFIO_TYPE1_IOMMU , - .name ="Type 1" , - .partial_unmap = false, - .dma_map_func = &vfio_type1_dma_map, - .dma_user_map_func = &vfio_type1_dma_mem_map - }, -/* ppc64 IOMMU, otherwise known as spapr */ - { - .type_id = VFIO_SPAPR_TCE_v2_IOMMU, - .name ="sPAPR" , - .partial_unmap = true, - .dma_map_func = &vfio_spapr_dma_map, - .dma_user_map_func = &vfio_spapr_dma_mem_map - }, -/* IOMMU-less mode */ - { - .type_id =VFIO_NOIOMMU_IOMMU , - .name ="No-IOMMU" , - .partial_unmap = true, - .dma_map_func = &vfio_noiommu_dma_map, - .dma_user_map_func = &vfio_noiommu_dma_mem_map - }, -}; -static int is_null_map (const struct vfio_user_mem_map *map) {
@@ -1205,29 +1171,6 @@ vfio_get_iommu_type(void)return vfio_global_cfg.ops->type_id; } -const struct vfio_iommu_ops * -vfio_set_iommu_type (int vfio_container_fd) -{ -unsigned idx; -for (idx =0 ; idx <RTE_DIM (iommu_types); idx++) { -const struct vfio_iommu_ops *t = &iommu_types[idx]; - -int ret =ioctl (vfio_container_fd,VFIO_SET_IOMMU , - t->type_id); -if (!ret) { -EAL_LOG (INFO ,"Using IOMMU type %d (%s)" , - t->type_id, t->name); -return t; - } -/* not an error, there may be more supported IOMMU types */ -EAL_LOG (DEBUG ,"Set IOMMU type %d (%s) failed, error " -"%i (%s)" , t->type_id, t->name, errno, -strerror (errno)); - } -/* if we didn't find a suitable IOMMU type, fail */ -return NULL ; -} -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_device_info) intdev_vfio_get_device_info (int vfio_dev_fd,struct vfio_device_info *device_info)
@@ -1249,39 +1192,6 @@ dev_vfio_get_device_info(int vfio_dev_fd, struct vfio_device_info *device_info)return 0 ; } -int -vfio_has_supported_extensions (int vfio_container_fd) -{ -int ret; -unsigned idx, n_extensions =0 ; -for (idx =0 ; idx <RTE_DIM (iommu_types); idx++) { -const struct vfio_iommu_ops *t = &iommu_types[idx]; - - ret =ioctl (vfio_container_fd,VFIO_CHECK_EXTENSION , - t->type_id); -if (ret <0 ) { -EAL_LOG (ERR ,"Could not get IOMMU type, error " -"%i (%s)" , errno,strerror (errno)); -close (vfio_container_fd); -return -1 ; - }else if (ret ==1 ) { -/* we found a supported extension */ - n_extensions++; - } -EAL_LOG (DEBUG ,"IOMMU type %d (%s) is %s" , - t->type_id, t->name, - ret ?"supported" :"not supported" ); - } - -/* if we didn't find any supported IOMMU types, fail */ -if (!n_extensions) { -close (vfio_container_fd); -return -1 ; - } - -return 0 ; -} -/* * Open a new VFIO container fd. *
@@ -1325,6 +1235,7 @@ vfio_open_container_fd(bool mp_request)if (ret) {EAL_LOG (ERR ,"No supported IOMMU extensions found!" ); +close (vfio_container_fd);return -1 ; }
@@ -1417,439 +1328,6 @@ dev_vfio_get_group_num(const char *sysfs_base,return 1 ; } -static int -type1_map (const struct rte_memseg_list *msl,const struct rte_memseg *ms,void *arg) -{ -struct vfio_container *cfg = arg; - -/* skip external memory that isn't a heap */ -if (msl->external && !msl->heap) -return 0 ; - -/* skip any segments with invalid IOVA addresses */ -if (ms->iova ==RTE_BAD_IOVA ) -return 0 ; - -return vfio_type1_dma_mem_map (cfg, ms->addr_64, ms->iova, ms->len,1 ); -} - -static int -vfio_type1_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, -int do_map) -{ -struct vfio_iommu_type1_dma_map dma_map; -struct vfio_iommu_type1_dma_unmap dma_unmap; -int ret; - -if (do_map !=0 ) { -memset (&dma_map,0 ,sizeof (dma_map)); - dma_map.argsz =sizeof (struct vfio_iommu_type1_dma_map ); - dma_map.vaddr = vaddr; - dma_map.size = len; - dma_map.iova = iova; - dma_map.flags =VFIO_DMA_MAP_FLAG_READ | -VFIO_DMA_MAP_FLAG_WRITE ; - - ret =ioctl (cfg->container_fd,VFIO_IOMMU_MAP_DMA , &dma_map); -if (ret) { -/** -* In case the mapping was already done EEXIST will be -* returned from kernel. -*/ -if (errno ==EEXIST ) { -EAL_LOG (DEBUG , -"Memory segment is already mapped, skipping" ); - }else { -EAL_LOG (ERR , -"Cannot set up DMA remapping, error " -"%i (%s)" , errno,strerror (errno)); -return -1 ; - } - } - }else { -memset (&dma_unmap,0 ,sizeof (dma_unmap)); - dma_unmap.argsz =sizeof (struct vfio_iommu_type1_dma_unmap ); - dma_unmap.size = len; - dma_unmap.iova = iova; - - ret =ioctl (cfg->container_fd,VFIO_IOMMU_UNMAP_DMA , &dma_unmap); -if (ret) { -EAL_LOG (ERR ,"Cannot clear DMA remapping, error " -"%i (%s)" , errno,strerror (errno)); -return -1 ; - }else if (dma_unmap.size != len) { -EAL_LOG (ERR ,"Unexpected size %" PRIu64 -" of DMA remapping cleared instead of %" PRIu64, - (uint64_t )dma_unmap.size, len); - rte_errno =EIO ; -return -1 ; - } - } - -return 0 ; -} - -static int -vfio_type1_dma_map (struct vfio_container *cfg) -{ -return rte_memseg_walk (type1_map, cfg); -} - -/* Track the size of the statically allocated DMA window for SPAPR */ -uint64_t spapr_dma_win_len; -uint64_t spapr_dma_win_page_sz; - -static int -vfio_spapr_dma_do_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, -int do_map) -{ -struct vfio_iommu_spapr_register_memory reg = { - .argsz =sizeof (reg), - .vaddr = (uintptr_t ) vaddr, - .size = len, - .flags =0 - }; -int ret; - -if (do_map !=0 ) { -struct vfio_iommu_type1_dma_map dma_map; - -if (iova + len > spapr_dma_win_len) { -EAL_LOG (ERR ,"DMA map attempt outside DMA window" ); -return -1 ; - } - - ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_REGISTER_MEMORY , ®); -if (ret) { -EAL_LOG (ERR , -"Cannot register vaddr for IOMMU, error " -"%i (%s)" , errno,strerror (errno)); -return -1 ; - } - -memset (&dma_map,0 ,sizeof (dma_map)); - dma_map.argsz =sizeof (struct vfio_iommu_type1_dma_map ); - dma_map.vaddr = vaddr; - dma_map.size = len; - dma_map.iova = iova; - dma_map.flags =VFIO_DMA_MAP_FLAG_READ | -VFIO_DMA_MAP_FLAG_WRITE ; - - ret =ioctl (cfg->container_fd,VFIO_IOMMU_MAP_DMA , &dma_map); -if (ret) { -EAL_LOG (ERR ,"Cannot map vaddr for IOMMU, error " -"%i (%s)" , errno,strerror (errno)); -return -1 ; - } - - }else { -struct vfio_iommu_type1_dma_map dma_unmap; - -memset (&dma_unmap,0 ,sizeof (dma_unmap)); - dma_unmap.argsz =sizeof (struct vfio_iommu_type1_dma_unmap ); - dma_unmap.size = len; - dma_unmap.iova = iova; - - ret =ioctl (cfg->container_fd,VFIO_IOMMU_UNMAP_DMA , &dma_unmap); -if (ret) { -EAL_LOG (ERR ,"Cannot unmap vaddr for IOMMU, error " -"%i (%s)" , errno,strerror (errno)); -return -1 ; - } - - ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY , ®); -if (ret) { -EAL_LOG (ERR , -"Cannot unregister vaddr for IOMMU, error " -"%i (%s)" , errno,strerror (errno)); -return -1 ; - } - } - -return ret; -} - -static int -vfio_spapr_map_walk (const struct rte_memseg_list *msl,const struct rte_memseg *ms,void *arg) -{ -struct vfio_container *cfg = arg; - -/* skip external memory that isn't a heap */ -if (msl->external && !msl->heap) -return 0 ; - -/* skip any segments with invalid IOVA addresses */ -if (ms->iova ==RTE_BAD_IOVA ) -return 0 ; - -return vfio_spapr_dma_do_map (cfg, ms->addr_64, ms->iova, ms->len,1 ); -} - -struct spapr_size_walk_param { -uint64_t max_va; -uint64_t page_sz; -bool is_user_managed; -}; - -/* -* In order to set the DMA window size required for the SPAPR IOMMU -* we need to walk the existing virtual memory allocations as well as -* find the hugepage size used. -*/ -static int -vfio_spapr_size_walk (const struct rte_memseg_list *msl,void *arg) -{ -struct spapr_size_walk_param *param = arg; -uint64_t max = (uint64_t ) msl->base_va + (uint64_t ) msl->len; - -if (msl->external && !msl->heap) { -/* ignore user managed external memory */ - param->is_user_managed = true; -return 0 ; - } - -if (max > param->max_va) { - param->page_sz = msl->page_sz; - param->max_va = max; - } - -return 0 ; -} - -/* -* Find the highest memory address used in physical or virtual address -* space and use that as the top of the DMA window. -*/ -static int -find_highest_mem_addr (struct spapr_size_walk_param *param) -{ -/* find the maximum IOVA address for setting the DMA window size */ -if (rte_eal_iova_mode () ==RTE_IOVA_PA ) { -static const char proc_iomem[] ="/proc/iomem" ; -static const char str_sysram[] ="System RAM" ; -uint64_t start, end, max =0 ; -char *line =NULL ; -char *dash, *space; -size_t line_len; - -/* -* Example "System RAM" in /proc/iomem: -* 00000000-1fffffffff : System RAM -* 200000000000-201fffffffff : System RAM -*/ -FILE *fd =fopen (proc_iomem,"r" ); -if (fd ==NULL ) { -EAL_LOG (ERR ,"Cannot open %s" , proc_iomem); -return -1 ; - } -/* Scan /proc/iomem for the highest PA in the system */ -while (getline (&line, &line_len, fd) !=-1 ) { -if (strstr (line, str_sysram) ==NULL ) -continue ; - - space =strstr (line," " ); - dash =strstr (line,"-" ); - -/* Validate the format of the memory string */ -if (space ==NULL || dash ==NULL || space < dash) { -EAL_LOG (ERR ,"Can't parse line \"%s\" in file %s" , - line, proc_iomem); -continue ; - } - - start =strtoull (line,NULL ,16 ); - end =strtoull (dash +1 ,NULL ,16 ); -EAL_LOG (DEBUG ,"Found system RAM from 0x%" PRIx64 -" to 0x%" PRIx64, start, end); -if (end > max) - max = end; - } -free (line); -fclose (fd); - -if (max ==0 ) { -EAL_LOG (ERR ,"Failed to find valid \"System RAM\" " -"entry in file %s" , proc_iomem); -return -1 ; - } - - spapr_dma_win_len =rte_align64pow2 (max +1 ); -return 0 ; - }else if (rte_eal_iova_mode () ==RTE_IOVA_VA ) { -EAL_LOG (DEBUG ,"Highest VA address in memseg list is 0x%" - PRIx64, param->max_va); - spapr_dma_win_len =rte_align64pow2 (param->max_va); -return 0 ; - } - - spapr_dma_win_len =0 ; -EAL_LOG (ERR ,"Unsupported IOVA mode" ); -return -1 ; -} - - -/* -* The SPAPRv2 IOMMU supports 2 DMA windows with starting -* address at 0 or 1<<59. By default, a DMA window is set -* at address 0, 2GB long, with a 4KB page. For DPDK we -* must remove the default window and setup a new DMA window -* based on the hugepage size and memory requirements of -* the application before we can map memory for DMA. -*/ -static int -spapr_dma_win_size (void ) -{ -struct spapr_size_walk_param param; - -/* only create DMA window once */ -if (spapr_dma_win_len >0 ) -return 0 ; - -/* walk the memseg list to find the page size/max VA address */ -memset (¶m,0 ,sizeof (param)); -if (rte_memseg_list_walk (vfio_spapr_size_walk, ¶m) <0 ) { -EAL_LOG (ERR ,"Failed to walk memseg list for DMA window size" ); -return -1 ; - } - -/* we can't be sure if DMA window covers external memory */ -if (param.is_user_managed) -EAL_LOG (WARNING ,"Detected user managed external memory which may not be managed by the IOMMU" ); - -/* check physical/virtual memory size */ -if (find_highest_mem_addr (¶m) <0 ) -return -1 ; -EAL_LOG (DEBUG ,"Setting DMA window size to 0x%" PRIx64, - spapr_dma_win_len); - spapr_dma_win_page_sz = param.page_sz; -rte_mem_set_dma_mask (rte_ctz64 (spapr_dma_win_len)); -return 0 ; -} - -static int -vfio_spapr_create_dma_window (struct vfio_container *cfg) -{ -struct vfio_iommu_spapr_tce_create create = { - .argsz =sizeof (create), }; -struct vfio_iommu_spapr_tce_remove remove = { - .argsz =sizeof (remove), }; -struct vfio_iommu_spapr_tce_info info = { - .argsz =sizeof (info), }; -int ret; - - ret =spapr_dma_win_size (); -if (ret <0 ) -return ret; - - ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_GET_INFO , &info); -if (ret) { -EAL_LOG (ERR ,"Cannot get IOMMU info, error %i (%s)" , - errno,strerror (errno)); -return -1 ; - } - -/* -* sPAPR v1/v2 IOMMU always has a default 1G DMA window set. The window -* can't be changed for v1 but it can be changed for v2. Since DPDK only -* supports v2, remove the default DMA window so it can be resized. -*/ - remove.start_addr = info.dma32_window_start; - ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_REMOVE , &remove); -if (ret) -return -1 ; - -/* create a new DMA window (start address is not selectable) */ - create.window_size = spapr_dma_win_len; - create.page_shift =rte_ctz64 (spapr_dma_win_page_sz); - create.levels =1 ; - ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_CREATE , &create); -#ifdef VFIO_IOMMU_SPAPR_INFO_DDW -/* -* The vfio_iommu_spapr_tce_info structure was modified in -* Linux kernel 4.2.0 to add support for the -* vfio_iommu_spapr_tce_ddw_info structure needed to try -* multiple table levels. Skip the attempt if running with -* an older kernel. -*/ -if (ret) { -/* if at first we don't succeed, try more levels */ -uint32_t levels; - -for (levels = create.levels +1 ; - ret && levels <= info.ddw.levels; levels++) { - create.levels = levels; - ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_CREATE , &create); - } - } -#endif /* VFIO_IOMMU_SPAPR_INFO_DDW */ -if (ret) { -EAL_LOG (ERR ,"Cannot create new DMA window, error " -"%i (%s)" , errno,strerror (errno)); -EAL_LOG (ERR , -"Consider using a larger hugepage size if supported by the system" ); -return -1 ; - } - -/* verify the start address */ -if (create.start_addr !=0 ) { -EAL_LOG (ERR ,"Received unsupported start address 0x%" - PRIx64, (uint64_t )create.start_addr); -return -1 ; - } -return ret; -} - -static int -vfio_spapr_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, -int do_map) -{ -int ret =0 ; - -if (do_map) { -if (vfio_spapr_dma_do_map (cfg, vaddr, iova, len,1 )) { -EAL_LOG (ERR ,"Failed to map DMA" ); - ret =-1 ; - } - }else { -if (vfio_spapr_dma_do_map (cfg, vaddr, iova, len,0 )) { -EAL_LOG (ERR ,"Failed to unmap DMA" ); - ret =-1 ; - } - } - -return ret; -} - -static int -vfio_spapr_dma_map (struct vfio_container *cfg) -{ -if (vfio_spapr_create_dma_window (cfg) <0 ) { -EAL_LOG (ERR ,"Could not create new DMA window!" ); -return -1 ; - } - -/* map all existing DPDK segments for DMA */ -if (rte_memseg_walk (vfio_spapr_map_walk, cfg) <0 ) -return -1 ; - -return 0 ; -} - -static int -vfio_noiommu_dma_map(struct vfio_container *cfg __rte_unused) -{ -/* No-IOMMU mode does not need DMA mapping */ -return 0 ; -} - -static int -vfio_noiommu_dma_mem_map(struct vfio_container *cfg __rte_unused, uint64_t vaddr __rte_unused, - uint64_t iova __rte_unused, uint64_t len __rte_unused, int do_map __rte_unused) -{ -/* No-IOMMU mode does not need DMA mapping */ -return 0 ; -} -static int vfio_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len,int do_map)
lib/eal/linux/eal_vfio.h +2 -0
@@ -70,6 +70,8 @@ struct vfio_iommu_ops {vfio_dma_func_t dma_map_func; }; +extern const struct vfio_iommu_ops iommu_types[3 ]; +/* get the vfio container that devices are bound to by default */ int vfio_open_container_fd (bool mp_request);
lib/eal/linux/eal_vfio_group.c new file +521 -0
521 lines not on this page · raw message
lib/eal/linux/meson.build +1 -0
@@ -16,6 +16,7 @@ sources += files( 'eal_thread.c', 'eal_timer.c', 'eal_vfio.c', + 'eal_vfio_group.c', 'eal_vfio_mp_sync.c', )
Signature · 1 line
2.54.0
PATCH v19 21/26 vfio: add some check on input parameters
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Make error handling more consistent, and provide/document rte_errno values returned from API's to indicate various conditions.
--- lib/eal/linux/eal_vfio.c | 33 ++++++++++++- lib/eal/linux/include/dev_vfio.h | 84 +++++++++++++++++--------------- 2 files changed, 78 insertions(+), 39 deletions(-)
lib/eal/linux/eal_vfio.c +32 -1
@@ -29,6 +29,12 @@#define VFIO_MEM_EVENT_CLB_NAME "vfio_mem_event_clb" +/* +* rte_errno convention: +* +* - EINVAL: invalid parameters +*/ +/* per-process VFIO config */ static struct vfio_container vfio_containers[RTE_MAX_VFIO_CONTAINERS ];
@@ -755,6 +761,11 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deconst struct internal_config *internal_conf =eal_get_internal_configuration (); +if (sysfs_base ==NULL || dev_addr ==NULL || vfio_dev_fd ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } +if (!vfio_enabled)return -1 ;
@@ -986,6 +997,11 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr,int iommu_group_num;int ret; +if (sysfs_base ==NULL || dev_addr ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } +if (!vfio_enabled)return -1 ;
@@ -1177,10 +1193,15 @@ dev_vfio_get_device_info(int vfio_dev_fd, struct vfio_device_info *device_info) {int ret; +if (device_info ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } +if (!vfio_enabled)return -1 ; -if (device_info ==NULL || vfio_dev_fd <0 ) +if (vfio_dev_fd <0 )return -1 ; ret =ioctl (vfio_dev_fd,VFIO_DEVICE_GET_INFO , device_info);
@@ -1291,6 +1312,11 @@ dev_vfio_get_group_num(const char *sysfs_base,char *tok[16 ], *group_tok, *end;int ret; +if (sysfs_base ==NULL || dev_addr ==NULL || iommu_group_num ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } +if (!vfio_enabled)return -1 ;
@@ -1610,6 +1636,11 @@ dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base,int iommu_group_num;int ret; +if (sysfs_base ==NULL || dev_addr ==NULL ) { + rte_errno =EINVAL ; +return -1 ; + } + 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);
lib/eal/linux/include/dev_vfio.h +46 -38
163 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v19 22/26 vfio: decouple device setup from bus concerns
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Change the return semantics of dev_vfio_setup_device and dev_vfio_get_group_num to be more consistent with standard error handling conventions.
Previously, these functions returned positive values (1 or >0) to indicate that a device is not managed by VFIO. This convention was inherited from PCI bus semantics where positive return means "skip this device", but VFIO should not follow bus-specific conventions.
Now both functions return -1 with rte_errno set to ENODEV when the device is not managed by VFIO. This makes error handling more consistent and allows callers to distinguish between "not a VFIO device" (ENODEV) and actual errors.
All driver call sites have been updated to check for rte_errno == ENODEV and convert it to the bus-specific "skip" return value (1) where appropriate.
--- drivers/bus/cdx/cdx_vfio.c | 13 ++++++++-- drivers/bus/fslmc/fslmc_vfio.c | 4 +-- drivers/bus/pci/linux/pci_vfio.c | 13 ++++++++-- drivers/crypto/bcmfs/bcmfs_vfio.c | 9 +++++-- drivers/net/nbl/nbl_common/nbl_userdev.c | 2 +- lib/eal/linux/eal_vfio.c | 33 +++++++----------------- lib/eal/linux/include/dev_vfio.h | 4 +-- 7 files changed, 43 insertions(+), 35 deletions(-)
drivers/bus/cdx/cdx_vfio.c +11 -2
@@ -22,6 +22,7 @@#include <eal_export.h> #include <rte_eal_paging.h> +#include <rte_errno.h> #include <rte_malloc.h> #include <dev_vfio.h>
@@ -402,8 +403,12 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev) ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, &vfio_dev_fd); -if (ret) +if (ret <0 ) { +/* Device not managed by VFIO - skip */ +if (rte_errno ==ENODEV ) + ret =1 ;return ret; + } ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info);if (ret)
@@ -514,8 +519,12 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev) } ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, &vfio_dev_fd); -if (ret) +if (ret <0 ) { +/* Device not managed by VFIO - skip */ +if (rte_errno ==ENODEV ) + ret =1 ;return ret; + } ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info);if (ret)
drivers/bus/fslmc/fslmc_vfio.c +2 -2
@@ -376,9 +376,9 @@ fslmc_get_group_id(const char *group_name,/* get group number */ ret =dev_vfio_get_group_num (SYSFS_FSL_MC_DEVICES , group_name, groupid); -if (ret <=0 ) { +if (ret <0 ) {DPAA2_BUS_ERR ("Find %s IOMMU group" , group_name); -if (ret <0 ) +if (rte_errno !=ENODEV )return ret;return -EIO ;
drivers/bus/pci/linux/pci_vfio.c +11 -2
@@ -20,6 +20,7 @@#include <rte_malloc.h> #include <dev_vfio.h> #include <rte_eal.h> +#include <rte_errno.h> #include <bus_driver.h> #include <rte_spinlock.h> #include <rte_tailq.h>
@@ -753,8 +754,12 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) loc->domain, loc->bus, loc->devid, loc->function); ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd); -if (ret) +if (ret <0 ) { +/* Device not managed by VFIO - skip */ +if (rte_errno ==ENODEV ) + ret =1 ;return ret; + } ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info);if (ret)
@@ -965,8 +970,12 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) } ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd); -if (ret) +if (ret <0 ) { +/* Device not managed by VFIO - skip */ +if (rte_errno ==ENODEV ) + ret =1 ;return ret; + } ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info);if (ret)
drivers/crypto/bcmfs/bcmfs_vfio.c +7 -2
@@ -9,6 +9,7 @@#include <sys/mman.h> #include <sys/ioctl.h> +#include <rte_errno.h> #include <dev_vfio.h> #include "bcmfs_device.h"
@@ -26,8 +27,12 @@ vfio_map_dev_obj(const char *path, const char *dev_obj,struct vfio_region_info reg_info = { .argsz =sizeof (reg_info) }; ret =dev_vfio_setup_device (path, dev_obj, dev_fd); -if (ret) { -BCMFS_LOG (ERR ,"VFIO Setting for device failed" ); +if (ret <0 ) { +/* Device not managed by VFIO - skip */ +if (rte_errno ==ENODEV ) + ret =1 ; +else +BCMFS_LOG (ERR ,"VFIO Setting for device failed" );return ret; }
drivers/net/nbl/nbl_common/nbl_userdev.c +1 -1
@@ -430,7 +430,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) "%s/%s/", rte_pci_get_sysfs_path(), dev_name); ret =dev_vfio_get_group_num (pathname, dev_name, &common->iommu_group_num); -if (ret <=0 ) { +if (ret <0 ) {NBL_LOG (ERR ,"nbl vfio group number failed" );return -1 ; }
lib/eal/linux/eal_vfio.c +10 -23
@@ -33,6 +33,7 @@* rte_errno convention: * * - EINVAL: invalid parameters +* - ENODEV: device not managed by VFIO */ /* per-process VFIO config */
@@ -771,14 +772,6 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de/* get group number */ ret =dev_vfio_get_group_num (sysfs_base, dev_addr, &iommu_group_num); -if (ret ==0 ) { -EAL_LOG (NOTICE , -"%s not managed by VFIO driver, skipping" , - dev_addr); -return 1 ; - } - -/* if negative, something failed */ if (ret <0 )return -1 ;
@@ -792,10 +785,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* isn't managed by VFIO */ if (vfio_group_fd == -ENOENT ) { -EAL_LOG (NOTICE , -"%s not managed by VFIO driver, skipping" , - dev_addr); -return 1 ; + rte_errno =ENODEV ; +return -1 ; }/*
@@ -1013,11 +1004,9 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr,/* get group number */ ret =dev_vfio_get_group_num (sysfs_base, dev_addr, &iommu_group_num); -if (ret <=0 ) { +if (ret <0 ) {EAL_LOG (WARNING ,"%s not managed by VFIO driver" , dev_addr); -/* This is an error at this point. */ - ret =-1 ; goto out; }
@@ -1304,8 +1293,7 @@ dev_vfio_get_container_fd(void)RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_group_num) int -dev_vfio_get_group_num (const char *sysfs_base, -const char *dev_addr,int *iommu_group_num) +dev_vfio_get_group_num (const char *sysfs_base,const char *dev_addr,int *iommu_group_num) {char linkname[PATH_MAX ];char filename[PATH_MAX ];
@@ -1330,8 +1318,10 @@ dev_vfio_get_group_num(const char *sysfs_base, ret =readlink (linkname, filename,sizeof (filename));/* if the link doesn't exist, no VFIO for us */ -if (ret <0 ) -return 0 ; +if (ret <0 ) { + rte_errno =ENODEV ; +return -1 ; + } ret =rte_strsplit (filename,sizeof (filename), tok,RTE_DIM (tok),'/' );
@@ -1351,7 +1341,7 @@ dev_vfio_get_group_num(const char *sysfs_base,return -1 ; } -return 1 ; +return 0 ; } static int
@@ -1645,9 +1635,6 @@ dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base,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 =vfio_container_group_bind (vfio_container_fd, iommu_group_num);
lib/eal/linux/include/dev_vfio.h +1 -3
@@ -62,7 +62,6 @@ enum dev_vfio_module {* * @return * 0 on success. -* >1 if the device cannot be managed this way. * <0 on failure, rte_errno is set. * * Possible rte_errno values include:
@@ -159,8 +158,7 @@ int dev_vfio_noiommu_is_enabled(void);* Pointer to where IOMMU group number will be stored. * * @return -* >0 on success -* 0 for non-existent group or VFIO +* 0 on success. * <0 on failure, rte_errno is set. * * Possible rte_errno values include:
Signature · 1 line
2.54.0
PATCH v19 23/26 vfio: introduce IOVA mode
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Introduce dev_vfio_get_iova_mode() to return the IOVA remapping capability (PA, VA or UNKNOWN).
Because the no-IOMMU check will rely on new mode infrastructure in later commits, the VFIO initialization now needs to happen before bus scan, as buses depend on no-IOMMU information.
--- drivers/bus/fslmc/fslmc_bus.c | 3 +- drivers/bus/fslmc/fslmc_vfio.c | 2 +- drivers/bus/pci/linux/pci.c | 2 +- drivers/net/hinic3/base/hinic3_hwdev.c | 3 +- drivers/net/ntnic/ntnic_ethdev.c | 2 +- lib/eal/linux/eal.c | 15 ++- lib/eal/linux/eal_vfio.c | 130 ++++++++++++++++++------- lib/eal/linux/eal_vfio.h | 5 + lib/eal/linux/eal_vfio_mp_sync.c | 5 + lib/eal/linux/include/dev_vfio.h | 27 +++-- 10 files changed, 143 insertions(+), 51 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +2 -1
@@ -500,7 +500,8 @@ rte_dpaa2_get_iommu_class(void)return RTE_IOVA_DC ;/* check if all devices on the bus support Virtual addressing or not */ -if (fslmc_all_device_support_iova () !=0 &&dev_vfio_noiommu_is_enabled () ==0 ) +if (fslmc_all_device_support_iova () !=0 && +dev_vfio_get_iova_mode () ==DEV_VFIO_IOVA_MODE_VA )return RTE_IOVA_VA ;return RTE_IOVA_PA ;
drivers/bus/fslmc/fslmc_vfio.c +1 -1
@@ -204,7 +204,7 @@ fslmc_vfio_add_group(int vfio_group_fd, group->fd = vfio_group_fd; group->groupid = iommu_group_num;rte_strscpy (group->group_name, group_name,sizeof (group->group_name)); -if (dev_vfio_noiommu_is_enabled () >0 ) +if (dev_vfio_get_iova_mode () ==DEV_VFIO_IOVA_MODE_PA ) group->iommu_type =VFIO_NOIOMMU_IOMMU ;else group->iommu_type =VFIO_TYPE1_IOMMU ;
drivers/bus/pci/linux/pci.c +1 -1
@@ -631,7 +631,7 @@ pci_device_iova_mode(const struct rte_pci_driver *pdrv,static int is_vfio_noiommu_enabled =-1 ;if (is_vfio_noiommu_enabled ==-1 ) { -if (dev_vfio_noiommu_is_enabled () ==1 ) +if (dev_vfio_get_iova_mode () ==DEV_VFIO_IOVA_MODE_PA ) is_vfio_noiommu_enabled =1 ;else is_vfio_noiommu_enabled =0 ;
drivers/net/hinic3/base/hinic3_hwdev.c +2 -1
@@ -78,7 +78,8 @@ hinic3_is_vfio_iommu_enable(const struct rte_eth_dev *eth_dev) {struct rte_pci_device *pci_dev =RTE_CLASS_TO_BUS_DEVICE (eth_dev, *pci_dev); -return pci_dev->kdrv ==RTE_PCI_KDRV_VFIO &&dev_vfio_noiommu_is_enabled () !=1 ; +return pci_dev->kdrv ==RTE_PCI_KDRV_VFIO && +dev_vfio_get_iova_mode () ==DEV_VFIO_IOVA_MODE_VA ; }int
drivers/net/ntnic/ntnic_ethdev.c +1 -1
@@ -2729,7 +2729,7 @@ nthw_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) (pci_dev->device.devargs->data ? pci_dev->device.devargs->data : "NULL")); } -const int n_rte_vfio_no_io_mmu_enabled =dev_vfio_noiommu_is_enabled (); +const int n_rte_vfio_no_io_mmu_enabled =dev_vfio_get_iova_mode () ==DEV_VFIO_IOVA_MODE_PA ;NT_LOG (DBG ,NTNIC ,"vfio_no_iommu_enabled=%d" , n_rte_vfio_no_io_mmu_enabled);if (n_rte_vfio_no_io_mmu_enabled) {
lib/eal/linux/eal.c +10 -5
@@ -674,6 +674,16 @@ rte_eal_init(int argc, char **argv) } } +/* +* VFIO must be initialized before bus scan because buses need to know +* about no-IOMMU mode status. +*/ +if (dev_vfio_enable ()) { +rte_eal_init_alert ("Cannot init VFIO" ); + rte_errno =EAGAIN ; + goto err_out; + } +if (rte_bus_scan ()) {rte_eal_init_alert ("Cannot scan the buses for devices" ); rte_errno =ENODEV ;
@@ -769,11 +779,6 @@ rte_eal_init(int argc, char **argv)#endif } -if (dev_vfio_enable ()) { -rte_eal_init_alert ("Cannot init VFIO" ); - rte_errno =EAGAIN ; - goto err_out; - }/* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first.
lib/eal/linux/eal_vfio.c +96 -34
167 lines not on this page · raw message
lib/eal/linux/eal_vfio.h +5 -0
@@ -9,6 +9,8 @@#include <stdint.h> +#include <dev_vfio.h> +/* hot plug/unplug of VFIO groups may cause all DMA maps to be dropped. we can * recreate the mappings for DPDK segments, but we cannot do so for memory that * was registered by the user themselves, so we need to store the user mappings
@@ -78,6 +80,7 @@ int vfio_open_container_fd(bool mp_request);/* global configuration */ struct vfio_config {struct vfio_container *default_cfg; +enum dev_vfio_iova_mode iova_mode;const struct vfio_iommu_ops *ops; };
@@ -105,6 +108,7 @@ void vfio_mp_sync_cleanup(void);#define VFIO_SOCKET_REQ_CONTAINER 0x100#define VFIO_SOCKET_REQ_GROUP 0x200#define VFIO_SOCKET_REQ_IOMMU_TYPE 0x400 +#define VFIO_SOCKET_REQ_IOVA_MODE 0x800#define VFIO_SOCKET_OK 0x0#define VFIO_SOCKET_NO_FD 0x1#define VFIO_SOCKET_ERR 0xFF
@@ -115,6 +119,7 @@ struct vfio_mp_param {union {int group_num;int iommu_type_id; +enum dev_vfio_iova_mode iova_mode; }; };
lib/eal/linux/eal_vfio_mp_sync.c +5 -0
@@ -74,6 +74,11 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer) }break ; } +case VFIO_SOCKET_REQ_IOVA_MODE : + r->req =VFIO_SOCKET_REQ_IOVA_MODE ; + r->iova_mode = vfio_global_cfg.iova_mode; + r->result =VFIO_SOCKET_OK ; +break ;default :EAL_LOG (ERR ,"vfio received invalid message!" );return -1 ;
lib/eal/linux/include/dev_vfio.h +20 -7
@@ -27,8 +27,6 @@ extern "C" {#define DEV_VFIO_CONTAINER_PATH "/dev/vfio/vfio"#define DEV_VFIO_GROUP_FMT "/dev/vfio/%u"#define DEV_VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u" -#define DEV_VFIO_NOIOMMU_MODE \ - "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode"/* we don't need an actual definition, only pointer is used */ struct vfio_device_info ;
@@ -46,6 +44,22 @@ enum dev_vfio_module { DEV_VFIO_MODULE_VFIO_PCI, /**< VFIO PCI module. */ }; +/** +* @enum dev_vfio_iova_mode +* IOVA modes. +* +* These modes describe IOVA remapping capability. +* +* - DEV_VFIO_IOVA_MODE_UNKNOWN: IOVA mode is unknown. +* - DEV_VFIO_IOVA_MODE_VA: IOVA addresses can be remapped. +* - DEV_VFIO_IOVA_MODE_PA: IOVA addresses cannot be remapped. +*/ +enum dev_vfio_iova_mode { +DEV_VFIO_IOVA_MODE_UNKNOWN =0 ,/**< IOVA mode not determined */ +DEV_VFIO_IOVA_MODE_VA ,/**< IOVA addresses can be remapped */ +DEV_VFIO_IOVA_MODE_PA ,/**< IOVA addresses cannot be remapped */ +}; +/** * @internal * Set up a device managed by VFIO driver.
@@ -136,15 +150,14 @@ int dev_vfio_is_enabled(void);/** * @internal -* Whether VFIO NOIOMMU mode is enabled. +* Get current VFIO IOVA mode. * * @return -* 1 if true. -* 0 if false. -* <0 for errors. +* VFIO IOVA mode currently in use. */ __rte_internal -int dev_vfio_noiommu_is_enabled(void); +enum dev_vfio_iova_mode +dev_vfio_get_iova_mode (void );/** * @internal
Signature · 1 line
2.54.0
PATCH v19 24/26 vfio: introduce VFIO mode
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Currently, VFIO code is a bit of an incoherent mess internally, with API's bleeding into each other, inconsistent returns, and a certain amount of spaghetti stemming from organic growth.
Refactor VFIO code to achieve the following goals:
- Make all error handling consistent, and provide/document rte_errno values returned from API's to indicate various conditions.
- Introduce new "VFIO mode" concept. This new API will tell caller which VFIO mode is in use, allowing callers to know when to call group number vs device number API
- Perform device setup in device assign, and make device setup use shared code path with device assign and explicitly assuming default container. This is technically not necessary for group mode as device set up is a two-step process in that mode, but coming cdev mode will have a single-step device setup, and it would be easier if the worked the same way under the hood.
- Add device deduplication based on sysfs path and device address.
- Make VFIO internals more readable. Introduce a lot of infrastructure and more explicit validation, rather than over-reliance on sentinel values and implicit assumptions. This will also make it easier to integrate cdev mode down the line, as it will rely on most of this infrastructure.
- Change dev_vfio_container_destroy so this function now releases and closes all group and device resources associated with the container being destroyed by this call
--- config/arm/meson.build | 1 + config/meson.build | 1 + lib/eal/linux/eal_vfio.c | 1679 +++++++++++++----------------- lib/eal/linux/eal_vfio.h | 77 +- lib/eal/linux/eal_vfio_group.c | 422 +++++++- lib/eal/linux/eal_vfio_mp_sync.c | 43 +- lib/eal/linux/include/dev_vfio.h | 104 +- 7 files changed, 1318 insertions(+), 1009 deletions(-)
config/arm/meson.build +1 -0
@@ -147,6 +147,7 @@ implementer_cavium = { 'description': 'Cavium', 'flags': [ ['RTE_MAX_VFIO_GROUPS', 128], + ['RTE_MAX_VFIO_DEVICES', 256], ['RTE_MAX_LCORE', 96], ['RTE_MAX_NUMA_NODES', 2] ],
config/meson.build +1 -0
@@ -386,6 +386,7 @@ dpdk_conf.set('RTE_ENABLE_TRACE_FP', get_option('enable_trace_fp')) dpdk_conf.set('RTE_PKTMBUF_HEADROOM', get_option('pkt_mbuf_headroom')) # values which have defaults which may be overridden dpdk_conf.set('RTE_MAX_VFIO_GROUPS', 64) +dpdk_conf.set('RTE_MAX_VFIO_DEVICES', 256) dpdk_conf.set('RTE_DRIVER_MEMPOOL_BUCKET_SIZE_KB', 64) dpdk_conf.set('RTE_LIBRTE_DPAA2_USE_PHYS_IOVA', true) if get_option('mbuf_refcnt_atomic')
lib/eal/linux/eal_vfio.c +718 -961
2,062 lines not on this page · raw message
lib/eal/linux/eal_vfio.h +60 -17
129 lines not on this page · raw message
lib/eal/linux/eal_vfio_group.c +412 -10
469 lines not on this page · raw message
lib/eal/linux/eal_vfio_mp_sync.c +35 -8
82 lines not on this page · raw message
lib/eal/linux/include/dev_vfio.h +91 -13
221 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v19 25/26 uapi: import IOMMUFD header
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
In order to support VF tokens for cdev-based VFIO mode, iommufd.h is required (from kernel v6.17).
---
Changes since v18:
- updated commitlog, following rebase,
--- kernel/linux/uapi/linux/iommufd.h | 1302 +++++++++++++++++++++++++++++ 1 file changed, 1302 insertions(+) create mode 100644 kernel/linux/uapi/linux/iommufd.h
kernel/linux/uapi/linux/iommufd.h new file +1302 -0
@@ -0,0 +1,1302 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. +*/ +#ifndef _IOMMUFD_H +#define _IOMMUFD_H + +#include <linux/ioctl.h> +#include <uapi/linux/types.h> + +#define IOMMUFD_TYPE (';') + +/** +* DOC: General ioctl format +* +* The ioctl interface follows a general format to allow for extensibility. Each +* ioctl is passed in a structure pointer as the argument providing the size of +* the structure in the first u32. The kernel checks that any structure space +* beyond what it understands is 0. This allows userspace to use the backward +* compatible portion while consistently using the newer, larger, structures. +* +* ioctls use a standard meaning for common errnos: +* +* - ENOTTY: The IOCTL number itself is not supported at all +* - E2BIG: The IOCTL number is supported, but the provided structure has +* non-zero in a part the kernel does not understand. +* - EOPNOTSUPP: The IOCTL number is supported, and the structure is +* understood, however a known field has a value the kernel does not +* understand or support. +* - EINVAL: Everything about the IOCTL was understood, but a field is not +* correct. +* - ENOENT: An ID or IOVA provided does not exist. +* - ENOMEM: Out of memory. +* - EOVERFLOW: Mathematics overflowed. +* +* As well as additional errnos, within specific ioctls. +*/ +enum { +IOMMUFD_CMD_BASE =0x80 , +IOMMUFD_CMD_DESTROY =IOMMUFD_CMD_BASE , +IOMMUFD_CMD_IOAS_ALLOC =0x81 , +IOMMUFD_CMD_IOAS_ALLOW_IOVAS =0x82 , +IOMMUFD_CMD_IOAS_COPY =0x83 , +IOMMUFD_CMD_IOAS_IOVA_RANGES =0x84 , +IOMMUFD_CMD_IOAS_MAP =0x85 , +IOMMUFD_CMD_IOAS_UNMAP =0x86 , +IOMMUFD_CMD_OPTION =0x87 , +IOMMUFD_CMD_VFIO_IOAS =0x88 , +IOMMUFD_CMD_HWPT_ALLOC =0x89 , +IOMMUFD_CMD_GET_HW_INFO =0x8a , +IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING =0x8b , +IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP =0x8c , +IOMMUFD_CMD_HWPT_INVALIDATE =0x8d , +IOMMUFD_CMD_FAULT_QUEUE_ALLOC =0x8e , +IOMMUFD_CMD_IOAS_MAP_FILE =0x8f , +IOMMUFD_CMD_VIOMMU_ALLOC =0x90 , +IOMMUFD_CMD_VDEVICE_ALLOC =0x91 , +IOMMUFD_CMD_IOAS_CHANGE_PROCESS =0x92 , +IOMMUFD_CMD_VEVENTQ_ALLOC =0x93 , +IOMMUFD_CMD_HW_QUEUE_ALLOC =0x94 , +}; + +/** +* struct iommu_destroy - ioctl(IOMMU_DESTROY) +* @size: sizeof(struct iommu_destroy) +* @id: iommufd object ID to destroy. Can be any destroyable object type. +* +* Destroy any object held within iommufd. +*/ +struct iommu_destroy { +__u32 size; +__u32 id; +}; +#define IOMMU_DESTROY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DESTROY) + +/** +* struct iommu_ioas_alloc - ioctl(IOMMU_IOAS_ALLOC) +* @size: sizeof(struct iommu_ioas_alloc) +* @flags: Must be 0 +* @out_ioas_id: Output IOAS ID for the allocated object +* +* Allocate an IO Address Space (IOAS) which holds an IO Virtual Address (IOVA) +* to memory mapping. +*/ +struct iommu_ioas_alloc { +__u32 size; +__u32 flags; +__u32 out_ioas_id; +}; +#define IOMMU_IOAS_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_ALLOC) + +/** +* struct iommu_iova_range - ioctl(IOMMU_IOVA_RANGE) +* @start: First IOVA +* @last: Inclusive last IOVA +* +* An interval in IOVA space. +*/ +struct iommu_iova_range { +__aligned_u64 start; +__aligned_u64 last; +}; + +/** +* struct iommu_ioas_iova_ranges - ioctl(IOMMU_IOAS_IOVA_RANGES) +* @size: sizeof(struct iommu_ioas_iova_ranges) +* @ioas_id: IOAS ID to read ranges from +* @num_iovas: Input/Output total number of ranges in the IOAS +* @__reserved: Must be 0 +* @allowed_iovas: Pointer to the output array of struct iommu_iova_range +* @out_iova_alignment: Minimum alignment required for mapping IOVA +* +* Query an IOAS for ranges of allowed IOVAs. Mapping IOVA outside these ranges +* is not allowed. num_iovas will be set to the total number of iovas and +* the allowed_iovas[] will be filled in as space permits. +* +* The allowed ranges are dependent on the HW path the DMA operation takes, and +* can change during the lifetime of the IOAS. A fresh empty IOAS will have a +* full range, and each attached device will narrow the ranges based on that +* device's HW restrictions. Detaching a device can widen the ranges. Userspace +* should query ranges after every attach/detach to know what IOVAs are valid +* for mapping. +* +* On input num_iovas is the length of the allowed_iovas array. On output it is +* the total number of iovas filled in. The ioctl will return -EMSGSIZE and set +* num_iovas to the required value if num_iovas is too small. In this case the +* caller should allocate a larger output array and re-issue the ioctl. +* +* out_iova_alignment returns the minimum IOVA alignment that can be given +* to IOMMU_IOAS_MAP/COPY. IOVA's must satisfy:: +* +* starting_iova % out_iova_alignment == 0 +* (starting_iova + length) % out_iova_alignment == 0 +* +* out_iova_alignment can be 1 indicating any IOVA is allowed. It cannot +* be higher than the system PAGE_SIZE. +*/ +struct iommu_ioas_iova_ranges { +__u32 size; +__u32 ioas_id; +__u32 num_iovas; +__u32 __reserved; +__aligned_u64 allowed_iovas; +__aligned_u64 out_iova_alignment; +}; +#define IOMMU_IOAS_IOVA_RANGES _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_IOVA_RANGES) + +/** +* struct iommu_ioas_allow_iovas - ioctl(IOMMU_IOAS_ALLOW_IOVAS) +* @size: sizeof(struct iommu_ioas_allow_iovas) +* @ioas_id: IOAS ID to allow IOVAs from +* @num_iovas: Input/Output total number of ranges in the IOAS +* @__reserved: Must be 0 +* @allowed_iovas: Pointer to array of struct iommu_iova_range +* +* Ensure a range of IOVAs are always available for allocation. If this call +* succeeds then IOMMU_IOAS_IOVA_RANGES will never return a list of IOVA ranges +* that are narrower than the ranges provided here. This call will fail if +* IOMMU_IOAS_IOVA_RANGES is currently narrower than the given ranges. +* +* When an IOAS is first created the IOVA_RANGES will be maximally sized, and as +* devices are attached the IOVA will narrow based on the device restrictions. +* When an allowed range is specified any narrowing will be refused, ie device +* attachment can fail if the device requires limiting within the allowed range. +* +* Automatic IOVA allocation is also impacted by this call. MAP will only +* allocate within the allowed IOVAs if they are present. +* +* This call replaces the entire allowed list with the given list. +*/ +struct iommu_ioas_allow_iovas { +__u32 size; +__u32 ioas_id; +__u32 num_iovas; +__u32 __reserved; +__aligned_u64 allowed_iovas; +}; +#define IOMMU_IOAS_ALLOW_IOVAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_ALLOW_IOVAS) + +/** +* enum iommufd_ioas_map_flags - Flags for map and copy +* @IOMMU_IOAS_MAP_FIXED_IOVA: If clear the kernel will compute an appropriate +* IOVA to place the mapping at +* @IOMMU_IOAS_MAP_WRITEABLE: DMA is allowed to write to this mapping +* @IOMMU_IOAS_MAP_READABLE: DMA is allowed to read from this mapping +*/ +enum iommufd_ioas_map_flags { +IOMMU_IOAS_MAP_FIXED_IOVA =1 <<0 , +IOMMU_IOAS_MAP_WRITEABLE =1 <<1 , +IOMMU_IOAS_MAP_READABLE =1 <<2 , +}; + +/** +* struct iommu_ioas_map - ioctl(IOMMU_IOAS_MAP) +* @size: sizeof(struct iommu_ioas_map) +* @flags: Combination of enum iommufd_ioas_map_flags +* @ioas_id: IOAS ID to change the mapping of +* @__reserved: Must be 0 +* @user_va: Userspace pointer to start mapping from +* @length: Number of bytes to map +* @iova: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is set +* then this must be provided as input. +* +* Set an IOVA mapping from a user pointer. If FIXED_IOVA is specified then the +* mapping will be established at iova, otherwise a suitable location based on +* the reserved and allowed lists will be automatically selected and returned in +* iova. +* +* If IOMMU_IOAS_MAP_FIXED_IOVA is specified then the iova range must currently +* be unused, existing IOVA cannot be replaced. +*/ +struct iommu_ioas_map { +__u32 size; +__u32 flags; +__u32 ioas_id; +__u32 __reserved; +__aligned_u64 user_va; +__aligned_u64 length; +__aligned_u64 iova; +}; +#define IOMMU_IOAS_MAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_MAP) + +/** +* struct iommu_ioas_map_file - ioctl(IOMMU_IOAS_MAP_FILE) +* @size: sizeof(struct iommu_ioas_map_file) +* @flags: same as for iommu_ioas_map +* @ioas_id: same as for iommu_ioas_map +* @fd: the memfd to map +* @start: byte offset from start of file to map from +* @length: same as for iommu_ioas_map +* @iova: same as for iommu_ioas_map +* +* Set an IOVA mapping from a memfd file. All other arguments and semantics +* match those of IOMMU_IOAS_MAP. +*/ +struct iommu_ioas_map_file { +__u32 size; +__u32 flags; +__u32 ioas_id; +__s32 fd; +__aligned_u64 start; +__aligned_u64 length; +__aligned_u64 iova; +}; +#define IOMMU_IOAS_MAP_FILE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_MAP_FILE) + +/** +* struct iommu_ioas_copy - ioctl(IOMMU_IOAS_COPY) +* @size: sizeof(struct iommu_ioas_copy) +* @flags: Combination of enum iommufd_ioas_map_flags +* @dst_ioas_id: IOAS ID to change the mapping of +* @src_ioas_id: IOAS ID to copy from +* @length: Number of bytes to copy and map +* @dst_iova: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is +* set then this must be provided as input. +* @src_iova: IOVA to start the copy +* +* Copy an already existing mapping from src_ioas_id and establish it in +* dst_ioas_id. The src iova/length must exactly match a range used with +* IOMMU_IOAS_MAP. +* +* This may be used to efficiently clone a subset of an IOAS to another, or as a +* kind of 'cache' to speed up mapping. Copy has an efficiency advantage over +* establishing equivalent new mappings, as internal resources are shared, and +* the kernel will pin the user memory only once. +*/ +struct iommu_ioas_copy { +__u32 size; +__u32 flags; +__u32 dst_ioas_id; +__u32 src_ioas_id; +__aligned_u64 length; +__aligned_u64 dst_iova; +__aligned_u64 src_iova; +}; +#define IOMMU_IOAS_COPY _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_COPY) + +/** +* struct iommu_ioas_unmap - ioctl(IOMMU_IOAS_UNMAP) +* @size: sizeof(struct iommu_ioas_unmap) +* @ioas_id: IOAS ID to change the mapping of +* @iova: IOVA to start the unmapping at +* @length: Number of bytes to unmap, and return back the bytes unmapped +* +* Unmap an IOVA range. The iova/length must be a superset of a previously +* mapped range used with IOMMU_IOAS_MAP or IOMMU_IOAS_COPY. Splitting or +* truncating ranges is not allowed. The values 0 to U64_MAX will unmap +* everything. +*/ +struct iommu_ioas_unmap { +__u32 size; +__u32 ioas_id; +__aligned_u64 iova; +__aligned_u64 length; +}; +#define IOMMU_IOAS_UNMAP _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_UNMAP) + +/** +* enum iommufd_option - ioctl(IOMMU_OPTION_RLIMIT_MODE) and +* ioctl(IOMMU_OPTION_HUGE_PAGES) +* @IOMMU_OPTION_RLIMIT_MODE: +* Change how RLIMIT_MEMLOCK accounting works. The caller must have privilege +* to invoke this. Value 0 (default) is user based accounting, 1 uses process +* based accounting. Global option, object_id must be 0 +* @IOMMU_OPTION_HUGE_PAGES: +* Value 1 (default) allows contiguous pages to be combined when generating +* iommu mappings. Value 0 disables combining, everything is mapped to +* PAGE_SIZE. This can be useful for benchmarking. This is a per-IOAS +* option, the object_id must be the IOAS ID. +*/ +enum iommufd_option { +IOMMU_OPTION_RLIMIT_MODE =0 , +IOMMU_OPTION_HUGE_PAGES =1 , +}; + +/** +* enum iommufd_option_ops - ioctl(IOMMU_OPTION_OP_SET) and +* ioctl(IOMMU_OPTION_OP_GET) +* @IOMMU_OPTION_OP_SET: Set the option's value +* @IOMMU_OPTION_OP_GET: Get the option's value +*/ +enum iommufd_option_ops { +IOMMU_OPTION_OP_SET =0 , +IOMMU_OPTION_OP_GET =1 , +}; + +/** +* struct iommu_option - iommu option multiplexer +* @size: sizeof(struct iommu_option) +* @option_id: One of enum iommufd_option +* @op: One of enum iommufd_option_ops +* @__reserved: Must be 0 +* @object_id: ID of the object if required +* @val64: Option value to set or value returned on get +* +* Change a simple option value. This multiplexor allows controlling options +* on objects. IOMMU_OPTION_OP_SET will load an option and IOMMU_OPTION_OP_GET +* will return the current value. +*/ +struct iommu_option { +__u32 size; +__u32 option_id; +__u16 op; +__u16 __reserved; +__u32 object_id; +__aligned_u64 val64; +}; +#define IOMMU_OPTION _IO(IOMMUFD_TYPE, IOMMUFD_CMD_OPTION) + +/** +* enum iommufd_vfio_ioas_op - IOMMU_VFIO_IOAS_* ioctls +* @IOMMU_VFIO_IOAS_GET: Get the current compatibility IOAS +* @IOMMU_VFIO_IOAS_SET: Change the current compatibility IOAS +* @IOMMU_VFIO_IOAS_CLEAR: Disable VFIO compatibility +*/ +enum iommufd_vfio_ioas_op { +IOMMU_VFIO_IOAS_GET =0 , +IOMMU_VFIO_IOAS_SET =1 , +IOMMU_VFIO_IOAS_CLEAR =2 , +}; + +/** +* struct iommu_vfio_ioas - ioctl(IOMMU_VFIO_IOAS) +* @size: sizeof(struct iommu_vfio_ioas) +* @ioas_id: For IOMMU_VFIO_IOAS_SET the input IOAS ID to set +* For IOMMU_VFIO_IOAS_GET will output the IOAS ID +* @op: One of enum iommufd_vfio_ioas_op +* @__reserved: Must be 0 +* +* The VFIO compatibility support uses a single ioas because VFIO APIs do not +* support the ID field. Set or Get the IOAS that VFIO compatibility will use. +* When VFIO_GROUP_SET_CONTAINER is used on an iommufd it will get the +* compatibility ioas, either by taking what is already set, or auto creating +* one. From then on VFIO will continue to use that ioas and is not effected by +* this ioctl. SET or CLEAR does not destroy any auto-created IOAS. +*/ +struct iommu_vfio_ioas { +__u32 size; +__u32 ioas_id; +__u16 op; +__u16 __reserved; +}; +#define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS) + +/** +* enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation +* @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a HWPT that can serve as +* the parent HWPT in a nesting configuration. +* @IOMMU_HWPT_ALLOC_DIRTY_TRACKING: Dirty tracking support for device IOMMU is +* enforced on device attachment +* @IOMMU_HWPT_FAULT_ID_VALID: The fault_id field of hwpt allocation data is +* valid. +* @IOMMU_HWPT_ALLOC_PASID: Requests a domain that can be used with PASID. The +* domain can be attached to any PASID on the device. +* Any domain attached to the non-PASID part of the +* device must also be flagged, otherwise attaching a +* PASID will blocked. +* For the user that wants to attach PASID, ioas is +* not recommended for both the non-PASID part +* and PASID part of the device. +* If IOMMU does not support PASID it will return +* error (-EOPNOTSUPP). +*/ +enum iommufd_hwpt_alloc_flags { +IOMMU_HWPT_ALLOC_NEST_PARENT =1 <<0 , +IOMMU_HWPT_ALLOC_DIRTY_TRACKING =1 <<1 , +IOMMU_HWPT_FAULT_ID_VALID =1 <<2 , +IOMMU_HWPT_ALLOC_PASID =1 <<3 , +}; + +/** +* enum iommu_hwpt_vtd_s1_flags - Intel VT-d stage-1 page table +* entry attributes +* @IOMMU_VTD_S1_SRE: Supervisor request +* @IOMMU_VTD_S1_EAFE: Extended access enable +* @IOMMU_VTD_S1_WPE: Write protect enable +*/ +enum iommu_hwpt_vtd_s1_flags { +IOMMU_VTD_S1_SRE =1 <<0 , +IOMMU_VTD_S1_EAFE =1 <<1 , +IOMMU_VTD_S1_WPE =1 <<2 , +}; + +/** +* struct iommu_hwpt_vtd_s1 - Intel VT-d stage-1 page table +* info (IOMMU_HWPT_DATA_VTD_S1) +* @flags: Combination of enum iommu_hwpt_vtd_s1_flags +* @pgtbl_addr: The base address of the stage-1 page table. +* @addr_width: The address width of the stage-1 page table +* @__reserved: Must be 0 +*/ +struct iommu_hwpt_vtd_s1 { +__aligned_u64 flags; +__aligned_u64 pgtbl_addr; +__u32 addr_width; +__u32 __reserved; +}; + +/** +* struct iommu_hwpt_arm_smmuv3 - ARM SMMUv3 nested STE +* (IOMMU_HWPT_DATA_ARM_SMMUV3) +* +* @ste: The first two double words of the user space Stream Table Entry for +* the translation. Must be little-endian. +* Allowed fields: (Refer to "5.2 Stream Table Entry" in SMMUv3 HW Spec) +* - word-0: V, Cfg, S1Fmt, S1ContextPtr, S1CDMax +* - word-1: EATS, S1DSS, S1CIR, S1COR, S1CSH, S1STALLD +* +* -EIO will be returned if @ste is not legal or contains any non-allowed field. +* Cfg can be used to select a S1, Bypass or Abort configuration. A Bypass +* nested domain will translate the same as the nesting parent. The S1 will +* install a Context Descriptor Table pointing at userspace memory translated +* by the nesting parent. +* +* It's suggested to allocate a vDEVICE object carrying vSID and then re-attach +* the nested domain, as soon as the vSID is available in the VMM level: +* +* - when Cfg=translate, a vDEVICE must be allocated prior to attaching to the +* allocated nested domain, as CD/ATS invalidations and vevents need a vSID. +* - when Cfg=bypass/abort, a vDEVICE is not enforced during the nested domain +* attachment, to support a GBPA case where VM sets CR0.SMMUEN=0. However, if +* VM sets CR0.SMMUEN=1 while missing a vDEVICE object, kernel would fail to +* report events to the VM. E.g. F_TRANSLATION when guest STE.Cfg=abort. +*/ +struct iommu_hwpt_arm_smmuv3 { +__aligned_le64 ste[2 ]; +}; + +/** +* enum iommu_hwpt_data_type - IOMMU HWPT Data Type +* @IOMMU_HWPT_DATA_NONE: no data +* @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table +* @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table +*/ +enum iommu_hwpt_data_type { +IOMMU_HWPT_DATA_NONE =0 , +IOMMU_HWPT_DATA_VTD_S1 =1 , +IOMMU_HWPT_DATA_ARM_SMMUV3 =2 , +}; + +/** +* struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC) +* @size: sizeof(struct iommu_hwpt_alloc) +* @flags: Combination of enum iommufd_hwpt_alloc_flags +* @dev_id: The device to allocate this HWPT for +* @pt_id: The IOAS or HWPT or vIOMMU to connect this HWPT to +* @out_hwpt_id: The ID of the new HWPT +* @__reserved: Must be 0 +* @data_type: One of enum iommu_hwpt_data_type +* @data_len: Length of the type specific data +* @data_uptr: User pointer to the type specific data +* @fault_id: The ID of IOMMUFD_FAULT object. Valid only if flags field of +* IOMMU_HWPT_FAULT_ID_VALID is set. +* @__reserved2: Padding to 64-bit alignment. Must be 0. +* +* Explicitly allocate a hardware page table object. This is the same object +* type that is returned by iommufd_device_attach() and represents the +* underlying iommu driver's iommu_domain kernel object. +* +* A kernel-managed HWPT will be created with the mappings from the given +* IOAS via the @pt_id. The @data_type for this allocation must be set to +* IOMMU_HWPT_DATA_NONE. The HWPT can be allocated as a parent HWPT for a +* nesting configuration by passing IOMMU_HWPT_ALLOC_NEST_PARENT via @flags. +* +* A user-managed nested HWPT will be created from a given vIOMMU (wrapping a +* parent HWPT) or a parent HWPT via @pt_id, in which the parent HWPT must be +* allocated previously via the same ioctl from a given IOAS (@pt_id). In this +* case, the @data_type must be set to a pre-defined type corresponding to an +* I/O page table type supported by the underlying IOMMU hardware. The device +* via @dev_id and the vIOMMU via @pt_id must be associated to the same IOMMU +* instance. +* +* If the @data_type is set to IOMMU_HWPT_DATA_NONE, @data_len and +* @data_uptr should be zero. Otherwise, both @data_len and @data_uptr +* must be given. +*/ +struct iommu_hwpt_alloc { +__u32 size; +__u32 flags; +__u32 dev_id; +__u32 pt_id; +__u32 out_hwpt_id; +__u32 __reserved; +__u32 data_type; +__u32 data_len; +__aligned_u64 data_uptr; +__u32 fault_id; +__u32 __reserved2; +}; +#define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC) + +/** +* enum iommu_hw_info_vtd_flags - Flags for VT-d hw_info +* @IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17: If set, disallow read-only mappings +* on a nested_parent domain. +* https://www.intel.com/content/www/us/en/content-details/772415/content-details.html +*/ +enum iommu_hw_info_vtd_flags { +IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17 =1 <<0 , +}; + +/** +* struct iommu_hw_info_vtd - Intel VT-d hardware information +* +* @flags: Combination of enum iommu_hw_info_vtd_flags +* @__reserved: Must be 0 +* +* @cap_reg: Value of Intel VT-d capability register defined in VT-d spec +* section 11.4.2 Capability Register. +* @ecap_reg: Value of Intel VT-d capability register defined in VT-d spec +* section 11.4.3 Extended Capability Register. +* +* User needs to understand the Intel VT-d specification to decode the +* register value. +*/ +struct iommu_hw_info_vtd { +__u32 flags; +__u32 __reserved; +__aligned_u64 cap_reg; +__aligned_u64 ecap_reg; +}; + +/** +* struct iommu_hw_info_arm_smmuv3 - ARM SMMUv3 hardware information +* (IOMMU_HW_INFO_TYPE_ARM_SMMUV3) +* +* @flags: Must be set to 0 +* @__reserved: Must be 0 +* @idr: Implemented features for ARM SMMU Non-secure programming interface +* @iidr: Information about the implementation and implementer of ARM SMMU, +* and architecture version supported +* @aidr: ARM SMMU architecture version +* +* For the details of @idr, @iidr and @aidr, please refer to the chapters +* from 6.3.1 to 6.3.6 in the SMMUv3 Spec. +* +* This reports the raw HW capability, and not all bits are meaningful to be +* read by userspace. Only the following fields should be used: +* +* idr[0]: ST_LEVEL, TERM_MODEL, STALL_MODEL, TTENDIAN , CD2L, ASID16, TTF +* idr[1]: SIDSIZE, SSIDSIZE +* idr[3]: BBML, RIL +* idr[5]: VAX, GRAN64K, GRAN16K, GRAN4K +* +* - S1P should be assumed to be true if a NESTED HWPT can be created +* - VFIO/iommufd only support platforms with COHACC, it should be assumed to be +* true. +* - ATS is a per-device property. If the VMM describes any devices as ATS +* capable in ACPI/DT it should set the corresponding idr. +* +* This list may expand in future (eg E0PD, AIE, PBHA, D128, DS etc). It is +* important that VMMs do not read bits outside the list to allow for +* compatibility with future kernels. Several features in the SMMUv3 +* architecture are not currently supported by the kernel for nesting: HTTU, +* BTM, MPAM and others. +*/ +struct iommu_hw_info_arm_smmuv3 { +__u32 flags; +__u32 __reserved; +__u32 idr[6 ]; +__u32 iidr; +__u32 aidr; +}; + +/** +* struct iommu_hw_info_tegra241_cmdqv - NVIDIA Tegra241 CMDQV Hardware +* Information (IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV) +* +* @flags: Must be 0 +* @version: Version number for the CMDQ-V HW for PARAM bits[03:00] +* @log2vcmdqs: Log2 of the total number of VCMDQs for PARAM bits[07:04] +* @log2vsids: Log2 of the total number of SID replacements for PARAM bits[15:12] +* @__reserved: Must be 0 +* +* VMM can use these fields directly in its emulated global PARAM register. Note +* that only one Virtual Interface (VINTF) should be exposed to a VM, i.e. PARAM +* bits[11:08] should be set to 0 for log2 of the total number of VINTFs. +*/ +struct iommu_hw_info_tegra241_cmdqv { +__u32 flags; +__u8 version; +__u8 log2vcmdqs; +__u8 log2vsids; +__u8 __reserved; +}; + +/** +* enum iommu_hw_info_type - IOMMU Hardware Info Types +* @IOMMU_HW_INFO_TYPE_NONE: Output by the drivers that do not report hardware +* info +* @IOMMU_HW_INFO_TYPE_DEFAULT: Input to request for a default type +* @IOMMU_HW_INFO_TYPE_INTEL_VTD: Intel VT-d iommu info type +* @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type +* @IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV: NVIDIA Tegra241 CMDQV (extension for ARM +* SMMUv3) info type +*/ +enum iommu_hw_info_type { +IOMMU_HW_INFO_TYPE_NONE =0 , +IOMMU_HW_INFO_TYPE_DEFAULT =0 , +IOMMU_HW_INFO_TYPE_INTEL_VTD =1 , +IOMMU_HW_INFO_TYPE_ARM_SMMUV3 =2 , +IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV =3 , +}; + +/** +* enum iommufd_hw_capabilities +* @IOMMU_HW_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking +* If available, it means the following APIs +* are supported: +* +* IOMMU_HWPT_GET_DIRTY_BITMAP +* IOMMU_HWPT_SET_DIRTY_TRACKING +* +* @IOMMU_HW_CAP_PCI_PASID_EXEC: Execute Permission Supported, user ignores it +* when the struct +* iommu_hw_info::out_max_pasid_log2 is zero. +* @IOMMU_HW_CAP_PCI_PASID_PRIV: Privileged Mode Supported, user ignores it +* when the struct +* iommu_hw_info::out_max_pasid_log2 is zero. +*/ +enum iommufd_hw_capabilities { +IOMMU_HW_CAP_DIRTY_TRACKING =1 <<0 , +IOMMU_HW_CAP_PCI_PASID_EXEC =1 <<1 , +IOMMU_HW_CAP_PCI_PASID_PRIV =1 <<2 , +}; + +/** +* enum iommufd_hw_info_flags - Flags for iommu_hw_info +* @IOMMU_HW_INFO_FLAG_INPUT_TYPE: If set, @in_data_type carries an input type +* for user space to request for a specific info +*/ +enum iommufd_hw_info_flags { +IOMMU_HW_INFO_FLAG_INPUT_TYPE =1 <<0 , +}; + +/** +* struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO) +* @size: sizeof(struct iommu_hw_info) +* @flags: Must be 0 +* @dev_id: The device bound to the iommufd +* @data_len: Input the length of a user buffer in bytes. Output the length of +* data that kernel supports +* @data_uptr: User pointer to a user-space buffer used by the kernel to fill +* the iommu type specific hardware information data +* @in_data_type: This shares the same field with @out_data_type, making it be +* a bidirectional field. When IOMMU_HW_INFO_FLAG_INPUT_TYPE is +* set, an input type carried via this @in_data_type field will +* be valid, requesting for the info data to the given type. If +* IOMMU_HW_INFO_FLAG_INPUT_TYPE is unset, any input value will +* be seen as IOMMU_HW_INFO_TYPE_DEFAULT +* @out_data_type: Output the iommu hardware info type as defined in the enum +* iommu_hw_info_type. +* @out_capabilities: Output the generic iommu capability info type as defined +* in the enum iommu_hw_capabilities. +* @out_max_pasid_log2: Output the width of PASIDs. 0 means no PASID support. +* PCI devices turn to out_capabilities to check if the +* specific capabilities is supported or not. +* @__reserved: Must be 0 +* +* Query an iommu type specific hardware information data from an iommu behind +* a given device that has been bound to iommufd. This hardware info data will +* be used to sync capabilities between the virtual iommu and the physical +* iommu, e.g. a nested translation setup needs to check the hardware info, so +* a guest stage-1 page table can be compatible with the physical iommu. +* +* To capture an iommu type specific hardware information data, @data_uptr and +* its length @data_len must be provided. Trailing bytes will be zeroed if the +* user buffer is larger than the data that kernel has. Otherwise, kernel only +* fills the buffer using the given length in @data_len. If the ioctl succeeds, +* @data_len will be updated to the length that kernel actually supports, +* @out_data_type will be filled to decode the data filled in the buffer +* pointed by @data_uptr. Input @data_len == zero is allowed. +*/ +struct iommu_hw_info { +__u32 size; +__u32 flags; +__u32 dev_id; +__u32 data_len; +__aligned_u64 data_uptr; +union { +__u32 in_data_type; +__u32 out_data_type; + }; +__u8 out_max_pasid_log2; +__u8 __reserved[3 ]; +__aligned_u64 out_capabilities; +}; +#define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO) + +/* +* enum iommufd_hwpt_set_dirty_tracking_flags - Flags for steering dirty +* tracking +* @IOMMU_HWPT_DIRTY_TRACKING_ENABLE: Enable dirty tracking +*/ +enum iommufd_hwpt_set_dirty_tracking_flags { +IOMMU_HWPT_DIRTY_TRACKING_ENABLE =1 , +}; + +/** +* struct iommu_hwpt_set_dirty_tracking - ioctl(IOMMU_HWPT_SET_DIRTY_TRACKING) +* @size: sizeof(struct iommu_hwpt_set_dirty_tracking) +* @flags: Combination of enum iommufd_hwpt_set_dirty_tracking_flags +* @hwpt_id: HW pagetable ID that represents the IOMMU domain +* @__reserved: Must be 0 +* +* Toggle dirty tracking on an HW pagetable. +*/ +struct iommu_hwpt_set_dirty_tracking { +__u32 size; +__u32 flags; +__u32 hwpt_id; +__u32 __reserved; +}; +#define IOMMU_HWPT_SET_DIRTY_TRACKING _IO(IOMMUFD_TYPE, \ + IOMMUFD_CMD_HWPT_SET_DIRTY_TRACKING) + +/** +* enum iommufd_hwpt_get_dirty_bitmap_flags - Flags for getting dirty bits +* @IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR: Just read the PTEs without clearing +* any dirty bits metadata. This flag +* can be passed in the expectation +* where the next operation is an unmap +* of the same IOVA range. +* +*/ +enum iommufd_hwpt_get_dirty_bitmap_flags { +IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR =1 , +}; + +/** +* struct iommu_hwpt_get_dirty_bitmap - ioctl(IOMMU_HWPT_GET_DIRTY_BITMAP) +* @size: sizeof(struct iommu_hwpt_get_dirty_bitmap) +* @hwpt_id: HW pagetable ID that represents the IOMMU domain +* @flags: Combination of enum iommufd_hwpt_get_dirty_bitmap_flags +* @__reserved: Must be 0 +* @iova: base IOVA of the bitmap first bit +* @length: IOVA range size +* @page_size: page size granularity of each bit in the bitmap +* @data: bitmap where to set the dirty bits. The bitmap bits each +* represent a page_size which you deviate from an arbitrary iova. +* +* Checking a given IOVA is dirty: +* +* data[(iova / page_size) / 64] & (1ULL << ((iova / page_size) % 64)) +* +* Walk the IOMMU pagetables for a given IOVA range to return a bitmap +* with the dirty IOVAs. In doing so it will also by default clear any +* dirty bit metadata set in the IOPTE. +*/ +struct iommu_hwpt_get_dirty_bitmap { +__u32 size; +__u32 hwpt_id; +__u32 flags; +__u32 __reserved; +__aligned_u64 iova; +__aligned_u64 length; +__aligned_u64 page_size; +__aligned_u64 data; +}; +#define IOMMU_HWPT_GET_DIRTY_BITMAP _IO(IOMMUFD_TYPE, \ + IOMMUFD_CMD_HWPT_GET_DIRTY_BITMAP) + +/** +* enum iommu_hwpt_invalidate_data_type - IOMMU HWPT Cache Invalidation +* Data Type +* @IOMMU_HWPT_INVALIDATE_DATA_VTD_S1: Invalidation data for VTD_S1 +* @IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3: Invalidation data for ARM SMMUv3 +*/ +enum iommu_hwpt_invalidate_data_type { +IOMMU_HWPT_INVALIDATE_DATA_VTD_S1 =0 , +IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3 =1 , +}; + +/** +* enum iommu_hwpt_vtd_s1_invalidate_flags - Flags for Intel VT-d +* stage-1 cache invalidation +* @IOMMU_VTD_INV_FLAGS_LEAF: Indicates whether the invalidation applies +* to all-levels page structure cache or just +* the leaf PTE cache. +*/ +enum iommu_hwpt_vtd_s1_invalidate_flags { +IOMMU_VTD_INV_FLAGS_LEAF =1 <<0 , +}; + +/** +* struct iommu_hwpt_vtd_s1_invalidate - Intel VT-d cache invalidation +* (IOMMU_HWPT_INVALIDATE_DATA_VTD_S1) +* @addr: The start address of the range to be invalidated. It needs to +* be 4KB aligned. +* @npages: Number of contiguous 4K pages to be invalidated. +* @flags: Combination of enum iommu_hwpt_vtd_s1_invalidate_flags +* @__reserved: Must be 0 +* +* The Intel VT-d specific invalidation data for user-managed stage-1 cache +* invalidation in nested translation. Userspace uses this structure to +* tell the impacted cache scope after modifying the stage-1 page table. +* +* Invalidating all the caches related to the page table by setting @addr +* to be 0 and @npages to be U64_MAX. +* +* The device TLB will be invalidated automatically if ATS is enabled. +*/ +struct iommu_hwpt_vtd_s1_invalidate { +__aligned_u64 addr; +__aligned_u64 npages; +__u32 flags; +__u32 __reserved; +}; + +/** +* struct iommu_viommu_arm_smmuv3_invalidate - ARM SMMUv3 cache invalidation +* (IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3) +* @cmd: 128-bit cache invalidation command that runs in SMMU CMDQ. +* Must be little-endian. +* +* Supported command list only when passing in a vIOMMU via @hwpt_id: +* CMDQ_OP_TLBI_NSNH_ALL +* CMDQ_OP_TLBI_NH_VA +* CMDQ_OP_TLBI_NH_VAA +* CMDQ_OP_TLBI_NH_ALL +* CMDQ_OP_TLBI_NH_ASID +* CMDQ_OP_ATC_INV +* CMDQ_OP_CFGI_CD +* CMDQ_OP_CFGI_CD_ALL +* +* -EIO will be returned if the command is not supported. +*/ +struct iommu_viommu_arm_smmuv3_invalidate { +__aligned_le64 cmd[2 ]; +}; + +/** +* struct iommu_hwpt_invalidate - ioctl(IOMMU_HWPT_INVALIDATE) +* @size: sizeof(struct iommu_hwpt_invalidate) +* @hwpt_id: ID of a nested HWPT or a vIOMMU, for cache invalidation +* @data_uptr: User pointer to an array of driver-specific cache invalidation +* data. +* @data_type: One of enum iommu_hwpt_invalidate_data_type, defining the data +* type of all the entries in the invalidation request array. It +* should be a type supported by the hwpt pointed by @hwpt_id. +* @entry_len: Length (in bytes) of a request entry in the request array +* @entry_num: Input the number of cache invalidation requests in the array. +* Output the number of requests successfully handled by kernel. +* @__reserved: Must be 0. +* +* Invalidate iommu cache for user-managed page table or vIOMMU. Modifications +* on a user-managed page table should be followed by this operation, if a HWPT +* is passed in via @hwpt_id. Other caches, such as device cache or descriptor +* cache can be flushed if a vIOMMU is passed in via the @hwpt_id field. +* +* Each ioctl can support one or more cache invalidation requests in the array +* that has a total size of @entry_len * @entry_num. +* +* An empty invalidation request array by setting @entry_num==0 is allowed, and +* @entry_len and @data_uptr would be ignored in this case. This can be used to +* check if the given @data_type is supported or not by kernel. +*/ +struct iommu_hwpt_invalidate { +__u32 size; +__u32 hwpt_id; +__aligned_u64 data_uptr; +__u32 data_type; +__u32 entry_len; +__u32 entry_num; +__u32 __reserved; +}; +#define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) + +/** +* enum iommu_hwpt_pgfault_flags - flags for struct iommu_hwpt_pgfault +* @IOMMU_PGFAULT_FLAGS_PASID_VALID: The pasid field of the fault data is +* valid. +* @IOMMU_PGFAULT_FLAGS_LAST_PAGE: It's the last fault of a fault group. +*/ +enum iommu_hwpt_pgfault_flags { +IOMMU_PGFAULT_FLAGS_PASID_VALID = (1 <<0 ), +IOMMU_PGFAULT_FLAGS_LAST_PAGE = (1 <<1 ), +}; + +/** +* enum iommu_hwpt_pgfault_perm - perm bits for struct iommu_hwpt_pgfault +* @IOMMU_PGFAULT_PERM_READ: request for read permission +* @IOMMU_PGFAULT_PERM_WRITE: request for write permission +* @IOMMU_PGFAULT_PERM_EXEC: (PCIE 10.4.1) request with a PASID that has the +* Execute Requested bit set in PASID TLP Prefix. +* @IOMMU_PGFAULT_PERM_PRIV: (PCIE 10.4.1) request with a PASID that has the +* Privileged Mode Requested bit set in PASID TLP +* Prefix. +*/ +enum iommu_hwpt_pgfault_perm { +IOMMU_PGFAULT_PERM_READ = (1 <<0 ), +IOMMU_PGFAULT_PERM_WRITE = (1 <<1 ), +IOMMU_PGFAULT_PERM_EXEC = (1 <<2 ), +IOMMU_PGFAULT_PERM_PRIV = (1 <<3 ), +}; + +/** +* struct iommu_hwpt_pgfault - iommu page fault data +* @flags: Combination of enum iommu_hwpt_pgfault_flags +* @dev_id: id of the originated device +* @pasid: Process Address Space ID +* @grpid: Page Request Group Index +* @perm: Combination of enum iommu_hwpt_pgfault_perm +* @__reserved: Must be 0. +* @addr: Fault address +* @length: a hint of how much data the requestor is expecting to fetch. For +* example, if the PRI initiator knows it is going to do a 10MB +* transfer, it could fill in 10MB and the OS could pre-fault in +* 10MB of IOVA. It's default to 0 if there's no such hint. +* @cookie: kernel-managed cookie identifying a group of fault messages. The +* cookie number encoded in the last page fault of the group should +* be echoed back in the response message. +*/ +struct iommu_hwpt_pgfault { +__u32 flags; +__u32 dev_id; +__u32 pasid; +__u32 grpid; +__u32 perm; +__u32 __reserved; +__aligned_u64 addr; +__u32 length; +__u32 cookie; +}; + +/** +* enum iommufd_page_response_code - Return status of fault handlers +* @IOMMUFD_PAGE_RESP_SUCCESS: Fault has been handled and the page tables +* populated, retry the access. This is the +* "Success" defined in PCI 10.4.2.1. +* @IOMMUFD_PAGE_RESP_INVALID: Could not handle this fault, don't retry the +* access. This is the "Invalid Request" in PCI +* 10.4.2.1. +*/ +enum iommufd_page_response_code { +IOMMUFD_PAGE_RESP_SUCCESS =0 , +IOMMUFD_PAGE_RESP_INVALID =1 , +}; + +/** +* struct iommu_hwpt_page_response - IOMMU page fault response +* @cookie: The kernel-managed cookie reported in the fault message. +* @code: One of response code in enum iommufd_page_response_code. +*/ +struct iommu_hwpt_page_response { +__u32 cookie; +__u32 code; +}; + +/** +* struct iommu_fault_alloc - ioctl(IOMMU_FAULT_QUEUE_ALLOC) +* @size: sizeof(struct iommu_fault_alloc) +* @flags: Must be 0 +* @out_fault_id: The ID of the new FAULT +* @out_fault_fd: The fd of the new FAULT +* +* Explicitly allocate a fault handling object. +*/ +struct iommu_fault_alloc { +__u32 size; +__u32 flags; +__u32 out_fault_id; +__u32 out_fault_fd; +}; +#define IOMMU_FAULT_QUEUE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_FAULT_QUEUE_ALLOC) + +/** +* enum iommu_viommu_type - Virtual IOMMU Type +* @IOMMU_VIOMMU_TYPE_DEFAULT: Reserved for future use +* @IOMMU_VIOMMU_TYPE_ARM_SMMUV3: ARM SMMUv3 driver specific type +* @IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV: NVIDIA Tegra241 CMDQV (extension for ARM +* SMMUv3) enabled ARM SMMUv3 type +*/ +enum iommu_viommu_type { +IOMMU_VIOMMU_TYPE_DEFAULT =0 , +IOMMU_VIOMMU_TYPE_ARM_SMMUV3 =1 , +IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV =2 , +}; + +/** +* struct iommu_viommu_tegra241_cmdqv - NVIDIA Tegra241 CMDQV Virtual Interface +* (IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV) +* @out_vintf_mmap_offset: mmap offset argument for VINTF's page0 +* @out_vintf_mmap_length: mmap length argument for VINTF's page0 +* +* Both @out_vintf_mmap_offset and @out_vintf_mmap_length are reported by kernel +* for user space to mmap the VINTF page0 from the host physical address space +* to the guest physical address space so that a guest kernel can directly R/W +* access to the VINTF page0 in order to control its virtual command queues. +*/ +struct iommu_viommu_tegra241_cmdqv { +__aligned_u64 out_vintf_mmap_offset; +__aligned_u64 out_vintf_mmap_length; +}; + +/** +* struct iommu_viommu_alloc - ioctl(IOMMU_VIOMMU_ALLOC) +* @size: sizeof(struct iommu_viommu_alloc) +* @flags: Must be 0 +* @type: Type of the virtual IOMMU. Must be defined in enum iommu_viommu_type +* @dev_id: The device's physical IOMMU will be used to back the virtual IOMMU +* @hwpt_id: ID of a nesting parent HWPT to associate to +* @out_viommu_id: Output virtual IOMMU ID for the allocated object +* @data_len: Length of the type specific data +* @__reserved: Must be 0 +* @data_uptr: User pointer to a driver-specific virtual IOMMU data +* +* Allocate a virtual IOMMU object, representing the underlying physical IOMMU's +* virtualization support that is a security-isolated slice of the real IOMMU HW +* that is unique to a specific VM. Operations global to the IOMMU are connected +* to the vIOMMU, such as: +* - Security namespace for guest owned ID, e.g. guest-controlled cache tags +* - Non-device-affiliated event reporting, e.g. invalidation queue errors +* - Access to a sharable nesting parent pagetable across physical IOMMUs +* - Virtualization of various platforms IDs, e.g. RIDs and others +* - Delivery of paravirtualized invalidation +* - Direct assigned invalidation queues +* - Direct assigned interrupts +*/ +struct iommu_viommu_alloc { +__u32 size; +__u32 flags; +__u32 type; +__u32 dev_id; +__u32 hwpt_id; +__u32 out_viommu_id; +__u32 data_len; +__u32 __reserved; +__aligned_u64 data_uptr; +}; +#define IOMMU_VIOMMU_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_ALLOC) + +/** +* struct iommu_vdevice_alloc - ioctl(IOMMU_VDEVICE_ALLOC) +* @size: sizeof(struct iommu_vdevice_alloc) +* @viommu_id: vIOMMU ID to associate with the virtual device +* @dev_id: The physical device to allocate a virtual instance on the vIOMMU +* @out_vdevice_id: Object handle for the vDevice. Pass to IOMMU_DESTORY +* @virt_id: Virtual device ID per vIOMMU, e.g. vSID of ARM SMMUv3, vDeviceID +* of AMD IOMMU, and vRID of Intel VT-d +* +* Allocate a virtual device instance (for a physical device) against a vIOMMU. +* This instance holds the device's information (related to its vIOMMU) in a VM. +* User should use IOMMU_DESTROY to destroy the virtual device before +* destroying the physical device (by closing vfio_cdev fd). Otherwise the +* virtual device would be forcibly destroyed on physical device destruction, +* its vdevice_id would be permanently leaked (unremovable & unreusable) until +* iommu fd closed. +*/ +struct iommu_vdevice_alloc { +__u32 size; +__u32 viommu_id; +__u32 dev_id; +__u32 out_vdevice_id; +__aligned_u64 virt_id; +}; +#define IOMMU_VDEVICE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VDEVICE_ALLOC) + +/** +* struct iommu_ioas_change_process - ioctl(VFIO_IOAS_CHANGE_PROCESS) +* @size: sizeof(struct iommu_ioas_change_process) +* @__reserved: Must be 0 +* +* This transfers pinned memory counts for every memory map in every IOAS +* in the context to the current process. This only supports maps created +* with IOMMU_IOAS_MAP_FILE, and returns EINVAL if other maps are present. +* If the ioctl returns a failure status, then nothing is changed. +* +* This API is useful for transferring operation of a device from one process +* to another, such as during userland live update. +*/ +struct iommu_ioas_change_process { +__u32 size; +__u32 __reserved; +}; + +#define IOMMU_IOAS_CHANGE_PROCESS \ + _IO(IOMMUFD_TYPE, IOMMUFD_CMD_IOAS_CHANGE_PROCESS) + +/** +* enum iommu_veventq_flag - flag for struct iommufd_vevent_header +* @IOMMU_VEVENTQ_FLAG_LOST_EVENTS: vEVENTQ has lost vEVENTs +*/ +enum iommu_veventq_flag { +IOMMU_VEVENTQ_FLAG_LOST_EVENTS = (1U <<0 ), +}; + +/** +* struct iommufd_vevent_header - Virtual Event Header for a vEVENTQ Status +* @flags: Combination of enum iommu_veventq_flag +* @sequence: The sequence index of a vEVENT in the vEVENTQ, with a range of +* [0, INT_MAX] where the following index of INT_MAX is 0 +* +* Each iommufd_vevent_header reports a sequence index of the following vEVENT: +* +* +----------------------+-------+----------------------+-------+---+-------+ +* | header0 {sequence=0} | data0 | header1 {sequence=1} | data1 |...| dataN | +* +----------------------+-------+----------------------+-------+---+-------+ +* +* And this sequence index is expected to be monotonic to the sequence index of +* the previous vEVENT. If two adjacent sequence indexes has a delta larger than +* 1, it means that delta - 1 number of vEVENTs has lost, e.g. two lost vEVENTs: +* +* +-----+----------------------+-------+----------------------+-------+-----+ +* | ... | header3 {sequence=3} | data3 | header6 {sequence=6} | data6 | ... | +* +-----+----------------------+-------+----------------------+-------+-----+ +* +* If a vEVENT lost at the tail of the vEVENTQ and there is no following vEVENT +* providing the next sequence index, an IOMMU_VEVENTQ_FLAG_LOST_EVENTS header +* would be added to the tail, and no data would follow this header: +* +* +--+----------------------+-------+-----------------------------------------+ +* |..| header3 {sequence=3} | data3 | header4 {flags=LOST_EVENTS, sequence=4} | +* +--+----------------------+-------+-----------------------------------------+ +*/ +struct iommufd_vevent_header { +__u32 flags; +__u32 sequence; +}; + +/** +* enum iommu_veventq_type - Virtual Event Queue Type +* @IOMMU_VEVENTQ_TYPE_DEFAULT: Reserved for future use +* @IOMMU_VEVENTQ_TYPE_ARM_SMMUV3: ARM SMMUv3 Virtual Event Queue +* @IOMMU_VEVENTQ_TYPE_TEGRA241_CMDQV: NVIDIA Tegra241 CMDQV Extension IRQ +*/ +enum iommu_veventq_type { +IOMMU_VEVENTQ_TYPE_DEFAULT =0 , +IOMMU_VEVENTQ_TYPE_ARM_SMMUV3 =1 , +IOMMU_VEVENTQ_TYPE_TEGRA241_CMDQV =2 , +}; + +/** +* struct iommu_vevent_arm_smmuv3 - ARM SMMUv3 Virtual Event +* (IOMMU_VEVENTQ_TYPE_ARM_SMMUV3) +* @evt: 256-bit ARM SMMUv3 Event record, little-endian. +* Reported event records: (Refer to "7.3 Event records" in SMMUv3 HW Spec) +* - 0x04 C_BAD_STE +* - 0x06 F_STREAM_DISABLED +* - 0x08 C_BAD_SUBSTREAMID +* - 0x0a C_BAD_CD +* - 0x10 F_TRANSLATION +* - 0x11 F_ADDR_SIZE +* - 0x12 F_ACCESS +* - 0x13 F_PERMISSION +* +* StreamID field reports a virtual device ID. To receive a virtual event for a +* device, a vDEVICE must be allocated via IOMMU_VDEVICE_ALLOC. +*/ +struct iommu_vevent_arm_smmuv3 { +__aligned_le64 evt[4 ]; +}; + +/** +* struct iommu_vevent_tegra241_cmdqv - Tegra241 CMDQV IRQ +* (IOMMU_VEVENTQ_TYPE_TEGRA241_CMDQV) +* @lvcmdq_err_map: 128-bit logical vcmdq error map, little-endian. +* (Refer to register LVCMDQ_ERR_MAPs per VINTF ) +* +* The 128-bit register value from HW exclusively reflect the error bits for a +* Virtual Interface represented by a vIOMMU object. Read and report directly. +*/ +struct iommu_vevent_tegra241_cmdqv { +__aligned_le64 lvcmdq_err_map[2 ]; +}; + +/** +* struct iommu_veventq_alloc - ioctl(IOMMU_VEVENTQ_ALLOC) +* @size: sizeof(struct iommu_veventq_alloc) +* @flags: Must be 0 +* @viommu_id: virtual IOMMU ID to associate the vEVENTQ with +* @type: Type of the vEVENTQ. Must be defined in enum iommu_veventq_type +* @veventq_depth: Maximum number of events in the vEVENTQ +* @out_veventq_id: The ID of the new vEVENTQ +* @out_veventq_fd: The fd of the new vEVENTQ. User space must close the +* successfully returned fd after using it +* @__reserved: Must be 0 +* +* Explicitly allocate a virtual event queue interface for a vIOMMU. A vIOMMU +* can have multiple FDs for different types, but is confined to one per @type. +* User space should open the @out_veventq_fd to read vEVENTs out of a vEVENTQ, +* if there are vEVENTs available. A vEVENTQ will lose events due to overflow, +* if the number of the vEVENTs hits @veventq_depth. +* +* Each vEVENT in a vEVENTQ encloses a struct iommufd_vevent_header followed by +* a type-specific data structure, in a normal case: +* +* +-+---------+-------+---------+-------+-----+---------+-------+-+ +* | | header0 | data0 | header1 | data1 | ... | headerN | dataN | | +* +-+---------+-------+---------+-------+-----+---------+-------+-+ +* +* unless a tailing IOMMU_VEVENTQ_FLAG_LOST_EVENTS header is logged (refer to +* struct iommufd_vevent_header). +*/ +struct iommu_veventq_alloc { +__u32 size; +__u32 flags; +__u32 viommu_id; +__u32 type; +__u32 veventq_depth; +__u32 out_veventq_id; +__u32 out_veventq_fd; +__u32 __reserved; +}; +#define IOMMU_VEVENTQ_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VEVENTQ_ALLOC) + +/** +* enum iommu_hw_queue_type - HW Queue Type +* @IOMMU_HW_QUEUE_TYPE_DEFAULT: Reserved for future use +* @IOMMU_HW_QUEUE_TYPE_TEGRA241_CMDQV: NVIDIA Tegra241 CMDQV (extension for ARM +* SMMUv3) Virtual Command Queue (VCMDQ) +*/ +enum iommu_hw_queue_type { +IOMMU_HW_QUEUE_TYPE_DEFAULT =0 , +/* +* TEGRA241_CMDQV requirements (otherwise, allocation will fail) +* - alloc starts from the lowest @index=0 in ascending order +* - destroy starts from the last allocated @index in descending order +* - @base_addr must be aligned to @length in bytes and mapped in IOAS +* - @length must be a power of 2, with a minimum 32 bytes and a maximum +* 2 ^ idr[1].CMDQS * 16 bytes (use GET_HW_INFO call to read idr[1] +* from struct iommu_hw_info_arm_smmuv3) +* - suggest to back the queue memory with contiguous physical pages or +* a single huge page with alignment of the queue size, and limit the +* emulated vSMMU's IDR1.CMDQS to log2(huge page size / 16 bytes) +*/ +IOMMU_HW_QUEUE_TYPE_TEGRA241_CMDQV =1 , +}; + +/** +* struct iommu_hw_queue_alloc - ioctl(IOMMU_HW_QUEUE_ALLOC) +* @size: sizeof(struct iommu_hw_queue_alloc) +* @flags: Must be 0 +* @viommu_id: Virtual IOMMU ID to associate the HW queue with +* @type: One of enum iommu_hw_queue_type +* @index: The logical index to the HW queue per virtual IOMMU for a multi-queue +* model +* @out_hw_queue_id: The ID of the new HW queue +* @nesting_parent_iova: Base address of the queue memory in the guest physical +* address space +* @length: Length of the queue memory +* +* Allocate a HW queue object for a vIOMMU-specific HW-accelerated queue, which +* allows HW to access a guest queue memory described using @nesting_parent_iova +* and @length. +* +* A vIOMMU can allocate multiple queues, but it must use a different @index per +* type to separate each allocation, e.g:: +* +* Type1 HW queue0, Type1 HW queue1, Type2 HW queue0, ... +*/ +struct iommu_hw_queue_alloc { +__u32 size; +__u32 flags; +__u32 viommu_id; +__u32 type; +__u32 index; +__u32 out_hw_queue_id; +__aligned_u64 nesting_parent_iova; +__aligned_u64 length; +}; +#define IOMMU_HW_QUEUE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HW_QUEUE_ALLOC) +#endif
Signature · 1 line
2.54.0
PATCH v19 26/26 vfio: introduce cdev mode
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Add support for VFIO cdev (also known as IOMMUFD) API. The group API is now considered legacy in the kernel, and all further development is expected to happen in IOMMUFD infrastructure.
The implementation largely follows the kernel reference code, with most differences from group mode concentrated in how the container and the devices are set up. The VFIO container allocates an "IOAS" (IO address space), maps the memory into that space, and attaches devices to IOAS - there is no IOMMU type discovery at device attach time.
Unlike group mode, the cdev mode is device-centric, and all DMA mappings are made for an IOAS and not into VFIO container itself. As a result, while group mode only maps memory during first device attach, cdev mode can map memory without having any devices attached. However, current VFIO init has moved to before bus scan, because we need VFIO mode information for buses to decide on IOVA mode. DMA memory mapping, however, must be performed after the DPDK memory was already initialized, so we add another internal API to trigger VFIO DMA maps for cdev mode right after memory init.
To assist any future use of VFIO cdev mode for custom behavior, also introduce "get device number" API, which is kind-of-but-not-really similar to the concept of IOMMU group.
--- doc/guides/linux_gsg/linux_drivers.rst | 30 ++ doc/guides/rel_notes/release_26_11.rst | 5 + drivers/bus/fslmc/fslmc_bus.c | 7 + lib/eal/linux/eal.c | 7 + lib/eal/linux/eal_vfio.c | 285 ++++++++++++++++- lib/eal/linux/eal_vfio.h | 38 ++- lib/eal/linux/eal_vfio_cdev.c | 415 +++++++++++++++++++++++++ lib/eal/linux/eal_vfio_mp_sync.c | 42 +++ lib/eal/linux/include/dev_vfio.h | 39 +++ lib/eal/linux/meson.build | 1 + 10 files changed, 855 insertions(+), 14 deletions(-) create mode 100644 lib/eal/linux/eal_vfio_cdev.c
doc/guides/linux_gsg/linux_drivers.rst +30 -0
@@ -133,6 +133,31 @@ For proper operation of VFIO when running DPDK applications as a non-privileged For more information, please refer to :ref:`linux_gsg_running_without_root_privileges`. +.. _linux_gsg_vfio_modes: + +VFIO group and cdev modes +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The Linux kernel provides two different interfaces for VFIO: + +group mode + The original interface, based on IOMMU groups. + It is accessed through the container device ``/dev/vfio/vfio`` and the per-group devices under ``/dev/vfio/``. + +cdev mode + The newer interface, based on iommufd. + It is accessed through ``/dev/iommu`` and the per-device character devices under ``/dev/vfio/devices/``. + +DPDK selects the mode automatically; there is no EAL option to force a particular mode. +Currently, group mode is preferred and is used whenever the container device ``/dev/vfio/vfio`` is usable. +Using cdev mode requires ``/dev/iommu`` to be present and accessible. + +.. note:: + + Using VF tokens in cdev mode requires Linux kernel version 6.17 or later. + On older kernels the device is bound without the token, so the kernel should be configured to use group mode if VF token support is required. + + .. _linux_gsg_vfio_noiommu: VFIO no-IOMMU mode
@@ -265,6 +290,11 @@ The token will be used for all PF and VF ports within the application. Linux versions earlier than version 5.7 do not support the creation of virtual functions within the VFIO framework. +.. note:: + + When VFIO uses cdev mode, VF tokens require a newer kernel. + See :ref:`linux_gsg_vfio_modes` for details. + Troubleshooting VFIO ~~~~~~~~~~~~~~~~~~~~
doc/guides/rel_notes/release_26_11.rst +5 -0
@@ -64,6 +64,11 @@ New Features Added ``rte_vlan_insert_tpid()`` to the net library. +* **Added VFIO cdev (IOMMUFD) mode.** + + Added support for the VFIO character device (cdev) API, also known as IOMMUFD. + DPDK now supports both the group mode and the new cdev mode. + * **Updated AF_XDP driver.** * Changed the default device plugin endpoint path used when
drivers/bus/fslmc/fslmc_bus.c +7 -0
@@ -332,6 +332,13 @@ rte_fslmc_scan(void) goto scan_fail; } +/* for container groups to work, VFIO must be in group mode */ +if (dev_vfio_get_mode () !=DEV_VFIO_MODE_GROUP ) { +DPAA2_BUS_DEBUG ("DPAA2: VFIO not in group mode" ); + ret = -EINVAL ; + goto scan_fail; + } + ret =fslmc_get_container_group (group_name, &groupid);if (ret !=0 ) goto scan_fail;
lib/eal/linux/eal.c +7 -0
@@ -816,6 +816,13 @@ rte_eal_init(int argc, char **argv) goto err_out; } +/* VFIO memory setup that requires DPDK memory to be available. */ +if (dev_vfio_init_mem () <0 ) { +rte_eal_init_alert ("Cannot init VFIO memory" ); + rte_errno =EAGAIN ; + goto err_out; + } +/* register multi-process action callbacks for hotplug after memory init */ if (eal_mp_dev_hotplug_init () <0 ) {rte_eal_init_alert ("failed to register mp callback for hotplug" );
lib/eal/linux/eal_vfio.c +275 -10
379 lines not on this page · raw message
lib/eal/linux/eal_vfio.h +34 -4
@@ -50,9 +50,16 @@ struct vfio_device {bool active;enum dev_vfio_mode mode;int fd; -int group;/**< back-reference to group list */ -char *sysfs_base;/**< sysfs path prefix */ -char *dev_addr;/**< device address */ +union { +struct { +int dev_num;/**< device number, e.g., X in /dev/vfio/devices/vfioX */ + }; +struct { +int group;/**< back-reference to group list */ +char *sysfs_base;/**< sysfs path prefix */ +char *dev_addr;/**< device address */ + }; + }; };/* group mode specific configuration */
@@ -63,13 +70,21 @@ struct vfio_group_config {struct vfio_group groups[RTE_MAX_VFIO_GROUPS ]; }; +/* cdev mode specific configuration */ +struct vfio_cdev_config { +uint32_t ioas_id; +}; +/* per-container configuration */ struct vfio_container {bool active;bool dma_setup_done;int container_fd;struct vfio_user_mem_maps mem_maps; -struct vfio_group_config group_cfg; +union { +struct vfio_group_config group_cfg; +struct vfio_cdev_config cdev_cfg; + };int n_devices;struct vfio_device devices[RTE_MAX_VFIO_DEVICES ]; };
@@ -145,12 +160,25 @@ int vfio_group_setup_iommu(struct vfio_container *cfg);int vfio_group_setup_device_fd (const char *dev_addr,struct vfio_group *grp,struct vfio_device *dev); +/* cdev mode functions */ +int vfio_cdev_enable (struct vfio_container *cfg); +void vfio_cdev_setup_ops (void ); +int vfio_cdev_setup_ioas (struct vfio_container *cfg); +int vfio_cdev_sync_ioas (struct vfio_container *cfg); +int vfio_cdev_get_iommufd (void ); +int vfio_cdev_get_device_num (const char *sysfs_base,const char *dev_addr, +int *cdev_dev_num); +struct vfio_device *vfio_cdev_get_dev_by_num (struct vfio_container *cfg,int cdev_dev_num); +int vfio_cdev_setup_device (struct vfio_container *cfg,struct vfio_device *dev); +#define EAL_VFIO_MP "eal_vfio_mp_sync"#define VFIO_SOCKET_REQ_CONTAINER 0x100#define VFIO_SOCKET_REQ_GROUP 0x200#define VFIO_SOCKET_REQ_IOMMU_TYPE 0x400#define VFIO_SOCKET_REQ_IOVA_MODE 0x800 +#define VFIO_SOCKET_REQ_CDEV 0x1000 +#define VFIO_SOCKET_REQ_IOAS_ID 0x2000#define VFIO_SOCKET_OK 0x0#define VFIO_SOCKET_NO_FD 0x1#define VFIO_SOCKET_ERR 0xFF
@@ -161,6 +189,8 @@ struct vfio_mp_param {union {int group_num;int iommu_type_id; +int cdev_dev_num; +int ioas_id;enum dev_vfio_mode mode;enum dev_vfio_iova_mode iova_mode; };
lib/eal/linux/eal_vfio_cdev.c new file +415 -0
415 lines not on this page · raw message
lib/eal/linux/eal_vfio_mp_sync.c +42 -0
48 lines not on this page · raw message
lib/eal/linux/include/dev_vfio.h +39 -0
@@ -51,10 +51,12 @@ enum dev_vfio_module {* * - DEV_VFIO_MODE_NONE: VFIO is not enabled. * - DEV_VFIO_MODE_GROUP: Legacy group mode. +* - DEV_VFIO_MODE_CDEV: Character device mode. */ enum dev_vfio_mode {DEV_VFIO_MODE_NONE =0 ,/**< VFIO not enabled */ DEV_VFIO_MODE_GROUP ,/**< Group mode */ +DEV_VFIO_MODE_CDEV ,/**< Cdev mode */ };/**
@@ -157,6 +159,18 @@ int dev_vfio_enable(void);__rte_internal void dev_vfio_cleanup(void); +/** +* @internal +* Initialize VFIO memory mapping. Must be called after `dev_vfio_enable()` and +* after EAL memory initialization has completed. +* +* @return +* 0 on success. +* <0 on failure. +*/ +__rte_internal +int dev_vfio_init_mem(void); +/** * @internal * Check whether a VFIO module is loaded.
@@ -228,6 +242,31 @@ __rte_internalint dev_vfio_get_group_num (const char *sysfs_base,const char *dev_addr,int *iommu_group_num); +/** +* @internal +* Parse VFIO cdev device number for a device. +* +* @param sysfs_base +* Sysfs path prefix. +* @param dev_addr +* Device identifier. +* @param vfio_device_num +* Pointer to where VFIO cdev device number will be stored. +* +* @return +* 0 on success. +* <0 on failure, rte_errno is set. +* +* Possible rte_errno values include: +* - ENODEV - Device not managed by VFIO. +* - EINVAL - Invalid parameters. +* - ENXIO - VFIO support not initialized. +* - ENOTSUP - Unsupported VFIO mode. +*/ +__rte_internal +int +dev_vfio_get_device_num (const char *sysfs_base,const char *dev_addr,int *vfio_device_num); +/** * @internal * Get device information.
lib/eal/linux/meson.build +1 -0
@@ -16,6 +16,7 @@ sources += files( 'eal_thread.c', 'eal_timer.c', 'eal_vfio.c', + 'eal_vfio_cdev.c', 'eal_vfio_group.c', 'eal_vfio_mp_sync.c', )
Signature · 1 line
2.54.0
Quoted 8 lines · David Marchand
v19:
TL;DR: the v18/v19 diff shows no major changes, more could have been done probably (especially on the huge API revamp patch), but rc1 is coming... Compilation per patch still works, hopefully my splitting broke nothing at runtime.
- Rebased so that CI can run on the series (did not happen with v18)
Forgot to check main branch a last time...
I'll resend soon.
Signature · 1 line
David Marchand
v19 cover Support VFIO cdev API in DPDK
In reply to a message not in the archiveThis patchset introduces a major refactor of the VFIO subsystem in DPDK to support character device (cdev) interface introduced in Linux kernel, as well as make the API more streamlined and useful. The goal is to simplify device management, improve compatibility, make the code readable, and clarify API.
The following sections outline the key issues addressed by this patchset and the corresponding changes introduced.
1. Only group mode is supported
===============================
Since kernel version 4.14.327 (LTS), VFIO supports the new character device (cdev)-based way of working with VFIO devices (otherwise known as IOMMUFD). This is a device-centric mode and does away with all the complexity regarding groups and IOMMU types, delegating it all to the kernel, and exposes a much simpler interface to userspace. The old group-based implementation will still be around, and will need to be kept in DPDK for compatibility reasons.
To enable this, VFIO is heavily refactored, so that the code can support both modes while relying on (mostly) common infrastructure.
Additionally, new vfio_get_mode API is added for those cases that need some introspection into VFIO's internals, with two modes: group (old-style), and cdev (the new mode).
Historically, no-IOMMU mode was technically a variant of group mode, the distinction is largely irrelevant to the user, as all usages of noiommu checks in our codebase are for deciding whether to use IOVA or PA, not anything to do with managing groups. However, now that upcoming kernel versions will support no-IOMMU for both group, cdev compatibility, and full cdev paths, a new vfio_get_iommu_mode is also added, with two modes: safe (full IOMMU backing), and unsafe (no-IOMMU mode). The naming is chosen explicitly to emphasize that using no-IOMMU mode is not ideal.
2. Custom container assignment API does not map to cdev mode
============================================================
The existing rte_vfio_device_setup/release model is fundamentally incompatible with cdev mode, because for custom container cases, the expected flow is that the user binds the IOMMU group (and thus, implicitly, the device itself) to a specific container using rte_vfio_container_group_bind, whereas this step is not needed for cdev as the device fd is assigned to the container straight away.
Therefore, what we do instead is introduce a new API for container device assignment which, semantically, will assign a device to specified container, so that when it is mapped using rte_pci_map_device, the appropriate container is selected. Under the hood though, we essentially transition to getting device fd straight away at assign stage, so that by the time the PCI bus attempts to map the device, it is already mapped and we just return an fd. There is no "unassign" API because release_device already performs that function.
Because the API is now unified around device assignment, the old group-specific API's can be removed and, where appropriate, reimplemented using new API. There were other users of VFIO which relied on group API but only for convenience purposes; no actual VFIO functionality depended on those API's.
List of removed API's:
* rte_vfio_get_group_fd
* rte_vfio_clear_group
* rte_vfio_container_group_bind (replaced by container assign API)
* rte_vfio_container_group_unbind
* rte_vfio_noiommu_is_enabled (replaced by new mode API)
3. The API responsibilities aren't clear and bleed into each other
==================================================================
Some API's do multiple things at once. In particular:
* rte_vfio_get_device_info will setup the device
* rte_vfio_setup_device will get device info
These API's have been adjusted to do one thing only.
4. The API does not need to be public
=====================================
The initial idea for exposing VFIO API was to enable userspace applications to directly map memory for DMA, but it turns out that in practice only drivers use this API. Therefore, the entire VFIO API is made internal, driver-only, and is renamed from rte_vfio to dev_vfio.
v19:
TL;DR: the v18/v19 diff shows no major changes, more could have been done probably (especially on the huge API revamp patch), but rc1 is coming... Compilation per patch still works, hopefully my splitting broke nothing at runtime.
- Rebased so that CI can run on the series (did not happen with v18)
- Reordered patches:
- moved the uAPI update at the end of the series when needed
- moved small cleanups earlier in the series (vhost DMA capability cleanup, bus updates like PCI or fslmc...)
- Replaced bus/pci update with the change I prepared when replying on v18:
the most notable change is that the pci bus object is left in common code
- Fixed (well, removed) VFIO header from FreeBSD and Windows exports list and removed all mentions of "Linux only" in this same header since it is now only exported by Linux
(iow lib/eal/include/dev_vfio.h -> lib/eal/linux/include/dev_vfio.h)
- Squashed the patches touching kernel module: those are mechanical and the diff is small. Also fixed one small string truncation issue reported by AI
- Squashed the two patches around making VFIO internal only: the diff is huge, but the changes are mechanical and I saw no interest in keeping them separate
- Dropped rte_errno updates in patches that did not document the change in eal_vfio.h/dev_vfio.h (such updates were dropped later in the series anyway)
- Split the too big "vfio: cleanup and refactor" patch
- Mechanical changes have been isolated in first patches: like renaming or reorganising structures
- Macros only used in one location were removed from headers
- vfio_containers is not exposed out of eal_vfio.c anymore
- Fixed uapi/linux/vfio.h inclusion (must be included *first*, important because of stddef dependencies)
- Fixed coding style like indentation, or line wrapping for 80 columns(?) or log messages split over multiple lines
v18:
- Adjusted pre-refactor VFIO cleanup to not rely on per-config enabled flag
- Moved loaded module detection from EAL into VFIO
- Added API to check for specific VFIO modules being loaded
- Removed VFIO stubs from non-Linux code by removing PCI bus dependency on VFIO
- Reworked vhost DMA capability check
- Renamed "IOMMU mode" and "safe/unsafe" terminology to IOVA VA/PA
- Fixed typo in FSLMC bus IOVA mode selection
v17:
- Support multiple devices per group in NBL
v16:
- Fixed an unused variable compile error due to typo
- Fixed code for patch 19 being accidentally added into patch 21
- Included the NBL fix[1] in the patchset to enable CI testing
v15:
- Fixed resource leak in group mode deduplication path
- On account of kernel 7.3 supporting no-IOMMU mode in kernel version 7.3, split the "VFIO mode" model into two distinct axis: group/cdev, and IOMMU mode
v14:
- Hardened the transitional patches against attempting to use VFIO without having done initialization
- Fixed a bunch of typos, moved a few hunks around to where they belong, and added a more release note entries
v13:
- Addressed feedback from Stephen's AI review:
- Added strdup-based deduplication for group mode to avoid leaking fd's when container assignment API is used
- Added more documentation about cdev mode to Linux GSG
- Fixed comments and log levels in a couple of places
- Renamed the API from rte_vfio_* to dev_vfio_* on account of it no longer being a publicly visible API
- Moved dev_vfio.h into driver SDK headers
- Decoupled VFIO internals from FSLMC and EAL
- Added proper teardown for VFIO subsystem on cleanup
v12:
- Addressed feedback from Stephen's AI review:
- Add release notes updates to patch 2 and 20
- Fix ENXIO typos
- Added a new init step after memory init to enable DMA mapping for cdev
v11:
- Addressed feedback from Stephen's AI review:
- Use CONTAINER_INITIALIZER for reset
- Set container fd to -1 in CONTAINER_INITIALIZER
- Fixed double close()
- Moved VFIO init to earlier in init sequence to account for bus drivers needing no-IOMMU mode status
- Fixed missing ops set for cdev mode, and missing ops reset
- Fixed fd leak on failed attach in cdev
v10:
- Added a patch that renames confusing error labels
- Fixed compiler warning about unused variable
v9:
- Moved erroneous rte_errno-related comments to later in the patchset
- Moved removal of vDPA group fd API's to their respective patches
- Fixed typo in errno comments (ENXIO vs ENOXIO)
- Fixed corruption of group config in secondary process (v8 AI review)
v8:
- Rebase
- Fixed build errors due to variable shadowing
- Removed duplicate fd check as kernel does not provide a way to distinguish between device fd's
v7:
- Rebase
- Added removal of deprecation notices
- Fixed implicit numeric comparison in patch 12
v6:
- Fixed missing header include in vfio cdev file
v5:
- Added back missing uapi patch
v4:
- Fixed issues with documenting rte_vfio_mode enum
- Separated deprecation notices into a separate patchset
v3:
- Make API removal cleaner
- Fix get_group_num usages to align with new API
- Fix issues with function exports
- Fix issues with setup_device returning old-style values in some cases
v2:
- Make the entire API internal
- More aggressive API pruning, complete removal of group API
- Fixed a bug in group mode where device could not be used
- Better documentation and deprecation notice patches
- Moved doc patches to beginning of patchset
Anatoly Burakov (24):
vhost: check DMA capability only once
bus/fslmc: decouple from EAL VFIO
bus/pci: rename mismatching error labels
vfio: make all functions internal
vfio: add module check API
vfio: teardown internals on VFIO cleanup
vfio: split get device info from setup
vfio: add container device assignment API
net/nbl: do not use VFIO group bind API
net/ntnic: use container device assignment API
vdpa/ifc: use container device assignment API
vdpa/nfp: use container device assignment API
vdpa/sfc: use container device assignment API
vhost: remove group-related API from driver
vfio: remove group-based API
vfio: rename some internal types and macros
vfio: declare global configuration
vfio: separate group-based IOMMU types
vfio: add some check on input parameters
vfio: decouple device setup from bus concerns
vfio: introduce IOVA mode
vfio: introduce VFIO mode
uapi: import IOMMUFD header
vfio: introduce cdev mode
David Marchand (2):
bus/pci: move VFIO concerns in Linux implementation
eal: provide VFIO only for Linux
config/arm/meson.build | 1 + config/meson.build | 1 + doc/api/doxy-api-index.md | 3 +- doc/guides/linux_gsg/linux_drivers.rst | 30 + doc/guides/prog_guide/vhost_lib.rst | 4 - doc/guides/rel_notes/deprecation.rst | 10 - doc/guides/rel_notes/release_26_11.rst | 12 + drivers/bus/cdx/cdx.c | 6 +- drivers/bus/cdx/cdx_vfio.c | 38 +- drivers/bus/fslmc/fslmc_bus.c | 12 +- drivers/bus/fslmc/fslmc_vfio.c | 66 +- drivers/bus/fslmc/meson.build | 1 - drivers/bus/pci/bsd/pci.c | 12 + drivers/bus/pci/linux/pci.c | 39 +- drivers/bus/pci/linux/pci_vfio.c | 84 +- drivers/bus/pci/pci_common.c | 26 +- drivers/bus/pci/private.h | 41 + drivers/bus/pci/windows/pci.c | 12 + drivers/bus/platform/platform.c | 17 +- drivers/crypto/bcmfs/bcmfs_vfio.c | 23 +- drivers/net/hinic3/base/hinic3_hwdev.c | 5 +- drivers/net/nbl/nbl_common/nbl_userdev.c | 73 +- drivers/net/nbl/nbl_common/nbl_userdev.h | 1 + drivers/net/nbl/nbl_include/nbl_include.h | 1 + drivers/net/ntnic/ntnic_ethdev.c | 4 +- drivers/net/ntnic/ntnic_vfio.c | 48 +- drivers/vdpa/ifc/ifcvf_vdpa.c | 54 +- drivers/vdpa/mlx5/mlx5_vdpa.c | 1 - drivers/vdpa/nfp/nfp_vdpa.c | 53 +- drivers/vdpa/sfc/sfc_vdpa.c | 47 +- drivers/vdpa/sfc/sfc_vdpa.h | 2 - drivers/vdpa/sfc/sfc_vdpa_hw.c | 12 +- kernel/linux/uapi/linux/iommufd.h | 1302 ++++++++++ lib/eal/common/eal_private.h | 14 - lib/eal/freebsd/eal.c | 128 - lib/eal/include/meson.build | 1 - lib/eal/include/rte_vfio.h | 338 --- lib/eal/linux/eal.c | 62 +- lib/eal/linux/eal_vfio.c | 2661 +++++++++------------ lib/eal/linux/eal_vfio.h | 164 +- lib/eal/linux/eal_vfio_cdev.c | 415 ++++ lib/eal/linux/eal_vfio_group.c | 923 +++++++ lib/eal/linux/eal_vfio_mp_sync.c | 118 +- lib/eal/linux/include/dev_vfio.h | 451 ++++ lib/eal/linux/include/meson.build | 4 + lib/eal/linux/meson.build | 2 + lib/eal/windows/eal.c | 23 - lib/vhost/socket.c | 5 +- lib/vhost/vdpa_driver.h | 3 - lib/vhost/vhost.h | 1 + lib/vhost/vhost_user.c | 16 +- 51 files changed, 4978 insertions(+), 2392 deletions(-) create mode 100644 kernel/linux/uapi/linux/iommufd.h delete mode 100644 lib/eal/include/rte_vfio.h create mode 100644 lib/eal/linux/eal_vfio_cdev.c create mode 100644 lib/eal/linux/eal_vfio_group.c create mode 100644 lib/eal/linux/include/dev_vfio.h
Signature · 1 line
2.54.0
PATCH RESEND v19 1/26 vhost: check DMA capability only once
From: Anatoly Burakov <[email protected]>
Currently, vhost async copy feature will check if VFIO supports DMA mapping on every attempt to add/remove memory region or set memory table. This is not necessary, so instead check this once at new vhost connection, and store that value for future use.
--- lib/vhost/socket.c | 5 ++++- lib/vhost/vhost.h | 1 + lib/vhost/vhost_user.c | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-)
lib/vhost/socket.c +4 -1
@@ -17,6 +17,7 @@#include <eal_export.h> #include <rte_thread.h> #include <rte_log.h> +#include <rte_vfio.h> #include "fd_man.h" #include "vduse.h"
@@ -242,8 +243,10 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)if (vsocket->async_copy) { dev =get_device (vid); -if (dev) +if (dev !=NULL ) { dev->async_copy =1 ; + dev->dma_map_available =rte_vfio_is_enabled ("vfio" ); + } }VHOST_CONFIG_LOG (vsocket->path,INFO ,"new device, handle is %d" , vid);
lib/vhost/vhost.h +1 -0
@@ -499,6 +499,7 @@ struct __rte_cache_aligned virtio_net {RTE_ATOMIC (int16_t ) broadcast_rarp;uint32_t nr_vring;int async_copy; +bool dma_map_available;int extbuf;int linearbuf;
lib/vhost/vhost_user.c +5 -5
@@ -267,7 +267,7 @@ free_all_mem_regions(struct virtio_net *dev)if (!dev || !dev->mem)return ; -if (dev->async_copy &&rte_vfio_is_enabled ("vfio" )) +if (dev->async_copy && dev->dma_map_available)async_dma_map (dev, false);for (i =0 ; i <VHOST_MEMORY_MAX_NREGIONS ; i++) {
@@ -1571,7 +1571,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, dev->mem->nregions++; } -if (dev->async_copy &&rte_vfio_is_enabled ("vfio" )) +if (dev->async_copy && dev->dma_map_available)async_dma_map (dev, true);if (vhost_user_postcopy_register (dev, main_fd, ctx) <0 )
@@ -1757,7 +1757,7 @@ vhost_user_add_mem_reg(struct virtio_net **pdev, dev->mem->nregions++; -if (dev->async_copy &&rte_vfio_is_enabled ("vfio" )) { +if (dev->async_copy && dev->dma_map_available) {if (async_dma_map_region (dev, reg, true) <0 ) goto free_new_region_no_dma; }
@@ -1798,7 +1798,7 @@ vhost_user_add_mem_reg(struct virtio_net **pdev,return RTE_VHOST_MSG_RESULT_OK ; free_new_region: -if (dev->async_copy &&rte_vfio_is_enabled ("vfio" )) +if (dev->async_copy && dev->dma_map_available)async_dma_map_region (dev, reg, false); free_new_region_no_dma:remove_guest_pages (dev, reg);
@@ -1834,7 +1834,7 @@ vhost_user_rem_mem_reg(struct virtio_net **pdev,if (region->userspace_addr == current_region->guest_user_addr && region->guest_phys_addr == current_region->guest_phys_addr && region->memory_size == current_region->size) { -if (dev->async_copy &&rte_vfio_is_enabled ("vfio" )) +if (dev->async_copy && dev->dma_map_available)async_dma_map_region (dev, current_region, false);if (dev->features & (1ULL <<VIRTIO_F_IOMMU_PLATFORM )) vhost_user_iotlb_cache_remove(dev,
Signature · 1 line
2.54.0
PATCH RESEND v19 2/26 bus/fslmc: decouple from EAL VFIO
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
FSLMC bus has its own VFIO implementation which is completely separate from one in EAL or rte_vfio. Yet, it references a couple of macros and uses a struct definition. Fully decoupling them is not a huge lift, so do that.
--- drivers/bus/fslmc/fslmc_vfio.c | 50 +++++++++++++++++++++------------- drivers/bus/fslmc/meson.build | 1 - 2 files changed, 31 insertions(+), 20 deletions(-)
drivers/bus/fslmc/fslmc_vfio.c +31 -19
@@ -35,7 +35,6 @@#include <dev_driver.h> #include <rte_eal_memconfig.h> #include <rte_vfio.h> -#include <eal_vfio.h> #include "private.h" #include "fslmc_vfio.h"
@@ -73,8 +72,21 @@ struct fslmc_dmaseg_list fslmc_iosegs =static uint64_t fslmc_mem_va2iova =RTE_BAD_IOVA ;static int fslmc_mem_map_num; +#define FSLMC_VFIO_SOCKET_OK 0x0 +#define FSLMC_VFIO_SOCKET_NO_FD 0x1 +#define FSLMC_VFIO_SOCKET_ERR 0xFF + +struct fslmc_vfio_mp_param { +int req; +int result; +union { +int group_num; +int iommu_type_id; + }; +}; +struct fslmc_mem_param { -struct vfio_mp_param mp_param; +struct fslmc_vfio_mp_param mp_param;struct fslmc_dmaseg_list memsegs;struct fslmc_dmaseg_list iosegs;uint64_t mem_va2iova;
@@ -386,7 +398,7 @@ fslmc_vfio_open_group_fd(const char *group_name)struct rte_mp_msg mp_req, *mp_rep;struct rte_mp_reply mp_reply = {0 };struct timespec ts = {.tv_sec =5 , .tv_nsec =0 }; -struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param; +struct fslmc_vfio_mp_param *p = (struct fslmc_vfio_mp_param *)mp_req.param;int iommu_group_num, ret; vfio_group_fd =fslmc_vfio_group_fd_by_name (group_name);
@@ -417,10 +429,10 @@ fslmc_vfio_open_group_fd(const char *group_name)if (rte_mp_request_sync (&mp_req, &mp_reply, &ts) ==0 && mp_reply.nb_received ==1 ) { mp_rep = &mp_reply.msgs[0 ]; - p = (struct vfio_mp_param *)mp_rep->param; -if (p->result ==SOCKET_OK && mp_rep->num_fds ==1 ) + p = (struct fslmc_vfio_mp_param *)mp_rep->param; +if (p->result ==FSLMC_VFIO_SOCKET_OK && mp_rep->num_fds ==1 ) vfio_group_fd = mp_rep->fds[0 ]; -else if (p->result ==SOCKET_NO_FD ) +else if (p->result ==FSLMC_VFIO_SOCKET_NO_FD )DPAA2_BUS_ERR ("Bad VFIO group fd" ); }
@@ -490,7 +502,7 @@ fslmc_vfio_open_container_fd(void)struct rte_mp_msg mp_req, *mp_rep;struct rte_mp_reply mp_reply = {0 };struct timespec ts = {.tv_sec =5 , .tv_nsec =0 }; -struct vfio_mp_param *p = (void *)mp_req.param; +struct fslmc_vfio_mp_param *p = (void *)mp_req.param;if (fslmc_vfio_container_fd () >0 )return fslmc_vfio_container_fd ();
@@ -551,7 +563,7 @@ fslmc_vfio_open_container_fd(void) mp_rep = &mp_reply.msgs[0 ]; p = (void *)mp_rep->param; -if (p->result ==SOCKET_OK && mp_rep->num_fds ==1 ) { +if (p->result ==FSLMC_VFIO_SOCKET_OK && mp_rep->num_fds ==1 ) { vfio_container_fd = mp_rep->fds[0 ];free (mp_reply.msgs); }
@@ -594,8 +606,8 @@ fslmc_vfio_mp_primary(const struct rte_mp_msg *msg,int fd =-1 ;int ret;struct rte_mp_msg reply; -struct vfio_mp_param *r = (void *)reply.param; -const struct vfio_mp_param *m = (const void *)msg->param; +struct fslmc_vfio_mp_param *r = (void *)reply.param; +const struct fslmc_vfio_mp_param *m = (const void *)msg->param;struct fslmc_mem_param *map;if (msg->len_param !=sizeof (*m)) {
@@ -612,13 +624,13 @@ fslmc_vfio_mp_primary(const struct rte_mp_msg *msg, r->group_num = m->group_num; fd =fslmc_vfio_group_fd_by_id (m->group_num);if (fd <0 ) { - r->result =SOCKET_ERR ; + r->result =FSLMC_VFIO_SOCKET_ERR ; }else if (!fd) {/* if group exists but isn't bound to VFIO driver */ - r->result =SOCKET_NO_FD ; + r->result =FSLMC_VFIO_SOCKET_NO_FD ; }else {/* if group exists and is bound to VFIO driver */ - r->result =SOCKET_OK ; + r->result =FSLMC_VFIO_SOCKET_OK ; reply.num_fds =1 ; reply.fds[0 ] = fd; }
@@ -628,9 +640,9 @@ fslmc_vfio_mp_primary(const struct rte_mp_msg *msg, r->req =FSLMC_VFIO_SOCKET_REQ_CONTAINER ; fd =fslmc_vfio_container_fd ();if (fd <=0 ) { - r->result =SOCKET_ERR ; + r->result =FSLMC_VFIO_SOCKET_ERR ; }else { - r->result =SOCKET_OK ; + r->result =FSLMC_VFIO_SOCKET_OK ; reply.num_fds =1 ; reply.fds[0 ] = fd; }
@@ -640,7 +652,7 @@ fslmc_vfio_mp_primary(const struct rte_mp_msg *msg, map = (void *)reply.param; r = &map->mp_param; r->req =FSLMC_VFIO_SOCKET_REQ_MEM ; - r->result =SOCKET_OK ; + r->result =FSLMC_VFIO_SOCKET_OK ; map->memsegs = fslmc_memsegs; map->iosegs = fslmc_iosegs; map->mem_va2iova = fslmc_mem_va2iova;
@@ -666,19 +678,19 @@ fslmc_vfio_mp_sync_mem_req(void)struct rte_mp_reply mp_reply = {0 };struct timespec ts = {.tv_sec =5 , .tv_nsec =0 };int ret =0 ; -struct vfio_mp_param *mp_param; +struct fslmc_vfio_mp_param *mp_param;struct fslmc_mem_param *mem_rsp; mp_param = (void *)mp_req.param;memset (&mp_req,0 ,sizeof (struct rte_mp_msg )); mp_param->req =FSLMC_VFIO_SOCKET_REQ_MEM ;rte_strscpy (mp_req.name,FSLMC_VFIO_MP ,sizeof (mp_req.name)); - mp_req.len_param =sizeof (struct vfio_mp_param ); + mp_req.len_param =sizeof (struct fslmc_vfio_mp_param );if (rte_mp_request_sync (&mp_req, &mp_reply, &ts) ==0 && mp_reply.nb_received ==1 ) { mp_rep = &mp_reply.msgs[0 ]; mem_rsp = (struct fslmc_mem_param *)mp_rep->param; -if (mem_rsp->mp_param.result ==SOCKET_OK ) { +if (mem_rsp->mp_param.result ==FSLMC_VFIO_SOCKET_OK ) { fslmc_memsegs = mem_rsp->memsegs; fslmc_mem_va2iova = mem_rsp->mem_va2iova; fslmc_mem_map_num = mem_rsp->mem_map_num;
drivers/bus/fslmc/meson.build +0 -1
@@ -30,4 +30,3 @@ sources = files( ) includes += include_directories('mc', 'qbman/include', 'portal') -includes += include_directories('../../../lib/eal/linux')
Signature · 1 line
2.54.0
PATCH RESEND v19 3/26 bus/pci: rename mismatching error labels
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Currently, there are two VFIO map functions - primary and secondary - that use a very similar goto error pattern. However, the label names are confusing.
Specifically, for primary, we have three error labels: vfio_res (release VFIO resource), vfio_dev_fd (close the fd), and map (unmap all the mapped regions). For secondary, there is vfio_dev (close the fd), and vfio_dev_fd (unmap all mapped regions).
For consistency, align secondary process function's error labels to match semantics of how they work in primary process function.
--- drivers/bus/pci/linux/pci_vfio.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/bus/pci/linux/pci_vfio.c +7 -7
@@ -968,7 +968,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) ret =pci_vfio_fill_regions (dev, vfio_dev_fd, &device_info);if (ret) - goto err_vfio_dev; + goto err_vfio_dev_fd;/* map BARs */ maps = vfio_res->maps;
@@ -979,14 +979,14 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)if (ret <0 ) {PCI_LOG (ERR ,"%s sparse mapping BAR%i failed: %s" , pci_addr, i,strerror (errno)); - goto err_vfio_dev_fd; + goto err_map; } }else { ret =pci_vfio_mmap_bar (vfio_dev_fd, vfio_res, i,MAP_FIXED );if (ret <0 ) {PCI_LOG (ERR ,"%s mapping BAR%i failed: %s" , pci_addr, i,strerror (errno)); - goto err_vfio_dev_fd; + goto err_map; } }
@@ -995,17 +995,17 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)/* we need save vfio_dev_fd, so it can be used during release */ if (rte_intr_dev_fd_set (dev->intr_handle, vfio_dev_fd)) - goto err_vfio_dev_fd; + goto err_map;if (rte_intr_dev_fd_set (dev->vfio_req_intr_handle, vfio_dev_fd)) - goto err_vfio_dev_fd; + goto err_map;return 0 ; -err_vfio_dev_fd: +err_map:for (j =0 ; j < i; j++) {if (maps[j].addr)pci_unmap_resource (maps[j].addr, maps[j].size); } -err_vfio_dev: +err_vfio_dev_fd:rte_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);return -1 ;
Signature · 1 line
2.54.0
PATCH RESEND v19 4/26 bus/pci: move VFIO concerns in Linux implementation
In reply to David MarchandMake the common PCI code independent of the VFIO API. Move VFIO dma map/unmap operation in Linux only code: adopt the same approach than IOMMU VA support and expose a OS specific handler which calls a common implementation for FreeBSD and Windows.
--- drivers/bus/pci/bsd/pci.c | 12 ++++++++++ drivers/bus/pci/linux/pci.c | 35 ++++++++++++++++++++++++++++++ drivers/bus/pci/pci_common.c | 26 +++++----------------- drivers/bus/pci/private.h | 41 +++++++++++++++++++++++++++++++++++ drivers/bus/pci/windows/pci.c | 12 ++++++++++ 5 files changed, 105 insertions(+), 21 deletions(-)
drivers/bus/pci/bsd/pci.c +12 -0
@@ -397,6 +397,18 @@ rte_pci_scan(void)return -1 ; } +int +pci_device_dma_map (struct rte_device *dev,void *addr,uint64_t iova,size_t len) +{ +return pci_dma_map (dev, addr, iova, len); +} + +int +pci_device_dma_unmap (struct rte_device *dev,void *addr,uint64_t iova,size_t len) +{ +return pci_dma_unmap (dev, addr, iova, len); +} +bool pci_device_iommu_support_va(__rte_unused const struct rte_pci_device *dev) {
drivers/bus/pci/linux/pci.c +35 -0
@@ -5,6 +5,7 @@#include <string.h> #include <dirent.h> +#include <rte_errno.h> #include <rte_log.h> #include <rte_pci.h> #include <rte_bus_pci.h>
@@ -478,6 +479,40 @@ rte_pci_scan(void)return -1 ; } +int +pci_device_dma_map (struct rte_device *dev,void *addr,uint64_t iova,size_t len) +{ +int ret =pci_dma_map (dev, addr, iova, len); + +if (ret ==-1 && rte_errno ==ENOTSUP ) { +struct rte_pci_device *pdev =RTE_BUS_DEVICE (dev, *pdev); + +/* In case driver doesn't provide any specific mapping try fallback to VFIO. */ +if (pdev->kdrv ==RTE_PCI_KDRV_VFIO ) + ret =rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , + (uintptr_t )addr, iova, len); + } + +return ret; +} + +int +pci_device_dma_unmap (struct rte_device *dev,void *addr,uint64_t iova,size_t len) +{ +int ret =pci_dma_unmap (dev, addr, iova, len); + +if (ret ==-1 && rte_errno ==ENOTSUP ) { +struct rte_pci_device *pdev =RTE_BUS_DEVICE (dev, *pdev); + +/* In case driver doesn't provide any specific mapping try fallback to VFIO. */ +if (pdev->kdrv ==RTE_PCI_KDRV_VFIO ) +return rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , + (uintptr_t )addr, iova, len); + } + +return ret; +} +#if defined(RTE_ARCH_X86 )bool pci_device_iommu_support_va (const struct rte_pci_device *dev)
drivers/bus/pci/pci_common.c +5 -21
@@ -25,7 +25,6 @@#include <rte_string_fns.h> #include <rte_common.h> #include <rte_devargs.h> -#include <rte_vfio.h> #include <rte_tailq.h> #include "private.h"
@@ -474,7 +473,7 @@ pci_sigbus_handler(const void *failure_addr)return ret; } -static int +int pci_dma_map (struct rte_device *dev,void *addr,uint64_t iova,size_t len) {struct rte_pci_device *pdev =RTE_BUS_DEVICE (dev, *pdev);
@@ -482,19 +481,12 @@ pci_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)if (pdrv->dma_map !=NULL )return pdrv->dma_map (pdev, addr, iova, len); -/** -* In case driver don't provides any specific mapping -* try fallback to VFIO. -*/ -if (pdev->kdrv ==RTE_PCI_KDRV_VFIO ) -return rte_vfio_container_dma_map - (RTE_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, - iova, len); + rte_errno =ENOTSUP ;return -1 ; } -static int +int pci_dma_unmap (struct rte_device *dev,void *addr,uint64_t iova,size_t len) {struct rte_pci_device *pdev =RTE_BUS_DEVICE (dev, *pdev);
@@ -502,14 +494,6 @@ pci_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)if (pdrv->dma_unmap !=NULL )return pdrv->dma_unmap (pdev, addr, iova, len); -/** -* In case driver don't provides any specific mapping -* try fallback to VFIO. -*/ -if (pdev->kdrv ==RTE_PCI_KDRV_VFIO ) -return rte_vfio_container_dma_unmap - (RTE_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, - iova, len); rte_errno =ENOTSUP ;return -1 ; }
@@ -727,8 +711,8 @@ struct rte_bus rte_pci_bus = { .parse = pci_parse, .dev_compare = pci_dev_compare, .devargs_parse = rte_pci_devargs_parse, - .dma_map = pci_dma_map, - .dma_unmap = pci_dma_unmap, + .dma_map = pci_device_dma_map, + .dma_unmap = pci_device_dma_unmap, .get_iommu_class = rte_pci_get_iommu_class, .dev_iterate = rte_pci_dev_iterate, .hot_unplug_handler = pci_hot_unplug_handler,
drivers/bus/pci/private.h +41 -0
47 lines not on this page · raw message
drivers/bus/pci/windows/pci.c +12 -0
@@ -120,6 +120,18 @@ rte_pci_mmio_write(const struct rte_pci_device *dev, int bar,return len; } +int +pci_device_dma_map (struct rte_device *dev,void *addr,uint64_t iova,size_t len) +{ +return pci_dma_map (dev, addr, iova, len); +} + +int +pci_device_dma_unmap (struct rte_device *dev,void *addr,uint64_t iova,size_t len) +{ +return pci_dma_unmap (dev, addr, iova, len); +} +enum rte_iova_mode pci_device_iova_mode(const struct rte_pci_driver *pdrv __rte_unused, const struct rte_pci_device *pdev __rte_unused)
Signature · 1 line
2.54.0
PATCH RESEND v19 5/26 eal: provide VFIO only for Linux
In reply to David MarchandThe VFIO API is used only in Linux related code.
We can hide this API on other OSes and unexport associated symbols, before the next commit which makes this API entirely internal.
---
lib/eal/freebsd/eal.c | 128 -------------------------
lib/eal/include/meson.build | 1 -
lib/eal/linux/include/meson.build | 1 +
lib/eal/{ => linux}/include/rte_vfio.h | 31 ------
lib/eal/windows/eal.c | 23 -----
5 files changed, 1 insertion(+), 183 deletions(-)
rename lib/eal/{ => linux}/include/rte_vfio.h (88%)lib/eal/freebsd/eal.c +0 -128
@@ -41,7 +41,6 @@#include <rte_dev.h> #include <rte_devargs.h> #include <rte_version.h> -#include <rte_vfio.h> #include <malloc_heap.h> #include <telemetry_internal.h>
@@ -818,130 +817,3 @@ void rte_eal_vfio_get_vf_token(__rte_unused rte_uuid_t vf_token) { } - -RTE_EXPORT_SYMBOL (rte_vfio_setup_device) -int rte_vfio_setup_device(__rte_unused const char *sysfs_base, - __rte_unused const char *dev_addr, - __rte_unused int *vfio_dev_fd, - __rte_unused struct vfio_device_info *device_info) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_release_device) -int rte_vfio_release_device(__rte_unused const char *sysfs_base, - __rte_unused const char *dev_addr, - __rte_unused int fd) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_enable) -int rte_vfio_enable(__rte_unused const char *modname) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_is_enabled) -int rte_vfio_is_enabled(__rte_unused const char *modname) -{ -return 0 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_noiommu_is_enabled) -int rte_vfio_noiommu_is_enabled(void) -{ -return 0 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_clear_group) -int rte_vfio_clear_group(__rte_unused int vfio_group_fd) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_get_group_num) -int -rte_vfio_get_group_num(__rte_unused const char *sysfs_base, - __rte_unused const char *dev_addr, - __rte_unused int *iommu_group_num) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_get_container_fd) -int -rte_vfio_get_container_fd (void ) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_get_group_fd) -int -rte_vfio_get_group_fd(__rte_unused int iommu_group_num) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_container_create) -int -rte_vfio_container_create (void ) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_container_destroy) -int -rte_vfio_container_destroy(__rte_unused int container_fd) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_container_group_bind) -int -rte_vfio_container_group_bind(__rte_unused int container_fd, - __rte_unused int iommu_group_num) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_container_group_unbind) -int -rte_vfio_container_group_unbind(__rte_unused int container_fd, - __rte_unused int iommu_group_num) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_container_dma_map) -int -rte_vfio_container_dma_map(__rte_unused int container_fd, - __rte_unused uint64_t vaddr, - __rte_unused uint64_t iova, - __rte_unused uint64_t len) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_container_dma_unmap) -int -rte_vfio_container_dma_unmap(__rte_unused int container_fd, - __rte_unused uint64_t vaddr, - __rte_unused uint64_t iova, - __rte_unused uint64_t len) -{ - rte_errno =ENOTSUP ; -return -1 ; -}
lib/eal/include/meson.build +0 -1
@@ -55,7 +55,6 @@ headers += files( 'rte_trace_point_register.h', 'rte_uuid.h', 'rte_version.h', - 'rte_vfio.h', ) driver_sdk_headers = files(
lib/eal/linux/include/meson.build +1 -0
@@ -5,4 +5,5 @@ includes += include_directories('.') headers += files( 'rte_os.h', + 'rte_vfio.h', )
lib/eal/linux/include/rte_vfio.h renamed from lib/eal/include/rte_vfio.h +0 -31
@@ -19,8 +19,6 @@extern "C" {#endif -#ifdef RTE_EXEC_ENV_LINUX -#define RTE_VFIO_DIR "/dev/vfio"#define RTE_VFIO_CONTAINER_PATH "/dev/vfio/vfio"#define RTE_VFIO_GROUP_FMT "/dev/vfio/%u"
@@ -28,8 +26,6 @@ extern "C" {#define RTE_VFIO_NOIOMMU_MODE \ "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode" -#endif /* RTE_EXEC_ENV_LINUX */ -/* we don't need an actual definition, only pointer is used */ struct vfio_device_info ;
@@ -40,9 +36,6 @@ struct vfio_device_info;* It discovers the configured I/O MMU groups or sets a new one for the device. * If a new groups is assigned, the DMA mapping is performed. * -* This function is only relevant to linux and will return -* an error on BSD. -* * @param sysfs_base * sysfs path prefix. *
@@ -66,9 +59,6 @@ int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,/** * Release a device mapped to a VFIO-managed I/O MMU group. * -* This function is only relevant to linux and will return -* an error on BSD. -* * @param sysfs_base * sysfs path prefix. *
@@ -87,9 +77,6 @@ int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd/** * Enable a VFIO-related kmod. * -* This function is only relevant to linux and will return -* an error on BSD. -* * @param modname * kernel module name. *
@@ -102,8 +89,6 @@ int rte_vfio_enable(const char *modname);/** * Check whether a VFIO-related kmod is enabled. * -* This function is only relevant to Linux. -* * @param modname * kernel module name. *
@@ -116,8 +101,6 @@ int rte_vfio_is_enabled(const char *modname);/** * Whether VFIO NOIOMMU mode is enabled. * -* This function is only relevant to Linux. -* * @return * 1 if true. * 0 if false.
@@ -128,9 +111,6 @@ int rte_vfio_noiommu_is_enabled(void);/** * Remove group fd from internal VFIO group fd array/ * -* This function is only relevant to linux and will return -* an error on BSD. -* * @param vfio_group_fd * VFIO Group FD. *
@@ -144,9 +124,6 @@ rte_vfio_clear_group(int vfio_group_fd);/** * Parse IOMMU group number for a device * -* This function is only relevant to linux and will return -* an error on BSD. -* * @param sysfs_base * sysfs path prefix. *
@@ -168,8 +145,6 @@ rte_vfio_get_group_num(const char *sysfs_base,/** * Get device information * -* This function is only relevant to Linux and will return an error on BSD. -* * @param sysfs_base * sysfs path prefix. *
@@ -194,9 +169,6 @@ rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr,/** * Get the default VFIO container fd * -* This function is only relevant to linux and will return -* an error on BSD. -* * @return * > 0 default container fd * < 0 if VFIO is not enabled or not supported
@@ -207,9 +179,6 @@ rte_vfio_get_container_fd(void);/** * Open VFIO group fd or get an existing one * -* This function is only relevant to linux and will return -* an error on BSD. -* * @param iommu_group_num * iommu group number *
lib/eal/windows/eal.c +0 -23
@@ -24,7 +24,6 @@#include <eal_options.h> #include <eal_private.h> #include <rte_service_component.h> -#include <rte_vfio.h> #include "eal_firmware.h" #include "eal_hugepages.h"
@@ -453,28 +452,6 @@ eal_asprintf(char **buffer, const char *format, ...)return ret; } -RTE_EXPORT_SYMBOL (rte_vfio_container_dma_map) -int -rte_vfio_container_dma_map(__rte_unused int container_fd, - __rte_unused uint64_t vaddr, - __rte_unused uint64_t iova, - __rte_unused uint64_t len) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - -RTE_EXPORT_SYMBOL (rte_vfio_container_dma_unmap) -int -rte_vfio_container_dma_unmap(__rte_unused int container_fd, - __rte_unused uint64_t vaddr, - __rte_unused uint64_t iova, - __rte_unused uint64_t len) -{ - rte_errno =ENOTSUP ; -return -1 ; -} - RTE_EXPORT_INTERNAL_SYMBOL(rte_firmware_read) int rte_firmware_read(__rte_unused const char *name,
Signature · 1 line
2.54.0
PATCH RESEND v19 6/26 vfio: make all functions internal
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The VFIO API is an externally exported API because the original intent was to offer DMA mapping facilities to applications. However, practical usage of this API seems to be centered around drivers, so keeping this API exported to applications only creates needless API/ABI stability surface that has no added value.
While at it, this API is still named with an rte_ prefix, which implies public API. To reflect the fact that this API is no longer public, rename all symbols and macros from rte_/RTE_ to dev_/DEV_, and adjust all callers.
---
Changes since v18:
- squashed with the prefix rte_vfio_ -> dev_vfio_ change,
---
doc/api/doxy-api-index.md | 3 +-
doc/guides/rel_notes/deprecation.rst | 6 -
doc/guides/rel_notes/release_26_11.rst | 4 +
drivers/bus/cdx/cdx.c | 6 +-
drivers/bus/cdx/cdx_vfio.c | 14 +--
drivers/bus/fslmc/fslmc_bus.c | 4 +-
drivers/bus/fslmc/fslmc_vfio.c | 12 +-
drivers/bus/pci/linux/pci.c | 8 +-
drivers/bus/pci/linux/pci_vfio.c | 38 +++---
drivers/bus/platform/platform.c | 10 +-
drivers/crypto/bcmfs/bcmfs_vfio.c | 8 +-
drivers/net/hinic3/base/hinic3_hwdev.c | 4 +-
drivers/net/nbl/nbl_common/nbl_userdev.c | 16 +--
drivers/net/ntnic/ntnic_ethdev.c | 4 +-
drivers/net/ntnic/ntnic_vfio.c | 22 ++--
drivers/vdpa/ifc/ifcvf_vdpa.c | 24 ++--
drivers/vdpa/nfp/nfp_vdpa.c | 24 ++--
drivers/vdpa/sfc/sfc_vdpa.c | 16 +--
drivers/vdpa/sfc/sfc_vdpa_hw.c | 12 +-
lib/eal/linux/eal.c | 4 +-
lib/eal/linux/eal_vfio.c | 116 +++++++++---------
lib/eal/linux/eal_vfio_mp_sync.c | 6 +-
.../linux/include/{rte_vfio.h => dev_vfio.h} | 104 ++++++++++------
lib/eal/linux/include/meson.build | 5 +-
lib/vhost/socket.c | 4 +-
lib/vhost/vhost_user.c | 6 +-
26 files changed, 256 insertions(+), 224 deletions(-)
rename lib/eal/linux/include/{rte_vfio.h => dev_vfio.h} (68%)doc/api/doxy-api-index.md +1 -2
@@ -37,8 +37,7 @@ The public API headers are grouped by topics: [latency](@ref rte_latencystats.h), [devargs](@ref rte_devargs.h), [PCI](@ref rte_pci.h), - [vdev](@ref rte_bus_vdev.h), - [vfio](@ref rte_vfio.h) + [vdev](@ref rte_bus_vdev.h) - **device specific**: [softnic](@ref rte_eth_softnic.h),
doc/guides/rel_notes/deprecation.rst +0 -6
@@ -29,12 +29,6 @@ Deprecation Notices Use the ``-S <service-corelist>`` parameter instead to specify the cores to be used for background services in DPDK. -* eal: The entire VFIO API (``rte_vfio_*``) will be made internal only, - and will only be available to EAL and drivers. - Group-based API (``rte_vfio_*_group_*``) will be removed - and replaced with unified container device assignment API. - This change will be made in 26.11 release. - * vdpa: The vDPA driver API will no longer offer ``get_vfio_group_fd`` as part of its internal API. All drivers will be adjusted to use the new unified VFIO container device assignment API.
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -240,6 +240,10 @@ API Changes are now declared with an alignment of 1 on all architectures. The compiler may generate narrower loads and stores than before. +* eal: The entire VFIO API (``rte_vfio_*``) was made internal. + These functions are now available only to EAL and drivers, + and are no longer part of the public API. + * ethdev: Updated VMDq related API. * At port configuration time, the number of VMDq pools advertised by a driver
drivers/bus/cdx/cdx.c +3 -3
@@ -73,7 +73,7 @@#include <rte_devargs.h> #include <rte_kvargs.h> #include <rte_malloc.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <eal_export.h> #include <eal_filesystem.h>
@@ -403,7 +403,7 @@ cdx_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len) {RTE_SET_USED (dev); -return rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , +return dev_vfio_container_dma_map (DEV_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, iova, len); }
@@ -412,7 +412,7 @@ cdx_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len) {RTE_SET_USED (dev); -return rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , +return dev_vfio_container_dma_unmap (DEV_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, iova, len); }
drivers/bus/cdx/cdx_vfio.c +7 -7
@@ -23,7 +23,7 @@#include <eal_export.h> #include <rte_eal_paging.h> #include <rte_malloc.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "bus_cdx_driver.h" #include "cdx_logs.h"
@@ -121,7 +121,7 @@ cdx_vfio_unmap_resource_primary(struct rte_cdx_device *dev)if (vfio_dev_fd <0 )return -1 ; - ret =rte_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev->device.name, + ret =dev_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev->device.name, vfio_dev_fd);if (ret <0 ) {CDX_BUS_ERR ("Cannot release VFIO device" );
@@ -155,7 +155,7 @@ cdx_vfio_unmap_resource_secondary(struct rte_cdx_device *dev)if (vfio_dev_fd <0 )return -1 ; - ret =rte_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev->device.name, + ret =dev_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev->device.name, vfio_dev_fd);if (ret <0 ) {CDX_BUS_ERR ("Cannot release VFIO device" );
@@ -407,7 +407,7 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev)if (rte_intr_fd_set (dev->intr_handle,-1 ))return -1 ; - ret =rte_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, + ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, &vfio_dev_fd, &device_info);if (ret)return ret;
@@ -484,7 +484,7 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev)cdx_vfio_find_and_unmap_resource (vfio_res_list, dev);rte_free (vfio_res); err_vfio_dev_fd: -rte_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, vfio_dev_fd); +dev_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, vfio_dev_fd);return -1 ; }
@@ -516,7 +516,7 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev)return -1 ; } - ret =rte_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, + ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, &vfio_dev_fd, &device_info);if (ret)return ret;
@@ -542,7 +542,7 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev)return 0 ; err_vfio_dev_fd: -rte_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, vfio_dev_fd); +dev_vfio_release_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, vfio_dev_fd);return -1 ; }
drivers/bus/fslmc/fslmc_bus.c +2 -2
@@ -17,7 +17,7 @@#include <rte_memcpy.h> #include <ethdev_driver.h> #include <rte_mbuf_dyn.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "private.h" #include <fslmc_vfio.h>
@@ -500,7 +500,7 @@ rte_dpaa2_get_iommu_class(void)return RTE_IOVA_DC ;/* check if all devices on the bus support Virtual addressing or not */ -if (fslmc_all_device_support_iova () !=0 &&rte_vfio_noiommu_is_enabled () ==0 ) +if (fslmc_all_device_support_iova () !=0 &&dev_vfio_noiommu_is_enabled () ==0 )return RTE_IOVA_VA ;return RTE_IOVA_PA ;
drivers/bus/fslmc/fslmc_vfio.c +6 -6
@@ -34,7 +34,7 @@#include <rte_kvargs.h> #include <dev_driver.h> #include <rte_eal_memconfig.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "private.h" #include "fslmc_vfio.h"
@@ -204,7 +204,7 @@ fslmc_vfio_add_group(int vfio_group_fd, group->fd = vfio_group_fd; group->groupid = iommu_group_num;rte_strscpy (group->group_name, group_name,sizeof (group->group_name)); -if (rte_vfio_noiommu_is_enabled () >0 ) +if (dev_vfio_noiommu_is_enabled () >0 ) group->iommu_type =VFIO_NOIOMMU_IOMMU ;else group->iommu_type =VFIO_TYPE1_IOMMU ;
@@ -374,7 +374,7 @@ fslmc_get_group_id(const char *group_name,int ret;/* get group number */ - ret =rte_vfio_get_group_num (SYSFS_FSL_MC_DEVICES , + ret =dev_vfio_get_group_num (SYSFS_FSL_MC_DEVICES , group_name, groupid);if (ret <=0 ) {DPAA2_BUS_ERR ("Find %s IOMMU group" , group_name);
@@ -411,7 +411,7 @@ fslmc_vfio_open_group_fd(const char *group_name)/* if primary, try to open the group */ if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) {/* try regular group format */ -snprintf (filename,sizeof (filename),RTE_VFIO_GROUP_FMT , iommu_group_num); +snprintf (filename,sizeof (filename),DEV_VFIO_GROUP_FMT , iommu_group_num); vfio_group_fd =open (filename,O_RDWR ); goto add_vfio_group;
@@ -509,10 +509,10 @@ fslmc_vfio_open_container_fd(void)/* if we're in a primary process, try to open the container */ if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { - vfio_container_fd =open (RTE_VFIO_CONTAINER_PATH ,O_RDWR ); + vfio_container_fd =open (DEV_VFIO_CONTAINER_PATH ,O_RDWR );if (vfio_container_fd <0 ) {DPAA2_BUS_ERR ("Open VFIO container(%s), err(%d)" , -RTE_VFIO_CONTAINER_PATH , vfio_container_fd); +DEV_VFIO_CONTAINER_PATH , vfio_container_fd); ret = vfio_container_fd; goto err_exit; }
drivers/bus/pci/linux/pci.c +4 -4
@@ -12,7 +12,7 @@#include <rte_malloc.h> #include <rte_devargs.h> #include <rte_memcpy.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <eal_export.h> #include "eal_filesystem.h"
@@ -489,7 +489,7 @@ pci_device_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len/* In case driver doesn't provide any specific mapping try fallback to VFIO. */ if (pdev->kdrv ==RTE_PCI_KDRV_VFIO ) - ret =rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , + ret =dev_vfio_container_dma_map (DEV_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, iova, len); }
@@ -506,7 +506,7 @@ pci_device_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t l/* In case driver doesn't provide any specific mapping try fallback to VFIO. */ if (pdev->kdrv ==RTE_PCI_KDRV_VFIO ) -return rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , +return dev_vfio_container_dma_unmap (DEV_VFIO_DEFAULT_CONTAINER_FD , (uintptr_t )addr, iova, len); }
@@ -635,7 +635,7 @@ pci_device_iova_mode(const struct rte_pci_driver *pdrv,static int is_vfio_noiommu_enabled =-1 ;if (is_vfio_noiommu_enabled ==-1 ) { -if (rte_vfio_noiommu_is_enabled () ==1 ) +if (dev_vfio_noiommu_is_enabled () ==1 ) is_vfio_noiommu_enabled =1 ;else is_vfio_noiommu_enabled =0 ;
drivers/bus/pci/linux/pci_vfio.c +19 -19
@@ -18,7 +18,7 @@#include <rte_bus_pci.h> #include <rte_eal_paging.h> #include <rte_malloc.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_eal.h> #include <bus_driver.h> #include <rte_spinlock.h>
@@ -29,10 +29,10 @@#include "pci_init.h" #include "private.h" -static struct rte_tailq_elem rte_vfio_tailq = { +static struct rte_tailq_elem dev_vfio_tailq = { .name ="VFIO_RESOURCE_LIST" , }; -EAL_REGISTER_TAILQ(rte_vfio_tailq) +EAL_REGISTER_TAILQ(dev_vfio_tailq) static int pci_vfio_get_region(const struct rte_pci_device *dev, int index,
@@ -418,7 +418,7 @@ pci_vfio_is_ioport_bar(const struct rte_pci_device *dev, int vfio_dev_fd, }static int -pci_rte_vfio_setup_device (struct rte_pci_device *dev,int vfio_dev_fd) +pci_vfio_setup_device (struct rte_pci_device *dev,int vfio_dev_fd) {if (pci_vfio_setup_interrupts (dev, vfio_dev_fd) !=0 ) {PCI_LOG (ERR ,"Error setting up interrupts!" );
@@ -738,7 +738,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)int i, j, ret;struct mapped_pci_resource *vfio_res =NULL ;struct mapped_pci_res_list *vfio_res_list = -RTE_TAILQ_CAST (rte_vfio_tailq.head, mapped_pci_res_list); +RTE_TAILQ_CAST (dev_vfio_tailq.head, mapped_pci_res_list);struct pci_map *maps;
@@ -752,7 +752,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)snprintf (pci_addr,sizeof (pci_addr),PCI_PRI_FMT , loc->domain, loc->bus, loc->devid, loc->function); - ret =rte_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, + ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd, &device_info);if (ret)return ret;
@@ -897,7 +897,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)free (reg); } -if (pci_rte_vfio_setup_device (dev, vfio_dev_fd) <0 ) { +if (pci_vfio_setup_device (dev, vfio_dev_fd) <0 ) {PCI_LOG (ERR ,"%s setup device failed" , pci_addr); goto err_map; }
@@ -920,7 +920,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) err_vfio_res:rte_free (vfio_res); err_vfio_dev_fd: -rte_vfio_release_device (rte_pci_get_sysfs_path (), +dev_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);return -1 ; }
@@ -935,7 +935,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)int j, ret, i =0 ;struct mapped_pci_resource *vfio_res =NULL ;struct mapped_pci_res_list *vfio_res_list = -RTE_TAILQ_CAST (rte_vfio_tailq.head, mapped_pci_res_list); +RTE_TAILQ_CAST (dev_vfio_tailq.head, mapped_pci_res_list);struct pci_map *maps;
@@ -961,7 +961,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)return -1 ; } - ret =rte_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, + ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd, &device_info);if (ret)return ret;
@@ -1006,7 +1006,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)pci_unmap_resource (maps[j].addr, maps[j].size); } err_vfio_dev_fd: -rte_vfio_release_device (rte_pci_get_sysfs_path (), +dev_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);return -1 ; }
@@ -1101,7 +1101,7 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev)return -1 ; } - ret =rte_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, + ret =dev_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);if (ret <0 ) {PCI_LOG (ERR ,"Cannot release VFIO device" );
@@ -1109,7 +1109,7 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev) } vfio_res_list = -RTE_TAILQ_CAST (rte_vfio_tailq.head, mapped_pci_res_list); +RTE_TAILQ_CAST (dev_vfio_tailq.head, mapped_pci_res_list); vfio_res =find_and_unmap_vfio_resource (vfio_res_list, dev, pci_addr);/* if we haven't found our tailq entry, something's wrong */
@@ -1140,7 +1140,7 @@ pci_vfio_unmap_resource_secondary(struct rte_pci_device *dev)if (vfio_dev_fd <0 )return -1 ; - ret =rte_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, + ret =dev_vfio_release_device (rte_pci_get_sysfs_path (), pci_addr, vfio_dev_fd);if (ret <0 ) {PCI_LOG (ERR ,"Cannot release VFIO device" );
@@ -1148,7 +1148,7 @@ pci_vfio_unmap_resource_secondary(struct rte_pci_device *dev) } vfio_res_list = -RTE_TAILQ_CAST (rte_vfio_tailq.head, mapped_pci_res_list); +RTE_TAILQ_CAST (dev_vfio_tailq.head, mapped_pci_res_list); vfio_res =find_and_unmap_vfio_resource (vfio_res_list, dev, pci_addr);/* if we haven't found our tailq entry, something's wrong */
@@ -1195,7 +1195,7 @@ pci_vfio_ioport_map(struct rte_pci_device *dev, int bar,if (vfio_dev_fd <0 ) {return -1 ; }else if (vfio_dev_fd ==0 ) { -if (rte_vfio_get_device_info (rte_pci_get_sysfs_path (), pci_addr, +if (dev_vfio_get_device_info (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd, &device_info) !=0 )return -1 ;/* save vfio_dev_fd so it can be used during release */
@@ -1300,11 +1300,11 @@ pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar,int pci_vfio_is_enabled (void ) { -int status =rte_vfio_is_enabled ("vfio_pci" ); +int status =dev_vfio_is_enabled ("vfio_pci" );if (!status) { -rte_vfio_enable ("vfio" ); - status =rte_vfio_is_enabled ("vfio_pci" ); +dev_vfio_enable ("vfio" ); + status =dev_vfio_is_enabled ("vfio_pci" ); }return status; }
drivers/bus/platform/platform.c +5 -5
@@ -23,7 +23,7 @@#include <rte_log.h> #include <rte_memory.h> #include <rte_string_fns.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "private.h"
@@ -282,7 +282,7 @@ static void device_cleanup(struct rte_platform_device *pdev) {device_unmap_resources (pdev); -rte_vfio_release_device (PLATFORM_BUS_DEVICES_PATH , pdev->name, pdev->dev_fd); +dev_vfio_release_device (PLATFORM_BUS_DEVICES_PATH , pdev->name, pdev->dev_fd); } static int
@@ -292,7 +292,7 @@ device_setup(struct rte_platform_device *pdev)const char *name = pdev->name;int ret; - ret =rte_vfio_setup_device (PLATFORM_BUS_DEVICES_PATH , name, &pdev->dev_fd, &dev_info); + ret =dev_vfio_setup_device (PLATFORM_BUS_DEVICES_PATH , name, &pdev->dev_fd, &dev_info);if (ret) {PLATFORM_LOG_LINE (ERR ,"failed to setup %s" , name);return -ENODEV ;
@@ -458,7 +458,7 @@ platform_bus_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t lif (pdrv->dma_map !=NULL )return pdrv->dma_map (pdev, addr, iova, len); -return rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , (uint64_t )addr, iova, len); +return dev_vfio_container_dma_map (DEV_VFIO_DEFAULT_CONTAINER_FD , (uint64_t )addr, iova, len); } static int
@@ -470,7 +470,7 @@ platform_bus_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_tif (pdrv->dma_unmap !=NULL )return pdrv->dma_unmap (pdev, addr, iova, len); -return rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , (uint64_t )addr, iova, +return dev_vfio_container_dma_unmap (DEV_VFIO_DEFAULT_CONTAINER_FD , (uint64_t )addr, iova, len); }
drivers/crypto/bcmfs/bcmfs_vfio.c +4 -4
@@ -9,7 +9,7 @@#include <sys/mman.h> #include <sys/ioctl.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "bcmfs_device.h" #include "bcmfs_logs.h"
@@ -25,7 +25,7 @@ vfio_map_dev_obj(const char *path, const char *dev_obj,struct vfio_device_info d_info = { .argsz =sizeof (d_info) };struct vfio_region_info reg_info = { .argsz =sizeof (reg_info) }; - ret =rte_vfio_setup_device (path, dev_obj, dev_fd, &d_info); + ret =dev_vfio_setup_device (path, dev_obj, dev_fd, &d_info);if (ret) {BCMFS_LOG (ERR ,"VFIO Setting for device failed" );return ret;
@@ -51,7 +51,7 @@ vfio_map_dev_obj(const char *path, const char *dev_obj,return 0 ; map_failed: -rte_vfio_release_device (path, dev_obj, *dev_fd); +dev_vfio_release_device (path, dev_obj, *dev_fd);return ret; }
@@ -87,7 +87,7 @@ bcmfs_release_vfio(struct bcmfs_device *dev)/* unmap the addr */ munmap (dev->mmap_addr, dev->mmap_size);/* release the device */ - ret =rte_vfio_release_device (dev->dirname, dev->name, + ret =dev_vfio_release_device (dev->dirname, dev->name, dev->vfio_dev_fd);if (ret <0 ) {BCMFS_LOG (ERR ,"cannot release device" );
drivers/net/hinic3/base/hinic3_hwdev.c +2 -2
@@ -2,7 +2,7 @@* Copyright(c) 2025 Huawei Technologies Co., Ltd */ -#include <rte_vfio.h> +#include <dev_vfio.h> #include "hinic3_compat.h" #include "hinic3_cmd.h"
@@ -78,7 +78,7 @@ hinic3_is_vfio_iommu_enable(const struct rte_eth_dev *eth_dev) {struct rte_pci_device *pci_dev =RTE_CLASS_TO_BUS_DEVICE (eth_dev, *pci_dev); -return pci_dev->kdrv ==RTE_PCI_KDRV_VFIO &&rte_vfio_noiommu_is_enabled () !=1 ; +return pci_dev->kdrv ==RTE_PCI_KDRV_VFIO &&dev_vfio_noiommu_is_enabled () !=1 ; }int
drivers/net/nbl/nbl_common/nbl_userdev.c +8 -8
@@ -5,7 +5,7 @@#include <uapi/linux/vfio.h> #include "nbl_userdev.h" -#include <rte_vfio.h> +#include <dev_vfio.h> #define NBL_USERDEV_EVENT_CLB_NAME "nbl_userspace_mem_event_clb"#define NBL_USERDEV_BAR0_SIZE 65536
@@ -406,7 +406,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter)snprintf (pathname,sizeof (pathname),"%s/%s/" ,rte_pci_get_sysfs_path (), dev_name); - ret =rte_vfio_get_group_num (pathname, dev_name, &common->iommu_group_num); + ret =dev_vfio_get_group_num (pathname, dev_name, &common->iommu_group_num);if (ret <=0 ) {NBL_LOG (ERR ,"nbl vfio group number failed" );return -1 ;
@@ -415,7 +415,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter)NBL_LOG (DEBUG ,"nbl vfio group number %d" , common->iommu_group_num);/* vfio_container */ if (nbl_default_container <0 ) { - container =rte_vfio_container_create (); + container =dev_vfio_container_create (); container_create =1 ;if (container <0 ) {
@@ -425,7 +425,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) }NBL_LOG (DEBUG ,"nbl vfio container %d" , container); - vfio_group_fd =rte_vfio_container_group_bind (container, common->iommu_group_num); + vfio_group_fd =dev_vfio_container_group_bind (container, common->iommu_group_num);if (vfio_group_fd <0 ) {NBL_LOG (ERR ,"nbl vfio group bind failed, %d" , vfio_group_fd); goto free_container;
@@ -536,10 +536,10 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) } free_group:close (vfio_group_fd); -rte_vfio_clear_group (vfio_group_fd); +dev_vfio_clear_group (vfio_group_fd); free_container:if (container_create) -rte_vfio_container_destroy (container); +dev_vfio_container_destroy (container);return -1 ; }
@@ -551,7 +551,7 @@ static int nbl_mdev_unmap_device(struct nbl_adapter *adapter)rte_mcfg_mem_read_lock ();TAILQ_REMOVE (&nbl_adapter_list, adapter, next);close (common->devfd); - vfio_group_fd =rte_vfio_container_group_bind (nbl_default_container, + vfio_group_fd =dev_vfio_container_group_bind (nbl_default_container, common->iommu_group_num);NBL_LOG (DEBUG ,"close vfio_group_fd %d" , vfio_group_fd); ret =ioctl (vfio_group_fd,VFIO_GROUP_UNSET_CONTAINER , &nbl_default_container);
@@ -559,7 +559,7 @@ static int nbl_mdev_unmap_device(struct nbl_adapter *adapter)NBL_LOG (ERR ,"unset container, error %i (%s) %d" , errno,strerror (errno), ret); nbl_group_count--; - ret =rte_vfio_container_group_unbind (nbl_default_container, common->iommu_group_num); + ret =dev_vfio_container_group_unbind (nbl_default_container, common->iommu_group_num);if (ret)NBL_LOG (ERR ,"vfio container group unbind failed %d" , ret);if (!nbl_group_count) {
drivers/net/ntnic/ntnic_ethdev.c +2 -2
@@ -7,7 +7,7 @@#include <rte_eal.h> #include <rte_dev.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_ethdev.h> #include <rte_bus_pci.h> #include <ethdev_pci.h>
@@ -2729,7 +2729,7 @@ nthw_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) (pci_dev->device.devargs->data ? pci_dev->device.devargs->data : "NULL")); } -const int n_rte_vfio_no_io_mmu_enabled =rte_vfio_noiommu_is_enabled (); +const int n_rte_vfio_no_io_mmu_enabled =dev_vfio_noiommu_is_enabled ();NT_LOG (DBG ,NTNIC ,"vfio_no_iommu_enabled=%d" , n_rte_vfio_no_io_mmu_enabled);if (n_rte_vfio_no_io_mmu_enabled) {
drivers/net/ntnic/ntnic_vfio.c +11 -11
@@ -6,7 +6,7 @@#include <rte_malloc.h> #include <rte_memory.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_dev.h> #include <rte_bus_pci.h> #include <rte_spinlock.h>
@@ -70,16 +70,16 @@ nthw_vfio_setup(struct rte_pci_device *dev) vfio->iova_addr =START_VF_IOVA ;rte_pci_device_name (&dev->addr, devname,RTE_DEV_NAME_MAX_LEN ); - ret =rte_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, &iommu_group_num); + ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, &iommu_group_num);if (ret <=0 )return -1 ;if (vf_num ==0 ) {/* use default container for pf0 */ - vfio->container_fd =RTE_VFIO_DEFAULT_CONTAINER_FD ; + vfio->container_fd =DEV_VFIO_DEFAULT_CONTAINER_FD ; }else { - vfio->container_fd =rte_vfio_container_create (); + vfio->container_fd =dev_vfio_container_create ();if (vfio->container_fd <0 ) { NT_LOG(ERR, NTNIC,
@@ -88,7 +88,7 @@ nthw_vfio_setup(struct rte_pci_device *dev) } } - vfio->group_fd =rte_vfio_container_group_bind (vfio->container_fd, iommu_group_num); + vfio->group_fd =dev_vfio_container_group_bind (vfio->container_fd, iommu_group_num);if (vfio->group_fd <0 ) { NT_LOG(ERR, NTNIC,
@@ -115,8 +115,8 @@ nthw_vfio_setup(struct rte_pci_device *dev) err: -if (vfio->container_fd !=RTE_VFIO_DEFAULT_CONTAINER_FD ) -rte_vfio_container_destroy (vfio->container_fd); +if (vfio->container_fd !=DEV_VFIO_DEFAULT_CONTAINER_FD ) +dev_vfio_container_destroy (vfio->container_fd);return -1 ; }
@@ -135,7 +135,7 @@ nthw_vfio_remove(int vf_num)return -1 ; } -rte_vfio_container_destroy (vfio->container_fd); +dev_vfio_container_destroy (vfio->container_fd);return 0 ; }
@@ -169,14 +169,14 @@ nthw_vfio_dma_map(int vf_num, void *virt_addr, uint64_t *iova_addr, uint64_t siz vf_num, virt_addr,rte_malloc_virt2iova (virt_addr), gp_virt_base, vfio->iova_addr, size); -int res =rte_vfio_container_dma_map (vfio->container_fd, gp_virt_base, vfio->iova_addr, +int res =dev_vfio_container_dma_map (vfio->container_fd, gp_virt_base, vfio->iova_addr, size);NT_LOG (DBG ,NTNIC ,"VFIO MMAP res %i, container_fd %i, vf_num %i" , res, vfio->container_fd, vf_num);if (res) { -NT_LOG (ERR ,NTNIC ,"rte_vfio_container_dma_map failed: res %d" , res); +NT_LOG (ERR ,NTNIC ,"dev_vfio_container_dma_map failed: res %d" , res);return -1 ; }
@@ -210,7 +210,7 @@ nthw_vfio_dma_unmap(int vf_num, void *virt_addr, uint64_t iova_addr, uint64_t sireturn -1 ; } -int res =rte_vfio_container_dma_unmap (vfio->container_fd, gp_virt_base, iova_addr, size); +int res =dev_vfio_container_dma_unmap (vfio->container_fd, gp_virt_base, iova_addr, size);if (res !=0 ) { NT_LOG(ERR, NTNIC,
drivers/vdpa/ifc/ifcvf_vdpa.c +12 -12
@@ -20,7 +20,7 @@#include <rte_vhost.h> #include <rte_vdpa.h> #include <vdpa_driver.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_spinlock.h> #include <rte_log.h> #include <rte_kvargs.h>
@@ -183,18 +183,18 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal) internal->vfio_container_fd =-1 ;rte_pci_device_name (&dev->addr, devname,RTE_DEV_NAME_MAX_LEN ); - ret =rte_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, + ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, &iommu_group_num);if (ret <=0 ) {DRV_LOG (ERR ,"%s failed to get IOMMU group" , devname);return -1 ; } - internal->vfio_container_fd =rte_vfio_container_create (); + internal->vfio_container_fd =dev_vfio_container_create ();if (internal->vfio_container_fd <0 )return -1 ; - internal->vfio_group_fd =rte_vfio_container_group_bind ( + internal->vfio_group_fd =dev_vfio_container_group_bind ( internal->vfio_container_fd, iommu_group_num);if (internal->vfio_group_fd <0 ) goto err;
@@ -217,7 +217,7 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal)return 0 ; err: -rte_vfio_container_destroy (internal->vfio_container_fd); +dev_vfio_container_destroy (internal->vfio_container_fd);return -1 ; }
@@ -247,7 +247,7 @@ ifcvf_dma_map(struct ifcvf_internal *internal, bool do_map) reg->host_user_addr, reg->guest_phys_addr, reg->size);if (do_map) { - ret =rte_vfio_container_dma_map (vfio_container_fd, + ret =dev_vfio_container_dma_map (vfio_container_fd, reg->host_user_addr, reg->guest_phys_addr, reg->size);if (ret <0 ) {
@@ -255,7 +255,7 @@ ifcvf_dma_map(struct ifcvf_internal *internal, bool do_map) goto exit; } }else { - ret =rte_vfio_container_dma_unmap (vfio_container_fd, + ret =dev_vfio_container_dma_unmap (vfio_container_fd, reg->host_user_addr, reg->guest_phys_addr, reg->size);if (ret <0 ) {
@@ -389,7 +389,7 @@ vdpa_ifcvf_stop(struct ifcvf_internal *internal)if (RTE_VHOST_NEED_LOG (features)) {ifcvf_disable_logging (hw);rte_vhost_get_log_base (internal->vid, &log_base, &log_size); -rte_vfio_container_dma_unmap (internal->vfio_container_fd, +dev_vfio_container_dma_unmap (internal->vfio_container_fd, log_base,IFCVF_LOG_BASE , log_size);/* * IFCVF marks dirty memory pages for only packet buffer,
@@ -792,7 +792,7 @@ m_ifcvf_start(struct ifcvf_internal *internal)vring_init (&internal->m_vring[i], vq.size, vring_buf,rte_mem_page_size ()); - ret =rte_vfio_container_dma_map (internal->vfio_container_fd, + ret =dev_vfio_container_dma_map (internal->vfio_container_fd, (uint64_t )(uintptr_t )vring_buf, m_vring_iova, size);if (ret <0 ) {DRV_LOG (ERR ,"mediated vring DMA map failed." );
@@ -901,7 +901,7 @@ m_ifcvf_stop(struct ifcvf_internal *internal) size =RTE_ALIGN_CEIL (vring_size (vq.size,rte_mem_page_size ()),rte_mem_page_size ()); -rte_vfio_container_dma_unmap (internal->vfio_container_fd, +dev_vfio_container_dma_unmap (internal->vfio_container_fd, (uint64_t )(uintptr_t )internal->m_vring[i].desc, m_vring_iova, size);
@@ -1206,7 +1206,7 @@ ifcvf_set_features(int vid)ifcvf_sw_fallback_switchover (internal); }else {rte_vhost_get_log_base (vid, &log_base, &log_size); -rte_vfio_container_dma_map (internal->vfio_container_fd, +dev_vfio_container_dma_map (internal->vfio_container_fd, log_base,IFCVF_LOG_BASE , log_size);ifcvf_enable_logging (&internal->hw,IFCVF_LOG_BASE , log_size); }
@@ -1825,7 +1825,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev)DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name);rte_pci_unmap_device (internal->pdev); -rte_vfio_container_destroy (internal->vfio_container_fd); +dev_vfio_container_destroy (internal->vfio_container_fd);rte_vdpa_unregister_device (internal->vdev);pthread_mutex_lock (&internal_list_lock);
drivers/vdpa/nfp/nfp_vdpa.c +12 -12
@@ -12,7 +12,7 @@#include <nfp_common_pci.h> #include <nfp_dev.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_eal_paging.h> #include <rte_malloc.h> #include <vdpa_driver.h>
@@ -120,16 +120,16 @@ nfp_vdpa_vfio_setup(struct nfp_vdpa_dev *device)struct rte_pci_device *pci_dev = device->pci_dev;rte_pci_device_name (&pci_dev->addr, dev_name,RTE_DEV_NAME_MAX_LEN ); - ret =rte_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, + ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, &device->iommu_group);if (ret <=0 )return -1 ; - device->vfio_container_fd =rte_vfio_container_create (); + device->vfio_container_fd =dev_vfio_container_create ();if (device->vfio_container_fd <0 )return -1 ; - device->vfio_group_fd =rte_vfio_container_group_bind ( + device->vfio_group_fd =dev_vfio_container_group_bind ( device->vfio_container_fd, device->iommu_group);if (device->vfio_group_fd <0 ) goto container_destroy;
@@ -146,9 +146,9 @@ nfp_vdpa_vfio_setup(struct nfp_vdpa_dev *device)return 0 ; group_unbind: -rte_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); +dev_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); container_destroy: -rte_vfio_container_destroy (device->vfio_container_fd); +dev_vfio_container_destroy (device->vfio_container_fd);return -1 ; }
@@ -157,8 +157,8 @@ static void nfp_vdpa_vfio_teardown(struct nfp_vdpa_dev *device) {rte_pci_unmap_device (device->pci_dev); -rte_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); -rte_vfio_container_destroy (device->vfio_container_fd); +dev_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); +dev_vfio_container_destroy (device->vfio_container_fd); } static int
@@ -173,7 +173,7 @@ nfp_vdpa_dma_do_unmap(struct rte_vhost_memory *mem,for (i =0 ; i < times; i++) { region = &mem->regions[i]; - ret =rte_vfio_container_dma_unmap (vfio_container_fd, + ret =dev_vfio_container_dma_unmap (vfio_container_fd, region->host_user_addr, region->guest_phys_addr, region->size);if (ret <0 ) {
@@ -197,7 +197,7 @@ nfp_vdpa_dma_do_map(struct rte_vhost_memory *mem,for (i =0 ; i < times; i++) { region = &mem->regions[i]; - ret =rte_vfio_container_dma_map (vfio_container_fd, + ret =dev_vfio_container_dma_map (vfio_container_fd, region->host_user_addr, region->guest_phys_addr, region->size);if (ret <0 ) {
@@ -282,7 +282,7 @@ nfp_vdpa_relay_vring_free(struct nfp_vdpa_dev *device, size =RTE_ALIGN_CEIL (vring_size (vring.size,rte_mem_page_size ()),rte_mem_page_size ()); -rte_vfio_container_dma_unmap (device->vfio_container_fd, +dev_vfio_container_dma_unmap (device->vfio_container_fd, (uint64_t )(uintptr_t )device->hw.m_vring[i].desc, m_vring_iova, size);
@@ -315,7 +315,7 @@ nfp_vdpa_relay_vring_alloc(struct nfp_vdpa_dev *device)vring_init (&vdpa_hw->m_vring[i], vring.size, vring_buf, page_size); - ret =rte_vfio_container_dma_map (device->vfio_container_fd, + ret =dev_vfio_container_dma_map (device->vfio_container_fd, (uint64_t )(uintptr_t )vring_buf, m_vring_iova, size);if (ret !=0 ) {DRV_VDPA_LOG (ERR ,"vDPA vring relay dma map failed." );
drivers/vdpa/sfc/sfc_vdpa.c +8 -8
@@ -12,7 +12,7 @@#include <rte_errno.h> #include <rte_kvargs.h> #include <rte_string_fns.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_vhost.h> #include "efx.h"
@@ -74,13 +74,13 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva)rte_pci_device_name (&dev->addr, dev_name,RTE_DEV_NAME_MAX_LEN ); - sva->vfio_container_fd =rte_vfio_container_create (); + sva->vfio_container_fd =dev_vfio_container_create ();if (sva->vfio_container_fd <0 ) {sfc_vdpa_err (sva,"failed to create VFIO container" ); goto fail_container_create; } - rc =rte_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, + rc =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, &sva->iommu_group_num);if (rc <=0 ) { sfc_vdpa_err(sva, "failed to get IOMMU group for %s : %s",
@@ -89,7 +89,7 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva) } sva->vfio_group_fd = -rte_vfio_container_group_bind (sva->vfio_container_fd, +dev_vfio_container_group_bind (sva->vfio_container_fd, sva->iommu_group_num);if (sva->vfio_group_fd <0 ) { sfc_vdpa_err(sva,
@@ -109,7 +109,7 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva)return 0 ; fail_pci_map_device: -if (rte_vfio_container_group_unbind (sva->vfio_container_fd, +if (dev_vfio_container_group_unbind (sva->vfio_container_fd, sva->iommu_group_num) !=0 ) { sfc_vdpa_err(sva, "failed to unbind IOMMU group %d from container %d",
@@ -118,7 +118,7 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva) fail_group_bind: fail_get_group_num: -if (rte_vfio_container_destroy (sva->vfio_container_fd) !=0 ) { +if (dev_vfio_container_destroy (sva->vfio_container_fd) !=0 ) {sfc_vdpa_err (sva,"failed to destroy container %d" , sva->vfio_container_fd); }
@@ -132,14 +132,14 @@ sfc_vdpa_vfio_teardown(struct sfc_vdpa_adapter *sva) {rte_pci_unmap_device (sva->pdev); -if (rte_vfio_container_group_unbind (sva->vfio_container_fd, +if (dev_vfio_container_group_unbind (sva->vfio_container_fd, sva->iommu_group_num) !=0 ) {sfc_vdpa_err (sva,"failed to unbind IOMMU group %d from container %d" , sva->iommu_group_num, sva->vfio_container_fd); } -if (rte_vfio_container_destroy (sva->vfio_container_fd) !=0 ) { +if (dev_vfio_container_destroy (sva->vfio_container_fd) !=0 ) {sfc_vdpa_err (sva,"failed to destroy container %d" , sva->vfio_container_fd);
drivers/vdpa/sfc/sfc_vdpa_hw.c +6 -6
@@ -6,7 +6,7 @@#include <rte_common.h> #include <rte_errno.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_vhost.h> #include "efx.h"
@@ -64,7 +64,7 @@ sfc_vdpa_dma_alloc(struct sfc_vdpa_adapter *sva, const char *name, mcdi_iova =SFC_VDPA_DEFAULT_MCDI_IOVA ;for (;;) { - ret =rte_vfio_container_dma_map (sva->vfio_container_fd, + ret =dev_vfio_container_dma_map (sva->vfio_container_fd, (uint64_t )mz->addr, mcdi_iova, mcdi_buff_size);if (ret ==0 )
@@ -98,7 +98,7 @@ sfc_vdpa_dma_free(struct sfc_vdpa_adapter *sva, efsys_mem_t *esmp)sfc_vdpa_log_init (sva,"name=%s" , esmp->esm_mz->name); - ret =rte_vfio_container_dma_unmap (sva->vfio_container_fd, + ret =dev_vfio_container_dma_unmap (sva->vfio_container_fd, (uint64_t )esmp->esm_base, esmp->esm_addr, sva->mcdi_buff_size);if (ret <0 )
@@ -140,7 +140,7 @@ sfc_vdpa_dma_map(struct sfc_vdpa_ops_data *ops_data, bool do_map) mem_reg = &vhost_mem->regions[i];if (do_map) { - rc =rte_vfio_container_dma_map (vfio_container_fd, + rc =dev_vfio_container_dma_map (vfio_container_fd, mem_reg->host_user_addr, mem_reg->guest_phys_addr, mem_reg->size);
@@ -151,7 +151,7 @@ sfc_vdpa_dma_map(struct sfc_vdpa_ops_data *ops_data, bool do_map) goto failed_vfio_dma_map; } }else { - rc =rte_vfio_container_dma_unmap (vfio_container_fd, + rc =dev_vfio_container_dma_unmap (vfio_container_fd, mem_reg->host_user_addr, mem_reg->guest_phys_addr, mem_reg->size);
@@ -171,7 +171,7 @@ sfc_vdpa_dma_map(struct sfc_vdpa_ops_data *ops_data, bool do_map) failed_vfio_dma_map:for (j =0 ; j < i; j++) { mem_reg = &vhost_mem->regions[j]; -rte_vfio_container_dma_unmap (vfio_container_fd, +dev_vfio_container_dma_unmap (vfio_container_fd, mem_reg->host_user_addr, mem_reg->guest_phys_addr, mem_reg->size);
lib/eal/linux/eal.c +2 -2
@@ -41,7 +41,7 @@#include <rte_bus.h> #include <rte_version.h> #include <malloc_heap.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <telemetry_internal.h> #include <eal_export.h>
@@ -772,7 +772,7 @@ rte_eal_init(int argc, char **argv)#endif } -if (rte_vfio_enable ("vfio" )) { +if (dev_vfio_enable ("vfio" )) {rte_eal_init_alert ("Cannot init VFIO" ); rte_errno =EAGAIN ; goto err_out;
lib/eal/linux/eal_vfio.c +58 -58
370 lines not on this page · raw message
lib/eal/linux/eal_vfio_mp_sync.c +3 -3
@@ -8,7 +8,7 @@#include <rte_errno.h> #include <rte_log.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_eal.h> #include "eal_private.h"
@@ -34,7 +34,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)case SOCKET_REQ_GROUP : r->req =SOCKET_REQ_GROUP ; r->group_num = m->group_num; - fd =rte_vfio_get_group_fd (m->group_num); + fd =dev_vfio_get_group_fd (m->group_num);if (fd <0 && fd != -ENOENT ) r->result =SOCKET_ERR ;else if (fd == -ENOENT )
@@ -49,7 +49,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)break ;case SOCKET_REQ_CONTAINER : r->req =SOCKET_REQ_CONTAINER ; - fd =rte_vfio_get_container_fd (); + fd =dev_vfio_get_container_fd ();if (fd <0 ) r->result =SOCKET_ERR ;else {
lib/eal/linux/include/dev_vfio.h renamed from lib/eal/linux/include/rte_vfio.h +68 -36
273 lines not on this page · raw message
lib/eal/linux/include/meson.build +4 -1
@@ -5,5 +5,8 @@ includes += include_directories('.') headers += files( 'rte_os.h', - 'rte_vfio.h', +) + +driver_sdk_headers += files( + 'dev_vfio.h', )
lib/vhost/socket.c +2 -2
@@ -17,7 +17,7 @@#include <eal_export.h> #include <rte_thread.h> #include <rte_log.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include "fd_man.h" #include "vduse.h"
@@ -245,7 +245,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)if (dev !=NULL ) { dev->async_copy =1 ; - dev->dma_map_available =rte_vfio_is_enabled ("vfio" ); + dev->dma_map_available =dev_vfio_is_enabled ("vfio" ); } }
lib/vhost/vhost_user.c +3 -3
@@ -42,7 +42,7 @@#include <rte_common.h> #include <rte_malloc.h> #include <rte_log.h> -#include <rte_vfio.h> +#include <dev_vfio.h> #include <rte_errno.h> #include "iotlb.h"
@@ -191,7 +191,7 @@ async_dma_map_region(struct virtio_net *dev, struct rte_vhost_mem_region *reg, bcontinue ;if (do_map) { - ret =rte_vfio_container_dma_map (RTE_VFIO_DEFAULT_CONTAINER_FD , + ret =dev_vfio_container_dma_map (DEV_VFIO_DEFAULT_CONTAINER_FD , page->host_user_addr, page->host_iova, page->size);
@@ -216,7 +216,7 @@ async_dma_map_region(struct virtio_net *dev, struct rte_vhost_mem_region *reg, breturn -1 ; } }else { - ret =rte_vfio_container_dma_unmap (RTE_VFIO_DEFAULT_CONTAINER_FD , + ret =dev_vfio_container_dma_unmap (DEV_VFIO_DEFAULT_CONTAINER_FD , page->host_user_addr, page->host_iova, page->size);
Signature · 1 line
2.54.0
PATCH RESEND v19 7/26 vfio: add module check API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
All VFIO initialization always happens with "vfio" module, and now that the API is not public, having a way to override the module name seems redundant as there is not going to be a use case that calls into rte_vfio_enable that isn't coming from EAL init.
On the other hand, there are a few users of VFIO API that depend on checking if a specific kernel module is loaded. This call is coupled with checking if VFIO is enabled (which should not be the case, as these are orthogonal), and depending on context different modules are checked with a string literal (which is suboptimal as well).
Provide a new API in VFIO to check for whether a specific VFIO-related kernel module is loaded, decouple it from "enabled" check, and adjust all callers accordingly.
With this change, there is no user left for the EAL function, remove it.
---
Changes since v18:
- squashed all kmod checks into a single patch,
--- drivers/bus/pci/linux/pci_vfio.c | 11 +++--- lib/eal/common/eal_private.h | 14 -------- lib/eal/linux/eal.c | 37 +------------------ lib/eal/linux/eal_vfio.c | 61 +++++++++++++++++++++++++++++--- lib/eal/linux/include/dev_vfio.h | 39 ++++++++++++++------ lib/vhost/socket.c | 2 +- 6 files changed, 93 insertions(+), 71 deletions(-)
drivers/bus/pci/linux/pci_vfio.c +6 -5
@@ -1300,11 +1300,12 @@ pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar,int pci_vfio_is_enabled (void ) { -int status =dev_vfio_is_enabled ("vfio_pci" ); +int status; -if (!status) { -dev_vfio_enable ("vfio" ); - status =dev_vfio_is_enabled ("vfio_pci" ); - } +if (dev_vfio_enable () <0 ) +return 0 ; + + status =dev_vfio_is_enabled () && +dev_vfio_module_is_loaded (DEV_VFIO_MODULE_VFIO_PCI );return status; }
lib/eal/common/eal_private.h +0 -14
@@ -206,20 +206,6 @@ int rte_eal_alarm_init(void);*/ void rte_eal_alarm_cleanup (void ); -/** -* Function is to check if the kernel module(like, vfio, vfio_iommu_type1, -* etc.) loaded. -* -* @param module_name -* The module's name which need to be checked -* -* @return -* -1 means some error happens(NULL pointer or open failure) -* 0 means the module not loaded -* 1 means the module loaded -*/ -int rte_eal_check_module (const char *module_name); -/** * Memory reservation flags. */
lib/eal/linux/eal.c +1 -36
@@ -17,9 +17,7 @@#include <fnmatch.h> #include <stddef.h> #include <errno.h> -#include <limits.h> #include <sys/mman.h> -#include <sys/stat.h> #if defined(RTE_ARCH_X86 )#include <sys/io.h> #endif
@@ -772,7 +770,7 @@ rte_eal_init(int argc, char **argv)#endif } -if (dev_vfio_enable ("vfio" )) { +if (dev_vfio_enable ()) {rte_eal_init_alert ("Cannot init VFIO" ); rte_errno =EAGAIN ; goto err_out;
@@ -1029,36 +1027,3 @@ rte_eal_vfio_get_vf_token(rte_uuid_t vf_token)rte_uuid_copy (vf_token, cfg->vfio_vf_token); } -int -rte_eal_check_module (const char *module_name) -{ -char sysfs_mod_name[PATH_MAX ]; -struct stat st; -int n; - -if (NULL == module_name) -return -1 ; - -/* Check if there is sysfs mounted */ -if (stat ("/sys/module" , &st) !=0 ) { -EAL_LOG (DEBUG ,"sysfs is not mounted! error %i (%s)" , - errno,strerror (errno)); -return -1 ; - } - -/* A module might be built-in, therefore try sysfs */ - n =snprintf (sysfs_mod_name,PATH_MAX ,"/sys/module/%s" , module_name); -if (n <0 || n >PATH_MAX ) { -EAL_LOG (DEBUG ,"Could not format module path" ); -return -1 ; - } - -if (stat (sysfs_mod_name, &st) !=0 ) { -EAL_LOG (DEBUG ,"Module %s not found! error %i (%s)" , - sysfs_mod_name, errno,strerror (errno)); -return 0 ; - } - -/* Module has been found */ -return 1 ; -}
lib/eal/linux/eal_vfio.c +56 -5
97 lines not on this page · raw message
lib/eal/linux/include/dev_vfio.h +29 -10
@@ -35,6 +35,17 @@ struct vfio_device_info;#define DEV_VFIO_DEFAULT_CONTAINER_FD (-1) +/** +* @enum dev_vfio_module +* VFIO kernel modules. +* +* These values identify kernel modules used by VFIO. +*/ +enum dev_vfio_module { +DEV_VFIO_MODULE_VFIO ,/**< Core VFIO module. */ +DEV_VFIO_MODULE_VFIO_PCI ,/**< VFIO PCI module. */ +}; +/** * @internal * Setup vfio_cfg for the device identified by its address.
@@ -84,31 +95,39 @@ int dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd/** * @internal -* Enable a VFIO-related kmod. -* -* @param modname -* kernel module name. +* Initialize VFIO. * * @return * 0 on success. * <0 on failure. */ __rte_internal -int dev_vfio_enable(const char *modname); +int dev_vfio_enable(void);/** * @internal -* Check whether a VFIO-related kmod is enabled. +* Check whether a VFIO module is loaded. * -* @param modname -* kernel module name. +* @param module +* VFIO module to check. * * @return -* 1 if true. +* 1 if the requested module is loaded. +* 0 otherwise. +*/ +__rte_internal +int dev_vfio_module_is_loaded(enum dev_vfio_module module); + +/** +* @internal +* Check whether VFIO was initialized. +* +* @return +* 1 if VFIO was initialized. * 0 otherwise. */ __rte_internal -int dev_vfio_is_enabled(const char *modname); +int dev_vfio_is_enabled(void);/** * @internal
lib/vhost/socket.c +1 -1
@@ -245,7 +245,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)if (dev !=NULL ) { dev->async_copy =1 ; - dev->dma_map_available =dev_vfio_is_enabled ("vfio" ); + dev->dma_map_available =dev_vfio_is_enabled (); } }
Signature · 1 line
2.54.0
PATCH RESEND v19 8/26 vfio: teardown internals on VFIO cleanup
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Currently, VFIO cleanup only unregisters multiprocess callback, but does not destroy containers, groups, and user mem maps. Do all of that on VFIO cleanup. We don't actually need a per-config enabled flag, as container fd should be enough to determine whether the config is active.
While we're at it, also harden the API against repeated initialization and attempts at using the API without having VFIO initialized.
---
Changes since v18:
- squashed with introduction of dev_vfio_cleanup(),
- removed rte_errno = ENODEV updates since most of them are dropped later in the series,
--- lib/eal/linux/eal.c | 3 +- lib/eal/linux/eal_vfio.c | 136 +++++++++++++++++++++++++++++-- lib/eal/linux/include/dev_vfio.h | 7 ++ 3 files changed, 139 insertions(+), 7 deletions(-)
lib/eal/linux/eal.c +1 -2
@@ -52,7 +52,6 @@#include "eal_memcfg.h" #include "eal_trace.h" #include "eal_options.h" -#include "eal_vfio.h" #include "hotplug_mp.h" #include "log_internal.h"
@@ -984,7 +983,7 @@ rte_eal_cleanup(void)rte_service_finalize ();eal_bus_cleanup (); -vfio_mp_sync_cleanup (); +dev_vfio_cleanup ();rte_mp_channel_cleanup ();rte_eal_alarm_cleanup ();rte_trace_save ();
lib/eal/linux/eal_vfio.c +131 -5
258 lines not on this page · raw message
lib/eal/linux/include/dev_vfio.h +7 -0
@@ -104,6 +104,13 @@ int dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd__rte_internal int dev_vfio_enable(void); +/** +* @internal +* Cleanup VFIO resources. +*/ +__rte_internal +void dev_vfio_cleanup(void); +/** * @internal * Check whether a VFIO module is loaded.
Signature · 1 line
2.54.0
PATCH RESEND v19 9/26 vfio: split get device info from setup
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Currently, setup gets device info as part of setup, while the separate get device info API also calls setup if the fd is zero. Untangle these two APIs and make each do one thing, and adjust all existing callers.
--- drivers/bus/cdx/cdx_vfio.c | 13 +++++++--- drivers/bus/pci/linux/pci_vfio.c | 20 +++++++++++----- drivers/bus/platform/platform.c | 9 ++++++- drivers/crypto/bcmfs/bcmfs_vfio.c | 8 ++++++- lib/eal/linux/eal_vfio.c | 40 ++++++++----------------------- lib/eal/linux/include/dev_vfio.h | 24 +++++++------------ 6 files changed, 57 insertions(+), 57 deletions(-)
drivers/bus/cdx/cdx_vfio.c +10 -3
@@ -408,10 +408,14 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev)return -1 ; ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, - &vfio_dev_fd, &device_info); + &vfio_dev_fd);if (ret)return ret; + ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info); +if (ret) + goto err_vfio_dev_fd; +/* allocate vfio_res and get region info */ vfio_res =rte_zmalloc ("VFIO_RES" ,sizeof (*vfio_res),0 );if (vfio_res ==NULL ) {
@@ -516,11 +520,14 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev)return -1 ; } - ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, - &vfio_dev_fd, &device_info); + ret =dev_vfio_setup_device (RTE_CDX_BUS_DEVICES_PATH , dev_name, &vfio_dev_fd);if (ret)return ret; + ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info); +if (ret) + goto err_vfio_dev_fd; +/* map MMIO regions */ maps = vfio_res->maps;
drivers/bus/pci/linux/pci_vfio.c +14 -6
@@ -752,11 +752,14 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)snprintf (pci_addr,sizeof (pci_addr),PCI_PRI_FMT , loc->domain, loc->bus, loc->devid, loc->function); - ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, - &vfio_dev_fd, &device_info); + ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd);if (ret)return ret; + ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info); +if (ret) + goto err_vfio_dev_fd; +if (rte_intr_dev_fd_set (dev->intr_handle, vfio_dev_fd)) goto err_vfio_dev_fd;
@@ -961,11 +964,14 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)return -1 ; } - ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, - &vfio_dev_fd, &device_info); + ret =dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, &vfio_dev_fd);if (ret)return ret; + ret =dev_vfio_get_device_info (vfio_dev_fd, &device_info); +if (ret) + goto err_vfio_dev_fd; + ret =pci_vfio_fill_regions (dev, vfio_dev_fd, &device_info);if (ret) goto err_vfio_dev_fd;
@@ -1195,12 +1201,14 @@ pci_vfio_ioport_map(struct rte_pci_device *dev, int bar,if (vfio_dev_fd <0 ) {return -1 ; }else if (vfio_dev_fd ==0 ) { -if (dev_vfio_get_device_info (rte_pci_get_sysfs_path (), pci_addr, - &vfio_dev_fd, &device_info) !=0 ) +if (dev_vfio_setup_device (rte_pci_get_sysfs_path (), pci_addr, + &vfio_dev_fd) !=0 )return -1 ;/* save vfio_dev_fd so it can be used during release */ if (rte_intr_dev_fd_set (dev->intr_handle, vfio_dev_fd) !=0 )return -1 ; +if (dev_vfio_get_device_info (vfio_dev_fd, &device_info) !=0 ) +return -1 ;if (pci_vfio_fill_regions (dev, vfio_dev_fd, &device_info) !=0 )return -1 ;
drivers/bus/platform/platform.c +8 -1
@@ -292,12 +292,19 @@ device_setup(struct rte_platform_device *pdev)const char *name = pdev->name;int ret; - ret =dev_vfio_setup_device (PLATFORM_BUS_DEVICES_PATH , name, &pdev->dev_fd, &dev_info); + ret =dev_vfio_setup_device (PLATFORM_BUS_DEVICES_PATH , name, &pdev->dev_fd);if (ret) {PLATFORM_LOG_LINE (ERR ,"failed to setup %s" , name);return -ENODEV ; } + ret =dev_vfio_get_device_info (pdev->dev_fd, &dev_info); +if (ret) { +PLATFORM_LOG_LINE (ERR ,"failed to get device info for %s" , name); + ret = -ENODEV ; + goto out; + } +/* This is an extra check to confirm that platform device was initialized * by a kernel vfio-platform driver. On kernels that predate vfio-platform * driver this flag obviously does not exist. In such scenarios this
drivers/crypto/bcmfs/bcmfs_vfio.c +7 -1
@@ -25,12 +25,18 @@ vfio_map_dev_obj(const char *path, const char *dev_obj,struct vfio_device_info d_info = { .argsz =sizeof (d_info) };struct vfio_region_info reg_info = { .argsz =sizeof (reg_info) }; - ret =dev_vfio_setup_device (path, dev_obj, dev_fd, &d_info); + ret =dev_vfio_setup_device (path, dev_obj, dev_fd);if (ret) {BCMFS_LOG (ERR ,"VFIO Setting for device failed" );return ret; } + ret =dev_vfio_get_device_info (*dev_fd, &d_info); +if (ret) { +BCMFS_LOG (ERR ,"VFIO Getting device info failed" ); + goto map_failed; + } +/* getting device region info*/ ret =ioctl (*dev_fd,VFIO_DEVICE_GET_REGION_INFO , ®_info);if (ret <0 ) {
lib/eal/linux/eal_vfio.c +10 -30
@@ -810,8 +810,7 @@ dev_vfio_clear_group(int vfio_group_fd)RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_setup_device) int -dev_vfio_setup_device (const char *sysfs_base,const char *dev_addr, -int *vfio_dev_fd,struct vfio_device_info *device_info) +dev_vfio_setup_device (const char *sysfs_base,const char *dev_addr,int *vfio_dev_fd) {struct vfio_group_status group_status = { .argsz =sizeof (group_status)
@@ -1031,7 +1030,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, *vfio_dev_fd =ioctl (vfio_group_fd,VFIO_GROUP_GET_DEVICE_FD , dev);if (*vfio_dev_fd >=0 ) - goto dev_get_info; + goto out; }/* get a file descriptor for the device */
@@ -1048,18 +1047,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr,return -1 ; } -/* test and setup the device */ -dev_get_info: - ret =ioctl (*vfio_dev_fd,VFIO_DEVICE_GET_INFO , device_info); -if (ret) { -EAL_LOG (ERR ,"%s cannot get device info, " -"error %i (%s)" , dev_addr, errno, -strerror (errno)); -close (*vfio_dev_fd); -close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); -return -1 ; - } +/* device is now set up */ +out:vfio_group_device_get (vfio_group_fd);return 0 ;
@@ -1288,29 +1277,20 @@ vfio_set_iommu_type(int vfio_container_fd)RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_device_info) int -dev_vfio_get_device_info (const char *sysfs_base,const char *dev_addr, -int *vfio_dev_fd,struct vfio_device_info *device_info) +dev_vfio_get_device_info (int vfio_dev_fd,struct vfio_device_info *device_info) {int ret;if (!vfio_enabled)return -1 ; -if (device_info ==NULL || *vfio_dev_fd <0 ) +if (device_info ==NULL || vfio_dev_fd <0 )return -1 ; -if (*vfio_dev_fd ==0 ) { - ret =dev_vfio_setup_device (sysfs_base, dev_addr, - vfio_dev_fd, device_info); -if (ret) -return -1 ; - }else { - ret =ioctl (*vfio_dev_fd,VFIO_DEVICE_GET_INFO , device_info); -if (ret) { -EAL_LOG (ERR ,"%s cannot get device info, error %i (%s)" , - dev_addr, errno,strerror (errno)); -return -1 ; - } + ret =ioctl (vfio_dev_fd,VFIO_DEVICE_GET_INFO , device_info); +if (ret) { +EAL_LOG (ERR ,"Cannot get device info, error %i (%s)" , errno,strerror (errno)); +return -1 ; }return 0 ;
lib/eal/linux/include/dev_vfio.h +8 -16
@@ -59,10 +59,7 @@ enum dev_vfio_module {* device location. * * @param vfio_dev_fd -* VFIO fd. -* -* @param device_info -* Device information. +* Pointer to VFIO fd, will be set to the opened device fd on success. * * @return * 0 on success.
@@ -70,8 +67,7 @@ enum dev_vfio_module {* >1 if the device cannot be managed this way. */ __rte_internal -int dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, -int *vfio_dev_fd,struct vfio_device_info *device_info); +int dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dev_fd);/** * @internal
@@ -189,26 +185,22 @@ dev_vfio_get_group_num(const char *sysfs_base, const char *dev_addr, int *iommu_* @internal * Get device information. * -* @param sysfs_base -* sysfs path prefix. -* -* @param dev_addr -* device location. +* This function retrieves VFIO device information from an already opened +* device. The device must be opened with `dev_vfio_setup_device()` first. * * @param vfio_dev_fd -* VFIO fd. +* VFIO device fd (must be a valid, already opened fd). * * @param device_info -* Device information. +* Pointer to device information structure to be filled. * * @return * 0 on success. -* <0 on failure. +* <0 on failure. */ __rte_internal int -dev_vfio_get_device_info (const char *sysfs_base,const char *dev_addr, -int *vfio_dev_fd,struct vfio_device_info *device_info); +dev_vfio_get_device_info (int vfio_dev_fd,struct vfio_device_info *device_info);/** * @internal
Signature · 1 line
2.54.0
PATCH RESEND v19 10/26 vfio: add container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
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.
--- lib/eal/linux/eal_vfio.c | 27 +++++++++++++++++++++++++++ lib/eal/linux/include/dev_vfio.h | 24 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
lib/eal/linux/eal_vfio.c +27 -0
@@ -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) intdev_vfio_container_group_bind (int container_fd,int iommu_group_num)
lib/eal/linux/include/dev_vfio.h +24 -0
@@ -264,6 +264,30 @@ __rte_internalint 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.
Signature · 1 line
2.54.0
PATCH RESEND v19 11/26 net/nbl: do not use VFIO group bind API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The NBL driver currently uses group bind API, but it is using it only to get group fd and nothing else. In context of NBL driver, this is the only usage of VFIO API's in the driver, and it is not necessary to use it for what NBL driver is trying to accomplish.
Use a direct open() call instead, store the group fd in common structure, and find group fd's opened earlier to prevent us from opening the same group fd twice.
--- drivers/net/nbl/nbl_common/nbl_userdev.c | 63 +++++++++++++++++------ drivers/net/nbl/nbl_common/nbl_userdev.h | 1 + drivers/net/nbl/nbl_include/nbl_include.h | 1 + 3 files changed, 50 insertions(+), 15 deletions(-)
drivers/net/nbl/nbl_common/nbl_userdev.c +48 -15
@@ -388,6 +388,28 @@ nbl_userdev_mem_event_callback(enum rte_mem_event type, const void *addr, size_t } } +static int +nbl_open_group_fd (int iommu_group_num) +{ +char path[PATH_MAX ]; + +snprintf (path,sizeof (path),DEV_VFIO_GROUP_FMT , iommu_group_num); +return open (path,O_RDWR ); +} + +static int +nbl_find_group_fd (int iommu_group_num) +{ +struct nbl_adapter *adapter; + + TAILQ_FOREACH(adapter, &nbl_adapter_list, next) { +if (adapter->common.iommu_group_num == iommu_group_num) +return adapter->common.groupfd; + } + +return -1 ; +} +static int nbl_mdev_map_device (struct nbl_adapter *adapter) {const struct rte_pci_device *pci_dev = adapter->pci_dev;
@@ -401,6 +423,7 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter)u64 dma_limit =NBL_USERDEV_DMA_LIMIT ;int ret, container_create =0 , container_set =0 ;int vfio_group_fd, container = nbl_default_container; +bool new_group = false;rte_pci_device_name (&pci_dev->addr, dev_name,RTE_DEV_NAME_MAX_LEN ); snprintf(pathname, sizeof(pathname),
@@ -425,11 +448,18 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) }NBL_LOG (DEBUG ,"nbl vfio container %d" , container); - vfio_group_fd =dev_vfio_container_group_bind (container, common->iommu_group_num); +rte_mcfg_mem_read_lock (); + vfio_group_fd =nbl_find_group_fd (common->iommu_group_num); +rte_mcfg_mem_read_unlock (); +if (vfio_group_fd <0 ) { + vfio_group_fd =nbl_open_group_fd (common->iommu_group_num); + new_group = true; + }if (vfio_group_fd <0 ) {NBL_LOG (ERR ,"nbl vfio group bind failed, %d" , vfio_group_fd); goto free_container; } + common->groupfd = vfio_group_fd;/* check if the group is viable */ ret =ioctl (vfio_group_fd,VFIO_GROUP_GET_STATUS , &group_status);
@@ -518,13 +548,13 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) close_fd:close (common->devfd); unregister_mem_event: -if (nbl_group_count ==1 ) { +if (container_set && nbl_group_count ==1 ) {rte_mcfg_mem_read_lock ();rte_mem_event_callback_unregister (NBL_USERDEV_EVENT_CLB_NAME ,NULL );rte_mcfg_mem_read_unlock (); } free_dma_map: -if (nbl_group_count ==1 ) { +if (container_set && nbl_group_count ==1 ) {rte_mcfg_mem_read_lock ();nbl_userdev_dma_free ();rte_mcfg_mem_read_unlock ();
@@ -535,8 +565,8 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter) nbl_group_count--; } free_group: -close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +if (new_group) +close (vfio_group_fd); free_container:if (container_create)dev_vfio_container_destroy (container);
@@ -547,21 +577,24 @@ static int nbl_mdev_unmap_device(struct nbl_adapter *adapter) {struct nbl_common_info *common = &adapter->common;int vfio_group_fd, ret; +bool last_group_user;rte_mcfg_mem_read_lock ();TAILQ_REMOVE (&nbl_adapter_list, adapter, next);close (common->devfd); - vfio_group_fd =dev_vfio_container_group_bind (nbl_default_container, - common->iommu_group_num); + common->devfd =-1 ; + vfio_group_fd = common->groupfd; + last_group_user =nbl_find_group_fd (common->iommu_group_num) <0 ;NBL_LOG (DEBUG ,"close vfio_group_fd %d" , vfio_group_fd); - ret =ioctl (vfio_group_fd,VFIO_GROUP_UNSET_CONTAINER , &nbl_default_container); -if (ret) -NBL_LOG (ERR ,"unset container, error %i (%s) %d" , - errno,strerror (errno), ret); - nbl_group_count--; - ret =dev_vfio_container_group_unbind (nbl_default_container, common->iommu_group_num); -if (ret) -NBL_LOG (ERR ,"vfio container group unbind failed %d" , ret); +if (last_group_user) { + ret =ioctl (vfio_group_fd,VFIO_GROUP_UNSET_CONTAINER , &nbl_default_container); +if (ret) +NBL_LOG (ERR ,"unset container, error %i (%s) %d" , + errno,strerror (errno), ret); + nbl_group_count--; +close (vfio_group_fd); + common->groupfd =-1 ; + }if (!nbl_group_count) {rte_mem_event_callback_unregister (NBL_USERDEV_EVENT_CLB_NAME ,NULL );nbl_userdev_dma_free ();
drivers/net/nbl/nbl_common/nbl_userdev.h +1 -0
@@ -11,6 +11,7 @@#define NBL_USERDEV_INIT_COMMON (common) do { \ typeof(common) _comm = (common); \ _comm->devfd = -1; \ + _comm->groupfd = -1; \ _comm->eventfd = -1; \ _comm->specific_dma = false; \ _comm->dma_set_msb = false; \
drivers/net/nbl/nbl_include/nbl_include.h +1 -0
@@ -132,6 +132,7 @@ struct nbl_common_info {u16 vsi_id;u16 instance_id;int devfd; +int groupfd;int eventfd;int ifindex;int iommu_group_num;
Signature · 1 line
2.54.0
PATCH RESEND v19 12/26 net/ntnic: use container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The NTNIC driver uses VFIO group bind/unbind functionality for container device assignment purposes. Use the new container device assignment API instead to provide clearer semantics.
--- drivers/net/ntnic/ntnic_vfio.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/net/ntnic/ntnic_vfio.c +9 -21
@@ -28,7 +28,6 @@ nt_vfio_vf_num(const struct rte_pci_device *pdev)/* Internal API */ struct vfio_dev {int container_fd; -int group_fd;int dev_fd;uint64_t iova_addr; };
@@ -50,7 +49,6 @@ nthw_vfio_setup(struct rte_pci_device *dev) {int ret;char devname[RTE_DEV_NAME_MAX_LEN ] = {0 }; -int iommu_group_num;int vf_num;struct vfio_dev *vfio;
@@ -66,14 +64,9 @@ nthw_vfio_setup(struct rte_pci_device *dev) } vfio->dev_fd =-1 ; - vfio->group_fd =-1 ; vfio->iova_addr =START_VF_IOVA ;rte_pci_device_name (&dev->addr, devname,RTE_DEV_NAME_MAX_LEN ); - ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, &iommu_group_num); -if (ret <=0 ) -return -1 ; -if (vf_num ==0 ) {/* use default container for pf0 */ vfio->container_fd =DEV_VFIO_DEFAULT_CONTAINER_FD ;
@@ -86,17 +79,14 @@ nthw_vfio_setup(struct rte_pci_device *dev) "VFIO device setup failed. VFIO container creation failed.");return -1 ; } - } - - vfio->group_fd =dev_vfio_container_group_bind (vfio->container_fd, iommu_group_num); - -if (vfio->group_fd <0 ) { -NT_LOG (ERR ,NTNIC , -"VFIO device setup failed. VFIO container group bind failed." ); - goto err; - } + ret =dev_vfio_container_assign_device (vfio->container_fd, +rte_pci_get_sysfs_path (), devname); +if (ret <0 ) { +NT_LOG (ERR ,NTNIC , +"VFIO device setup failed. Assign device to container failed." ); + goto err; + } -if (vf_num >0 ) {if (rte_pci_map_device (dev)) {NT_LOG (ERR ,NTNIC ,"Map VFIO device failed. is the vfio-pci driver loaded?" );
@@ -106,10 +96,8 @@ nthw_vfio_setup(struct rte_pci_device *dev) vfio->dev_fd =rte_intr_dev_fd_get (dev->intr_handle); -NT_LOG (DBG ,NTNIC , -"%s: VFIO id=%d, dev_fd=%d, container_fd=%d, group_fd=%d, iommu_group_num=%d" , - dev->name, vf_num, vfio->dev_fd, vfio->container_fd, vfio->group_fd, - iommu_group_num); +NT_LOG (DBG ,NTNIC ,"%s: VFIO id=%d, dev_fd=%d, container_fd=%d" , + dev->name, vf_num, vfio->dev_fd, vfio->container_fd);return vf_num;
Signature · 1 line
2.54.0
PATCH RESEND v19 13/26 vdpa/ifc: use container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The IFC vDPA driver uses VFIO group bind/unbind functionality for container device assignment purposes. Use the new container device assignment API instead to provide clearer semantics. Since group API is no longer used after these changes, remove its implementation.
--- drivers/vdpa/ifc/ifcvf_vdpa.c | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-)
drivers/vdpa/ifc/ifcvf_vdpa.c +3 -31
@@ -59,7 +59,6 @@ struct ifcvf_internal {struct ifcvf_hw hw;int configured;int vfio_container_fd; -int vfio_group_fd;int vfio_dev_fd;rte_thread_t tid;/* thread for notify relay */ rte_thread_t intr_tid;/* thread for config space change interrupt relay */
@@ -175,28 +174,19 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal) {struct rte_pci_device *dev = internal->pdev;char devname[RTE_DEV_NAME_MAX_LEN ] = {0 }; -int iommu_group_num; -int i, ret; +int i; internal->vfio_dev_fd =-1 ; - internal->vfio_group_fd =-1 ; internal->vfio_container_fd =-1 ;rte_pci_device_name (&dev->addr, devname,RTE_DEV_NAME_MAX_LEN ); - ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), devname, - &iommu_group_num); -if (ret <=0 ) { -DRV_LOG (ERR ,"%s failed to get IOMMU group" , devname); -return -1 ; - } internal->vfio_container_fd =dev_vfio_container_create ();if (internal->vfio_container_fd <0 )return -1 ; - internal->vfio_group_fd =dev_vfio_container_group_bind ( - internal->vfio_container_fd, iommu_group_num); -if (internal->vfio_group_fd <0 ) +if (dev_vfio_container_assign_device (internal->vfio_container_fd, +rte_pci_get_sysfs_path (), devname) <0 ) goto err;if (rte_pci_map_device (dev))
@@ -1214,22 +1204,6 @@ ifcvf_set_features(int vid)return 0 ; } -static int -ifcvf_get_vfio_group_fd (int vid) -{ -struct rte_vdpa_device *vdev; -struct internal_list *list; - - vdev =rte_vhost_get_vdpa_device (vid); - list =find_internal_resource_by_vdev (vdev); -if (list ==NULL ) { -DRV_LOG (ERR ,"Invalid vDPA device: %p" , vdev); -return -1 ; - } - -return list->internal->vfio_group_fd; -} -static int ifcvf_get_vfio_device_fd (int vid) {
@@ -1475,7 +1449,6 @@ static struct rte_vdpa_dev_ops ifcvf_net_ops = { .set_vring_state = ifcvf_set_vring_state, .set_features = ifcvf_set_features, .migration_done = NULL, - .get_vfio_group_fd = ifcvf_get_vfio_group_fd, .get_vfio_device_fd = ifcvf_get_vfio_device_fd, .get_notify_area = ifcvf_get_notify_area, .get_dev_type = ifcvf_get_device_type,
@@ -1606,7 +1579,6 @@ static struct rte_vdpa_dev_ops ifcvf_blk_ops = { .dev_close = ifcvf_dev_close, .set_vring_state = ifcvf_set_vring_state, .migration_done = NULL, - .get_vfio_group_fd = ifcvf_get_vfio_group_fd, .get_vfio_device_fd = ifcvf_get_vfio_device_fd, .get_notify_area = ifcvf_get_notify_area, .get_config = ifcvf_blk_get_config,
Signature · 1 line
2.54.0
PATCH RESEND v19 14/26 vdpa/nfp: use container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The NFP vDPA driver uses VFIO group bind/unbind functionality for container device assignment purposes. Use the new container device assignment API instead to provide clearer semantics. Since group API is no longer used after these changes, remove its implementation.
--- drivers/vdpa/nfp/nfp_vdpa.c | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-)
drivers/vdpa/nfp/nfp_vdpa.c +5 -32
@@ -36,9 +36,7 @@ struct nfp_vdpa_dev {struct nfp_vdpa_hw hw;int vfio_container_fd; -int vfio_group_fd;int vfio_dev_fd; -int iommu_group;rte_thread_t tid;/**< Thread for notify relay */ int epoll_fd;
@@ -120,33 +118,26 @@ nfp_vdpa_vfio_setup(struct nfp_vdpa_dev *device)struct rte_pci_device *pci_dev = device->pci_dev;rte_pci_device_name (&pci_dev->addr, dev_name,RTE_DEV_NAME_MAX_LEN ); - ret =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, - &device->iommu_group); -if (ret <=0 ) -return -1 ; device->vfio_container_fd =dev_vfio_container_create ();if (device->vfio_container_fd <0 )return -1 ; - device->vfio_group_fd =dev_vfio_container_group_bind ( - device->vfio_container_fd, device->iommu_group); -if (device->vfio_group_fd <0 ) + ret =dev_vfio_container_assign_device (device->vfio_container_fd, +rte_pci_get_sysfs_path (), dev_name); +if (ret <0 ) goto container_destroy; -DRV_VDPA_LOG (DEBUG ,"The container_fd=%d, group_fd=%d." , - device->vfio_container_fd, device->vfio_group_fd); +DRV_VDPA_LOG (DEBUG ,"container_fd=%d" , device->vfio_container_fd); ret =rte_pci_map_device (pci_dev);if (ret !=0 ) - goto group_unbind; + goto container_destroy; device->vfio_dev_fd =rte_intr_dev_fd_get (pci_dev->intr_handle);return 0 ; -group_unbind: -dev_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group); container_destroy:dev_vfio_container_destroy (device->vfio_container_fd);
@@ -157,7 +148,6 @@ static void nfp_vdpa_vfio_teardown(struct nfp_vdpa_dev *device) {rte_pci_unmap_device (device->pci_dev); -dev_vfio_container_group_unbind (device->vfio_container_fd, device->iommu_group);dev_vfio_container_destroy (device->vfio_container_fd); }
@@ -1023,22 +1013,6 @@ nfp_vdpa_dev_close(int vid)return 0 ; } -static int -nfp_vdpa_get_vfio_group_fd (int vid) -{ -struct rte_vdpa_device *vdev; -struct nfp_vdpa_dev_node *node; - - vdev =rte_vhost_get_vdpa_device (vid); - node =nfp_vdpa_find_node_by_vdev (vdev); -if (node ==NULL ) { -DRV_VDPA_LOG (ERR ,"Invalid vDPA device: %p." , vdev); -return -ENODEV ; - } - -return node->device->vfio_group_fd; -} -static int nfp_vdpa_get_vfio_device_fd (int vid) {
@@ -1190,7 +1164,6 @@ struct rte_vdpa_dev_ops nfp_vdpa_ops = { .dev_close = nfp_vdpa_dev_close, .set_vring_state = nfp_vdpa_set_vring_state, .set_features = nfp_vdpa_set_features, - .get_vfio_group_fd = nfp_vdpa_get_vfio_group_fd, .get_vfio_device_fd = nfp_vdpa_get_vfio_device_fd, .get_notify_area = nfp_vdpa_get_notify_area, };
Signature · 1 line
2.54.0
PATCH RESEND v19 15/26 vdpa/sfc: use container device assignment API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The SFC vDPA driver uses VFIO group bind/unbind functionality for container device assignment purposes. Use the new container device assignment API instead to provide clearer semantics.
--- drivers/vdpa/sfc/sfc_vdpa.c | 39 +++++++------------------------------ drivers/vdpa/sfc/sfc_vdpa.h | 2 -- 2 files changed, 7 insertions(+), 34 deletions(-)
drivers/vdpa/sfc/sfc_vdpa.c +7 -32
@@ -80,22 +80,12 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva) goto fail_container_create; } - rc =dev_vfio_get_group_num (rte_pci_get_sysfs_path (), dev_name, - &sva->iommu_group_num); -if (rc <=0 ) { -sfc_vdpa_err (sva,"failed to get IOMMU group for %s : %s" , - dev_name,rte_strerror (-rc)); - goto fail_get_group_num; - } - - sva->vfio_group_fd = -dev_vfio_container_group_bind (sva->vfio_container_fd, - sva->iommu_group_num); -if (sva->vfio_group_fd <0 ) { -sfc_vdpa_err (sva, -"failed to bind IOMMU group %d to container %d" , - sva->iommu_group_num, sva->vfio_container_fd); - goto fail_group_bind; + rc =dev_vfio_container_assign_device (sva->vfio_container_fd, +rte_pci_get_sysfs_path (), dev_name); +if (rc <0 ) { +sfc_vdpa_err (sva,"failed to assign device %s to container %d" , + dev_name, sva->vfio_container_fd); + goto fail_device_assign; }if (rte_pci_map_device (dev) !=0 ) {
@@ -109,15 +99,7 @@ sfc_vdpa_vfio_setup(struct sfc_vdpa_adapter *sva)return 0 ; fail_pci_map_device: -if (dev_vfio_container_group_unbind (sva->vfio_container_fd, - sva->iommu_group_num) !=0 ) { -sfc_vdpa_err (sva, -"failed to unbind IOMMU group %d from container %d" , - sva->iommu_group_num, sva->vfio_container_fd); - } - -fail_group_bind: -fail_get_group_num: +fail_device_assign:if (dev_vfio_container_destroy (sva->vfio_container_fd) !=0 ) {sfc_vdpa_err (sva,"failed to destroy container %d" , sva->vfio_container_fd);
@@ -132,13 +114,6 @@ sfc_vdpa_vfio_teardown(struct sfc_vdpa_adapter *sva) {rte_pci_unmap_device (sva->pdev); -if (dev_vfio_container_group_unbind (sva->vfio_container_fd, - sva->iommu_group_num) !=0 ) { -sfc_vdpa_err (sva, -"failed to unbind IOMMU group %d from container %d" , - sva->iommu_group_num, sva->vfio_container_fd); - } -if (dev_vfio_container_destroy (sva->vfio_container_fd) !=0 ) { sfc_vdpa_err(sva, "failed to destroy container %d",
drivers/vdpa/sfc/sfc_vdpa.h +0 -2
@@ -70,10 +70,8 @@ struct sfc_vdpa_adapter {sfc_vdpa_filter_t filters; -int vfio_group_fd;int vfio_dev_fd;int vfio_container_fd; -int iommu_group_num;struct sfc_vdpa_ops_data *ops_data; };
Signature · 1 line
2.54.0
PATCH RESEND v19 16/26 vhost: remove group-related API from driver
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
The vDPA driver API has "get_vfio_group_fd" in its ops structure, but no driver is using it any more, as better API's were added and implemented. Remove this API from vDPA ops structure.
---
Changes since v18:
- squashed vdpa/mlx5 update,
--- doc/guides/prog_guide/vhost_lib.rst | 4 ---- doc/guides/rel_notes/deprecation.rst | 4 ---- doc/guides/rel_notes/release_26_11.rst | 3 +++ drivers/vdpa/mlx5/mlx5_vdpa.c | 1 - lib/vhost/vdpa_driver.h | 3 --- 5 files changed, 3 insertions(+), 12 deletions(-)
doc/guides/prog_guide/vhost_lib.rst +0 -4
@@ -471,10 +471,6 @@ Finally, a set of device ops is defined for device specific operations: Called to allow the device to respond to RARP sending. -* ``get_vfio_group_fd`` - - Called to get the VFIO group fd of the device. - * ``get_vfio_device_fd`` Called to get the VFIO device fd of the device.
doc/guides/rel_notes/deprecation.rst +0 -4
@@ -29,10 +29,6 @@ Deprecation Notices Use the ``-S <service-corelist>`` parameter instead to specify the cores to be used for background services in DPDK. -* vdpa: The vDPA driver API will no longer offer ``get_vfio_group_fd`` - as part of its internal API. All drivers will be adjusted - to use the new unified VFIO container device assignment API. - * rte_smp_*mb: These APIs provide full barrier functionality. However, many use cases do not require full barriers. To support such use cases, DPDK has adopted atomic operations from
doc/guides/rel_notes/release_26_11.rst +3 -0
@@ -344,6 +344,9 @@ API Changes ``rte_reorder_seqn``, ``rte_reorder_drain_up_to_seqn``, ``rte_reorder_min_seqn_set`` and ``rte_reorder_memory_footprint_get``. +* vhost: Removed ``get_vfio_group_fd`` from ``struct rte_vdpa_dev_ops``. + vDPA drivers should now use the VFIO container device assignment API. + * telemetry: Promoted the following API from experimental to stable: * ``rte_tel_data_add_array_uint_hex``
drivers/vdpa/mlx5/mlx5_vdpa.c +0 -1
@@ -523,7 +523,6 @@ static struct rte_vdpa_dev_ops mlx5_vdpa_ops = { .set_vring_state = mlx5_vdpa_set_vring_state, .set_features = mlx5_vdpa_features_set, .migration_done = NULL, - .get_vfio_group_fd = NULL, .get_vfio_device_fd = mlx5_vdpa_get_device_fd, .get_notify_area = mlx5_vdpa_get_notify_area, .get_stats_names = mlx5_vdpa_get_stats_names,
lib/vhost/vdpa_driver.h +0 -3
@@ -50,9 +50,6 @@ struct rte_vdpa_dev_ops {/** Destination operations when migration done */ int (*migration_done)(int vid); -/** Get the vfio group fd */ -int (*get_vfio_group_fd)(int vid); -/** Get the vfio device fd */ int (*get_vfio_device_fd)(int vid);
Signature · 1 line
2.54.0
PATCH RESEND v19 17/26 vfio: remove group-based API
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
All drivers have been adjusted to not use the VFIO group API directly and instead rely on container device assignment model, so the group API is no longer useful and can be removed.
--- lib/eal/linux/eal_vfio.c | 48 +++++++++++------------ lib/eal/linux/eal_vfio.h | 2 + lib/eal/linux/eal_vfio_mp_sync.c | 2 +- lib/eal/linux/include/dev_vfio.h | 66 -------------------------------- 4 files changed, 26 insertions(+), 92 deletions(-)
lib/eal/linux/eal_vfio.c +23 -25
@@ -114,6 +114,9 @@ static int vfio_noiommu_dma_mem_map(int, uint64_t, uint64_t, uint64_t, int);static int vfio_dma_mem_map (struct vfio_config *vfio_cfg,uint64_t vaddr,uint64_t iova,uint64_t len,int do_map); +static int vfio_container_group_bind (int container_fd,int iommu_group_num); +static int vfio_container_group_unbind (int container_fd,int iommu_group_num); +/* IOMMU types we support */ static const struct vfio_iommu_type iommu_types[] = {/* x86 IOMMU, otherwise known as type 1 */
@@ -579,9 +582,8 @@ get_vfio_cfg_by_container_fd(int container_fd)return NULL ; } -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_group_fd)int -dev_vfio_get_group_fd (int iommu_group_num) +vfio_get_group_fd_by_num (int iommu_group_num) {struct vfio_config *vfio_cfg;
@@ -781,9 +783,8 @@ vfio_sync_default_container(void)return -1 ; } -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_clear_group) -int -dev_vfio_clear_group (int vfio_group_fd) +static int +vfio_clear_group (int vfio_group_fd) {int i;struct vfio_config *vfio_cfg;
@@ -842,7 +843,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ;/* get the actual group fd */ - vfio_group_fd =dev_vfio_get_group_fd (iommu_group_num); + vfio_group_fd =vfio_get_group_fd_by_num (iommu_group_num);if (vfio_group_fd <0 && vfio_group_fd != -ENOENT )return -1 ;
@@ -868,14 +869,14 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deEAL_LOG (ERR ,"%s cannot get VFIO group status, " "error %i (%s)" , dev_addr, errno,strerror (errno));close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }else if (!(group_status.flags &VFIO_GROUP_FLAGS_VIABLE )) {EAL_LOG (ERR ,"%s VFIO group is not viable! " "Not all devices in IOMMU group bound to VFIO or unbound" , dev_addr);close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }
@@ -896,7 +897,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de"%s cannot add VFIO group to container, error " "%i (%s)", dev_addr, errno, strerror(errno));close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }
@@ -920,7 +921,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de"%s failed to select IOMMU type" , dev_addr);close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }/* lock memory hotplug before mapping and release it
@@ -937,7 +938,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de"%i (%s)" , dev_addr, errno, strerror(errno));close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);rte_mcfg_mem_read_unlock ();return -1 ; }
@@ -1006,7 +1007,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deif (ret <0 ) {EAL_LOG (ERR ,"Could not sync default VFIO container" );close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }/* we have successfully initialized VFIO, notify user */
@@ -1043,7 +1044,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deEAL_LOG (WARNING ,"Getting a vfio_dev_fd for %s failed" , dev_addr);close (vfio_group_fd); -dev_vfio_clear_group (vfio_group_fd); +vfio_clear_group (vfio_group_fd);return -1 ; }
@@ -1084,10 +1085,9 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, }/* get the actual group fd */ - vfio_group_fd =dev_vfio_get_group_fd (iommu_group_num); + vfio_group_fd =vfio_get_group_fd_by_num (iommu_group_num);if (vfio_group_fd <0 ) { -EAL_LOG (INFO ,"dev_vfio_get_group_fd failed for %s" , - dev_addr); +EAL_LOG (INFO ,"vfio_get_group_fd_by_num failed for %s" , dev_addr); ret = vfio_group_fd; goto out; }
@@ -1122,7 +1122,7 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, goto out; } -if (dev_vfio_clear_group (vfio_group_fd) <0 ) { +if (vfio_clear_group (vfio_group_fd) <0 ) {EAL_LOG (INFO ,"Error when clearing group for %s" , dev_addr); ret =-1 ;
@@ -2177,7 +2177,7 @@ dev_vfio_container_destroy(int container_fd)for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++)if (vfio_cfg->vfio_groups[i].group_num !=-1 ) -dev_vfio_container_group_unbind (container_fd, +vfio_container_group_unbind (container_fd, vfio_cfg->vfio_groups[i].group_num);close (container_fd);
@@ -2205,7 +2205,7 @@ dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base,return -1 ; } - ret =dev_vfio_container_group_bind (vfio_container_fd, iommu_group_num); + ret =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);
@@ -2215,9 +2215,8 @@ dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base,return 0 ; } -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_container_group_bind) -int -dev_vfio_container_group_bind (int container_fd,int iommu_group_num) +static int +vfio_container_group_bind (int container_fd,int iommu_group_num) {struct vfio_config *vfio_cfg;
@@ -2233,9 +2232,8 @@ dev_vfio_container_group_bind(int container_fd, int iommu_group_num)return vfio_get_group_fd (vfio_cfg, iommu_group_num); } -RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_container_group_unbind) -int -dev_vfio_container_group_unbind (int container_fd,int iommu_group_num) +static int +vfio_container_group_unbind (int container_fd,int iommu_group_num) {struct vfio_group *cur_grp =NULL ;struct vfio_config *vfio_cfg;
lib/eal/linux/eal_vfio.h +2 -0
@@ -51,6 +51,8 @@ vfio_set_iommu_type(int vfio_container_fd);int vfio_get_iommu_type (void ); +int vfio_get_group_fd_by_num (int iommu_group_num); +/* check if we have any supported extensions */ int vfio_has_supported_extensions (int vfio_container_fd);
lib/eal/linux/eal_vfio_mp_sync.c +1 -1
@@ -34,7 +34,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)case SOCKET_REQ_GROUP : r->req =SOCKET_REQ_GROUP ; r->group_num = m->group_num; - fd =dev_vfio_get_group_fd (m->group_num); + fd =vfio_get_group_fd_by_num (m->group_num);if (fd <0 && fd != -ENOENT ) r->result =SOCKET_ERR ;else if (fd == -ENOENT )
lib/eal/linux/include/dev_vfio.h +0 -66
84 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH RESEND v19 18/26 vfio: rename some internal types and macros
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Some types and macros will be used in multiple code units in later commits.
Prefix them with vfio_/VFIO_.
Rename vfio_config as vfio_container and pass it instead of the container FD.
--- lib/eal/linux/eal_vfio.c | 548 ++++++++++++++----------------- lib/eal/linux/eal_vfio.h | 50 ++- lib/eal/linux/eal_vfio_mp_sync.c | 26 +- 3 files changed, 298 insertions(+), 326 deletions(-)
lib/eal/linux/eal_vfio.c +245 -303
@@ -29,36 +29,9 @@#define VFIO_MEM_EVENT_CLB_NAME "vfio_mem_event_clb" -/* hot plug/unplug of VFIO groups may cause all DMA maps to be dropped. we can -* recreate the mappings for DPDK segments, but we cannot do so for memory that -* was registered by the user themselves, so we need to store the user mappings -* somewhere, to recreate them later. -*/ -#define EAL_VFIO_MAX_USER_MEM_MAPS 256 -struct user_mem_map { -uint64_t addr;/**< start VA */ -uint64_t iova;/**< start IOVA */ -uint64_t len;/**< total length of the mapping */ -uint64_t chunk;/**< this mapping can be split in chunks of this size */ -}; - -struct user_mem_maps { -rte_spinlock_recursive_t lock; -int n_maps; -struct user_mem_map maps[EAL_VFIO_MAX_USER_MEM_MAPS ]; -}; - -struct vfio_config { -int vfio_container_fd; -int vfio_active_groups; -const struct vfio_iommu_type *vfio_iommu_type; -struct vfio_group vfio_groups[RTE_MAX_VFIO_GROUPS ]; -struct user_mem_maps mem_maps; -}; -/* per-process VFIO config */ -static struct vfio_config vfio_cfgs[RTE_MAX_VFIO_CONTAINERS ]; -static struct vfio_config *default_vfio_cfg = &vfio_cfgs[0 ]; +static struct vfio_container vfio_containers[RTE_MAX_VFIO_CONTAINERS ]; +static struct vfio_container *default_vfio_cfg = &vfio_containers[0 ];/* whether VFIO is enabled (usable) in this process */ static bool vfio_enabled;
@@ -105,14 +78,14 @@ vfio_check_module(enum dev_vfio_module module)return 1 ; } -static int vfio_type1_dma_map (int ); -static int vfio_type1_dma_mem_map (int ,uint64_t ,uint64_t ,uint64_t ,int ); -static int vfio_spapr_dma_map (int ); -static int vfio_spapr_dma_mem_map (int ,uint64_t ,uint64_t ,uint64_t ,int ); -static int vfio_noiommu_dma_map (int ); -static int vfio_noiommu_dma_mem_map (int ,uint64_t ,uint64_t ,uint64_t ,int ); -static int vfio_dma_mem_map (struct vfio_config *vfio_cfg,uint64_t vaddr, -uint64_t iova,uint64_t len,int do_map); +static int vfio_type1_dma_map (struct vfio_container *); +static int vfio_type1_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int ); +static int vfio_spapr_dma_map (struct vfio_container *); +static int vfio_spapr_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int ); +static int vfio_noiommu_dma_map (struct vfio_container *); +static int vfio_noiommu_dma_mem_map (struct vfio_container *,uint64_t ,uint64_t ,uint64_t ,int ); +static int vfio_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova, +uint64_t len,int do_map);static int vfio_container_group_bind (int container_fd,int iommu_group_num);static int vfio_container_group_unbind (int container_fd,int iommu_group_num);
@@ -146,10 +119,9 @@ static const struct vfio_iommu_type iommu_types[] = { };static int -is_null_map (const struct user_mem_map *map) +is_null_map (const struct vfio_user_mem_map *map) { -return map->addr ==0 && map->iova ==0 && - map->len ==0 && map->chunk ==0 ; +return map->addr ==0 && map->iova ==0 && map->len ==0 && map->chunk ==0 ; }/* we may need to merge user mem maps together in case of user mapping/unmapping
@@ -158,8 +130,8 @@ is_null_map(const struct user_mem_map *map)static int user_mem_map_cmp (const void *a,const void *b) { -const struct user_mem_map *umm_a = a; -const struct user_mem_map *umm_b = b; +const struct vfio_user_mem_map *umm_a = a; +const struct vfio_user_mem_map *umm_b = b;/* move null entries to end */ if (is_null_map (umm_a))
@@ -196,14 +168,14 @@ user_mem_map_cmp(const void *a, const void *b)* mappings that will be kept. */ static int -process_maps (struct user_mem_map *src,size_t src_len, -struct user_mem_map newmap[2 ],uint64_t vaddr,uint64_t len) +process_maps (struct vfio_user_mem_map *src,size_t src_len,struct vfio_user_mem_map newmap[2 ], +uint64_t vaddr,uint64_t len) { -struct user_mem_map *src_first = &src[0 ]; -struct user_mem_map *src_last = &src[src_len -1 ]; -struct user_mem_map *dst_first = &newmap[0 ]; +struct vfio_user_mem_map *src_first = &src[0 ]; +struct vfio_user_mem_map *src_last = &src[src_len -1 ]; +struct vfio_user_mem_map *dst_first = &newmap[0 ];/* we can get at most two new segments */ -struct user_mem_map *dst_last = &newmap[1 ]; +struct vfio_user_mem_map *dst_last = &newmap[1 ];uint64_t first_off = vaddr - src_first->addr;uint64_t last_off = (src_last->addr + src_last->len) - (vaddr + len);int newmap_len =0 ;
@@ -218,8 +190,8 @@ process_maps(struct user_mem_map *src, size_t src_len, }if (last_off !=0 ) {/* if we had start offset, we have two segments */ -struct user_mem_map *last = - first_off ==0 ? dst_first : dst_last; +struct vfio_user_mem_map *last = first_off ==0 ? dst_first : dst_last; + last->addr = (src_last->addr + src_last->len) - last_off; last->iova = (src_last->iova + src_last->len) - last_off; last->len = last_off;
@@ -232,15 +204,15 @@ process_maps(struct user_mem_map *src, size_t src_len,/* erase certain maps from the list */ static void -delete_maps (struct user_mem_maps *user_mem_maps,struct user_mem_map *del_maps, +delete_maps (struct vfio_user_mem_maps *user_mem_maps,struct vfio_user_mem_map *del_maps,size_t n_del) {unsigned int i;size_t j;for (i =0 , j =0 ; i <RTE_DIM (user_mem_maps->maps) && j < n_del; i++) { -struct user_mem_map *left = &user_mem_maps->maps[i]; -struct user_mem_map *right = &del_maps[j]; +struct vfio_user_mem_map *left = &user_mem_maps->maps[i]; +struct vfio_user_mem_map *right = &del_maps[j];if (user_mem_map_cmp (left, right) ==0 ) {memset (left,0 ,sizeof (*left));
@@ -251,15 +223,15 @@ delete_maps(struct user_mem_maps *user_mem_maps, struct user_mem_map *del_maps, }static void -copy_maps (struct user_mem_maps *user_mem_maps,struct user_mem_map *add_maps, +copy_maps (struct vfio_user_mem_maps *user_mem_maps,struct vfio_user_mem_map *add_maps,size_t n_add) {unsigned int i;size_t j;for (i =0 , j =0 ; i <RTE_DIM (user_mem_maps->maps) && j < n_add; i++) { -struct user_mem_map *left = &user_mem_maps->maps[i]; -struct user_mem_map *right = &add_maps[j]; +struct vfio_user_mem_map *left = &user_mem_maps->maps[i]; +struct vfio_user_mem_map *right = &add_maps[j];/* insert into empty space */ if (is_null_map (left)) {
@@ -272,10 +244,10 @@ copy_maps(struct user_mem_maps *user_mem_maps, struct user_mem_map *add_maps,/* try merging two maps into one, return 1 if succeeded */ static int -merge_map (struct user_mem_map *left,struct user_mem_map *right) +merge_map (struct vfio_user_mem_map *left,struct vfio_user_mem_map *right) {/* merge the same maps into one */ -if (memcmp (left, right,sizeof (struct user_mem_map )) ==0 ) +if (memcmp (left, right,sizeof (struct vfio_user_mem_map )) ==0 ) goto out;if (left->addr + left->len != right->addr)
@@ -293,13 +265,12 @@ merge_map(struct user_mem_map *left, struct user_mem_map *right) }static bool -addr_is_chunk_aligned (struct user_mem_map *maps,size_t n_maps, -uint64_t vaddr,uint64_t iova) +addr_is_chunk_aligned (struct vfio_user_mem_map *maps,size_t n_maps,uint64_t vaddr,uint64_t iova) {unsigned int i;for (i =0 ; i < n_maps; i++) { -struct user_mem_map *map = &maps[i]; +struct vfio_user_mem_map *map = &maps[i];uint64_t map_va_end = map->addr + map->len;uint64_t map_iova_end = map->iova + map->len;uint64_t map_va_off = vaddr - map->addr;
@@ -312,17 +283,15 @@ addr_is_chunk_aligned(struct user_mem_map *maps, size_t n_maps,bool addr_is_aligned = (map_va_off % map->chunk) ==0 ;bool iova_is_aligned = (map_iova_off % map->chunk) ==0 ; -if (addr_in_map && iova_in_map && - addr_is_aligned && iova_is_aligned) +if (addr_in_map && iova_in_map && addr_is_aligned && iova_is_aligned)return true; }return false; }static int -find_user_mem_maps (struct user_mem_maps *user_mem_maps,uint64_t addr, -uint64_t iova,uint64_t len,struct user_mem_map *dst, -size_t dst_len) +find_user_mem_maps (struct vfio_user_mem_maps *user_mem_maps,uint64_t addr,uint64_t iova, +uint64_t len,struct vfio_user_mem_map *dst,size_t dst_len) {uint64_t va_end = addr + len;uint64_t iova_end = iova + len;
@@ -331,18 +300,14 @@ find_user_mem_maps(struct user_mem_maps *user_mem_maps, uint64_t addr,int i, ret;for (i =0 , j =0 ; i < user_mem_maps->n_maps; i++) { -struct user_mem_map *map = &user_mem_maps->maps[i]; +struct vfio_user_mem_map *map = &user_mem_maps->maps[i];uint64_t map_va_end = map->addr + map->len;uint64_t map_iova_end = map->iova + map->len; -bool start_addr_in_map = (addr >= map->addr) && - (addr < map_va_end); -bool end_addr_in_map = (va_end > map->addr) && - (va_end <= map_va_end); -bool start_iova_in_map = (iova >= map->iova) && - (iova < map_iova_end); -bool end_iova_in_map = (iova_end > map->iova) && - (iova_end <= map_iova_end); +bool start_addr_in_map = (addr >= map->addr) && (addr < map_va_end); +bool end_addr_in_map = (va_end > map->addr) && (va_end <= map_va_end); +bool start_iova_in_map = (iova >= map->iova) && (iova < map_iova_end); +bool end_iova_in_map = (iova_end > map->iova) && (iova_end <= map_iova_end);/* do we have space in temporary map? */ if (j == dst_len) {
@@ -371,16 +336,16 @@ find_user_mem_maps(struct user_mem_maps *user_mem_maps, uint64_t addr,/* this will sort all user maps, and merge/compact any adjacent maps */ static void -compact_user_maps (struct user_mem_maps *user_mem_maps) +compact_user_maps (struct vfio_user_mem_maps *user_mem_maps) {unsigned int i; -qsort (user_mem_maps->maps,RTE_DIM (user_mem_maps->maps), -sizeof (user_mem_maps->maps[0 ]), user_mem_map_cmp); +qsort (user_mem_maps->maps,RTE_DIM (user_mem_maps->maps),sizeof (user_mem_maps->maps[0 ]), + user_mem_map_cmp);/* we'll go over the list backwards when merging */ for (i =RTE_DIM (user_mem_maps->maps) -2 ; i !=0 ; i--) { -struct user_mem_map *l, *r; +struct vfio_user_mem_map *l, *r; l = &user_mem_maps->maps[i]; r = &user_mem_maps->maps[i +1 ];
@@ -396,8 +361,8 @@ compact_user_maps(struct user_mem_maps *user_mem_maps)/* the entries are still sorted, but now they have holes in them, so * sort the list again. */ -qsort (user_mem_maps->maps,RTE_DIM (user_mem_maps->maps), -sizeof (user_mem_maps->maps[0 ]), user_mem_map_cmp); +qsort (user_mem_maps->maps,RTE_DIM (user_mem_maps->maps),sizeof (user_mem_maps->maps[0 ]), + user_mem_map_cmp); } static int
@@ -444,7 +409,7 @@ vfio_open_group_fd(int iommu_group_num, bool mp_request)/* if we're in a secondary process, request group fd from the primary * process via mp channel. */ - p->req =SOCKET_REQ_GROUP ; + p->req =VFIO_SOCKET_REQ_GROUP ; p->group_num = iommu_group_num;strcpy (mp_req.name,EAL_VFIO_MP ); mp_req.len_param =sizeof (*p);
@@ -455,9 +420,9 @@ vfio_open_group_fd(int iommu_group_num, bool mp_request) mp_reply.nb_received == 1) { mp_rep = &mp_reply.msgs[0 ]; p = (struct vfio_mp_param *)mp_rep->param; -if (p->result ==SOCKET_OK && mp_rep->num_fds ==1 ) { +if (p->result ==VFIO_SOCKET_OK && mp_rep->num_fds ==1 ) { vfio_group_fd = mp_rep->fds[0 ]; - }else if (p->result ==SOCKET_NO_FD ) { + }else if (p->result ==VFIO_SOCKET_NO_FD ) {EAL_LOG (ERR ,"Bad VFIO group fd" ); vfio_group_fd = -ENOENT ; }
@@ -469,18 +434,18 @@ vfio_open_group_fd(int iommu_group_num, bool mp_request)return vfio_group_fd; } -static struct vfio_config * +static struct vfio_container *get_vfio_cfg_by_group_num (int iommu_group_num) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i, j; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { - vfio_cfg = &vfio_cfgs[i]; -for (j =0 ; j <RTE_DIM (vfio_cfg->vfio_groups); j++) { -if (vfio_cfg->vfio_groups[j].group_num == +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { + cfg = &vfio_containers[i]; +for (j =0 ; j <RTE_DIM (cfg->vfio_groups); j++) { +if (cfg->vfio_groups[j].group_num == iommu_group_num) -return vfio_cfg; +return cfg; } }
@@ -488,28 +453,27 @@ get_vfio_cfg_by_group_num(int iommu_group_num) }static int -vfio_get_group_fd (struct vfio_config *vfio_cfg, -int iommu_group_num) +vfio_get_group_fd (struct vfio_container *cfg,int iommu_group_num) {struct vfio_group *cur_grp =NULL ;int vfio_group_fd;unsigned int i;/* check if we already have the group descriptor open */ -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) -if (vfio_cfg->vfio_groups[i].group_num == iommu_group_num) -return vfio_cfg->vfio_groups[i].fd; +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) +if (cfg->vfio_groups[i].group_num == iommu_group_num) +return cfg->vfio_groups[i].fd;/* Lets see first if there is room for a new group */ -if (vfio_cfg->vfio_active_groups ==RTE_DIM (vfio_cfg->vfio_groups)) { +if (cfg->vfio_active_groups ==RTE_DIM (cfg->vfio_groups)) {EAL_LOG (ERR ,"Maximum number of VFIO groups reached!" );return -1 ; }/* Now lets get an index for the new group */ -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) -if (vfio_cfg->vfio_groups[i].group_num ==-1 ) { - cur_grp = &vfio_cfg->vfio_groups[i]; +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) +if (cfg->vfio_groups[i].group_num ==-1 ) { + cur_grp = &cfg->vfio_groups[i];break ; }
@@ -534,7 +498,7 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg,*/ const struct internal_config *internal_conf =eal_get_internal_configuration ();bool mp_request = (internal_conf->process_type ==RTE_PROC_SECONDARY ) && - (vfio_cfg == default_vfio_cfg); + (cfg == default_vfio_cfg); vfio_group_fd =vfio_open_group_fd (iommu_group_num, mp_request);if (vfio_group_fd <0 ) {
@@ -545,28 +509,28 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg, cur_grp->group_num = iommu_group_num; cur_grp->fd = vfio_group_fd; - vfio_cfg->vfio_active_groups++; + cfg->vfio_active_groups++;return vfio_group_fd; } -static struct vfio_config * +static struct vfio_container *get_vfio_cfg_by_group_fd (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i, j; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { - vfio_cfg = &vfio_cfgs[i]; -for (j =0 ; j <RTE_DIM (vfio_cfg->vfio_groups); j++) -if (vfio_cfg->vfio_groups[j].fd == vfio_group_fd) -return vfio_cfg; +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { + cfg = &vfio_containers[i]; +for (j =0 ; j <RTE_DIM (cfg->vfio_groups); j++) +if (cfg->vfio_groups[j].fd == vfio_group_fd) +return cfg; }return NULL ; } -static struct vfio_config * +static struct vfio_container *get_vfio_cfg_by_container_fd (int container_fd) {unsigned int i;
@@ -574,9 +538,9 @@ get_vfio_cfg_by_container_fd(int container_fd)if (container_fd ==DEV_VFIO_DEFAULT_CONTAINER_FD )return default_vfio_cfg; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { -if (vfio_cfgs[i].vfio_container_fd == container_fd) -return &vfio_cfgs[i]; +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { +if (vfio_containers[i].container_fd == container_fd) +return &vfio_containers[i]; }return NULL ;
@@ -585,28 +549,28 @@ get_vfio_cfg_by_container_fd(int container_fd)int vfio_get_group_fd_by_num (int iommu_group_num) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;if (!vfio_enabled)return -1 ; -/* get the vfio_config it belongs to */ - vfio_cfg =get_vfio_cfg_by_group_num (iommu_group_num); - vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg; +/* get the vfio_container it belongs to */ + cfg =get_vfio_cfg_by_group_num (iommu_group_num); + cfg = cfg ? cfg : default_vfio_cfg; -return vfio_get_group_fd (vfio_cfg, iommu_group_num); +return vfio_get_group_fd (cfg, iommu_group_num); }static int get_vfio_group_idx (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i, j; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { - vfio_cfg = &vfio_cfgs[i]; -for (j =0 ; j <RTE_DIM (vfio_cfg->vfio_groups); j++) -if (vfio_cfg->vfio_groups[j].fd == vfio_group_fd) +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { + cfg = &vfio_containers[i]; +for (j =0 ; j <RTE_DIM (cfg->vfio_groups); j++) +if (cfg->vfio_groups[j].fd == vfio_group_fd)return j; }
@@ -616,11 +580,11 @@ get_vfio_group_idx(int vfio_group_fd)static void vfio_group_device_get (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;int i; - vfio_cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO group fd!" );return ; }
@@ -629,17 +593,17 @@ vfio_group_device_get(int vfio_group_fd)if (i <0 )EAL_LOG (ERR ,"Wrong VFIO group index (%d)" , i);else - vfio_cfg->vfio_groups[i].devices++; + cfg->vfio_groups[i].devices++; }static void vfio_group_device_put (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;int i; - vfio_cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO group fd!" );return ; }
@@ -648,17 +612,17 @@ vfio_group_device_put(int vfio_group_fd)if (i <0 )EAL_LOG (ERR ,"Wrong VFIO group index (%d)" , i);else - vfio_cfg->vfio_groups[i].devices--; + cfg->vfio_groups[i].devices--; }static int vfio_group_device_count (int vfio_group_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;int i; - vfio_cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO group fd!" );return -1 ; }
@@ -669,7 +633,7 @@ vfio_group_device_count(int vfio_group_fd)return -1 ; } -return vfio_cfg->vfio_groups[i].devices; +return cfg->vfio_groups[i].devices; } static void
@@ -738,14 +702,13 @@ vfio_sync_default_container(void)return -1 ;/* default container fd should have been opened in dev_vfio_enable() */ -if (!vfio_enabled || - default_vfio_cfg->vfio_container_fd <0 ) { +if (!vfio_enabled || default_vfio_cfg->container_fd <0 ) {EAL_LOG (ERR ,"VFIO support is not initialized" );return -1 ; }/* find default container's IOMMU type */ - p->req =SOCKET_REQ_IOMMU_TYPE ; + p->req =VFIO_SOCKET_REQ_IOMMU_TYPE ;strcpy (mp_req.name,EAL_VFIO_MP ); mp_req.len_param =sizeof (*p); mp_req.num_fds =0 ;
@@ -755,7 +718,7 @@ vfio_sync_default_container(void) mp_reply.nb_received == 1) { mp_rep = &mp_reply.msgs[0 ]; p = (struct vfio_mp_param *)mp_rep->param; -if (p->result ==SOCKET_OK ) +if (p->result ==VFIO_SOCKET_OK ) iommu_type_id = p->iommu_type_id; }free (mp_reply.msgs);
@@ -787,13 +750,13 @@ static int vfio_clear_group(int vfio_group_fd) {int i; -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;if (!vfio_enabled)return -1 ; - vfio_cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_group_fd (vfio_group_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO group fd!" );return -1 ; }
@@ -801,10 +764,10 @@ vfio_clear_group(int vfio_group_fd) i =get_vfio_group_idx (vfio_group_fd);if (i <0 )return -1 ; - vfio_cfg->vfio_groups[i].group_num =-1 ; - vfio_cfg->vfio_groups[i].fd =-1 ; - vfio_cfg->vfio_groups[i].devices =0 ; - vfio_cfg->vfio_active_groups--; + cfg->vfio_groups[i].group_num =-1 ; + cfg->vfio_groups[i].fd =-1 ; + cfg->vfio_groups[i].devices =0 ; + cfg->vfio_active_groups--;return 0 ; }
@@ -816,8 +779,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_destruct vfio_group_status group_status = { .argsz =sizeof (group_status) }; -struct vfio_config *vfio_cfg; -struct user_mem_maps *user_mem_maps; +struct vfio_container *cfg; +struct vfio_user_mem_maps *user_mem_maps;int vfio_container_fd;int vfio_group_fd;int iommu_group_num;
@@ -880,18 +843,17 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ; } -/* get the vfio_config it belongs to */ - vfio_cfg =get_vfio_cfg_by_group_num (iommu_group_num); - vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg; - vfio_container_fd = vfio_cfg->vfio_container_fd; - user_mem_maps = &vfio_cfg->mem_maps; +/* get the vfio_container it belongs to */ + cfg =get_vfio_cfg_by_group_num (iommu_group_num); + cfg = cfg ? cfg : default_vfio_cfg; + vfio_container_fd = cfg->container_fd; + user_mem_maps = &cfg->mem_maps;/* check if group does not have a container yet */ if (!(group_status.flags &VFIO_GROUP_FLAGS_CONTAINER_SET )) {/* add group to a container */ - ret =ioctl (vfio_group_fd,VFIO_GROUP_SET_CONTAINER , - &vfio_container_fd); + ret =ioctl (vfio_group_fd,VFIO_GROUP_SET_CONTAINER , &vfio_container_fd);if (ret) {EAL_LOG (ERR , "%s cannot add VFIO group to container, error "
@@ -910,7 +872,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* functionality. */ if (internal_conf->process_type ==RTE_PROC_PRIMARY && - vfio_cfg->vfio_active_groups ==1 && + cfg->vfio_active_groups ==1 &&vfio_group_device_count (vfio_group_fd) ==0 ) {const struct vfio_iommu_type *t;
@@ -928,8 +890,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* after registering callback, to prevent races */ rte_mcfg_mem_read_lock (); -if (vfio_cfg == default_vfio_cfg) - ret = t->dma_map_func (vfio_container_fd); +if (cfg == default_vfio_cfg) + ret = t->dma_map_func (cfg);else ret =0 ;if (ret) {
@@ -943,7 +905,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ; } - vfio_cfg->vfio_iommu_type = t; + cfg->vfio_iommu_type = t;/* re-map all user-mapped segments */ rte_spinlock_recursive_lock (&user_mem_maps->lock);
@@ -954,13 +916,10 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* be sure that DMA mapping is supported. */ for (i =0 ; i < user_mem_maps->n_maps; i++) { -struct user_mem_map *map; +struct vfio_user_mem_map *map; map = &user_mem_maps->maps[i]; - ret = t->dma_user_map_func ( - vfio_container_fd, - map->addr, map->iova, map->len, -1 ); + ret = t->dma_user_map_func (cfg, map->addr, map->iova, map->len,1 );if (ret) {EAL_LOG (ERR ,"Couldn't map user memory for DMA: " "va: 0x%" PRIx64 " "
@@ -977,7 +936,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_derte_spinlock_recursive_unlock (&user_mem_maps->lock);/* register callback for mem events */ -if (vfio_cfg == default_vfio_cfg) +if (cfg == default_vfio_cfg) ret =rte_mem_event_callback_register (VFIO_MEM_EVENT_CLB_NAME , vfio_mem_event_callback,NULL );
@@ -996,8 +955,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deEAL_LOG (DEBUG ,"Installed memory event callback for VFIO" ); } }else if (rte_eal_process_type () !=RTE_PROC_PRIMARY && - vfio_cfg == default_vfio_cfg && - vfio_cfg->vfio_iommu_type ==NULL ) { + cfg == default_vfio_cfg && + cfg->vfio_iommu_type ==NULL ) {/* if we're not a primary process, we do not set up the VFIO * container because it's already been set up by the primary * process. instead, we simply ask the primary about VFIO type
@@ -1060,7 +1019,7 @@ int dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, int vfio_dev_fd) { - struct vfio_config *vfio_cfg; + struct vfio_container *cfg;int vfio_group_fd;int iommu_group_num;int ret;
@@ -1092,9 +1051,9 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr, goto out; } -/* get the vfio_config it belongs to */ - vfio_cfg =get_vfio_cfg_by_group_num (iommu_group_num); - vfio_cfg = vfio_cfg ? vfio_cfg : default_vfio_cfg; +/* get the vfio_container it belongs to */ + cfg =get_vfio_cfg_by_group_num (iommu_group_num); + cfg = cfg ? cfg : default_vfio_cfg;/* At this point we got an active group. Closing it will make the * container detachment. If this is the last active group, VFIO kernel
@@ -1133,7 +1092,7 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr,/* if there are no active device groups, unregister the callback to * avoid spurious attempts to map/unmap memory from VFIO. */ -if (vfio_cfg == default_vfio_cfg && vfio_cfg->vfio_active_groups ==0 && +if (cfg == default_vfio_cfg && cfg->vfio_active_groups ==0 &&rte_eal_process_type () !=RTE_PROC_SECONDARY )rte_mem_event_callback_unregister (VFIO_MEM_EVENT_CLB_NAME ,NULL );
@@ -1162,16 +1121,16 @@ dev_vfio_enable(void)if (vfio_enabled)return 0 ; -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { - vfio_cfgs[i].vfio_container_fd =-1 ; - vfio_cfgs[i].vfio_active_groups =0 ; - vfio_cfgs[i].vfio_iommu_type =NULL ; - vfio_cfgs[i].mem_maps.lock = lock; +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { + vfio_containers[i].container_fd =-1 ; + vfio_containers[i].vfio_active_groups =0 ; + vfio_containers[i].vfio_iommu_type =NULL ; + vfio_containers[i].mem_maps.lock = lock; -for (j =0 ; j <RTE_DIM (vfio_cfgs[i].vfio_groups); j++) { - vfio_cfgs[i].vfio_groups[j].fd =-1 ; - vfio_cfgs[i].vfio_groups[j].group_num =-1 ; - vfio_cfgs[i].vfio_groups[j].devices =0 ; +for (j =0 ; j <RTE_DIM (vfio_containers[i].vfio_groups); j++) { + vfio_containers[i].vfio_groups[j].fd =-1 ; + vfio_containers[i].vfio_groups[j].group_num =-1 ; + vfio_containers[i].vfio_groups[j].devices =0 ; } }
@@ -1204,19 +1163,18 @@ dev_vfio_enable(void)if (internal_conf->process_type ==RTE_PROC_PRIMARY ) {if (vfio_mp_sync_setup () ==-1 ) { - default_vfio_cfg->vfio_container_fd =-1 ; + default_vfio_cfg->container_fd =-1 ; }else {/* open a default container */ - default_vfio_cfg->vfio_container_fd =vfio_open_container_fd (false); + default_vfio_cfg->container_fd =vfio_open_container_fd (false); } }else {/* get the default container from the primary process */ - default_vfio_cfg->vfio_container_fd = -vfio_open_container_fd (true); + default_vfio_cfg->container_fd =vfio_open_container_fd (true); }/* check if we have VFIO driver enabled */ -if (default_vfio_cfg->vfio_container_fd !=-1 ) { +if (default_vfio_cfg->container_fd !=-1 ) {EAL_LOG (INFO ,"VFIO support initialized" ); vfio_enabled = true; }else {
@@ -1381,7 +1339,7 @@ vfio_open_container_fd(bool mp_request)* if we're in a secondary process, request container fd from the * primary process via mp channel */ - p->req =SOCKET_REQ_CONTAINER ; + p->req =VFIO_SOCKET_REQ_CONTAINER ;strcpy (mp_req.name,EAL_VFIO_MP ); mp_req.len_param =sizeof (*p); mp_req.num_fds =0 ;
@@ -1391,7 +1349,7 @@ vfio_open_container_fd(bool mp_request) mp_reply.nb_received == 1) { mp_rep = &mp_reply.msgs[0 ]; p = (struct vfio_mp_param *)mp_rep->param; -if (p->result ==SOCKET_OK && mp_rep->num_fds ==1 ) { +if (p->result ==VFIO_SOCKET_OK && mp_rep->num_fds ==1 ) { vfio_container_fd = mp_rep->fds[0 ];free (mp_reply.msgs);return vfio_container_fd;
@@ -1414,7 +1372,7 @@ dev_vfio_get_container_fd(void)if (!vfio_enabled)return -1 ; -return default_vfio_cfg->vfio_container_fd; +return default_vfio_cfg->container_fd; }RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_group_num)
@@ -1465,10 +1423,9 @@ dev_vfio_get_group_num(const char *sysfs_base, }static int -type1_map (const struct rte_memseg_list *msl,const struct rte_memseg *ms, -void *arg) +type1_map (const struct rte_memseg_list *msl,const struct rte_memseg *ms,void *arg) { -int *vfio_container_fd = arg; +struct vfio_container *cfg = arg;/* skip external memory that isn't a heap */ if (msl->external && !msl->heap)
@@ -1478,13 +1435,12 @@ type1_map(const struct rte_memseg_list *msl, const struct rte_memseg *ms,if (ms->iova ==RTE_BAD_IOVA )return 0 ; -return vfio_type1_dma_mem_map (*vfio_container_fd, ms->addr_64, ms->iova, - ms->len,1 ); +return vfio_type1_dma_mem_map (cfg, ms->addr_64, ms->iova, ms->len,1 ); }static int -vfio_type1_dma_mem_map (int vfio_container_fd,uint64_t vaddr,uint64_t iova, -uint64_t len,int do_map) +vfio_type1_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, +int do_map) {struct vfio_iommu_type1_dma_map dma_map;struct vfio_iommu_type1_dma_unmap dma_unmap;
@@ -1499,7 +1455,7 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, dma_map.flags =VFIO_DMA_MAP_FLAG_READ |VFIO_DMA_MAP_FLAG_WRITE ; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_MAP_DMA , &dma_map); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_MAP_DMA , &dma_map);if (ret) {/** * In case the mapping was already done EEXIST will be
@@ -1521,8 +1477,7 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, dma_unmap.size = len; dma_unmap.iova = iova; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_UNMAP_DMA , - &dma_unmap); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_UNMAP_DMA , &dma_unmap);if (ret) {EAL_LOG (ERR ,"Cannot clear DMA remapping, error " "%i (%s)" , errno,strerror (errno));
@@ -1540,9 +1495,9 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, }static int -vfio_type1_dma_map (int vfio_container_fd) +vfio_type1_dma_map (struct vfio_container *cfg) { -return rte_memseg_walk (type1_map, &vfio_container_fd); +return rte_memseg_walk (type1_map, cfg); }/* Track the size of the statically allocated DMA window for SPAPR */
@@ -1550,8 +1505,8 @@ uint64_t spapr_dma_win_len;uint64_t spapr_dma_win_page_sz;static int -vfio_spapr_dma_do_map (int vfio_container_fd,uint64_t vaddr,uint64_t iova, -uint64_t len,int do_map) +vfio_spapr_dma_do_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, +int do_map) {struct vfio_iommu_spapr_register_memory reg = { .argsz =sizeof (reg),
@@ -1569,8 +1524,7 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,return -1 ; } - ret =ioctl (vfio_container_fd, -VFIO_IOMMU_SPAPR_REGISTER_MEMORY , ®); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_REGISTER_MEMORY , ®);if (ret) {EAL_LOG (ERR , "Cannot register vaddr for IOMMU, error "
@@ -1586,7 +1540,7 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, dma_map.flags =VFIO_DMA_MAP_FLAG_READ |VFIO_DMA_MAP_FLAG_WRITE ; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_MAP_DMA , &dma_map); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_MAP_DMA , &dma_map);if (ret) {EAL_LOG (ERR ,"Cannot map vaddr for IOMMU, error " "%i (%s)" , errno,strerror (errno));
@@ -1601,16 +1555,14 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, dma_unmap.size = len; dma_unmap.iova = iova; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_UNMAP_DMA , - &dma_unmap); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_UNMAP_DMA , &dma_unmap);if (ret) {EAL_LOG (ERR ,"Cannot unmap vaddr for IOMMU, error " "%i (%s)" , errno,strerror (errno));return -1 ; } - ret =ioctl (vfio_container_fd, -VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY , ®); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY , ®);if (ret) {EAL_LOG (ERR , "Cannot unregister vaddr for IOMMU, error "
@@ -1623,10 +1575,9 @@ vfio_spapr_dma_do_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova, }static int -vfio_spapr_map_walk (const struct rte_memseg_list *msl, -const struct rte_memseg *ms,void *arg) +vfio_spapr_map_walk (const struct rte_memseg_list *msl,const struct rte_memseg *ms,void *arg) { -int *vfio_container_fd = arg; +struct vfio_container *cfg = arg;/* skip external memory that isn't a heap */ if (msl->external && !msl->heap)
@@ -1636,8 +1587,7 @@ vfio_spapr_map_walk(const struct rte_memseg_list *msl,if (ms->iova ==RTE_BAD_IOVA )return 0 ; -return vfio_spapr_dma_do_map (*vfio_container_fd, - ms->addr_64, ms->iova, ms->len,1 ); +return vfio_spapr_dma_do_map (cfg, ms->addr_64, ms->iova, ms->len,1 ); }struct spapr_size_walk_param {
@@ -1782,7 +1732,7 @@ spapr_dma_win_size(void) }static int -vfio_spapr_create_dma_window (int vfio_container_fd) +vfio_spapr_create_dma_window (struct vfio_container *cfg) {struct vfio_iommu_spapr_tce_create create = { .argsz =sizeof (create), };
@@ -1796,7 +1746,7 @@ vfio_spapr_create_dma_window(int vfio_container_fd)if (ret <0 )return ret; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_SPAPR_TCE_GET_INFO , &info); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_GET_INFO , &info);if (ret) {EAL_LOG (ERR ,"Cannot get IOMMU info, error %i (%s)" , errno,strerror (errno));
@@ -1809,7 +1759,7 @@ vfio_spapr_create_dma_window(int vfio_container_fd)* supports v2, remove the default DMA window so it can be resized. */ remove.start_addr = info.dma32_window_start; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_SPAPR_TCE_REMOVE , &remove); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_REMOVE , &remove);if (ret)return -1 ;
@@ -1817,7 +1767,7 @@ vfio_spapr_create_dma_window(int vfio_container_fd) create.window_size = spapr_dma_win_len; create.page_shift =rte_ctz64 (spapr_dma_win_page_sz); create.levels =1 ; - ret =ioctl (vfio_container_fd,VFIO_IOMMU_SPAPR_TCE_CREATE , &create); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_CREATE , &create);#ifdef VFIO_IOMMU_SPAPR_INFO_DDW /* * The vfio_iommu_spapr_tce_info structure was modified in
@@ -1833,8 +1783,7 @@ vfio_spapr_create_dma_window(int vfio_container_fd)for (levels = create.levels +1 ; ret && levels <= info.ddw.levels; levels++) { create.levels = levels; - ret =ioctl (vfio_container_fd, -VFIO_IOMMU_SPAPR_TCE_CREATE , &create); + ret =ioctl (cfg->container_fd,VFIO_IOMMU_SPAPR_TCE_CREATE , &create); } }#endif /* VFIO_IOMMU_SPAPR_INFO_DDW */
@@ -1856,20 +1805,18 @@ vfio_spapr_create_dma_window(int vfio_container_fd) }static int -vfio_spapr_dma_mem_map (int vfio_container_fd,uint64_t vaddr, -uint64_t iova,uint64_t len,int do_map) +vfio_spapr_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, +int do_map) {int ret =0 ;if (do_map) { -if (vfio_spapr_dma_do_map (vfio_container_fd, - vaddr, iova, len,1 )) { +if (vfio_spapr_dma_do_map (cfg, vaddr, iova, len,1 )) {EAL_LOG (ERR ,"Failed to map DMA" ); ret =-1 ; } }else { -if (vfio_spapr_dma_do_map (vfio_container_fd, - vaddr, iova, len,0 )) { +if (vfio_spapr_dma_do_map (cfg, vaddr, iova, len,0 )) {EAL_LOG (ERR ,"Failed to unmap DMA" ); ret =-1 ; }
@@ -1879,42 +1826,40 @@ vfio_spapr_dma_mem_map(int vfio_container_fd, uint64_t vaddr, }static int -vfio_spapr_dma_map (int vfio_container_fd) +vfio_spapr_dma_map (struct vfio_container *cfg) { -if (vfio_spapr_create_dma_window (vfio_container_fd) <0 ) { +if (vfio_spapr_create_dma_window (cfg) <0 ) {EAL_LOG (ERR ,"Could not create new DMA window!" );return -1 ; }/* map all existing DPDK segments for DMA */ -if (rte_memseg_walk (vfio_spapr_map_walk, &vfio_container_fd) <0 ) +if (rte_memseg_walk (vfio_spapr_map_walk, cfg) <0 )return -1 ;return 0 ; }static int -vfio_noiommu_dma_map(int __rte_unused vfio_container_fd) +vfio_noiommu_dma_map(struct vfio_container *cfg __rte_unused) {/* No-IOMMU mode does not need DMA mapping */ return 0 ; }static int -vfio_noiommu_dma_mem_map(int __rte_unused vfio_container_fd, - uint64_t __rte_unused vaddr, - uint64_t __rte_unused iova, uint64_t __rte_unused len, - int __rte_unused do_map) +vfio_noiommu_dma_mem_map(struct vfio_container *cfg __rte_unused, uint64_t vaddr __rte_unused, + uint64_t iova __rte_unused, uint64_t len __rte_unused, int do_map __rte_unused) {/* No-IOMMU mode does not need DMA mapping */ return 0 ; }static int -vfio_dma_mem_map (struct vfio_config *vfio_cfg,uint64_t vaddr,uint64_t iova, -uint64_t len,int do_map) +vfio_dma_mem_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len, +int do_map) { -const struct vfio_iommu_type *t = vfio_cfg->vfio_iommu_type; +const struct vfio_iommu_type *t = cfg->vfio_iommu_type;if (!t) {EAL_LOG (ERR ,"VFIO support not initialized" );
@@ -1930,20 +1875,18 @@ vfio_dma_mem_map(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova,return -1 ; } -return t->dma_user_map_func (vfio_cfg->vfio_container_fd, vaddr, iova, - len, do_map); +return t->dma_user_map_func (cfg, vaddr, iova, len, do_map); }static int -container_dma_map (struct vfio_config *vfio_cfg,uint64_t vaddr,uint64_t iova, -uint64_t len) +container_dma_map (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len) { -struct user_mem_map *new_map; -struct user_mem_maps *user_mem_maps; +struct vfio_user_mem_map *new_map; +struct vfio_user_mem_maps *user_mem_maps;bool has_partial_unmap;int ret =0 ; - user_mem_maps = &vfio_cfg->mem_maps; + user_mem_maps = &cfg->mem_maps;rte_spinlock_recursive_lock (&user_mem_maps->lock);if (user_mem_maps->n_maps ==RTE_DIM (user_mem_maps->maps)) {EAL_LOG (ERR ,"No more space for user mem maps" );
@@ -1952,7 +1895,7 @@ container_dma_map(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, goto out; }/* map the entry */ -if (vfio_dma_mem_map (vfio_cfg, vaddr, iova, len,1 )) { +if (vfio_dma_mem_map (cfg, vaddr, iova, len,1 )) {/* technically, this will fail if there are currently no devices * plugged in, even if a device were added later, this mapping * might have succeeded. however, since we cannot verify if this
@@ -1965,7 +1908,7 @@ container_dma_map(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, goto out; }/* do we have partial unmap support? */ - has_partial_unmap = vfio_cfg->vfio_iommu_type->partial_unmap; + has_partial_unmap = cfg->vfio_iommu_type->partial_unmap;/* create new user mem map entry */ new_map = &user_mem_maps->maps[user_mem_maps->n_maps++];
@@ -1982,17 +1925,16 @@ container_dma_map(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, }static int -container_dma_unmap (struct vfio_config *vfio_cfg,uint64_t vaddr,uint64_t iova, -uint64_t len) +container_dma_unmap (struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len) { -struct user_mem_map orig_maps[RTE_DIM (vfio_cfg->mem_maps.maps)]; -struct user_mem_map new_maps[2 ];/* can be at most 2 */ -struct user_mem_maps *user_mem_maps; +struct vfio_user_mem_map orig_maps[RTE_DIM (cfg->mem_maps.maps)]; +struct vfio_user_mem_map new_maps[2 ];/* can be at most 2 */ +struct vfio_user_mem_maps *user_mem_maps;int n_orig, n_new, ret =0 ;bool has_partial_unmap;unsigned int newlen; - user_mem_maps = &vfio_cfg->mem_maps; + user_mem_maps = &cfg->mem_maps;rte_spinlock_recursive_lock (&user_mem_maps->lock);/*
@@ -2024,7 +1966,7 @@ container_dma_unmap(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, }/* do we have partial unmap capability? */ - has_partial_unmap = vfio_cfg->vfio_iommu_type->partial_unmap; + has_partial_unmap = cfg->vfio_iommu_type->partial_unmap;/* * if we don't support partial unmap, we must check if start and end of
@@ -2064,7 +2006,7 @@ container_dma_unmap(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova, }/* unmap the entry */ -if (vfio_dma_mem_map (vfio_cfg, vaddr, iova, len,0 )) { +if (vfio_dma_mem_map (cfg, vaddr, iova, len,0 )) {/* there may not be any devices plugged in, so unmapping will * fail with ENODEV/ENOTSUP rte_errno values, but that doesn't * stop us from removing the mapping, as the assumption is we
@@ -2134,31 +2076,31 @@ dev_vfio_container_create(void)return -1 ;/* Find an empty slot to store new vfio config */ -for (i =1 ; i <RTE_DIM (vfio_cfgs); i++) { -if (vfio_cfgs[i].vfio_container_fd ==-1 ) +for (i =1 ; i <RTE_DIM (vfio_containers); i++) { +if (vfio_containers[i].container_fd ==-1 )break ; } -if (i ==RTE_DIM (vfio_cfgs)) { +if (i ==RTE_DIM (vfio_containers)) {EAL_LOG (ERR ,"Exceed max VFIO container limit" );return -1 ; }/* Create a new container fd */ - vfio_cfgs[i].vfio_container_fd =vfio_open_container_fd (false); -if (vfio_cfgs[i].vfio_container_fd <0 ) { + vfio_containers[i].container_fd =vfio_open_container_fd (false); +if (vfio_containers[i].container_fd <0 ) {EAL_LOG (NOTICE ,"Fail to create a new VFIO container" );return -1 ; } -return vfio_cfgs[i].vfio_container_fd; +return vfio_containers[i].container_fd; }RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_container_destroy) intdev_vfio_container_destroy (int container_fd) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i;if (!vfio_enabled)
@@ -2169,21 +2111,21 @@ dev_vfio_container_destroy(int container_fd)return -1 ; } - vfio_cfg =get_vfio_cfg_by_container_fd (container_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) -if (vfio_cfg->vfio_groups[i].group_num !=-1 ) +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) +if (cfg->vfio_groups[i].group_num !=-1 )vfio_container_group_unbind (container_fd, - vfio_cfg->vfio_groups[i].group_num); + cfg->vfio_groups[i].group_num);close (container_fd); - vfio_cfg->vfio_container_fd =-1 ; - vfio_cfg->vfio_active_groups =0 ; - vfio_cfg->vfio_iommu_type =NULL ; + cfg->container_fd =-1 ; + cfg->vfio_active_groups =0 ; + cfg->vfio_iommu_type =NULL ;return 0 ; }
@@ -2218,39 +2160,39 @@ dev_vfio_container_assign_device(int vfio_container_fd, const char *sysfs_base,static int vfio_container_group_bind (int container_fd,int iommu_group_num) { -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;if (!vfio_enabled)return -1 ; - vfio_cfg =get_vfio_cfg_by_container_fd (container_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -return vfio_get_group_fd (vfio_cfg, iommu_group_num); +return vfio_get_group_fd (cfg, iommu_group_num); }static int vfio_container_group_unbind (int container_fd,int iommu_group_num) {struct vfio_group *cur_grp =NULL ; -struct vfio_config *vfio_cfg; +struct vfio_container *cfg;unsigned int i;if (!vfio_enabled)return -1 ; - vfio_cfg =get_vfio_cfg_by_container_fd (container_fd); -if (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) { -if (vfio_cfg->vfio_groups[i].group_num == iommu_group_num) { - cur_grp = &vfio_cfg->vfio_groups[i]; +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) { +if (cfg->vfio_groups[i].group_num == iommu_group_num) { + cur_grp = &cfg->vfio_groups[i];break ; } }
@@ -2270,7 +2212,7 @@ vfio_container_group_unbind(int container_fd, int iommu_group_num) cur_grp->group_num =-1 ; cur_grp->fd =-1 ; cur_grp->devices =0 ; - vfio_cfg->vfio_active_groups--; + cfg->vfio_active_groups--;return 0 ; }
@@ -2280,7 +2222,7 @@ int dev_vfio_container_dma_map(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len) { - struct vfio_config *vfio_cfg; + struct vfio_container *cfg;if (!vfio_enabled)return -1 ;
@@ -2290,13 +2232,13 @@ dev_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 (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -return container_dma_map (vfio_cfg, vaddr, iova, len); +return container_dma_map (cfg, vaddr, iova, len); }RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_container_dma_unmap)
@@ -2304,7 +2246,7 @@ int dev_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len) { - struct vfio_config *vfio_cfg; + struct vfio_container *cfg;if (!vfio_enabled)return -1 ;
@@ -2314,22 +2256,22 @@ dev_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 (vfio_cfg ==NULL ) { + cfg =get_vfio_cfg_by_container_fd (container_fd); +if (cfg ==NULL ) {EAL_LOG (ERR ,"Invalid VFIO container fd" );return -1 ; } -return container_dma_unmap (vfio_cfg, vaddr, iova, len); +return container_dma_unmap (cfg, vaddr, iova, len); }static int -vfio_cleanup_config (struct vfio_config *vfio_cfg) +vfio_cleanup_config (struct vfio_container *cfg) {unsigned int i; -for (i =0 ; i <RTE_DIM (vfio_cfg->vfio_groups); i++) { -struct vfio_group *group = &vfio_cfg->vfio_groups[i]; +for (i =0 ; i <RTE_DIM (cfg->vfio_groups); i++) { +struct vfio_group *group = &cfg->vfio_groups[i];if (group->group_num ==-1 )continue ;
@@ -2347,26 +2289,26 @@ vfio_cleanup_config(struct vfio_config *vfio_cfg) group->group_num =-1 ; group->fd =-1 ; group->devices =0 ; - vfio_cfg->vfio_active_groups--; + cfg->vfio_active_groups--; }/* if there are still active groups, we cannot cleanup the container */ -if (vfio_cfg->vfio_active_groups !=0 ) { +if (cfg->vfio_active_groups !=0 ) {EAL_LOG (ERR ,"Cannot cleanup VFIO container with %d active groups" , - vfio_cfg->vfio_active_groups); + cfg->vfio_active_groups);return -1 ; } -if (vfio_cfg->vfio_container_fd >=0 &&close (vfio_cfg->vfio_container_fd) <0 ) { +if (cfg->container_fd >=0 &&close (cfg->container_fd) <0 ) {EAL_LOG (ERR ,"Cannot close VFIO container: %s" ,strerror (errno));return -1 ; } - vfio_cfg->vfio_container_fd =-1 ; - vfio_cfg->vfio_iommu_type =NULL ; + cfg->container_fd =-1 ; + cfg->vfio_iommu_type =NULL ; - vfio_cfg->mem_maps.n_maps =0 ; -memset (vfio_cfg->mem_maps.maps,0 ,sizeof (vfio_cfg->mem_maps.maps)); + cfg->mem_maps.n_maps =0 ; +memset (cfg->mem_maps.maps,0 ,sizeof (cfg->mem_maps.maps));return 0 ; }
@@ -2388,9 +2330,9 @@ dev_vfio_cleanup(void)rte_mem_event_callback_unregister (VFIO_MEM_EVENT_CLB_NAME ,NULL );/* cleanup all initialized configs */ -for (i =0 ; i <RTE_DIM (vfio_cfgs); i++) { -if (vfio_cfgs[i].vfio_container_fd !=-1 ) - stuck |=vfio_cleanup_config (&vfio_cfgs[i]) !=0 ; +for (i =0 ; i <RTE_DIM (vfio_containers); i++) { +if (vfio_containers[i].container_fd !=-1 ) + stuck |=vfio_cleanup_config (&vfio_containers[i]) !=0 ; }/* failed to deinitialize some configs, so don't set VFIO as disabled */
lib/eal/linux/eal_vfio.h +40 -10
76 lines not on this page · raw message
lib/eal/linux/eal_vfio_mp_sync.c +13 -13
@@ -31,46 +31,46 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)memset (&reply,0 ,sizeof (reply));switch (m->req) { -case SOCKET_REQ_GROUP : - r->req =SOCKET_REQ_GROUP ; +case VFIO_SOCKET_REQ_GROUP : + r->req =VFIO_SOCKET_REQ_GROUP ; r->group_num = m->group_num; fd =vfio_get_group_fd_by_num (m->group_num);if (fd <0 && fd != -ENOENT ) - r->result =SOCKET_ERR ; + r->result =VFIO_SOCKET_ERR ;else if (fd == -ENOENT )/* if VFIO group exists but isn't bound to VFIO driver */ - r->result =SOCKET_NO_FD ; + r->result =VFIO_SOCKET_NO_FD ;else {/* if group exists and is bound to VFIO driver */ - r->result =SOCKET_OK ; + r->result =VFIO_SOCKET_OK ; reply.num_fds =1 ; reply.fds[0 ] = fd; }break ; -case SOCKET_REQ_CONTAINER : - r->req =SOCKET_REQ_CONTAINER ; +case VFIO_SOCKET_REQ_CONTAINER : + r->req =VFIO_SOCKET_REQ_CONTAINER ; fd =dev_vfio_get_container_fd ();if (fd <0 ) - r->result =SOCKET_ERR ; + r->result =VFIO_SOCKET_ERR ;else { - r->result =SOCKET_OK ; + r->result =VFIO_SOCKET_OK ; reply.num_fds =1 ; reply.fds[0 ] = fd; }break ; -case SOCKET_REQ_IOMMU_TYPE : +case VFIO_SOCKET_REQ_IOMMU_TYPE : {int iommu_type_id; - r->req =SOCKET_REQ_IOMMU_TYPE ; + r->req =VFIO_SOCKET_REQ_IOMMU_TYPE ; iommu_type_id =vfio_get_iommu_type ();if (iommu_type_id <0 ) - r->result =SOCKET_ERR ; + r->result =VFIO_SOCKET_ERR ;else { r->iommu_type_id = iommu_type_id; - r->result =SOCKET_OK ; + r->result =VFIO_SOCKET_OK ; }break ; }
Signature · 1 line
2.54.0
PATCH RESEND v19 19/26 vfio: declare global configuration
In reply to David MarchandFrom: Anatoly Burakov <[email protected]>
Move containers under a single global variable.
Rename the IOMMU callbacks structure and have a single global ops.
--- lib/eal/linux/eal_vfio.c | 85 ++++++++++++++++++---------------------- lib/eal/linux/eal_vfio.h | 16 ++++++-- 2 files changed, 51 insertions(+), 50 deletions(-)
lib/eal/linux/eal_vfio.c +39 -46
@@ -31,7 +31,10 @@/* per-process VFIO config */ static struct vfio_container vfio_containers[RTE_MAX_VFIO_CONTAINERS ]; -static struct vfio_container *default_vfio_cfg = &vfio_containers[0 ]; + +struct vfio_config vfio_global_cfg = { + .default_cfg = &vfio_containers[0 ] +};/* whether VFIO is enabled (usable) in this process */ static bool vfio_enabled;
@@ -91,7 +94,7 @@ static int vfio_container_group_bind(int container_fd, int iommu_group_num);static int vfio_container_group_unbind (int container_fd,int iommu_group_num);/* IOMMU types we support */ -static const struct vfio_iommu_type iommu_types[] = { +static const struct vfio_iommu_ops iommu_types[] = {/* x86 IOMMU, otherwise known as type 1 */ { .type_id =VFIO_TYPE1_IOMMU ,
@@ -498,7 +501,7 @@ vfio_get_group_fd(struct vfio_container *cfg, int iommu_group_num)*/ const struct internal_config *internal_conf =eal_get_internal_configuration ();bool mp_request = (internal_conf->process_type ==RTE_PROC_SECONDARY ) && - (cfg == default_vfio_cfg); + (cfg == vfio_global_cfg.default_cfg); vfio_group_fd =vfio_open_group_fd (iommu_group_num, mp_request);if (vfio_group_fd <0 ) {
@@ -536,7 +539,7 @@ get_vfio_cfg_by_container_fd(int container_fd)unsigned int i;if (container_fd ==DEV_VFIO_DEFAULT_CONTAINER_FD ) -return default_vfio_cfg; +return vfio_global_cfg.default_cfg;for (i =0 ; i <RTE_DIM (vfio_containers); i++) {if (vfio_containers[i].container_fd == container_fd)
@@ -556,7 +559,7 @@ vfio_get_group_fd_by_num(int iommu_group_num)/* get the vfio_container it belongs to */ cfg =get_vfio_cfg_by_group_num (iommu_group_num); - cfg = cfg ? cfg : default_vfio_cfg; + cfg = cfg ? cfg : vfio_global_cfg.default_cfg;return vfio_get_group_fd (cfg, iommu_group_num); }
@@ -640,6 +643,7 @@ static void vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len, void *arg __rte_unused) { + struct vfio_container *cfg = vfio_global_cfg.default_cfg;struct rte_memseg_list *msl;struct rte_memseg *ms;size_t cur_len =0 ;
@@ -654,11 +658,9 @@ vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len,/* Maintain granularity of DMA map/unmap to memseg size */ for (; cur_len < len; cur_len += page_sz) {if (type ==RTE_MEM_EVENT_ALLOC ) -vfio_dma_mem_map (default_vfio_cfg, vfio_va, - vfio_va, page_sz,1 ); +vfio_dma_mem_map (cfg, vfio_va, vfio_va, page_sz,1 );else -vfio_dma_mem_map (default_vfio_cfg, vfio_va, - vfio_va, page_sz,0 ); +vfio_dma_mem_map (cfg, vfio_va, vfio_va, page_sz,0 ); vfio_va += page_sz; }
@@ -676,11 +678,9 @@ vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len, goto next; }if (type ==RTE_MEM_EVENT_ALLOC ) -vfio_dma_mem_map (default_vfio_cfg, ms->addr_64, - ms->iova, ms->len,1 ); +vfio_dma_mem_map (cfg, ms->addr_64, ms->iova, ms->len,1 );else -vfio_dma_mem_map (default_vfio_cfg, ms->addr_64, - ms->iova, ms->len,0 ); +vfio_dma_mem_map (cfg, ms->addr_64, ms->iova, ms->len,0 ); next: cur_len += ms->len; ++ms;
@@ -702,7 +702,7 @@ vfio_sync_default_container(void)return -1 ;/* default container fd should have been opened in dev_vfio_enable() */ -if (!vfio_enabled || default_vfio_cfg->container_fd <0 ) { +if (!vfio_enabled || vfio_global_cfg.default_cfg->container_fd <0 ) {EAL_LOG (ERR ,"VFIO support is not initialized" );return -1 ; }
@@ -732,12 +732,12 @@ vfio_sync_default_container(void)* now, set up default VFIO container config to match. */ for (i =0 ; i <RTE_DIM (iommu_types); i++) { -const struct vfio_iommu_type *t = &iommu_types[i]; +const struct vfio_iommu_ops *t = &iommu_types[i];if (t->type_id != iommu_type_id)continue ;/* we found our IOMMU type */ - default_vfio_cfg->vfio_iommu_type = t; + vfio_global_cfg.ops = t;return 0 ; }
@@ -845,7 +845,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de/* get the vfio_container it belongs to */ cfg =get_vfio_cfg_by_group_num (iommu_group_num); - cfg = cfg ? cfg : default_vfio_cfg; + cfg = cfg ? cfg : vfio_global_cfg.default_cfg; vfio_container_fd = cfg->container_fd; user_mem_maps = &cfg->mem_maps;
@@ -874,7 +874,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deif (internal_conf->process_type ==RTE_PROC_PRIMARY && cfg->vfio_active_groups ==1 &&vfio_group_device_count (vfio_group_fd) ==0 ) { -const struct vfio_iommu_type *t; +const struct vfio_iommu_ops *t;/* select an IOMMU type which we will be using */ t =vfio_set_iommu_type (vfio_container_fd);
@@ -890,7 +890,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_de* after registering callback, to prevent races */ rte_mcfg_mem_read_lock (); -if (cfg == default_vfio_cfg) +if (cfg == vfio_global_cfg.default_cfg) ret = t->dma_map_func (cfg);else ret =0 ;
@@ -905,8 +905,6 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ; } - cfg->vfio_iommu_type = t; -/* re-map all user-mapped segments */ rte_spinlock_recursive_lock (&user_mem_maps->lock);
@@ -936,7 +934,7 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_derte_spinlock_recursive_unlock (&user_mem_maps->lock);/* register callback for mem events */ -if (cfg == default_vfio_cfg) +if (cfg == vfio_global_cfg.default_cfg) ret =rte_mem_event_callback_register (VFIO_MEM_EVENT_CLB_NAME , vfio_mem_event_callback,NULL );
@@ -955,8 +953,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_deEAL_LOG (DEBUG ,"Installed memory event callback for VFIO" ); } }else if (rte_eal_process_type () !=RTE_PROC_PRIMARY && - cfg == default_vfio_cfg && - cfg->vfio_iommu_type ==NULL ) { + cfg == vfio_global_cfg.default_cfg && + vfio_global_cfg.ops ==NULL ) {/* if we're not a primary process, we do not set up the VFIO * container because it's already been set up by the primary * process. instead, we simply ask the primary about VFIO type
@@ -970,10 +968,8 @@ dev_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dereturn -1 ; }/* we have successfully initialized VFIO, notify user */ -const struct vfio_iommu_type *t = - default_vfio_cfg->vfio_iommu_type; -EAL_LOG (INFO ,"Using IOMMU type %d (%s)" , - t->type_id, t->name); +const struct vfio_iommu_ops *t = vfio_global_cfg.ops; +EAL_LOG (INFO ,"Using IOMMU type %d (%s)" , t->type_id, t->name); }rte_eal_vfio_get_vf_token (vf_token);
@@ -1053,7 +1049,7 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr,/* get the vfio_container it belongs to */ cfg =get_vfio_cfg_by_group_num (iommu_group_num); - cfg = cfg ? cfg : default_vfio_cfg; + cfg = cfg ? cfg : vfio_global_cfg.default_cfg;/* At this point we got an active group. Closing it will make the * container detachment. If this is the last active group, VFIO kernel
@@ -1092,7 +1088,7 @@ dev_vfio_release_device(const char *sysfs_base, const char *dev_addr,/* if there are no active device groups, unregister the callback to * avoid spurious attempts to map/unmap memory from VFIO. */ -if (cfg == default_vfio_cfg && cfg->vfio_active_groups ==0 && +if (cfg == vfio_global_cfg.default_cfg && cfg->vfio_active_groups ==0 &&rte_eal_process_type () !=RTE_PROC_SECONDARY )rte_mem_event_callback_unregister (VFIO_MEM_EVENT_CLB_NAME ,NULL );
@@ -1124,7 +1120,6 @@ dev_vfio_enable(void)for (i =0 ; i <RTE_DIM (vfio_containers); i++) { vfio_containers[i].container_fd =-1 ; vfio_containers[i].vfio_active_groups =0 ; - vfio_containers[i].vfio_iommu_type =NULL ; vfio_containers[i].mem_maps.lock = lock;for (j =0 ; j <RTE_DIM (vfio_containers[i].vfio_groups); j++) {
@@ -1163,18 +1158,18 @@ dev_vfio_enable(void)if (internal_conf->process_type ==RTE_PROC_PRIMARY ) {if (vfio_mp_sync_setup () ==-1 ) { - default_vfio_cfg->container_fd =-1 ; + vfio_global_cfg.default_cfg->container_fd =-1 ; }else {/* open a default container */ - default_vfio_cfg->container_fd =vfio_open_container_fd (false); + vfio_global_cfg.default_cfg->container_fd =vfio_open_container_fd (false); } }else {/* get the default container from the primary process */ - default_vfio_cfg->container_fd =vfio_open_container_fd (true); + vfio_global_cfg.default_cfg->container_fd =vfio_open_container_fd (true); }/* check if we have VFIO driver enabled */ -if (default_vfio_cfg->container_fd !=-1 ) { +if (vfio_global_cfg.default_cfg->container_fd !=-1 ) {EAL_LOG (INFO ,"VFIO support initialized" ); vfio_enabled = true; }else {
@@ -1204,18 +1199,18 @@ vfio_get_iommu_type(void)if (!vfio_enabled)return -1 ; -if (default_vfio_cfg->vfio_iommu_type ==NULL ) +if (vfio_global_cfg.ops ==NULL )return -1 ; -return default_vfio_cfg->vfio_iommu_type->type_id; +return vfio_global_cfg.ops->type_id; } -const struct vfio_iommu_type * +const struct vfio_iommu_ops *vfio_set_iommu_type (int vfio_container_fd) {unsigned idx;for (idx =0 ; idx <RTE_DIM (iommu_types); idx++) { -const struct vfio_iommu_type *t = &iommu_types[idx]; +const struct vfio_iommu_ops *t = &iommu_types[idx];int ret =ioctl (vfio_container_fd,VFIO_SET_IOMMU , t->type_id);
@@ -1260,7 +1255,7 @@ vfio_has_supported_extensions(int vfio_container_fd)int ret;unsigned idx, n_extensions =0 ;for (idx =0 ; idx <RTE_DIM (iommu_types); idx++) { -const struct vfio_iommu_type *t = &iommu_types[idx]; +const struct vfio_iommu_ops *t = &iommu_types[idx]; ret =ioctl (vfio_container_fd,VFIO_CHECK_EXTENSION , t->type_id);
@@ -1372,7 +1367,7 @@ dev_vfio_get_container_fd(void)if (!vfio_enabled)return -1 ; -return default_vfio_cfg->container_fd; +return vfio_global_cfg.default_cfg->container_fd; }RTE_EXPORT_INTERNAL_SYMBOL (dev_vfio_get_group_num)
@@ -1859,7 +1854,7 @@ static int vfio_dma_mem_map(struct vfio_container *cfg, uint64_t vaddr, uint64_t iova, uint64_t len, int do_map) { - const struct vfio_iommu_type *t = cfg->vfio_iommu_type; + const struct vfio_iommu_ops *t = vfio_global_cfg.ops;if (!t) {EAL_LOG (ERR ,"VFIO support not initialized" );
@@ -1908,7 +1903,7 @@ container_dma_map(struct vfio_container *cfg, uint64_t vaddr, uint64_t iova, uin goto out; }/* do we have partial unmap support? */ - has_partial_unmap = cfg->vfio_iommu_type->partial_unmap; + has_partial_unmap = vfio_global_cfg.ops->partial_unmap;/* create new user mem map entry */ new_map = &user_mem_maps->maps[user_mem_maps->n_maps++];
@@ -1966,7 +1961,7 @@ container_dma_unmap(struct vfio_container *cfg, uint64_t vaddr, uint64_t iova, u }/* do we have partial unmap capability? */ - has_partial_unmap = cfg->vfio_iommu_type->partial_unmap; + has_partial_unmap = vfio_global_cfg.ops->partial_unmap;/* * if we don't support partial unmap, we must check if start and end of
@@ -2125,7 +2120,6 @@ dev_vfio_container_destroy(int container_fd)close (container_fd); cfg->container_fd =-1 ; cfg->vfio_active_groups =0 ; - cfg->vfio_iommu_type =NULL ;return 0 ; }
@@ -2305,7 +2299,6 @@ vfio_cleanup_config(struct vfio_container *cfg) } cfg->container_fd =-1 ; - cfg->vfio_iommu_type =NULL ; cfg->mem_maps.n_maps =0 ;memset (cfg->mem_maps.maps,0 ,sizeof (cfg->mem_maps.maps));
lib/eal/linux/eal_vfio.h +12 -4
@@ -44,7 +44,6 @@ struct vfio_group {struct vfio_container {int container_fd;int vfio_active_groups; -const struct vfio_iommu_type *vfio_iommu_type;struct vfio_group vfio_groups[RTE_MAX_VFIO_GROUPS ];struct vfio_user_mem_maps mem_maps; };
@@ -63,7 +62,7 @@ typedef int (*vfio_dma_func_t)(struct vfio_container *cfg);typedef int (*vfio_dma_user_func_t )(struct vfio_container *cfg,uint64_t vaddr,uint64_t iova,uint64_t len,int do_map); -struct vfio_iommu_type { +struct vfio_iommu_ops {int type_id;const char *name;bool partial_unmap;
@@ -74,8 +73,17 @@ struct vfio_iommu_type {/* get the vfio container that devices are bound to by default */ int vfio_open_container_fd (bool mp_request); -/* pick IOMMU type. returns a pointer to vfio_iommu_type or NULL for error */ -const struct vfio_iommu_type * +/* global configuration */ +struct vfio_config { +struct vfio_container *default_cfg; +const struct vfio_iommu_ops *ops; +}; + +/* current configuration */ +extern struct vfio_config vfio_global_cfg; + +/* pick IOMMU type. returns a pointer to vfio_iommu_ops or NULL for error */ +const struct vfio_iommu_ops *vfio_set_iommu_type (int vfio_container_fd);int
Signature · 1 line
2.54.0