git: 93af0db0d529 - stable/14 - libsa: smbios: Favor the v3 (64-bit) entry point on non-EFI boot

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Tue, 08 Apr 2025 13:41:07 UTC
The branch stable/14 has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=93af0db0d5298bc7d1eb05d57aacfc6495d2c057

commit 93af0db0d5298bc7d1eb05d57aacfc6495d2c057
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-03-03 14:38:10 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-04-08 13:38:27 +0000

    libsa: smbios: Favor the v3 (64-bit) entry point on non-EFI boot
    
    When both the 32-bit and 64-bit entry points are present, the SMBIOS
    specification says that the 64-bit entry point always has at least all
    the structures the 32-bit entry point refers.  In other words, the
    32-bit entry point is provided for compatibility, so we assume the
    64-bit one has more chances to be filled with adequate values.
    
    Doing this also increases consistency with the kernel's smbios(4)
    driver.
    
    Reviewed by:    imp, markj
    MFC after:      2 weeks
    Relnotes:       yes
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D49287
    
    (cherry picked from commit 3f744fb8b2c5528c2170be113e0e4947eee3cffc)
---
 stand/libsa/smbios.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/stand/libsa/smbios.c b/stand/libsa/smbios.c
index 4deea4f31b11..2477c0ccf2d3 100644
--- a/stand/libsa/smbios.c
+++ b/stand/libsa/smbios.c
@@ -180,16 +180,10 @@ static caddr_t
 smbios_sigsearch(const caddr_t addr, const uint32_t len)
 {
 	caddr_t		cp;
+	caddr_t		v2_p = NULL;
 
 	/* Search on 16-byte boundaries. */
 	for (cp = addr; cp < addr + len; cp += SMBIOS_STEP) {
-		/* v2.1, 32-bit Entry point */
-		if (strncmp(cp, SMBIOS_SIG, sizeof(SMBIOS_SIG) - 1) == 0 &&
-		    smbios_checksum(cp, SMBIOS_GET8(cp, 0x05)) == 0 &&
-		    strncmp(cp + 0x10, SMBIOS_DMI_SIG, 5) == 0 &&
-		    smbios_checksum(cp + 0x10, 0x0f) == 0)
-			return (cp);
-
 #ifdef SMBIOS_64BIT_EP
 		/* v3.0, 64-bit Entry point */
 		if (strncmp(cp, SMBIOS3_SIG, sizeof(SMBIOS3_SIG) - 1) == 0 &&
@@ -205,8 +199,24 @@ smbios_sigsearch(const caddr_t addr, const uint32_t len)
 			return (cp);
 		}
 #endif
+
+		/* v2.1, 32-bit Entry point */
+		if (strncmp(cp, SMBIOS_SIG, sizeof(SMBIOS_SIG) - 1) == 0 &&
+		    smbios_checksum(cp, SMBIOS_GET8(cp, 0x05)) == 0 &&
+		    strncmp(cp + 0x10, SMBIOS_DMI_SIG, 5) == 0 &&
+		    smbios_checksum(cp + 0x10, 0x0f) == 0) {
+			/*
+			 * Note that we saw this entry point, but don't return
+			 * it right now on SMBIOS_64BIT_EP as we favor the 64-bit
+			 * one if present.
+			 */
+			v2_p = cp;
+#ifndef SMBIOS_64BIT_EP
+			break;
+#endif
+		}
 	}
-	return (NULL);
+	return (v2_p);
 }
 
 static const char*