Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3166905imm; Sun, 24 Jun 2018 13:14:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLuzyTLO46Ny0lEWs0Mgw+/6Zjb65CsSU6U1wyj3L8GC02e9s3YRknna42jxGYTEGXtgx+i X-Received: by 2002:a62:9d58:: with SMTP id i85-v6mr10277175pfd.76.1529871271377; Sun, 24 Jun 2018 13:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529871271; cv=none; d=google.com; s=arc-20160816; b=fxx0TJLkFMqS3bb5Lbav9JeFFWZ21aJ8P7/wQso+nurQz1XdJnPmQbqJY4+iWsjECG fyYZtCPUgK23tYLkWqN+/e5yDfySTRKBWkE/tcJnERFNZN7az7YAeDk/gCkE7W3Oo8wa RDeaM6smWkQ+5eIqSqBPRpg7Y+S3HYeufAaECXlr93/u0+tagypRN7vlXVJNLX/ZWfwX qLbRdF7pdA454EQH5Cfk4kMPtlfiyp0ZTQlube10uHnkL0LdWv55SDPNofrHITmer8EK LKR37bWyXYQw5voleqinlBGvdMTKqfYasPnLrqrIM2GL/iT3hwTfTlXnM8SkVboeuhp+ dZBw== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=hdWmUIkki88gapF/2HW8YDaHMfLFg3t6ahF+D2RmJsA=; b=Q8nLG2slnRMgrQhz4gxU3TI9Vzni+wzBogr1ng0eSlBRl1c8EZX9NZ/Zgn+3RabVh3 qURQbXkhnzwIYAMQcvhv/jaL7AjeRgkA4i3kaSGN2VxXzIAXNHr2PvkIQ2C7l2vBz0Sw BvsYub9F1nOs9jXqZ+1ODiKnxrv3nN7qHn4jJmBRw3ZwRSvkbf8N4aKpYBDjeQqRJRGG mttgpJ04EzAhLaa6fdxGmWGcIjR8wUz09db0jbPOoyuioJlT0v3Bfu+KhgC0I+60P0iK qYcfIuesxBVlUQIsLMzL7Kt6YIJLyzf0zjDWKKIb57VEwRHIV5ifoGomfFJLs2ktKZTj NTPQ== 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 y28-v6si1108702pfj.159.2018.06.24.13.14.03; Sun, 24 Jun 2018 13:14:31 -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 S1751624AbeFXUNC convert rfc822-to-8bit (ORCPT + 99 others); Sun, 24 Jun 2018 16:13:02 -0400 Received: from mail.bootlin.com ([62.4.15.54]:57975 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750972AbeFXUNB (ORCPT ); Sun, 24 Jun 2018 16:13:01 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 2EA142079C; Sun, 24 Jun 2018 22:12:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id DD023206A0; Sun, 24 Jun 2018 22:12:58 +0200 (CEST) Date: Sun, 24 Jun 2018 22:12:59 +0200 From: Boris Brezillon To: Kees Cook Cc: Richard Weinberger , LKML , Marek Vasut , Linux mtd , Ivan Djelic , Brian Norris , David Woodhouse Subject: Re: [PATCH v3] lib/bch: Remove VLA usage Message-ID: <20180624221259.3c39c77e@bbrezillon> In-Reply-To: References: <20180531184525.GA11068@beast> <20180601110921.GC4695@parrot.com> <20180620093805.6d9c602e@bbrezillon> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 Jun 2018 11:16:11 -0700 Kees Cook wrote: > On Wed, Jun 20, 2018 at 12:38 AM, Boris Brezillon > wrote: > > Hi Kees, > > > > On Tue, 19 Jun 2018 16:48:17 -0700 > > Kees Cook wrote: > > > >> On Fri, Jun 1, 2018 at 4:09 AM, Ivan Djelic wrote: > >> > On Thu, May 31, 2018 at 11:45:25AM -0700, Kees Cook wrote: > >> >> In the quest to remove all stack VLA usage from the kernel[1], this > >> >> allocates a fixed size stack array to cover the range needed for > >> >> bch. This was done instead of a preallocation on the SLAB due to > >> >> performance reasons, shown by Ivan Djelic: > >> >> > >> >> little-endian, type sizes: int=4 long=8 longlong=8 > >> >> cpu: Intel(R) Core(TM) i5 CPU 650 @ 3.20GHz > >> >> calibration: iter=4.9143µs niter=2034 nsamples=200 m=13 t=4 > >> >> > >> >> Buffer allocation | Encoding throughput (Mbit/s) > >> >> --------------------------------------------------- > >> >> on-stack, VLA | 3988 > >> >> on-stack, fixed | 4494 > >> >> kmalloc | 1967 > >> >> > >> >> So this change actually improves performance too, it seems. > >> >> > >> >> The resulting stack allocation can get rather large; without > >> >> CONFIG_BCH_CONST_PARAMS, it will allocate 4096 bytes, which > >> >> trips the stack size checking: > >> >> > >> >> lib/bch.c: In function ‘encode_bch’: > >> >> lib/bch.c:261:1: warning: the frame size of 4432 bytes is larger than 2048 bytes [-Wframe-larger-than=] > >> >> > >> >> Even the default case for "allmodconfig" (with CONFIG_BCH_CONST_M=14 and > >> >> CONFIG_BCH_CONST_T=4) would have started throwing a warning: > >> >> > >> >> lib/bch.c: In function ‘encode_bch’: > >> >> lib/bch.c:261:1: warning: the frame size of 2288 bytes is larger than 2048 bytes [-Wframe-larger-than=] > >> >> > >> >> But this is how large it's always been; it was just hidden from > >> >> the checker because it was a VLA. So the Makefile has been adjusted to > >> >> silence this warning for anything smaller than 4500 bytes, which should > >> >> provide room for normal cases, but still low enough to catch any future > >> >> pathological situations. > >> >> > >> >> [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com > >> >> > >> >> Signed-off-by: Kees Cook > >> >> --- > >> >> v3: fix r_bytes to whole-word size > >> >> v2: switch to fixed-size stack array > >> >> --- > >> >> lib/Makefile | 1 + > >> >> lib/bch.c | 23 +++++++++++++++-------- > >> >> 2 files changed, 16 insertions(+), 8 deletions(-) > >> > > >> > > >> > The patch looks good to me. It also passed my regression tests. > >> > > >> > Reviewed-by: Ivan Djelic > >> > Tested-by: Ivan Djelic > >> > >> Thanks for the review and testing! > >> > >> Who's the best person to carry this patch? > > > > Looks like all users of this lib are in drivers/mtd, so I can take the > > patches if you want, but I can also let you take them if you prefer. > > I'd love it if you could take it; thank you! Applied to mtd/next. Thanks, Boris