Return-Path: Received: from mail-sn1nam02on0132.outbound.protection.outlook.com ([104.47.36.132]:23728 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756608AbeDIAfw (ORCPT ); Sun, 8 Apr 2018 20:35:52 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jean Delvare , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 039/162] firmware: dmi_scan: Look for SMBIOS 3 entry point first Date: Mon, 9 Apr 2018 00:28:11 +0000 Message-ID: <20180409002738.163941-39-alexander.levin@microsoft.com> References: <20180409002738.163941-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002738.163941-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Jean Delvare [ Upstream commit c9aba14362a6eec583819ec8f4b872c1816f5cbe ] Since version 3.0.0 of the SMBIOS specification, there can be multiple entry points in memory, pointing to one or two DMI tables. If both a 32-bit ("_SM_") entry point and a 64-bit ("_SM3_") entry point are present, the specification requires that the latter points to a table which is a super-set of the table pointed to by the former. Therefore we should give preference to the 64-bit ("_SM3_") entry point. However, currently the code is picking the first valid entry point it finds. Per specification, we should look for a 64-bit ("_SM3_") entry point first, and if we can't find any, look for a 32-bit ("_SM_" or "_DMI_") entry point. Modify the code to do that. Signed-off-by: Jean Delvare Signed-off-by: Sasha Levin --- drivers/firmware/dmi_scan.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index 0e08e665f715..f1d4881dd2fc 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -626,6 +626,21 @@ void __init dmi_scan_machine(void) if (p =3D=3D NULL) goto error; =20 + /* + * Same logic as above, look for a 64-bit entry point + * first, and if not found, fall back to 32-bit entry point. + */ + memcpy_fromio(buf, p, 16); + for (q =3D p + 16; q < p + 0x10000; q +=3D 16) { + memcpy_fromio(buf + 16, q, 16); + if (!dmi_smbios3_present(buf)) { + dmi_available =3D 1; + dmi_early_unmap(p, 0x10000); + goto out; + } + memcpy(buf, buf + 16, 16); + } + /* * Iterate over all possible DMI header addresses q. * Maintain the 32 bytes around q in buf. On the @@ -636,7 +651,7 @@ void __init dmi_scan_machine(void) memset(buf, 0, 16); for (q =3D p; q < p + 0x10000; q +=3D 16) { memcpy_fromio(buf + 16, q, 16); - if (!dmi_smbios3_present(buf) || !dmi_present(buf)) { + if (!dmi_present(buf)) { dmi_available =3D 1; dmi_early_unmap(p, 0x10000); goto out; --=20 2.15.1