From patchwork Thu Apr 5 14:57:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Lomovtsev X-Patchwork-Id: 10324697 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 8DE546053F for ; Thu, 5 Apr 2018 14:58:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D0072909A for ; Thu, 5 Apr 2018 14:58:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7037F29278; Thu, 5 Apr 2018 14:58:40 +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=-1.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,DKIM_VALID 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 DEA522909A for ; Thu, 5 Apr 2018 14:58:39 +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: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:In-Reply-To:References: List-Owner; bh=o1zc+8DDJvQNZN1tESWMIb1GAecWQHZczgbr1X3hsnY=; b=f+gIsjhvq07gB/ kawXWV+0z3WvbkbC/gLoSCt5jhE2UL0Pktz/eaSGmLXtoWobz8qE5ZQrms24S//UG2zgrE8UZGFWK A5m93fFWRx9rLlFaReYc7Btr0uMQBDsuZcRmTK1gQQmN+y/Dy31ex+YTKiDNkdfJKmT++aiQBd6k4 aJq1g+Ro4oMGW3T8ZgHcYfJflW1HxjMoYBlkMnohhe/jpMCdtORwOClEFJAlhsuP9zMwvoB7wPL0a OcxhxnCKSU0i9/dlBn/obS43dm2y5V8OvM97O4vbQGjmF3Yx2tatdvdOvFj7Az8Rfo0ic6xv6/Q/1 NSUPGtNhy3VJ5F7dxJ9g==; 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 1f46LO-0006Bk-LO; Thu, 05 Apr 2018 14:58:30 +0000 Received: from mail-by2nam01on0611.outbound.protection.outlook.com ([2a01:111:f400:fe42::611] helo=NAM01-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f46LK-0005yx-KC for linux-arm-kernel@lists.infradead.org; Thu, 05 Apr 2018 14:58:28 +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=tUSV54rxblVrCnns4jAdrRE0Sj/c1QkCvTi1oeXuQp4=; b=eq7us8fMSVZnyq5PGuB+L5Dn6zvyrKjJXP+wKd2Xq6PYg5ltLoKCq6yxaKDOyUiaZc7T0CahdS8yi6NFfM0kJj0gAMnzpUUsw7bJTbcr1Arx6YDpO2fNPhF/RGg2mAoJ5pulVRL1NRg7mcgcyO5HTNrZUUtxCDPbysFmNHXqcc4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Vadim.Lomovtsev@cavium.com; Received: from localhost.localdomain.com (50.233.148.156) by BN6PR07MB2993.namprd07.prod.outlook.com (2603:10b6:404:a7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.653.12; Thu, 5 Apr 2018 14:58:11 +0000 From: Vadim Lomovtsev To: sgoutham@cavium.com, sunil.kovvuri@gmail.com, robert.richter@kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net Subject: [PATCH] net: thunderx: rework mac addresses list to u64 array Date: Thu, 5 Apr 2018 07:57:56 -0700 Message-Id: <20180405145756.12633-1-Vadim.Lomovtsev@caviumnetworks.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: DM5PR12CA0069.namprd12.prod.outlook.com (2603:10b6:3:103::31) To BN6PR07MB2993.namprd07.prod.outlook.com (2603:10b6:404:a7::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8c40448b-077e-4195-21f8-08d59b05a71d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603328)(7153060)(7193020); SRVR:BN6PR07MB2993; X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB2993; 3:QweQbUyK64E2yy2IFjj9VNVcn34ZVHHArrPOcIZ7mEdJ6yInmS1QMJ5njdoQSXYI3LG4vj7vTHsid754PgG0idc3oJ4KuzyzpK/DyjgZS31l0AZ722JgvyNLoYOq5FIHsJsYANPV0mLMMPe6WNHnlhkv7aJoDbKvrGOqwdIKqAoCnK9xykpL/GE9N+ByK7U+aSB66d6jdLGj4GeEwonzPfn9kMyteubpn/XbfTgjYSM8plfgz2UBXhJdwiwWu0lV; 25:FuM4Q3SlhSUsqudOKZjpAR3WwveTUbOJMZy7CXS7VgB0eMEF3Y9n8MAY3wLO9+E2+x6No5atxqiBBQl7IUr/WjGyODBp2W8eHeN+4MYUEwpvUtlf24MTNY5TwVhTF22y7XQLPKcThIsjQrGoM4Zx2YKDok5wmq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vUXkdDDdmUaKawS3eIIUONVRqtpW8=; 4:qyQMgMK42z47P9A/HLWk8o5dBpKkgBHT9HFw39VW3mqGEtAE9FJheUs6hQiQ2er2ntZVpYur3yBvM0I2O7olBTbschomZqyG49LcGnS3xdxbK+n50PV6fH+EGONDz7K4w/mQqbGASuYeDTKy2j/+imLIPkcmjDCbjNxSmImPzRIr35meHoxzMOY+7fVuo2QHQzoJP2L7kvF/UJIvn9CEawgKzEdy0xYmfzbZeXP0htAaJoelweUq1N7AgQR+MtrUEjCkgJAGcWzNNJgM5mwziWri5OaC/717LEVC+w8kT/O/53A5ltCTW9o8geKUJ6du X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(277106579953875); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(10201501046)(3231221)(944501327)(52105095)(6041310)(20161123562045)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:BN6PR07MB2993; BCL:0; PCL:0; RULEID:; SRVR:BN6PR07MB2993; X-Forefront-PRVS: 06339BAE63 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(346002)(39380400002)(376002)(396003)(39860400002)(366004)(199004)(189003)(97736004)(6116002)(36756003)(6486002)(1076002)(16526019)(8936002)(3846002)(26005)(2906002)(66066001)(486006)(16586007)(2616005)(386003)(69596002)(476003)(6506007)(316002)(50226002)(478600001)(81166006)(956004)(81156014)(59450400001)(5660300001)(51416003)(105586002)(42882007)(68736007)(25786009)(48376002)(8676002)(47776003)(106356001)(72206003)(305945005)(53416004)(53936002)(7736002)(6512007)(39060400002)(52116002)(50466002)(4326008)(1857600001)(6666003)(107886003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR07MB2993; 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; BN6PR07MB2993; 23:De8vhtMlcAuXCZn4P/14GUNzBywL9zXLwvP5pS2Kg?= =?us-ascii?Q?lDYi1oqfgny+5boRCJy5556N7LrxYFY6qSolv01w8boOU6GdrojEzcMzLsiF?= =?us-ascii?Q?iu7bxccHMDvz6Dsw18PGkIczsazh+T0WCQEVVfadZurhO4LWZojDhpkad2ub?= =?us-ascii?Q?TN6oIitD89xzFzqgiuE1RG23dWWAbk9pUL8esMI+9Kozjh1aa58KD731dhBF?= =?us-ascii?Q?ptRNA0gcWgWFUWY444F/1AVA78YDpUlPfqpmj/6+RokEQkjjOL9zoiluzo+G?= =?us-ascii?Q?NC0gfMkiDWIcBWJiPw8GRJEuay3xUZJJl3NuoQM6Cxo46yWOtzKdkS0Co79+?= =?us-ascii?Q?fCDF6JYDsdmNy9CTDEdyF0LxAXRKo/BD4hcfkZfnkzP54GHCARxiGHV0OBUW?= =?us-ascii?Q?a0rZP/8EXDuRgNQIxdVw7BslxB62sNUhzKFuWQlQcnV0xcr9dvu1HzANfavJ?= =?us-ascii?Q?jZ0rP50eAPii9MtpOCe5LD44shJNYVR2fQ4DjSDUMwylZrzUdftNc506/efd?= =?us-ascii?Q?hVs+jUjzG3lURMaIUrN4Tkm5/wozhBsMmvvbGaNqsDv1y2EsHQQBbEl1v00W?= =?us-ascii?Q?9ktiP+0A2wVcKTxiCHOEQm7kX4yQFeS2Yud49AQKK4n8gaYEvalJseSMGtzN?= =?us-ascii?Q?jNt1JLHQv9/wO5/wb2D9L3aNsHVyPmWn/BWpDetgMYzBIA+F3H7BCHl+jSG3?= =?us-ascii?Q?N37peVpfQTCCg+C+yBCrndXktsmZtXPuhc0lwNCPERWSQf9vbFIYZp5HyQUM?= =?us-ascii?Q?brY/oHWJ6UG2fSW09zedXg00FYsAMnOnwWXdBprtpePjGQArBPGMf41FL+dz?= =?us-ascii?Q?RW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QcpG1HjGsmc/NcgFka1OxlTZQLrPDk2lW8GMbXpoEPs8RNuNxL3IZfg6MvGZqfCkM3UsD48HbSXFsWHnEtGkqndufn+1UFYLf0HIa1bJ2OWdxVCsdnbx3AB9WpSZvlf9qsb8hXveYSnIlxYJcAApgmH8sAtS8XiSiM5s+wxcUYcuXWqMMtZ3BEa5+qrOEyldgwj7vCTRHHBuEUIdJ2BYwnTjqToe3hJ4l8VyD1gf/TSRsKeP6g==; 5:nmWRJAvCAwwatnHLUOZso31uV/dqWUUfvOeo60KAcAjrvzMoIJkYRrnBIBw4+3WeABiQBPJmK/nvshuRX7F7EpmbRimcOX0tl8oWjB15+/+uQTG1Gq9enFmD5T3pePqq7J+8Y1+uHwyglHAW1ovsTbsumXR0tS87D6AC3JuWGpw=; 24:6ko45ZJepESfe+cZOEd8WX5VmhsPrWrzqqDCsRpYmdi9D5C79WXLSt2L8MNokKs5XA1fHBFNoXbJeazGde9kFAJ4AykP6dKYGt6w0NEDmS0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB2993; 7:yZ3Rrav+Mi1bKTx5PNeHuKiyceskPBjS6jEKJhfSMCVvNAMZjwW4+TeDuvAJPF/m8MxhiLTjJqk7odFukr9lnAtvfzfKFwS6q39jyRsuPTATA/J5vZFif7aHJ7lJOrjWJ3CmsJej2JqJLbJJnNcKtMAki6P+uh7ZPYI7JpQZ8juB3/8jM1gRwvm/LPtOlqnrlcnJ4b/U1zPC4Fcb2WyZ6ri+9QT0qB/UyDuNINUkmbm32k8aXck+MRovJotduxc6 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2018 14:58:11.3700 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c40448b-077e-4195-21f8-08d59b05a71d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR07MB2993 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180405_075826_679735_390313B6 X-CRM114-Status: GOOD ( 12.35 ) 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: dnelson@redhat.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") Signed-off-by: Vadim Lomovtsev --- 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..da052159f014 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[0]; }; 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..a26d8bc92e01 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; + u8 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(sizeof(*mc_list) + + sizeof(u64) * 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++; } }