Received: by 10.192.165.148 with SMTP id m20csp3447894imm; Mon, 7 May 2018 12:27:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrsE0BdTuD0HL5TNHbe+oJM//+UVNjEzrjPsraeaU7yo1hKW7SqGsWpWBmJ/u/KHPWR4aD2 X-Received: by 2002:a24:1609:: with SMTP id a9-v6mr2793010ita.48.1525721252206; Mon, 07 May 2018 12:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525721252; cv=none; d=google.com; s=arc-20160816; b=sUXA2gtEqQtH4+gMxJZcFMIXWB/1VgAmAT8QlR1/A3WUOTcCUL8V8rIZ3jlyEjxjDC nwORoAY8KwHLtB1/hWxtLzDwxhUzDg7qXt/lYzejMowr86zSf3FA6cM61epTRckHV0iT 6P6Ot1P9cIjeWRKOq07arLTgz4b1XPCyhH36DioQXIEBWEuP553sV57fH/VqclR/78Bh dZAA0EEQtqn794kRJ4//X+PDT148W/upWlGavj8NftCoo5WS3JYixhmD3/pPY07MfXdu W8pnjxsoXaVxTJovgnWstHriRO04soPAzs4sM5HYCu/8cWIzxo9Qc3cb7G7mVc115Ll7 WMLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=PeR4NgLGT7trCdqtTJjXU/DZbzCxci3eOhLLgKpN23U=; b=hQCf7yM17nM6u4kCoXn+0PqgRLJoP5y0sFBuzN1nlnrjhO+gXYzIUJRHUaFSYxA2us H4GijKFHfqe3PCN48hgskGtX0Ks5wf8uGfL5k8VR11GkrqyhHzhXgfCUi0YrOTXEmRGp 3ebswmu9EurspBh2/62dRgydLPvjFfX5VThWyOXWHunctpJwcBsQCEMzGyPNDqOYclv1 a6a2+Jn5Iy/sZy0b4NVxzL4CAtkuqakyq6Y0M5xzrDY7+ZBR2pRrwMX/EG03Sw6jAFhW ueRfF+3exgt+LWedWlCEQ5xR2eX9okhRHLrXxjVzBFtdQHxoXCh3uIN5f133dJFOF0Vy uzeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=1QyDiUHX; 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 g12-v6si8073610itg.28.2018.05.07.12.27.18; Mon, 07 May 2018 12:27:32 -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=@lunn.ch header.s=20171124 header.b=1QyDiUHX; 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 S1752757AbeEGT0t (ORCPT + 99 others); Mon, 7 May 2018 15:26:49 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:51662 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752631AbeEGT0s (ORCPT ); Mon, 7 May 2018 15:26:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=PeR4NgLGT7trCdqtTJjXU/DZbzCxci3eOhLLgKpN23U=; b=1QyDiUHXnUmV2hG7EjM2YChCgYYsTMb6jnxlfwZQoubJVk5zpKjZcxBXOQtrz+0y2w4i/zWXROwC5iPY2ARe3AUnjyZ+SipKlRhFafm7XUOSseQRHAK8e5bWQQa96xGPsgokarpJrceQh20lTU9EhzfQzibaNw7DmSs7eQSxPXs=; Received: from andrew by vps0.lunn.ch with local (Exim 4.84_2) (envelope-from ) id 1fFlmT-000054-8a; Mon, 07 May 2018 21:26:41 +0200 Date: Mon, 7 May 2018 21:26:41 +0200 From: Andrew Lunn To: Salvatore Mesoraca Cc: Florian Fainelli , linux-kernel@vger.kernel.org, Kernel Hardening , netdev@vger.kernel.org, "David S. Miller" , Kees Cook , Vivien Didelot , David Laight Subject: Re: [PATCH v2] net: dsa: drop some VLAs in switch.c Message-ID: <20180507192641.GD31021@lunn.ch> References: <1525706596-13601-1-git-send-email-s.mesoraca16@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > >> +++ b/include/net/dsa.h > >> @@ -256,6 +256,9 @@ struct dsa_switch { > >> /* Number of switch port queues */ > >> unsigned int num_tx_queues; > >> > >> + unsigned long *bitmap; > >> + unsigned long _bitmap; > >> + > >> /* Dynamically allocated ports, keep last */ > >> size_t num_ports; > >> struct dsa_port ports[]; > >> diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c > >> index adf50fb..cebf35f0 100644 > >> --- a/net/dsa/dsa2.c > >> +++ b/net/dsa/dsa2.c > >> @@ -748,6 +748,20 @@ struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) > >> if (!ds) > >> return NULL; > >> > >> + /* We avoid allocating memory outside dsa_switch > >> + * if it is not needed. > >> + */ > >> + if (n <= sizeof(ds->_bitmap) * 8) { > >> + ds->bitmap = &ds->_bitmap; > > > > Should not this be / BITS_PER_BYTE? If the sizeof(unsigned long) is <= > > 8, then you don't need to allocate it, otherwise, you have to. > This optimization will save us an allocation when number of ports is > less than 32 or 64 (depending on arch). > IMHO it's useful, if you consider that, right now, DSA works only with > 12-ports switches. Do you have a feeling for the savings? I don't see it being very large, and given the extra code, it might actually be negative. Andrew