Skip to contentSkip to conversation

platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER

PATCH Superseded Tzung-Bi Shih 2 participants 6 messages Jul 26, 2023 – Aug 3, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Tzung-Bi Shih

author maintainer
#0 lore raw

PATCH 1/1 platform/chrome: chromeos_acpi: print hex string for ACPI_TYPE_BUFFER

element->buffer.pointer should be binary blob. %s doesn't work perfect for them.

Print hex string for ACPI_TYPE_BUFFER.

---
 drivers/platform/chrome/chromeos_acpi.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/platform/chrome/chromeos_acpi.c +19 -1
index 50d8a4d4352d..a60d344c54e4 100644
@@ -90,7 +90,25 @@ static int chromeos_acpi_handle_package(struct device *dev, union acpi_object *o
 	case ACPI_TYPE_STRING:
 		return sysfs_emit(buf, "%s\n", element->string.pointer);
 	case ACPI_TYPE_BUFFER:
-		return sysfs_emit(buf, "%s\n", element->buffer.pointer);
+		{
+			int i, n;
+			const int char_per_line = 16;
+
+			for (i = 0, n = 0; i < element->buffer.length; ++i) {
+				n += sysfs_emit_at(buf, n, " %2.2x", element->buffer.pointer[i]);
+
+				if (((i + 1) % char_per_line) == 0)
+					n += sysfs_emit_at(buf, n, "\n");
+			}
+			n += sysfs_emit_at(buf, n, "\n");
+
+			if (n == PAGE_SIZE - 1) {
+				dev_info(dev, "truncating sysfs content for %s\n", name);
+				sysfs_emit_at(buf, n - 3, "..\n");
+			}
+
+			return n;
+		}
 	default:
 		dev_err(dev, "element type %d not supported\n", element->type);
 		return -EINVAL;
Signature · 1 line
2.41.0.487.g6d72f3e995-goog
author maintainer
#1 lore raw
Quoted 6 lines · Tzung-Bi Shih

element->buffer.pointer should be binary blob. %s doesn't work perfect for them.

Print hex string for ACPI_TYPE_BUFFER.

Curious about does this patch make sense to folks on the mailing list?

Quoted 38 lines
---
 drivers/platform/chrome/chromeos_acpi.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/platform/chrome/chromeos_acpi.c +19 -1
index 50d8a4d4352d..a60d344c54e4 100644
@@ -90,7 +90,25 @@ static int chromeos_acpi_handle_package(struct device *dev, union acpi_object *o
 	case ACPI_TYPE_STRING:
 		return sysfs_emit(buf, "%s\n", element->string.pointer);
 	case ACPI_TYPE_BUFFER:
-		return sysfs_emit(buf, "%s\n", element->buffer.pointer);
+		{
+			int i, n;
+			const int char_per_line = 16;
+
+			for (i = 0, n = 0; i < element->buffer.length; ++i) {
+				n += sysfs_emit_at(buf, n, " %2.2x", element->buffer.pointer[i]);
+
+				if (((i + 1) % char_per_line) == 0)
+					n += sysfs_emit_at(buf, n, "\n");
+			}
+			n += sysfs_emit_at(buf, n, "\n");
+
+			if (n == PAGE_SIZE - 1) {
+				dev_info(dev, "truncating sysfs content for %s\n", name);
+				sysfs_emit_at(buf, n - 3, "..\n");
+			}
+
+			return n;
+		}
 	default:
 		dev_err(dev, "element type %d not supported\n", element->type);
 		return -EINVAL;
Signature · 1 line
2.41.0.487.g6d72f3e995-goog
#2 lore raw
Quoted 9 lines · Tzung-Bi Shih
Quoted 6 lines · Tzung-Bi Shih

element->buffer.pointer should be binary blob. %s doesn't work perfect for them.

Print hex string for ACPI_TYPE_BUFFER.

Curious about does this patch make sense to folks on the mailing list?

Since you asked.... (sorry if the questions are dumb; I'm not extremely familiar with this one)

Are there any ABI concerns here? As in, did this perhaps work for some use cases that will be broken now by this change in format? If not, it would be nice to note your thought process on that. [1]

Also, is it possible to use some standard formatting, like hex_dump_to_buffer()?

Or, would it make more sense to make these into binary attributes (struct bin_attribute)?

NB: the docs (Documentation/ABI/testing/sysfs-driver-chromeos-acpi) suggest that some attributes (like VDAT) are indeed binary, and so we should probably maintain or fix that.

Brian

[1] My guess: no real user space actually uses this driver yet, since ChromiumOS still has its own downstream variant on its active kernels?

author maintainer
#3 lore raw
Quoted 3 lines · Brian Norris

Are there any ABI concerns here? As in, did this perhaps work for some use cases that will be broken now by this change in format? If not, it would be nice to note your thought process on that. [1]

There is an existing use case from userland program[2]. It works with downstream chromeos_acpi driver but not the upstream one.

[2]: https://crrev.com/48a12071a43813e5bf0694f99e4024468ea900b6/host/arch/x86/lib/crossystem_arch.c#232

Quoted 2 lines

Also, is it possible to use some standard formatting, like hex_dump_to_buffer()?

Ack, fix in v2[3].

[3]: https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/

Quoted 6 lines

Or, would it make more sense to make these into binary attributes (struct bin_attribute)?

NB: the docs (Documentation/ABI/testing/sysfs-driver-chromeos-acpi) suggest that some attributes (like VDAT) are indeed binary, and so we should probably maintain or fix that.

No. Unless we also want to change userland program in [2].

Quoted 2 lines

[1] My guess: no real user space actually uses this driver yet, since ChromiumOS still has its own downstream variant on its active kernels?

Correct, AFAIK, there has no use cases for the upstream chromeos_acpi driver yet.

#4 lore raw
Quoted 6 lines · Tzung-Bi Shih
Quoted 3 lines · Brian Norris

NB: the docs (Documentation/ABI/testing/sysfs-driver-chromeos-acpi) suggest that some attributes (like VDAT) are indeed binary, and so we should probably maintain or fix that.

No. Unless we also want to change userland program in [2].

I mean, I think you need to do one of those two -- either keep this (maintain) as "binary", or update (fix) the doc to describe the hex dump instead.

i.e., I think this piece of Documentation/ABI/testing/sysfs-driver-chromeos-acpi is now wrong:

What:           /sys/bus/platform/devices/GGL0001:*/VDAT
Date:           May 2022
KernelVersion:  5.19

Description:
Returns the verified boot data block shared between the firmware verification step and the kernel verification step (binary).

But, the userland program already doesn't know how to handle the upstream driver. So it'd be possible to change both at the same time.

Anyway, hex-encoded is fine with me too; we just need to get the docs to match.

Regards,
Brian

author maintainer
#5 lore raw
Quoted 23 lines · Brian Norris
Quoted 6 lines · Tzung-Bi Shih
Quoted 3 lines · Brian Norris

NB: the docs (Documentation/ABI/testing/sysfs-driver-chromeos-acpi) suggest that some attributes (like VDAT) are indeed binary, and so we should probably maintain or fix that.

No. Unless we also want to change userland program in [2].

I mean, I think you need to do one of those two -- either keep this (maintain) as "binary", or update (fix) the doc to describe the hex dump instead.

i.e., I think this piece of Documentation/ABI/testing/sysfs-driver-chromeos-acpi is now wrong:

What:           /sys/bus/platform/devices/GGL0001:*/VDAT
Date:           May 2022
KernelVersion:  5.19

Description:
Returns the verified boot data block shared between the firmware verification step and the kernel verification step (binary).

Quoted 5 lines

But, the userland program already doesn't know how to handle the upstream driver. So it'd be possible to change both at the same time.

Anyway, hex-encoded is fine with me too; we just need to get the docs to match.

Ack, fix in v3 (https://patchwork.kernel.org/project/chrome-platform/patch/[email protected]/).