Skip to content

Commit

Permalink
net/iavf: unregister interrupt handler before FD close
Browse files Browse the repository at this point in the history
[ upstream commit e35a5737a7469423880a0946afffd2568f6156dd ]

Unregister VFIO interrupt handler before the interrupt fd gets closed in
case iavf_dev_init() returns an error.

dpdk creates a standalone thread named eal-intr-thread for processing
interrupts for the PCI devices. The interrupt handler callbacks are
registered by the VF driver(iavf, in this case).

When we do a PCI probe of the network interfaces, we register an
interrupt handler, open a vfio-device fd using ioctl, and an eventfd in
dpdk. These interrupt sources are registered in a global linked list
that the eal-intr-thread keeps iterating over for handling the
interrupts. In our internal testing, we see eal-intr-thread crash in
these two ways:

Error adding fd 660 epoll_ctl, Operation not permitted

or

Error adding fd 660 epoll_ctl, Bad file descriptor

epoll_ctl() returns EPERM if the target fd does not support poll.
It returns EBADF when the epoll fd itself is closed or the target fd is
closed.

When the first type of crash happens, we see that the fd 660 is
anon_inode:[vfio-device] which does not support poll.

When the second type of crash happens, we could see from the fd map of
the crashing process that the fd 660 was already closed.

This means the said fd has been closed and in certain cases may have
been reassigned to a different device by the operating system but the
eal-intr-thread does not know about it.

We observed that these crashes were always accompanied by an error in
iavf_dev_init() after rte_intr_callback_register() and
iavf_enable_irq0() have already happened. In the error path, the
intr_handle_fd was being closed but the interrupt handler wasn't being
unregistered.

The fix is to unregister the interrupt handle in the
iavf_dev_init() error path.

Ensure proper cleanup if iavf_security_init() or
iavf_security_ctx_create() fail. Earlier, we were leaking memory by
simply returning from iavf_dev_init().

Fixes: 22b123a ("net/avf: initialize PMD")
Fixes: 6bc987e ("net/iavf: support IPsec inline crypto")

Signed-off-by: Saurabh Singhal <saurabhs@arista.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
  • Loading branch information
sasinghal authored and kevintraynor committed Oct 31, 2023
1 parent 1b0d948 commit 77aff6a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ Satananda Burla <sburla@marvell.com>
Satha Rao <skoteshwar@marvell.com> <skoteshwar@caviumnetworks.com>
Satheesh Paul <psatheesh@marvell.com>
Sathesh Edara <sedara@marvell.com>
Saurabh Singhal <saurabhs@arista.com>
Savinay Dharmappa <savinay.dharmappa@intel.com>
Scott Branden <scott.branden@broadcom.com>
Scott Daniels <daniels@research.att.com>
Expand Down
22 changes: 20 additions & 2 deletions drivers/net/iavf/iavf_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
uint16_t queue_id);
static int iavf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
uint16_t queue_id);
static void iavf_dev_interrupt_handler(void *param);
static void iavf_disable_irq0(struct iavf_hw *hw);
static int iavf_dev_flow_ops_get(struct rte_eth_dev *dev,
const struct rte_flow_ops **ops);
static int iavf_set_mc_addr_list(struct rte_eth_dev *dev,
Expand Down Expand Up @@ -2613,13 +2615,13 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
ret = iavf_security_ctx_create(adapter);
if (ret) {
PMD_INIT_LOG(ERR, "failed to create ipsec crypto security instance");
return ret;
goto flow_init_err;
}

ret = iavf_security_init(adapter);
if (ret) {
PMD_INIT_LOG(ERR, "failed to initialized ipsec crypto resources");
return ret;
goto security_init_err;
}
}

Expand All @@ -2633,7 +2635,23 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)

return 0;

security_init_err:
iavf_security_ctx_destroy(adapter);

flow_init_err:
iavf_disable_irq0(hw);

if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) {
/* disable uio intr before callback unregiser */
rte_intr_disable(pci_dev->intr_handle);

/* unregister callback func from eal lib */
rte_intr_callback_unregister(pci_dev->intr_handle,
iavf_dev_interrupt_handler, eth_dev);
} else {
rte_eal_alarm_cancel(iavf_dev_alarm_handler, eth_dev);
}

rte_free(eth_dev->data->mac_addrs);
eth_dev->data->mac_addrs = NULL;

Expand Down

0 comments on commit 77aff6a

Please sign in to comment.