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]
Date:   Wed, 16 Oct 2019 09:01:26 -0700
From:   Dmitry Torokhov <dmitry.torokhov@...il.com>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc:     "Rafael J. Wysocki" <rafael@...nel.org>,
        Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
        Mika Westerberg <mika.westerberg@...ux.intel.com>,
        Linus Walleij <linus.walleij@...aro.org>,
        Ard Biesheuvel <ard.biesheuvel@...aro.org>,
        linux-acpi@...r.kernel.org, linux-kernel@...r.kernel.org,
        platform-driver-x86@...r.kernel.org
Subject: Re: [PATCH v5 11/14] software node: move small properties inline
 when copying

On Wed, Oct 16, 2019 at 10:48:57AM +0300, Andy Shevchenko wrote:
> On Tue, Oct 15, 2019 at 11:25:53AM -0700, Dmitry Torokhov wrote:
> > On Tue, Oct 15, 2019 at 03:20:28PM +0300, Andy Shevchenko wrote:
> > > On Fri, Oct 11, 2019 at 04:07:18PM -0700, Dmitry Torokhov wrote:
> > > > When copying/duplicating set of properties, move smaller properties that
> > > > were stored separately directly inside property entry structures. We can
> > > > move:
> > > > 
> > > > - up to 8 bytes from U8 arrays
> > > > - up to 4 words
> > > > - up to 2 double words
> > > > - one U64 value
> > > > - one or 2 strings.
> > > 
> > > Can you show where you extract such values?
> > 
> > the "value" union's largest member is u64, which is 8 bytes. Strings are
> > pointers, so on 32-bit arches you can stuff 2 pointers into 8 bytes,
> > while on 64-bits you have space for only one.
> > 
> > > 
> > > > +	if (!dst->is_inline && dst->length <= sizeof(dst->value)) {
> > > > +		/* We have an opportunity to move the data inline */
> > > > +		const void *tmp = dst->pointer;
> > > > +
> > > 
> > > > +		memcpy(&dst->value, tmp, dst->length);
> > > 
> > > ...because this is strange trick.
> > 
> > Not sure what is so strange about it. You just take data that is stored
> > separately and move it into the structure, provided that it is not too
> > big (i.e. it does not exceed sizeof(value union) size).
> 
> You store a value as union, but going to read as a member of union?
> I'm pretty sure it breaks standard rules.

No, I move the values _in place_ of the union, and the data is always
fetched via void pointers. And copying data via char * or memcpy() is
allowed even in C99 and C11.

But I am wondering why are we actually worrying about all of this? The
kernel is gnu89 and I think is going to stay this way because we use
initializers with a cast in a lot of places:

#define __RAW_SPIN_LOCK_UNLOCKED(lockname)      \
        (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)

and C99 and gnu99 do not allow this. See
https://lore.kernel.org/lkml/20141019231031.GB9319@node.dhcp.inet.fi/

Thanks.

-- 
Dmitry

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ