From: Jake Freeland <jfree@FreeBSD.org>
To: Chenbo Xia <chenbox@nvidia.com>,
Nipun Gupta <nipun.gupta@amd.com>,
Tyler Retzlaff <roretzla@linux.microsoft.com>,
Bruce Richardson <bruce.richardson@intel.com>
Cc: Jake Freeland <jfree@FreeBSD.org>, dev@dpdk.org
Subject: [PATCH 4/4] bus/pci/bsd: Fix device existence check
Date: Tue, 6 May 2025 12:40:44 -0500 [thread overview]
Message-ID: <20250506174046.1136711-5-jfree@FreeBSD.org> (raw)
In-Reply-To: <20250506174046.1136711-1-jfree@FreeBSD.org>
Use open(2) instead of access(2) to check for the existence of the target
device. This avoids a possible race condition where the the device file is
removed after a successful call to access(2) but before open(2).
This also fixes any potential bugs associated with passing open(2)-style
flags into access(2). i.e. access(2) does not formally support the O_RDWR
flag.
Signed-off-by: Jake Freeland <jfree@FreeBSD.org>
---
drivers/bus/pci/bsd/pci.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c
index c64cd2c86c..9bce9df503 100644
--- a/drivers/bus/pci/bsd/pci.c
+++ b/drivers/bus/pci/bsd/pci.c
@@ -106,20 +106,29 @@ pci_uio_alloc_resource(struct rte_pci_device *dev,
{
char devname[PATH_MAX]; /* contains the /dev/uioX */
struct rte_pci_addr *loc;
+ int fd;
loc = &dev->addr;
snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
dev->addr.bus, dev->addr.devid, dev->addr.function);
- if (access(devname, O_RDWR) < 0) {
- PCI_LOG(WARNING, " "PCI_PRI_FMT" not managed by UIO driver, skipping",
- loc->domain, loc->bus, loc->devid, loc->function);
- return 1;
+ fd = open(devname, O_RDWR);
+ if (fd < 0) {
+ if (errno == ENOENT) {
+ PCI_LOG(WARNING, PCI_PRI_FMT" not managed by UIO "
+ "driver, skipping", loc->domain,
+ loc->bus, loc->devid, loc->function);
+ return 1;
+ }
+ PCI_LOG(ERR, "Failed to open device file for " PCI_PRI_FMT
+ " (%s)", loc->domain, loc->bus, loc->devid,
+ loc->function, devname);
+ return -1;
}
/* save fd if in primary process */
- if (rte_intr_fd_set(dev->intr_handle, open(devname, O_RDWR))) {
+ if (rte_intr_fd_set(dev->intr_handle, fd)) {
PCI_LOG(WARNING, "Failed to save fd");
goto error;
}
--
2.47.2
next prev parent reply other threads:[~2025-05-06 17:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 17:40 [PATCH 0/4] BSD PCI Fixes Jake Freeland
2025-05-06 17:40 ` [PATCH 1/4] bus/pci: Use force-noreplace flag when mapping PCI resources Jake Freeland
2025-05-08 11:32 ` Burakov, Anatoly
2025-05-06 17:40 ` [PATCH 2/4] bus/pci/bsd: Map resources at EAL baseaddr Jake Freeland
2025-05-08 11:31 ` Burakov, Anatoly
2025-05-06 17:40 ` [PATCH 3/4] bus/pci/bsd: Eliminate potential overflow Jake Freeland
2025-05-08 11:28 ` Burakov, Anatoly
2025-05-06 17:40 ` Jake Freeland [this message]
2025-05-08 11:27 ` [PATCH 4/4] bus/pci/bsd: Fix device existence check Burakov, Anatoly
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250506174046.1136711-5-jfree@FreeBSD.org \
--to=jfree@freebsd.org \
--cc=bruce.richardson@intel.com \
--cc=chenbox@nvidia.com \
--cc=dev@dpdk.org \
--cc=nipun.gupta@amd.com \
--cc=roretzla@linux.microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).