DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] eal/linux: fix eventfd leaks when enabling interrupts
@ 2026-10-23  9:36 Anatoly Burakov
  2026-10-23 11:42 ` David Marchand
                   ` (3 more replies)
  0 siblings, 4 replies; 33+ messages in thread
From: Anatoly Burakov @ 2026-10-23  9:36 UTC (permalink / raw)
  To: dev, Harman Kalra, Cunming Liang

When enabling MSI-X eventfds, a failure after creating some descriptors
leaves them open. The eventfd count is recorded only after all allocations
succeed, so disabling eventfds cannot clean up a partial allocation.

Calling enable again without disabling first also leaks descriptors by
overwriting the existing eventfd entries.

Reject repeated MSI-X enable calls with EBUSY before modifying the handle.
On failure, close all eventfds created by the call, clear their entries
and reset the eventfd count while preserving the original error.

Fixes: b9e0662a931d ("eal/linux: add interrupt API for drivers")
Cc: stable@dpdk.org

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/eal/linux/eal_interrupts.c | 39 +++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c
index 4cfaeba7fe0..ff05d649607 100644
--- a/lib/eal/linux/eal_interrupts.c
+++ b/lib/eal/linux/eal_interrupts.c
@@ -1570,30 +1570,43 @@ int
 rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd)
 {
 	uint32_t i;
-	int fd;
+	int fd, ret;
 	uint32_t n = RTE_MIN(nb_efd, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
 
 	assert(nb_efd != 0);
 
 	if (rte_intr_type_get(intr_handle) == RTE_INTR_HANDLE_VFIO_MSIX) {
+		if (rte_intr_nb_efd_get(intr_handle) != 0) {
+			EAL_LOG(ERR, "Interrupt eventfds are already enabled");
+			return -EBUSY;
+		}
+
 		for (i = 0; i < n; i++) {
 			fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
 			if (fd < 0) {
+				ret = -errno;
 				EAL_LOG(ERR,
 					"can't setup eventfd, error %i (%s)",
 					errno, strerror(errno));
-				return -errno;
+				goto error;
 			}
 
-			if (rte_intr_efds_index_set(intr_handle, i, fd))
-				return -rte_errno;
+			if (rte_intr_efds_index_set(intr_handle, i, fd)) {
+				ret = -rte_errno;
+				close(fd);
+				goto error;
+			}
 		}
 
-		if (rte_intr_nb_efd_set(intr_handle, n))
-			return -rte_errno;
+		if (rte_intr_nb_efd_set(intr_handle, n)) {
+			ret = -rte_errno;
+			goto error;
+		}
 
-		if (rte_intr_max_intr_set(intr_handle, NB_OTHER_INTR + n))
-			return -rte_errno;
+		if (rte_intr_max_intr_set(intr_handle, NB_OTHER_INTR + n)) {
+			ret = -rte_errno;
+			goto error;
+		}
 	} else if (rte_intr_type_get(intr_handle) == RTE_INTR_HANDLE_VDEV) {
 		/* only check, initialization would be done in vdev driver.*/
 		if ((uint64_t)rte_intr_efd_counter_size_get(intr_handle) >
@@ -1611,6 +1624,16 @@ rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd)
 	}
 
 	return 0;
+
+error:
+	while (i > 0) {
+		i--;
+		close(rte_intr_efds_index_get(intr_handle, i));
+		rte_intr_efds_index_set(intr_handle, i, -1);
+	}
+	rte_intr_nb_efd_set(intr_handle, 0);
+
+	return ret;
 }
 
 RTE_EXPORT_INTERNAL_SYMBOL(rte_intr_efd_disable)
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2026-10-24  9:58 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23  9:36 [PATCH v1 1/1] eal/linux: fix eventfd leaks when enabling interrupts Anatoly Burakov
2026-10-23 11:42 ` David Marchand
2026-10-23 12:25   ` Burakov, Anatoly
2026-10-23 13:07 ` [PATCH v2 1/3] eal/linux: fix closing of event FDs not owned by EAL Anatoly Burakov
2026-10-23 13:07   ` [PATCH v2 2/3] interrupts: warn on leaked event FDs Anatoly Burakov
2026-10-23 13:07   ` [PATCH v2 3/3] eal/linux: fix eventfd leaks when enabling interrupts Anatoly Burakov
2026-10-23 13:39 ` [PATCH v3 1/8] interrupts: fix size of duplicated instance Anatoly Burakov
2026-10-23 13:39   ` [PATCH v3 2/8] interrupts: fix event arrays copy on instance duplication Anatoly Burakov
2026-10-23 13:39   ` [PATCH v3 3/8] eal/linux: fix closing of event FDs not owned by EAL Anatoly Burakov
2026-10-23 13:39   ` [PATCH v3 4/8] eal/linux: fix eventfd leaks when enabling interrupts Anatoly Burakov
2026-10-23 13:39   ` [PATCH v3 5/8] eal/linux: fix leaked FD warnings for interrupt sources Anatoly Burakov
2026-10-23 13:39   ` [PATCH v3 6/8] eal/freebsd: fix interrupt source handle leak Anatoly Burakov
2026-10-23 13:39   ` [PATCH v3 7/8] bus/pci: fix leaked device FD warning on VFIO unmap Anatoly Burakov
2026-10-23 13:49     ` Burakov, Anatoly
2026-10-23 13:39   ` [PATCH v3 8/8] interrupts: warn on leaked event FDs Anatoly Burakov
2026-10-23 13:51 ` [PATCH v4 1/8] interrupts: fix size of duplicated instance Anatoly Burakov
2026-10-23 13:51   ` [PATCH v4 2/8] interrupts: fix event arrays copy on instance duplication Anatoly Burakov
2026-10-23 14:15     ` David Marchand
2026-10-23 14:36       ` Burakov, Anatoly
2026-10-23 14:44         ` David Marchand
2026-10-23 14:55           ` Burakov, Anatoly
2026-10-23 13:51   ` [PATCH v4 3/8] eal/linux: fix closing of event FDs not owned by EAL Anatoly Burakov
2026-10-23 14:17     ` David Marchand
2026-10-23 13:51   ` [PATCH v4 4/8] eal/linux: fix eventfd leaks when enabling interrupts Anatoly Burakov
2026-10-23 14:37     ` David Marchand
2026-10-23 13:51   ` [PATCH v4 5/8] eal/linux: fix leaked FD warnings for interrupt sources Anatoly Burakov
2026-10-23 13:51   ` [PATCH v4 6/8] eal/freebsd: fix interrupt source handle leak Anatoly Burakov
2026-10-23 13:51   ` [PATCH v4 7/8] bus/pci: fix leaked device FD warning on VFIO unmap Anatoly Burakov
2026-10-23 13:51   ` [PATCH v4 8/8] interrupts: warn on leaked event FDs Anatoly Burakov
2026-10-23 14:41     ` David Marchand
2026-10-23 14:48       ` Burakov, Anatoly
2026-10-24  8:56         ` David Marchand
2026-10-24  9:57           ` Burakov, Anatoly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox