From patchwork Fri Apr 6 19:53:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Lomovtsev X-Patchwork-Id: 10327525 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2630A6053F for ; Fri, 6 Apr 2018 19:54:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1564428817 for ; Fri, 6 Apr 2018 19:54:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 091F82965C; Fri, 6 Apr 2018 19:54:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6D98F28817 for ; Fri, 6 Apr 2018 19:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LcDvHIOBZxhrC/zCCqQySJzIh5hNkLeY5sRMmdqcbqU=; b=nwp3CXyE90KyW3 9H4geyfTHfwKNOMN6A7eYSzsDbnjpWOvK/LaLNO3DlMEYoMpxwzqFBHZzjymDBE4xEq9WyM17quvy 8YBhOiql96mJxEHfs3GQlsvJtF6xvc1p/S4wrfzZB554LDKHltHnwwtsOQeGf8kYaHaZpmiNMWUvr JKK8/1YHMXd6koAZ/wgwGQY8DKW0906p17lPvKyxrPr4Z14Wz+z3tfSi94JpVtf87kIWcp4UoMOtx 08BJ0MKiiTopNbVW0lAL7ZmAUwr0wAjvp3i5zxa4c9pxSbESBu67yItx+xlegdJa2va0FX7uPIzkY 2WTveSDAZ8OOSFsAAF/A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f4XRK-00057K-JY; Fri, 06 Apr 2018 19:54:26 +0000 Received: from mail-cys01nam02on0067.outbound.protection.outlook.com ([104.47.37.67] helo=NAM02-CY1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f4XRG-00054C-HV for linux-arm-kernel@lists.infradead.org; Fri, 06 Apr 2018 19:54:24 +0000 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=NRPbcp3nEp2JVdvHJ84dweyceothMmXNRffHKTPNb94=; b=ff81tviM6Z6ObIQ4CsEe2GawLft8ItPp/Jjosv2O46tY6XYlRkLjwbgzSi31rJa0amxEPtr16v1goq1hw2iFCUMM+Yb0fprF7DgauUQChXyE4uunCZcvmd8BCGjhcI5IvgusM46qHeMO64dHErm37fWF4rlNgWrXH3iVNhJvIyo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Vadim.Lomovtsev@cavium.com; Received: from localhost.localdomain.com (50.233.148.156) by DM5PR07MB3002.namprd07.prod.outlook.com (2603:10b6:3:e3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Fri, 6 Apr 2018 19:54:03 +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 Subject: [PATCH v4] net: thunderx: rework mac addresses list to u64 array Date: Fri, 6 Apr 2018 12:53:54 -0700 Message-Id: <20180406195354.16037-1-Vadim.Lomovtsev@caviumnetworks.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180406140443.15181-1-Vadim.Lomovtsev@caviumnetworks.com> References: <20180406140443.15181-1-Vadim.Lomovtsev@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: MWHPR2001CA0007.namprd20.prod.outlook.com (2603:10b6:301:15::17) To DM5PR07MB3002.namprd07.prod.outlook.com (2603:10b6:3:e3::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 27bd79bd-3978-4281-eb60-08d59bf826f1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603328)(7153060)(7193020); SRVR:DM5PR07MB3002; X-Microsoft-Exchange-Diagnostics: 1; DM5PR07MB3002; 3:oFmVqah8WvmpUohRmx1wLVhGlIYVXJQPbs2/UDH/x/4DaiWC73YSPvWJ4pKUKqtHCMbfJPBn9hvhgY7ptKTzCYufnMNFISRR4MZ49imqgFgQM/QYtiCCk2hPzONZxyGs1I7YN8o/d1+22Muc7P448zCpxG9xSsb7JrnLYBj8eBSwE7RzNnl8pD/nrqqsIEwxazXqmg5D/czDPrWWzbpqrqAhrzcD1Sb4+8HJB5KMoMre9zCe45/EmbxEA+trzJdu; 25:STgkdVoU6GGa/NlUX4ajyPB4ltNMQ22vVKpWeXmu+1dqPSErKj0coLvIhlPStUWYjDS+FlqG0n7vz90Bqg/Q1O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KPK9SDBLyboUuMkWm3S7STKMyQBwdEFpIThkkAdFdoOiNXuozkUAdZuzCzvRi9x1ZnaCyqzzdMzvUesYWw2OhO0qaVbRMoJUhSGB30= 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)(93006095)(10201501046)(3231221)(944501327)(52105095)(3002001)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR07MB3002; BCL:0; PCL:0; RULEID:; SRVR:DM5PR07MB3002; X-Microsoft-Exchange-Diagnostics: 1; DM5PR07MB3002; 4:ID6bGnmKrDO/GOVfFidsX1/f5F0QGcc00iX+keRSOmCpag0sw6xZsRda9WR27It78k7KGOmScyb9+AGinR+z4mzTKvh9j/0VwUP7xyurqhLQfD1BmIsHIIyIcSJ2PrGApH/hZTZdo44btMdtIDxQ/e4USZuPxy1V6qXcL2xYx3NjRDdFGzoyj9KVf87uKJLZWRQVkPKZ2HVfSty2K9GNN18R9IXKZzDYG+sRlLaCJYqfgUpmxe/nE5IMytQ5CcgauUoJ6EQSA7rc07bKyLkqnPxVoUfqAKlqExlUz0uS8uYCFjy+RLJnFk89Ff1khd075uiOWcA51ZmEgzpdAFJg2v79iRg31v7MyUbINU10+nY= X-Forefront-PRVS: 0634F37BFF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(366004)(346002)(39860400002)(396003)(39380400002)(376002)(199004)(189003)(66066001)(6506007)(478600001)(39060400002)(305945005)(107886003)(4326008)(50226002)(59450400001)(72206003)(8676002)(105586002)(81156014)(106356001)(7736002)(81166006)(76176011)(52116002)(51416003)(7416002)(47776003)(97736004)(8936002)(53416004)(386003)(3846002)(6116002)(69596002)(6666003)(11346002)(446003)(50466002)(48376002)(36756003)(2616005)(956004)(2906002)(476003)(486006)(26005)(16526019)(1076002)(42882007)(16586007)(6486002)(53936002)(5660300001)(6512007)(68736007)(25786009)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR07MB3002; H:localhost.localdomain.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR07MB3002; 23:cKqsBMDshZ3lu1lR53kseQBEHk+xZ+0uSXX/gHQmg?= =?us-ascii?Q?P9UQ2vtBaNFwT5LdS1bIpxmMn0kQ7BuWaUZyxjND7h7RlypHj9+6EDL+3lrL?= =?us-ascii?Q?EppZme8ck7QDGhyF1p3gcA/0Dh3fMdfZ99VVXVbSZ4zK6kWqNLKL4yhQmM5T?= =?us-ascii?Q?fLGO1TCiA3S9bdDETvvwnegMr644y04DCqg3uFm43Y03okNByzBLfLKRg1Og?= =?us-ascii?Q?yzC1qAeYuFE9E14wUQyY/yvhzqUbf5VsZRKeXG/vsGL36VNuzIMD4Pxi0aYp?= =?us-ascii?Q?rpooXmssq/L/s1R/wnBA9pvo2u2y1Ao/0HcJ6003xM5nqkTwdsARqBsKY9VS?= =?us-ascii?Q?URt6HvdTNXcREJE0W6/u8sK4lK2KgZYSD9icL3z6n1VNLIbfy0jcqMqp9Zgs?= =?us-ascii?Q?wnNIqKDwbIJ0830lust3PJd1nKLMfCfI2G/nyaEWBScMEi0j0KNKXOz0MF3R?= =?us-ascii?Q?k8BRGk1HrCwlxxmsJbDTz9LU3Mu0cCkednRCbEe5VYsu+JwgrBViI99W1vlk?= =?us-ascii?Q?xW7LjeiOi2gk/J7NRhbN2AHH5uKPa11bA8NB2yBVqOdMZI6Fnss4SQ1ftaiQ?= =?us-ascii?Q?GkkhxC+79X02YX9bamdRi4v9vNuyQ+SFZaF16KAJae+tRTgOd+8V4JPv/lSe?= =?us-ascii?Q?YtIBFX5fLtZs77nB20eHirkLaGyg8vWI7PaLyJH2z15BaOfhSXCCtPMpdwRu?= =?us-ascii?Q?GT9fVhf+XdcSG9dl1sdQOOhJtQWHtZGivBUp9he6wHd7HKtKUTUH2/6rX5GZ?= =?us-ascii?Q?fIdhVyiuLHa/yKxdOLO7XUr7nGLqSeLQpa48Pzday6GB7obrAe/28DPeMlhh?= =?us-ascii?Q?gzsHqjOzcO3JQLrFIDEeN4TFfsFR3W92GnhbuasNEowpBzRpkj8S0lL+7r0R?= =?us-ascii?Q?ZeZRRm/brEF1stDtPZPkF93jiOFg0NO4m/5xE1R2PKuws7xlr8v5T87+cl3z?= =?us-ascii?Q?DkQpYWub8PQqonEdCH9MCviyPPCYqdbOfaT2ozxDgQCwEeDjOjSJNfTRbh+1?= =?us-ascii?Q?gFW0gLGlWVm2TZmaGF4n4SoUycl9zesmuII56nqp4Sbs9PQd+3p+ZzXwfGLR?= =?us-ascii?Q?LcXNsM9ERQXUT4oqc5hMkxc6WcJsW4yfrheH7fcIllFUE2IkVnnpI53FbFzt?= =?us-ascii?Q?fouCz1EICfz1GzSsVR6LjXx8MTNpsV8OXd0bGBSL6U4xRqNI4feoSwpzTvB7?= =?us-ascii?Q?A2rjK6B7sWm51010YRcHjsP/TLIXAXTcxzYONTXErThqQrdRpOHUX1Wrz7+7?= =?us-ascii?Q?LgvVvlDZIy/htg+max6id2a+e2FP2nt6AiSKIFoRYvanlYgnMYjGfe1vw+gs?= =?us-ascii?Q?J+wIILc1LugTWQiXJS2nUkItW83Sz2945SKKJSMQ5ec?= X-Microsoft-Antispam-Message-Info: FvhJGLGveyEv4QatspFaH5aZnYzrBWfJ0M6balQlDlYj6Dw0F/Wac43I1pDYErDlm26Dew8u24f+Om2g6KOZlEaIwOa4jSF4YV5+9H9DQRRmO3QS5eq8nyAHHqZnhDF8bNE1ef/aPYZCAZ8mqRs3lnVIvo7ubC6/hpD1sVyKaoO6KLYVII07mtcRD6orM2EF X-Microsoft-Exchange-Diagnostics: 1; DM5PR07M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CmLRqVa9nZJprjj8znppkDgBkgEHnMOSZllTuzk X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2018 19:54:03.9595 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27bd79bd-3978-4281-eb60-08d59bf826f1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR07MB3002 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180406_125422_621806_6CE27C0C X-CRM114-Status: GOOD ( 12.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hch@infradead.org, dnelson@redhat.com, robin.murphy@arm.com, Vadim Lomovtsev , gustavo@embeddedor.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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; --- 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 5fc46c5..448d1fa 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 1e9a31f..6bd5658 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 = 0; 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++; } }