From patchwork Mon Sep 4 13:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singhal X-Patchwork-Id: 131162 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 C68A2424F1; Mon, 4 Sep 2023 16:15:01 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E6A6140697; Mon, 4 Sep 2023 16:14:57 +0200 (CEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 7F277400EF for ; Mon, 4 Sep 2023 15:01:32 +0200 (CEST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1c0db66af1bso5343345ad.2 for ; Mon, 04 Sep 2023 06:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1693832491; x=1694437291; 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=CmcIBUZP/RDGA/LbiZwrrmVFhodQNLsmfq7+EcYd0Bo=; b=ZnZTRUiuTWwjT/QYTFihjdAoeB3XiS4vJRBjn2qqDlx4dwBfkw8913nAwRD/sfrA93 Hc4Ww1Vcuq/Ted8wAuTrJdZhmTtrVQqC+6yKD6oS62Bk6nFVCWIbAIAEMvHlapQJKM3v /EghWd8BMEPhyLLU5gXDxMHAaqHb0yW3FnUiUdlwTmkgajlTuB0Rj+gbJ6kRr7qm2CjD Ey+Rv388o2JXdrPT+yuMG+Z7qiwCEwEWvbhMKq1umdXowkMVwCpitqUY/1PMo0iNSpE3 Esoxd0kYsdy2nJjYNC1zzIm0icV6JoGinbc4Qop8BnlgXHpfIGDXhHD4qrKp/dYq6TiG 0Qmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693832491; x=1694437291; 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=CmcIBUZP/RDGA/LbiZwrrmVFhodQNLsmfq7+EcYd0Bo=; b=aJ5XPz+69tnOhs2sqbM+KJLO40at5nIf/vn9DYEzZCDeY849HZHkipOQcqhkQZskse MRFjuqGxtUyxvepGaGpdjAjwXXuuadSa1H0lslDDt8CgDQkWnqb8hebxfNP0fvhXL8g9 T8/0/MQw+1q/SyRAJNGmfI4YYAw8zov2eqiuptZNCfR0FKBxXVd7rPqeWw3C0ziP0kXp jDwsMe28LlRaTNRwMz4+SM8Qq3NqkDmi3K4vT56PqNjQisXXYTr0PcCwHBDosz4MtcBf 2VV3z35cgqMrl+ymDkdFjmEVons+SxjKZsALhxdKI/Rxq7NtFOaosoOC+ks8ti5UyEDj 2UFA== X-Gm-Message-State: AOJu0YyhB0Yw7tcvAMt2i4AAt77oN//TnrPUzLYWbiXc1HeuzzTUQVX1 pXRR6UmT3rrwsmrSluwH/9uWyA== X-Google-Smtp-Source: AGHT+IGQjGa5ZcybzRv5AlgjDIZNv5LhYS7Vjh5Js0wuQNXrgOSJwf/HjNVW3w1bvny0qDUKYtjF+Q== X-Received: by 2002:a17:902:da86:b0:1c0:c7ae:a8a2 with SMTP id j6-20020a170902da8600b001c0c7aea8a2mr3969241plx.35.1693832491247; Mon, 04 Sep 2023 06:01:31 -0700 (PDT) Received: from saurabhs-sfelagsubintfimpl-0.sjc.aristanetworks.com ([74.123.28.17]) by smtp.gmail.com with ESMTPSA id w1-20020a170902e88100b001b9d335223csm7564942plg.26.2023.09.04.06.01.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Sep 2023 06:01:30 -0700 (PDT) From: Saurabh Singhal To: Thomas Monjalon , Jingjing Wu , Beilei Xing Cc: dev@dpdk.org, Saurabh Singhal Subject: [PATCH] net/iavf: unregister intr handler before FD close Date: Mon, 4 Sep 2023 06:01:23 -0700 Message-ID: <20230904130123.40084-1-saurabhs@arista.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 04 Sep 2023 16:14:55 +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. Signed-off-by: Saurabh Singhal --- .mailmap | 1 + drivers/net/iavf/iavf_ethdev.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) 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..df87a553db 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 inline 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, @@ -2490,9 +2492,22 @@ iavf_uninit_vf(struct rte_eth_dev *dev) { struct iavf_hw *hw = IAVF_DEV_PRIVATE_TO_HW(dev->data->dev_private); struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_intr_handle *intr_handle = pci_dev->intr_handle; iavf_shutdown_adminq(hw); + if (vf->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) { + /* disable uio intr before callback unregiser */ + rte_intr_disable(intr_handle); + + /* unregister callback func from eal lib */ + rte_intr_callback_unregister(intr_handle, + iavf_dev_interrupt_handler, dev); + } else { + rte_eal_alarm_cancel(iavf_dev_alarm_handler, dev); + } + rte_free(vf->vf_res); vf->vsi_res = NULL; vf->vf_res = NULL;