[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6df8e01e2e9e4906be5ceaea72c61c0f@AcuMS.aculab.com>
Date: Tue, 30 Mar 2021 08:14:37 +0000
From: David Laight <David.Laight@...LAB.COM>
To: '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>
CC: "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: Zhang Rui
> Sent: 30 March 2021 09:00
> To: Xiaofei Tan <tanxiaofei@...wei.com>; David Laight <David.Laight@...LAB.COM>; rjw@...ysocki.net;
> lenb@...nel.org; bhelgaas@...gle.com
> Cc: linux-acpi@...r.kernel.org; linux-kernel@...r.kernel.org; linux-pci@...r.kernel.org;
> linuxarm@...neuler.org
> Subject: Re: [PATCH v2 04/15] ACPI: table: replace __attribute__((packed)) by __packed
>
> On Tue, 2021-03-30 at 15:31 +0800, Zhang Rui wrote:
> > On Tue, 2021-03-30 at 10:23 +0800, Xiaofei Tan wrote:
> > > Hi David,
> > >
> > > On 2021/3/29 18:09, David Laight wrote:
> > > > From: Xiaofei Tan
> > > > > Sent: 27 March 2021 07:46
> > > > >
> > > > > Replace __attribute__((packed)) by __packed following the
> > > > > advice of checkpatch.pl.
> > > > >
> > > > > Signed-off-by: Xiaofei Tan <tanxiaofei@...wei.com>
> > > > > ---
> > > > > drivers/acpi/acpi_fpdt.c | 6 +++---
> > > > > 1 file changed, 3 insertions(+), 3 deletions(-)
> > > > >
> > > > > diff --git a/drivers/acpi/acpi_fpdt.c
> > > > > b/drivers/acpi/acpi_fpdt.c
> > > > > index a89a806..690a88a 100644
> > > > > --- a/drivers/acpi/acpi_fpdt.c
> > > > > +++ b/drivers/acpi/acpi_fpdt.c
> > > > > @@ -53,7 +53,7 @@ struct resume_performance_record {
> > > > > u32 resume_count;
> > > > > u64 resume_prev;
> > > > > u64 resume_avg;
> > > > > -} __attribute__((packed));
> > > > > +} __packed;
> > > > >
> > > > > struct boot_performance_record {
> > > > > struct fpdt_record_header header;
> > > > > @@ -63,13 +63,13 @@ struct boot_performance_record {
> > > > > u64 bootloader_launch;
> > > > > u64 exitbootservice_start;
> > > > > u64 exitbootservice_end;
> > > > > -} __attribute__((packed));
> > > > > +} __packed;
> > > > >
> > > > > struct suspend_performance_record {
> > > > > struct fpdt_record_header header;
> > > > > u64 suspend_start;
> > > > > u64 suspend_end;
> > > > > -} __attribute__((packed));
> > > > > +} __packed;
> > > >
> > > > My standard question about 'packed' is whether it is actually
> > > > needed.
> > > > It should only be used if the structures might be misaligned in
> > > > memory.
> > > > If the only problem is that a 64bit item needs to be 32bit
> > > > aligned
> > > > then a suitable type should be used for those specific fields.
> > > >
> > > > Those all look very dubious - the standard header isn't packed
> > > > so everything must eb assumed to be at least 32bit aligned.
> > > >
> > > > There are also other sub-structures that contain 64bit values.
> > > > These don't contain padding - but that requires 64bit alignement.
> > > >
> > > > The only problematic structure is the last one - which would have
> > > > a 32bit pad after the header.
> > > > Is this even right given than there are explicit alignment pads
> > > > in some of the other structures.
> > > >
> > > > If 64bit alignment isn't guaranteed then a '64bit aligned to
> > > > 32bit'
> > > > type should be used for the u64 fields.
> > > >
> > >
> > > Yes, some of them has been aligned already, then nothing changed
> > > when
> > > add this "packed ". Maybe the purpose of the original author is
> > > for
> > > extension, and can tell others that this struct need be packed.
> > >
> >
> > The patch is upstreamed recently but it was made long time ago.
> > I think the original problem is that one of the address, probably the
> > suspend_performance record, is not 64bit aligned, thus we can not
> > read
> > the proper content of suspend_start and suspend_end, mapped from
> > physical memory.
> >
> > I will try to find a machine to reproduce the problem with all
> > __attribute__((packed)) removed to double confirm this.
> >
>
> So here is the problem, without __attribute__((packed))
>
> [ 0.858442] suspend_record: 0xffffaad500175020
> /sys/firmware/acpi/fpdt/suspend/suspend_end_ns:addr:
> 0xffffaad500175030, 15998179292659843072
> /sys/firmware/acpi/fpdt/suspend/suspend_start_ns:addr:
> 0xffffaad500175028, 0
>
> suspend_record is mapped to 0xffffaad500175020, and it is combined with
> one 32bit header and two 64bit fields (suspend_start and suspend_end),
> this is how it is located in physical memory.
> So the addresses of the two 64bit fields are actually not 64bit
> aligned.
>
> David,
> Is this the "a 64bit item needs to be 32bit aligned" problem you
> referred?
> If yes, what is the proper fix? should I used two 32bits for each of
> the field instead?
Define something like:
typedef u64 __attribute__((aligned(4))) u64_align32;
and then use it for the 64bit structure members.
There doesn't seem to be a standard type name for it - although
it is used in several places.
I'm not entirely sure but is ACPI always LE?
(is it even x86 only??)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists