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:   Thu, 1 Apr 2021 14:23:17 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     "'Rafael J. Wysocki'" <rafael@...nel.org>
CC:     Bjorn Helgaas <helgaas@...nel.org>,
        Zhang Rui <rui.zhang@...el.com>,
        Xiaofei Tan <tanxiaofei@...wei.com>,
        "rjw@...ysocki.net" <rjw@...ysocki.net>,
        "lenb@...nel.org" <lenb@...nel.org>,
        "bhelgaas@...gle.com" <bhelgaas@...gle.com>,
        "linux-acpi@...r.kernel.org" <linux-acpi@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-pci@...r.kernel.org" <linux-pci@...r.kernel.org>,
        "linuxarm@...neuler.org" <linuxarm@...neuler.org>
Subject: RE: [PATCH v2 04/15] ACPI: table: replace __attribute__((packed)) by
 __packed

From: Rafael J. Wysocki
> Sent: 01 April 2021 14:50
...
> So what exactly is wrong with using "packed"?  It is way easier to
> understand for a casual reader of the code.

Because it is usually wrong!

If I have:
	struct foo {
		u64 val;
	} __packed;

And then have:
u64 bar(struct foo *foo)
{
	return foo->val;
}

The on some cpu the compiler has to generate the equivalent of:
	u8 *x = (void *)&foo->val;
	return x[0] | x[1] << 8 | x[2] << 16 | x[3] << 24 | x[4] << 32 | x[5] << 40 | x[6] << 48 | x[7] << 56;

If you can guarantee that the structure is 32bit aligned
then it can generate the simpler:
	u32 *x = (void *)&foo->val;
	return x[0] | x[1] << 32;

(Yes I've missed out the 64-bit casts)

This is why you should almost never use __packed.

There are historic structures with 64 bit items on 4 byte boundaries
(and 32 bit values on 2 byte boundaries).
Typically most of the fields are shorter so can be read directly
(although they might need a byte-swapping load).

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ