public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Alexander Graf <agraf@suse.de>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	trini@konsulko.com, robdclark@gmail.com, u-boot@lists.denx.de,
	edk2-devel@lists.01.org, Jian J Wang <jian.j.wang@intel.com>,
	Hao Wu <hao.a.wu@intel.com>, Ruiyu Ni <ruiyu.ni@intel.com>,
	Star Zeng <star.zeng@intel.com>, Andrew Fish <afish@apple.com>,
	Laszlo Ersek <lersek@redhat.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: Re: [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols
Date: Mon, 7 Jan 2019 14:09:32 +0000	[thread overview]
Message-ID: <20190107140932.uefkly3a3jzlyjjf@bivouac.eciton.net> (raw)
In-Reply-To: <20181225083024.GC14405@linaro.org>

Apologies for late reply, back from holidays today.

On Tue, Dec 25, 2018 at 05:30:25PM +0900, AKASHI Takahiro wrote:
> > >>> +struct efi_key_descriptor {
> > >>> +	efi_key key;
> > >>
> > >> Hello Takahiro,
> > >>
> > >> with the patch I can start the EFI shell. But I am still trying to check
> > >> the different definitions in this file.
> > >>
> > >> As mentioned in prior mail the size of enum is not defined in the C
> > >> spec. So better use u32.
> > > 
> > > Sure, but I still wonder whether this should be u32 or u16 (or even u8)
> > > as UEFI spec doesn't clearly define this.
> > 
> > Enums may hold up to INT_MAX, so just make it u32.
> 
> OK.
> 
> > > 
> > >>> +	u16 unicode;
> > >>> +	u16 shifted_unicode;
> > >>> +	u16 alt_gr_unicode;
> > >>> +	u16 shifted_alt_gr_unicode;
> > >>> +	u16 modifier;
> > >>> +	u16 affected_attribute;
> > >>> +};
> > >>> +
> > >>> +struct efi_hii_keyboard_layout {
> > >>> +	u16 layout_length;
> > >>> +	efi_guid_t guid;
> > >>
> > >> A patch to change the alignment of efi_guid_t to __alinged(8) has been
> > >> merged into efi-next.
> > > 
> > > I have one concern here;
> > > This structure will also be used as a data format/layout in a file,
> > > a package list, given the fact that UEFI defines ExportPackageLists().
> > > So extra six bytes after layout_length, for example, may not be very
> > > useful in general.
> > > I'm not very much sure if UEFI spec intends so.
> > 
> > I'm not sure I fully follow. We ideally should be compatible with edk2,
> > no? So if the spec isn't clear, let's make sure we clarify the spec to
> > the behavior edk2 exposes today.

The spec cannot simply be changed to be incompatible with a previous
version of the spec, regardless of what EDK2 happens to do. (But...)

> I'm not sure that EDK2 is very careful about data alignment.
> Regarding guid, in MdePkg/Include/Base.h,
> 	///
> 	/// 128 bit buffer containing a unique identifier value.
> 	/// Unless otherwise specified, aligned on a 64 bit boundary.
> 	///
> 	typedef struct {
> 	  UINT32  Data1;
> 	  UINT16  Data2;
> 	  UINT16  Data3;
> 	  UINT8   Data4[8];
> 	} GUID;
> in MdePkg/Include/Uefi/UefiBaseType.h,
> 	typedef GUID                      EFI_GUID;
> 
> There is no explicit "aligned()" attribute contrary to Heinrich's patch.

No, so the alignment when building for (any) ARM architecture will end
up being 32-bit. Which I agree does not seem to live up to the
specification's requirement on 64-bit alignment where nothing else is
said.

Since, obviously, u-boot and edk2 disagreeing about the layout of
structs that are exposed to external applications/drivers would defeat
this whole exercise, I think we should start by taking this question
to edk2-devel (which I have).

> Regarding hii_keyboard_layout,
> in  Include/Uefi/UefiInternalFormRepresentation.h,
> 	typedef struct {
> 	  UINT16                  LayoutLength;
> 	  EFI_GUID                Guid;
> 	  UINT32                  LayoutDescriptorStringOffset;
> 	  UINT8                   DescriptorCount;
> 	  // EFI_KEY_DESCRIPTOR    Descriptors[];
> 	} EFI_HII_KEYBOARD_LAYOUT;
> 
> No "packed" attribute, so neither in my code.

There is a #pragma pack(1) near the start of this file and a #pragma
pack() near the end.

Interestingly, UEFI 2.7a describes the EFI_HII_KEYBOARD_LAYOUT struct
as containing the EFI_KEY_DESCRIPTOR array at the end, whereas the
EDK2 code above has it commented it out.
EDK2 itself treats the EFI_HII_KEYBOARD_LAYOUT as a header, which is
discarded.

So, continuning the (But...)
My understanding is this:
- The EDK2 implementation does not conform to the specification; it
  completely packs the EFI_HII_KEYBOARD_LAYOUT, which the
  specification does not mention anything about. Since this code is
  well in the wild, and drivers tested against the current layout need
  to continuw eorking, I expect the only possible solution is to
  update the specification to say EFI_HII_KEYBOARD_LAYOUT must be
  packed.
- The default EDK2 definition of GUID  (and hence EFI_GUID) gives it a
  32-bit alignment requirement also on 64-bit architectures. In
  practice, I expect this would only affect (some of the) GUIDs that
  are members of structs used in UEFI interfaces. But that may already
  be too common an occurrence to audit and address in EDK2. Does the
  spec need to change on this also?

Can the TianoCore MdeModulePkg Maintainers on cc please comment?
(I also cc:d the other stewards as well as Ard, in case they have
further input.)

> > >>> +	u32 layout_descriptor_string_offset;
> > >>> +	u8 descriptor_count;
> > >>> +	struct efi_key_descriptor descriptors[];
> > >>> +};
> > >>> +
> > >>> +struct efi_hii_package_list_header {
> > >>> +	efi_guid_t package_list_guid;
> > >>> +	u32 package_length;
> > >>> +} __packed;
> > >>
> > >> You are defining several structures as __packed. It is unclear to me
> > >> where I can find this in the UEFI spec. Looking at EDK2 I could not find
> > >> the same __packed attributes.
> > > 
> > > To be honest, I don't know. I just copied these lines from
> > > the original patch from Leif & Rob.
> > > My guess here is that such data structures are also used as data
> > > formats/layouts as part of a package list in a *file* and that no paddings
> > > are necessary. Same as I explained above.
> > > 
> > > # Same comments to yours below.
> > > 
> > > I hope that Leif will confirm (or deny) it.
> > 
> > Leif? :)
> 
> I'd like to echo, "Leif?"

I think the __packed bits were added by Rob, presumably in order to
get the Shell (built with EDK2 headers) working.

Regards,

Leif


       reply	other threads:[~2019-01-07 14:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20181214101043.14067-1-takahiro.akashi@linaro.org>
     [not found] ` <20181214101043.14067-3-takahiro.akashi@linaro.org>
     [not found]   ` <eaa42b61-8335-e6f1-87c5-b9be79d32982@gmx.de>
     [not found]     ` <20181217011626.GC14562@linaro.org>
     [not found]       ` <84b6f3fd-ed68-a541-7727-69e5392984e6@suse.de>
     [not found]         ` <20181225083024.GC14405@linaro.org>
2019-01-07 14:09           ` Leif Lindholm [this message]
2019-01-07 18:29             ` [RESEND PATCH v2 2/6] efi_loader: Initial HII database protocols Laszlo Ersek
2019-01-07 19:22               ` Leif Lindholm
2019-01-08  0:28                 ` Laszlo Ersek
2019-01-08  9:51                   ` Leif Lindholm
2019-01-08 10:07                     ` Ard Biesheuvel
2019-01-08 11:55                     ` Laszlo Ersek
2019-01-08 15:12                       ` Gao, Liming
2019-01-08 15:45                         ` Leif Lindholm
2019-01-08 17:15                         ` Laszlo Ersek
2019-01-08 15:02                     ` Bi, Dandan

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-list 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=20190107140932.uefkly3a3jzlyjjf@bivouac.eciton.net \
    --to=devel@edk2.groups.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox