bus/pci: don't open uio device in secondary process
PATCH 1/1 bus/pci: don't open uio device in secondary process
The uio_pci_generic driver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.
To avoid that, the device file is now opened only in the primary process. The commit that introduced this regression, 847d78fb95 ("bus/pci: fix FD in secondary process"), only mentioned enabling access to config space from secondary process, which still works, as it doesn't rely on the device file.
--- drivers/bus/pci/linux/pci_uio.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/bus/pci/linux/pci_uio.c +13 -12
@@ -232,18 +232,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function);return 1 ; } -snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); - -/* save fd */ - fd =open (devname,O_RDWR ); -if (fd <0 ) { -PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); - goto error; - } - -if (rte_intr_fd_set (dev->intr_handle, fd)) - goto error; -snprintf (cfgname,sizeof (cfgname),"/sys/class/uio/uio%u/device/config" , uio_num);
@@ -273,6 +261,19 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return 0 ; +/* the uio_pci_generic driver clears the bus master enable bit when the device file is +* closed, so open it only in the primary process */ +snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); +/* save fd */ + fd =open (devname,O_RDWR ); +if (fd <0 ) { +PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); + goto error; + } + +if (rte_intr_fd_set (dev->intr_handle, fd)) + goto error; +/* allocate the mapping details for secondary processes*/ *uio_res =rte_zmalloc ("UIO_RES" ,sizeof (**uio_res),0 );if (*uio_res ==NULL ) {
Signature · 1 line
2.45.0
Quoted 10 lines
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.To avoid that, the device file is now opened only in the primary process. The commit that introduced this regression,
847d78fb95
("bus/pci: fix FD in secondary process"), only mentioned enabling access to config space from secondary process, which still works, as it doesn't rely on the device file.
Yes, we can still access the config space from secondary process.
Quoted 2 lines
Fixes 847d78fb95 ("bus/pci: fix FD in secondary process")
Maybe here also need a 'Cc: [email protected]' ?
With this, It looks good to me, thanks.
Quoted 52 lines
Signed-off-by Konrad Sztyber <[email protected]>--- drivers/bus/pci/linux/pci_uio.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)drivers/bus/pci/linux/pci_uio.c +1
-12@@ -232,18 +232,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function);return 1 ; } -snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); - -/* save fd */ - fd =open (devname,O_RDWR ); -if (fd <0 ) { -PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); - goto error; - } - -if (rte_intr_fd_set (dev->intr_handle, fd)) - goto error; -snprintf (cfgname,sizeof (cfgname),"/sys/class/uio/uio%u/device/config" , uio_num);@@ -273,6 +261,19 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return 0 ; +/* the uio_pci_generic driver clears the bus master enable bit when the device file is
drivers/bus/pci/linux/pci_uio.c +12
-1+* closed, so open it only in the primary process */ +snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); +/* save fd */ + fd =open (devname,O_RDWR ); +if (fd <0 ) { +PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); + goto error; + } + +if (rte_intr_fd_set (dev->intr_handle, fd)) + goto error; +/* allocate the mapping details for secondary processes*/ *uio_res =rte_zmalloc ("UIO_RES" ,sizeof (**uio_res),0 );if (*uio_res ==NULL ) { --2.45.0
Quoted 9 lines · Konrad Sztyber
External email: Use caution opening links or attachments
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing
Should be one space before ‘So'
Quoted 9 lines
a device, that device becomes unusable in the primary process.
To avoid that, the device file is now opened only in the primary process. The commit that introduced this regression,
847d78fb95("bus/pci: fix FD in secondary process"), only mentioned enabling access to config space from secondary process, which still works, as it doesn't rely on the device file.Fixes 847d78fb95 ("bus/pci: fix FD in secondary process")
Besides the cc stable tag mentioned by Chaoyong, commit ID should be 12-digit.
Please also fix the coding style:
WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line #176: FILE: drivers/bus/pci/linux/pci_uio.c:265:
+ * closed, so open it only in the primary process */
With above fixed:
Quoted 52 lines
Signed-off-by Konrad Sztyber <[email protected]>---
drivers/bus/pci/linux/pci_uio.c| 25 +++++++++++++------------1 file changed, 13 insertions(+), 12 deletions(-)drivers/bus/pci/linux/pci_uio.c +13
-13@@ -232,18 +232,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function);return 1 ; } -snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); - -/* save fd */ - fd =open (devname,O_RDWR ); -if (fd <0 ) { -PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); - goto error; - } - -if (rte_intr_fd_set (dev->intr_handle, fd)) - goto error; -snprintf (cfgname,sizeof (cfgname),"/sys/class/uio/uio%u/device/config" , uio_num);@@ -273,6 +261,19 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return 0 ; +/* the uio_pci_generic driver clears the bus master enable bit when the device file is +* closed, so open it only in the primary process */ +snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); +/* save fd */ + fd =open (devname,O_RDWR ); +if (fd <0 ) { +PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); + goto error; + } + +if (rte_intr_fd_set (dev->intr_handle, fd)) + goto error; +/* allocate the mapping details for secondary processes*/ *uio_res =rte_zmalloc ("UIO_RES" ,sizeof (**uio_res),0 );if (*uio_res ==NULL ) { --2.45.0
PATCH v2 1/1 bus/pci: don't open uio device in secondary process
In reply to Konrad SztyberThe uio_pci_generic driver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.
To avoid that, the device file is now opened only in the primary process. The commit that introduced this regression, 847d78fb9530 ("bus/pci: fix FD in secondary process"), only mentioned enabling access to config space from secondary process, which still works, as it doesn't rely on the device file.
--- drivers/bus/pci/linux/pci_uio.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/bus/pci/linux/pci_uio.c +15 -12
@@ -232,18 +232,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function);return 1 ; } -snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); - -/* save fd */ - fd =open (devname,O_RDWR ); -if (fd <0 ) { -PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); - goto error; - } - -if (rte_intr_fd_set (dev->intr_handle, fd)) - goto error; -snprintf (cfgname,sizeof (cfgname),"/sys/class/uio/uio%u/device/config" , uio_num);
@@ -273,6 +261,21 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return 0 ; +/* +* the uio_pci_generic driver clears the bus master enable bit when the device file is +* closed, so open it only in the primary process +*/ +snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); +/* save fd */ + fd =open (devname,O_RDWR ); +if (fd <0 ) { +PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); + goto error; + } + +if (rte_intr_fd_set (dev->intr_handle, fd)) + goto error; +/* allocate the mapping details for secondary processes*/ *uio_res =rte_zmalloc ("UIO_RES" ,sizeof (**uio_res),0 );if (*uio_res ==NULL ) {
Signature · 1 line
2.45.0
Quoted 70 lines · Konrad Sztyber
External email: Use caution opening links or attachments
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.To avoid that, the device file is now opened only in the primary process. The commit that introduced this regression,
847d78fb9530("bus/pci: fix FD in secondary process"), only mentioned enabling access to config space from secondary process, which still works, as it doesn't rely on the device file.Fixes 847d78fb9530 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>---
drivers/bus/pci/linux/pci_uio.c| 27 +++++++++++++++------------1 file changed, 15 insertions(+), 12 deletions(-)drivers/bus/pci/linux/pci_uio.c +15
-13@@ -232,18 +232,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function);return 1 ; } -snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); - -/* save fd */ - fd =open (devname,O_RDWR ); -if (fd <0 ) { -PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); - goto error; - } - -if (rte_intr_fd_set (dev->intr_handle, fd)) - goto error; -snprintf (cfgname,sizeof (cfgname),"/sys/class/uio/uio%u/device/config" , uio_num);@@ -273,6 +261,21 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return 0 ; +/* +* the uio_pci_generic driver clears the bus master enable bit when the device file is +* closed, so open it only in the primary process +*/ +snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); +/* save fd */ + fd =open (devname,O_RDWR ); +if (fd <0 ) { +PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); + goto error; + } + +if (rte_intr_fd_set (dev->intr_handle, fd)) + goto error; +/* allocate the mapping details for secondary processes*/ *uio_res =rte_zmalloc ("UIO_RES" ,sizeof (**uio_res),0 );if (*uio_res ==NULL ) { --
Quoted 2 lines
2.45.0
PATCH v3 1/1 bus/pci: don't open uio device in secondary process
In reply to Konrad SztyberThe uio_pci_generic driver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.
To avoid that, the device file is now opened only in the primary process and the secondary gets it over UNIX domain socket via SCM_RIGHTS.
---
v3:
Use the rte_mp_* infrastructure to pass the uio fd from the primary process to the secondary.
v2:
Fixed coding style issues.
--- drivers/bus/pci/linux/pci_uio.c | 140 ++++++++++++++++++++++++++++---- 1 file changed, 126 insertions(+), 14 deletions(-)
drivers/bus/pci/linux/pci_uio.c +126 -14
@@ -21,14 +21,22 @@#include <rte_bus_pci.h> #include <rte_common.h> #include <rte_malloc.h> +#include <rte_eal.h> +#include <rte_errno.h> #include "eal_filesystem.h" #include "pci_init.h" #include "private.h" void *pci_map_addr =NULL ; +static int pci_uio_dev_count;#define OFF_MAX ((uint64_t)(off_t)-1) +#define SEND_FD_MP_KEY "pci_uio_send_fd" + +struct pci_uio_send_fd_param { +struct rte_pci_addr addr; +}; int pci_uio_read_config(const struct rte_intr_handle *intr_handle,
@@ -211,6 +219,93 @@ pci_uio_free_resource(struct rte_pci_device *dev,rte_intr_fd_set (dev->intr_handle,-1 );rte_intr_type_set (dev->intr_handle,RTE_INTR_HANDLE_UNKNOWN ); } + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +assert (pci_uio_dev_count >0 ); + pci_uio_dev_count--; +if (pci_uio_dev_count ==0 ) +rte_mp_action_unregister (SEND_FD_MP_KEY ); + } +} + +static int +pci_uio_send_fd (const struct rte_mp_msg *request,const void *peer) +{ +struct rte_pci_device *dev; +const struct pci_uio_send_fd_param *param = + (const struct pci_uio_send_fd_param *)request->param; +struct rte_mp_msg reply = {}; +int fd; + +strlcpy (reply.name, request->name,sizeof (reply.name)); + TAILQ_FOREACH(dev, &rte_pci_bus.device_list, next) { +if (!rte_pci_addr_cmp (&dev->addr, ¶m->addr)) +break ; + } + +if (dev ==NULL ) { +PCI_LOG (ERR ,"Could not find PCI device (" PCI_PRI_FMT ")" , + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + } + + fd =rte_intr_fd_get (dev->intr_handle); +if (fd <0 ) { +PCI_LOG (ERR ,"Could not get fd (" PCI_PRI_FMT ")" , + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + } + + reply.num_fds =1 ; + reply.fds[0 ] = fd; +reply: +if (rte_mp_reply (&reply, peer) !=0 ) { +PCI_LOG (ERR ,"Failed to send reply: %d (" PCI_PRI_FMT ")" , + rte_errno, param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); +return -1 ; + } + +return 0 ; +} + +static int +pci_uio_request_fd (struct rte_pci_device *dev) +{ +struct rte_mp_msg request = {}, *reply; +struct timespec timeout = {.tv_sec =1 , .tv_nsec =0 }; +struct pci_uio_send_fd_param *param = + (struct pci_uio_send_fd_param *)request.param; +struct rte_mp_reply replies; +int rc; + +strlcpy (request.name,SEND_FD_MP_KEY ,sizeof (request.name)); +memcpy (¶m->addr, &dev->addr,sizeof (param->addr)); + request.len_param =sizeof (*param); + + rc =rte_mp_request_sync (&request, &replies, &timeout); +if (rc !=0 || replies.nb_received !=1 ) { +PCI_LOG (ERR ,"Failed to request fd from primary: %d (" PCI_PRI_FMT ")" , + rte_errno, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +return -1 ; + } + + reply = replies.msgs; +if (reply->num_fds !=1 ) { +PCI_LOG (ERR ,"Received unexpected number of fds: %d (" PCI_PRI_FMT ")" , + reply->num_fds, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +free (reply); +return -1 ; + } + +rte_intr_fd_set (dev->intr_handle, reply->fds[0 ]); +free (reply); + +return 0 ; }int
@@ -220,7 +315,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,char dirname[PATH_MAX ];char cfgname[PATH_MAX ];char devname[PATH_MAX ];/* contains the /dev/uioX */ -int uio_num, fd, uio_cfg_fd; +int rc, uio_num, fd, uio_cfg_fd;struct rte_pci_addr *loc; loc = &dev->addr;
@@ -232,18 +327,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function);return 1 ; } -snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); - -/* save fd */ - fd =open (devname,O_RDWR ); -if (fd <0 ) { -PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); - goto error; - } - -if (rte_intr_fd_set (dev->intr_handle, fd)) - goto error; -snprintf (cfgname,sizeof (cfgname),"/sys/class/uio/uio%u/device/config" , uio_num);
@@ -270,8 +353,27 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, } } -if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { +if (pci_uio_request_fd (dev) !=0 ) + goto error;return 0 ; + } + +/* +* The uio_pci_generic driver clears the bus master enable bit when the +* device file is closed, so open it only in the primary process. The +* secondary will get it via SCM_RIGHTS. +*/ +snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); +/* save fd */ + fd =open (devname,O_RDWR ); +if (fd <0 ) { +PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); + goto error; + } + +if (rte_intr_fd_set (dev->intr_handle, fd)) + goto error;/* allocate the mapping details for secondary processes*/ *uio_res =rte_zmalloc ("UIO_RES" ,sizeof (**uio_res),0 );
@@ -280,6 +382,16 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, goto error; } +if (pci_uio_dev_count ==0 ) { + rc =rte_mp_action_register (SEND_FD_MP_KEY , pci_uio_send_fd); +if (rc !=0 && rte_errno !=ENOTSUP ) { +PCI_LOG (ERR ,"Failed to register multi-process callback: %d" , + rte_errno); + goto error; + } + } + + pci_uio_dev_count++;strlcpy ((*uio_res)->path, devname,sizeof ((*uio_res)->path));memcpy (&(*uio_res)->pci_addr, &dev->addr,sizeof ((*uio_res)->pci_addr));
Signature · 1 line
2.46.2
Quoted 5 lines · Konrad Sztyber
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.
Quoted 7 lines
To avoid that, the device file is now opened only in the primary process and the secondary gets it over UNIX domain socket via
SCM_RIGHTS.Fixes 847d78fb9530 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>
Recheck-request: rebase=main,iol-compile-amd64-testing
Signature · 1 line
David Marchand
Quoted 9 lines · David Marchand
Quoted 8 lines · Konrad Sztyber
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.To avoid that, the device file is now opened only in the primary process and the secondary gets it over UNIX domain socket via
SCM_RIGHTS.
Quoted 6 lines
Quoted 4 lines
Fixes 847d78fb9530 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>Recheck-request: rebase=main,iol-compile-amd64-testing
Is there anything that's required of me to get this patch merged?
Quoted 5 lines · Konrad Sztyber
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.
Quoted 7 lines
To avoid that, the device file is now opened only in the primary process and the secondary gets it over UNIX domain socket via
SCM_RIGHTS.Fixes 847d78fb9530 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>
Sorry I let this patch slip out of my radar.
I see nothing wrong in this v3, but could you rebase and resend it so it goes through our CI?
Anatoly, Chenbo, Nipun, please have a look.
Thanks.
Signature · 1 line
David Marchand
Quoted 3 lines · david.marchand at redhat.com (David Marchand)
Sorry I let this patch slip out of my radar.
I see nothing wrong in this v3, but could you rebase and resend it so it goes through our CI?
No worries. Sorry for the late response too, I've missed your e-mail and a colleague has brought it to my attention recently. I'll rebase the patch and resend it today.
Konrad
Hi Konrad,
Quoted 85 lines · Konrad Sztyber
External email: Use caution opening links or attachments
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.To avoid that, the device file is now opened only in the primary process and the secondary gets it over UNIX domain socket via
SCM_RIGHTS.Fixes 847d78fb9530 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>---
v3:
Use the rte_mp_* infrastructure to pass the uio fd from the primary process to the secondary.
v2:
Fixed coding style issues.
---drivers/bus/pci/linux/pci_uio.c| 140 ++++++++++++++++++++++++++++----1 file changed, 126 insertions(+), 14 deletions(-)drivers/bus/pci/linux/pci_uio.c +8
-0@@ -21,14 +21,22 @@#include <rte_bus_pci.h> #include <rte_common.h> #include <rte_malloc.h> +#include <rte_eal.h> +#include <rte_errno.h> #include "eal_filesystem.h" #include "pci_init.h" #include "private.h" void *pci_map_addr =NULL ; +static int pci_uio_dev_count;#define OFF_MAX ((uint64_t)(off_t)-1) +#define SEND_FD_MP_KEY "pci_uio_send_fd" + +struct pci_uio_send_fd_param { +struct rte_pci_addr addr; +};int
pci_uio_read_config(const structrte_intr_handle*intr_handle,drivers/bus/pci/linux/pci_uio.c +28
-0@@ -211,6 +219,93 @@ pci_uio_free_resource(struct rte_pci_device *dev,rte_intr_fd_set (dev->intr_handle,-1 );rte_intr_type_set (dev->intr_handle,RTE_INTR_HANDLE_UNKNOWN ); } + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +assert (pci_uio_dev_count >0 ); + pci_uio_dev_count--; +if (pci_uio_dev_count ==0 ) +rte_mp_action_unregister (SEND_FD_MP_KEY ); + } +} + +static int +pci_uio_send_fd (const struct rte_mp_msg *request,const void *peer) +{ +struct rte_pci_device *dev; +const struct pci_uio_send_fd_param *param = + (const struct pci_uio_send_fd_param *)request->param; +struct rte_mp_msg reply = {}; +int fd; + +strlcpy (reply.name, request->name,sizeof (reply.name)); + TAILQ_FOREACH(dev, &rte_pci_bus.device_list, next) { +if (!rte_pci_addr_cmp (&dev->addr, ¶m->addr)) +break ; + } + +if (dev ==NULL ) { +PCI_LOG (ERR ,"Could not find PCI device (" PCI_PRI_FMT ")" , + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function);
drivers/bus/pci/linux/pci_uio.c pci_uio_free_resource(struct rte_pci_device *dev, · line 259
Quoted 10 lines
drivers/bus/pci/linux/pci_uio.c +10
-0+ goto reply; + } + + fd =rte_intr_fd_get (dev->intr_handle); +if (fd <0 ) { +PCI_LOG (ERR ,"Could not get fd (" PCI_PRI_FMT ")" , + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + }
Should we just return error instead of calling rte_mp_reply when dev == NULL or fd < 0?
Thanks,
Chenbo
Quoted 129 lines
drivers/bus/pci/linux/pci_uio.c +49
-0+ + reply.num_fds =1 ; + reply.fds[0 ] = fd; +reply: +if (rte_mp_reply (&reply, peer) !=0 ) { +PCI_LOG (ERR ,"Failed to send reply: %d (" PCI_PRI_FMT ")" , + rte_errno, param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); +return -1 ; + } + +return 0 ; +} + +static int +pci_uio_request_fd (struct rte_pci_device *dev) +{ +struct rte_mp_msg request = {}, *reply; +struct timespec timeout = {.tv_sec =1 , .tv_nsec =0 }; +struct pci_uio_send_fd_param *param = + (struct pci_uio_send_fd_param *)request.param; +struct rte_mp_reply replies; +int rc; + +strlcpy (request.name,SEND_FD_MP_KEY ,sizeof (request.name)); +memcpy (¶m->addr, &dev->addr,sizeof (param->addr)); + request.len_param =sizeof (*param); + + rc =rte_mp_request_sync (&request, &replies, &timeout); +if (rc !=0 || replies.nb_received !=1 ) { +PCI_LOG (ERR ,"Failed to request fd from primary: %d (" PCI_PRI_FMT ")" , + rte_errno, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +return -1 ; + } + + reply = replies.msgs; +if (reply->num_fds !=1 ) { +PCI_LOG (ERR ,"Received unexpected number of fds: %d (" PCI_PRI_FMT ")" , + reply->num_fds, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +free (reply); +return -1 ; + } + +rte_intr_fd_set (dev->intr_handle, reply->fds[0 ]); +free (reply); + +return 0 ; }int
drivers/bus/pci/linux/pci_uio.c +31
-15@@ -220,7 +315,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,char dirname[PATH_MAX ];char cfgname[PATH_MAX ];char devname[PATH_MAX ];/* contains the /dev/uioX */ -int uio_num, fd, uio_cfg_fd; +int rc, uio_num, fd, uio_cfg_fd;struct rte_pci_addr *loc; loc = &dev->addr;@@ -232,18 +327,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function);return 1 ; } -snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); - -/* save fd */ - fd =open (devname,O_RDWR ); -if (fd <0 ) { -PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); - goto error; - } - -if (rte_intr_fd_set (dev->intr_handle, fd)) - goto error; -snprintf (cfgname,sizeof (cfgname),"/sys/class/uio/uio%u/device/config" , uio_num);@@ -270,8 +353,27 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, } } -if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { +if (pci_uio_request_fd (dev) !=0 ) + goto error;return 0 ; + } + +/* +* The uio_pci_generic driver clears the bus master enable bit when the +* device file is closed, so open it only in the primary process. The +* secondary will get it via SCM_RIGHTS. +*/ +snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); +/* save fd */ + fd =open (devname,O_RDWR ); +if (fd <0 ) { +PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); + goto error; + } + +if (rte_intr_fd_set (dev->intr_handle, fd)) + goto error;/* allocate the mapping details for secondary processes*/ *uio_res =rte_zmalloc ("UIO_RES" ,sizeof (**uio_res),0 );@@ -280,6 +382,16 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, goto error; } +if (pci_uio_dev_count ==0 ) { + rc =rte_mp_action_register (SEND_FD_MP_KEY , pci_uio_send_fd); +if (rc !=0 && rte_errno !=ENOTSUP ) { +PCI_LOG (ERR ,"Failed to register multi-process callback: %d" , + rte_errno); + goto error; + } + } + + pci_uio_dev_count++;strlcpy ((*uio_res)->path, devname,sizeof ((*uio_res)->path));memcpy (&(*uio_res)->pci_addr, &dev->addr,sizeof ((*uio_res)->pci_addr)); --2.46.2
Quoted 22 lines · chenbox at nvidia.com (Chenbo Xia)
Quoted 22 lines
drivers/bus/pci/linux/pci_uio.c +22
-0+static int +pci_uio_send_fd (const struct rte_mp_msg *request,const void *peer) +{ +struct rte_pci_device *dev; +const struct pci_uio_send_fd_param *param = + (const struct pci_uio_send_fd_param *)request->param; +struct rte_mp_msg reply = {}; +int fd; + +strlcpy (reply.name, request->name,sizeof (reply.name)); + TAILQ_FOREACH(dev, &rte_pci_bus.device_list, next) { +if (!rte_pci_addr_cmp (&dev->addr, ¶m->addr)) +break ; + } + +if (dev ==NULL ) { +PCI_LOG (ERR ,"Could not find PCI device (" PCI_PRI_FMT ")" , + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + } +
Quoted 8 lines
drivers/bus/pci/linux/pci_uio.c pci_uio_free_resource(struct rte_pci_device *dev, · line 259
Quoted 7 lines
drivers/bus/pci/linux/pci_uio.c +7
-0+ fd =rte_intr_fd_get (dev->intr_handle); +if (fd <0 ) { +PCI_LOG (ERR ,"Could not get fd (" PCI_PRI_FMT ")" , + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + }Should we just return error instead of calling
rte_mp_replywhen dev == NULL or fd < 0?
We could, but that means that we won't send any response to the secondary process, so it'll timeout. I figured it's better to return a response with num_fds = 0 to let it fail immediately.
Konrad
PATCH v4 1/1 bus/pci: don't open uio device in secondary process
In reply to Konrad SztyberFrom: Konrad Sztyber <[email protected]>
The uio_pci_generic driver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.
To avoid that, the device file is now opened only in the primary process and the secondary gets it over UNIX domain socket via SCM_RIGHTS.
---
v4:
Rebased on top of current main branch.
v3:
Use the rte_mp_* infrastructure to pass the uio fd from the primary process to the secondary.
v2:
Fixed coding style issues.
--- drivers/bus/pci/linux/pci_uio.c | 140 ++++++++++++++++++++++++++++---- 1 file changed, 126 insertions(+), 14 deletions(-)
drivers/bus/pci/linux/pci_uio.c +126 -14
@@ -21,14 +21,22 @@#include <rte_bus_pci.h> #include <rte_common.h> #include <rte_malloc.h> +#include <rte_eal.h> +#include <rte_errno.h> #include "eal_filesystem.h" #include "pci_init.h" #include "private.h" void *pci_map_addr =NULL ; +static int pci_uio_dev_count;#define OFF_MAX ((uint64_t)(off_t)-1) +#define SEND_FD_MP_KEY "pci_uio_send_fd" + +struct pci_uio_send_fd_param { +struct rte_pci_addr addr; +}; int pci_uio_read_config(const struct rte_intr_handle *intr_handle,
@@ -211,6 +219,93 @@ pci_uio_free_resource(struct rte_pci_device *dev,rte_intr_fd_set (dev->intr_handle,-1 );rte_intr_type_set (dev->intr_handle,RTE_INTR_HANDLE_UNKNOWN ); } + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +assert (pci_uio_dev_count >0 ); + pci_uio_dev_count--; +if (pci_uio_dev_count ==0 ) +rte_mp_action_unregister (SEND_FD_MP_KEY ); + } +} + +static int +pci_uio_send_fd (const struct rte_mp_msg *request,const void *peer) +{ +struct rte_pci_device *dev; +const struct pci_uio_send_fd_param *param = + (const struct pci_uio_send_fd_param *)request->param; +struct rte_mp_msg reply = {}; +int fd; + +strlcpy (reply.name, request->name,sizeof (reply.name)); + TAILQ_FOREACH(dev, &rte_pci_bus.device_list, next) { +if (!rte_pci_addr_cmp (&dev->addr, ¶m->addr)) +break ; + } + +if (dev ==NULL ) { +PCI_LOG (ERR ,"Could not find PCI device (" PCI_PRI_FMT ")" , + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + } + + fd =rte_intr_fd_get (dev->intr_handle); +if (fd <0 ) { +PCI_LOG (ERR ,"Could not get fd (" PCI_PRI_FMT ")" , + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + } + + reply.num_fds =1 ; + reply.fds[0 ] = fd; +reply: +if (rte_mp_reply (&reply, peer) !=0 ) { +PCI_LOG (ERR ,"Failed to send reply: %d (" PCI_PRI_FMT ")" , + rte_errno, param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); +return -1 ; + } + +return 0 ; +} + +static int +pci_uio_request_fd (struct rte_pci_device *dev) +{ +struct rte_mp_msg request = {}, *reply; +struct timespec timeout = {.tv_sec =1 , .tv_nsec =0 }; +struct pci_uio_send_fd_param *param = + (struct pci_uio_send_fd_param *)request.param; +struct rte_mp_reply replies; +int rc; + +strlcpy (request.name,SEND_FD_MP_KEY ,sizeof (request.name)); +memcpy (¶m->addr, &dev->addr,sizeof (param->addr)); + request.len_param =sizeof (*param); + + rc =rte_mp_request_sync (&request, &replies, &timeout); +if (rc !=0 || replies.nb_received !=1 ) { +PCI_LOG (ERR ,"Failed to request fd from primary: %d (" PCI_PRI_FMT ")" , + rte_errno, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +return -1 ; + } + + reply = replies.msgs; +if (reply->num_fds !=1 ) { +PCI_LOG (ERR ,"Received unexpected number of fds: %d (" PCI_PRI_FMT ")" , + reply->num_fds, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); +free (reply); +return -1 ; + } + +rte_intr_fd_set (dev->intr_handle, reply->fds[0 ]); +free (reply); + +return 0 ; }int
@@ -220,7 +315,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,char dirname[PATH_MAX ];char cfgname[PATH_MAX ];char devname[PATH_MAX ];/* contains the /dev/uioX */ -int uio_num, fd, uio_cfg_fd; +int rc, uio_num, fd, uio_cfg_fd;struct rte_pci_addr *loc; loc = &dev->addr;
@@ -232,18 +327,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function);return 1 ; } -snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); - -/* save fd */ - fd =open (devname,O_RDWR ); -if (fd <0 ) { -PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); - goto error; - } - -if (rte_intr_fd_set (dev->intr_handle, fd)) - goto error; -snprintf (cfgname,sizeof (cfgname),"/sys/class/uio/uio%u/device/config" , uio_num);
@@ -270,8 +353,27 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, } } -if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) +if (rte_eal_process_type () !=RTE_PROC_PRIMARY ) { +if (pci_uio_request_fd (dev) !=0 ) + goto error;return 0 ; + } + +/* +* The uio_pci_generic driver clears the bus master enable bit when the +* device file is closed, so open it only in the primary process. The +* secondary will get it via SCM_RIGHTS. +*/ +snprintf (devname,sizeof (devname),"/dev/uio%u" , uio_num); +/* save fd */ + fd =open (devname,O_RDWR ); +if (fd <0 ) { +PCI_LOG (ERR ,"Cannot open %s: %s" , devname,strerror (errno)); + goto error; + } + +if (rte_intr_fd_set (dev->intr_handle, fd)) + goto error;/* allocate the mapping details for secondary processes*/ *uio_res =rte_zmalloc ("UIO_RES" ,sizeof (**uio_res),0 );
@@ -280,6 +382,16 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, goto error; } +if (pci_uio_dev_count ==0 ) { + rc =rte_mp_action_register (SEND_FD_MP_KEY , pci_uio_send_fd); +if (rc !=0 && rte_errno !=ENOTSUP ) { +PCI_LOG (ERR ,"Failed to register multi-process callback: %d" , + rte_errno); + goto error; + } + } + + pci_uio_dev_count++;strlcpy ((*uio_res)->path, devname,sizeof ((*uio_res)->path));memcpy (&(*uio_res)->pci_addr, &dev->addr,sizeof ((*uio_res)->pci_addr));
Signature · 1 line
2.43.0
Quoted 6 lines · On Tue, 13 Jan 2026 13:35:43 +0100 Konrad Sztyber <[email protected]>…
From: Konrad Sztyber <[email protected]>
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.
Quoted 8 lines
To avoid that, the device file is now opened only in the primary process and the secondary gets it over UNIX domain socket via
SCM_RIGHTS.Fixes 847d78fb9530 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>---
AI code review spotted one minor issue
## DPDK Patch Review: bus/pci: don't open uio device in secondary process
### Summary
This patch fixes a bug where the uio_pci_generic driver clears the bus master bit when the secondary process closes its UIO device file, rendering the device unusable in the primary process. The fix requests the fd from the primary process via SCM_RIGHTS instead of opening it directly in the secondary.
---
### Commit Message Review
| Check | Status | Notes |
|-------|--------|-------|
| Subject ≤60 chars | ✅ Pass | 50 characters |
| Lowercase after colon | ✅ Pass | |
| Correct prefix | ✅ Pass | `bus/pci:` is correct for `drivers/bus/pci/` |
| Imperative mood | ✅ Pass | "don't open" |
| No trailing period | ✅ Pass | |
| No forbidden punctuation | ✅ Pass | |
| Body ≤75 chars | ✅ Pass | All lines within limit |
| Body doesn't start with "It" | ✅ Pass | Starts with "The" |
| `Fixes:` tag present | ✅ Pass | `Fixes: 847d78fb9530 ("bus/pci: fix FD in secondary process")` |
| `Fixes:` uses 12-char SHA | ✅ Pass | |
| `Cc: [email protected]` | ✅ Pass | Present for backport |
| `Signed-off-by:` present | ✅ Pass | Real name and valid email |
| Tag order correct | ✅ Pass | Fixes → Cc → (blank) → Signed-off-by |---
### Code Style Review
| Check | Status | Notes | |-------|--------|-------| | Lines ≤100 chars | ✅ Pass | | | Function return type on own line | ✅ Pass | `pci_uio_send_fd`, `pci_uio_request_fd` | | Explicit NULL comparisons | ✅ Pass | `dev == NULL`, `dev != NULL` | | Explicit integer comparisons | ✅ Pass | `fd < 0`, `rc != 0`, `pci_uio_dev_count == 0` | | Naming conventions | ✅ Pass | lowercase with underscores throughout | | Comment style | ✅ Pass | Multi-line block comment properly formatted | | Include order | ✅ Pass | DPDK includes grouped appropriately | | No trailing whitespace | ✅ Pass | |
---
### Warnings (should fix)
**1. Use of assert() instead of RTE_ASSERT or proper error handling**
```c
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
assert(pci_uio_dev_count > 0);
```Standard C assert() is disabled when NDEBUG is defined and isn't consistent with DPDK style. Consider:
- Using RTE_ASSERT(pci_uio_dev_count > 0); for debug builds, or
- Adding explicit error handling if this is a condition that could occur in production
---
### Info (consider)
**1. Silent error handling in pci_uio_send_fd**
When the device isn't found or the fd is invalid, the function logs an error but sends an empty reply (num_fds=0). While the secondary process detects this, consider whether the reply should include an explicit error code in the param field for better diagnostics.
**2. Missing header include**
The code uses assert() but doesn't show <assert.h> being added. If assert() is retained, ensure the header is included. If switching to RTE_ASSERT(), <rte_debug.h> may be needed.
---
### Technical Review
The implementation approach is sound:
1. **Primary process**: Opens the UIO device and registers an MP action handler to send the fd to secondary processes
2. **Secondary process**: Requests the fd from primary via rte_mp_request_sync instead of opening it directly
3. **Cleanup**: Properly unregisters the MP action when the last UIO device is freed
The use of rte_mp_* infrastructure and SCM_RIGHTS for fd passing is the correct pattern for DPDK multi-process communication.
---
### Verdict
**Acceptable with minor changes** — The patch is well-structured and addresses a real bug correctly. The only substantive issue is the use of assert() which should be changed to DPDK-style error handling or RTE_ASSERT().
Quoted 10 lines · On Wed, 28 Aug 2024 12:40:02 +0200 Konrad Sztyber <[email protected]>…
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.To avoid that, the device file is now opened only in the primary process. The commit that introduced this regression,
847d78fb95("bus/pci: fix FD in secondary process"), only mentioned enabling access to config space from secondary process, which still works, as it doesn't rely on the device file.
Quoted 3 lines
Fixes 847d78fb95 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>
Wouldn't this break use of interrupts in the secondary process?
The patch does need the minor fix of the comment style. So resubmit
Quoted 13 lines · Stephen Hemminger
Quoted 10 lines · On Wed, 28 Aug 2024 12:40:02 +0200 Konrad Sztyber <[email protected]>…
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.To avoid that, the device file is now opened only in the primary process. The commit that introduced this regression,
847d78fb95("bus/pci: fix FD in secondary process"), only mentioned enabling access to config space from secondary process, which still works, as it doesn't rely on the device file.
Quoted 5 lines
Quoted 3 lines
Fixes 847d78fb95 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>Wouldn't this break use of interrupts in the secondary process?
Yes, it will. But I don't think we can support interrupts in the secondary process *and*, at the same time, keep the device usable in the primary process when secondary terminates. Maybe we could pass the fd via SCM_RIGHTS? But I don't know if that results in the same struct file being used by both processes.
Quoted 2 lines
The patch does need the minor fix of the comment style. So resubmit
I already did, see: https://inbox.dpdk.org/dev/[email protected]
Quoted 18 lines · On Wed, 9 Oct 2024 12:11:32 +0200 Konrad Sztyber <[email protected]>…
Quoted 17 lines · Stephen Hemminger
Quoted 13 lines · On Wed, 28 Aug 2024 12:40:02 +0200 Konrad Sztyber <[email protected]>…
The
uio_pci_genericdriver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process.To avoid that, the device file is now opened only in the primary process. The commit that introduced this regression,
847d78fb95("bus/pci: fix FD in secondary process"), only mentioned enabling access to config space from secondary process, which still works, as it doesn't rely on the device file.Fixes 847d78fb95 ("bus/pci: fix FD in secondary process")Signed-off-by Konrad Sztyber <[email protected]>
Quoted 7 lines
Quoted 1 line
Wouldn't this break use of interrupts in the secondary process?
Yes, it will. But I don't think we can support interrupts in the secondary process *and*, at the same time, keep the device usable in the primary process when secondary terminates. Maybe we could pass the fd via
SCM_RIGHTS? But I don't know if that results in the same struct file being used by both processes.
That is what tap, and xdp are doing.
Quoted 1 line · Stephen Hemminger
That is what tap, and xdp are doing.
Thanks for the info. I'll take a look and will send a next rev doing something similar in uio.
Konrad
Quoted 6 lines · Konrad Sztyber
Quoted 1 line · Stephen Hemminger
That is what tap, and xdp are doing.
Thanks for the info. I'll take a look and will send a next rev doing something similar in uio.
My two cents.
net/tap uses the rte_mp_* infrastructure and this is what you need. net/af_xdp has two cases, so don't get confused with the custom SCM_RIGHTS stuff and stick to rte_mp_*.
Signature · 1 line
David Marchand