Received: by 10.213.65.68 with SMTP id h4csp2119332imn; Sun, 8 Apr 2018 20:10:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx49n99QcGL48XNZUB9+og3JcRM2P6Ww5JbxMMtZfjeGU2Mv2GmkSpuVb722B/x2Uy8MaJJxG X-Received: by 2002:a17:902:aa98:: with SMTP id d24-v6mr37234354plr.220.1523243457698; Sun, 08 Apr 2018 20:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243457; cv=none; d=google.com; s=arc-20160816; b=iTbwViUpELjjreQwdIoviPCDO5aE6fCsZJM43lOYTqkBZf47N/hLuGj4913mBnh/oA EtMjfGnsphyPpcEZY+KdTFmwAINq2sXqD5pbttKNy9JYX9EaY3nep59nXo6tVZOewjJY CmreiQvTDakAcjwIcxTqamtTY+sYGY9OvGUcnvoIczvR1WmMwjV1pGF3cM3W2Q7c/c4m WlJYHStJ2g3Bvs0L12InpeDq2jd7e3B2MhogqYricyRfjo+Af++Jro6aOFwo61VYg9f+ eXa91unv8U1m+sqIAnCqqHmIdfW/oFBCaoUP4ubrcuCfufF5nXxOe+pU7H+zOrwu/E8c 3srQ== 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=sCkdtetybf3W/Qbd5I8Qn1aGUQlPvmHPF22HvhTYaFg=; b=dXammQpyYl+7IzQ6KA0uH7Mb0DT/JnsKZoXSiwNKI4/l7A6sQ+h4QK50ffu+vXDpZ8 OXhCIEIwvUIfoWCPLQU2MW1xhzMA4zLinXIUU4M+EgqxNTdi8RaYhCDKV3z77bruLxl3 E8auD9yoR6hGFkBZvM889kFVJCXINjcGPgqyb7F5/H61erL27JHlN//0ihKhRIL1XuXd 9rUf83yZFbTezzDZEsirv54fBS0Zz407QmedyMWWTeP2uQybxnroWSd4wMJw9QCkBzIn ohluFyXnDoEEc86biGR3xa8qFfTO9b0AQ00/iSfxd2MqRGtyl8GvFj+02etYy8G1vxey 06bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=EwgbLiuO; 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 f26si9902011pfn.269.2018.04.08.20.10.21; Sun, 08 Apr 2018 20:10:57 -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=EwgbLiuO; 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 S933019AbeDICV5 (ORCPT + 98 others); Sun, 8 Apr 2018 22:21:57 -0400 Received: from mail-by2nam03on0108.outbound.protection.outlook.com ([104.47.42.108]:9678 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756031AbeDIA3k (ORCPT ); Sun, 8 Apr 2018 20:29:40 -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=sCkdtetybf3W/Qbd5I8Qn1aGUQlPvmHPF22HvhTYaFg=; b=EwgbLiuOXZn7W+RcYey2DAQlobRu4mibcOIA2REVLYjWOSmMcavsAGnPji89glm/1QC7K/mm2aq/mrwh7mgoFUKFnOWiAS4tNEAAis9IjGfrczZFHWZ2fQM3L6pUpTajcK2aXxmZFBcuqiXvQLrNlThoFgDnShBCTO1pL+/Vc/4= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0967.namprd21.prod.outlook.com (52.132.133.25) 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:29:36 +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:29:36 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jacob Keller , Jeff Kirsher , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 110/293] i40evf: assign num_active_queues inside i40evf_alloc_queues Thread-Topic: [PATCH AUTOSEL for 4.9 110/293] i40evf: assign num_active_queues inside i40evf_alloc_queues Thread-Index: AQHTz5kZet1POMSreE6BRb+oumHUoQ== Date: Mon, 9 Apr 2018 00:24:19 +0000 Message-ID: <20180409002239.163177-110-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;DM5PR2101MB0967;7:A7X/sD2UCB/eRwPaBuYOPLBmbwp0/O78nr2n5kiS87fnrrSVw+rt2C0kuahF2KX9+p/OqCZ1rXyngqJwNxuCu4GEkSRYLOY2DlD4durJcrl4I1+2cUOelr8upF450HE/TzKQ83r+AA8YZGrT3KoaG9aR1DNN40s3xuIIDpTPjoWD4KgONYidqEeJMrYtlnIx0EnnAgjyOQLSEzlhagswQOCvpCsjFNivUHVDTGTmsHyQvvZn2eGOXes53XKhZ9pF;20:bKz/n9ulhJl0lwwYkMmthljs5j6UL4uwkHSCIIjb8OTRrl9KpsnYzQIHQLgyrJrpz3jQkSe0fcDfojnXOgsspNclwbuhmMWMd1Ado1T5j9EgZ457IpA//nTgokAJqL7Id3hMP+vatoz/U3NHT+SiANd3WHCu95/XPUnfmuc9WSk= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: b5baf6ec-ef99-4653-d05c-08d59db0f916 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0967; x-ms-traffictypediagnostic: DM5PR2101MB0967: 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)(228905959029699)(17755550239193); 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:DM5PR2101MB0967;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0967; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(376002)(39380400002)(346002)(199004)(189003)(6506007)(486006)(86362001)(14454004)(59450400001)(68736007)(102836004)(99286004)(26005)(3846002)(6116002)(186003)(15760500003)(476003)(2616005)(1076002)(3280700002)(86612001)(72206003)(4326008)(446003)(54906003)(76176011)(11346002)(2906002)(22452003)(3660700001)(110136005)(97736004)(316002)(6666003)(5660300001)(478600001)(8676002)(6512007)(8936002)(107886003)(6486002)(53936002)(81166006)(36756003)(81156014)(10290500003)(6436002)(10090500001)(25786009)(66066001)(106356001)(305945005)(7736002)(2501003)(5250100002)(105586002)(2900100001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0967;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: M9Ois2KJxVlOIbzg6ARXz7nMD0LeFGHenWejBCGo+pPyY/o3VqCc057F2bdofT+T/dHlCcakc9Xd4Zbkq154q9lR4feVKuVNmSsnHl1rZ94S+AF5N/pW6Kby2mYWeFuVUa1/AjHp3W1tRHSlUHWhHD85wsZlPJm8GPfjmyRuw34Elt/KnU8iCSgonYI0RbQ2Ks9oYnlnFj/vS0ql7E6a9n832hrTYdpIE+ajJCjET7fa3EaaELWjvpYYpBts2nMTavPSPvt3xlGfwvDPQijGc+954yJnQaMWIj3as63pX1iKp6epbXB0tL6aIrkDAuzMXPFXv3NtR09pquUjttHyDtXH24cBvOBJJkRBTN4NHV0yW7vFGfeNXQmsoCQ1v0fQZrbkm2PudiHqUrzk6i1B37/YM2RD4nv6a2Ko+Ky7Kfk= 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: b5baf6ec-ef99-4653-d05c-08d59db0f916 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:19.1594 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0967 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jacob Keller [ Upstream commit 65c7006f234c9ede887d468f595f259a5c5cc552 ] The variable num_active_queues represents the number of active queues we have for the device. We assign this pretty early in i40evf_init_subtask. Several code locations are written with loops over the tx_rings and rx_rings structures, which don't get allocated until i40evf_alloc_queues, and which get freed by i40evf_free_queues. These call sites were written under the assumption that tx_rings and rx_rings would always be allocated at least when num_active_queues is non-zero. Lets fix this by moving the assignment into the function where we allocate queues. We'll use a temporary variable for storage so that we don't assign the value in the adapter structure until after the rings have been set up. Finally, when we free the queues, we'll clear the value to ensure that we do not loop over the rings memory that no longer exists. This resolves a possible NULL pointer dereference in i40evf_get_ethtool_stats which could occur if the VF fails to recover from a reset, and then a user requests statistics. Signed-off-by: Jacob Keller Tested-by: Andrew Bowers Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/i40evf/i40evf_main.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/i40evf/i40evf_main.c b/drivers/net/= ethernet/intel/i40evf/i40evf_main.c index 14372810fc27..34fc948bf550 100644 --- a/drivers/net/ethernet/intel/i40evf/i40evf_main.c +++ b/drivers/net/ethernet/intel/i40evf/i40evf_main.c @@ -1123,6 +1123,7 @@ static void i40evf_free_queues(struct i40evf_adapter = *adapter) { if (!adapter->vsi_res) return; + adapter->num_active_queues =3D 0; kfree(adapter->tx_rings); adapter->tx_rings =3D NULL; kfree(adapter->rx_rings); @@ -1139,18 +1140,22 @@ static void i40evf_free_queues(struct i40evf_adapte= r *adapter) **/ static int i40evf_alloc_queues(struct i40evf_adapter *adapter) { - int i; + int i, num_active_queues; + + num_active_queues =3D min_t(int, + adapter->vsi_res->num_queue_pairs, + (int)(num_online_cpus())); =20 - adapter->tx_rings =3D kcalloc(adapter->num_active_queues, + adapter->tx_rings =3D kcalloc(num_active_queues, sizeof(struct i40e_ring), GFP_KERNEL); if (!adapter->tx_rings) goto err_out; - adapter->rx_rings =3D kcalloc(adapter->num_active_queues, + adapter->rx_rings =3D kcalloc(num_active_queues, sizeof(struct i40e_ring), GFP_KERNEL); if (!adapter->rx_rings) goto err_out; =20 - for (i =3D 0; i < adapter->num_active_queues; i++) { + for (i =3D 0; i < num_active_queues; i++) { struct i40e_ring *tx_ring; struct i40e_ring *rx_ring; =20 @@ -1172,6 +1177,8 @@ static int i40evf_alloc_queues(struct i40evf_adapter = *adapter) rx_ring->rx_itr_setting =3D (I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF); } =20 + adapter->num_active_queues =3D num_active_queues; + return 0; =20 err_out: @@ -2440,9 +2447,6 @@ static void i40evf_init_task(struct work_struct *work= ) adapter->watchdog_timer.data =3D (unsigned long)adapter; mod_timer(&adapter->watchdog_timer, jiffies + 1); =20 - adapter->num_active_queues =3D min_t(int, - adapter->vsi_res->num_queue_pairs, - (int)(num_online_cpus())); adapter->tx_desc_count =3D I40EVF_DEFAULT_TXD; adapter->rx_desc_count =3D I40EVF_DEFAULT_RXD; err =3D i40evf_init_interrupt_scheme(adapter); --=20 2.15.1