public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data
@ 2018-12-08 10:24 Ard Biesheuvel
  2018-12-10 12:25 ` Leif Lindholm
  2018-12-11  1:48 ` Wu, Hao A
  0 siblings, 2 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2018-12-08 10:24 UTC (permalink / raw)
  To: edk2-devel; +Cc: jian.j.wang, hao.a.wu, ruiyu.ni, Ard Biesheuvel

Struct packing is only necessary for data structures whose in-memory
representation is covered by the PI or UEFI specs, and may deviate
from the ordinary C rules for alignment.

So in case of FileExplorerLib, this applies to the device path struct
only, and other structures used to carry program data should not be
packed, or we may end up with alignment faults on architectures such
as ARM, which don't permit load/store double or multiple instructions
to access memory locations that are not 32-bit aligned.

E.g., the following call in FileExplorerLibConstructor()

  InitializeListHead (&gFileExplorerPrivate.FsOptionMenu->Head);

which is emitted as follows for 32-bit ARM/Thumb2 by Clang-5.0

    3de0:       b510            push    {r4, lr}
    3de2:       4604            mov     r4, r0
    ...
    3de8:       e9c4 4400       strd    r4, r4, [r4]
    3dec:       bd10            pop     {r4, pc}

will perform a double-word store on the first argument, passed in
register r0, assuming that the pointer type of the argument is
enough to guarantee that the value is suitably aligned.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 MdeModulePkg/Library/FileExplorerLib/FileExplorer.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
index bf1450dbd581..603185abe4b1 100644
--- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
+++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
@@ -51,6 +51,8 @@ typedef struct {
   EFI_DEVICE_PATH_PROTOCOL       End;
 } HII_VENDOR_DEVICE_PATH;
 
+#pragma pack()
+
 typedef struct {
   EFI_HANDLE                        DeviceHandle;
   EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
@@ -100,8 +102,6 @@ typedef struct {
 
 #define FILE_EXPLORER_PRIVATE_FROM_THIS(a)  CR (a, FILE_EXPLORER_CALLBACK_DATA, FeConfigAccess, FILE_EXPLORER_CALLBACK_DATA_SIGNATURE)
 
-#pragma pack()
-
 extern UINT8    FileExplorerVfrBin[];
 
 #define MENU_OPTION_SIGNATURE      SIGNATURE_32 ('m', 'e', 'n', 'u')
-- 
2.19.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data
  2018-12-08 10:24 [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data Ard Biesheuvel
@ 2018-12-10 12:25 ` Leif Lindholm
  2018-12-10 14:39   ` Gao, Liming
  2018-12-11  1:48 ` Wu, Hao A
  1 sibling, 1 reply; 6+ messages in thread
From: Leif Lindholm @ 2018-12-10 12:25 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel, hao.a.wu, ruiyu.ni

On Sat, Dec 08, 2018 at 11:24:31AM +0100, Ard Biesheuvel wrote:
> Struct packing is only necessary for data structures whose in-memory
> representation is covered by the PI or UEFI specs, and may deviate
> from the ordinary C rules for alignment.
> 
> So in case of FileExplorerLib, this applies to the device path struct
> only, and other structures used to carry program data should not be
> packed, or we may end up with alignment faults on architectures such
> as ARM, which don't permit load/store double or multiple instructions
> to access memory locations that are not 32-bit aligned.
> 
> E.g., the following call in FileExplorerLibConstructor()
> 
>   InitializeListHead (&gFileExplorerPrivate.FsOptionMenu->Head);
> 
> which is emitted as follows for 32-bit ARM/Thumb2 by Clang-5.0
> 
>     3de0:       b510            push    {r4, lr}
>     3de2:       4604            mov     r4, r0
>     ...
>     3de8:       e9c4 4400       strd    r4, r4, [r4]
>     3dec:       bd10            pop     {r4, pc}
> 
> will perform a double-word store on the first argument, passed in
> register r0, assuming that the pointer type of the argument is
> enough to guarantee that the value is suitably aligned.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

I agree with the architectural rationale.

However, I also decided to have a look.

$ git grep "} HII_VENDOR_DEVICE_PATH;"
EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.h:} HII_VENDOR_DEVICE_PATH;
EdkCompatibilityPkg/Foundation/Library/Dxe/UefiEfiIfrSupportLib/UefiIfrLibrary.h:} HII_VENDOR_DEVICE_PATH;
EmbeddedPkg/Drivers/ConsolePrefDxe/ConsolePrefDxe.c:} HII_VENDOR_DEVICE_PATH;
EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c:} HII_VENDOR_DEVICE_PATH;
IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.h:} HII_VENDOR_DEVICE_PATH;
IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Application/UiApp/Ui.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Library/BootManagerUiLib/BootManager.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Library/FileExplorerLib/FileExplorer.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanup.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.h:} HII_VENDOR_DEVICE_PATH;
MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c:} HII_VENDOR_DEVICE_PATH;
NetworkPkg/IScsiDxe/IScsiConfig.h:} HII_VENDOR_DEVICE_PATH;
NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
QuarkPlatformPkg/Platform/Dxe/Setup/SetupPlatform.h:} HII_VENDOR_DEVICE_PATH;
SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.h:} HII_VENDOR_DEVICE_PATH;
SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
SecurityPkg/UserIdentification/PwdCredentialProviderDxe/PwdCredentialProvider.h:} HII_VENDOR_DEVICE_PATH;
SecurityPkg/UserIdentification/UserIdentifyManagerDxe/UserIdentifyManager.h:} HII_VENDOR_DEVICE_PATH;
SecurityPkg/UserIdentification/UserProfileManagerDxe/UserProfileManager.h:} HII_VENDOR_DEVICE_PATH;
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.h:} HII_VENDOR_DEVICE_PATH;
Vlv2TbltDevicePkg/PlatformSetupDxe/PlatformSetupDxe.c:} HII_VENDOR_DEVICE_PATH;

Now, I will confess to being lazy and not manually checking all of
them, but 100% of the ones I did check were identical (except in
packedness).

Does this definition belong in a central header somewhere rather than
in 29 (and counting) different locations, implemented differently?

/
    Leif

> ---
>  MdeModulePkg/Library/FileExplorerLib/FileExplorer.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> index bf1450dbd581..603185abe4b1 100644
> --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> @@ -51,6 +51,8 @@ typedef struct {
>    EFI_DEVICE_PATH_PROTOCOL       End;
>  } HII_VENDOR_DEVICE_PATH;
>  
> +#pragma pack()
> +
>  typedef struct {
>    EFI_HANDLE                        DeviceHandle;
>    EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
> @@ -100,8 +102,6 @@ typedef struct {
>  
>  #define FILE_EXPLORER_PRIVATE_FROM_THIS(a)  CR (a, FILE_EXPLORER_CALLBACK_DATA, FeConfigAccess, FILE_EXPLORER_CALLBACK_DATA_SIGNATURE)
>  
> -#pragma pack()
> -
>  extern UINT8    FileExplorerVfrBin[];
>  
>  #define MENU_OPTION_SIGNATURE      SIGNATURE_32 ('m', 'e', 'n', 'u')
> -- 
> 2.19.2
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data
  2018-12-10 12:25 ` Leif Lindholm
@ 2018-12-10 14:39   ` Gao, Liming
  2018-12-10 15:01     ` Leif Lindholm
  0 siblings, 1 reply; 6+ messages in thread
From: Gao, Liming @ 2018-12-10 14:39 UTC (permalink / raw)
  To: Leif Lindholm, Ard Biesheuvel
  Cc: Wu, Hao A, Ni, Ruiyu, edk2-devel@lists.01.org

Ard:
  I agree this change.

Leif:
  On the duplicated definition of HII_VENDOR_DEVICE_PATH, MdeModulePkg DriverSampleDxe first defines it and use it as the driver level definition. Other UEFI HII driver may refer to the driver sample driver and define the same structure. One centralized header file can be defined for the default HII vendor device path. If the driver wants to use the different one, it can define its own structure. 

Thanks
Liming
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Leif Lindholm
> Sent: Monday, December 10, 2018 8:26 PM
> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>; edk2-devel@lists.01.org
> Subject: Re: [edk2] [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data
> 
> On Sat, Dec 08, 2018 at 11:24:31AM +0100, Ard Biesheuvel wrote:
> > Struct packing is only necessary for data structures whose in-memory
> > representation is covered by the PI or UEFI specs, and may deviate
> > from the ordinary C rules for alignment.
> >
> > So in case of FileExplorerLib, this applies to the device path struct
> > only, and other structures used to carry program data should not be
> > packed, or we may end up with alignment faults on architectures such
> > as ARM, which don't permit load/store double or multiple instructions
> > to access memory locations that are not 32-bit aligned.
> >
> > E.g., the following call in FileExplorerLibConstructor()
> >
> >   InitializeListHead (&gFileExplorerPrivate.FsOptionMenu->Head);
> >
> > which is emitted as follows for 32-bit ARM/Thumb2 by Clang-5.0
> >
> >     3de0:       b510            push    {r4, lr}
> >     3de2:       4604            mov     r4, r0
> >     ...
> >     3de8:       e9c4 4400       strd    r4, r4, [r4]
> >     3dec:       bd10            pop     {r4, pc}
> >
> > will perform a double-word store on the first argument, passed in
> > register r0, assuming that the pointer type of the argument is
> > enough to guarantee that the value is suitably aligned.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> 
> I agree with the architectural rationale.
> 
> However, I also decided to have a look.
> 
> $ git grep "} HII_VENDOR_DEVICE_PATH;"
> EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.h:} HII_VENDOR_DEVICE_PATH;
> EdkCompatibilityPkg/Foundation/Library/Dxe/UefiEfiIfrSupportLib/UefiIfrLibrary.h:} HII_VENDOR_DEVICE_PATH;
> EmbeddedPkg/Drivers/ConsolePrefDxe/ConsolePrefDxe.c:} HII_VENDOR_DEVICE_PATH;
> EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c:} HII_VENDOR_DEVICE_PATH;
> IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.h:} HII_VENDOR_DEVICE_PATH;
> IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Application/UiApp/Ui.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Library/BootManagerUiLib/BootManager.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Library/FileExplorerLib/FileExplorer.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanup.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.h:} HII_VENDOR_DEVICE_PATH;
> MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c:} HII_VENDOR_DEVICE_PATH;
> NetworkPkg/IScsiDxe/IScsiConfig.h:} HII_VENDOR_DEVICE_PATH;
> NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
> QuarkPlatformPkg/Platform/Dxe/Setup/SetupPlatform.h:} HII_VENDOR_DEVICE_PATH;
> SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.h:} HII_VENDOR_DEVICE_PATH;
> SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
> SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
> SecurityPkg/UserIdentification/PwdCredentialProviderDxe/PwdCredentialProvider.h:} HII_VENDOR_DEVICE_PATH;
> SecurityPkg/UserIdentification/UserIdentifyManagerDxe/UserIdentifyManager.h:} HII_VENDOR_DEVICE_PATH;
> SecurityPkg/UserIdentification/UserProfileManagerDxe/UserProfileManager.h:} HII_VENDOR_DEVICE_PATH;
> SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
> Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.h:} HII_VENDOR_DEVICE_PATH;
> Vlv2TbltDevicePkg/PlatformSetupDxe/PlatformSetupDxe.c:} HII_VENDOR_DEVICE_PATH;
> 
> Now, I will confess to being lazy and not manually checking all of
> them, but 100% of the ones I did check were identical (except in
> packedness).
> 
> Does this definition belong in a central header somewhere rather than
> in 29 (and counting) different locations, implemented differently?
> 
> /
>     Leif
> 
> > ---
> >  MdeModulePkg/Library/FileExplorerLib/FileExplorer.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > index bf1450dbd581..603185abe4b1 100644
> > --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > @@ -51,6 +51,8 @@ typedef struct {
> >    EFI_DEVICE_PATH_PROTOCOL       End;
> >  } HII_VENDOR_DEVICE_PATH;
> >
> > +#pragma pack()
> > +
> >  typedef struct {
> >    EFI_HANDLE                        DeviceHandle;
> >    EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
> > @@ -100,8 +102,6 @@ typedef struct {
> >
> >  #define FILE_EXPLORER_PRIVATE_FROM_THIS(a)  CR (a, FILE_EXPLORER_CALLBACK_DATA, FeConfigAccess,
> FILE_EXPLORER_CALLBACK_DATA_SIGNATURE)
> >
> > -#pragma pack()
> > -
> >  extern UINT8    FileExplorerVfrBin[];
> >
> >  #define MENU_OPTION_SIGNATURE      SIGNATURE_32 ('m', 'e', 'n', 'u')
> > --
> > 2.19.2
> >
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data
  2018-12-10 14:39   ` Gao, Liming
@ 2018-12-10 15:01     ` Leif Lindholm
  0 siblings, 0 replies; 6+ messages in thread
From: Leif Lindholm @ 2018-12-10 15:01 UTC (permalink / raw)
  To: Gao, Liming; +Cc: Ard Biesheuvel, Wu, Hao A, Ni, Ruiyu, edk2-devel@lists.01.org

On Mon, Dec 10, 2018 at 02:39:01PM +0000, Gao, Liming wrote:
> Ard:
>   I agree this change.
> 
> Leif:
>   On the duplicated definition of HII_VENDOR_DEVICE_PATH,
>   MdeModulePkg DriverSampleDxe first defines it and use it as the
>   driver level definition. Other UEFI HII driver may refer to the
>   driver sample driver and define the same structure. One
>   centralized header file can be defined for the default HII vendor
>   device path. If the driver wants to use the different one, it can
>   define its own structure.

Exactly. You're correct, my comment was imprecise. But the fact that
29 locations use the same default HII vendor device patch definition
suggests that there would be value in having a centralised default to
refer to.

I raised https://bugzilla.tianocore.org/show_bug.cgi?id=1388

Actually, I found there are 3 more in edk2-platforms :)

https://bugzilla.tianocore.org/show_bug.cgi?id=1389

Regards,

Leif

> 
> Thanks
> Liming
> > -----Original Message-----
> > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Leif Lindholm
> > Sent: Monday, December 10, 2018 8:26 PM
> > To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > Cc: Wu, Hao A <hao.a.wu@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>; edk2-devel@lists.01.org
> > Subject: Re: [edk2] [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data
> > 
> > On Sat, Dec 08, 2018 at 11:24:31AM +0100, Ard Biesheuvel wrote:
> > > Struct packing is only necessary for data structures whose in-memory
> > > representation is covered by the PI or UEFI specs, and may deviate
> > > from the ordinary C rules for alignment.
> > >
> > > So in case of FileExplorerLib, this applies to the device path struct
> > > only, and other structures used to carry program data should not be
> > > packed, or we may end up with alignment faults on architectures such
> > > as ARM, which don't permit load/store double or multiple instructions
> > > to access memory locations that are not 32-bit aligned.
> > >
> > > E.g., the following call in FileExplorerLibConstructor()
> > >
> > >   InitializeListHead (&gFileExplorerPrivate.FsOptionMenu->Head);
> > >
> > > which is emitted as follows for 32-bit ARM/Thumb2 by Clang-5.0
> > >
> > >     3de0:       b510            push    {r4, lr}
> > >     3de2:       4604            mov     r4, r0
> > >     ...
> > >     3de8:       e9c4 4400       strd    r4, r4, [r4]
> > >     3dec:       bd10            pop     {r4, pc}
> > >
> > > will perform a double-word store on the first argument, passed in
> > > register r0, assuming that the pointer type of the argument is
> > > enough to guarantee that the value is suitably aligned.
> > >
> > > Contributed-under: TianoCore Contribution Agreement 1.1
> > > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > 
> > I agree with the architectural rationale.
> > 
> > However, I also decided to have a look.
> > 
> > $ git grep "} HII_VENDOR_DEVICE_PATH;"
> > EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.h:} HII_VENDOR_DEVICE_PATH;
> > EdkCompatibilityPkg/Foundation/Library/Dxe/UefiEfiIfrSupportLib/UefiIfrLibrary.h:} HII_VENDOR_DEVICE_PATH;
> > EmbeddedPkg/Drivers/ConsolePrefDxe/ConsolePrefDxe.c:} HII_VENDOR_DEVICE_PATH;
> > EmbeddedPkg/Drivers/DtPlatformDxe/DtPlatformDxe.c:} HII_VENDOR_DEVICE_PATH;
> > IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.h:} HII_VENDOR_DEVICE_PATH;
> > IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Application/UiApp/Ui.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Library/BootManagerUiLib/BootManager.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Library/FileExplorerLib/FileExplorer.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Library/PlatformVarCleanupLib/PlatVarCleanup.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Universal/HiiResourcesSampleDxe/HiiResourcesSample.c:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.h:} HII_VENDOR_DEVICE_PATH;
> > MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c:} HII_VENDOR_DEVICE_PATH;
> > NetworkPkg/IScsiDxe/IScsiConfig.h:} HII_VENDOR_DEVICE_PATH;
> > NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
> > QuarkPlatformPkg/Platform/Dxe/Setup/SetupPlatform.h:} HII_VENDOR_DEVICE_PATH;
> > SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.h:} HII_VENDOR_DEVICE_PATH;
> > SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
> > SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
> > SecurityPkg/UserIdentification/PwdCredentialProviderDxe/PwdCredentialProvider.h:} HII_VENDOR_DEVICE_PATH;
> > SecurityPkg/UserIdentification/UserIdentifyManagerDxe/UserIdentifyManager.h:} HII_VENDOR_DEVICE_PATH;
> > SecurityPkg/UserIdentification/UserProfileManagerDxe/UserProfileManager.h:} HII_VENDOR_DEVICE_PATH;
> > SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.h:} HII_VENDOR_DEVICE_PATH;
> > Vlv2TbltDevicePkg/Library/PlatformBdsLib/BdsPlatform.h:} HII_VENDOR_DEVICE_PATH;
> > Vlv2TbltDevicePkg/PlatformSetupDxe/PlatformSetupDxe.c:} HII_VENDOR_DEVICE_PATH;
> > 
> > Now, I will confess to being lazy and not manually checking all of
> > them, but 100% of the ones I did check were identical (except in
> > packedness).
> > 
> > Does this definition belong in a central header somewhere rather than
> > in 29 (and counting) different locations, implemented differently?
> > 
> > /
> >     Leif
> > 
> > > ---
> > >  MdeModulePkg/Library/FileExplorerLib/FileExplorer.h | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > > index bf1450dbd581..603185abe4b1 100644
> > > --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > > +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > > @@ -51,6 +51,8 @@ typedef struct {
> > >    EFI_DEVICE_PATH_PROTOCOL       End;
> > >  } HII_VENDOR_DEVICE_PATH;
> > >
> > > +#pragma pack()
> > > +
> > >  typedef struct {
> > >    EFI_HANDLE                        DeviceHandle;
> > >    EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
> > > @@ -100,8 +102,6 @@ typedef struct {
> > >
> > >  #define FILE_EXPLORER_PRIVATE_FROM_THIS(a)  CR (a, FILE_EXPLORER_CALLBACK_DATA, FeConfigAccess,
> > FILE_EXPLORER_CALLBACK_DATA_SIGNATURE)
> > >
> > > -#pragma pack()
> > > -
> > >  extern UINT8    FileExplorerVfrBin[];
> > >
> > >  #define MENU_OPTION_SIGNATURE      SIGNATURE_32 ('m', 'e', 'n', 'u')
> > > --
> > > 2.19.2
> > >
> > > _______________________________________________
> > > edk2-devel mailing list
> > > edk2-devel@lists.01.org
> > > https://lists.01.org/mailman/listinfo/edk2-devel
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data
  2018-12-08 10:24 [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data Ard Biesheuvel
  2018-12-10 12:25 ` Leif Lindholm
@ 2018-12-11  1:48 ` Wu, Hao A
  2018-12-11 12:15   ` Ard Biesheuvel
  1 sibling, 1 reply; 6+ messages in thread
From: Wu, Hao A @ 2018-12-11  1:48 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel@lists.01.org
  Cc: Wang, Jian J, Ni, Ruiyu, Gao, Liming, Leif Lindholm

> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Saturday, December 08, 2018 6:25 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Jian J; Wu, Hao A; Ni, Ruiyu; Ard Biesheuvel
> Subject: [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for
> program data
> 
> Struct packing is only necessary for data structures whose in-memory
> representation is covered by the PI or UEFI specs, and may deviate
> from the ordinary C rules for alignment.
> 
> So in case of FileExplorerLib, this applies to the device path struct
> only, and other structures used to carry program data should not be
> packed, or we may end up with alignment faults on architectures such
> as ARM, which don't permit load/store double or multiple instructions
> to access memory locations that are not 32-bit aligned.
> 
> E.g., the following call in FileExplorerLibConstructor()
> 
>   InitializeListHead (&gFileExplorerPrivate.FsOptionMenu->Head);
> 
> which is emitted as follows for 32-bit ARM/Thumb2 by Clang-5.0
> 
>     3de0:       b510            push    {r4, lr}
>     3de2:       4604            mov     r4, r0
>     ...
>     3de8:       e9c4 4400       strd    r4, r4, [r4]
>     3dec:       bd10            pop     {r4, pc}
> 
> will perform a double-word store on the first argument, passed in
> register r0, assuming that the pointer type of the argument is
> enough to guarantee that the value is suitably aligned.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  MdeModulePkg/Library/FileExplorerLib/FileExplorer.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> index bf1450dbd581..603185abe4b1 100644
> --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> @@ -51,6 +51,8 @@ typedef struct {
>    EFI_DEVICE_PATH_PROTOCOL       End;
>  } HII_VENDOR_DEVICE_PATH;
> 
> +#pragma pack()
> +
>  typedef struct {
>    EFI_HANDLE                        DeviceHandle;
>    EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
> @@ -100,8 +102,6 @@ typedef struct {
> 
>  #define FILE_EXPLORER_PRIVATE_FROM_THIS(a)  CR (a,
> FILE_EXPLORER_CALLBACK_DATA, FeConfigAccess,
> FILE_EXPLORER_CALLBACK_DATA_SIGNATURE)
> 
> -#pragma pack()
> -

Reviewed-by: Hao Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu

>  extern UINT8    FileExplorerVfrBin[];
> 
>  #define MENU_OPTION_SIGNATURE      SIGNATURE_32 ('m', 'e', 'n', 'u')
> --
> 2.19.2



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data
  2018-12-11  1:48 ` Wu, Hao A
@ 2018-12-11 12:15   ` Ard Biesheuvel
  0 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2018-12-11 12:15 UTC (permalink / raw)
  To: Wu, Hao A
  Cc: edk2-devel@lists.01.org, Jian J Wang, Ruiyu Ni, Gao, Liming,
	Leif Lindholm

On Tue, 11 Dec 2018 at 02:48, Wu, Hao A <hao.a.wu@intel.com> wrote:
>
> > -----Original Message-----
> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> > Sent: Saturday, December 08, 2018 6:25 PM
> > To: edk2-devel@lists.01.org
> > Cc: Wang, Jian J; Wu, Hao A; Ni, Ruiyu; Ard Biesheuvel
> > Subject: [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for
> > program data
> >
> > Struct packing is only necessary for data structures whose in-memory
> > representation is covered by the PI or UEFI specs, and may deviate
> > from the ordinary C rules for alignment.
> >
> > So in case of FileExplorerLib, this applies to the device path struct
> > only, and other structures used to carry program data should not be
> > packed, or we may end up with alignment faults on architectures such
> > as ARM, which don't permit load/store double or multiple instructions
> > to access memory locations that are not 32-bit aligned.
> >
> > E.g., the following call in FileExplorerLibConstructor()
> >
> >   InitializeListHead (&gFileExplorerPrivate.FsOptionMenu->Head);
> >
> > which is emitted as follows for 32-bit ARM/Thumb2 by Clang-5.0
> >
> >     3de0:       b510            push    {r4, lr}
> >     3de2:       4604            mov     r4, r0
> >     ...
> >     3de8:       e9c4 4400       strd    r4, r4, [r4]
> >     3dec:       bd10            pop     {r4, pc}
> >
> > will perform a double-word store on the first argument, passed in
> > register r0, assuming that the pointer type of the argument is
> > enough to guarantee that the value is suitably aligned.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > ---
> >  MdeModulePkg/Library/FileExplorerLib/FileExplorer.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > index bf1450dbd581..603185abe4b1 100644
> > --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.h
> > @@ -51,6 +51,8 @@ typedef struct {
> >    EFI_DEVICE_PATH_PROTOCOL       End;
> >  } HII_VENDOR_DEVICE_PATH;
> >
> > +#pragma pack()
> > +
> >  typedef struct {
> >    EFI_HANDLE                        DeviceHandle;
> >    EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
> > @@ -100,8 +102,6 @@ typedef struct {
> >
> >  #define FILE_EXPLORER_PRIVATE_FROM_THIS(a)  CR (a,
> > FILE_EXPLORER_CALLBACK_DATA, FeConfigAccess,
> > FILE_EXPLORER_CALLBACK_DATA_SIGNATURE)
> >
> > -#pragma pack()
> > -
>
> Reviewed-by: Hao Wu <hao.a.wu@intel.com>
>
> Best Regards,
> Hao Wu
>

Thanks all

Pushed as  f0574a194c1e..765fb87c2b70


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-12-11 12:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-08 10:24 [PATCH] MdeModulePkg/FileExplorerLib: avoid packed struct for program data Ard Biesheuvel
2018-12-10 12:25 ` Leif Lindholm
2018-12-10 14:39   ` Gao, Liming
2018-12-10 15:01     ` Leif Lindholm
2018-12-11  1:48 ` Wu, Hao A
2018-12-11 12:15   ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox