Skip to contentSkip to conversation

firmware: coreboot: Support for System Management Interrupt (SMI) handling in coreboot payload (MM payload concept)

PATCH Superseded Michal Gorlas 2 participants 12 messages Jun 16, 2025 – Jun 27, 2025 ChromeOS EC subdrivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover firmware: coreboot: Support for System Management Interrupt (SMI) handling in coreboot payload (MM payload concept)

Hi,

This patchset adds support for MM payload when Linux is used as coreboot's payload. The main idea is to delegate higher-level SMM functions to the payload, limiting the coreboot's System Management Mode (SMM) related responsibilities to the minimum of basic SMM setup [1]. This is done by loading a blob with SMI handler to the shared buffer, from which it is copied to SMRAM [2].

The MM payload is still in a Proof of Concept stage, and we are still working on getting the patches needed for coreboot upstreamed, but I would appreciate any feedback that you may have.

Thanks,
Michal

[1]: https://github.com/9elements/LinuxBootSMM/wiki/Proposed-design#current-design-approach---mm-payload
[2]: https://github.com/9elements/LinuxBootSMM/wiki/Proof-of-Concept-(PoC)

Changes in v2:
- merged mm_info into mm_loader
- removed mm_loader_exit in favour of allocating memory with devm_*()
- added forgotten "\n\t" in trigger_smi()
- added gitignore in mm_handler/
- added COREBOOT_PAYLOAD_MM dependency on x86
- error handling for mm_info struct
- error handling for shared_buffer
- removed whitespace changes in coreboot_table.h
- removed INFO level prints

---
Michal Gorlas (3):
firmware: coreboot: support for parsing SMM related informations from coreboot tables
firmware: coreboot: loader for Linux-owned SMI handler
firmware: coreboot: Linux-owned SMI handler to be loaded by coreboot

 drivers/firmware/google/Kconfig                  |  12 +
 drivers/firmware/google/Makefile                 |  11 +
 drivers/firmware/google/coreboot_table.h         |  11 +
 drivers/firmware/google/mm_blob.S                |  20 +
 drivers/firmware/google/mm_handler/.gitignore    |   4 +
 drivers/firmware/google/mm_handler/Makefile      |  51 +++
 drivers/firmware/google/mm_handler/handler.lds.S |  46 ++
 drivers/firmware/google/mm_handler/mm_handler.S  | 510 +++++++++++++++++++++++
 drivers/firmware/google/mm_handler/mm_handler.h  |  21 +
 drivers/firmware/google/mm_handler/mm_header.S   |  19 +
 drivers/firmware/google/mm_loader.c              | 215 ++++++++++
 drivers/firmware/google/mm_payload.h             |  58 +++
 12 files changed, 978 insertions(+)

---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250613-coreboot-payload-mm-6642bb42284a

Best regards,

Signature · 1 line
Michal Gorlas <[email protected]>
#1 lore raw

PATCH v2 1/3 firmware: coreboot: support for parsing SMM related informations from coreboot tables

coreboot exposes (S)MM related data in the coreboot table. Extends existing interface with structure corresponding to (S)MM data, and adds COREBOOT_PAYLOAD_MM config used by follow-up patches.

---
 drivers/firmware/google/Kconfig          | 12 +++++++
 drivers/firmware/google/coreboot_table.h | 11 ++++++
 drivers/firmware/google/mm_payload.h     | 58 ++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)
drivers/firmware/google/Kconfig +12 -0
index 41b78f5cb7351e512cbaeb6443634a4b97bf6255..ff443f0c4a9a990052d83903fb0f0b0795cc76bd 100644
@@ -81,4 +81,16 @@ config GOOGLE_VPD
 	  This option enables the kernel to expose the content of Google VPD
 	  under /sys/firmware/vpd.
 
+config COREBOOT_PAYLOAD_MM
+	tristate "SMI handling in Linux (LinuxBootSMM)"
+	depends on X86 && GOOGLE_COREBOOT_TABLE
+	help
+	  Enables support for SMI handling by Linux-owned code.
+	  coreboot reserves region for payload-owned SMI handler, the Linux
+	  driver prepares its SMI handler outside of SMRAM, and lets coreboot
+	  know where the handler is placed by issuing an SMI. On this SMI, the
+	  handler is being placed in SMRAM and all supported SMIs from that point
+	  on are handled by Linux-owned SMI handler.
+	  If in doubt, say N.
+
 endif # GOOGLE_FIRMWARE
drivers/firmware/google/coreboot_table.h +11 -0
index bb6f0f7299b4670d0b1f91bd7a3c038cdb412f7b..8a7934e679903e39ce1d86b4aecbc2b4e89363fd 100644
@@ -52,6 +52,16 @@ struct lb_cbmem_entry {
 	u32 id;
 };
 
+/* Corresponds to LB_TAG_PLD_MM_INTERFACE_INFO */
+#define LB_TAG_PLD_MM_INTERFACE_INFO 0x3b
+struct lb_pld_mm_interface_info {
+	u32 tag;
+	u32 size;
+	u8 revision;
+	u8 requires_long_mode_call;
+	u8 register_mm_entry_command;
+};
+
 /* Describes framebuffer setup by coreboot */
 struct lb_framebuffer {
 	u32 tag;
@@ -80,6 +90,7 @@ struct coreboot_device {
 		struct lb_cbmem_ref cbmem_ref;
 		struct lb_cbmem_entry cbmem_entry;
 		struct lb_framebuffer framebuffer;
+		struct lb_pld_mm_interface_info mm_info;
 		DECLARE_FLEX_ARRAY(u8, raw);
 	};
 };
drivers/firmware/google/mm_payload.h new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH v2 1/3] firmware: coreboot: support for parsing SMM related informations from coreboot tables

Quoted 3 lines · Michal Gorlas

coreboot exposes (S)MM related data in the coreboot table. Extends existing interface with structure corresponding to (S)MM data, and adds COREBOOT_PAYLOAD_MM config used by follow-up patches.

s/Extends/Extend/;s/adds/add/ not a hard requirement but [1]("imperative mood").

It'd be better to annotate what MM and SMM stand for as well.

Symbols introduced in the patch are used in the following patch of the series. How about just merge them into one patch?

[1]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html

#3 lore raw

PATCH v2 2/3 firmware: coreboot: loader for Linux-owned SMI handler

In reply to Michal Gorlas

Places a blob with Linux-owned SMI handler in the lower 4GB of memory, calculates entry points for the it and triggers SMI to coreboot's SMI handler informing it where to look for Linux-owned SMI handler.

---
 drivers/firmware/google/Makefile    |  11 ++
 drivers/firmware/google/mm_blob.S   |  20 ++++
 drivers/firmware/google/mm_loader.c | 215 ++++++++++++++++++++++++++++++++++++
 3 files changed, 246 insertions(+)
drivers/firmware/google/Makefile +11 -0
index 8151e323cc434673b0fe56f1df1cec2fb7873295..bcac8dd1509ed251e3739b5905d6267ac097379d 100644
@@ -12,3 +12,14 @@ obj-$(CONFIG_GOOGLE_CBMEM)		+= cbmem.o
 
 vpd-sysfs-y := vpd.o vpd_decode.o
 obj-$(CONFIG_GOOGLE_VPD)		+= vpd-sysfs.o
+
+# LinuxBootSMM related.
+payload-mm-$(CONFIG_COREBOOT_PAYLOAD_MM)	:= mm_loader.o mm_blob.o
+
+subdir-						:= mm_handler
+obj-$(CONFIG_COREBOOT_PAYLOAD_MM)		+= payload-mm.o
+
+$(obj)/mm_blob.o: $(obj)/mm_handler/handler.bin
+
+$(obj)/mm_handler/handler.bin: FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/mm_handler $@
drivers/firmware/google/mm_blob.S new file +20 -0
new file mode 100644
index 0000000000000000000000000000000000000000..d45ff661d74ab85fbb283704df7ceeee475dcbc5
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Derived from rmpiggy.S.
+ *
+ * Wrapper script for the MM payload binary as a transport object
+ * before copying to SMRAM memory.
+ */
+#include <linux/linkage.h>
+#include <asm/page_types.h>
+
+	.section ".data","aw"
+
+	.balign PAGE_SIZE
+
+SYM_DATA_START(mm_blob)
+	.incbin	"drivers/firmware/google/mm_handler/handler.bin"
+SYM_DATA_END_LABEL(mm_blob, SYM_L_GLOBAL, mm_blob_end)
+
+SYM_DATA_START(mm_relocs)
+	.incbin	"drivers/firmware/google/mm_handler/handler.relocs"
+SYM_DATA_END(mm_relocs)
drivers/firmware/google/mm_loader.c new file +215 -0

215 lines not on this page · raw message

Signature · 1 line
2.49.0
#4 lore raw

Re: [PATCH v2 2/3] firmware: coreboot: loader for Linux-owned SMI handler

Quoted 2 lines · Michal Gorlas

Places a blob with Linux-owned SMI handler in the lower 4GB of memory, calculates entry points for the it and triggers SMI to coreboot's SMI handler

                   ^^^

s/the//? s/Places/Place/;s/calculates/calculate/;s/triggers/trigger/.

Quoted 1 line

informing it where to look for Linux-owned SMI handler.

How about repharse the message to something like:

Load Linux-owned SMI handler:
- Place Linux-owned SMI handler in ...
- Inform coreboot the location of Linux-owned SMI handler via SMI ...

On success, the Linux-owned SMI handler takes over all upcoming SMIs.

drivers/firmware/google/Makefile obj-$(CONFIG_GOOGLE_CBMEM) += cbmem.o · line 19

Quoted 7 lines
drivers/firmware/google/Makefile +5 -0
[...]
+
+# LinuxBootSMM related.
+payload-mm-$(CONFIG_COREBOOT_PAYLOAD_MM)	:= mm_loader.o mm_blob.o
+
+subdir-						:= mm_handler

subdir-$(CONFIG_COREBOOT_PAYLOAD_MM)?

drivers/firmware/google/Makefile obj-$(CONFIG_GOOGLE_CBMEM) += cbmem.o · line 25

Quoted 6 lines
drivers/firmware/google/Makefile +6 -0
+obj-$(CONFIG_COREBOOT_PAYLOAD_MM)		+= payload-mm.o
+
+$(obj)/mm_blob.o: $(obj)/mm_handler/handler.bin
+
+$(obj)/mm_handler/handler.bin: FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/mm_handler $@

mm_handler/ isn't visible to this patch. Separate them into the following patch of series?

drivers/firmware/google/mm_blob.S line 20

Quoted 9 lines
drivers/firmware/google/mm_blob.S +7 -0
[...]
+SYM_DATA_START(mm_blob)
+	.incbin	"drivers/firmware/google/mm_handler/handler.bin"
+SYM_DATA_END_LABEL(mm_blob, SYM_L_GLOBAL, mm_blob_end)
+
+SYM_DATA_START(mm_relocs)
+	.incbin	"drivers/firmware/google/mm_handler/handler.relocs"
+SYM_DATA_END(mm_relocs)

mm_handler/ isn't visible to this patch. Separate them into the following patch of series?

drivers/firmware/google/mm_loader.c line 17

Quoted 10 lines
drivers/firmware/google/mm_loader.c +8 -0
[...]
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/cpu.h>
+#include <linux/delay.h>
+#include <linux/gfp.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/device.h>

Please review again if it really needs to include the headers. Does it need to include cpu.h, mm.h, and slab.h?

Also sort them alphabetically.

drivers/firmware/google/mm_loader.c line 26

Quoted 5 lines
drivers/firmware/google/mm_loader.c +5 -0
+struct mm_header *mm_header;
+static void *shared_buffer;
+static size_t blob_size;
+static struct lb_pld_mm_interface_info *mm_cbtable_info;
+struct mm_info *mm_info;

No. Please allocate a driver specific struct and access it via dev_set_drvdata() and dev_get_drvdata() if the context needs to be kept.

drivers/firmware/google/mm_loader.c line 69

Quoted 9 lines
drivers/firmware/google/mm_loader.c +8 -0
+static int trigger_smi(u64 cmd, u64 arg, u64 retry)
+{
+	u64 status;
[...]
+
+	if (status == cmd || status == PAYLOAD_MM_RET_FAILURE)
+		status = PAYLOAD_MM_RET_FAILURE;
+	else
+		status = PAYLOAD_MM_RET_SUCCESS;

No. Please use -errno in the kernel.

Quoted 5 lines
drivers/firmware/google/mm_loader.c +5 -0
+static int get_mm_info(struct coreboot_device *dev)
+{
+	mm_cbtable_info = &dev->mm_info;
+	if (mm_cbtable_info->tag != LB_TAG_PLD_MM_INTERFACE_INFO)
+		return -ENXIO;

drivers/firmware/google/mm_loader.c line 169

Quoted 10 lines
drivers/firmware/google/mm_loader.c +10 -0
+
+	mm_info = devm_kzalloc(&dev->dev, sizeof(*mm_info), GFP_KERNEL);
+	if (!mm_info)
+		return -ENOMEM;
+
+	mm_info->revision = mm_cbtable_info->revision;
+	mm_info->requires_long_mode_call =
+		mm_cbtable_info->requires_long_mode_call;
+	mm_info->register_mm_entry_command =
+		mm_cbtable_info->register_mm_entry_command;

Does it really need to copy the data from &dev->mm_info?

drivers/firmware/google/mm_loader.c line 176

Quoted 4 lines
drivers/firmware/google/mm_loader.c +4 -0
+static int mm_loader_probe(struct coreboot_device *dev)
+{
+	if (get_mm_info(dev))
+		return -ENOMEM;

get_mm_info() isn't necessarily to be -ENOMEM. How about:

    ret = get_mm_info(...);
    if (ret)
        return ret;

drivers/firmware/google/mm_loader.c line 184

Quoted 8 lines
drivers/firmware/google/mm_loader.c +8 -0
+
+	u32 entry_point;
+
+	entry_point = place_handler(&dev->dev);
+
+	if (register_entry_point(&dev->dev, mm_info, entry_point)) {
+		dev_warn(&dev->dev, ": registering entry point for MM payload failed.\n");
+		return -1;

Please use -errno in the kernel. -ENOENT or -ENOTSUPP?

drivers/firmware/google/mm_loader.c line 191

Quoted 7 lines
drivers/firmware/google/mm_loader.c +7 -0
+	}
+
+	/*
+	 * Gives SMI some time in case it takes longer than expected.
+	 * Only useful on real hardware (tested on RaptorLake), not needed on emulation.
+	 */
+	mdelay(100);

This looks weird. Are there some ways for Linux to be aware of the SMI has completed?

#5 lore raw

Re: [PATCH v2 2/3] firmware: coreboot: loader for Linux-owned SMI handler

Quoted 8 lines · Tzung-Bi Shih

How about repharse the message to something like:

Load Linux-owned SMI handler:
- Place Linux-owned SMI handler in ...
- Inform coreboot the location of Linux-owned SMI handler via SMI ...

On success, the Linux-owned SMI handler takes over all upcoming SMIs.

Yep, will do.

Quoted 10 lines

drivers/firmware/google/Makefile obj-$(CONFIG_GOOGLE_CBMEM) += cbmem.o · line 19

Quoted 7 lines
drivers/firmware/google/Makefile +5 -0
[...]
+
+# LinuxBootSMM related.
+payload-mm-$(CONFIG_COREBOOT_PAYLOAD_MM)	:= mm_loader.o mm_blob.o
+
+subdir-						:= mm_handler

subdir-$(CONFIG_COREBOOT_PAYLOAD_MM)?

Right.

Quoted 10 lines

drivers/firmware/google/Makefile obj-$(CONFIG_GOOGLE_CBMEM) += cbmem.o · line 25

Quoted 6 lines
drivers/firmware/google/Makefile +6 -0
+obj-$(CONFIG_COREBOOT_PAYLOAD_MM)		+= payload-mm.o
+
+$(obj)/mm_blob.o: $(obj)/mm_handler/handler.bin
+
+$(obj)/mm_handler/handler.bin: FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/mm_handler $@

mm_handler/ isn't visible to this patch. Separate them into the following patch of series?

Quoted 13 lines

drivers/firmware/google/mm_blob.S line 20

Quoted 9 lines
drivers/firmware/google/mm_blob.S +7 -0
[...]
+SYM_DATA_START(mm_blob)
+	.incbin	"drivers/firmware/google/mm_handler/handler.bin"
+SYM_DATA_END_LABEL(mm_blob, SYM_L_GLOBAL, mm_blob_end)
+
+SYM_DATA_START(mm_relocs)
+	.incbin	"drivers/firmware/google/mm_handler/handler.relocs"
+SYM_DATA_END(mm_relocs)

mm_handler/ isn't visible to this patch. Separate them into the following patch of series?

Would it make sense then to merge patch 2/3 and 3/3 into one? mm_loader depends on mm_blob, and mm_blob depends on mm_handler/ being visible. I wanted to split these initially as the 3rd patch is already terrible to read because of all the assembly code in mm_handler/. But if it makes sense to have them as one patch, I'll do that.

Quoted 14 lines

drivers/firmware/google/mm_loader.c line 17

Quoted 10 lines
drivers/firmware/google/mm_loader.c +8 -0
[...]
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/cpu.h>
+#include <linux/delay.h>
+#include <linux/gfp.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/device.h>

Please review again if it really needs to include the headers. Does it need to include cpu.h, mm.h, and slab.h?

Quoted 2 lines

Also sort them alphabetically.

Right, I forgot to clean these up, my bad.

Quoted 9 lines

drivers/firmware/google/mm_loader.c line 26

Quoted 5 lines
drivers/firmware/google/mm_loader.c +5 -0
+struct mm_header *mm_header;
+static void *shared_buffer;
+static size_t blob_size;
+static struct lb_pld_mm_interface_info *mm_cbtable_info;
+struct mm_info *mm_info;

No. Please allocate a driver specific struct and access it via dev_set_drvdata() and dev_get_drvdata() if the context needs to be kept.

Yep will do.

Quoted 12 lines

drivers/firmware/google/mm_loader.c line 69

Quoted 9 lines
drivers/firmware/google/mm_loader.c +8 -0
+static int trigger_smi(u64 cmd, u64 arg, u64 retry)
+{
+	u64 status;
[...]
+
+	if (status == cmd || status == PAYLOAD_MM_RET_FAILURE)
+		status = PAYLOAD_MM_RET_FAILURE;
+	else
+		status = PAYLOAD_MM_RET_SUCCESS;

No. Please use -errno in the kernel.

In which line here exactly? In the conditional statement I explicitly check for RAX (and hence status) being 1. Not sure if status == EPERM would make any sense here. I guess you meant specifically status = PAYLOAD_MM_RET_FAILURE? Then what would be appropriate -errno? I think it could be -EREMOTEIO or -EIO, since the APMC SMI which trigger_smi does is an I/O write. But I am not sure if that's the appropriate errno.

Quoted 9 lines
Quoted 9 lines
drivers/firmware/google/mm_loader.c +9 -0
+static int get_mm_info(struct coreboot_device *dev)
+{
+	mm_cbtable_info = &dev->mm_info;
+	if (mm_cbtable_info->tag != LB_TAG_PLD_MM_INTERFACE_INFO)
+		return -ENXIO;
+
+	mm_info = devm_kzalloc(&dev->dev, sizeof(*mm_info), GFP_KERNEL);
+	if (!mm_info)
+		return -ENOMEM;
Quoted 9 lines

drivers/firmware/google/mm_loader.c line 169

Quoted 6 lines
drivers/firmware/google/mm_loader.c +6 -0
+
+	mm_info->revision = mm_cbtable_info->revision;
+	mm_info->requires_long_mode_call =
+		mm_cbtable_info->requires_long_mode_call;
+	mm_info->register_mm_entry_command =
+		mm_cbtable_info->register_mm_entry_command;

Does it really need to copy the data from &dev->mm_info?

Not necessarily, the concept of copying the data made sense with v1 patches where the "parser" was in separate module, and was exporting mm_info to mm_loader. I think it would be sufficient here to get rid of get_mm_info and just let mm_loader_probe check for the tag:

	mm_cbtable_info = &dev->mm_info;
	if (mm_cbtable_info->tag != LB_TAG_PLD_MM_INTERFACE_INFO)
		return -ENXIO;	
Quoted 11 lines

drivers/firmware/google/mm_loader.c line 184

Quoted 8 lines
drivers/firmware/google/mm_loader.c +8 -0
+
+	u32 entry_point;
+
+	entry_point = place_handler(&dev->dev);
+
+	if (register_entry_point(&dev->dev, mm_info, entry_point)) {
+		dev_warn(&dev->dev, ": registering entry point for MM payload failed.\n");
+		return -1;

Please use -errno in the kernel. -ENOENT or -ENOTSUPP?

Yep. -ENOTSUPP fits here.

Quoted 10 lines

drivers/firmware/google/mm_loader.c line 191

Quoted 7 lines
drivers/firmware/google/mm_loader.c +7 -0
+	}
+
+	/*
+	 * Gives SMI some time in case it takes longer than expected.
+	 * Only useful on real hardware (tested on RaptorLake), not needed on emulation.
+	 */
+	mdelay(100);

This looks weird. Are there some ways for Linux to be aware of the SMI has completed?

Not in a straight forward fashion. On Intel SoCs we could read MSR_SMI_COUNT
[1] before and after sending an SMI, and wait till it increments. I am not aware about any unified way that works for AMD SoCs. However, so far none of the AMD boards supported by coreboot was tested with MM payload, so to make it Intel-only in v3 is not a bad idea.

[1]: https://elixir.bootlin.com/linux/v6.16-rc3/source/arch/x86/include/asm/msr-index.h#L880

#6 lore raw

Re: [PATCH v2 2/3] firmware: coreboot: loader for Linux-owned SMI handler

Quoted 10 lines · Michal Gorlas
Quoted 9 lines

drivers/firmware/google/mm_loader.c line 191

Quoted 6 lines
drivers/firmware/google/mm_loader.c new file +6 -0
+
+	/*
+	 * Gives SMI some time in case it takes longer than expected.
+	 * Only useful on real hardware (tested on RaptorLake), not needed on emulation.
+	 */
+	mdelay(100);

This looks weird. Are there some ways for Linux to be aware of the SMI has completed?

Quoted 7 lines

Not in a straight forward fashion. On Intel SoCs we could read MSR_SMI_COUNT
[1] before and after sending an SMI, and wait till it increments. I am not aware about any unified way that works for AMD SoCs. However, so far none of the AMD boards supported by coreboot was tested with MM payload, so to make it Intel-only in v3 is not a bad idea.

[1]: https://elixir.bootlin.com/linux/v6.16-rc3/source/arch/x86/include/asm/msr-index.h#L880

As a follow-up here, making COREBOOT_PAYLOAD_MM dependent on !SMP resolves the need of acknowledging SMI completion. If SMI takes longer, Linux is just stalled until SMI handler gives the CPU back to the caller. I think for this case it could be the way, LinuxBoot is by default compiled without SMP support anyways when used as coreboot's payload [1], [2].

[1]: https://github.com/coreboot/coreboot/blob/main/payloads/external/LinuxBoot/x86_64/defconfig
[2]: https://github.com/coreboot/coreboot/blob/main/payloads/external/LinuxBoot/i386/defconfig

#7 lore raw

Re: [PATCH v2 2/3] firmware: coreboot: loader for Linux-owned SMI handler

Quoted 26 lines · Michal Gorlas
Quoted 10 lines · Michal Gorlas
Quoted 9 lines

drivers/firmware/google/mm_loader.c line 191

Quoted 6 lines
drivers/firmware/google/mm_loader.c new file +6 -0
+
+	/*
+	 * Gives SMI some time in case it takes longer than expected.
+	 * Only useful on real hardware (tested on RaptorLake), not needed on emulation.
+	 */
+	mdelay(100);

This looks weird. Are there some ways for Linux to be aware of the SMI has completed?

Quoted 7 lines

Not in a straight forward fashion. On Intel SoCs we could read MSR_SMI_COUNT
[1] before and after sending an SMI, and wait till it increments. I am not aware about any unified way that works for AMD SoCs. However, so far none of the AMD boards supported by coreboot was tested with MM payload, so to make it Intel-only in v3 is not a bad idea.

[1]: https://elixir.bootlin.com/linux/v6.16-rc3/source/arch/x86/include/asm/msr-index.h#L880

As a follow-up here, making COREBOOT_PAYLOAD_MM dependent on !SMP resolves the need of acknowledging SMI completion. If SMI takes longer, Linux is just stalled until SMI handler gives the CPU back to the caller. I think for this case it could be the way, LinuxBoot is by default compiled without SMP support anyways when used as coreboot's payload [1], [2].

Quoted 2 lines

[1]: https://github.com/coreboot/coreboot/blob/main/payloads/external/LinuxBoot/x86_64/defconfig
[2]: https://github.com/coreboot/coreboot/blob/main/payloads/external/LinuxBoot/i386/defconfig

To make sure I understand: do you mean the trigger_smi() becomes a blocking call without a timeout?

I may misunderstand: depends on !SMP which also means it can't use on most modern architectures.

#8 lore raw

Re: [PATCH v2 2/3] firmware: coreboot: loader for Linux-owned SMI handler

Quoted 27 lines · Tzung-Bi Shih
Quoted 26 lines · Michal Gorlas
Quoted 10 lines · Michal Gorlas
Quoted 9 lines

drivers/firmware/google/mm_loader.c line 191

Quoted 6 lines
drivers/firmware/google/mm_loader.c new file +6 -0
+
+	/*
+	 * Gives SMI some time in case it takes longer than expected.
+	 * Only useful on real hardware (tested on RaptorLake), not needed on emulation.
+	 */
+	mdelay(100);

This looks weird. Are there some ways for Linux to be aware of the SMI has completed?

Quoted 7 lines

Not in a straight forward fashion. On Intel SoCs we could read MSR_SMI_COUNT
[1] before and after sending an SMI, and wait till it increments. I am not aware about any unified way that works for AMD SoCs. However, so far none of the AMD boards supported by coreboot was tested with MM payload, so to make it Intel-only in v3 is not a bad idea.

[1]: https://elixir.bootlin.com/linux/v6.16-rc3/source/arch/x86/include/asm/msr-index.h#L880

As a follow-up here, making COREBOOT_PAYLOAD_MM dependent on !SMP resolves the need of acknowledging SMI completion. If SMI takes longer, Linux is just stalled until SMI handler gives the CPU back to the caller. I think for this case it could be the way, LinuxBoot is by default compiled without SMP support anyways when used as coreboot's payload [1], [2].

Quoted 5 lines
Quoted 2 lines

[1]: https://github.com/coreboot/coreboot/blob/main/payloads/external/LinuxBoot/x86_64/defconfig
[2]: https://github.com/coreboot/coreboot/blob/main/payloads/external/LinuxBoot/i386/defconfig

To make sure I understand: do you mean the trigger_smi() becomes a blocking call without a timeout?

Short answer: potentially yes. Longer answer:

"mov %[apmc_port], %%dx\n\t"
"outb %%al, %%dx\n\t"

in trigger_smi() will switch CPU context to SMM, meaning, current state is saved and CPU starts executing whatever instructions are under the address stored under SMBASE register. At this point, Linux has no control over that CPU, which can cause chaos, particulary on real hardware. I am not an expert on how the scheduler is implemented, but I can imagine it will assign next not-blocked CPU to execute the instructions coming after trigger_smi(), while SMI is still being handled on other CPU.

Quoted 3 lines

I may misunderstand: depends on !SMP which also means it can't use on most modern architectures.

Not necessarily. This driver is useful only if Linux is used to be coreboot payload (aka LinuxBoot). As far as I know there is no real need to have SMP enabled there, sole responsibility of the LinuxBoot is to bring-up remaining hardware (similar to Driver Execution Environment (DXE) responsibilities when booting with UEFI), and kexec to the OS kernel, which is likely built with SMP.

#9 lore raw

Re: [PATCH v2 2/3] firmware: coreboot: loader for Linux-owned SMI handler

In reply to Michal Gorlas
Quoted 25 lines · Michal Gorlas
Quoted 10 lines · Tzung-Bi Shih

drivers/firmware/google/Makefile obj-$(CONFIG_GOOGLE_CBMEM) += cbmem.o · line 25

Quoted 6 lines
drivers/firmware/google/Makefile +6 -0
+obj-$(CONFIG_COREBOOT_PAYLOAD_MM)		+= payload-mm.o
+
+$(obj)/mm_blob.o: $(obj)/mm_handler/handler.bin
+
+$(obj)/mm_handler/handler.bin: FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/mm_handler $@

mm_handler/ isn't visible to this patch. Separate them into the following patch of series?

Quoted 13 lines

drivers/firmware/google/mm_blob.S line 20

Quoted 9 lines
drivers/firmware/google/mm_blob.S +7 -0
[...]
+SYM_DATA_START(mm_blob)
+	.incbin	"drivers/firmware/google/mm_handler/handler.bin"
+SYM_DATA_END_LABEL(mm_blob, SYM_L_GLOBAL, mm_blob_end)
+
+SYM_DATA_START(mm_relocs)
+	.incbin	"drivers/firmware/google/mm_handler/handler.relocs"
+SYM_DATA_END(mm_relocs)

mm_handler/ isn't visible to this patch. Separate them into the following patch of series?

Quoted 5 lines

Would it make sense then to merge patch 2/3 and 3/3 into one? mm_loader depends on mm_blob, and mm_blob depends on mm_handler/ being visible. I wanted to split these initially as the 3rd patch is already terrible to read because of all the assembly code in mm_handler/. But if it makes sense to have them as one patch, I'll do that.

Yes, please merge them if that makes sense. Otherwise, you could still separate them via providing a "nop" mm_handler (e.g. just returns success) in the 2nd patch and implement the handler details in the 3rd patch.

Quoted 13 lines
Quoted 12 lines

drivers/firmware/google/mm_blob.S

Quoted 9 lines
drivers/firmware/google/mm_blob.S +8 -0
+static int trigger_smi(u64 cmd, u64 arg, u64 retry)
+{
+	u64 status;
[...]
+
+	if (status == cmd || status == PAYLOAD_MM_RET_FAILURE)
+		status = PAYLOAD_MM_RET_FAILURE;
+	else
+		status = PAYLOAD_MM_RET_SUCCESS;

No. Please use -errno in the kernel.

Quoted 7 lines

In which line here exactly? In the conditional statement I explicitly check for RAX (and hence status) being 1. Not sure if status == EPERM would make any sense here. I guess you meant specifically status = PAYLOAD_MM_RET_FAILURE? Then what would be appropriate -errno? I think it could be -EREMOTEIO or -EIO, since the APMC SMI which trigger_smi does is an I/O write. But I am not sure if that's the appropriate errno.

Let trigger_smi() return 0 on success; or, -errno. Eliminate the 2 macros (PAYLOAD_MM_RET_*).

-EIO makes sense.

#10 lore raw

PATCH v2 3/3 firmware: coreboot: Linux-owned SMI handler to be loaded by coreboot

In reply to Michal Gorlas

Compiled in similar fashion to the realmode trampolines for x86. Currently supported are two SMIs: ACPI enable and disable. After being placed in SMRAM, this handler takes over handling of the supported SMIs from coreboot.

---
 drivers/firmware/google/mm_handler/.gitignore    |   4 +
 drivers/firmware/google/mm_handler/Makefile      |  51 +++
 drivers/firmware/google/mm_handler/handler.lds.S |  46 ++
 drivers/firmware/google/mm_handler/mm_handler.S  | 510 +++++++++++++++++++++++
 drivers/firmware/google/mm_handler/mm_handler.h  |  21 +
 drivers/firmware/google/mm_handler/mm_header.S   |  19 +
 6 files changed, 651 insertions(+)
drivers/firmware/google/mm_handler/.gitignore new file +4 -0
new file mode 100644
index 0000000000000000000000000000000000000000..662f71dca9ce9dceeaf526746a6f323044296439
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+pasyms.h
+handler.lds
+handler.relocs
drivers/firmware/google/mm_handler/Makefile new file +51 -0

51 lines not on this page · raw message

drivers/firmware/google/mm_handler/handler.lds.S new file +46 -0

46 lines not on this page · raw message

drivers/firmware/google/mm_handler/mm_handler.S new file +510 -0

510 lines not on this page · raw message

drivers/firmware/google/mm_handler/mm_handler.h new file +21 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4f32f84371d5cff3fcf6c9d1c1c33a2d2b50118e
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Derived from arch/x86/include/realmode.h
+ */
+
+#ifndef _MM_HANDLER_H
+#define _MM_HANDLER_H
+
+#define REALMODE_END_SIGNATURE	0x65a22c82
+
+/*
+ * These macros correspond to the arguments
+ * passed by coreboot's SMI handler. Depending
+ * on which one is passed in rdi or esp + x, handler
+ * will jump to the appropriate section.
+ */
+#define MM_ACPI_ENABLE		1
+#define MM_ACPI_DISABLE		0
+#define MM_STORE		2
+
+#endif /* _MM_HANDLER_H */
drivers/firmware/google/mm_handler/mm_header.S new file +19 -0
new file mode 100644
index 0000000000000000000000000000000000000000..342cd60492f89f8bea8d7051650365d1eaad4c2e
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * MM blob header; this should match mm_payload.h
+ */
+
+#include <linux/linkage.h>
+#include <asm/page_types.h>
+#include <asm/segment.h>
+
+	.section ".header", "a"
+
+	.balign	16
+SYM_DATA_START(mm_header)
+	.long	pa_text_start
+	.long	pa_mm_entry_32
+	.long	pa_mm_entry_64
+	.long	pa_mm_signature
+	.long	pa_mm_blob_size
+SYM_DATA_END(mm_header)
Signature · 1 line
2.49.0
#11 lore raw
In reply to Michal Gorlas
Quoted 3 lines · Michal Gorlas

Hi,

This patchset adds support for MM payload when Linux is used as

Please provide some annotation when you first time use the acronyms for readability. From the context, here MM stands for Management Mode?

Quoted 9 lines

coreboot's payload. The main idea is to delegate higher-level SMM functions to the payload, limiting the coreboot's System Management Mode (SMM) related responsibilities to the minimum of basic SMM setup [1]. This is done by loading a blob with SMI handler to the shared buffer, from which it is copied to SMRAM [2].

The MM payload is still in a Proof of Concept stage, and we are still working on getting the patches needed for coreboot upstreamed, but I would appreciate any feedback that you may have.

I don't think I could provide any useful comments to the feature. Only feedbacked some general comments for the driver parts.