Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3798600pxb; Mon, 4 Oct 2021 09:50:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySw/BppXfVfowoUoiX2OM8FrhQrdV0YlBwBeTunTRriPmn369W2pXuhn4s48wx2luM5buD X-Received: by 2002:a63:200a:: with SMTP id g10mr11491268pgg.242.1633366199873; Mon, 04 Oct 2021 09:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633366199; cv=none; d=google.com; s=arc-20160816; b=UqBhGt4Uhzpc0c09uN508zKmAT0JDSXer2KZCBqjB4Pb//JuvLU+NrIg+nrBd8tDI8 yrS2IMDXuZ/jUwQfC263kY1iKdbuV+iL2jRnPe1eBXTqs3VC8GcuQeDjC0SQLnuQu08e DUCod1I6z3JnttleT7OZ7qViJ7VdAG5ogwYJquwYmstWPl24UY9qIWqLO8vBVrtC2Qln 4nM7KKPsPlfYbxE0e/pOBOnHX88N/AV/ZsYXY34D0A81KUmshImjwpx57R69ryOD5FIx U7DXgg97f1khHfYHMoXHW+Ex1EkPUX8+Hv7W/Tl8/p9rEXxe2oNA03z3hbuK6vs8kNBO T+Ww== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gH81P2QzMvW7Xwg0SXNDDLtsSywC9Fy5dQD+c9Eomts=; b=GggbFauA4336Qz8UBFwcUI+UtUmORALJK8bpu9fdzfkP/1rD1oYbt86lnoGbYaoan4 WtSZVyfx3C7zRLUu+a2KmUEp21wmHTPcExfjp5MoxAVjQTTy9wvtmEIaxIuurDwLlZ9S pCjIw1pHtjeCddAUND658HYr1cfAEXMXQ3kbL19+RLD8741iOcJbcNJuulJVvYP7fjFc jSUfG+I49xLo98ANA0HvMSdaHuAXvdaEaviauwRqJrLsqt17zLQxbtnrrpTOyJPTBAIp XIRRTIYUkiHA6uoWMj72EVgvi2dkVYrMlviuTYwiJY7a6R02kSOue3vz+8pwV87jWuOR xzUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KgtBpwHL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oj9si26409975pjb.85.2021.10.04.09.49.32; Mon, 04 Oct 2021 09:49:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KgtBpwHL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237870AbhJDNja (ORCPT + 99 others); Mon, 4 Oct 2021 09:39:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:48748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238243AbhJDNhj (ORCPT ); Mon, 4 Oct 2021 09:37:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9591061409; Mon, 4 Oct 2021 13:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353431; bh=R5uxxn9DzDyPVVxSyA7s65e0PfvERh2ByqkcVG7xAJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KgtBpwHLyOljWUl3zu58BxQ94FJmn1ZU6Wyg2htOcLX8l+wTvBO0QFpBPS+LLMSx2 LrISrYrICGXeVmI2U0iG6nEJHiBmldHf0KsTidO8sY98ssH+q9BVqRf0pHt7tRT+PY ri7uYeS2DxqjfXUNuA/9Tn4QGVz0xOdOGI4XFLi4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jian Shen , Guangbin Huang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.14 124/172] net: hns3: do not allow call hns3_nic_net_open repeatedly Date: Mon, 4 Oct 2021 14:52:54 +0200 Message-Id: <20211004125048.980281126@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jian Shen [ Upstream commit 5b09e88e1bf7fe86540fab4b5f3eece8abead39e ] hns3_nic_net_open() is not allowed to called repeatly, but there is no checking for this. When doing device reset and setup tc concurrently, there is a small oppotunity to call hns3_nic_net_open repeatedly, and cause kernel bug by calling napi_enable twice. The calltrace information is like below: [ 3078.222780] ------------[ cut here ]------------ [ 3078.230255] kernel BUG at net/core/dev.c:6991! [ 3078.236224] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP [ 3078.243431] Modules linked in: hns3 hclgevf hclge hnae3 vfio_iommu_type1 vfio_pci vfio_virqfd vfio pv680_mii(O) [ 3078.258880] CPU: 0 PID: 295 Comm: kworker/u8:5 Tainted: G O 5.14.0-rc4+ #1 [ 3078.269102] Hardware name: , BIOS KpxxxFPGA 1P B600 V181 08/12/2021 [ 3078.276801] Workqueue: hclge hclge_service_task [hclge] [ 3078.288774] pstate: 60400009 (nZCv daif +PAN -UAO -TCO BTYPE=--) [ 3078.296168] pc : napi_enable+0x80/0x84 tc qdisc sho[w 3d0e7v8 .e3t0h218 79] lr : hns3_nic_net_open+0x138/0x510 [hns3] [ 3078.314771] sp : ffff8000108abb20 [ 3078.319099] x29: ffff8000108abb20 x28: 0000000000000000 x27: ffff0820a8490300 [ 3078.329121] x26: 0000000000000001 x25: ffff08209cfc6200 x24: 0000000000000000 [ 3078.339044] x23: ffff0820a8490300 x22: ffff08209cd76000 x21: ffff0820abfe3880 [ 3078.349018] x20: 0000000000000000 x19: ffff08209cd76900 x18: 0000000000000000 [ 3078.358620] x17: 0000000000000000 x16: ffffc816e1727a50 x15: 0000ffff8f4ff930 [ 3078.368895] x14: 0000000000000000 x13: 0000000000000000 x12: 0000259e9dbeb6b4 [ 3078.377987] x11: 0096a8f7e764eb40 x10: 634615ad28d3eab5 x9 : ffffc816ad8885b8 [ 3078.387091] x8 : ffff08209cfc6fb8 x7 : ffff0820ac0da058 x6 : ffff0820a8490344 [ 3078.396356] x5 : 0000000000000140 x4 : 0000000000000003 x3 : ffff08209cd76938 [ 3078.405365] x2 : 0000000000000000 x1 : 0000000000000010 x0 : ffff0820abfe38a0 [ 3078.414657] Call trace: [ 3078.418517] napi_enable+0x80/0x84 [ 3078.424626] hns3_reset_notify_up_enet+0x78/0xd0 [hns3] [ 3078.433469] hns3_reset_notify+0x64/0x80 [hns3] [ 3078.441430] hclge_notify_client+0x68/0xb0 [hclge] [ 3078.450511] hclge_reset_rebuild+0x524/0x884 [hclge] [ 3078.458879] hclge_reset_service_task+0x3c4/0x680 [hclge] [ 3078.467470] hclge_service_task+0xb0/0xb54 [hclge] [ 3078.475675] process_one_work+0x1dc/0x48c [ 3078.481888] worker_thread+0x15c/0x464 [ 3078.487104] kthread+0x160/0x170 [ 3078.492479] ret_from_fork+0x10/0x18 [ 3078.498785] Code: c8027c81 35ffffa2 d50323bf d65f03c0 (d4210000) [ 3078.506889] ---[ end trace 8ebe0340a1b0fb44 ]--- Once hns3_nic_net_open() is excute success, the flag HNS3_NIC_STATE_DOWN will be cleared. So add checking for this flag, directly return when HNS3_NIC_STATE_DOWN is no set. Fixes: e888402789b9 ("net: hns3: call hns3_nic_net_open() while doing HNAE3_UP_CLIENT") Signed-off-by: Jian Shen Signed-off-by: Guangbin Huang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 9faa3712ea5b..b24ad9bc8e1b 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -776,6 +776,11 @@ static int hns3_nic_net_open(struct net_device *netdev) if (hns3_nic_resetting(netdev)) return -EBUSY; + if (!test_bit(HNS3_NIC_STATE_DOWN, &priv->state)) { + netdev_warn(netdev, "net open repeatedly!\n"); + return 0; + } + netif_carrier_off(netdev); ret = hns3_nic_set_real_num_queue(netdev); -- 2.33.0