Received: by 10.192.165.156 with SMTP id m28csp1145611imm; Fri, 13 Apr 2018 14:11:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx49N1Ku7RgqR3C8+8Nx29Nqm/bf4L44cI8/V+oEviTd182orl9bJlNicGusbYsyQehkGhCKn X-Received: by 2002:a17:902:8ec5:: with SMTP id x5-v6mr6510498plo.391.1523653907434; Fri, 13 Apr 2018 14:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523653907; cv=none; d=google.com; s=arc-20160816; b=ChiCYYO2NLE8Xr5gjdZT+MInJ5EGlSPraUW4U3eGPecvWn5N+pvHLP7M8GdDxLkBZ8 TA7P0eyVbYCxqj5CSTygeKS4upz/DrsPOgzEBAk7Dyv/ERPefnwbU8Xt8pwP0MvHxTTE qjFGmROxeOWa2QJiFV88jQyfZXldguNSbIhQ8GlTAPXDTk0Qc/xhNvUgwg0JTzHSNvV5 39ERTwLt3glAw9Gv6HAJuEL+sNB4BANZKLhSruX5poPS6/Q4gD/DXmeRCCZ+bB8+RLS6 f72RzcUt2tyPTDx3AxNPtDY/JdNhkr2mBTpUY9Mjhh3gQ/mL3ycyqghlQEE0POi7R9ZG gsYQ== 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=OhrMLFZ7fAu/TsV3wI1DCpbh4yG72Hzczxmnj/pez10=; b=gj9RLzMEa/1VDro/PEbgwsO6FiRoUlDLT1zjb3KwaPrAdLZE4yKSuzNG+EJz1VbEdI KICpSyHjUnlEB0gd3icg1j1ME8m1PYdIoi/M+cy6SwacgUualxkLsU5ErH+2rkKDNYYy C2QCaP8RTEeiT3AV973MXtbi5pW4g+xV462oKLtjxbJ9bLFd+iKzPpo0RgLgUaHmRnLJ 6bMEHqwAR4duBT6SSn8wbKBpWVvn6UdVLEO0cl4+1jbXTzGVeJgusi64L2zhS/e+6Gef Zy3aL4YxpVfF0XVSWXu1kDYARHXYl/iMHj9hJJHP+WNmrslrSjmilqJ23DCgTTeklktd iPCQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9si5186578pff.109.2018.04.13.14.11.33; Fri, 13 Apr 2018 14:11:47 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751036AbeDMVK2 (ORCPT + 99 others); Fri, 13 Apr 2018 17:10:28 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:46085 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750839AbeDMVK0 (ORCPT ); Fri, 13 Apr 2018 17:10:26 -0400 Received: by mail-ot0-f193.google.com with SMTP id v64-v6so11339786otb.13 for ; Fri, 13 Apr 2018 14:10:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OhrMLFZ7fAu/TsV3wI1DCpbh4yG72Hzczxmnj/pez10=; b=d1V+vXvroDP+Sy0LqQILTlNTNgcWMDan2voqVLyuLMTUchp2fvxcJLLJATDAhG6sN5 X7Hl2l846gscZV9gRLD7QfBVZwWbIOGv7EPmVP/RulogBMlH9Mhs8t9mFqCVcZNCrMNK bPSjm/wbtCPW9wx30cq7qQb2k98vumeT884NkaYMURG8miDpOSTxA6np7aAuxweoBfzk PQaxAZUM33BB1IniNdtG5vtMRwtuSqHzeN9lOLO1/9cO4Z1922VslPnT2t+wYIViik+S Irvu/FsuPqh7AWu4KSoaNlWIh7TBVNw2UCAmSIp9x7giX9NxTjymAaZ3I7nS2f5/Ds3U V1dA== X-Gm-Message-State: ALQs6tBNVyzzn7jFGLSCdNBP1Gerohcrhzq19uBi8F/uSxGtu4q3h7LQ LHbdpGBYQBb8OTjv4wJ7S+1LpA== X-Received: by 2002:a9d:338a:: with SMTP id u10-v6mr4446975otc.263.1523653825515; Fri, 13 Apr 2018 14:10:25 -0700 (PDT) Received: from ?IPv6:2601:602:9802:a8dc::ce63? ([2601:602:9802:a8dc::ce63]) by smtp.gmail.com with ESMTPSA id b41-v6sm4015705oth.60.2018.04.13.14.10.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Apr 2018 14:10:23 -0700 (PDT) Subject: Re: [PATCHv4] gpio: Remove VLA from gpiolib To: Phil Reid , Linus Walleij Cc: Kees Cook , Lukas Wunner , Rasmus Villemoes , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , kernel-hardening@lists.openwall.com References: <20180411010352.17929-1-labbott@redhat.com> From: Laura Abbott Message-ID: <0aea6c90-ba94-708c-5cad-836c50dadfe6@redhat.com> Date: Fri, 13 Apr 2018 14:10:22 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/12/2018 05:39 PM, Phil Reid wrote: > On 12/04/2018 16:38, Linus Walleij wrote: >> 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. > Isn't that for total GPIO's in the system? > And the arrays just need to cater for max per chip? > From what I can understand of the code which is admittedly limited. > > Yeah the switch back to 256 was a mistake on my end (I think I grabbed an incorrect version for my base). ARCH_NR_GPIOs is the total number in the system which may be multiple chips so yes we would be possibly allocating more space than necessary. unsigned long fastpath[2 * BITS_TO_LONGS(FASTPATH_NGPIO)] unsigned long fastpath[2 * BITS_TO_LONGS(512)] unsigned long fastpath[2 * DIV_ROUND_UP(512, 8 * sizeof(long))] so we end up with 128 bytes on the stack total assuming I can do math correctly. I think this a fairly reasonable amount though, even if we are over-estimating if there are multiple chips. Thanks, Laura