Skip to contentSkip to conversation

pci: add O_CLOEXEC when open uio device

PATCH In review Weifeng Su 2 participants 2 messages Jun 29, 2023 – Jul 6, 2023

lore
Share & tools
lore

Weifeng Su

author
#0 lore raw

PATCH v2 1/1 pci: add O_CLOEXEC when open uio device

In this scenario, the DPDK process invokes a script which inherits an open file descriptor (FD) for a UIO device.
After the script execution is complete, the UIO device's close operation is called. However, in a new kernel version (865a11f987ab5f03:uio/uio_pci_generic: Disable bus-mastering on release), this close operation causes the PCI bus master bit to be cleared, rendering the device unusable and leading to unexpected behavior.

This modification was made to prevent the UIO device's FD from being inherited by the child process.

---
 drivers/bus/pci/linux/pci_uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/pci/linux/pci_uio.c +1 -1
index d52125e49b..7ac142c36e 100644
@@ -246,7 +246,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,
 	snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
 
 	/* save fd if in primary process */
-	fd = open(devname, O_RDWR);
+	fd = open(devname, O_RDWR | O_CLOEXEC);
 	if (fd < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
 			devname, strerror(errno));
Signature · 1 line
2.18.0.windows.1
Acked-by on v2 1/1
#1 lore raw
Quoted 8 lines · On Thu, 29 Jun 2023 10:53:39 +0800 Weifeng Su <[email protected]> wrote:

In this scenario, the DPDK process invokes a script which inherits an open file descriptor (FD) for a UIO device.
After the script execution is complete, the UIO device's close operation is called. However, in a new kernel version (865a11f987ab5f03:uio/uio_pci_generic: Disable bus-mastering on release), this close operation causes the PCI bus master bit to be cleared, rendering the device unusable and leading to unexpected behavior.

Quoted 4 lines

This modification was made to prevent the UIO device's FD from being inherited by the child process.

Makes sense, the eventfd used form VFIO is already marked as close on exec.