Received: by 10.192.165.148 with SMTP id m20csp71522imm; Tue, 1 May 2018 17:44:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrz4IrytUwo+8C0FSG1q1Cv+bWlCooFpqcJ2S3h2+0j09htG+XOulBEEzxUiLpNm41pXsWB X-Received: by 2002:a17:902:b209:: with SMTP id t9-v6mr18186671plr.105.1525221899679; Tue, 01 May 2018 17:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525221899; cv=none; d=google.com; s=arc-20160816; b=WIk2BNI9BGs+U4SPdfTwbbqVV7cFZAP90uC4+dsD2OYC4GMv4ZCp0Ku94f8aqDkjmm MBcyOANl3IMy58IdkElSbJHQCPAOTSf4VhmfbUpRNDU6pn3cmyfr1Z/FwkwMlQmeyHpj kWAb3TK3ukQcF0745se33zwjHLV79mwbp0btQrL6kg5W+PfIdNkLLkme7ytaoAhAGvRM iSavBJCuo1xUO4zBJ4maMgPpbXH+y/xEe8zrYUlOyt2zhudz9D/OsOPv6/PHDxfr2HhT yA2PXBmphpF9NQ/F6FyBzj0U1yfMtPD/4f1PP0MvL12By95seN8XMQGY3yv1L1SgqCtj 5CYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=5iLGbWltbyhV2t3sS4MyNd+5dMdxo/9cEZd9oBJ9ipE=; b=FqDKndAO/ekKebRvLFr6dz1Y6SaXJ+edX8bFjH0gt0HP+HJbuhe+AB6q8HRypwZZGY n12VTZfBsqM1hCQaTAKb+6tii/LupcMijJHPQ3eFeMNsixKJM3RKBzXO9WU9YiU1th4l NQ/1hPYWhEyo0Rnesmb7mS1/rkhwRceBN3vbGf6LdF4RI69CjLWBSRVhSf6LdbRSFzJt DRdFF+REx4OVxkfDzxSdM+vyrnKT/fQG2qDBYJ+CoeGirf4DGDIetbpI9rj2lzyeTIJ9 TYL19C6S7YguyhRtShsWULVNYXfT3e9oCXyKgeZwd6sFzd9AARH3dLI45JUpSlcaOri2 OjCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11-v6si10244955pll.15.2018.05.01.17.44.43; Tue, 01 May 2018 17:44:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751109AbeEBAo3 (ORCPT + 99 others); Tue, 1 May 2018 20:44:29 -0400 Received: from mail5.windriver.com ([192.103.53.11]:46366 "EHLO mail5.wrs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750755AbeEBAo2 (ORCPT ); Tue, 1 May 2018 20:44:28 -0400 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id w420hCkC005543 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 1 May 2018 17:43:28 -0700 Received: from pek-lpggp4.wrs.com (128.224.153.77) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.361.1; Tue, 1 May 2018 17:43:02 -0700 From: Zumeng Chen To: , CC: , , , , Zumeng Chen , Zumeng Chen Subject: [v2 PATCH 1/1] tg3: fix meaningless hw_stats reading after tg3_halt memset 0 hw_stats Date: Wed, 2 May 2018 08:42:34 +0800 Message-ID: <20180502004234.230662-1-zumeng.chen@gmail.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zumeng Chen Reading hw_stats will get the actual data after a sucessfull tg3_reset_hw, which actually after tg3_timer_start, so TG3_FLAG_HALT is introduced to tell tg3_get_stats64 when hw_stats is ready to read. It will be set after having done memset(tp->hw_stats, 0) in tg3_halt and be clear when hw_init done. Both tg3_get_stats64 and tg3_halt are protected by tp->lock in all scope. Meanwhile, this patch is also to fix a kernel BUG_ON(in_interrupt) crash when tg3_free_consistent is stuck in tp->lock, which might get a lot of in_softirq counts(512 or so), and BUG_ON when vunmap to unmap hw->stats. ------------[ cut here ]------------ kernel BUG at /kernel-source//mm/vmalloc.c:1621! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP task: ffffffc874310000 task.stack: ffffffc8742bc000 PC is at vunmap+0x48/0x50 LR is at __dma_free+0x98/0xa0 pc : [] lr : [] pstate: 00000145 sp : ffffffc8742bfad0 x29: ffffffc8742bfad0 x28: ffffffc874310000 x27: ffffffc878931200 x26: ffffffc874530000 x25: 0000000000000003 x24: ffffff800b3aa000 x23: 00000000700bb000 x22: 0000000000000000 x21: 0000000000000000 x20: ffffffc87aafd0a0 x19: ffffff800b3aa000 x18: 0000000000000020 x17: 0000007f9e191e10 x16: ffffff8008eb0d28 x15: 000000000000000a x14: 0000000000070cc8 x13: ffffff8008c65000 x12: 00000000ffffffff x11: 000000000000000a x10: ffffffbf21d0e220 x9 : 0000000000000004 x8 : ffffff8008c65000 x7 : 0000000000003ff0 x6 : 0000000000000000 x5 : ffffff8008097f20 x4 : 0000000000000000 x3 : ffffff8008fd4fff x2 : ffffffc87b361788 x1 : ffffff800b3aafff x0 : 0000000000000201 Process connmand (pid: 785, stack limit = 0xffffffc8742bc000) Stack: (0xffffffc8742bfad0 to 0xffffffc8742c0000) fac0: ffffffc8742bfaf0 ffffff8008097fb8 fae0: 0000000000001000 ffffff80ffffffff ffffffc8742bfb30 ffffff8000b717d4 fb00: ffffffc87aafd0a0 ffffff8008a38000 ffffff800b3aa000 ffffffc874530904 fb20: ffffffc874530900 00000000700bb000 ffffffc8742bfb80 ffffff8000b80324 fb40: 0000000000000001 ffffffc874530900 0000000000000100 0000000000000200 fb60: 0000000000009003 ffffffc874530000 0000000000000003 ffffffc874530000 fb80: ffffffc8742bfbd0 ffffff8000b8aa5c ffffffc874530900 ffffffc874530000 fba0: 00000000ffff0001 0000000000000000 0000000000009003 ffffffc878931210 fbc0: 0000000000009002 ffffffc874530000 ffffffc8742bfc00 ffffff80088bf44c fbe0: ffffffc874530000 ffffffc8742bfc50 00000000ffff0001 ffffffc874310000 fc00: ffffffc8742bfc30 ffffff80088bf5e4 ffffffc874530000 00000000ffff9002 fc20: ffffffc8742bfc40 ffffffc874530000 ffffffc8742bfc60 ffffff80088c9d58 fc40: ffffffc874530000 ffffff80088c9d34 ffffffc874530080 ffffffc874530080 fc60: ffffffc8742bfca0 ffffff80088c9e4c ffffffc874530000 0000000000009003 fc80: 0000000000008914 0000000000000000 0000007ffd94ba10 ffffffc8742bfd38 fca0: ffffffc8742bfcd0 ffffff80089509f8 0000000000000000 00000000ffffff9d fcc0: 0000000000008914 0000000000000000 ffffffc8742bfd60 ffffff8008953088 fce0: 0000000000008914 ffffffc874b49b80 0000007ffd94ba10 ffffff8008e9b400 fd00: 0000000000000004 0000007ffd94ba10 0000000000000124 000000000000001d fd20: ffffff8008a32000 ffffff8008e9b400 0000000000000004 0000000034687465 fd40: 0000000000000000 0000000000009002 0000000000000000 0000000000000000 fd60: ffffffc8742bfd90 ffffff80088a1720 ffffffc874b49b80 0000000000008914 fd80: 0000007ffd94ba10 0000000000000000 ffffffc8742bfdc0 ffffff80088a2648 fda0: 0000000000008914 0000007ffd94ba10 ffffff8008e9b400 ffffffc878a73c00 fdc0: ffffffc8742bfe00 ffffff800822e9e0 0000000000008914 0000007ffd94ba10 fde0: ffffffc874b49bb0 ffffffc8747e5800 ffffffc8742bfe50 ffffff800823cd58 fe00: ffffffc8742bfe80 ffffff800822f0ec 0000000000000000 ffffffc878a73c00 fe20: ffffffc878a73c00 0000000000000004 0000000000008914 0000000000080000 fe40: ffffffc8742bfe80 ffffff800822f0b0 0000000000000000 ffffffc878a73c00 fe60: ffffffc878a73c00 0000000000000004 0000000000008914 ffffff8008083730 fe80: 0000000000000000 ffffff8008083730 0000000000000000 00000048771fb000 fea0: ffffffffffffffff 0000007f9e191e1c 0000000000000000 0000000000000015 fec0: 0000000000000004 0000000000008914 0000007ffd94ba10 0000000000000000 fee0: 000000000000002f 0000000000000004 0000000000000010 0000000000000000 ff00: 000000000000001d 0000000fffffffff 0101010101010101 0000000000000000 ff20: 6532336338646634 00656c6261635f38 0000007f9e46a220 0000007f9e45f318 ff40: 00000000004c1a58 0000007f9e191e10 00000000000006df 0000000000000000 ff60: 0000000000000004 00000000004c6470 00000000004c3c40 0000000000512d20 ff80: 0000000000000001 0000000000000000 0000000000000000 0000000000000000 ffa0: 0000000000000000 0000007ffd94b9f0 0000000000463dec 0000007ffd94b9f0 ffc0: 0000007f9e191e1c 0000000000000000 0000000000000004 000000000000001d ffe0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 Call trace: Exception stack(0xffffffc8742bf900 to 0xffffffc8742bfa30) f900: ffffff800b3aa000 0000008000000000 ffffffc8742bfad0 ffffff80081eb420 f920: ffffff8000000000 ffffff80081a58ec ffffffc8742bf940 ffffff80081c3ea8 f940: ffffffc8742bf990 ffffff80081a591c ffffffc8742bf970 ffffff8008a1d89c f960: ffffff8008eb1780 ffffff8008eb1780 ffffffc8742bf990 ffffff80081a59dc f980: ffffffbf21c4ae00 ffffffbf00000000 ffffffc8742bfa20 ffffff80081a5db4 f9a0: 0000000000000201 ffffff800b3aafff ffffffc87b361788 ffffff8008fd4fff f9c0: 0000000000000000 ffffff8008097f20 0000000000000000 0000000000003ff0 f9e0: ffffff8008c65000 0000000000000004 ffffffbf21d0e220 000000000000000a fa00: 00000000ffffffff ffffff8008c65000 0000000000070cc8 000000000000000a fa20: ffffff8008eb0d28 0000007f9e191e10 [] vunmap+0x48/0x50 [] __dma_free+0x98/0xa0 [] tg3_free_consistent+0x14c/0x190 [tg3] [] tg3_stop+0x204/0x238 [tg3] [] tg3_close+0x34/0x98 [tg3] [] __dev_close_many+0x94/0xe8 [] __dev_close+0x34/0x50 [] __dev_change_flags+0xa0/0x160 [] dev_change_flags+0x34/0x70 [] devinet_ioctl+0x740/0x808 [] inet_ioctl+0x140/0x158 [] sock_do_ioctl+0x40/0x88 [] sock_ioctl+0x238/0x368 [] do_vfs_ioctl+0xb0/0x730 [] SyS_ioctl+0x8c/0xa8 [] el0_svc_naked+0x24/0x28 Code: f9400bf3 a8c27bfd d65f03c0 d503201f (d4210000) ---[ end trace e214990b7cc445ce ]--- Kernel panic - not syncing: Fatal exception in interrupt Signed-off-by: Zumeng Chen --- V2 changes: As Michael mentioned, use TG3_FLAG_HALT to flag the interface down. Sanity tests include building and runtime, passed. Cheers, Zumeng drivers/net/ethernet/broadcom/tg3.c | 13 ++++++++----- drivers/net/ethernet/broadcom/tg3.h | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c index 537d571..690cdc6 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -8723,14 +8723,11 @@ static void tg3_free_consistent(struct tg3 *tp) tg3_mem_rx_release(tp); tg3_mem_tx_release(tp); - /* Protect tg3_get_stats64() from reading freed tp->hw_stats. */ - tg3_full_lock(tp, 0); if (tp->hw_stats) { dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), tp->hw_stats, tp->stats_mapping); tp->hw_stats = NULL; } - tg3_full_unlock(tp); } /* @@ -9334,6 +9331,7 @@ static int tg3_halt(struct tg3 *tp, int kind, bool silent) /* And make sure the next sample is new data */ memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); + tg3_flag_set(tp, HALT); } return err; @@ -10732,6 +10730,7 @@ static int tg3_reset_hw(struct tg3 *tp, bool reset_phy) */ static int tg3_init_hw(struct tg3 *tp, bool reset_phy) { + int retval; /* Chip may have been just powered on. If so, the boot code may still * be running initialization. Wait for it to finish to avoid races in * accessing the hardware. @@ -10743,7 +10742,11 @@ static int tg3_init_hw(struct tg3 *tp, bool reset_phy) tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); - return tg3_reset_hw(tp, reset_phy); + retval = tg3_reset_hw(tp, reset_phy); + if (retval == 0) + tg3_flag_clear(tp, HALT); + + return retval; } #ifdef CONFIG_TIGON3_HWMON @@ -14155,7 +14158,7 @@ static void tg3_get_stats64(struct net_device *dev, struct tg3 *tp = netdev_priv(dev); spin_lock_bh(&tp->lock); - if (!tp->hw_stats) { + if (!tp->hw_stats || tg3_flag(tp, HALT)) { *stats = tp->net_stats_prev; spin_unlock_bh(&tp->lock); return; diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h index 3b5e98e..c61d83c 100644 --- a/drivers/net/ethernet/broadcom/tg3.h +++ b/drivers/net/ethernet/broadcom/tg3.h @@ -3102,6 +3102,7 @@ enum TG3_FLAGS { TG3_FLAG_ROBOSWITCH, TG3_FLAG_ONE_DMA_AT_ONCE, TG3_FLAG_RGMII_MODE, + TG3_FLAG_HALT, /* Add new flags before this comment and TG3_FLAG_NUMBER_OF_FLAGS */ TG3_FLAG_NUMBER_OF_FLAGS, /* Last entry in enum TG3_FLAGS */ -- 2.9.3