Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp491933imm; Wed, 20 Jun 2018 01:34:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLGaSc2tAh/ajEti3Ho45VMgnmGahrfGyL33KbBAXoh7jTcIXqwNcqDcMyfS2/u4Q1DN4mq X-Received: by 2002:a63:66c4:: with SMTP id a187-v6mr206913pgc.167.1529483663365; Wed, 20 Jun 2018 01:34:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529483663; cv=none; d=google.com; s=arc-20160816; b=QPjDqBM0m52whRwIA59Csw8p9Iwi/XqMFxpVxtoFWhUDVaTqKv/GTXrN0LDcmCvIS8 U6rJnHX3igl50PBUx6iamMnONKoODedFt0CFnzW63ewY+uM7wQYRZew0v3keeN3Eb+Ze OSW2CzHwsCT3PX8v1q6rssvSAj1oLFDrBkrLCEVd6CTH/pO+ayyicl5MGG8hwdxWvzOQ eRi9l59XOUsAwgnP+Y0whNPJMW8FIMDk6oI//bjen6GUBQrg3ilQiRLJApAOHyqavRhy 8I5m1lCtd5zjqs/lXqrBbkJVkbaAArTGPgmoHzW7U9l1dhRH9+adS0s71CmVOvrqbEth laXw== 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=fNzO2cO+xAaZBKqjECLQFclx1kH3psAG5Mym4WnS0gc=; b=hXWZRoSdbTF6Y/tpiDxZh+wsIPCgp8TDzPYNmojOzBH7DsEoHhnJy1OYSC6ECPVras AjRylfJBgS3dT9aXbD0InKg0f4xuaMULyL4niQFO50xQCPBxA4k0Kp4TlpbWNyt6+dzm CuQ7s/kwLeJSZ5tgmiBeq6Sx5UcYqku34O2cf332JXbnSResWBDH7/P2dEMAzKEuBy9j Fx98//wkhA+LRDUc0Ldsq2dxOwwRGmjb3saPgg18oNRwknS9yPthMAlGWbxES8L47ths 2sruTD2+pVhFrwSpRXbuxAirzfpHG8yuH9el6ZyWTtKdPNXkdMqmFTSTkbwQ3XYPEVb0 zWcA== 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 p1-v6si1864508plo.363.2018.06.20.01.34.09; Wed, 20 Jun 2018 01:34:23 -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 S1754175AbeFTIdb convert rfc822-to-8bit (ORCPT + 99 others); Wed, 20 Jun 2018 04:33:31 -0400 Received: from mail.bootlin.com ([62.4.15.54]:44107 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752750AbeFTId2 (ORCPT ); Wed, 20 Jun 2018 04:33:28 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 9E1FD20750; Wed, 20 Jun 2018 09:38:15 +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, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-50-153.w90-88.abo.wanadoo.fr [90.88.168.153]) by mail.bootlin.com (Postfix) with ESMTPSA id 4C29C203EC; Wed, 20 Jun 2018 09:38:05 +0200 (CEST) Date: Wed, 20 Jun 2018 09:38:05 +0200 From: Boris Brezillon To: Kees Cook Cc: Ivan Djelic , Brian Norris , David Woodhouse , Marek Vasut , Richard Weinberger , Linux mtd , LKML Subject: Re: [PATCH v3] lib/bch: Remove VLA usage Message-ID: <20180620093805.6d9c602e@bbrezillon> In-Reply-To: References: <20180531184525.GA11068@beast> <20180601110921.GC4695@parrot.com> 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 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. Here is my Acked-by: Boris Brezillon in case you were waiting for it. Regards, Boris