Received: by 10.192.165.156 with SMTP id m28csp1694259imm; Thu, 12 Apr 2018 01:42:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx495OiAh/kpQwsC27vYBq3wkfZHMBSa5GlPik6p+OODB+QkpdbRpepG+9+99BiNj/E7xgpki X-Received: by 10.98.10.131 with SMTP id 3mr6969988pfk.112.1523522525062; Thu, 12 Apr 2018 01:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523522525; cv=none; d=google.com; s=arc-20160816; b=xZespfuIfg/sZO7XjiIBQCooQuY57vq0GaxwZDcXeCW+v7Udw0CYts985fXBNlB45A q/mZEbixP39PAXwv0T/qW75U6fc2e+k9KEh2ZGTpt/G9VGeCC2QcoNQSy1KHQsiYBYm4 W/QhTW69f3ADmaAZkg694C35jZOCtGEHN7ESSFSe9zad9OZP2wZh0BIMJczhYCVCgMvg 8aiVfpc6Ph75AcJNjX7dbe/eMxIGprqVeBa4likYo+YP5MC47H4ZXBvqcvba5u/LOHXl 1i+0l2MfwtzjOx0LaJUL422Dlo+74MthDfMNHrB9FvvcblauxqD0i9TutPcioUqJo757 YX2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=bNCnfJyYWKbQBEzvs307gvBNu7S5veca5RoGFpEuf/c=; b=bNA0MyZof3ZE7lKFSncTWQ3XZMWo73dpLF4QRoAhaeKF5l9mgfbs8Q8gwy+MIreVFk rv1QM3sglS+qvcTzNkpNLY7vMZ2tml5KiHRS2QgXOg0R5r36vhEsK1rKkVV6GLW76qY5 /mQiCWhby3xhH7lUVKTn81AZeWisgFYOFtkFgirquj9e5pmZcvfFmQbrZ863glUJV/6M cuJZmJFJMMKYzvmw734IB0CGq4SP+OfkuRSiReQGl2nu2gbcJShovHY6ZJZgHSDXcCsZ CJ+k6JImF3lhiZk1CVFayIjgFspeqv1pIGmcUi5T9iE6rSQgez/3mmKzopmwkUknxYX9 /nkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bf7VBPd3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si1873299pgr.634.2018.04.12.01.41.27; Thu, 12 Apr 2018 01:42:04 -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=@linaro.org header.s=google header.b=Bf7VBPd3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752369AbeDLIiq (ORCPT + 99 others); Thu, 12 Apr 2018 04:38:46 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:37659 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751112AbeDLIio (ORCPT ); Thu, 12 Apr 2018 04:38:44 -0400 Received: by mail-io0-f194.google.com with SMTP id y128so5424068iod.4 for ; Thu, 12 Apr 2018 01:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=bNCnfJyYWKbQBEzvs307gvBNu7S5veca5RoGFpEuf/c=; b=Bf7VBPd3oSwfg/XfTDSWQIk/daG3wcKUR/vAPfqm4D7AAKeKUNzwTOpZFncJYJOpYm 1He1Pjn8v6FebTECe85dhI4+7Vdt6kIOM+9WS7KMvEitQ31IB3dj73QjLNGlmgBH29Ik 3oPQV1CZ68H0+MLrEOePD+RvR7ZeFgo3oZ7oI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=bNCnfJyYWKbQBEzvs307gvBNu7S5veca5RoGFpEuf/c=; b=R1wcF7XKGfN5wmJKphImRHaHTzCdUDnUYkprG5nEJNQaV2URCFhFFa8Mx++DCmJy1w h9LnP1BUn9icjFo9bfj7+anCnWwqWjIFbNap4V9MM+zotwverm7uJy99kwnqErZjQrBs 06RPJ2ZBQBtHmPVf6HpDND3TIv7ixRF+mCZ6PnDmWuGzq9OSj1wK3aO6L4tfKzoY0zmI brwWT/cPBI0EjCntkAqPTUJApeoWN9N/W1DnT/Q+fQ+ESDWPqbKDUF8pxR00lvKhyTvj m54LkCGM2FEpfQDK/diQ4Z/S3oNaqUbhiBF+BS+0HZMJEb4CT6/V5TfMFhaqdvbnGJl2 FqVw== X-Gm-Message-State: ALQs6tDKv2JM+A0IH2tmRZUlF8i6jrT/zvkL+Dj+tSbPIsMPpLpRHHnl ZyfmDvWxk9USonaG6qnNP85kpcsbjn99n/tN4WQp1Q== X-Received: by 10.107.140.202 with SMTP id o193mr7986603iod.175.1523522323679; Thu, 12 Apr 2018 01:38:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.207.141 with HTTP; Thu, 12 Apr 2018 01:38:43 -0700 (PDT) In-Reply-To: <20180411010352.17929-1-labbott@redhat.com> References: <20180411010352.17929-1-labbott@redhat.com> From: Linus Walleij Date: Thu, 12 Apr 2018 10:38:43 +0200 Message-ID: Subject: Re: [PATCHv4] gpio: Remove VLA from gpiolib To: Laura Abbott Cc: Kees Cook , Lukas Wunner , Rasmus Villemoes , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , kernel-hardening@lists.openwall.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 11, 2018 at 3:03 AM, Laura Abbott wrote: > The new challenge is to remove VLAs from the kernel > (see https://lkml.org/lkml/2018/3/7/621) to eventually > turn on -Wvla. > > Using a kmalloc array is the easy way to fix this but kmalloc is still > more expensive than stack allocation. Introduce a fast path with a > fixed size stack array to cover most chip with gpios below some fixed > amount. The slow path dynamically allocates an array to cover those > chips with a large number of gpios. > > Reviewed-and-tested-by: Lukas Wunner > Signed-off-by: Lukas Wunner > Signed-off-by: Laura Abbott > --- > v4: Changed some local variables to avoid coccinelle warnings. Added a > warning if the number of GPIOs exceeds the current fast path define. > > Lukas, I kept your Tested-by because the changes were pretty minimal. > Let me know if you want to run the tests again. This patch is starting to look really good. > +/* > + * Number of GPIOs to use for the fast path in set array > + */ > +#define FASTPATH_NGPIO 256 There is still some comment about this. And now that I am also tryint to think I wonder about it, we have a global ARCH_NR_GPIOS that is typically 512. Some archs set it up. This define is something of an abomination, in the ARM case it comes from arch/arm/include/asm/gpio.h where #define ARCH_NR_GPIOS CONFIG_ARCH_NR_GPIO where the latter is a Kconfig option that is mostly 512 for most ARM systems. Well, ARM looks like this: config ARCH_NR_GPIO int default 2048 if ARCH_SOCFPGA default 1024 if ARCH_BRCMSTB || ARCH_SHMOBILE || ARCH_TEGRA || \ ARCH_ZYNQ default 512 if ARCH_EXYNOS || ARCH_KEYSTONE || SOC_OMAP5 || \ SOC_DRA7XX || ARCH_S3C24XX || ARCH_S3C64XX || ARCH_S5PV210 default 416 if ARCH_SUNXI default 392 if ARCH_U8500 default 352 if ARCH_VT8500 default 288 if ARCH_ROCKCHIP default 264 if MACH_H4700 default 0 help Maximum number of GPIOs in the system. If unsure, leave the default value. So if FASTPATH_NGPIO should be anything else than ARCH_NR_GPIO this has to be established somewhere as a floor or half or something, but I would just set it as the same as ARCH_NR_GPIOS... The main reason this define exist is for this function from : /* Convert between the old gpio_ and new gpiod_ interfaces */ struct gpio_desc *gpio_to_desc(unsigned gpio); Nowadays that fact is a bit obscured since the variable is only used when assigning the base (in the global GPIO number space, which is what we want to get rid of but sigh) in gpiochip_find_base() where it attempts to place a newly allocated gpiochip in the higher region of this numberspace since the embedded SoC GPIO base tends to be 0, on old platforms. So I don't know about this. Can't we just use ARCH_NR_GPIOS? Very few systems have more than 512 assigned global GPIO numbers and those are FPGA experimental machines. In the long run obviously I want to get rid of these defines altogether and only allocate GPIO descriptos dynamically so as you see I am reluctant to add new numberspace weirdness around here. Yours, Linus Walleij