Skip to contentSkip to conversation

Add basic Boot Loader Interface support

PATCH In review Oliver Steffen 8 participants 58 messages May 26, 2023 – Oct 5, 2023 Kbuild

lore
Share & tools
lore
#0 lore raw

v9 cover Add basic Boot Loader Interface support

This is a step towards supporting unified kernel images (UKI) in Grub.

Add a new module named bli. It implements a small but quite useful part of the Boot Loader Interface [0]. This interface uses EFI variables for communication between the boot loader and the operating system.

This module sets two EFI variables under the vendor GUID 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:

- LoaderInfo: contains GRUB + <version number>.
This allows the running operating system to identify the boot loader used during boot.

- LoaderDevicePartUUID: contains the partition UUID of the EFI System Partition (ESP). This is used by systemd-gpt-auto-generator [1] to find the root partitions (and others too), via partition type IDs [2]. This is especially useful for UKIs, where the kernel command line is fixed and usually does not contain any information about the root partition.

This module is only available on EFI platforms.

This series also unifies the GUID implementations and introduces a printf format specifier for them: %pG.

[0] https://systemd.io/BOOT_LOADER_INTERFACE/
[1] https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
[2] https://uapi-group.org/specifications/specs/discoverable_partitions_specification/

v9:
- Rebase to latest master branch
- Fix error handling in bli.c: get_part_uuid()
And with that fix the NULL pointer issue discovered by Coverity
- Add NULL checks to grub_device_close() and grub_disk_close() These are not strictly needed anymore with the changed error handling in get_part_uuid().
I leave the fate of this patch at the maintainer's discretion.

v8:
- https://mail.gnu.org/archive/html/grub-devel/2023-05/msg00128.html
- Rebase to latest master branch
- Fix the documentation build (I hope)
- Fix build on arm
- Make more grub_guid instances 'static'
- Move endian conversion back out of the grub_guid printf code

v7:
- https://mail.gnu.org/archive/html/grub-devel/2023-05/msg00005.html
- Add a "Modules" chapter to the documentation and describe the bli module there
- Reword some section headings in the documentation

v6:
- https://mail.gnu.org/archive/html/grub-devel/2023-04/msg00068.html
- Initialize the Boot Loader Interface on module load and remove the bli command.
- Extract code for grub_efi_set_variable_to_string()
- Improve error messages in the bli module
- Improve GUID printing code

v5:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00120.html
- Replace more grub_*_guid with the new grub_guid struct

v4:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00058.html
- Place grub_utf8_to_utf16_alloc() in kern/misc.c and use it in kern/efi.c
- bli: rework partition GUID code, improve error reporting
- Add documentation for the bli module
- Address other comments

v3:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00008.html
- Unify GUID implementations for GPT and EFI
- Add printf format specifier for GUIDs, drop guid print function from v2.
- WIP/Please comment: Started extracting utf8->utf16 code. Where should this go?
- Address other comments

v2:
- https://mail.gnu.org/archive/html/grub-devel/2023-02/msg00099.html
- Addressed comments from Daniel
- Added a print function for gpt guids`
- Added integer overflow check in UTF16 conversion
- Added config drop-in file that loads the module on EFI

v1:
- https://mail.gnu.org/archive/html/grub-devel/2023-01/msg00104.html

Oliver Steffen (11):
efi: Add grub_efi_set_variable_with_attributes() Unify GUID types
kern/misc: Add a format specifier GUIDs
grub-core: Make use of guid printf format specifier types.h: Add GRUB_SSIZE_MAX
kern/misc, kern/efi: Extract UTF-8 to UTF-16 code
efi: Add grub_efi_set_variable_to_string()
docs: Reword section headings
kern: check for NULL when closing devices and disks Add a module for the Boot Loader Interface util/grub.d: Activate bli module on EFI

 Makefile.util.def                    |   6 ++
 docs/grub.texi                       |  43 +++++++---
 grub-core/Makefile.core.def          |   6 ++
 grub-core/commands/acpi.c            |   4 +-
 grub-core/commands/bli.c             | 122 +++++++++++++++++++++++++++
 grub-core/commands/efi/efifwsetup.c  |   4 +-
 grub-core/commands/efi/loadbios.c    |  14 +--
 grub-core/commands/efi/lsefi.c       |  17 +---
 grub-core/commands/efi/lsefisystab.c |  10 +--
 grub-core/commands/efi/lssal.c       |   4 +-
 grub-core/commands/efi/smbios.c      |  12 +--
 grub-core/commands/efi/tpm.c         |   6 +-
 grub-core/commands/probe.c           |  14 ++-
 grub-core/disk/efi/efidisk.c         |   4 +-
 grub-core/disk/ldm.c                 |   2 +-
 grub-core/efiemu/i386/pc/cfgtables.c |   6 +-
 grub-core/efiemu/main.c              |   4 +-
 grub-core/efiemu/runtime/efiemu.c    |  14 +--
 grub-core/kern/device.c              |   3 +
 grub-core/kern/disk.c                |   4 +
 grub-core/kern/efi/acpi.c            |  12 +--
 grub-core/kern/efi/efi.c             | 109 ++++++++++++------------
 grub-core/kern/efi/fdt.c             |   2 +-
 grub-core/kern/efi/init.c            |   2 +-
 grub-core/kern/efi/sb.c              |   4 +-
 grub-core/kern/misc.c                | 113 ++++++++++++++++++++-----
 grub-core/loader/efi/fdt.c           |   2 +-
 grub-core/loader/efi/linux.c         |   4 +-
 grub-core/loader/i386/xnu.c          |  13 +--
 grub-core/loader/ia64/efi/linux.c    |   2 +-
 grub-core/net/drivers/efi/efinet.c   |   4 +-
 grub-core/partmap/gpt.c              |   4 +-
 grub-core/term/efi/console.c         |   2 +-
 grub-core/term/efi/serial.c          |   2 +-
 grub-core/video/efi_gop.c            |   8 +-
 grub-core/video/efi_uga.c            |   2 +-
 include/grub/efi/api.h               |  69 ++++++---------
 include/grub/efi/efi.h               |  23 +++--
 include/grub/efiemu/efiemu.h         |  10 +--
 include/grub/efiemu/runtime.h        |   2 +-
 include/grub/gpt_partition.h         |  13 +--
 include/grub/misc.h                  |   3 +
 include/grub/types.h                 |  11 +++
 util/grub-install.c                  |   2 +-
 util/grub-probe.c                    |   2 +-
 util/grub.d/25_bli.in                |  24 ++++++
 46 files changed, 487 insertions(+), 256 deletions(-)
 create mode 100644 grub-core/commands/bli.c
 create mode 100644 util/grub.d/25_bli.in
Signature · 1 line
2.40.1
#1 lore raw

PATCH v9 1/11 efi: Add grub_efi_set_variable_with_attributes()

Add a function to the EFI module that allows setting EFI variables with specific attributes.

This is useful for marking variables as volatile, for example.

---
 grub-core/kern/efi/efi.c | 20 +++++++++++++-------
 include/grub/efi/efi.h   |  6 ++++++
 2 files changed, 19 insertions(+), 7 deletions(-)
grub-core/kern/efi/efi.c +13 -7
index c84d5d280..4a1df6fb2 100644
@@ -203,8 +203,8 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
 }
 
 grub_err_t
-grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
-		      void *data, grub_size_t datasize)
+grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *guid,
+		      void *data, grub_size_t datasize, grub_efi_uint32_t attributes)
 {
   grub_efi_status_t status;
   grub_efi_runtime_services_t *r;
@@ -221,11 +221,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
 
   r = grub_efi_system_table->runtime_services;
 
-  status = r->set_variable (var16, guid,
-			    (GRUB_EFI_VARIABLE_NON_VOLATILE
-			     | GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
-			     | GRUB_EFI_VARIABLE_RUNTIME_ACCESS),
-			    datasize, data);
+  status = r->set_variable (var16, guid, attributes, datasize, data);
   grub_free (var16);
   if (status == GRUB_EFI_SUCCESS)
     return GRUB_ERR_NONE;
@@ -233,6 +229,16 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
   return grub_error (GRUB_ERR_IO, "could not set EFI variable `%s'", var);
 }
 
+grub_err_t
+grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,
+		      void *data, grub_size_t datasize)
+{
+  return grub_efi_set_variable_with_attributes (var, guid, data, datasize, 
+			GRUB_EFI_VARIABLE_NON_VOLATILE
+			| GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
+			| GRUB_EFI_VARIABLE_RUNTIME_ACCESS);
+}
+
 grub_efi_status_t
 grub_efi_get_variable_with_attributes (const char *var,
 				       const grub_efi_guid_t *guid,
include/grub/efi/efi.h +6 -0
index d3b967619..26f33433b 100644
@@ -98,6 +98,12 @@ grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
 						       grub_size_t *datasize_out,
 						       void **data_out);
 grub_err_t
+EXPORT_FUNC (grub_efi_set_variable_with_attributes) (const char *var,
+				     const grub_efi_guid_t *guid,
+				     void *data,
+				     grub_size_t datasize,
+				     grub_efi_uint32_t attributes);
+grub_err_t
 EXPORT_FUNC (grub_efi_set_variable) (const char *var,
 				     const grub_efi_guid_t *guid,
 				     void *data,
Signature · 1 line
2.40.1
#2 lore raw

PATCH v9 2/11 Unify GUID types

In reply to Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

---
 grub-core/commands/acpi.c            |  4 +-
 grub-core/commands/efi/efifwsetup.c  |  4 +-
 grub-core/commands/efi/loadbios.c    | 14 +++---
 grub-core/commands/efi/lsefi.c       |  4 +-
 grub-core/commands/efi/lsefisystab.c |  4 +-
 grub-core/commands/efi/lssal.c       |  4 +-
 grub-core/commands/efi/smbios.c      | 12 +++---
 grub-core/commands/efi/tpm.c         |  6 +--
 grub-core/commands/probe.c           |  2 +-
 grub-core/disk/efi/efidisk.c         |  4 +-
 grub-core/disk/ldm.c                 |  2 +-
 grub-core/efiemu/i386/pc/cfgtables.c |  6 +--
 grub-core/efiemu/main.c              |  4 +-
 grub-core/efiemu/runtime/efiemu.c    | 14 +++---
 grub-core/kern/efi/acpi.c            | 12 +++---
 grub-core/kern/efi/efi.c             | 22 +++++-----
 grub-core/kern/efi/fdt.c             |  2 +-
 grub-core/kern/efi/init.c            |  2 +-
 grub-core/kern/efi/sb.c              |  4 +-
 grub-core/loader/efi/fdt.c           |  2 +-
 grub-core/loader/efi/linux.c         |  4 +-
 grub-core/loader/i386/xnu.c          |  4 +-
 grub-core/loader/ia64/efi/linux.c    |  2 +-
 grub-core/net/drivers/efi/efinet.c   |  4 +-
 grub-core/partmap/gpt.c              |  4 +-
 grub-core/term/efi/console.c         |  2 +-
 grub-core/term/efi/serial.c          |  2 +-
 grub-core/video/efi_gop.c            |  8 ++--
 grub-core/video/efi_uga.c            |  2 +-
 include/grub/efi/api.h               | 64 ++++++++++------------------
 include/grub/efi/efi.h               | 16 +++----
 include/grub/efiemu/efiemu.h         | 10 ++---
 include/grub/efiemu/runtime.h        |  2 +-
 include/grub/gpt_partition.h         | 13 +-----
 include/grub/types.h                 |  9 ++++
 util/grub-install.c                  |  2 +-
 util/grub-probe.c                    |  2 +-
 37 files changed, 130 insertions(+), 148 deletions(-)
grub-core/commands/acpi.c +2 -2
index ab067ae6e..deec4bb43 100644
@@ -759,8 +759,8 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
 
 #ifdef GRUB_MACHINE_EFI
   {
-    struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID;
-    struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
+    static grub_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
+    static grub_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
 
     grub_efi_system_table->boot_services->install_configuration_table (&acpi20,
 								       grub_acpi_get_rsdpv2 ());
grub-core/commands/efi/efifwsetup.c +2 -2
index de66c3035..704f9d352 100644
@@ -38,7 +38,7 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
   grub_efi_uint64_t os_indications = GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
   grub_err_t status;
   grub_size_t oi_size;
-  static grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
 
   if (argc >= 1 && grub_strcmp(args[0], "--is-supported") == 0)
     return !efifwsetup_is_supported ();
@@ -72,7 +72,7 @@ efifwsetup_is_supported (void)
 {
   grub_efi_uint64_t *os_indications_supported = NULL;
   grub_size_t oi_size = 0;
-  static grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
   grub_efi_boolean_t ret = 0;
 
   grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size,
grub-core/commands/efi/loadbios.c +7 -7
index 574e41046..8f6b0ecfc 100644
@@ -27,9 +27,9 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
-static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
-static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
+static grub_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
+static grub_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
+static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
 
 #define EBDA_SEG_ADDR	0x40e
 #define LOW_MEM_ADDR	0x413
@@ -105,15 +105,15 @@ fake_bios_data (int use_rom)
   smbios = 0;
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_efi_guid_t)))
+      if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_guid_t)))
 	{
 	  acpi = grub_efi_system_table->configuration_table[i].vendor_table;
 	  grub_dprintf ("efi", "ACPI2: %p\n", acpi);
 	}
-      else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
+      else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_guid_t)))
 	{
 	  void *t;
 
@@ -122,7 +122,7 @@ fake_bios_data (int use_rom)
 	    acpi = t;
 	  grub_dprintf ("efi", "ACPI: %p\n", t);
 	}
-      else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_guid_t)))
+      else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_guid_t)))
 	{
 	  smbios = grub_efi_system_table->configuration_table[i].vendor_table;
 	  grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
grub-core/commands/efi/lsefi.c +2 -2
index 539701497..6935cd302 100644
@@ -31,7 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 
 struct known_protocol
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 } known_protocols[] =
   {
@@ -96,7 +96,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
       grub_efi_handle_t handle = handles[i];
       grub_efi_status_t status;
       grub_efi_uintn_t num_protocols;
-      grub_efi_packed_guid_t **protocols;
+      grub_guid_t **protocols;
       grub_efi_device_path_t *dp;
 
       grub_printf ("Handle %p\n", handle);
grub-core/commands/efi/lsefisystab.c +2 -2
index ac3299b7f..eff8c41f3 100644
@@ -29,7 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 
 struct guid_mapping
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 };
 
@@ -104,7 +104,7 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),
 
       for (j = 0; j < ARRAY_SIZE (guid_mappings); j++)
 	if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
-			 sizeof (grub_efi_guid_t)) == 0)
+			 sizeof (grub_guid_t)) == 0)
 	  grub_printf ("   %s", guid_mappings[j].name);
 
       grub_printf ("\n");
grub-core/commands/efi/lssal.c +2 -2
index 5084ddd8b..fd6085f1b 100644
@@ -139,12 +139,12 @@ grub_cmd_lssal (struct grub_command *cmd __attribute__ ((unused)),
   const grub_efi_system_table_t *st = grub_efi_system_table;
   grub_efi_configuration_table_t *t = st->configuration_table;
   unsigned int i;
-  grub_efi_packed_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
+  static grub_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
 
   for (i = 0; i < st->num_table_entries; i++)
     {
       if (grub_memcmp (&guid, &t->vendor_guid,
-		       sizeof (grub_efi_packed_guid_t)) == 0)
+		       sizeof (grub_guid_t)) == 0)
 	{
 	  disp_sal (t->vendor_table);
 	  return GRUB_ERR_NONE;
grub-core/commands/efi/smbios.c +6 -6
index 75202d5aa..d77239732 100644
@@ -26,14 +26,14 @@ struct grub_smbios_eps *
 grub_machine_smbios_get_eps (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
+  static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_guid_t)))
 	return (struct grub_smbios_eps *)
 	  grub_efi_system_table->configuration_table[i].vendor_table;
     }
@@ -45,14 +45,14 @@ struct grub_smbios_eps3 *
 grub_machine_smbios_get_eps3 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
+  static grub_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_guid_t)))
 	return (struct grub_smbios_eps3 *)
 	  grub_efi_system_table->configuration_table[i].vendor_table;
     }
grub-core/commands/efi/tpm.c +3 -3
index 421355204..c616768f9 100644
@@ -30,9 +30,9 @@
 
 typedef TCG_PCR_EVENT grub_tpm_event_t;
 
-static grub_efi_guid_t tpm_guid = EFI_TPM_GUID;
-static grub_efi_guid_t tpm2_guid = EFI_TPM2_GUID;
-static grub_efi_guid_t cc_measurement_guid = GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID;
+static grub_guid_t tpm_guid = EFI_TPM_GUID;
+static grub_guid_t tpm2_guid = EFI_TPM2_GUID;
+static grub_guid_t cc_measurement_guid = GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID;
 
 static grub_efi_handle_t *grub_tpm_handle;
 static grub_uint8_t grub_tpm_version;
grub-core/commands/probe.c +1 -1
index 9a80ea54f..cc8c05586 100644
@@ -119,7 +119,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)
 	  if (grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0)
 	    {
 	      struct grub_gpt_partentry entry;
-	      grub_gpt_part_guid_t *guid;
+	      grub_guid_t *guid;
 
 	      if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), &entry))
 		{
grub-core/disk/efi/efidisk.c +2 -2
index ad025010a..3b5ed5691 100644
@@ -37,7 +37,7 @@ struct grub_efidisk_data
 };
 
 /* GUID.  */
-static grub_efi_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID;
+static grub_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID;
 
 static struct grub_efidisk_data *fd_devices;
 static struct grub_efidisk_data *hd_devices;
@@ -319,7 +319,7 @@ name_devices (struct grub_efidisk_data *devices)
 	  == GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE)
 	{
 	  grub_efi_vendor_device_path_t *vendor = (grub_efi_vendor_device_path_t *) dp;
-	  const struct grub_efi_guid apple = GRUB_EFI_VENDOR_APPLE_GUID;
+	  static const grub_guid_t apple = GRUB_EFI_VENDOR_APPLE_GUID;
 
 	  if (vendor->header.length == sizeof (*vendor)
 	      && grub_memcmp (&vendor->vendor_guid, &apple,
grub-core/disk/ldm.c +1 -1
index 9632bc489..34bfe6bd1 100644
@@ -136,7 +136,7 @@ msdos_has_ldm_partition (grub_disk_t dsk)
   return has_ldm;
 }
 
-static const grub_gpt_part_guid_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM;
+static const grub_guid_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM;
 
 /* Helper for gpt_ldm_sector.  */
 static int
grub-core/efiemu/i386/pc/cfgtables.c +3 -3
index 1098f0b79..056ec0bc9 100644
@@ -29,9 +29,9 @@ grub_machine_efiemu_init_tables (void)
 {
   void *table;
   grub_err_t err;
-  static grub_efi_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID;
-  static grub_efi_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
-  static grub_efi_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
+  static grub_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID;
+  static grub_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
+  static grub_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
 
   err = grub_efiemu_unregister_configuration_table (smbios);
   if (err)
grub-core/efiemu/main.c +2 -2
index a81934725..e7037f4ed 100644
@@ -80,7 +80,7 @@ grub_efiemu_unload (void)
 
 /* Remove previously registered table from the list */
 grub_err_t
-grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid)
+grub_efiemu_unregister_configuration_table (grub_guid_t guid)
 {
   struct grub_efiemu_configuration_table *cur, *prev;
 
@@ -136,7 +136,7 @@ grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),
    or with a hook
 */
 grub_err_t
-grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
+grub_efiemu_register_configuration_table (grub_guid_t guid,
 					  void * (*get_table) (void *data),
 					  void (*unload) (void *data),
 					  void *data)
grub-core/efiemu/runtime/efiemu.c +7 -7
index 53b3cce7b..c84b30652 100644
@@ -66,7 +66,7 @@ efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,
 
 grub_efi_status_t __grub_efi_api
 efiemu_get_variable (grub_efi_char16_t *variable_name,
-		     const grub_efi_guid_t *vendor_guid,
+		     const grub_guid_t *vendor_guid,
 		     grub_efi_uint32_t *attributes,
 		     grub_efi_uintn_t *data_size,
 		     void *data);
@@ -74,11 +74,11 @@ efiemu_get_variable (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api
 efiemu_get_next_variable_name (grub_efi_uintn_t *variable_name_size,
 			       grub_efi_char16_t *variable_name,
-			       grub_efi_guid_t *vendor_guid);
+			       grub_guid_t *vendor_guid);
 
 grub_efi_status_t __grub_efi_api
 efiemu_set_variable (grub_efi_char16_t *variable_name,
-		     const grub_efi_guid_t *vendor_guid,
+		     const grub_guid_t *vendor_guid,
 		     grub_efi_uint32_t attributes,
 		     grub_efi_uintn_t data_size,
 		     void *data);
@@ -416,7 +416,7 @@ EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
 
 /* Find variable by name and GUID. */
 static struct efi_variable *
-find_variable (const grub_efi_guid_t *vendor_guid,
+find_variable (const grub_guid_t *vendor_guid,
 	       grub_efi_char16_t *variable_name)
 {
   grub_uint8_t *ptr;
@@ -438,7 +438,7 @@ find_variable (const grub_efi_guid_t *vendor_guid,
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
-				const grub_efi_guid_t *vendor_guid,
+				const grub_guid_t *vendor_guid,
 				grub_efi_uint32_t *attributes,
 				grub_efi_uintn_t *data_size,
 				void *data)
@@ -464,7 +464,7 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api EFI_FUNC
 (efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
 				 grub_efi_char16_t *variable_name,
-				 grub_efi_guid_t *vendor_guid)
+				 grub_guid_t *vendor_guid)
 {
   struct efi_variable *efivar;
   LOG ('l');
@@ -503,7 +503,7 @@ grub_efi_status_t __grub_efi_api EFI_FUNC
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
-				const grub_efi_guid_t *vendor_guid,
+				const grub_guid_t *vendor_guid,
 				grub_efi_uint32_t attributes,
 				grub_efi_uintn_t data_size,
 				void *data)
grub-core/kern/efi/acpi.c +6 -6
index 74f8cd1a9..461c77c33 100644
@@ -26,14 +26,14 @@ struct grub_acpi_rsdp_v10 *
 grub_machine_acpi_get_rsdpv1 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
+  static grub_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_guid_t)))
 	return (struct grub_acpi_rsdp_v10 *)
 	  grub_efi_system_table->configuration_table[i].vendor_table;
     }
@@ -44,14 +44,14 @@ struct grub_acpi_rsdp_v20 *
 grub_machine_acpi_get_rsdpv2 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
+  static grub_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_guid_t)))
 	return (struct grub_acpi_rsdp_v20 *)
 	  grub_efi_system_table->configuration_table[i].vendor_table;
     }
grub-core/kern/efi/efi.c +11 -11
index 4a1df6fb2..9e7d1a4a7 100644
@@ -35,12 +35,12 @@ grub_efi_handle_t grub_efi_image_handle;
 /* The pointer to a system table. Filled in by the startup code.  */
 grub_efi_system_table_t *grub_efi_system_table;
 
-static grub_efi_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID;
-static grub_efi_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
-static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
+static grub_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID;
+static grub_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
+static grub_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
 
 void *
-grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
+grub_efi_locate_protocol (grub_guid_t *protocol, void *registration)
 {
   void *interface;
   grub_efi_status_t status;
@@ -59,7 +59,7 @@ grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
    from the heap.  */
 grub_efi_handle_t *
 grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
-			grub_efi_guid_t *protocol,
+			grub_guid_t *protocol,
 			void *search_key,
 			grub_efi_uintn_t *num_handles)
 {
@@ -98,7 +98,7 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
 
 void *
 grub_efi_open_protocol (grub_efi_handle_t handle,
-			grub_efi_guid_t *protocol,
+			grub_guid_t *protocol,
 			grub_efi_uint32_t attributes)
 {
   grub_efi_boot_services_t *b;
@@ -119,7 +119,7 @@ grub_efi_open_protocol (grub_efi_handle_t handle,
 }
 
 grub_efi_status_t
-grub_efi_close_protocol (grub_efi_handle_t handle, grub_efi_guid_t *protocol)
+grub_efi_close_protocol (grub_efi_handle_t handle, grub_guid_t *protocol)
 {
   grub_efi_boot_services_t *b = grub_efi_system_table->boot_services;
 
@@ -203,7 +203,7 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
 }
 
 grub_err_t
-grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *guid,
+grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,
 		      void *data, grub_size_t datasize, grub_efi_uint32_t attributes)
 {
   grub_efi_status_t status;
@@ -230,7 +230,7 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *g
 }
 
 grub_err_t
-grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,
+grub_efi_set_variable (const char *var, const grub_guid_t *guid,
 		      void *data, grub_size_t datasize)
 {
   return grub_efi_set_variable_with_attributes (var, guid, data, datasize, 
@@ -241,7 +241,7 @@ grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,
 
 grub_efi_status_t
 grub_efi_get_variable_with_attributes (const char *var,
-				       const grub_efi_guid_t *guid,
+				       const grub_guid_t *guid,
 				       grub_size_t *datasize_out,
 				       void **data_out,
 				       grub_efi_uint32_t *attributes)
@@ -296,7 +296,7 @@ grub_efi_get_variable_with_attributes (const char *var,
 }
 
 grub_efi_status_t
-grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
+grub_efi_get_variable (const char *var, const grub_guid_t *guid,
 		       grub_size_t *datasize_out, void **data_out)
 {
   return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL);
grub-core/kern/efi/fdt.c +1 -1
index 24f955289..8fcf43f1b 100644
@@ -24,7 +24,7 @@ void *
 grub_efi_get_firmware_fdt (void)
 {
   grub_efi_configuration_table_t *tables;
-  static grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
+  static grub_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
   void *firmware_fdt = NULL;
   unsigned int i;
 
grub-core/kern/efi/init.c +1 -1
index e873ef529..8a9c838c0 100644
@@ -36,7 +36,7 @@ static grub_efi_char16_t stack_chk_fail_msg[] =
   L"* GRUB: ABORTED!!! *\r\n"
   L"* GRUB: REBOOTING IN 5 SECONDS... *\r\n";
 
-static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
+static grub_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
 
 /*
  * Don't put this on grub_efi_init()'s local stack to avoid it
grub-core/kern/efi/sb.c +2 -2
index db42c2539..80cfa0888 100644
@@ -30,7 +30,7 @@
 #include <grub/types.h>
 #include <grub/verify.h>
 
-static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
+static grub_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
 
 /*
  * Determine whether we're in secure boot mode.
@@ -41,7 +41,7 @@ static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
 grub_uint8_t
 grub_efi_get_secureboot (void)
 {
-  static grub_efi_guid_t efi_variable_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t efi_variable_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
   grub_efi_status_t status;
   grub_efi_uint32_t attr = 0;
   grub_size_t size = 0;
grub-core/loader/efi/fdt.c +1 -1
index 35a3be2e5..439964b9c 100644
@@ -86,7 +86,7 @@ grub_err_t
 grub_fdt_install (void)
 {
   grub_efi_boot_services_t *b;
-  static grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
+  static grub_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
   grub_efi_status_t status;
 
   if (fdt == NULL && loaded_fdt == NULL)
grub-core/loader/efi/linux.c +2 -2
index 1d98fa365..c1eef7c98 100644
@@ -51,8 +51,8 @@ static struct grub_linux_initrd_context initrd_ctx = {0, 0, 0};
 static grub_efi_handle_t initrd_lf2_handle = NULL;
 static bool initrd_use_loadfile2 = false;
 
-static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
-static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
+static grub_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
+static grub_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
 
 static initrd_media_device_path_t initrd_lf2_device_path = {
   {
grub-core/loader/i386/xnu.c +2 -2
index 4c88ce5e0..93ba4476d 100644
@@ -48,7 +48,7 @@ grub_uint32_t grub_xnu_entry_point, grub_xnu_arg1, grub_xnu_stack;
 /* Aliases set for some tables. */
 struct tbl_alias
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 };
 
@@ -694,7 +694,7 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)
     {
       void *ptr;
       struct grub_xnu_devtree_key *curkey;
-      grub_efi_packed_guid_t guid;
+      grub_guid_t guid;
       char guidbuf[64];
 
       /* Retrieve current key. */
grub-core/loader/ia64/efi/linux.c +1 -1
index fb9b961f7..3dd2e8236 100644
@@ -106,7 +106,7 @@ query_fpswa (void)
   grub_efi_boot_services_t *bs;
   grub_efi_status_t status;
   grub_efi_uintn_t size;
-  static const grub_efi_guid_t fpswa_protocol =
+  static const grub_guid_t fpswa_protocol =
     { 0xc41b6531, 0x97b9, 0x11d3,
       {0x9a, 0x29, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} };
 
grub-core/net/drivers/efi/efinet.c +2 -2
index 56a179709..3ea25cf98 100644
@@ -27,8 +27,8 @@
 GRUB_MOD_LICENSE ("GPLv3+");
 
 /* GUID.  */
-static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID;
-static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID;
+static grub_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID;
+static grub_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID;
 
 static grub_err_t
 send_card_buffer (struct grub_net_card *dev,
grub-core/partmap/gpt.c +2 -2
index 075cc96f1..877ceefc3 100644
@@ -36,10 +36,10 @@ static grub_uint8_t grub_gpt_magic[8] =
     0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54
   };
 
-static const grub_gpt_part_guid_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
+static const grub_guid_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
 
 #ifdef GRUB_UTIL
-static const grub_gpt_part_guid_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
+static const grub_guid_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
 #endif
 
 /* 512 << 7 = 65536 byte sectors.  */
grub-core/term/efi/console.c +1 -1
index 9a7bc0fcf..bb587f39d 100644
@@ -352,7 +352,7 @@ grub_console_getkeystatus (struct grub_term_input *term)
 static grub_err_t
 grub_efi_console_input_init (struct grub_term_input *term)
 {
-  static grub_efi_guid_t text_input_ex_guid =
+  static grub_guid_t text_input_ex_guid =
     GRUB_EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
 
   if (grub_efi_is_finished)
grub-core/term/efi/serial.c +1 -1
index e86ebce3f..5dfd2d86c 100644
@@ -31,7 +31,7 @@
 #include <grub/i18n.h>
 
 /* GUID.  */
-static grub_efi_guid_t serial_io_guid = GRUB_EFI_SERIAL_IO_GUID;
+static grub_guid_t serial_io_guid = GRUB_EFI_SERIAL_IO_GUID;
 
 static void
 do_real_config (struct grub_serial_port *port)
grub-core/video/efi_gop.c +4 -4
index 9c7901038..7247aeea7 100644
@@ -32,10 +32,10 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t graphics_output_guid = GRUB_EFI_GOP_GUID;
-static grub_efi_guid_t active_edid_guid = GRUB_EFI_EDID_ACTIVE_GUID;
-static grub_efi_guid_t discovered_edid_guid = GRUB_EFI_EDID_DISCOVERED_GUID;
-static grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+static grub_guid_t graphics_output_guid = GRUB_EFI_GOP_GUID;
+static grub_guid_t active_edid_guid = GRUB_EFI_EDID_ACTIVE_GUID;
+static grub_guid_t discovered_edid_guid = GRUB_EFI_EDID_DISCOVERED_GUID;
+static grub_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
 static struct grub_efi_gop *gop;
 static unsigned old_mode;
 static int restore_needed;
grub-core/video/efi_uga.c +1 -1
index aa4659b8e..d53079e0b 100644
@@ -32,7 +32,7 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
+static grub_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
 static struct grub_efi_uga_draw_protocol *uga;
 static grub_uint64_t uga_fb;
 static grub_uint32_t uga_pitch;
include/grub/efi/api.h +23 -41

191 lines not on this page · raw message

include/grub/efi/efi.h +8 -8
index 26f33433b..3d056a0a4 100644
@@ -37,18 +37,18 @@ struct linux_arch_kernel_header {
 };
 
 /* Functions.  */
-void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_efi_guid_t *protocol,
+void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_guid_t *protocol,
 					     void *registration);
 grub_efi_handle_t *
 EXPORT_FUNC(grub_efi_locate_handle) (grub_efi_locate_search_type_t search_type,
-				     grub_efi_guid_t *protocol,
+				     grub_guid_t *protocol,
 				     void *search_key,
 				     grub_efi_uintn_t *num_handles);
 void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle,
-					   grub_efi_guid_t *protocol,
+					   grub_guid_t *protocol,
 					   grub_efi_uint32_t attributes);
 grub_efi_status_t
-EXPORT_FUNC(grub_efi_close_protocol) (grub_efi_handle_t handle, grub_efi_guid_t *protocol);
+EXPORT_FUNC(grub_efi_close_protocol) (grub_efi_handle_t handle, grub_guid_t *protocol);
 int EXPORT_FUNC(grub_efi_set_text_mode) (int on);
 void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds);
 void *
@@ -89,23 +89,23 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memo
 							   grub_efi_uint32_t descriptor_version,
 							   grub_efi_memory_descriptor_t *virtual_map);
 grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable_with_attributes) (const char *variable,
-								       const grub_efi_guid_t *guid,
+								       const grub_guid_t *guid,
 								       grub_size_t *datasize_out,
 								       void **data_out,
 								       grub_efi_uint32_t *attributes);
 grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
-						       const grub_efi_guid_t *guid,
+						       const grub_guid_t *guid,
 						       grub_size_t *datasize_out,
 						       void **data_out);
 grub_err_t
 EXPORT_FUNC (grub_efi_set_variable_with_attributes) (const char *var,
-				     const grub_efi_guid_t *guid,
+				     const grub_guid_t *guid,
 				     void *data,
 				     grub_size_t datasize,
 				     grub_efi_uint32_t attributes);
 grub_err_t
 EXPORT_FUNC (grub_efi_set_variable) (const char *var,
-				     const grub_efi_guid_t *guid,
+				     const grub_guid_t *guid,
 				     void *data,
 				     grub_size_t datasize);
 int
include/grub/efiemu/efiemu.h +5 -5
index 5325e5839..caf0b505f 100644
@@ -176,26 +176,26 @@ grub_err_t grub_efiemu_loadcore_load (void);
 struct grub_efiemu_configuration_table
 {
   struct grub_efiemu_configuration_table *next;
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   void * (*get_table) (void *data);
   void (*unload) (void *data);
   void *data;
 };
 struct grub_efiemu_configuration_table32
 {
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint32_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t;
 struct grub_efiemu_configuration_table64
 {
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint64_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t;
-grub_err_t grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid);
+grub_err_t grub_efiemu_unregister_configuration_table (grub_guid_t guid);
 grub_err_t
-grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
+grub_efiemu_register_configuration_table (grub_guid_t guid,
 					  void * (*get_table) (void *data),
 					  void (*unload) (void *data),
 					  void *data);
include/grub/efiemu/runtime.h +1 -1
index 36d2dedf4..c9ad9fdfa 100644
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
 
 struct efi_variable
 {
-  grub_efi_packed_guid_t guid;
+  grub_guid_t guid;
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
include/grub/gpt_partition.h +2 -11
index 7a93f4329..020e71920 100644
@@ -22,15 +22,6 @@
 #include <grub/types.h>
 #include <grub/partition.h>
 
-struct grub_gpt_part_guid
-{
-  grub_uint32_t data1;
-  grub_uint16_t data2;
-  grub_uint16_t data3;
-  grub_uint8_t data4[8];
-} GRUB_PACKED;
-typedef struct grub_gpt_part_guid grub_gpt_part_guid_t;
-
 #define GRUB_GPT_PARTITION_TYPE_EMPTY \
   { 0x0, 0x0, 0x0, \
     { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } \
@@ -70,8 +61,8 @@ struct grub_gpt_header
 
 struct grub_gpt_partentry
 {
-  grub_gpt_part_guid_t type;
-  grub_gpt_part_guid_t guid;
+  grub_guid_t type;
+  grub_guid_t guid;
   grub_uint64_t start;
   grub_uint64_t end;
   grub_uint64_t attrib;
include/grub/types.h +9 -0
index 6d5dc5cda..c56ce9820 100644
@@ -365,4 +365,13 @@ static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
 # define grub_absolute_pointer(val) ((void *) (val))
 #endif
 
+struct grub_guid
+{
+  grub_uint32_t data1;
+  grub_uint16_t data2;
+  grub_uint16_t data3;
+  grub_uint8_t data4[8];
+} GRUB_PACKED;
+typedef struct grub_guid grub_guid_t;
+
 #endif /* ! GRUB_TYPES_HEADER */
util/grub-install.c +1 -1
index e20820d9e..1ad04db36 100644
@@ -728,7 +728,7 @@ is_prep_partition (grub_device_t dev)
       if (grub_disk_read (dev->disk, p->offset, p->index,
 			  sizeof (gptdata), &gptdata) == 0)
 	{
-	  const grub_gpt_part_guid_t template = {
+	  const grub_guid_t template = {
 	    grub_cpu_to_le32_compile_time (0x9e1a2d38),
 	    grub_cpu_to_le16_compile_time (0xc612),
 	    grub_cpu_to_le16_compile_time (0x4316),
util/grub-probe.c +1 -1
index 446bd2553..65c1ca3f8 100644
@@ -133,7 +133,7 @@ get_targets_string (void)
 }
 
 static int
-print_gpt_guid (grub_gpt_part_guid_t guid)
+print_gpt_guid (grub_guid_t guid)
 {
   guid.data1 = grub_le_to_cpu32 (guid.data1);
   guid.data2 = grub_le_to_cpu16 (guid.data2);
Signature · 1 line
2.40.1
#3 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Hi Oliver!

Quoted 1,103 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

---
 grub-core/commands/acpi.c            |  4 +-
 grub-core/commands/efi/efifwsetup.c  |  4 +-
 grub-core/commands/efi/loadbios.c    | 14 +++---
 grub-core/commands/efi/lsefi.c       |  4 +-
 grub-core/commands/efi/lsefisystab.c |  4 +-
 grub-core/commands/efi/lssal.c       |  4 +-
 grub-core/commands/efi/smbios.c      | 12 +++---
 grub-core/commands/efi/tpm.c         |  6 +--
 grub-core/commands/probe.c           |  2 +-
 grub-core/disk/efi/efidisk.c         |  4 +-
 grub-core/disk/ldm.c                 |  2 +-
 grub-core/efiemu/i386/pc/cfgtables.c |  6 +--
 grub-core/efiemu/main.c              |  4 +-
 grub-core/efiemu/runtime/efiemu.c    | 14 +++---
 grub-core/kern/efi/acpi.c            | 12 +++---
 grub-core/kern/efi/efi.c             | 22 +++++-----
 grub-core/kern/efi/fdt.c             |  2 +-
 grub-core/kern/efi/init.c            |  2 +-
 grub-core/kern/efi/sb.c              |  4 +-
 grub-core/loader/efi/fdt.c           |  2 +-
 grub-core/loader/efi/linux.c         |  4 +-
 grub-core/loader/i386/xnu.c          |  4 +-
 grub-core/loader/ia64/efi/linux.c    |  2 +-
 grub-core/net/drivers/efi/efinet.c   |  4 +-
 grub-core/partmap/gpt.c              |  4 +-
 grub-core/term/efi/console.c         |  2 +-
 grub-core/term/efi/serial.c          |  2 +-
 grub-core/video/efi_gop.c            |  8 ++--
 grub-core/video/efi_uga.c            |  2 +-
 include/grub/efi/api.h               | 64 ++++++++++------------------
 include/grub/efi/efi.h               | 16 +++----
 include/grub/efiemu/efiemu.h         | 10 ++---
 include/grub/efiemu/runtime.h        |  2 +-
 include/grub/gpt_partition.h         | 13 +-----
 include/grub/types.h                 |  9 ++++
 util/grub-install.c                  |  2 +-
 util/grub-probe.c                    |  2 +-
 37 files changed, 130 insertions(+), 148 deletions(-)
grub-core/commands/acpi.c +2 -2
index ab067ae6e..deec4bb43 100644
@@ -759,8 +759,8 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
 
 #ifdef GRUB_MACHINE_EFI
   {
-    struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID;
-    struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
+    static grub_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
+    static grub_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
 
     grub_efi_system_table->boot_services->install_configuration_table (&acpi20,
 								       grub_acpi_get_rsdpv2 ());
grub-core/commands/efi/efifwsetup.c +2 -2
index de66c3035..704f9d352 100644
@@ -38,7 +38,7 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
   grub_efi_uint64_t os_indications = GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
   grub_err_t status;
   grub_size_t oi_size;
-  static grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
 
   if (argc >= 1 && grub_strcmp(args[0], "--is-supported") == 0)
     return !efifwsetup_is_supported ();
@@ -72,7 +72,7 @@ efifwsetup_is_supported (void)
 {
   grub_efi_uint64_t *os_indications_supported = NULL;
   grub_size_t oi_size = 0;
-  static grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
   grub_efi_boolean_t ret = 0;
 
   grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size,
grub-core/commands/efi/loadbios.c +7 -7
index 574e41046..8f6b0ecfc 100644
@@ -27,9 +27,9 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
-static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
-static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
+static grub_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
+static grub_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
+static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
 
 #define EBDA_SEG_ADDR	0x40e
 #define LOW_MEM_ADDR	0x413
@@ -105,15 +105,15 @@ fake_bios_data (int use_rom)
   smbios = 0;
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_efi_guid_t)))
+      if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_guid_t)))
 	{
 	  acpi = grub_efi_system_table->configuration_table[i].vendor_table;
 	  grub_dprintf ("efi", "ACPI2: %p\n", acpi);
 	}
-      else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
+      else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_guid_t)))
 	{
 	  void *t;
 
@@ -122,7 +122,7 @@ fake_bios_data (int use_rom)
 	    acpi = t;
 	  grub_dprintf ("efi", "ACPI: %p\n", t);
 	}
-      else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_guid_t)))
+      else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_guid_t)))
 	{
 	  smbios = grub_efi_system_table->configuration_table[i].vendor_table;
 	  grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
grub-core/commands/efi/lsefi.c +2 -2
index 539701497..6935cd302 100644
@@ -31,7 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 
 struct known_protocol
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 } known_protocols[] =
   {
@@ -96,7 +96,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
       grub_efi_handle_t handle = handles[i];
       grub_efi_status_t status;
       grub_efi_uintn_t num_protocols;
-      grub_efi_packed_guid_t **protocols;
+      grub_guid_t **protocols;
       grub_efi_device_path_t *dp;
 
       grub_printf ("Handle %p\n", handle);
grub-core/commands/efi/lsefisystab.c +2 -2
index ac3299b7f..eff8c41f3 100644
@@ -29,7 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 
 struct guid_mapping
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 };
 
@@ -104,7 +104,7 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),
 
       for (j = 0; j < ARRAY_SIZE (guid_mappings); j++)
 	if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
-			 sizeof (grub_efi_guid_t)) == 0)
+			 sizeof (grub_guid_t)) == 0)
 	  grub_printf ("   %s", guid_mappings[j].name);
 
       grub_printf ("\n");
grub-core/commands/efi/lssal.c +2 -2
index 5084ddd8b..fd6085f1b 100644
@@ -139,12 +139,12 @@ grub_cmd_lssal (struct grub_command *cmd __attribute__ ((unused)),
   const grub_efi_system_table_t *st = grub_efi_system_table;
   grub_efi_configuration_table_t *t = st->configuration_table;
   unsigned int i;
-  grub_efi_packed_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
+  static grub_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
 
   for (i = 0; i < st->num_table_entries; i++)
     {
       if (grub_memcmp (&guid, &t->vendor_guid,
-		       sizeof (grub_efi_packed_guid_t)) == 0)
+		       sizeof (grub_guid_t)) == 0)
 	{
 	  disp_sal (t->vendor_table);
 	  return GRUB_ERR_NONE;
grub-core/commands/efi/smbios.c +6 -6
index 75202d5aa..d77239732 100644
@@ -26,14 +26,14 @@ struct grub_smbios_eps *
 grub_machine_smbios_get_eps (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
+  static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_guid_t)))
 	return (struct grub_smbios_eps *)
 	  grub_efi_system_table->configuration_table[i].vendor_table;
     }
@@ -45,14 +45,14 @@ struct grub_smbios_eps3 *
 grub_machine_smbios_get_eps3 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
+  static grub_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_guid_t)))
 	return (struct grub_smbios_eps3 *)
 	  grub_efi_system_table->configuration_table[i].vendor_table;
     }
grub-core/commands/efi/tpm.c +3 -3
index 421355204..c616768f9 100644
@@ -30,9 +30,9 @@
 
 typedef TCG_PCR_EVENT grub_tpm_event_t;
 
-static grub_efi_guid_t tpm_guid = EFI_TPM_GUID;
-static grub_efi_guid_t tpm2_guid = EFI_TPM2_GUID;
-static grub_efi_guid_t cc_measurement_guid = GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID;
+static grub_guid_t tpm_guid = EFI_TPM_GUID;
+static grub_guid_t tpm2_guid = EFI_TPM2_GUID;
+static grub_guid_t cc_measurement_guid = GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID;
 
 static grub_efi_handle_t *grub_tpm_handle;
 static grub_uint8_t grub_tpm_version;
grub-core/commands/probe.c +1 -1
index 9a80ea54f..cc8c05586 100644
@@ -119,7 +119,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)
 	  if (grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0)
 	    {
 	      struct grub_gpt_partentry entry;
-	      grub_gpt_part_guid_t *guid;
+	      grub_guid_t *guid;
 
 	      if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), &entry))
 		{
grub-core/disk/efi/efidisk.c +2 -2
index ad025010a..3b5ed5691 100644
@@ -37,7 +37,7 @@ struct grub_efidisk_data
 };
 
 /* GUID.  */
-static grub_efi_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID;
+static grub_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID;
 
 static struct grub_efidisk_data *fd_devices;
 static struct grub_efidisk_data *hd_devices;
@@ -319,7 +319,7 @@ name_devices (struct grub_efidisk_data *devices)
 	  == GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE)
 	{
 	  grub_efi_vendor_device_path_t *vendor = (grub_efi_vendor_device_path_t *) dp;
-	  const struct grub_efi_guid apple = GRUB_EFI_VENDOR_APPLE_GUID;
+	  static const grub_guid_t apple = GRUB_EFI_VENDOR_APPLE_GUID;
 
 	  if (vendor->header.length == sizeof (*vendor)
 	      && grub_memcmp (&vendor->vendor_guid, &apple,
grub-core/disk/ldm.c +1 -1
index 9632bc489..34bfe6bd1 100644
@@ -136,7 +136,7 @@ msdos_has_ldm_partition (grub_disk_t dsk)
   return has_ldm;
 }
 
-static const grub_gpt_part_guid_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM;
+static const grub_guid_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM;
 
 /* Helper for gpt_ldm_sector.  */
 static int
grub-core/efiemu/i386/pc/cfgtables.c +3 -3
index 1098f0b79..056ec0bc9 100644
@@ -29,9 +29,9 @@ grub_machine_efiemu_init_tables (void)
 {
   void *table;
   grub_err_t err;
-  static grub_efi_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID;
-  static grub_efi_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
-  static grub_efi_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
+  static grub_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID;
+  static grub_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
+  static grub_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
 
   err = grub_efiemu_unregister_configuration_table (smbios);
   if (err)
grub-core/efiemu/main.c +2 -2
index a81934725..e7037f4ed 100644
@@ -80,7 +80,7 @@ grub_efiemu_unload (void)
 
 /* Remove previously registered table from the list */
 grub_err_t
-grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid)
+grub_efiemu_unregister_configuration_table (grub_guid_t guid)
 {
   struct grub_efiemu_configuration_table *cur, *prev;
 
@@ -136,7 +136,7 @@ grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),
    or with a hook
 */
 grub_err_t
-grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
+grub_efiemu_register_configuration_table (grub_guid_t guid,
 					  void * (*get_table) (void *data),
 					  void (*unload) (void *data),
 					  void *data)
grub-core/efiemu/runtime/efiemu.c +7 -7
index 53b3cce7b..c84b30652 100644
@@ -66,7 +66,7 @@ efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,
 
 grub_efi_status_t __grub_efi_api
 efiemu_get_variable (grub_efi_char16_t *variable_name,
-		     const grub_efi_guid_t *vendor_guid,
+		     const grub_guid_t *vendor_guid,
 		     grub_efi_uint32_t *attributes,
 		     grub_efi_uintn_t *data_size,
 		     void *data);
@@ -74,11 +74,11 @@ efiemu_get_variable (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api
 efiemu_get_next_variable_name (grub_efi_uintn_t *variable_name_size,
 			       grub_efi_char16_t *variable_name,
-			       grub_efi_guid_t *vendor_guid);
+			       grub_guid_t *vendor_guid);
 
 grub_efi_status_t __grub_efi_api
 efiemu_set_variable (grub_efi_char16_t *variable_name,
-		     const grub_efi_guid_t *vendor_guid,
+		     const grub_guid_t *vendor_guid,
 		     grub_efi_uint32_t attributes,
 		     grub_efi_uintn_t data_size,
 		     void *data);
@@ -416,7 +416,7 @@ EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
 
 /* Find variable by name and GUID. */
 static struct efi_variable *
-find_variable (const grub_efi_guid_t *vendor_guid,
+find_variable (const grub_guid_t *vendor_guid,
 	       grub_efi_char16_t *variable_name)
 {
   grub_uint8_t *ptr;
@@ -438,7 +438,7 @@ find_variable (const grub_efi_guid_t *vendor_guid,
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
-				const grub_efi_guid_t *vendor_guid,
+				const grub_guid_t *vendor_guid,
 				grub_efi_uint32_t *attributes,
 				grub_efi_uintn_t *data_size,
 				void *data)
@@ -464,7 +464,7 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api EFI_FUNC
 (efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
 				 grub_efi_char16_t *variable_name,
-				 grub_efi_guid_t *vendor_guid)
+				 grub_guid_t *vendor_guid)
 {
   struct efi_variable *efivar;
   LOG ('l');
@@ -503,7 +503,7 @@ grub_efi_status_t __grub_efi_api EFI_FUNC
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
-				const grub_efi_guid_t *vendor_guid,
+				const grub_guid_t *vendor_guid,
 				grub_efi_uint32_t attributes,
 				grub_efi_uintn_t data_size,
 				void *data)
grub-core/kern/efi/acpi.c +6 -6
index 74f8cd1a9..461c77c33 100644
@@ -26,14 +26,14 @@ struct grub_acpi_rsdp_v10 *
 grub_machine_acpi_get_rsdpv1 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
+  static grub_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_guid_t)))
 	return (struct grub_acpi_rsdp_v10 *)
 	  grub_efi_system_table->configuration_table[i].vendor_table;
     }
@@ -44,14 +44,14 @@ struct grub_acpi_rsdp_v20 *
 grub_machine_acpi_get_rsdpv2 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
+  static grub_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_guid_t)))
 	return (struct grub_acpi_rsdp_v20 *)
 	  grub_efi_system_table->configuration_table[i].vendor_table;
     }
grub-core/kern/efi/efi.c +11 -11
index 4a1df6fb2..9e7d1a4a7 100644
@@ -35,12 +35,12 @@ grub_efi_handle_t grub_efi_image_handle;
 /* The pointer to a system table. Filled in by the startup code.  */
 grub_efi_system_table_t *grub_efi_system_table;
 
-static grub_efi_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID;
-static grub_efi_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
-static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
+static grub_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID;
+static grub_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
+static grub_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
 
 void *
-grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
+grub_efi_locate_protocol (grub_guid_t *protocol, void *registration)
 {
   void *interface;
   grub_efi_status_t status;
@@ -59,7 +59,7 @@ grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
    from the heap.  */
 grub_efi_handle_t *
 grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
-			grub_efi_guid_t *protocol,
+			grub_guid_t *protocol,
 			void *search_key,
 			grub_efi_uintn_t *num_handles)
 {
@@ -98,7 +98,7 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
 
 void *
 grub_efi_open_protocol (grub_efi_handle_t handle,
-			grub_efi_guid_t *protocol,
+			grub_guid_t *protocol,
 			grub_efi_uint32_t attributes)
 {
   grub_efi_boot_services_t *b;
@@ -119,7 +119,7 @@ grub_efi_open_protocol (grub_efi_handle_t handle,
 }
 
 grub_efi_status_t
-grub_efi_close_protocol (grub_efi_handle_t handle, grub_efi_guid_t *protocol)
+grub_efi_close_protocol (grub_efi_handle_t handle, grub_guid_t *protocol)
 {
   grub_efi_boot_services_t *b = grub_efi_system_table->boot_services;
 
@@ -203,7 +203,7 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
 }
 
 grub_err_t
-grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *guid,
+grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,
 		      void *data, grub_size_t datasize, grub_efi_uint32_t attributes)
 {
   grub_efi_status_t status;
@@ -230,7 +230,7 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *g
 }
 
 grub_err_t
-grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,
+grub_efi_set_variable (const char *var, const grub_guid_t *guid,
 		      void *data, grub_size_t datasize)
 {
   return grub_efi_set_variable_with_attributes (var, guid, data, datasize, 
@@ -241,7 +241,7 @@ grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,
 
 grub_efi_status_t
 grub_efi_get_variable_with_attributes (const char *var,
-				       const grub_efi_guid_t *guid,
+				       const grub_guid_t *guid,
 				       grub_size_t *datasize_out,
 				       void **data_out,
 				       grub_efi_uint32_t *attributes)
@@ -296,7 +296,7 @@ grub_efi_get_variable_with_attributes (const char *var,
 }
 
 grub_efi_status_t
-grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
+grub_efi_get_variable (const char *var, const grub_guid_t *guid,
 		       grub_size_t *datasize_out, void **data_out)
 {
   return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL);
grub-core/kern/efi/fdt.c +1 -1
index 24f955289..8fcf43f1b 100644
@@ -24,7 +24,7 @@ void *
 grub_efi_get_firmware_fdt (void)
 {
   grub_efi_configuration_table_t *tables;
-  static grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
+  static grub_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
   void *firmware_fdt = NULL;
   unsigned int i;
 
grub-core/kern/efi/init.c +1 -1
index e873ef529..8a9c838c0 100644
@@ -36,7 +36,7 @@ static grub_efi_char16_t stack_chk_fail_msg[] =
   L"* GRUB: ABORTED!!! *\r\n"
   L"* GRUB: REBOOTING IN 5 SECONDS... *\r\n";
 
-static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
+static grub_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
 
 /*
  * Don't put this on grub_efi_init()'s local stack to avoid it
grub-core/kern/efi/sb.c +2 -2
index db42c2539..80cfa0888 100644
@@ -30,7 +30,7 @@
 #include <grub/types.h>
 #include <grub/verify.h>
 
-static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
+static grub_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
 
 /*
  * Determine whether we're in secure boot mode.
@@ -41,7 +41,7 @@ static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
 grub_uint8_t
 grub_efi_get_secureboot (void)
 {
-  static grub_efi_guid_t efi_variable_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t efi_variable_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
   grub_efi_status_t status;
   grub_efi_uint32_t attr = 0;
   grub_size_t size = 0;
grub-core/loader/efi/fdt.c +1 -1
index 35a3be2e5..439964b9c 100644
@@ -86,7 +86,7 @@ grub_err_t
 grub_fdt_install (void)
 {
   grub_efi_boot_services_t *b;
-  static grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
+  static grub_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
   grub_efi_status_t status;
 
   if (fdt == NULL && loaded_fdt == NULL)
grub-core/loader/efi/linux.c +2 -2
index 1d98fa365..c1eef7c98 100644
@@ -51,8 +51,8 @@ static struct grub_linux_initrd_context initrd_ctx = {0, 0, 0};
 static grub_efi_handle_t initrd_lf2_handle = NULL;
 static bool initrd_use_loadfile2 = false;
 
-static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
-static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
+static grub_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
+static grub_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
 
 static initrd_media_device_path_t initrd_lf2_device_path = {
   {
grub-core/loader/i386/xnu.c +2 -2
index 4c88ce5e0..93ba4476d 100644
@@ -48,7 +48,7 @@ grub_uint32_t grub_xnu_entry_point, grub_xnu_arg1, grub_xnu_stack;
 /* Aliases set for some tables. */
 struct tbl_alias
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 };
 
@@ -694,7 +694,7 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)
     {
       void *ptr;
       struct grub_xnu_devtree_key *curkey;
-      grub_efi_packed_guid_t guid;
+      grub_guid_t guid;
       char guidbuf[64];
 
       /* Retrieve current key. */
grub-core/loader/ia64/efi/linux.c +1 -1
index fb9b961f7..3dd2e8236 100644
@@ -106,7 +106,7 @@ query_fpswa (void)
   grub_efi_boot_services_t *bs;
   grub_efi_status_t status;
   grub_efi_uintn_t size;
-  static const grub_efi_guid_t fpswa_protocol =
+  static const grub_guid_t fpswa_protocol =
     { 0xc41b6531, 0x97b9, 0x11d3,
       {0x9a, 0x29, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} };
 
grub-core/net/drivers/efi/efinet.c +2 -2
index 56a179709..3ea25cf98 100644
@@ -27,8 +27,8 @@
 GRUB_MOD_LICENSE ("GPLv3+");
 
 /* GUID.  */
-static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID;
-static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID;
+static grub_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID;
+static grub_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID;
 
 static grub_err_t
 send_card_buffer (struct grub_net_card *dev,
grub-core/partmap/gpt.c +2 -2
index 075cc96f1..877ceefc3 100644
@@ -36,10 +36,10 @@ static grub_uint8_t grub_gpt_magic[8] =
     0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54
   };
 
-static const grub_gpt_part_guid_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
+static const grub_guid_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
 
 #ifdef GRUB_UTIL
-static const grub_gpt_part_guid_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
+static const grub_guid_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
 #endif
 
 /* 512 << 7 = 65536 byte sectors.  */
grub-core/term/efi/console.c +1 -1
index 9a7bc0fcf..bb587f39d 100644
@@ -352,7 +352,7 @@ grub_console_getkeystatus (struct grub_term_input *term)
 static grub_err_t
 grub_efi_console_input_init (struct grub_term_input *term)
 {
-  static grub_efi_guid_t text_input_ex_guid =
+  static grub_guid_t text_input_ex_guid =
     GRUB_EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
 
   if (grub_efi_is_finished)
grub-core/term/efi/serial.c +1 -1
index e86ebce3f..5dfd2d86c 100644
@@ -31,7 +31,7 @@
 #include <grub/i18n.h>
 
 /* GUID.  */
-static grub_efi_guid_t serial_io_guid = GRUB_EFI_SERIAL_IO_GUID;
+static grub_guid_t serial_io_guid = GRUB_EFI_SERIAL_IO_GUID;
 
 static void
 do_real_config (struct grub_serial_port *port)
grub-core/video/efi_gop.c +4 -4
index 9c7901038..7247aeea7 100644
@@ -32,10 +32,10 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t graphics_output_guid = GRUB_EFI_GOP_GUID;
-static grub_efi_guid_t active_edid_guid = GRUB_EFI_EDID_ACTIVE_GUID;
-static grub_efi_guid_t discovered_edid_guid = GRUB_EFI_EDID_DISCOVERED_GUID;
-static grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+static grub_guid_t graphics_output_guid = GRUB_EFI_GOP_GUID;
+static grub_guid_t active_edid_guid = GRUB_EFI_EDID_ACTIVE_GUID;
+static grub_guid_t discovered_edid_guid = GRUB_EFI_EDID_DISCOVERED_GUID;
+static grub_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
 static struct grub_efi_gop *gop;
 static unsigned old_mode;
 static int restore_needed;
grub-core/video/efi_uga.c +1 -1
index aa4659b8e..d53079e0b 100644
@@ -32,7 +32,7 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
+static grub_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
 static struct grub_efi_uga_draw_protocol *uga;
 static grub_uint64_t uga_fb;
 static grub_uint32_t uga_pitch;
include/grub/efi/api.h +23 -41
index fb881ae12..c0b6e86f1 100644
@@ -639,24 +639,6 @@ typedef grub_uint8_t grub_efi_ip_address_t[8] __attribute__ ((aligned(4)));
 typedef grub_efi_uint64_t grub_efi_physical_address_t;
 typedef grub_efi_uint64_t grub_efi_virtual_address_t;
 
-struct grub_efi_guid
-{
-  grub_uint32_t data1;
-  grub_uint16_t data2;
-  grub_uint16_t data3;
-  grub_uint8_t data4[8];
-} __attribute__ ((aligned(8)));
-typedef struct grub_efi_guid grub_efi_guid_t;
-
-struct grub_efi_packed_guid
-{
-  grub_uint32_t data1;
-  grub_uint16_t data2;
-  grub_uint16_t data3;
-  grub_uint8_t data4[8];
-} GRUB_PACKED;
-typedef struct grub_efi_packed_guid grub_efi_packed_guid_t;
-
 /* XXX although the spec does not specify the padding, this actually
    must have the padding!  */
 struct grub_efi_memory_descriptor
@@ -743,7 +725,7 @@ typedef struct grub_efi_memory_mapped_device_path grub_efi_memory_mapped_device_
 struct grub_efi_vendor_device_path
 {
   grub_efi_device_path_t header;
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint8_t vendor_defined_data[0];
 } GRUB_PACKED;
 typedef struct grub_efi_vendor_device_path grub_efi_vendor_device_path_t;
@@ -987,7 +969,7 @@ typedef struct grub_efi_cdrom_device_path grub_efi_cdrom_device_path_t;
 struct grub_efi_vendor_media_device_path
 {
   grub_efi_device_path_t header;
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint8_t vendor_defined_data[0];
 } GRUB_PACKED;
 typedef struct grub_efi_vendor_media_device_path grub_efi_vendor_media_device_path_t;
@@ -1006,7 +988,7 @@ typedef struct grub_efi_file_path_device_path grub_efi_file_path_device_path_t;
 struct grub_efi_protocol_device_path
 {
   grub_efi_device_path_t header;
-  grub_efi_packed_guid_t guid;
+  grub_guid_t guid;
 } GRUB_PACKED;
 typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
 
@@ -1015,7 +997,7 @@ typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
 struct grub_efi_piwg_device_path
 {
   grub_efi_device_path_t header;
-  grub_efi_packed_guid_t guid;
+  grub_guid_t guid;
 } GRUB_PACKED;
 typedef struct grub_efi_piwg_device_path grub_efi_piwg_device_path_t;
 
@@ -1186,47 +1168,47 @@ struct grub_efi_boot_services
 
   grub_efi_status_t
   (__grub_efi_api *install_protocol_interface) (grub_efi_handle_t *handle,
-						grub_efi_guid_t *protocol,
+						grub_guid_t *protocol,
 						grub_efi_interface_type_t protocol_interface_type,
 						void *protocol_interface);
 
   grub_efi_status_t
   (__grub_efi_api *reinstall_protocol_interface) (grub_efi_handle_t handle,
-						  grub_efi_guid_t *protocol,
+						  grub_guid_t *protocol,
 						  void *old_interface,
 						  void *new_interface);
 
   grub_efi_status_t
   (__grub_efi_api *uninstall_protocol_interface) (grub_efi_handle_t handle,
-						  grub_efi_guid_t *protocol,
+						  grub_guid_t *protocol,
 						  void *protocol_interface);
 
   grub_efi_status_t
   (__grub_efi_api *handle_protocol) (grub_efi_handle_t handle,
-				     grub_efi_guid_t *protocol,
+				     grub_guid_t *protocol,
 				     void **protocol_interface);
 
   void *reserved;
 
   grub_efi_status_t
-  (__grub_efi_api *register_protocol_notify) (grub_efi_guid_t *protocol,
+  (__grub_efi_api *register_protocol_notify) (grub_guid_t *protocol,
 					      grub_efi_event_t event,
 					      void **registration);
 
   grub_efi_status_t
   (__grub_efi_api *locate_handle) (grub_efi_locate_search_type_t search_type,
-				   grub_efi_guid_t *protocol,
+				   grub_guid_t *protocol,
 				   void *search_key,
 				   grub_efi_uintn_t *buffer_size,
 				   grub_efi_handle_t *buffer);
 
   grub_efi_status_t
-  (__grub_efi_api *locate_device_path) (grub_efi_guid_t *protocol,
+  (__grub_efi_api *locate_device_path) (grub_guid_t *protocol,
 					grub_efi_device_path_t **device_path,
 					grub_efi_handle_t *device);
 
   grub_efi_status_t
-  (__grub_efi_api *install_configuration_table) (grub_efi_guid_t *guid,
+  (__grub_efi_api *install_configuration_table) (grub_guid_t *guid,
 						 void *table);
 
   grub_efi_status_t
@@ -1280,7 +1262,7 @@ struct grub_efi_boot_services
 
   grub_efi_status_t
   (__grub_efi_api *open_protocol) (grub_efi_handle_t handle,
-				   grub_efi_guid_t *protocol,
+				   grub_guid_t *protocol,
 				   void **protocol_interface,
 				   grub_efi_handle_t agent_handle,
 				   grub_efi_handle_t controller_handle,
@@ -1288,30 +1270,30 @@ struct grub_efi_boot_services
 
   grub_efi_status_t
   (__grub_efi_api *close_protocol) (grub_efi_handle_t handle,
-				    grub_efi_guid_t *protocol,
+				    grub_guid_t *protocol,
 				    grub_efi_handle_t agent_handle,
 				    grub_efi_handle_t controller_handle);
 
   grub_efi_status_t
   (__grub_efi_api *open_protocol_information) (grub_efi_handle_t handle,
-					       grub_efi_guid_t *protocol,
+					       grub_guid_t *protocol,
 					       grub_efi_open_protocol_information_entry_t **entry_buffer,
 					       grub_efi_uintn_t *entry_count);
 
   grub_efi_status_t
   (__grub_efi_api *protocols_per_handle) (grub_efi_handle_t handle,
-					  grub_efi_packed_guid_t ***protocol_buffer,
+					  grub_guid_t ***protocol_buffer,
 					  grub_efi_uintn_t *protocol_buffer_count);
 
   grub_efi_status_t
   (__grub_efi_api *locate_handle_buffer) (grub_efi_locate_search_type_t search_type,
-					  grub_efi_guid_t *protocol,
+					  grub_guid_t *protocol,
 					  void *search_key,
 					  grub_efi_uintn_t *no_handles,
 					  grub_efi_handle_t **buffer);
 
   grub_efi_status_t
-  (__grub_efi_api *locate_protocol) (grub_efi_guid_t *protocol,
+  (__grub_efi_api *locate_protocol) (grub_guid_t *protocol,
 				     void *registration,
 				     void **protocol_interface);
 
@@ -1369,7 +1351,7 @@ struct grub_efi_runtime_services
 
   grub_efi_status_t
   (__grub_efi_api *get_variable) (grub_efi_char16_t *variable_name,
-				  const grub_efi_guid_t *vendor_guid,
+				  const grub_guid_t *vendor_guid,
 				  grub_efi_uint32_t *attributes,
 				  grub_efi_uintn_t *data_size,
 				  void *data);
@@ -1377,11 +1359,11 @@ struct grub_efi_runtime_services
   grub_efi_status_t
   (__grub_efi_api *get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
 					    grub_efi_char16_t *variable_name,
-					    grub_efi_guid_t *vendor_guid);
+					    grub_guid_t *vendor_guid);
 
   grub_efi_status_t
   (__grub_efi_api *set_variable) (grub_efi_char16_t *variable_name,
-				  const grub_efi_guid_t *vendor_guid,
+				  const grub_guid_t *vendor_guid,
 				  grub_efi_uint32_t attributes,
 				  grub_efi_uintn_t data_size,
 				  void *data);
@@ -1399,7 +1381,7 @@ typedef struct grub_efi_runtime_services grub_efi_runtime_services_t;
 
 struct grub_efi_configuration_table
 {
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   void *vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
@@ -1794,7 +1776,7 @@ struct grub_efi_shim_lock_protocol
 };
 typedef struct grub_efi_shim_lock_protocol grub_efi_shim_lock_protocol_t;
 
-typedef grub_efi_guid_t grub_efi_rng_algorithm_t;
+typedef grub_guid_t grub_efi_rng_algorithm_t;
 
 struct grub_efi_rng_protocol
 {
include/grub/efi/efi.h +8 -8
index 26f33433b..3d056a0a4 100644
@@ -37,18 +37,18 @@ struct linux_arch_kernel_header {
 };
 
 /* Functions.  */
-void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_efi_guid_t *protocol,
+void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_guid_t *protocol,
 					     void *registration);
 grub_efi_handle_t *
 EXPORT_FUNC(grub_efi_locate_handle) (grub_efi_locate_search_type_t search_type,
-				     grub_efi_guid_t *protocol,
+				     grub_guid_t *protocol,
 				     void *search_key,
 				     grub_efi_uintn_t *num_handles);
 void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle,
-					   grub_efi_guid_t *protocol,
+					   grub_guid_t *protocol,
 					   grub_efi_uint32_t attributes);
 grub_efi_status_t
-EXPORT_FUNC(grub_efi_close_protocol) (grub_efi_handle_t handle, grub_efi_guid_t *protocol);
+EXPORT_FUNC(grub_efi_close_protocol) (grub_efi_handle_t handle, grub_guid_t *protocol);
 int EXPORT_FUNC(grub_efi_set_text_mode) (int on);
 void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds);
 void *
@@ -89,23 +89,23 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memo
 							   grub_efi_uint32_t descriptor_version,
 							   grub_efi_memory_descriptor_t *virtual_map);
 grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable_with_attributes) (const char *variable,
-								       const grub_efi_guid_t *guid,
+								       const grub_guid_t *guid,
 								       grub_size_t *datasize_out,
 								       void **data_out,
 								       grub_efi_uint32_t *attributes);
 grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
-						       const grub_efi_guid_t *guid,
+						       const grub_guid_t *guid,
 						       grub_size_t *datasize_out,
 						       void **data_out);
 grub_err_t
 EXPORT_FUNC (grub_efi_set_variable_with_attributes) (const char *var,
-				     const grub_efi_guid_t *guid,
+				     const grub_guid_t *guid,
 				     void *data,
 				     grub_size_t datasize,
 				     grub_efi_uint32_t attributes);
 grub_err_t
 EXPORT_FUNC (grub_efi_set_variable) (const char *var,
-				     const grub_efi_guid_t *guid,
+				     const grub_guid_t *guid,
 				     void *data,
 				     grub_size_t datasize);
 int
include/grub/efiemu/efiemu.h +5 -5
index 5325e5839..caf0b505f 100644
@@ -176,26 +176,26 @@ grub_err_t grub_efiemu_loadcore_load (void);
 struct grub_efiemu_configuration_table
 {
   struct grub_efiemu_configuration_table *next;
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   void * (*get_table) (void *data);
   void (*unload) (void *data);
   void *data;
 };
 struct grub_efiemu_configuration_table32
 {
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint32_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t;
 struct grub_efiemu_configuration_table64
 {
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint64_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t;
-grub_err_t grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid);
+grub_err_t grub_efiemu_unregister_configuration_table (grub_guid_t guid);
 grub_err_t
-grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
+grub_efiemu_register_configuration_table (grub_guid_t guid,
 					  void * (*get_table) (void *data),
 					  void (*unload) (void *data),
 					  void *data);
include/grub/efiemu/runtime.h +1 -1
index 36d2dedf4..c9ad9fdfa 100644
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
 
 struct efi_variable
 {
-  grub_efi_packed_guid_t guid;
+  grub_guid_t guid;
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
include/grub/gpt_partition.h +2 -11
index 7a93f4329..020e71920 100644
@@ -22,15 +22,6 @@
 #include <grub/types.h>
 #include <grub/partition.h>
 
-struct grub_gpt_part_guid
-{
-  grub_uint32_t data1;
-  grub_uint16_t data2;
-  grub_uint16_t data3;
-  grub_uint8_t data4[8];
-} GRUB_PACKED;
-typedef struct grub_gpt_part_guid grub_gpt_part_guid_t;
-
 #define GRUB_GPT_PARTITION_TYPE_EMPTY \
   { 0x0, 0x0, 0x0, \
     { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } \
@@ -70,8 +61,8 @@ struct grub_gpt_header
 
 struct grub_gpt_partentry
 {
-  grub_gpt_part_guid_t type;
-  grub_gpt_part_guid_t guid;
+  grub_guid_t type;
+  grub_guid_t guid;
   grub_uint64_t start;
   grub_uint64_t end;
   grub_uint64_t attrib;
include/grub/types.h +9 -0
index 6d5dc5cda..c56ce9820 100644
@@ -365,4 +365,13 @@ static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
 # define grub_absolute_pointer(val) ((void *) (val))
 #endif
 
+struct grub_guid
+{
+  grub_uint32_t data1;
+  grub_uint16_t data2;
+  grub_uint16_t data3;
+  grub_uint8_t data4[8];
+} GRUB_PACKED;
+typedef struct grub_guid grub_guid_t;
+
 #endif /* ! GRUB_TYPES_HEADER */
util/grub-install.c +1 -1
index e20820d9e..1ad04db36 100644
@@ -728,7 +728,7 @@ is_prep_partition (grub_device_t dev)
       if (grub_disk_read (dev->disk, p->offset, p->index,
 			  sizeof (gptdata), &gptdata) == 0)
 	{
-	  const grub_gpt_part_guid_t template = {
+	  const grub_guid_t template = {
 	    grub_cpu_to_le32_compile_time (0x9e1a2d38),
 	    grub_cpu_to_le16_compile_time (0xc612),
 	    grub_cpu_to_le16_compile_time (0x4316),
util/grub-probe.c +0 -0
index 446bd2553..65c1ca3f8 100644

util/grub-probe.c get_targets_string (void) · line 139

Quoted 8 lines
util/grub-probe.c +1 -1
@@ -133,7 +133,7 @@ get_targets_string (void)
 }
 
 static int
-print_gpt_guid (grub_gpt_part_guid_t guid)
+print_gpt_guid (grub_guid_t guid)
 {
   guid.data1 = grub_le_to_cpu32 (guid.data1);
   guid.data2 = grub_le_to_cpu16 (guid.data2);

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

Thanks,
Adrian

Quoted 1 line

[1] https://lists.gnu.org/archive/html/grub-devel/2023-08/msg00016.html

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#4 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 1,119 lines

Hi Oliver!

Quoted 1,103 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

---
 grub-core/commands/acpi.c            |  4 +-
 grub-core/commands/efi/efifwsetup.c  |  4 +-
 grub-core/commands/efi/loadbios.c    | 14 +++---
 grub-core/commands/efi/lsefi.c       |  4 +-
 grub-core/commands/efi/lsefisystab.c |  4 +-
 grub-core/commands/efi/lssal.c       |  4 +-
 grub-core/commands/efi/smbios.c      | 12 +++---
 grub-core/commands/efi/tpm.c         |  6 +--
 grub-core/commands/probe.c           |  2 +-
 grub-core/disk/efi/efidisk.c         |  4 +-
 grub-core/disk/ldm.c                 |  2 +-
 grub-core/efiemu/i386/pc/cfgtables.c |  6 +--
 grub-core/efiemu/main.c              |  4 +-
 grub-core/efiemu/runtime/efiemu.c    | 14 +++---
 grub-core/kern/efi/acpi.c            | 12 +++---
 grub-core/kern/efi/efi.c             | 22 +++++-----
 grub-core/kern/efi/fdt.c             |  2 +-
 grub-core/kern/efi/init.c            |  2 +-
 grub-core/kern/efi/sb.c              |  4 +-
 grub-core/loader/efi/fdt.c           |  2 +-
 grub-core/loader/efi/linux.c         |  4 +-
 grub-core/loader/i386/xnu.c          |  4 +-
 grub-core/loader/ia64/efi/linux.c    |  2 +-
 grub-core/net/drivers/efi/efinet.c   |  4 +-
 grub-core/partmap/gpt.c              |  4 +-
 grub-core/term/efi/console.c         |  2 +-
 grub-core/term/efi/serial.c          |  2 +-
 grub-core/video/efi_gop.c            |  8 ++--
 grub-core/video/efi_uga.c            |  2 +-
 include/grub/efi/api.h               | 64 ++++++++++------------------
 include/grub/efi/efi.h               | 16 +++----
 include/grub/efiemu/efiemu.h         | 10 ++---
 include/grub/efiemu/runtime.h        |  2 +-
 include/grub/gpt_partition.h         | 13 +-----
 include/grub/types.h                 |  9 ++++
 util/grub-install.c                  |  2 +-
 util/grub-probe.c                    |  2 +-
 37 files changed, 130 insertions(+), 148 deletions(-)
grub-core/commands/acpi.c +2 -2
index ab067ae6e..deec4bb43 100644
@@ -759,8 +759,8 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
 
 #ifdef GRUB_MACHINE_EFI
   {
-    struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID;
-    struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
+    static grub_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
+    static grub_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
 
     grub_efi_system_table->boot_services->install_configuration_table (&acpi20,
                                                                     grub_acpi_get_rsdpv2 ());
grub-core/commands/efi/efifwsetup.c +2 -2
index de66c3035..704f9d352 100644
@@ -38,7 +38,7 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)),
   grub_efi_uint64_t os_indications = GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
   grub_err_t status;
   grub_size_t oi_size;
-  static grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
 
   if (argc >= 1 && grub_strcmp(args[0], "--is-supported") == 0)
     return !efifwsetup_is_supported ();
@@ -72,7 +72,7 @@ efifwsetup_is_supported (void)
 {
   grub_efi_uint64_t *os_indications_supported = NULL;
   grub_size_t oi_size = 0;
-  static grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID;
   grub_efi_boolean_t ret = 0;
 
   grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size,
grub-core/commands/efi/loadbios.c +7 -7
index 574e41046..8f6b0ecfc 100644
@@ -27,9 +27,9 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
-static grub_efi_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
-static grub_efi_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
+static grub_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
+static grub_guid_t acpi2_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
+static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
 
 #define EBDA_SEG_ADDR        0x40e
 #define LOW_MEM_ADDR 0x413
@@ -105,15 +105,15 @@ fake_bios_data (int use_rom)
   smbios = 0;
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
      &grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_efi_guid_t)))
+      if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_guid_t)))
      {
        acpi = grub_efi_system_table->configuration_table[i].vendor_table;
        grub_dprintf ("efi", "ACPI2: %p\n", acpi);
      }
-      else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
+      else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_guid_t)))
      {
        void *t;
 
@@ -122,7 +122,7 @@ fake_bios_data (int use_rom)
          acpi = t;
        grub_dprintf ("efi", "ACPI: %p\n", t);
      }
-      else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_guid_t)))
+      else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_guid_t)))
      {
        smbios = grub_efi_system_table->configuration_table[i].vendor_table;
        grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
grub-core/commands/efi/lsefi.c +2 -2
index 539701497..6935cd302 100644
@@ -31,7 +31,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 
 struct known_protocol
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 } known_protocols[] =
   {
@@ -96,7 +96,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
       grub_efi_handle_t handle = handles[i];
       grub_efi_status_t status;
       grub_efi_uintn_t num_protocols;
-      grub_efi_packed_guid_t **protocols;
+      grub_guid_t **protocols;
       grub_efi_device_path_t *dp;
 
       grub_printf ("Handle %p\n", handle);
grub-core/commands/efi/lsefisystab.c +2 -2
index ac3299b7f..eff8c41f3 100644
@@ -29,7 +29,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
 
 struct guid_mapping
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 };
 
@@ -104,7 +104,7 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),
 
       for (j = 0; j < ARRAY_SIZE (guid_mappings); j++)
      if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
-                      sizeof (grub_efi_guid_t)) == 0)
+                      sizeof (grub_guid_t)) == 0)
        grub_printf ("   %s", guid_mappings[j].name);
 
       grub_printf ("\n");
grub-core/commands/efi/lssal.c +2 -2
index 5084ddd8b..fd6085f1b 100644
@@ -139,12 +139,12 @@ grub_cmd_lssal (struct grub_command *cmd __attribute__ ((unused)),
   const grub_efi_system_table_t *st = grub_efi_system_table;
   grub_efi_configuration_table_t *t = st->configuration_table;
   unsigned int i;
-  grub_efi_packed_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
+  static grub_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
 
   for (i = 0; i < st->num_table_entries; i++)
     {
       if (grub_memcmp (&guid, &t->vendor_guid,
-                    sizeof (grub_efi_packed_guid_t)) == 0)
+                    sizeof (grub_guid_t)) == 0)
      {
        disp_sal (t->vendor_table);
        return GRUB_ERR_NONE;
grub-core/commands/efi/smbios.c +6 -6
index 75202d5aa..d77239732 100644
@@ -26,14 +26,14 @@ struct grub_smbios_eps *
 grub_machine_smbios_get_eps (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
+  static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
      &grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_guid_t)))
      return (struct grub_smbios_eps *)
        grub_efi_system_table->configuration_table[i].vendor_table;
     }
@@ -45,14 +45,14 @@ struct grub_smbios_eps3 *
 grub_machine_smbios_get_eps3 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
+  static grub_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
      &grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_guid_t)))
      return (struct grub_smbios_eps3 *)
        grub_efi_system_table->configuration_table[i].vendor_table;
     }
grub-core/commands/efi/tpm.c +3 -3
index 421355204..c616768f9 100644
@@ -30,9 +30,9 @@
 
 typedef TCG_PCR_EVENT grub_tpm_event_t;
 
-static grub_efi_guid_t tpm_guid = EFI_TPM_GUID;
-static grub_efi_guid_t tpm2_guid = EFI_TPM2_GUID;
-static grub_efi_guid_t cc_measurement_guid = GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID;
+static grub_guid_t tpm_guid = EFI_TPM_GUID;
+static grub_guid_t tpm2_guid = EFI_TPM2_GUID;
+static grub_guid_t cc_measurement_guid = GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID;
 
 static grub_efi_handle_t *grub_tpm_handle;
 static grub_uint8_t grub_tpm_version;
grub-core/commands/probe.c +1 -1
index 9a80ea54f..cc8c05586 100644
@@ -119,7 +119,7 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)
        if (grub_strcmp(dev->disk->partition->partmap->name, "gpt") == 0)
          {
            struct grub_gpt_partentry entry;
-           grub_gpt_part_guid_t *guid;
+           grub_guid_t *guid;
 
            if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), &entry))
              {
grub-core/disk/efi/efidisk.c +2 -2
index ad025010a..3b5ed5691 100644
@@ -37,7 +37,7 @@ struct grub_efidisk_data
 };
 
 /* GUID.  */
-static grub_efi_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID;
+static grub_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID;
 
 static struct grub_efidisk_data *fd_devices;
 static struct grub_efidisk_data *hd_devices;
@@ -319,7 +319,7 @@ name_devices (struct grub_efidisk_data *devices)
        == GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE)
      {
        grub_efi_vendor_device_path_t *vendor = (grub_efi_vendor_device_path_t *) dp;
-       const struct grub_efi_guid apple = GRUB_EFI_VENDOR_APPLE_GUID;
+       static const grub_guid_t apple = GRUB_EFI_VENDOR_APPLE_GUID;
 
        if (vendor->header.length == sizeof (*vendor)
            && grub_memcmp (&vendor->vendor_guid, &apple,
grub-core/disk/ldm.c +1 -1
index 9632bc489..34bfe6bd1 100644
@@ -136,7 +136,7 @@ msdos_has_ldm_partition (grub_disk_t dsk)
   return has_ldm;
 }
 
-static const grub_gpt_part_guid_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM;
+static const grub_guid_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM;
 
 /* Helper for gpt_ldm_sector.  */
 static int
grub-core/efiemu/i386/pc/cfgtables.c +3 -3
index 1098f0b79..056ec0bc9 100644
@@ -29,9 +29,9 @@ grub_machine_efiemu_init_tables (void)
 {
   void *table;
   grub_err_t err;
-  static grub_efi_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID;
-  static grub_efi_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
-  static grub_efi_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
+  static grub_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID;
+  static grub_guid_t acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
+  static grub_guid_t acpi = GRUB_EFI_ACPI_TABLE_GUID;
 
   err = grub_efiemu_unregister_configuration_table (smbios);
   if (err)
grub-core/efiemu/main.c +2 -2
index a81934725..e7037f4ed 100644
@@ -80,7 +80,7 @@ grub_efiemu_unload (void)
 
 /* Remove previously registered table from the list */
 grub_err_t
-grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid)
+grub_efiemu_unregister_configuration_table (grub_guid_t guid)
 {
   struct grub_efiemu_configuration_table *cur, *prev;
 
@@ -136,7 +136,7 @@ grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),
    or with a hook
 */
 grub_err_t
-grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
+grub_efiemu_register_configuration_table (grub_guid_t guid,
                                        void * (*get_table) (void *data),
                                        void (*unload) (void *data),
                                        void *data)
grub-core/efiemu/runtime/efiemu.c +7 -7
index 53b3cce7b..c84b30652 100644
@@ -66,7 +66,7 @@ efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,
 
 grub_efi_status_t __grub_efi_api
 efiemu_get_variable (grub_efi_char16_t *variable_name,
-                  const grub_efi_guid_t *vendor_guid,
+                  const grub_guid_t *vendor_guid,
                   grub_efi_uint32_t *attributes,
                   grub_efi_uintn_t *data_size,
                   void *data);
@@ -74,11 +74,11 @@ efiemu_get_variable (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api
 efiemu_get_next_variable_name (grub_efi_uintn_t *variable_name_size,
                             grub_efi_char16_t *variable_name,
-                            grub_efi_guid_t *vendor_guid);
+                            grub_guid_t *vendor_guid);
 
 grub_efi_status_t __grub_efi_api
 efiemu_set_variable (grub_efi_char16_t *variable_name,
-                  const grub_efi_guid_t *vendor_guid,
+                  const grub_guid_t *vendor_guid,
                   grub_efi_uint32_t attributes,
                   grub_efi_uintn_t data_size,
                   void *data);
@@ -416,7 +416,7 @@ EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
 
 /* Find variable by name and GUID. */
 static struct efi_variable *
-find_variable (const grub_efi_guid_t *vendor_guid,
+find_variable (const grub_guid_t *vendor_guid,
             grub_efi_char16_t *variable_name)
 {
   grub_uint8_t *ptr;
@@ -438,7 +438,7 @@ find_variable (const grub_efi_guid_t *vendor_guid,
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
-                             const grub_efi_guid_t *vendor_guid,
+                             const grub_guid_t *vendor_guid,
                              grub_efi_uint32_t *attributes,
                              grub_efi_uintn_t *data_size,
                              void *data)
@@ -464,7 +464,7 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api EFI_FUNC
 (efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
                               grub_efi_char16_t *variable_name,
-                              grub_efi_guid_t *vendor_guid)
+                              grub_guid_t *vendor_guid)
 {
   struct efi_variable *efivar;
   LOG ('l');
@@ -503,7 +503,7 @@ grub_efi_status_t __grub_efi_api EFI_FUNC
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
-                             const grub_efi_guid_t *vendor_guid,
+                             const grub_guid_t *vendor_guid,
                              grub_efi_uint32_t attributes,
                              grub_efi_uintn_t data_size,
                              void *data)
grub-core/kern/efi/acpi.c +6 -6
index 74f8cd1a9..461c77c33 100644
@@ -26,14 +26,14 @@ struct grub_acpi_rsdp_v10 *
 grub_machine_acpi_get_rsdpv1 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
+  static grub_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
      &grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_guid_t)))
      return (struct grub_acpi_rsdp_v10 *)
        grub_efi_system_table->configuration_table[i].vendor_table;
     }
@@ -44,14 +44,14 @@ struct grub_acpi_rsdp_v20 *
 grub_machine_acpi_get_rsdpv2 (void)
 {
   unsigned i;
-  static grub_efi_packed_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
+  static grub_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_efi_packed_guid_t *guid =
+      grub_guid_t *guid =
      &grub_efi_system_table->configuration_table[i].vendor_guid;
 
-      if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_efi_packed_guid_t)))
+      if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_guid_t)))
      return (struct grub_acpi_rsdp_v20 *)
        grub_efi_system_table->configuration_table[i].vendor_table;
     }
grub-core/kern/efi/efi.c +11 -11
index 4a1df6fb2..9e7d1a4a7 100644
@@ -35,12 +35,12 @@ grub_efi_handle_t grub_efi_image_handle;
 /* The pointer to a system table. Filled in by the startup code.  */
 grub_efi_system_table_t *grub_efi_system_table;
 
-static grub_efi_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID;
-static grub_efi_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
-static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
+static grub_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID;
+static grub_guid_t loaded_image_guid = GRUB_EFI_LOADED_IMAGE_GUID;
+static grub_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
 
 void *
-grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
+grub_efi_locate_protocol (grub_guid_t *protocol, void *registration)
 {
   void *interface;
   grub_efi_status_t status;
@@ -59,7 +59,7 @@ grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
    from the heap.  */
 grub_efi_handle_t *
 grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
-                     grub_efi_guid_t *protocol,
+                     grub_guid_t *protocol,
                      void *search_key,
                      grub_efi_uintn_t *num_handles)
 {
@@ -98,7 +98,7 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
 
 void *
 grub_efi_open_protocol (grub_efi_handle_t handle,
-                     grub_efi_guid_t *protocol,
+                     grub_guid_t *protocol,
                      grub_efi_uint32_t attributes)
 {
   grub_efi_boot_services_t *b;
@@ -119,7 +119,7 @@ grub_efi_open_protocol (grub_efi_handle_t handle,
 }
 
 grub_efi_status_t
-grub_efi_close_protocol (grub_efi_handle_t handle, grub_efi_guid_t *protocol)
+grub_efi_close_protocol (grub_efi_handle_t handle, grub_guid_t *protocol)
 {
   grub_efi_boot_services_t *b = grub_efi_system_table->boot_services;
 
@@ -203,7 +203,7 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
 }
 
 grub_err_t
-grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *guid,
+grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,
                    void *data, grub_size_t datasize, grub_efi_uint32_t attributes)
 {
   grub_efi_status_t status;
@@ -230,7 +230,7 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_efi_guid_t *g
 }
 
 grub_err_t
-grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,
+grub_efi_set_variable (const char *var, const grub_guid_t *guid,
                    void *data, grub_size_t datasize)
 {
   return grub_efi_set_variable_with_attributes (var, guid, data, datasize,
@@ -241,7 +241,7 @@ grub_efi_set_variable (const char *var, const grub_efi_guid_t *guid,
 
 grub_efi_status_t
 grub_efi_get_variable_with_attributes (const char *var,
-                                    const grub_efi_guid_t *guid,
+                                    const grub_guid_t *guid,
                                     grub_size_t *datasize_out,
                                     void **data_out,
                                     grub_efi_uint32_t *attributes)
@@ -296,7 +296,7 @@ grub_efi_get_variable_with_attributes (const char *var,
 }
 
 grub_efi_status_t
-grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
+grub_efi_get_variable (const char *var, const grub_guid_t *guid,
                     grub_size_t *datasize_out, void **data_out)
 {
   return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL);
grub-core/kern/efi/fdt.c +1 -1
index 24f955289..8fcf43f1b 100644
@@ -24,7 +24,7 @@ void *
 grub_efi_get_firmware_fdt (void)
 {
   grub_efi_configuration_table_t *tables;
-  static grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
+  static grub_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
   void *firmware_fdt = NULL;
   unsigned int i;
 
grub-core/kern/efi/init.c +1 -1
index e873ef529..8a9c838c0 100644
@@ -36,7 +36,7 @@ static grub_efi_char16_t stack_chk_fail_msg[] =
   L"* GRUB: ABORTED!!! *\r\n"
   L"* GRUB: REBOOTING IN 5 SECONDS... *\r\n";
 
-static grub_efi_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
+static grub_guid_t rng_protocol_guid = GRUB_EFI_RNG_PROTOCOL_GUID;
 
 /*
  * Don't put this on grub_efi_init()'s local stack to avoid it
grub-core/kern/efi/sb.c +2 -2
index db42c2539..80cfa0888 100644
@@ -30,7 +30,7 @@
 #include <grub/types.h>
 #include <grub/verify.h>
 
-static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
+static grub_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
 
 /*
  * Determine whether we're in secure boot mode.
@@ -41,7 +41,7 @@ static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
 grub_uint8_t
 grub_efi_get_secureboot (void)
 {
-  static grub_efi_guid_t efi_variable_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+  static grub_guid_t efi_variable_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
   grub_efi_status_t status;
   grub_efi_uint32_t attr = 0;
   grub_size_t size = 0;
grub-core/loader/efi/fdt.c +1 -1
index 35a3be2e5..439964b9c 100644
@@ -86,7 +86,7 @@ grub_err_t
 grub_fdt_install (void)
 {
   grub_efi_boot_services_t *b;
-  static grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
+  static grub_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
   grub_efi_status_t status;
 
   if (fdt == NULL && loaded_fdt == NULL)
grub-core/loader/efi/linux.c +2 -2
index 1d98fa365..c1eef7c98 100644
@@ -51,8 +51,8 @@ static struct grub_linux_initrd_context initrd_ctx = {0, 0, 0};
 static grub_efi_handle_t initrd_lf2_handle = NULL;
 static bool initrd_use_loadfile2 = false;
 
-static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
-static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
+static grub_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
+static grub_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
 
 static initrd_media_device_path_t initrd_lf2_device_path = {
   {
grub-core/loader/i386/xnu.c +2 -2
index 4c88ce5e0..93ba4476d 100644
@@ -48,7 +48,7 @@ grub_uint32_t grub_xnu_entry_point, grub_xnu_arg1, grub_xnu_stack;
 /* Aliases set for some tables. */
 struct tbl_alias
 {
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   const char *name;
 };
 
@@ -694,7 +694,7 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)
     {
       void *ptr;
       struct grub_xnu_devtree_key *curkey;
-      grub_efi_packed_guid_t guid;
+      grub_guid_t guid;
       char guidbuf[64];
 
       /* Retrieve current key. */
grub-core/loader/ia64/efi/linux.c +1 -1
index fb9b961f7..3dd2e8236 100644
@@ -106,7 +106,7 @@ query_fpswa (void)
   grub_efi_boot_services_t *bs;
   grub_efi_status_t status;
   grub_efi_uintn_t size;
-  static const grub_efi_guid_t fpswa_protocol =
+  static const grub_guid_t fpswa_protocol =
     { 0xc41b6531, 0x97b9, 0x11d3,
       {0x9a, 0x29, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} };
 
grub-core/net/drivers/efi/efinet.c +2 -2
index 56a179709..3ea25cf98 100644
@@ -27,8 +27,8 @@
 GRUB_MOD_LICENSE ("GPLv3+");
 
 /* GUID.  */
-static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID;
-static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID;
+static grub_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID;
+static grub_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID;
 
 static grub_err_t
 send_card_buffer (struct grub_net_card *dev,
grub-core/partmap/gpt.c +2 -2
index 075cc96f1..877ceefc3 100644
@@ -36,10 +36,10 @@ static grub_uint8_t grub_gpt_magic[8] =
     0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54
   };
 
-static const grub_gpt_part_guid_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
+static const grub_guid_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
 
 #ifdef GRUB_UTIL
-static const grub_gpt_part_guid_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
+static const grub_guid_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
 #endif
 
 /* 512 << 7 = 65536 byte sectors.  */
grub-core/term/efi/console.c +1 -1
index 9a7bc0fcf..bb587f39d 100644
@@ -352,7 +352,7 @@ grub_console_getkeystatus (struct grub_term_input *term)
 static grub_err_t
 grub_efi_console_input_init (struct grub_term_input *term)
 {
-  static grub_efi_guid_t text_input_ex_guid =
+  static grub_guid_t text_input_ex_guid =
     GRUB_EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
 
   if (grub_efi_is_finished)
grub-core/term/efi/serial.c +1 -1
index e86ebce3f..5dfd2d86c 100644
@@ -31,7 +31,7 @@
 #include <grub/i18n.h>
 
 /* GUID.  */
-static grub_efi_guid_t serial_io_guid = GRUB_EFI_SERIAL_IO_GUID;
+static grub_guid_t serial_io_guid = GRUB_EFI_SERIAL_IO_GUID;
 
 static void
 do_real_config (struct grub_serial_port *port)
grub-core/video/efi_gop.c +4 -4
index 9c7901038..7247aeea7 100644
@@ -32,10 +32,10 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t graphics_output_guid = GRUB_EFI_GOP_GUID;
-static grub_efi_guid_t active_edid_guid = GRUB_EFI_EDID_ACTIVE_GUID;
-static grub_efi_guid_t discovered_edid_guid = GRUB_EFI_EDID_DISCOVERED_GUID;
-static grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
+static grub_guid_t graphics_output_guid = GRUB_EFI_GOP_GUID;
+static grub_guid_t active_edid_guid = GRUB_EFI_EDID_ACTIVE_GUID;
+static grub_guid_t discovered_edid_guid = GRUB_EFI_EDID_DISCOVERED_GUID;
+static grub_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
 static struct grub_efi_gop *gop;
 static unsigned old_mode;
 static int restore_needed;
grub-core/video/efi_uga.c +1 -1
index aa4659b8e..d53079e0b 100644
@@ -32,7 +32,7 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
+static grub_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID;
 static struct grub_efi_uga_draw_protocol *uga;
 static grub_uint64_t uga_fb;
 static grub_uint32_t uga_pitch;
include/grub/efi/api.h +23 -41
index fb881ae12..c0b6e86f1 100644
@@ -639,24 +639,6 @@ typedef grub_uint8_t grub_efi_ip_address_t[8] __attribute__ ((aligned(4)));
 typedef grub_efi_uint64_t grub_efi_physical_address_t;
 typedef grub_efi_uint64_t grub_efi_virtual_address_t;
 
-struct grub_efi_guid
-{
-  grub_uint32_t data1;
-  grub_uint16_t data2;
-  grub_uint16_t data3;
-  grub_uint8_t data4[8];
-} __attribute__ ((aligned(8)));
-typedef struct grub_efi_guid grub_efi_guid_t;
-
-struct grub_efi_packed_guid
-{
-  grub_uint32_t data1;
-  grub_uint16_t data2;
-  grub_uint16_t data3;
-  grub_uint8_t data4[8];
-} GRUB_PACKED;
-typedef struct grub_efi_packed_guid grub_efi_packed_guid_t;
-
 /* XXX although the spec does not specify the padding, this actually
    must have the padding!  */
 struct grub_efi_memory_descriptor
@@ -743,7 +725,7 @@ typedef struct grub_efi_memory_mapped_device_path grub_efi_memory_mapped_device_
 struct grub_efi_vendor_device_path
 {
   grub_efi_device_path_t header;
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint8_t vendor_defined_data[0];
 } GRUB_PACKED;
 typedef struct grub_efi_vendor_device_path grub_efi_vendor_device_path_t;
@@ -987,7 +969,7 @@ typedef struct grub_efi_cdrom_device_path grub_efi_cdrom_device_path_t;
 struct grub_efi_vendor_media_device_path
 {
   grub_efi_device_path_t header;
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint8_t vendor_defined_data[0];
 } GRUB_PACKED;
 typedef struct grub_efi_vendor_media_device_path grub_efi_vendor_media_device_path_t;
@@ -1006,7 +988,7 @@ typedef struct grub_efi_file_path_device_path grub_efi_file_path_device_path_t;
 struct grub_efi_protocol_device_path
 {
   grub_efi_device_path_t header;
-  grub_efi_packed_guid_t guid;
+  grub_guid_t guid;
 } GRUB_PACKED;
 typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
 
@@ -1015,7 +997,7 @@ typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
 struct grub_efi_piwg_device_path
 {
   grub_efi_device_path_t header;
-  grub_efi_packed_guid_t guid;
+  grub_guid_t guid;
 } GRUB_PACKED;
 typedef struct grub_efi_piwg_device_path grub_efi_piwg_device_path_t;
 
@@ -1186,47 +1168,47 @@ struct grub_efi_boot_services
 
   grub_efi_status_t
   (__grub_efi_api *install_protocol_interface) (grub_efi_handle_t *handle,
-                                             grub_efi_guid_t *protocol,
+                                             grub_guid_t *protocol,
                                              grub_efi_interface_type_t protocol_interface_type,
                                              void *protocol_interface);
 
   grub_efi_status_t
   (__grub_efi_api *reinstall_protocol_interface) (grub_efi_handle_t handle,
-                                               grub_efi_guid_t *protocol,
+                                               grub_guid_t *protocol,
                                                void *old_interface,
                                                void *new_interface);
 
   grub_efi_status_t
   (__grub_efi_api *uninstall_protocol_interface) (grub_efi_handle_t handle,
-                                               grub_efi_guid_t *protocol,
+                                               grub_guid_t *protocol,
                                                void *protocol_interface);
 
   grub_efi_status_t
   (__grub_efi_api *handle_protocol) (grub_efi_handle_t handle,
-                                  grub_efi_guid_t *protocol,
+                                  grub_guid_t *protocol,
                                   void **protocol_interface);
 
   void *reserved;
 
   grub_efi_status_t
-  (__grub_efi_api *register_protocol_notify) (grub_efi_guid_t *protocol,
+  (__grub_efi_api *register_protocol_notify) (grub_guid_t *protocol,
                                            grub_efi_event_t event,
                                            void **registration);
 
   grub_efi_status_t
   (__grub_efi_api *locate_handle) (grub_efi_locate_search_type_t search_type,
-                                grub_efi_guid_t *protocol,
+                                grub_guid_t *protocol,
                                 void *search_key,
                                 grub_efi_uintn_t *buffer_size,
                                 grub_efi_handle_t *buffer);
 
   grub_efi_status_t
-  (__grub_efi_api *locate_device_path) (grub_efi_guid_t *protocol,
+  (__grub_efi_api *locate_device_path) (grub_guid_t *protocol,
                                      grub_efi_device_path_t **device_path,
                                      grub_efi_handle_t *device);
 
   grub_efi_status_t
-  (__grub_efi_api *install_configuration_table) (grub_efi_guid_t *guid,
+  (__grub_efi_api *install_configuration_table) (grub_guid_t *guid,
                                               void *table);
 
   grub_efi_status_t
@@ -1280,7 +1262,7 @@ struct grub_efi_boot_services
 
   grub_efi_status_t
   (__grub_efi_api *open_protocol) (grub_efi_handle_t handle,
-                                grub_efi_guid_t *protocol,
+                                grub_guid_t *protocol,
                                 void **protocol_interface,
                                 grub_efi_handle_t agent_handle,
                                 grub_efi_handle_t controller_handle,
@@ -1288,30 +1270,30 @@ struct grub_efi_boot_services
 
   grub_efi_status_t
   (__grub_efi_api *close_protocol) (grub_efi_handle_t handle,
-                                 grub_efi_guid_t *protocol,
+                                 grub_guid_t *protocol,
                                  grub_efi_handle_t agent_handle,
                                  grub_efi_handle_t controller_handle);
 
   grub_efi_status_t
   (__grub_efi_api *open_protocol_information) (grub_efi_handle_t handle,
-                                            grub_efi_guid_t *protocol,
+                                            grub_guid_t *protocol,
                                             grub_efi_open_protocol_information_entry_t **entry_buffer,
                                             grub_efi_uintn_t *entry_count);
 
   grub_efi_status_t
   (__grub_efi_api *protocols_per_handle) (grub_efi_handle_t handle,
-                                       grub_efi_packed_guid_t ***protocol_buffer,
+                                       grub_guid_t ***protocol_buffer,
                                        grub_efi_uintn_t *protocol_buffer_count);
 
   grub_efi_status_t
   (__grub_efi_api *locate_handle_buffer) (grub_efi_locate_search_type_t search_type,
-                                       grub_efi_guid_t *protocol,
+                                       grub_guid_t *protocol,
                                        void *search_key,
                                        grub_efi_uintn_t *no_handles,
                                        grub_efi_handle_t **buffer);
 
   grub_efi_status_t
-  (__grub_efi_api *locate_protocol) (grub_efi_guid_t *protocol,
+  (__grub_efi_api *locate_protocol) (grub_guid_t *protocol,
                                   void *registration,
                                   void **protocol_interface);
 
@@ -1369,7 +1351,7 @@ struct grub_efi_runtime_services
 
   grub_efi_status_t
   (__grub_efi_api *get_variable) (grub_efi_char16_t *variable_name,
-                               const grub_efi_guid_t *vendor_guid,
+                               const grub_guid_t *vendor_guid,
                                grub_efi_uint32_t *attributes,
                                grub_efi_uintn_t *data_size,
                                void *data);
@@ -1377,11 +1359,11 @@ struct grub_efi_runtime_services
   grub_efi_status_t
   (__grub_efi_api *get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
                                          grub_efi_char16_t *variable_name,
-                                         grub_efi_guid_t *vendor_guid);
+                                         grub_guid_t *vendor_guid);
 
   grub_efi_status_t
   (__grub_efi_api *set_variable) (grub_efi_char16_t *variable_name,
-                               const grub_efi_guid_t *vendor_guid,
+                               const grub_guid_t *vendor_guid,
                                grub_efi_uint32_t attributes,
                                grub_efi_uintn_t data_size,
                                void *data);
@@ -1399,7 +1381,7 @@ typedef struct grub_efi_runtime_services grub_efi_runtime_services_t;
 
 struct grub_efi_configuration_table
 {
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   void *vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
@@ -1794,7 +1776,7 @@ struct grub_efi_shim_lock_protocol
 };
 typedef struct grub_efi_shim_lock_protocol grub_efi_shim_lock_protocol_t;
 
-typedef grub_efi_guid_t grub_efi_rng_algorithm_t;
+typedef grub_guid_t grub_efi_rng_algorithm_t;
 
 struct grub_efi_rng_protocol
 {
include/grub/efi/efi.h +8 -8
index 26f33433b..3d056a0a4 100644
@@ -37,18 +37,18 @@ struct linux_arch_kernel_header {
 };
 
 /* Functions.  */
-void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_efi_guid_t *protocol,
+void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_guid_t *protocol,
                                           void *registration);
 grub_efi_handle_t *
 EXPORT_FUNC(grub_efi_locate_handle) (grub_efi_locate_search_type_t search_type,
-                                  grub_efi_guid_t *protocol,
+                                  grub_guid_t *protocol,
                                   void *search_key,
                                   grub_efi_uintn_t *num_handles);
 void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle,
-                                        grub_efi_guid_t *protocol,
+                                        grub_guid_t *protocol,
                                         grub_efi_uint32_t attributes);
 grub_efi_status_t
-EXPORT_FUNC(grub_efi_close_protocol) (grub_efi_handle_t handle, grub_efi_guid_t *protocol);
+EXPORT_FUNC(grub_efi_close_protocol) (grub_efi_handle_t handle, grub_guid_t *protocol);
 int EXPORT_FUNC(grub_efi_set_text_mode) (int on);
 void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds);
 void *
@@ -89,23 +89,23 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memo
                                                         grub_efi_uint32_t descriptor_version,
                                                         grub_efi_memory_descriptor_t *virtual_map);
 grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable_with_attributes) (const char *variable,
-                                                                    const grub_efi_guid_t *guid,
+                                                                    const grub_guid_t *guid,
                                                                     grub_size_t *datasize_out,
                                                                     void **data_out,
                                                                     grub_efi_uint32_t *attributes);
 grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
-                                                    const grub_efi_guid_t *guid,
+                                                    const grub_guid_t *guid,
                                                     grub_size_t *datasize_out,
                                                     void **data_out);
 grub_err_t
 EXPORT_FUNC (grub_efi_set_variable_with_attributes) (const char *var,
-                                  const grub_efi_guid_t *guid,
+                                  const grub_guid_t *guid,
                                   void *data,
                                   grub_size_t datasize,
                                   grub_efi_uint32_t attributes);
 grub_err_t
 EXPORT_FUNC (grub_efi_set_variable) (const char *var,
-                                  const grub_efi_guid_t *guid,
+                                  const grub_guid_t *guid,
                                   void *data,
                                   grub_size_t datasize);
 int
include/grub/efiemu/efiemu.h +5 -5
index 5325e5839..caf0b505f 100644
@@ -176,26 +176,26 @@ grub_err_t grub_efiemu_loadcore_load (void);
 struct grub_efiemu_configuration_table
 {
   struct grub_efiemu_configuration_table *next;
-  grub_efi_guid_t guid;
+  grub_guid_t guid;
   void * (*get_table) (void *data);
   void (*unload) (void *data);
   void *data;
 };
 struct grub_efiemu_configuration_table32
 {
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint32_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t;
 struct grub_efiemu_configuration_table64
 {
-  grub_efi_packed_guid_t vendor_guid;
+  grub_guid_t vendor_guid;
   grub_efi_uint64_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t;
-grub_err_t grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid);
+grub_err_t grub_efiemu_unregister_configuration_table (grub_guid_t guid);
 grub_err_t
-grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
+grub_efiemu_register_configuration_table (grub_guid_t guid,
                                        void * (*get_table) (void *data),
                                        void (*unload) (void *data),
                                        void *data);
include/grub/efiemu/runtime.h +1 -1
index 36d2dedf4..c9ad9fdfa 100644
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
 
 struct efi_variable
 {
-  grub_efi_packed_guid_t guid;
+  grub_guid_t guid;
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
include/grub/gpt_partition.h +2 -11
index 7a93f4329..020e71920 100644
@@ -22,15 +22,6 @@
 #include <grub/types.h>
 #include <grub/partition.h>
 
-struct grub_gpt_part_guid
-{
-  grub_uint32_t data1;
-  grub_uint16_t data2;
-  grub_uint16_t data3;
-  grub_uint8_t data4[8];
-} GRUB_PACKED;
-typedef struct grub_gpt_part_guid grub_gpt_part_guid_t;
-
 #define GRUB_GPT_PARTITION_TYPE_EMPTY \
   { 0x0, 0x0, 0x0, \
     { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } \
@@ -70,8 +61,8 @@ struct grub_gpt_header
 
 struct grub_gpt_partentry
 {
-  grub_gpt_part_guid_t type;
-  grub_gpt_part_guid_t guid;
+  grub_guid_t type;
+  grub_guid_t guid;
   grub_uint64_t start;
   grub_uint64_t end;
   grub_uint64_t attrib;
include/grub/types.h +9 -0
index 6d5dc5cda..c56ce9820 100644
@@ -365,4 +365,13 @@ static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
 # define grub_absolute_pointer(val) ((void *) (val))
 #endif
 
+struct grub_guid
+{
+  grub_uint32_t data1;
+  grub_uint16_t data2;
+  grub_uint16_t data3;
+  grub_uint8_t data4[8];
+} GRUB_PACKED;
+typedef struct grub_guid grub_guid_t;
+
 #endif /* ! GRUB_TYPES_HEADER */
util/grub-install.c +1 -1
index e20820d9e..1ad04db36 100644
@@ -728,7 +728,7 @@ is_prep_partition (grub_device_t dev)
       if (grub_disk_read (dev->disk, p->offset, p->index,
                        sizeof (gptdata), &gptdata) == 0)
      {
-       const grub_gpt_part_guid_t template = {
+       const grub_guid_t template = {
          grub_cpu_to_le32_compile_time (0x9e1a2d38),
          grub_cpu_to_le16_compile_time (0xc612),
          grub_cpu_to_le16_compile_time (0x4316),
util/grub-probe.c +0 -0
index 446bd2553..65c1ca3f8 100644

util/grub-probe.c get_targets_string (void) · line 139

Quoted 8 lines
util/grub-probe.c +1 -1
@@ -133,7 +133,7 @@ get_targets_string (void)
 }
 
 static int
-print_gpt_guid (grub_gpt_part_guid_t guid)
+print_gpt_guid (grub_guid_t guid)
 {
   guid.data1 = grub_le_to_cpu32 (guid.data1);
   guid.data2 = grub_le_to_cpu16 (guid.data2);

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

Quoted 8 lines

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed the fact that in my "solution" the alignments are not correct in all cases.

The quickest way out could be to revert the GUID unification and printf format specifier commits:

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

I am open to suggestions / comments.

Sorry again,
Oliver

Quoted 11 lines

Thanks,
Adrian

Quoted 1 line

[1] https://lists.gnu.org/archive/html/grub-devel/2023-08/msg00016.html

--

 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 12 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 11 lines

Hi Oliver!

Quoted 8 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

[...]

Quoted 19 lines
Quoted 11 lines

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed the fact that in my "solution" the alignments are not correct in all cases.

The quickest way out could be to revert the GUID unification and printf format specifier commits:

Quoted 8 lines

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

I am open to suggestions / comments.

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always enforced alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

Daniel

Quoted 1 line
Quoted 1 line
Quoted 1 line

[1] https://lists.gnu.org/archive/html/grub-devel/2023-08/msg00016.html

[2] https://lists.gnu.org/archive/html/grub-devel/2023-08/msg00020.html

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Hi Daniel!

Quoted 44 lines · Daniel Kiper
Quoted 12 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 11 lines

Hi Oliver!

Quoted 8 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

[...]

Quoted 19 lines
Quoted 11 lines

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed the fact that in my "solution" the alignments are not correct in all cases.

The quickest way out could be to revert the GUID unification and printf format specifier commits:

Quoted 8 lines

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

I am open to suggestions / comments.

Quoted 7 lines

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always enforced alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

My Itanium hardware is not available for bootloader tests at the moment, so I would like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed fix.

Thanks,
Adrian

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#7 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 54 lines · John Paul Adrian Glaubitz

Hi Daniel!

Quoted 47 lines · Daniel Kiper
Quoted 12 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 11 lines

Hi Oliver!

Quoted 8 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

[...]

Quoted 19 lines
Quoted 11 lines

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed the fact that in my "solution" the alignments are not correct in all cases.

The quickest way out could be to revert the GUID unification and printf format specifier commits:

Quoted 8 lines

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

I am open to suggestions / comments.

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Quoted 7 lines
Quoted 4 lines

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always enforced alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

My Itanium hardware is not available for bootloader tests at the moment, so I would like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```
diff --git a/include/grub/types.h b/include/grub/types.h
index 0d96006fe..ff415c970 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;
 
 #endif /* ! GRUB_TYPES_HEADER */
```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
   70 | } GRUB_PACKED;
      | ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

Quoted 9 lines

Thanks,
Adrian

Signature · 4 lines
.''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
 `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#8 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 95 lines · Pedro Miguel Justo
Quoted 3 lines

On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <

Quoted 13 lines · [email protected]> wrote:

Hi Daniel!

Quoted 9 lines · Daniel Kiper
Quoted 8 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 7 lines

Hi Oliver!

Quoted 4 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment

attribute

Quoted 38 lines
Quoted 38 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

is dropped, since it is not required.

[...]

Quoted 19 lines
Quoted 11 lines

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed the fact that in my "solution" the alignments are not correct in all cases.

The quickest way out could be to revert the GUID unification and printf format specifier commits:

Quoted 8 lines

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

I am open to suggestions / comments.

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Quoted 6 lines
Quoted 4 lines

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always enforced alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

My Itanium hardware is not available for bootloader tests at the moment,

so I would

Quoted 1 line

like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed

fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```

include/grub/types.h +1 -1
index 0d96006fe..ff415c970 100644
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;
 
 #endif /* ! GRUB_TYPES_HEADER */

```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

Quoted 6 lines

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

Quoted 10 lines
```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct
grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
   70 | } GRUB_PACKED;
      | ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct
grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
```
Quoted 16 lines

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

Quoted 9 lines

Thanks,
Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
. ' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#9 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20 bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan.
All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Quoted 114 lines · Vladimir 'phcoder' Serbinenko

Le dim. 13 août 2023, 00:57, Pedro Miguel Justo <[email protected]> a écrit :

Quoted 100 lines
Quoted 3 lines

On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <

Quoted 13 lines · [email protected]> wrote:

Hi Daniel!

Quoted 9 lines · Daniel Kiper
Quoted 8 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 7 lines

Hi Oliver!

Quoted 4 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment

attribute

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

is dropped, since it is not required.

[...]

Quoted 2 lines
Quoted 2 lines

According to [1], this change broke GRUB on ia64:

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on

ia64.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

fact that in my "solution" the alignments are not correct in all

cases.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The quickest way out could be to revert the GUID unification and

printf

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

format specifier commits:

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

I am open to suggestions / comments.

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always

enforced

Quoted 4 lines
Quoted 2 lines

alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

My Itanium hardware is not available for bootloader tests at the

moment, so I would

Quoted 1 line

like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed

fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```

include/grub/types.h +1 -1
index 0d96006fe..ff415c970 100644
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;
 
 #endif /* ! GRUB_TYPES_HEADER */

```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

Quoted 6 lines

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

Quoted 32 lines

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

Quoted 26 lines
```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct
grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
   70 | } GRUB_PACKED;
      | ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct
grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

Quoted 9 lines

Thanks,
Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
. ' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

From 2464b685824e09f9e970497e30f43860e3d40ce2 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:17:22 +0200
Subject: [PATCH 2/5] Mark grub_gpt_partentry as aligned to 8 bytes

---
 include/grub/gpt_partition.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/gpt_partition.h +1 -1
index 19df7dfff..3c70b148d 100644
@@ -74,7 +74,7 @@ struct grub_gpt_partentry
   grub_uint64_t end;
   grub_uint64_t attrib;
   char name[72];
-} GRUB_PACKED;
+} __attribute__((aligned(8)));
 
 grub_err_t
 grub_gpt_partition_map_iterate (grub_disk_t disk,
Signature · 1 line
2.39.2

From 74d86aa1e0ec87fa017ac661f033e1566b51088d Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:15:54 +0200
Subject: [PATCH 1/5] Add missing static qualifier

---
 grub-core/commands/efi/lsefi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/commands/efi/lsefi.c +1 -1
index 05e2e511e..95cba5baf 100644
@@ -29,7 +29,7 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-struct known_protocol
+static struct known_protocol
 {
   grub_guid_t guid;
   const char *name;
Signature · 1 line
2.39.2

From 3cd891ec5e8c51fe9e0d4872aa426cdd1335166e Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:18:53 +0200
Subject: [PATCH 4/5] Add compile time asserts for guid and gpt_partentry sizes

---
 grub-core/partmap/gpt.c | 3 +++
 1 file changed, 3 insertions(+)
grub-core/partmap/gpt.c +3 -0
index 877ceefc3..426f616ae 100644
@@ -229,6 +229,9 @@ static struct grub_partition_map grub_gpt_partition_map =
 
 GRUB_MOD_INIT(part_gpt)
 {
+  COMPILE_TIME_ASSERT(sizeof(grub_guid_t) == 16);
+  COMPILE_TIME_ASSERT(sizeof(grub_packed_guid_t) == 16);
+  COMPILE_TIME_ASSERT(sizeof(struct grub_gpt_partentry) == 128);
   grub_partition_map_register (&grub_gpt_partition_map);
 }
 
Signature · 1 line
2.39.2

From 580463c0194308149c5a92cd28dde0a6f40bd850 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:18:23 +0200
Subject: [PATCH 3/5] Split aligned and packed guids

---
 grub-core/commands/efi/lsefi.c    |  2 +-
 grub-core/efiemu/runtime/efiemu.c | 14 +++++++-------
 grub-core/kern/efi/efi.c          |  2 +-
 grub-core/kern/misc.c             |  2 +-
 grub-core/loader/i386/xnu.c       |  2 +-
 include/grub/efi/api.h            | 12 ++++++------
 include/grub/efiemu/efiemu.h      |  4 ++--
 include/grub/efiemu/runtime.h     |  2 +-
 include/grub/types.h              | 11 ++++++++++-
 9 files changed, 30 insertions(+), 21 deletions(-)
grub-core/commands/efi/lsefi.c +1 -1
index 95cba5baf..7b8316d41 100644
@@ -96,7 +96,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
       grub_efi_handle_t handle = handles[i];
       grub_efi_status_t status;
       grub_efi_uintn_t num_protocols;
-      grub_guid_t **protocols;
+      grub_packed_guid_t **protocols;
       grub_efi_device_path_t *dp;
 
       grub_printf ("Handle %p\n", handle);
grub-core/efiemu/runtime/efiemu.c +7 -7
index c84b30652..b98c0f2b0 100644
@@ -66,7 +66,7 @@ efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,
 
 grub_efi_status_t __grub_efi_api
 efiemu_get_variable (grub_efi_char16_t *variable_name,
-		     const grub_guid_t *vendor_guid,
+		     const grub_packed_guid_t *vendor_guid,
 		     grub_efi_uint32_t *attributes,
 		     grub_efi_uintn_t *data_size,
 		     void *data);
@@ -74,11 +74,11 @@ efiemu_get_variable (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api
 efiemu_get_next_variable_name (grub_efi_uintn_t *variable_name_size,
 			       grub_efi_char16_t *variable_name,
-			       grub_guid_t *vendor_guid);
+			       grub_packed_guid_t *vendor_guid);
 
 grub_efi_status_t __grub_efi_api
 efiemu_set_variable (grub_efi_char16_t *variable_name,
-		     const grub_guid_t *vendor_guid,
+		     const grub_packed_guid_t *vendor_guid,
 		     grub_efi_uint32_t attributes,
 		     grub_efi_uintn_t data_size,
 		     void *data);
@@ -416,7 +416,7 @@ EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
 
 /* Find variable by name and GUID. */
 static struct efi_variable *
-find_variable (const grub_guid_t *vendor_guid,
+find_variable (const grub_packed_guid_t *vendor_guid,
 	       grub_efi_char16_t *variable_name)
 {
   grub_uint8_t *ptr;
@@ -438,7 +438,7 @@ find_variable (const grub_guid_t *vendor_guid,
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
-				const grub_guid_t *vendor_guid,
+				const grub_packed_guid_t *vendor_guid,
 				grub_efi_uint32_t *attributes,
 				grub_efi_uintn_t *data_size,
 				void *data)
@@ -464,7 +464,7 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api EFI_FUNC
 (efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
 				 grub_efi_char16_t *variable_name,
-				 grub_guid_t *vendor_guid)
+				 grub_packed_guid_t *vendor_guid)
 {
   struct efi_variable *efivar;
   LOG ('l');
@@ -503,7 +503,7 @@ grub_efi_status_t __grub_efi_api EFI_FUNC
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
-				const grub_guid_t *vendor_guid,
+				const grub_packed_guid_t *vendor_guid,
 				grub_efi_uint32_t attributes,
 				grub_efi_uintn_t data_size,
 				void *data)
grub-core/kern/efi/efi.c +1 -1
index 9bf4f571c..20728af6b 100644
@@ -1039,7 +1039,7 @@ grub_efi_find_configuration_table(const grub_guid_t *target_guid)
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_guid_t *guid =
+      grub_packed_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
       if (! grub_memcmp (guid, target_guid, sizeof (grub_guid_t)))
grub-core/kern/misc.c +1 -1
index 2890aad49..499d7b981 100644
@@ -1068,7 +1068,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
 	  if (*(fmt) == 'G')
 	    {
 	      ++fmt;
-	      grub_guid_t *guid = (grub_guid_t *)(grub_addr_t) curarg;
+	      grub_packed_guid_t *guid = (grub_packed_guid_t *)(grub_addr_t) curarg;
 	      write_number (str, &count, max_len, 8, 0, '0', 'x', guid->data1);
 	      write_char (str, &count, max_len, '-');
 	      write_number (str, &count, max_len, 4, 0, '0', 'x', guid->data2);
grub-core/loader/i386/xnu.c +1 -1
index 4e31ce99a..b91e2f840 100644
@@ -694,7 +694,7 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)
     {
       void *ptr;
       struct grub_xnu_devtree_key *curkey;
-      grub_guid_t guid;
+      grub_packed_guid_t guid;
       char guidbuf[64];
 
       /* Retrieve current key. */
include/grub/efi/api.h +6 -6
index d3eaef3fb..d44d00ad7 100644
@@ -730,7 +730,7 @@ typedef struct grub_efi_memory_mapped_device_path grub_efi_memory_mapped_device_
 struct grub_efi_vendor_device_path
 {
   grub_efi_device_path_t header;
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   grub_efi_uint8_t vendor_defined_data[0];
 } GRUB_PACKED;
 typedef struct grub_efi_vendor_device_path grub_efi_vendor_device_path_t;
@@ -974,7 +974,7 @@ typedef struct grub_efi_cdrom_device_path grub_efi_cdrom_device_path_t;
 struct grub_efi_vendor_media_device_path
 {
   grub_efi_device_path_t header;
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   grub_efi_uint8_t vendor_defined_data[0];
 } GRUB_PACKED;
 typedef struct grub_efi_vendor_media_device_path grub_efi_vendor_media_device_path_t;
@@ -993,7 +993,7 @@ typedef struct grub_efi_file_path_device_path grub_efi_file_path_device_path_t;
 struct grub_efi_protocol_device_path
 {
   grub_efi_device_path_t header;
-  grub_guid_t guid;
+  grub_packed_guid_t guid;
 } GRUB_PACKED;
 typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
 
@@ -1002,7 +1002,7 @@ typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
 struct grub_efi_piwg_device_path
 {
   grub_efi_device_path_t header;
-  grub_guid_t guid;
+  grub_packed_guid_t guid;
 } GRUB_PACKED;
 typedef struct grub_efi_piwg_device_path grub_efi_piwg_device_path_t;
 
@@ -1287,7 +1287,7 @@ struct grub_efi_boot_services
 
   grub_efi_status_t
   (__grub_efi_api *protocols_per_handle) (grub_efi_handle_t handle,
-					  grub_guid_t ***protocol_buffer,
+					  grub_packed_guid_t ***protocol_buffer,
 					  grub_efi_uintn_t *protocol_buffer_count);
 
   grub_efi_status_t
@@ -1386,7 +1386,7 @@ typedef struct grub_efi_runtime_services grub_efi_runtime_services_t;
 
 struct grub_efi_configuration_table
 {
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   void *vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
include/grub/efiemu/efiemu.h +2 -2
index caf0b505f..d6a868e94 100644
@@ -183,13 +183,13 @@ struct grub_efiemu_configuration_table
 };
 struct grub_efiemu_configuration_table32
 {
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   grub_efi_uint32_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t;
 struct grub_efiemu_configuration_table64
 {
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   grub_efi_uint64_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t;
include/grub/efiemu/runtime.h +1 -1
index c9ad9fdfa..2ff429845 100644
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
 
 struct efi_variable
 {
-  grub_guid_t guid;
+  grub_packed_guid_t guid;
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
include/grub/types.h +10 -1
index 0d96006fe..4028c32bf 100644
@@ -376,7 +376,16 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;
 
+struct grub_packed_guid
+{
+  grub_uint32_t data1;
+  grub_uint16_t data2;
+  grub_uint16_t data3;
+  grub_uint8_t data4[8];
+} __attribute__ ((packed));
+typedef struct grub_packed_guid grub_packed_guid_t;
+
 #endif /* ! GRUB_TYPES_HEADER */
Signature · 1 line
2.39.2

From cfa21b94ee00035fbff713ea7787fcdc85e21bef Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:19:02 +0200
Subject: [PATCH 5/5] Fix typo

---
 include/grub/types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/types.h +1 -1
index 4028c32bf..c31c707e3 100644
@@ -349,7 +349,7 @@ static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
 /*
  * The grub_absolute_pointer() macro borrows the idea from Linux kernel of using
  * RELOC_HIDE() macro to stop GCC from checking the result of pointer arithmetic
- * and also it's conversion to be inside the symbol's boundary [1]. The check
+ * and also its conversion to be inside the symbol's boundary [1]. The check
  * is sometimes false positive, especially it is controversial to emit the array
  * bounds [-Warray-bounds] warning on all hardwired literal pointers since GCC
  * 11/12 [2]. Unless a good solution can be settled, for the time being we
Signature · 1 line
2.39.2

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#10 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Hi Vladimir.

Thanks for the analysis and for providing the candidate patches. I'll be away from my computer for a couple of days but will give it a try as soon as I can find a sliver of time.

Pedro

On Aug 13, 2023, at 08:47, Vladimir 'phcoder' Serbinenko <[email protected]> wrote:


Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20 bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan. All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Le dim. 13 août 2023, 05:27, Vladimir 'phcoder' Serbinenko <[email protected]<mailto:[email protected]>> a écrit :

Quoted 52 lines · Le dim. 13 août 2023, 00:57, Pedro Miguel Justo…

On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <[email protected]<mailto:[email protected]>> wrote:

Hi Daniel!

Quoted 47 lines · Daniel Kiper
Quoted 12 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 11 lines

Hi Oliver!

Quoted 8 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

[...]

Quoted 19 lines
Quoted 11 lines

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed the fact that in my "solution" the alignments are not correct in all cases.

The quickest way out could be to revert the GUID unification and printf format specifier commits:

Quoted 8 lines

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

I am open to suggestions / comments.

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Quoted 7 lines
Quoted 4 lines

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always enforced alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

My Itanium hardware is not available for bootloader tests at the moment, so I would like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```
diff --git a/include/grub/types.h b/include/grub/types.h
index 0d96006fe..ff415c970 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;

 #endif /* ! GRUB_TYPES_HEADER */
```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
   70 | } GRUB_PACKED;
      | ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

Quoted 9 lines

Thanks,
Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
. ' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

<0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch> <0001-Add-missing-static-qualifier.patch> <0004-Add-compile-time-asserts-for-guid-and-gpt_partentry-.patch> <0003-Split-aligned-and-packed-guids.patch> <0005-Fix-typo.patch>

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#11 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Hi Vladimir.

I got a conplict while applying 0003. Out of expedience, instead of me trying to resolve the conflict, can you just share your baseline commit# over which these will apply cleanly?

```
pmsjt@itanium:~/grub$ patch -p1 < ../0001-Add-missing-static-qualifier.patch
patching file grub-core/commands/efi/lsefi.c
pmsjt@itanium:~/grub$ patch -p1 < ../0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch
patching file include/grub/gpt_partition.h
Hunk #1 succeeded at 67 (offset -7 lines).
pmsjt@itanium:~/grub$ patch -p1 < ../0003-Split-aligned-and-packed-guids.patch
patching file grub-core/commands/efi/lsefi.c
patching file grub-core/efiemu/runtime/efiemu.c
patching file grub-core/kern/efi/efi.c
Hunk #1 FAILED at 1039.
1 out of 1 hunk FAILED -- saving rejects to file grub-core/kern/efi/efi.c.rej
patching file grub-core/kern/misc.c
patching file grub-core/loader/i386/xnu.c
patching file include/grub/efi/api.h
patching file include/grub/efiemu/efiemu.h
patching file include/grub/efiemu/runtime.h
patching file include/grub/types.h
```

On Aug 14, 2023, at 03:26, Pedro Miguel Justo <[email protected]> wrote:

Hi Vladimir.

Thanks for the analysis and for providing the candidate patches. I'll be away from my computer for a couple of days but will give it a try as soon as I can find a sliver of time.

Pedro

On Aug 13, 2023, at 08:47, Vladimir 'phcoder' Serbinenko <[email protected]> wrote:


Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20 bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan. All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Le dim. 13 août 2023, 05:27, Vladimir 'phcoder' Serbinenko <[email protected]<mailto:[email protected]>> a écrit :

Quoted 52 lines · Le dim. 13 août 2023, 00:57, Pedro Miguel Justo…

On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <[email protected]<mailto:[email protected]>> wrote:

Hi Daniel!

Quoted 47 lines · Daniel Kiper
Quoted 12 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 11 lines

Hi Oliver!

Quoted 8 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

[...]

Quoted 19 lines
Quoted 11 lines

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed the fact that in my "solution" the alignments are not correct in all cases.

The quickest way out could be to revert the GUID unification and printf format specifier commits:

Quoted 8 lines

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

I am open to suggestions / comments.

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Quoted 7 lines
Quoted 4 lines

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always enforced alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

My Itanium hardware is not available for bootloader tests at the moment, so I would like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```
diff --git a/include/grub/types.h b/include/grub/types.h
index 0d96006fe..ff415c970 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;

 #endif /* ! GRUB_TYPES_HEADER */
```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
   70 | } GRUB_PACKED;
      | ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

Quoted 9 lines

Thanks,
Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
. ' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

<0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch> <0001-Add-missing-static-qualifier.patch> <0004-Add-compile-time-asserts-for-guid-and-gpt_partentry-.patch> <0003-Split-aligned-and-packed-guids.patch> <0005-Fix-typo.patch>

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#12 lore raw

Re: [PATCH v9 02/11] Unify GUID types

I uploaded the entire branch (patches) to my GitHub copy:
https://github.com/phcoder/GRUB/tree/rb1

Quoted 208 lines · Pedro Miguel Justo

Hi Vladimir.

I got a conplict while applying 0003. Out of expedience, instead of me trying to resolve the conflict, can you just share your baseline commit# over which these will apply cleanly?

```
pmsjt@itanium:~/grub$ patch -p1 <
../0001-Add-missing-static-qualifier.patch
patching file grub-core/commands/efi/lsefi.c
pmsjt@itanium:~/grub$ patch -p1 <
../0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch
patching file include/grub/gpt_partition.h
Hunk #1 succeeded at 67 (offset -7 lines).
pmsjt@itanium:~/grub$ patch -p1 <
../0003-Split-aligned-and-packed-guids.patch
patching file grub-core/commands/efi/lsefi.c
patching file grub-core/efiemu/runtime/efiemu.c
patching file grub-core/kern/efi/efi.c
Hunk #1 FAILED at 1039.
1 out of 1 hunk FAILED -- saving rejects to file
grub-core/kern/efi/efi.c.rej
patching file grub-core/kern/misc.c
patching file grub-core/loader/i386/xnu.c
patching file include/grub/efi/api.h
patching file include/grub/efiemu/efiemu.h
patching file include/grub/efiemu/runtime.h
patching file include/grub/types.h
```

On Aug 14, 2023, at 03:26, Pedro Miguel Justo <[email protected]> wrote:

Hi Vladimir.

Thanks for the analysis and for providing the candidate patches. I'll be away from my computer for a couple of days but will give it a try as soon as I can find a sliver of time.

Pedro

On Aug 13, 2023, at 08:47, Vladimir 'phcoder' Serbinenko < [email protected]> wrote:


Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20 bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan.
All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Quoted 145 lines · Vladimir 'phcoder' Serbinenko

Le dim. 13 août 2023, 00:57, Pedro Miguel Justo <[email protected]> a écrit :

Quoted 100 lines
Quoted 3 lines

On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <

Quoted 13 lines · [email protected]> wrote:

Hi Daniel!

Quoted 9 lines · Daniel Kiper
Quoted 8 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 7 lines

Hi Oliver!

Quoted 4 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment

attribute

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

is dropped, since it is not required.

[...]

Quoted 2 lines
Quoted 2 lines

According to [1], this change broke GRUB on ia64:

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on

ia64.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

fact that in my "solution" the alignments are not correct in all

cases.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The quickest way out could be to revert the GUID unification and

printf

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

format specifier commits:

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

I am open to suggestions / comments.

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always

enforced

Quoted 4 lines
Quoted 2 lines

alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

My Itanium hardware is not available for bootloader tests at the

moment, so I would

Quoted 1 line

like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed

fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```

include/grub/types.h +1 -1
index 0d96006fe..ff415c970 100644
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;
 
 #endif /* ! GRUB_TYPES_HEADER */

```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

Quoted 6 lines

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

Quoted 25 lines
```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct
grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
   70 | } GRUB_PACKED;
      | ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct
grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

Quoted 9 lines

Thanks,
Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
. ' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

Quoted 8 lines
Quoted 1 line
Quoted 1 line

<0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch>

<0001-Add-missing-static-qualifier.patch> <0004-Add-compile-time-asserts-for-guid-and-gpt_partentry-.patch> <0003-Split-aligned-and-packed-guids.patch> <0005-Fix-typo.patch>

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#13 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Perfect! Thank you.

On Aug 14, 2023, at 12:56, Vladimir 'phcoder' Serbinenko <[email protected]> wrote:


I uploaded the entire branch (patches) to my GitHub copy: https://github.com/phcoder/GRUB/tree/rb1

Le lun. 14 août 2023, 13:07, Pedro Miguel Justo <[email protected]<mailto:[email protected]>> a écrit :

Hi Vladimir.

I got a conplict while applying 0003. Out of expedience, instead of me trying to resolve the conflict, can you just share your baseline commit# over which these will apply cleanly?

```
pmsjt@itanium:~/grub$ patch -p1 < ../0001-Add-missing-static-qualifier.patch
patching file grub-core/commands/efi/lsefi.c
pmsjt@itanium:~/grub$ patch -p1 < ../0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch
patching file include/grub/gpt_partition.h
Hunk #1 succeeded at 67 (offset -7 lines).
pmsjt@itanium:~/grub$ patch -p1 < ../0003-Split-aligned-and-packed-guids.patch
patching file grub-core/commands/efi/lsefi.c
patching file grub-core/efiemu/runtime/efiemu.c
patching file grub-core/kern/efi/efi.c
Hunk #1 FAILED at 1039.
1 out of 1 hunk FAILED -- saving rejects to file grub-core/kern/efi/efi.c.rej
patching file grub-core/kern/misc.c
patching file grub-core/loader/i386/xnu.c
patching file include/grub/efi/api.h
patching file include/grub/efiemu/efiemu.h
patching file include/grub/efiemu/runtime.h
patching file include/grub/types.h
```

On Aug 14, 2023, at 03:26, Pedro Miguel Justo <[email protected]<mailto:[email protected]>> wrote:

Hi Vladimir.

Thanks for the analysis and for providing the candidate patches. I'll be away from my computer for a couple of days but will give it a try as soon as I can find a sliver of time.

Pedro

On Aug 13, 2023, at 08:47, Vladimir 'phcoder' Serbinenko <[email protected]<mailto:[email protected]>> wrote:


Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20 bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan. All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Le dim. 13 août 2023, 05:27, Vladimir 'phcoder' Serbinenko <[email protected]<mailto:[email protected]>> a écrit :

Quoted 52 lines · Le dim. 13 août 2023, 00:57, Pedro Miguel Justo…

On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <[email protected]<mailto:[email protected]>> wrote:

Hi Daniel!

Quoted 47 lines · Daniel Kiper
Quoted 12 lines · Oliver Steffen

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 11 lines

Hi Oliver!

Quoted 8 lines · Oliver Steffen

There are 3 implementations of a GUID in Grub. Replace them with a common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the alignment attribute is dropped, since it is not required.

[...]

Quoted 19 lines
Quoted 11 lines

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap
7 0 0x000066 0x000000000000001E trap taken, number in ext PE 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE

I assume this is because of the strict alignment requirements on ia64.

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub but I missed the fact that in my "solution" the alignments are not correct in all cases.

The quickest way out could be to revert the GUID unification and printf format specifier commits:

Quoted 8 lines

6ad116e5f guid: Make use of GUID printf format specifier f82dbf2bd kern/misc: Add a format specifier GUIDs 06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for printing the GUID in the bli module instead (added in the commits following those).

I am open to suggestions / comments.

Adrian, could you check what will happen when you add alignment to the grub_guid_t as it was suggested by Frank here [2]?

Quoted 7 lines
Quoted 4 lines

Personally I would avoid adding another GUID type with just alignment requirement as the difference. Making one GUID type with always enforced alignment should not cost us a lot. Or we can enforce alignment on EFI platforms only.

My Itanium hardware is not available for bootloader tests at the moment, so I would like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```
diff --git a/include/grub/types.h b/include/grub/types.h
index 0d96006fe..ff415c970 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;

 #endif /* ! GRUB_TYPES_HEADER */
```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
   70 | } GRUB_PACKED;
      | ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]
```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

Quoted 9 lines

Thanks,
Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
. ' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

<0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch> <0001-Add-missing-static-qualifier.patch> <0004-Add-compile-time-asserts-for-guid-and-gpt_partentry-.patch> <0003-Split-aligned-and-packed-guids.patch> <0005-Fix-typo.patch>

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#14 lore raw

Re: [PATCH v9 02/11] Unify GUID types

In reply to Vladimir 'phcoder' Serbinenko

Quoting Vladimir 'phcoder' Serbinenko (2023-08-14 13:56:31)

Quoted 2 lines

I uploaded the entire branch (patches) to my GitHub copy: [1]https://github.com /phcoder/GRUB/tree/rb1

87532c5b Deduplicate configuration table search function is the reason for the rejection.

Thanks, Vladimir!

-Oliver

Quoted 246 lines

Le lun. 14 août 2023, 13:07, Pedro Miguel Justo <[2][email protected]> a écrit :

Hi Vladimir.

I got a conplict while applying 0003. Out of expedience, instead of me trying to resolve the conflict, can you just share your baseline commit# over which these will apply cleanly?

```
pmsjt@itanium:~/grub$ patch -p1 < ../ 0001-Add-missing-static-qualifier.patch
patching file grub-core/commands/efi/lsefi.c pmsjt@itanium:~/grub$ patch -p1 < ../ 0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch patching file include/grub/gpt_partition.h
Hunk #1 succeeded at 67 (offset -7 lines). pmsjt@itanium:~/grub$ patch -p1 < ../ 0003-Split-aligned-and-packed-guids.patch
patching file grub-core/commands/efi/lsefi.c
patching file grub-core/efiemu/runtime/efiemu.c
patching file grub-core/kern/efi/efi.c
Hunk #1 FAILED at 1039.
1 out of 1 hunk FAILED -- saving rejects to file grub-core/kern/efi/ efi.c.rej
patching file grub-core/kern/misc.c
patching file grub-core/loader/i386/xnu.c
patching file include/grub/efi/api.h
patching file include/grub/efiemu/efiemu.h
patching file include/grub/efiemu/runtime.h
patching file include/grub/types.h
```

On Aug 14, 2023, at 03:26, Pedro Miguel Justo <[3][email protected]> wrote:

Hi Vladimir.

Thanks for the analysis and for providing the candidate patches. I'll be away from my computer for a couple of days but will give it a try as soon as I can find a sliver of time.

Pedro

On Aug 13, 2023, at 08:47, Vladimir 'phcoder' Serbinenko <[4] [email protected]> wrote:

Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20 bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan. All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Le dim. 13 août 2023, 05:27, Vladimir 'phcoder' Serbinenko <[5] [email protected]> a écrit :

Le dim. 13 août 2023, 00:57, Pedro Miguel Justo <[6] [email protected]> a écrit :

> On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <[7] [email protected]> wrote:
>
> Hi Daniel!
>
> On Fri, 2023-08-11 at 17:31 +0200, Daniel Kiper wrote:
>> On Fri, Aug 11, 2023 at 04:10:14AM -0700, Oliver Steffen wrote:
>>> Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17) >>>> Hi Oliver!
>>>>
>>>> On Fri, 2023-05-26 at 13:35 +0200, Oliver Steffen wrote:
>>>>> There are 3 implementations of a GUID in Grub. Replace them with a
>>>>> common one, placed in types.h.
>>>>>
>>>>> It uses the "packed" flavor of the GUID structs, the alignment attribute
>>>>> is dropped, since it is not required. >>>>>
>>>>> Signed-off-by: Oliver Steffen <[8][email protected] >
>>>>> Reviewed-by: Daniel Kiper <[9][email protected] >
>>
>> [...]
>>
>>>> According to [1], this change broke GRUB on ia64:
>>>>
>>>> Welcome to GRUB!
>>>>
>>>> 7 0 0x00006B 0x000000000000001E unexpected trap >>>> 7 0 0x000066 0x000000000000001E trap taken, number in ext PE
>>>> 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE
>>>>
>>>> I assume this is because of the strict alignment requirements on ia64.
>>>>
>>>> Could you have a look?
>>>
>>> I am very sorry for this mistake.
>>> My goal was to unify the two GUID types we had in grub but I missed the
>>> fact that in my "solution" the alignments are not correct in all cases.
>>>
>>> The quickest way out could be to revert the GUID unification and printf
>>> format specifier commits:
>>>
>>> 6ad116e5f guid: Make use of GUID printf format specifier
>>> f82dbf2bd kern/misc: Add a format specifier GUIDs >>> 06edd40db guid: Unify GUID types
>>>
>>> And use the explicit, long-winded format string for printing the GUID
>>> in the bli module instead (added in the commits following those).
>>>
>>> I am open to suggestions / comments.
>>
>> Adrian, could you check what will happen when you add alignment to the
>> grub_guid_t as it was suggested by Frank here [2]? >>
>> Personally I would avoid adding another GUID type with just alignment
>> requirement as the difference. Making one GUID type with always enforced
>> alignment should not cost us a lot. Or we can enforce alignment on EFI
>> platforms only.
>
> My Itanium hardware is not available for bootloader tests at the moment, so I would
> like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```
diff --git a/include/grub/types.h b/include/grub/types.h index 0d96006fe..ff415c970 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -376,7 +376,7 @@ struct grub_guid grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;

 #endif /* ! GRUB_TYPES_HEADER */ ```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror= packed-not-aligned]
   70 | } GRUB_PACKED;
      | ^ ./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror= packed-not-aligned]
```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

>
> Thanks,
> Adrian
>
> --
> .''`.  John Paul Adrian Glaubitz
> : :' :  Debian Developer
> . '   Physicist
>  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

<0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch> <0001-Add-missing-static-qualifier.patch> <0004-Add-compile-time-asserts-for-guid-and-gpt_partentry-.patch> <0003-Split-aligned-and-packed-guids.patch> <0005-Fix-typo.patch>

References:

Quoted 9 lines

[1] https://github.com/phcoder/GRUB/tree/rb1
[2] mailto:[email protected]
[3] mailto:[email protected]
[4] mailto:[email protected]
[5] mailto:[email protected]
[6] mailto:[email protected]
[7] mailto:[email protected]
[8] mailto:[email protected]
[9] mailto:[email protected]

--
🎩Oliver Steffen (he/him) - Software Engineer, Virtualization Red Hat GmbH <https://www.redhat.com/de/global/dach>,
Registered seat: Werner-von-Siemens-Ring 12, D-85630 Grasbrunn, Germany Commercial register: Amtsgericht München/Munich, HRB 153243, Managing Directors: Ryan Barnhart, Charles Cachera, Michael O'Neill, Amy Ross

Everyone has different working hours… Please do not feel obligated to reply outside of your normal work schedule.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#15 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 7 lines · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-14 13:56:31)

Quoted 2 lines

I uploaded the entire branch (patches) to my GitHub copy: [1]https://github.com /phcoder/GRUB/tree/rb1

Hi Vladimir.

When I try to build from your branch, I eventually get this error:

```
done
mv syminfo.lst.new syminfo.lst
cat syminfo.lst | sort | mawk -f ./genmoddep.awk > moddep.lst || (rm -f moddep.lst; exit 1)
mawk: ./genmoddep.awk: line 106: function asorti never defined
make[3]: *** [Makefile:51272: moddep.lst] Error 1
make[3]: Leaving directory '/home/pmsjt/grub_github/grub-core'
make[2]: *** [Makefile:28852: all] Error 2
make[2]: Leaving directory '/home/pmsjt/grub_github/grub-core'
make[1]: *** [Makefile:12126: all-recursive] Error 1
make[1]: Leaving directory '/home/pmsjt/grub_github'
make: *** [Makefile:3953: all] Error 2
```

Is this something you know about?

Quoted 272 lines

87532c5b Deduplicate configuration table search function is the reason for the rejection.

Thanks, Vladimir!

-Oliver

Quoted 246 lines · Pedro Miguel Justo

Hi Vladimir.

I got a conplict while applying 0003. Out of expedience, instead of me trying to resolve the conflict, can you just share your baseline commit# over which these will apply cleanly?

   ```
   pmsjt@itanium:~/grub$ patch -p1 < ../
   0001-Add-missing-static-qualifier.patch
   patching file grub-core/commands/efi/lsefi.c
   pmsjt@itanium:~/grub$ patch -p1 < ../
   0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch
   patching file include/grub/gpt_partition.h
   Hunk #1 succeeded at 67 (offset -7 lines).
   pmsjt@itanium:~/grub$ patch -p1 < ../
   0003-Split-aligned-and-packed-guids.patch
   patching file grub-core/commands/efi/lsefi.c
   patching file grub-core/efiemu/runtime/efiemu.c
   patching file grub-core/kern/efi/efi.c
   Hunk #1 FAILED at 1039.
   1 out of 1 hunk FAILED -- saving rejects to file grub-core/kern/efi/
   efi.c.rej
   patching file grub-core/kern/misc.c
   patching file grub-core/loader/i386/xnu.c
   patching file include/grub/efi/api.h
   patching file include/grub/efiemu/efiemu.h
   patching file include/grub/efiemu/runtime.h
   patching file include/grub/types.h
   ```

On Aug 14, 2023, at 03:26, Pedro Miguel Justo <[3][email protected]> wrote:

Hi Vladimir.

Thanks for the analysis and for providing the candidate patches. I'll be away from my computer for a couple of days but will give it a try as soon as I can find a sliver of time.

Pedro

On Aug 13, 2023, at 08:47, Vladimir 'phcoder' Serbinenko <[4] [email protected]> wrote:

Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20 bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan. All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Le dim. 13 août 2023, 05:27, Vladimir 'phcoder' Serbinenko <[5] [email protected]> a écrit :

Quoted 1 line · Pedro Miguel Justo

On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <[7]

Quoted 5 lines · [email protected]> wrote:

Hi Daniel!

Quoted 1 line · Daniel Kiper

On Fri, Aug 11, 2023 at 04:10:14AM -0700, Oliver Steffen

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines

Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17)

Quoted 3 lines

Hi Oliver!

On Fri, 2023-05-26 at 13:35 +0200, Oliver Steffen

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

There are 3 implementations of a GUID in Grub.

Replace them with a

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

common one, placed in types.h.

It uses the "packed" flavor of the GUID structs, the

alignment attribute

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

is dropped, since it is not required.

Quoted 8 lines
Quoted 8 lines

[...]

Quoted 6 lines
Quoted 6 lines

According to [1], this change broke GRUB on ia64:

Welcome to GRUB!

7 0 0x00006B 0x000000000000001E unexpected trap 7 0 0x000066 0x000000000000001E trap taken, number in

ext PE

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

7 0 0x00003C 0x0000000000005A00 trap taken, offset in

ext PE

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I assume this is because of the strict alignment

requirements on ia64.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Could you have a look?

I am very sorry for this mistake.
My goal was to unify the two GUID types we had in grub

but I missed the

Quoted 1 line
Quoted 1 line
Quoted 1 line

fact that in my "solution" the alignments are not

correct in all cases.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The quickest way out could be to revert the GUID

unification and printf

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

format specifier commits:

6ad116e5f guid: Make use of GUID printf format

specifier

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

f82dbf2bd kern/misc: Add a format specifier GUIDs
06edd40db guid: Unify GUID types

And use the explicit, long-winded format string for

printing the GUID

Quoted 1 line
Quoted 1 line
Quoted 1 line

in the bli module instead (added in the commits

following those).

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

I am open to suggestions / comments.

Adrian, could you check what will happen when you add

alignment to the

Quoted 3 lines
Quoted 3 lines

grub_guid_t as it was suggested by Frank here [2]?

Personally I would avoid adding another GUID type with

just alignment

Quoted 1 line
Quoted 1 line

requirement as the difference. Making one GUID type with

always enforced

Quoted 1 line
Quoted 1 line

alignment should not cost us a lot. Or we can enforce

alignment on EFI

Quoted 3 lines
Quoted 1 line

platforms only.

My Itanium hardware is not available for bootloader tests

at the moment, so I would

Quoted 1 line

like to ask Pedro Miguel Justo or Frank Scheiner to test

the proposed fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```
diff --git a/include/grub/types.h b/include/grub/types.h index 0d96006fe..ff415c970 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -376,7 +376,7 @@ struct grub_guid
grub_uint16_t data2;
grub_uint16_t data3;
grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
typedef struct grub_guid grub_guid_t;

#endif /* ! GRUB_TYPES_HEADER */
```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror= packed-not-aligned]
70 | } GRUB_PACKED;
| ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror= packed-not-aligned]
```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

Quoted 9 lines

Thanks,
Adrian

--
.''`. John Paul Adrian Glaubitz

: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5
                   F913


           <0002-Mark-grub_gpt_partentry-as-aligned-to-8-bytes.patch>
           <0001-Add-missing-static-qualifier.patch>
           <0004-Add-compile-time-asserts-for-guid-and-gpt_partentry-.patch>
           <0003-Split-aligned-and-packed-guids.patch>
           <0005-Fix-typo.patch>

References:

Quoted 9 lines

[1] https://github.com/phcoder/GRUB/tree/rb1
[2] mailto:[email protected]
[3] mailto:[email protected]
[4] mailto:[email protected]
[5] mailto:[email protected]
[6] mailto:[email protected]
[7] mailto:[email protected]
[8] mailto:[email protected]
[9] mailto:[email protected]

--
🎩Oliver Steffen (he/him) - Software Engineer, Virtualization Red Hat GmbH <https://www.redhat.com/de/global/dach>,
Registered seat: Werner-von-Siemens-Ring 12, D-85630 Grasbrunn, Germany Commercial register: Amtsgericht München/Munich, HRB 153243, Managing Directors: Ryan Barnhart, Charles Cachera, Michael O'Neill, Amy Ross

Quoted 3 lines

Everyone has different working hours… Please do not feel obligated to reply outside of your normal work schedule.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#16 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Hi Pedro!

Quoted 16 lines · Pedro Miguel Justo

en I try to build from your branch, I eventually get this error:

```
done
mv syminfo.lst.new syminfo.lst
cat syminfo.lst | sort | mawk -f ./genmoddep.awk > moddep.lst || (rm -f moddep.lst; exit 1)
mawk: ./genmoddep.awk: line 106: function asorti never defined
make[3]: *** [Makefile:51272: moddep.lst] Error 1
make[3]: Leaving directory '/home/pmsjt/grub_github/grub-core'
make[2]: *** [Makefile:28852: all] Error 2
make[2]: Leaving directory '/home/pmsjt/grub_github/grub-core'
make[1]: *** [Makefile:12126: all-recursive] Error 1
make[1]: Leaving directory '/home/pmsjt/grub_github'
make: *** [Makefile:3953: all] Error 2
```
Quoted 1 line

Is this something you know about?

This is a known generic problem with GRUB. You must install gawk instead of mawk.

Adrian

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#17 lore raw

Re: [PATCH v9 02/11] Unify GUID types

In reply to Vladimir 'phcoder' Serbinenko

Hi Vladimir!

Quoted 1 line · Vladimir 'phcoder' Serbinenko

I uploaded the entire branch (patches) to my GitHub copy: https://github.com/phcoder/GRUB/tree/rb1

Any chance this could be reworked and merged before the 2.12 release?

Adrian

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#18 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Yes, sorry for delay. My laptop is bricked now. I got parts for external reflashing and will attempt to recover it today

Quoted 16 lines · John Paul Adrian Glaubitz

Hi Vladimir!

Quoted 1 line · Vladimir 'phcoder' Serbinenko

I uploaded the entire branch (patches) to my GitHub copy:

https://github.com/phcoder/GRUB/tree/rb1

Any chance this could be reworked and merged before the 2.12 release?

Adrian

--

 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#19 lore raw

Re: [PATCH v9 02/11] Unify GUID types

In reply to Vladimir 'phcoder' Serbinenko

Quoting Vladimir 'phcoder' Serbinenko (2023-08-13 09:46:45)

Quoted 4 lines

Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20

Quoted 8 lines

bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan.
All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Looking at https://uefi.org/specs/UEFI/2.10/02_Overview.html#data-types,
the problem is the alignment, not the packing.

As far as EFI is concerned, GUIDs are always 128bit in size. This means there shall be no padding between the struct members. To be on the safe side one could add the "packed" attribute to the struct, but the original grub_efi_guid struct was not marked like that and it worked. Whenever we had over GUIDs to EFI, they have to be aligned to 64bit.

GPT GUIDs are also packed, but here we do not want the alignment restriction.

I am not convinced that we can get away with just one type for both cases. How about at least reducing from 3 to 2 GUID types, like:

struct grub_efi_guid
{
grub_uint32_t data1;
grub_uint16_t data2;
grub_uint16_t data3;
grub_uint8_t data4[8];
} GRUB_PACKED __attribute__ ((aligned(8)));

struct grub_guid
{
grub_uint32_t data1;
grub_uint16_t data2;
grub_uint16_t data3;
grub_uint8_t data4[8];
} GRUB_PACKED;

At least when converting from grub_guid to grub_efi_guid a copy would be required, but I think that is a rare case. A cast would work in the other direction (casting to a less strict alignment) so the %pG could still be used.

Does this make sense? Or am I missing something?

Thanks,
Oliver

Quoted 156 lines

Le dim. 13 août 2023, 05:27, Vladimir 'phcoder' Serbinenko <[1] [email protected]> a écrit :

Le dim. 13 août 2023, 00:57, Pedro Miguel Justo <[2][email protected]> a écrit :

> On Aug 12, 2023, at 11:04, John Paul Adrian Glaubitz <[3] [email protected]> wrote:
>
> Hi Daniel!
>
> On Fri, 2023-08-11 at 17:31 +0200, Daniel Kiper wrote:
>> On Fri, Aug 11, 2023 at 04:10:14AM -0700, Oliver Steffen wrote:
>>> Quoting John Paul Adrian Glaubitz (2023-08-11 10:32:17) >>>> Hi Oliver!
>>>>
>>>> On Fri, 2023-05-26 at 13:35 +0200, Oliver Steffen wrote:
>>>>> There are 3 implementations of a GUID in Grub. Replace them with a
>>>>> common one, placed in types.h.
>>>>>
>>>>> It uses the "packed" flavor of the GUID structs, the alignment attribute
>>>>> is dropped, since it is not required.
>>>>>
>>>>> Signed-off-by: Oliver Steffen <[4][email protected]> >>>>> Reviewed-by: Daniel Kiper <[5][email protected]> >>
>> [...]
>>
>>>> According to [1], this change broke GRUB on ia64:
>>>>
>>>> Welcome to GRUB!
>>>>
>>>> 7 0 0x00006B 0x000000000000001E unexpected trap
>>>> 7 0 0x000066 0x000000000000001E trap taken, number in ext PE >>>> 7 0 0x00003C 0x0000000000005A00 trap taken, offset in ext PE >>>>
>>>> I assume this is because of the strict alignment requirements on ia64.
>>>>
>>>> Could you have a look?
>>>
>>> I am very sorry for this mistake.
>>> My goal was to unify the two GUID types we had in grub but I missed the
>>> fact that in my "solution" the alignments are not correct in all cases.
>>>
>>> The quickest way out could be to revert the GUID unification and printf
>>> format specifier commits:
>>>
>>> 6ad116e5f guid: Make use of GUID printf format specifier >>> f82dbf2bd kern/misc: Add a format specifier GUIDs
>>> 06edd40db guid: Unify GUID types
>>>
>>> And use the explicit, long-winded format string for printing the GUID
>>> in the bli module instead (added in the commits following those). >>>
>>> I am open to suggestions / comments.
>>
>> Adrian, could you check what will happen when you add alignment to the
>> grub_guid_t as it was suggested by Frank here [2]?
>>
>> Personally I would avoid adding another GUID type with just alignment
>> requirement as the difference. Making one GUID type with always enforced
>> alignment should not cost us a lot. Or we can enforce alignment on EFI
>> platforms only.
>
> My Itanium hardware is not available for bootloader tests at the moment, so I would
> like to ask Pedro Miguel Justo or Frank Scheiner to test the proposed fix.

The reason that before this unification there were a packed and aligned types suggest that the packed type was necessary in some cases. Frank had shared the concern against his own suggestion that changing the unified type to be aligned (as opposite to packed) would likely regress the cases where the packed might be needed/expected.

Just for kicks, I gave it a try:

```
diff --git a/include/grub/types.h b/include/grub/types.h index 0d96006fe..ff415c970 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -376,7 +376,7 @@ struct grub_guid grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;

 #endif /* ! GRUB_TYPES_HEADER */
```

As hypothesized, there are places where these structs (now unified) are expected to be packed, meaning to have an alignment of 1 (even smaller than the natural alignment of its larger member).

One of the cases where the dependency is present is in the grub_gpt_partentry structure. This structure is packed and includes a GUID field. One struct of an enforced alignment ’n’ cannot host a member with enforced alignment ‘m’ where m > n. Thus, an 8 byte aligned grub_guid cannot be hosted inside a 1 byte aligned grub_gpt_partentry:

grub_gpt_partentry doesn't need

GRUB_PACKED. To be on a safe side we can

add compile time assert on its size

```
In file included from grub-core/disk/ldm.c:26:
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned] 70 | } GRUB_PACKED;
      | ^
./include/grub/gpt_partition.h:70:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned] ```

Now, we could go this rabbit hole on and try to hack grub_gpt_partentry, or special-case the GUID inside grub_gpt_partentry to be packed… but at which point will I just end up with the thing we were trying to avoid: more than one definition of GUID?

>
> Thanks,
> Adrian
>
> --
> .''`.  John Paul Adrian Glaubitz
> : :' :  Debian Developer
> . '   Physicist
>  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

Quoted 7 lines

References:

[1] mailto:[email protected]
[2] mailto:[email protected]
[3] mailto:[email protected]
[4] mailto:[email protected]
[5] mailto:[email protected]

--
🎩Oliver Steffen (he/him) - Software Engineer, Virtualization Red Hat GmbH <https://www.redhat.com/de/global/dach>,
Registered seat: Werner-von-Siemens-Ring 12, D-85630 Grasbrunn, Germany Commercial register: Amtsgericht München/Munich, HRB 153243, Managing Directors: Ryan Barnhart, Charles Cachera, Michael O'Neill, Amy Ross

Everyone has different working hours… Please do not feel obligated to reply outside of your normal work schedule.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#20 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Hi Steffen, Ard,

Quoted 14 lines · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-13 09:46:45)

Quoted 4 lines

Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20

Quoted 8 lines

bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan.
All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Quoted 8 lines

Looking at https://uefi.org/specs/UEFI/2.10/02_Overview.html#data-types,
the problem is the alignment, not the packing.

As far as EFI is concerned, GUIDs are always 128bit in size. This means there shall be no padding between the struct members. To be on the safe side one could add the "packed" attribute to the struct, but the original grub_efi_guid struct was not marked like that and it worked. Whenever we had over GUIDs to EFI, they have to be aligned to 64bit.

Ard thinks that a 64 bit alignment for EFI GUIDs is a mistake - see [1] and [2]. Hence Linux uses __aligned(__alignof__(u32)) for "efi_guid_t" since 2019.

[1]:
https://github.com/torvalds/linux/blob/master/include/linux/efi.h#L60-L78

[2]:
https://github.com/torvalds/linux/commit/494c704f9af0a0cddf593b381ea44320888733e6

I know I mentioned [1] earlier, but it sounds like it might have slipped through and it might be a good idea to have both GRUB and Linux in sync in this regard.

Cheers,
Frank

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#21 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 37 lines · Frank Scheiner

Hi Steffen, Ard,

Quoted 15 lines · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-13 09:46:45)

Quoted 4 lines

Full analysis: gpt_partentry can be marked as aligned8. But following are problem:
* protocols_per_handle may return unaligned guids
* configuration_tables array may be unaligned. On efi32 every entry is 20

Quoted 8 lines

bytes, so guids can't be 8-byte aligned
* The worst offender is device path as it's packed, unpredictable and contains uuids.
* Efiemu gets guid as argument and probably should be able to handle unaligned case. So far it's x86 only and we have no mmx and co so it's not a problem right now unless we enable ubsan.
All in all we do need packed guid type unless those are resolved. I attach patches for testing. If they work, I'll rearrange them a bit

Quoted 8 lines

Looking at https://uefi.org/specs/UEFI/2.10/02_Overview.html#data-types,
the problem is the alignment, not the packing.

As far as EFI is concerned, GUIDs are always 128bit in size. This means there shall be no padding between the struct members. To be on the safe side one could add the "packed" attribute to the struct, but the original grub_efi_guid struct was not marked like that and it worked. Whenever we had over GUIDs to EFI, they have to be aligned to 64bit.

Ard thinks that a 64 bit alignment for EFI GUIDs is a mistake - see [1] and [2]. Hence Linux uses __aligned(__alignof__(u32)) for "efi_guid_t" since 2019.

[1]:
https://github.com/torvalds/linux/blob/master/include/linux/efi.h#L60-L78

Quoted 7 lines

[2]:
https://github.com/torvalds/linux/commit/494c704f9af0a0cddf593b381ea44320888733e6

I know I mentioned [1] earlier, but it sounds like it might have slipped through and it might be a good idea to have both GRUB and Linux in sync in this regard.

So what is GRUB's current allocation granule, if it is not the same as Linux?

Quoted 2 lines

Cheers,
Frank

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#22 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoting Vladimir 'phcoder' Serbinenko (2023-08-14 13:56:31) I uploaded the entire branch (patches) to my GitHub copy:
[1]https://github.com<https://github.com/>/phcoder/GRUB/tree/rb1

Vladimir, I can confirm that, with the code presently in this branch, my Itanium system boots fine. The regression is resolved.

This statement is valid for Itanium aline. I have not tried any other architecture.

On Aug 14, 2023, at 07:36, John Paul Adrian Glaubitz <[email protected]> wrote:

Hi Pedro!

This is a known generic problem with GRUB. You must install gawk instead of mawk.

Thank you Adrian, that worked.

On Aug 14, 2023, at 21:38, Frank Scheiner <[email protected]> wrote:

Ard thinks that a 64 bit alignment for EFI GUIDs is a mistake - see [1] and [2]. Hence Linux uses __aligned(__alignof__(u32)) for "efi_guid_t" since 2019.

[1]:
https://github.com/torvalds/linux/blob/master/include/linux/efi.h#L60-L78

[2]:
https://github.com/torvalds/linux/commit/494c704f9af0a0cddf593b381ea44320888733e6

I know I mentioned [1] earlier, but it sounds like it might have slipped through and it might be a good idea to have both GRUB and Linux in sync in this regard.

So what is GRUB's current allocation granule, if it is not the same as Linux?

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#23 lore raw

Re: [PATCH v9 02/11] Unify GUID types

In reply to Frank Scheiner
Quoted 7 lines

.

Ard thinks that a 64 bit alignment for EFI GUIDs is a mistake - see [1] and [2]. Hence Linux uses __aligned(__alignof__(u32)) for "efi_guid_t" since 2019.

My patch presents a reliability paradigm: accept all inputs, produce outputs that are always aligned to 8-byte. It can make sense even though I agree that requiring 8-byte alignment for UUID is weird. Yet it's difficult to know if some obscure firmware does rely on it in some one in a thousand edge case

Quoted 6 lines

[1]:
https://github.com/torvalds/linux/blob/master/include/linux/efi.h#L60-L78

[2]:

Quoted 9 lines

https://github.com/torvalds/linux/commit/494c704f9af0a0cddf593b381ea44320888733e6

I know I mentioned [1] earlier, but it sounds like it might have slipped through and it might be a good idea to have both GRUB and Linux in sync in this regard.

Cheers,
Frank

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#24 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Quoted 6 lines

.

Ard thinks that a 64 bit alignment for EFI GUIDs is a mistake - see [1] and [2]. Hence Linux uses __aligned(__alignof__(u32)) for "efi_guid_t" since 2019.

My patch presents a reliability paradigm: accept all inputs, produce outputs that are always aligned to 8-byte. It can make sense even though I agree that requiring 8-byte alignment for UUID is weird. Yet it's difficult to know if some obscure firmware does rely on it in some one in a thousand edge case

+1

The Linux side change ensures that the OS does not present misaligned GUIDs to the firmware.

The problem with 8-byte alignment is that it deviates from EDK2, and could result in struct layout changes due to padding. Given that EDK2 uses 32-bit alignment only, some of the struct types it defines might suddenly need the __packed attribute on 32-bit builds if the alignment of the GUID type is increased to 64 bits.

E.g.,

struct {
void *
guid
}

will have no padding in 32-bit EDK2 based firmware builds, even if the spec claims that GUIDs are 64-bit aligned.

So the lowest risk change for Linux was to increase to 32-bit alignment, as it fixes any potential issues with misaligned load-multiple instructions on ARM, and other architectures don't care that much about alignment anyway.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#25 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 30 lines · Ard Biesheuvel
Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Quoted 6 lines

.

Ard thinks that a 64 bit alignment for EFI GUIDs is a mistake - see [1] and [2]. Hence Linux uses __aligned(__alignof__(u32)) for "efi_guid_t" since 2019.

My patch presents a reliability paradigm: accept all inputs, produce outputs that are always aligned to 8-byte. It can make sense even though I agree that requiring 8-byte alignment for UUID is weird. Yet it's difficult to know if some obscure firmware does rely on it in some one in a thousand edge case

+1

The Linux side change ensures that the OS does not present misaligned GUIDs to the firmware.

The problem with 8-byte alignment is that it deviates from EDK2, and could result in struct layout changes due to padding. Given that EDK2 uses 32-bit alignment only, some of the struct types it defines might suddenly need the __packed attribute on 32-bit builds if the alignment of the GUID type is increased to 64 bits.

E.g.,

struct {
void *
guid
}

Quoted 8 lines

will have no padding in 32-bit EDK2 based firmware builds, even if the spec claims that GUIDs are 64-bit aligned.

So the lowest risk change for Linux was to increase to 32-bit alignment, as it fixes any potential issues with misaligned load-multiple instructions on ARM, and other architectures don't care that much about alignment anyway.

This is terrible.

First, the Itanium firmware in question clearly enforces the 8-byte alignment. (BTW, have we checked Itanium with a 4-byte but not 8-byte alignment?) Edk2 has killed off Itanium support, but the UEFI spec still specifies a binding for Itanium. And, we're having this discussion in the first place because of Itanium. So we need to make up our minds about adhering to the 8-byte alignment or not.

Second, the fact that edk2 does not align EFI_GUID to 8 bytes, contrary to the spec, is absolutely terrible. I don't understand then how it worked on Itanium before Itanium support was killed.

What I can imagine is the following situation:
- the UEFI spec does not match reality (the reference implementation), and the actually required alignment is 4 bytes only
- Itanium is happy with the 4 bytes alignment too (IIUC grub's malloc aligns at 1 byte by default, so the 4-byte alignment could still be violated in practice)

I'd really like if edk2 changed EFI_GUID to match the spec, but a git-grep for EFI_GUID in edk2 header files returns 800+ lines. Noone ever will audit all those lines, to check for the potantial padding increase that you raise. Absolutely terrible.

Either way, I'd say grub still needs two distinct types, one packed *and* aligned (at 4 bytes), and another only packed (but not aligned).

Laszlo

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#26 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 9 lines · Laszlo Ersek
Quoted 7 lines · Ard Biesheuvel
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Quoted 5 lines

.

Ard thinks that a 64 bit alignment for EFI GUIDs is a mistake - see [1] and [2]. Hence Linux uses __aligned(__alignof__(u32)) for

"efi_guid_t"

Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

since 2019.

My patch presents a reliability paradigm: accept all inputs, produce

outputs that are always aligned to 8-byte. It can make sense even though I agree that requiring 8-byte alignment for UUID is weird. Yet it's difficult to know if some obscure firmware does rely on it in some one in a thousand edge case

Quoted 8 lines

+1

The Linux side change ensures that the OS does not present misaligned GUIDs to the firmware.

The problem with 8-byte alignment is that it deviates from EDK2, and could result in struct layout changes due to padding.

See my audit in previous message

Quoted 8 lines
Quoted 8 lines

Given that EDK2

uses 32-bit alignment only, some of the struct types it defines might suddenly need the __packed attribute on 32-bit builds if the alignment of the GUID type is increased to 64 bits.

E.g.,

Quoted 8 lines
Quoted 8 lines

struct {
void *
guid
}

will have no padding in 32-bit EDK2 based firmware builds, even if the spec claims that GUIDs are 64-bit aligned.

Yes, this is weird but in case of reference implementation contradicting spec, then reference implementation takes priority in practice.

Quoted 7 lines
Quoted 6 lines

So the lowest risk change for Linux was to increase to 32-bit alignment, as it fixes any potential issues with misaligned load-multiple instructions on ARM, and other architectures don't care that much about alignment anyway.

Quoted 5 lines

This is terrible.

First, the Itanium firmware in question clearly enforces the 8-byte alignment. (BTW, have we checked Itanium with a 4-byte but not 8-byte alignment?)

No, we didn't AFAIK

Quoted 4 lines

specifies a binding for Itanium. And, we're having this discussion in the first place because of Itanium. So we need to make up our minds about adhering to the 8-byte alignment or not.

I'm biased towards allocating at 8-byte alignment but accepting any alignment

Quoted 5 lines

Second, the fact that edk2 does not align EFI_GUID to 8 bytes, contrary to the spec, is absolutely terrible. I don't understand then how it worked on Itanium before Itanium support was killed.

No members in guid have uint64_t type so most likely only 32-bit alignment was used in most cases. 64-bit alignment allows accessing guid as 2 uint64_t's but I doubt it was ever widely used. A rare use might still happen though.

Quoted 8 lines

What I can imagine is the following situation:
- the UEFI spec does not match reality (the reference implementation), and the actually required alignment is 4 bytes only
- Itanium is happy with the 4 bytes alignment too (IIUC grub's malloc aligns at 1 byte by default, so the 4-byte alignment could still be violated in practice)

grub-malloc is 16-byte aligned.
The problem is that stack and static allocations are aligned only to type alignment.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#27 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoting Vladimir 'phcoder' Serbinenko (2023-08-15 18:14:11)

Quoted 89 lines

Le mar. 15 août 2023, 14:00, Laszlo Ersek <[1][email protected]> a écrit :

    On 8/15/23 10:17, Ard Biesheuvel wrote:
    > On Tue, 15 Aug 2023 at 05:42, Vladimir 'phcoder' Serbinenko
    > <[2][email protected]> wrote:
    >>>
    >>> .
    >>>
    >>> Ard thinks that a 64 bit alignment for EFI GUIDs is a mistake - see [1]
    >>> and [2]. Hence Linux uses `__aligned(__alignof__(u32))` for
    "efi_guid_t"
    >>> since 2019.
    >>
    >>
    >> My patch presents a reliability paradigm: accept all inputs, produce
    outputs that are always aligned to 8-byte. It can make sense even though I
    agree that requiring 8-byte alignment for UUID is weird. Yet it's difficult
    to know if some obscure firmware does rely on it in some one in a thousand
    edge case
    >
    > +1
    >
    > The Linux side change ensures that the OS does not present misaligned
    > GUIDs to the firmware.
    >
    > The problem with 8-byte alignment is that it deviates from EDK2, and
    > could result in struct layout changes due to padding.

See my audit in previous message

Quoted 8 lines
Quoted 1 line

Given that EDK2

uses 32-bit alignment only, some of the struct types it defines might suddenly need the __packed attribute on 32-bit builds if the alignment of the GUID type is increased to 64 bits.

E.g.,

Quoted 8 lines

struct {
   void *
   guid
}

will have no padding in 32-bit EDK2 based firmware builds, even if the spec claims that GUIDs are 64-bit aligned.

Yes, this is weird but in case of reference implementation contradicting spec, then reference implementation takes priority in practice.

Quoted 5 lines

So the lowest risk change for Linux was to increase to 32-bit alignment, as it fixes any potential issues with misaligned load-multiple instructions on ARM, and other architectures don't care that much about alignment anyway.

This is terrible.

First, the Itanium firmware in question clearly enforces the 8-byte alignment. (BTW, have we checked Itanium with a 4-byte but not 8-byte alignment?)

No, we didn't  AFAIK

specifies a binding for Itanium. And, we're having this discussion in the first place because of Itanium. So we need to make up our minds about adhering to the 8-byte alignment or not.

I'm biased towards allocating at 8-byte alignment but accepting any alignment

Second, the fact that edk2 does not align EFI_GUID to 8 bytes, contrary to the spec, is absolutely terrible. I don't understand then how it worked on Itanium before Itanium support was killed.

No members in guid have uint64_t type so most likely only 32-bit alignment was used in most cases. 64-bit alignment allows accessing guid as 2 uint64_t's but I doubt it was ever widely used. A rare use might still happen though.

What I can imagine is the following situation:
- the UEFI spec does not match reality (the reference implementation), and the actually required alignment is 4 bytes only
- Itanium is happy with the 4 bytes alignment too (IIUC grub's malloc aligns at 1 byte by default, so the 4-byte alignment could still be violated in practice)

Quoted 3 lines

grub-malloc is 16-byte aligned.
The problem is that stack and static allocations are aligned only to type alignment.

I am not sure what the best way forward is now, but we at least have the patches from Vladimir (thanks!).

Pedro, Adrian, could you - if you get a chance - try them with a 4 byte alignment too?

Thanks a lot, everybody!

Oliver

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#28 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 1 line · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-15 18:14:11)

[...]

Quoted 5 lines

I am not sure what the best way forward is now, but we at least have the patches from Vladimir (thanks!).

Pedro, Adrian, could you - if you get a chance - try them with a 4 byte alignment too?

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches to 4 and test them on Itanium?

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#29 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 12 lines · Daniel Kiper
Quoted 1 line · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-15 18:14:11)

[...]

Quoted 5 lines

I am not sure what the best way forward is now, but we at least have the patches from Vladimir (thanks!).

Pedro, Adrian, could you - if you get a chance - try them with a 4 byte alignment too?

Quoted 7 lines

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches to 4 and test them on Itanium?

Note that itanium is a 64-bit architecture, whereas the potential alignment/padding issue I raised only occurs on 32-bit systems.

So another option is to align GUIDs to __alignof__(void*)

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#30 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 17 lines · Ard Biesheuvel
Quoted 16 lines · Daniel Kiper
Quoted 1 line · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-15 18:14:11)

[...]

Quoted 5 lines

I am not sure what the best way forward is now, but we at least have the patches from Vladimir (thanks!).

Pedro, Adrian, could you - if you get a chance - try them with a 4 byte alignment too?

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Quoted 6 lines
Quoted 3 lines

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches to 4 and test them on Itanium?

Note that itanium is a 64-bit architecture, whereas the potential alignment/padding issue I raised only occurs on 32-bit systems.

Yeah, I know. But IIRC your Linux kernel patch aligns GUIDs to 4 bytes even on Itanium. So, how does it work on 64-bit architecture and nobody complained for more than 4 years... Hmmm...

Quoted 1 line

So another option is to align GUIDs to __alignof__(void*)

Vladimir and I are considering an ifdefery if needed. Or we can potentially use your proposal...

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#31 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 25 lines · Daniel Kiper
Quoted 8 lines · Ard Biesheuvel
Quoted 7 lines · Daniel Kiper
Quoted 1 line · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-15 18:14:11)

[...]

Quoted 1 line

I am not sure what the best way forward is now, but we at least have

the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

patches from Vladimir (thanks!).

Pedro, Adrian, could you - if you get a chance - try them with a 4

byte

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

alignment too?

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches

to

Quoted 3 lines
Quoted 2 lines

4 and test them on Itanium?

Quoted 7 lines
Quoted 2 lines

Note that itanium is a 64-bit architecture, whereas the potential alignment/padding issue I raised only occurs on 32-bit systems.

Yeah, I know. But IIRC your Linux kernel patch aligns GUIDs to 4 bytes even on Itanium. So, how does it work on 64-bit architecture and nobody complained for more than 4 years... Hmmm...

Unaligned access causes an exception. In GRUB it leads to unhandled exception. Linux catches exception and emulates unaligned access. It's typical for RISC platforms

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#32 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 30 lines · Vladimir 'phcoder' Serbinenko
Quoted 26 lines · Daniel Kiper
Quoted 23 lines · Ard Biesheuvel
Quoted 12 lines · Daniel Kiper
Quoted 1 line · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-15 18:14:11)

[...]

Quoted 5 lines

I am not sure what the best way forward is now, but we at least have the patches from Vladimir (thanks!).

Pedro, Adrian, could you - if you get a chance - try them with a 4 byte alignment too?

Quoted 7 lines

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches to 4 and test them on Itanium?

Note that itanium is a 64-bit architecture, whereas the potential alignment/padding issue I raised only occurs on 32-bit systems.

Quoted 6 lines
Quoted 3 lines

Yeah, I know. But IIRC your Linux kernel patch aligns GUIDs to 4 bytes even on Itanium. So, how does it work on 64-bit architecture and nobody complained for more than 4 years... Hmmm...

Unaligned access causes an exception. In GRUB it leads to unhandled exception. Linux catches exception and emulates unaligned access. It's typical for RISC platforms

No it does not, at least not in the general case.

Every Linux arch except IA-64 supports booting via the EFI stub, which is Linux kernel code that executes in the context of the EFI boot services. Any unaligned accesses occurring in this phase will be handled by the system firmware in the exact same way as an unaligned access caused by a misaligned GUID provided by GRUB. This is why the Linux EFI code needed to be fixed.

IA-64 deviates in this regard because it predates the introduction of the EFI stub, and the only EFI calls that occur from Linux are runtime services calls. Any unaligned traps occurring in that context will indeed be fixed up by the kernel, and this explains why neither the original unaligned GUIDs nor the 4-byte aligned ones Linux has been using for the past four years ever created any problems on IA-64

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#33 lore raw

Re: [PATCH v9 02/11] Unify GUID types

In reply to Daniel Kiper
Quoted 11 lines · Daniel Kiper
Quoted 1 line · Oliver Steffen

Quoting Vladimir 'phcoder' Serbinenko (2023-08-15 18:14:11)

[...]

Quoted 5 lines

I am not sure what the best way forward is now, but we at least have the patches from Vladimir (thanks!).

Pedro, Adrian, could you - if you get a chance - try them with a 4 byte alignment too?

Quoted 6 lines

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches to 4 and test them on Itanium?

If I find the time tomorrow, I will test that change.

Adrian

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#34 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 11 lines · John Paul Adrian Glaubitz
Quoted 6 lines · Daniel Kiper

On Fri, Aug 25, 2023 at 05:50:58AM -0700, Oliver Steffen wrote:

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Quoted 7 lines
Quoted 2 lines

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches to 4 and test them on Itanium?

If I find the time tomorrow, I will test that change.

Adrian

If Adrian can’t make it this week. I most certainly can next week.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#35 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 8 lines · Pedro Miguel Justo
Quoted 8 lines · John Paul Adrian Glaubitz
Quoted 6 lines · Daniel Kiper

On Fri, Aug 25, 2023 at 05:50:58AM -0700, Oliver Steffen wrote:

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches to 4 and test them on Itanium?

If I find the time tomorrow, I will test that change.

Adrian

If Adrian can’t make it this week. I most certainly can next week.

Pedro, Adrian, ping?

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#36 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 12 lines · Daniel Kiper
Quoted 11 lines · Pedro Miguel Justo
Quoted 11 lines · John Paul Adrian Glaubitz
Quoted 8 lines · Daniel Kiper

On Fri, Aug 25, 2023 at 05:50:58AM -0700, Oliver Steffen wrote:

Yes, that would be perfect. If Itanium works then I suggest to align GUIDs to 4 bytes. This alignment is used in the kernel for more than 4 years and it looks nobody complains...

Pedro, Adrian, could you change GUIDs alignment in Vladimir's patches to 4 and test them on Itanium?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

If I find the time tomorrow, I will test that change.

Adrian

If Adrian can’t make it this week. I most certainly can next week.

Pedro, Adrian, ping?

I should have some time tomorrow to perform the tests.

Adrian

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#37 lore raw

Re: [PATCH v9 02/11] Unify GUID types

In reply to Daniel Kiper
Quoted 5 lines · Daniel Kiper

Pedro, Adrian, ping?

Just to be overzealous and incredibly dense, here is my full understanding of what is being asked to test:

1) Take the payload that was tested before in [1][2]
2) Replace the 2 __attribute__ ((aligned(8))) that were added commits [3] and [4] with __attribute__ ((aligned(4)))
3) See if it still works

Correct?

[1] - https://github.com/phcoder/GRUB.git
[2] - cfa21b94e
[3] - 2464b6858
[4] - 580463c01
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#38 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Hi Pedro!

Quoted 5 lines · Pedro Miguel Justo
Quoted 4 lines · Daniel Kiper

Pedro, Adrian, ping?

Quoted 7 lines

Just to be overzealous and incredibly dense, here is my full understanding of what is being asked to test:

1) Take the payload that was tested before in [1][2]
2) Replace the 2 __attribute__ ((aligned(8))) that were added commits [3] and [4] with __attribute__ ((aligned(4)))
3) See if it still works

Correct?

I would very much appreciate if you could test this particular change so that I don't have to hook up my RX2600 which is currently stored under my sofa ;-).

Adrian

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#39 lore raw

Re: [PATCH v9 02/11] Unify GUID types

I can confirm that, taking [1][2] and making [3] on top of it, my Montvale-based rx2660 machine still boots fine.

[1] - https://github.com/phcoder/GRUB.git
[2] - cfa21b94e
[3] :

include/grub/gpt_partition.h +1 -1
index 3c70b148d..bddf832fa 100644
@@ -74,7 +74,7 @@ struct grub_gpt_partentry
   grub_uint64_t end;
   grub_uint64_t attrib;
   char name[72];
-} __attribute__((aligned(8)));
+} __attribute__((aligned(4)));
  grub_err_t
 grub_gpt_partition_map_iterate (grub_disk_t disk,
include/grub/types.h +1 -1
index c31c707e3..7d161e59f 100644
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} __attribute__ ((aligned(8)));
+} __attribute__ ((aligned(4)));
 typedef struct grub_guid grub_guid_t;
  struct grub_packed_guid
 
Quoted 16 lines · John Paul Adrian Glaubitz

Hi Pedro!

Quoted 11 lines · Pedro Miguel Justo
Quoted 4 lines · Daniel Kiper

Pedro, Adrian, ping?

Just to be overzealous and incredibly dense, here is my full understanding of what is being asked to test:

1) Take the payload that was tested before in [1][2]
2) Replace the 2 __attribute__ ((aligned(8))) that were added commits [3] and [4] with __attribute__ ((aligned(4)))
3) See if it still works

Quoted 17 lines
Quoted 1 line

Correct?

I would very much appreciate if you could test this particular change so that I don't have to hook up my RX2600 which is currently stored under my sofa ;-).

Adrian

Signature · 9 lines
.''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
 `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#40 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 3 lines · Pedro Miguel Justo

I can confirm that, taking [1][2] and making [3] on top of it, my Montvale-based rx2660 machine still boots fine.

Wonderful! Thanks for testing!

Oliver

Quoted 62 lines

[1] - https://github.com/phcoder/GRUB.git
[2] - cfa21b94e
[3] :

include/grub/gpt_partition.h +1 -1
index 3c70b148d..bddf832fa 100644
@@ -74,7 +74,7 @@ struct grub_gpt_partentry
   grub_uint64_t end;
   grub_uint64_t attrib;
   char name[72];
-} __attribute__((aligned(8)));
+} __attribute__((aligned(4)));
  grub_err_t
 grub_gpt_partition_map_iterate (grub_disk_t disk,
include/grub/types.h +1 -1
index c31c707e3..7d161e59f 100644
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} __attribute__ ((aligned(8)));
+} __attribute__ ((aligned(4)));
 typedef struct grub_guid grub_guid_t;
  struct grub_packed_guid
 
Quoted 32 lines · John Paul Adrian Glaubitz

Hi Pedro!

Quoted 5 lines · Pedro Miguel Justo
Quoted 4 lines · Daniel Kiper

Pedro, Adrian, ping?

Quoted 7 lines

Just to be overzealous and incredibly dense, here is my full understanding of what is being asked to test:

1) Take the payload that was tested before in [1][2]
2) Replace the 2 __attribute__ ((aligned(8))) that were added commits [3] and [4] with __attribute__ ((aligned(4)))
3) See if it still works

Correct?

I would very much appreciate if you could test this particular change so that I don't have to hook up my RX2600 which is currently stored under my sofa ;-).

Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
. ' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

Quoted 5 lines
Quoted 4 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#41 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Hi Oliver!

Quoted 6 lines · Oliver Steffen
Quoted 3 lines · Pedro Miguel Justo

I can confirm that, taking [1][2] and making [3] on top of it, my Montvale-based rx2660 machine still boots fine.

Wonderful! Thanks for testing!

Are you going to submit a patch to fix the issue with the new information?

Would be great if the bug could be fixed before the 2.12 release.

Thanks,
Adrian

Signature · 9 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#42 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 7 lines · John Paul Adrian Glaubitz

Hi Oliver!

Quoted 3 lines · Oliver Steffen
Quoted 2 lines · Pedro Miguel Justo
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I can confirm that, taking [1][2] and making [3] on top of it, my Montvale-based rx2660 machine still boots fine.

Wonderful! Thanks for testing!

Are you going to submit a patch to fix the issue with the new information?

Would be great if the bug could be fixed before the 2.12 release.

Yes, this needs to be fixed. The EFI GUID type should not have the packed attribute in the general case, only in places where it could really appear misaligned (e.g., in device path nodes), although I suspect that adding the packed attribute to the outer struct would be sufficient there (given that the guid struct has no internal padding so the attribute only affects its minimum alignment)

E.g,

struct grub_efi_vendor_device_path
{
grub_efi_device_path_t header;
grub_guid_t vendor_guid;
grub_efi_uint8_t vendor_defined_data[0];
} GRUB_PACKED;

Here the GUID is already 32-bit aligned due to the size of the preceding field

I think simply dropping the PACKED attribute from grub_guid_t should be sufficient here - this will affect the placement of all the grub_guid_t global and automatic variables that are passed to the firmware APIs by reference. If needed we could bring back the efi_packed_guid_t as well, but I'm not sure it is necessary.

Note that this affects 32-bit ARM as well: GRUB may pass misaligned GUIDs to APIs such as Get/SetVariable and this could crash the firmware if it assumes GUIDs are 32-bit aligned.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#43 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 28 lines · Ard Biesheuvel
Quoted 5 lines · John Paul Adrian Glaubitz

Hi Oliver!

Quoted 1 line · Oliver Steffen

On Wed, Sep 13, 2023 at 6:10 AM Pedro Miguel Justo <[email protected]>

Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines

I can confirm that, taking [1][2] and making [3] on top of it, my

Montvale-based rx2660 machine still boots fine.

Quoted 4 lines
Quoted 2 lines

Wonderful! Thanks for testing!

Are you going to submit a patch to fix the issue with the new

information?

Quoted 3 lines

Would be great if the bug could be fixed before the 2.12 release.

Yes, this needs to be fixed. The EFI GUID type should not have the packed attribute in the general case, only in places where it could really appear misaligned (e.g., in device path nodes), although I suspect that adding the packed attribute to the outer struct would be sufficient there (given that the guid struct has no internal padding so the attribute only affects its minimum alignment)

Quoted 9 lines

E.g,

struct grub_efi_vendor_device_path
{
grub_efi_device_path_t header;
grub_guid_t vendor_guid;
grub_efi_uint8_t vendor_defined_data[0];
} GRUB_PACKED;

Tried this. Compiler doesn't allow it

Quoted 11 lines

Here the GUID is already 32-bit aligned due to the size of the preceding field

I think simply dropping the PACKED attribute from grub_guid_t should be sufficient here - this will affect the placement of all the grub_guid_t global and automatic variables that are passed to the firmware APIs by reference. If needed we could bring back the efi_packed_guid_t as well, but I'm not sure it is necessary.

Quoted 4 lines

Note that this affects 32-bit ARM as well: GRUB may pass misaligned GUIDs to APIs such as Get/SetVariable and this could crash the firmware if it assumes GUIDs are 32-bit aligned.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#44 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 32 lines · Vladimir 'phcoder' Serbinenko
Quoted 28 lines · Ard Biesheuvel
Quoted 7 lines · John Paul Adrian Glaubitz

Hi Oliver!

Quoted 3 lines · Oliver Steffen
Quoted 2 lines · Pedro Miguel Justo
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I can confirm that, taking [1][2] and making [3] on top of it, my Montvale-based rx2660 machine still boots fine.

Wonderful! Thanks for testing!

Are you going to submit a patch to fix the issue with the new information?

Would be great if the bug could be fixed before the 2.12 release.

Yes, this needs to be fixed. The EFI GUID type should not have the packed attribute in the general case, only in places where it could really appear misaligned (e.g., in device path nodes), although I suspect that adding the packed attribute to the outer struct would be sufficient there (given that the guid struct has no internal padding so the attribute only affects its minimum alignment)

E.g,

Quoted 8 lines
Quoted 6 lines

struct grub_efi_vendor_device_path
{
grub_efi_device_path_t header;
grub_guid_t vendor_guid;
grub_efi_uint8_t vendor_defined_data[0];
} GRUB_PACKED;

Tried this. Compiler doesn't allow it

Tried what exactly? This is just copy/paste from the existing tree

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#45 lore raw

Re: [PATCH v9 02/11] Unify GUID types

Quoted 42 lines · Ard Biesheuvel
Quoted 39 lines · Vladimir 'phcoder' Serbinenko
Quoted 34 lines · Ard Biesheuvel
Quoted 7 lines · John Paul Adrian Glaubitz

Hi Oliver!

Quoted 3 lines · Oliver Steffen
Quoted 2 lines · Pedro Miguel Justo
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I can confirm that, taking [1][2] and making [3] on top of it, my Montvale-based rx2660 machine still boots fine.

Wonderful! Thanks for testing!

Are you going to submit a patch to fix the issue with the new information?

Would be great if the bug could be fixed before the 2.12 release.

Yes, this needs to be fixed. The EFI GUID type should not have the packed attribute in the general case, only in places where it could really appear misaligned (e.g., in device path nodes), although I suspect that adding the packed attribute to the outer struct would be sufficient there (given that the guid struct has no internal padding so the attribute only affects its minimum alignment)

E.g,

struct grub_efi_vendor_device_path
{
grub_efi_device_path_t header;
grub_guid_t vendor_guid;
grub_efi_uint8_t vendor_defined_data[0];
} GRUB_PACKED;

Quoted 3 lines
Quoted 1 line

Tried this. Compiler doesn't allow it

Tried what exactly? This is just copy/paste from the existing tree

With

include/grub/types.h +1 -1
index 0d96006fe..fb0dfc8b6 100644
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+};
 typedef struct grub_guid grub_guid_t;
 #endif /* ! GRUB_TYPES_HEADER */
 

I get:

[...]
commands/efi/loadbios.c: In function ‘fake_bios_data’:
commands/efi/loadbios.c:109:9: warning: taking address of packed member of ‘struct grub_efi_configuration_table’ may result in an unaligned pointer value [-Waddress-of-packed-member]

  109 |         &grub_efi_system_table->configuration_table[i].vendor_guid;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

commands/probe.c: In function ‘grub_cmd_probe’:
commands/probe.c:132:22: warning: taking address of packed member of ‘struct grub_gpt_partentry’ may result in an unaligned pointer value [-Waddress-of-packed-member]

  132 |               guid = &entry.guid;
      |                      ^~~~~~~~~~~

[...]

also in a couple of other places.

  struct grub_efi_configuration_table
  {
    grub_guid_t vendor_guid;
    void *vendor_table;
  } GRUB_PACKED;

and

  struct grub_gpt_partentry
  {
    grub_guid_t type;
    grub_guid_t guid;
    grub_uint64_t start;
    grub_uint64_t end;
    grub_uint64_t attrib;
    char name[72];
  } GRUB_PACKED;

Is this what you mean, Vladimir?

Oliver

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#46 lore raw

Re: [PATCH v9 02/11] Unify GUID types

re-adding Ard, who was dropped due to a bug in my MUA - sorry.

I seems that removing the packed attribute from the GUID struct alone does not solve it.

I am about to post a revert of the whole GUID thing so we can move on with the 2.12 release. If we want this feature, I can spend some time on GUIDs after the release.

Oliver

Quoting Oliver Steffen (2023-09-13 13:48:21)

Quoted 102 lines · Ard Biesheuvel
Quoted 42 lines
Quoted 39 lines · Vladimir 'phcoder' Serbinenko
Quoted 34 lines · Ard Biesheuvel
Quoted 7 lines · John Paul Adrian Glaubitz

Hi Oliver!

Quoted 3 lines · Oliver Steffen
Quoted 2 lines · Pedro Miguel Justo
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I can confirm that, taking [1][2] and making [3] on top of it, my Montvale-based rx2660 machine still boots fine.

Wonderful! Thanks for testing!

Are you going to submit a patch to fix the issue with the new information?

Would be great if the bug could be fixed before the 2.12 release.

Yes, this needs to be fixed. The EFI GUID type should not have the packed attribute in the general case, only in places where it could really appear misaligned (e.g., in device path nodes), although I suspect that adding the packed attribute to the outer struct would be sufficient there (given that the guid struct has no internal padding so the attribute only affects its minimum alignment)

E.g,

struct grub_efi_vendor_device_path
{
grub_efi_device_path_t header;
grub_guid_t vendor_guid;
grub_efi_uint8_t vendor_defined_data[0];
} GRUB_PACKED;

Quoted 3 lines
Quoted 1 line

Tried this. Compiler doesn't allow it

Tried what exactly? This is just copy/paste from the existing tree

With

include/grub/types.h +1 -1
index 0d96006fe..fb0dfc8b6 100644
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+};
 typedef struct grub_guid grub_guid_t;
 #endif /* ! GRUB_TYPES_HEADER */
 

I get:

[...]
commands/efi/loadbios.c: In function ‘fake_bios_data’:
commands/efi/loadbios.c:109:9: warning: taking address of packed member of ‘struct grub_efi_configuration_table’ may result in an unaligned pointer value [-Waddress-of-packed-member]

  109 |         &grub_efi_system_table->configuration_table[i].vendor_guid;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

commands/probe.c: In function ‘grub_cmd_probe’:
commands/probe.c:132:22: warning: taking address of packed member of ‘struct grub_gpt_partentry’ may result in an unaligned pointer value [-Waddress-of-packed-member]

  132 |               guid = &entry.guid;
      |                      ^~~~~~~~~~~

[...]

also in a couple of other places.

  struct grub_efi_configuration_table
  {
    grub_guid_t vendor_guid;
    void *vendor_table;
  } GRUB_PACKED;

and

  struct grub_gpt_partentry
  {
    grub_guid_t type;
    grub_guid_t guid;
    grub_uint64_t start;
    grub_uint64_t end;
    grub_uint64_t attrib;
    char name[72];
  } GRUB_PACKED;
Quoted 3 lines

Is this what you mean, Vladimir?

Oliver

--
🎩Oliver Steffen (he/him) - Software Engineer, Virtualization Red Hat GmbH <https://www.redhat.com/de/global/dach>,
Registered seat: Werner-von-Siemens-Ring 12, D-85630 Grasbrunn, Germany Commercial register: Amtsgericht München/Munich, HRB 153243, Managing Directors: Ryan Barnhart, Charles Cachera, Michael O'Neill, Amy Ross

Everyone has different working hours… Please do not feel obligated to reply outside of your normal work schedule.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#47 lore raw

Re: [PATCH v9 02/11] Unify GUID types

In reply to John Paul Adrian Glaubitz
Quoted 4 lines · John Paul Adrian Glaubitz

Hi Oliver!

On Wed, 2023-09-13 at 12:14 +0200, Oliver Steffen wrote:

Quoted 9 lines
Quoted 6 lines · Pedro Miguel Justo
Quoted 3 lines

I can confirm that, taking [1][2] and making [3] on top of it, my Montvale-based rx2660 machine still boots fine.

Wonderful! Thanks for testing!

Are you going to submit a patch to fix the issue with the new information?

We could use Vladimir's patches, if he wants to contribute those. With the change to 32bit alignment, as Pedro tested, of course. They apply nicely on top of the current branch, if this patch from this github repo is also applied:

bf7f056b "efi: Deduplicate configuration table search function"

Vladimir said that he wanted to work on these patches before they go in.

I attached them to this email, for reference, incl. the change to 32bit alignment.

Oliver

From c4e4417d3e37d0254390baaf7acb24dfc37c8dd3 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:18:23 +0200
Subject: [PATCH 3/6] types: Split aligned and packed guids

---
 grub-core/commands/efi/lsefi.c    |  2 +-
 grub-core/efiemu/runtime/efiemu.c | 33 +++++++++++++++++++++----------
 grub-core/kern/efi/efi.c          |  2 +-
 grub-core/kern/misc.c             |  2 +-
 grub-core/loader/i386/xnu.c       |  2 +-
 include/grub/efi/api.h            | 12 +++++------
 include/grub/efiemu/efiemu.h      |  4 ++--
 include/grub/efiemu/runtime.h     |  2 +-
 include/grub/types.h              | 11 ++++++++++-
 9 files changed, 46 insertions(+), 24 deletions(-)
grub-core/commands/efi/lsefi.c +1 -1
index 05e2e511e..3ea278a82 100644
@@ -96,7 +96,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
       grub_efi_handle_t handle = handles[i];
       grub_efi_status_t status;
       grub_efi_uintn_t num_protocols;
-      grub_guid_t **protocols;
+      grub_packed_guid_t **protocols;
       grub_efi_device_path_t *dp;
 
       grub_printf ("Handle %p\n", handle);
grub-core/efiemu/runtime/efiemu.c +23 -10
index c84b30652..f6b6d19f7 100644
@@ -66,7 +66,7 @@ efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,
 
 grub_efi_status_t __grub_efi_api
 efiemu_get_variable (grub_efi_char16_t *variable_name,
-		     const grub_guid_t *vendor_guid,
+		     const grub_packed_guid_t *vendor_guid,
 		     grub_efi_uint32_t *attributes,
 		     grub_efi_uintn_t *data_size,
 		     void *data);
@@ -74,11 +74,11 @@ efiemu_get_variable (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api
 efiemu_get_next_variable_name (grub_efi_uintn_t *variable_name_size,
 			       grub_efi_char16_t *variable_name,
-			       grub_guid_t *vendor_guid);
+			       grub_packed_guid_t *vendor_guid);
 
 grub_efi_status_t __grub_efi_api
 efiemu_set_variable (grub_efi_char16_t *variable_name,
-		     const grub_guid_t *vendor_guid,
+		     const grub_packed_guid_t *vendor_guid,
 		     grub_efi_uint32_t attributes,
 		     grub_efi_uintn_t data_size,
 		     void *data);
@@ -416,7 +416,7 @@ EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
 
 /* Find variable by name and GUID. */
 static struct efi_variable *
-find_variable (const grub_guid_t *vendor_guid,
+find_variable (const grub_packed_guid_t *vendor_guid,
 	       grub_efi_char16_t *variable_name)
 {
   grub_uint8_t *ptr;
@@ -438,7 +438,7 @@ find_variable (const grub_guid_t *vendor_guid,
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
-				const grub_guid_t *vendor_guid,
+				const grub_packed_guid_t *vendor_guid,
 				grub_efi_uint32_t *attributes,
 				grub_efi_uintn_t *data_size,
 				void *data)
@@ -464,7 +464,7 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
 grub_efi_status_t __grub_efi_api EFI_FUNC
 (efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
 				 grub_efi_char16_t *variable_name,
-				 grub_guid_t *vendor_guid)
+				 grub_packed_guid_t *vendor_guid)
 {
   struct efi_variable *efivar;
   LOG ('l');
@@ -503,7 +503,7 @@ grub_efi_status_t __grub_efi_api EFI_FUNC
 
 grub_efi_status_t __grub_efi_api
 EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
-				const grub_guid_t *vendor_guid,
+				const grub_packed_guid_t *vendor_guid,
 				grub_efi_uint32_t attributes,
 				grub_efi_uintn_t data_size,
 				void *data)
@@ -597,9 +597,22 @@ struct grub_efi_runtime_services efiemu_runtime_services =
   .set_virtual_address_map = efiemu_set_virtual_address_map,
   .convert_pointer = efiemu_convert_pointer,
 
-  .get_variable = efiemu_get_variable,
-  .get_next_variable_name = efiemu_get_next_variable_name,
-  .set_variable = efiemu_set_variable,
+  .get_variable = (grub_efi_status_t
+		   (__grub_efi_api *) (grub_efi_char16_t *variable_name,
+				       const grub_guid_t *vendor_guid,
+				       grub_efi_uint32_t *attributes,
+				       grub_efi_uintn_t *data_size,
+				       void *data)) efiemu_get_variable,
+  .get_next_variable_name = (grub_efi_status_t
+			     (__grub_efi_api *) (grub_efi_uintn_t *variable_name_size,
+						 grub_efi_char16_t *variable_name,
+						 grub_guid_t *vendor_guid)) efiemu_get_next_variable_name,
+  .set_variable = (grub_efi_status_t
+		   (__grub_efi_api *) (grub_efi_char16_t *variable_name,
+				       const grub_guid_t *vendor_guid,
+				       grub_efi_uint32_t attributes,
+				       grub_efi_uintn_t data_size,
+				       void *data)) efiemu_set_variable,
   .get_next_high_monotonic_count = efiemu_get_next_high_monotonic_count,
 
   .reset_system = efiemu_reset_system
grub-core/kern/efi/efi.c +1 -1
index 9bf4f571c..20728af6b 100644
@@ -1039,7 +1039,7 @@ grub_efi_find_configuration_table(const grub_guid_t *target_guid)
 
   for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
     {
-      grub_guid_t *guid =
+      grub_packed_guid_t *guid =
 	&grub_efi_system_table->configuration_table[i].vendor_guid;
 
       if (! grub_memcmp (guid, target_guid, sizeof (grub_guid_t)))
grub-core/kern/misc.c +1 -1
index b57249acb..7cee5d75c 100644
@@ -1068,7 +1068,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
 	  if (*(fmt) == 'G')
 	    {
 	      ++fmt;
-	      grub_guid_t *guid = (grub_guid_t *)(grub_addr_t) curarg;
+	      grub_packed_guid_t *guid = (grub_packed_guid_t *)(grub_addr_t) curarg;
 	      write_number (str, &count, max_len, 8, 0, '0', 'x', guid->data1);
 	      write_char (str, &count, max_len, '-');
 	      write_number (str, &count, max_len, 4, 0, '0', 'x', guid->data2);
grub-core/loader/i386/xnu.c +1 -1
index 4e31ce99a..b91e2f840 100644
@@ -694,7 +694,7 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)
     {
       void *ptr;
       struct grub_xnu_devtree_key *curkey;
-      grub_guid_t guid;
+      grub_packed_guid_t guid;
       char guidbuf[64];
 
       /* Retrieve current key. */
include/grub/efi/api.h +6 -6
index d3eaef3fb..d44d00ad7 100644
@@ -730,7 +730,7 @@ typedef struct grub_efi_memory_mapped_device_path grub_efi_memory_mapped_device_
 struct grub_efi_vendor_device_path
 {
   grub_efi_device_path_t header;
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   grub_efi_uint8_t vendor_defined_data[0];
 } GRUB_PACKED;
 typedef struct grub_efi_vendor_device_path grub_efi_vendor_device_path_t;
@@ -974,7 +974,7 @@ typedef struct grub_efi_cdrom_device_path grub_efi_cdrom_device_path_t;
 struct grub_efi_vendor_media_device_path
 {
   grub_efi_device_path_t header;
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   grub_efi_uint8_t vendor_defined_data[0];
 } GRUB_PACKED;
 typedef struct grub_efi_vendor_media_device_path grub_efi_vendor_media_device_path_t;
@@ -993,7 +993,7 @@ typedef struct grub_efi_file_path_device_path grub_efi_file_path_device_path_t;
 struct grub_efi_protocol_device_path
 {
   grub_efi_device_path_t header;
-  grub_guid_t guid;
+  grub_packed_guid_t guid;
 } GRUB_PACKED;
 typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
 
@@ -1002,7 +1002,7 @@ typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
 struct grub_efi_piwg_device_path
 {
   grub_efi_device_path_t header;
-  grub_guid_t guid;
+  grub_packed_guid_t guid;
 } GRUB_PACKED;
 typedef struct grub_efi_piwg_device_path grub_efi_piwg_device_path_t;
 
@@ -1287,7 +1287,7 @@ struct grub_efi_boot_services
 
   grub_efi_status_t
   (__grub_efi_api *protocols_per_handle) (grub_efi_handle_t handle,
-					  grub_guid_t ***protocol_buffer,
+					  grub_packed_guid_t ***protocol_buffer,
 					  grub_efi_uintn_t *protocol_buffer_count);
 
   grub_efi_status_t
@@ -1386,7 +1386,7 @@ typedef struct grub_efi_runtime_services grub_efi_runtime_services_t;
 
 struct grub_efi_configuration_table
 {
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   void *vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
include/grub/efiemu/efiemu.h +2 -2
index caf0b505f..d6a868e94 100644
@@ -183,13 +183,13 @@ struct grub_efiemu_configuration_table
 };
 struct grub_efiemu_configuration_table32
 {
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   grub_efi_uint32_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t;
 struct grub_efiemu_configuration_table64
 {
-  grub_guid_t vendor_guid;
+  grub_packed_guid_t vendor_guid;
   grub_efi_uint64_t vendor_table;
 } GRUB_PACKED;
 typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t;
include/grub/efiemu/runtime.h +1 -1
index c9ad9fdfa..2ff429845 100644
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
 
 struct efi_variable
 {
-  grub_guid_t guid;
+  grub_packed_guid_t guid;
   grub_uint32_t namelen;
   grub_uint32_t size;
   grub_efi_uint32_t attributes;
include/grub/types.h +10 -1
index 0d96006fe..4028c32bf 100644
@@ -376,7 +376,16 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(8)));
 typedef struct grub_guid grub_guid_t;
 
+struct grub_packed_guid
+{
+  grub_uint32_t data1;
+  grub_uint16_t data2;
+  grub_uint16_t data3;
+  grub_uint8_t data4[8];
+} __attribute__ ((packed));
+typedef struct grub_packed_guid grub_packed_guid_t;
+
 #endif /* ! GRUB_TYPES_HEADER */
Signature · 1 line
2.41.0

From 61071bac8481a6a3b43a1435674c3835dc9664af Mon Sep 17 00:00:00 2001
From: Oliver Steffen <[email protected]>
Date: Wed, 13 Sep 2023 20:58:46 +0200
Subject: [PATCH 5/6] types: Use 32bit alignment for guids

---
 include/grub/types.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/grub/types.h +2 -2
index 4028c32bf..1d0e25de3 100644
@@ -376,7 +376,7 @@ struct grub_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} __attribute__ ((aligned(8)));
+} __attribute__ ((aligned(4)));
 typedef struct grub_guid grub_guid_t;
 
 struct grub_packed_guid
@@ -385,7 +385,7 @@ struct grub_packed_guid
   grub_uint16_t data2;
   grub_uint16_t data3;
   grub_uint8_t data4[8];
-} __attribute__ ((packed));
+} GRUB_PACKED;
 typedef struct grub_packed_guid grub_packed_guid_t;
 
 #endif /* ! GRUB_TYPES_HEADER */
Signature · 1 line
2.41.0

From 3a4ad7847f982f567ae7b4ed8971d412926f8722 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:17:22 +0200
Subject: [PATCH 2/6] gpt: Mark grub_gpt_partentry as aligned to 8 bytes

---
 include/grub/gpt_partition.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/gpt_partition.h +1 -1
index 020e71920..e271ea9fa 100644
@@ -67,7 +67,7 @@ struct grub_gpt_partentry
   grub_uint64_t end;
   grub_uint64_t attrib;
   char name[72];
-} GRUB_PACKED;
+} __attribute__((aligned(8)));
 
 grub_err_t
 grub_gpt_partition_map_iterate (grub_disk_t disk,
Signature · 1 line
2.41.0

From 6c924bfe65c49328dfa995357139e676fa241536 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:18:53 +0200
Subject: [PATCH 4/6] gpt: Add compile time asserts for guid and gpt_partentry
sizes

---
 grub-core/partmap/gpt.c | 3 +++
 1 file changed, 3 insertions(+)
grub-core/partmap/gpt.c +3 -0
index 877ceefc3..426f616ae 100644
@@ -229,6 +229,9 @@ static struct grub_partition_map grub_gpt_partition_map =
 
 GRUB_MOD_INIT(part_gpt)
 {
+  COMPILE_TIME_ASSERT(sizeof(grub_guid_t) == 16);
+  COMPILE_TIME_ASSERT(sizeof(grub_packed_guid_t) == 16);
+  COMPILE_TIME_ASSERT(sizeof(struct grub_gpt_partentry) == 128);
   grub_partition_map_register (&grub_gpt_partition_map);
 }
 
Signature · 1 line
2.41.0

From 76b4b607f3da7332d600f130b1110f421a2a1feb Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <[email protected]>
Date: Sun, 13 Aug 2023 09:15:02 +0200
Subject: [PATCH 1/6] efi: Deduplicate configuration table search function

---
 grub-core/commands/efi/loadbios.c | 37 ++++++++-----------------------
 grub-core/commands/efi/lssal.c    | 18 +++++----------
 grub-core/commands/efi/smbios.c   | 30 ++-----------------------
 grub-core/kern/efi/acpi.c         | 28 ++---------------------
 grub-core/kern/efi/efi.c          | 18 +++++++++++++++
 grub-core/kern/efi/fdt.c          | 21 +++++-------------
 include/grub/efi/efi.h            |  3 +++
 7 files changed, 46 insertions(+), 109 deletions(-)
grub-core/commands/efi/loadbios.c +9 -28
index 8f6b0ecfc..916633631 100644
@@ -92,7 +92,6 @@ lock_rom_area (void)
 static void
 fake_bios_data (int use_rom)
 {
-  unsigned i;
   void *acpi, *smbios;
   grub_uint16_t *ebda_seg_ptr, *low_mem_ptr;
 
@@ -101,33 +100,15 @@ fake_bios_data (int use_rom)
   if ((*ebda_seg_ptr) || (*low_mem_ptr))
     return;
 
-  acpi = 0;
-  smbios = 0;
-  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
-    {
-      grub_guid_t *guid =
-	&grub_efi_system_table->configuration_table[i].vendor_guid;
-
-      if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_guid_t)))
-	{
-	  acpi = grub_efi_system_table->configuration_table[i].vendor_table;
-	  grub_dprintf ("efi", "ACPI2: %p\n", acpi);
-	}
-      else if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_guid_t)))
-	{
-	  void *t;
-
-	  t = grub_efi_system_table->configuration_table[i].vendor_table;
-	  if (! acpi)
-	    acpi = t;
-	  grub_dprintf ("efi", "ACPI: %p\n", t);
-	}
-      else if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_guid_t)))
-	{
-	  smbios = grub_efi_system_table->configuration_table[i].vendor_table;
-	  grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
-	}
-    }
+  acpi = grub_efi_find_configuration_table(&acpi2_guid);
+  grub_dprintf ("efi", "ACPI2: %p\n", acpi);
+  if (!acpi) {
+    acpi = grub_efi_find_configuration_table(&acpi_guid);
+    grub_dprintf ("efi", "ACPI1: %p\n", acpi);
+  }
+
+  smbios = grub_efi_find_configuration_table(&smbios_guid);
+  grub_dprintf ("efi", "SMBIOS: %p\n", smbios);
 
   *ebda_seg_ptr = FAKE_EBDA_SEG;
   *low_mem_ptr = (FAKE_EBDA_SEG >> 6);
grub-core/commands/efi/lssal.c +6 -12
index fd6085f1b..0e36bfcdc 100644
@@ -136,22 +136,16 @@ grub_cmd_lssal (struct grub_command *cmd __attribute__ ((unused)),
 		int argc __attribute__ ((unused)),
 		char **args __attribute__ ((unused)))
 {
-  const grub_efi_system_table_t *st = grub_efi_system_table;
-  grub_efi_configuration_table_t *t = st->configuration_table;
-  unsigned int i;
   static grub_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
+  void *table = grub_efi_find_configuration_table(&guid);
 
-  for (i = 0; i < st->num_table_entries; i++)
+  if (!table)
     {
-      if (grub_memcmp (&guid, &t->vendor_guid,
-		       sizeof (grub_guid_t)) == 0)
-	{
-	  disp_sal (t->vendor_table);
-	  return GRUB_ERR_NONE;
-	}
-      t++;
+        grub_printf ("SAL not found\n");
+	return GRUB_ERR_NONE;
     }
-  grub_printf ("SAL not found\n");
+
+  disp_sal (table);
   return GRUB_ERR_NONE;
 }
 
grub-core/commands/efi/smbios.c +2 -28
index d77239732..296bedf7b 100644
@@ -18,44 +18,18 @@
  */
 
 #include <grub/smbios.h>
-#include <grub/misc.h>
 #include <grub/efi/efi.h>
-#include <grub/efi/api.h>
 
 struct grub_smbios_eps *
 grub_machine_smbios_get_eps (void)
 {
-  unsigned i;
   static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
-
-  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
-    {
-      grub_guid_t *guid =
-	&grub_efi_system_table->configuration_table[i].vendor_guid;
-
-      if (! grub_memcmp (guid, &smbios_guid, sizeof (grub_guid_t)))
-	return (struct grub_smbios_eps *)
-	  grub_efi_system_table->configuration_table[i].vendor_table;
-    }
-
-  return 0;
+  return (struct grub_smbios_eps *) grub_efi_find_configuration_table(&smbios_guid);
 }
 
 struct grub_smbios_eps3 *
 grub_machine_smbios_get_eps3 (void)
 {
-  unsigned i;
   static grub_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
-
-  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
-    {
-      grub_guid_t *guid =
-	&grub_efi_system_table->configuration_table[i].vendor_guid;
-
-      if (! grub_memcmp (guid, &smbios3_guid, sizeof (grub_guid_t)))
-	return (struct grub_smbios_eps3 *)
-	  grub_efi_system_table->configuration_table[i].vendor_table;
-    }
-
-  return 0;
+  return (struct grub_smbios_eps3 *) grub_efi_find_configuration_table(&smbios3_guid);
 }
grub-core/kern/efi/acpi.c +2 -26
index 461c77c33..640ba172f 100644
@@ -18,42 +18,18 @@
  */
 
 #include <grub/acpi.h>
-#include <grub/misc.h>
 #include <grub/efi/efi.h>
-#include <grub/efi/api.h>
 
 struct grub_acpi_rsdp_v10 *
 grub_machine_acpi_get_rsdpv1 (void)
 {
-  unsigned i;
   static grub_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID;
-
-  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
-    {
-      grub_guid_t *guid =
-	&grub_efi_system_table->configuration_table[i].vendor_guid;
-
-      if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_guid_t)))
-	return (struct grub_acpi_rsdp_v10 *)
-	  grub_efi_system_table->configuration_table[i].vendor_table;
-    }
-  return 0;
+  return (struct grub_acpi_rsdp_v10 *) grub_efi_find_configuration_table(&acpi_guid);
 }
 
 struct grub_acpi_rsdp_v20 *
 grub_machine_acpi_get_rsdpv2 (void)
 {
-  unsigned i;
   static grub_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID;
-
-  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
-    {
-      grub_guid_t *guid =
-	&grub_efi_system_table->configuration_table[i].vendor_guid;
-
-      if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_guid_t)))
-	return (struct grub_acpi_rsdp_v20 *)
-	  grub_efi_system_table->configuration_table[i].vendor_table;
-    }
-  return 0;
+  return (struct grub_acpi_rsdp_v20 *) grub_efi_find_configuration_table(&acpi20_guid);
 }
grub-core/kern/efi/efi.c +18 -0
index a2afd8de9..9bf4f571c 100644
@@ -1031,3 +1031,21 @@ grub_efi_compare_device_paths (const grub_efi_device_path_t *dp1,
 
   return 0;
 }
+
+void *
+grub_efi_find_configuration_table(const grub_guid_t *target_guid)
+{
+  unsigned i;
+
+  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
+    {
+      grub_guid_t *guid =
+	&grub_efi_system_table->configuration_table[i].vendor_guid;
+
+      if (! grub_memcmp (guid, target_guid, sizeof (grub_guid_t)))
+	return (void *)
+	  grub_efi_system_table->configuration_table[i].vendor_table;
+    }
+
+  return 0;
+}
grub-core/kern/efi/fdt.c +6 -15
index 8fcf43f1b..99e95d34e 100644
@@ -23,21 +23,12 @@
 void *
 grub_efi_get_firmware_fdt (void)
 {
-  grub_efi_configuration_table_t *tables;
   static grub_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
-  void *firmware_fdt = NULL;
-  unsigned int i;
-
-  /* Look for FDT in UEFI config tables. */
-  tables = grub_efi_system_table->configuration_table;
-
-  for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
-    if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0)
-      {
-	firmware_fdt = tables[i].vendor_table;
-	grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt);
-	break;
-      }
-
+  void *firmware_fdt = grub_efi_find_configuration_table(&fdt_guid);
+  if (firmware_fdt) {
+    grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt);
+  } else {
+    grub_dprintf ("linux", "not found registered FDT\n");
+  }
   return firmware_fdt;
 }
include/grub/efi/efi.h +3 -0
index 572f7135f..a5cd99e5a 100644
@@ -119,6 +119,9 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,
 						char **device,
 						char **path);
 
+void *
+EXPORT_FUNC (grub_efi_find_configuration_table) (const grub_guid_t *target_guid);
+
 #if defined(__arm__) || defined(__aarch64__) || defined(__riscv) || defined(__loongarch__)
 void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
 grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
Signature · 1 line
2.41.0

From 42c04927e05d59e3a8920bff16db8b6b54f6f9c0 Mon Sep 17 00:00:00 2001
From: Oliver Steffen <[email protected]>
Date: Wed, 13 Sep 2023 21:03:46 +0200
Subject: [PATCH 6/6] gpt: use 32bit alignment for grub_gpt_partentry

---
 include/grub/gpt_partition.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/gpt_partition.h +1 -1
index e271ea9fa..7defd731a 100644
@@ -67,7 +67,7 @@ struct grub_gpt_partentry
   grub_uint64_t end;
   grub_uint64_t attrib;
   char name[72];
-} __attribute__((aligned(8)));
+} __attribute__((aligned(4)));
 
 grub_err_t
 grub_gpt_partition_map_iterate (grub_disk_t disk,
Signature · 1 line
2.41.0

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#48 lore raw

PATCH v9 3/11 kern/misc: Add a format specifier GUIDs

In reply to Oliver Steffen

Extend the printf format specifier for pointers (%p) to accept a suffix specifier G to print GUIDs: %pG can be used to print grub_guid structs. This does not interfere with the -Wformat checking of gcc. Note that the data type is not checked though (%p accepts void*).

---
 grub-core/kern/misc.c | 81 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 60 insertions(+), 21 deletions(-)
grub-core/kern/misc.c +60 -21
index dfae4f9d7..22b7dca42 100644
@@ -24,6 +24,7 @@
 #include <grub/term.h>
 #include <grub/env.h>
 #include <grub/i18n.h>
+#include <grub/types.h>
 
 union printf_arg
 {
@@ -34,7 +35,8 @@ union printf_arg
     {
       INT, LONG, LONGLONG,
       UNSIGNED_INT = 3, UNSIGNED_LONG, UNSIGNED_LONGLONG,
-      STRING
+      STRING,
+      GUID
     } type;
   long long ll;
 };
@@ -772,6 +774,9 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args,
       switch (c)
 	{
 	case 'p':
+	  if (*(fmt) == 'G')
+	    ++fmt;
+	  /* Fall through. */
 	case 'x':
 	case 'X':
 	case 'u':
@@ -885,6 +890,10 @@ parse_printf_arg_fmt (const char *fmt0, struct printf_args *args,
 	    args->ptr[curn].type = UNSIGNED_LONGLONG;
 	  else
 	    args->ptr[curn].type = UNSIGNED_INT;
+	  if (*(fmt) == 'G') {
+	    args->ptr[curn].type = GUID;
+	    ++fmt;
+	  }
 	  break;
 	case 's':
 	  args->ptr[curn].type = STRING;
@@ -926,6 +935,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, va_list args_in)
 	args->ptr[n].ll = va_arg (args_in, long long);
 	break;
       case STRING:
+      case GUID:
 	if (sizeof (void *) == sizeof (long long))
 	  args->ptr[n].ll = va_arg (args_in, long long);
 	else
@@ -943,6 +953,27 @@ write_char (char *str, grub_size_t *count, grub_size_t max_len, unsigned char ch
   (*count)++;
 }
 
+static void
+write_number (char *str, grub_size_t *count, grub_size_t max_len, grub_size_t format1,
+	     char rightfill, char zerofill, char c, long long value)
+{
+  char tmp[32];
+  const char *p = tmp;
+  grub_size_t len;
+  grub_size_t fill;
+
+  len = grub_lltoa (tmp, c, value) - tmp;
+  fill = len < format1 ? format1 - len : 0;
+  if (! rightfill)
+    while (fill--)
+      write_char (str, count, max_len, zerofill);
+  while (*p)
+    write_char (str, count, max_len, *p++);
+  if (rightfill)
+    while (fill--)
+      write_char (str, count, max_len, zerofill);
+}
+
 static int
 grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
 		     struct printf_args *args)
@@ -1025,31 +1056,39 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
       switch (c)
 	{
 	case 'p':
-	  write_char (str, &count, max_len, '0');
-	  write_char (str, &count, max_len, 'x');
-	  c = 'x';
+	  if (*(fmt) == 'G')
+	    {
+	      ++fmt;
+	      grub_guid_t *guid = (grub_guid_t *)(grub_addr_t) curarg;
+	      write_number (str, &count, max_len, 8, 0, '0', 'x', guid->data1);
+	      write_char (str, &count, max_len, '-');
+	      write_number (str, &count, max_len, 4, 0, '0', 'x', guid->data2);
+	      write_char (str, &count, max_len, '-');
+	      write_number (str, &count, max_len, 4, 0, '0', 'x', guid->data3);
+	      write_char (str, &count, max_len, '-');
+	      write_number (str, &count, max_len, 2, 0, '0', 'x', guid->data4[0]);
+	      write_number (str, &count, max_len, 2, 0, '0', 'x', guid->data4[1]);
+	      write_char (str, &count, max_len, '-');
+	      write_number (str, &count, max_len, 2, 0, '0', 'x', guid->data4[2]);
+	      write_number (str, &count, max_len, 2, 0, '0', 'x', guid->data4[3]);
+	      write_number (str, &count, max_len, 2, 0, '0', 'x', guid->data4[4]);
+	      write_number (str, &count, max_len, 2, 0, '0', 'x', guid->data4[5]);
+	      write_number (str, &count, max_len, 2, 0, '0', 'x', guid->data4[6]);
+	      write_number (str, &count, max_len, 2, 0, '0', 'x', guid->data4[7]);
+	      break;
+	    }
+	  else
+	    {
+	      write_char (str, &count, max_len, '0');
+	      write_char (str, &count, max_len, 'x');
+	      c = 'x';
+	    }
 	  /* Fall through. */
 	case 'x':
 	case 'X':
 	case 'u':
 	case 'd':
-	  {
-	    char tmp[32];
-	    const char *p = tmp;
-	    grub_size_t len;
-	    grub_size_t fill;
-
-	    len = grub_lltoa (tmp, c, curarg) - tmp;
-	    fill = len < format1 ? format1 - len : 0;
-	    if (! rightfill)
-	      while (fill--)
-		write_char (str, &count, max_len, zerofill);
-	    while (*p)
-	      write_char (str, &count, max_len, *p++);
-	    if (rightfill)
-	      while (fill--)
-		write_char (str, &count, max_len, zerofill);
-	  }
+	  write_number (str, &count, max_len, format1, rightfill, zerofill, c, curarg);
 	  break;
 
 	case 'c':
Signature · 1 line
2.40.1
#49 lore raw

PATCH v9 4/11 grub-core: Make use of guid printf format specifier

In reply to Oliver Steffen

Use the new printf format specifier %pG.

Fixes the text representation of GUIDs in the output of the lsefisystab command (missing 4th dash).

---
 grub-core/commands/efi/lsefi.c       | 13 +------------
 grub-core/commands/efi/lsefisystab.c |  6 +-----
 grub-core/commands/probe.c           | 12 ++++--------
 grub-core/kern/efi/efi.c             | 28 ++--------------------------
 grub-core/loader/i386/xnu.c          |  9 ++-------
 5 files changed, 10 insertions(+), 58 deletions(-)
grub-core/commands/efi/lsefi.c +1 -12
index 6935cd302..05e2e511e 100644
@@ -124,18 +124,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
 	  if (k < ARRAY_SIZE (known_protocols))
 	    grub_printf ("  %s\n", known_protocols[k].name);
 	  else
-	    grub_printf ("  %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
-			 protocols[j]->data1,
-			 protocols[j]->data2,
-			 protocols[j]->data3,
-			 (unsigned) protocols[j]->data4[0],
-			 (unsigned) protocols[j]->data4[1],
-			 (unsigned) protocols[j]->data4[2],
-			 (unsigned) protocols[j]->data4[3],
-			 (unsigned) protocols[j]->data4[4],
-			 (unsigned) protocols[j]->data4[5],
-			 (unsigned) protocols[j]->data4[6],
-			 (unsigned) protocols[j]->data4[7]);
+	    grub_printf ("  %pG\n", protocols[j]);
 	}
 
     }
grub-core/commands/efi/lsefisystab.c +1 -5
index eff8c41f3..79ccee12a 100644
@@ -96,11 +96,7 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),
 
       grub_printf ("%p  ", t->vendor_table);
 
-      grub_printf ("%08x-%04x-%04x-",
-		   t->vendor_guid.data1, t->vendor_guid.data2,
-		   t->vendor_guid.data3);
-      for (j = 0; j < 8; j++)
-	grub_printf ("%02x", t->vendor_guid.data4[j]);
+      grub_printf ("%pG", &t->vendor_guid);
 
       for (j = 0; j < ARRAY_SIZE (guid_mappings); j++)
 	if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
grub-core/commands/probe.c +4 -8
index cc8c05586..be9637f33 100644
@@ -130,14 +130,10 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)
 		  return grub_errno;
 		}
 	      guid = &entry.guid;
-	      grub_snprintf (val, sizeof(val),
-			     "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-			     grub_le_to_cpu32 (guid->data1),
-			     grub_le_to_cpu16 (guid->data2),
-			     grub_le_to_cpu16 (guid->data3),
-			     guid->data4[0], guid->data4[1], guid->data4[2],
-			     guid->data4[3], guid->data4[4], guid->data4[5],
-			     guid->data4[6], guid->data4[7]);
+	      guid->data1 = grub_le_to_cpu32 (guid->data1);
+	      guid->data2 = grub_le_to_cpu16 (guid->data2);
+	      guid->data3 = grub_le_to_cpu16 (guid->data3);
+	      grub_snprintf (val, sizeof(val), "%pG", guid);
 	    }
 	  else if (grub_strcmp(dev->disk->partition->partmap->name, "msdos") == 0)
 	    {
grub-core/kern/efi/efi.c +2 -26
index 9e7d1a4a7..394523d0a 100644
@@ -545,20 +545,7 @@ static void
 dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor)
 {
   grub_uint32_t vendor_data_len = vendor->header.length - sizeof (*vendor);
-  grub_printf ("/%sVendor(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)[%x: ",
-	       type,
-	       (unsigned) vendor->vendor_guid.data1,
-	       (unsigned) vendor->vendor_guid.data2,
-	       (unsigned) vendor->vendor_guid.data3,
-	       (unsigned) vendor->vendor_guid.data4[0],
-	       (unsigned) vendor->vendor_guid.data4[1],
-	       (unsigned) vendor->vendor_guid.data4[2],
-	       (unsigned) vendor->vendor_guid.data4[3],
-	       (unsigned) vendor->vendor_guid.data4[4],
-	       (unsigned) vendor->vendor_guid.data4[5],
-	       (unsigned) vendor->vendor_guid.data4[6],
-	       (unsigned) vendor->vendor_guid.data4[7],
-	       vendor_data_len);
+  grub_printf ("/%sVendor(%pG)[%x: ", type, &vendor->vendor_guid, vendor_data_len);
   if (vendor->header.length > sizeof (*vendor))
     {
       grub_uint32_t i;
@@ -929,18 +916,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp)
 	      {
 		grub_efi_protocol_device_path_t *proto
 		  = (grub_efi_protocol_device_path_t *) dp;
-		grub_printf ("/Protocol(%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x)",
-			     (unsigned) proto->guid.data1,
-			     (unsigned) proto->guid.data2,
-			     (unsigned) proto->guid.data3,
-			     (unsigned) proto->guid.data4[0],
-			     (unsigned) proto->guid.data4[1],
-			     (unsigned) proto->guid.data4[2],
-			     (unsigned) proto->guid.data4[3],
-			     (unsigned) proto->guid.data4[4],
-			     (unsigned) proto->guid.data4[5],
-			     (unsigned) proto->guid.data4[6],
-			     (unsigned) proto->guid.data4[7]);
+		grub_printf ("/Protocol(%pG)",&proto->guid);
 	      }
 	      break;
 	    default:
grub-core/loader/i386/xnu.c +2 -7
index 93ba4476d..4e31ce99a 100644
@@ -726,13 +726,8 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)
 #endif
 
       /* The name of key for new table. */
-      grub_snprintf (guidbuf, sizeof (guidbuf), "%08x-%04x-%04x-%02x%02x-",
-		     guid.data1, guid.data2, guid.data3, guid.data4[0],
-		     guid.data4[1]);
-      for (j = 2; j < 8; j++)
-	grub_snprintf (guidbuf + grub_strlen (guidbuf),
-		       sizeof (guidbuf) - grub_strlen (guidbuf),
-		       "%02x", guid.data4[j]);
+      grub_snprintf (guidbuf, sizeof (guidbuf), "%pG", &guid);
+
       /* For some reason GUID has to be in uppercase. */
       for (j = 0; guidbuf[j] ; j++)
 	if (guidbuf[j] >= 'a' && guidbuf[j] <= 'f')
Signature · 1 line
2.40.1
#50 lore raw

PATCH v9 5/11 types.h: Add GRUB_SSIZE_MAX

In reply to Oliver Steffen

In the same way as GRUB_SIZE_MAX, add GRUB_SSIZE_MAX.

---
 include/grub/types.h | 2 ++
 1 file changed, 2 insertions(+)
include/grub/types.h +2 -0
index c56ce9820..9f43a5580 100644
@@ -122,6 +122,7 @@ typedef grub_uint64_t	grub_size_t;
 typedef grub_int64_t	grub_ssize_t;
 
 # define GRUB_SIZE_MAX 18446744073709551615UL
+# define GRUB_SSIZE_MAX 9223372036854775807L
 
 # if GRUB_CPU_SIZEOF_LONG == 8
 #  define PRIxGRUB_SIZE	 "lx"
@@ -140,6 +141,7 @@ typedef grub_uint32_t	grub_size_t;
 typedef grub_int32_t	grub_ssize_t;
 
 # define GRUB_SIZE_MAX 4294967295UL
+# define GRUB_SSIZE_MAX 2147483647L
 
 # define PRIxGRUB_SIZE	"x"
 # define PRIxGRUB_ADDR	"x"
Signature · 1 line
2.40.1
#51 lore raw

PATCH v9 6/11 kern/misc, kern/efi: Extract UTF-8 to UTF-16 code

In reply to Oliver Steffen

Create a new function for UTF-8 to UTF-16 conversion called grub_utf8_to_utf16_alloc() in the grub-code/kern/misc.c and replace charset conversion code used in some places in the EFI code. It is modeled after the grub_utf8_to_ucs4_alloc() like functions in charset.h. It can't live in charset.h, because it needs to be reachable from the kern/efi code.

Add a check for integer overflow and remove redundant NUL-termination.

---
 grub-core/kern/efi/efi.c | 21 ++++++---------------
 grub-core/kern/misc.c    | 32 ++++++++++++++++++++++++++++++++
 include/grub/misc.h      |  3 +++
 3 files changed, 41 insertions(+), 15 deletions(-)
grub-core/kern/efi/efi.c +6 -15
index 394523d0a..0583a7b5c 100644
@@ -209,15 +209,11 @@ grub_efi_set_variable_with_attributes (const char *var, const grub_guid_t *guid,
   grub_efi_status_t status;
   grub_efi_runtime_services_t *r;
   grub_efi_char16_t *var16;
-  grub_size_t len, len16;
 
-  len = grub_strlen (var);
-  len16 = len * GRUB_MAX_UTF16_PER_UTF8;
-  var16 = grub_calloc (len16 + 1, sizeof (var16[0]));
-  if (!var16)
+  grub_utf8_to_utf16_alloc (var, &var16, NULL);
+
+  if (var16 == NULL)
     return grub_errno;
-  len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);
-  var16[len16] = 0;
 
   r = grub_efi_system_table->runtime_services;
 
@@ -251,18 +247,13 @@ grub_efi_get_variable_with_attributes (const char *var,
   grub_efi_runtime_services_t *r;
   grub_efi_char16_t *var16;
   void *data;
-  grub_size_t len, len16;
 
   *data_out = NULL;
   *datasize_out = 0;
 
-  len = grub_strlen (var);
-  len16 = len * GRUB_MAX_UTF16_PER_UTF8;
-  var16 = grub_calloc (len16 + 1, sizeof (var16[0]));
-  if (!var16)
-    return GRUB_EFI_OUT_OF_RESOURCES;
-  len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL);
-  var16[len16] = 0;
+  grub_utf8_to_utf16_alloc (var, &var16, NULL);
+  if (var16 == NULL)
+    return grub_errno;
 
   r = grub_efi_system_table->runtime_services;
 
grub-core/kern/misc.c +32 -0
index 22b7dca42..977535282 100644
@@ -25,6 +25,7 @@
 #include <grub/env.h>
 #include <grub/i18n.h>
 #include <grub/types.h>
+#include <grub/charset.h>
 
 union printf_arg
 {
@@ -1318,6 +1319,37 @@ grub_fatal (const char *fmt, ...)
   grub_abort ();
 }
 
+grub_ssize_t
+grub_utf8_to_utf16_alloc (const char *str8, grub_uint16_t **utf16_msg, grub_uint16_t **last_position)
+{
+  grub_size_t len;
+  grub_size_t len16;
+
+  len = grub_strlen (str8);
+
+  /* Check for integer overflow */
+  if (len > GRUB_SSIZE_MAX / GRUB_MAX_UTF16_PER_UTF8 - 1)
+    {
+      grub_error (GRUB_ERR_BAD_ARGUMENT, N_("string too long"));
+      *utf16_msg = NULL;
+      return -1;
+    }
+
+  len16 = len * GRUB_MAX_UTF16_PER_UTF8;
+
+  *utf16_msg = grub_calloc (len16 + 1, sizeof (*utf16_msg[0]));
+  if (*utf16_msg == NULL)
+    return -1;
+
+  len16 = grub_utf8_to_utf16 (*utf16_msg, len16, (grub_uint8_t *) str8, len, NULL);
+
+  if (last_position != NULL)
+    *last_position = *utf16_msg + len16;
+
+  return len16;
+}
+
+
 #if BOOT_TIME_STATS
 
 #include <grub/time.h>
include/grub/misc.h +3 -0
index 6c9d56de9..1b35a167f 100644
@@ -529,4 +529,7 @@ void EXPORT_FUNC(grub_real_boot_time) (const char *file,
 
 #define grub_log2ull(n) (GRUB_TYPE_BITS (grub_uint64_t) - __builtin_clzll (n) - 1)
 
+grub_ssize_t
+EXPORT_FUNC(grub_utf8_to_utf16_alloc) (const char *str8, grub_uint16_t **utf16_msg, grub_uint16_t **last_position);
+
 #endif /* ! GRUB_MISC_HEADER */
Signature · 1 line
2.40.1
#52 lore raw

PATCH v9 7/11 efi: Add grub_efi_set_variable_to_string()

In reply to Oliver Steffen

Add a function that sets an EFI variable to a string value. The string is converted from UTF-8 to UTF-16.

---
 grub-core/kern/efi/efi.c | 22 ++++++++++++++++++++++
 include/grub/efi/efi.h   |  3 +++
 2 files changed, 25 insertions(+)
grub-core/kern/efi/efi.c +22 -0
index 0583a7b5c..6b0aef115 100644
@@ -286,6 +286,28 @@ grub_efi_get_variable_with_attributes (const char *var,
   return status;
 }
 
+grub_err_t
+grub_efi_set_variable_to_string (const char *name, const grub_guid_t *guid,
+			         const char *value, grub_efi_uint32_t attributes)
+{
+  grub_efi_char16_t *value_16;
+  grub_ssize_t len16;
+  grub_err_t status;
+
+  len16 = grub_utf8_to_utf16_alloc (value, &value_16, NULL);
+
+  if (len16 < 0)
+    return grub_errno;
+
+  status = grub_efi_set_variable_with_attributes (name, guid,
+			(void *) value_16, (len16 + 1) * sizeof (value_16[0]),
+			attributes);
+
+  grub_free (value_16);
+
+  return status;
+}
+
 grub_efi_status_t
 grub_efi_get_variable (const char *var, const grub_guid_t *guid,
 		       grub_size_t *datasize_out, void **data_out)
include/grub/efi/efi.h +3 -0
index 3d056a0a4..cd977cbbc 100644
@@ -108,6 +108,9 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,
 				     const grub_guid_t *guid,
 				     void *data,
 				     grub_size_t datasize);
+grub_err_t
+EXPORT_FUNC (grub_efi_set_variable_to_string) (const char *name, const grub_guid_t *guid,
+					       const char *value, grub_efi_uint32_t attributes);
 int
 EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
 					     const grub_efi_device_path_t *dp2);
Signature · 1 line
2.40.1
#53 lore raw

PATCH v9 8/11 docs: Reword section headings

In reply to Oliver Steffen

Reword some section headings, remove "The List of" from titles. While grammatically correct, this phrase can be omitted to increase readability, especially in the table of contents.

---
 docs/grub.texi | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
docs/grub.texi +10 -10
index 41167519d..8c43693d9 100644
@@ -96,12 +96,12 @@ This edition documents version @value{VERSION}.
 * Filesystem::                  Filesystem syntax and semantics
 * Interface::                   The menu and the command-line
 * Environment::                 GRUB environment variables
-* Commands::                    The list of available builtin commands
+* Commands::                    Available builtin commands
 * Internationalisation::        Topics relating to language support
 * Security::                    Authentication, authorisation, and signatures
-* Platform limitations::        The list of platform-specific limitations
+* Platform limitations::        Platform-specific limitations
 * Platform-specific operations:: Platform-specific operations
-* Supported kernels::           The list of supported kernels
+* Supported kernels::           Supported kernels
 * Troubleshooting::             Error messages produced by GRUB
 * Invoking grub-install::       How to use the GRUB installer
 * Invoking grub-mkconfig::      Generate a GRUB configuration file
@@ -3869,7 +3869,7 @@ using BIOS or EFI functions (no ATA, USB or IEEE1275).
 
 
 @node Commands
-@chapter The list of available commands
+@chapter Available commands
 
 In this chapter, we list all commands that are available in GRUB.
 
@@ -3895,7 +3895,7 @@ shell}.
 
 
 @node Menu-specific commands
-@section The list of commands for the menu only
+@section Commands for the menu only
 
 The semantics used in parsing the configuration file are the following:
 
@@ -3976,7 +3976,7 @@ All options are the same as in the @command{menuentry} command
 
 
 @node Loader commands
-@section The list of various loader commands
+@section Various loader commands
 
 These commands are used to load necessary components to boot desired OS.
 Many of the loader commands are not sufficiently documented. The following is
@@ -4127,7 +4127,7 @@ This command is only available on AArch64 systems.
 
 
 @node General commands
-@section The list of general commands
+@section General commands
 
 Commands usable anywhere in the menu and in the command-line.
 
@@ -4262,7 +4262,7 @@ printed.
 
 
 @node Command-line commands
-@section The list of command-line commands
+@section Command-line commands
 
 These commands are usable in the command-line and in menu entries.  If
 you forget a command, you can run the command @command{help}
@@ -5843,7 +5843,7 @@ Note: The command is not allowed when lockdown is enforced (@pxref{Lockdown}).
 @end deffn
 
 @node Networking commands
-@section The list of networking commands
+@section Networking commands
 
 @menu
 * net_add_addr::                Add a network address
@@ -6058,7 +6058,7 @@ net_set_vlan efinet1 0
 
 
 @node Undocumented commands
-@section The list of commands currently undocumented
+@section Commands currently undocumented
 Unfortunately, not all GRUB commands are documented at this time due to
 developer resource constraints. One way to contribute back to the GRUB
 project would be to help document these commands, and submit patches or
Signature · 1 line
2.40.1
#54 lore raw

PATCH v9 9/11 kern: check for NULL when closing devices and disks

In reply to Oliver Steffen

Add checks for NULL pointers to grub_device_close() and grub_disk_close() to make these functions more robust.

---
 grub-core/kern/device.c | 3 +++
 grub-core/kern/disk.c   | 4 ++++
 2 files changed, 7 insertions(+)
grub-core/kern/device.c +3 -0
index 92ce8a75e..670e213cf 100644
@@ -71,6 +71,9 @@ grub_device_open (const char *name)
 grub_err_t
 grub_device_close (grub_device_t device)
 {
+  if (device == NULL)
+    return GRUB_ERR_NONE;
+
   if (device->disk)
     grub_disk_close (device->disk);
 
grub-core/kern/disk.c +4 -0
index eb0c7bb73..1eda58fe9 100644
@@ -292,6 +292,10 @@ void
 grub_disk_close (grub_disk_t disk)
 {
   grub_partition_t part;
+
+  if (disk == NULL)
+    return;
+
   grub_dprintf ("disk", "Closing `%s'.\n", disk->name);
 
   if (disk->dev && disk->dev->disk_close)
Signature · 1 line
2.40.1
#55 lore raw

PATCH v9 10/11 Add a module for the Boot Loader Interface

In reply to Oliver Steffen

Add a new module named bli. It implements a small but quite useful part of the Boot Loader Interface [0]. This interface uses EFI variables for communication between the boot loader and the operating system.

When loaded, this module sets two EFI variables under the vendor GUID 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:

- LoaderInfo: contains GRUB + <version number>.
This allows the running operating system to identify the boot loader used during boot.

- LoaderDevicePartUUID: contains the partition UUID of the EFI System Partition (ESP). This is used by systemd-gpt-auto-generator [1] to find the root partitions (and others too), via partition type IDs [2].

This module is available on EFI platforms only. bli relies on the part_gpt module which has to be loaded beforehand to make the GPT partitions discoverable.

Update the documentation, add a new chapter "Modules" and describe the bli module there.

[0] https://systemd.io/BOOT_LOADER_INTERFACE/
[1] https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
[2] https://uapi-group.org/specifications/specs/discoverable_partitions_specification/

---
 docs/grub.texi              |  23 +++++++
 grub-core/Makefile.core.def |   6 ++
 grub-core/commands/bli.c    | 122 ++++++++++++++++++++++++++++++++++++
 include/grub/efi/api.h      |   5 ++
 4 files changed, 156 insertions(+)
 create mode 100644 grub-core/commands/bli.c
docs/grub.texi +23 -0
index 8c43693d9..f6c828d46 100644
@@ -96,6 +96,7 @@ This edition documents version @value{VERSION}.
 * Filesystem::                  Filesystem syntax and semantics
 * Interface::                   The menu and the command-line
 * Environment::                 GRUB environment variables
+* Modules::                     Available modules
 * Commands::                    Available builtin commands
 * Internationalisation::        Topics relating to language support
 * Security::                    Authentication, authorisation, and signatures
@@ -3867,6 +3868,28 @@ using BIOS or EFI functions (no ATA, USB or IEEE1275).
 @command{grub-mkconfig} uses this facility to implement
 @samp{GRUB_SAVEDEFAULT} (@pxref{Simple configuration}).
 
+@node Modules
+@chapter Modules
+
+In this chapter, we list all modules that are available in GRUB (currently incomplete).
+
+Modules can be loaded via the @command{insmod} (@pxref{insmod}) command.
+
+@menu
+* bli::
+@end menu
+
+@node bli
+@section bli
+This module provides basic support for the Boot Loader Interface. The Boot
+Loader Interface specifies a set of EFI variables that are used to communicate
+boot-time information between the boot loader and the operating system.
+
+When loaded, the bli module publishes the GPT partition UUID of the EFI System
+Partition used during boot and a string identifying GRUB as the active boot
+loader, including the version number.
+
+This module is only available on UEFI platforms.
 
 @node Commands
 @chapter Available commands
grub-core/Makefile.core.def +6 -0
index 04549e868..a8c0c4a52 100644
@@ -2580,3 +2580,9 @@ module = {
   common = commands/memtools.c;
   condition = COND_MM_DEBUG;
 };
+
+module = {
+  name = bli;
+  efi = commands/bli.c;
+  enable = efi;
+};
grub-core/commands/bli.c new file +122 -0

122 lines not on this page · raw message

include/grub/efi/api.h +5 -0
index c0b6e86f1..16161e1f0 100644
@@ -374,6 +374,11 @@
     { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \
   }
 
+#define GRUB_EFI_VENDOR_BOOT_LOADER_INTERFACE_GUID \
+  { 0x4a67b082, 0x0a4c, 0x41cf, \
+    {0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f } \
+  }
+
 struct grub_efi_sal_system_table
 {
   grub_uint32_t signature;
Signature · 1 line
2.40.1
#56 lore raw

PATCH v9 11/11 util/grub.d: Activate bli module on EFI

In reply to Oliver Steffen

Add a new configuration drop-in file that loads the bli module and runs the command if booting on the EFI platform.

---
 Makefile.util.def     |  6 ++++++
 util/grub.d/25_bli.in | 24 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 util/grub.d/25_bli.in
Makefile.util.def +6 -0
index fdbd58c8f..1e9a13d3e 100644
@@ -511,6 +511,12 @@ script = {
   condition = COND_HOST_LINUX;
 };
 
+script = {
+  name = '25_bli';
+  common = util/grub.d/25_bli.in;
+  installdir = grubconf;
+};
+
 script = {
   name = '30_os-prober';
   common = util/grub.d/30_os-prober.in;
util/grub.d/25_bli.in new file +24 -0
new file mode 100644
index 000000000..6e4538716
@@ -0,0 +1,24 @@
+#!/usr/bin/sh
+set -e
+
+# grub-mkconfig helper script.
+# Copyright (C) 2023  Free Software Foundation, Inc.
+#
+# GRUB is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# GRUB is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+
+cat << EOF
+if [ "\$grub_platform" = "efi" ]; then
+  insmod bli
+fi
+EOF
Signature · 1 line
2.40.1
#57 lore raw
In reply to Oliver Steffen
Quoted 145 lines · Oliver Steffen

This is a step towards supporting unified kernel images (UKI) in Grub.

Add a new module named bli. It implements a small but quite useful part of the Boot Loader Interface [0]. This interface uses EFI variables for communication between the boot loader and the operating system.

This module sets two EFI variables under the vendor GUID 4a67b082-0a4c-41cf-b6c7-440b29bb8c4f:

- LoaderInfo: contains GRUB + <version number>.
This allows the running operating system to identify the boot loader used during boot.

- LoaderDevicePartUUID: contains the partition UUID of the EFI System Partition (ESP). This is used by systemd-gpt-auto-generator [1] to find the root partitions (and others too), via partition type IDs [2]. This is especially useful for UKIs, where the kernel command line is fixed and usually does not contain any information about the root partition.

This module is only available on EFI platforms.

This series also unifies the GUID implementations and introduces a printf format specifier for them: %pG.

[0] https://systemd.io/BOOT_LOADER_INTERFACE/
[1] https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
[2] https://uapi-group.org/specifications/specs/discoverable_partitions_specification/

v9:
- Rebase to latest master branch
- Fix error handling in bli.c: get_part_uuid()
And with that fix the NULL pointer issue discovered by Coverity
- Add NULL checks to grub_device_close() and grub_disk_close() These are not strictly needed anymore with the changed error handling in get_part_uuid().
I leave the fate of this patch at the maintainer's discretion.

v8:
- https://mail.gnu.org/archive/html/grub-devel/2023-05/msg00128.html
- Rebase to latest master branch
- Fix the documentation build (I hope)
- Fix build on arm
- Make more grub_guid instances 'static'
- Move endian conversion back out of the grub_guid printf code

v7:
- https://mail.gnu.org/archive/html/grub-devel/2023-05/msg00005.html
- Add a "Modules" chapter to the documentation and describe the bli module there
- Reword some section headings in the documentation

v6:
- https://mail.gnu.org/archive/html/grub-devel/2023-04/msg00068.html
- Initialize the Boot Loader Interface on module load and remove the bli command.
- Extract code for grub_efi_set_variable_to_string()
- Improve error messages in the bli module
- Improve GUID printing code

v5:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00120.html
- Replace more grub_*_guid with the new grub_guid struct

v4:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00058.html
- Place grub_utf8_to_utf16_alloc() in kern/misc.c and use it in kern/efi.c
- bli: rework partition GUID code, improve error reporting
- Add documentation for the bli module
- Address other comments

v3:
- https://mail.gnu.org/archive/html/grub-devel/2023-03/msg00008.html
- Unify GUID implementations for GPT and EFI
- Add printf format specifier for GUIDs, drop guid print function from v2.
- WIP/Please comment: Started extracting utf8->utf16 code. Where should this go?
- Address other comments

v2:
- https://mail.gnu.org/archive/html/grub-devel/2023-02/msg00099.html
- Addressed comments from Daniel
- Added a print function for gpt guids`
- Added integer overflow check in UTF16 conversion
- Added config drop-in file that loads the module on EFI

v1:
- https://mail.gnu.org/archive/html/grub-devel/2023-01/msg00104.html

Oliver Steffen (11):
efi: Add grub_efi_set_variable_with_attributes() Unify GUID types
kern/misc: Add a format specifier GUIDs
grub-core: Make use of guid printf format specifier types.h: Add GRUB_SSIZE_MAX
kern/misc, kern/efi: Extract UTF-8 to UTF-16 code
efi: Add grub_efi_set_variable_to_string()
docs: Reword section headings
kern: check for NULL when closing devices and disks Add a module for the Boot Loader Interface util/grub.d: Activate bli module on EFI

 Makefile.util.def                    |   6 ++
 docs/grub.texi                       |  43 +++++++---
 grub-core/Makefile.core.def          |   6 ++
 grub-core/commands/acpi.c            |   4 +-
 grub-core/commands/bli.c             | 122 +++++++++++++++++++++++++++
 grub-core/commands/efi/efifwsetup.c  |   4 +-
 grub-core/commands/efi/loadbios.c    |  14 +--
 grub-core/commands/efi/lsefi.c       |  17 +---
 grub-core/commands/efi/lsefisystab.c |  10 +--
 grub-core/commands/efi/lssal.c       |   4 +-
 grub-core/commands/efi/smbios.c      |  12 +--
 grub-core/commands/efi/tpm.c         |   6 +-
 grub-core/commands/probe.c           |  14 ++-
 grub-core/disk/efi/efidisk.c         |   4 +-
 grub-core/disk/ldm.c                 |   2 +-
 grub-core/efiemu/i386/pc/cfgtables.c |   6 +-
 grub-core/efiemu/main.c              |   4 +-
 grub-core/efiemu/runtime/efiemu.c    |  14 +--
 grub-core/kern/device.c              |   3 +
 grub-core/kern/disk.c                |   4 +
 grub-core/kern/efi/acpi.c            |  12 +--
 grub-core/kern/efi/efi.c             | 109 ++++++++++++------------
 grub-core/kern/efi/fdt.c             |   2 +-
 grub-core/kern/efi/init.c            |   2 +-
 grub-core/kern/efi/sb.c              |   4 +-
 grub-core/kern/misc.c                | 113 ++++++++++++++++++++-----
 grub-core/loader/efi/fdt.c           |   2 +-
 grub-core/loader/efi/linux.c         |   4 +-
 grub-core/loader/i386/xnu.c          |  13 +--
 grub-core/loader/ia64/efi/linux.c    |   2 +-
 grub-core/net/drivers/efi/efinet.c   |   4 +-
 grub-core/partmap/gpt.c              |   4 +-
 grub-core/term/efi/console.c         |   2 +-
 grub-core/term/efi/serial.c          |   2 +-
 grub-core/video/efi_gop.c            |   8 +-
 grub-core/video/efi_uga.c            |   2 +-
 include/grub/efi/api.h               |  69 ++++++---------
 include/grub/efi/efi.h               |  23 +++--
 include/grub/efiemu/efiemu.h         |  10 +--
 include/grub/efiemu/runtime.h        |   2 +-
 include/grub/gpt_partition.h         |  13 +--
Quoted 8 lines
 include/grub/misc.h                  |   3 +
 include/grub/types.h                 |  11 +++
 util/grub-install.c                  |   2 +-
 util/grub-probe.c                    |   2 +-
 util/grub.d/25_bli.in                |  24 ++++++
 46 files changed, 487 insertions(+), 256 deletions(-)
 create mode 100644 grub-core/commands/bli.c
 create mode 100644 util/grub.d/25_bli.in

For all the patches Reviewed-by: Daniel Kiper <[email protected]>...

Thank you for adding this feature!

Daniel