Received: by 10.213.65.68 with SMTP id h4csp2616559imn; Mon, 9 Apr 2018 06:28:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/b+rv/zQ7AQ/lTGC23j8jbGrliETUzUF3CA2s8Qu/oBaA77+2feB9RSNyWAoM4lHi0SjsW X-Received: by 2002:a17:902:2d24:: with SMTP id o33-v6mr39652796plb.143.1523280501278; Mon, 09 Apr 2018 06:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523280501; cv=none; d=google.com; s=arc-20160816; b=EZBKJEexlliGou6oAx8ADuPE2MufFnpJxGNdHXRvh5XFmfdCVrHHvWi4ApLIwUUTHU zsfRcEpnUhfPbiviCPp9wysIKCr3QHHP6JKLIeImKf4/1mCsm4Zd/QfaDOk+/fCF9Mrx gF52ZhCbx7JL52v2ziPO2+vxDMRzi5tBAGdAT1RQlf+9R5Ue9myAtxezSHOjONBpppVw XRh1VtTR1smaGp77qXLYPHm5rU+KUFHwaJFlcP4eK+2jSVjNPx5DFjUma/ozttWz1pDF cOC20eMRaSDqFaL/UVSZEmw/0bFAcY2PhpMkhrmvmvSBIqQs77xksfQUD3FElSinnd/n 6Bnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=jpxoUjDxVBa/wHyIBnfYlDbk897yQUgTL2+t20ViAus=; b=fVlDPFp13pjMxklthuE0G3B7uPBBo7Xy+yTVQCfEUdyN64as8YbaDjEp/fa4BuxuYg UsEQEhB0+KXwkYj732A6aLwRYJfnwUzwNfjIHwvGDsdIiPRoCGxZ6MAtBeGB3DT27mHA 7MkfSyF0Jo/dvkTaLQmRx/BxcbWTSuJc50TKkReKrOEhC1p/jwFJ12m8lYqtmfzqwpst 1tRVyrgjj3d+Ihtt9b1JcxHzSzChAhYFgfreLs86c1ntrnQMmZqTmXYdEGHwFhzFU5bE 2GXpW0pSbw2l06Np35JtSlW/VgOBkIW+dipHuzsOsjv187EYKCNU5iJ+1mti+NqePSIs 9U/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=biDRLLzs; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 38-v6si172406plf.737.2018.04.09.06.27.44; Mon, 09 Apr 2018 06:28:21 -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=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=biDRLLzs; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752232AbeDINZG (ORCPT + 99 others); Mon, 9 Apr 2018 09:25:06 -0400 Received: from mail-cys01nam02on0082.outbound.protection.outlook.com ([104.47.37.82]:7276 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751367AbeDINZD (ORCPT ); Mon, 9 Apr 2018 09:25:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=jpxoUjDxVBa/wHyIBnfYlDbk897yQUgTL2+t20ViAus=; b=biDRLLzsg+/UUK2B+RfdaBfTozWMbQdXjIFGpLn2ahT4aNQTyaMZoZlXfRDANcAbYE6b9NLCG4hevaTnSx4nlerglT/GzB8Nt4ABd7+ONN2DG49v68EFcm62vCMnPjuuGdoxa7RkMq5NfRH5QsvcB0jrDMFDF9cyrn7J0ovfRDM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Vadim.Lomovtsev@cavium.com; Received: from localhost.localdomain.com (50.233.148.156) by BN6PR07MB2996.namprd07.prod.outlook.com (2603:10b6:404:a7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.653.12; Mon, 9 Apr 2018 13:25:00 +0000 From: Vadim Lomovtsev To: sgoutham@cavium.com, sunil.kovvuri@gmail.com, rric@kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net Cc: dnelson@redhat.com, robin.murphy@arm.com, hch@infradead.org, gustavo@embeddedor.com, Vadim Lomovtsev Subject: [PATCH v5] net: thunderx: rework mac addresses list to u64 array Date: Mon, 9 Apr 2018 06:24:48 -0700 Message-Id: <20180409132448.22278-1-Vadim.Lomovtsev@caviumnetworks.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180406195354.16037-1-Vadim.Lomovtsev@caviumnetworks.com> References: <20180406195354.16037-1-Vadim.Lomovtsev@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: CY4PR19CA0031.namprd19.prod.outlook.com (2603:10b6:903:103::17) To BN6PR07MB2996.namprd07.prod.outlook.com (2603:10b6:404:a7::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1385f4cd-a3a5-46f6-193a-08d59e1d4ca7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603328)(7153060)(7193020);SRVR:BN6PR07MB2996; X-Microsoft-Exchange-Diagnostics: 1;BN6PR07MB2996;3:YYP1BLRd18cO9MlzB1XRXKiS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cln39ZGeU34fkqBmYoi/PNIrbtP50flTO8KwxxeXU5IW2y0lZTsPuMQyYpnlXtJiNJVXzlv1hR3FXaUU2fM5F4yDLEtyQh6SeTVIE0vIz+YXmUaPKI4CkOSY1Pl/lfIhrNw9PESBKstZz4cgF/PzP8oyRE+8Te/bzhlqAb/kzqa6OcpxExjot3GiqRMmC4bwlO/zQBuW+SVT8FWCMCjD07MHiDuf6AQhEp8H3+T2MOXxZTUqNru5Bgvbt9hTLi1fGPFQphnOrfE/IORKJUvEiQpxG+9FjAO0pc2b1lSFVzQ8C3WOz7lpL6JTiX/G0iJMvn5jpd5WjBaPQEh6cnL4+dulyMQq7Ia1DrV/qRvnCcp6iZo9fU4yD7F08zBKqSAlLnTU5mWFKPUYGjdk+eHA6xFjzm93b7cJ1Ts+2U/wCLp97ocs4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(277106579953875)(146099531331640); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(10201501046)(93006095)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(6072148)(201708071742011);SRVR:BN6PR07MB2996;BCL:0;PCL:0;RULEID:;SRVR:BN6PR07MB2996; X-Microsoft-Exchange-Diagnostics: 1;BN6PR07MB2996;4:KKD+LcB8XLN65/lQm1QRr+DGBf4C7sz6S9qKM1t58emMh5GlwU426bOBivCpx2CVBCyzOYsHDh+4zywAPqSuhqF2Ax7IT4IZDOTBr0Gjx41e0ZTOVSTuQyKN9frdnJ0a5gctye6dpNEyEgm89DkMUIniu7WcIwVPEkdCC+Er7hM4l3RFoNuzFVHIK+mAlgMXGFbxUMaYJP1EEQz5ZnIuIoPnmEDyRDMs7MzOrJREL07aTpOm8aq7JD3+vT0SMDKGpLm87i55YkdSD0vgs1kl82x0MSXzZlA0Mb3topd7BApzWd+8c4RI14tx7fdqCJQUFdGZ7NPqIJa8pg969SHQKYSmw5L3gJkxc9XhIbWzkYI= X-Forefront-PRVS: 0637FCE711 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6069001)(366004)(396003)(39380400002)(346002)(376002)(39850400004)(189003)(199004)(52116002)(97736004)(16586007)(6116002)(3846002)(39060400002)(81166006)(8936002)(25786009)(50226002)(76176011)(81156014)(4326008)(8676002)(6512007)(53416004)(51416003)(47776003)(6666003)(105586002)(66066001)(6486002)(26005)(107886003)(1076002)(53936002)(316002)(42882007)(36756003)(16526019)(68736007)(478600001)(476003)(386003)(6506007)(59450400001)(5660300001)(69596002)(956004)(2616005)(446003)(72206003)(11346002)(50466002)(7736002)(48376002)(486006)(2906002)(7416002)(106356001)(305945005);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR07MB2996;H:localhost.localdomain.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN6PR07MB2996;23:iPE+ucAC/9byclglJUIAJwTOZl3vBpDpdgtt1ykW6?= =?us-ascii?Q?kROHJ0GUj1grj9jn69p7HMQtCXrIBIUzKPPfFtNAmKdmuM6R3vutSYDogQV5?= =?us-ascii?Q?QfPvxh9fdcyE2eXk+eEt9IO447hm4QZMFTjJlI43On66KMfkrcdaXSYumqNr?= =?us-ascii?Q?6ryCyl6K14RAv8NuCahy+eXC8RvWeOT3p5AnDyTgdXgxeNYDcgm2yThRAQFu?= =?us-ascii?Q?Msw1YPqqetGBxebsGKJLbAn6RYufkxBrBQbaV80wGbPAFJw2yCmlc5Xojh2u?= =?us-ascii?Q?36IIhK+1IjWk5/nxzICO7SKW9gVLlkM0dMb+yHFYwTWdqBTBq9cyZXeCXwOY?= =?us-ascii?Q?QCwCIKS40Q4AIaIy3UVi1sH9hfi9bJe+GPpV32Kl2L7bg3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ecRorChaAlI3DoN31vSoyStr3KI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR07MB2996;7:24o/LCZnnJ6AgKyxDxmTqyuFWbH8Ofewt2ey9if4JtMFPyUxo/H1sCYuOEtr8IYzs2QOH417qFhiru66wpoRYokV7nZEgBcqYwADOyEOig3g0On2kV/ytdN7IT0TdkEF9JY/zorDCoDNd5Z51nEhmkvZMLqUo/+bAQ5EdXdVWQ8g31pw4XcyySXe3zIOab/NOYeebrPY2f/30xnixIv4hFUq4RpmMW8E/81ghwZ4bv4kxdQT5Rcy+VsbcuQNJfZ/ X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2018 13:25:00.8802 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1385f4cd-a3a5-46f6-193a-08d59e1d4ca7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR07MB2996 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vadim Lomovtsev It is too expensive to pass u64 values via linked list, instead allocate array for them by overall number of mac addresses from netdev. This eventually removes multiple kmalloc() calls, aviod memory fragmentation and allow to put single null check on kmalloc return value in order to prevent a potential null pointer dereference. Addresses-Coverity-ID: 1467429 ("Dereference null return value") Fixes: 37c3347eb247 ("net: thunderx: add ndo_set_rx_mode callback implementation for VF") Reported-by: Dan Carpenter Signed-off-by: Vadim Lomovtsev --- Changes from v1 to v2: - C99 syntax: update xcast_addr_list struct field mc[0] -> mc[]; Changes from v2 to v3: - update commit description with 'Reported-by: Dan Carpenter'; - update size calculations for mc list to offsetof() call instead of explicit arithmetic; Changes from v3 to v4: - change loop control variable type from u8 to int, accordingly to mc_count size; Changes from v4 to v5: - remove explicit initialization of 'idx' variable as per review comment; --- drivers/net/ethernet/cavium/thunder/nic.h | 7 +----- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 28 +++++++++--------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/cavium/thunder/nic.h b/drivers/net/ethernet/cavium/thunder/nic.h index 5fc46c5a4f36..448d1fafc827 100644 --- a/drivers/net/ethernet/cavium/thunder/nic.h +++ b/drivers/net/ethernet/cavium/thunder/nic.h @@ -265,14 +265,9 @@ struct nicvf_drv_stats { struct cavium_ptp; -struct xcast_addr { - struct list_head list; - u64 addr; -}; - struct xcast_addr_list { - struct list_head list; int count; + u64 mc[]; }; struct nicvf_work { diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c index 1e9a31fef729..707db3304396 100644 --- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c +++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c @@ -1929,7 +1929,7 @@ static void nicvf_set_rx_mode_task(struct work_struct *work_arg) work.work); struct nicvf *nic = container_of(vf_work, struct nicvf, rx_mode_work); union nic_mbx mbx = {}; - struct xcast_addr *xaddr, *next; + int idx; if (!vf_work) return; @@ -1956,16 +1956,10 @@ static void nicvf_set_rx_mode_task(struct work_struct *work_arg) /* check if we have any specific MACs to be added to PF DMAC filter */ if (vf_work->mc) { /* now go through kernel list of MACs and add them one by one */ - list_for_each_entry_safe(xaddr, next, - &vf_work->mc->list, list) { + for (idx = 0; idx < vf_work->mc->count; idx++) { mbx.xcast.msg = NIC_MBOX_MSG_ADD_MCAST; - mbx.xcast.data.mac = xaddr->addr; + mbx.xcast.data.mac = vf_work->mc->mc[idx]; nicvf_send_msg_to_pf(nic, &mbx); - - /* after receiving ACK from PF release memory */ - list_del(&xaddr->list); - kfree(xaddr); - vf_work->mc->count--; } kfree(vf_work->mc); } @@ -1996,17 +1990,15 @@ static void nicvf_set_rx_mode(struct net_device *netdev) mode |= BGX_XCAST_MCAST_FILTER; /* here we need to copy mc addrs */ if (netdev_mc_count(netdev)) { - struct xcast_addr *xaddr; - - mc_list = kmalloc(sizeof(*mc_list), GFP_ATOMIC); - INIT_LIST_HEAD(&mc_list->list); + mc_list = kmalloc(offsetof(typeof(*mc_list), + mc[netdev_mc_count(netdev)]), + GFP_ATOMIC); + if (unlikely(!mc_list)) + return; + mc_list->count = 0; netdev_hw_addr_list_for_each(ha, &netdev->mc) { - xaddr = kmalloc(sizeof(*xaddr), - GFP_ATOMIC); - xaddr->addr = + mc_list->mc[mc_list->count] = ether_addr_to_u64(ha->addr); - list_add_tail(&xaddr->list, - &mc_list->list); mc_list->count++; } } -- 2.14.3