Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp919906rwb; Fri, 28 Jul 2023 01:41:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlG6Pmqtywu1VdWRfzNmcQq8c5D0q1EQgQmZvycAyzMgCTiX5mjmMFQbTSoM7FfwBvrmxbKx X-Received: by 2002:a05:6a00:13a1:b0:682:2fea:39f0 with SMTP id t33-20020a056a0013a100b006822fea39f0mr1365256pfg.5.1690533683634; Fri, 28 Jul 2023 01:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690533683; cv=none; d=google.com; s=arc-20160816; b=Ce0ey056Ae/lrEpFQJ7hKaK0mf+dckcL/lFBTizoJ2DPpd+mfpPkXwQQlT03LzR/vi jkU4JvYza6+eb5Bbk14zGoJto1ftIhtIVuTYiVZfA+1g55B8RrhLppkbO2fAdgIqzKI6 3X1u6McIj1WRZ00Vl7HBms6KH5lKzB4pF3lWsGUA45tfDi6pkw4ve2MKcJ2Qn36HrFb2 ylxysRiNDzAQVrPrkDApek3qzOS5IHngJsWQPg5UqM0sb18LHvUB3uigAMY/OTIQizKf U8f0vPpS5WqCFVCfTItmL9MfgMjm4CQktJfTk48+p9fk+KNzDb/a/5SKibFJpqujz36B Ls/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oCTnLZE8VsrAZw2z8PAlf589WsyFsRbkcsIfv4GV5n0=; fh=rhoMx0VN1EBFBgM+MRLh5DDELNHeiDru4nB1GuImL/0=; b=M7HbfatcwmCtN4G4mtSlb3WfvFs7YJGl5yLo141FkCsbWIp03ozIi08V9bR+B7Zdl3 w0y+kBu5JUYaXDQsIXolrNNtxE7B9LUp3SIP9HHQmg8ygHh+ykX+nN+eX2rrhCrYfbEL 0ISBzYXoYTqRzwtFnSB08yoLZKiqguzCAJFpTz2zeiAQ1A8FggEx6VgClJDIdWW8BYAv 32j1m5fsg7kJ4NfxtkwI3ykoyuYNGe8MPPyoUi8dB3HZ0i1gIsKwOQPcfSuPyjp0sbHt G8/EiFI0lDssEMuU2efMd4LbHfHrLM1qEk3ACa2mPmu/pGI/yIKaoTovilVf4O3LecQq 5cDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020a639303000000b00543cbd73c02si2646758pge.409.2023.07.28.01.41.11; Fri, 28 Jul 2023 01:41:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234679AbjG1IEc (ORCPT + 99 others); Fri, 28 Jul 2023 04:04:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234638AbjG1IDw (ORCPT ); Fri, 28 Jul 2023 04:03:52 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 658D630E0; Fri, 28 Jul 2023 01:01:53 -0700 (PDT) Received: from kwepemm600007.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RC0Pb6MhmzNm62; Fri, 28 Jul 2023 15:58:27 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemm600007.china.huawei.com (7.193.23.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 28 Jul 2023 16:01:50 +0800 From: Jijie Shao To: , , , , , CC: , , , , , , , Subject: [PATCH net 6/6] net: hns3: fix deadlock issue when externel_lb and reset are executed together Date: Fri, 28 Jul 2023 15:58:40 +0800 Message-ID: <20230728075840.4022760-7-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230728075840.4022760-1-shaojijie@huawei.com> References: <20230728075840.4022760-1-shaojijie@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600007.china.huawei.com (7.193.23.208) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yonglong Liu When externel_lb and reset are executed together, a deadlock may occur: [ 3147.217009] INFO: task kworker/u321:0:7 blocked for more than 120 seconds. [ 3147.230483] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 3147.238999] task:kworker/u321:0 state:D stack: 0 pid: 7 ppid: 2 flags:0x00000008 [ 3147.248045] Workqueue: hclge hclge_service_task [hclge] [ 3147.253957] Call trace: [ 3147.257093] __switch_to+0x7c/0xbc [ 3147.261183] __schedule+0x338/0x6f0 [ 3147.265357] schedule+0x50/0xe0 [ 3147.269185] schedule_preempt_disabled+0x18/0x24 [ 3147.274488] __mutex_lock.constprop.0+0x1d4/0x5dc [ 3147.279880] __mutex_lock_slowpath+0x1c/0x30 [ 3147.284839] mutex_lock+0x50/0x60 [ 3147.288841] rtnl_lock+0x20/0x2c [ 3147.292759] hclge_reset_prepare+0x68/0x90 [hclge] [ 3147.298239] hclge_reset_subtask+0x88/0xe0 [hclge] [ 3147.303718] hclge_reset_service_task+0x84/0x120 [hclge] [ 3147.309718] hclge_service_task+0x2c/0x70 [hclge] [ 3147.315109] process_one_work+0x1d0/0x490 [ 3147.319805] worker_thread+0x158/0x3d0 [ 3147.324240] kthread+0x108/0x13c [ 3147.328154] ret_from_fork+0x10/0x18 In externel_lb process, the hns3 driver call napi_disable() first, then the reset happen, then the restore process of the externel_lb will fail, and will not call napi_enable(). When doing externel_lb again, napi_disable() will be double call, cause a deadlock of rtnl_lock(). This patch use the HNS3_NIC_STATE_DOWN state to protect the calling of napi_disable() and napi_enable() in externel_lb process, just as the usage in ndo_stop() and ndo_start(). Fixes: 04b6ba143521 ("net: hns3: add support for external loopback test") Signed-off-by: Yonglong Liu Signed-off-by: Jijie Shao --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 823e6d2e85f5..7da54a5b81d1 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -5855,6 +5855,9 @@ void hns3_external_lb_prepare(struct net_device *ndev, bool if_running) if (!if_running) return; + if (test_and_set_bit(HNS3_NIC_STATE_DOWN, &priv->state)) + return; + netif_carrier_off(ndev); netif_tx_disable(ndev); @@ -5883,7 +5886,16 @@ void hns3_external_lb_restore(struct net_device *ndev, bool if_running) if (!if_running) return; - hns3_nic_reset_all_ring(priv->ae_handle); + if (hns3_nic_resetting(ndev)) + return; + + if (!test_bit(HNS3_NIC_STATE_DOWN, &priv->state)) + return; + + if (hns3_nic_reset_all_ring(priv->ae_handle)) + return; + + clear_bit(HNS3_NIC_STATE_DOWN, &priv->state); for (i = 0; i < priv->vector_num; i++) hns3_vector_enable(&priv->tqp_vector[i]); -- 2.30.0