firmware: coreboot: Support for System Management Interrupt (SMI) handling in coreboot payload (MM payload concept)
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]>
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
@@ -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
@@ -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
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_MMconfig 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
PATCH v2 2/3 firmware: coreboot: loader for Linux-owned SMI handler
In reply to Michal GorlasPlaces 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
@@ -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
@@ -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
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?
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_handlersubdir-$(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, andslab.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()anddev_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.
-ENOENTor-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
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
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_MMdependent 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.
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_MMdependent 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/defconfigTo 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.
Re: [PATCH v2 2/3] firmware: coreboot: loader for Linux-owned SMI handler
In reply to Michal GorlasQuoted 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_loaderdepends onmm_blob, andmm_blobdepends 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-EREMOTEIOor-EIO, since the APMC SMI whichtrigger_smidoes 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.
PATCH v2 3/3 firmware: coreboot: Linux-owned SMI handler to be loaded by coreboot
In reply to Michal GorlasCompiled 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
@@ -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
@@ -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
@@ -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
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.