pci: add O_CLOEXEC when open uio device

Message ID 20230525030035.33872-1-suweifeng1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series pci: add O_CLOEXEC when open uio device |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing fail Unit Testing FAIL
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing fail Testing issues
ci/github-robot: build success github build: passed
ci/iol-unit-testing fail Testing issues
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS

Commit Message

Weifeng Su May 25, 2023, 3 a.m. UTC
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.
Cc: stable@dpdk.org

Signed-off-by: Weifeng Su <suweifeng1@huawei.com>
---
 drivers/bus/pci/linux/pci_uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Stephen Hemminger Oct. 3, 2024, 7:08 p.m. UTC | #1
On Thu, 25 May 2023 11:00:35 +0800
Weifeng Su <suweifeng1@huawei.com> 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.
> This modification was made to prevent the UIO device's FD
> from being inherited by the child process.
> Cc: stable@dpdk.org
> 
> Signed-off-by: Weifeng Su <suweifeng1@huawei.com>

Makes sense that UIO fd's would be marked close on exec.
But should the interrupt fd, and all the other fd's which EAL leaves.

DPDK internal code doesn't invoke scripts. If your application is
going to do so then it needs to lots more cleanup. Probably some
variant of closing all fd's.
  

Patch

diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c
index d52125e49b..7ac142c36e 100644
--- a/drivers/bus/pci/linux/pci_uio.c
+++ b/drivers/bus/pci/linux/pci_uio.c
@@ -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));