Received: by 10.223.176.5 with SMTP id f5csp891775wra; Sat, 3 Feb 2018 12:43:31 -0800 (PST) X-Google-Smtp-Source: AH8x22663Di5kVphqj4HzlBHj03Y5AMBNQNuMDBvQ4euMreQZHUdyJ8HfyoDSvpdFC/O5qv+v2JO X-Received: by 2002:a17:902:aa85:: with SMTP id d5-v6mr40786051plr.239.1517690610924; Sat, 03 Feb 2018 12:43:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517690610; cv=none; d=google.com; s=arc-20160816; b=ODhMlCzhJx9H0j3/og7PLeI8zJMy0EP6uC7fcZUO5hA14BtnMYKcIh1sdWLqwcU/Y3 Jtohnlror7XT6XwQLKzz3TIInMtzxSIdo3nVEqoCyG+cp8EmUi0rv6FYcl6yVKXvy1lU RgIg76IqC6ALtgJlF9/3IvEVq/XV9SGUepLNqeJ4qCzEXC90DoWyywpOsM1VSIo1srMp QqynqdQkzNXwBhDs6G/Hd1QhrZBZ3+fEwVrPZMIRF3DjbfY6+Rlpvee4USUuEMFDTTcQ gDqZhd1EIn6aOJqRkSG8Z8S2AlcSTtV0AkVlo570905THEtXeyKz0AQbEnuGuJnr6QAo mqxg== 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=6MNxDckMRIJ9OBH3456lro0nG/bAWVPv7AJjnsKfjWg=; b=PnKcwwtAs7X4ocgMmymlCsO2LsqUUY2C5V78se1iPRegl3tbfTbYQ/ub8hr717j/C5 1OypV1ffUTdWRb88fo77f79y2SOuO0fkbn1ilRkRt05376jHvk/VXOjkhAJdR+fWRWgC otZf2n1/IXzkw10Y+4wOnItotk6CRX5YxwhH26enoAO4ES8IR6oI/QasU8GR0VpA16Au zNemg4QXEzB87G3Gat1LpHSht+2M9gYq9cKNvUv2Gx9dxzTsXLo2N/ZLiIObGDl7KJIH vfd0J/YJO4FU77gf/w/YmEEAxbqf9cXM01bFoRh81euC2hbOKXCj7i818w4NCVpGqnBh AsRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=iIy+Wepl; 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 i2si4169223pfi.190.2018.02.03.12.43.16; Sat, 03 Feb 2018 12:43:30 -0800 (PST) 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=iIy+Wepl; 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 S1754706AbeBCSak (ORCPT + 99 others); Sat, 3 Feb 2018 13:30:40 -0500 Received: from mail-by2nam03on0111.outbound.protection.outlook.com ([104.47.42.111]:44500 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753313AbeBCSEv (ORCPT ); Sat, 3 Feb 2018 13:04:51 -0500 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=6MNxDckMRIJ9OBH3456lro0nG/bAWVPv7AJjnsKfjWg=; b=iIy+Wepl9TbAORhSBI77NMISe9zpcdp12RSMWWmfdSY+XfSApwCLkiQoHcdlz2GcJFktWNOxFbgJqUQbwqZQyCY/vltRqSQuXQtgfVYnuTsVqioaLTtM7g5fcE9l+cGzqeb0H9eMiV4ldVMZTsip7HANfWKVK5beKafE38+3J1E= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB1105.namprd21.prod.outlook.com (52.132.24.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.485.5; Sat, 3 Feb 2018 18:02:08 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:02:08 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Erez Shitrit , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 074/110] IB/ipoib: Fix race condition in neigh creation Thread-Topic: [PATCH AUTOSEL for 4.14 074/110] IB/ipoib: Fix race condition in neigh creation Thread-Index: AQHTnRj80YjHlLfYFk+cO/w9ycU3sQ== Date: Sat, 3 Feb 2018 18:01:17 +0000 Message-ID: <20180203180015.29073-74-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-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;BL0PR2101MB1105;6:FVFM3xfsxpohUiDiFdYg/tCEOYImDBVYlqj98zHBeA8e3o/D39HD4xVINqzsArNu6C2dbL4FUAju4wngj42PLfJRv70H9q5bXMWUbcMJYDTft/+1L5BgC+UXyHu5it5zaXEme6FpwPlb+zwmd1RpkIyuqh7k2Qo7yYDDw/ll+bvRhnv4sYi3jVv98B7JLzN9cA/cq5iPiHkJpHB2bQyX6y0BgpgmZSJkViZDUjKMQiAPkKBRPH6kN5ZFA8LYRUCBED2RYHlVIly7F3yXPrSDEaTNXTyKF6TMQOAzh2436ziBmPN/4eCL7G0246W9J2ED7QaSPT8dHqRB0ezojYGf43+rcE+bL62rrQNVl50pp2nVf4VfuPmgJuI7HgOTEe2w;5:Dg90w8MKTyfiPFqP/jH9lK78aoakXv/qjZiyVFe4EUvEpMyNFBYM1nrKHFE/5UofUY2Vz1aViOkvYzEe0P4aybOx3396Udqd0y5Y7CBO/xpYuar6VcN/IXXWWu+S8gtP9VGkG0hPA0spdzis6TIA7QPL/MS7e4n2Vsbxeh7IaFY=;24:h5hK62D8+Qw1Zx9XweM08BMwd3YjV4StYijl5k7lOa9oxDfLO+QiAMEe2GCJOBCbUHq5uxW6g8xBKMjSFq0swVDjx76zQizbLpAu5LNdf6Y=;7:sR/1izBEx/P8QzntKlpQXPkkycEoHOZBTNr7Fomlk9B5iI+jv3m0GVZC52oQchu28gSf0oROUJqNy2H6K6Rk+EZnEsUD0URtA9ErlUzgCqV7XwHWpXZpR2Aavw5PP1U2+XuBXe66vFnScJKfMAwXhX/zXylk3Ic4MtIrlnU5Ab6TwqF9Q3fEmewH2/qya+xvlZknrResT/fYp2AGofrgcJ9KEcmnYw+xMxoX97Y19OCJvvATfJ1LGx/PKtsfprEC x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: b4b9b245-3d07-4848-9653-08d56b303e16 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB1105; x-ms-traffictypediagnostic: BL0PR2101MB1105: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231101)(2400082)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:BL0PR2101MB1105;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB1105; x-forefront-prvs: 05724A8921 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(396003)(39380400002)(39860400002)(346002)(376002)(199004)(189003)(6346003)(97736004)(6512007)(7736002)(26005)(305945005)(102836004)(105586002)(68736007)(5250100002)(8936002)(59450400001)(6486002)(6436002)(106356001)(6506007)(81166006)(81156014)(2501003)(2906002)(10090500001)(99286004)(66066001)(54906003)(6116002)(3846002)(36756003)(1076002)(8676002)(110136005)(107886003)(72206003)(2950100002)(478600001)(10290500003)(22452003)(6666003)(5660300001)(2900100001)(4326008)(25786009)(14454004)(316002)(86362001)(53936002)(3280700002)(186003)(3660700001)(76176011)(86612001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB1105;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: WTJdPNdXbgDsgGg0mu3xINuNNaysiOj+gKi6n2xrbpdsISdL+ISB4OzJ2ojEP1gmNHTsh3Q5F7vMRJvIuvanJw== 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: b4b9b245-3d07-4848-9653-08d56b303e16 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:01:17.2534 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1105 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Erez Shitrit [ Upstream commit 16ba3defb8bd01a9464ba4820a487f5b196b455b ] When using enhanced mode for IPoIB, two threads may execute xmit in parallel to two different TX queues while the target is the same. In this case, both of them will add the same neighbor to the path's neigh link list and we might see the following message: list_add double add: new=3Dffff88024767a348, prev=3Dffff88024767a348... WARNING: lib/list_debug.c:31__list_add_valid+0x4e/0x70 ipoib_start_xmit+0x477/0x680 [ib_ipoib] dev_hard_start_xmit+0xb9/0x3e0 sch_direct_xmit+0xf9/0x250 __qdisc_run+0x176/0x5d0 __dev_queue_xmit+0x1f5/0xb10 __dev_queue_xmit+0x55/0xb10 Analysis: Two SKB are scheduled to be transmitted from two cores. In ipoib_start_xmit, both gets NULL when calling ipoib_neigh_get. Two calls to neigh_add_path are made. One thread takes the spin-lock and calls ipoib_neigh_alloc which creates the neigh structure, then (after the __path_find) the neigh is added to the path's neigh link list. When the second thread enters the critical section it also calls ipoib_neigh_alloc but in this case it gets the already allocated ipoib_neigh structure, which is already linked to the path's neigh link list and adds it again to the list. Which beside of triggering the list, it creates a loop in the linked list. This loop leads to endless loop inside path_rec_completion. Solution: Check list_empty(&neigh->list) before adding to the list. Add a similar fix in "ipoib_multicast.c::ipoib_mcast_send" Fixes: b63b70d87741 ('IPoIB: Use a private hash table for path lookup in xm= it path') Signed-off-by: Erez Shitrit Reviewed-by: Alex Vesker Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/ipoib/ipoib_main.c | 25 ++++++++++++++++++----= --- drivers/infiniband/ulp/ipoib/ipoib_multicast.c | 5 ++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband= /ulp/ipoib/ipoib_main.c index dcc77014018d..f6935811ef3f 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c @@ -903,8 +903,8 @@ static int path_rec_start(struct net_device *dev, return 0; } =20 -static void neigh_add_path(struct sk_buff *skb, u8 *daddr, - struct net_device *dev) +static struct ipoib_neigh *neigh_add_path(struct sk_buff *skb, u8 *daddr, + struct net_device *dev) { struct ipoib_dev_priv *priv =3D ipoib_priv(dev); struct rdma_netdev *rn =3D netdev_priv(dev); @@ -918,7 +918,15 @@ static void neigh_add_path(struct sk_buff *skb, u8 *da= ddr, spin_unlock_irqrestore(&priv->lock, flags); ++dev->stats.tx_dropped; dev_kfree_skb_any(skb); - return; + return NULL; + } + + /* To avoid race condition, make sure that the + * neigh will be added only once. + */ + if (unlikely(!list_empty(&neigh->list))) { + spin_unlock_irqrestore(&priv->lock, flags); + return neigh; } =20 path =3D __path_find(dev, daddr + 4); @@ -957,7 +965,7 @@ static void neigh_add_path(struct sk_buff *skb, u8 *dad= dr, path->ah->last_send =3D rn->send(dev, skb, path->ah->ah, IPOIB_QPN(daddr)); ipoib_neigh_put(neigh); - return; + return NULL; } } else { neigh->ah =3D NULL; @@ -974,7 +982,7 @@ static void neigh_add_path(struct sk_buff *skb, u8 *dad= dr, =20 spin_unlock_irqrestore(&priv->lock, flags); ipoib_neigh_put(neigh); - return; + return NULL; =20 err_path: ipoib_neigh_free(neigh); @@ -984,6 +992,8 @@ err_drop: =20 spin_unlock_irqrestore(&priv->lock, flags); ipoib_neigh_put(neigh); + + return NULL; } =20 static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev, @@ -1092,8 +1102,9 @@ static int ipoib_start_xmit(struct sk_buff *skb, stru= ct net_device *dev) case htons(ETH_P_TIPC): neigh =3D ipoib_neigh_get(dev, phdr->hwaddr); if (unlikely(!neigh)) { - neigh_add_path(skb, phdr->hwaddr, dev); - return NETDEV_TX_OK; + neigh =3D neigh_add_path(skb, phdr->hwaddr, dev); + if (likely(!neigh)) + return NETDEV_TX_OK; } break; case htons(ETH_P_ARP): diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infin= iband/ulp/ipoib/ipoib_multicast.c index 93e149efc1f5..9b3f47ae2016 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c @@ -816,7 +816,10 @@ void ipoib_mcast_send(struct net_device *dev, u8 *dadd= r, struct sk_buff *skb) spin_lock_irqsave(&priv->lock, flags); if (!neigh) { neigh =3D ipoib_neigh_alloc(daddr, dev); - if (neigh) { + /* Make sure that the neigh will be added only + * once to mcast list. + */ + if (neigh && list_empty(&neigh->list)) { kref_get(&mcast->ah->ref); neigh->ah =3D mcast->ah; list_add_tail(&neigh->list, &mcast->neigh_list); --=20 2.11.0