dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0124-lscpu-use-sysfs-for-table-access-if-available.patch

64664a
From 6999f3f3ca525bb6b132f4ed804e7f8fe62e5f79 Mon Sep 17 00:00:00 2001
64664a
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
64664a
Date: Wed, 12 Apr 2017 10:11:29 +0100
64664a
Subject: [PATCH] lscpu: use sysfs for table access if available
64664a
64664a
On ARM systems, accessing SMBIOS tables via /dev/mem using read()
64664a
calls is not supported. The reason is that such tables are usually
64664a
located in EFI_RUNTIME_SERVICE_DATA memory, which is not covered
64664a
by the linear mapping on those systems, and so read() calls will
64664a
fail.
64664a
64664a
So instead, use the /sys/firmware/dmi/tables/DMI sysfs file, which
64664a
contains the entire structure table array, and will be available
64664a
on any recent Linux system, even on ones that only export the rev3
64664a
SMBIOS entry point, which is currently ignored by lscpu.
64664a
64664a
Note that the max 'num' value is inferred from the size. This is not
64664a
a limitation of the sysfs interface, but a limitation of the rev3
64664a
entry point, which no longer carries a number of array elements.
64664a
64664a
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1455664
64664a
Upstream: http://github.com/karelzak/util-linux/commit/92a6392c41c11bcb49af9f129dfbd1fed651f044
64664a
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
64664a
Tested-by: Alexander Graf <agraf@suse.de>
64664a
Reviewed-by: Alexander Graf <agraf@suse.de>
64664a
---
64664a
 sys-utils/lscpu-dmi.c | 16 ++++++++++++++++
64664a
 1 file changed, 16 insertions(+)
64664a
64664a
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
64664a
index 0e497d1..a8298ff 100644
64664a
--- a/sys-utils/lscpu-dmi.c
64664a
+++ b/sys-utils/lscpu-dmi.c
64664a
@@ -192,6 +192,18 @@ static int hypervisor_decode_smbios(uint8_t *buf, const char *devmem)
64664a
 		devmem);
64664a
 }
64664a
 
64664a
+static int hypervisor_decode_sysfw(void)
64664a
+{
64664a
+	static char const sys_fw_dmi_tables[] = "/sys/firmware/dmi/tables/DMI";
64664a
+	struct stat st;
64664a
+
64664a
+	if (stat(sys_fw_dmi_tables, &st))
64664a
+		return -1;
64664a
+
64664a
+	return hypervisor_from_dmi_table(0, st.st_size, st.st_size / 4,
64664a
+					 sys_fw_dmi_tables);
64664a
+}
64664a
+
64664a
 /*
64664a
  * Probe for EFI interface
64664a
  */
64664a
@@ -242,6 +254,10 @@ int read_hypervisor_dmi(void)
64664a
 	    || '\0' != 0)
64664a
 		return rc;
64664a
 
64664a
+	rc = hypervisor_decode_sysfw();
64664a
+	if (rc >= 0)
64664a
+		return rc;
64664a
+
64664a
 	/* First try EFI (ia64, Intel-based Mac) */
64664a
 	switch (address_from_efi(&fp)) {
64664a
 		case EFI_NOT_FOUND:
64664a
-- 
64664a
2.9.4
64664a