All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lspcu: use sysfs for table access if available
@ 2017-04-12  9:11 Ard Biesheuvel
  2017-04-12  9:14 ` Alexander Graf
  2017-04-18  9:23 ` Karel Zak
  0 siblings, 2 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2017-04-12  9:11 UTC (permalink / raw)
  To: util-linux-ng; +Cc: leif.lindholm, agraf, kzak, Ard Biesheuvel

On ARM systems, accessing SMBIOS tables via /dev/mem using read()
calls is not supported. The reason is that such tables are usually
located in EFI_RUNTIME_SERVICE_DATA memory, which is not covered
by the linear mapping on those systems, and so read() calls will
fail.

So instead, use the /sys/firmware/dmi/tables/DMI sysfs file, which
contains the entire structure table array, and will be available
on any recent Linux system, even on ones that only export the rev3
SMBIOS entry point, which is currently ignored by lscpu.

Note that the max 'num' value is inferred from the size. This is not
a limitation of the sysfs interface, but a limitation of the rev3
entry point, which no longer carries a number of array elements.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 sys-utils/lscpu-dmi.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
index 0e497d10c..a8298ff74 100644
--- a/sys-utils/lscpu-dmi.c
+++ b/sys-utils/lscpu-dmi.c
@@ -192,6 +192,18 @@ static int hypervisor_decode_smbios(uint8_t *buf, const char *devmem)
 		devmem);
 }
 
+static int hypervisor_decode_sysfw(void)
+{
+	static char const sys_fw_dmi_tables[] = "/sys/firmware/dmi/tables/DMI";
+	struct stat st;
+
+	if (stat(sys_fw_dmi_tables, &st))
+		return -1;
+
+	return hypervisor_from_dmi_table(0, st.st_size, st.st_size / 4,
+					 sys_fw_dmi_tables);
+}
+
 /*
  * Probe for EFI interface
  */
@@ -242,6 +254,10 @@ int read_hypervisor_dmi(void)
 	    || '\0' != 0)
 		return rc;
 
+	rc = hypervisor_decode_sysfw();
+	if (rc >= 0)
+		return rc;
+
 	/* First try EFI (ia64, Intel-based Mac) */
 	switch (address_from_efi(&fp)) {
 		case EFI_NOT_FOUND:
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lspcu: use sysfs for table access if available
  2017-04-12  9:11 [PATCH] lspcu: use sysfs for table access if available Ard Biesheuvel
@ 2017-04-12  9:14 ` Alexander Graf
  2017-04-18  9:23 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Graf @ 2017-04-12  9:14 UTC (permalink / raw)
  To: Ard Biesheuvel, util-linux-ng; +Cc: leif.lindholm, kzak



On 12.04.17 11:11, Ard Biesheuvel wrote:
> On ARM systems, accessing SMBIOS tables via /dev/mem using read()
> calls is not supported. The reason is that such tables are usually
> located in EFI_RUNTIME_SERVICE_DATA memory, which is not covered
> by the linear mapping on those systems, and so read() calls will
> fail.
>
> So instead, use the /sys/firmware/dmi/tables/DMI sysfs file, which
> contains the entire structure table array, and will be available
> on any recent Linux system, even on ones that only export the rev3
> SMBIOS entry point, which is currently ignored by lscpu.
>
> Note that the max 'num' value is inferred from the size. This is not
> a limitation of the sysfs interface, but a limitation of the rev3
> entry point, which no longer carries a number of array elements.
>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Tested-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Alexander Graf <agraf@suse.de>

Thanks :)


Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lspcu: use sysfs for table access if available
  2017-04-12  9:11 [PATCH] lspcu: use sysfs for table access if available Ard Biesheuvel
  2017-04-12  9:14 ` Alexander Graf
@ 2017-04-18  9:23 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Karel Zak @ 2017-04-18  9:23 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: util-linux-ng, leif.lindholm, agraf

On Wed, Apr 12, 2017 at 10:11:29AM +0100, Ard Biesheuvel wrote:
>  sys-utils/lscpu-dmi.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-18  9:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12  9:11 [PATCH] lspcu: use sysfs for table access if available Ard Biesheuvel
2017-04-12  9:14 ` Alexander Graf
2017-04-18  9:23 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.