Received: by 10.213.65.68 with SMTP id h4csp533397imn; Fri, 6 Apr 2018 04:50:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+/HrJIcCgZX6PjYtzIJX90w7/1jyMx6kSHKS5UBmnQFAYnsB6JL3i/BPyRh0hYsrkwJbtW X-Received: by 10.101.101.138 with SMTP id u10mr9652539pgv.54.1523015408651; Fri, 06 Apr 2018 04:50:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523015408; cv=none; d=google.com; s=arc-20160816; b=I+Kyz/W7jjb4be5fOLQFIYcwMU8II+JKZWKadCcQrLnn3FTJr7cbeIMs+7rPrm9ZXF FW3NeA8Ty+G0EEE+PkiGQk+vnG3cylEsG5FGggI9H/lnfWHvx/s6b7wDb1PW5xTuEtiG f5jmHwzFKuVmv2URSsV8hYuNvQQ+NLG+Oo44gjOyD6ov9zB3lKJCsrz1EyXWPs5wv8pU VLUIxBTyqWQuzbQtSuX0qYyf30JDGcYDKygxiLtS390P4Ph28hwD4Rg0qR3xaeEzggT9 ghGwsKLpCro+MIhYYy1q6nPMi3xrlqbNznpoM87okts7Gbz25IM/iVfzmDxD8EGiXxP2 EfJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=abF883A+X85KhEOa61JRIWIT7HMkpgkq/SDpxmADZbA=; b=APARa9mCcyDJ05jQjo/mdrgr40rie7iOL94nUUJuITnx4vCCs/qeFF4CXDoMxCKayW A4xWZsfycjHDfwMnKdTPC6Uwlb1MI/kZZ5DgMlB1mBKQCNtyl7BX2qnBSNgnc5eHBXNO k0D0GqWDPlhiaUMKu2Ijlrn+S92mkciFJq+WmGYw/pyaMvZ3DrK/kPgYgnwmK71eseX1 sbtwxEbBTlf9iqm7ZD6Qp1jEbgGNnlhFlKADQwAFn+6H0nppRNE7T9n7/9AiLDf8Y9/f 86vXWNs8s8AyxD3uh7UxIFH1hn1fZDgTB4cFWBEloScmjrppVM9DexRpyfeXZ/K05wmO E4xQ== ARC-Authentication-Results: i=1; mx.google.com; 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 18si7967413pfl.407.2018.04.06.04.49.54; Fri, 06 Apr 2018 04:50:08 -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; 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 S1752474AbeDFLsq (ORCPT + 99 others); Fri, 6 Apr 2018 07:48:46 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:35578 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751540AbeDFLso (ORCPT ); Fri, 6 Apr 2018 07:48:44 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 57F081529; Fri, 6 Apr 2018 04:48:44 -0700 (PDT) Received: from [10.1.210.88] (e110467-lin.cambridge.arm.com [10.1.210.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 88FC23F487; Fri, 6 Apr 2018 04:48:42 -0700 (PDT) Subject: Re: [PATCH v2] net: thunderx: rework mac addresses list to u64 array To: Vadim Lomovtsev , 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, Vadim Lomovtsev , gustavo@embeddedor.com References: <20180405145756.12633-1-Vadim.Lomovtsev@caviumnetworks.com> <20180406111425.14636-1-Vadim.Lomovtsev@caviumnetworks.com> From: Robin Murphy Message-ID: <32d75865-6407-9e9e-a78d-38ba761b2575@arm.com> Date: Fri, 6 Apr 2018 12:48:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180406111425.14636-1-Vadim.Lomovtsev@caviumnetworks.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/04/18 12:14, Vadim Lomovtsev wrote: > 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 > --- > Changes from v1 to v2: > - C99 syntax: update xcast_addr_list struct field mc[0] -> mc[]; > > --- > 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..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), FWIW if you really wanted to disambiguate that it's a structure and not just an array being allocated, then it could be expressed without explicit arithmetic: size = offsetof(typeof(*mc_list), mc[netdev_mc_count(netdev)]); but that's probably just a matter of personal preference at this point. Robin. > + 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++; > } > } >