All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Kees Cook <keescook@chromium.org>
Cc: Ivan Djelic <ivan.djelic@parrot.com>,
	Brian Norris <computersforpeace@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Marek Vasut <marek.vasut@gmail.com>,
	Richard Weinberger <richard@nod.at>,
	Linux mtd <linux-mtd@lists.infradead.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] lib/bch: Remove VLA usage
Date: Wed, 20 Jun 2018 09:38:05 +0200	[thread overview]
Message-ID: <20180620093805.6d9c602e@bbrezillon> (raw)
In-Reply-To: <CAGXu5jJVX5tk3w5etreTPJpoEzXfF9bFD4GNNW69yRHZTEBYiA@mail.gmail.com>

Hi Kees,

On Tue, 19 Jun 2018 16:48:17 -0700
Kees Cook <keescook@chromium.org> wrote:

> On Fri, Jun 1, 2018 at 4:09 AM, Ivan Djelic <ivan.djelic@parrot.com> 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 <keescook@chromium.org>
> >> ---
> >> 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 <ivan.djelic@parrot.com>
> > Tested-by: Ivan Djelic <ivan.djelic@parrot.com>  
> 
> 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 <boris.brezillon@bootlin.com>

in case you were waiting for it.

Regards,

Boris

  reply	other threads:[~2018-06-20  8:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-31 18:45 [PATCH v3] lib/bch: Remove VLA usage Kees Cook
2018-06-01 11:09 ` Ivan Djelic
2018-06-19 23:48   ` Kees Cook
2018-06-20  7:38     ` Boris Brezillon [this message]
2018-06-20 18:16       ` Kees Cook
2018-06-24 20:12         ` Boris Brezillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180620093805.6d9c602e@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=ivan.djelic@parrot.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.