From patchwork Wed Sep 6 16:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singhal X-Patchwork-Id: 131226 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C306B42534; Thu, 7 Sep 2023 10:25:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A87B2402E6; Thu, 7 Sep 2023 10:25:34 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id 0E2364027C for ; Wed, 6 Sep 2023 18:05:10 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-68a440a8a20so3259407b3a.3 for ; Wed, 06 Sep 2023 09:05:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1694016309; x=1694621109; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7Xob+TBXK70dN4oo5VBxzAZn9ZWTDhHYK2xCKf71fzo=; b=KgAjMK+1tYI/yka5opbMPdb29RTqQh62DW5k5G75Z1QxvLd41adG/sdB5KOjNX7E84 cANzvW8tlGoMaH7zYRna8u+mCBQHVP0r3gS5o9+6Lw+g0OSW7jkZE+VYqYMu1v1sqvrk iHRjGafDFW9EDWRfFCC8giJ3Ma6QnafUqakelpRS0vgZjXKLlRORAeyA93tonkxc/Plf lCzY5cdABk4q7SqE4iwJ4qTOE4WmP2e+/Brkd+DJZES1/SnTm8Qmh0AehouPgQ5fZW9Y nGlJXTxWB2xdAMBU9u1lr+vDYoTq7PcmAmyPrkmPtUFLUfIJn0xjt1uNjvofSwP1Gtp7 qNZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694016309; x=1694621109; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7Xob+TBXK70dN4oo5VBxzAZn9ZWTDhHYK2xCKf71fzo=; b=EGt6BdStoEm5i9Vr8gOIu3v0hgPwmqrZwbRjm6jjYeBaF9EvhVyFAxKgpKO2nGqn5T CBAHhOVDpqFidHzmTrb8QVw4b1S7RNVUo7B7XZhOSgi7Fxq3sLfGAYBa+ZRU37Mkm3RX ApqDDkr8QQrCwCEDw0ZjU7GfvFqeoaON9RSimUyRr8fxM6aFwdRtDkSXMcb3Xj5MzXh+ t9cLfgVBUQwGgTAV6IxascHCRtpxbK6sJ1N4MwDY+1di+oAwp+fF6x7V3fspYb6K6N9l x6VoYzZOBhYGXHuhmOB6gyh8Mu8po1s6WfsyH4mRMwul+1yppKHIzBUStZeDiyB2Kzfc ELYw== X-Gm-Message-State: AOJu0Yw57y2kRkflU9IUDBraeId3aFLPgbag8HIb8x89b90QhKVIujdY v6QvZ0P2BDeZBZu2WmSdzjANRw== X-Google-Smtp-Source: AGHT+IEMwdnls9I3oLUL7m+AUa2Klpjk9vjbHjXs1Ew5g9F0Jq0OHUMZJnMZC+HqZNqkEZugpL/YZQ== X-Received: by 2002:a05:6a00:2291:b0:68a:49bc:e091 with SMTP id f17-20020a056a00229100b0068a49bce091mr20432804pfe.2.1694016308980; Wed, 06 Sep 2023 09:05:08 -0700 (PDT) Received: from saurabhs-sfelagsubintfimpl-0.sjc.aristanetworks.com ([74.123.28.11]) by smtp.gmail.com with ESMTPSA id h26-20020aa786da000000b00653fe2d527esm11020352pfo.32.2023.09.06.09.05.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2023 09:05:08 -0700 (PDT) From: Saurabh Singhal To: Thomas Monjalon , Jingjing Wu , Beilei Xing Cc: dev@dpdk.org, Saurabh Singhal Subject: [PATCH v4] net/iavf: unregister intr handler before FD close Date: Wed, 6 Sep 2023 09:04:59 -0700 Message-ID: <20230906160459.78660-1-saurabhs@arista.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 07 Sep 2023 10:25:32 +0200 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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(). Signed-off-by: Saurabh Singhal --- .mailmap | 1 + drivers/net/iavf/iavf_ethdev.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.mailmap b/.mailmap index 864d33ee46..4dac53011b 100644 --- a/.mailmap +++ b/.mailmap @@ -1227,6 +1227,7 @@ Satananda Burla Satha Rao Satheesh Paul Sathesh Edara +Saurabh Singhal Savinay Dharmappa Scott Branden Scott Daniels diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c index f2fc5a5621..47c1399a52 100644 --- a/drivers/net/iavf/iavf_ethdev.c +++ b/drivers/net/iavf/iavf_ethdev.c @@ -133,6 +133,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, @@ -2709,13 +2711,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; } } @@ -2728,7 +2730,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;