lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <nycvar.YSQ.7.76.1801170859210.13881@knanqh.ubzr>
Date:   Wed, 17 Jan 2018 09:03:29 -0500 (EST)
From:   Nicolas Pitre <nicolas.pitre@...aro.org>
To:     Russell King - ARM Linux <linux@...linux.org.uk>
cc:     Arnd Bergmann <arnd@...db.de>,
        Ard Biesheuvel <ard.biesheuvel@...aro.org>,
        Zhichang Yuan <yuanzhichang@...ilicon.com>,
        Linux ARM <linux-arm-kernel@...ts.infradead.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] ARM: make memzero optimization smarter

On Wed, 17 Jan 2018, Russell King - ARM Linux wrote:

> On Tue, Jan 16, 2018 at 11:07:34PM -0500, Nicolas Pitre wrote:
> > On Tue, 16 Jan 2018, Arnd Bergmann wrote:
> > 
> > > On Tue, Jan 16, 2018 at 6:10 PM, Nicolas Pitre <nicolas.pitre@...aro.org> wrote:
> > > > On Tue, 16 Jan 2018, Arnd Bergmann wrote:
> > > >
> > > >> However, we can avoid this class of bogus warnings for the memset() macro
> > > >> by only doing the micro-optimization for zero-length arguments when the
> > > >> length is a compile-time constant. This should also reduce code size by
> > > >> a few bytes, and avoid an extra branch for the cases that a variable-length
> > > >> argument is always nonzero, which is probably the common case anyway.
> > > >>
> > > >> I have made sure that the __memzero implementation can safely handle
> > > >> a zero length argument.
> > > >
> > > > Why not simply drop the test on (__n) != 0 then? I fail to see what the
> > > > advantage is in that case.
> > > 
> > > Good point. We might actually get even better results by dropping the
> > > __memzero path entirely, since gcc has can optimize trivial memset()
> > > operations and inline them.
> > > 
> > > If I read arch/arm/lib/memzero.S correctly, it saves exactly two 'orr'
> > > instructions compared to the memset.S implementation, but calling
> > > memset() rather than __memzero() from C code ends up saving a
> > > function call at least some of the time.
> > > 
> > > Building a defconfig kernel with gcc-7.2.1, I see 1919 calls to __memzero()
> > > and 636 calls to memset() in vmlinux. If I remove the macro entirely,
> > > I get 1775 calls to memset() instead, so 780 memzero instances got
> > > inlined, and kernel shrinks by 5488 bytes (0.03%), not counting the
> > > __memzero implementation that we could possibly also drop.
> > 
> > I get 3668 fewer bytes just by removing the test against 0 in the macro.
> > 
> > And an additional 5092 fewer bytes by removing the call-to-__memzero 
> > optimization.
> 
> However, __memzero is not safe against being called with a zero length
> so it's not something we can simply remove.

The idea is about the possibility of removing __memzero altogether.
It is not clear that the tiny performance gain from a dedicated memzero 
implementation is worth the current overhead around it.


Nicolas

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ