From nobody Sun Oct 5 16:16:37 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0BAB2BF00B; Thu, 31 Jul 2025 13:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753970123; cv=none; b=gt2XnUpFLGQfxyMFhY3b+AqYaFCobf8fxS1dquay+WZ4ezk0zeTSTmHUrif30PfWpoza1Q9hM6y3cI5TU27IIXmQ2UCwqN8ibjRzSm86ZEL5LyTZIcM9w0csKbp0lUJaKKHINzh30sNbkxvrMG+amHfhtwEFtEXFb2I9yqZNnAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753970123; c=relaxed/simple; bh=7hHBqQf805NswColiBex+ANNVzs2Xz5BQCv/ANGMenY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pUY67nFPLYvtiWtnSejB+00yAKXlhAfMdEtRuM9hiCr0GMN3qme5MfZjcb7tauuHcbRSdypDq+l5zVzR/hZ0JFmc6+s/OMwSXPidgeN9EDmxKRaK+Zl/GF5zN+gUHLN5OP+jGpQXhx14ucoAxuXUvii1Jg2yJSiADsBRjHmdNVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4bt9YL3j4wztSbd; Thu, 31 Jul 2025 21:54:14 +0800 (CST) Received: from kwepemk100013.china.huawei.com (unknown [7.202.194.61]) by mail.maildlp.com (Postfix) with ESMTPS id 0813118007F; Thu, 31 Jul 2025 21:55:17 +0800 (CST) Received: from localhost.localdomain (10.90.31.46) by kwepemk100013.china.huawei.com (7.202.194.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 31 Jul 2025 21:55:16 +0800 From: Jijie Shao To: , , , , , CC: , , , , , , , , Subject: [PATCH net 1/3] net: hibmcge: fix rtnl deadlock issue Date: Thu, 31 Jul 2025 21:47:47 +0800 Message-ID: <20250731134749.4090041-2-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20250731134749.4090041-1-shaojijie@huawei.com> References: <20250731134749.4090041-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemk100013.china.huawei.com (7.202.194.61) Content-Type: text/plain; charset="utf-8" Currently, the hibmcge netdev acquires the rtnl_lock in pci_error_handlers.reset_prepare() and releases it in pci_error_handlers.reset_done(). However, in the PCI framework: pci_reset_bus - __pci_reset_slot - pci_slot_save_and_disable_locked - pci_dev_save_and_disable - err_handler->reset_prepare(dev); In pci_slot_save_and_disable_locked(): list_for_each_entry(dev, &slot->bus->devices, bus_list) { if (!dev->slot || dev->slot!=3D slot) continue; pci_dev_save_and_disable(dev); if (dev->subordinate) pci_bus_save_and_disable_locked(dev->subordinate); } This will iterate through all devices under the current bus and execute err_handler->reset_prepare(), causing two devices of the hibmcge driver to sequentially request the rtnl_lock, leading to a deadlock. Since the driver now executes netif_device_detach() before the reset process, it will not concurrently with other netdev APIs, so there is no need to hold the rtnl_lock now. Therefore, this patch removes the rtnl_lock during the reset process and adjusts the position of HBG_NIC_STATE_RESETTING to ensure that multiple resets are not executed concurrently. Fixes: 3f5a61f6d504f ("net: hibmcge: Add reset supported in this module") Signed-off-by: Jijie Shao --- drivers/net/ethernet/hisilicon/hibmcge/hbg_err.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_err.c b/drivers/net= /ethernet/hisilicon/hibmcge/hbg_err.c index 503cfbfb4a8a..94bc6f0da912 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_err.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_err.c @@ -53,9 +53,11 @@ static int hbg_reset_prepare(struct hbg_priv *priv, enum= hbg_reset_type type) { int ret; =20 - ASSERT_RTNL(); + if (test_and_set_bit(HBG_NIC_STATE_RESETTING, &priv->state)) + return -EBUSY; =20 if (netif_running(priv->netdev)) { + clear_bit(HBG_NIC_STATE_RESETTING, &priv->state); dev_warn(&priv->pdev->dev, "failed to reset because port is up\n"); return -EBUSY; @@ -64,7 +66,6 @@ static int hbg_reset_prepare(struct hbg_priv *priv, enum = hbg_reset_type type) netif_device_detach(priv->netdev); =20 priv->reset_type =3D type; - set_bit(HBG_NIC_STATE_RESETTING, &priv->state); clear_bit(HBG_NIC_STATE_RESET_FAIL, &priv->state); ret =3D hbg_hw_event_notify(priv, HBG_HW_EVENT_RESET); if (ret) { @@ -84,10 +85,8 @@ static int hbg_reset_done(struct hbg_priv *priv, enum hb= g_reset_type type) type !=3D priv->reset_type) return 0; =20 - ASSERT_RTNL(); - - clear_bit(HBG_NIC_STATE_RESETTING, &priv->state); ret =3D hbg_rebuild(priv); + clear_bit(HBG_NIC_STATE_RESETTING, &priv->state); if (ret) { priv->stats.reset_fail_cnt++; set_bit(HBG_NIC_STATE_RESET_FAIL, &priv->state); @@ -101,12 +100,10 @@ static int hbg_reset_done(struct hbg_priv *priv, enum= hbg_reset_type type) return ret; } =20 -/* must be protected by rtnl lock */ int hbg_reset(struct hbg_priv *priv) { int ret; =20 - ASSERT_RTNL(); ret =3D hbg_reset_prepare(priv, HBG_RESET_TYPE_FUNCTION); if (ret) return ret; @@ -171,7 +168,6 @@ static void hbg_pci_err_reset_prepare(struct pci_dev *p= dev) struct net_device *netdev =3D pci_get_drvdata(pdev); struct hbg_priv *priv =3D netdev_priv(netdev); =20 - rtnl_lock(); hbg_reset_prepare(priv, HBG_RESET_TYPE_FLR); } =20 @@ -181,7 +177,6 @@ static void hbg_pci_err_reset_done(struct pci_dev *pdev) struct hbg_priv *priv =3D netdev_priv(netdev); =20 hbg_reset_done(priv, HBG_RESET_TYPE_FLR); - rtnl_unlock(); } =20 static const struct pci_error_handlers hbg_pci_err_handler =3D { --=20 2.33.0 From nobody Sun Oct 5 16:16:37 2025 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02D3C2D0C89; Thu, 31 Jul 2025 13:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753970122; cv=none; b=XOzzHJsBtjkfQJxkKWiKWqiyniNi3D00oW6v9YzMjoim5w+Cfzuw3QYuo39L7n7rjv3E1DJwA6+1Bc6ESy9rNxnSywHJhTSbcWrOrmfVkzOTTyIxUMlviypM2vtIylm6Y0XAbkN+ZJpFry8NzfPtwpxkFq4lwmaTNXxadkIIB4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753970122; c=relaxed/simple; bh=IGzAvOKK4u8cz5H/9E4wl6j/drqE0AIDZkGzbOGHgnw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=J8XTKTRe7cFDv676jWY6c/TMjpQoGhWP6F9fBl3dMjQElfUgefgZfhLeP6nfPRuDeDrqpWvAIjdnY0O2Gtkx4DM5O3OFHZ08jZQ8eajrFBkNHbsFJckoKiGNCWEqu61N8b1N6TmyINmRwYzyar4w435B3oypE7CEEoBkR6HSIaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4bt9Sv70zxz14M8W; Thu, 31 Jul 2025 21:50:23 +0800 (CST) Received: from kwepemk100013.china.huawei.com (unknown [7.202.194.61]) by mail.maildlp.com (Postfix) with ESMTPS id 92D22180486; Thu, 31 Jul 2025 21:55:17 +0800 (CST) Received: from localhost.localdomain (10.90.31.46) by kwepemk100013.china.huawei.com (7.202.194.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 31 Jul 2025 21:55:16 +0800 From: Jijie Shao To: , , , , , CC: , , , , , , , , Subject: [PATCH net 2/3] net: hibmcge: fix the division by zero issue Date: Thu, 31 Jul 2025 21:47:48 +0800 Message-ID: <20250731134749.4090041-3-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20250731134749.4090041-1-shaojijie@huawei.com> References: <20250731134749.4090041-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemk100013.china.huawei.com (7.202.194.61) Content-Type: text/plain; charset="utf-8" When the network port is down, the queue is released, and ring->len is 0. In debugfs, hbg_get_queue_used_num() will be called, which may lead to a division by zero issue. This patch adds a check, if ring->len is 0, hbg_get_queue_used_num() directly returns 0. Fixes: 40735e7543f9 ("net: hibmcge: Implement .ndo_start_xmit function") Signed-off-by: Jijie Shao Reviewed-by: Simon Horman --- drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h b/drivers/ne= t/ethernet/hisilicon/hibmcge/hbg_txrx.h index 2883a5899ae2..2aecc73f3d49 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.h @@ -29,6 +29,9 @@ static inline bool hbg_fifo_is_full(struct hbg_priv *priv= , enum hbg_dir dir) =20 static inline u32 hbg_get_queue_used_num(struct hbg_ring *ring) { + if (!ring->len) + return 0; + return (ring->ntu + ring->len - ring->ntc) % ring->len; } =20 --=20 2.33.0 From nobody Sun Oct 5 16:16:37 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D8962D12F5; Thu, 31 Jul 2025 13:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753970134; cv=none; b=WqmnQ5/OpYt6QsvY2dZfWGmm5tI/79c7ykZyeMtoM2n7CxPuMHCCI8bjGhDd9zALWWDdvqT+8THfkDYIcufT8zH2ULnPv297evN+3SfpVGeAnnLs8DiplCyZqWWcr//ggO4wivzRBEJQSID+qmyaR1sOhtVtoM2yE0Q+YManMgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753970134; c=relaxed/simple; bh=uzNDS/W4/Z9idSdDiNlbGbqsPoV54gSSlG/GepAK288=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uOmu9/Ok9tYWiOpRHmeypmxJ4Ggc07/pQE/BMOoNwLfuPz2GpP6bFbgq2s13ROll2UsAL8B2BK4Lw3FUfKv4JbTruSL+X1Wled1io9dNtRUCp3GR9LL13axMRBCGcu1UDC11V3sgXqS4rbzYAx1b8WMzJLcfifj3cVO22mtxyY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4bt9Tn5nxNz2Cg0v; Thu, 31 Jul 2025 21:51:09 +0800 (CST) Received: from kwepemk100013.china.huawei.com (unknown [7.202.194.61]) by mail.maildlp.com (Postfix) with ESMTPS id 9B3E51A016C; Thu, 31 Jul 2025 21:55:23 +0800 (CST) Received: from localhost.localdomain (10.90.31.46) by kwepemk100013.china.huawei.com (7.202.194.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 31 Jul 2025 21:55:17 +0800 From: Jijie Shao To: , , , , , CC: , , , , , , , , Subject: [PATCH net 3/3] net: hibmcge: fix the np_link_fai error reporting issue Date: Thu, 31 Jul 2025 21:47:49 +0800 Message-ID: <20250731134749.4090041-4-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20250731134749.4090041-1-shaojijie@huawei.com> References: <20250731134749.4090041-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemk100013.china.huawei.com (7.202.194.61) Content-Type: text/plain; charset="utf-8" Currently, after modifying device port mode, the np_link_ok state is immediately checked. At this point, the device may not yet ready, leading to the querying of an intermediate state. This patch will poll to check if np_link is ok after modifying device port mode, and only report np_link_fail upon timeout. Fixes: e0306637e85d ("net: hibmcge: Add support for mac link exception hand= ling feature") Signed-off-by: Jijie Shao Reviewed-by: Simon Horman --- drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c b/drivers/net/= ethernet/hisilicon/hibmcge/hbg_hw.c index 8cca8316ba40..d0aa0661ecd4 100644 --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_hw.c @@ -12,6 +12,8 @@ =20 #define HBG_HW_EVENT_WAIT_TIMEOUT_US (2 * 1000 * 1000) #define HBG_HW_EVENT_WAIT_INTERVAL_US (10 * 1000) +#define HBG_MAC_LINK_WAIT_TIMEOUT_US (500 * 1000) +#define HBG_MAC_LINK_WAIT_INTERVAL_US (5 * 1000) /* little endian or big endian. * ctrl means packet description, data means skb packet data */ @@ -228,6 +230,9 @@ void hbg_hw_fill_buffer(struct hbg_priv *priv, u32 buff= er_dma_addr) =20 void hbg_hw_adjust_link(struct hbg_priv *priv, u32 speed, u32 duplex) { + u32 link_status; + int ret; + hbg_hw_mac_enable(priv, HBG_STATUS_DISABLE); =20 hbg_reg_write_field(priv, HBG_REG_PORT_MODE_ADDR, @@ -239,8 +244,14 @@ void hbg_hw_adjust_link(struct hbg_priv *priv, u32 spe= ed, u32 duplex) =20 hbg_hw_mac_enable(priv, HBG_STATUS_ENABLE); =20 - if (!hbg_reg_read_field(priv, HBG_REG_AN_NEG_STATE_ADDR, - HBG_REG_AN_NEG_STATE_NP_LINK_OK_B)) + /* wait MAC link up */ + ret =3D readl_poll_timeout(priv->io_base + HBG_REG_AN_NEG_STATE_ADDR, + link_status, + FIELD_GET(HBG_REG_AN_NEG_STATE_NP_LINK_OK_B, + link_status), + HBG_MAC_LINK_WAIT_INTERVAL_US, + HBG_MAC_LINK_WAIT_TIMEOUT_US); + if (ret) hbg_np_link_fail_task_schedule(priv); } =20 --=20 2.33.0