Received: by 10.213.65.68 with SMTP id h4csp2117463imn; Sun, 8 Apr 2018 20:08:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Xx8vPbVfmU6jdpcJouO4q/TtgnEbqc8M3PSeqICm5PrMC3bkSNgPo9xDezssqbWs3ojvg X-Received: by 2002:a17:902:9046:: with SMTP id w6-v6mr7662022plz.393.1523243310651; Sun, 08 Apr 2018 20:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243310; cv=none; d=google.com; s=arc-20160816; b=0Q8ix1ZbIvsf++gYdgR8cxAsjICGA4PheVU6UPkIk4rLueF4l6JKjNjYdpRoW6ES3Y kLtrgnwcnq0bZwTLHfF3JMLdkBCHxzeM1s0231ev4kiwm/lN9CmQJEjTHKEzEG6InnPU szz5z0NHIvW9sdOaC+XxsPdlZtHocAJC7OmFrmDTTGXHwFqwex3bIJ+soQdXSqMjKlaL 4Z7x7db7RR3X11w+eF7ExY93mQXn3LtsdS/LXKy3H2iNjdtGqizSWPNYzm6U/HnJhv0E CGjlWzWPWYSHkzwjfe3eZD2eD0DaH/nQzRHNg1dGVK6MOQ+HDQJmXb20hqz+Fcbpb25W FVHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=3pT+yLVSQRSrrHhHWd0KcabLHfgIsxHV1ndtmS1C31M=; b=XJvu7kmCvwMfpbk/1Ev3Naa07y5vcCVoo2InHTETllABvQ6icsSFGO+5F0Aw+SOeHf cNSB2F1TPeATKl9PyGCSVBlzg1EAbsfg47UrbTladAH0DPLuA3Wl/Ia3bwoIQNKpqNJp LwviXRSoIBSE+pDLVjNVgXTOmd6RnSrkq55ZSzPx18revkmpooqCWdrvYLLMVjxxA80V jGlv30/GalCo8XVWfCVPeGCJBt5nULiF3Q90qylTHpRs+kz3Q6UK5yF99sPwPZOLaCuN BvKB2Q9QpOiIdh2J6v7CxLGqRDxxKV44F4tIFGv1L2IN5EDQA/N6FYg1ISZdYZ+tkZQ7 TY8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=maOIk32V; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l128si10573760pgl.248.2018.04.08.20.07.53; Sun, 08 Apr 2018 20:08:30 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=maOIk32V; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757637AbeDICBo (ORCPT + 99 others); Sun, 8 Apr 2018 22:01:44 -0400 Received: from mail-sn1nam01on0103.outbound.protection.outlook.com ([104.47.32.103]:45281 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756455AbeDIAcN (ORCPT ); Sun, 8 Apr 2018 20:32:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=3pT+yLVSQRSrrHhHWd0KcabLHfgIsxHV1ndtmS1C31M=; b=maOIk32Vh2cGQYLqoYhgFSCgP+V1W6rlo0CCwxd0CWIDY/PvvF4now5Vn3pdmTyGAuaOhTL/Jq/7V+Adjinv+ymLAimWUhrzIDjAaKsmJiMhb6dEInVbh2X6e7nAvIfq0vHLIdTMJB1HF8edCRiniRLc6QcLFz15ty+urSS24ns= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0870.namprd21.prod.outlook.com (10.167.110.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:32:08 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:32:08 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Sean Wang , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 201/293] net: ethernet: mediatek: fixed deadlock captured by lockdep Thread-Topic: [PATCH AUTOSEL for 4.9 201/293] net: ethernet: mediatek: fixed deadlock captured by lockdep Thread-Index: AQHTz5lErdtSKt2nF06XNNtp3Z4q+A== Date: Mon, 9 Apr 2018 00:25:31 +0000 Message-ID: <20180409002239.163177-201-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0870;7:gVJkjmj1mhMnwqm0YsX8aUQcEEc2Fg0APD2+oHnGx05i0uaEvfFMJN9zD+JKYEOEFKRy2i807ZNV79i3vw9oF3YCAAGDtVey4Y9/NSPFuT+cjATUfM7XORVwmeo4TG7b2JCWawJbrozNlnmd3biOAypcr3T7mAcrVxN6FaDHV09Fn9nILexOuWNOkWL9KO/oD+c/IvBT8HgEDuKtvRCr0SMU2zjn0uKmJgGNqiOqn6QPLj+mOEg6QU+rmGlsV+kA;20:Q5YvdO3tS7sx9iZUH8nwIiSIR0ioGSOVe8Gp26tqlpb9PGTQEeCQfKu7xixf/4d3dAGX3wwAnD+SXe4XDwLvjYa3vbPv3wsAW4SwnTxjU6Y5O6OPKKBFe7OawkfyAb6fuSvqJssoH4fgTVUgxqmTN25HTLsZeBYZm9xWHRKbqmM= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: e6d6c820-8152-4a5e-8db1-08d59db15398 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0870; x-ms-traffictypediagnostic: DM5PR2101MB0870: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231221)(944501327)(52105095)(93006095)(93001095)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0870;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0870; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(979002)(346002)(39860400002)(366004)(396003)(39380400002)(376002)(199004)(189003)(53936002)(2906002)(6512007)(102836004)(2616005)(76176011)(14454004)(446003)(10090500001)(11346002)(476003)(486006)(107886003)(59450400001)(2900100001)(97736004)(66066001)(6506007)(6436002)(106356001)(99286004)(105586002)(3660700001)(6116002)(86612001)(3280700002)(6666003)(2501003)(10290500003)(26005)(8676002)(8936002)(478600001)(68736007)(5250100002)(5660300001)(316002)(4326008)(72206003)(186003)(110136005)(6486002)(7736002)(25786009)(3846002)(86362001)(36756003)(22452003)(81156014)(81166006)(305945005)(54906003)(1076002)(22906009)(217873001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0870;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: W5j32HTcIzfSCVM1BGDvemKUPfZR8PSlBtwkiSrMqU3tjZOyByX9Dd4WKnvQ4QG1ys2lIlMmLIfG6CKz4gHN+hu37aGKHGvc8JYFWRLu46VmLcTAScOoxPb4AK1v1QwSRrWRhr/4I8+VDjnK8iVaf0Bk2coIg1xPDxNgkWAvuCmAe6aK4jdfUNDw458ykVGYNFTUws9ujhjBIfFYTOPLhq+AAPvadDub93OXBWWVh3E881ByNFyyymBWLqTdbrEJAZd9vkK+wta3cjg3NxSKNxo4NBsCMk3Z8Tl/V3PSog2Nhirx6MFknBHKlOmAh+wPzjAtH2rVcXV7mQhSLuTriTmRLWKAxEMCgwU7Og9ie5nHkvw/k9zWnxAYnp8CwrxcZ46oX+kWaNE+cAeQgSq31lXGtFohV+yQ/KgIOzhWKC0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6d6c820-8152-4a5e-8db1-08d59db15398 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:25:31.1440 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0870 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Wang [ Upstream commit 8d32e0624392bb4abfbe122f754757a4cb326d7f ] Lockdep found an inconsistent lock state when mtk_get_stats64 is called in user context while NAPI updates MAC statistics in softirq. Use spin_trylock_bh/spin_unlock_bh fix following lockdep warning. [ 81.321030] WARNING: inconsistent lock state [ 81.325266] 4.12.0-rc1-00035-gd9dda65 #32 Not tainted [ 81.330273] -------------------------------- [ 81.334505] inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage. [ 81.340464] ksoftirqd/0/7 [HC0[0]:SC1[1]:HE1:SE0] takes: [ 81.345731] (&syncp->seq#2){+.?...}, at: [] mtk_handle_status= _irq.part.6+0x70/0x84 [ 81.354219] {SOFTIRQ-ON-W} state was registered at: [ 81.359062] lock_acquire+0xfc/0x2b0 [ 81.362696] mtk_stats_update_mac+0x60/0x2c0 [ 81.367017] mtk_get_stats64+0x17c/0x18c [ 81.370995] dev_get_stats+0x48/0xbc [ 81.374628] rtnl_fill_stats+0x48/0x128 [ 81.378520] rtnl_fill_ifinfo+0x4ac/0xd1c [ 81.382584] rtmsg_ifinfo_build_skb+0x7c/0xe0 [ 81.386991] rtmsg_ifinfo.part.5+0x24/0x54 [ 81.391139] rtmsg_ifinfo+0x24/0x28 [ 81.394685] __dev_notify_flags+0xa4/0xac [ 81.398749] dev_change_flags+0x50/0x58 [ 81.402640] devinet_ioctl+0x768/0x85c [ 81.406444] inet_ioctl+0x1a4/0x1d0 [ 81.409990] sock_ioctl+0x16c/0x33c [ 81.413538] do_vfs_ioctl+0xb4/0xa34 [ 81.417169] SyS_ioctl+0x44/0x6c [ 81.420458] ret_fast_syscall+0x0/0x1c [ 81.424260] irq event stamp: 3354692 [ 81.427806] hardirqs last enabled at (3354692): [] net_rx_act= ion+0xc0/0x504 [ 81.435660] hardirqs last disabled at (3354691): [] net_rx_act= ion+0x8c/0x504 [ 81.443515] softirqs last enabled at (3354106): [] __do_softi= rq+0x4b4/0x614 [ 81.451370] softirqs last disabled at (3354109): [] run_ksofti= rqd+0x44/0x80 [ 81.459134] [ 81.459134] other info that might help us debug this: [ 81.465608] Possible unsafe locking scenario: [ 81.465608] [ 81.471478] CPU0 [ 81.473900] ---- [ 81.476321] lock(&syncp->seq#2); [ 81.479701] [ 81.482294] lock(&syncp->seq#2); [ 81.485847] [ 81.485847] *** DEADLOCK *** [ 81.485847] [ 81.491720] 1 lock held by ksoftirqd/0/7: [ 81.495693] #0: (&(&mac->hw_stats->stats_lock)->rlock){+.+...}, at: [<= c054ba14>] mtk_handle_status_irq.part.6+0x48/0x84 [ 81.506579] [ 81.506579] stack backtrace: [ 81.510904] CPU: 0 PID: 7 Comm: ksoftirqd/0 Not tainted 4.12.0-rc1-00035= -gd9dda65 #32 [ 81.518668] Hardware name: Mediatek Cortex-A7 (Device Tree) [ 81.524208] [] (unwind_backtrace) from [] (show_stac= k+0x20/0x24) [ 81.531899] [] (show_stack) from [] (dump_stack+0xb4= /0xe0) [ 81.539072] [] (dump_stack) from [] (print_usage_bug= +0x234/0x2e0) [ 81.546846] [] (print_usage_bug) from [] (mark_lock+= 0x63c/0x7bc) [ 81.554532] [] (mark_lock) from [] (__lock_acquire+0= x654/0x1bfc) [ 81.562217] [] (__lock_acquire) from [] (lock_acquir= e+0xfc/0x2b0) [ 81.569990] [] (lock_acquire) from [] (mtk_stats_upd= ate_mac+0x60/0x2c0) [ 81.578283] [] (mtk_stats_update_mac) from [] (mtk_h= andle_status_irq.part.6+0x70/0x84) [ 81.587865] [] (mtk_handle_status_irq.part.6) from [= ] (mtk_napi_tx+0x358/0x37c) [ 81.596845] [] (mtk_napi_tx) from [] (net_rx_action+= 0x244/0x504) [ 81.604533] [] (net_rx_action) from [] (__do_softirq= +0x134/0x614) [ 81.612306] [] (__do_softirq) from [] (run_ksoftirqd= +0x44/0x80) [ 81.619907] [] (run_ksoftirqd) from [] (smpboot_thre= ad_fn+0x14c/0x25c) [ 81.628110] [] (smpboot_thread_fn) from [] (kthread+= 0x150/0x180) [ 81.635798] [] (kthread) from [] (ret_from_fork+0x14= /0x24) Signed-off-by: Sean Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethe= rnet/mediatek/mtk_eth_soc.c index 20de37a414fe..d76f65f9d8dd 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -470,9 +470,9 @@ static struct rtnl_link_stats64 *mtk_get_stats64(struct= net_device *dev, unsigned int start; =20 if (netif_running(dev) && netif_device_present(dev)) { - if (spin_trylock(&hw_stats->stats_lock)) { + if (spin_trylock_bh(&hw_stats->stats_lock)) { mtk_stats_update_mac(mac); - spin_unlock(&hw_stats->stats_lock); + spin_unlock_bh(&hw_stats->stats_lock); } } =20 @@ -2151,9 +2151,9 @@ static void mtk_get_ethtool_stats(struct net_device *= dev, return; =20 if (netif_running(dev) && netif_device_present(dev)) { - if (spin_trylock(&hwstats->stats_lock)) { + if (spin_trylock_bh(&hwstats->stats_lock)) { mtk_stats_update_mac(mac); - spin_unlock(&hwstats->stats_lock); + spin_unlock_bh(&hwstats->stats_lock); } } =20 --=20 2.15.1