Received: by 10.213.65.68 with SMTP id h4csp2113354imn; Sun, 8 Apr 2018 20:03:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx49MIJ3oZspkzxuq0lkgM0Zy4g/YYvteePhJpLjRX+U1zbcM8d1RE4B/RQsbR8EWXyBAvofx X-Received: by 10.99.141.200 with SMTP id z191mr23705743pgd.418.1523242999953; Sun, 08 Apr 2018 20:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523242999; cv=none; d=google.com; s=arc-20160816; b=GyD44fZhRgbCfAetDVHA505oFU7PZyuqedVcLstAzxBm+2tT90qDbNriJ3PafIsjBI HA9Wu0zk1EoD12/n1BJF0iYob8tjM/aKy5JXK7cu7rq6TBwZBMv14R21wb767xg0UmxB OvuCnaLbkEqNf0uyzgnJllh+N3fDt/LAH5/eytajx9gkB4z3x3s7ltnr6ov/0OHc5pVL RtvX8vFXO35/kKCLGMY9c2n6z004kNmhL6WZ2jV33dsRTIzCiYf4UTvu6nhq+Ajqlma4 yCzMmAJ0sqwEqiE2vL0KrgSIEV+2yM31Hem7XlOziWK2TiiQr4AcJlwuMQUbNa9eOH33 hPgQ== 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=RbMjNXNf9iOapiXJhfUlkUH9s3hljlEi6FEEQOweCBI=; b=zqqEy5pp6OtMF1HB3xu6L7piistFCh6NuAQa9BW6u2AJ982FN57KLe9s+0/eeHOKeH GPtfXN0KP4HuMV76vTQ3ShZ51WeytyI9pagHXRVeSky9XxiJBqbmWOkYn9Q7o7YGTLHg geA/J6HIJ/qe46rPrKzkzobTXihMzwPvK/eNZ1BHxjkQffNeFNqf7htJcZTAzKMXRF6g jh5kmi+tT4G91e1pIm32Tudr00MX+HzqqQ4A8xSAsmm7hrpmpKnnpr1EJrNhAL8dy3mi j1Q1CE+AcF6T5nz3QASERDfvU3hKZZkDoIq7FyKw/LRVW2Z2fTDO8epquMHC3e+q4iTM yr2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=gkr84Ezn; 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 u12si1552638pgr.128.2018.04.08.20.02.42; Sun, 08 Apr 2018 20:03:19 -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=gkr84Ezn; 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 S1755573AbeDIA12 (ORCPT + 99 others); Sun, 8 Apr 2018 20:27:28 -0400 Received: from mail-cys01nam02on0094.outbound.protection.outlook.com ([104.47.37.94]:22752 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754664AbeDIA1V (ORCPT ); Sun, 8 Apr 2018 20:27:21 -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=RbMjNXNf9iOapiXJhfUlkUH9s3hljlEi6FEEQOweCBI=; b=gkr84Ezn3NtN1n5fvskHHekoKJxVCATxOjF/M5Qu5PmgzL0bWZEu2EW6Q/omzbqU8/fopsLl/jJgzTkBv7Jrccqe9k8hL+d83Xvc/Ov1+3jGAdlNs6B0ki353N7TSrorvVd/4J5WIH2CaI4mEmizTGSnelcwJBrmgrxtsGGOlLo= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1031.namprd21.prod.outlook.com (52.132.128.12) 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:27:19 +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:27:18 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Netanel Belgazal , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 033/293] net: ena: fix race condition between submit and completion admin command Thread-Topic: [PATCH AUTOSEL for 4.9 033/293] net: ena: fix race condition between submit and completion admin command Thread-Index: AQHTz5j0jcBHpdppDkOM1ghVZudKaw== Date: Mon, 9 Apr 2018 00:23:16 +0000 Message-ID: <20180409002239.163177-33-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;DM5PR2101MB1031;7:WJa0WhY7MH/6/bmaDh6znij3ikdXgmsT4qkii8erlmLH+//Ixa0EX59+WA4lLnbeeqCj1v/Tai877om8zv7yDLuM7FgeJTrOfwdEKJ3oklxCzAuploCgg1BH2DINsJ8N830YUoJXS0NS2mp3v9JiMPJQveD3IqE2aTNQ0vmlOaR/O4yOkixbixWjLmMBpChmUv8155tHNNStQyQh/GbTeWrTPbKKa21sNOi2UQkTzYy4vac3Tw9IIxNfMzD1UPCr;20:EEK+c5ebU3NasYYCghYmFW4eargL3T+iRHjcFZuRfuSXi8olhYVJX9f6IieDteeZz1f0GIRYHC2iSPV1cMWhe+1OlUFPtJ+AyTEcumH2df45LuRteC6EZloNfSrj6Hj2HdnYRF13npk6sQ2JVNPq6hu/SBgdk7Gs1T6XRkHVR9w= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: f7bd4169-b860-40fb-7625-08d59db0a751 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1031; x-ms-traffictypediagnostic: DM5PR2101MB1031: 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)(33061846794335)(47284530071512); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1031;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1031; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(376002)(366004)(39380400002)(346002)(39860400002)(189003)(199004)(2900100001)(10290500003)(99286004)(76176011)(14454004)(7736002)(11346002)(26005)(86612001)(72206003)(478600001)(36756003)(106356001)(66066001)(2616005)(186003)(575784001)(22452003)(86362001)(68736007)(305945005)(54906003)(102836004)(486006)(59450400001)(110136005)(316002)(6506007)(446003)(107886003)(53936002)(4326008)(105586002)(6436002)(6486002)(476003)(6512007)(5660300001)(5250100002)(25786009)(3846002)(6116002)(1076002)(97736004)(3280700002)(2501003)(2906002)(81156014)(8676002)(10090500001)(81166006)(8936002)(3660700001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1031;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: sTQkquVIAKvodRQCpDr9wR3DxmPZwiBxXzdGYbXMhXZvNPv50wxFkGSxwjm2dR7mpZ1eCIgtf4rklaEopR/r1Kxikh+48jgTn6aRFEcbrJmx9Yb4fmb6SoSifM0KX4sNXFBW4sUCi6FwB8z17dta1vsgEKMykDckjoKrkBitvdBYH1dtU22ICXiu0dFt0I3X4wXC1gXhxpVcP4p8mEak3D5tLwYra+AAaZiA32aWOwOSu2+cLo9PTweTeU0H3APDoI4fKCpfE/gDU+yyECpl6+beusmV2CLPz47grUGyStEd1LBR1BCtg/X0x19czrH49q548KJfIAyp0FvWsii4PDJkZbNA0XJ5OTpHJWRF7EdwmD+BvskJoCuV8MMGYF4eKiRbOHCCF1IjH3HBRNV9jEOH/gyDblzfXNjs7ENUA+8= 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: f7bd4169-b860-40fb-7625-08d59db0a751 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:23:16.0342 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1031 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Netanel Belgazal [ Upstream commit 661d2b0ccef6a63f48b61105cf7be17403d1db01 ] Bug: "Completion context is occupied" error printout will be noticed in dmesg. This error will cause the admin command to fail, which will lead to an ena_probe() failure or a watchdog reset (depends on which admin command failed). Root cause: __ena_com_submit_admin_cmd() is the function that submits new entries to the admin queue. The function have a check that makes sure the queue is not full and the function does not override any outstanding command. It uses head and tail indexes for this check. The head is increased by ena_com_handle_admin_completion() which runs from interrupt context, and the tail index is increased by the submit function (the function is running under ->q_lock, so there is no risk of multithread increment). Each command is associated with a completion context. This context allocated before call to __ena_com_submit_admin_cmd() and freed by ena_com_wait_and_process_admin_cq_interrupts(), right after the command was completed. This can lead to a state where the head was increased, the check passed, but the completion context is still in use. Solution: Use the atomic variable ->outstanding_cmds instead of using the head and the tail indexes. This variable is safe for use since it is bumped in get_comp_ctx() in __ena_com_submit_admin_cmd() and is freed by comp_ctxt_release() Fixes: 1738cd3ed342 ("Add a driver for Amazon Elastic Network Adapters (ENA= )") Signed-off-by: Netanel Belgazal Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/amazon/ena/ena_com.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethern= et/amazon/ena/ena_com.c index 564b556baba9..f4c107b66af4 100644 --- a/drivers/net/ethernet/amazon/ena/ena_com.c +++ b/drivers/net/ethernet/amazon/ena/ena_com.c @@ -232,11 +232,9 @@ static struct ena_comp_ctx *__ena_com_submit_admin_cmd= (struct ena_com_admin_queu tail_masked =3D admin_queue->sq.tail & queue_size_mask; =20 /* In case of queue FULL */ - cnt =3D admin_queue->sq.tail - admin_queue->sq.head; + cnt =3D atomic_read(&admin_queue->outstanding_cmds); if (cnt >=3D admin_queue->q_depth) { - pr_debug("admin queue is FULL (tail %d head %d depth: %d)\n", - admin_queue->sq.tail, admin_queue->sq.head, - admin_queue->q_depth); + pr_debug("admin queue is full.\n"); admin_queue->stats.out_of_space++; return ERR_PTR(-ENOSPC); } --=20 2.15.1