Device unplug and bus cleanup refactoring for NXP
cover Device unplug and bus cleanup refactoring for NXP
Hello Hemant,
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
Signature · 26 lines
David Marchand David Marchand (11): drivers/bus: cleanup device freeing in NXP bus scan bus/dpaa: allocate interrupt during probing bus/dpaa: support unplug and use generic cleanup bus/fslmc: fix memory leaks in scan bus/fslmc: fix per type device count bus/fslmc: simplify device parsing in scan bus/fslmc: refactor device filtering for multiprocess bus/fslmc: move unplug for some device out of VFIO bus/fslmc: call VFIO setup for some device from bus layer bus/fslmc: allocate interrupt during probing bus/fslmc: use generic cleanup doc/guides/rel_notes/release_26_11.rst | 4 + drivers/bus/dpaa/dpaa_bus.c | 134 +++++----- drivers/bus/fslmc/fslmc_bus.c | 295 +++++++++++++++-------- drivers/bus/fslmc/fslmc_vfio.c | 255 +++++++------------- drivers/bus/fslmc/fslmc_vfio.h | 5 + drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 + drivers/bus/fslmc/private.h | 2 + 7 files changed, 368 insertions(+), 328 deletions(-) -- 2.54.0
RFC 1/11 drivers/bus: cleanup device freeing in NXP bus scan
Following the scan/probe refactoring, in the DPAA bus driver scan method, the device list is empty at the time the pthread key object is allocated. This leaves only one location that wants to release the whole device list, so remove the dpaa_clean_device_list() helper.
Remove the same helper in FSLMC bus for consistency.
--- drivers/bus/dpaa/dpaa_bus.c | 15 ++------------- drivers/bus/fslmc/fslmc_bus.c | 21 ++++++--------------- 2 files changed, 8 insertions(+), 28 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +2 -13
@@ -193,8 +193,6 @@ dpaa_sec_available(void)return -1 ; } -static void dpaa_clean_device_list (void ); -static int dpaa_create_device_list (void ) {
@@ -336,21 +334,13 @@ dpaa_create_device_list(void)return 0 ; cleanup: -dpaa_clean_device_list (); -return ret; -} - -static void -dpaa_clean_device_list (void ) -{ -struct rte_dpaa_device *dev =NULL ; - RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {rte_bus_remove_device (&rte_dpaa_bus, &dev->device);rte_intr_instance_free (dev->intr_handle);free (dev); - dev =NULL ; } + +return ret; }RTE_EXPORT_INTERNAL_SYMBOL (rte_dpaa_portal_init)
@@ -699,7 +689,6 @@ rte_dpaa_bus_scan(void) ret =pthread_key_create (&dpaa_portal_key, dpaa_portal_finish);if (ret) {DPAA_BUS_LOG (DEBUG ,"Unable to create pthread key. (%d)" , ret); -dpaa_clean_device_list ();return ret; }
drivers/bus/fslmc/fslmc_bus.c +6 -15
@@ -43,19 +43,6 @@ rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type)return fslmc_bus_device_count[device_type]; } -static void -cleanup_fslmc_device_list (void ) -{ -struct rte_dpaa2_device *dev; - - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle); -free (dev); - dev =NULL ; - } -} -static int compare_dpaa2_devname (struct rte_dpaa2_device *dev1,struct rte_dpaa2_device *dev2)
@@ -305,6 +292,7 @@ fslmc_dev_compare(const char *name1, const char *name2)static int rte_fslmc_scan (void ) { +struct rte_dpaa2_device *dev;int ret;char fslmc_dirpath[PATH_MAX ];DIR *dir;
@@ -314,7 +302,6 @@ rte_fslmc_scan(void)char *group_name;if (process_once) { -struct rte_dpaa2_device *dev;DPAA2_BUS_DEBUG ("Fslmc bus already scanned. Not rescanning" ); RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {
@@ -416,7 +403,11 @@ rte_fslmc_scan(void)closedir (dir);/* Remove all devices in the list */ -cleanup_fslmc_device_list (); + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { +rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +rte_intr_instance_free (dev->intr_handle); +free (dev); + } scan_fail:DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */
Signature · 1 line
2.54.0
RFC 2/11 bus/dpaa: allocate interrupt during probing
In reply to David MarchandAllocating the interrupt handle is a waste of memory if no device is probed later (like for example, if a allowlist is passed).
Instead, allocate this handle, set eventfds and vfio at the time probe_device is called.
Adjust the unplug_device path accordingly.
--- drivers/bus/dpaa/dpaa_bus.c | 76 +++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 36 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +40 -36
@@ -215,16 +215,6 @@ dpaa_create_device_list(void) dev->device.numa_node =SOCKET_ID_ANY ; -/* Allocate interrupt handle instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); - ret = -ENOMEM ; -free (dev); - goto cleanup; - } - cfg = &dpaa_netcfg->port_cfg[i]; fman_intf = cfg->fman_if;
@@ -276,16 +266,6 @@ dpaa_create_device_list(void) goto cleanup; } -/* Allocate interrupt handle instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); - ret = -ENOMEM ; -free (dev); - goto cleanup; - } - dev->device_type =FSL_DPAA_CRYPTO ; dev->id.dev_id = dpaa_bus.device_count + i;
@@ -336,7 +316,6 @@ dpaa_create_device_list(void) cleanup: RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {rte_bus_remove_device (&rte_dpaa_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -637,7 +616,8 @@ rte_dpaa_bus_dev_build(void)return 0 ; } -static int rte_dpaa_setup_intr (struct rte_intr_handle *intr_handle) +static int +dpaa_setup_intr (struct rte_intr_handle *intr_handle) {int fd;
@@ -657,13 +637,21 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)return 0 ; } +static void +dpaa_close_intr (struct rte_intr_handle *intr_handle) +{ +if (rte_intr_fd_get (intr_handle) >=0 ) { +close (rte_intr_fd_get (intr_handle)); +rte_intr_fd_set (intr_handle,-1 ); + } +} +#define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa"#define DPAA_DEV_PATH2 "/sys/devices/platform/fsl,dpaa"static int rte_dpaa_bus_scan (void ) { -struct rte_dpaa_device *dev;FILE *svr_file =NULL ;uint32_t svr_ver;static int process_once;
@@ -752,14 +740,6 @@ rte_dpaa_bus_scan(void)*/ rte_mbuf_set_platform_mempool_ops (DPAA_MEMPOOL_OPS_NAME ); - RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) { -if (dev->device_type ==FSL_DPAA_ETH ) { - ret =rte_dpaa_setup_intr (dev->intr_handle); -if (ret) -DPAA_BUS_ERR ("Error setting up interrupt." ); - } - } -/* And initialize the PA->VA translation table */ dpaax_iova_table_populate ();
@@ -787,10 +767,30 @@ dpaa_bus_probe_device(struct rte_driver *drv, struct rte_device *dev)struct rte_dpaa_driver *dpaa_drv =RTE_BUS_DRIVER (drv, *dpaa_drv);int ret; +/* Allocate interrupt handle instance */ + dpaa_dev->intr_handle =rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); +if (dpaa_dev->intr_handle ==NULL ) { +DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); +return -ENOMEM ; + } + +if (dpaa_dev->device_type ==FSL_DPAA_ETH ) { + ret =dpaa_setup_intr (dpaa_dev->intr_handle); +if (ret !=0 ) { +DPAA_BUS_ERR ("error setting up interrupt: %s" , dpaa_dev->name); + ret = -ret; + goto release_intr; + } + } + ret = dpaa_drv->probe (dpaa_drv, dpaa_dev); -if (ret !=0 ) +if (ret !=0 ) {DPAA_BUS_ERR ("unable to probe: %s" , dpaa_dev->name); - +dpaa_close_intr (dpaa_dev->intr_handle); +release_intr: +rte_intr_instance_free (dpaa_dev->intr_handle); + dpaa_dev->intr_handle =NULL ; + }return ret; }
@@ -805,16 +805,20 @@ dpaa_bus_cleanup(struct rte_bus *bus)int ret =0 ;if (!rte_dev_is_probed (&dev->device)) -continue ; + goto next; drv =RTE_BUS_DRIVER (dev->device.driver, *drv);if (drv->remove ==NULL ) -continue ; + goto next; ret = drv->remove (dev);if (ret <0 ) { rte_errno = errno; -return -1 ; + goto next; } dev->device.driver =NULL ; +next: +dpaa_close_intr (dev->intr_handle); +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; }dpaa_portal_finish ((void *)DPAA_PER_LCORE_PORTAL ); dpaa_bus_global_init =0 ;
Signature · 1 line
2.54.0
RFC 3/11 bus/dpaa: support unplug and use generic cleanup
In reply to David MarchandAdd .unplug callback to handle driver removal and interrupt cleanup. This enables use of the generic bus cleanup helper while preserving bus-specific cleanup (portal finish, global init reset).
The cleanup function was already performing these operations, so it seems safe to expose them through the unplug operation.
--- doc/guides/rel_notes/release_26_11.rst | 4 ++ drivers/bus/dpaa/dpaa_bus.c | 57 +++++++++++++++----------- 2 files changed, 38 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -55,6 +55,10 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added unplug operation support to DPAA bus.** + + Implemented device unplug operation to allow runtime removal of DPAA devices. + Removed Items -------------
drivers/bus/dpaa/dpaa_bus.c +34 -23
84 lines not on this page · raw message
Signature · 1 line
2.54.0
RFC 4/11 bus/fslmc: fix memory leaks in scan
In reply to David MarchandDuring the scan phase (more precisely, during device filtering), device pointers were leaked.
Add a simple helper so a device pointer is fully freed.
As a consequence of the filtering during scan, all blocklisted devices are freed from the bus list during scan: there is no need for reevaluating if a device is blocklisted during cleanup.
--- drivers/bus/fslmc/fslmc_bus.c | 15 ++++++++++----- drivers/bus/fslmc/fslmc_vfio.c | 33 +++++++++------------------------ drivers/bus/fslmc/private.h | 2 ++ 3 files changed, 21 insertions(+), 29 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +10 -5
@@ -85,6 +85,14 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)rte_bus_add_device (&rte_fslmc_bus, &newdev->device); } +void +fslmc_bus_remove_device (struct rte_dpaa2_device *dev) +{ +rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +rte_intr_instance_free (dev->intr_handle); +free (dev); +} +static void dump_device_list (void ) {
@@ -403,11 +411,8 @@ rte_fslmc_scan(void)closedir (dir);/* Remove all devices in the list */ - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle); -free (dev); - } + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) +fslmc_bus_remove_device (dev); scan_fail:DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */
drivers/bus/fslmc/fslmc_vfio.c +9 -24
@@ -1555,13 +1555,6 @@ fslmc_vfio_close_group(void) } RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -if (dev->device.devargs && - dev->device.devargs->policy ==RTE_DEV_BLOCKED ) { -DPAA2_BUS_LOG (DEBUG ,"%s Blacklisted, skipping" , - dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -continue ; - }switch (dev->dev_type) {case DPAA2_ETH :case DPAA2_CRYPTO :
@@ -1623,8 +1616,7 @@ fslmc_vfio_process_group(void) dev->device.devargs->policy == RTE_DEV_BLOCKED) {DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);continue ; }
@@ -1632,8 +1624,7 @@ fslmc_vfio_process_group(void) !is_dpmcp_in_blocklist) {if (dpmcp_count ==1 || current_device != dpmcp_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);continue ; } }
@@ -1647,9 +1638,7 @@ fslmc_vfio_process_group(void) found_mportal =1 ; } -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -free (dev); - dev =NULL ; +fslmc_bus_remove_device (dev);/* Ideally there is only a single dpmcp, but in case * multiple exists, looping on remaining devices. */
@@ -1673,7 +1662,7 @@ fslmc_vfio_process_group(void)DPAA2_BUS_ERR ("Unable to process dprc" );return ret; } -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev); } }
@@ -1685,7 +1674,7 @@ fslmc_vfio_process_group(void) dev->device.devargs->policy == RTE_DEV_BLOCKED) {DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev);continue ; } if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
@@ -1693,7 +1682,7 @@ fslmc_vfio_process_group(void) dev->dev_type != DPAA2_CRYPTO && dev->dev_type != DPAA2_QDMA && dev->dev_type != DPAA2_IO) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev);continue ; }switch (dev->dev_type) {
@@ -1735,14 +1724,12 @@ fslmc_vfio_process_group(void)if (!is_dpio_in_blocklist && dpio_count >1 ) {if (rte_eal_process_type () ==RTE_PROC_SECONDARY && current_device != dpio_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);break ; }if (rte_eal_process_type () ==RTE_PROC_PRIMARY && current_device == dpio_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);break ; } }
@@ -1760,9 +1747,7 @@ fslmc_vfio_process_group(void)/* Unknown - ignore */ DPAA2_BUS_DEBUG ("Found unknown device (%s)" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -free (dev); - dev =NULL ; +fslmc_bus_remove_device (dev); } }
drivers/bus/fslmc/private.h +2 -0
@@ -11,4 +11,6 @@extern struct rte_bus rte_fslmc_bus; +void fslmc_bus_remove_device (struct rte_dpaa2_device *dev); +#endif /* BUS_FSLMC_PRIVATE_H */
Signature · 1 line
2.54.0
RFC 5/11 bus/fslmc: fix per type device count
In reply to David MarchandWhen blocklisting some device, the per type count was wrong.
--- drivers/bus/fslmc/fslmc_bus.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +6 -3
@@ -83,11 +83,17 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)if (!inserted)rte_bus_add_device (&rte_fslmc_bus, &newdev->device); + +if (newdev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[newdev->dev_type]++; }void fslmc_bus_remove_device (struct rte_dpaa2_device *dev) { +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]--; +rte_bus_remove_device (&rte_fslmc_bus, &dev->device);rte_intr_instance_free (dev->intr_handle);free (dev);
@@ -195,9 +201,6 @@ scan_one_fslmc_device(char *dev_name) } dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); -/* Update the device found into the device_count table */ - fslmc_bus_device_count[dev->dev_type]++; -/* Add device in the fslmc device list */ insert_in_device_list (dev);
Signature · 1 line
2.54.0
RFC 6/11 bus/fslmc: simplify device parsing in scan
In reply to David MarchandRefactor string manipulations and avoid unneeded allocation.
--- drivers/bus/fslmc/fslmc_bus.c | 78 +++++++++++++---------------------- 1 file changed, 28 insertions(+), 50 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +28 -50
@@ -116,18 +116,33 @@ dump_device_list(void)static int scan_one_fslmc_device (char *dev_name) { -char *dup_dev_name, *t_ptr; +enum rte_dpaa2_dev_type dev_type =DPAA2_UNKNOWN ;struct rte_dpaa2_device *dev =NULL ; +struct { +const char *prefix; +enum rte_dpaa2_dev_type type; + } dev_types[] = { + {"dpni." ,DPAA2_ETH }, + {"dpseci." ,DPAA2_CRYPTO }, + {"dpcon." ,DPAA2_CON }, + {"dpbp." ,DPAA2_BPOOL }, + {"dpio." ,DPAA2_IO }, + {"dpci." ,DPAA2_CI }, + {"dpmcp." ,DPAA2_MPORTAL }, + {"dpdmai." ,DPAA2_QDMA }, + {"dpdmux." ,DPAA2_MUX }, + {"dprtc." ,DPAA2_DPRTC }, + {"dprc." ,DPAA2_DPRC }, + }; +char *dev_id =NULL ;int ret =-1 ; -if (!dev_name) -return ret; - -/* Creating a temporary copy to perform cut-parse over string */ - dup_dev_name =strdup (dev_name); -if (!dup_dev_name) { -DPAA2_BUS_ERR ("Unable to allocate device name memory" ); -return -ENOMEM ; +for (unsigned int i =0 ; i <RTE_DIM (dev_types); i++) { +if (strncmp (dev_types[i].prefix, dev_name,strlen (dev_types[i].prefix)) !=0 ) +continue ; + dev_id = dev_name +strlen (dev_types[i].prefix); + dev_type = dev_types[i].type; +break ; }/* For all other devices, we allocate rte_dpaa2_device.
@@ -138,11 +153,11 @@ scan_one_fslmc_device(char *dev_name) dev =calloc (1 ,sizeof (struct rte_dpaa2_device ));if (!dev) {DPAA2_BUS_ERR ("Unable to allocate device object" ); -free (dup_dev_name);return -ENOMEM ; } dev->device.numa_node =SOCKET_ID_ANY ; + dev->dev_type = dev_type;/* Allocate interrupt instance */ dev->intr_handle =
@@ -153,46 +168,13 @@ scan_one_fslmc_device(char *dev_name) goto cleanup; } -/* Parse the device name and ID */ - t_ptr =strtok (dup_dev_name,"." ); -if (!t_ptr) { -DPAA2_BUS_ERR ("Invalid device found: (%s)" , dup_dev_name); - ret = -EINVAL ; - goto cleanup; - } -if (!strncmp ("dpni" , t_ptr,4 )) - dev->dev_type =DPAA2_ETH ; -else if (!strncmp ("dpseci" , t_ptr,6 )) - dev->dev_type =DPAA2_CRYPTO ; -else if (!strncmp ("dpcon" , t_ptr,5 )) - dev->dev_type =DPAA2_CON ; -else if (!strncmp ("dpbp" , t_ptr,4 )) - dev->dev_type =DPAA2_BPOOL ; -else if (!strncmp ("dpio" , t_ptr,4 )) - dev->dev_type =DPAA2_IO ; -else if (!strncmp ("dpci" , t_ptr,4 )) - dev->dev_type =DPAA2_CI ; -else if (!strncmp ("dpmcp" , t_ptr,5 )) - dev->dev_type =DPAA2_MPORTAL ; -else if (!strncmp ("dpdmai" , t_ptr,6 )) - dev->dev_type =DPAA2_QDMA ; -else if (!strncmp ("dpdmux" , t_ptr,6 )) - dev->dev_type =DPAA2_MUX ; -else if (!strncmp ("dprtc" , t_ptr,5 )) - dev->dev_type =DPAA2_DPRTC ; -else if (!strncmp ("dprc" , t_ptr,4 )) - dev->dev_type =DPAA2_DPRC ; -else - dev->dev_type =DPAA2_UNKNOWN ; - - t_ptr =strtok (NULL ,"." ); -if (!t_ptr) { -DPAA2_BUS_ERR ("Skipping invalid device (%s)" , dup_dev_name); +if (dev_id ==NULL ) { +DPAA2_BUS_ERR ("Skipping invalid device (%s)" , dev_name); ret =0 ; goto cleanup; } -sscanf (t_ptr,"%hu" , &dev->object_id); +sscanf (dev_id,"%hu" , &dev->object_id); dev->device.name =strdup (dev_name);if (!dev->device.name) {DPAA2_BUS_ERR ("Unable to clone device name. Out of memory" );
@@ -204,12 +186,8 @@ scan_one_fslmc_device(char *dev_name)/* Add device in the fslmc device list */ insert_in_device_list (dev); -/* Don't need the duplicated device filesystem entry anymore */ -free (dup_dev_name); -return 0 ; cleanup: -free (dup_dev_name);if (dev) {rte_intr_instance_free (dev->intr_handle);free (dev);
Signature · 1 line
2.54.0
RFC 7/11 bus/fslmc: refactor device filtering for multiprocess
In reply to David MarchandRefactor device filtering logic by splitting what was done in fslmc_vfio_process_group().
During scan, do not add device to the bus list unless needed (wrt secondary process, blocklist ...). Yet, keep a special case for MPORTAL/DPIO objects and filter them in a new fslmc_filter_control_devices() helper.
This helper is also responsible for selecting the right MPORTAL/DPIO objects depending on primary/secondary considerations.
As a consequence, fslmc_vfio_process_group() only handles IO device init without having to care about skipping some device.
Finally, remove now dead code in fslmc_vfio_close_group() since only used devices are left in the bus device list.
--- drivers/bus/fslmc/fslmc_bus.c | 134 ++++++++++++++++++++++++++--- drivers/bus/fslmc/fslmc_vfio.c | 150 +++++---------------------------- 2 files changed, 139 insertions(+), 145 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +120 -14
@@ -135,7 +135,6 @@ scan_one_fslmc_device(char *dev_name) { "dprc.", DPAA2_DPRC }, };char *dev_id =NULL ; -int ret =-1 ;for (unsigned int i =0 ; i <RTE_DIM (dev_types); i++) {if (strncmp (dev_types[i].prefix, dev_name,strlen (dev_types[i].prefix)) !=0 )
@@ -145,11 +144,37 @@ scan_one_fslmc_device(char *dev_name)break ; } -/* For all other devices, we allocate rte_dpaa2_device. -* For those devices where there is no driver, probe would release -* the memory associated with the rte_dpaa2_device after necessary -* initialization. +if (dev_id ==NULL ) { +DPAA2_BUS_ERR ("Skipping invalid device (%s)" , dev_name); +return 0 ; + } + +/* +* DPAA2_MPORTAL and DPAA2_IO types are handled separately, +* see fslmc_filter_control_devices() */ +if (rte_bus_device_is_ignored (&rte_fslmc_bus, dev_name) && + dev_type !=DPAA2_MPORTAL && dev_type !=DPAA2_IO ) { +DPAA2_BUS_DEBUG ("Skipping blocklisted device (%s)" , dev_name); +return 0 ; + } + +/* For secondary processes, control objects are not needed */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) { +switch (dev_type) { +case DPAA2_ETH : +case DPAA2_CRYPTO : +case DPAA2_QDMA : +case DPAA2_IO : +case DPAA2_MPORTAL : +case DPAA2_DPRC : +break ; +default : +DPAA2_BUS_DEBUG ("Skipping device in secondary process (%s)" , dev_name); +return 0 ; + } + } + dev =calloc (1 ,sizeof (struct rte_dpaa2_device ));if (!dev) {DPAA2_BUS_ERR ("Unable to allocate device object" );
@@ -164,13 +189,6 @@ scan_one_fslmc_device(char *dev_name)rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE );if (dev->intr_handle ==NULL ) {DPAA2_BUS_ERR ("Failed to allocate intr handle" ); - ret = -ENOMEM ; - goto cleanup; - } - -if (dev_id ==NULL ) { -DPAA2_BUS_ERR ("Skipping invalid device (%s)" , dev_name); - ret =0 ; goto cleanup; }
@@ -178,7 +196,6 @@ scan_one_fslmc_device(char *dev_name) dev->device.name =strdup (dev_name);if (!dev->device.name) {DPAA2_BUS_ERR ("Unable to clone device name. Out of memory" ); - ret = -ENOMEM ; goto cleanup; } dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name);
@@ -192,7 +209,7 @@ scan_one_fslmc_device(char *dev_name)rte_intr_instance_free (dev->intr_handle);free (dev); } -return ret; +return -ENOMEM ; } static int
@@ -278,6 +295,91 @@ fslmc_dev_compare(const char *name1, const char *name2)return strncmp (devname1, devname2,sizeof (devname1)); } +static int +fslmc_filter_control_devices (void ) +{ +bool is_dpmcp_in_blocklist = false, is_dpio_in_blocklist = false; +int dpmcp_count =0 , dpio_count =0 ; +struct rte_dpaa2_device *dev; + +/* Track MPORTAL/DPIO blocklists */ + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { +if (dev->dev_type !=DPAA2_MPORTAL && dev->dev_type !=DPAA2_IO ) +continue ; +if (rte_bus_device_is_ignored (&rte_fslmc_bus,rte_dev_name (&dev->device))) { +DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); +if (dev->dev_type ==DPAA2_MPORTAL ) + is_dpmcp_in_blocklist = true; +else if (dev->dev_type ==DPAA2_IO ) + is_dpio_in_blocklist = true; +fslmc_bus_remove_device (dev); +continue ; + } +if (dev->dev_type ==DPAA2_MPORTAL ) + dpmcp_count++; +else if (dev->dev_type ==DPAA2_IO ) + dpio_count++; + } + +if (dpmcp_count ==0 ) { +DPAA2_BUS_ERR ("No MC Portal device found" ); +return -ENODEV ; + } + +/* Automatic MPORTAL split: primary keeps first, secondary keeps last */ +if (!is_dpmcp_in_blocklist) { +int current_device =0 ; +int keep_index; + +/* Check MPORTAL availability for secondary */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && dpmcp_count <2 ) { +DPAA2_BUS_ERR ("No MC Portal device found for secondary" ); +return -ENODEV ; + } + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) + keep_index =0 ; +else + keep_index = dpmcp_count -1 ; + + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { +if (dev->dev_type !=DPAA2_MPORTAL ) +continue ; +if (current_device != keep_index) +fslmc_bus_remove_device (dev); + + current_device++; +if (current_device == dpmcp_count) +break ; + } + } + +/* Automatic DPIO split: secondary keeps last only, primary removes last */ +if (!is_dpio_in_blocklist) { +int last_index = dpio_count -1 ; +int current_device =0 ; + + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { +if (dev->dev_type !=DPAA2_IO ) +continue ; + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && + current_device != last_index) { +fslmc_bus_remove_device (dev); + }else if (rte_eal_process_type () ==RTE_PROC_PRIMARY && + current_device == last_index) { +fslmc_bus_remove_device (dev); + } + + current_device++; +if (current_device == dpio_count) +break ; + } + } + +return 0 ; +} +static int rte_fslmc_scan (void ) {
@@ -377,6 +479,10 @@ rte_fslmc_scan(void) } } + ret =fslmc_filter_control_devices (); +if (ret) +return 0 ; + ret =fslmc_vfio_process_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup devices %d" , ret);
drivers/bus/fslmc/fslmc_vfio.c +19 -131
195 lines not on this page · raw message
Signature · 1 line
2.54.0
RFC 8/11 bus/fslmc: move unplug for some device out of VFIO
In reply to David MarchandMove device unplug out of the code dealing with VFIO, interrupts and IO devices.
--- drivers/bus/fslmc/fslmc_bus.c | 15 ++++++++++++++- drivers/bus/fslmc/fslmc_vfio.c | 10 ---------- 2 files changed, 14 insertions(+), 11 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +14 -1
@@ -519,10 +519,23 @@ fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev) }static int -rte_fslmc_close(struct rte_bus *bus __rte_unused) +fslmc_bus_unplug_device (struct rte_device *rte_dev); + +static int +rte_fslmc_close (struct rte_bus *bus) { +struct rte_dpaa2_device *dev;int ret =0 ; + RTE_BUS_FOREACH_DEV(dev, bus) { +if (dev->dev_type !=DPAA2_ETH && + dev->dev_type !=DPAA2_CRYPTO && + dev->dev_type !=DPAA2_QDMA ) +continue ; +if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device)) +DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); + } + ret =fslmc_vfio_close_group ();if (ret)DPAA2_BUS_INFO ("Unable to close devices %d" , ret);
drivers/bus/fslmc/fslmc_vfio.c +0 -10
@@ -1392,7 +1392,6 @@ fslmc_close_iodevices(struct rte_dpaa2_device *dev, int vfio_fd) {struct rte_dpaa2_object *object =NULL ; -const struct rte_dpaa2_driver *drv;int ret;switch (dev->dev_type) {
@@ -1408,15 +1407,6 @@ fslmc_close_iodevices(struct rte_dpaa2_device *dev,continue ; }break ; -case DPAA2_ETH : -case DPAA2_CRYPTO : -case DPAA2_QDMA : -if (dev->device.driver !=NULL ) { - drv =RTE_BUS_DRIVER (dev->device.driver, *drv); -if (drv->remove && drv->remove (dev)) -DPAA2_BUS_ERR ("Unable to remove" ); - } -break ;default :break ; }
Signature · 1 line
2.54.0
RFC 9/11 bus/fslmc: call VFIO setup for some device from bus layer
In reply to David MarchandMove VFIO device and interrupt setup for ETH, CRYPTO, and QDMA devices from fslmc_vfio.c to fslmc_bus.c scan layer.
Add fslmc_vfio_dev_setup() (resp. fslmc_vfio_dev_close()) wrapper that handles VFIO device fd acquisition and interrupt setup (resp. device removal), hiding VFIO internals from the bus layer.
--- drivers/bus/fslmc/fslmc_bus.c | 13 ++++++ drivers/bus/fslmc/fslmc_vfio.c | 80 ++++++++++++++++++++++++++++++---- drivers/bus/fslmc/fslmc_vfio.h | 5 +++ 3 files changed, 90 insertions(+), 8 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +13 -0
@@ -488,6 +488,18 @@ rte_fslmc_scan(void)DPAA2_BUS_ERR ("Unable to setup devices %d" , ret);return 0 ; } + + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { +if (dev->dev_type !=DPAA2_ETH && + dev->dev_type !=DPAA2_CRYPTO && + dev->dev_type !=DPAA2_QDMA ) +continue ; + ret =fslmc_vfio_dev_setup (dev); +if (ret) { +DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); +return 0 ; + } + } } process_once =1 ;
@@ -534,6 +546,7 @@ rte_fslmc_close(struct rte_bus *bus)continue ;if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device))DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); +fslmc_vfio_dev_close (dev); } ret =fslmc_vfio_close_group ();
drivers/bus/fslmc/fslmc_vfio.c +72 -8
122 lines not on this page · raw message
drivers/bus/fslmc/fslmc_vfio.h +5 -0
@@ -60,4 +60,9 @@ int fslmc_vfio_close_group(void);char *fslmc_get_container (void );int fslmc_get_container_group (const char *group_name,int *gropuid);int fslmc_vfio_dmamap (void ); + +struct rte_dpaa2_device ; +int fslmc_vfio_dev_setup (struct rte_dpaa2_device *dev); +int fslmc_vfio_dev_close (struct rte_dpaa2_device *dev); +#endif /* _FSLMC_VFIO_H_ */
Signature · 1 line
2.54.0
RFC 10/11 bus/fslmc: allocate interrupt during probing
In reply to David MarchandAllocating the interrupt handle is a waste of memory if no device is probed later (like for example, if a allowlist is passed).
Instead, allocate this handle, set eventfds and vfio at the time probe_device is called.
Adjust the unplug_device path accordingly.
--- drivers/bus/fslmc/fslmc_bus.c | 54 ++++++++++-------------- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 + 2 files changed, 24 insertions(+), 31 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +23 -31
@@ -95,7 +95,6 @@ fslmc_bus_remove_device(struct rte_dpaa2_device *dev) fslmc_bus_device_count[dev->dev_type]--;rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -184,19 +183,12 @@ scan_one_fslmc_device(char *dev_name) dev->device.numa_node =SOCKET_ID_ANY ; dev->dev_type = dev_type; -/* Allocate interrupt instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA2_BUS_ERR ("Failed to allocate intr handle" ); - goto cleanup; - } -sscanf (dev_id,"%hu" , &dev->object_id); dev->device.name =strdup (dev_name);if (!dev->device.name) {DPAA2_BUS_ERR ("Unable to clone device name. Out of memory" ); - goto cleanup; +free (dev); +return -ENOMEM ; } dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name);
@@ -204,12 +196,6 @@ scan_one_fslmc_device(char *dev_name)insert_in_device_list (dev);return 0 ; -cleanup: -if (dev) { -rte_intr_instance_free (dev->intr_handle); -free (dev); - } -return -ENOMEM ; } static int
@@ -488,18 +474,6 @@ rte_fslmc_scan(void)DPAA2_BUS_ERR ("Unable to setup devices %d" , ret);return 0 ; } - - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -if (dev->dev_type !=DPAA2_ETH && - dev->dev_type !=DPAA2_CRYPTO && - dev->dev_type !=DPAA2_QDMA ) -continue ; - ret =fslmc_vfio_dev_setup (dev); -if (ret) { -DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); -return 0 ; - } - } } process_once =1 ;
@@ -546,7 +520,6 @@ rte_fslmc_close(struct rte_bus *bus)continue ;if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device))DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); -fslmc_vfio_dev_close (dev); } ret =fslmc_vfio_close_group ();
@@ -622,10 +595,27 @@ fslmc_bus_probe_device(struct rte_driver *driver, struct rte_device *rte_dev)struct rte_dpaa2_driver *drv =RTE_BUS_DRIVER (driver, *drv);int ret =0 ; -/* FIXME: probe_device should allocate intr_handle */ +/* Allocate interrupt instance */ + dev->intr_handle = +rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); +if (dev->intr_handle ==NULL ) { +DPAA2_BUS_ERR ("Failed to allocate intr handle" ); +return -ENOMEM ; + } + + ret =fslmc_vfio_dev_setup (dev); +if (ret) { +DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); + goto release_intr; + } + ret = drv->probe (drv, dev);if (ret !=0 ) {DPAA2_BUS_ERR ("Unable to probe" ); +fslmc_vfio_dev_close (dev); +release_intr: +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; }else {DPAA2_BUS_INFO ("%s Plugged" , dev->device.name); }
@@ -643,7 +633,9 @@ fslmc_bus_unplug_device(struct rte_device *rte_dev)int ret = drv->remove (dev);if (ret !=0 )return ret; -/* FIXME: unplug_device should free intr_handle */ +fslmc_vfio_dev_close (dev); +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ;DPAA2_BUS_INFO ("%s Un-Plugged" , dev->device.name);return 0 ; }
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +1 -0
@@ -470,6 +470,7 @@ dpaa2_close_dpio_device(int object_id)rte_free (dpio_dev->dpio); }TAILQ_REMOVE (&dpio_dev_list, dpio_dev, next); +rte_intr_instance_free (dpio_dev->intr_handle);rte_free (dpio_dev); } }
Signature · 1 line
2.54.0
RFC 11/11 bus/fslmc: use generic cleanup
In reply to David MarchandNow that the probe and unplug callback behave like other buses, we can call generic cleanup in addition to the special handling for IO devices.
--- drivers/bus/fslmc/fslmc_bus.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +10 -14
@@ -504,23 +504,18 @@ fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev)return false; } -static int -fslmc_bus_unplug_device (struct rte_device *rte_dev); +static void +fslmc_free_device (struct rte_device *rte_dev) +{ +free (RTE_BUS_DEVICE(rte_dev ,struct rte_dpaa2_device )); +}static int -rte_fslmc_close (struct rte_bus *bus) +fslmc_cleanup (struct rte_bus *bus) { -struct rte_dpaa2_device *dev; -int ret =0 ; +int ret; - RTE_BUS_FOREACH_DEV(dev, bus) { -if (dev->dev_type !=DPAA2_ETH && - dev->dev_type !=DPAA2_CRYPTO && - dev->dev_type !=DPAA2_QDMA ) -continue ; -if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device)) -DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); - } +rte_bus_generic_cleanup (bus); ret =fslmc_vfio_close_group ();if (ret)
@@ -646,7 +641,8 @@ fslmc_bus_unplug_device(struct rte_device *rte_dev)struct rte_bus rte_fslmc_bus = { .scan = rte_fslmc_scan, .probe = rte_bus_generic_probe, - .cleanup = rte_fslmc_close, + .free_device = fslmc_free_device, + .cleanup = fslmc_cleanup, .parse = rte_fslmc_parse, .dev_compare = fslmc_dev_compare, .find_device = rte_bus_generic_find_device,
Signature · 1 line
2.54.0
HI David,
Thanks for the work. We will test it soon.
Regards
Hemant
Quoted 51 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: 23 July 2026 19:24
To: Hemant Agrawal <[email protected]>; [email protected]
Subject: [RFC 00/11] Device unplug and bus cleanup refactoring for NXP
Importance: HighHello Hemant,
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
--
David MarchandDavid Marchand (11):
drivers/bus: cleanup device freeing in NXP bus scan bus/dpaa: allocate interrupt during probing bus/dpaa: support unplug and use generic cleanup bus/fslmc: fix memory leaks in scan
bus/fslmc: fix per type device count
bus/fslmc: simplify device parsing in scan bus/fslmc: refactor device filtering for multiprocess bus/fslmc: move unplug for some device out of VFIO bus/fslmc: call VFIO setup for some device from bus layer bus/fslmc: allocate interrupt during probing bus/fslmc: use generic cleanupdoc/guides/rel_notes/release_26_11.rst | 4 + drivers/bus/dpaa/dpaa_bus.c | 134 +++++----- drivers/bus/fslmc/fslmc_bus.c | 295 +++++++++++++++-------- drivers/bus/fslmc/fslmc_vfio.c | 255 +++++++------------- drivers/bus/fslmc/fslmc_vfio.h | 5 + drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 + drivers/bus/fslmc/private.h | 2 + 7 files changed, 368 insertions(+), 328 deletions(-)--
2.54.0
Quoted 3 lines · Hemant Agrawal
HI David,
Thanks for the work. We will test it soon.
Any update?
Signature · 1 line
David Marchand
________________________________
From: David Marchand <[email protected]>
Sent: Thursday, September 3, 2026 7:00 PM
To: Hemant Agrawal <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [RFC 00/11] Device unplug and bus cleanup refactoring for NXP
Quoted 3 lines · Hemant Agrawal
HI David,
Thanks for the work. We will test it soon.
Any update?
We just completed sanity and a few quick tests. This patch set is not causing any regression.
--
David Marchand
NXP Confidential
Hello Hemant,
Quoted 8 lines · Hemant Agrawal
Quoted 5 lines · Hemant Agrawal
Quoted 3 lines
HI David,
Thanks for the work. We will test it soon.Any update?
We just completed sanity and a few quick tests. This patch set is not causing any regression.
Thanks a lot for testing.
Stephen comments have spotted a number of issues, I'll post a v2 soon.
Signature · 1 line
David Marchand
Quoted 10 lines · On Thu, 23 Jul 2026 15:53:48 +0200 David Marchand <[email protected]>…
Hello Hemant,
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
Quoted 8 lines
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
Detailed AI review spotted some things.
Review of [RFC 00/11] bus refactoring for NXP buses
Reviewed against DPDK main (c1a46b9), applied with git am, cross-built with config/arm/arm64_dpaa_linux_gcc -Dwerror=true.
Patch 02/11: bus/dpaa: allocate interrupt during probing
Error: fd leak on the dpaa_setup_intr() failure path.
ret = dpaa_setup_intr(dpaa_dev->intr_handle);
if (ret != 0) {
...
goto release_intr;
}
...
dpaa_close_intr(dpaa_dev->intr_handle);
release_intr:
rte_intr_instance_free(dpaa_dev->intr_handle);dpaa_setup_intr() opens an eventfd and stores it with rte_intr_fd_set() before calling rte_intr_type_set(). If rte_intr_type_set() fails, the fd is already installed in the handle, but the goto lands past dpaa_close_intr(), so the instance is freed with the fd still open. Move the label above dpaa_close_intr(), or close the fd inside dpaa_setup_intr() on its own error paths.
Warning: error propagation lost in dpaa_bus_cleanup(). The old code returned -1 when drv->remove() failed; the rewritten loop does "rte_errno = errno; goto next;" and the function unconditionally returns
0. The local "ret" is also assigned and never read afterwards. This is transient (patch 03 replaces the body with rte_bus_generic_cleanup()) but each commit should stand on its own; track the failure in a variable and return it.
Info: jumping into the middle of an if-block ("release_intr:" inside the "if (ret != 0)" body) is legal but hard to follow. A separate error block would read better.
Patch 04/11: bus/fslmc: fix memory leaks in scan
Warning: fslmc_bus_remove_device() is described as fully freeing a device, but dev->device.name is strdup()'d in scan_one_fslmc_device() and never freed here or anywhere else. Same gap in fslmc_free_device() added by patch 11. Since this patch is specifically about scan-time leaks, freeing the name belongs here.
Patch 07/11: bus/fslmc: refactor device filtering for multiprocess
Error: allowlist mode is broken by moving the ignore test into scan. scan_one_fslmc_device() now calls rte_bus_device_is_ignored(), which in RTE_BUS_SCAN_ALLOWLIST mode returns true for every device lacking an explicit RTE_DEV_ALLOWED devargs. A single "-a fslmc:dpni.1" sets rte_fslmc_bus.conf.scan_mode to ALLOWLIST (eal_common_devargs.c:349), after which dpbp/dpcon/dpci/dprc/dpdmux/dprtc are dropped at scan time. Those control objects are not probed by a driver; they are initialised by fslmc_vfio_process_group(), so dropping them at scan leaves the bus non-functional. fslmc_filter_control_devices() applies the same test to DPMCP and DPIO, so allowlist mode also fails "No MC Portal device found" (-ENODEV). The old code tested only devargs->policy == RTE_DEV_BLOCKED, and the generic probe loop already skips ignored devices at probe time, which is why allowlists worked before.
Error: the DPIO split drops the only DPIO on a primary process. The old code guarded the split with "dpio_count > 1":
if (!is_dpio_in_blocklist && dpio_count > 1) {The new helper has no such guard, so with exactly one DPIO, last_index == 0, current_device == 0, and the primary branch removes it:
} else if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
current_device == last_index) {
fslmc_bus_remove_device(dev);Restore the dpio_count > 1 condition.
Warning: when a DPMCP is blocklisted, surplus MPORTAL devices are left in the bus list. fslmc_vfio_process_group() now breaks out of the MPORTAL loop after the first device. When is_dpmcp_in_blocklist is set, fslmc_filter_control_devices() skips the split, so more than one MPORTAL can remain and the extras are never removed. The previous loop had no break and removed all of them.
Patch 11/11: bus/fslmc: use generic cleanup
Error: cleanup ordering makes fslmc_vfio_close_group() a no-op.
rte_bus_generic_cleanup(bus); ret = fslmc_vfio_close_group();
rte_bus_generic_cleanup() unplugs every device, calls rte_bus_remove_device() and then bus->free_device(), emptying rte_fslmc_bus.device_list. fslmc_vfio_close_group() then iterates that now-empty list, so fslmc_close_iodevices() is never called for DPIO, DPCON, DPCI, DPBP or DPDMUX; only fslmc_vfio_clear_group() still runs. Call fslmc_vfio_close_group() before rte_bus_generic_cleanup().
Warning: the return value of rte_bus_generic_cleanup() is discarded. It reports unplug failures via -1/rte_errno; fslmc_cleanup() overwrites "ret" with the fslmc_vfio_close_group() result and loses it.
Warning: fslmc_free_device() only calls free(). It does not release dev->intr_handle and does not decrement fslmc_bus_device_count[], both of which fslmc_bus_remove_device() handles. Devices torn down through the generic path therefore leave the per-type counters permanently stale.
Info (01/11): removing the "struct rte_dpaa2_device *dev" declaration from the process_once block leaves a stray blank line at the top of the block in rte_fslmc_scan().
Info (06/11): dev_types[] is a non-static, non-const local array, so it is rebuilt on the stack for every device. Make it "static const".
Info (06/11): the sscanf() return value is unchecked, and the new prefix-based match is weaker than the old strtok() guard. A name such as "dpni." matches the prefix, leaves dev_id pointing at "", sscanf() fails, and the device is registered with object_id 0 -- colliding with a real dpni.0. The old code rejected it because strtok(NULL, ".") returned NULL. Check that sscanf() returns 1 and skip the device otherwise.
v2 cover Device unplug and bus cleanup refactoring for NXP
In reply to David MarchandHello Hemant,
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
Signature · 41 lines
David Marchand
Changes since RFC v1:
- fixed FD leak in bus/dpaa pre existing code,
- fixed device name leak in bus/fslmc pre existing code,
- fixed other leaks found by AI review,
- split DPAA2 devices in two list:
- one list in the bus object for devices for which a driver exists,
- one list local to the fslmc bus code for internal resources that
are initialised out of the EAL / bus framework,
David Marchand (16):
drivers/bus: cleanup device freeing in NXP bus scan
drivers/bus: fix FD leak during scan in NXP drivers
bus/dpaa: allocate interrupt during probing
bus/dpaa: support unplug and use generic cleanup
bus/fslmc: fix device name leak
bus/fslmc: fix memory leaks in scan
bus/fslmc: fix per type device count
bus/fslmc: fix some VFIO device FD and memory leaks
bus/fslmc: fix interrupt leak in DPIO cleanup
bus/fslmc: simplify device parsing in scan
bus/fslmc: release resources on scan failure
bus/fslmc: refactor device filtering for multiprocess
bus/fslmc: move unplug for some device out of VFIO
bus/fslmc: call VFIO setup for some device from bus layer
bus/fslmc: allocate interrupt during probing
bus/fslmc: use generic cleanup
doc/guides/rel_notes/release_26_11.rst | 4 +
drivers/bus/dpaa/dpaa_bus.c | 146 ++++----
drivers/bus/fslmc/bus_fslmc_driver.h | 4 +-
drivers/bus/fslmc/fslmc_bus.c | 431 +++++++++++++++++------
drivers/bus/fslmc/fslmc_vfio.c | 407 ++++++++++-----------
drivers/bus/fslmc/fslmc_vfio.h | 6 +
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 +
drivers/bus/fslmc/private.h | 6 +
8 files changed, 601 insertions(+), 404 deletions(-)
--
2.54.0RFC v2 1/16 drivers/bus: cleanup device freeing in NXP bus scan
Following the scan/probe refactoring, in the DPAA bus driver scan method, the device list is empty at the time the pthread key object is allocated. This leaves only one location that wants to release the whole device list, so remove the dpaa_clean_device_list() helper.
Remove the same helper in FSLMC bus for consistency.
--- drivers/bus/dpaa/dpaa_bus.c | 15 ++------------- drivers/bus/fslmc/fslmc_bus.c | 22 ++++++---------------- 2 files changed, 8 insertions(+), 29 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +2 -13
@@ -193,8 +193,6 @@ dpaa_sec_available(void)return -1 ; } -static void dpaa_clean_device_list (void ); -static int dpaa_create_device_list (void ) {
@@ -336,21 +334,13 @@ dpaa_create_device_list(void)return 0 ; cleanup: -dpaa_clean_device_list (); -return ret; -} - -static void -dpaa_clean_device_list (void ) -{ -struct rte_dpaa_device *dev =NULL ; - RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {rte_bus_remove_device (&rte_dpaa_bus, &dev->device);rte_intr_instance_free (dev->intr_handle);free (dev); - dev =NULL ; } + +return ret; }RTE_EXPORT_INTERNAL_SYMBOL (rte_dpaa_portal_init)
@@ -699,7 +689,6 @@ rte_dpaa_bus_scan(void) ret =pthread_key_create (&dpaa_portal_key, dpaa_portal_finish);if (ret) {DPAA_BUS_LOG (DEBUG ,"Unable to create pthread key. (%d)" , ret); -dpaa_clean_device_list ();return ret; }
drivers/bus/fslmc/fslmc_bus.c +6 -16
@@ -43,19 +43,6 @@ rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type)return fslmc_bus_device_count[device_type]; } -static void -cleanup_fslmc_device_list (void ) -{ -struct rte_dpaa2_device *dev; - - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle); -free (dev); - dev =NULL ; - } -} -static int compare_dpaa2_devname (struct rte_dpaa2_device *dev1,struct rte_dpaa2_device *dev2)
@@ -305,6 +292,7 @@ fslmc_dev_compare(const char *name1, const char *name2)static int rte_fslmc_scan (void ) { +struct rte_dpaa2_device *dev;int ret;char fslmc_dirpath[PATH_MAX ];DIR *dir;
@@ -314,8 +302,6 @@ rte_fslmc_scan(void)char *group_name;if (process_once) { -struct rte_dpaa2_device *dev; -DPAA2_BUS_DEBUG ("Fslmc bus already scanned. Not rescanning" ); RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { dev->device.devargs = rte_bus_find_devargs(&rte_fslmc_bus,
@@ -416,7 +402,11 @@ rte_fslmc_scan(void)closedir (dir);/* Remove all devices in the list */ -cleanup_fslmc_device_list (); + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { +rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +rte_intr_instance_free (dev->intr_handle); +free (dev); + } scan_fail:DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */
Signature · 1 line
2.54.0
RFC v2 2/16 drivers/bus: fix FD leak during scan in NXP drivers
In reply to David MarchandIn theory, if the interrupt handle setup fails, an eventfd gets leaked.
In practice, as long as the interrupt handle is valid, those calls can not fail, but this could get broken in the future so it is better to handle this error branch correctly.
--- drivers/bus/dpaa/dpaa_bus.c | 11 +++++++---- drivers/bus/fslmc/fslmc_vfio.c | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +7 -4
@@ -648,11 +648,14 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)return errno; } -if (rte_intr_fd_set (intr_handle, fd)) -return rte_errno; +if (rte_intr_fd_set (intr_handle, fd) || +rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_EXT )) { +int err = rte_errno; -if (rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_EXT )) -return rte_errno; +close (fd); +rte_intr_fd_set (intr_handle,-1 ); +return err; + }return 0 ; }
drivers/bus/fslmc/fslmc_vfio.c +10 -8
@@ -1371,14 +1371,16 @@ rte_dpaa2_vfio_setup_intr(struct rte_intr_handle *intr_handle,return fd; } -if (rte_intr_fd_set (intr_handle, fd)) -return -rte_errno; - -if (rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_VFIO_MSI )) -return -rte_errno; - -if (rte_intr_dev_fd_set (intr_handle, vfio_dev_fd)) -return -rte_errno; +if (rte_intr_fd_set (intr_handle, fd) || +rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_VFIO_MSI ) || +rte_intr_dev_fd_set (intr_handle, vfio_dev_fd)) { +int error = -rte_errno; + +close (fd); +rte_intr_fd_set (intr_handle,-1 ); +rte_intr_dev_fd_set (intr_handle,-1 ); +return error; + }return 0 ; }
Signature · 1 line
2.54.0
RFC v2 3/16 bus/dpaa: allocate interrupt during probing
In reply to David MarchandAllocating the interrupt handle is a waste of memory if no device is probed later (like for example, if a allowlist is passed).
Instead, allocate this handle, set eventfds and vfio at the time probe_device is called.
Adjust the unplug_device path accordingly.
---
Changes since RFC v1:
- restored return code on error in cleanup,
--- drivers/bus/dpaa/dpaa_bus.c | 82 ++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 38 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +44 -38
@@ -215,16 +215,6 @@ dpaa_create_device_list(void) dev->device.numa_node =SOCKET_ID_ANY ; -/* Allocate interrupt handle instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); - ret = -ENOMEM ; -free (dev); - goto cleanup; - } - cfg = &dpaa_netcfg->port_cfg[i]; fman_intf = cfg->fman_if;
@@ -276,16 +266,6 @@ dpaa_create_device_list(void) goto cleanup; } -/* Allocate interrupt handle instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); - ret = -ENOMEM ; -free (dev); - goto cleanup; - } - dev->device_type =FSL_DPAA_CRYPTO ; dev->id.dev_id = dpaa_bus.device_count + i;
@@ -336,7 +316,6 @@ dpaa_create_device_list(void) cleanup: RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {rte_bus_remove_device (&rte_dpaa_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -637,7 +616,8 @@ rte_dpaa_bus_dev_build(void)return 0 ; } -static int rte_dpaa_setup_intr (struct rte_intr_handle *intr_handle) +static int +dpaa_setup_intr (struct rte_intr_handle *intr_handle) {int fd;
@@ -660,13 +640,21 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)return 0 ; } +static void +dpaa_close_intr (struct rte_intr_handle *intr_handle) +{ +if (rte_intr_fd_get (intr_handle) >=0 ) { +close (rte_intr_fd_get (intr_handle)); +rte_intr_fd_set (intr_handle,-1 ); + } +} +#define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa"#define DPAA_DEV_PATH2 "/sys/devices/platform/fsl,dpaa"static int rte_dpaa_bus_scan (void ) { -struct rte_dpaa_device *dev;FILE *svr_file =NULL ;uint32_t svr_ver;static int process_once;
@@ -755,14 +743,6 @@ rte_dpaa_bus_scan(void)*/ rte_mbuf_set_platform_mempool_ops (DPAA_MEMPOOL_OPS_NAME ); - RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) { -if (dev->device_type ==FSL_DPAA_ETH ) { - ret =rte_dpaa_setup_intr (dev->intr_handle); -if (ret) -DPAA_BUS_ERR ("Error setting up interrupt." ); - } - } -/* And initialize the PA->VA translation table */ dpaax_iova_table_populate ();
@@ -790,10 +770,30 @@ dpaa_bus_probe_device(struct rte_driver *drv, struct rte_device *dev)struct rte_dpaa_driver *dpaa_drv =RTE_BUS_DRIVER (drv, *dpaa_drv);int ret; +/* Allocate interrupt handle instance */ + dpaa_dev->intr_handle =rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); +if (dpaa_dev->intr_handle ==NULL ) { +DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); +return -ENOMEM ; + } + +if (dpaa_dev->device_type ==FSL_DPAA_ETH ) { + ret =dpaa_setup_intr (dpaa_dev->intr_handle); +if (ret !=0 ) { +DPAA_BUS_ERR ("error setting up interrupt: %s" , dpaa_dev->name); + ret = -ret; + goto release_intr; + } + } + ret = dpaa_drv->probe (dpaa_drv, dpaa_dev); -if (ret !=0 ) +if (ret !=0 ) {DPAA_BUS_ERR ("unable to probe: %s" , dpaa_dev->name); - +dpaa_close_intr (dpaa_dev->intr_handle); +release_intr: +rte_intr_instance_free (dpaa_dev->intr_handle); + dpaa_dev->intr_handle =NULL ; + }return ret; }
@@ -801,29 +801,35 @@ static int dpaa_bus_cleanup(struct rte_bus *bus) {struct rte_dpaa_device *dev; +int error =0 ;BUS_INIT_FUNC_TRACE (); RTE_BUS_FOREACH_DEV(dev, bus) {const struct rte_dpaa_driver *drv; -int ret =0 ; +int ret;if (!rte_dev_is_probed (&dev->device)) -continue ; + goto next; drv =RTE_BUS_DRIVER (dev->device.driver, *drv);if (drv->remove ==NULL ) -continue ; + goto next; ret = drv->remove (dev);if (ret <0 ) { rte_errno = errno; -return -1 ; + error =-1 ; + goto next; } dev->device.driver =NULL ; +next: +dpaa_close_intr (dev->intr_handle); +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; }dpaa_portal_finish ((void *)DPAA_PER_LCORE_PORTAL ); dpaa_bus_global_init =0 ;DPAA_BUS_DEBUG ("Bus cleanup done" ); -return 0 ; +return error; }/* Adding destructor for double check in case non-gracefully
Signature · 1 line
2.54.0
RFC v2 4/16 bus/dpaa: support unplug and use generic cleanup
In reply to David MarchandAdd .unplug callback to handle driver removal and interrupt cleanup. This enables use of the generic bus cleanup helper while preserving bus-specific cleanup (portal finish, global init reset).
The cleanup function was already performing these operations, so it seems safe to expose them through the unplug operation.
--- doc/guides/rel_notes/release_26_11.rst | 4 ++ drivers/bus/dpaa/dpaa_bus.c | 56 +++++++++++++++----------- 2 files changed, 37 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -55,6 +55,10 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added unplug operation support to DPAA bus.** + + Implemented device unplug operation to allow runtime removal of DPAA devices. + Removed Items -------------
drivers/bus/dpaa/dpaa_bus.c +33 -23
85 lines not on this page · raw message
Signature · 1 line
2.54.0
RFC v2 5/16 bus/fslmc: fix device name leak
In reply to David MarchandThe device name allocated during scan was never freed. Store it to the (unused) name field in the rte_dpaa2_device.
This simplifies the device freeing to a simple free() call later.
--- drivers/bus/fslmc/bus_fslmc_driver.h | 4 +--- drivers/bus/fslmc/fslmc_bus.c | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/bus/fslmc/bus_fslmc_driver.h +1 -3
@@ -39,8 +39,6 @@ extern "C" {struct vfio_device_info ; -#define FSLMC_OBJECT_MAX_LEN 32/**< Length of each device on bus */ -#define DPAA2_INVALID_MBUF_SEQN 0typedef uint32_t dpaa2_seqn_t ;
@@ -101,7 +99,7 @@ struct rte_dpaa2_device {uint16_t ep_object_id;/**< Endpoint DPAA2 Object ID */ char ep_name[RTE_DEV_NAME_MAX_LEN ];struct rte_intr_handle *intr_handle;/**< Interrupt handle */ -char name[FSLMC_OBJECT_MAX_LEN ];/**< DPAA2 Object name*/ +char name[RTE_DEV_NAME_MAX_LEN ]; }; typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
drivers/bus/fslmc/fslmc_bus.c +4 -4
@@ -179,12 +179,12 @@ scan_one_fslmc_device(char *dev_name) }sscanf (t_ptr,"%hu" , &dev->object_id); - dev->device.name =strdup (dev_name); -if (!dev->device.name) { -DPAA2_BUS_ERR ("Unable to clone device name. Out of memory" ); - ret = -ENOMEM ; +if (rte_strscpy (dev->name, dev_name,sizeof (dev->name)) <0 ) { +DPAA2_BUS_ERR ("Unable to copy device name: %s" ,rte_strerror (rte_errno)); + ret = -rte_errno; goto cleanup; } + dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name);/* Update the device found into the device_count table */
Signature · 1 line
2.54.0
RFC v2 6/16 bus/fslmc: fix memory leaks in scan
In reply to David MarchandDuring the scan phase (more precisely, during device filtering), device pointers were leaked.
Add a simple helper so a device pointer is fully freed.
As a consequence of the filtering during scan, all blocklisted devices are freed from the bus list during scan: there is no need for reevaluating if a device is blocklisted during cleanup.
---
Changes since RFC v1:
- fixed interrupt handle leak by adding fslmc_free_device helper sooner in the series,
--- drivers/bus/fslmc/fslmc_bus.c | 23 ++++++++++++++++++----- drivers/bus/fslmc/fslmc_vfio.c | 33 +++++++++------------------------ drivers/bus/fslmc/private.h | 2 ++ 3 files changed, 29 insertions(+), 29 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +18 -5
@@ -85,6 +85,22 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)rte_bus_add_device (&rte_fslmc_bus, &newdev->device); } +static void +fslmc_free_device (struct rte_device *rte_dev) +{ +struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); + +rte_intr_instance_free (dev->intr_handle); +free (dev); +} + +void +fslmc_bus_remove_device (struct rte_dpaa2_device *dev) +{ +rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_free_device (&dev->device); +} +static void dump_device_list (void ) {
@@ -402,11 +418,8 @@ rte_fslmc_scan(void)closedir (dir);/* Remove all devices in the list */ - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle); -free (dev); - } + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) +fslmc_bus_remove_device (dev); scan_fail:DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */
drivers/bus/fslmc/fslmc_vfio.c +9 -24
@@ -1557,13 +1557,6 @@ fslmc_vfio_close_group(void) } RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -if (dev->device.devargs && - dev->device.devargs->policy ==RTE_DEV_BLOCKED ) { -DPAA2_BUS_LOG (DEBUG ,"%s Blacklisted, skipping" , - dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -continue ; - }switch (dev->dev_type) {case DPAA2_ETH :case DPAA2_CRYPTO :
@@ -1625,8 +1618,7 @@ fslmc_vfio_process_group(void) dev->device.devargs->policy == RTE_DEV_BLOCKED) {DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);continue ; }
@@ -1634,8 +1626,7 @@ fslmc_vfio_process_group(void) !is_dpmcp_in_blocklist) {if (dpmcp_count ==1 || current_device != dpmcp_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);continue ; } }
@@ -1649,9 +1640,7 @@ fslmc_vfio_process_group(void) found_mportal =1 ; } -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -free (dev); - dev =NULL ; +fslmc_bus_remove_device (dev);/* Ideally there is only a single dpmcp, but in case * multiple exists, looping on remaining devices. */
@@ -1675,7 +1664,7 @@ fslmc_vfio_process_group(void)DPAA2_BUS_ERR ("Unable to process dprc" );return ret; } -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev); } }
@@ -1687,7 +1676,7 @@ fslmc_vfio_process_group(void) dev->device.devargs->policy == RTE_DEV_BLOCKED) {DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev);continue ; } if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
@@ -1695,7 +1684,7 @@ fslmc_vfio_process_group(void) dev->dev_type != DPAA2_CRYPTO && dev->dev_type != DPAA2_QDMA && dev->dev_type != DPAA2_IO) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev);continue ; }switch (dev->dev_type) {
@@ -1737,14 +1726,12 @@ fslmc_vfio_process_group(void)if (!is_dpio_in_blocklist && dpio_count >1 ) {if (rte_eal_process_type () ==RTE_PROC_SECONDARY && current_device != dpio_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);break ; }if (rte_eal_process_type () ==RTE_PROC_PRIMARY && current_device == dpio_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);break ; } }
@@ -1762,9 +1749,7 @@ fslmc_vfio_process_group(void)/* Unknown - ignore */ DPAA2_BUS_DEBUG ("Found unknown device (%s)" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -free (dev); - dev =NULL ; +fslmc_bus_remove_device (dev); } }
drivers/bus/fslmc/private.h +2 -0
@@ -11,4 +11,6 @@extern struct rte_bus rte_fslmc_bus; +void fslmc_bus_remove_device (struct rte_dpaa2_device *dev); +#endif /* BUS_FSLMC_PRIVATE_H */
Signature · 1 line
2.54.0
RFC v2 7/16 bus/fslmc: fix per type device count
In reply to David MarchandWhen blocklisting some device, the per type count was wrong.
---
Changes since RFC v1:
- moved counter decrement to the free helper,
--- drivers/bus/fslmc/fslmc_bus.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +5 -3
@@ -83,6 +83,9 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)if (!inserted)rte_bus_add_device (&rte_fslmc_bus, &newdev->device); + +if (newdev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[newdev->dev_type]++; } static void
@@ -90,6 +93,8 @@ fslmc_free_device(struct rte_device *rte_dev) {struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]--;rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -203,9 +208,6 @@ scan_one_fslmc_device(char *dev_name) dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); -/* Update the device found into the device_count table */ - fslmc_bus_device_count[dev->dev_type]++; -/* Add device in the fslmc device list */ insert_in_device_list (dev);
Signature · 1 line
2.54.0
RFC v2 8/16 bus/fslmc: fix some VFIO device FD and memory leaks
In reply to David MarchandIn case VFIO_DEVICE_GET_INFO fails, the vfio_dev_fd was leaked. In a similar way, failing to add this device FD in the group list would result in leaking the FD.
When uninitialising a device or doing a bus cleanup, the per device VFIO FD and the associated memory used for tracking it were leaked.
--- drivers/bus/fslmc/fslmc_vfio.c | 45 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-)
drivers/bus/fslmc/fslmc_vfio.c +30 -15
@@ -205,13 +205,17 @@ static int fslmc_vfio_clear_group(int vfio_group_fd) {struct fslmc_vfio_group *group; -struct fslmc_vfio_device *dev;int clear =0 ; LIST_FOREACH(group, &s_vfio_container.groups, next) {if (group->fd == vfio_group_fd) { - LIST_FOREACH(dev, &group->vfio_devices, next) +while (!LIST_EMPTY (&group->vfio_devices)) { +struct fslmc_vfio_device *dev =LIST_FIRST (&group->vfio_devices); + +close (dev->fd);LIST_REMOVE (dev, next); +rte_free (dev); + }close (vfio_group_fd);LIST_REMOVE (group, next);
@@ -311,6 +315,8 @@ fslmc_vfio_group_add_dev(int vfio_group_fd,if (group->fd == vfio_group_fd) { dev =rte_zmalloc (NULL ,sizeof (struct fslmc_vfio_device ),0 ); +if (dev ==NULL ) +return -ENOMEM ; dev->fd = dev_fd;rte_strscpy (dev->dev_name, name,sizeof (dev->dev_name));LIST_INSERT_HEAD (&group->vfio_devices, dev, next);
@@ -326,26 +332,25 @@ fslmc_vfio_group_remove_dev(int vfio_group_fd, {struct fslmc_vfio_group *group =NULL ;struct fslmc_vfio_device *dev; -int removed =0 ; LIST_FOREACH(group, &s_vfio_container.groups, next) {if (group->fd == vfio_group_fd)break ; } -if (group) { - LIST_FOREACH(dev, &group->vfio_devices, next) { -if (!strcmp (dev->dev_name, name)) { -LIST_REMOVE (dev, next); - removed =1 ; -break ; - } +if (group ==NULL ) + goto err; + + LIST_FOREACH(dev, &group->vfio_devices, next) { +if (strcmp (dev->dev_name, name) ==0 ) { +close (dev->fd); +LIST_REMOVE (dev, next); +rte_free (dev); +return 0 ; } } -if (removed) -return 0 ; - +err:return -ENODEV ; }
@@ -1240,11 +1245,21 @@ fslmc_vfio_setup_device(const char *dev_addr,if (ret) {DPAA2_BUS_ERR ("%s cannot get device info err(%d)(%s)" , dev_addr, errno,strerror (errno)); +close (*vfio_dev_fd); + *vfio_dev_fd =-1 ;return ret; } -return fslmc_vfio_group_add_dev (vfio_group_fd, *vfio_dev_fd, - dev_addr); + ret =fslmc_vfio_group_add_dev (vfio_group_fd, *vfio_dev_fd, dev_addr); +if (ret) { +DPAA2_BUS_ERR ("%s cannot add device in group err(%d)(%s)" , + dev_addr, ret,strerror (-ret)); +close (*vfio_dev_fd); + *vfio_dev_fd =-1 ; +return ret; + } + +return 0 ; }static intptr_t vfio_map_mcp_obj (const char *mcp_obj)
Signature · 1 line
2.54.0
RFC v2 9/16 bus/fslmc: fix interrupt leak in DPIO cleanup
In reply to David MarchandThe interrupt handle in the DPIO device is separate from the bus device object handle. The cleanup code was leaking this handle.
--- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 + 1 file changed, 1 insertion(+)
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +1 -0
@@ -470,6 +470,7 @@ dpaa2_close_dpio_device(int object_id)rte_free (dpio_dev->dpio); }TAILQ_REMOVE (&dpio_dev_list, dpio_dev, next); +rte_intr_instance_free (dpio_dev->intr_handle);rte_free (dpio_dev); } }
Signature · 1 line
2.54.0
RFC v2 10/16 bus/fslmc: simplify device parsing in scan
In reply to David MarchandRefactor string manipulations and avoid unneeded allocation.
---
Changes since RFC v1:
- declared dev_types as static const,
- restored dev_id parsing for "unknown" devices,
--- drivers/bus/fslmc/fslmc_bus.c | 87 ++++++++++++++++------------------- 1 file changed, 39 insertions(+), 48 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +39 -48
@@ -123,18 +123,47 @@ dump_device_list(void)static int scan_one_fslmc_device (char *dev_name) { -char *dup_dev_name, *t_ptr; +enum rte_dpaa2_dev_type dev_type =DPAA2_UNKNOWN ;struct rte_dpaa2_device *dev =NULL ; +static const struct { +const char *prefix; +enum rte_dpaa2_dev_type type; + } dev_types[] = { + {"dpni." ,DPAA2_ETH }, + {"dpseci." ,DPAA2_CRYPTO }, + {"dpcon." ,DPAA2_CON }, + {"dpbp." ,DPAA2_BPOOL }, + {"dpio." ,DPAA2_IO }, + {"dpci." ,DPAA2_CI }, + {"dpmcp." ,DPAA2_MPORTAL }, + {"dpdmai." ,DPAA2_QDMA }, + {"dpdmux." ,DPAA2_MUX }, + {"dprtc." ,DPAA2_DPRTC }, + {"dprc." ,DPAA2_DPRC }, + }; +char *dev_id;int ret =-1 ; -if (!dev_name) +if (dev_name ==NULL )return ret; -/* Creating a temporary copy to perform cut-parse over string */ - dup_dev_name =strdup (dev_name); -if (!dup_dev_name) { -DPAA2_BUS_ERR ("Unable to allocate device name memory" ); -return -ENOMEM ; +for (unsigned int i =0 ; i <RTE_DIM (dev_types); i++) { +if (strncmp (dev_types[i].prefix, dev_name,strlen (dev_types[i].prefix)) !=0 ) +continue ; + dev_id = dev_name +strlen (dev_types[i].prefix); + dev_type = dev_types[i].type; +break ; + } + +if (dev_type ==DPAA2_UNKNOWN ) { +char *ptr =strchr (dev_name,'.' ); + +if (ptr ==NULL ) { +DPAA2_BUS_ERR ("Invalid device found: (%s)" , dev_name); + ret =0 ; + goto cleanup; + } + dev_id = ptr +1 ; }/* For all other devices, we allocate rte_dpaa2_device.
@@ -145,11 +174,11 @@ scan_one_fslmc_device(char *dev_name) dev =calloc (1 ,sizeof (struct rte_dpaa2_device ));if (!dev) {DPAA2_BUS_ERR ("Unable to allocate device object" ); -free (dup_dev_name);return -ENOMEM ; } dev->device.numa_node =SOCKET_ID_ANY ; + dev->dev_type = dev_type;/* Allocate interrupt instance */ dev->intr_handle =
@@ -160,46 +189,12 @@ scan_one_fslmc_device(char *dev_name) goto cleanup; } -/* Parse the device name and ID */ - t_ptr =strtok (dup_dev_name,"." ); -if (!t_ptr) { -DPAA2_BUS_ERR ("Invalid device found: (%s)" , dup_dev_name); +if (sscanf (dev_id,"%hu" , &dev->object_id) !=1 ) { +DPAA2_BUS_ERR ("Failed to parse object ID" ); ret = -EINVAL ; goto cleanup; } -if (!strncmp ("dpni" , t_ptr,4 )) - dev->dev_type =DPAA2_ETH ; -else if (!strncmp ("dpseci" , t_ptr,6 )) - dev->dev_type =DPAA2_CRYPTO ; -else if (!strncmp ("dpcon" , t_ptr,5 )) - dev->dev_type =DPAA2_CON ; -else if (!strncmp ("dpbp" , t_ptr,4 )) - dev->dev_type =DPAA2_BPOOL ; -else if (!strncmp ("dpio" , t_ptr,4 )) - dev->dev_type =DPAA2_IO ; -else if (!strncmp ("dpci" , t_ptr,4 )) - dev->dev_type =DPAA2_CI ; -else if (!strncmp ("dpmcp" , t_ptr,5 )) - dev->dev_type =DPAA2_MPORTAL ; -else if (!strncmp ("dpdmai" , t_ptr,6 )) - dev->dev_type =DPAA2_QDMA ; -else if (!strncmp ("dpdmux" , t_ptr,6 )) - dev->dev_type =DPAA2_MUX ; -else if (!strncmp ("dprtc" , t_ptr,5 )) - dev->dev_type =DPAA2_DPRTC ; -else if (!strncmp ("dprc" , t_ptr,4 )) - dev->dev_type =DPAA2_DPRC ; -else - dev->dev_type =DPAA2_UNKNOWN ; - - t_ptr =strtok (NULL ,"." ); -if (!t_ptr) { -DPAA2_BUS_ERR ("Skipping invalid device (%s)" , dup_dev_name); - ret =0 ; - goto cleanup; - } -sscanf (t_ptr,"%hu" , &dev->object_id);if (rte_strscpy (dev->name, dev_name,sizeof (dev->name)) <0 ) {DPAA2_BUS_ERR ("Unable to copy device name: %s" ,rte_strerror (rte_errno)); ret = -rte_errno;
@@ -211,12 +206,8 @@ scan_one_fslmc_device(char *dev_name)/* Add device in the fslmc device list */ insert_in_device_list (dev); -/* Don't need the duplicated device filesystem entry anymore */ -free (dup_dev_name); -return 0 ; cleanup: -free (dup_dev_name);if (dev) {rte_intr_instance_free (dev->intr_handle);free (dev);
Signature · 1 line
2.54.0
RFC v2 11/16 bus/fslmc: release resources on scan failure
In reply to David MarchandIn case of a single failure, all mapped memory, VFIO resources and device pointers were left untouched.
When reaching one init failure during scan, unwind what had been done so far.
Note: the mapping helper was ignoring the memory callback registration failure, so it is kept as is.
--- drivers/bus/fslmc/fslmc_bus.c | 38 +++++++++++------------ drivers/bus/fslmc/fslmc_vfio.c | 56 +++++++++++++++++++++++++++++----- drivers/bus/fslmc/fslmc_vfio.h | 1 + 3 files changed, 68 insertions(+), 27 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +19 -19
@@ -341,23 +341,20 @@ rte_fslmc_scan(void)/* Scan the DPRC container object */ ret =scan_one_fslmc_device (group_name); -if (ret !=0 ) { -/* Error in parsing directory - exit gracefully */ - goto scan_fail_cleanup; - } - -while ((entry =readdir (dir)) !=NULL ) { -if (entry->d_name[0 ] =='.' || entry->d_type !=DT_DIR ) -continue ; +if (ret ==0 ) { +while ((entry =readdir (dir)) !=NULL ) { +if (entry->d_name[0 ] =='.' || entry->d_type !=DT_DIR ) +continue ; - ret =scan_one_fslmc_device (entry->d_name); -if (ret !=0 ) { -/* Error in parsing directory - exit gracefully */ - goto scan_fail_cleanup; + ret =scan_one_fslmc_device (entry->d_name); +if (ret !=0 ) +break ; } }closedir (dir); +if (ret !=0 ) + goto scan_fail;DPAA2_BUS_INFO ("FSLMC Bus scan completed" );/* If debugging is enabled, device list is dumped to log output */
@@ -375,13 +372,13 @@ rte_fslmc_scan(void)rte_mbuf_dynfield_register (&dpaa2_seqn_dynfield_desc);if (dpaa2_seqn_dynfield_offset <0 ) {DPAA2_BUS_ERR ("Failed to register mbuf field for dpaa sequence number" ); -return 0 ; + goto scan_fail; } ret =fslmc_vfio_setup_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup VFIO %d" , ret); -return 0 ; + goto scan_fail; }/* Map existing segments as well as, in case of hotpluggable memory,
@@ -392,14 +389,14 @@ rte_fslmc_scan(void)if (ret) {DPAA2_BUS_ERR ("Unable to DMA map existing VAs: (%d)" , ret);DPAA2_BUS_ERR ("FSLMC VFIO Mapping failed" ); -return 0 ; + goto vfio_close_group; } } ret =fslmc_vfio_process_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup devices %d" , ret); -return 0 ; + goto vfio_dma_unmap; } }
@@ -407,13 +404,16 @@ rte_fslmc_scan(void)return 0 ; -scan_fail_cleanup: -closedir (dir); +vfio_dma_unmap: +fslmc_vfio_dmaunmap (); +vfio_close_group: +fslmc_vfio_close_group (); +scan_fail:/* Remove all devices in the list */ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus)fslmc_bus_remove_device (dev); -scan_fail: +DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */ return 0 ;
drivers/bus/fslmc/fslmc_vfio.c +48 -8
76 lines not on this page · raw message
drivers/bus/fslmc/fslmc_vfio.h +1 -0
@@ -60,4 +60,5 @@ int fslmc_vfio_close_group(void);char *fslmc_get_container (void );int fslmc_get_container_group (const char *group_name,int *gropuid);int fslmc_vfio_dmamap (void ); +int fslmc_vfio_dmaunmap (void );#endif /* _FSLMC_VFIO_H_ */
Signature · 1 line
2.54.0
RFC v2 12/16 bus/fslmc: refactor device filtering for multiprocess
In reply to David MarchandRefactor device filtering logic by splitting what was done in fslmc_vfio_process_group().
Separate control devices from other bus devices.
During scan, do not add device to the control list unless needed (wrt secondary process, blocklist ...). Yet, keep a special case for MPORTAL/DPIO objects and filter them in a new fslmc_filter_control_devices() helper.
This helper is also responsible for selecting the right MPORTAL/DPIO objects depending on primary/secondary considerations.
As a consequence, fslmc_vfio_process_group() only handles IO device init without having to care about skipping some device.
Finally, remove now dead code in fslmc_vfio_close_group() since only used devices are left in the control and bus device lists.
---
Changes since RFC v1:
- split DPAA2 devices in two lists, one for EAL and one for the internal devices initialisation. This new list is kept ordered,
- fixed regressions raised by Stephen AI review:
- allowlist issue: internal devices must be exempted from allowlist in some cases, so I simply reproduced the existing custom logic,
- device pruning with only one DPIO device,
- (unused) MPORTAL objects kept in device list,
--- drivers/bus/fslmc/fslmc_bus.c | 202 ++++++++++++++++++++++++++++++-- drivers/bus/fslmc/fslmc_vfio.c | 205 ++++++++------------------------- drivers/bus/fslmc/private.h | 4 + 3 files changed, 250 insertions(+), 161 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +195 -7
@@ -30,6 +30,15 @@struct rte_bus rte_fslmc_bus;static int fslmc_bus_device_count[DPAA2_DEVTYPE_MAX ]; +/* +* Control devices (MPORTAL, IO, CON, CI, BPOOL, MUX, DPRC) are bus infrastructure, +* not regular devices. They are initialized during scan/setup and don't participate +* in normal probe/unplug. Keep them in a separate list to avoid interference with +* generic bus operations. +*/ +struct fslmc_control_device_list fslmc_control_devices = +TAILQ_HEAD_INITIALIZER (fslmc_control_devices); +#define DPAA2_SEQN_DYNFIELD_NAME "dpaa2_seqn_dynfield"RTE_EXPORT_INTERNAL_SYMBOL (dpaa2_seqn_dynfield_offset) int dpaa2_seqn_dynfield_offset = -1;
@@ -106,10 +115,44 @@ fslmc_bus_remove_device(struct rte_dpaa2_device *dev)fslmc_free_device (&dev->device); } +static void +insert_in_control_device_list (struct rte_dpaa2_device *dev) +{ +struct rte_device *rte_dev; +struct rte_device *prev; + + prev =NULL ; + TAILQ_FOREACH(rte_dev, &fslmc_control_devices, next) { +if (compare_dpaa2_devname (dev,RTE_BUS_DEVICE (rte_dev, *dev)) <0 ) +break ; + prev = rte_dev; + } + +if (prev !=NULL ) +TAILQ_INSERT_AFTER (&fslmc_control_devices, prev, &dev->device, next); +else +TAILQ_INSERT_HEAD (&fslmc_control_devices, &dev->device, next); + +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]++; +} + +void +fslmc_remove_control_device (struct rte_dpaa2_device *dev) +{ +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]--; + +TAILQ_REMOVE (&fslmc_control_devices, &dev->device, next); +rte_intr_instance_free (dev->intr_handle); +free (dev); +} +static void dump_device_list (void ) {struct rte_dpaa2_device *dev; +struct rte_device *rte_dev;/* Only if the log level has been set to Debugging, print list */ if (rte_log_can_log (dpaa2_logtype_bus,RTE_LOG_DEBUG )) {
@@ -117,6 +160,11 @@ dump_device_list(void) RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {DPAA2_BUS_LOG (DEBUG ,"\t\t%s" , dev->device.name); } +DPAA2_BUS_LOG (DEBUG ,"List of control devices:" ); + TAILQ_FOREACH(rte_dev, &fslmc_control_devices, next) { + dev = RTE_BUS_DEVICE(rte_dev, struct rte_dpaa2_device); +DPAA2_BUS_LOG (DEBUG ,"\t\t%s" , dev->device.name); + } } }
@@ -166,11 +214,39 @@ scan_one_fslmc_device(char *dev_name) dev_id = ptr +1 ; } -/* For all other devices, we allocate rte_dpaa2_device. -* For those devices where there is no driver, probe would release -* the memory associated with the rte_dpaa2_device after necessary -* initialization. +/* +* DPAA2_MPORTAL and DPAA2_IO types are handled separately, +* see fslmc_filter_control_devices() +* +* Note: Only check for explicit blocklist (RTE_DEV_BLOCKED). +* Control objects (dpbp, dpcon, etc.) are required even in allowlist +* mode as they are initialized by fslmc_vfio_process_group(), not probed. */ +if (dev_type !=DPAA2_MPORTAL && dev_type !=DPAA2_IO ) { +struct rte_devargs *devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); + +if (devargs && devargs->policy ==RTE_DEV_BLOCKED ) { +DPAA2_BUS_DEBUG ("Skipping blocklisted device (%s)" , dev_name); +return 0 ; + } + } + +/* For secondary processes, control objects are not needed */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) { +switch (dev_type) { +case DPAA2_ETH : +case DPAA2_CRYPTO : +case DPAA2_QDMA : +case DPAA2_IO : +case DPAA2_MPORTAL : +case DPAA2_DPRC : +break ; +default : +DPAA2_BUS_DEBUG ("Skipping device in secondary process (%s)" , dev_name); +return 0 ; + } + } + dev =calloc (1 ,sizeof (struct rte_dpaa2_device ));if (!dev) {DPAA2_BUS_ERR ("Unable to allocate device object" );
@@ -203,8 +279,16 @@ scan_one_fslmc_device(char *dev_name) dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); -/* Add device in the fslmc device list */ -insert_in_device_list (dev); +switch (dev_type) { +case DPAA2_ETH : +case DPAA2_CRYPTO : +case DPAA2_QDMA : +insert_in_device_list (dev); +break ; +default : +insert_in_control_device_list (dev); +break ; + }return 0 ; cleanup:
@@ -298,6 +382,97 @@ fslmc_dev_compare(const char *name1, const char *name2)return strncmp (devname1, devname2,sizeof (devname1)); } +static int +fslmc_filter_control_devices (void ) +{ +bool is_dpmcp_in_blocklist = false, is_dpio_in_blocklist = false; +int dpmcp_count =0 , dpio_count =0 ; +struct rte_dpaa2_device *dev; +struct rte_device *rte_dev; +struct rte_device *tmp_dev; + +/* Track MPORTAL/DPIO blocklists */ + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_MPORTAL && dev->dev_type !=DPAA2_IO ) +continue ; +/* Only check for explicit blocklist, not allowlist */ +if (dev->device.devargs && dev->device.devargs->policy ==RTE_DEV_BLOCKED ) { +DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); +if (dev->dev_type ==DPAA2_MPORTAL ) + is_dpmcp_in_blocklist = true; +else if (dev->dev_type ==DPAA2_IO ) + is_dpio_in_blocklist = true; +fslmc_remove_control_device (dev); +continue ; + } +if (dev->dev_type ==DPAA2_MPORTAL ) + dpmcp_count++; +else if (dev->dev_type ==DPAA2_IO ) + dpio_count++; + } + +if (dpmcp_count ==0 ) { +DPAA2_BUS_ERR ("No MC Portal device found" ); +return -ENODEV ; + } + +/* Automatic MPORTAL split: primary keeps first, secondary keeps last */ +if (!is_dpmcp_in_blocklist) { +int current_device =0 ; +int keep_index; + +/* Check MPORTAL availability for secondary */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && dpmcp_count <2 ) { +DPAA2_BUS_ERR ("No MC Portal device found for secondary" ); +return -ENODEV ; + } + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) + keep_index =0 ; +else + keep_index = dpmcp_count -1 ; + + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_MPORTAL ) +continue ; +if (current_device != keep_index) +fslmc_remove_control_device (dev); + + current_device++; +if (current_device == dpmcp_count) +break ; + } + } + +/* Automatic DPIO split: secondary keeps last only, primary removes last */ +if (!is_dpio_in_blocklist && dpio_count >1 ) { +int last_index = dpio_count -1 ; +int current_device =0 ; + + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_IO ) +continue ; + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && + current_device != last_index) { +fslmc_remove_control_device (dev); + }else if (rte_eal_process_type () ==RTE_PROC_PRIMARY && + current_device == last_index) { +fslmc_remove_control_device (dev); + } + + current_device++; +if (current_device == dpio_count) +break ; + } + } + +return 0 ; +} +static int rte_fslmc_scan (void ) {
@@ -361,7 +536,7 @@ rte_fslmc_scan(void)dump_device_list ();/* Bus initialization - only if devices were found */ -if (!TAILQ_EMPTY (&rte_fslmc_bus.device_list)) { +if (!TAILQ_EMPTY (&rte_fslmc_bus.device_list) || !TAILQ_EMPTY (&fslmc_control_devices)) {static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = { .name =DPAA2_SEQN_DYNFIELD_NAME , .size =sizeof (dpaa2_seqn_t),
@@ -393,6 +568,12 @@ rte_fslmc_scan(void) } } + ret =fslmc_filter_control_devices (); +if (ret) { +DPAA2_BUS_ERR ("Unable to filter control devices %d" , ret); + goto vfio_dma_unmap; + } + ret =fslmc_vfio_process_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup devices %d" , ret);
@@ -410,6 +591,13 @@ rte_fslmc_scan(void)fslmc_vfio_close_group (); scan_fail: +while (!TAILQ_EMPTY (&fslmc_control_devices)) { +struct rte_device *rte_dev =TAILQ_FIRST (&fslmc_control_devices); + + dev =RTE_BUS_DEVICE (rte_dev, *dev); +fslmc_remove_control_device (dev); + } +/* Remove all devices in the list */ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus)fslmc_bus_remove_device (dev);
drivers/bus/fslmc/fslmc_vfio.c +51 -154
255 lines not on this page · raw message
drivers/bus/fslmc/private.h +4 -0
@@ -11,6 +11,10 @@extern struct rte_bus rte_fslmc_bus; +RTE_TAILQ_HEAD (fslmc_control_device_list, rte_device); +extern struct fslmc_control_device_list fslmc_control_devices; +void fslmc_bus_remove_device (struct rte_dpaa2_device *dev); +void fslmc_remove_control_device (struct rte_dpaa2_device *dev);#endif /* BUS_FSLMC_PRIVATE_H */
Signature · 1 line
2.54.0
RFC v2 13/16 bus/fslmc: move unplug for some device out of VFIO
In reply to David MarchandMove device unplug out of the code dealing with VFIO, interrupts and IO devices.
---
Changes since RFC v1:
- simplified the loop over devices since only devices for ethdev, dma or crypto are in the bus device list,
--- drivers/bus/fslmc/fslmc_bus.c | 11 ++++++++++- drivers/bus/fslmc/fslmc_vfio.c | 13 ------------- 2 files changed, 10 insertions(+), 14 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +10 -1
@@ -620,10 +620,19 @@ fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev) }static int -rte_fslmc_close(struct rte_bus *bus __rte_unused) +fslmc_bus_unplug_device (struct rte_device *rte_dev); + +static int +rte_fslmc_close (struct rte_bus *bus) { +struct rte_dpaa2_device *dev;int ret =0 ; + RTE_BUS_FOREACH_DEV(dev, bus) { +if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device)) +DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); + } + ret =fslmc_vfio_close_group ();if (ret)DPAA2_BUS_INFO ("Unable to close devices %d" , ret);
drivers/bus/fslmc/fslmc_vfio.c +0 -13
@@ -1449,7 +1449,6 @@ fslmc_close_iodevices(struct rte_dpaa2_device *dev, int vfio_fd) {struct rte_dpaa2_object *object =NULL ; -const struct rte_dpaa2_driver *drv;int ret;switch (dev->dev_type) {
@@ -1465,15 +1464,6 @@ fslmc_close_iodevices(struct rte_dpaa2_device *dev,continue ; }break ; -case DPAA2_ETH : -case DPAA2_CRYPTO : -case DPAA2_QDMA : -if (dev->device.driver !=NULL ) { - drv =RTE_BUS_DRIVER (dev->device.driver, *drv); -if (drv->remove && drv->remove (dev)) -DPAA2_BUS_ERR ("Unable to remove" ); - } -break ;default :break ; }
@@ -1617,9 +1607,6 @@ fslmc_vfio_close_group(void)fslmc_close_iodevices (dev, vfio_group_fd); } - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) -fslmc_close_iodevices (dev, vfio_group_fd); -fslmc_vfio_clear_group (vfio_group_fd);return 0 ;
Signature · 1 line
2.54.0
RFC v2 14/16 bus/fslmc: call VFIO setup for some device from bus layer
In reply to David MarchandMove VFIO setup for ETH, CRYPTO and QDMA devices from fslmc_vfio.c to fslmc_bus.c scan layer.
Also move interrupt setup for ETH devices.
Add fslmc_vfio_dev_setup() (resp. fslmc_vfio_dev_close()) wrapper that handles VFIO device fd acquisition and interrupt setup (resp. device removal), hiding VFIO internals from the bus layer.
Note: before this change, CRYPTO and QDMA devices were getting a VFIO device FD even though nothing seems to be done with it. This is kept as is, the device FD is closed on call to fslmc_vfio_dev_close().
---
Changes since RFC v1:
- added cleanup on failure,
--- drivers/bus/fslmc/fslmc_bus.c | 12 +++++ drivers/bus/fslmc/fslmc_vfio.c | 83 ++++++++++++++++++++++++++-------- drivers/bus/fslmc/fslmc_vfio.h | 5 ++ 3 files changed, 82 insertions(+), 18 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +12 -0
@@ -579,12 +579,23 @@ rte_fslmc_scan(void)DPAA2_BUS_ERR ("Unable to setup devices %d" , ret); goto vfio_dma_unmap; } + + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { + ret =fslmc_vfio_dev_setup (dev); +if (ret) { +DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); + goto vfio_dev_close; + } + } } process_once =1 ;return 0 ; +vfio_dev_close: + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) +fslmc_vfio_dev_close (dev); vfio_dma_unmap:fslmc_vfio_dmaunmap (); vfio_close_group:
@@ -631,6 +642,7 @@ rte_fslmc_close(struct rte_bus *bus) RTE_BUS_FOREACH_DEV(dev, bus) {if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device))DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); +fslmc_vfio_dev_close (dev); } ret =fslmc_vfio_close_group ();
drivers/bus/fslmc/fslmc_vfio.c +65 -18
113 lines not on this page · raw message
drivers/bus/fslmc/fslmc_vfio.h +5 -0
@@ -61,4 +61,9 @@ char *fslmc_get_container(void);int fslmc_get_container_group (const char *group_name,int *gropuid);int fslmc_vfio_dmamap (void );int fslmc_vfio_dmaunmap (void ); + +struct rte_dpaa2_device ; +int fslmc_vfio_dev_setup (struct rte_dpaa2_device *dev); +int fslmc_vfio_dev_close (struct rte_dpaa2_device *dev); +#endif /* _FSLMC_VFIO_H_ */
Signature · 1 line
2.54.0
RFC v2 15/16 bus/fslmc: allocate interrupt during probing
In reply to David MarchandAllocating the interrupt handle is a waste of memory if no device is probed later (like for example, if a allowlist is passed).
Instead, allocate this handle, set eventfds and vfio at the time probe_device is called.
Adjust the unplug_device path accordingly.
--- drivers/bus/fslmc/fslmc_bus.c | 51 +++++++++++++++-------------------- 1 file changed, 22 insertions(+), 29 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +22 -29
@@ -104,7 +104,6 @@ fslmc_free_device(struct rte_device *rte_dev)if (dev->dev_type <DPAA2_DEVTYPE_MAX ) fslmc_bus_device_count[dev->dev_type]--; -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -144,7 +143,6 @@ fslmc_remove_control_device(struct rte_dpaa2_device *dev) fslmc_bus_device_count[dev->dev_type]--;TAILQ_REMOVE (&fslmc_control_devices, &dev->device, next); -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -256,15 +254,6 @@ scan_one_fslmc_device(char *dev_name) dev->device.numa_node =SOCKET_ID_ANY ; dev->dev_type = dev_type; -/* Allocate interrupt instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA2_BUS_ERR ("Failed to allocate intr handle" ); - ret = -ENOMEM ; - goto cleanup; - } -if (sscanf (dev_id,"%hu" , &dev->object_id) !=1 ) {DPAA2_BUS_ERR ("Failed to parse object ID" ); ret = -EINVAL ;
@@ -292,10 +281,7 @@ scan_one_fslmc_device(char *dev_name)return 0 ; cleanup: -if (dev) { -rte_intr_instance_free (dev->intr_handle); -free (dev); - } +free (dev);return ret; }
@@ -579,23 +565,12 @@ rte_fslmc_scan(void)DPAA2_BUS_ERR ("Unable to setup devices %d" , ret); goto vfio_dma_unmap; } - - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { - ret =fslmc_vfio_dev_setup (dev); -if (ret) { -DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); - goto vfio_dev_close; - } - } } process_once =1 ;return 0 ; -vfio_dev_close: - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) -fslmc_vfio_dev_close (dev); vfio_dma_unmap:fslmc_vfio_dmaunmap (); vfio_close_group:
@@ -642,7 +617,6 @@ rte_fslmc_close(struct rte_bus *bus) RTE_BUS_FOREACH_DEV(dev, bus) {if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device))DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); -fslmc_vfio_dev_close (dev); } ret =fslmc_vfio_close_group ();
@@ -718,10 +692,27 @@ fslmc_bus_probe_device(struct rte_driver *driver, struct rte_device *rte_dev)struct rte_dpaa2_driver *drv =RTE_BUS_DRIVER (driver, *drv);int ret =0 ; -/* FIXME: probe_device should allocate intr_handle */ +/* Allocate interrupt instance */ + dev->intr_handle = +rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); +if (dev->intr_handle ==NULL ) { +DPAA2_BUS_ERR ("Failed to allocate intr handle" ); +return -ENOMEM ; + } + + ret =fslmc_vfio_dev_setup (dev); +if (ret) { +DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); + goto release_intr; + } + ret = drv->probe (drv, dev);if (ret !=0 ) {DPAA2_BUS_ERR ("Unable to probe" ); +fslmc_vfio_dev_close (dev); +release_intr: +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; }else {DPAA2_BUS_INFO ("%s Plugged" , dev->device.name); }
@@ -739,7 +730,9 @@ fslmc_bus_unplug_device(struct rte_device *rte_dev)int ret = drv->remove (dev);if (ret !=0 )return ret; -/* FIXME: unplug_device should free intr_handle */ +fslmc_vfio_dev_close (dev); +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ;DPAA2_BUS_INFO ("%s Un-Plugged" , dev->device.name);return 0 ; }
Signature · 1 line
2.54.0
RFC v2 16/16 bus/fslmc: use generic cleanup
In reply to David MarchandNow that the probe and unplug callback behave like other buses, we can call generic cleanup in addition to the special handling for IO devices.
Also cleanup any object left in the control devices list.
---
Changes since RFC v1:
- added a debug log on cleanup failure,
--- drivers/bus/fslmc/fslmc_bus.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +14 -11
@@ -606,23 +606,25 @@ fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev) }static int -fslmc_bus_unplug_device (struct rte_device *rte_dev); - -static int -rte_fslmc_close (struct rte_bus *bus) +fslmc_cleanup (struct rte_bus *bus) { -struct rte_dpaa2_device *dev; -int ret =0 ; +int ret; - RTE_BUS_FOREACH_DEV(dev, bus) { -if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device)) -DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); - } + ret =rte_bus_generic_cleanup (bus); +if (ret) +DPAA2_BUS_INFO ("Unable to cleanup devices %d" , ret); ret =fslmc_vfio_close_group ();if (ret)DPAA2_BUS_INFO ("Unable to close devices %d" , ret); +while (!TAILQ_EMPTY (&fslmc_control_devices)) { +struct rte_device *rte_dev =TAILQ_FIRST (&fslmc_control_devices); +struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); + +fslmc_remove_control_device (dev); + } +return 0 ; }
@@ -743,7 +745,8 @@ fslmc_bus_unplug_device(struct rte_device *rte_dev)struct rte_bus rte_fslmc_bus = { .scan = rte_fslmc_scan, .probe = rte_bus_generic_probe, - .cleanup = rte_fslmc_close, + .free_device = fslmc_free_device, + .cleanup = fslmc_cleanup, .parse = rte_fslmc_parse, .dev_compare = fslmc_dev_compare, .find_device = rte_bus_generic_find_device,
Signature · 1 line
2.54.0
Hello Hemant,
Quoted 12 lines · David Marchand
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
Quoted 8 lines
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
Could I get a round of tests? Or should I just sent a non RFC series?
I see potential conflicts with other series coming from NXP. I think it is worth getting this cleanup in, to limit the number of special cases for those two bus drivers when compared to other buses.
Signature · 1 line
David Marchand
________________________________
From: David Marchand <[email protected]>
Sent: Thursday, September 24, 2026 9:46 AM
To: Hemant Agrawal <[email protected]>
Cc: dev <[email protected]>; Thomas Monjalon <[email protected]>
Subject: Re: [RFC v2 00/16] Device unplug and bus cleanup refactoring for NXP
Hello Hemant,
Quoted 12 lines · David Marchand
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
Quoted 8 lines
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
Could I get a round of tests? Or should I just sent a non RFC series?
I see potential conflicts with other series coming from NXP. I think it is worth getting this cleanup in, to limit the number of special cases for those two bus drivers when compared to other buses.
++ @Prashant Gupta<mailto:[email protected]> Please confirm your test report on this updated series.
--
David Marchand
NXP Confidential
cover Device unplug and bus cleanup refactoring for NXP
In reply to David MarchandHello Hemant,
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
Signature · 45 lines
David Marchand
Changes since RFC v2:
- rebased,
- fixed interrupt closing,
Changes since RFC v1:
- fixed FD leak in bus/dpaa pre existing code,
- fixed device name leak in bus/fslmc pre existing code,
- fixed other leaks found by AI review,
- split DPAA2 devices in two list:
- one list in the bus object for devices for which a driver exists,
- one list local to the fslmc bus code for internal resources that
are initialised out of the EAL / bus framework,
David Marchand (16):
drivers/bus: cleanup device freeing in NXP bus scan
drivers/bus: fix FD leak during scan in NXP drivers
bus/dpaa: allocate interrupt during probing
bus/dpaa: support unplug and use generic cleanup
bus/fslmc: fix device name leak
bus/fslmc: fix memory leaks in scan
bus/fslmc: fix per type device count
bus/fslmc: fix some VFIO device FD and memory leaks
bus/fslmc: fix interrupt leak in DPIO cleanup
bus/fslmc: simplify device parsing in scan
bus/fslmc: release resources on probe failure
bus/fslmc: refactor device filtering for multiprocess
bus/fslmc: move unplug for some device out of VFIO
bus/fslmc: call VFIO setup for some device from bus layer
bus/fslmc: allocate interrupt during probing
bus/fslmc: use generic cleanup
doc/guides/rel_notes/release_26_11.rst | 4 +
drivers/bus/dpaa/dpaa_bus.c | 149 +++++----
drivers/bus/fslmc/bus_fslmc_driver.h | 4 +-
drivers/bus/fslmc/fslmc_bus.c | 404 ++++++++++++++++------
drivers/bus/fslmc/fslmc_vfio.c | 407 +++++++++++------------
drivers/bus/fslmc/fslmc_vfio.h | 6 +
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 +
drivers/bus/fslmc/private.h | 6 +
8 files changed, 592 insertions(+), 389 deletions(-)
--
2.54.0PATCH 1/16 drivers/bus: cleanup device freeing in NXP bus scan
Following the scan/probe refactoring, in the DPAA bus driver scan method, the device list is empty at the time the pthread key object is allocated. This leaves only one location that wants to release the whole device list, so remove the dpaa_clean_device_list() helper.
Remove the same helper in FSLMC bus for consistency.
--- drivers/bus/dpaa/dpaa_bus.c | 15 ++------------- drivers/bus/fslmc/fslmc_bus.c | 22 ++++++---------------- 2 files changed, 8 insertions(+), 29 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +2 -13
@@ -193,8 +193,6 @@ dpaa_sec_available(void)return -1 ; } -static void dpaa_clean_device_list (void ); -static int dpaa_create_device_list (void ) {
@@ -336,21 +334,13 @@ dpaa_create_device_list(void)return 0 ; cleanup: -dpaa_clean_device_list (); -return ret; -} - -static void -dpaa_clean_device_list (void ) -{ -struct rte_dpaa_device *dev =NULL ; - RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {rte_bus_remove_device (&rte_dpaa_bus, &dev->device);rte_intr_instance_free (dev->intr_handle);free (dev); - dev =NULL ; } + +return ret; }RTE_EXPORT_INTERNAL_SYMBOL (rte_dpaa_portal_init)
@@ -699,7 +689,6 @@ rte_dpaa_bus_scan(void) ret =pthread_key_create (&dpaa_portal_key, dpaa_portal_finish);if (ret) {DPAA_BUS_LOG (DEBUG ,"Unable to create pthread key. (%d)" , ret); -dpaa_clean_device_list ();return ret; }
drivers/bus/fslmc/fslmc_bus.c +6 -16
@@ -43,19 +43,6 @@ rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type)return fslmc_bus_device_count[device_type]; } -static void -cleanup_fslmc_device_list (void ) -{ -struct rte_dpaa2_device *dev; - - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle); -free (dev); - dev =NULL ; - } -} -static int compare_dpaa2_devname (struct rte_dpaa2_device *dev1,struct rte_dpaa2_device *dev2)
@@ -305,6 +292,7 @@ fslmc_dev_compare(const char *name1, const char *name2)static int rte_fslmc_scan (void ) { +struct rte_dpaa2_device *dev;int ret;char fslmc_dirpath[PATH_MAX ];DIR *dir;
@@ -314,8 +302,6 @@ rte_fslmc_scan(void)char *group_name;if (process_once) { -struct rte_dpaa2_device *dev; -DPAA2_BUS_DEBUG ("Fslmc bus already scanned. Not rescanning" ); RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { dev->device.devargs = rte_bus_find_devargs(&rte_fslmc_bus,
@@ -383,7 +369,11 @@ rte_fslmc_scan(void)closedir (dir);/* Remove all devices in the list */ -cleanup_fslmc_device_list (); + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { +rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +rte_intr_instance_free (dev->intr_handle); +free (dev); + } scan_fail:DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */
Signature · 1 line
2.54.0
PATCH 2/16 drivers/bus: fix FD leak during scan in NXP drivers
In reply to David MarchandIn theory, if the interrupt handle setup fails, an eventfd gets leaked.
In practice, as long as the interrupt handle is valid, those calls can not fail, but this could get broken in the future so it is better to handle this error branch correctly.
--- drivers/bus/dpaa/dpaa_bus.c | 11 +++++++---- drivers/bus/fslmc/fslmc_vfio.c | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +7 -4
@@ -648,11 +648,14 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)return errno; } -if (rte_intr_fd_set (intr_handle, fd)) -return rte_errno; +if (rte_intr_fd_set (intr_handle, fd) || +rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_EXT )) { +int err = rte_errno; -if (rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_EXT )) -return rte_errno; +close (fd); +rte_intr_fd_set (intr_handle,-1 ); +return err; + }return 0 ; }
drivers/bus/fslmc/fslmc_vfio.c +10 -8
@@ -1382,14 +1382,16 @@ rte_dpaa2_vfio_setup_intr(struct rte_intr_handle *intr_handle,return fd; } -if (rte_intr_fd_set (intr_handle, fd)) -return -rte_errno; - -if (rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_VFIO_MSI )) -return -rte_errno; - -if (rte_intr_dev_fd_set (intr_handle, vfio_dev_fd)) -return -rte_errno; +if (rte_intr_fd_set (intr_handle, fd) || +rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_VFIO_MSI ) || +rte_intr_dev_fd_set (intr_handle, vfio_dev_fd)) { +int error = -rte_errno; + +close (fd); +rte_intr_fd_set (intr_handle,-1 ); +rte_intr_dev_fd_set (intr_handle,-1 ); +return error; + }return 0 ; }
Signature · 1 line
2.54.0
PATCH 3/16 bus/dpaa: allocate interrupt during probing
In reply to David MarchandAllocating the interrupt handle is a waste of memory if no device is probed later (like for example, if a allowlist is passed).
Instead, allocate this handle, set eventfds and vfio at the time probe_device is called.
Adjust the unplug_device path accordingly.
---
---
Changes since RFC v2:
- changed sign of returned error,
- fixed invalid FD in interrupt handle,
Changes since RFC v1:
- restored return code on error in cleanup,
--- drivers/bus/dpaa/dpaa_bus.c | 87 ++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 40 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +47 -40
@@ -215,16 +215,6 @@ dpaa_create_device_list(void) dev->device.numa_node =SOCKET_ID_ANY ; -/* Allocate interrupt handle instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); - ret = -ENOMEM ; -free (dev); - goto cleanup; - } - cfg = &dpaa_netcfg->port_cfg[i]; fman_intf = cfg->fman_if;
@@ -276,16 +266,6 @@ dpaa_create_device_list(void) goto cleanup; } -/* Allocate interrupt handle instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); - ret = -ENOMEM ; -free (dev); - goto cleanup; - } - dev->device_type =FSL_DPAA_CRYPTO ; dev->id.dev_id = dpaa_bus.device_count + i;
@@ -336,7 +316,6 @@ dpaa_create_device_list(void) cleanup: RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {rte_bus_remove_device (&rte_dpaa_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -637,7 +616,8 @@ rte_dpaa_bus_dev_build(void)return 0 ; } -static int rte_dpaa_setup_intr (struct rte_intr_handle *intr_handle) +static int +dpaa_setup_intr (struct rte_intr_handle *intr_handle) {int fd;
@@ -645,12 +625,12 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)if (fd <0 ) {DPAA_BUS_ERR ("Cannot set up eventfd, error %i (%s)" , errno,strerror (errno)); -return errno; +return -errno; }if (rte_intr_fd_set (intr_handle, fd) ||rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_EXT )) { -int err = rte_errno; +int err = -rte_errno;close (fd);rte_intr_fd_set (intr_handle,-1 );
@@ -660,13 +640,21 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)return 0 ; } +static void +dpaa_close_intr (struct rte_intr_handle *intr_handle) +{ +if (rte_intr_fd_get (intr_handle) >=0 ) { +close (rte_intr_fd_get (intr_handle)); +rte_intr_fd_set (intr_handle,-1 ); + } +} +#define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa"#define DPAA_DEV_PATH2 "/sys/devices/platform/fsl,dpaa"static int rte_dpaa_bus_scan (void ) { -struct rte_dpaa_device *dev;FILE *svr_file =NULL ;uint32_t svr_ver;static int process_once;
@@ -755,14 +743,6 @@ rte_dpaa_bus_scan(void)*/ rte_mbuf_set_platform_mempool_ops (DPAA_MEMPOOL_OPS_NAME ); - RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) { -if (dev->device_type ==FSL_DPAA_ETH ) { - ret =rte_dpaa_setup_intr (dev->intr_handle); -if (ret) -DPAA_BUS_ERR ("Error setting up interrupt." ); - } - } -/* And initialize the PA->VA translation table */ dpaax_iova_table_populate ();
@@ -790,10 +770,31 @@ dpaa_bus_probe_device(struct rte_driver *drv, struct rte_device *dev)struct rte_dpaa_driver *dpaa_drv =RTE_BUS_DRIVER (drv, *dpaa_drv);int ret; +/* Allocate interrupt handle instance */ + dpaa_dev->intr_handle =rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); +if (dpaa_dev->intr_handle ==NULL ) { +DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); +return -ENOMEM ; + } + +if (dpaa_dev->device_type ==FSL_DPAA_ETH ) { + ret =dpaa_setup_intr (dpaa_dev->intr_handle); +if (ret !=0 ) { +DPAA_BUS_ERR ("error setting up interrupt: %s" , dpaa_dev->name); + goto release_intr; + } + }else { +rte_intr_fd_set (dpaa_dev->intr_handle,-1 ); + } + ret = dpaa_drv->probe (dpaa_drv, dpaa_dev); -if (ret !=0 ) +if (ret !=0 ) {DPAA_BUS_ERR ("unable to probe: %s" , dpaa_dev->name); - +dpaa_close_intr (dpaa_dev->intr_handle); +release_intr: +rte_intr_instance_free (dpaa_dev->intr_handle); + dpaa_dev->intr_handle =NULL ; + }return ret; }
@@ -801,29 +802,35 @@ static int dpaa_bus_cleanup(struct rte_bus *bus) {struct rte_dpaa_device *dev; +int error =0 ;BUS_INIT_FUNC_TRACE (); RTE_BUS_FOREACH_DEV(dev, bus) {const struct rte_dpaa_driver *drv; -int ret =0 ; +int ret;if (!rte_dev_is_probed (&dev->device)) -continue ; + goto next; drv =RTE_BUS_DRIVER (dev->device.driver, *drv);if (drv->remove ==NULL ) -continue ; + goto next; ret = drv->remove (dev);if (ret <0 ) { rte_errno = errno; -return -1 ; + error =-1 ; + goto next; } dev->device.driver =NULL ; +next: +dpaa_close_intr (dev->intr_handle); +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; }dpaa_portal_finish ((void *)DPAA_PER_LCORE_PORTAL ); dpaa_bus_global_init =0 ;DPAA_BUS_DEBUG ("Bus cleanup done" ); -return 0 ; +return error; }/* Adding destructor for double check in case non-gracefully
Signature · 1 line
2.54.0
PATCH 4/16 bus/dpaa: support unplug and use generic cleanup
In reply to David MarchandAdd .unplug callback to handle driver removal and interrupt cleanup. This enables use of the generic bus cleanup helper while preserving bus-specific cleanup (portal finish, global init reset).
The cleanup function was already performing these operations, so it seems safe to expose them through the unplug operation.
--- doc/guides/rel_notes/release_26_11.rst | 4 ++ drivers/bus/dpaa/dpaa_bus.c | 56 +++++++++++++++----------- 2 files changed, 37 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -73,6 +73,10 @@ New Features Added the experimental ``rte_cpu_socket_id()`` function to map an OS logical CPU ID to the NUMA socket containing that CPU. +* **Added unplug operation support to DPAA bus.** + + Implemented device unplug operation to allow runtime removal of DPAA devices. + * **Added TPID support to VLAN tag insertion.** Added ``rte_vlan_insert_tpid()`` to the net library.
drivers/bus/dpaa/dpaa_bus.c +33 -23
85 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH 5/16 bus/fslmc: fix device name leak
In reply to David MarchandThe device name allocated during scan was never freed. Store it to the (unused) name field in the rte_dpaa2_device.
This simplifies the device freeing to a simple free() call later.
--- drivers/bus/fslmc/bus_fslmc_driver.h | 4 +--- drivers/bus/fslmc/fslmc_bus.c | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/bus/fslmc/bus_fslmc_driver.h +1 -3
@@ -39,8 +39,6 @@ extern "C" {struct vfio_device_info ; -#define FSLMC_OBJECT_MAX_LEN 32/**< Length of each device on bus */ -#define DPAA2_INVALID_MBUF_SEQN 0typedef uint32_t dpaa2_seqn_t ;
@@ -101,7 +99,7 @@ struct rte_dpaa2_device {uint16_t ep_object_id;/**< Endpoint DPAA2 Object ID */ char ep_name[RTE_DEV_NAME_MAX_LEN ];struct rte_intr_handle *intr_handle;/**< Interrupt handle */ -char name[FSLMC_OBJECT_MAX_LEN ];/**< DPAA2 Object name*/ +char name[RTE_DEV_NAME_MAX_LEN ]; }; typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
drivers/bus/fslmc/fslmc_bus.c +4 -4
@@ -179,12 +179,12 @@ scan_one_fslmc_device(char *dev_name) }sscanf (t_ptr,"%hu" , &dev->object_id); - dev->device.name =strdup (dev_name); -if (!dev->device.name) { -DPAA2_BUS_ERR ("Unable to clone device name. Out of memory" ); - ret = -ENOMEM ; +if (rte_strscpy (dev->name, dev_name,sizeof (dev->name)) <0 ) { +DPAA2_BUS_ERR ("Unable to copy device name: %s" ,rte_strerror (rte_errno)); + ret = -rte_errno; goto cleanup; } + dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name);/* Update the device found into the device_count table */
Signature · 1 line
2.54.0
PATCH 6/16 bus/fslmc: fix memory leaks in scan
In reply to David MarchandDuring the scan phase (more precisely, during device filtering), device pointers were leaked.
Add a simple helper so a device pointer is fully freed.
As a consequence of the filtering during scan, all blocklisted devices are freed from the bus list during scan: there is no need for reevaluating if a device is blocklisted during cleanup.
---
Changes since RFC v1:
- fixed interrupt handle leak by adding fslmc_free_device helper sooner in the series,
--- drivers/bus/fslmc/fslmc_bus.c | 23 ++++++++++++++++++----- drivers/bus/fslmc/fslmc_vfio.c | 33 +++++++++------------------------ drivers/bus/fslmc/private.h | 2 ++ 3 files changed, 29 insertions(+), 29 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +18 -5
@@ -85,6 +85,22 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)rte_bus_add_device (&rte_fslmc_bus, &newdev->device); } +static void +fslmc_free_device (struct rte_device *rte_dev) +{ +struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); + +rte_intr_instance_free (dev->intr_handle); +free (dev); +} + +void +fslmc_bus_remove_device (struct rte_dpaa2_device *dev) +{ +rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_free_device (&dev->device); +} +static void dump_device_list (void ) {
@@ -369,11 +385,8 @@ rte_fslmc_scan(void)closedir (dir);/* Remove all devices in the list */ - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle); -free (dev); - } + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) +fslmc_bus_remove_device (dev); scan_fail:DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */
drivers/bus/fslmc/fslmc_vfio.c +9 -24
@@ -1568,13 +1568,6 @@ fslmc_vfio_close_group(void) } RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -if (dev->device.devargs && - dev->device.devargs->policy ==RTE_DEV_BLOCKED ) { -DPAA2_BUS_LOG (DEBUG ,"%s Blacklisted, skipping" , - dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -continue ; - }switch (dev->dev_type) {case DPAA2_ETH :case DPAA2_CRYPTO :
@@ -1636,8 +1629,7 @@ fslmc_vfio_process_group(void) dev->device.devargs->policy == RTE_DEV_BLOCKED) {DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);continue ; }
@@ -1645,8 +1637,7 @@ fslmc_vfio_process_group(void) !is_dpmcp_in_blocklist) {if (dpmcp_count ==1 || current_device != dpmcp_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);continue ; } }
@@ -1660,9 +1651,7 @@ fslmc_vfio_process_group(void) found_mportal =1 ; } -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -free (dev); - dev =NULL ; +fslmc_bus_remove_device (dev);/* Ideally there is only a single dpmcp, but in case * multiple exists, looping on remaining devices. */
@@ -1686,7 +1675,7 @@ fslmc_vfio_process_group(void)DPAA2_BUS_ERR ("Unable to process dprc" );return ret; } -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev); } }
@@ -1698,7 +1687,7 @@ fslmc_vfio_process_group(void) dev->device.devargs->policy == RTE_DEV_BLOCKED) {DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev);continue ; } if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
@@ -1706,7 +1695,7 @@ fslmc_vfio_process_group(void) dev->dev_type != DPAA2_CRYPTO && dev->dev_type != DPAA2_QDMA && dev->dev_type != DPAA2_IO) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev);continue ; }switch (dev->dev_type) {
@@ -1748,14 +1737,12 @@ fslmc_vfio_process_group(void)if (!is_dpio_in_blocklist && dpio_count >1 ) {if (rte_eal_process_type () ==RTE_PROC_SECONDARY && current_device != dpio_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);break ; }if (rte_eal_process_type () ==RTE_PROC_PRIMARY && current_device == dpio_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);break ; } }
@@ -1773,9 +1760,7 @@ fslmc_vfio_process_group(void)/* Unknown - ignore */ DPAA2_BUS_DEBUG ("Found unknown device (%s)" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -free (dev); - dev =NULL ; +fslmc_bus_remove_device (dev); } }
drivers/bus/fslmc/private.h +2 -0
@@ -11,4 +11,6 @@extern struct rte_bus rte_fslmc_bus; +void fslmc_bus_remove_device (struct rte_dpaa2_device *dev); +#endif /* BUS_FSLMC_PRIVATE_H */
Signature · 1 line
2.54.0
PATCH 7/16 bus/fslmc: fix per type device count
In reply to David MarchandWhen blocklisting some device, the per type count was wrong.
---
Changes since RFC v1:
- moved counter decrement to the free helper,
--- drivers/bus/fslmc/fslmc_bus.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +5 -3
@@ -83,6 +83,9 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)if (!inserted)rte_bus_add_device (&rte_fslmc_bus, &newdev->device); + +if (newdev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[newdev->dev_type]++; } static void
@@ -90,6 +93,8 @@ fslmc_free_device(struct rte_device *rte_dev) {struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]--;rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -203,9 +208,6 @@ scan_one_fslmc_device(char *dev_name) dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); -/* Update the device found into the device_count table */ - fslmc_bus_device_count[dev->dev_type]++; -/* Add device in the fslmc device list */ insert_in_device_list (dev);
Signature · 1 line
2.54.0
PATCH 8/16 bus/fslmc: fix some VFIO device FD and memory leaks
In reply to David MarchandIn case VFIO_DEVICE_GET_INFO fails, the vfio_dev_fd was leaked. In a similar way, failing to add this device FD in the group list would result in leaking the FD.
When uninitialising a device or doing a bus cleanup, the per device VFIO FD and the associated memory used for tracking it were leaked.
--- drivers/bus/fslmc/fslmc_vfio.c | 45 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-)
drivers/bus/fslmc/fslmc_vfio.c +30 -15
@@ -217,13 +217,17 @@ static int fslmc_vfio_clear_group(int vfio_group_fd) {struct fslmc_vfio_group *group; -struct fslmc_vfio_device *dev;int clear =0 ; LIST_FOREACH(group, &s_vfio_container.groups, next) {if (group->fd == vfio_group_fd) { - LIST_FOREACH(dev, &group->vfio_devices, next) +while (!LIST_EMPTY (&group->vfio_devices)) { +struct fslmc_vfio_device *dev =LIST_FIRST (&group->vfio_devices); + +close (dev->fd);LIST_REMOVE (dev, next); +rte_free (dev); + }close (vfio_group_fd);LIST_REMOVE (group, next);
@@ -323,6 +327,8 @@ fslmc_vfio_group_add_dev(int vfio_group_fd,if (group->fd == vfio_group_fd) { dev =rte_zmalloc (NULL ,sizeof (struct fslmc_vfio_device ),0 ); +if (dev ==NULL ) +return -ENOMEM ; dev->fd = dev_fd;rte_strscpy (dev->dev_name, name,sizeof (dev->dev_name));LIST_INSERT_HEAD (&group->vfio_devices, dev, next);
@@ -338,26 +344,25 @@ fslmc_vfio_group_remove_dev(int vfio_group_fd, {struct fslmc_vfio_group *group =NULL ;struct fslmc_vfio_device *dev; -int removed =0 ; LIST_FOREACH(group, &s_vfio_container.groups, next) {if (group->fd == vfio_group_fd)break ; } -if (group) { - LIST_FOREACH(dev, &group->vfio_devices, next) { -if (!strcmp (dev->dev_name, name)) { -LIST_REMOVE (dev, next); - removed =1 ; -break ; - } +if (group ==NULL ) + goto err; + + LIST_FOREACH(dev, &group->vfio_devices, next) { +if (strcmp (dev->dev_name, name) ==0 ) { +close (dev->fd); +LIST_REMOVE (dev, next); +rte_free (dev); +return 0 ; } } -if (removed) -return 0 ; - +err:return -ENODEV ; }
@@ -1251,11 +1256,21 @@ fslmc_vfio_setup_device(const char *dev_addr,if (ret) {DPAA2_BUS_ERR ("%s cannot get device info err(%d)(%s)" , dev_addr, errno,strerror (errno)); +close (*vfio_dev_fd); + *vfio_dev_fd =-1 ;return ret; } -return fslmc_vfio_group_add_dev (vfio_group_fd, *vfio_dev_fd, - dev_addr); + ret =fslmc_vfio_group_add_dev (vfio_group_fd, *vfio_dev_fd, dev_addr); +if (ret) { +DPAA2_BUS_ERR ("%s cannot add device in group err(%d)(%s)" , + dev_addr, ret,strerror (-ret)); +close (*vfio_dev_fd); + *vfio_dev_fd =-1 ; +return ret; + } + +return 0 ; }static intptr_t vfio_map_mcp_obj (const char *mcp_obj)
Signature · 1 line
2.54.0
PATCH 9/16 bus/fslmc: fix interrupt leak in DPIO cleanup
In reply to David MarchandThe interrupt handle in the DPIO device is separate from the bus device object handle. The cleanup code was leaking this handle.
--- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 + 1 file changed, 1 insertion(+)
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +1 -0
@@ -476,6 +476,7 @@ dpaa2_close_dpio_device(int object_id)rte_free (dpio_dev->dpio); }TAILQ_REMOVE (&dpio_dev_list, dpio_dev, next); +rte_intr_instance_free (dpio_dev->intr_handle);rte_free (dpio_dev); } }
Signature · 1 line
2.54.0
PATCH 10/16 bus/fslmc: simplify device parsing in scan
In reply to David MarchandRefactor string manipulations and avoid unneeded allocation.
---
Changes since RFC v1:
- declared dev_types as static const,
- restored dev_id parsing for "unknown" devices,
--- drivers/bus/fslmc/fslmc_bus.c | 87 ++++++++++++++++------------------- 1 file changed, 39 insertions(+), 48 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +39 -48
@@ -123,18 +123,47 @@ dump_device_list(void)static int scan_one_fslmc_device (char *dev_name) { -char *dup_dev_name, *t_ptr; +enum rte_dpaa2_dev_type dev_type =DPAA2_UNKNOWN ;struct rte_dpaa2_device *dev =NULL ; +static const struct { +const char *prefix; +enum rte_dpaa2_dev_type type; + } dev_types[] = { + {"dpni." ,DPAA2_ETH }, + {"dpseci." ,DPAA2_CRYPTO }, + {"dpcon." ,DPAA2_CON }, + {"dpbp." ,DPAA2_BPOOL }, + {"dpio." ,DPAA2_IO }, + {"dpci." ,DPAA2_CI }, + {"dpmcp." ,DPAA2_MPORTAL }, + {"dpdmai." ,DPAA2_QDMA }, + {"dpdmux." ,DPAA2_MUX }, + {"dprtc." ,DPAA2_DPRTC }, + {"dprc." ,DPAA2_DPRC }, + }; +char *dev_id;int ret =-1 ; -if (!dev_name) +if (dev_name ==NULL )return ret; -/* Creating a temporary copy to perform cut-parse over string */ - dup_dev_name =strdup (dev_name); -if (!dup_dev_name) { -DPAA2_BUS_ERR ("Unable to allocate device name memory" ); -return -ENOMEM ; +for (unsigned int i =0 ; i <RTE_DIM (dev_types); i++) { +if (strncmp (dev_types[i].prefix, dev_name,strlen (dev_types[i].prefix)) !=0 ) +continue ; + dev_id = dev_name +strlen (dev_types[i].prefix); + dev_type = dev_types[i].type; +break ; + } + +if (dev_type ==DPAA2_UNKNOWN ) { +char *ptr =strchr (dev_name,'.' ); + +if (ptr ==NULL ) { +DPAA2_BUS_ERR ("Invalid device found: (%s)" , dev_name); + ret =0 ; + goto cleanup; + } + dev_id = ptr +1 ; }/* For all other devices, we allocate rte_dpaa2_device.
@@ -145,11 +174,11 @@ scan_one_fslmc_device(char *dev_name) dev =calloc (1 ,sizeof (struct rte_dpaa2_device ));if (!dev) {DPAA2_BUS_ERR ("Unable to allocate device object" ); -free (dup_dev_name);return -ENOMEM ; } dev->device.numa_node =SOCKET_ID_ANY ; + dev->dev_type = dev_type;/* Allocate interrupt instance */ dev->intr_handle =
@@ -160,46 +189,12 @@ scan_one_fslmc_device(char *dev_name) goto cleanup; } -/* Parse the device name and ID */ - t_ptr =strtok (dup_dev_name,"." ); -if (!t_ptr) { -DPAA2_BUS_ERR ("Invalid device found: (%s)" , dup_dev_name); +if (sscanf (dev_id,"%hu" , &dev->object_id) !=1 ) { +DPAA2_BUS_ERR ("Failed to parse object ID" ); ret = -EINVAL ; goto cleanup; } -if (!strncmp ("dpni" , t_ptr,4 )) - dev->dev_type =DPAA2_ETH ; -else if (!strncmp ("dpseci" , t_ptr,6 )) - dev->dev_type =DPAA2_CRYPTO ; -else if (!strncmp ("dpcon" , t_ptr,5 )) - dev->dev_type =DPAA2_CON ; -else if (!strncmp ("dpbp" , t_ptr,4 )) - dev->dev_type =DPAA2_BPOOL ; -else if (!strncmp ("dpio" , t_ptr,4 )) - dev->dev_type =DPAA2_IO ; -else if (!strncmp ("dpci" , t_ptr,4 )) - dev->dev_type =DPAA2_CI ; -else if (!strncmp ("dpmcp" , t_ptr,5 )) - dev->dev_type =DPAA2_MPORTAL ; -else if (!strncmp ("dpdmai" , t_ptr,6 )) - dev->dev_type =DPAA2_QDMA ; -else if (!strncmp ("dpdmux" , t_ptr,6 )) - dev->dev_type =DPAA2_MUX ; -else if (!strncmp ("dprtc" , t_ptr,5 )) - dev->dev_type =DPAA2_DPRTC ; -else if (!strncmp ("dprc" , t_ptr,4 )) - dev->dev_type =DPAA2_DPRC ; -else - dev->dev_type =DPAA2_UNKNOWN ; - - t_ptr =strtok (NULL ,"." ); -if (!t_ptr) { -DPAA2_BUS_ERR ("Skipping invalid device (%s)" , dup_dev_name); - ret =0 ; - goto cleanup; - } -sscanf (t_ptr,"%hu" , &dev->object_id);if (rte_strscpy (dev->name, dev_name,sizeof (dev->name)) <0 ) {DPAA2_BUS_ERR ("Unable to copy device name: %s" ,rte_strerror (rte_errno)); ret = -rte_errno;
@@ -211,12 +206,8 @@ scan_one_fslmc_device(char *dev_name)/* Add device in the fslmc device list */ insert_in_device_list (dev); -/* Don't need the duplicated device filesystem entry anymore */ -free (dup_dev_name); -return 0 ; cleanup: -free (dup_dev_name);if (dev) {rte_intr_instance_free (dev->intr_handle);free (dev);
Signature · 1 line
2.54.0
PATCH 11/16 bus/fslmc: release resources on probe failure
In reply to David MarchandIn case of a single failure, all mapped memory, VFIO resources and device pointers were left untouched.
When reaching one init failure during probe, unwind what had been done so far.
Note: the mapping helper was ignoring the memory callback registration failure, so it is kept as is.
---
Changes since RFC v2:
- rebased,
--- drivers/bus/fslmc/fslmc_bus.c | 10 ++++-- drivers/bus/fslmc/fslmc_vfio.c | 56 +++++++++++++++++++++++++++++----- drivers/bus/fslmc/fslmc_vfio.h | 1 + 3 files changed, 57 insertions(+), 10 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +8 -2
@@ -423,17 +423,23 @@ rte_fslmc_probe(struct rte_bus *bus)if (ret) {DPAA2_BUS_ERR ("Unable to DMA map existing VAs: (%d)" , ret);DPAA2_BUS_ERR ("FSLMC VFIO Mapping failed" ); -return ret; + goto vfio_close_group; } } ret =fslmc_vfio_process_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup devices %d" , ret); -return ret; + goto vfio_dma_unmap; }return rte_bus_generic_probe (bus); + +vfio_dma_unmap: +fslmc_vfio_dmaunmap (); +vfio_close_group: +fslmc_vfio_close_group (); +return ret; } static bool
drivers/bus/fslmc/fslmc_vfio.c +48 -8
76 lines not on this page · raw message
drivers/bus/fslmc/fslmc_vfio.h +1 -0
@@ -60,4 +60,5 @@ int fslmc_vfio_close_group(void);char *fslmc_get_container (void );int fslmc_get_container_group (const char *group_name,int *gropuid);int fslmc_vfio_dmamap (void ); +int fslmc_vfio_dmaunmap (void );#endif /* _FSLMC_VFIO_H_ */
Signature · 1 line
2.54.0
PATCH 12/16 bus/fslmc: refactor device filtering for multiprocess
In reply to David MarchandRefactor device filtering logic by splitting what was done in fslmc_vfio_process_group().
Separate control devices from other bus devices.
During probe, do not add device to the control list unless needed (wrt secondary process, blocklist ...). Yet, keep a special case for MPORTAL/DPIO objects and filter them in a new fslmc_filter_control_devices() helper.
This helper is also responsible for selecting the right MPORTAL/DPIO objects depending on primary/secondary considerations.
As a consequence, fslmc_vfio_process_group() only handles IO device init without having to care about skipping some device.
Finally, remove now dead code in fslmc_vfio_close_group() since only used devices are left in the control and bus device lists.
---
Changes since RFC v1:
- split DPAA2 devices in two lists, one for EAL and one for the internal devices initialisation. This new list is kept ordered,
- fixed regressions raised by Stephen AI review:
- allowlist issue: internal devices must be exempted from allowlist in some cases, so I simply reproduced the existing custom logic,
- device pruning with only one DPIO device,
- (unused) MPORTAL objects kept in device list,
--- drivers/bus/fslmc/fslmc_bus.c | 203 ++++++++++++++++++++++++++++++-- drivers/bus/fslmc/fslmc_vfio.c | 205 ++++++++------------------------- drivers/bus/fslmc/private.h | 4 + 3 files changed, 250 insertions(+), 162 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +195 -8
@@ -30,6 +30,15 @@struct rte_bus rte_fslmc_bus;static int fslmc_bus_device_count[DPAA2_DEVTYPE_MAX ]; +/* +* Control devices (MPORTAL, IO, CON, CI, BPOOL, MUX, DPRC) are bus infrastructure, +* not regular devices. They are initialized during scan/setup and don't participate +* in normal probe/unplug. Keep them in a separate list to avoid interference with +* generic bus operations. +*/ +struct fslmc_control_device_list fslmc_control_devices = +TAILQ_HEAD_INITIALIZER (fslmc_control_devices); +#define DPAA2_SEQN_DYNFIELD_NAME "dpaa2_seqn_dynfield"RTE_EXPORT_INTERNAL_SYMBOL (dpaa2_seqn_dynfield_offset) int dpaa2_seqn_dynfield_offset = -1;
@@ -106,10 +115,44 @@ fslmc_bus_remove_device(struct rte_dpaa2_device *dev)fslmc_free_device (&dev->device); } +static void +insert_in_control_device_list (struct rte_dpaa2_device *dev) +{ +struct rte_device *rte_dev; +struct rte_device *prev; + + prev =NULL ; + TAILQ_FOREACH(rte_dev, &fslmc_control_devices, next) { +if (compare_dpaa2_devname (dev,RTE_BUS_DEVICE (rte_dev, *dev)) <0 ) +break ; + prev = rte_dev; + } + +if (prev !=NULL ) +TAILQ_INSERT_AFTER (&fslmc_control_devices, prev, &dev->device, next); +else +TAILQ_INSERT_HEAD (&fslmc_control_devices, &dev->device, next); + +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]++; +} + +void +fslmc_remove_control_device (struct rte_dpaa2_device *dev) +{ +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]--; + +TAILQ_REMOVE (&fslmc_control_devices, &dev->device, next); +rte_intr_instance_free (dev->intr_handle); +free (dev); +} +static void dump_device_list (void ) {struct rte_dpaa2_device *dev; +struct rte_device *rte_dev;/* Only if the log level has been set to Debugging, print list */ if (rte_log_can_log (dpaa2_logtype_bus,RTE_LOG_DEBUG )) {
@@ -117,6 +160,11 @@ dump_device_list(void) RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {DPAA2_BUS_LOG (DEBUG ,"\t\t%s" , dev->device.name); } +DPAA2_BUS_LOG (DEBUG ,"List of control devices:" ); + TAILQ_FOREACH(rte_dev, &fslmc_control_devices, next) { + dev = RTE_BUS_DEVICE(rte_dev, struct rte_dpaa2_device); +DPAA2_BUS_LOG (DEBUG ,"\t\t%s" , dev->device.name); + } } }
@@ -166,11 +214,39 @@ scan_one_fslmc_device(char *dev_name) dev_id = ptr +1 ; } -/* For all other devices, we allocate rte_dpaa2_device. -* For those devices where there is no driver, probe would release -* the memory associated with the rte_dpaa2_device after necessary -* initialization. +/* +* DPAA2_MPORTAL and DPAA2_IO types are handled separately, +* see fslmc_filter_control_devices() +* +* Note: Only check for explicit blocklist (RTE_DEV_BLOCKED). +* Control objects (dpbp, dpcon, etc.) are required even in allowlist +* mode as they are initialized by fslmc_vfio_process_group(), not probed. */ +if (dev_type !=DPAA2_MPORTAL && dev_type !=DPAA2_IO ) { +struct rte_devargs *devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); + +if (devargs && devargs->policy ==RTE_DEV_BLOCKED ) { +DPAA2_BUS_DEBUG ("Skipping blocklisted device (%s)" , dev_name); +return 0 ; + } + } + +/* For secondary processes, control objects are not needed */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) { +switch (dev_type) { +case DPAA2_ETH : +case DPAA2_CRYPTO : +case DPAA2_QDMA : +case DPAA2_IO : +case DPAA2_MPORTAL : +case DPAA2_DPRC : +break ; +default : +DPAA2_BUS_DEBUG ("Skipping device in secondary process (%s)" , dev_name); +return 0 ; + } + } + dev =calloc (1 ,sizeof (struct rte_dpaa2_device ));if (!dev) {DPAA2_BUS_ERR ("Unable to allocate device object" );
@@ -203,8 +279,16 @@ scan_one_fslmc_device(char *dev_name) dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); -/* Add device in the fslmc device list */ -insert_in_device_list (dev); +switch (dev_type) { +case DPAA2_ETH : +case DPAA2_CRYPTO : +case DPAA2_QDMA : +insert_in_device_list (dev); +break ; +default : +insert_in_control_device_list (dev); +break ; + }return 0 ; cleanup:
@@ -298,6 +382,97 @@ fslmc_dev_compare(const char *name1, const char *name2)return strncmp (devname1, devname2,sizeof (devname1)); } +static int +fslmc_filter_control_devices (void ) +{ +bool is_dpmcp_in_blocklist = false, is_dpio_in_blocklist = false; +int dpmcp_count =0 , dpio_count =0 ; +struct rte_dpaa2_device *dev; +struct rte_device *rte_dev; +struct rte_device *tmp_dev; + +/* Track MPORTAL/DPIO blocklists */ + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_MPORTAL && dev->dev_type !=DPAA2_IO ) +continue ; +/* Only check for explicit blocklist, not allowlist */ +if (dev->device.devargs && dev->device.devargs->policy ==RTE_DEV_BLOCKED ) { +DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); +if (dev->dev_type ==DPAA2_MPORTAL ) + is_dpmcp_in_blocklist = true; +else if (dev->dev_type ==DPAA2_IO ) + is_dpio_in_blocklist = true; +fslmc_remove_control_device (dev); +continue ; + } +if (dev->dev_type ==DPAA2_MPORTAL ) + dpmcp_count++; +else if (dev->dev_type ==DPAA2_IO ) + dpio_count++; + } + +if (dpmcp_count ==0 ) { +DPAA2_BUS_ERR ("No MC Portal device found" ); +return -ENODEV ; + } + +/* Automatic MPORTAL split: primary keeps first, secondary keeps last */ +if (!is_dpmcp_in_blocklist) { +int current_device =0 ; +int keep_index; + +/* Check MPORTAL availability for secondary */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && dpmcp_count <2 ) { +DPAA2_BUS_ERR ("No MC Portal device found for secondary" ); +return -ENODEV ; + } + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) + keep_index =0 ; +else + keep_index = dpmcp_count -1 ; + + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_MPORTAL ) +continue ; +if (current_device != keep_index) +fslmc_remove_control_device (dev); + + current_device++; +if (current_device == dpmcp_count) +break ; + } + } + +/* Automatic DPIO split: secondary keeps last only, primary removes last */ +if (!is_dpio_in_blocklist && dpio_count >1 ) { +int last_index = dpio_count -1 ; +int current_device =0 ; + + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_IO ) +continue ; + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && + current_device != last_index) { +fslmc_remove_control_device (dev); + }else if (rte_eal_process_type () ==RTE_PROC_PRIMARY && + current_device == last_index) { +fslmc_remove_control_device (dev); + } + + current_device++; +if (current_device == dpio_count) +break ; + } + } + +return 0 ; +} +static int rte_fslmc_scan (void ) {
@@ -377,7 +552,13 @@ rte_fslmc_scan(void) scan_fail_cleanup:closedir (dir); -/* Remove all devices in the list */ +while (!TAILQ_EMPTY (&fslmc_control_devices)) { +struct rte_device *rte_dev =TAILQ_FIRST (&fslmc_control_devices); + + dev =RTE_BUS_DEVICE (rte_dev, *dev); +fslmc_remove_control_device (dev); + } + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus)fslmc_bus_remove_device (dev); scan_fail:
@@ -399,7 +580,7 @@ rte_fslmc_probe(struct rte_bus *bus) };int ret; -if (TAILQ_EMPTY (&rte_fslmc_bus.device_list)) +if (TAILQ_EMPTY (&rte_fslmc_bus.device_list) &&TAILQ_EMPTY (&fslmc_control_devices))return 0 ; dpaa2_seqn_dynfield_offset =
@@ -427,6 +608,12 @@ rte_fslmc_probe(struct rte_bus *bus) } } + ret =fslmc_filter_control_devices (); +if (ret) { +DPAA2_BUS_ERR ("Unable to filter control devices %d" , ret); + goto vfio_dma_unmap; + } + ret =fslmc_vfio_process_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup devices %d" , ret);
drivers/bus/fslmc/fslmc_vfio.c +51 -154
255 lines not on this page · raw message
drivers/bus/fslmc/private.h +4 -0
@@ -11,6 +11,10 @@extern struct rte_bus rte_fslmc_bus; +RTE_TAILQ_HEAD (fslmc_control_device_list, rte_device); +extern struct fslmc_control_device_list fslmc_control_devices; +void fslmc_bus_remove_device (struct rte_dpaa2_device *dev); +void fslmc_remove_control_device (struct rte_dpaa2_device *dev);#endif /* BUS_FSLMC_PRIVATE_H */
Signature · 1 line
2.54.0
PATCH 13/16 bus/fslmc: move unplug for some device out of VFIO
In reply to David MarchandMove device unplug out of the code dealing with VFIO, interrupts and IO devices.
---
Changes since RFC v1:
- simplified the loop over devices since only devices for ethdev, dma or crypto are in the bus device list,
--- drivers/bus/fslmc/fslmc_bus.c | 11 ++++++++++- drivers/bus/fslmc/fslmc_vfio.c | 13 ------------- 2 files changed, 10 insertions(+), 14 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +10 -1
@@ -642,10 +642,19 @@ fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev) }static int -rte_fslmc_close(struct rte_bus *bus __rte_unused) +fslmc_bus_unplug_device (struct rte_device *rte_dev); + +static int +rte_fslmc_close (struct rte_bus *bus) { +struct rte_dpaa2_device *dev;int ret =0 ; + RTE_BUS_FOREACH_DEV(dev, bus) { +if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device)) +DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); + } + ret =fslmc_vfio_close_group ();if (ret)DPAA2_BUS_INFO ("Unable to close devices %d" , ret);
drivers/bus/fslmc/fslmc_vfio.c +0 -13
@@ -1460,7 +1460,6 @@ fslmc_close_iodevices(struct rte_dpaa2_device *dev, int vfio_fd) {struct rte_dpaa2_object *object =NULL ; -const struct rte_dpaa2_driver *drv;int ret;switch (dev->dev_type) {
@@ -1476,15 +1475,6 @@ fslmc_close_iodevices(struct rte_dpaa2_device *dev,continue ; }break ; -case DPAA2_ETH : -case DPAA2_CRYPTO : -case DPAA2_QDMA : -if (dev->device.driver !=NULL ) { - drv =RTE_BUS_DRIVER (dev->device.driver, *drv); -if (drv->remove && drv->remove (dev)) -DPAA2_BUS_ERR ("Unable to remove" ); - } -break ;default :break ; }
@@ -1628,9 +1618,6 @@ fslmc_vfio_close_group(void)fslmc_close_iodevices (dev, vfio_group_fd); } - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) -fslmc_close_iodevices (dev, vfio_group_fd); -fslmc_vfio_clear_group (vfio_group_fd);return 0 ;
Signature · 1 line
2.54.0
PATCH 14/16 bus/fslmc: call VFIO setup for some device from bus layer
In reply to David MarchandMove VFIO setup for ETH, CRYPTO and QDMA devices from fslmc_vfio.c to fslmc_bus.c probe.
Also move interrupt setup for ETH devices.
Add fslmc_vfio_dev_setup() (resp. fslmc_vfio_dev_close()) wrapper that handles VFIO device fd acquisition and interrupt setup (resp. device removal), hiding VFIO internals from the bus layer.
Note: before this change, CRYPTO and QDMA devices were getting a VFIO device FD even though nothing seems to be done with it. This is kept as is, the device FD is closed on call to fslmc_vfio_dev_close().
--- drivers/bus/fslmc/fslmc_bus.c | 13 ++++++ drivers/bus/fslmc/fslmc_vfio.c | 83 ++++++++++++++++++++++++++-------- drivers/bus/fslmc/fslmc_vfio.h | 5 ++ 3 files changed, 83 insertions(+), 18 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +13 -0
@@ -573,6 +573,7 @@ rte_fslmc_scan(void)static int rte_fslmc_probe (struct rte_bus *bus) { +struct rte_dpaa2_device *dev;static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = { .name =DPAA2_SEQN_DYNFIELD_NAME , .size =sizeof (dpaa2_seqn_t),
@@ -620,8 +621,19 @@ rte_fslmc_probe(struct rte_bus *bus) goto vfio_dma_unmap; } + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { + ret =fslmc_vfio_dev_setup (dev); +if (ret) { +DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); + goto vfio_dev_close; + } + } +return rte_bus_generic_probe (bus); +vfio_dev_close: + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) +fslmc_vfio_dev_close (dev); vfio_dma_unmap:fslmc_vfio_dmaunmap (); vfio_close_group:
@@ -653,6 +665,7 @@ rte_fslmc_close(struct rte_bus *bus) RTE_BUS_FOREACH_DEV(dev, bus) {if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device))DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); +fslmc_vfio_dev_close (dev); } ret =fslmc_vfio_close_group ();
drivers/bus/fslmc/fslmc_vfio.c +65 -18
113 lines not on this page · raw message
drivers/bus/fslmc/fslmc_vfio.h +5 -0
@@ -61,4 +61,9 @@ char *fslmc_get_container(void);int fslmc_get_container_group (const char *group_name,int *gropuid);int fslmc_vfio_dmamap (void );int fslmc_vfio_dmaunmap (void ); + +struct rte_dpaa2_device ; +int fslmc_vfio_dev_setup (struct rte_dpaa2_device *dev); +int fslmc_vfio_dev_close (struct rte_dpaa2_device *dev); +#endif /* _FSLMC_VFIO_H_ */
Signature · 1 line
2.54.0
PATCH 15/16 bus/fslmc: allocate interrupt during probing
In reply to David MarchandAllocating the interrupt handle is a waste of memory if no device is probed later (like for example, if a allowlist is passed).
Instead, allocate this handle, set eventfds and vfio at the time probe_device is called.
Adjust the unplug_device path accordingly.
--- drivers/bus/fslmc/fslmc_bus.c | 52 +++++++++++++++-------------------- 1 file changed, 22 insertions(+), 30 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +22 -30
@@ -104,7 +104,6 @@ fslmc_free_device(struct rte_device *rte_dev)if (dev->dev_type <DPAA2_DEVTYPE_MAX ) fslmc_bus_device_count[dev->dev_type]--; -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -144,7 +143,6 @@ fslmc_remove_control_device(struct rte_dpaa2_device *dev) fslmc_bus_device_count[dev->dev_type]--;TAILQ_REMOVE (&fslmc_control_devices, &dev->device, next); -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -256,15 +254,6 @@ scan_one_fslmc_device(char *dev_name) dev->device.numa_node =SOCKET_ID_ANY ; dev->dev_type = dev_type; -/* Allocate interrupt instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA2_BUS_ERR ("Failed to allocate intr handle" ); - ret = -ENOMEM ; - goto cleanup; - } -if (sscanf (dev_id,"%hu" , &dev->object_id) !=1 ) {DPAA2_BUS_ERR ("Failed to parse object ID" ); ret = -EINVAL ;
@@ -292,10 +281,7 @@ scan_one_fslmc_device(char *dev_name)return 0 ; cleanup: -if (dev) { -rte_intr_instance_free (dev->intr_handle); -free (dev); - } +free (dev);return ret; }
@@ -573,7 +559,6 @@ rte_fslmc_scan(void)static int rte_fslmc_probe (struct rte_bus *bus) { -struct rte_dpaa2_device *dev;static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = { .name =DPAA2_SEQN_DYNFIELD_NAME , .size =sizeof (dpaa2_seqn_t),
@@ -621,19 +606,8 @@ rte_fslmc_probe(struct rte_bus *bus) goto vfio_dma_unmap; } - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { - ret =fslmc_vfio_dev_setup (dev); -if (ret) { -DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); - goto vfio_dev_close; - } - } -return rte_bus_generic_probe (bus); -vfio_dev_close: - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) -fslmc_vfio_dev_close (dev); vfio_dma_unmap:fslmc_vfio_dmaunmap (); vfio_close_group:
@@ -665,7 +639,6 @@ rte_fslmc_close(struct rte_bus *bus) RTE_BUS_FOREACH_DEV(dev, bus) {if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device))DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); -fslmc_vfio_dev_close (dev); } ret =fslmc_vfio_close_group ();
@@ -742,10 +715,27 @@ fslmc_bus_probe_device(struct rte_driver *driver, struct rte_device *rte_dev)struct rte_dpaa2_driver *drv =RTE_BUS_DRIVER (driver, *drv);int ret =0 ; -/* FIXME: probe_device should allocate intr_handle */ +/* Allocate interrupt instance */ + dev->intr_handle = +rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); +if (dev->intr_handle ==NULL ) { +DPAA2_BUS_ERR ("Failed to allocate intr handle" ); +return -ENOMEM ; + } + + ret =fslmc_vfio_dev_setup (dev); +if (ret) { +DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); + goto release_intr; + } + ret = drv->probe (drv, dev);if (ret !=0 ) {DPAA2_BUS_ERR ("Unable to probe" ); +fslmc_vfio_dev_close (dev); +release_intr: +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; }else {DPAA2_BUS_INFO ("%s Plugged" , dev->device.name); }
@@ -763,7 +753,9 @@ fslmc_bus_unplug_device(struct rte_device *rte_dev)int ret = drv->remove (dev);if (ret !=0 )return ret; -/* FIXME: unplug_device should free intr_handle */ +fslmc_vfio_dev_close (dev); +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ;DPAA2_BUS_INFO ("%s Un-Plugged" , dev->device.name);return 0 ; }
Signature · 1 line
2.54.0
PATCH 16/16 bus/fslmc: use generic cleanup
In reply to David MarchandNow that the probe and unplug callback behave like other buses, we can call generic cleanup in addition to the special handling for IO devices.
Also cleanup any object left in the control devices list.
--- drivers/bus/fslmc/fslmc_bus.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +14 -11
@@ -628,23 +628,25 @@ fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev) }static int -fslmc_bus_unplug_device (struct rte_device *rte_dev); - -static int -rte_fslmc_close (struct rte_bus *bus) +fslmc_cleanup (struct rte_bus *bus) { -struct rte_dpaa2_device *dev; -int ret =0 ; +int ret; - RTE_BUS_FOREACH_DEV(dev, bus) { -if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device)) -DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); - } + ret =rte_bus_generic_cleanup (bus); +if (ret) +DPAA2_BUS_INFO ("Unable to cleanup devices %d" , ret); ret =fslmc_vfio_close_group ();if (ret)DPAA2_BUS_INFO ("Unable to close devices %d" , ret); +while (!TAILQ_EMPTY (&fslmc_control_devices)) { +struct rte_device *rte_dev =TAILQ_FIRST (&fslmc_control_devices); +struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); + +fslmc_remove_control_device (dev); + } +return 0 ; }
@@ -766,7 +768,8 @@ fslmc_bus_unplug_device(struct rte_device *rte_dev)struct rte_bus rte_fslmc_bus = { .scan = rte_fslmc_scan, .probe = rte_fslmc_probe, - .cleanup = rte_fslmc_close, + .free_device = fslmc_free_device, + .cleanup = fslmc_cleanup, .parse = rte_fslmc_parse, .dev_compare = fslmc_dev_compare, .find_device = rte_bus_generic_find_device,
Signature · 1 line
2.54.0
Hi @Prashant Gupta
Please share your test results
Regards
Hemant
NXP Confidential
Quoted 75 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: 14 October 2026 23:10
To: Hemant Agrawal <[email protected]>; [email protected]
Subject: [PATCH 00/16] Device unplug and bus cleanup refactoring for NXP
Importance: HighHello Hemant,
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
--
David MarchandChanges since RFC v2:
- rebased,
- fixed interrupt closing,Changes since RFC v1:
- fixed FD leak in bus/dpaa pre existing code,
- fixed device name leak in bus/fslmc pre existing code,
- fixed other leaks found by AI review,
- split DPAA2 devices in two list:
- one list in the bus object for devices for which a driver exists,
- one list local to the fslmc bus code for internal resources that are initialised out of the EAL / bus framework,David Marchand (16):
drivers/bus: cleanup device freeing in NXP bus scandrivers/bus: fix FD leak during scan in NXP drivers bus/dpaa: allocate interrupt during probing bus/dpaa: support unplug and use generic cleanup bus/fslmc: fix device name leak
bus/fslmc: fix memory leaks in scan
bus/fslmc: fix per type device count
bus/fslmc: fix some VFIO device FD and memory leaks bus/fslmc: fix interrupt leak in DPIO cleanup bus/fslmc: simplify device parsing in scan bus/fslmc: release resources on probe failure bus/fslmc: refactor device filtering for multiprocess bus/fslmc: move unplug for some device out of VFIO bus/fslmc: call VFIO setup for some device from bus layer bus/fslmc: allocate interrupt during probing bus/fslmc: use generic cleanupdoc/guides/rel_notes/release_26_11.rst | 4 + drivers/bus/dpaa/dpaa_bus.c | 149 +++++---- drivers/bus/fslmc/bus_fslmc_driver.h | 4 +- drivers/bus/fslmc/fslmc_bus.c | 404 ++++++++++++++++------ drivers/bus/fslmc/fslmc_vfio.c | 407 +++++++++++------------ drivers/bus/fslmc/fslmc_vfio.h | 6 + drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 + drivers/bus/fslmc/private.h | 6 + 8 files changed, 592 insertions(+), 389 deletions(-)--
2.54.0
Hi David,
I am not able to apply these patches on next-net-main. Could you please check if rebase is required?
Thanks,
Prashant
NXP Confidential
-----Original Message-----
From: Hemant Agrawal <[email protected]>
Sent: 18 October 2026 16:05
To: David Marchand <[email protected]>; [email protected]; Prashant Gupta <[email protected]>
Subject: RE: [PATCH 00/16] Device unplug and bus cleanup refactoring for NXP
Hi @Prashant Gupta
Please share your test results
Regards
Hemant
NXP Confidential
Quoted 76 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: 14 October 2026 23:10
To: Hemant Agrawal <[email protected]>; [email protected]
Subject: [PATCH 00/16] Device unplug and bus cleanup refactoring for NXP
Importance: HighHello Hemant,
This is a followup to the refactoring started in 26.07.
I took some time with my best AI friend to cleanup DPAA and FSLMC bus drivers.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
I think it is worth testing and fixing, as it will make the two NXP bus drivers similar to other bus drivers (but keep the special IO devices handling internal to the FSLMC bus for example).
--
David MarchandChanges since RFC v2:
- rebased,
- fixed interrupt closing,Changes since RFC v1:
- fixed FD leak in bus/dpaa pre existing code,
- fixed device name leak in bus/fslmc pre existing code,
- fixed other leaks found by AI review,
- split DPAA2 devices in two list:
- one list in the bus object for devices for which a driver exists,
- one list local to the fslmc bus code for internal resources that are initialised out of the EAL / bus framework,David Marchand (16):
drivers/bus: cleanup device freeing in NXP bus scandrivers/bus: fix FD leak during scan in NXP drivers bus/dpaa: allocate interrupt during probing bus/dpaa: support unplug and use generic cleanup bus/fslmc: fix device name leak
bus/fslmc: fix memory leaks in scan
bus/fslmc: fix per type device count
bus/fslmc: fix some VFIO device FD and memory leaks bus/fslmc: fix interrupt leak in DPIO cleanup bus/fslmc: simplify device parsing in scan bus/fslmc: release resources on probe failure bus/fslmc: refactor device filtering for multiprocess bus/fslmc: move unplug for some device out of VFIO bus/fslmc: call VFIO setup for some device from bus layer bus/fslmc: allocate interrupt during probing bus/fslmc: use generic cleanupdoc/guides/rel_notes/release_26_11.rst | 4 + drivers/bus/dpaa/dpaa_bus.c | 149 +++++---- drivers/bus/fslmc/bus_fslmc_driver.h | 4 +- drivers/bus/fslmc/fslmc_bus.c | 404 ++++++++++++++++------ drivers/bus/fslmc/fslmc_vfio.c | 407 +++++++++++------------ drivers/bus/fslmc/fslmc_vfio.h | 6 + drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 1 + drivers/bus/fslmc/private.h | 6 + 8 files changed, 592 insertions(+), 389 deletions(-)--
2.54.0
Hello,
Quoted 3 lines · Prashant Gupta
I am not able to apply these patches on next-net-main. Could you please check if rebase is required?
The only conflict I see with next-net is the macro changes on dpaa_bus.c.
Sending a series based on next-net-main will likely fail in the CI as it will try to apply on main.
(bus drivers updates are supposed to go through main)
I'll respin for the rte_intr_fd_close changes in main, I push a rebased branch in my GH.
Signature · 1 line
David Marchand
Hi David,
I tested the patches on my side. They work correctly, and I don't see any issues during application cleanup or closure. The changes look good from my testing.
Thanks,
Prashant
NXP Confidential
-----Original Message-----
From: David Marchand <[email protected]>
Sent: 26 October 2026 23:41
To: Prashant Gupta <[email protected]>
Cc: Hemant Agrawal <[email protected]>; [email protected]
Subject: [EXT] Re: [PATCH 00/16] Device unplug and bus cleanup refactoring for NXP
Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
Hello,
Quoted 3 lines · Prashant Gupta
I am not able to apply these patches on next-net-main. Could you please check if rebase is required?
The only conflict I see with next-net is the macro changes on dpaa_bus.c.
Sending a series based on next-net-main will likely fail in the CI as it will try to apply on main. (bus drivers updates are supposed to go through main)
I'll respin for the rte_intr_fd_close changes in main, I push a rebased branch in my GH.
--
David Marchand
v2 cover Device unplug and bus cleanup refactoring for NXP
In reply to David MarchandHello Hemant,
This is a followup to the refactoring started in 26.07.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
I did not get much feedback on the series. I'll let CI pass on this new revision and merge it.
Signature · 51 lines
David Marchand
Changes since v1:
- rebased,
- used fd_close API,
- branch rebased against next-net is available here:
https://github.com/david-marchand/dpdk/commits/dpaa_bus_next-net
Changes since RFC v2:
- rebased,
- fixed interrupt closing,
Changes since RFC v1:
- fixed FD leak in bus/dpaa pre existing code,
- fixed device name leak in bus/fslmc pre existing code,
- fixed other leaks found by AI review,
- split DPAA2 devices in two list:
- one list in the bus object for devices for which a driver exists,
- one list local to the fslmc bus code for internal resources that
are initialised out of the EAL / bus framework,
David Marchand (16):
drivers/bus: cleanup device freeing in NXP bus scan
drivers/bus: fix FD leak during scan in NXP drivers
bus/dpaa: allocate interrupt during probing
bus/dpaa: support unplug and use generic cleanup
bus/fslmc: fix device name leak
bus/fslmc: fix memory leaks in scan
bus/fslmc: fix per type device count
bus/fslmc: fix some VFIO device FD and memory leaks
bus/fslmc: fix interrupt leak in DPIO cleanup
bus/fslmc: simplify device parsing in scan
bus/fslmc: release resources on probe failure
bus/fslmc: refactor device filtering for multiprocess
bus/fslmc: move unplug for some device out of VFIO
bus/fslmc: call VFIO setup for some device from bus layer
bus/fslmc: allocate interrupt during probing
bus/fslmc: use generic cleanup
doc/guides/rel_notes/release_26_11.rst | 4 +
drivers/bus/dpaa/dpaa_bus.c | 138 ++++----
drivers/bus/fslmc/bus_fslmc_driver.h | 4 +-
drivers/bus/fslmc/fslmc_bus.c | 410 +++++++++++++++++------
drivers/bus/fslmc/fslmc_vfio.c | 401 ++++++++++------------
drivers/bus/fslmc/fslmc_vfio.h | 6 +
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 10 +
drivers/bus/fslmc/private.h | 6 +
8 files changed, 587 insertions(+), 392 deletions(-)
--
2.54.0PATCH v2 1/16 drivers/bus: cleanup device freeing in NXP bus scan
Following the scan/probe refactoring, in the DPAA bus driver scan method, the device list is empty at the time the pthread key object is allocated. This leaves only one location that wants to release the whole device list, so remove the dpaa_clean_device_list() helper.
Remove the same helper in FSLMC bus for consistency.
--- drivers/bus/dpaa/dpaa_bus.c | 15 ++------------- drivers/bus/fslmc/fslmc_bus.c | 22 ++++++---------------- 2 files changed, 8 insertions(+), 29 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +2 -13
@@ -193,8 +193,6 @@ dpaa_sec_available(void)return -1 ; } -static void dpaa_clean_device_list (void ); -static int dpaa_create_device_list (void ) {
@@ -336,21 +334,13 @@ dpaa_create_device_list(void)return 0 ; cleanup: -dpaa_clean_device_list (); -return ret; -} - -static void -dpaa_clean_device_list (void ) -{ -struct rte_dpaa_device *dev =NULL ; - RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {rte_bus_remove_device (&rte_dpaa_bus, &dev->device);rte_intr_instance_free (dev->intr_handle);free (dev); - dev =NULL ; } + +return ret; }RTE_EXPORT_INTERNAL_SYMBOL (rte_dpaa_portal_init)
@@ -699,7 +689,6 @@ rte_dpaa_bus_scan(void) ret =pthread_key_create (&dpaa_portal_key, dpaa_portal_finish);if (ret) {DPAA_BUS_LOG (DEBUG ,"Unable to create pthread key. (%d)" , ret); -dpaa_clean_device_list ();return ret; }
drivers/bus/fslmc/fslmc_bus.c +6 -16
@@ -43,19 +43,6 @@ rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type)return fslmc_bus_device_count[device_type]; } -static void -cleanup_fslmc_device_list (void ) -{ -struct rte_dpaa2_device *dev; - - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle); -free (dev); - dev =NULL ; - } -} -static int compare_dpaa2_devname (struct rte_dpaa2_device *dev1,struct rte_dpaa2_device *dev2)
@@ -305,6 +292,7 @@ fslmc_dev_compare(const char *name1, const char *name2)static int rte_fslmc_scan (void ) { +struct rte_dpaa2_device *dev;int ret;char fslmc_dirpath[PATH_MAX ];DIR *dir;
@@ -314,8 +302,6 @@ rte_fslmc_scan(void)char *group_name;if (process_once) { -struct rte_dpaa2_device *dev; -DPAA2_BUS_DEBUG ("Fslmc bus already scanned. Not rescanning" ); RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { dev->device.devargs = rte_bus_find_devargs(&rte_fslmc_bus,
@@ -383,7 +369,11 @@ rte_fslmc_scan(void)closedir (dir);/* Remove all devices in the list */ -cleanup_fslmc_device_list (); + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { +rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +rte_intr_instance_free (dev->intr_handle); +free (dev); + } scan_fail:DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */
Signature · 1 line
2.54.0
PATCH v2 2/16 drivers/bus: fix FD leak during scan in NXP drivers
In reply to David MarchandIn theory, if the interrupt handle setup fails, an eventfd gets leaked.
In practice, as long as the interrupt handle is valid, those calls can not fail, but this could get broken in the future so it is better to handle this error branch correctly.
--- drivers/bus/dpaa/dpaa_bus.c | 11 +++++++---- drivers/bus/fslmc/fslmc_vfio.c | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +7 -4
@@ -648,11 +648,14 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)return errno; } -if (rte_intr_fd_set (intr_handle, fd)) -return rte_errno; +if (rte_intr_fd_set (intr_handle, fd) || +rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_EXT )) { +int err = rte_errno; -if (rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_EXT )) -return rte_errno; +close (fd); +rte_intr_fd_set (intr_handle,-1 ); +return err; + }return 0 ; }
drivers/bus/fslmc/fslmc_vfio.c +10 -8
@@ -1382,14 +1382,16 @@ rte_dpaa2_vfio_setup_intr(struct rte_intr_handle *intr_handle,return fd; } -if (rte_intr_fd_set (intr_handle, fd)) -return -rte_errno; - -if (rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_VFIO_MSI )) -return -rte_errno; - -if (rte_intr_dev_fd_set (intr_handle, vfio_dev_fd)) -return -rte_errno; +if (rte_intr_fd_set (intr_handle, fd) || +rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_VFIO_MSI ) || +rte_intr_dev_fd_set (intr_handle, vfio_dev_fd)) { +int error = -rte_errno; + +close (fd); +rte_intr_fd_set (intr_handle,-1 ); +rte_intr_dev_fd_set (intr_handle,-1 ); +return error; + }return 0 ; }
Signature · 1 line
2.54.0
PATCH v2 3/16 bus/dpaa: allocate interrupt during probing
In reply to David MarchandAllocating the interrupt handle is a waste of memory if no device is probed later (like for example, if a allowlist is passed).
Instead, allocate this handle, set eventfds and vfio at the time probe_device is called.
Adjust the unplug_device path accordingly.
---
Changes since v1:
- used rte_intr_fd_close,
Changes since RFC v2:
- changed sign of returned error,
- fixed invalid FD in interrupt handle,
Changes since RFC v1:
- restored return code on error in cleanup,
--- drivers/bus/dpaa/dpaa_bus.c | 76 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 40 deletions(-)
drivers/bus/dpaa/dpaa_bus.c +36 -40
@@ -215,16 +215,6 @@ dpaa_create_device_list(void) dev->device.numa_node =SOCKET_ID_ANY ; -/* Allocate interrupt handle instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); - ret = -ENOMEM ; -free (dev); - goto cleanup; - } - cfg = &dpaa_netcfg->port_cfg[i]; fman_intf = cfg->fman_if;
@@ -276,16 +266,6 @@ dpaa_create_device_list(void) goto cleanup; } -/* Allocate interrupt handle instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); - ret = -ENOMEM ; -free (dev); - goto cleanup; - } - dev->device_type =FSL_DPAA_CRYPTO ; dev->id.dev_id = dpaa_bus.device_count + i;
@@ -336,7 +316,6 @@ dpaa_create_device_list(void) cleanup: RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) {rte_bus_remove_device (&rte_dpaa_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -637,7 +616,8 @@ rte_dpaa_bus_dev_build(void)return 0 ; } -static int rte_dpaa_setup_intr (struct rte_intr_handle *intr_handle) +static int +dpaa_setup_intr (struct rte_intr_handle *intr_handle) {int fd;
@@ -645,12 +625,12 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)if (fd <0 ) {DPAA_BUS_ERR ("Cannot set up eventfd, error %i (%s)" , errno,strerror (errno)); -return errno; +return -errno; }if (rte_intr_fd_set (intr_handle, fd) ||rte_intr_type_set (intr_handle,RTE_INTR_HANDLE_EXT )) { -int err = rte_errno; +int err = -rte_errno;close (fd);rte_intr_fd_set (intr_handle,-1 );
@@ -666,7 +646,6 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)static int rte_dpaa_bus_scan (void ) { -struct rte_dpaa_device *dev;FILE *svr_file =NULL ;uint32_t svr_ver;static int process_once;
@@ -755,14 +734,6 @@ rte_dpaa_bus_scan(void)*/ rte_mbuf_set_platform_mempool_ops (DPAA_MEMPOOL_OPS_NAME ); - RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus) { -if (dev->device_type ==FSL_DPAA_ETH ) { - ret =rte_dpaa_setup_intr (dev->intr_handle); -if (ret) -DPAA_BUS_ERR ("Error setting up interrupt." ); - } - } -/* And initialize the PA->VA translation table */ dpaax_iova_table_populate ();
@@ -790,10 +761,29 @@ dpaa_bus_probe_device(struct rte_driver *drv, struct rte_device *dev)struct rte_dpaa_driver *dpaa_drv =RTE_BUS_DRIVER (drv, *dpaa_drv);int ret; +/* Allocate interrupt handle instance */ + dpaa_dev->intr_handle =rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); +if (dpaa_dev->intr_handle ==NULL ) { +DPAA_BUS_LOG (ERR ,"Failed to allocate intr handle" ); +return -ENOMEM ; + } + +if (dpaa_dev->device_type ==FSL_DPAA_ETH ) { + ret =dpaa_setup_intr (dpaa_dev->intr_handle); +if (ret !=0 ) { +DPAA_BUS_ERR ("error setting up interrupt: %s" , dpaa_dev->name); + goto release_intr; + } + } + ret = dpaa_drv->probe (dpaa_drv, dpaa_dev); -if (ret !=0 ) +if (ret !=0 ) {DPAA_BUS_ERR ("unable to probe: %s" , dpaa_dev->name); - +rte_intr_fd_close (dpaa_dev->intr_handle); +release_intr: +rte_intr_instance_free (dpaa_dev->intr_handle); + dpaa_dev->intr_handle =NULL ; + }return ret; }
@@ -801,29 +791,35 @@ static int dpaa_bus_cleanup(struct rte_bus *bus) {struct rte_dpaa_device *dev; +int error =0 ;BUS_INIT_FUNC_TRACE (); RTE_BUS_FOREACH_DEV(dev, bus) {const struct rte_dpaa_driver *drv; -int ret =0 ; +int ret;if (!rte_dev_is_probed (&dev->device)) -continue ; + goto next; drv =RTE_BUS_DRIVER (dev->device.driver, *drv);if (drv->remove ==NULL ) -continue ; + goto next; ret = drv->remove (dev);if (ret <0 ) { rte_errno = errno; -return -1 ; + error =-1 ; + goto next; } dev->device.driver =NULL ; +next: +rte_intr_fd_close (dev->intr_handle); +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; }dpaa_portal_finish ((void *)DPAA_PER_LCORE_PORTAL ); dpaa_bus_global_init =0 ;DPAA_BUS_DEBUG ("Bus cleanup done" ); -return 0 ; +return error; }/* Adding destructor for double check in case non-gracefully
Signature · 1 line
2.54.0
PATCH v2 4/16 bus/dpaa: support unplug and use generic cleanup
In reply to David MarchandAdd .unplug callback to handle driver removal and interrupt cleanup. This enables use of the generic bus cleanup helper while preserving bus-specific cleanup (portal finish, global init reset).
The cleanup function was already performing these operations, so it seems safe to expose them through the unplug operation.
--- doc/guides/rel_notes/release_26_11.rst | 4 ++ drivers/bus/dpaa/dpaa_bus.c | 56 +++++++++++++++----------- 2 files changed, 37 insertions(+), 23 deletions(-)
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -82,6 +82,10 @@ New Features but objects within each bulk are not ordered as expected by a stack. Furthermore, it is not strictly bounded by its size, but might hold more objects. +* **Added unplug operation support to DPAA bus.** + + Implemented device unplug operation to allow runtime removal of DPAA devices. + * **Added TPID support to VLAN tag insertion.** Added ``rte_vlan_insert_tpid()`` to the net library.
drivers/bus/dpaa/dpaa_bus.c +33 -23
85 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v2 5/16 bus/fslmc: fix device name leak
In reply to David MarchandThe device name allocated during scan was never freed. Store it to the (unused) name field in the rte_dpaa2_device.
This simplifies the device freeing to a simple free() call later.
--- drivers/bus/fslmc/bus_fslmc_driver.h | 4 +--- drivers/bus/fslmc/fslmc_bus.c | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-)
drivers/bus/fslmc/bus_fslmc_driver.h +1 -3
@@ -39,8 +39,6 @@ extern "C" {struct vfio_device_info ; -#define FSLMC_OBJECT_MAX_LEN 32/**< Length of each device on bus */ -#define DPAA2_INVALID_MBUF_SEQN 0typedef uint32_t dpaa2_seqn_t ;
@@ -101,7 +99,7 @@ struct rte_dpaa2_device {uint16_t ep_object_id;/**< Endpoint DPAA2 Object ID */ char ep_name[RTE_DEV_NAME_MAX_LEN ];struct rte_intr_handle *intr_handle;/**< Interrupt handle */ -char name[FSLMC_OBJECT_MAX_LEN ];/**< DPAA2 Object name*/ +char name[RTE_DEV_NAME_MAX_LEN ]; }; typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
drivers/bus/fslmc/fslmc_bus.c +4 -4
@@ -179,12 +179,12 @@ scan_one_fslmc_device(char *dev_name) }sscanf (t_ptr,"%hu" , &dev->object_id); - dev->device.name =strdup (dev_name); -if (!dev->device.name) { -DPAA2_BUS_ERR ("Unable to clone device name. Out of memory" ); - ret = -ENOMEM ; +if (rte_strscpy (dev->name, dev_name,sizeof (dev->name)) <0 ) { +DPAA2_BUS_ERR ("Unable to copy device name: %s" ,rte_strerror (rte_errno)); + ret = -rte_errno; goto cleanup; } + dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name);/* Update the device found into the device_count table */
Signature · 1 line
2.54.0
PATCH v2 6/16 bus/fslmc: fix memory leaks in scan
In reply to David MarchandDuring the scan phase (more precisely, during device filtering), device pointers were leaked.
Add a simple helper so a device pointer is fully freed.
As a consequence of the filtering during scan, all blocklisted devices are freed from the bus list during scan: there is no need for reevaluating if a device is blocklisted during cleanup.
---
Changes since RFC v1:
- fixed interrupt handle leak by adding fslmc_free_device helper sooner in the series,
--- drivers/bus/fslmc/fslmc_bus.c | 23 ++++++++++++++++++----- drivers/bus/fslmc/fslmc_vfio.c | 33 +++++++++------------------------ drivers/bus/fslmc/private.h | 2 ++ 3 files changed, 29 insertions(+), 29 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +18 -5
@@ -85,6 +85,22 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)rte_bus_add_device (&rte_fslmc_bus, &newdev->device); } +static void +fslmc_free_device (struct rte_device *rte_dev) +{ +struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); + +rte_intr_instance_free (dev->intr_handle); +free (dev); +} + +void +fslmc_bus_remove_device (struct rte_dpaa2_device *dev) +{ +rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_free_device (&dev->device); +} +static void dump_device_list (void ) {
@@ -369,11 +385,8 @@ rte_fslmc_scan(void)closedir (dir);/* Remove all devices in the list */ - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -rte_intr_instance_free (dev->intr_handle); -free (dev); - } + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) +fslmc_bus_remove_device (dev); scan_fail:DPAA2_BUS_DEBUG ("FSLMC Bus Not Available. Skipping (%d)" , ret);/* Irrespective of failure, scan only return success */
drivers/bus/fslmc/fslmc_vfio.c +9 -24
@@ -1568,13 +1568,6 @@ fslmc_vfio_close_group(void) } RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { -if (dev->device.devargs && - dev->device.devargs->policy ==RTE_DEV_BLOCKED ) { -DPAA2_BUS_LOG (DEBUG ,"%s Blacklisted, skipping" , - dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -continue ; - }switch (dev->dev_type) {case DPAA2_ETH :case DPAA2_CRYPTO :
@@ -1636,8 +1629,7 @@ fslmc_vfio_process_group(void) dev->device.devargs->policy == RTE_DEV_BLOCKED) {DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);continue ; }
@@ -1645,8 +1637,7 @@ fslmc_vfio_process_group(void) !is_dpmcp_in_blocklist) {if (dpmcp_count ==1 || current_device != dpmcp_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);continue ; } }
@@ -1660,9 +1651,7 @@ fslmc_vfio_process_group(void) found_mportal =1 ; } -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -free (dev); - dev =NULL ; +fslmc_bus_remove_device (dev);/* Ideally there is only a single dpmcp, but in case * multiple exists, looping on remaining devices. */
@@ -1686,7 +1675,7 @@ fslmc_vfio_process_group(void)DPAA2_BUS_ERR ("Unable to process dprc" );return ret; } -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev); } }
@@ -1698,7 +1687,7 @@ fslmc_vfio_process_group(void) dev->device.devargs->policy == RTE_DEV_BLOCKED) {DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev);continue ; } if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
@@ -1706,7 +1695,7 @@ fslmc_vfio_process_group(void) dev->dev_type != DPAA2_CRYPTO && dev->dev_type != DPAA2_QDMA && dev->dev_type != DPAA2_IO) { -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); +fslmc_bus_remove_device (dev);continue ; }switch (dev->dev_type) {
@@ -1748,14 +1737,12 @@ fslmc_vfio_process_group(void)if (!is_dpio_in_blocklist && dpio_count >1 ) {if (rte_eal_process_type () ==RTE_PROC_SECONDARY && current_device != dpio_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);break ; }if (rte_eal_process_type () ==RTE_PROC_PRIMARY && current_device == dpio_count) { -rte_bus_remove_device (&rte_fslmc_bus, - &dev->device); +fslmc_bus_remove_device (dev);break ; } }
@@ -1773,9 +1760,7 @@ fslmc_vfio_process_group(void)/* Unknown - ignore */ DPAA2_BUS_DEBUG ("Found unknown device (%s)" , dev->device.name); -rte_bus_remove_device (&rte_fslmc_bus, &dev->device); -free (dev); - dev =NULL ; +fslmc_bus_remove_device (dev); } }
drivers/bus/fslmc/private.h +2 -0
@@ -11,4 +11,6 @@extern struct rte_bus rte_fslmc_bus; +void fslmc_bus_remove_device (struct rte_dpaa2_device *dev); +#endif /* BUS_FSLMC_PRIVATE_H */
Signature · 1 line
2.54.0
PATCH v2 7/16 bus/fslmc: fix per type device count
In reply to David MarchandWhen blocklisting some device, the per type count was wrong.
---
Changes since RFC v1:
- moved counter decrement to the free helper,
--- drivers/bus/fslmc/fslmc_bus.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +5 -3
@@ -83,6 +83,9 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)if (!inserted)rte_bus_add_device (&rte_fslmc_bus, &newdev->device); + +if (newdev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[newdev->dev_type]++; } static void
@@ -90,6 +93,8 @@ fslmc_free_device(struct rte_device *rte_dev) {struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]--;rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -203,9 +208,6 @@ scan_one_fslmc_device(char *dev_name) dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); -/* Update the device found into the device_count table */ - fslmc_bus_device_count[dev->dev_type]++; -/* Add device in the fslmc device list */ insert_in_device_list (dev);
Signature · 1 line
2.54.0
PATCH v2 8/16 bus/fslmc: fix some VFIO device FD and memory leaks
In reply to David MarchandIn case VFIO_DEVICE_GET_INFO fails, the vfio_dev_fd was leaked. In a similar way, failing to add this device FD in the group list would result in leaking the FD.
When uninitialising a device or doing a bus cleanup, the per device VFIO FD and the associated memory used for tracking it were leaked.
--- drivers/bus/fslmc/fslmc_vfio.c | 45 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-)
drivers/bus/fslmc/fslmc_vfio.c +30 -15
@@ -217,13 +217,17 @@ static int fslmc_vfio_clear_group(int vfio_group_fd) {struct fslmc_vfio_group *group; -struct fslmc_vfio_device *dev;int clear =0 ; LIST_FOREACH(group, &s_vfio_container.groups, next) {if (group->fd == vfio_group_fd) { - LIST_FOREACH(dev, &group->vfio_devices, next) +while (!LIST_EMPTY (&group->vfio_devices)) { +struct fslmc_vfio_device *dev =LIST_FIRST (&group->vfio_devices); + +close (dev->fd);LIST_REMOVE (dev, next); +rte_free (dev); + }close (vfio_group_fd);LIST_REMOVE (group, next);
@@ -323,6 +327,8 @@ fslmc_vfio_group_add_dev(int vfio_group_fd,if (group->fd == vfio_group_fd) { dev =rte_zmalloc (NULL ,sizeof (struct fslmc_vfio_device ),0 ); +if (dev ==NULL ) +return -ENOMEM ; dev->fd = dev_fd;rte_strscpy (dev->dev_name, name,sizeof (dev->dev_name));LIST_INSERT_HEAD (&group->vfio_devices, dev, next);
@@ -338,26 +344,25 @@ fslmc_vfio_group_remove_dev(int vfio_group_fd, {struct fslmc_vfio_group *group =NULL ;struct fslmc_vfio_device *dev; -int removed =0 ; LIST_FOREACH(group, &s_vfio_container.groups, next) {if (group->fd == vfio_group_fd)break ; } -if (group) { - LIST_FOREACH(dev, &group->vfio_devices, next) { -if (!strcmp (dev->dev_name, name)) { -LIST_REMOVE (dev, next); - removed =1 ; -break ; - } +if (group ==NULL ) + goto err; + + LIST_FOREACH(dev, &group->vfio_devices, next) { +if (strcmp (dev->dev_name, name) ==0 ) { +close (dev->fd); +LIST_REMOVE (dev, next); +rte_free (dev); +return 0 ; } } -if (removed) -return 0 ; - +err:return -ENODEV ; }
@@ -1251,11 +1256,21 @@ fslmc_vfio_setup_device(const char *dev_addr,if (ret) {DPAA2_BUS_ERR ("%s cannot get device info err(%d)(%s)" , dev_addr, errno,strerror (errno)); +close (*vfio_dev_fd); + *vfio_dev_fd =-1 ;return ret; } -return fslmc_vfio_group_add_dev (vfio_group_fd, *vfio_dev_fd, - dev_addr); + ret =fslmc_vfio_group_add_dev (vfio_group_fd, *vfio_dev_fd, dev_addr); +if (ret) { +DPAA2_BUS_ERR ("%s cannot add device in group err(%d)(%s)" , + dev_addr, ret,strerror (-ret)); +close (*vfio_dev_fd); + *vfio_dev_fd =-1 ; +return ret; + } + +return 0 ; }static intptr_t vfio_map_mcp_obj (const char *mcp_obj)
Signature · 1 line
2.54.0
PATCH v2 9/16 bus/fslmc: fix interrupt leak in DPIO cleanup
In reply to David MarchandThe interrupt handle in the DPIO device is separate from the bus device object handle. The cleanup code was leaking this handle and the FD it carries.
---
Changes since v1:
- fixed FD leaks,
--- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +10 -0
@@ -476,6 +476,10 @@ dpaa2_close_dpio_device(int object_id)rte_free (dpio_dev->dpio); }TAILQ_REMOVE (&dpio_dev_list, dpio_dev, next); +rte_intr_fd_close (dpio_dev->intr_handle); +/* dev_fd is closed by caller, clear reference here. */ +rte_intr_dev_fd_set (dpio_dev->intr_handle,-1 ); +rte_intr_instance_free (dpio_dev->intr_handle);rte_free (dpio_dev); } }
@@ -668,6 +672,9 @@ dpaa2_create_dpio_device(int vdev_fd,rte_free (dpio_dev->dpio); } +rte_intr_fd_close (dpio_dev->intr_handle); +/* dev_fd is closed by caller, clear reference here. */ +rte_intr_dev_fd_set (dpio_dev->intr_handle,-1 );rte_intr_instance_free (dpio_dev->intr_handle);rte_free (dpio_dev);
@@ -680,6 +687,9 @@ dpaa2_create_dpio_device(int vdev_fd, dpio_dev->token);rte_free (dpio_dev->dpio); } +rte_intr_fd_close (dpio_dev->intr_handle); +/* dev_fd is closed by caller, clear reference here. */ +rte_intr_dev_fd_set (dpio_dev->intr_handle,-1 );rte_intr_instance_free (dpio_dev->intr_handle);rte_free (dpio_dev); }
Signature · 1 line
2.54.0
PATCH v2 10/16 bus/fslmc: simplify device parsing in scan
In reply to David MarchandRefactor string manipulations and avoid unneeded allocation.
---
Changes since RFC v1:
- declared dev_types as static const,
- restored dev_id parsing for "unknown" devices,
--- drivers/bus/fslmc/fslmc_bus.c | 87 ++++++++++++++++------------------- 1 file changed, 39 insertions(+), 48 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +39 -48
@@ -123,18 +123,47 @@ dump_device_list(void)static int scan_one_fslmc_device (char *dev_name) { -char *dup_dev_name, *t_ptr; +enum rte_dpaa2_dev_type dev_type =DPAA2_UNKNOWN ;struct rte_dpaa2_device *dev =NULL ; +static const struct { +const char *prefix; +enum rte_dpaa2_dev_type type; + } dev_types[] = { + {"dpni." ,DPAA2_ETH }, + {"dpseci." ,DPAA2_CRYPTO }, + {"dpcon." ,DPAA2_CON }, + {"dpbp." ,DPAA2_BPOOL }, + {"dpio." ,DPAA2_IO }, + {"dpci." ,DPAA2_CI }, + {"dpmcp." ,DPAA2_MPORTAL }, + {"dpdmai." ,DPAA2_QDMA }, + {"dpdmux." ,DPAA2_MUX }, + {"dprtc." ,DPAA2_DPRTC }, + {"dprc." ,DPAA2_DPRC }, + }; +char *dev_id;int ret =-1 ; -if (!dev_name) +if (dev_name ==NULL )return ret; -/* Creating a temporary copy to perform cut-parse over string */ - dup_dev_name =strdup (dev_name); -if (!dup_dev_name) { -DPAA2_BUS_ERR ("Unable to allocate device name memory" ); -return -ENOMEM ; +for (unsigned int i =0 ; i <RTE_DIM (dev_types); i++) { +if (strncmp (dev_types[i].prefix, dev_name,strlen (dev_types[i].prefix)) !=0 ) +continue ; + dev_id = dev_name +strlen (dev_types[i].prefix); + dev_type = dev_types[i].type; +break ; + } + +if (dev_type ==DPAA2_UNKNOWN ) { +char *ptr =strchr (dev_name,'.' ); + +if (ptr ==NULL ) { +DPAA2_BUS_ERR ("Invalid device found: (%s)" , dev_name); + ret =0 ; + goto cleanup; + } + dev_id = ptr +1 ; }/* For all other devices, we allocate rte_dpaa2_device.
@@ -145,11 +174,11 @@ scan_one_fslmc_device(char *dev_name) dev =calloc (1 ,sizeof (struct rte_dpaa2_device ));if (!dev) {DPAA2_BUS_ERR ("Unable to allocate device object" ); -free (dup_dev_name);return -ENOMEM ; } dev->device.numa_node =SOCKET_ID_ANY ; + dev->dev_type = dev_type;/* Allocate interrupt instance */ dev->intr_handle =
@@ -160,46 +189,12 @@ scan_one_fslmc_device(char *dev_name) goto cleanup; } -/* Parse the device name and ID */ - t_ptr =strtok (dup_dev_name,"." ); -if (!t_ptr) { -DPAA2_BUS_ERR ("Invalid device found: (%s)" , dup_dev_name); +if (sscanf (dev_id,"%hu" , &dev->object_id) !=1 ) { +DPAA2_BUS_ERR ("Failed to parse object ID" ); ret = -EINVAL ; goto cleanup; } -if (!strncmp ("dpni" , t_ptr,4 )) - dev->dev_type =DPAA2_ETH ; -else if (!strncmp ("dpseci" , t_ptr,6 )) - dev->dev_type =DPAA2_CRYPTO ; -else if (!strncmp ("dpcon" , t_ptr,5 )) - dev->dev_type =DPAA2_CON ; -else if (!strncmp ("dpbp" , t_ptr,4 )) - dev->dev_type =DPAA2_BPOOL ; -else if (!strncmp ("dpio" , t_ptr,4 )) - dev->dev_type =DPAA2_IO ; -else if (!strncmp ("dpci" , t_ptr,4 )) - dev->dev_type =DPAA2_CI ; -else if (!strncmp ("dpmcp" , t_ptr,5 )) - dev->dev_type =DPAA2_MPORTAL ; -else if (!strncmp ("dpdmai" , t_ptr,6 )) - dev->dev_type =DPAA2_QDMA ; -else if (!strncmp ("dpdmux" , t_ptr,6 )) - dev->dev_type =DPAA2_MUX ; -else if (!strncmp ("dprtc" , t_ptr,5 )) - dev->dev_type =DPAA2_DPRTC ; -else if (!strncmp ("dprc" , t_ptr,4 )) - dev->dev_type =DPAA2_DPRC ; -else - dev->dev_type =DPAA2_UNKNOWN ; - - t_ptr =strtok (NULL ,"." ); -if (!t_ptr) { -DPAA2_BUS_ERR ("Skipping invalid device (%s)" , dup_dev_name); - ret =0 ; - goto cleanup; - } -sscanf (t_ptr,"%hu" , &dev->object_id);if (rte_strscpy (dev->name, dev_name,sizeof (dev->name)) <0 ) {DPAA2_BUS_ERR ("Unable to copy device name: %s" ,rte_strerror (rte_errno)); ret = -rte_errno;
@@ -211,12 +206,8 @@ scan_one_fslmc_device(char *dev_name)/* Add device in the fslmc device list */ insert_in_device_list (dev); -/* Don't need the duplicated device filesystem entry anymore */ -free (dup_dev_name); -return 0 ; cleanup: -free (dup_dev_name);if (dev) {rte_intr_instance_free (dev->intr_handle);free (dev);
Signature · 1 line
2.54.0
PATCH v2 11/16 bus/fslmc: release resources on probe failure
In reply to David MarchandIn case of a single failure, all mapped memory, VFIO resources and device pointers were left untouched.
When reaching one init failure during probe, unwind what had been done so far.
Note: the mapping helper was ignoring the memory callback registration failure, so it is kept as is.
---
Changes since RFC v2:
- rebased,
--- drivers/bus/fslmc/fslmc_bus.c | 10 ++++-- drivers/bus/fslmc/fslmc_vfio.c | 56 +++++++++++++++++++++++++++++----- drivers/bus/fslmc/fslmc_vfio.h | 1 + 3 files changed, 57 insertions(+), 10 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +8 -2
@@ -423,17 +423,23 @@ rte_fslmc_probe(struct rte_bus *bus)if (ret) {DPAA2_BUS_ERR ("Unable to DMA map existing VAs: (%d)" , ret);DPAA2_BUS_ERR ("FSLMC VFIO Mapping failed" ); -return ret; + goto vfio_close_group; } } ret =fslmc_vfio_process_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup devices %d" , ret); -return ret; + goto vfio_dma_unmap; }return rte_bus_generic_probe (bus); + +vfio_dma_unmap: +fslmc_vfio_dmaunmap (); +vfio_close_group: +fslmc_vfio_close_group (); +return ret; } static bool
drivers/bus/fslmc/fslmc_vfio.c +48 -8
76 lines not on this page · raw message
drivers/bus/fslmc/fslmc_vfio.h +1 -0
@@ -60,4 +60,5 @@ int fslmc_vfio_close_group(void);char *fslmc_get_container (void );int fslmc_get_container_group (const char *group_name,int *gropuid);int fslmc_vfio_dmamap (void ); +int fslmc_vfio_dmaunmap (void );#endif /* _FSLMC_VFIO_H_ */
Signature · 1 line
2.54.0
PATCH v2 12/16 bus/fslmc: refactor device filtering for multiprocess
In reply to David MarchandRefactor device filtering logic by splitting what was done in fslmc_vfio_process_group().
Separate control devices from other bus devices.
During probe, do not add device to the control list unless needed (wrt secondary process, blocklist ...). Yet, keep a special case for MPORTAL/DPIO objects and filter them in a new fslmc_filter_control_devices() helper.
This helper is also responsible for selecting the right MPORTAL/DPIO objects depending on primary/secondary considerations.
As a consequence, fslmc_vfio_process_group() only handles IO device init without having to care about skipping some device.
Finally, remove now dead code in fslmc_vfio_close_group() since only used devices are left in the control and bus device lists.
---
Changes since RFC v1:
- split DPAA2 devices in two lists, one for EAL and one for the internal devices initialisation. This new list is kept ordered,
- fixed regressions raised by Stephen AI review:
- allowlist issue: internal devices must be exempted from allowlist in some cases, so I simply reproduced the existing custom logic,
- device pruning with only one DPIO device,
- (unused) MPORTAL objects kept in device list,
--- drivers/bus/fslmc/fslmc_bus.c | 203 ++++++++++++++++++++++++++++++-- drivers/bus/fslmc/fslmc_vfio.c | 205 ++++++++------------------------- drivers/bus/fslmc/private.h | 4 + 3 files changed, 250 insertions(+), 162 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +195 -8
@@ -30,6 +30,15 @@struct rte_bus rte_fslmc_bus;static int fslmc_bus_device_count[DPAA2_DEVTYPE_MAX ]; +/* +* Control devices (MPORTAL, IO, CON, CI, BPOOL, MUX, DPRC) are bus infrastructure, +* not regular devices. They are initialized during scan/setup and don't participate +* in normal probe/unplug. Keep them in a separate list to avoid interference with +* generic bus operations. +*/ +struct fslmc_control_device_list fslmc_control_devices = +TAILQ_HEAD_INITIALIZER (fslmc_control_devices); +#define DPAA2_SEQN_DYNFIELD_NAME "dpaa2_seqn_dynfield"RTE_EXPORT_INTERNAL_SYMBOL (dpaa2_seqn_dynfield_offset) int dpaa2_seqn_dynfield_offset = -1;
@@ -106,10 +115,44 @@ fslmc_bus_remove_device(struct rte_dpaa2_device *dev)fslmc_free_device (&dev->device); } +static void +insert_in_control_device_list (struct rte_dpaa2_device *dev) +{ +struct rte_device *rte_dev; +struct rte_device *prev; + + prev =NULL ; + TAILQ_FOREACH(rte_dev, &fslmc_control_devices, next) { +if (compare_dpaa2_devname (dev,RTE_BUS_DEVICE (rte_dev, *dev)) <0 ) +break ; + prev = rte_dev; + } + +if (prev !=NULL ) +TAILQ_INSERT_AFTER (&fslmc_control_devices, prev, &dev->device, next); +else +TAILQ_INSERT_HEAD (&fslmc_control_devices, &dev->device, next); + +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]++; +} + +void +fslmc_remove_control_device (struct rte_dpaa2_device *dev) +{ +if (dev->dev_type <DPAA2_DEVTYPE_MAX ) + fslmc_bus_device_count[dev->dev_type]--; + +TAILQ_REMOVE (&fslmc_control_devices, &dev->device, next); +rte_intr_instance_free (dev->intr_handle); +free (dev); +} +static void dump_device_list (void ) {struct rte_dpaa2_device *dev; +struct rte_device *rte_dev;/* Only if the log level has been set to Debugging, print list */ if (rte_log_can_log (dpaa2_logtype_bus,RTE_LOG_DEBUG )) {
@@ -117,6 +160,11 @@ dump_device_list(void) RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) {DPAA2_BUS_LOG (DEBUG ,"\t\t%s" , dev->device.name); } +DPAA2_BUS_LOG (DEBUG ,"List of control devices:" ); + TAILQ_FOREACH(rte_dev, &fslmc_control_devices, next) { + dev = RTE_BUS_DEVICE(rte_dev, struct rte_dpaa2_device); +DPAA2_BUS_LOG (DEBUG ,"\t\t%s" , dev->device.name); + } } }
@@ -166,11 +214,39 @@ scan_one_fslmc_device(char *dev_name) dev_id = ptr +1 ; } -/* For all other devices, we allocate rte_dpaa2_device. -* For those devices where there is no driver, probe would release -* the memory associated with the rte_dpaa2_device after necessary -* initialization. +/* +* DPAA2_MPORTAL and DPAA2_IO types are handled separately, +* see fslmc_filter_control_devices() +* +* Note: Only check for explicit blocklist (RTE_DEV_BLOCKED). +* Control objects (dpbp, dpcon, etc.) are required even in allowlist +* mode as they are initialized by fslmc_vfio_process_group(), not probed. */ +if (dev_type !=DPAA2_MPORTAL && dev_type !=DPAA2_IO ) { +struct rte_devargs *devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); + +if (devargs && devargs->policy ==RTE_DEV_BLOCKED ) { +DPAA2_BUS_DEBUG ("Skipping blocklisted device (%s)" , dev_name); +return 0 ; + } + } + +/* For secondary processes, control objects are not needed */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY ) { +switch (dev_type) { +case DPAA2_ETH : +case DPAA2_CRYPTO : +case DPAA2_QDMA : +case DPAA2_IO : +case DPAA2_MPORTAL : +case DPAA2_DPRC : +break ; +default : +DPAA2_BUS_DEBUG ("Skipping device in secondary process (%s)" , dev_name); +return 0 ; + } + } + dev =calloc (1 ,sizeof (struct rte_dpaa2_device ));if (!dev) {DPAA2_BUS_ERR ("Unable to allocate device object" );
@@ -203,8 +279,16 @@ scan_one_fslmc_device(char *dev_name) dev->device.name = dev->name; dev->device.devargs =rte_bus_find_devargs (&rte_fslmc_bus, dev_name); -/* Add device in the fslmc device list */ -insert_in_device_list (dev); +switch (dev_type) { +case DPAA2_ETH : +case DPAA2_CRYPTO : +case DPAA2_QDMA : +insert_in_device_list (dev); +break ; +default : +insert_in_control_device_list (dev); +break ; + }return 0 ; cleanup:
@@ -298,6 +382,97 @@ fslmc_dev_compare(const char *name1, const char *name2)return strncmp (devname1, devname2,sizeof (devname1)); } +static int +fslmc_filter_control_devices (void ) +{ +bool is_dpmcp_in_blocklist = false, is_dpio_in_blocklist = false; +int dpmcp_count =0 , dpio_count =0 ; +struct rte_dpaa2_device *dev; +struct rte_device *rte_dev; +struct rte_device *tmp_dev; + +/* Track MPORTAL/DPIO blocklists */ + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_MPORTAL && dev->dev_type !=DPAA2_IO ) +continue ; +/* Only check for explicit blocklist, not allowlist */ +if (dev->device.devargs && dev->device.devargs->policy ==RTE_DEV_BLOCKED ) { +DPAA2_BUS_LOG (DEBUG ,"%s Blocked, skipping" , dev->device.name); +if (dev->dev_type ==DPAA2_MPORTAL ) + is_dpmcp_in_blocklist = true; +else if (dev->dev_type ==DPAA2_IO ) + is_dpio_in_blocklist = true; +fslmc_remove_control_device (dev); +continue ; + } +if (dev->dev_type ==DPAA2_MPORTAL ) + dpmcp_count++; +else if (dev->dev_type ==DPAA2_IO ) + dpio_count++; + } + +if (dpmcp_count ==0 ) { +DPAA2_BUS_ERR ("No MC Portal device found" ); +return -ENODEV ; + } + +/* Automatic MPORTAL split: primary keeps first, secondary keeps last */ +if (!is_dpmcp_in_blocklist) { +int current_device =0 ; +int keep_index; + +/* Check MPORTAL availability for secondary */ +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && dpmcp_count <2 ) { +DPAA2_BUS_ERR ("No MC Portal device found for secondary" ); +return -ENODEV ; + } + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) + keep_index =0 ; +else + keep_index = dpmcp_count -1 ; + + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_MPORTAL ) +continue ; +if (current_device != keep_index) +fslmc_remove_control_device (dev); + + current_device++; +if (current_device == dpmcp_count) +break ; + } + } + +/* Automatic DPIO split: secondary keeps last only, primary removes last */ +if (!is_dpio_in_blocklist && dpio_count >1 ) { +int last_index = dpio_count -1 ; +int current_device =0 ; + + RTE_TAILQ_FOREACH_SAFE(rte_dev, &fslmc_control_devices, next, tmp_dev) { + dev =RTE_BUS_DEVICE (rte_dev, *dev); +if (dev->dev_type !=DPAA2_IO ) +continue ; + +if (rte_eal_process_type () ==RTE_PROC_SECONDARY && + current_device != last_index) { +fslmc_remove_control_device (dev); + }else if (rte_eal_process_type () ==RTE_PROC_PRIMARY && + current_device == last_index) { +fslmc_remove_control_device (dev); + } + + current_device++; +if (current_device == dpio_count) +break ; + } + } + +return 0 ; +} +static int rte_fslmc_scan (void ) {
@@ -377,7 +552,13 @@ rte_fslmc_scan(void) scan_fail_cleanup:closedir (dir); -/* Remove all devices in the list */ +while (!TAILQ_EMPTY (&fslmc_control_devices)) { +struct rte_device *rte_dev =TAILQ_FIRST (&fslmc_control_devices); + + dev =RTE_BUS_DEVICE (rte_dev, *dev); +fslmc_remove_control_device (dev); + } + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus)fslmc_bus_remove_device (dev); scan_fail:
@@ -399,7 +580,7 @@ rte_fslmc_probe(struct rte_bus *bus) };int ret; -if (TAILQ_EMPTY (&rte_fslmc_bus.device_list)) +if (TAILQ_EMPTY (&rte_fslmc_bus.device_list) &&TAILQ_EMPTY (&fslmc_control_devices))return 0 ; dpaa2_seqn_dynfield_offset =
@@ -427,6 +608,12 @@ rte_fslmc_probe(struct rte_bus *bus) } } + ret =fslmc_filter_control_devices (); +if (ret) { +DPAA2_BUS_ERR ("Unable to filter control devices %d" , ret); + goto vfio_dma_unmap; + } + ret =fslmc_vfio_process_group ();if (ret) {DPAA2_BUS_ERR ("Unable to setup devices %d" , ret);
drivers/bus/fslmc/fslmc_vfio.c +51 -154
255 lines not on this page · raw message
drivers/bus/fslmc/private.h +4 -0
@@ -11,6 +11,10 @@extern struct rte_bus rte_fslmc_bus; +RTE_TAILQ_HEAD (fslmc_control_device_list, rte_device); +extern struct fslmc_control_device_list fslmc_control_devices; +void fslmc_bus_remove_device (struct rte_dpaa2_device *dev); +void fslmc_remove_control_device (struct rte_dpaa2_device *dev);#endif /* BUS_FSLMC_PRIVATE_H */
Signature · 1 line
2.54.0
PATCH v2 13/16 bus/fslmc: move unplug for some device out of VFIO
In reply to David MarchandMove device unplug out of the code dealing with VFIO, interrupts and IO devices.
---
Changes since RFC v1:
- simplified the loop over devices since only devices for ethdev, dma or crypto are in the bus device list,
--- drivers/bus/fslmc/fslmc_bus.c | 11 ++++++++++- drivers/bus/fslmc/fslmc_vfio.c | 13 ------------- 2 files changed, 10 insertions(+), 14 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +10 -1
@@ -642,10 +642,19 @@ fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev) }static int -rte_fslmc_close(struct rte_bus *bus __rte_unused) +fslmc_bus_unplug_device (struct rte_device *rte_dev); + +static int +rte_fslmc_close (struct rte_bus *bus) { +struct rte_dpaa2_device *dev;int ret =0 ; + RTE_BUS_FOREACH_DEV(dev, bus) { +if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device)) +DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); + } + ret =fslmc_vfio_close_group ();if (ret)DPAA2_BUS_INFO ("Unable to close devices %d" , ret);
drivers/bus/fslmc/fslmc_vfio.c +0 -13
@@ -1460,7 +1460,6 @@ fslmc_close_iodevices(struct rte_dpaa2_device *dev, int vfio_fd) {struct rte_dpaa2_object *object =NULL ; -const struct rte_dpaa2_driver *drv;int ret;switch (dev->dev_type) {
@@ -1476,15 +1475,6 @@ fslmc_close_iodevices(struct rte_dpaa2_device *dev,continue ; }break ; -case DPAA2_ETH : -case DPAA2_CRYPTO : -case DPAA2_QDMA : -if (dev->device.driver !=NULL ) { - drv =RTE_BUS_DRIVER (dev->device.driver, *drv); -if (drv->remove && drv->remove (dev)) -DPAA2_BUS_ERR ("Unable to remove" ); - } -break ;default :break ; }
@@ -1628,9 +1618,6 @@ fslmc_vfio_close_group(void)fslmc_close_iodevices (dev, vfio_group_fd); } - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) -fslmc_close_iodevices (dev, vfio_group_fd); -fslmc_vfio_clear_group (vfio_group_fd);return 0 ;
Signature · 1 line
2.54.0
PATCH v2 14/16 bus/fslmc: call VFIO setup for some device from bus layer
In reply to David MarchandMove VFIO setup for ETH, CRYPTO and QDMA devices from fslmc_vfio.c to fslmc_bus.c probe.
Also move interrupt setup for ETH devices.
Add fslmc_vfio_dev_setup() (resp. fslmc_vfio_dev_close()) wrapper that handles VFIO device fd acquisition and interrupt setup (resp. device removal), hiding VFIO internals from the bus layer.
Note: before this change, CRYPTO and QDMA devices were getting a VFIO device FD even though nothing seems to be done with it. This is kept as is, the device FD is closed on call to fslmc_vfio_dev_close().
---
Changes since v1:
- used rte_intr_fd_close,
--- drivers/bus/fslmc/fslmc_bus.c | 13 ++++++ drivers/bus/fslmc/fslmc_vfio.c | 77 ++++++++++++++++++++++++++-------- drivers/bus/fslmc/fslmc_vfio.h | 5 +++ 3 files changed, 77 insertions(+), 18 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +13 -0
@@ -573,6 +573,7 @@ rte_fslmc_scan(void)static int rte_fslmc_probe (struct rte_bus *bus) { +struct rte_dpaa2_device *dev;static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = { .name =DPAA2_SEQN_DYNFIELD_NAME , .size =sizeof (dpaa2_seqn_t),
@@ -620,8 +621,19 @@ rte_fslmc_probe(struct rte_bus *bus) goto vfio_dma_unmap; } + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { + ret =fslmc_vfio_dev_setup (dev); +if (ret) { +DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); + goto vfio_dev_close; + } + } +return rte_bus_generic_probe (bus); +vfio_dev_close: + RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) +fslmc_vfio_dev_close (dev); vfio_dma_unmap:fslmc_vfio_dmaunmap (); vfio_close_group:
@@ -653,6 +665,7 @@ rte_fslmc_close(struct rte_bus *bus) RTE_BUS_FOREACH_DEV(dev, bus) {if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device))DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); +fslmc_vfio_dev_close (dev); } ret =fslmc_vfio_close_group ();
drivers/bus/fslmc/fslmc_vfio.c +59 -18
101 lines not on this page · raw message
drivers/bus/fslmc/fslmc_vfio.h +5 -0
@@ -61,4 +61,9 @@ char *fslmc_get_container(void);int fslmc_get_container_group (const char *group_name,int *gropuid);int fslmc_vfio_dmamap (void );int fslmc_vfio_dmaunmap (void ); + +struct rte_dpaa2_device ; +int fslmc_vfio_dev_setup (struct rte_dpaa2_device *dev); +int fslmc_vfio_dev_close (struct rte_dpaa2_device *dev); +#endif /* _FSLMC_VFIO_H_ */
Signature · 1 line
2.54.0
PATCH v2 15/16 bus/fslmc: allocate interrupt during probing
In reply to David MarchandAllocating the interrupt handle is a waste of memory if no device is probed later (like for example, if a allowlist is passed).
Instead, allocate this handle, set eventfds and vfio at the time probe_device is called.
Adjust the unplug_device path accordingly.
--- drivers/bus/fslmc/fslmc_bus.c | 58 +++++++++++++++-------------------- 1 file changed, 25 insertions(+), 33 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +25 -33
@@ -104,7 +104,6 @@ fslmc_free_device(struct rte_device *rte_dev)if (dev->dev_type <DPAA2_DEVTYPE_MAX ) fslmc_bus_device_count[dev->dev_type]--; -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -144,7 +143,6 @@ fslmc_remove_control_device(struct rte_dpaa2_device *dev) fslmc_bus_device_count[dev->dev_type]--;TAILQ_REMOVE (&fslmc_control_devices, &dev->device, next); -rte_intr_instance_free (dev->intr_handle);free (dev); }
@@ -256,15 +254,6 @@ scan_one_fslmc_device(char *dev_name) dev->device.numa_node =SOCKET_ID_ANY ; dev->dev_type = dev_type; -/* Allocate interrupt instance */ - dev->intr_handle = -rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); -if (dev->intr_handle ==NULL ) { -DPAA2_BUS_ERR ("Failed to allocate intr handle" ); - ret = -ENOMEM ; - goto cleanup; - } -if (sscanf (dev_id,"%hu" , &dev->object_id) !=1 ) {DPAA2_BUS_ERR ("Failed to parse object ID" ); ret = -EINVAL ;
@@ -292,10 +281,7 @@ scan_one_fslmc_device(char *dev_name)return 0 ; cleanup: -if (dev) { -rte_intr_instance_free (dev->intr_handle); -free (dev); - } +free (dev);return ret; }
@@ -573,7 +559,6 @@ rte_fslmc_scan(void)static int rte_fslmc_probe (struct rte_bus *bus) { -struct rte_dpaa2_device *dev;static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = { .name =DPAA2_SEQN_DYNFIELD_NAME , .size =sizeof (dpaa2_seqn_t),
@@ -621,19 +606,8 @@ rte_fslmc_probe(struct rte_bus *bus) goto vfio_dma_unmap; } - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) { - ret =fslmc_vfio_dev_setup (dev); -if (ret) { -DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); - goto vfio_dev_close; - } - } -return rte_bus_generic_probe (bus); -vfio_dev_close: - RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus) -fslmc_vfio_dev_close (dev); vfio_dma_unmap:fslmc_vfio_dmaunmap (); vfio_close_group:
@@ -665,7 +639,6 @@ rte_fslmc_close(struct rte_bus *bus) RTE_BUS_FOREACH_DEV(dev, bus) {if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device))DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); -fslmc_vfio_dev_close (dev); } ret =fslmc_vfio_close_group ();
@@ -742,10 +715,27 @@ fslmc_bus_probe_device(struct rte_driver *driver, struct rte_device *rte_dev)struct rte_dpaa2_driver *drv =RTE_BUS_DRIVER (driver, *drv);int ret =0 ; -/* FIXME: probe_device should allocate intr_handle */ +/* Allocate interrupt instance */ + dev->intr_handle = +rte_intr_instance_alloc (RTE_INTR_INSTANCE_F_PRIVATE ); +if (dev->intr_handle ==NULL ) { +DPAA2_BUS_ERR ("Failed to allocate intr handle" ); +return -ENOMEM ; + } + + ret =fslmc_vfio_dev_setup (dev); +if (ret) { +DPAA2_BUS_ERR ("Dev (%s) VFIO setup failed" , dev->device.name); + goto release_intr; + } + ret = drv->probe (drv, dev);if (ret !=0 ) {DPAA2_BUS_ERR ("Unable to probe" ); +fslmc_vfio_dev_close (dev); +release_intr: +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; }else {DPAA2_BUS_INFO ("%s Plugged" , dev->device.name); }
@@ -763,12 +753,14 @@ fslmc_bus_unplug_device(struct rte_device *rte_dev)int ret = drv->remove (dev);if (ret !=0 )return ret; -/* FIXME: unplug_device should free intr_handle */ -DPAA2_BUS_INFO ("%s Un-Plugged" , dev->device.name); -return 0 ; } -return -ENODEV ; +fslmc_vfio_dev_close (dev); +rte_intr_instance_free (dev->intr_handle); + dev->intr_handle =NULL ; +DPAA2_BUS_INFO ("%s Un-Plugged" , dev->device.name); + +return 0 ; }struct rte_bus rte_fslmc_bus = {
Signature · 1 line
2.54.0
PATCH v2 16/16 bus/fslmc: use generic cleanup
In reply to David MarchandNow that the probe and unplug callback behave like other buses, we can call generic cleanup in addition to the special handling for IO devices.
Also cleanup any object left in the control devices list.
--- drivers/bus/fslmc/fslmc_bus.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/bus/fslmc/fslmc_bus.c +14 -11
@@ -628,23 +628,25 @@ fslmc_bus_match(const struct rte_driver *drv, const struct rte_device *dev) }static int -fslmc_bus_unplug_device (struct rte_device *rte_dev); - -static int -rte_fslmc_close (struct rte_bus *bus) +fslmc_cleanup (struct rte_bus *bus) { -struct rte_dpaa2_device *dev; -int ret =0 ; +int ret; - RTE_BUS_FOREACH_DEV(dev, bus) { -if (rte_dev_is_probed (&dev->device) &&fslmc_bus_unplug_device (&dev->device)) -DPAA2_BUS_ERR ("Unable to remove %s" , dev->device.name); - } + ret =rte_bus_generic_cleanup (bus); +if (ret) +DPAA2_BUS_INFO ("Unable to cleanup devices %d" , ret); ret =fslmc_vfio_close_group ();if (ret)DPAA2_BUS_INFO ("Unable to close devices %d" , ret); +while (!TAILQ_EMPTY (&fslmc_control_devices)) { +struct rte_device *rte_dev =TAILQ_FIRST (&fslmc_control_devices); +struct rte_dpaa2_device *dev =RTE_BUS_DEVICE (rte_dev, *dev); + +fslmc_remove_control_device (dev); + } +return 0 ; }
@@ -766,7 +768,8 @@ fslmc_bus_unplug_device(struct rte_device *rte_dev)struct rte_bus rte_fslmc_bus = { .scan = rte_fslmc_scan, .probe = rte_fslmc_probe, - .cleanup = rte_fslmc_close, + .free_device = fslmc_free_device, + .cleanup = fslmc_cleanup, .parse = rte_fslmc_parse, .dev_compare = fslmc_dev_compare, .find_device = rte_bus_generic_find_device,
Signature · 1 line
2.54.0
NXP Confidential
Quoted 17 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: 26 October 2026 23:40
To: Hemant Agrawal <[email protected]>; [email protected]
Subject: [PATCH v2 00/16] Device unplug and bus cleanup refactoring for NXP
Importance: HighHello Hemant,
This is a followup to the refactoring started in 26.07.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
Quoted 6 lines
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
I did not get much feedback on the series. I'll let CI pass on this new revision and merge it.
Series-
Quoted 10 lines · Hemant Agrawal
Quoted 10 lines
Hello Hemant,
This is a followup to the refactoring started in 26.07.
Like the last time, only compilation has been checked. I have no hardware to test runtime.
One thing that could be broken is either the order of devices initialisation, or bugs in the device filtering that I tried to simplify.
Quoted 6 lines
Quoted 3 lines
I went with the approach of splitting the device list between internal bus object (that I called "control" devices, maybe a better name can be found), and normal bus device object for which DPDK has a driver.
Series-
Acked-by Hemant Agrawal <[email protected]>
Thanks for testing the series!
Series applied in main.
A rebase will be needed at some point for other work touching the fslmc bus like:
https://patchwork.dpdk.org/project/dpdk/list/?series=39787
Signature · 1 line
David Marchand