With Rx interrupts, configuring a port initializes the device, twice
when an offload or RSS is requested. Each initialization enables the
interrupt eventfds. EAL now refuses to enable MSI-X eventfds twice
(before, it leaked the previous ones). So such a configuration fails,
and so does a second configuration:

  EAL: Interrupt eventfds are already enabled
  virtio_configure_intr(): Fail to create eventfd
  ETHDEV: Port0 dev_configure = -16

Enable the eventfds only when they are not enabled. There is one per
Rx queue, so release them first when the number of Rx queues changed.
The application must then register the Rx queue interrupts again.

Release them only for a VFIO MSI-X handle, whose eventfds EAL creates.
A virtio-user handle also gets here. Its eventfds are the backend's
call fds, set once when the device is created. Releasing them would
reset their count for good, and registering an Rx queue's interrupt
would then fail.

To reproduce, with a virtio-net PCI device bound to vfio-pci:

  dpdk-l3fwd-power -l 0 -a 0000:0c:00.0 -- -p 1 --interrupt-only \
      --parse-ptype --config="(0,0,0)"

Fixes: 3ba6b689893f ("eal/linux: fix eventfd leaks when enabling interrupts")
Cc: [email protected]

Signed-off-by: Isaac Boukris <[email protected]>
---
v4: shorter commit message, no code change.
v2: keep the eventfds unless the number of Rx queues changed (David Marchand).

 drivers/net/virtio/virtio_ethdev.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c 
b/drivers/net/virtio/virtio_ethdev.c
index f2302089ee..8600f3899a 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1455,10 +1455,20 @@ virtio_configure_intr(struct rte_eth_dev *dev)
                return -ENOTSUP;
        }
 
-       ret = rte_intr_efd_enable(dev->intr_handle, dev->data->nb_rx_queues);
-       if (ret < 0) {
-               PMD_INIT_LOG(ERR, "Fail to create eventfd");
-               return ret;
+       /* On reinitialization, release the eventfds if the number of Rx queues 
changed. */
+       if (rte_intr_type_get(dev->intr_handle) == RTE_INTR_HANDLE_VFIO_MSIX &&
+           rte_intr_dp_is_en(dev->intr_handle) &&
+           rte_intr_nb_efd_get(dev->intr_handle) != dev->data->nb_rx_queues) {
+               virtio_intr_disable(dev);
+               rte_intr_efd_disable(dev->intr_handle);
+       }
+
+       if (!rte_intr_dp_is_en(dev->intr_handle)) {
+               ret = rte_intr_efd_enable(dev->intr_handle, 
dev->data->nb_rx_queues);
+               if (ret < 0) {
+                       PMD_INIT_LOG(ERR, "Fail to create eventfd");
+                       return ret;
+               }
        }
 
        ret = rte_intr_vec_list_alloc(dev->intr_handle, "intr_vec",
-- 
2.56.1

Reply via email to