Skip to contentSkip to conversation

smbios: Deal with tables beyond 4GB

PATCH Superseded Simon Glass 5 participants 25 messages Dec 27, 2023 – Dec 31, 2023

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover smbios: Deal with tables beyond 4GB

When the malloc() region extends beyond 4GB on ARM we may end up with an SMBIOS table in that region.

Add support for writing an SMBIOS3 table, which supports a 64-bit address.

Note that this problem does not happen on x86 since it requires the tables to be placed just below 1MB in memory, unless CONFIG_BLOBLIST_TABLES is enabled.

Changes in v4:
- Bring in this patch from Heinrich's series
- Check the start of the table rather than the end

Changes in v2:
- Check the end of the table rather than the start.
- Add a new patch to correct gd_smbios_start()
- Add a note about why unmap_system() is called

Heinrich Schuchardt (1):
smbios: SMBIOS 3.0 (64-bit) Entry Point structure

Simon Glass (6):
smbios: Refactor 32-bit code into an else statement
smbios: Move the rest of the SMBIOS2 code
smbios: Use SMBIOS 3.0 to support an address above 4GB
smbios: Correct gd_smbios_start()
efi: Use the correct GUID for the SMBIOS table
smbios: Require the caller to align the SMBIOS table

 include/asm-generic/global_data.h |  2 +-
 include/efi_api.h                 |  4 ++
 include/smbios.h                  | 37 ++++++++++++--
 lib/efi_loader/efi_smbios.c       | 14 +++--
 lib/smbios.c                      | 85 +++++++++++++++++++------------
 5 files changed, 101 insertions(+), 41 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/7 smbios: Refactor 32-bit code into an else statement

In preparation for adding support for SMBIOS3 move this code into an else statement. There is no functional change.

---

(no changes since v1)

 lib/smbios.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
lib/smbios.c +21 -17
index 45480b01af4..b417f8a9057 100644
@@ -589,14 +589,6 @@ ulong write_smbios_table(ulong addr)
 		len += tmp;
 	}
 
-	memcpy(se->anchor, "_SM_", 4);
-	se->length = sizeof(struct smbios_entry);
-	se->major_ver = SMBIOS_MAJOR_VER;
-	se->minor_ver = SMBIOS_MINOR_VER;
-	se->max_struct_size = max_struct_size;
-	memcpy(se->intermediate_anchor, "_DMI_", 5);
-	se->struct_table_length = len;
-
 	/*
 	 * We must use a pointer here so things work correctly on sandbox. The
 	 * user of this table is not aware of the mapping of addresses to
@@ -612,16 +604,28 @@ ulong write_smbios_table(ulong addr)
 		       (unsigned long long)table_addr);
 		addr = 0;
 		goto out;
+	} else {
+		memcpy(se->anchor, "_SM_", 4);
+		se->length = sizeof(struct smbios_entry);
+		se->major_ver = SMBIOS_MAJOR_VER;
+		se->minor_ver = SMBIOS_MINOR_VER;
+		se->max_struct_size = max_struct_size;
+		memcpy(se->intermediate_anchor, "_DMI_", 5);
+		se->struct_table_length = len;
+
+		se->struct_table_address = table_addr;
+
+		se->struct_count = handle;
+
+		/* calculate checksums */
+		istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
+		isize = sizeof(struct smbios_entry) -
+			SMBIOS_INTERMEDIATE_OFFSET;
+		se->intermediate_checksum = table_compute_checksum(istart,
+								   isize);
+		se->checksum = table_compute_checksum(se,
+					      sizeof(struct smbios_entry));
 	}
-	se->struct_table_address = table_addr;
-
-	se->struct_count = handle;
-
-	/* calculate checksums */
-	istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
-	isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET;
-	se->intermediate_checksum = table_compute_checksum(istart, isize);
-	se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry));
 out:
 	unmap_sysmem(se);
 
Signature · 1 line
2.34.1
Reviewed-by on v4 1/7
#2 lore raw

Re: [PATCH v4 1/7] smbios: Refactor 32-bit code into an else statement

Quoted 71 lines · Simon Glass

In preparation for adding support for SMBIOS3 move this code into an else statement. There is no functional change.

---

(no changes since v1)

 lib/smbios.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
lib/smbios.c +21 -18
index 45480b01af4..b417f8a9057 100644
@@ -589,14 +589,6 @@ ulong write_smbios_table(ulong addr)
                len += tmp;
        }
 
-       memcpy(se->anchor, "_SM_", 4);
-       se->length = sizeof(struct smbios_entry);
-       se->major_ver = SMBIOS_MAJOR_VER;
-       se->minor_ver = SMBIOS_MINOR_VER;
-       se->max_struct_size = max_struct_size;
-       memcpy(se->intermediate_anchor, "_DMI_", 5);
-       se->struct_table_length = len;
-
        /*
         * We must use a pointer here so things work correctly on sandbox. The
         * user of this table is not aware of the mapping of addresses to
@@ -612,16 +604,28 @@ ulong write_smbios_table(ulong addr)
                       (unsigned long long)table_addr);
                addr = 0;
                goto out;
+       } else {
+               memcpy(se->anchor, "_SM_", 4);
+               se->length = sizeof(struct smbios_entry);
+               se->major_ver = SMBIOS_MAJOR_VER;
+               se->minor_ver = SMBIOS_MINOR_VER;
+               se->max_struct_size = max_struct_size;
+               memcpy(se->intermediate_anchor, "_DMI_", 5);
+               se->struct_table_length = len;
+
+               se->struct_table_address = table_addr;
+
+               se->struct_count = handle;
+
+               /* calculate checksums */
+               istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
+               isize = sizeof(struct smbios_entry) -
+                       SMBIOS_INTERMEDIATE_OFFSET;
+               se->intermediate_checksum = table_compute_checksum(istart,
+                                                                  isize);
+               se->checksum = table_compute_checksum(se,
+                                             sizeof(struct smbios_entry));
        }
-       se->struct_table_address = table_addr;
-
-       se->struct_count = handle;
-
-       /* calculate checksums */
-       istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
-       isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET;
-       se->intermediate_checksum = table_compute_checksum(istart, isize);
-       se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry));
 out:
        unmap_sysmem(se);
 
--
Quoted 2 lines

2.34.1

#3 lore raw

PATCH v4 2/7 smbios: Move the rest of the SMBIOS2 code

In reply to Simon Glass

Move all of this logic into the else clause, since it will not be used for SMBIOS3

---

(no changes since v1)

 lib/smbios.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/smbios.c +7 -8
index b417f8a9057..eea72670bd9 100644
@@ -544,9 +544,8 @@ static struct smbios_write_method smbios_write_funcs[] = {
 ulong write_smbios_table(ulong addr)
 {
 	ofnode parent_node = ofnode_null();
-	struct smbios_entry *se;
+	ulong table_addr, start_addr;
 	struct smbios_ctx ctx;
-	ulong table_addr;
 	ulong tables;
 	int len = 0;
 	int max_struct_size = 0;
@@ -566,9 +565,7 @@ ulong write_smbios_table(ulong addr)
 
 	/* 16 byte align the table address */
 	addr = ALIGN(addr, 16);
-
-	se = map_sysmem(addr, sizeof(struct smbios_entry));
-	memset(se, 0, sizeof(struct smbios_entry));
+	start_addr = addr;
 
 	addr += sizeof(struct smbios_entry);
 	addr = ALIGN(addr, 16);
@@ -603,8 +600,11 @@ ulong write_smbios_table(ulong addr)
 		printf("WARNING: SMBIOS table_address overflow %llx\n",
 		       (unsigned long long)table_addr);
 		addr = 0;
-		goto out;
 	} else {
+		struct smbios_entry *se;
+
+		se = map_sysmem(start_addr, sizeof(struct smbios_entry));
+		memset(se, '\0', sizeof(struct smbios_entry));
 		memcpy(se->anchor, "_SM_", 4);
 		se->length = sizeof(struct smbios_entry);
 		se->major_ver = SMBIOS_MAJOR_VER;
@@ -625,9 +625,8 @@ ulong write_smbios_table(ulong addr)
 								   isize);
 		se->checksum = table_compute_checksum(se,
 					      sizeof(struct smbios_entry));
+		unmap_sysmem(se);
 	}
-out:
-	unmap_sysmem(se);
 
 	return addr;
 }
Signature · 1 line
2.34.1
Reviewed-by on v4 2/7
#4 lore raw

Re: [PATCH v4 2/7] smbios: Move the rest of the SMBIOS2 code

Quoted 64 lines · Simon Glass

Move all of this logic into the else clause, since it will not be used for SMBIOS3

---

(no changes since v1)

 lib/smbios.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
lib/smbios.c +7 -9
index b417f8a9057..eea72670bd9 100644
@@ -544,9 +544,8 @@ static struct smbios_write_method smbios_write_funcs[] = {
 ulong write_smbios_table(ulong addr)
 {
        ofnode parent_node = ofnode_null();
-       struct smbios_entry *se;
+       ulong table_addr, start_addr;
        struct smbios_ctx ctx;
-       ulong table_addr;
        ulong tables;
        int len = 0;
        int max_struct_size = 0;
@@ -566,9 +565,7 @@ ulong write_smbios_table(ulong addr)
 
        /* 16 byte align the table address */
        addr = ALIGN(addr, 16);
-
-       se = map_sysmem(addr, sizeof(struct smbios_entry));
-       memset(se, 0, sizeof(struct smbios_entry));
+       start_addr = addr;
 
        addr += sizeof(struct smbios_entry);
        addr = ALIGN(addr, 16);
@@ -603,8 +600,11 @@ ulong write_smbios_table(ulong addr)
                printf("WARNING: SMBIOS table_address overflow %llx\n",
                       (unsigned long long)table_addr);
                addr = 0;
-               goto out;
        } else {
+               struct smbios_entry *se;
+
+               se = map_sysmem(start_addr, sizeof(struct smbios_entry));
+               memset(se, '\0', sizeof(struct smbios_entry));
                memcpy(se->anchor, "_SM_", 4);
                se->length = sizeof(struct smbios_entry);
                se->major_ver = SMBIOS_MAJOR_VER;
@@ -625,9 +625,8 @@ ulong write_smbios_table(ulong addr)
                                                                   isize);
                se->checksum = table_compute_checksum(se,
                                              sizeof(struct smbios_entry));
+               unmap_sysmem(se);
        }
-out:
-       unmap_sysmem(se);
 
        return addr;
 }
--
Quoted 2 lines

2.34.1

#5 lore raw

PATCH v4 3/7 smbios: SMBIOS 3.0 (64-bit) Entry Point structure

In reply to Simon Glass

From: Heinrich Schuchardt <[email protected]>

Add definition of the SMBIOS 3.0 (64-bit) Entry Point structure.

---

Changes in v4:
- Bring in this patch from Heinrich's series

 include/smbios.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
include/smbios.h +26 -0
index c9df2706f5a..e601283d293 100644
@@ -54,6 +54,32 @@ struct __packed smbios_entry {
 	u8 bcd_rev;
 };
 
+/**
+ * struct smbios3_entry - SMBIOS 3.0 (64-bit) Entry Point structure
+ */
+struct __packed smbios3_entry {
+	/** @anchor: anchor string */
+	u8 anchor[5];
+	/** @checksum: checksum of the entry point structure */
+	u8 checksum;
+	/** @length: length of the entry point structure */
+	u8 length;
+	/** @major_ver: major version of the SMBIOS specification */
+	u8 major_ver;
+	/** @minor_ver: minor version of the SMBIOS specification */
+	u8 minor_ver;
+	/** @docrev: revision of the SMBIOS specification */
+	u8 doc_rev;
+	/** @entry_point_rev: revision of the entry point structure */
+	u8 entry_point_rev;
+	/** @reserved: reserved */
+	u8 reserved;
+	/** maximum size of SMBIOS table */
+	u32 max_struct_size;
+	/** @struct_table_address: 64-bit physical starting address */
+	u64 struct_table_address;
+};
+
 /* BIOS characteristics */
 #define BIOS_CHARACTERISTICS_PCI_SUPPORTED	(1 << 7)
 #define BIOS_CHARACTERISTICS_UPGRADEABLE	(1 << 11)
Signature · 1 line
2.34.1
Reviewed-by on v4 3/7
#6 lore raw

Re: [PATCH v4 3/7] smbios: SMBIOS 3.0 (64-bit) Entry Point structure

Quoted 55 lines · Simon Glass

From: Heinrich Schuchardt <[email protected]>

Add definition of the SMBIOS 3.0 (64-bit) Entry Point structure.

---

Changes in v4:
- Bring in this patch from Heinrich's series

 include/smbios.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
include/smbios.h +26 -1
index c9df2706f5a..e601283d293 100644
@@ -54,6 +54,32 @@ struct __packed smbios_entry {
        u8 bcd_rev;
 };
 
+/**
+ * struct smbios3_entry - SMBIOS 3.0 (64-bit) Entry Point structure
+ */
+struct __packed smbios3_entry {
+       /** @anchor: anchor string */
+       u8 anchor[5];
+       /** @checksum: checksum of the entry point structure */
+       u8 checksum;
+       /** @length: length of the entry point structure */
+       u8 length;
+       /** @major_ver: major version of the SMBIOS specification */
+       u8 major_ver;
+       /** @minor_ver: minor version of the SMBIOS specification */
+       u8 minor_ver;
+       /** @docrev: revision of the SMBIOS specification */
+       u8 doc_rev;
+       /** @entry_point_rev: revision of the entry point structure */
+       u8 entry_point_rev;
+       /** @reserved: reserved */
+       u8 reserved;
+       /** maximum size of SMBIOS table */
+       u32 max_struct_size;
+       /** @struct_table_address: 64-bit physical starting address */
+       u64 struct_table_address;
+};
+
 /* BIOS characteristics */
 #define BIOS_CHARACTERISTICS_PCI_SUPPORTED     (1 << 7)
 #define BIOS_CHARACTERISTICS_UPGRADEABLE       (1 << 11)
--
Quoted 2 lines

2.34.1

#7 lore raw

PATCH v4 4/7 smbios: Use SMBIOS 3.0 to support an address above 4GB

In reply to Simon Glass

When the SMBIOS table is written to an address above 4GB a 32-bit table address is not large enough.

Use an SMBIOS3 table in that case.

Note that we cannot use efi_allocate_pages() since this function has nothing to do with EFI. There is no equivalent function to allocate memory below 4GB in U-Boot. One solution would be to create a separate malloc() pool, or just always put the malloc() pool below 4GB.

- Use log_debug() for warning
- Rebase on Heinrich's smbios.h patch
- Set the checksum for SMBIOS3

---

Changes in v4:
- Check the start of the table rather than the end

Changes in v2:
- Check the end of the table rather than the start.

 include/smbios.h |  6 +++++-
 lib/smbios.c     | 30 +++++++++++++++++++++++++-----
 2 files changed, 30 insertions(+), 6 deletions(-)
include/smbios.h +5 -1
index e601283d293..77be58887a2 100644
@@ -12,7 +12,7 @@
 
 /* SMBIOS spec version implemented */
 #define SMBIOS_MAJOR_VER	3
-#define SMBIOS_MINOR_VER	0
+#define SMBIOS_MINOR_VER	7
 
 enum {
 	SMBIOS_STR_MAX	= 64,	/* Maximum length allowed for a string */
@@ -80,6 +80,10 @@ struct __packed smbios3_entry {
 	u64 struct_table_address;
 };
 
+/* These two structures should use the same amount of 16-byte-aligned space */
+static_assert(ALIGN(16, sizeof(struct smbios_entry)) ==
+	      ALIGN(16, sizeof(struct smbios3_entry)));
+
 /* BIOS characteristics */
 #define BIOS_CHARACTERISTICS_PCI_SUPPORTED	(1 << 7)
 #define BIOS_CHARACTERISTICS_UPGRADEABLE	(1 << 11)
lib/smbios.c +25 -5
index eea72670bd9..7f79d969c92 100644
@@ -567,7 +567,11 @@ ulong write_smbios_table(ulong addr)
 	addr = ALIGN(addr, 16);
 	start_addr = addr;
 
-	addr += sizeof(struct smbios_entry);
+	/*
+	 * So far we don't know which struct will be used, but they both end
+	 * up using the same amount of 16-bit-aligned space
+	 */
+	addr += max(sizeof(struct smbios_entry), sizeof(struct smbios3_entry));
 	addr = ALIGN(addr, 16);
 	tables = addr;
 
@@ -590,16 +594,32 @@ ulong write_smbios_table(ulong addr)
 	 * We must use a pointer here so things work correctly on sandbox. The
 	 * user of this table is not aware of the mapping of addresses to
 	 * sandbox's DRAM buffer.
+	 *
+	 * Check the address of the end of the tables. If it is above 4GB then
+	 * it is sensible to use SMBIOS3 even if the start of the table is below
+	 * 4GB (this case is very unlikely to happen in practice)
 	 */
 	table_addr = (ulong)map_sysmem(tables, 0);
-	if (sizeof(table_addr) > sizeof(u32) && table_addr > (ulong)UINT_MAX) {
+	if (sizeof(table_addr) > sizeof(u32) && addr >= (ulong)UINT_MAX) {
+		struct smbios3_entry *se;
 		/*
 		 * We need to put this >32-bit pointer into the table but the
 		 * field is only 32 bits wide.
 		 */
-		printf("WARNING: SMBIOS table_address overflow %llx\n",
-		       (unsigned long long)table_addr);
-		addr = 0;
+		log_debug("WARNING: Using SMBIOS3.0 due to table-address overflow %lx\n",
+			  table_addr);
+		se = map_sysmem(start_addr, sizeof(struct smbios_entry));
+		memset(se, '\0', sizeof(struct smbios_entry));
+		memcpy(se->anchor, "_SM3_", 5);
+		se->length = sizeof(struct smbios3_entry);
+		se->major_ver = SMBIOS_MAJOR_VER;
+		se->minor_ver = SMBIOS_MINOR_VER;
+		se->doc_rev = 0;
+		se->entry_point_rev = 1;
+		se->max_struct_size = len;
+		se->struct_table_address = table_addr;
+		se->checksum = table_compute_checksum(se,
+						sizeof(struct smbios3_entry));
 	} else {
 		struct smbios_entry *se;
 
Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH v4 4/7] smbios: Use SMBIOS 3.0 to support an address above 4GB

Hi Simon,

Quoted 5 lines · Simon Glass

When the SMBIOS table is written to an address above 4GB a 32-bit table address is not large enough.

Use an SMBIOS3 table in that case.

Maybe I missed this on the previous revisions, but is there a reason we don't always use SMBIOS3 now? And perhaps try to install SMBIOS2 if
1. we fail
2. and the address is < 4GB

Thanks
/Ilias

Quoted 104 lines

Note that we cannot use efi_allocate_pages() since this function has nothing to do with EFI. There is no equivalent function to allocate memory below 4GB in U-Boot. One solution would be to create a separate malloc() pool, or just always put the malloc() pool below 4GB.

- Use log_debug() for warning
- Rebase on Heinrich's smbios.h patch
- Set the checksum for SMBIOS3

---

Changes in v4:
- Check the start of the table rather than the end

Changes in v2:
- Check the end of the table rather than the start.

 include/smbios.h |  6 +++++-
 lib/smbios.c     | 30 +++++++++++++++++++++++++-----
 2 files changed, 30 insertions(+), 6 deletions(-)
include/smbios.h +5 -1
index e601283d293..77be58887a2 100644
@@ -12,7 +12,7 @@
 
 /* SMBIOS spec version implemented */
 #define SMBIOS_MAJOR_VER       3
-#define SMBIOS_MINOR_VER       0
+#define SMBIOS_MINOR_VER       7
 
 enum {
        SMBIOS_STR_MAX  = 64,   /* Maximum length allowed for a string */
@@ -80,6 +80,10 @@ struct __packed smbios3_entry {
        u64 struct_table_address;
 };
 
+/* These two structures should use the same amount of 16-byte-aligned space */
+static_assert(ALIGN(16, sizeof(struct smbios_entry)) ==
+             ALIGN(16, sizeof(struct smbios3_entry)));
+
 /* BIOS characteristics */
 #define BIOS_CHARACTERISTICS_PCI_SUPPORTED     (1 << 7)
 #define BIOS_CHARACTERISTICS_UPGRADEABLE       (1 << 11)
lib/smbios.c +25 -6
index eea72670bd9..7f79d969c92 100644
@@ -567,7 +567,11 @@ ulong write_smbios_table(ulong addr)
        addr = ALIGN(addr, 16);
        start_addr = addr;
 
-       addr += sizeof(struct smbios_entry);
+       /*
+        * So far we don't know which struct will be used, but they both end
+        * up using the same amount of 16-bit-aligned space
+        */
+       addr += max(sizeof(struct smbios_entry), sizeof(struct smbios3_entry));
        addr = ALIGN(addr, 16);
        tables = addr;
 
@@ -590,16 +594,32 @@ ulong write_smbios_table(ulong addr)
         * We must use a pointer here so things work correctly on sandbox. The
         * user of this table is not aware of the mapping of addresses to
         * sandbox's DRAM buffer.
+        *
+        * Check the address of the end of the tables. If it is above 4GB then
+        * it is sensible to use SMBIOS3 even if the start of the table is below
+        * 4GB (this case is very unlikely to happen in practice)
         */
        table_addr = (ulong)map_sysmem(tables, 0);
-       if (sizeof(table_addr) > sizeof(u32) && table_addr > (ulong)UINT_MAX) {
+       if (sizeof(table_addr) > sizeof(u32) && addr >= (ulong)UINT_MAX) {
+               struct smbios3_entry *se;
                /*
                 * We need to put this >32-bit pointer into the table but the
                 * field is only 32 bits wide.
                 */
-               printf("WARNING: SMBIOS table_address overflow %llx\n",
-                      (unsigned long long)table_addr);
-               addr = 0;
+               log_debug("WARNING: Using SMBIOS3.0 due to table-address overflow %lx\n",
+                         table_addr);
+               se = map_sysmem(start_addr, sizeof(struct smbios_entry));
+               memset(se, '\0', sizeof(struct smbios_entry));
+               memcpy(se->anchor, "_SM3_", 5);
+               se->length = sizeof(struct smbios3_entry);
+               se->major_ver = SMBIOS_MAJOR_VER;
+               se->minor_ver = SMBIOS_MINOR_VER;
+               se->doc_rev = 0;
+               se->entry_point_rev = 1;
+               se->max_struct_size = len;
+               se->struct_table_address = table_addr;
+               se->checksum = table_compute_checksum(se,
+                                               sizeof(struct smbios3_entry));
        } else {
                struct smbios_entry *se;
 
--

2.34.1

#9 lore raw

Re: [PATCH v4 4/7] smbios: Use SMBIOS 3.0 to support an address above 4GB

Hi Ilias,

Quoted 5 lines · Ilias Apalodimas

Hi Simon,

Quoted 1 line · Simon Glass
Quoted 7 lines
Quoted 4 lines

When the SMBIOS table is written to an address above 4GB a 32-bit table address is not large enough.

Use an SMBIOS3 table in that case.

Maybe I missed this on the previous revisions, but is there a reason we don't always use SMBIOS3 now?

I am not sure...there was some comment about it not being supported in some cases, so I have tried to accommodate that.

Quoted 2 lines

And perhaps try to install SMBIOS2 if
1. we fail

due to?

Quoted 1 line

2. and the address is < 4GB

We could, I suppose. Effectively we would drop generation of SMBIOS2.

I really don't mind. This whole SMBIOS thing is a bit ridiculous, if you ask me.

Regards,
Simon

#10 lore raw

Re: [PATCH v4 4/7] smbios: Use SMBIOS 3.0 to support an address above 4GB

Quoted 26 lines

From: Simon Glass <[email protected]>
Date: Thu, 28 Dec 2023 13:37:03 +0000

Hi Ilias,

Quoted 5 lines · Ilias Apalodimas

Hi Simon,

Quoted 1 line · Simon Glass
Quoted 7 lines
Quoted 4 lines

When the SMBIOS table is written to an address above 4GB a 32-bit table address is not large enough.

Use an SMBIOS3 table in that case.

Maybe I missed this on the previous revisions, but is there a reason we don't always use SMBIOS3 now?

I am not sure...there was some comment about it not being supported in some cases, so I have tried to accommodate that.

Quoted 2 lines

And perhaps try to install SMBIOS2 if
1. we fail

Quoted 8 lines

due to?

Quoted 1 line

2. and the address is < 4GB

We could, I suppose. Effectively we would drop generation of SMBIOS2.

I really don't mind. This whole SMBIOS thing is a bit ridiculous, if you ask me.

Linux added support for the SMBIOS 3.0 64-bit entry point in 2014. I doubt anyone who cares about SMBIOS cares about kernels that old.

So if it simplifies things, I'd drop support for the 32-bit SMBIOS entry point.

#11 lore raw

Re: [PATCH v4 4/7] smbios: Use SMBIOS 3.0 to support an address above 4GB

Quoted 32 lines · Mark Kettenis
Quoted 32 lines

From: Simon Glass <[email protected]>
Date: Thu, 28 Dec 2023 13:37:03 +0000

Hi Ilias,

Quoted 5 lines · Ilias Apalodimas

Hi Simon,

Quoted 1 line · Simon Glass
Quoted 7 lines
Quoted 4 lines

When the SMBIOS table is written to an address above 4GB a 32-bit table address is not large enough.

Use an SMBIOS3 table in that case.

Maybe I missed this on the previous revisions, but is there a reason we don't always use SMBIOS3 now?

I am not sure...there was some comment about it not being supported in some cases, so I have tried to accommodate that.

Quoted 2 lines

And perhaps try to install SMBIOS2 if
1. we fail

due to?

Quoted 1 line

2. and the address is < 4GB

We could, I suppose. Effectively we would drop generation of SMBIOS2.

Quoted 8 lines
Quoted 2 lines

I really don't mind. This whole SMBIOS thing is a bit ridiculous, if you ask me.

Linux added support for the SMBIOS 3.0 64-bit entry point in 2014. I doubt anyone who cares about SMBIOS cares about kernels that old.

So if it simplifies things, I'd drop support for the 32-bit SMBIOS entry point.

I agree, lets just provide SMBIOS3 tables.

Signature · 1 line
Tom
#12 lore raw

Re: [PATCH v4 4/7] smbios: Use SMBIOS 3.0 to support an address above 4GB

Hi Tom,

Quoted 37 lines · Tom Rini
Quoted 35 lines · Mark Kettenis
Quoted 34 lines

From: Simon Glass <[email protected]>
Date: Thu, 28 Dec 2023 13:37:03 +0000

Hi Ilias,

Quoted 5 lines · Ilias Apalodimas

Hi Simon,

Quoted 1 line · Simon Glass
Quoted 7 lines
Quoted 4 lines

When the SMBIOS table is written to an address above 4GB a 32-bit table address is not large enough.

Use an SMBIOS3 table in that case.

Maybe I missed this on the previous revisions, but is there a reason we don't always use SMBIOS3 now?

I am not sure...there was some comment about it not being supported in some cases, so I have tried to accommodate that.

Quoted 2 lines

And perhaps try to install SMBIOS2 if
1. we fail

due to?

Quoted 1 line

2. and the address is < 4GB

We could, I suppose. Effectively we would drop generation of SMBIOS2.

I really don't mind. This whole SMBIOS thing is a bit ridiculous, if you ask me.

Quoted 7 lines
Quoted 5 lines

Linux added support for the SMBIOS 3.0 64-bit entry point in 2014. I doubt anyone who cares about SMBIOS cares about kernels that old.

So if it simplifies things, I'd drop support for the 32-bit SMBIOS entry point.

I agree, lets just provide SMBIOS3 tables.

OK...I would like to do this as a followup patch, so we still have the SMBIOS2 in the git history. I will take a look.

Regards,
Simon

#13 lore raw

PATCH v4 5/7 smbios: Correct gd_smbios_start()

In reply to Simon Glass

This should access arch-specific properties. Fix it and update the existing usage.

---

(no changes since v2)

Changes in v2:
- Add a new patch to correct gd_smbios_start()

 include/asm-generic/global_data.h | 2 +-
 lib/efi_loader/efi_smbios.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/asm-generic/global_data.h +1 -1
index e8c6412e3f8..c1f7818817f 100644
@@ -553,7 +553,7 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
 #endif
 
 #ifdef CONFIG_SMBIOS
-#define gd_smbios_start()	gd->smbios_start
+#define gd_smbios_start()	gd->arch.smbios_start
 #define gd_set_smbios_start(addr)	gd->arch.smbios_start = addr
 #else
 #define gd_smbios_start()	0UL
lib/efi_loader/efi_smbios.c +1 -1
index bbb8421ce14..49adc87e45a 100644
@@ -28,7 +28,7 @@ efi_status_t efi_smbios_register(void)
 	ulong addr;
 	efi_status_t ret;
 
-	addr = gd->arch.smbios_start;
+	addr = gd_smbios_start();
 	if (!addr) {
 		log_err("No SMBIOS tables to install\n");
 		return EFI_NOT_FOUND;
Signature · 1 line
2.34.1
Reviewed-by on v4 5/7
#14 lore raw

Re: [PATCH v4 5/7] smbios: Correct gd_smbios_start()

Quoted 44 lines · Simon Glass

This should access arch-specific properties. Fix it and update the existing usage.

---

(no changes since v2)

Changes in v2:
- Add a new patch to correct gd_smbios_start()

 include/asm-generic/global_data.h | 2 +-
 lib/efi_loader/efi_smbios.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/asm-generic/global_data.h +1 -1
index e8c6412e3f8..c1f7818817f 100644
@@ -553,7 +553,7 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
 #endif
 
 #ifdef CONFIG_SMBIOS
-#define gd_smbios_start()      gd->smbios_start
+#define gd_smbios_start()      gd->arch.smbios_start
 #define gd_set_smbios_start(addr)      gd->arch.smbios_start = addr
 #else
 #define gd_smbios_start()      0UL
lib/efi_loader/efi_smbios.c +1 -2
index bbb8421ce14..49adc87e45a 100644
@@ -28,7 +28,7 @@ efi_status_t efi_smbios_register(void)
        ulong addr;
        efi_status_t ret;
 
-       addr = gd->arch.smbios_start;
+       addr = gd_smbios_start();
        if (!addr) {
                log_err("No SMBIOS tables to install\n");
                return EFI_NOT_FOUND;
--
Quoted 2 lines

2.34.1

#15 lore raw

PATCH v4 6/7 efi: Use the correct GUID for the SMBIOS table

In reply to Simon Glass

EFI does not use the 'anchor string' to determine the SMBIOS table version, instead preferring to have two separate GUIDs. Use the correct one, depending on the table version.

Call unmap_system() to balance to the use of map_sysmem()

---

(no changes since v2)

Changes in v2:
- Add a note about why unmap_system() is called

 include/efi_api.h           |  4 ++++
 lib/efi_loader/efi_smbios.c | 12 ++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
include/efi_api.h +4 -0
index 0e92cb8a7f6..ab40b1b5ddf 100644
@@ -433,6 +433,10 @@ struct efi_runtime_services {
 	EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3,  \
 		 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
+#define SMBIOS3_TABLE_GUID \
+	EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, \
+		 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
+
 #define EFI_LOAD_FILE_PROTOCOL_GUID \
 	EFI_GUID(0x56ec3091, 0x954c, 0x11d2, \
 		 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
lib/efi_loader/efi_smbios.c +10 -2
index 49adc87e45a..5cbce6dc4eb 100644
@@ -14,6 +14,8 @@
 #include <smbios.h>
 #include <linux/sizes.h>
 
+const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID;
+
 enum {
 	TABLE_SIZE	= SZ_4K,
 };
@@ -25,8 +27,10 @@ enum {
  */
 efi_status_t efi_smbios_register(void)
 {
+	const efi_guid_t *guid;
 	ulong addr;
 	efi_status_t ret;
+	void *buf;
 
 	addr = gd_smbios_start();
 	if (!addr) {
@@ -42,8 +46,12 @@ efi_status_t efi_smbios_register(void)
 	log_debug("EFI using SMBIOS tables at %lx\n", addr);
 
 	/* Install SMBIOS information as configuration table */
-	return efi_install_configuration_table(&smbios_guid,
-					       map_sysmem(addr, 0));
+	buf = map_sysmem(addr, 0);
+	guid = !memcmp(buf, "_SM_", 4) ? &smbios_guid : &smbios3_guid;
+	ret = efi_install_configuration_table(guid, buf);
+	unmap_sysmem(buf);
+
+	return ret;
 }
 
 static int install_smbios_table(void)
Signature · 1 line
2.34.1
Reviewed-by on v4 6/7
#16 lore raw

Re: [PATCH v4 6/7] efi: Use the correct GUID for the SMBIOS table

Quoted 75 lines · Simon Glass

EFI does not use the 'anchor string' to determine the SMBIOS table version, instead preferring to have two separate GUIDs. Use the correct one, depending on the table version.

Call unmap_system() to balance to the use of map_sysmem()

---

(no changes since v2)

Changes in v2:
- Add a note about why unmap_system() is called

 include/efi_api.h           |  4 ++++
 lib/efi_loader/efi_smbios.c | 12 ++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
include/efi_api.h +4 -0
index 0e92cb8a7f6..ab40b1b5ddf 100644
@@ -433,6 +433,10 @@ struct efi_runtime_services {
        EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3,  \
                 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
 
+#define SMBIOS3_TABLE_GUID \
+       EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, \
+                0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
+
 #define EFI_LOAD_FILE_PROTOCOL_GUID \
        EFI_GUID(0x56ec3091, 0x954c, 0x11d2, \
                 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
lib/efi_loader/efi_smbios.c +10 -3
index 49adc87e45a..5cbce6dc4eb 100644
@@ -14,6 +14,8 @@
 #include <smbios.h>
 #include <linux/sizes.h>
 
+const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID;
+
 enum {
        TABLE_SIZE      = SZ_4K,
 };
@@ -25,8 +27,10 @@ enum {
  */
 efi_status_t efi_smbios_register(void)
 {
+       const efi_guid_t *guid;
        ulong addr;
        efi_status_t ret;
+       void *buf;
 
        addr = gd_smbios_start();
        if (!addr) {
@@ -42,8 +46,12 @@ efi_status_t efi_smbios_register(void)
        log_debug("EFI using SMBIOS tables at %lx\n", addr);
 
        /* Install SMBIOS information as configuration table */
-       return efi_install_configuration_table(&smbios_guid,
-                                              map_sysmem(addr, 0));
+       buf = map_sysmem(addr, 0);
+       guid = !memcmp(buf, "_SM_", 4) ? &smbios_guid : &smbios3_guid;
+       ret = efi_install_configuration_table(guid, buf);
+       unmap_sysmem(buf);
+
+       return ret;
 }
 
 static int install_smbios_table(void)
--
Quoted 2 lines

2.34.1

#17 lore raw

PATCH v4 7/7 smbios: Require the caller to align the SMBIOS table

In reply to Simon Glass

All callers handle this alignment, so drop the unnecessary code. This simplifies things a little.

---

(no changes since v1)

 include/smbios.h | 5 +----
 lib/smbios.c     | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)
include/smbios.h +1 -4
index 77be58887a2..879b8a814b8 100644
@@ -258,12 +258,9 @@ static inline void fill_smbios_header(void *table, int type,
  *
  * This writes SMBIOS table at a given address.
  *
- * @addr:	start address to write SMBIOS table. If this is not
- *		16-byte-aligned then it will be aligned before the table is
- *		written.
+ * @addr:	start address to write SMBIOS table (must be 16-byte-aligned)
  * Return:	end address of SMBIOS table (and start address for next entry)
  *		or NULL in case of an error
- *
  */
 ulong write_smbios_table(ulong addr);
 
lib/smbios.c +0 -2
index 7f79d969c92..cfd451e4088 100644
@@ -563,8 +563,6 @@ ulong write_smbios_table(ulong addr)
 		ctx.dev = NULL;
 	}
 
-	/* 16 byte align the table address */
-	addr = ALIGN(addr, 16);
 	start_addr = addr;
 
 	/*
Signature · 1 line
2.34.1
#18 lore raw

Re: [PATCH v4 7/7] smbios: Require the caller to align the SMBIOS table

Hi Simon,

I commented on v3 as well, but in case you miss that

Quoted 37 lines · Simon Glass

All callers handle this alignment, so drop the unnecessary code. This simplifies things a little.

---

(no changes since v1)

 include/smbios.h | 5 +----
 lib/smbios.c     | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)
include/smbios.h +1 -4
index 77be58887a2..879b8a814b8 100644
@@ -258,12 +258,9 @@ static inline void fill_smbios_header(void *table, int type,
  *
  * This writes SMBIOS table at a given address.
  *
- * @addr:      start address to write SMBIOS table. If this is not
- *             16-byte-aligned then it will be aligned before the table is
- *             written.
+ * @addr:      start address to write SMBIOS table (must be 16-byte-aligned)
  * Return:     end address of SMBIOS table (and start address for next entry)
  *             or NULL in case of an error
- *
  */
 ulong write_smbios_table(ulong addr);
 
lib/smbios.c +0 -0
index 7f79d969c92..cfd451e4088 100644

lib/smbios.c ulong write_smbios_table(ulong addr) · line 567

Quoted 5 lines
lib/smbios.c +0 -2
@@ -563,8 +563,6 @@ ulong write_smbios_table(ulong addr)
                ctx.dev = NULL;
        }
 
-       /* 16 byte align the table address */
-       addr = ALIGN(addr, 16);

I think this is wrong. It will break SMBIOS on a user error. I am fine replacing that with a check instead and error out if the address is not 16b aligned

Thanks
/Ilias

Quoted 6 lines
lib/smbios.c +0 -1
        start_addr = addr;
 
        /*
--

2.34.1

#19 lore raw

Re: [PATCH v4 7/7] smbios: Require the caller to align the SMBIOS table

Hi Ilias,

Quoted 46 lines · Ilias Apalodimas

Hi Simon,

I commented on v3 as well, but in case you miss that

Quoted 40 lines · Simon Glass

All callers handle this alignment, so drop the unnecessary code. This simplifies things a little.

---

(no changes since v1)

 include/smbios.h | 5 +----
 lib/smbios.c     | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)
include/smbios.h +1 -4
index 77be58887a2..879b8a814b8 100644
@@ -258,12 +258,9 @@ static inline void fill_smbios_header(void *table, int type,
  *
  * This writes SMBIOS table at a given address.
  *
- * @addr:      start address to write SMBIOS table. If this is not
- *             16-byte-aligned then it will be aligned before the table is
- *             written.
+ * @addr:      start address to write SMBIOS table (must be 16-byte-aligned)
  * Return:     end address of SMBIOS table (and start address for next entry)
  *             or NULL in case of an error
- *
  */
 ulong write_smbios_table(ulong addr);
 
lib/smbios.c +0 -0
index 7f79d969c92..cfd451e4088 100644
@@ -563,8 +563,6 @@ ulong write_smbios_table(ulong addr)
                ctx.dev = NULL;
        }
 
Quoted 6 lines

lib/smbios.c ulong write_smbios_table(ulong addr) · line 567

Quoted 2 lines
lib/smbios.c +0 -2
-       /* 16 byte align the table address */
-       addr = ALIGN(addr, 16);

I think this is wrong. It will break SMBIOS on a user error. I am fine replacing that with a check instead and error out if the address is not 16b aligned

Well this is why the comment says it must be aligned. This function is not called willy nilly, from code we control. Checking for alignment at runtime creates confusion and adds to code size.

Quoted 9 lines

Thanks
/Ilias

Quoted 6 lines
lib/smbios.c +0 -1
        start_addr = addr;
 
        /*
--

2.34.1

Regards,
Simon

#20 lore raw

Re: [PATCH v4 7/7] smbios: Require the caller to align the SMBIOS table

Am 28. Dezember 2023 14:37:19 MEZ schrieb Simon Glass <[email protected]>:

Quoted 57 lines

Hi Ilias,

Quoted 46 lines · Ilias Apalodimas

Hi Simon,

I commented on v3 as well, but in case you miss that

Quoted 40 lines · Simon Glass

All callers handle this alignment, so drop the unnecessary code. This simplifies things a little.

---

(no changes since v1)

 include/smbios.h | 5 +----
 lib/smbios.c     | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)
include/smbios.h +1 -4
index 77be58887a2..879b8a814b8 100644
@@ -258,12 +258,9 @@ static inline void fill_smbios_header(void *table, int type,
  *
  * This writes SMBIOS table at a given address.
  *
- * @addr:      start address to write SMBIOS table. If this is not
- *             16-byte-aligned then it will be aligned before the table is
- *             written.
+ * @addr:      start address to write SMBIOS table (must be 16-byte-aligned)
  * Return:     end address of SMBIOS table (and start address for next entry)
  *             or NULL in case of an error
- *
  */
 ulong write_smbios_table(ulong addr);
 
lib/smbios.c +0 -0
index 7f79d969c92..cfd451e4088 100644
@@ -563,8 +563,6 @@ ulong write_smbios_table(ulong addr)
                ctx.dev = NULL;
        }
 
Quoted 6 lines

lib/smbios.c ulong write_smbios_table(ulong addr) · line 567

Quoted 2 lines
lib/smbios.c +0 -2
-       /* 16 byte align the table address */
-       addr = ALIGN(addr, 16);

I think this is wrong. It will break SMBIOS on a user error. I am fine replacing that with a check instead and error out if the address is not 16b aligned

Quoted 3 lines

Well this is why the comment says it must be aligned. This function is not called willy nilly, from code we control. Checking for alignment at runtime creates confusion and adds to code size.

The SMBIOS tables themself have no alignment requirement. Only on non UEFI x86 system presenting a UEFI entry point in the range 000F0000h to 000FFFFFh this copy of the entry point has to be 16 byte aligned.

Best regards

Heinrich

Quoted 13 lines
Quoted 10 lines

Thanks
/Ilias

Quoted 6 lines
lib/smbios.c +0 -1
        start_addr = addr;
 
        /*
--

2.34.1

Regards,
Simon

#21 lore raw

Re: [PATCH v4 7/7] smbios: Require the caller to align the SMBIOS table

Hi Heinrich,

Quoted 61 lines · Heinrich Schuchardt

Am 28. Dezember 2023 14:37:19 MEZ schrieb Simon Glass <[email protected]>:

Quoted 57 lines

Hi Ilias,

Quoted 52 lines · Ilias Apalodimas

Hi Simon,

I commented on v3 as well, but in case you miss that

Quoted 37 lines · Simon Glass

All callers handle this alignment, so drop the unnecessary code. This simplifies things a little.

---

(no changes since v1)

 include/smbios.h | 5 +----
 lib/smbios.c     | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)
include/smbios.h +1 -4
index 77be58887a2..879b8a814b8 100644
@@ -258,12 +258,9 @@ static inline void fill_smbios_header(void *table, int type,
  *
  * This writes SMBIOS table at a given address.
  *
- * @addr:      start address to write SMBIOS table. If this is not
- *             16-byte-aligned then it will be aligned before the table is
- *             written.
+ * @addr:      start address to write SMBIOS table (must be 16-byte-aligned)
  * Return:     end address of SMBIOS table (and start address for next entry)
  *             or NULL in case of an error
- *
  */
 ulong write_smbios_table(ulong addr);
 
lib/smbios.c +0 -0
index 7f79d969c92..cfd451e4088 100644

lib/smbios.c ulong write_smbios_table(ulong addr) · line 567

Quoted 5 lines
lib/smbios.c +0 -2
@@ -563,8 +563,6 @@ ulong write_smbios_table(ulong addr)
                ctx.dev = NULL;
        }
 
-       /* 16 byte align the table address */
-       addr = ALIGN(addr, 16);

I think this is wrong. It will break SMBIOS on a user error. I am fine replacing that with a check instead and error out if the address is not 16b aligned

Quoted 5 lines
Quoted 3 lines

Well this is why the comment says it must be aligned. This function is not called willy nilly,from code we control. Checking for alignment at runtime creates confusion and adds to code size.

The SMBIOS tables themself have no alignment requirement. Only on non UEFI x86 system presenting a UEFI entry point in the range 000F0000h to 000FFFFFh this copy of the entry point has to be 16 byte aligned.

OK. So perhaps I should reword the comment to say that any arch-specific alignment must be respected by the caller?

Regards,
Simon

#22 lore raw

Re: [PATCH v4 7/7] smbios: Require the caller to align the SMBIOS table

Am 28. Dezember 2023 20:48:04 MEZ schrieb Simon Glass <[email protected]>:

Quoted 64 lines

Hi Heinrich,

Quoted 61 lines · Heinrich Schuchardt

Am 28. Dezember 2023 14:37:19 MEZ schrieb Simon Glass <[email protected]>:

Quoted 57 lines

Hi Ilias,

Quoted 52 lines · Ilias Apalodimas

Hi Simon,

I commented on v3 as well, but in case you miss that

Quoted 37 lines · Simon Glass

All callers handle this alignment, so drop the unnecessary code. This simplifies things a little.

---

(no changes since v1)

 include/smbios.h | 5 +----
 lib/smbios.c     | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)
include/smbios.h +1 -4
index 77be58887a2..879b8a814b8 100644
@@ -258,12 +258,9 @@ static inline void fill_smbios_header(void *table, int type,
  *
  * This writes SMBIOS table at a given address.
  *
- * @addr:      start address to write SMBIOS table. If this is not
- *             16-byte-aligned then it will be aligned before the table is
- *             written.
+ * @addr:      start address to write SMBIOS table (must be 16-byte-aligned)
  * Return:     end address of SMBIOS table (and start address for next entry)
  *             or NULL in case of an error
- *
  */
 ulong write_smbios_table(ulong addr);
 
lib/smbios.c +0 -0
index 7f79d969c92..cfd451e4088 100644

lib/smbios.c ulong write_smbios_table(ulong addr) · line 567

Quoted 5 lines
lib/smbios.c +0 -2
@@ -563,8 +563,6 @@ ulong write_smbios_table(ulong addr)
                ctx.dev = NULL;
        }
 
-       /* 16 byte align the table address */
-       addr = ALIGN(addr, 16);

I think this is wrong. It will break SMBIOS on a user error. I am fine replacing that with a check instead and error out if the address is not 16b aligned

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Well this is why the comment says it must be aligned. This function is not called willy nilly,from code we control. Checking for alignment at runtime creates confusion and adds to code size.

The SMBIOS tables themself have no alignment requirement. Only on non UEFI x86 system presenting a UEFI entry point in the range 000F0000h to 000FFFFFh this copy of the entry point has to be 16 byte aligned.

OK. So perhaps I should reword the comment to say that any arch-specific alignment must be respected by the caller?

Just mentioning the requirement from the spec in the function description should be good enough.

Best regards

Heinrich

Quoted 3 lines

Regards,
Simon

Reviewed-by
#23 lore raw

Re: [PATCH v4 7/7] smbios: Require the caller to align the SMBIOS table

Quoted 74 lines · Heinrich Schuchardt

Am 28. Dezember 2023 20:48:04 MEZ schrieb Simon Glass <[email protected]>:

Quoted 70 lines

Hi Heinrich,

Quoted 66 lines · Heinrich Schuchardt

Am 28. Dezember 2023 14:37:19 MEZ schrieb Simon Glass <[email protected]>:

Quoted 57 lines

Hi Ilias,

Quoted 46 lines · Ilias Apalodimas

Hi Simon,

I commented on v3 as well, but in case you miss that

Quoted 40 lines · Simon Glass

All callers handle this alignment, so drop the unnecessary code. This simplifies things a little.

---

(no changes since v1)

 include/smbios.h | 5 +----
 lib/smbios.c     | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)
include/smbios.h +1 -4
index 77be58887a2..879b8a814b8 100644
@@ -258,12 +258,9 @@ static inline void fill_smbios_header(void *table, int type,
  *
  * This writes SMBIOS table at a given address.
  *
- * @addr:      start address to write SMBIOS table. If this is not
- *             16-byte-aligned then it will be aligned before the table is
- *             written.
+ * @addr:      start address to write SMBIOS table (must be 16-byte-aligned)
  * Return:     end address of SMBIOS table (and start address for next entry)
  *             or NULL in case of an error
- *
  */
 ulong write_smbios_table(ulong addr);
 
lib/smbios.c +0 -0
index 7f79d969c92..cfd451e4088 100644
@@ -563,8 +563,6 @@ ulong write_smbios_table(ulong addr)
                ctx.dev = NULL;
        }
 
Quoted 6 lines

lib/smbios.c ulong write_smbios_table(ulong addr) · line 567

Quoted 2 lines
lib/smbios.c +0 -2
-       /* 16 byte align the table address */
-       addr = ALIGN(addr, 16);

I think this is wrong. It will break SMBIOS on a user error. I am fine replacing that with a check instead and error out if the address is not 16b aligned

Quoted 3 lines

Well this is why the comment says it must be aligned. This function is not called willy nilly,from code we control. Checking for alignment at runtime creates confusion and adds to code size.

The SMBIOS tables themself have no alignment requirement. Only on non UEFI x86 system presenting a UEFI entry point in the range 000F0000h to 000FFFFFh this copy of the entry point has to be 16 byte aligned.

Thanks Heinrich, this makes sense

Quoted 12 lines
Quoted 2 lines

OK. So perhaps I should reword the comment to say that any arch-specific alignment must be respected by the caller?

Just mentioning the requirement from the spec in the function description should be good enough.

Best regards

Heinrich

Quoted 3 lines

Regards,
Simon

Tested-by on the v4 series
#24 lore raw
In reply to Simon Glass

Hi Simon,

Thanks this looks good

Quoted 39 lines · Simon Glass

When the malloc() region extends beyond 4GB on ARM we may end up with an SMBIOS table in that region.

Add support for writing an SMBIOS3 table, which supports a 64-bit address.

Note that this problem does not happen on x86 since it requires the tables to be placed just below 1MB in memory, unless CONFIG_BLOBLIST_TABLES is enabled.

Changes in v4:
- Bring in this patch from Heinrich's series
- Check the start of the table rather than the end

Changes in v2:
- Check the end of the table rather than the start.
- Add a new patch to correct gd_smbios_start()
- Add a note about why unmap_system() is called

Heinrich Schuchardt (1):
smbios: SMBIOS 3.0 (64-bit) Entry Point structure

Simon Glass (6):
smbios: Refactor 32-bit code into an else statement
smbios: Move the rest of the SMBIOS2 code
smbios: Use SMBIOS 3.0 to support an address above 4GB
smbios: Correct gd_smbios_start()
efi: Use the correct GUID for the SMBIOS table
smbios: Require the caller to align the SMBIOS table

 include/asm-generic/global_data.h |  2 +-
 include/efi_api.h                 |  4 ++
 include/smbios.h                  | 37 ++++++++++++--
 lib/efi_loader/efi_smbios.c       | 14 +++--
 lib/smbios.c                      | 85 +++++++++++++++++++------------
 5 files changed, 101 insertions(+), 41 deletions(-)
Quoted 3 lines

--
2.34.1

For the series