eal/pci: Improve automatic selection of IOVA mode
In SPDK, not all drivers are registered with DPDK at start up time. Previously, that meant DPDK always chose to set itself up in IOVA_PA mode. Instead, when the correct iova choice is unclear based on the devices and drivers known to DPDK at start up time, use other heuristics (such as whether /proc/self/pagemap is accessible) to make a better choice.
This enables SPDK to run as an unprivileged user again without requiring users to explicitly set the iova mode on the command line.
PATCH 1/12 eal: Make rte_eal_using_phys_addrs work sooner
This function only returned the correct answer after a call to initialize the memory subsystem. Make it work prior to that.
--- lib/librte_eal/linux/eal/eal_memory.c | 63 ++++++++++++--------------- 1 file changed, 28 insertions(+), 35 deletions(-)
lib/librte_eal/linux/eal/eal_memory.c +28 -35
@@ -66,34 +66,8 @@* zone as well as a physical contiguous zone. */ -static bool phys_addrs_available = true; -#define RANDOMIZE_VA_SPACE_FILE "/proc/sys/kernel/randomize_va_space" -static void -test_phys_addrs_available (void ) -{ -uint64_t tmp =0 ; -phys_addr_t physaddr; - -if (!rte_eal_has_hugepages ()) { -RTE_LOG (ERR ,EAL , -"Started without hugepages support, physical addresses not available\n" ); - phys_addrs_available = false; -return ; - } - - physaddr =rte_mem_virt2phy (&tmp); -if (physaddr ==RTE_BAD_PHYS_ADDR ) { -if (rte_eal_iova_mode () ==RTE_IOVA_PA ) -RTE_LOG (ERR ,EAL , -"Cannot obtain physical addresses: %s. " -"Only vfio will function.\n" , -strerror (errno)); - phys_addrs_available = false; - } -} -/* * Get physical address of any mapped virtual address in the current process. */
@@ -107,7 +81,7 @@ rte_mem_virt2phy(const void *virtaddr)off_t offset;/* Cannot parse /proc/self/pagemap, no need to log errors everywhere */ -if (!phys_addrs_available) +if (!rte_eal_using_phys_addrs ())return RTE_BAD_IOVA ;/* standard page size */
@@ -1336,8 +1310,6 @@ eal_legacy_hugepage_init(void)int nr_hugefiles, nr_hugepages =0 ;void *addr; -test_phys_addrs_available (); -memset (used_hp,0 ,sizeof (used_hp));/* get pointer to global configuration */
@@ -1516,7 +1488,7 @@ eal_legacy_hugepage_init(void)continue ; } -if (phys_addrs_available && +if (rte_eal_using_phys_addrs () &&rte_eal_iova_mode () !=RTE_IOVA_VA ) {/* find physical addresses for each hugepage */ if (find_physaddrs (&tmp_hp[hp_offset], hpi) <0 ) {
@@ -1735,8 +1707,6 @@ eal_hugepage_init(void)uint64_t memory[RTE_MAX_NUMA_NODES ];int hp_sz_idx, socket_id; -test_phys_addrs_available (); -memset (used_hp,0 ,sizeof (used_hp)); for (hp_sz_idx = 0;
@@ -1879,8 +1849,6 @@ eal_legacy_hugepage_attach(void) "into secondary processes\n"); } -test_phys_addrs_available (); - fd_hugepage =open (eal_hugepage_data_path (),O_RDONLY );if (fd_hugepage <0 ) { RTE_LOG(ERR, EAL, "Could not open %s\n",
@@ -2020,7 +1988,32 @@ rte_eal_hugepage_attach(void)int rte_eal_using_phys_addrs (void ) { -return phys_addrs_available; +static int using_phys_addrs =-1 ; +uint64_t tmp =0 ; +phys_addr_t physaddr; + +if (using_phys_addrs !=-1 ) +return using_phys_addrs; + +/* Set the default to 1 */ + using_phys_addrs =1 ; + +if (!rte_eal_has_hugepages ()) { +RTE_LOG (ERR ,EAL , +"Started without hugepages support, physical addresses not available\n" ); + using_phys_addrs =0 ; +return using_phys_addrs; + } + + physaddr =rte_mem_virt2phy (&tmp); +if (physaddr ==RTE_BAD_PHYS_ADDR ) { +if (rte_eal_iova_mode () ==RTE_IOVA_PA ) +RTE_LOG (ERR ,EAL , +"Cannot obtain physical addresses. Only vfio will function.\n" ); + using_phys_addrs =0 ; + } + +return using_phys_addrs; }static int __rte_unused
Signature · 1 line
2.20.1
PATCH v2 1/12 eal: Make rte_eal_using_phys_addrs work sooner
This function only returned the correct answer after a call to initialize the memory subsystem. Make it work prior to that.
--- lib/librte_eal/linux/eal/eal_memory.c | 63 ++++++++++++--------------- 1 file changed, 28 insertions(+), 35 deletions(-)
lib/librte_eal/linux/eal/eal_memory.c +28 -35
@@ -66,34 +66,8 @@* zone as well as a physical contiguous zone. */ -static bool phys_addrs_available = true; -#define RANDOMIZE_VA_SPACE_FILE "/proc/sys/kernel/randomize_va_space" -static void -test_phys_addrs_available (void ) -{ -uint64_t tmp =0 ; -phys_addr_t physaddr; - -if (!rte_eal_has_hugepages ()) { -RTE_LOG (ERR ,EAL , -"Started without hugepages support, physical addresses not available\n" ); - phys_addrs_available = false; -return ; - } - - physaddr =rte_mem_virt2phy (&tmp); -if (physaddr ==RTE_BAD_PHYS_ADDR ) { -if (rte_eal_iova_mode () ==RTE_IOVA_PA ) -RTE_LOG (ERR ,EAL , -"Cannot obtain physical addresses: %s. " -"Only vfio will function.\n" , -strerror (errno)); - phys_addrs_available = false; - } -} -/* * Get physical address of any mapped virtual address in the current process. */
@@ -107,7 +81,7 @@ rte_mem_virt2phy(const void *virtaddr)off_t offset;/* Cannot parse /proc/self/pagemap, no need to log errors everywhere */ -if (!phys_addrs_available) +if (!rte_eal_using_phys_addrs ())return RTE_BAD_IOVA ;/* standard page size */
@@ -1336,8 +1310,6 @@ eal_legacy_hugepage_init(void)int nr_hugefiles, nr_hugepages =0 ;void *addr; -test_phys_addrs_available (); -memset (used_hp,0 ,sizeof (used_hp));/* get pointer to global configuration */
@@ -1516,7 +1488,7 @@ eal_legacy_hugepage_init(void)continue ; } -if (phys_addrs_available && +if (rte_eal_using_phys_addrs () &&rte_eal_iova_mode () !=RTE_IOVA_VA ) {/* find physical addresses for each hugepage */ if (find_physaddrs (&tmp_hp[hp_offset], hpi) <0 ) {
@@ -1735,8 +1707,6 @@ eal_hugepage_init(void)uint64_t memory[RTE_MAX_NUMA_NODES ];int hp_sz_idx, socket_id; -test_phys_addrs_available (); -memset (used_hp,0 ,sizeof (used_hp)); for (hp_sz_idx = 0;
@@ -1879,8 +1849,6 @@ eal_legacy_hugepage_attach(void) "into secondary processes\n"); } -test_phys_addrs_available (); - fd_hugepage =open (eal_hugepage_data_path (),O_RDONLY );if (fd_hugepage <0 ) { RTE_LOG(ERR, EAL, "Could not open %s\n",
@@ -2020,7 +1988,32 @@ rte_eal_hugepage_attach(void)int rte_eal_using_phys_addrs (void ) { -return phys_addrs_available; +static int using_phys_addrs =-1 ; +uint64_t tmp =0 ; +phys_addr_t physaddr; + +if (using_phys_addrs !=-1 ) +return using_phys_addrs; + +/* Set the default to 1 */ + using_phys_addrs =1 ; + +if (!rte_eal_has_hugepages ()) { +RTE_LOG (ERR ,EAL , +"Started without hugepages support, physical addresses not available\n" ); + using_phys_addrs =0 ; +return using_phys_addrs; + } + + physaddr =rte_mem_virt2phy (&tmp); +if (physaddr ==RTE_BAD_PHYS_ADDR ) { +if (rte_eal_iova_mode () ==RTE_IOVA_PA ) +RTE_LOG (ERR ,EAL , +"Cannot obtain physical addresses. Only vfio will function.\n" ); + using_phys_addrs =0 ; + } + +return using_phys_addrs; }static int __rte_unused
Signature · 1 line
2.20.1
PATCH v2 2/12 eal/pci: Inline several functions into rte_pci_get_iommu_class
This is in preparation for future simplifications. The functions are simply inlined for now.
--- drivers/bus/pci/linux/pci.c | 176 +++++++++++++++--------------------- 1 file changed, 71 insertions(+), 105 deletions(-)
drivers/bus/pci/linux/pci.c +71 -105
@@ -497,86 +497,6 @@ rte_pci_scan(void)return -1 ; } -/* -* Is pci device bound to any kdrv -*/ -static inline int -pci_one_device_is_bound (void ) -{ -struct rte_pci_device *dev =NULL ; -int ret =0 ; - -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (dev->kdrv ==RTE_KDRV_UNKNOWN || - dev->kdrv ==RTE_KDRV_NONE ) { -continue ; - }else { - ret =1 ; -break ; - } - } -return ret; -} - -/* -* Any one of the device bound to uio -*/ -static inline int -pci_one_device_bound_uio (void ) -{ -struct rte_pci_device *dev =NULL ; -struct rte_devargs *devargs; -int need_check; - -FOREACH_DEVICE_ON_PCIBUS (dev) { - devargs = dev->device.devargs; - - need_check =0 ; -switch (rte_pci_bus.bus.conf.scan_mode) { -case RTE_BUS_SCAN_WHITELIST : -if (devargs && devargs->policy ==RTE_DEV_WHITELISTED ) - need_check =1 ; -break ; -case RTE_BUS_SCAN_UNDEFINED : -case RTE_BUS_SCAN_BLACKLIST : -if (devargs ==NULL || - devargs->policy !=RTE_DEV_BLACKLISTED ) - need_check =1 ; -break ; - } - -if (!need_check) -continue ; - -if (dev->kdrv ==RTE_KDRV_IGB_UIO || - dev->kdrv ==RTE_KDRV_UIO_GENERIC ) { -return 1 ; - } - } -return 0 ; -} - -/* -* Any one of the device has iova as va -*/ -static inline int -pci_one_device_has_iova_va (void ) -{ -struct rte_pci_device *dev =NULL ; -struct rte_pci_driver *drv =NULL ; - -FOREACH_DRIVER_ON_PCIBUS (drv) { -if (drv && drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (dev->kdrv ==RTE_KDRV_VFIO && -rte_pci_match (drv, dev)) -return 1 ; - } - } - } -return 0 ; -} -#if defined(RTE_ARCH_X86 )static bool pci_one_device_iommu_support_va (struct rte_pci_device *dev)
@@ -641,14 +561,76 @@ pci_one_device_iommu_support_va(__rte_unused struct rte_pci_device *dev)#endif /* -* All devices IOMMUs support VA as IOVA +* Get iommu class of PCI devices on the bus. */ -static bool -pci_devices_iommu_support_va (void ) +enum rte_iova_mode +rte_pci_get_iommu_class (void ) { +bool is_bound = false; +bool is_vfio_noiommu_enabled = true; +bool has_iova_va = false; +bool is_bound_uio = false; +bool iommu_no_va = false; +bool break_out; +bool need_check;struct rte_pci_device *dev =NULL ;struct rte_pci_driver *drv =NULL ; +struct rte_devargs *devargs; + +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (dev->kdrv ==RTE_KDRV_UNKNOWN || + dev->kdrv ==RTE_KDRV_NONE ) { +continue ; + }else { + is_bound = true; +break ; + } + } +if (!is_bound) +return RTE_IOVA_DC ; +FOREACH_DRIVER_ON_PCIBUS (drv) { +if (drv && drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (dev->kdrv ==RTE_KDRV_VFIO && +rte_pci_match (drv, dev)) { + has_iova_va = true; +break ; + } + } + +if (has_iova_va) +break ; + } + } + +FOREACH_DEVICE_ON_PCIBUS (dev) { + devargs = dev->device.devargs; + + need_check = false; +switch (rte_pci_bus.bus.conf.scan_mode) { +case RTE_BUS_SCAN_WHITELIST : +if (devargs && devargs->policy ==RTE_DEV_WHITELISTED ) + need_check = true; +break ; +case RTE_BUS_SCAN_UNDEFINED : +case RTE_BUS_SCAN_BLACKLIST : +if (devargs ==NULL || + devargs->policy !=RTE_DEV_BLACKLISTED ) + need_check = true; +break ; + } + +if (!need_check) +continue ; + +if (dev->kdrv ==RTE_KDRV_IGB_UIO || + dev->kdrv ==RTE_KDRV_UIO_GENERIC ) { + is_bound_uio = true; + } + } + + break_out = false;FOREACH_DRIVER_ON_PCIBUS (drv) {FOREACH_DEVICE_ON_PCIBUS (dev) {if (!rte_pci_match (drv, dev))
@@ -657,31 +639,15 @@ pci_devices_iommu_support_va(void)* just one PCI device needs to be checked out because * the IOMMU hardware is the same for all of them. */ -return pci_one_device_iommu_support_va (dev); + iommu_no_va = !pci_one_device_iommu_support_va (dev); + break_out = true; +break ; } - } -return true; -} -/* -* Get iommu class of PCI devices on the bus. -*/ -enum rte_iova_mode -rte_pci_get_iommu_class (void ) -{ -bool is_bound; -bool is_vfio_noiommu_enabled = true; -bool has_iova_va; -bool is_bound_uio; -bool iommu_no_va; - - is_bound =pci_one_device_is_bound (); -if (!is_bound) -return RTE_IOVA_DC ; +if (break_out) +break ; + } - has_iova_va =pci_one_device_has_iova_va (); - is_bound_uio =pci_one_device_bound_uio (); - iommu_no_va = !pci_devices_iommu_support_va ();#ifdef VFIO_PRESENT is_vfio_noiommu_enabled =rte_vfio_noiommu_is_enabled () == true ? true : false;
Signature · 1 line
2.20.1
PATCH v2 3/12 eal/pci: Rework loops in rte_pci_get_iommu_class
In reply to Ben WalkerMake all of the loops first iterate over devices, then drivers. This is in preparation for combining them into a single loop.
--- drivers/bus/pci/linux/pci.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/bus/pci/linux/pci.c +6 -6
@@ -589,10 +589,10 @@ rte_pci_get_iommu_class(void)if (!is_bound)return RTE_IOVA_DC ; -FOREACH_DRIVER_ON_PCIBUS (drv) { -if (drv && drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (dev->kdrv ==RTE_KDRV_VFIO && +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (dev->kdrv ==RTE_KDRV_VFIO ) { +FOREACH_DRIVER_ON_PCIBUS (drv) { +if (drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA &&rte_pci_match (drv, dev)) { has_iova_va = true;break ;
@@ -631,8 +631,8 @@ rte_pci_get_iommu_class(void) } break_out = false; -FOREACH_DRIVER_ON_PCIBUS (drv) { -FOREACH_DEVICE_ON_PCIBUS (dev) { +FOREACH_DEVICE_ON_PCIBUS (dev) { +FOREACH_DRIVER_ON_PCIBUS (drv) {if (!rte_pci_match (drv, dev))continue ;/*
Signature · 1 line
2.20.1
PATCH v2 4/12 eal/pci: Collapse two loops in rte_pci_get_iommu_class
In reply to Ben WalkerTwo of these loops easily collapse into a single loop. This sets the stage for future simplifications.
--- drivers/bus/pci/linux/pci.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-)
drivers/bus/pci/linux/pci.c +10 -21
@@ -571,7 +571,6 @@ rte_pci_get_iommu_class(void)bool has_iova_va = false;bool is_bound_uio = false;bool iommu_no_va = false; -bool break_out;bool need_check;struct rte_pci_device *dev =NULL ;struct rte_pci_driver *drv =NULL ;
@@ -592,8 +591,16 @@ rte_pci_get_iommu_class(void)FOREACH_DEVICE_ON_PCIBUS (dev) {if (dev->kdrv ==RTE_KDRV_VFIO ) {FOREACH_DRIVER_ON_PCIBUS (drv) { -if (drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA && -rte_pci_match (drv, dev)) { +if (!rte_pci_match (drv, dev)) +continue ; + +/* +* just one PCI device needs to be checked out because +* the IOMMU hardware is the same for all of them. +*/ + iommu_no_va = !pci_one_device_iommu_support_va (dev); + +if (drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { has_iova_va = true;break ; }
@@ -630,24 +637,6 @@ rte_pci_get_iommu_class(void) } } - break_out = false; -FOREACH_DEVICE_ON_PCIBUS (dev) { -FOREACH_DRIVER_ON_PCIBUS (drv) { -if (!rte_pci_match (drv, dev)) -continue ; -/* -* just one PCI device needs to be checked out because -* the IOMMU hardware is the same for all of them. -*/ - iommu_no_va = !pci_one_device_iommu_support_va (dev); - break_out = true; -break ; - } - -if (break_out) -break ; - } -#ifdef VFIO_PRESENT is_vfio_noiommu_enabled =rte_vfio_noiommu_is_enabled () == true ? true : false;
Signature · 1 line
2.20.1
PATCH v2 5/12 eal/pci: Add function pci_ignore_device
In reply to Ben WalkerThis performs a check for whether the device should be ignored due to whitelist or blacklist. This check eventually needs to apply to all of the other checks in rte_pci_get_iommu_class.
--- drivers/bus/pci/linux/pci.c | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-)
drivers/bus/pci/linux/pci.c +25 -19
@@ -560,6 +560,29 @@ pci_one_device_iommu_support_va(__rte_unused struct rte_pci_device *dev) }#endif +static bool +pci_ignore_device (struct rte_pci_device *dev) +{ +struct rte_devargs *devargs; + + devargs = dev->device.devargs; + +switch (rte_pci_bus.bus.conf.scan_mode) { +case RTE_BUS_SCAN_WHITELIST : +if (devargs && devargs->policy ==RTE_DEV_WHITELISTED ) +return false; +break ; +case RTE_BUS_SCAN_UNDEFINED : +case RTE_BUS_SCAN_BLACKLIST : +if (devargs ==NULL || + devargs->policy !=RTE_DEV_BLACKLISTED ) +return false; +break ; + } + +return true; +} +/* * Get iommu class of PCI devices on the bus. */
@@ -571,10 +594,9 @@ rte_pci_get_iommu_class(void)bool has_iova_va = false;bool is_bound_uio = false;bool iommu_no_va = false; -bool need_check;struct rte_pci_device *dev =NULL ;struct rte_pci_driver *drv =NULL ; -struct rte_devargs *devargs; +FOREACH_DEVICE_ON_PCIBUS (dev) { if (dev->kdrv == RTE_KDRV_UNKNOWN ||
@@ -612,23 +634,7 @@ rte_pci_get_iommu_class(void) }FOREACH_DEVICE_ON_PCIBUS (dev) { - devargs = dev->device.devargs; - - need_check = false; -switch (rte_pci_bus.bus.conf.scan_mode) { -case RTE_BUS_SCAN_WHITELIST : -if (devargs && devargs->policy ==RTE_DEV_WHITELISTED ) - need_check = true; -break ; -case RTE_BUS_SCAN_UNDEFINED : -case RTE_BUS_SCAN_BLACKLIST : -if (devargs ==NULL || - devargs->policy !=RTE_DEV_BLACKLISTED ) - need_check = true; -break ; - } - -if (!need_check) +if (pci_ignore_device (dev))continue ; if (dev->kdrv == RTE_KDRV_IGB_UIO ||
Signature · 1 line
2.20.1
PATCH v2 6/12 eal/pci: Correctly test whitelist/blacklist in rte_pci_get_iommu_class
In reply to Ben WalkerAll of the checks should respect the white and black lists.
--- drivers/bus/pci/linux/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +6 -1
@@ -597,8 +597,10 @@ rte_pci_get_iommu_class(void)struct rte_pci_device *dev =NULL ;struct rte_pci_driver *drv =NULL ; -FOREACH_DEVICE_ON_PCIBUS (dev) { +if (pci_ignore_device (dev)) +continue ; +if (dev->kdrv ==RTE_KDRV_UNKNOWN || dev->kdrv ==RTE_KDRV_NONE ) {continue ;
@@ -611,6 +613,9 @@ rte_pci_get_iommu_class(void)return RTE_IOVA_DC ;FOREACH_DEVICE_ON_PCIBUS (dev) { +if (pci_ignore_device (dev)) +continue ; +if (dev->kdrv ==RTE_KDRV_VFIO ) {FOREACH_DRIVER_ON_PCIBUS (drv) {if (!rte_pci_match (drv, dev))
Signature · 1 line
2.20.1
PATCH v2 7/12 eal/pci: Reverse if check in rte_pci_get_iommu_class
In reply to Ben WalkerIt's simpler to reverse the if statement here, especially with an upcoming simplification.
--- drivers/bus/pci/linux/pci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/bus/pci/linux/pci.c +2 -4
@@ -601,10 +601,8 @@ rte_pci_get_iommu_class(void)if (pci_ignore_device (dev))continue ; -if (dev->kdrv ==RTE_KDRV_UNKNOWN || - dev->kdrv ==RTE_KDRV_NONE ) { -continue ; - }else { +if (dev->kdrv !=RTE_KDRV_UNKNOWN && + dev->kdrv !=RTE_KDRV_NONE ) { is_bound = true;break ; }
Signature · 1 line
2.20.1
PATCH v2 8/12 eal/pci: Collapse loops in rte_pci_get_iommu_class
In reply to Ben WalkerThe three loops can now be easily combined into one.
This is slightly less efficient than before because it doesn't break out early. But that can be addressed later.
--- drivers/bus/pci/linux/pci.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-)
drivers/bus/pci/linux/pci.c +3 -16
@@ -604,15 +604,7 @@ rte_pci_get_iommu_class(void)if (dev->kdrv !=RTE_KDRV_UNKNOWN && dev->kdrv !=RTE_KDRV_NONE ) { is_bound = true; -break ; } - } -if (!is_bound) -return RTE_IOVA_DC ; - -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (pci_ignore_device (dev)) -continue ;if (dev->kdrv ==RTE_KDRV_VFIO ) {FOREACH_DRIVER_ON_PCIBUS (drv) {
@@ -630,15 +622,7 @@ rte_pci_get_iommu_class(void)break ; } } - -if (has_iova_va) -break ; } - } - -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (pci_ignore_device (dev)) -continue ;if (dev->kdrv ==RTE_KDRV_IGB_UIO || dev->kdrv ==RTE_KDRV_UIO_GENERIC ) {
@@ -646,6 +630,9 @@ rte_pci_get_iommu_class(void) } } +if (!is_bound) +return RTE_IOVA_DC ; +#ifdef VFIO_PRESENT is_vfio_noiommu_enabled =rte_vfio_noiommu_is_enabled () == true ? true : false;
Signature · 1 line
2.20.1
PATCH v2 9/12 eal/pci: Simplify rte_pci_get_iommu class by using a switch
In reply to Ben WalkerTake several independent if statements and convert to a switch statement.
--- drivers/bus/pci/linux/pci.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/bus/pci/linux/pci.c +12 -9
@@ -601,12 +601,12 @@ rte_pci_get_iommu_class(void)if (pci_ignore_device (dev))continue ; -if (dev->kdrv !=RTE_KDRV_UNKNOWN && - dev->kdrv !=RTE_KDRV_NONE ) { +switch (dev->kdrv) { +case RTE_KDRV_UNKNOWN : +case RTE_KDRV_NONE : +break ; +case RTE_KDRV_VFIO : is_bound = true; - } - -if (dev->kdrv ==RTE_KDRV_VFIO ) { FOREACH_DRIVER_ON_PCIBUS(drv) {if (!rte_pci_match (drv, dev))continue ;
@@ -622,11 +622,14 @@ rte_pci_get_iommu_class(void)break ; } } - } - -if (dev->kdrv ==RTE_KDRV_IGB_UIO || - dev->kdrv ==RTE_KDRV_UIO_GENERIC ) { +break ; +case RTE_KDRV_IGB_UIO : +case RTE_KDRV_UIO_GENERIC : +case RTE_KDRV_NIC_UIO : + is_bound = true; is_bound_uio = true; +break ; + } }
Signature · 1 line
2.20.1
PATCH v2 10/12 eal/pci: Finding a device bound to UIO does not force PA
In reply to Ben WalkerIf a device is found that is bound to the UIO driver, only force IOVA_PA if there is a driver registered to use it.
--- drivers/bus/pci/linux/pci.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +7 -1
@@ -627,7 +627,13 @@ rte_pci_get_iommu_class(void)case RTE_KDRV_UIO_GENERIC :case RTE_KDRV_NIC_UIO : is_bound = true; - is_bound_uio = true; + FOREACH_DRIVER_ON_PCIBUS(drv) { +if (!rte_pci_match (drv, dev)) +continue ; + + is_bound_uio = true; +break ; + }break ; }
Signature · 1 line
2.20.1
PATCH v2 11/12 eal/pci: rte_pci_get_iommu_class handles no drivers
In reply to Ben WalkerIn the case where no drivers are registered with the system, rte_pci_get_iommu_class should return RTE_IOVA_DC.
--- drivers/bus/pci/linux/pci.c | 91 ++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 41 deletions(-)
drivers/bus/pci/linux/pci.c +50 -41
@@ -589,49 +589,80 @@ pci_ignore_device(struct rte_pci_device *dev)enum rte_iova_mode rte_pci_get_iommu_class (void ) { -bool is_bound = false; -bool is_vfio_noiommu_enabled = true; -bool has_iova_va = false; -bool is_bound_uio = false; -bool iommu_no_va = false; -struct rte_pci_device *dev =NULL ; -struct rte_pci_driver *drv =NULL ; +struct rte_pci_device *dev; +struct rte_pci_driver *drv; +struct rte_pci_addr *addr; +enum rte_iova_mode iova_mode; + + iova_mode =RTE_IOVA_DC ;FOREACH_DEVICE_ON_PCIBUS (dev) {if (pci_ignore_device (dev))continue ; + addr = &dev->addr; +switch (dev->kdrv) {case RTE_KDRV_UNKNOWN :case RTE_KDRV_NONE :break ;case RTE_KDRV_VFIO : - is_bound = true; FOREACH_DRIVER_ON_PCIBUS(drv) {if (!rte_pci_match (drv, dev))continue ; -/* -* just one PCI device needs to be checked out because -* the IOMMU hardware is the same for all of them. -*/ - iommu_no_va = !pci_one_device_iommu_support_va (dev); +if ((drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) ==0 ) +continue ; -if (drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { - has_iova_va = true; -break ; +if (!pci_one_device_iommu_support_va (dev)) { +RTE_LOG (WARNING ,EAL ,"Device " PCI_PRI_FMT +" wanted IOVA as VA, but " , + addr->domain, addr->bus, addr->devid, + addr->function); +RTE_LOG (WARNING ,EAL , +"IOMMU does not support it.\n" ); + iova_mode =RTE_IOVA_PA ; + } +#ifdef VFIO_PRESENT + else if (rte_vfio_noiommu_is_enabled()) { +RTE_LOG (WARNING ,EAL ,"Device " PCI_PRI_FMT +" wanted IOVA as VA, but " , + addr->domain, addr->bus, addr->devid, + addr->function); +RTE_LOG (WARNING ,EAL , +"vfio-noiommu is enabled.\n" ); + iova_mode =RTE_IOVA_PA ; +#endif + } else if (iova_mode == RTE_IOVA_PA) { +RTE_LOG (WARNING ,EAL ,"Device " PCI_PRI_FMT +" wanted IOVA as VA, but " , + addr->domain, addr->bus, addr->devid, + addr->function); +RTE_LOG (WARNING ,EAL , +"other devices require PA.\n" ); + } else { + iova_mode =RTE_IOVA_VA ; } }break ;case RTE_KDRV_IGB_UIO :case RTE_KDRV_UIO_GENERIC :case RTE_KDRV_NIC_UIO : - is_bound = true; FOREACH_DRIVER_ON_PCIBUS(drv) {if (!rte_pci_match (drv, dev))continue ; - is_bound_uio = true; +if (iova_mode ==RTE_IOVA_VA ) { +RTE_LOG (WARNING ,EAL , +"Some devices wanted IOVA as VA, but " ); +RTE_LOG (WARNING ,EAL ,"device " PCI_PRI_FMT +" requires PA.\n" , + addr->domain, addr->bus, addr->devid, + addr->function); + + } + + iova_mode =RTE_IOVA_PA ;break ; }break ;
@@ -639,29 +670,7 @@ rte_pci_get_iommu_class(void) } } -if (!is_bound) -return RTE_IOVA_DC ; - -#ifdef VFIO_PRESENT - is_vfio_noiommu_enabled =rte_vfio_noiommu_is_enabled () == true ? - true : false; -#endif - -if (has_iova_va && !is_bound_uio && !is_vfio_noiommu_enabled && - !iommu_no_va) -return RTE_IOVA_VA ; - -if (has_iova_va) { -RTE_LOG (WARNING ,EAL ,"Some devices want iova as va but pa will be used because.. " ); -if (is_vfio_noiommu_enabled) -RTE_LOG (WARNING ,EAL ,"vfio-noiommu mode configured\n" ); -if (is_bound_uio) -RTE_LOG (WARNING ,EAL ,"few device bound to UIO\n" ); -if (iommu_no_va) -RTE_LOG (WARNING ,EAL ,"IOMMU does not support IOVA as VA\n" ); - } - -return RTE_IOVA_PA ; +return iova_mode; }/* Read PCI config space. */
Signature · 1 line
2.20.1
PATCH v2 12/12 eal: If bus can't decide PA or VA, try to access PA
In reply to Ben WalkerIf the bus can't determine a preference for IOVA_PA vs. IOVA_VA by looking at the devices and drivers, as a last resort test if physical addresses are even accessible in /proc/self/pagemap. If they are, use IOVA_PA. If they are not, use IOVA_VA.
--- lib/librte_eal/common/eal_common_bus.c | 4 ---- lib/librte_eal/linux/eal/eal.c | 30 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-)
lib/librte_eal/common/eal_common_bus.c +0 -4
@@ -237,10 +237,6 @@ rte_bus_get_iommu_class(void) mode |= bus->get_iommu_class (); } -if (mode !=RTE_IOVA_VA ) { -/* Use default IOVA mode */ - mode =RTE_IOVA_PA ; - }return mode; }
lib/librte_eal/linux/eal/eal.c +23 -7
@@ -948,6 +948,7 @@ rte_eal_init(int argc, char **argv)static char logid[PATH_MAX ];char cpuset[RTE_CPU_AFFINITY_STR_LEN ];char thread_name[RTE_MAX_THREAD_NAME_LEN ]; +enum rte_iova_mode iova_mode;/* checks if the machine is adequate */ if (!rte_cpu_is_supported ()) {
@@ -1037,18 +1038,33 @@ rte_eal_init(int argc, char **argv)/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */ if (internal_config.iova_mode ==RTE_IOVA_DC ) { -/* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ -rte_eal_get_configuration ()->iova_mode = -rte_bus_get_iommu_class (); +/* autodetect the IOVA mapping mode */ + iova_mode =rte_bus_get_iommu_class ();/* Workaround for KNI which requires physical address to work */ -if (rte_eal_get_configuration ()->iova_mode ==RTE_IOVA_VA && +if (iova_mode ==RTE_IOVA_VA &&rte_eal_check_module ("rte_kni" ) ==1 ) { -rte_eal_get_configuration ()->iova_mode =RTE_IOVA_PA ; + iova_mode =RTE_IOVA_PA ;RTE_LOG (WARNING ,EAL , -"Some devices want IOVA as VA but PA will be used because.. " -"KNI module inserted\n" ); +"Some devices want IOVA as VA but PA will be" +" used because KNI module inserted\n" ); + } + +if (iova_mode ==RTE_IOVA_DC ) { +/* If the bus doesn't care, check if physical addresses are +* accessible. +*/ +if (rte_eal_using_phys_addrs ()) { +/* Physical addresses are available, so the safest +* choice is to use those. +*/ + iova_mode =RTE_IOVA_PA ; + }else { + iova_mode =RTE_IOVA_VA ; + } } + +rte_eal_get_configuration ()->iova_mode = iova_mode; }else {rte_eal_get_configuration ()->iova_mode = internal_config.iova_mode;
Signature · 1 line
2.20.1
PATCH 2/12 eal/pci: Inline several functions into rte_pci_get_iommu_class
In reply to Ben WalkerThis is in preparation for future simplifications. The functions are simply inlined for now.
--- drivers/bus/pci/linux/pci.c | 176 +++++++++++++++--------------------- 1 file changed, 71 insertions(+), 105 deletions(-)
drivers/bus/pci/linux/pci.c +71 -105
@@ -497,86 +497,6 @@ rte_pci_scan(void)return -1 ; } -/* -* Is pci device bound to any kdrv -*/ -static inline int -pci_one_device_is_bound (void ) -{ -struct rte_pci_device *dev =NULL ; -int ret =0 ; - -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (dev->kdrv ==RTE_KDRV_UNKNOWN || - dev->kdrv ==RTE_KDRV_NONE ) { -continue ; - }else { - ret =1 ; -break ; - } - } -return ret; -} - -/* -* Any one of the device bound to uio -*/ -static inline int -pci_one_device_bound_uio (void ) -{ -struct rte_pci_device *dev =NULL ; -struct rte_devargs *devargs; -int need_check; - -FOREACH_DEVICE_ON_PCIBUS (dev) { - devargs = dev->device.devargs; - - need_check =0 ; -switch (rte_pci_bus.bus.conf.scan_mode) { -case RTE_BUS_SCAN_WHITELIST : -if (devargs && devargs->policy ==RTE_DEV_WHITELISTED ) - need_check =1 ; -break ; -case RTE_BUS_SCAN_UNDEFINED : -case RTE_BUS_SCAN_BLACKLIST : -if (devargs ==NULL || - devargs->policy !=RTE_DEV_BLACKLISTED ) - need_check =1 ; -break ; - } - -if (!need_check) -continue ; - -if (dev->kdrv ==RTE_KDRV_IGB_UIO || - dev->kdrv ==RTE_KDRV_UIO_GENERIC ) { -return 1 ; - } - } -return 0 ; -} - -/* -* Any one of the device has iova as va -*/ -static inline int -pci_one_device_has_iova_va (void ) -{ -struct rte_pci_device *dev =NULL ; -struct rte_pci_driver *drv =NULL ; - -FOREACH_DRIVER_ON_PCIBUS (drv) { -if (drv && drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (dev->kdrv ==RTE_KDRV_VFIO && -rte_pci_match (drv, dev)) -return 1 ; - } - } - } -return 0 ; -} -#if defined(RTE_ARCH_X86 )static bool pci_one_device_iommu_support_va (struct rte_pci_device *dev)
@@ -641,14 +561,76 @@ pci_one_device_iommu_support_va(__rte_unused struct rte_pci_device *dev)#endif /* -* All devices IOMMUs support VA as IOVA +* Get iommu class of PCI devices on the bus. */ -static bool -pci_devices_iommu_support_va (void ) +enum rte_iova_mode +rte_pci_get_iommu_class (void ) { +bool is_bound = false; +bool is_vfio_noiommu_enabled = true; +bool has_iova_va = false; +bool is_bound_uio = false; +bool iommu_no_va = false; +bool break_out; +bool need_check;struct rte_pci_device *dev =NULL ;struct rte_pci_driver *drv =NULL ; +struct rte_devargs *devargs; + +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (dev->kdrv ==RTE_KDRV_UNKNOWN || + dev->kdrv ==RTE_KDRV_NONE ) { +continue ; + }else { + is_bound = true; +break ; + } + } +if (!is_bound) +return RTE_IOVA_DC ; +FOREACH_DRIVER_ON_PCIBUS (drv) { +if (drv && drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (dev->kdrv ==RTE_KDRV_VFIO && +rte_pci_match (drv, dev)) { + has_iova_va = true; +break ; + } + } + +if (has_iova_va) +break ; + } + } + +FOREACH_DEVICE_ON_PCIBUS (dev) { + devargs = dev->device.devargs; + + need_check = false; +switch (rte_pci_bus.bus.conf.scan_mode) { +case RTE_BUS_SCAN_WHITELIST : +if (devargs && devargs->policy ==RTE_DEV_WHITELISTED ) + need_check = true; +break ; +case RTE_BUS_SCAN_UNDEFINED : +case RTE_BUS_SCAN_BLACKLIST : +if (devargs ==NULL || + devargs->policy !=RTE_DEV_BLACKLISTED ) + need_check = true; +break ; + } + +if (!need_check) +continue ; + +if (dev->kdrv ==RTE_KDRV_IGB_UIO || + dev->kdrv ==RTE_KDRV_UIO_GENERIC ) { + is_bound_uio = true; + } + } + + break_out = false;FOREACH_DRIVER_ON_PCIBUS (drv) {FOREACH_DEVICE_ON_PCIBUS (dev) {if (!rte_pci_match (drv, dev))
@@ -657,31 +639,15 @@ pci_devices_iommu_support_va(void)* just one PCI device needs to be checked out because * the IOMMU hardware is the same for all of them. */ -return pci_one_device_iommu_support_va (dev); + iommu_no_va = !pci_one_device_iommu_support_va (dev); + break_out = true; +break ; } - } -return true; -} -/* -* Get iommu class of PCI devices on the bus. -*/ -enum rte_iova_mode -rte_pci_get_iommu_class (void ) -{ -bool is_bound; -bool is_vfio_noiommu_enabled = true; -bool has_iova_va; -bool is_bound_uio; -bool iommu_no_va; - - is_bound =pci_one_device_is_bound (); -if (!is_bound) -return RTE_IOVA_DC ; +if (break_out) +break ; + } - has_iova_va =pci_one_device_has_iova_va (); - is_bound_uio =pci_one_device_bound_uio (); - iommu_no_va = !pci_devices_iommu_support_va ();#ifdef VFIO_PRESENT is_vfio_noiommu_enabled =rte_vfio_noiommu_is_enabled () == true ? true : false;
Signature · 1 line
2.20.1
Re: [dpdk-dev] [PATCH 02/12] eal/pci: Inline several functions into rte_pci_get_iommu_class
Quoted 5 lines · On Thu, 30 May 2019 10:48:09 -0700 Ben Walker <[email protected]> wrote:
This is in preparation for future simplifications. The functions are simply inlined for now.
Signed-off-by Ben Walker <[email protected]>Change-Id I129992c9b44f4575a28cc05b78297e15b6be4249
Please don't inline any functions that are not in the fast path. The compiler will do it anyway.
Re: [dpdk-dev] [PATCH 02/12] eal/pci: Inline several functions into rte_pci_get_iommu_class
Quoted 11 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, May 30, 2019 10:57 AM
To: Walker, Benjamin <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH 02/12] eal/pci: Inline several functions intorte_pci_get_iommu_classOn Thu, 30 May 2019 10:48:09 -0700
Ben Walker <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines
This is in preparation for future simplifications. The functions are simply inlined for now.
Signed-off-by Ben Walker <[email protected]>Change-Id I129992c9b44f4575a28cc05b78297e15b6be4249Please don't inline any functions that are not in the fast path. The compiler will do it anyway.
That's not what I mean by inline. I didn't mark the functions inline - I copied their contents into the single place they are called. This patch is a set up patch for a later one that refactors the way this function works, and doing this makes the diff easier to read.
PATCH 3/12 eal/pci: Rework loops in rte_pci_get_iommu_class
In reply to Ben WalkerMake all of the loops first iterate over devices, then drivers. This is in preparation for combining them into a single loop.
--- drivers/bus/pci/linux/pci.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/bus/pci/linux/pci.c +6 -6
@@ -589,10 +589,10 @@ rte_pci_get_iommu_class(void)if (!is_bound)return RTE_IOVA_DC ; -FOREACH_DRIVER_ON_PCIBUS (drv) { -if (drv && drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (dev->kdrv ==RTE_KDRV_VFIO && +FOREACH_DEVICE_ON_PCIBUS (dev) { +if (dev->kdrv ==RTE_KDRV_VFIO ) { +FOREACH_DRIVER_ON_PCIBUS (drv) { +if (drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA &&rte_pci_match (drv, dev)) { has_iova_va = true;break ;
@@ -631,8 +631,8 @@ rte_pci_get_iommu_class(void) } break_out = false; -FOREACH_DRIVER_ON_PCIBUS (drv) { -FOREACH_DEVICE_ON_PCIBUS (dev) { +FOREACH_DEVICE_ON_PCIBUS (dev) { +FOREACH_DRIVER_ON_PCIBUS (drv) {if (!rte_pci_match (drv, dev))continue ;/*
Signature · 1 line
2.20.1
PATCH 4/12 eal/pci: Collapse two loops in rte_pci_get_iommu_class
In reply to Ben WalkerTwo of these loops easily collapse into a single loop. This sets the stage for future simplifications.
--- drivers/bus/pci/linux/pci.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-)
drivers/bus/pci/linux/pci.c +10 -21
@@ -571,7 +571,6 @@ rte_pci_get_iommu_class(void)bool has_iova_va = false;bool is_bound_uio = false;bool iommu_no_va = false; -bool break_out;bool need_check;struct rte_pci_device *dev =NULL ;struct rte_pci_driver *drv =NULL ;
@@ -592,8 +591,16 @@ rte_pci_get_iommu_class(void)FOREACH_DEVICE_ON_PCIBUS (dev) {if (dev->kdrv ==RTE_KDRV_VFIO ) {FOREACH_DRIVER_ON_PCIBUS (drv) { -if (drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA && -rte_pci_match (drv, dev)) { +if (!rte_pci_match (drv, dev)) +continue ; + +/* +* just one PCI device needs to be checked out because +* the IOMMU hardware is the same for all of them. +*/ + iommu_no_va = !pci_one_device_iommu_support_va (dev); + +if (drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { has_iova_va = true;break ; }
@@ -630,24 +637,6 @@ rte_pci_get_iommu_class(void) } } - break_out = false; -FOREACH_DEVICE_ON_PCIBUS (dev) { -FOREACH_DRIVER_ON_PCIBUS (drv) { -if (!rte_pci_match (drv, dev)) -continue ; -/* -* just one PCI device needs to be checked out because -* the IOMMU hardware is the same for all of them. -*/ - iommu_no_va = !pci_one_device_iommu_support_va (dev); - break_out = true; -break ; - } - -if (break_out) -break ; - } -#ifdef VFIO_PRESENT is_vfio_noiommu_enabled =rte_vfio_noiommu_is_enabled () == true ? true : false;
Signature · 1 line
2.20.1
PATCH 5/12 eal/pci: Add function pci_ignore_device
In reply to Ben WalkerThis performs a check for whether the device should be ignored due to whitelist or blacklist. This check eventually needs to apply to all of the other checks in rte_pci_get_iommu_class.
--- drivers/bus/pci/linux/pci.c | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-)
drivers/bus/pci/linux/pci.c +25 -19
@@ -560,6 +560,29 @@ pci_one_device_iommu_support_va(__rte_unused struct rte_pci_device *dev) }#endif +static bool +pci_ignore_device (struct rte_pci_device *dev) +{ +struct rte_devargs *devargs; + + devargs = dev->device.devargs; + +switch (rte_pci_bus.bus.conf.scan_mode) { +case RTE_BUS_SCAN_WHITELIST : +if (devargs && devargs->policy ==RTE_DEV_WHITELISTED ) +return false; +break ; +case RTE_BUS_SCAN_UNDEFINED : +case RTE_BUS_SCAN_BLACKLIST : +if (devargs ==NULL || + devargs->policy !=RTE_DEV_BLACKLISTED ) +return false; +break ; + } + +return true; +} +/* * Get iommu class of PCI devices on the bus. */
@@ -571,10 +594,9 @@ rte_pci_get_iommu_class(void)bool has_iova_va = false;bool is_bound_uio = false;bool iommu_no_va = false; -bool need_check;struct rte_pci_device *dev =NULL ;struct rte_pci_driver *drv =NULL ; -struct rte_devargs *devargs; +FOREACH_DEVICE_ON_PCIBUS (dev) { if (dev->kdrv == RTE_KDRV_UNKNOWN ||
@@ -612,23 +634,7 @@ rte_pci_get_iommu_class(void) }FOREACH_DEVICE_ON_PCIBUS (dev) { - devargs = dev->device.devargs; - - need_check = false; -switch (rte_pci_bus.bus.conf.scan_mode) { -case RTE_BUS_SCAN_WHITELIST : -if (devargs && devargs->policy ==RTE_DEV_WHITELISTED ) - need_check = true; -break ; -case RTE_BUS_SCAN_UNDEFINED : -case RTE_BUS_SCAN_BLACKLIST : -if (devargs ==NULL || - devargs->policy !=RTE_DEV_BLACKLISTED ) - need_check = true; -break ; - } - -if (!need_check) +if (pci_ignore_device (dev))continue ; if (dev->kdrv == RTE_KDRV_IGB_UIO ||
Signature · 1 line
2.20.1
PATCH 6/12 eal/pci: Correctly test whitelist/blacklist in rte_pci_get_iommu_class
In reply to Ben WalkerAll of the checks should respect the white and black lists.
--- drivers/bus/pci/linux/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +6 -1
@@ -597,8 +597,10 @@ rte_pci_get_iommu_class(void)struct rte_pci_device *dev =NULL ;struct rte_pci_driver *drv =NULL ; -FOREACH_DEVICE_ON_PCIBUS (dev) { +if (pci_ignore_device (dev)) +continue ; +if (dev->kdrv ==RTE_KDRV_UNKNOWN || dev->kdrv ==RTE_KDRV_NONE ) {continue ;
@@ -611,6 +613,9 @@ rte_pci_get_iommu_class(void)return RTE_IOVA_DC ;FOREACH_DEVICE_ON_PCIBUS (dev) { +if (pci_ignore_device (dev)) +continue ; +if (dev->kdrv ==RTE_KDRV_VFIO ) {FOREACH_DRIVER_ON_PCIBUS (drv) {if (!rte_pci_match (drv, dev))
Signature · 1 line
2.20.1
PATCH 7/12 eal/pci: Reverse if check in rte_pci_get_iommu_class
In reply to Ben WalkerIt's simpler to reverse the if statement here, especially with an upcoming simplification.
--- drivers/bus/pci/linux/pci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/bus/pci/linux/pci.c +2 -4
@@ -601,10 +601,8 @@ rte_pci_get_iommu_class(void)if (pci_ignore_device (dev))continue ; -if (dev->kdrv ==RTE_KDRV_UNKNOWN || - dev->kdrv ==RTE_KDRV_NONE ) { -continue ; - }else { +if (dev->kdrv !=RTE_KDRV_UNKNOWN && + dev->kdrv !=RTE_KDRV_NONE ) { is_bound = true;break ; }
Signature · 1 line
2.20.1
PATCH 8/12 eal/pci: Collapse loops in rte_pci_get_iommu_class
In reply to Ben WalkerThe three loops can now be easily combined into one.
This is slightly less efficient than before because it doesn't break out early. But that can be addressed later.
--- drivers/bus/pci/linux/pci.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-)
drivers/bus/pci/linux/pci.c +3 -16
@@ -604,15 +604,7 @@ rte_pci_get_iommu_class(void)if (dev->kdrv !=RTE_KDRV_UNKNOWN && dev->kdrv !=RTE_KDRV_NONE ) { is_bound = true; -break ; } - } -if (!is_bound) -return RTE_IOVA_DC ; - -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (pci_ignore_device (dev)) -continue ;if (dev->kdrv ==RTE_KDRV_VFIO ) {FOREACH_DRIVER_ON_PCIBUS (drv) {
@@ -630,15 +622,7 @@ rte_pci_get_iommu_class(void)break ; } } - -if (has_iova_va) -break ; } - } - -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (pci_ignore_device (dev)) -continue ;if (dev->kdrv ==RTE_KDRV_IGB_UIO || dev->kdrv ==RTE_KDRV_UIO_GENERIC ) {
@@ -646,6 +630,9 @@ rte_pci_get_iommu_class(void) } } +if (!is_bound) +return RTE_IOVA_DC ; +#ifdef VFIO_PRESENT is_vfio_noiommu_enabled =rte_vfio_noiommu_is_enabled () == true ? true : false;
Signature · 1 line
2.20.1
PATCH 9/12 eal/pci: Simplify rte_pci_get_iommu class by using a switch
In reply to Ben WalkerTake several independent if statements and convert to a switch statement.
--- drivers/bus/pci/linux/pci.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/bus/pci/linux/pci.c +12 -9
@@ -601,12 +601,12 @@ rte_pci_get_iommu_class(void)if (pci_ignore_device (dev))continue ; -if (dev->kdrv !=RTE_KDRV_UNKNOWN && - dev->kdrv !=RTE_KDRV_NONE ) { +switch (dev->kdrv) { +case RTE_KDRV_UNKNOWN : +case RTE_KDRV_NONE : +break ; +case RTE_KDRV_VFIO : is_bound = true; - } - -if (dev->kdrv ==RTE_KDRV_VFIO ) { FOREACH_DRIVER_ON_PCIBUS(drv) {if (!rte_pci_match (drv, dev))continue ;
@@ -622,11 +622,14 @@ rte_pci_get_iommu_class(void)break ; } } - } - -if (dev->kdrv ==RTE_KDRV_IGB_UIO || - dev->kdrv ==RTE_KDRV_UIO_GENERIC ) { +break ; +case RTE_KDRV_IGB_UIO : +case RTE_KDRV_UIO_GENERIC : +case RTE_KDRV_NIC_UIO : + is_bound = true; is_bound_uio = true; +break ; + } }
Signature · 1 line
2.20.1
PATCH 10/12 eal/pci: Finding a device bound to UIO does not force PA
In reply to Ben WalkerIf a device is found that is bound to the UIO driver, only force IOVA_PA if there is a driver registered to use it.
--- drivers/bus/pci/linux/pci.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +7 -1
@@ -627,7 +627,13 @@ rte_pci_get_iommu_class(void)case RTE_KDRV_UIO_GENERIC :case RTE_KDRV_NIC_UIO : is_bound = true; - is_bound_uio = true; + FOREACH_DRIVER_ON_PCIBUS(drv) { +if (!rte_pci_match (drv, dev)) +continue ; + + is_bound_uio = true; +break ; + }break ; }
Signature · 1 line
2.20.1
PATCH 11/12 eal/pci: rte_pci_get_iommu_class handles no drivers
In reply to Ben WalkerIn the case where no drivers are registered with the system, rte_pci_get_iommu_class should return RTE_IOVA_DC.
--- drivers/bus/pci/linux/pci.c | 79 ++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 41 deletions(-)
drivers/bus/pci/linux/pci.c +38 -41
@@ -589,49 +589,68 @@ pci_ignore_device(struct rte_pci_device *dev)enum rte_iova_mode rte_pci_get_iommu_class (void ) { -bool is_bound = false; -bool is_vfio_noiommu_enabled = true; -bool has_iova_va = false; -bool is_bound_uio = false; -bool iommu_no_va = false; -struct rte_pci_device *dev =NULL ; -struct rte_pci_driver *drv =NULL ; +struct rte_pci_device *dev; +struct rte_pci_driver *drv; +struct rte_pci_addr *addr; +enum rte_iova_mode iova_mode; + + iova_mode =RTE_IOVA_DC ;FOREACH_DEVICE_ON_PCIBUS (dev) {if (pci_ignore_device (dev))continue ; + addr = &dev->addr; +switch (dev->kdrv) {case RTE_KDRV_UNKNOWN :case RTE_KDRV_NONE :break ;case RTE_KDRV_VFIO : - is_bound = true; FOREACH_DRIVER_ON_PCIBUS(drv) {if (!rte_pci_match (drv, dev))continue ; -/* -* just one PCI device needs to be checked out because -* the IOMMU hardware is the same for all of them. -*/ - iommu_no_va = !pci_one_device_iommu_support_va (dev); +if ((drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) ==0 ) +continue ; -if (drv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) { - has_iova_va = true; -break ; +if (!pci_one_device_iommu_support_va (dev)) { +RTE_LOG (WARNING ,EAL ,"Device " PCI_PRI_FMT " wanted IOVA as VA, but " , + addr->domain, addr->bus, addr->devid, addr->function); +RTE_LOG (WARNING ,EAL ,"IOMMU does not support it.\n" ); + iova_mode =RTE_IOVA_PA ; + } +#ifdef VFIO_PRESENT + else if (rte_vfio_noiommu_is_enabled()) { +RTE_LOG (WARNING ,EAL ,"Device " PCI_PRI_FMT " wanted IOVA as VA, but " , + addr->domain, addr->bus, addr->devid, addr->function); +RTE_LOG (WARNING ,EAL ,"vfio-noiommu is enabled.\n" ); + iova_mode =RTE_IOVA_PA ; +#endif + } else if (iova_mode == RTE_IOVA_PA) { +RTE_LOG (WARNING ,EAL ,"Device " PCI_PRI_FMT " wanted IOVA as VA, but " , + addr->domain, addr->bus, addr->devid, addr->function); +RTE_LOG (WARNING ,EAL ,"other devices require PA.\n" ); + } else { + iova_mode =RTE_IOVA_VA ; } }break ;case RTE_KDRV_IGB_UIO :case RTE_KDRV_UIO_GENERIC :case RTE_KDRV_NIC_UIO : - is_bound = true; FOREACH_DRIVER_ON_PCIBUS(drv) {if (!rte_pci_match (drv, dev))continue ; - is_bound_uio = true; +if (iova_mode ==RTE_IOVA_VA ) { +RTE_LOG (WARNING ,EAL ,"Some devices wanted IOVA as VA, but " ); +RTE_LOG (WARNING ,EAL ,"device " PCI_PRI_FMT " requires PA.\n" , + addr->domain, addr->bus, addr->devid, addr->function); + + } + + iova_mode =RTE_IOVA_PA ;break ; }break ;
@@ -639,29 +658,7 @@ rte_pci_get_iommu_class(void) } } -if (!is_bound) -return RTE_IOVA_DC ; - -#ifdef VFIO_PRESENT - is_vfio_noiommu_enabled =rte_vfio_noiommu_is_enabled () == true ? - true : false; -#endif - -if (has_iova_va && !is_bound_uio && !is_vfio_noiommu_enabled && - !iommu_no_va) -return RTE_IOVA_VA ; - -if (has_iova_va) { -RTE_LOG (WARNING ,EAL ,"Some devices want iova as va but pa will be used because.. " ); -if (is_vfio_noiommu_enabled) -RTE_LOG (WARNING ,EAL ,"vfio-noiommu mode configured\n" ); -if (is_bound_uio) -RTE_LOG (WARNING ,EAL ,"few device bound to UIO\n" ); -if (iommu_no_va) -RTE_LOG (WARNING ,EAL ,"IOMMU does not support IOVA as VA\n" ); - } - -return RTE_IOVA_PA ; +return iova_mode; }/* Read PCI config space. */
Signature · 1 line
2.20.1
PATCH 12/12 eal: If bus can't decide PA or VA, try to access PA
In reply to Ben WalkerIf the bus can't determine a preference for IOVA_PA vs. IOVA_VA by looking at the devices and drivers, as a last resort test if physical addresses are even accessible in /proc/self/pagemap. If they are, use IOVA_PA. If they are not, use IOVA_VA.
Change-Id: If1eeb723283b80b24bd973987054fdad62f59cbd
--- lib/librte_eal/common/eal_common_bus.c | 4 ---- lib/librte_eal/linux/eal/eal.c | 28 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-)
lib/librte_eal/common/eal_common_bus.c +0 -4
@@ -237,10 +237,6 @@ rte_bus_get_iommu_class(void) mode |= bus->get_iommu_class (); } -if (mode !=RTE_IOVA_VA ) { -/* Use default IOVA mode */ - mode =RTE_IOVA_PA ; - }return mode; }
lib/librte_eal/linux/eal/eal.c +21 -7
@@ -948,6 +948,7 @@ rte_eal_init(int argc, char **argv)static char logid[PATH_MAX ];char cpuset[RTE_CPU_AFFINITY_STR_LEN ];char thread_name[RTE_MAX_THREAD_NAME_LEN ]; +enum rte_iova_mode iova_mode;/* checks if the machine is adequate */ if (!rte_cpu_is_supported ()) {
@@ -1037,18 +1038,31 @@ rte_eal_init(int argc, char **argv)/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */ if (internal_config.iova_mode ==RTE_IOVA_DC ) { -/* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ -rte_eal_get_configuration ()->iova_mode = -rte_bus_get_iommu_class (); +/* autodetect the IOVA mapping mode */ + iova_mode =rte_bus_get_iommu_class ();/* Workaround for KNI which requires physical address to work */ -if (rte_eal_get_configuration ()->iova_mode ==RTE_IOVA_VA && +if (iova_mode ==RTE_IOVA_VA &&rte_eal_check_module ("rte_kni" ) ==1 ) { -rte_eal_get_configuration ()->iova_mode =RTE_IOVA_PA ; + iova_mode =RTE_IOVA_PA ;RTE_LOG (WARNING ,EAL , -"Some devices want IOVA as VA but PA will be used because.. " -"KNI module inserted\n" ); +"Some devices want IOVA as VA but PA will be" +" used because KNI module inserted\n" ); + } + +if (iova_mode ==RTE_IOVA_DC ) { +/* If the bus doesn't care, check if physical addresses are +* accessible. */ +if (rte_eal_using_phys_addrs ()) { +/* Physical addresses are available, so the safest +* choice is to use those. */ + iova_mode =RTE_IOVA_PA ; + }else { + iova_mode =RTE_IOVA_VA ; + } } + +rte_eal_get_configuration ()->iova_mode = iova_mode; }else {rte_eal_get_configuration ()->iova_mode = internal_config.iova_mode;
Signature · 1 line
2.20.1
Hello,
Quoted 11 lines · Ben Walker
In SPDK, not all drivers are registered with DPDK at start up time. Previously, that meant DPDK always chose to set itself up in
IOVA_PAmode. Instead, when the correct iova choice is unclear based on the devices and drivers known to DPDK at start up time, use other heuristics (such as whether/proc/self/pagemapis accessible) to make a better choice.This enables SPDK to run as an unprivileged user again without requiring users to explicitly set the iova mode on the command line.
Interesting, I got a bz on something similar the day you sent this patchset ;-)
- When a dpdk process is started, either it has access to physical addresses or not, and this won't change for the rest of its life. Your fix on defaulting to VA based on a rte_eal_using_phys_addrs() check makes sense to me.
It is the most encountered situation when running ovs as non root on recent kernels.
- However, I fail to see the need for all of this detection code wrt drivers and devices.
On one side of the equation, when dpdk starts, it checks physical address availability.
On the other side of the equation, we have the drivers that will be invoked when probing devices (either at dpdk init, or when hotplugging a device).
At this point, the probing call should check the driver requirement wrt to the kernel driver the device is attached to.
If this requirement is not fulfilled, then the probing fails.
- This leaves the --iova-va forcing option.
Why do we need it?
If we don't have access to physical addresses, no choice but run in VA mode. If we have access to physical addresses, the only case would be that you want to downgrade from PA to VA.
But well, your process can still access it, not sure what the benefit is.
Jerin, I can see in the history you worked on this. What did I miss?
Is there something wrong with dropping the detection code?
Signature · 1 line
David Marchand
Quoted 39 lines · David Marchand
Hello,
Quoted 10 lines · Ben Walker
In SPDK, not all drivers are registered with DPDK at start up time. Previously, that meant DPDK always chose to set itself up in
IOVA_PAmode. Instead, when the correct iova choice is unclear based on the devices and drivers known to DPDK at start up time, use other heuristics (such as whether/proc/self/pagemapis accessible) to make a better choice.This enables SPDK to run as an unprivileged user again without requiring users to explicitly set the iova mode on the command line.
Interesting, I got a bz on something similar the day you sent this patchset ;- )
- When a dpdk process is started, either it has access to physical addresses or not, and this won't change for the rest of its life.
Your fix on defaulting to VA based on arte_eal_using_phys_addrs()check makes sense to me.
It is the most encountered situation when running ovs as non root on recent kernels.- However, I fail to see the need for all of this detection code wrt drivers and devices.
On one side of the equation, when dpdk starts, it checks physical address availability.
On the other side of the equation, we have the drivers that will be invoked when probing devices (either at dpdk init, or when hotplugging a device).At this point, the probing call should check the driver requirement wrt to the kernel driver the device is attached to.
If this requirement is not fulfilled, then the probing fails.
Quoted 6 lines
- This leaves the --iova-va forcing option.
Why do we need it?
If we don't have access to physical addresses, no choice but run in VA mode. If we have access to physical addresses, the only case would be that you want to downgrade from PA to VA.
But well, your process can still access it, not sure what the benefit is.
All of the complexity here, at least as far as I understand it, stems from supporting hot insert of devices. This is very important to SPDK because storage devices get hot inserted all the time, so we very much appreciate that DPDK has put in so much effort in this area and continues to accept our patches to improve it. I know hot insert is not nearly as important for network devices.
When DPDK starts up, it needs to select whether to use virtual addresses or physical addresses in its memory maps. It can do that by answering the following questions:
1. Does the system only have buses that support an IOMMU?
2. Is the IOMMU sufficiently fast for the use case?
3. Will all of the devices that will be used with DPDK throughout the application's lifetime work with an IOMMU?
If these three things are true, then the best choice is to use virtual addresses in the memory translations. However, if any of the above are not true it needs to fall back to physical addresses.
#1 is checked by simply asking all of the buses, which are known up front. #2 is just assumed to be true. But #3 is not possible to check fully because of hot insert.
The code currently approximates the #3 check by looking at the devices present at initialization time. If a device exists that's bound to vfio-pci, and no other devices exist that are bound to a uio driver, and DPDK has a registered driver that's actually going to load against the vfio-pci devices, then it will elect to use virtual addresses. This is purely a heuristic - it's not a definitive answer because the user could later hot insert a device that gets bound to uio.
The user, of course, knows the answer to which addressing scheme to use typically. For example, these checks assume #2 is true, but there may be hardware implementations where it is not and the user wants to force physical addresses. Or the user may know that they are going to hot insert a device at run time that doesn't work with the IOMMU. That's why it's important to maintain the ability for the user to override the default heuristic's decision via the command line.
My patch series is simply improving the heuristic in a few ways. First, previously each bus when queried would return either virtual or physical addresses as its choice. However, often the bus just does not have enough information to formulate any preference at all (and PCI was defaulting to physical addresses in this case). Instead, I made it so that the bus can return that it doesn't care, which pushes the decision up to a higher level. That higher level then makes the decision by checking whether it can access /proc/self/pagemap. Second, I narrowed the uio check such that physical addresses will only be selected if a device bound to uio exists and there is a driver registered to use it. Previously if any device was bound to uio it would select physical addresses, even if DPDK never ended up loading against that device.
I think these two things make the heuristic choose the right thing more often, but it still won't always get it right so the command line option needs to remain.
Thanks,
Ben
Quoted 10 lines
Jerin, I can see in the history you worked on this. What did I miss?
Is there something wrong with dropping the detection code?Signature · 1 line
David Marchand
Quoted 130 lines · Benjamin
Quoted 3 lines · David Marchand
Hello,
On Thu, May 30, 2019 at 7:48 PM Ben Walker <[email protected]>
Quoted 4 lines · wrote:
Quoted 4 lines
In SPDK, not all drivers are registered with DPDK at start up time. Previously, that meant DPDK always chose to set itself up in
IOVA_PAmode. Instead, when the correct iova choice is unclear based on the devices and drivers known to DPDK at start up time, use otherheuristics
Quoted 4 lines
Quoted 4 lines
(such as whether
/proc/self/pagemapis accessible) to make a better choice.This enables SPDK to run as an unprivileged user again without
requiring
Quoted 4 lines
Quoted 2 lines
users to explicitly set the iova mode on the command line.
Interesting, I got a bz on something similar the day you sent this
patchset ;-
Quoted 4 lines
)
- When a dpdk process is started, either it has access to physical
addresses
Quoted 2 lines
or not, and this won't change for the rest of its life.
Your fix on defaulting to VA based on arte_eal_using_phys_addrs()checkmakes
Quoted 2 lines
sense to me.
It is the most encountered situation when running ovs as non root onrecent
Quoted 4 lines
kernels.
- However, I fail to see the need for all of this detection code wrt
drivers
Quoted 5 lines
and devices.
On one side of the equation, when dpdk starts, it checks physical address availability.
On the other side of the equation, we have the drivers that will beinvoked
Quoted 3 lines
when probing devices (either at dpdk init, or when hotplugging a device).
At this point, the probing call should check the driver requirement wrt
to the
Quoted 7 lines
kernel driver the device is attached to.
If this requirement is not fulfilled, then the probing fails.- This leaves the --iova-va forcing option.
Why do we need it?
If we don't have access to physical addresses, no choice but run in VAmode.
Quoted 1 line
If we have access to physical addresses, the only case would be that you
want
Quoted 2 lines
to downgrade from PA to VA.
But well, your process can still access it, not sure what the benefit is.All of the complexity here, at least as far as I understand it, stems from supporting hot insert of devices. This is very important to SPDK because storage
devices get hot inserted all the time, so we very much appreciate that DPDK has
put in so much effort in this area and continues to accept our patches to improve it. I know hot insert is not nearly as important for network devices.When DPDK starts up, it needs to select whether to use virtual addresses or physical addresses in its memory maps. It can do that by answering the following
questions:1. Does the system only have buses that support an IOMMU?
2. Is the IOMMU sufficiently fast for the use case?
3. Will all of the devices that will be used with DPDK throughout the application's lifetime work with an IOMMU?If these three things are true, then the best choice is to use virtual addresses
in the memory translations. However, if any of the above are not true it needs
to fall back to physical addresses.#1 is checked by simply asking all of the buses, which are known up front. #2 is
just assumed to be true. But #3 is not possible to check fully because of hot
insert.The code currently approximates the #3 check by looking at the devices present
at initialization time. If a device exists that's bound to vfio-pci, and no other devices exist that are bound to a uio driver, and DPDK has a registered
driver that's actually going to load against the vfio-pci devices, then it will
elect to use virtual addresses. This is purely a heuristic - it's not a definitive answer because the user could later hot insert a device that gets
bound to uio.The user, of course, knows the answer to which addressing scheme to use typically. For example, these checks assume #2 is true, but there may be hardware implementations where it is not and the user wants to force physical
addresses. Or the user may know that they are going to hot insert a device at
run time that doesn't work with the IOMMU. That's why it's important to maintain
the ability for the user to override the default heuristic's decision via the
command line.My patch series is simply improving the heuristic in a few ways. First, previously each bus when queried would return either virtual or physical addresses as its choice. However, often the bus just does not have enough information to formulate any preference at all (and PCI was defaulting to physical addresses in this case). Instead, I made it so that the bus can return
that it doesn't care, which pushes the decision up to a higher level. That higher level then makes the decision by checking whether it can access/proc/self/pagemap. Second, I narrowed the uio check such that physical addresses will only be selected if a device bound to uio exists and there is a
driver registered to use it. Previously if any device was bound to uio it would
select physical addresses, even if DPDK never ended up loading against that device.
Quoted 6 lines
I think these two things make the heuristic choose the right thing more often,
but it still won't always get it right so the command line option needs to remain.
After some exchanges offlist, on irc and taking some time looking at the code, here are my conclusions.
Copying bus drivers maintainers/connaisseurs.
We have cases where we prefer using VA even if PA are available (for fslmc where translating from iova as PA to VA is more costly).
I worked on Ben patches and summarised it as two main issues with the current code:
- physical addresses availability is not taken into account early enough in EAL init, and we end up with memory subsystem complaining later which is not that user friendly.
A collateral is that the init could have fallen back to using VA in most
cases if there were no strong requirement on PA.
- pci bus driver looks at all devices on the system, with no consideration on the pci white/blacklist and no consideration on the fact that dpdk has a driver that supports the device
I prepared a new series that I will send shortly. I am currently considering the backport potential for it. Thoughts?
Else, reviews are welcome.
Thanks.
Signature · 1 line
David Marchand
v2 cover Improve automatic selection of IOVA mode
In reply to Ben WalkerIn SPDK, not all drivers are registered with DPDK at start up time. Previously, that meant DPDK always chose to set itself up in IOVA_PA mode. Instead, when the correct iova choice is unclear based on the devices and drivers known to DPDK at start up time, use other heuristics (such as whether /proc/self/pagemap is accessible) to make a better choice.
This enables SPDK to run as an unprivileged user again without requiring users to explicitly set the iova mode on the command line.
Changelog since v1:
- I took over the series following experiments and discussions with Ben and others, squashed Ben patches as two patches focusing on the main issues,
- introduced a fix on KNI,
- on the EAL bits,
- added log on which IOVA mode has been selected,
- updated BSD EAL,
- in Linux EAL, moved KNI special case after IOVA selection,
- in Linux EAL, added check on forced mode wrt physical addresses availability,
- on the PCI bus driver bits,
- enforced the checks in the common code of the PCI bus,
- added debug logs to track why a iova mode has been chosen per device,
- added BSD part,
- in Linux part, checked that VFIO is enabled,
- in Linux part, defaulted to DC if a driver supports both PA and VA,
Signature · 23 lines
David Marchand Ben Walker (2): eal: compute IOVA mode based on PA availability bus/pci: only consider usable devices to select IOVA mode David Marchand (1): kni: refuse to initialise when IOVA is not PA drivers/bus/pci/bsd/pci.c | 9 +- drivers/bus/pci/linux/pci.c | 191 +++++++++----------------------- drivers/bus/pci/pci_common.c | 65 +++++++++++ drivers/bus/pci/private.h | 8 ++ lib/librte_eal/common/eal_common_bus.c | 4 - lib/librte_eal/common/include/rte_bus.h | 2 +- lib/librte_eal/freebsd/eal/eal.c | 10 +- lib/librte_eal/linux/eal/eal.c | 38 +++++-- lib/librte_eal/linux/eal/eal_memory.c | 46 ++------ lib/librte_kni/rte_kni.c | 5 + 10 files changed, 187 insertions(+), 191 deletions(-) -- 1.8.3.1
PATCH v2 1/3 kni: refuse to initialise when IOVA is not PA
If a forced iova-mode has been passed at init, kni is not supposed to work.
--- lib/librte_kni/rte_kni.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/librte_kni/rte_kni.c +5 -0
@@ -97,6 +97,11 @@ enum kni_ops_status {int rte_kni_init(unsigned int max_kni_ifaces __rte_unused) { +if (rte_eal_iova_mode () !=RTE_IOVA_PA ) { +RTE_LOG (ERR ,KNI ,"KNI requires IOVA as PA\n" ); +return -1 ; + } +/* Check FD and open */ if (kni_fd <0 ) { kni_fd =open ("/dev/" KNI_DEVICE ,O_RDWR );
Signature · 1 line
1.8.3.1
PATCH v2 2/3 eal: compute IOVA mode based on PA availability
In reply to David MarchandFrom: Ben Walker <[email protected]>
Currently, if the bus selects IOVA as PA, the memory init can fail when lacking access to physical addresses.
This can be quite hard for normal users to understand what is wrong since this is the default behavior.
Catch this situation earlier in eal init by validating physical addresses availability, or select IOVA when no clear preferrence had been expressed.
The bus code is changed so that it reports when it does not care about the IOVA mode and let the eal init decide.
In Linux implementation, rework rte_eal_using_phys_addrs() so that it can be called earlier but still avoid a circular dependency with rte_mem_virt2phys().
In FreeBSD implementation, rte_eal_using_phys_addrs() always returns false, so the detection part is left as is.
If librte_kni is compiled in and the KNI kmod is loaded,
- if the buses requested VA, force to PA if physical addresses are available as it was done before,
- else, keep iova as VA, KNI init will fail later.
--- lib/librte_eal/common/eal_common_bus.c | 4 --- lib/librte_eal/common/include/rte_bus.h | 2 +- lib/librte_eal/freebsd/eal/eal.c | 10 +++++-- lib/librte_eal/linux/eal/eal.c | 38 +++++++++++++++++++++------ lib/librte_eal/linux/eal/eal_memory.c | 46 +++++++++------------------------ 5 files changed, 51 insertions(+), 49 deletions(-)
lib/librte_eal/common/eal_common_bus.c +0 -4
@@ -237,10 +237,6 @@ enum rte_iova_mode mode |= bus->get_iommu_class (); } -if (mode !=RTE_IOVA_VA ) { -/* Use default IOVA mode */ - mode =RTE_IOVA_PA ; - }return mode; }
lib/librte_eal/common/include/rte_bus.h +1 -1
@@ -392,7 +392,7 @@ struct rte_bus *rte_bus_find(const struct rte_bus *start, rte_bus_cmp_t cmp,/** * Get the common iommu class of devices bound on to buses available in the -* system. The default mode is PA. +* system. RTE_IOVA_DC means that no preferrence has been expressed. * * @return * enum rte_iova_mode value.
lib/librte_eal/freebsd/eal/eal.c +8 -2
@@ -689,13 +689,19 @@ static void rte_eal_init_alert(const char *msg)/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */ if (internal_config.iova_mode ==RTE_IOVA_DC ) {/* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ -rte_eal_get_configuration ()->iova_mode = -rte_bus_get_iommu_class (); +enum rte_iova_mode iova_mode =rte_bus_get_iommu_class (); + +if (iova_mode ==RTE_IOVA_DC ) + iova_mode =RTE_IOVA_PA ; +rte_eal_get_configuration ()->iova_mode = iova_mode; }else {rte_eal_get_configuration ()->iova_mode = internal_config.iova_mode; } +RTE_LOG (INFO ,EAL ,"Selected IOVA mode '%s'\n" , +rte_eal_iova_mode () ==RTE_IOVA_PA ?"PA" :"VA" ); +if (internal_config.no_hugetlbfs ==0 ) {/* rte_config isn't initialized yet */ ret = internal_config.process_type == RTE_PROC_PRIMARY ?
lib/librte_eal/linux/eal/eal.c +30 -8
@@ -948,6 +948,7 @@ static void rte_eal_init_alert(const char *msg)static char logid[PATH_MAX ];char cpuset[RTE_CPU_AFFINITY_STR_LEN ];char thread_name[RTE_MAX_THREAD_NAME_LEN ]; +bool phys_addrs;/* checks if the machine is adequate */ if (!rte_cpu_is_supported ()) {
@@ -1035,25 +1036,46 @@ static void rte_eal_init_alert(const char *msg)return -1 ; } + phys_addrs =rte_eal_using_phys_addrs () !=0 ; +/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */ if (internal_config.iova_mode ==RTE_IOVA_DC ) { -/* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ -rte_eal_get_configuration ()->iova_mode = -rte_bus_get_iommu_class (); +/* autodetect the IOVA mapping mode */ +enum rte_iova_mode iova_mode =rte_bus_get_iommu_class (); +if (iova_mode ==RTE_IOVA_DC ) { + iova_mode = phys_addrs ?RTE_IOVA_PA :RTE_IOVA_VA ; +RTE_LOG (DEBUG ,EAL , +"Buses did not request a specific IOVA mode, using '%s' based on physical addresses availability.\n" , + phys_addrs ?"PA" :"VA" ); + } +#ifdef RTE_LIBRTE_KNI /* Workaround for KNI which requires physical address to work */ -if (rte_eal_get_configuration ()->iova_mode ==RTE_IOVA_VA && +if (iova_mode ==RTE_IOVA_VA &&rte_eal_check_module ("rte_kni" ) ==1 ) { -rte_eal_get_configuration ()->iova_mode =RTE_IOVA_PA ; -RTE_LOG (WARNING ,EAL , -"Some devices want IOVA as VA but PA will be used because.. " -"KNI module inserted\n" ); +if (phys_addrs) { + iova_mode =RTE_IOVA_PA ; +RTE_LOG (WARNING ,EAL ,"Forcing IOVA as 'PA' because KNI module is loaded\n" ); + }else { +RTE_LOG (DEBUG ,EAL ,"KNI can not work since physical addresses are unavailable\n" ); + } } +#endif +rte_eal_get_configuration ()->iova_mode = iova_mode; }else {rte_eal_get_configuration ()->iova_mode = internal_config.iova_mode; } +if (rte_eal_iova_mode () ==RTE_IOVA_PA && !phys_addrs) { +rte_eal_init_alert ("Cannot use IOVA as 'PA' since physical addresses are not available" ); + rte_errno =EINVAL ; +return -1 ; + } + +RTE_LOG (INFO ,EAL ,"Selected IOVA mode '%s'\n" , +rte_eal_iova_mode () ==RTE_IOVA_PA ?"PA" :"VA" ); +if (internal_config.no_hugetlbfs ==0 ) {/* rte_config isn't initialized yet */ ret = internal_config.process_type == RTE_PROC_PRIMARY ?
lib/librte_eal/linux/eal/eal_memory.c +12 -34
91 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v2 2/3] eal: compute IOVA mode based on PA availability
Quoted 27 lines · David Marchand
From: Ben Walker <[email protected]>
Currently, if the bus selects IOVA as PA, the memory init can fail when lacking access to physical addresses.
This can be quite hard for normal users to understand what is wrong since this is the default behavior.Catch this situation earlier in eal init by validating physical addresses availability, or select IOVA when no clear preferrence had been expressed.
The bus code is changed so that it reports when it does not care about the IOVA mode and let the eal init decide.
In Linux implementation, rework
rte_eal_using_phys_addrs()so that it can be called earlier but still avoid a circular dependency withrte_mem_virt2phys().
In FreeBSD implementation,rte_eal_using_phys_addrs()always returns false, so the detection part is left as is.If
librte_kniis compiled in and the KNI kmod is loaded,
- if the buses requested VA, force to PA if physical addresses are available as it was done before,
- else, keep iova as VA, KNI init will fail later.Signed-off-by Ben Walker <[email protected]>Signed-off-by David Marchand <[email protected]>---
<snip>
Quoted 16 lines
lib/librte_eal/linux/eal/eal.c +10
-3+/* autodetect the IOVA mapping mode */ +enum rte_iova_mode iova_mode =rte_bus_get_iommu_class (); +if (iova_mode ==RTE_IOVA_DC ) { + iova_mode = phys_addrs ?RTE_IOVA_PA :RTE_IOVA_VA ; +RTE_LOG (DEBUG ,EAL , +"Buses did not request a specific IOVA mode, using '%s' based on physical addresses availability.\n" , + phys_addrs ?"PA" :"VA" ); + } +#ifdef RTE_LIBRTE_KNI /* Workaround for KNI which requires physical address to work */ -if (rte_eal_get_configuration ()->iova_mode ==RTE_IOVA_VA && +if (iova_mode ==RTE_IOVA_VA &&rte_eal_check_module ("rte_kni" ) ==1 ) { -rte_eal_get_configuration ()->iova_mode =RTE_IOVA_PA ; - RTE_LOG(WARNING, EAL,
lib/librte_eal/linux/eal/eal.c static void rte_eal_init_alert(const char *msg) · line 1063
Quoted 10 lines
lib/librte_eal/linux/eal/eal.c +7
-2-"Some devices want IOVA as VA but PA will be used because.. " - "KNI module inserted\n"); +if (phys_addrs) { + iova_mode =RTE_IOVA_PA ; +RTE_LOG (WARNING ,EAL ,"Forcing IOVA as 'PA' because KNI module is loaded\n" ); + }else { +RTE_LOG (DEBUG ,EAL ,"KNI can not work since physical addresses are unavailable\n" ); + } } +#endif
Why the ifdefs? I don't think there's something specific to KNI there, rte_eal_check_module() works absent of KNI.
Otherwise LGTM,
I wish we would make IOVA as VA the default already, but at least picking it automatically when physical addresses aren't available is a good start :)
Signature · 2 lines
Thanks, Anatoly
Re: [dpdk-dev] [PATCH v2 2/3] eal: compute IOVA mode based on PA availability
Quoted 61 lines · Anatoly
Quoted 9 lines · David Marchand
From: Ben Walker <[email protected]>
Currently, if the bus selects IOVA as PA, the memory init can fail when lacking access to physical addresses.
This can be quite hard for normal users to understand what is wrong since this is the default behavior.Catch this situation earlier in eal init by validating physical addresses availability, or select IOVA when no clear preferrence had been
expressed.
Quoted 18 lines
The bus code is changed so that it reports when it does not care about the IOVA mode and let the eal init decide.
In Linux implementation, rework
rte_eal_using_phys_addrs()so that it can be called earlier but still avoid a circular dependency withrte_mem_virt2phys().
In FreeBSD implementation,rte_eal_using_phys_addrs()always returns false, so the detection part is left as is.If
librte_kniis compiled in and the KNI kmod is loaded,
- if the buses requested VA, force to PA if physical addresses are available as it was done before,
- else, keep iova as VA, KNI init will fail later.Signed-off-by Ben Walker <[email protected]>Signed-off-by David Marchand <[email protected]>---
<snip>
lib/librte_eal/linux/eal/eal.c static void rte_eal_init_alert(const char *msg)
Quoted 7 lines
lib/librte_eal/linux/eal/eal.c +6
-0+/* autodetect the IOVA mapping mode */ +enum rte_iova_mode iova_mode =rte_bus_get_iommu_class (); +if (iova_mode ==RTE_IOVA_DC ) { + iova_mode = phys_addrs ?RTE_IOVA_PA :RTE_IOVA_VA ; + RTE_LOG(DEBUG, EAL, + "Buses did not request a specific IOVAmode, using '%s' based on physical addresses availability.\n",
lib/librte_eal/linux/eal/eal.c static void rte_eal_init_alert(const char *msg)
Quoted 4 lines
lib/librte_eal/linux/eal/eal.c +3
-0+ phys_addrs ? "PA" : "VA"); + } +#ifdef RTE_LIBRTE_KNI /* Workaround for KNI which requires physical address to work */
Quoted 1 line
- if (rte_eal_get_configuration()->iova_mode ==
RTE_IOVA_VA&&
lib/librte_eal/linux/eal/eal.c static void rte_eal_init_alert(const char *msg)
Quoted 3 lines
lib/librte_eal/linux/eal/eal.c +1
-1+if (iova_mode ==RTE_IOVA_VA &&rte_eal_check_module ("rte_kni" ) ==1 ) { - rte_eal_get_configuration()->iova_mode =
RTE_IOVA_PA;Review
Quoted 2 lines
(quoted diff) +0
-2- RTE_LOG(WARNING, EAL, - "Some devices want IOVA as VA but PA willbe used because.. "
lib/librte_eal/linux/eal/eal.c static void rte_eal_init_alert(const char *msg)
Quoted 4 lines
lib/librte_eal/linux/eal/eal.c +3
-1- "KNI module inserted\n"); +if (phys_addrs) { + iova_mode =RTE_IOVA_PA ; + RTE_LOG(WARNING, EAL, "Forcing IOVA as'PA' because KNI module is loaded\n");
Review
Quoted 2 lines
(quoted diff) +2
-0+ } else { + RTE_LOG(DEBUG, EAL, "KNI can not work
Quoted 8 lines
since physical addresses are unavailable\n");
lib/librte_eal/linux/eal/eal.c static void rte_eal_init_alert(const char *msg) · line 1063
Quoted 3 lines
lib/librte_eal/linux/eal/eal.c +2
-0+ } } +#endif Why the ifdefs? I don't think there's something specific to KNI there,
rte_eal_check_module()works absent of KNI.
The sole presence of the kni kmod does not mean you have librte_kni in your binary.
So if you consider the case where you would have two dpdk applications running, one with kni, the other one without it.
It does not makes sense to force PA for the one that does not have librte_kni.
Otherwise LGTM,
Quoted 3 lines
Acked-by Anatoly Burakov <[email protected]>
Thanks for the review !
Signature · 1 line
David Marchand
PATCH v2 3/3 bus/pci: only consider usable devices to select IOVA mode
In reply to David MarchandFrom: Ben Walker <[email protected]>
When selecting the preferred IOVA mode of the pci bus, the current heuristic ("are devices bound?", "are devices bound to UIO?", "are pmd drivers supporting IOVA as VA?" etc..) should honor the device white/blacklist so that an unwanted device does not impact the decision.
There is no reason to consider a device which has no driver available.
This applies to all OS, so implements this in common code then call a OS specific callback.
On Linux side:
- the VFIO special considerations should be evaluated only if VFIO support is built,
- there is no strong requirement on using VA rather than PA if a driver supports VA, so defaulting to DC in such a case.
--- drivers/bus/pci/bsd/pci.c | 9 +- drivers/bus/pci/linux/pci.c | 191 ++++++++++++------------------------------- drivers/bus/pci/pci_common.c | 65 +++++++++++++++ drivers/bus/pci/private.h | 8 ++ 4 files changed, 131 insertions(+), 142 deletions(-)
drivers/bus/pci/bsd/pci.c +5 -4
@@ -376,13 +376,14 @@return -1 ; } -/* -* Get iommu class of PCI devices on the bus. -*/ enum rte_iova_mode -rte_pci_get_iommu_class (void ) +pci_device_iova_mode(const struct rte_pci_driver *pdrv __rte_unused, +const struct rte_pci_device *pdev) {/* Supports only RTE_KDRV_NIC_UIO */ +if (pdev->kdrv !=RTE_KDRV_NIC_UIO ) +RTE_LOG (DEBUG ,EAL ,"Unsupported kernel driver? Defaulting to IOVA as 'PA'\n" ); +return RTE_IOVA_PA ; }
drivers/bus/pci/linux/pci.c +53 -138
228 lines not on this page · raw message
drivers/bus/pci/pci_common.c +65 -0
71 lines not on this page · raw message
drivers/bus/pci/private.h +8 -0
@@ -173,6 +173,14 @@ int pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, const struct rte_pci_device *pci_dev);/** +* OS specific callback for rte_pci_get_iommu_class +* +*/ +enum rte_iova_mode +pci_device_iova_mode (const struct rte_pci_driver *pci_drv, +const struct rte_pci_device *pci_dev); + +/** * Get iommu class of PCI devices on the bus. * And return their preferred iova mapping mode. *
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v2 3/3] bus/pci: only consider usable devices to select IOVA mode
Quoted 21 lines · David Marchand
From: Ben Walker <[email protected]>
When selecting the preferred IOVA mode of the pci bus, the current heuristic ("are devices bound?", "are devices bound to UIO?", "are pmd drivers supporting IOVA as VA?" etc..) should honor the device white/blacklist so that an unwanted device does not impact the decision.
There is no reason to consider a device which has no driver available.
This applies to all OS, so implements this in common code then call a OS specific callback.
On Linux side:
- the VFIO special considerations should be evaluated only if VFIO support is built,
- there is no strong requirement on using VA rather than PA if a driver supports VA, so defaulting to DC in such a case.Signed-off-by Ben Walker <[email protected]>Signed-off-by David Marchand <[email protected]>---
<snip>
Quoted 25 lines
drivers/bus/pci/linux/pci.c +12
-11+ const struct rte_pci_device *pdev) { -struct rte_pci_device *dev =NULL ; -struct rte_pci_driver *drv =NULL ; +enum rte_iova_mode iova_mode =RTE_IOVA_DC ; +static int iommu_no_va =-1 ; -FOREACH_DRIVER_ON_PCIBUS (drv) { -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (!rte_pci_match (drv, dev)) -continue ; -/* -* just one PCI device needs to be checked out because -* the IOMMU hardware is the same for all of them. -*/ -return pci_one_device_iommu_support_va (dev); +switch (pdev->kdrv) { +case RTE_KDRV_VFIO : { +#ifdef VFIO_PRESENT +static int is_vfio_noiommu_enabled =-1 ; + +if (is_vfio_noiommu_enabled ==-1 ) { +if (rte_vfio_noiommu_is_enabled () ==1 ) + is_vfio_noiommu_enabled =1 ; +else
drivers/bus/pci/linux/pci.c line 591
Quoted 10 lines
drivers/bus/pci/linux/pci.c +9
-0+ is_vfio_noiommu_enabled = 0; + } +if ((pdrv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) ==0 ) { + iova_mode =RTE_IOVA_PA ; + }else if (is_vfio_noiommu_enabled !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Forcing to 'PA', vfio-noiommu mode configured\n" ); + iova_mode =RTE_IOVA_PA ; } +#endif +break ;
I'm not too well-versed in bus code, so please excuse my ignorance of this codebase.
It seems that we would be ignoring drv_flags in case VFIO wasn't compiled - if the driver has no RTE_PCI_DRV_IOVA_AS_VA flag, i'm pretty sure we can set IOVA mode to PA without caring about VFIO at all. I think it would be better to have something like this:
if ((pdrv->drv_flags & RTE_PCI_DRV_IOVA_AS_VA) == 0) {
iova_mode = RTE_IOVA_PA;
break; // early exit
}#ifdef VFIO_PRESENT
static int is_vfio_noiommu_enabled = -1;
if (is_vfio_noiommu_enabled == -1) {
if (rte_vfio_noiommu_is_enabled() == 1)
is_vfio_noiommu_enabled = 1;
else
is_vfio_noiommu_enabled = 0;
}
if (is_vfio_noiommu_enabled != 0) {
iova_mode = RTE_IOVA_PA;
}#endif
break;
In fact, could we not check if devices support both flags, and do an early exit in case they don't?
Something like this, for example:
if ((pdrv->drv_flags & RTE_PCI_DRV_IOVA_AS_VA) == 0) {
return RTE_IOVA_PA; // early exit - device only wants PA
}
// device supports both PA and VA modes, so do more checks switch (pdev->kdrv) {
...
}
Unless i'm missing something, this would look much simpler and easier to understand.
Signature · 2 lines
Thanks, Anatoly
Re: [dpdk-dev] [PATCH v2 3/3] bus/pci: only consider usable devices to select IOVA mode
Quoted 71 lines · Anatoly
Quoted 21 lines · David Marchand
From: Ben Walker <[email protected]>
When selecting the preferred IOVA mode of the pci bus, the current heuristic ("are devices bound?", "are devices bound to UIO?", "are pmd drivers supporting IOVA as VA?" etc..) should honor the device white/blacklist so that an unwanted device does not impact the decision.
There is no reason to consider a device which has no driver available.
This applies to all OS, so implements this in common code then call a OS specific callback.
On Linux side:
- the VFIO special considerations should be evaluated only if VFIO support is built,
- there is no strong requirement on using VA rather than PA if a driver supports VA, so defaulting to DC in such a case.Signed-off-by Ben Walker <[email protected]>Signed-off-by David Marchand <[email protected]>---
<snip>
drivers/bus/pci/linux/pci.c
Quoted 13 lines
drivers/bus/pci/linux/pci.c +3
-8+ const struct rte_pci_device *pdev) { -struct rte_pci_device *dev =NULL ; -struct rte_pci_driver *drv =NULL ; +enum rte_iova_mode iova_mode =RTE_IOVA_DC ; +static int iommu_no_va =-1 ; -FOREACH_DRIVER_ON_PCIBUS (drv) { -FOREACH_DEVICE_ON_PCIBUS (dev) { -if (!rte_pci_match (drv, dev)) -continue ; -/* -* just one PCI device needs to be checked out because
Quoted 8 lines
drivers/bus/pci/linux/pci.c +5
-3-* the IOMMU hardware is the same for all of them. -*/ -return pci_one_device_iommu_support_va (dev); +switch (pdev->kdrv) { +case RTE_KDRV_VFIO : { +#ifdef VFIO_PRESENT +static int is_vfio_noiommu_enabled =-1 ; +drivers/bus/pci/linux/pci.c
Quoted 10 lines
drivers/bus/pci/linux/pci.c +10
-0+if (is_vfio_noiommu_enabled ==-1 ) { +if (rte_vfio_noiommu_is_enabled () ==1 ) + is_vfio_noiommu_enabled =1 ; +else + is_vfio_noiommu_enabled =0 ; + } +if ((pdrv->drv_flags &RTE_PCI_DRV_IOVA_AS_VA ) ==0 ) { + iova_mode =RTE_IOVA_PA ; + }else if (is_vfio_noiommu_enabled !=0 ) { + RTE_LOG(DEBUG, EAL, "Forcing to 'PA', vfio-noiommumode configured\n");
drivers/bus/pci/linux/pci.c line 591
Quoted 4 lines
drivers/bus/pci/linux/pci.c +3
-0+ iova_mode = RTE_IOVA_PA; } +#endif +break ;I'm not too well-versed in bus code, so please excuse my ignorance of this codebase.
It seems that we would be ignoring
drv_flagsin case VFIO wasn't compiled - if the driver has noRTE_PCI_DRV_IOVA_AS_VAflag, i'm pretty sure we can set IOVA mode to PA without caring about VFIO at all. I think it would be better to have something like this:
Quoted 5 lines
if ((
pdrv->drv_flags&RTE_PCI_DRV_IOVA_AS_VA) == 0) {
iova_mode=RTE_IOVA_PA;
break; // early exit
}
If the device is bound to VFIO, but the dpdk binary has no vfio support, we don't need to consider this device in the decision.
Did I miss something in what you suggest?
Signature · 1 line
David Marchand
Burakov, Anatoly
Reviewed-byRe: [dpdk-dev] [PATCH v2 3/3] bus/pci: only consider usable devices to select IOVA mode
Quoted 89 lines · David Marchand
On Wed, Jul 3, 2019 at 12:45 PM Burakov, Anatoly <[email protected] <mailto:[email protected]>> wrote:
On 14-Jun-19 10:39 AM, David Marchand wrote: > From: Ben Walker <[email protected] <mailto:[email protected]>> > > When selecting the preferred IOVA mode of the pci bus, the current > heuristic ("are devices bound?", "are devices bound to UIO?", "are pmd > drivers supporting IOVA as VA?" etc..) should honor the device > white/blacklist so that an unwanted device does not impact the decision. > > There is no reason to consider a device which has no driver available. > > This applies to all OS, so implements this in common code then call a > OS specific callback. > > On Linux side: > - the VFIO special considerations should be evaluated only if VFIO > support is built, > - there is no strong requirement on using VA rather than PA if a driver > supports VA, so defaulting to DC in such a case. > > Signed-off-by: Ben Walker <[email protected] <mailto:[email protected]>> > Signed-off-by: David Marchand <[email protected] <mailto:[email protected]>> > --- <snip> > + const struct rte_pci_device *pdev) > { > - struct rte_pci_device *dev = NULL; > - struct rte_pci_driver *drv = NULL; > + enum rte_iova_mode iova_mode = RTE_IOVA_DC; > + static int iommu_no_va = -1; > > - FOREACH_DRIVER_ON_PCIBUS(drv) { > - FOREACH_DEVICE_ON_PCIBUS(dev) { > - if (!rte_pci_match(drv, dev)) > - continue; > - /* > - * just one PCI device needs to be checked out because > - * the IOMMU hardware is the same for all of them. > - */ > - return pci_one_device_iommu_support_va(dev); > + switch (pdev->kdrv) { > + case RTE_KDRV_VFIO: { > +#ifdef VFIO_PRESENT > + static int is_vfio_noiommu_enabled = -1; > + > + if (is_vfio_noiommu_enabled == -1) { > + if (rte_vfio_noiommu_is_enabled() == 1) > + is_vfio_noiommu_enabled = 1; > + else > + is_vfio_noiommu_enabled = 0; > + } > + if ((pdrv->drv_flags & RTE_PCI_DRV_IOVA_AS_VA) == 0) { > + iova_mode = RTE_IOVA_PA; > + } else if (is_vfio_noiommu_enabled != 0) { > + RTE_LOG(DEBUG, EAL, "Forcing to 'PA', vfio-noiommu mode configured\n"); > + iova_mode = RTE_IOVA_PA; > } > +#endif > + break; I'm not too well-versed in bus code, so please excuse my ignorance of this codebase. It seems that we would be ignoring drv_flags in case VFIO wasn't compiled - if the driver has no RTE_PCI_DRV_IOVA_AS_VA flag, i'm pretty sure we can set IOVA mode to PA without caring about VFIO at all. I think it would be better to have something like this: if ((pdrv->drv_flags & RTE_PCI_DRV_IOVA_AS_VA) == 0) { iova_mode = RTE_IOVA_PA; break; // early exit }
Quoted 3 lines
If the device is bound to VFIO, but the dpdk binary has no vfio support, we don't need to consider this device in the decision. Did I miss something in what you suggest?
Yep, you're correct :)
Quoted 3 lines
Signature · 2 lines
-- David Marchand
Signature · 2 lines
Thanks, Anatoly
Re: [dpdk-dev] [PATCH v2 3/3] bus/pci: only consider usable devices to select IOVA mode
Quoted 94 lines · Anatoly
Quoted 5 lines · David Marchand
On Wed, Jul 3, 2019 at 12:45 PM Burakov, Anatoly <[email protected] <mailto:[email protected]>> wrote:
Quoted 15 lines
On 14-Jun-19 10:39 AM, David Marchand wrote:
> From: Ben Walker <[email protected]
<mailto:[email protected]>>
>
> When selecting the preferred IOVA mode of the pci bus, the current > heuristic ("are devices bound?", "are devices bound to UIO?",
"are pmd
> drivers supporting IOVA as VA?" etc..) should honor the device > white/blacklist so that an unwanted device does not impact the
decision.
>
> There is no reason to consider a device which has no driver
available.
>
> This applies to all OS, so implements this in common code thencall a
Quoted 39 lines
> OS specific callback. > > On Linux side: > - the VFIO special considerations should be evaluated only if VFIO > support is built, > - there is no strong requirement on using VA rather than PA if a driver > supports VA, so defaulting to DC in such a case. > > Signed-off-by: Ben Walker <[email protected] <mailto:[email protected]>> > Signed-off-by: David Marchand <[email protected] <mailto:[email protected]>> > --- <snip> > + const struct rte_pci_device *pdev) > { > - struct rte_pci_device *dev = NULL; > - struct rte_pci_driver *drv = NULL; > + enum rte_iova_mode iova_mode = RTE_IOVA_DC; > + static int iommu_no_va = -1; > > - FOREACH_DRIVER_ON_PCIBUS(drv) { > - FOREACH_DEVICE_ON_PCIBUS(dev) { > - if (!rte_pci_match(drv, dev)) > - continue; > - /* > - * just one PCI device needs to be checked out because > - * the IOMMU hardware is the same for all of them. > - */ > - return pci_one_device_iommu_support_va(dev); > + switch (pdev->kdrv) { > + case RTE_KDRV_VFIO: { > +#ifdef VFIO_PRESENT > + static int is_vfio_noiommu_enabled = -1;Quoted 8 lines
> + > + if (is_vfio_noiommu_enabled == -1) { > + if (rte_vfio_noiommu_is_enabled() == 1) > + is_vfio_noiommu_enabled = 1; > + else > + is_vfio_noiommu_enabled = 0; > + } > + if ((pdrv->drv_flags & RTE_PCI_DRV_IOVA_AS_VA) ==0) {
Quoted 6 lines
> + iova_mode = RTE_IOVA_PA; > + } else if (is_vfio_noiommu_enabled != 0) { > + RTE_LOG(DEBUG, EAL, "Forcing to 'PA', vfio-noiommu mode configured\n"); > + iova_mode = RTE_IOVA_PA; > }Quoted 8 lines
> +#endif > + break; I'm not too well-versed in bus code, so please excuse my ignorance of this codebase. It seems that we would be ignoring drv_flags in case VFIO wasn't compiled - if the driver has no RTE_PCI_DRV_IOVA_AS_VA flag, i'mpretty
Quoted 9 lines
sure we can set IOVA mode to PA without caring about VFIO at all. I think it would be better to have something like this:
if ((
pdrv->drv_flags&RTE_PCI_DRV_IOVA_AS_VA) == 0) {
iova_mode=RTE_IOVA_PA;
break; // early exit
}
Quoted 9 lines
Quoted 4 lines
If the device is bound to VFIO, but the dpdk binary has no vfio support, we don't need to consider this device in the decision.
Did I miss something in what you suggest?Yep, you're correct :)
Reviewed-by Anatoly Burakov <[email protected]>
Cool, thanks Anatoly!
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v2 3/3] bus/pci: only consider usable devices to select IOVA mode
In reply to David Marchanddrivers/bus/pci/bsd/pci.c line 385
Quoted 3 lines · On Fri, 14 Jun 2019 11:39:17 +0200 David Marchand <[email protected]>…
drivers/bus/pci/bsd/pci.c +2
-0/* Supports only RTE_KDRV_NIC_UIO */ +if (pdev->kdrv !=RTE_KDRV_NIC_UIO ) +RTE_LOG (DEBUG ,EAL ,"Unsupported kernel driver? Defaulting to IOVA as 'PA'\n" );
Maybe NOTICE level, rather than DEBUG which is usually suppressed.
drivers/bus/pci/linux/pci.c line 587
Quoted 2 lines
drivers/bus/pci/linux/pci.c +2
-0+ }else if (is_vfio_noiommu_enabled !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Forcing to 'PA', vfio-noiommu mode configured\n" );
ditto
Re: [dpdk-dev] [PATCH v2 3/3] bus/pci: only consider usable devices to select IOVA mode
Quoted 10 lines · Stephen Hemminger
Review
Quoted 3 lines · On Fri, 14 Jun 2019 11:39:17 +0200 David Marchand <[email protected]>…
/* Supports only RTE_KDRV_NIC_UIO */(quoted diff) +2
-0+ if (pdev->kdrv != RTE_KDRV_NIC_UIO) + RTE_LOG(DEBUG, EAL, "Unsupported kernel driver? Defaultingto IOVA as 'PA'\n");
Maybe NOTICE level, rather than DEBUG which is usually suppressed.
What do you mean by "suppressed" ?
We had a hardwired log level some time ago, but it has been removed and all logs are in the binaries now.
https://git.dpdk.org/dpdk/commit/?id=5d8f0baf69ea
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } else if (is_vfio_noiommu_enabled != 0) { + RTE_LOG(DEBUG, EAL, "Forcing to 'PA', vfio-noiommumode configured\n");
ditto
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v2 3/3] bus/pci: only consider usable devices to select IOVA mode
Quoted 11 lines · On Fri, 5 Jul 2019 09:58:44 +0200 David Marchand <[email protected]>…
Quoted 8 lines · Stephen Hemminger
Review
Quoted 3 lines · On Fri, 14 Jun 2019 11:39:17 +0200 David Marchand <[email protected]>…
/* Supports only RTE_KDRV_NIC_UIO */(quoted diff) +2
-0+ if (pdev->kdrv != RTE_KDRV_NIC_UIO) + RTE_LOG(DEBUG, EAL, "Unsupported kernel driver? Defaultingto IOVA as 'PA'\n");
Quoted 8 lines
Quoted 2 lines
Maybe NOTICE level, rather than DEBUG which is usually suppressed.
What do you mean by "suppressed" ?
We had a hardwired log level some time ago, but it has been removed and all logs are in the binaries now.
https://git.dpdk.org/dpdk/commit/?id=5d8f0baf69ea
Unless user increases the log level, the default is to not print debug logs.
Re: [dpdk-dev] [PATCH v2 3/3] bus/pci: only consider usable devices to select IOVA mode
In reply to Stephen Hemminger04/07/2019 19:14, Stephen Hemminger:
Quoted 8 lines
drivers/bus/pci/bsd/pci.c line 385
Quoted 3 lines · On Fri, 14 Jun 2019 11:39:17 +0200 David Marchand <[email protected]>…
drivers/bus/pci/bsd/pci.c +2
-0/* Supports only RTE_KDRV_NIC_UIO */ +if (pdev->kdrv !=RTE_KDRV_NIC_UIO ) +RTE_LOG (DEBUG ,EAL ,"Unsupported kernel driver? Defaulting to IOVA as 'PA'\n" );Maybe NOTICE level, rather than DEBUG which is usually suppressed.
DEBUG may be enough here, as it is not something unexpected. The IOVA choice will be printed in INFO level:
RTE_LOG(INFO, EAL, "Selected IOVA mode '%s'\n",
rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
Re: [dpdk-dev] [PATCH v2 0/3] Improve automatic selection of IOVA mode
In reply to David MarchandHelp in review would be much appreciated here, thanks.
14/06/2019 11:39, David Marchand:
Quoted 31 lines
In SPDK, not all drivers are registered with DPDK at start up time. Previously, that meant DPDK always chose to set itself up in
IOVA_PAmode. Instead, when the correct iova choice is unclear based on the devices and drivers known to DPDK at start up time, use other heuristics (such as whether/proc/self/pagemapis accessible) to make a better choice.This enables SPDK to run as an unprivileged user again without requiring users to explicitly set the iova mode on the command line.
Changelog since v1:
- I took over the series following experiments and discussions with Ben and others, squashed Ben patches as two patches focusing on the main issues,
- introduced a fix on KNI,
- on the EAL bits,- added log on which IOVA mode has been selected,
- updated BSD EAL,
- in Linux EAL, moved KNI special case after IOVA selection,
- in Linux EAL, added check on forced mode wrt physical addresses availability,- on the PCI bus driver bits,
- enforced the checks in the common code of the PCI bus,
- added debug logs to track why a iova mode has been chosen per device,
- added BSD part,
- in Linux part, checked that VFIO is enabled,
- in Linux part, defaulted to DC if a driver supports both PA and VA,
Re: [dpdk-dev] [PATCH v2 0/3] Improve automatic selection of IOVA mode
No review at all? I can merge then?
27/06/2019 19:05, Thomas Monjalon:
Quoted 38 lines
Help in review would be much appreciated here, thanks.
14/06/2019 11:39, David Marchand:
Quoted 31 lines
In SPDK, not all drivers are registered with DPDK at start up time. Previously, that meant DPDK always chose to set itself up in
IOVA_PAmode. Instead, when the correct iova choice is unclear based on the devices and drivers known to DPDK at start up time, use other heuristics (such as whether/proc/self/pagemapis accessible) to make a better choice.This enables SPDK to run as an unprivileged user again without requiring users to explicitly set the iova mode on the command line.
Changelog since v1:
- I took over the series following experiments and discussions with Ben and others, squashed Ben patches as two patches focusing on the main issues,
- introduced a fix on KNI,
- on the EAL bits,- added log on which IOVA mode has been selected,
- updated BSD EAL,
- in Linux EAL, moved KNI special case after IOVA selection,
- in Linux EAL, added check on forced mode wrt physical addresses availability,- on the PCI bus driver bits,
- enforced the checks in the common code of the PCI bus,
- added debug logs to track why a iova mode has been chosen per device,
- added BSD part,
- in Linux part, checked that VFIO is enabled,
- in Linux part, defaulted to DC if a driver supports both PA and VA,
Thomas Monjalon
AppliedRe: [dpdk-dev] [PATCH v2 0/3] Improve automatic selection of IOVA mode
In reply to David Marchand14/06/2019 11:39, David Marchand:
Quoted 9 lines
In SPDK, not all drivers are registered with DPDK at start up time. Previously, that meant DPDK always chose to set itself up in
IOVA_PAmode. Instead, when the correct iova choice is unclear based on the devices and drivers known to DPDK at start up time, use other heuristics (such as whether/proc/self/pagemapis accessible) to make a better choice.This enables SPDK to run as an unprivileged user again without requiring users to explicitly set the iova mode on the command line.
Applied, thanks