x86: Trenchboot Secure Launch DRTM (Xen)
v4 cover x86: Trenchboot Secure Launch DRTM (Xen)
The aim of the [TrenchBoot] project is to provide an implementation of DRTM that is generic enough to cover various use cases:
- Intel TXT and AMD SKINIT on x86 CPUs
- legacy and UEFI boot
- TPM1.2 and TPM2.0 (TIS and CRB)
- (in the future) DRTM on Arm CPUs
DRTM is a version of a measured launch that starts on request rather than at the start of a boot cycle. One of its advantages is in not including the firmware in the chain of trust.
Xen already supports DRTM via [tboot] which targets Intel TXT only. tboot encapsulates some of the DRTM details within itself while with TrenchBoot Xen (or Linux) is meant to be a self-contained payload for a TrenchBoot-enabled bootloader (think GRUB). The one exception is that UEFI case requires calling back into bootloader to initiate DRTM, which is necessary to give Xen a chance of querying all the information it needs from the firmware before performing DRTM start.
From reading the above tboot might seem like a more abstracted, but the reality is that the payload needs to have DRTM-specific knowledge either way. In principle, TrenchBoot, allows coming up with independent implementations of bootloaders and payloads that are compatible with each other.
The "x86/boot: choose AP stack based on APIC ID" patch is shared with [Parallelize AP bring-up] series and is required here because Intel TXT always releases all APs simultaneously. The rest of the patches are unique.
This version of the patches corresponds to this branch:
https://github.com/TrenchBoot/xen/compare/7c77acd452fb...tb-staging-2026-07-31-v4
-----
[TrenchBoot]: https://trenchboot.org/
[tboot]: https://sourceforge.net/p/tboot/wiki/Home/
[Parallelize AP bring-up]: https://lore.kernel.org/xen-devel/[email protected]/
[v1]: https://lore.kernel.org/xen-devel/[email protected]/
[v2]: https://lore.kernel.org/xen-devel/[email protected]/
[v3]: https://lore.kernel.org/xen-devel/[email protected]/
-----
Changes in v4:
- added notes to individial commits, the notes below cover some of more generic changes or those spanning multiple commits
- dropped SHA-1 changes (was committed independently of this patchset)
- added CONFIG_SLAUNCH Kconfig option
- TPM driver changes have been moved to the front and are now independent from TPM event log and the rest of this patchset in general
- a few commits were split, joined and/or renamed to make changes more independent, see notes in individual patches
- added support for communicating with TPM2.0 via CRB and memory protection using TPR to support newer handware
- moved UEFI_SLR_TABLE_GUID from xen/include/xen/slr-table.h to xen/common/efi/boot.c
- changed the code for dealing with tables in TXT heap to be iterative
- added more implementation-specific error codes and removed unused ones
- extracted declarations from tpm.c into headers for TPM1.2 and TPM2.0
- return EACCES instead of EPERM when refusing to go into S3 state
- moved SLAUNCH_BOOTLOADER_MAGIC from x86/asm/intel-txt.h to x86/boot/head.S
- moved making MTRR-related functions public to commit which uses them
- use container_of() after slr_next_entry_by_tag() instead of a cast
- made more code that deals with SLRT const-correct (including adding const to the parameter of dl_handler_func)
- absent TPM event log is now consistently allowed by both TPM1.2 and TPM2.0 implementations
Changes in [v3]:
- sorted F: entries in MAINTAINERS file
- made sha1 implementation more similar to sha256
- dropped unused parameter from xen/arch/x86/cpu/intel.c:intel_log_smx_txt()
- updated header guards according to new style
- xen/arch/x86/include/asm/intel-txt.h:
+ briefly explained what TXT is
+ renamed: NR_TXT_CONFIG_SIZE -> TXT_CONFIG_SPACE_SIZE
+ renamed: read_txt_reg() -> txt_read()
+ renamed: write_txt_reg() -> txt_write()
+ marked txt_reset() as noreturn and used unreacheable() instead of
while(1)
+ explained a bit more about TXT Heap
- xen/include/xen/slr-table.h:
+ briefly explained what SLRT is
+ fixed checks in slr_next_entry()
- SPDX-License-Identifier: GPL-2.0 -> GPL-2.0-only
- made more code const-correct
- use arithmetic on pointers to void instead of pointers to uint8_t
Changes in [v2]:
- using dashes instead of underscores in the names of new files
- dropping of an extra sha256 implementation
- rewriting sha1 implementation to be in line with already present sha256 implementation (simplifying it and getting rid of macros)
- correct placement of new lines in Makefile
- add header guards to all new files
- use correct names for header guards in new files
- update license of xen/include/xen/slr-table.h
- changed fixmlehdr to search for header within 8 instead of 4 KiB file prefix
- don't print DRTM-related capabilities when resuming from S3
- forbade S3 in case of Secure Launch
- fixed an issue with resuming from S3 caused by inappropriate use of __initdata
- added a new section to MAINTAINERS
- improved commit messages
- fixed MISRA C violations:
+ shadowing of e820 global
+ missing U literal suffixes
+ use of ull literal suffix
+ excluded fixmlehdr from analysis (similar to other build tools)
+ use of 0 instead of NULL in one place
+ provided declarations for some definitions
+ marked asm-invoked functions with asmlinkage
-----
Kacper Stojek (2):
x86/boot: add CONFIG_SLAUNCH, MLE header and Secure Launch entry point xen/arch/x86: reserve TXT memory during Slaunch
Krystian Hebel (7):
x86/tpm.c: hashing and extending PCRs for TPM1.2 x86/include/asm/intel-txt.h: constants and accessors for TXT registers
and heap
x86/boot/slaunch-early: early Intel TXT sanity checks x86/slaunch: restore boot MTRRs after Intel TXT DRTM x86/slaunch: measure MBI into TPM
x86/boot: choose AP stack based on APIC ID
x86/smpboot.c: TXT AP bringup
Michał Żygowski (2):
x86/cpu: report SMX, TXT and SKINIT capabilities x86/hvm: check for VMX in SMX if Slaunch is active
Sergii Dmytruk (10):
x86/mtrr: get rid of a static variable on pause/restore x86/tpm.c: support extending PCRs of TPM2.0 via TIS include/xen/slr-table.h: Secure Launch Resource Table definitions x86/boot/slaunch-early: implement early initialization x86/slaunch: update TPM event log (TPM1.2 or TPM2.0) x86/slaunch: process DRTM policy
x86/acpi: disallow S3 on Secure Launch boot x86/slaunch: support AMD CPUs
x86/slaunch: support EFI boot
MAINTAINERS: add a section for TrenchBoot Slaunch
Szymon Acedański (2):
x86/tpm.c: add CRB interface support
xen/arch/x86: add TPR (TXT Protected Range) DMA protection support
.gitignore | 1 + MAINTAINERS | 19 + .../eclair_analysis/ECLAIR/out_of_scope.ecl | 1 + docs/hypervisor-guide/x86/how-xen-boots.rst | 12 + xen/arch/x86/Kconfig | 8 + xen/arch/x86/Makefile | 16 +- xen/arch/x86/acpi/power.c | 8 + xen/arch/x86/boot/Makefile | 22 +- xen/arch/x86/boot/head.S | 267 ++++++ xen/arch/x86/boot/slaunch-early.c | 104 +++ xen/arch/x86/boot/trampoline.S | 42 +- xen/arch/x86/boot/x86_64.S | 67 +- xen/arch/x86/cpu/amd.c | 16 + xen/arch/x86/cpu/cpu.h | 1 + xen/arch/x86/cpu/hygon.c | 1 + xen/arch/x86/cpu/intel.c | 50 + xen/arch/x86/cpu/mtrr/generic.c | 50 +- xen/arch/x86/e820.c | 5 + xen/arch/x86/efi/efi-boot.h | 95 +- xen/arch/x86/efi/fixmlehdr.c | 127 +++ xen/arch/x86/hvm/vmx/vmcs.c | 3 +- xen/arch/x86/include/asm/apicdef.h | 4 + xen/arch/x86/include/asm/intel-txt.h | 573 ++++++++++++ xen/arch/x86/include/asm/msr-index.h | 3 + xen/arch/x86/include/asm/mtrr.h | 8 + xen/arch/x86/include/asm/processor.h | 1 + xen/arch/x86/include/asm/setup.h | 3 + xen/arch/x86/include/asm/slaunch-tpm.h | 26 + xen/arch/x86/include/asm/slaunch.h | 128 +++ xen/arch/x86/include/asm/tpm.h | 74 ++ xen/arch/x86/include/asm/tpm1.h | 94 ++ xen/arch/x86/include/asm/tpm2.h | 150 +++ xen/arch/x86/intel-txt.c | 197 ++++ xen/arch/x86/setup.c | 32 +- xen/arch/x86/slaunch-tpm.c | 312 +++++++ xen/arch/x86/slaunch.c | 478 ++++++++++ xen/arch/x86/smpboot.c | 75 ++ xen/arch/x86/tboot.c | 20 +- xen/arch/x86/tpm.c | 862 ++++++++++++++++++ xen/arch/x86/x86_64/asm-offsets.c | 13 + xen/common/efi/boot.c | 6 + xen/common/efi/runtime.c | 1 + xen/include/xen/efi.h | 1 + xen/include/xen/slr-table.h | 272 ++++++ 44 files changed, 4191 insertions(+), 57 deletions(-) create mode 100644 xen/arch/x86/boot/slaunch-early.c create mode 100644 xen/arch/x86/efi/fixmlehdr.c create mode 100644 xen/arch/x86/include/asm/intel-txt.h create mode 100644 xen/arch/x86/include/asm/slaunch-tpm.h create mode 100644 xen/arch/x86/include/asm/slaunch.h create mode 100644 xen/arch/x86/include/asm/tpm.h create mode 100644 xen/arch/x86/include/asm/tpm1.h create mode 100644 xen/arch/x86/include/asm/tpm2.h create mode 100644 xen/arch/x86/intel-txt.c create mode 100644 xen/arch/x86/slaunch-tpm.c create mode 100644 xen/arch/x86/slaunch.c create mode 100644 xen/arch/x86/tpm.c create mode 100644 xen/include/xen/slr-table.h
base-commit: 7c77acd452fb6a3079661e75ebb5cf23ed985cc7
Signature · 1 line
2.55.0
PATCH v4 1/23 x86/mtrr: get rid of a static variable on pause/restore
In addition to keeping the state in one place instead of on stack and in a static variable, this enables exposing this functionality to other units in the future.
---
Notes:
v4: was called "x86/mtrr: expose functions for pausing caching"
v4: no longer makes anything public, just updates implementation
v4: the state structure is now an output parameter instead of a return value
v4: switches from rdmsrl() to rdmsr() on one line that's updated anyway
xen/arch/x86/cpu/mtrr/generic.c | 55 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 27 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +28 -27
@@ -14,6 +14,11 @@#include <asm/cpufeature.h> #include "mtrr.h" +struct mtrr_pausing_state { +bool pge; +uint64_t def_type; +}; + static const struct fixed_range_block { uint32_t base_msr; /* start address of an MTRR block */ unsigned int ranges; /* number of MTRRs in this block */
@@ -395,9 +400,7 @@ static bool set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)return changed; } -static uint64_t deftype; - -static unsigned long set_mtrr_state (void ) +static unsigned long set_mtrr_state (uint64_t *deftype)/* [SUMMARY] Set the MTRR state for this CPU. <state> The MTRR state information to read. <ctxt> Some relevant CPU context.
@@ -415,14 +418,12 @@ static unsigned long set_mtrr_state(void)if (mtrr_state.have_fixed &&set_fixed_ranges (mtrr_state.fixed_ranges)) change_mask |=MTRR_CHANGE_MASK_FIXED ; -/* Set_mtrr_restore restores the old value of MTRRdefType, -so to set it we fiddle with the saved value */ -if ((deftype &0xff ) != mtrr_state.def_type - ||MASK_EXTR (deftype, MTRRdefType_E) != mtrr_state.enabled - ||MASK_EXTR (deftype, MTRRdefType_FE) != mtrr_state.fixed_enabled) { - deftype = (deftype & ~0xcff ) | mtrr_state.def_type | -MASK_INSR (mtrr_state.enabled, MTRRdefType_E) | -MASK_INSR (mtrr_state.fixed_enabled, MTRRdefType_FE); +if ((*deftype &0xff ) != mtrr_state.def_type + ||MASK_EXTR (*deftype, MTRRdefType_E) != mtrr_state.enabled + ||MASK_EXTR (*deftype, MTRRdefType_FE) != mtrr_state.fixed_enabled) { + *deftype = (*deftype & ~0xcff ) | mtrr_state.def_type | +MASK_INSR (mtrr_state.enabled, MTRRdefType_E) | +MASK_INSR (mtrr_state.fixed_enabled, MTRRdefType_FE); change_mask |=MTRR_CHANGE_MASK_DEFTYPE ; }
@@ -439,7 +440,7 @@ static DEFINE_SPINLOCK(set_atomicity_lock);* has been called. */ -static bool prepare_set (void ) +static void mtrr_pause_caching (struct mtrr_pausing_state *state) {unsigned long cr4;
@@ -461,7 +462,9 @@ static bool prepare_set(void)alternative ("wbinvd" ,"" ,X86_FEATURE_XEN_SELFSNOOP ); cr4 =read_cr4 (); -if (cr4 &X86_CR4_PGE ) + state->pge = cr4 &X86_CR4_PGE ; + +if (state->pge)write_cr4 (cr4 & ~X86_CR4_PGE );else if (use_invpcid)invpcid_flush_all ();
@@ -469,27 +472,25 @@ static bool prepare_set(void)write_cr3 (read_cr3 ());/* Save MTRR state */ -rdmsrl (MSR_MTRRdefType, deftype); + state->def_type =rdmsr (MSR_MTRRdefType);/* Disable MTRRs, and set the default type to uncached */ -mtrr_wrmsr (MSR_MTRRdefType, deftype & ~0xcff ); +mtrr_wrmsr (MSR_MTRRdefType, state->def_type & ~0xcff );/* Again, only flush caches if we have to. */ alternative ("wbinvd" ,"" ,X86_FEATURE_XEN_SELFSNOOP ); - -return cr4 &X86_CR4_PGE ; } -static void post_set (bool pge) +static void mtrr_resume_caching (struct mtrr_pausing_state state) {/* Intel (P6) standard MTRRs */ -mtrr_wrmsr (MSR_MTRRdefType, deftype); +mtrr_wrmsr (MSR_MTRRdefType, state.def_type);/* Enable caches */ write_cr0 (read_cr0 () & ~X86_CR0_CD );/* Reenable CR4.PGE (also flushes the TLB) */ -if (pge) +if (state.pge)write_cr4 (read_cr4 () |X86_CR4_PGE );else if (use_invpcid)invpcid_flush_all ();
@@ -503,15 +504,15 @@ void mtrr_set_all(void) {unsigned long mask, count;unsigned long flags; -bool pge; +struct mtrr_pausing_state pausing_state;local_irq_save (flags); - pge =prepare_set (); +mtrr_pause_caching (&pausing_state);/* Actually set the state */ - mask =set_mtrr_state (); + mask =set_mtrr_state (&pausing_state.def_type); -post_set (pge); +mtrr_resume_caching (pausing_state);local_irq_restore (flags);/* Use the atomic bitops to update the global mask */
@@ -536,12 +537,12 @@ void mtrr_set( {unsigned long flags;struct mtrr_var_range *vr; -bool pge; +struct mtrr_pausing_state pausing_state; vr = &mtrr_state.var_ranges[reg];local_irq_save (flags); - pge =prepare_set (); +mtrr_pause_caching (&pausing_state);if (size ==0 ) {/* The invalid bit is kept in the mask, so we simply clear the
@@ -562,7 +563,7 @@ void mtrr_set(mtrr_wrmsr (MSR_IA32_MTRR_PHYSMASK (reg), vr->mask); } -post_set (pge); +mtrr_resume_caching (pausing_state);local_irq_restore (flags); }
Signature · 1 line
2.55.0
Re: [PATCH v4 01/23] x86/mtrr: get rid of a static variable on pause/restore
Quoted 11 lines · Sergii Dmytruk
In addition to keeping the state in one place instead of on stack and in a static variable, this enables exposing this functionality to other units in the future.
Signed-off-by Sergii Dmytruk <[email protected]>---
Notes:
v4: was called "x86/mtrr: expose functions for pausing caching"
v4: no longer makes anything public, just updates implementation
v4: the state structure is now an output parameter instead of a return value
I don't mind it to stay as you have it now, but recently we discussed this aspect in another context, and I've changed my position: When the struct can be returned in registers, it's okay to return by value.
xen/arch/x86/cpu/mtrr/generic.c static DEFINE_SPINLOCK(set_atomicity_lock); · line 445
Quoted 8 lines
xen/arch/x86/cpu/mtrr/generic.c +1
-1@@ -439,7 +440,7 @@ static DEFINE_SPINLOCK(set_atomicity_lock);* has been called. */ -static bool prepare_set (void ) +static void mtrr_pause_caching (struct mtrr_pausing_state *state) {unsigned long cr4;
Considering the conditional ...
Review static bool prepare_set(void) · line 462
Quoted 2 lines
(quoted diff) +0
-0@@ -461,7 +462,9 @@ static bool prepare_set(void) alternative("wbinvd", "", X86_FEATURE_XEN_SELFSNOOP);
... cache flush that's done (and the comment just out of context also correctly saying "no-fill cache mode"), we're not really pausing caching in all cases. I'm therefore worried of the new names of the two involved functions. Andrew, Roger - thoughts? (My inclination would be to suggest mtrr_{pause,resume}_cache_fill().)
Jan
Re: [PATCH v4 01/23] x86/mtrr: get rid of a static variable on pause/restore
In reply to Sergii DmytrukLe 02/08/2026 à 15:14, Sergii Dmytruk a écrit :
Quoted 93 lines
In addition to keeping the state in one place instead of on stack and in a static variable, this enables exposing this functionality to other units in the future.
Signed-off-by Sergii Dmytruk <[email protected]>---
Notes:
v4: was called "x86/mtrr: expose functions for pausing caching"
v4: no longer makes anything public, just updates implementation
v4: the state structure is now an output parameter instead of a return value
v4: switches fromrdmsrl()tordmsr()on one line that's updated anywayxen/arch/x86/cpu/mtrr/generic.c | 55 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 27 deletions(-)xen/arch/x86/cpu/mtrr/generic.c +17
-15@@ -14,6 +14,11 @@#include <asm/cpufeature.h> #include "mtrr.h" +struct mtrr_pausing_state { +bool pge; +uint64_t def_type; +}; + static const struct fixed_range_block { uint32_t base_msr; /* start address of an MTRR block */ unsigned int ranges; /* number of MTRRs in this block */@@ -395,9 +400,7 @@ static bool set_mtrr_var_ranges(unsigned int index, struct mtrr_var_range *vr)return changed; } -static uint64_t deftype; - -static unsigned long set_mtrr_state (void ) +static unsigned long set_mtrr_state (uint64_t *deftype)/* [SUMMARY] Set the MTRR state for this CPU. <state> The MTRR state information to read. <ctxt> Some relevant CPU context. @@ -415,14 +418,12 @@ static unsigned long set_mtrr_state(void)if (mtrr_state.have_fixed &&set_fixed_ranges (mtrr_state.fixed_ranges)) change_mask |=MTRR_CHANGE_MASK_FIXED ; -/* Set_mtrr_restore restores the old value of MTRRdefType, -so to set it we fiddle with the saved value */ -if ((deftype &0xff ) != mtrr_state.def_type - ||MASK_EXTR (deftype, MTRRdefType_E) != mtrr_state.enabled - ||MASK_EXTR (deftype, MTRRdefType_FE) != mtrr_state.fixed_enabled) { - deftype = (deftype & ~0xcff ) | mtrr_state.def_type | -MASK_INSR (mtrr_state.enabled, MTRRdefType_E) | -MASK_INSR (mtrr_state.fixed_enabled, MTRRdefType_FE); +if ((*deftype &0xff ) != mtrr_state.def_type + ||MASK_EXTR (*deftype, MTRRdefType_E) != mtrr_state.enabled + ||MASK_EXTR (*deftype, MTRRdefType_FE) != mtrr_state.fixed_enabled) { + *deftype = (*deftype & ~0xcff ) | mtrr_state.def_type | +MASK_INSR (mtrr_state.enabled, MTRRdefType_E) | +MASK_INSR (mtrr_state.fixed_enabled, MTRRdefType_FE); change_mask |=MTRR_CHANGE_MASK_DEFTYPE ; }@@ -439,7 +440,7 @@ static DEFINE_SPINLOCK(set_atomicity_lock);* has been called. */ -static bool prepare_set (void ) +static void mtrr_pause_caching (struct mtrr_pausing_state *state) {unsigned long cr4;@@ -461,7 +462,9 @@ static bool prepare_set(void)alternative ("wbinvd" ,"" ,X86_FEATURE_XEN_SELFSNOOP ); cr4 =read_cr4 (); -if (cr4 &X86_CR4_PGE ) + state->pge = cr4 &X86_CR4_PGE ; + +if (state->pge)write_cr4 (cr4 & ~X86_CR4_PGE );else if (use_invpcid)invpcid_flush_all ();@@ -469,27 +472,25 @@ static bool prepare_set(void)write_cr3 (read_cr3 ());/* Save MTRR state */ -rdmsrl (MSR_MTRRdefType, deftype); + state->def_type =rdmsr (MSR_MTRRdefType);/* Disable MTRRs, and set the default type to uncached */ -mtrr_wrmsr (MSR_MTRRdefType, deftype & ~0xcff );
xen/arch/x86/cpu/mtrr/generic.c static bool prepare_set(void) · line 484
Quoted 10 lines
xen/arch/x86/cpu/mtrr/generic.c +2
-3+mtrr_wrmsr (MSR_MTRRdefType, state->def_type & ~0xcff );/* Again, only flush caches if we have to. */ alternative ("wbinvd" ,"" ,X86_FEATURE_XEN_SELFSNOOP ); - -return cr4 &X86_CR4_PGE ; } -static void post_set (bool pge) +static void mtrr_resume_caching (struct mtrr_pausing_state state)
It would be preferable to have const on the struct mtrr_pausing_state state to potentially improve codegen, as I guess the intent here is to pass a read-only object.
Quoted 50 lines
xen/arch/x86/cpu/mtrr/generic.c +8
-8{/* Intel (P6) standard MTRRs */ -mtrr_wrmsr (MSR_MTRRdefType, deftype); +mtrr_wrmsr (MSR_MTRRdefType, state.def_type);/* Enable caches */ write_cr0 (read_cr0 () & ~X86_CR0_CD );/* Reenable CR4.PGE (also flushes the TLB) */ -if (pge) +if (state.pge)write_cr4 (read_cr4 () |X86_CR4_PGE );else if (use_invpcid)invpcid_flush_all ();@@ -503,15 +504,15 @@ void mtrr_set_all(void) {unsigned long mask, count;unsigned long flags; -bool pge; +struct mtrr_pausing_state pausing_state;local_irq_save (flags); - pge =prepare_set (); +mtrr_pause_caching (&pausing_state);/* Actually set the state */ - mask =set_mtrr_state (); + mask =set_mtrr_state (&pausing_state.def_type); -post_set (pge); +mtrr_resume_caching (pausing_state);local_irq_restore (flags);/* Use the atomic bitops to update the global mask */ @@ -536,12 +537,12 @@ void mtrr_set( {unsigned long flags;struct mtrr_var_range *vr; -bool pge; +struct mtrr_pausing_state pausing_state; vr = &mtrr_state.var_ranges[reg];local_irq_save (flags); - pge =prepare_set (); +mtrr_pause_caching (&pausing_state);if (size ==0 ) {/* The invalid bit is kept in the mask, so we simply clear the
xen/arch/x86/cpu/mtrr/generic.c void mtrr_set( · line 569
Quoted 8 lines
xen/arch/x86/cpu/mtrr/generic.c +1
-1@@ -562,7 +563,7 @@ void mtrr_set(mtrr_wrmsr (MSR_IA32_MTRR_PHYSMASK (reg), vr->mask); } -post_set (pge); +mtrr_resume_caching (pausing_state);local_irq_restore (flags); }
With that change,
PATCH v4 2/23 x86/cpu: report SMX, TXT and SKINIT capabilities
In reply to Sergii DmytrukFrom: Michał Żygowski <[email protected]>
Report TXT capabilities so that dom0 can query the Intel TXT or AMD SKINIT support information using xl dmesg.
---
Notes:
v4: fixed conditions for not reporting capabilities (match correct comments)
v4: define GETSEC_* macros used only by xen/arch/x86/cpu/intel.c in the file itself (to not depend on Slaunch)
v4: don't postpone restoring state of X86_CR4_SMXE, do it before printing test results
xen/arch/x86/cpu/amd.c | 16 +++++++++++++ xen/arch/x86/cpu/cpu.h | 1 + xen/arch/x86/cpu/hygon.c | 1 + xen/arch/x86/cpu/intel.c | 50 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+)
xen/arch/x86/cpu/amd.c +16 -0
@@ -617,6 +617,21 @@ void amd_process_freq(const struct cpuinfo_x86 *c, *low_mhz =amd_parse_freq (c->family, lo); } +void amd_log_skinit (const struct cpuinfo_x86 *c) +{ +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ; + +printk ("CPU: SKINIT capability " ); +if ( !test_bit (X86_FEATURE_SKINIT , &boot_cpu_data.x86_capability) ) +printk ("not supported\n" ); +else +printk ("supported\n" ); +} + void cf_check early_init_amd(struct cpuinfo_x86 *c) {if (c == &boot_cpu_data)
@@ -1325,6 +1340,7 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)setup_force_cpu_cap (X86_FEATURE_XEN_REP_MOVSB );amd_log_freq (c); +amd_log_skinit (c); } const struct cpu_dev __initconst_cf_clobber amd_cpu_dev = {
xen/arch/x86/cpu/cpu.h +1 -0
@@ -21,6 +21,7 @@ extern bool detect_extended_topology(struct cpuinfo_x86 *c); void cf_check early_init_amd(struct cpuinfo_x86 *c);void amd_log_freq (const struct cpuinfo_x86 *c); +void amd_log_skinit (const struct cpuinfo_x86 *c);void amd_init_de_cfg (const struct cpuinfo_x86 *c);void amd_init_lfence_dispatch (void );void amd_init_ssbd (const struct cpuinfo_x86 *c);
xen/arch/x86/cpu/hygon.c +1 -0
@@ -90,6 +90,7 @@ static void cf_check init_hygon(struct cpuinfo_x86 *c) }amd_log_freq (c); +amd_log_skinit (c); } const struct cpu_dev __initconst_cf_clobber hygon_cpu_dev = {
xen/arch/x86/cpu/intel.c +50 -0
68 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v4 02/23] x86/cpu: report SMX, TXT and SKINIT capabilities
Quoted 4 lines · Sergii Dmytruk
From: Michał Żygowski <[email protected]>
Report TXT capabilities so that dom0 can query the Intel TXT or AMD SKINIT support information using xl dmesg.
Hmm. I first meant to ask: In how far is this extra logging useful, especially as long as we don't use the features just yet? And only then I noticed that I must have paid too little attention here already in v3. Querying through "xl dmesg" is entirely unreliable. Sooner or later the boot messages will scroll off of the ring buffer. Making this a query-able interface also would mean we can't alter any of the messages, should the want/need arise.
For AMD the situation is easy: It's part of the featureset / CPU policy exposed via sysctl. The same is true for SMX on Intel, but the further GETSEC output requires some other means to communicate. I wonder whether making this part of the CPU policy would make sense, or whether to introduce a Dom0-only hypervisor-CPUID bit for it, or whether yet something else would be best here. Likely Andrew will have had thoughts on this long before ...
Irrespective of the above also a few comments on the patch itself.
xen/arch/x86/cpu/amd.c void amd_process_freq(const struct cpuinfo_x86 *c, · line 626
Quoted 13 lines
xen/arch/x86/cpu/amd.c +7
-0@@ -617,6 +617,21 @@ void amd_process_freq(const struct cpuinfo_x86 *c, *low_mhz =amd_parse_freq (c->family, lo); } +void amd_log_skinit (const struct cpuinfo_x86 *c) +{ +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ;
If this is BSP-on-boot only, the function really wants to be __init. For that,
...
xen/arch/x86/cpu/amd.c void amd_process_freq(const struct cpuinfo_x86 *c, · line 637
Quoted 10 lines
xen/arch/x86/cpu/amd.c +7
-0+printk ("CPU: SKINIT capability " ); +if ( !test_bit (X86_FEATURE_SKINIT , &boot_cpu_data.x86_capability) ) +printk ("not supported\n" ); +else +printk ("supported\n" ); +} + void cf_check early_init_amd(struct cpuinfo_x86 *c) {if (c == &boot_cpu_data)
... use this condition ...
xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct cpuinfo_x86 *c) · line 1343
Quoted 5 lines
xen/arch/x86/cpu/amd.c +1
-0@@ -1325,6 +1340,7 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)setup_force_cpu_cap (X86_FEATURE_XEN_REP_MOVSB );amd_log_freq (c); +amd_log_skinit (c);
... at the call site (and of course also the other one). Same for the Intel code, obviously.
Quoted 27 lines
xen/arch/x86/cpu/amd.c +23
-0@@ -620,6 +625,49 @@ static void init_intel_perf(struct cpuinfo_x86 *c) } } +/* +* Print out the SMX and TXT capabilties, so that dom0 can determine if the +* system is DRTM-capable. +*/ +static void intel_log_smx_txt (void ) +{ +unsigned long cr4_val, getsec_caps; + +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ; + +printk ("CPU: SMX capability " ); +if ( !test_bit (X86_FEATURE_SMX , &boot_cpu_data.x86_capability) ) + { +printk ("not supported\n" ); +return ; + } +printk ("supported\n" ); + +/* Can't run GETSEC without VMX and SMX */
xen/arch/x86/cpu/amd.c static void init_intel_perf(struct cpuinfo_x86 *c) · line 660
Quoted 10 lines
xen/arch/x86/cpu/amd.c +10
-0+if ( !test_bit (X86_FEATURE_VMX , &boot_cpu_data.x86_capability) ) +return ; + + cr4_val =read_cr4 (); +if ( !(cr4_val &X86_CR4_SMXE ) ) +write_cr4 (cr4_val |X86_CR4_SMXE ); + + asmvolatile ("getsec\n" + :"=a" (getsec_caps) + :"a" (GETSEC_CAPABILITIES ),"b" (0 ) :);
Nit (style): Bad indentation, missing blanks, unnecessary \n, and stray colon. Overall:
asm volatile ( "getsec"
: "=a" (getsec_caps)
: "a" (GETSEC_CAPABILITIES), "b" (0) );I further question the need for volatile here. (Like for we have for CPUID, we anyway may want to gain a getsec() wrapper for GETSEC.)
xen/arch/x86/cpu/amd.c static void init_intel_perf(struct cpuinfo_x86 *c) · line 662
Quoted 2 lines
xen/arch/x86/cpu/amd.c +2
-0+if ( !(cr4_val &X86_CR4_SMXE ) ) +write_cr4 (cr4_val & ~X86_CR4_SMXE );
The clearing of SMXE here is pointless, as the if() already guarantees the bit to be clear.
Jan
Re: [PATCH v4 02/23] x86/cpu: report SMX, TXT and SKINIT capabilities
Quoted 14 lines · Jan Beulich
Quoted 4 lines · Sergii Dmytruk
From: Michał Żygowski <[email protected]>
Report TXT capabilities so that dom0 can query the Intel TXT or AMD SKINIT support information using xl dmesg.
Hmm. I first meant to ask: In how far is this extra logging useful, especially as long as we don't use the features just yet? And only then I noticed that I must have paid too little attention here already in v3. Querying through "xl dmesg" is entirely unreliable. Sooner or later the boot messages will scroll off of the ring buffer. Making this a query-able interface also would mean we can't alter any of the messages, should the want/need arise.
Quoted 7 lines
For AMD the situation is easy: It's part of the featureset / CPU policy exposed via sysctl. The same is true for SMX on Intel, but the further GETSEC output requires some other means to communicate. I wonder whether making this part of the CPU policy would make sense, or whether to introduce a Dom0-only hypervisor-CPUID bit for it, or whether yet something else would be best here. Likely Andrew will have had thoughts on this long before ...
I'm not aware of anything relying on this output. It's just for making this information more accessible to users that may be wondering if DRTM has a chance of working (e.g., if hardware supports it and firmware is properly configured). The wording may be unfortunate (and needs a fix anyway), I can change it to
Report DRTM-related capabilities to enable checking for them in dom0 using xl dmesg. This targets debug and diagnostic use cases.
if that helps.
Quoted 30 lines
xen/arch/x86/cpu/amd.c void amd_process_freq(const struct cpuinfo_x86 *c, · line 626
Quoted 13 lines
xen/arch/x86/cpu/amd.c +7
-0@@ -617,6 +617,21 @@ void amd_process_freq(const struct cpuinfo_x86 *c, *low_mhz =amd_parse_freq (c->family, lo); } +void amd_log_skinit (const struct cpuinfo_x86 *c) +{ +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ;If this is BSP-on-boot only, the function really wants to be
__init. For that,
...xen/arch/x86/cpu/amd.c void amd_process_freq(const struct cpuinfo_x86 *c, · line 637
Quoted 10 lines
xen/arch/x86/cpu/amd.c +7
-0+printk ("CPU: SKINIT capability " ); +if ( !test_bit (X86_FEATURE_SKINIT , &boot_cpu_data.x86_capability) ) +printk ("not supported\n" ); +else +printk ("supported\n" ); +} + void cf_check early_init_amd(struct cpuinfo_x86 *c) {if (c == &boot_cpu_data)... use this condition ...
Quoted 8 lines
xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct cpuinfo_x86 *c) · line 1343
Quoted 5 lines
xen/arch/x86/cpu/amd.c +1
-0@@ -1325,6 +1340,7 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)setup_force_cpu_cap (X86_FEATURE_XEN_REP_MOVSB );amd_log_freq (c); +amd_log_skinit (c);... at the call site (and of course also the other one). Same for the Intel code, obviously.
OK, thanks.
Quoted 41 lines
Quoted 27 lines
xen/arch/x86/cpu/amd.c +23
-0@@ -620,6 +625,49 @@ static void init_intel_perf(struct cpuinfo_x86 *c) } } +/* +* Print out the SMX and TXT capabilties, so that dom0 can determine if the +* system is DRTM-capable. +*/ +static void intel_log_smx_txt (void ) +{ +unsigned long cr4_val, getsec_caps; + +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ; + +printk ("CPU: SMX capability " ); +if ( !test_bit (X86_FEATURE_SMX , &boot_cpu_data.x86_capability) ) + { +printk ("not supported\n" ); +return ; + } +printk ("supported\n" ); + +/* Can't run GETSEC without VMX and SMX */ xen/arch/x86/cpu/amd.c static void init_intel_perf(struct cpuinfo_x86 *c) · line 660
Quoted 10 lines
xen/arch/x86/cpu/amd.c +10
-0+if ( !test_bit (X86_FEATURE_VMX , &boot_cpu_data.x86_capability) ) +return ; + + cr4_val =read_cr4 (); +if ( !(cr4_val &X86_CR4_SMXE ) ) +write_cr4 (cr4_val |X86_CR4_SMXE ); + + asmvolatile ("getsec\n" + :"=a" (getsec_caps) + :"a" (GETSEC_CAPABILITIES ),"b" (0 ) :);Nit (style): Bad indentation, missing blanks, unnecessary \n, and stray colon. Overall:
Quoted 6 lines
asm volatile ( "getsec" : "=a" (getsec_caps) : "a" (GETSEC_CAPABILITIES), "b" (0) );I further question the need for volatile here. (Like for we have for CPUID, we anyway may want to gain a
getsec()wrapper for GETSEC.)
I think volatile was added just because it doesn't hurt, rather than because it's necessary, so it can be dropped. Can add a wrapper, but there is only one use so far and a generic wrapper will have to use 64-bit parameters (GETSEC[EXITAC] sets RBX).
Quoted 5 lines
xen/arch/x86/cpu/amd.c static void init_intel_perf(struct cpuinfo_x86 *c) · line 662
Quoted 2 lines
xen/arch/x86/cpu/amd.c +2
-0+if ( !(cr4_val &X86_CR4_SMXE ) ) +write_cr4 (cr4_val & ~X86_CR4_SMXE );The clearing of SMXE here is pointless, as the
if()already guarantees the bit to be clear.
This statement restores the value stored in cr4_val (see above). Maybe should name the variable old_cr4_val or orig_cr4_val.
Regards
Re: [PATCH v4 02/23] x86/cpu: report SMX, TXT and SKINIT capabilities
Quoted 29 lines · Sergii Dmytruk
Quoted 14 lines · Jan Beulich
Quoted 4 lines · Sergii Dmytruk
From: Michał Żygowski <[email protected]>
Report TXT capabilities so that dom0 can query the Intel TXT or AMD SKINIT support information using xl dmesg.
Hmm. I first meant to ask: In how far is this extra logging useful, especially as long as we don't use the features just yet? And only then I noticed that I must have paid too little attention here already in v3. Querying through "xl dmesg" is entirely unreliable. Sooner or later the boot messages will scroll off of the ring buffer. Making this a query-able interface also would mean we can't alter any of the messages, should the want/need arise.
Quoted 7 lines
For AMD the situation is easy: It's part of the featureset / CPU policy exposed via sysctl. The same is true for SMX on Intel, but the further GETSEC output requires some other means to communicate. I wonder whether making this part of the CPU policy would make sense, or whether to introduce a Dom0-only hypervisor-CPUID bit for it, or whether yet something else would be best here. Likely Andrew will have had thoughts on this long before ...
I'm not aware of anything relying on this output. It's just for making this information more accessible to users that may be wondering if DRTM has a chance of working (e.g., if hardware supports it and firmware is properly configured). The wording may be unfortunate (and needs a fix anyway), I can change it to
Quoted 4 lines
Report DRTM-related capabilities to enable checking for them in dom0 using
xl dmesg. This targets debug and diagnostic use cases.if that helps.
Yes, please. Provided we need this separate output at all. Furthermore, if we need it, wouldn't it better be adjacent with other extended VT-x / SVM features?
Quoted 45 lines
Quoted 45 lines
Quoted 27 lines
xen/arch/x86/cpu/intel.c +23
-0@@ -620,6 +625,49 @@ static void init_intel_perf(struct cpuinfo_x86 *c) } } +/* +* Print out the SMX and TXT capabilties, so that dom0 can determine if the +* system is DRTM-capable. +*/ +static void intel_log_smx_txt (void ) +{ +unsigned long cr4_val, getsec_caps; + +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ; + +printk ("CPU: SMX capability " ); +if ( !test_bit (X86_FEATURE_SMX , &boot_cpu_data.x86_capability) ) + { +printk ("not supported\n" ); +return ; + } +printk ("supported\n" ); + +/* Can't run GETSEC without VMX and SMX */ xen/arch/x86/cpu/intel.c static void init_intel_perf(struct cpuinfo_x86 *c) · line 660
Quoted 10 lines
xen/arch/x86/cpu/intel.c +10
-0+if ( !test_bit (X86_FEATURE_VMX , &boot_cpu_data.x86_capability) ) +return ; + + cr4_val =read_cr4 (); +if ( !(cr4_val &X86_CR4_SMXE ) ) +write_cr4 (cr4_val |X86_CR4_SMXE ); + + asmvolatile ("getsec\n" + :"=a" (getsec_caps) + :"a" (GETSEC_CAPABILITIES ),"b" (0 ) :);Nit (style): Bad indentation, missing blanks, unnecessary \n, and stray colon. Overall:
asm volatile ( "getsec" : "=a" (getsec_caps) : "a" (GETSEC_CAPABILITIES), "b" (0) );
Quoted 7 lines
Quoted 2 lines
I further question the need for volatile here. (Like for we have for CPUID, we anyway may want to gain a
getsec()wrapper for GETSEC.)I think
volatilewas added just because it doesn't hurt, rather than because it's necessary, so it can be dropped. Can add a wrapper, but there is only one use so far and a generic wrapper will have to use 64-bit parameters (GETSEC[EXITAC]sets RBX).
Well, if it'll remain just one use, maybe indeed too early for having a wrapper.
Quoted 8 lines
Quoted 5 lines
Review static void init_intel_perf(struct cpuinfo_x86 *c) · line 662
Quoted 2 lines
(quoted diff) +2
-0+ if ( !(cr4_val & X86_CR4_SMXE) ) + write_cr4(cr4_val & ~X86_CR4_SMXE);The clearing of SMXE here is pointless, as the
if()already guarantees the bit to be clear.This statement restores the value stored in
cr4_val(see above). Maybe should name the variableold_cr4_valororig_cr4_val.
Naming wasn't my point here. My point was that masking off a bit that's already off is pretty clearly useless code.
Jan
Re: [PATCH v4 02/23] x86/cpu: report SMX, TXT and SKINIT capabilities
In reply to Sergii DmytrukQuoted 46 lines · Sergii Dmytruk
Quoted 45 lines · Jan Beulich
Quoted 27 lines · Sergii Dmytruk
xen/arch/x86/cpu/intel.c +23
-0@@ -620,6 +625,49 @@ static void init_intel_perf(struct cpuinfo_x86 *c) } } +/* +* Print out the SMX and TXT capabilties, so that dom0 can determine if the +* system is DRTM-capable. +*/ +static void intel_log_smx_txt (void ) +{ +unsigned long cr4_val, getsec_caps; + +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ; + +printk ("CPU: SMX capability " ); +if ( !test_bit (X86_FEATURE_SMX , &boot_cpu_data.x86_capability) ) + { +printk ("not supported\n" ); +return ; + } +printk ("supported\n" ); + +/* Can't run GETSEC without VMX and SMX */ xen/arch/x86/cpu/intel.c static void init_intel_perf(struct cpuinfo_x86 *c) · line 660
Quoted 10 lines
xen/arch/x86/cpu/intel.c +10
-0+if ( !test_bit (X86_FEATURE_VMX , &boot_cpu_data.x86_capability) ) +return ; + + cr4_val =read_cr4 (); +if ( !(cr4_val &X86_CR4_SMXE ) ) +write_cr4 (cr4_val |X86_CR4_SMXE ); + + asmvolatile ("getsec\n" + :"=a" (getsec_caps) + :"a" (GETSEC_CAPABILITIES ),"b" (0 ) :);Nit (style): Bad indentation, missing blanks, unnecessary \n, and stray colon. Overall:
asm volatile ( "getsec" : "=a" (getsec_caps) : "a" (GETSEC_CAPABILITIES), "b" (0) );
Quoted 6 lines
Quoted 2 lines
I further question the need for volatile here. (Like for we have for CPUID, we anyway may want to gain a
getsec()wrapper for GETSEC.)I think
volatilewas added just because it doesn't hurt, rather than because it's necessary, so it can be dropped. Can add a wrapper, but there is only one use so far and a generic wrapper will have to use 64-bit parameters (GETSEC[EXITAC]sets RBX).
GETSEC is a horrible instruction. The different functions (eax input) produce and consume different registers,
This in turn requires different volatilities. GETSEC[CAPABILITIES] and GETSEC[PARAMETERS] should be non-volatile (they're read-only operation without interesting side effects which the optimiser can safely discard) whereas GETSEC[ENTERACCS] or GETSEC[SENTER] are really "jump into new processor mode". They're both longjmp-like so are considered volatile by virtue of having no outputs.
I was going to request a getsec.h header to abstract these away. Having more than one location where we need to carefully check the asm constraints against the SDM is too many.
~Andrew
Re: [PATCH v4 02/23] x86/cpu: report SMX, TXT and SKINIT capabilities
In reply to Sergii DmytrukLe 02/08/2026 à 15:14, Sergii Dmytruk a écrit :
Quoted 47 lines
From: Michał Żygowski <[email protected]>
Report TXT capabilities so that dom0 can query the Intel TXT or AMD SKINIT support information using xl dmesg.
Signed-off-by Michał Żygowski <[email protected]>Signed-off-by Sergii Dmytruk <[email protected]>---
Notes:
v4: fixed conditions for not reporting capabilities (match correct comments)
v4: define GETSEC_* macros used only byxen/arch/x86/cpu/intel.cin the file itself (to not depend on Slaunch)
v4: don't postpone restoring state ofX86_CR4_SMXE, do it before printing test resultsxen/arch/x86/cpu/amd.c | 16 +++++++++++++ xen/arch/x86/cpu/cpu.h | 1 + xen/arch/x86/cpu/hygon.c | 1 + xen/arch/x86/cpu/intel.c | 50 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+)xen/arch/x86/cpu/amd.c +15
-0@@ -617,6 +617,21 @@ void amd_process_freq(const struct cpuinfo_x86 *c, *low_mhz =amd_parse_freq (c->family, lo); } +void amd_log_skinit (const struct cpuinfo_x86 *c) +{ +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ; + +printk ("CPU: SKINIT capability " ); +if ( !test_bit (X86_FEATURE_SKINIT , &boot_cpu_data.x86_capability) ) +printk ("not supported\n" ); +else +printk ("supported\n" ); +} + void cf_check early_init_amd(struct cpuinfo_x86 *c) {if (c == &boot_cpu_data)
xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct cpuinfo_x86 *c) · line 1344
Quoted 5 lines
xen/arch/x86/cpu/amd.c +1
-0@@ -1325,6 +1340,7 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)setup_force_cpu_cap (X86_FEATURE_XEN_REP_MOVSB );amd_log_freq (c); +amd_log_skinit (c); }
On which Xen branch this patch is based ?
early_init_amd() doesn't seem to have amd_log_freq (which is in init_amd instead).
Quoted 73 lines
xen/arch/x86/cpu/amd.c +0
-0const struct cpu_dev __initconst_cf_clobber amd_cpu_dev = {xen/arch/x86/cpu/cpu.h +1
-0@@ -21,6 +21,7 @@ extern bool detect_extended_topology(struct cpuinfo_x86 *c); void cf_check early_init_amd(struct cpuinfo_x86 *c);void amd_log_freq (const struct cpuinfo_x86 *c); +void amd_log_skinit (const struct cpuinfo_x86 *c);void amd_init_de_cfg (const struct cpuinfo_x86 *c);void amd_init_lfence_dispatch (void );void amd_init_ssbd (const struct cpuinfo_x86 *c);xen/arch/x86/cpu/hygon.c +1
-0@@ -90,6 +90,7 @@ static void cf_check init_hygon(struct cpuinfo_x86 *c) }amd_log_freq (c); +amd_log_skinit (c); } const struct cpu_dev __initconst_cf_clobber hygon_cpu_dev = {xen/arch/x86/cpu/intel.c +32
-0@@ -14,6 +14,11 @@#include "cpu.h" +/* EAX value for GETSEC leaf functions. Intel SDM: GETSEC[CAPABILITIES] */ +#define GETSEC_CAPABILITIES 0 +/* Intel SDM: GETSEC Capability Result Encoding */ +#define GETSEC_CAP_TXT_CHIPSET 1 +/* * MSR_MCU_OPT_CTRL is a collection of unrelated functionality, with separate * enablement requirements, but which want to be consistent across the system. @@ -620,6 +625,49 @@ static void init_intel_perf(struct cpuinfo_x86 *c) } } +/* +* Print out the SMX and TXT capabilties, so that dom0 can determine if the +* system is DRTM-capable. +*/ +static void intel_log_smx_txt (void ) +{ +unsigned long cr4_val, getsec_caps; + +/* +* Run only on BSP and not during resume to report the capability only once. +*/ +if ( system_state == SYS_STATE_resume ||smp_processor_id () ) +return ; + +printk ("CPU: SMX capability " ); +if ( !test_bit (X86_FEATURE_SMX , &boot_cpu_data.x86_capability) ) + { +printk ("not supported\n" ); +return ; + } +printk ("supported\n" ); + +/* Can't run GETSEC without VMX and SMX */ +if ( !test_bit (X86_FEATURE_VMX , &boot_cpu_data.x86_capability) ) +return ; + + cr4_val =read_cr4 ();
xen/arch/x86/cpu/intel.c static void init_intel_perf(struct cpuinfo_x86 *c) · line 664
Quoted 10 lines
xen/arch/x86/cpu/intel.c +10
-0+if ( !(cr4_val &X86_CR4_SMXE ) ) +write_cr4 (cr4_val |X86_CR4_SMXE ); + + asmvolatile ("getsec\n" + :"=a" (getsec_caps) + :"a" (GETSEC_CAPABILITIES ),"b" (0 ) :); + +if ( !(cr4_val &X86_CR4_SMXE ) ) +write_cr4 (cr4_val & ~X86_CR4_SMXE ); +
That looks wrong, the logic is written as : if SMXE is cleared, you clear SMXE again.
Regardless, if we're looking to use TXT later on, wouldn't it be preferable to keep SMXE bit on ? That means we would not only do reporting but "basic" initialization.
Quoted 10 lines
xen/arch/x86/cpu/intel.c +6
-0+if ( getsec_caps &GETSEC_CAP_TXT_CHIPSET ) +printk ("Chipset supports TXT\n" ); +else +printk ("Chipset does not support TXT\n" ); +} + static void cf_check init_intel(struct cpuinfo_x86 *c) {/* Detect the extended topology information if available */
xen/arch/x86/cpu/intel.c static void cf_check init_intel(struct cpuinfo_x86 *c) · line 689
Quoted 8 lines
xen/arch/x86/cpu/intel.c +2
-0@@ -634,6 +682,8 @@ static void cf_check init_intel(struct cpuinfo_x86 *c)detect_ht (c); } +intel_log_smx_txt (); +/* Work around errata */ Intel_errata_workarounds (c);
Teddy
Re: [PATCH v4 02/23] x86/cpu: report SMX, TXT and SKINIT capabilities
Quoted 59 lines · Teddy Astie
Le 02/08/2026 à 15:14, Sergii Dmytruk a écrit :
Quoted 50 lines
From: Michał Żygowski <[email protected]>
Report TXT capabilities so that dom0 can query the Intel TXT or AMD SKINIT support information using xl dmesg.
Signed-off-by Michał Żygowski <[email protected]>Signed-off-by Sergii Dmytruk <[email protected]>---
Notes:
v4: fixed conditions for not reporting capabilities (match correct comments)
v4: define GETSEC_* macros used only byxen/arch/x86/cpu/intel.cin the file itself (to not depend on Slaunch)
v4: don't postpone restoring state ofX86_CR4_SMXE, do it before printing test resultsxen/arch/x86/cpu/amd.c | 16 +++++++++++++ xen/arch/x86/cpu/cpu.h | 1 +
xen/arch/x86/cpu/hygon.c| 1 +
xen/arch/x86/cpu/intel.c| 50 ++++++++++++++++++++++++++++++++++++++++4 files changed, 68 insertions(+)xen/arch/x86/cpu/amd.c +3
-0@@ -617,6 +617,21 @@ void amd_process_freq(const struct cpuinfo_x86 *c, *low_mhz = amd_parse_freq(c->family, lo); } +void amd_log_skinit(const struct cpuinfo_x86 *c) +{ + /* +* Run only on BSP and not during resume to report the capability only once.
+ */
+ if (system_state==SYS_STATE_resume||smp_processor_id()) + return;xen/arch/x86/cpu/amd.c +8
-0+ + printk("CPU: SKINIT capability "); + if ( !test_bit(X86_FEATURE_SKINIT, &boot_cpu_data.x86_capability) ) + printk("not supported\n"); + else + printk("supported\n"); +} +void
cf_checkearly_init_amd(struct cpuinfo_x86 *c){
if (c ==&boot_cpu_data)xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct · line 1344
Quoted 5 lines
xen/arch/x86/cpu/amd.c +1
-0@@ -1325,6 +1340,7 @@ static void cf_check init_amd(struct cpuinfo_x86 *c) setup_force_cpu_cap(X86_FEATURE_XEN_REP_MOVSB); amd_log_freq(c); + amd_log_skinit(c); }On which Xen branch this patch is based ?
Quoted 2 lines
early_init_amd()doesn't seem to haveamd_log_freq(which is ininit_amdinstead).
See the cover letter:
base-commit: 7c77acd452fb6a3079661e75ebb5cf23ed985cc7
$ git describe 7c77acd452fb6a3079661e75ebb5cf23ed985cc7 4.23-dev-119-g7c77acd452fb
so it's something recent.
PATCH v4 3/23 x86/tpm.c: hashing and extending PCRs for TPM1.2
In reply to Sergii DmytrukFrom: Krystian Hebel <[email protected]>
This file is built twice: for early 32b mode without paging and for 64b code. The expectation is that the data that's measured early is small and thus sending it to TPM to do the hashing is viable. Version with paging computes digests and only sends their values to TPM, thus permitting hashing of large chunks of data like dom0's kernel and initrd (sending them to TPM would take multiple minutes).
---
Notes:
v4: renamed from "x86/tpm.c: code for early hashing and extending PCRs (for TPM1.2)"
v4: no longer depends on Slaunch
v4: __EARLY_SLAUNCH__ got replaced with __EARLY_TPM__
v4: fixed SPDX license comments
v4: added short description at the top
v4: TPM_TIS_* => TPM_MMIO_*
v4: tpm_hash_extend() now returns an error code
v4: tpm_hash_extend() now accepts list of hashes like TPM2 but expects at most SHA1
v4: turned is_tpm12() into public tpm_is_tpm1() function (to be used for event log)
v4: added xen/arch/x86/include/asm/tpm1.h with TPM1.2 TCG declarations
v4: removed swap16() and swap32() macros to use macros from <xen/byteorder.h>
v4: no more static inline in tpm.c, it's pointless there
v4: style fixes for empty loops, operator placement on wrapped lines, checking for unset bits
v4: take TPM burst count into account
v4: fixed incorrect check for data_avail when communicating with TPM
v4: internal functions return TPM error code instead of bool
v4: added command and response fields to union cmd_rsp to make using it easier
v4: unsigned => unsigned int
v4: not opencoding ROUNDDOWN() macro
v4: digest storage became optional
v4: returns TPM_INTERNAL_ERROR if not dealing with TPM1.2 or on communication error
v4: the code is written for TIS, but has room for other TPM interfaces
xen/arch/x86/Makefile | 1 + xen/arch/x86/boot/Makefile | 5 + xen/arch/x86/include/asm/tpm.h | 69 ++++++ xen/arch/x86/include/asm/tpm1.h | 79 +++++++ xen/arch/x86/tpm.c | 406 ++++++++++++++++++++++++++++++++ 5 files changed, 560 insertions(+) create mode 100644 xen/arch/x86/include/asm/tpm.h create mode 100644 xen/arch/x86/include/asm/tpm1.h create mode 100644 xen/arch/x86/tpm.c
xen/arch/x86/Makefile +1 -0
@@ -68,6 +68,7 @@ obj-y += string.o obj-$(CONFIG_SYSCTL) += sysctl.o obj-$(CONFIG_TBOOT) += tboot.o obj-y += time.o +obj-y += tpm.o obj-y += traps-setup.o obj-y += traps.o obj-$(CONFIG_INTEL) += tsx.o
xen/arch/x86/boot/Makefile +5 -0
@@ -5,6 +5,7 @@ obj-bin-y += $(obj64) obj32 := cmdline.32.o obj32 += reloc.32.o obj32 += reloc-trampoline.32.o +obj32 += tpm-early.32.o obj64 := reloc-trampoline.o
@@ -28,6 +29,10 @@ $(obj32): XEN_CFLAGS := $(CFLAGS_x86_32) -fpic $(obj)/%.32.o: $(src)/%.c FORCE $(call if_changed_rule,cc_o_c) +$(obj)/tpm-early.32.o: XEN_CFLAGS += -D__EARLY_TPM__ +$(obj)/tpm-early.32.o: $(src)/../tpm.c FORCE + $(call if_changed_rule,cc_o_c) + orphan-handling-$(call ld-option,--orphan-handling=error) := --orphan-handling=error LDFLAGS_DIRECT-$(call ld-option,--warn-rwx-segments) := --no-warn-rwx-segments LDFLAGS_DIRECT += $(LDFLAGS_DIRECT-y)
xen/arch/x86/include/asm/tpm.h new file +69 -0
69 lines not on this page · raw message
xen/arch/x86/include/asm/tpm1.h new file +79 -0
79 lines not on this page · raw message
xen/arch/x86/tpm.c new file +406 -0
406 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 4/23 x86/tpm.c: support extending PCRs of TPM2.0 via TIS
In reply to Sergii DmytrukSHA1 and SHA256 are hard-coded here, but their support by the TPM is checked.
CRB isn't supported, only TPM1.2-like TIS interface is (data is passed via writes and reads to/from a single-byte FIFO register).
---
Notes:
v4: was called "x86/tpm.c: support extending PCRs of TPM2.0"
v4: adds xen/arch/x86/include/asm/tpm2.h with TPM2.0 declarations by TCG
v4: detect CRB and do nothing (implemented separately)
v4: put SPDX license comment on its own line
v4: unsigned => unsigned int
v4: replace uses of swap16() and swap32()
v4: more error checks when parsing TPM responses
v4: style fixes for goto labels and spacing
xen/arch/x86/include/asm/tpm.h | 5 + xen/arch/x86/include/asm/tpm2.h | 150 ++++++++++++++ xen/arch/x86/tpm.c | 340 +++++++++++++++++++++++++++++++- 3 files changed, 489 insertions(+), 6 deletions(-) create mode 100644 xen/arch/x86/include/asm/tpm2.h
xen/arch/x86/include/asm/tpm.h +5 -0
@@ -57,6 +57,11 @@ bool tpm_is_tpm1(void);* The list of hashes must either be empty or contain nothing but SHA1 hash when * tpm_is_tpm1() returns true. * +* When tpm_is_tpm1() returns false, the list of digests can also be used to +* determine which hashes to extend. The only hashes that are guaranteed to be +* supported are SHA1 and SHA256, all other digests need to be pre-filled by +* the caller with some placeholder value. +* * Returns: * - TPM error code when < 4096 (0 means success) * - TPM_INTERNAL_ERROR on invalid invocation or a failure to communicate with
xen/arch/x86/include/asm/tpm2.h new file +150 -0
150 lines not on this page · raw message
xen/arch/x86/tpm.c +334 -6
400 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 5/23 x86/tpm.c: add CRB interface support
In reply to Sergii DmytrukFrom: Szymon Acedański <[email protected]>
TIS is an older and slower byte-oriented TPM interface that gets replaced by CRB on modern systems.
---
Notes:
v4: new commit to support CRB interface of TPM2.0
xen/arch/x86/tpm.c | 134 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 3 deletions(-)
xen/arch/x86/tpm.c +131 -3
@@ -72,6 +72,11 @@ static uint8_t tpm_read8(unsigned int reg)return *(volatile uint8_t *)__va (TPM_MMIO_BASE + reg); } +static void tpm_write32 (unsigned int reg,uint32_t val) +{ + *(volatile uint32_t *)__va (TPM_MMIO_BASE + reg) = val; +} +static void tpm_write8 (unsigned int reg,uint8_t val) { *(volatile uint8_t *)__va (TPM_MMIO_BASE + reg) = val;
@@ -110,6 +115,31 @@ static bool tpm_is_crb(void)#define TIS_BURST_COUNT_ (x) TPM_LOC_REG(x, 0x19)/* the middle of STS */ #define TIS_DATA_FIFO_ (x) TPM_LOC_REG(x, 0x24) +/************************** CRB register definitions **************************/ + +#define CRB_LOC_STATE_ (x) TPM_LOC_REG(x, 0x00) +#define CRB_LOC_STATE_LOC_ASSIGNED (1 << 1) +#define CRB_LOC_STATE_REG_VALID_STS (1 << 7) +#define CRB_LOC_CTRL_ (x) TPM_LOC_REG(x, 0x08) +#define CRB_LOC_CTRL_REQUEST_ACCESS (1 << 0) +#define CRB_LOC_CTRL_RELINQUISH (1 << 1) +#define CRB_CTRL_REQ_ (x) TPM_LOC_REG(x, 0x40) +#define CRB_CTRL_REQ_CMD_READY (1 << 0) +#define CRB_CTRL_REQ_GO_IDLE (1 << 1) +#define CRB_CTRL_STS_ (x) TPM_LOC_REG(x, 0x44) +#define CRB_CTRL_STS_ERROR (1 << 0) +#define CRB_CTRL_CANCEL_ (x) TPM_LOC_REG(x, 0x48) +#define CRB_CTRL_CANCEL_INVOKE (1 << 0) +#define CRB_CTRL_START_ (x) TPM_LOC_REG(x, 0x4C) +#define CRB_CTRL_START_INVOKE (1 << 0) +#define CRB_CTRL_CMD_SIZE_ (x) TPM_LOC_REG(x, 0x58) +#define CRB_CTRL_CMD_LADDR_ (x) TPM_LOC_REG(x, 0x5C) +#define CRB_CTRL_CMD_HADDR_ (x) TPM_LOC_REG(x, 0x60) +#define CRB_CTRL_RSP_SIZE_ (x) TPM_LOC_REG(x, 0x64) +#define CRB_CTRL_RSP_ADDR_ (x) TPM_LOC_REG(x, 0x68) +#define CRB_DATA_BUFFER_ (x) TPM_LOC_REG(x, 0x80) +#define CRB_DATA_BUFFER_SIZE 0x0F80 +/************************** TIS locality & command ****************************/ static void tis_request_locality (unsigned int loc)
@@ -195,12 +225,110 @@ static void tis_send_cmd(unsigned int loc, uint8_t *buf, unsigned int i_size,tpm_write8 (TIS_STS_ (loc),STS_COMMAND_READY ); } +/************************** CRB locality & command ****************************/ + +static void crb_request_locality (unsigned int loc) +{ +const uint32_t mask =CRB_LOC_STATE_LOC_ASSIGNED | +CRB_LOC_STATE_REG_VALID_STS ; + +tpm_write32 (CRB_LOC_CTRL_ (loc),CRB_LOC_CTRL_REQUEST_ACCESS ); +while ( (tpm_read32 (CRB_LOC_STATE_ (loc)) & mask) != mask ) + ; +} + +static void crb_relinquish_locality (unsigned int loc) +{ +tpm_write32 (CRB_LOC_CTRL_ (loc),CRB_LOC_CTRL_RELINQUISH ); +while (tpm_read32 (CRB_LOC_STATE_ (loc)) &CRB_LOC_STATE_LOC_ASSIGNED ) + ; +} + +static void crb_cmd_ready (unsigned int loc) +{ +tpm_write32 (CRB_CTRL_REQ_ (loc),CRB_CTRL_REQ_CMD_READY ); +while (tpm_read32 (CRB_CTRL_REQ_ (loc)) &CRB_CTRL_REQ_CMD_READY ) + ; +} + +static void crb_go_idle (unsigned int loc) +{ +tpm_write32 (CRB_CTRL_REQ_ (loc),CRB_CTRL_REQ_GO_IDLE ); +while (tpm_read32 (CRB_CTRL_REQ_ (loc)) &CRB_CTRL_REQ_GO_IDLE ) + ; +} + +static void crb_send_cmd (unsigned int loc,uint8_t *buf,unsigned int i_size, +unsigned int *o_size) +{ +paddr_t data_buf_pa =TPM_MMIO_BASE +CRB_DATA_BUFFER_ (loc); +unsigned int expected; + +if ( i_size >CRB_DATA_BUFFER_SIZE || *o_size <sizeof (struct tpm_rsp_hdr ) ) + { + *o_size =0 ; +return ; + } + +/* Out of caution, make sure no previous command is still executing. */ +while (tpm_read32 (CRB_CTRL_START_ (loc)) &CRB_CTRL_START_INVOKE ) + ; + +crb_cmd_ready (loc); + +/* In an unlikely event that TPM signals irrecoverable error here, +* better bail out than hang in infinite loop waiting for the +* start condition later. */ +if (tpm_read32 (CRB_CTRL_STS_ (loc)) &CRB_CTRL_STS_ERROR ) + { + *o_size =0 ; +crb_go_idle (loc); +return ; + } + +tpm_write32 (CRB_CTRL_CANCEL_ (loc),0 ); + +tpm_write32 (CRB_CTRL_CMD_LADDR_ (loc), data_buf_pa); +tpm_write32 (CRB_CTRL_CMD_HADDR_ (loc),0 ); +tpm_write32 (CRB_CTRL_CMD_SIZE_ (loc),CRB_DATA_BUFFER_SIZE ); +tpm_write32 (CRB_CTRL_RSP_SIZE_ (loc),CRB_DATA_BUFFER_SIZE ); +/* RSP_ADDR is 64-bit. */ +tpm_write32 (CRB_CTRL_RSP_ADDR_ (loc), data_buf_pa); +tpm_write32 (CRB_CTRL_RSP_ADDR_ (loc) +4 ,0 ); + +memcpy (__va (data_buf_pa), buf, i_size); + +tpm_write32 (CRB_CTRL_START_ (loc),CRB_CTRL_START_INVOKE ); +while (tpm_read32 (CRB_CTRL_START_ (loc)) &CRB_CTRL_START_INVOKE ) + ; + +if (tpm_read32 (CRB_CTRL_STS_ (loc)) &CRB_CTRL_STS_ERROR ) + { + *o_size =0 ; +crb_go_idle (loc); +return ; + } + +/* Read header to learn the response length. */ +memcpy (buf,__va (data_buf_pa),sizeof (struct tpm_rsp_hdr )); + expected =be32_to_cpu (((struct tpm_rsp_hdr *)buf)->paramSize); +if ( expected > *o_size ) + expected = *o_size; +if ( expected >CRB_DATA_BUFFER_SIZE ) + expected =CRB_DATA_BUFFER_SIZE ; + +memcpy (buf,__va (data_buf_pa), expected); + + *o_size = expected; +crb_go_idle (loc); +} +/************************** Interface dispatch ********************************/ static void request_locality (unsigned int loc) {if (tpm_is_crb () ) -return ; +crb_request_locality (loc);else tis_request_locality (loc); }
@@ -208,7 +336,7 @@ static void request_locality(unsigned int loc)static void relinquish_locality (unsigned int loc) {if (tpm_is_crb () ) -return ; +crb_relinquish_locality (loc);else tis_relinquish_locality (loc); }
@@ -217,7 +345,7 @@ static void send_cmd(unsigned int loc, uint8_t *buf, unsigned int i_size, unsigned int *o_size) {if (tpm_is_crb () ) - *o_size =0 ; +crb_send_cmd (loc, buf, i_size, o_size);else tis_send_cmd (loc, buf, i_size, o_size); }
Signature · 1 line
2.55.0
PATCH v4 6/23 x86/include/asm/intel-txt.h: constants and accessors for TXT registers and heap
In reply to Sergii DmytrukFrom: Krystian Hebel <[email protected]>
The file contains base address of TXT register spaces, offsets of registers within them, error codes and inline functions for accessing structures stored on TXT heap.
xen/arch/x86/tboot.c is updated to use definitions from this new header instead of duplicating them. The change in tboot_protect_mem_regions() there is caused by going from NR_TXT_CONFIG_PAGES to TXT_CONFIG_SPACE_SIZE which avoids multiplying number of pages by page size on every use.
---
Notes:
v4: removed unused SLAUNCH_ERROR_* #defines
v4: __ASSEMBLY__ => __ASSEMBLER__
v4: added back halt() loop before unreachable() in txt_reset() as reset is apparently asynchronous
v4: replaced txt_*_{start,size}() with an enumeration and txt_{start,size}() that iterate over entries
v4: NR_TXT_CONFIG_SIZE => TXT_CONFIG_SPACE_SIZE in one place (this was renamed but one use remained unchanged)
xen/arch/x86/include/asm/intel-txt.h | 250 +++++++++++++++++++++++++++ xen/arch/x86/tboot.c | 20 +-- 2 files changed, 252 insertions(+), 18 deletions(-) create mode 100644 xen/arch/x86/include/asm/intel-txt.h
xen/arch/x86/include/asm/intel-txt.h new file +250 -0
@@ -0,0 +1,250 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Intel TXT is an implementation of DRTM in CPUs made by Intel (although CPU +* alone isn't enough, chipset must support TXT as well). +* +* Overview: +* https://www.intel.com/content/www/us/en/support/articles/000025873/processors.html +* Software Development Guide (SDG): +* https://www.intel.com/content/www/us/en/content-details/315168/ +*/ + +#ifndef X86_INTEL_TXT_H +#define X86_INTEL_TXT_H + +/* +* TXT configuration registers (offsets from TXT_{PUB, PRIV}_CONFIG_REGS_BASE) +*/ +#define TXT_PUB_CONFIG_REGS_BASE 0xfed30000U +#define TXT_PRIV_CONFIG_REGS_BASE 0xfed20000U + +/* +* The same set of registers is exposed twice (with different permissions) and +* they are allocated continuously with page alignment. +*/ +#define TXT_CONFIG_SPACE_SIZE \ + (TXT_PUB_CONFIG_REGS_BASE - TXT_PRIV_CONFIG_REGS_BASE) + +/* Offsets from pub/priv config space. */ +#define TXTCR_STS 0x0000 +#define TXTCR_ESTS 0x0008 +#define TXTCR_ERRORCODE 0x0030 +#define TXTCR_CMD_RESET 0x0038 +#define TXTCR_CMD_CLOSE_PRIVATE 0x0048 +#define TXTCR_DIDVID 0x0110 +#define TXTCR_VER_EMIF 0x0200 +#define TXTCR_CMD_UNLOCK_MEM_CONFIG 0x0218 +#define TXTCR_SINIT_BASE 0x0270 +#define TXTCR_SINIT_SIZE 0x0278 +#define TXTCR_MLE_JOIN 0x0290 +#define TXTCR_HEAP_BASE 0x0300 +#define TXTCR_HEAP_SIZE 0x0308 +#define TXTCR_SCRATCHPAD 0x0378 +#define TXTCR_CMD_OPEN_LOCALITY1 0x0380 +#define TXTCR_CMD_CLOSE_LOCALITY1 0x0388 +#define TXTCR_CMD_OPEN_LOCALITY2 0x0390 +#define TXTCR_CMD_CLOSE_LOCALITY2 0x0398 +#define TXTCR_CMD_SECRETS 0x08e0 +#define TXTCR_CMD_NO_SECRETS 0x08e8 +#define TXTCR_E2STS 0x08f0 + +/* +* Secure Launch Defined Error Codes used in MLE-initiated TXT resets. +* +* TXT Specification +* Appendix I ACM Error Codes +*/ +#define SLAUNCH_ERROR_INTEGER_OVERFLOW 0xc0008001U +#define SLAUNCH_ERROR_HI_PMR_BASE 0xc0008002U +#define SLAUNCH_ERROR_LO_PMR_BASE 0xc0008003U +#define SLAUNCH_ERROR_LO_PMR_SIZE 0xc0008004U +#define SLAUNCH_ERROR_LO_PMR_MLE 0xc0008005U +#define SLAUNCH_ERROR_BUFFER_BEYOND_PMR 0xc0008006U +#define SLAUNCH_ERROR_HEAP_BAD_OS2MLE 0xc0008007U +#define SLAUNCH_ERROR_HEAP_BAD_OS2SINIT 0xc0008008U + +#ifndef __ASSEMBLER__ + +/* Need to differentiate between pre- and post paging enabled. */ +#ifdef __EARLY_SLAUNCH__ +#include <xen/macros.h> +#define _txt (x) _p(x) +#else +#include <xen/types.h> +#include <asm/page.h> /* __va() */ +#define _txt (x) __va(x) +#endif + +/* +* Always use private space as some of registers are either read-only or not +* present in public space. +*/ +static inline uint64_t txt_read (unsigned int reg_no) +{ +volatile uint64_t *reg =_txt (TXT_PRIV_CONFIG_REGS_BASE + reg_no); +return *reg; +} + +static inline void txt_write (unsigned int reg_no,uint64_t val) +{ +volatile uint64_t *reg =_txt (TXT_PRIV_CONFIG_REGS_BASE + reg_no); + *reg = val; +} + +static inline void noreturntxt_reset (uint32_t error) +{ +txt_write (TXTCR_ERRORCODE , error); +txt_write (TXTCR_CMD_NO_SECRETS ,1 ); +txt_write (TXTCR_CMD_UNLOCK_MEM_CONFIG ,1 ); +/* +* Ignoring the result as this serves as a TXT register barrier after +* writing to TXTCR_CMD_UNLOCK_MEM_CONFIG. Must be done to ensure that any +* future chipset operations see the write. +*/ +txt_read (TXTCR_ESTS ); +txt_write (TXTCR_CMD_RESET ,1 ); + +while (true) + { +/* +* This is halt() from <asm/system.h>. Can't include the file as it +* breaks early code compilation. +*/ + asmvolatile ("hlt" : : :"memory" ); + } +unreachable (); +} + +/* +* Secure Launch defined OS/MLE TXT Heap table +*/ +struct txt_os_mle_data { +uint32_t version; +uint32_t reserved; +uint64_t slrt; +uint64_t txt_info; +uint32_t ap_wake_block; +uint32_t ap_wake_block_size; +uint8_t mle_scratch[64 ]; +} __packed; + +/* +* TXT specification defined BIOS data TXT Heap table +*/ +struct txt_bios_data { +uint32_t version;/* Currently 5 for TPM 1.2 and 6 for TPM 2.0 */ +uint32_t bios_sinit_size; +uint64_t reserved1; +uint64_t reserved2; +uint32_t num_logical_procs; +/* Versions >= 3 && < 5 */ +uint32_t sinit_flags; +/* Versions >= 5 with updates in version 6 */ +uint32_t mle_flags; +/* Versions >= 4 */ +/* Ext Data Elements */ +} __packed; + +/* +* TXT specification defined OS/SINIT TXT Heap table +*/ +struct txt_os_sinit_data { +uint32_t version;/* Currently 6 for TPM 1.2 and 7 for TPM 2.0 */ +uint32_t flags;/* Reserved in version 6 */ +uint64_t mle_ptab; +uint64_t mle_size; +uint64_t mle_hdr_base; +uint64_t vtd_pmr_lo_base; +uint64_t vtd_pmr_lo_size; +uint64_t vtd_pmr_hi_base; +uint64_t vtd_pmr_hi_size; +uint64_t lcp_po_base; +uint64_t lcp_po_size; +uint32_t capabilities; +/* Version = 5 */ +uint64_t efi_rsdt_ptr;/* RSD*P* in versions >= 6 */ +/* Versions >= 6 */ +/* Ext Data Elements */ +} __packed; + +/* +* TXT specification defined SINIT/MLE TXT Heap table +*/ +struct txt_sinit_mle_data { +uint32_t version;/* Current values are 6 through 9 */ +/* Versions <= 8, fields until lcp_policy_control must be 0 for >= 9 */ +uint8_t bios_acm_id[20 ]; +uint32_t edx_senter_flags; +uint64_t mseg_valid; +uint8_t sinit_hash[20 ]; +uint8_t mle_hash[20 ]; +uint8_t stm_hash[20 ]; +uint8_t lcp_policy_hash[20 ]; +uint32_t lcp_policy_control; +/* Versions >= 7 */ +uint32_t rlp_wakeup_addr; +uint32_t reserved; +uint32_t num_of_sinit_mdrs; +uint32_t sinit_mdrs_table_offset; +uint32_t sinit_vtd_dmar_table_size; +uint32_t sinit_vtd_dmar_table_offset; +/* Versions >= 8 */ +uint32_t processor_scrtm_status; +/* Versions >= 9 */ +/* Ext Data Elements */ +} __packed; + +/* +* Functions to extract data from the Intel TXT Heap Memory. +* +* The layout of the heap is dictated by TXT. It's a set of variable-sized +* tables that appear in pre-defined order: +* +* +------------------------------------+ +* | Size of Bios Data table (uint64_t) | +* +------------------------------------+ +* | Bios Data table | +* +------------------------------------+ +* | Size of OS MLE table (uint64_t) | +* +------------------------------------+ +* | OS MLE table | +* +-------------------------------- + +* | Size of OS SINIT table (uint64_t) | +* +------------------------------------+ +* | OS SINIT table | +* +------------------------------------+ +* | Size of SINIT MLE table (uint64_t) | +* +------------------------------------+ +* | SINIT MLE table | +* +------------------------------------+ +* +* NOTE: the table size fields include the 8 byte size field itself. +* +* NOTE: despite SDG mentioning 8-byte alignment, at least some BIOS ACM modules +* were observed to violate this requirement for Bios Data table, so not +* enforcing any alignment. +*/ +enum { +TXT_BIOS , +TXT_OS2MLE , +TXT_OS2SINIT , +TXT_SINIT2MLE , +}; +static inline uint64_t txt_size (const void *heap,int table_index) +{ +int i; +for (i =0 ; i < table_index; ++i) + heap += *(const uint64_t *)heap; +return *(const uint64_t *)heap -sizeof (uint64_t ); +} +static inline void *txt_start (void *heap,int table_index) +{ +int i; +for (i =0 ; i < table_index; ++i) + heap += *(const uint64_t *)heap; +return heap +sizeof (uint64_t ); +} + +#endif /* !__ASSEMBLER__ */ + +#endif /* X86_INTEL_TXT_H */
xen/arch/x86/tboot.c +2 -18
@@ -17,6 +17,7 @@#include <asm/setup.h> #include <asm/tboot.h> #include <asm/trampoline.h> +#include <asm/intel-txt.h> #include <crypto/vmac.h>
@@ -37,23 +38,6 @@ static uint64_t __initdata sinit_base, __initdata sinit_size;static bool __ro_after_init is_vtd; -/* -* TXT configuration registers (offsets from TXT_{PUB, PRIV}_CONFIG_REGS_BASE) -*/ - -#define TXT_PUB_CONFIG_REGS_BASE 0xfed30000U -#define TXT_PRIV_CONFIG_REGS_BASE 0xfed20000U - -/* # pages for each config regs space - used by fixmap */ -#define NR_TXT_CONFIG_PAGES ((TXT_PUB_CONFIG_REGS_BASE - \ - TXT_PRIV_CONFIG_REGS_BASE) >> PAGE_SHIFT) - -/* offsets from pub/priv config space */ -#define TXTCR_SINIT_BASE 0x0270 -#define TXTCR_SINIT_SIZE 0x0278 -#define TXTCR_HEAP_BASE 0x0300 -#define TXTCR_HEAP_SIZE 0x0308 -#define SHA1_SIZE 20typedef uint8_t sha1_hash_t [SHA1_SIZE ];
@@ -411,7 +395,7 @@ int __init tboot_protect_mem_regions(void)/* TXT Private Space */ rc =e820_change_range_type (&e820,TXT_PRIV_CONFIG_REGS_BASE , -TXT_PRIV_CONFIG_REGS_BASE +NR_TXT_CONFIG_PAGES *PAGE_SIZE , +TXT_PRIV_CONFIG_REGS_BASE +TXT_CONFIG_SPACE_SIZE ,E820_RESERVED ,E820_UNUSABLE );if ( !rc )return 0 ;
Signature · 1 line
2.55.0
PATCH v4 7/23 x86/boot: add CONFIG_SLAUNCH, MLE header and Secure Launch entry point
In reply to Sergii DmytrukFrom: Kacper Stojek <[email protected]>
Measured Launched Environment (MLE) is Intel TXT specific term for DLME (Dynamic Launch Measured Environment) which is whatever gets control after DRTM (Dynamic Root of Trust for Measurement) is initiated.
DRTM is a way to establish hardware root of trust which excludes firmware and is not directly tied to hardware's boot process (in contrast to static RTM, or SRTM). A bootloader compatible with Secure Launch specification [1] parses MLE header to know how to invoke Xen as MLE/DLME. The header is also processed by SINIT ACM.
The new entry point is called slaunch_stub_entry and is used mainly to differentiate from other kinds of boots. It moves a magic number to EAX before jumping into common startup code.
[1]: https://trenchboot.org/specifications/Secure_Launch/
---
Notes:
v4: was "x86/boot: add MLE header and Secure Launch entry point"
v4: added CONFIG_SLAUNCH Kconfig option
v4: expanded commit message significantly
v4: expanded the paragraph added to the documentation
v4: SLAUNCH_BOOTLOADER_MAGIC now lives here
v4: MLE header size is now computed from labels
v4: provided more details in the comment on slaunch_stub_entry
v4: handle Slaunch bootloader by just hanging (wasn't handled here in v3)
v4: use __base_reloc_end as an end of image instead of _end
docs/hypervisor-guide/x86/how-xen-boots.rst | 10 +++ xen/arch/x86/Kconfig | 8 +++ xen/arch/x86/boot/head.S | 76 +++++++++++++++++++++ 3 files changed, 94 insertions(+)
docs/hypervisor-guide/x86/how-xen-boots.rst +10 -0
@@ -55,6 +55,16 @@ If ``CONFIG_PVH_GUEST`` was selected at build time, an Elf note is included which indicates the ability to use the PVH boot protocol, and registers ``__pvh_start`` as the entrypoint, entered in 32bit mode. +A combination of Multiboot 2 and Measured Launched Environment (MLE) headers +is used to support Dynamic Root of Trust for Measurement (DRTM) for legacy +(BIOS) boot. DRTM is a way to establish hardware root of trust which +excludes firmware and is not directly tied to hardware's boot process. The +separate entry point called ``slaunch_stub_entry`` is used mainly to +differentiate from other kinds of boots. It moves a magic number to ``EAX`` +before jumping into common startup code. More details about Secure Launch +data structures processed by Xen in this boot mode can be found in +`<https://trenchboot.org/specifications/Secure_Launch/>`_. + xen.gz ~~~~~~
xen/arch/x86/Kconfig +8 -0
@@ -187,6 +187,14 @@ config TBOOT If unsure, stay with the default. +config SLAUNCH + bool "DRTM via Secure Launch support" + depends on INTEL + default y + help + Allows support for Secure Launch DRTM boot. This is a boot in a + measured environment which requires a compatible bootloader. + config X86_PSR bool "Platform Shared Resource support" if EXPERT default INTEL
xen/arch/x86/boot/head.S +76 -0
118 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 8/23 include/xen/slr-table.h: Secure Launch Resource Table definitions
In reply to Sergii DmytrukThe file provides constants, structures and several helper functions for parsing SLRT.
The data described by the structures is passed to Xen by a bootloader which initiated DRTM.
---
Notes:
v4: don't define UEFI_SLR_TABLE_GUID here, it's specific to UEFI support
v4: made pointer parameter of dl_handler_func() constant
xen/include/xen/slr-table.h | 272 ++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 xen/include/xen/slr-table.h
xen/include/xen/slr-table.h new file +272 -0
@@ -0,0 +1,272 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Secure Launch Resource Table definitions. This table is passed to Xen by +* a bootloader and contains information about pre-DRTM state necessary to +* restore hardware configuration, where to find TPM event log, how to call +* back into the bootloader (for EFI case) and what needs to be measured by +* Xen. In other words, this is similar to MBI in Multiboot Specification. +* +* Specification: +* https://trenchboot.org/specifications/Secure_Launch/ +* +* Copyright (c) 2025 Apertus Solutions, LLC +* Copyright (c) 2025 Oracle and/or its affiliates. +* Copyright (c) 2026 3mdeb Sp. z o.o +*/ + +#ifndef XEN_SLR_TABLE_H +#define XEN_SLR_TABLE_H + +#include <xen/types.h> + +/* SLR table header values */ +#define SLR_TABLE_MAGIC 0x4452544d +#define SLR_TABLE_REVISION 1 + +/* Current revisions for the policy and UEFI config */ +#define SLR_POLICY_REVISION 1 +#define SLR_UEFI_CONFIG_REVISION 1 + +/* SLR defined architectures */ +#define SLR_INTEL_TXT 1 +#define SLR_AMD_SKINIT 2 + +/* SLR defined bootloaders */ +#define SLR_BOOTLOADER_INVALID 0 +#define SLR_BOOTLOADER_GRUB 1 + +/* Log formats */ +#define SLR_DRTM_TPM12_LOG 1 +#define SLR_DRTM_TPM20_LOG 2 + +/* DRTM Policy Entry Flags */ +#define SLR_POLICY_FLAG_MEASURED 0x1 +#define SLR_POLICY_IMPLICIT_SIZE 0x2 + +/* Array Lengths */ +#define TPM_EVENT_INFO_LENGTH 32 +#define TXT_VARIABLE_MTRRS_LENGTH 32 + +/* Tags */ +#define SLR_ENTRY_INVALID 0x0000 +#define SLR_ENTRY_DL_INFO 0x0001 +#define SLR_ENTRY_LOG_INFO 0x0002 +#define SLR_ENTRY_DRTM_POLICY 0x0003 +#define SLR_ENTRY_INTEL_INFO 0x0004 +#define SLR_ENTRY_AMD_INFO 0x0005 +#define SLR_ENTRY_ARM_INFO 0x0006 +#define SLR_ENTRY_UEFI_INFO 0x0007 +#define SLR_ENTRY_UEFI_CONFIG 0x0008 +#define SLR_ENTRY_END 0xffff + +/* Entity Types */ +#define SLR_ET_UNSPECIFIED 0x0000 +#define SLR_ET_SLRT 0x0001 +#define SLR_ET_BOOT_PARAMS 0x0002 +#define SLR_ET_SETUP_DATA 0x0003 +#define SLR_ET_CMDLINE 0x0004 +#define SLR_ET_UEFI_MEMMAP 0x0005 +#define SLR_ET_RAMDISK 0x0006 +#define SLR_ET_MULTIBOOT2_INFO 0x0007 +#define SLR_ET_MULTIBOOT2_MODULE 0x0008 +#define SLR_ET_TXT_OS2MLE 0x0010 +#define SLR_ET_UNUSED 0xffff + +/* +* Primary SLR Table Header +*/ +struct slr_table +{ +uint32_t magic; +uint16_t revision; +uint16_t architecture; +uint32_t size; +uint32_t max_size; +/* entries[] */ +} __packed; + +/* +* Common SLRT Table Header +*/ +struct slr_entry_hdr +{ +uint32_t tag; +uint32_t size; +} __packed; + +/* +* Boot loader context +*/ +struct slr_bl_context +{ +uint16_t bootloader; +uint16_t reserved[3 ]; +uint64_t context; +} __packed; + +/* +* Prototype of a function pointed to by slr_entry_dl_info::dl_handler. +*/ +typedef void (*dl_handler_func )(const struct slr_bl_context *bl_context); + +/* +* DRTM Dynamic Launch Configuration +*/ +struct slr_entry_dl_info +{ +struct slr_entry_hdr hdr; +uint64_t dce_size; +uint64_t dce_base; +uint64_t dlme_size; +uint64_t dlme_base; +uint64_t dlme_entry; +struct slr_bl_context bl_context; +uint64_t dl_handler; +} __packed; + +/* +* TPM Log Information +*/ +struct slr_entry_log_info +{ +struct slr_entry_hdr hdr; +uint16_t format; +uint16_t reserved; +uint32_t size; +uint64_t addr; +} __packed; + +/* +* DRTM Measurement Entry +*/ +struct slr_policy_entry +{ +uint16_t pcr; +uint16_t entity_type; +uint16_t flags; +uint16_t reserved; +uint64_t size; +uint64_t entity; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +/* +* DRTM Measurement Policy +*/ +struct slr_entry_policy +{ +struct slr_entry_hdr hdr; +uint16_t reserved[2 ]; +uint16_t revision; +uint16_t nr_entries; +struct slr_policy_entry policy_entries[]; +} __packed; + +/* +* Secure Launch defined MTRR saving structures +*/ +struct slr_txt_mtrr_pair +{ +uint64_t mtrr_physbase; +uint64_t mtrr_physmask; +} __packed; + +struct slr_txt_mtrr_state +{ +uint64_t default_mem_type; +uint64_t mtrr_vcnt; +struct slr_txt_mtrr_pair mtrr_pair[TXT_VARIABLE_MTRRS_LENGTH ]; +} __packed; + +/* +* Intel TXT Info table +*/ +struct slr_entry_intel_info +{ +struct slr_entry_hdr hdr; +uint64_t boot_params_base; +uint64_t txt_heap; +uint64_t saved_misc_enable_msr; +struct slr_txt_mtrr_state saved_bsp_mtrrs; +} __packed; + +/* +* AMD SKINIT Info table +*/ +struct slr_entry_amd_info +{ +struct slr_entry_hdr hdr; +uint64_t next; +uint32_t type; +uint32_t len; +uint64_t slrt_size; +uint64_t slrt_base; +uint64_t boot_params_base; +uint16_t psp_version; +uint16_t reserved[3 ]; +} __packed; + +/* +* UEFI config measurement entry +*/ +struct slr_uefi_cfg_entry +{ +uint16_t pcr; +uint16_t reserved; +uint32_t size; +uint64_t cfg;/* address or value */ +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +struct slr_entry_uefi_config +{ +struct slr_entry_hdr hdr; +uint16_t reserved[2 ]; +uint16_t revision; +uint16_t nr_entries; +struct slr_uefi_cfg_entry uefi_cfg_entries[]; +} __packed; + +static inline const void * +slr_end_of_entries (const struct slr_table *table) +{ +return (const void *)table + table->size; +} + +static inline const struct slr_entry_hdr * +slr_next_entry (const struct slr_table *table,const struct slr_entry_hdr *curr) +{ +const struct slr_entry_hdr *next = (void *)curr + curr->size; + +if ( (void *)next +sizeof (*next) >slr_end_of_entries (table) ) +return NULL ; +if ( next->tag ==SLR_ENTRY_END ) +return NULL ; +if ( (void *)next + next->size >slr_end_of_entries (table) ) +return NULL ; + +return next; +} + +static inline const struct slr_entry_hdr * +slr_next_entry_by_tag (const struct slr_table *table, +const struct slr_entry_hdr *entry, +uint16_t tag) +{ +if ( !entry )/* Start from the beginning */ + entry = (void *)table +sizeof (*table); + +for ( ; ; ) + { +if ( entry->tag == tag ) +return entry; + + entry =slr_next_entry (table, entry); +if ( !entry ) +return NULL ; + } + +return NULL ; +} + +#endif /* XEN_SLR_TABLE_H */
Signature · 1 line
2.55.0
PATCH v4 9/23 x86/boot/slaunch-early: implement early initialization
In reply to Sergii DmytrukMake head.S invoke a C function to retrieve MBI and SLRT addresses in a platform-specific way. This is also the place to perform sanity checks of DRTM.
---
Notes:
v4: use CONFIG_SLAUNCH
v4: expose slaunch_early_init_results via asm-offsets.c to not hard-code its size
v4: use mov instead of lea in head.S
v4: put SPDX license comment on its own line
v4: check that SLRT address is below 4 GiB
v4: perform a TXT reset with specific error codes if data doesn't meet expectations
v4: replace SLAUNCH_ERROR_GENERIC with specific error codes
v4: removed declaration and a reference to otherwise unused slaunch_get_slrt()
v4: mark slaunch_active variable with __ro_after_init
v4: updates to the handling of TXT heap sections due to different API
xen/arch/x86/Makefile | 1 + xen/arch/x86/boot/Makefile | 12 +++++++- xen/arch/x86/boot/head.S | 35 +++++++++++++++++++-- xen/arch/x86/boot/slaunch-early.c | 46 ++++++++++++++++++++++++++++ xen/arch/x86/include/asm/intel-txt.h | 20 ++++++++++++ xen/arch/x86/include/asm/slaunch.h | 30 ++++++++++++++++++ xen/arch/x86/slaunch.c | 32 +++++++++++++++++++ xen/arch/x86/x86_64/asm-offsets.c | 10 ++++++ 8 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 xen/arch/x86/boot/slaunch-early.c create mode 100644 xen/arch/x86/include/asm/slaunch.h create mode 100644 xen/arch/x86/slaunch.c
xen/arch/x86/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_COMPAT) += x86_64/physdev.o obj-$(CONFIG_X86_PSR) += psr.o obj-y += setup.o obj-y += shutdown.o +obj-$(CONFIG_SLAUNCH) += slaunch.o obj-y += smp.o obj-y += smpboot.o obj-y += spec_ctrl.o
xen/arch/x86/boot/Makefile +11 -1
@@ -5,10 +5,18 @@ obj-bin-y += $(obj64) obj32 := cmdline.32.o obj32 += reloc.32.o obj32 += reloc-trampoline.32.o +ifeq ($(CONFIG_SLAUNCH),y) +obj32 += slaunch-early.32.o +endif obj32 += tpm-early.32.o obj64 := reloc-trampoline.o +exports := cmdline_parse_early,reloc,reloc_trampoline32 +ifeq ($(CONFIG_SLAUNCH),y) +exports := $(exports),slaunch_early_init +endif + nocov-y += $(obj32) $(obj64) noubsan-y += $(obj32) $(obj64) targets += $(obj32)
@@ -29,6 +37,8 @@ $(obj32): XEN_CFLAGS := $(CFLAGS_x86_32) -fpic $(obj)/%.32.o: $(src)/%.c FORCE $(call if_changed_rule,cc_o_c) +$(obj)/slaunch-early.32.o: XEN_CFLAGS += -D__EARLY_SLAUNCH__ + $(obj)/tpm-early.32.o: XEN_CFLAGS += -D__EARLY_TPM__ $(obj)/tpm-early.32.o: $(src)/../tpm.c FORCE $(call if_changed_rule,cc_o_c)
@@ -86,7 +96,7 @@ cmd_combine = \ --bin1 $(obj)/built-in-32.base.bin \ --bin2 $(obj)/built-in-32.offset.bin \ --map $(obj)/built-in-32.base.map \ - --exports cmdline_parse_early,reloc,reloc_trampoline32 \ + --exports $(exports) \ --output $@ targets += built-in-32.S
xen/arch/x86/boot/head.S +33 -2
@@ -508,8 +508,39 @@ __start: * bootloader with ESP, ESI and EDX being clobbered above. */ - /* Hang as this boot path is yet to be implemented. */ - jmp .Lslaunch_proto + /* Save information that TrenchBoot slaunch was used. */ + movb $1, sym_esi(slaunch_active) + + /* + * Prepare space for output parameter of slaunch_early_init(), which is + * the following structure: + * struct slaunch_early_init_results + * { + * uint32_t mbi_pa; + * uint32_t slrt_pa; + * } __packed; + */ + sub $SL_EIR_size, %esp + + push %esp /* pointer to output structure */ + mov $sym_offs(__2M_rwdata_end), %ecx /* end of target image */ + mov $sym_offs(_start), %edx /* target base address */ + mov %esi, %eax /* load base address */ + /* + * slaunch_early_init(load/eax, tgt/edx, tgt_end/ecx, ret/stk) using + * fastcall calling convention. + */ + call slaunch_early_init + add $4, %esp /* pop the fourth parameter */ + + /* Move outputs of slaunch_early_init() from the stack. */ + pop %ebx /* store physical MBI address in EBX where + MB2 code expects it */ + pop sym_esi(slaunch_slrt) /* save physical address of SLRT for C + code */ + + /* Move magic number expected by Multiboot 2 to EAX and fall through. */ + movl $MULTIBOOT2_BOOTLOADER_MAGIC, %eax #endif .Lmultiboot2_proto:
xen/arch/x86/boot/slaunch-early.c new file +46 -0
46 lines not on this page · raw message
xen/arch/x86/include/asm/intel-txt.h +20 -0
@@ -62,6 +62,9 @@#define SLAUNCH_ERROR_BUFFER_BEYOND_PMR 0xc0008006U#define SLAUNCH_ERROR_HEAP_BAD_OS2MLE 0xc0008007U#define SLAUNCH_ERROR_HEAP_BAD_OS2SINIT 0xc0008008U +#define SLAUNCH_ERROR_NO_VENDOR_INFO 0xc0008009U +#define SLAUNCH_ERROR_BAD_VENDOR_INFO 0xc000800AU +#define SLAUNCH_ERROR_BAD_SLRT_ADDRESS 0xc000800BU#ifndef __ASSEMBLER__
@@ -245,6 +248,23 @@ static inline void *txt_start(void *heap, int table_index)return heap +sizeof (uint64_t ); } +static inline void *txt_init (void ) +{ +void *txt_heap; + +/* Clear the TXT error register for a clean start of the day. */ +txt_write (TXTCR_ERRORCODE ,0 ); + + txt_heap =_p (txt_read (TXTCR_HEAP_BASE )); + +if (txt_size (txt_heap,TXT_OS2MLE ) <sizeof (struct txt_os_mle_data ) ) +txt_reset (SLAUNCH_ERROR_HEAP_BAD_OS2MLE ); +if (txt_size (txt_heap,TXT_OS2SINIT ) <sizeof (struct txt_os_sinit_data ) ) +txt_reset (SLAUNCH_ERROR_HEAP_BAD_OS2SINIT ); + +return txt_heap; +} +#endif /* !__ASSEMBLER__ */ #endif /* X86_INTEL_TXT_H */
xen/arch/x86/include/asm/slaunch.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Declarations related to Slaunch (an implementation of a DRTM launch). This +* header is consumed by both normal and early boot code and has to take the +* two environments into account. +* +* More details about Slaunch are available at: +* https://trenchboot.org/specifications/Secure_Launch/ +* +* Copyright (c) 2022-2026 3mdeb Sp. z o.o. All rights reserved. +*/ + +#ifndef X86_SLAUNCH_H +#define X86_SLAUNCH_H + +#include <xen/types.h> + +struct slaunch_early_init_results +{ +uint32_t mbi_pa; +uint32_t slrt_pa; +} __packed; + +/* Indicates an active Secure Launch boot. */ +extern bool slaunch_active; + +/* Holds physical address of SLRT. */ +extern uint32_t slaunch_slrt; + +#endif /* X86_SLAUNCH_H */
xen/arch/x86/slaunch.c new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Main Slaunch code used during boot process. +* +* Copyright (c) 2022-2026 3mdeb Sp. z o.o. All rights reserved. +*/ + +#include <xen/compiler.h> +#include <xen/init.h> +#include <xen/inttypes.h> +#include <xen/macros.h> +#include <xen/sections.h> + +#include <asm/slaunch.h> + +/* +* These variables are assigned to by the code near Xen's entry point. +* +* slaunch_active is not __initdata to allow checking for an active Secure +* Launch boot at any point. +*/ +bool __ro_after_init slaunch_active; +uint32_t __initdata slaunch_slrt;/* physical address */ + +/* +* Using slaunch_active in head.S assumes it's a single byte in size, so enforce +* this assumption. +*/ +static void __maybe_unused compile_time_checks (void ) +{ +BUILD_BUG_ON (sizeof (slaunch_active) !=1 ); +}
xen/arch/x86/x86_64/asm-offsets.c +10 -0
@@ -16,6 +16,9 @@#include <xen/multiboot.h> #include <xen/multiboot2.h> #include <asm/guest-msr.h> +#ifdef CONFIG_SLAUNCH +#include <asm/slaunch.h> +#endif #ifdef CONFIG_VIDEO # include "../boot/video.h"
@@ -236,4 +239,11 @@ void __dummy__(void)DEFINE (BVI_size,sizeof (struct boot_video_info ));BLANK ();#endif /* CONFIG_VIDEO */ + +#ifdef CONFIG_SLAUNCH + OFFSET(SL_EIR_mbi_pa, struct slaunch_early_init_results, mbi_pa); + OFFSET(SL_EIR_slrt_pa, struct slaunch_early_init_results, slrt_pa); +DEFINE (SL_EIR_size,sizeof (struct slaunch_early_init_results )); +BLANK (); +#endif }
Signature · 1 line
2.55.0
PATCH v4 10/23 x86/boot/slaunch-early: early Intel TXT sanity checks
In reply to Sergii DmytrukFrom: Krystian Hebel <[email protected]>
The tests validate that important parts of memory are protected against DMA attacks, including Xen and MBI. Modules can be tested later, when it is possible to report issues to a user before invoking TXT reset.
The protection used here is Protected Memory Regions (PMRs), which is not available on modern hardware like MeteorLake that uses TXT DMA Protection Ranges (TPR) and is to be added separately.
TPM event log validation is temporarily disabled due to an issue with its allocation by bootloader (GRUB) which will need to be modified to address this. Ultimately event log will also have to be validated early as it is used immediately after these tests to hold MBI measurements. See larger comment in txt_verify_pmr_ranges().
---
Notes:
v4: was "x86/boot/slaunch-early: early TXT checks and boot data retrieval"
v4: updates to the handling of TXT heap sections due to different API
v4: use bool instead of int in two places
v4: don't use low range in is_in_pmr(), it must be zero
v4: use struct multiboot2_fixed_t instead of casting and dereferencing uint32_t *
v4: TPM event log check being covered by PMR can't be safely uncommented without constraining where TPM event log is allocated
xen/arch/x86/boot/slaunch-early.c | 6 ++ xen/arch/x86/include/asm/intel-txt.h | 118 +++++++++++++++++++++++++++ 2 files changed, 124 insertions(+)
xen/arch/x86/boot/slaunch-early.c +6 -0
@@ -21,11 +21,14 @@ void asmlinkage slaunch_early_init(uint32_t load_base_addr,void *txt_heap;const struct txt_os_mle_data *os_mle;const struct slr_table *slrt; +const struct txt_os_sinit_data *os_sinit;const struct slr_entry_hdr *entry;const struct slr_entry_intel_info *intel_info; +uint32_t size = tgt_end_addr - tgt_base_addr; txt_heap =txt_init (); os_mle =txt_start (txt_heap,TXT_OS2MLE ); + os_sinit =txt_start (txt_heap,TXT_OS2SINIT );if ( os_mle->slrt & ~0xffffffffULL )txt_reset (SLAUNCH_ERROR_BAD_SLRT_ADDRESS );
@@ -43,4 +46,7 @@ void asmlinkage slaunch_early_init(uint32_t load_base_addr,txt_reset (SLAUNCH_ERROR_BAD_VENDOR_INFO ); result->mbi_pa = intel_info->boot_params_base; + +txt_verify_pmr_ranges (os_mle, os_sinit, intel_info, + load_base_addr, tgt_base_addr, size); }
xen/arch/x86/include/asm/intel-txt.h +118 -0
130 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 11/23 xen/arch/x86: reserve TXT memory during Slaunch
In reply to Sergii DmytrukFrom: Kacper Stojek <[email protected]>
TXT heap, SINIT and TXT private space are marked as reserved or unused in e820 to protect from unintended uses.
---
Notes:
v4: use CONFIG_SLAUNCH
v4: use unsigned long constant in PREBUILT_MAP_LIMIT #define
v4: add slaunch-tpm unit for TPM-related code specific to Slaunch (builds as normal and early code)
v4: slaunch_get_slrt() now makes its first appearance in this commit
v4: slaunch_find_log() is now defined in slaunch-tpm.c
v4: improved signature and comment for slaunch_map_l2()
v4: moved SPDX license comments to their own lines
v4: reduced txt_heap_base and txt_heap_size from 64-bit to 32-bit
v4: changed reserve_ram() to return bool and not take type (it's always the same) and skip already reserved memory
v4: switch from "(from - to)" ranges to "[from, to)" in prints
v4: verify that slaunch_map_l2() was passed a range below 4 GiB
v4: move PREBUILT_MAP_LIMIT from asm/mm.h to asm/setup.h
xen/arch/x86/Makefile | 2 + xen/arch/x86/include/asm/intel-txt.h | 6 ++ xen/arch/x86/include/asm/setup.h | 3 + xen/arch/x86/include/asm/slaunch-tpm.h | 19 +++++ xen/arch/x86/include/asm/slaunch.h | 34 +++++++- xen/arch/x86/intel-txt.c | 113 +++++++++++++++++++++++++ xen/arch/x86/setup.c | 10 ++- xen/arch/x86/slaunch-tpm.c | 36 ++++++++ xen/arch/x86/slaunch.c | 105 ++++++++++++++++++++++- 9 files changed, 323 insertions(+), 5 deletions(-) create mode 100644 xen/arch/x86/include/asm/slaunch-tpm.h create mode 100644 xen/arch/x86/intel-txt.c create mode 100644 xen/arch/x86/slaunch-tpm.c
xen/arch/x86/Makefile +2 -0
@@ -42,6 +42,7 @@ obj-y += i387.o obj-y += i8259.o obj-$(CONFIG_INDIRECT_THUNK) += indirect-thunk.o obj-$(CONFIG_RETURN_THUNK) += indirect-thunk.o +obj-$(CONFIG_SLAUNCH) += intel-txt.o obj-$(CONFIG_PV) += ioport_emulate.o obj-y += io_apic.o obj-y += irq.o
@@ -61,6 +62,7 @@ obj-$(CONFIG_X86_PSR) += psr.o obj-y += setup.o obj-y += shutdown.o obj-$(CONFIG_SLAUNCH) += slaunch.o +obj-$(CONFIG_SLAUNCH) += slaunch-tpm.o obj-y += smp.o obj-y += smpboot.o obj-y += spec_ctrl.o
xen/arch/x86/include/asm/intel-txt.h +6 -0
@@ -383,6 +383,12 @@ static inline void txt_verify_pmr_ranges(*/ } +/* Prepares for accesses to TXT-specific memory. */ +void txt_map_mem_regions (void ); + +/* Marks TXT-specific memory as used to avoid its corruption. */ +void txt_reserve_mem_regions (void ); +#endif /* !__ASSEMBLER__ */ #endif /* X86_INTEL_TXT_H */
xen/arch/x86/include/asm/setup.h +3 -0
@@ -4,6 +4,9 @@#include <xen/multiboot.h> #include <asm/numa.h> +/* How much of the directmap is prebuilt at compile time. */ +#define PREBUILT_MAP_LIMIT (1UL << L2_PAGETABLE_SHIFT) +extern const char __2M_text_start[], __2M_text_end[];extern const char __2M_rodata_start[], __2M_rodata_end[];extern char __2M_init_start[], __2M_init_end[];
xen/arch/x86/include/asm/slaunch-tpm.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* TPM-related functions of Slaunch. Can be used in both normal and early boot +* environments. +* +* Copyright (c) 2026 3mdeb Sp. z o.o. All rights reserved. +*/ + +#ifndef X86_SLAUNCH_TPM_H +#define X86_SLAUNCH_TPM_H + +#include <xen/types.h> + +struct slr_table ; + +void slaunch_find_log (const struct slr_table *slrt,paddr_t *evt_log, +uint32_t *evt_log_size); + +#endif /* X86_SLAUNCH_TPM_H */
xen/arch/x86/include/asm/slaunch.h +33 -1
@@ -13,6 +13,8 @@#ifndef X86_SLAUNCH_H #define X86_SLAUNCH_H +#include <xen/kernel.h> +#include <xen/slr-table.h> #include <xen/types.h> struct slaunch_early_init_results
@@ -24,7 +26,37 @@ struct slaunch_early_init_results/* Indicates an active Secure Launch boot. */ extern bool slaunch_active; -/* Holds physical address of SLRT. */ +/* +* Holds physical address of SLRT. Use slaunch_get_slrt() to access SLRT +* instead of mapping where this points to. +*/ extern uint32_t slaunch_slrt; +/* +* Retrieves pointer to SLRT. Checks table's validity and maps it as necessary. +*/ +struct slr_table *slaunch_get_slrt (void ); + +/* +* Prepares for accesses to essential data structures setup by boot environment. +*/ +void slaunch_map_mem_regions (void ); + +/* Marks regions of memory as used to avoid their corruption. */ +void slaunch_reserve_mem_regions (void ); + +/* +* This helper function is used to map memory below 4 GiB using L2 page tables +* by aligning mapped regions to 2MB. This way page allocator (which at this +* point isn't yet initialized) isn't needed for creating new L1 mappings. The +* function also checks and skips memory already mapped by the prebuilt tables. +* +* There is no unmap_l2() because the function is meant to be used by the code +* that accesses DRTM-related memory soon after which Xen rebuilds memory maps, +* effectively dropping all existing mappings. +* +* Returns zero on success. +*/ +int slaunch_map_l2 (paddr_t paddr,size_t size); +#endif /* X86_SLAUNCH_H */
xen/arch/x86/intel-txt.c new file +113 -0
113 lines not on this page · raw message
xen/arch/x86/setup.c +7 -3
@@ -50,6 +50,7 @@#include <asm/pv/domain.h> #include <asm/setup.h> #include <asm/shstk.h> +#include <asm/slaunch.h> #include <asm/smp.h> #include <asm/spec_ctrl.h> #include <asm/stubs.h>
@@ -1128,9 +1129,6 @@ static struct domain *__init create_dom0(struct boot_info *bi)return d; } -/* How much of the directmap is prebuilt at compile time. */ -#define PREBUILT_MAP_LIMIT (1 << L2_PAGETABLE_SHIFT) - void asmlinkage __init noreturn __start_xen(void) {const char *memmap_type =NULL ;
@@ -1472,6 +1470,12 @@ void asmlinkage __init noreturn __start_xen(void)#endif } +if ( slaunch_active ) + { +slaunch_map_mem_regions (); +slaunch_reserve_mem_regions (); + } +/* Sanitise the raw E820 map to produce a final clean version. */ max_page = raw_max_page =init_e820 (memmap_type, &e820_raw);
xen/arch/x86/slaunch-tpm.c new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Slaunch functions related to TPM. +* +* Copyright (c) 2022-2026 3mdeb Sp. z o.o. All rights reserved. +*/ + +#include <xen/macros.h> +#include <xen/slr-table.h> +#include <xen/types.h> + +void slaunch_find_log (const struct slr_table *slrt,paddr_t *evt_log, +uint32_t *evt_log_size) +{ +const struct slr_entry_hdr *hdr; + + hdr =slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_LOG_INFO ); +if ( hdr !=NULL ) + { +const struct slr_entry_log_info *log_info; + log_info = container_of(hdr, const struct slr_entry_log_info, hdr); + + *evt_log = (uintptr_t )_p (log_info->addr); + *evt_log_size = log_info->size; + } +else + { +/* +* Event log is used to verify measurements, but values of PCRs is the +* real authoritative source of information, so keep going if there is +* no log as secrets may still be correctly unsealed by TPM. +*/ + *evt_log =0 ; + *evt_log_size =0 ; + } +}
xen/arch/x86/slaunch.c +104 -1
118 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 12/23 x86/slaunch: restore boot MTRRs after Intel TXT DRTM
In reply to Sergii DmytrukFrom: Krystian Hebel <[email protected]>
In preparation for TXT SENTER call, GRUB had to modify MTRR settings to be UC for everything except SINIT ACM. Old values are restored from SLRT where they were saved by the bootloader.
---
Notes:
v4: now this commit makes two functions of mtrr/generic.c public
v4: take CONFIG_SLAUNCH into account
v4: restore MTRRs earlier: move from mtrr_top_of_ram() to machine_specific_memory_setup()
v4: renamed parameter of txt_restore_mtrrs(): e820_verbose => verbose
v4: don't use rdmsrl() and wrmsrl()
v4: extract part of an integer consistently (mtrr_cap in txt_restore_mtrrs(), was a mix of (uint8_t) cast and & 0xff)
v4: use container_of()
v4: manage MTRR count in txt_restore_mtrrs() better (separate variable, no weird ?: operator)
xen/arch/x86/cpu/mtrr/generic.c | 9 +-- xen/arch/x86/e820.c | 5 ++ xen/arch/x86/include/asm/intel-txt.h | 3 + xen/arch/x86/include/asm/mtrr.h | 8 +++ xen/arch/x86/include/asm/slaunch.h | 8 +++ xen/arch/x86/intel-txt.c | 84 ++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 7 deletions(-)
xen/arch/x86/cpu/mtrr/generic.c +2 -7
@@ -14,11 +14,6 @@#include <asm/cpufeature.h> #include "mtrr.h" -struct mtrr_pausing_state { -bool pge; -uint64_t def_type; -}; - static const struct fixed_range_block { uint32_t base_msr; /* start address of an MTRR block */ unsigned int ranges; /* number of MTRRs in this block */
@@ -440,7 +435,7 @@ static DEFINE_SPINLOCK(set_atomicity_lock);* has been called. */ -static void mtrr_pause_caching (struct mtrr_pausing_state *state) +void mtrr_pause_caching (struct mtrr_pausing_state *state) {unsigned long cr4;
@@ -481,7 +476,7 @@ static void mtrr_pause_caching(struct mtrr_pausing_state *state)alternative ("wbinvd" ,"" ,X86_FEATURE_XEN_SELFSNOOP ); } -static void mtrr_resume_caching (struct mtrr_pausing_state state) +void mtrr_resume_caching (struct mtrr_pausing_state state) {/* Intel (P6) standard MTRRs */ mtrr_wrmsr (MSR_MTRRdefType, state.def_type);
xen/arch/x86/e820.c +5 -0
@@ -11,6 +11,8 @@#include <asm/mtrr.h> #include <asm/msr.h> #include <asm/guest.h> +#include <asm/intel-txt.h> +#include <asm/slaunch.h> /* * opt_mem: Limit maximum address of physical RAM.
@@ -499,6 +501,9 @@ static void __init machine_specific_memory_setup(struct e820map *raw)uint64_t top_of_ram, size;unsigned int i; +if ( slaunch_active ) +txt_restore_mtrrs (e820_verbose); +sanitize_e820_map (raw->map, &raw->nr_map);copy_e820_map (raw->map, raw->nr_map);
xen/arch/x86/include/asm/intel-txt.h +3 -0
@@ -389,6 +389,9 @@ void txt_map_mem_regions(void);/* Marks TXT-specific memory as used to avoid its corruption. */ void txt_reserve_mem_regions (void ); +/* Restores original MTRR values saved by a bootloader before starting DRTM. */ +void txt_restore_mtrrs (bool verbose); +#endif /* !__ASSEMBLER__ */ #endif /* X86_INTEL_TXT_H */
xen/arch/x86/include/asm/mtrr.h +8 -0
@@ -63,6 +63,14 @@ extern uint8_t pat_type_2_pte_flags(uint8_t pat_type);extern void mtrr_aps_sync_begin (void );extern void mtrr_aps_sync_end (void ); +struct mtrr_pausing_state { +bool pge; +uint64_t def_type; +}; + +extern void mtrr_pause_caching (struct mtrr_pausing_state *state); +extern void mtrr_resume_caching (struct mtrr_pausing_state state); +extern bool mtrr_var_range_msr_set (struct domain *d,struct mtrr_state *m,uint32_t msr,uint64_t msr_content); extern bool mtrr_fix_range_msr_set(struct domain *d, struct mtrr_state *m,
xen/arch/x86/include/asm/slaunch.h +8 -0
@@ -23,8 +23,16 @@ struct slaunch_early_init_resultsuint32_t slrt_pa; } __packed; +#ifdef CONFIG_SLAUNCH /* Indicates an active Secure Launch boot. */ extern bool slaunch_active; +#else +/* +* This avoids `#ifdef CONFIG_SLAUNCH` around `if ( slaunch_active )` thanks to +* dead code elimination. +*/ +static bool slaunch_active = false; +#endif /* * Holds physical address of SLRT. Use slaunch_get_slrt() to access SLRT
xen/arch/x86/intel-txt.c +84 -0
97 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 13/23 x86/slaunch: measure MBI into TPM
In reply to Sergii DmytrukFrom: Krystian Hebel <[email protected]>
Make slaunch-tpm.c compile in early boot environment use it to measure MBI in early 32b code without paging (gets triggered from head.S).
The fact of the measurement is not yet stored anywhere as there is no code for TPM event log discovery and modification.
---
Notes:
v4: was part of "x86/tpm.c: code for early hashing and extending PCRs (for TPM1.2)"
v4: tpm_extend_mbi => slaunch_measure_mbi
v4: doesn't touch tpm.c, uses slaunch-tpm.c instead
v4: use const multiboot2_fixed_t * instead of uint32_t * for MBI
xen/arch/x86/boot/Makefile | 7 +- xen/arch/x86/boot/head.S | 5 ++ xen/arch/x86/include/asm/slaunch-tpm.h | 7 ++ xen/arch/x86/include/asm/slaunch.h | 14 ++++ xen/arch/x86/slaunch-tpm.c | 112 +++++++++++++++++++++++++ xen/arch/x86/slaunch.c | 4 + 6 files changed, 148 insertions(+), 1 deletion(-)
xen/arch/x86/boot/Makefile +6 -1
@@ -7,6 +7,7 @@ obj32 += reloc.32.o obj32 += reloc-trampoline.32.o ifeq ($(CONFIG_SLAUNCH),y) obj32 += slaunch-early.32.o +obj32 += slaunch-tpm-early.32.o endif obj32 += tpm-early.32.o
@@ -14,7 +15,7 @@ obj64 := reloc-trampoline.o exports := cmdline_parse_early,reloc,reloc_trampoline32 ifeq ($(CONFIG_SLAUNCH),y) -exports := $(exports),slaunch_early_init +exports := $(exports),slaunch_early_init,slaunch_measure_mbi endif nocov-y += $(obj32) $(obj64)
@@ -39,6 +40,10 @@ $(obj)/%.32.o: $(src)/%.c FORCE $(obj)/slaunch-early.32.o: XEN_CFLAGS += -D__EARLY_SLAUNCH__ +$(obj)/slaunch-tpm-early.32.o: XEN_CFLAGS += -D__EARLY_SLAUNCH__ +$(obj)/slaunch-tpm-early.32.o: $(src)/../slaunch-tpm.c FORCE + $(call if_changed_rule,cc_o_c) + $(obj)/tpm-early.32.o: XEN_CFLAGS += -D__EARLY_TPM__ $(obj)/tpm-early.32.o: $(src)/../tpm.c FORCE $(call if_changed_rule,cc_o_c)
xen/arch/x86/boot/head.S +5 -0
@@ -539,6 +539,11 @@ __start: pop sym_esi(slaunch_slrt) /* save physical address of SLRT for C code */ + mov sym_esi(slaunch_slrt), %edx /* physical SLRT address */ + mov %ebx, %eax /* physical MBI address */ + /* slaunch_measure_mbi(mbi/eax, slrt/edx) using fastcall. */ + call slaunch_measure_mbi + /* Move magic number expected by Multiboot 2 to EAX and fall through. */ movl $MULTIBOOT2_BOOTLOADER_MAGIC, %eax #endif
xen/arch/x86/include/asm/slaunch-tpm.h +7 -0
@@ -16,4 +16,11 @@ struct slr_table;void slaunch_find_log (const struct slr_table *slrt,paddr_t *evt_log,uint32_t *evt_log_size); +/* +* Log data is optional (pass in NULL and/or zero size to indicate its absence). +*/ +void slaunch_hash_extend (unsigned int loc,unsigned int pcr,const uint8_t *buf, +unsigned int size,uint32_t type, +const uint8_t *log_data,unsigned int log_data_size); +#endif /* X86_SLAUNCH_TPM_H */
xen/arch/x86/include/asm/slaunch.h +14 -0
@@ -17,6 +17,20 @@#include <xen/slr-table.h> #include <xen/types.h> +#define DRTM_LOC 2 +#define DRTM_CODE_PCR 17 +#define DRTM_DATA_PCR 18 + +/* +* Secure Launch event log entry types. The TXT specification defines the base +* event value as 0x400 for DRTM values, use it regardless of the DRTM for +* consistency. +*/ +#define DLE_EVTYPE_BASE 0x400 +#define DLE_EVTYPE_SLAUNCH (DLE_EVTYPE_BASE + 0x102) +#define DLE_EVTYPE_SLAUNCH_START (DLE_EVTYPE_BASE + 0x103) +#define DLE_EVTYPE_SLAUNCH_END (DLE_EVTYPE_BASE + 0x104) +struct slaunch_early_init_results {uint32_t mbi_pa;
xen/arch/x86/slaunch-tpm.c +112 -0
128 lines not on this page · raw message
xen/arch/x86/slaunch.c +4 -0
@@ -18,6 +18,7 @@#include <asm/setup.h> #include <asm/slaunch.h> #include <asm/slaunch-tpm.h> +#include <asm/tpm.h> /* * These variables are assigned to by the code near Xen's entry point.
@@ -78,6 +79,9 @@ void __init slaunch_map_mem_regions(void)paddr_t evt_log_addr;uint32_t evt_log_size; + rc =slaunch_map_l2 (TPM_MMIO_BASE ,TPM_MMIO_SIZE ); +BUG_ON (rc !=0 ); +/* Vendor-specific part. */ txt_map_mem_regions ();
Signature · 1 line
2.55.0
PATCH v4 14/23 x86/slaunch: update TPM event log (TPM1.2 or TPM2.0)
In reply to Sergii DmytrukInstead of storing hashing result to stack variables, a TPM event log is discovered in an Slaunch-specific way, extended with an additional entry and that entry is filled with digests.
---
Notes:
v4: was "x86/tpm.c: implement event log for TPM2.0"
v4: part of it as in "x86/tpm.c: code for early hashing and extending PCRs (for TPM1.2)"
v4: TPM event log code was part of tpm.c changes, now in slaunch-tpm.c
v4: fixed comment on txt_ext_data_element::size and finding log element (worked because it was first)
v4: provide list of hashes even in the absence of event log to extend PCRs
xen/arch/x86/include/asm/intel-txt.h | 69 ++++++++++ xen/arch/x86/slaunch-tpm.c | 188 +++++++++++++++++++++++---- 2 files changed, 232 insertions(+), 25 deletions(-)
xen/arch/x86/include/asm/intel-txt.h +69 -0
@@ -71,6 +71,8 @@#include <xen/multiboot2.h> #include <xen/slr-table.h> +#include <asm/tpm1.h> +/* Need to differentiate between pre- and post paging enabled. */ #ifdef __EARLY_SLAUNCH__#include <xen/macros.h>
@@ -200,6 +202,52 @@ struct txt_sinit_mle_data {/* Ext Data Elements */ } __packed; +struct txt_ev_log_container_12 { +char Signature[20 ];/* "TXT Event Container", null-terminated */ +uint8_t Reserved[12 ]; +uint8_t ContainerVerMajor; +uint8_t ContainerVerMinor; +uint8_t PCREventVerMajor; +uint8_t PCREventVerMinor; +uint32_t ContainerSize;/* Allocated size */ +uint32_t PCREventsOffset; +uint32_t NextEventOffset; +struct TPM12_PCREvent PCREvents[]; +}; + +/* Types of extended data. */ +#define TXT_HEAP_EXTDATA_TYPE_END 0 +#define TXT_HEAP_EXTDATA_TYPE_BIOS_SPEC_VER 1 +#define TXT_HEAP_EXTDATA_TYPE_ACM 2 +#define TXT_HEAP_EXTDATA_TYPE_STM 3 +#define TXT_HEAP_EXTDATA_TYPE_CUSTOM 4 +#define TXT_HEAP_EXTDATA_TYPE_MADT 6 +#define TXT_HEAP_EXTDATA_TYPE_EVENT_LOG_POINTER2_1 8 +#define TXT_HEAP_EXTDATA_TYPE_MCFG 9 +#define TXT_HEAP_EXTDATA_TYPE_TPR_REQ 13 +#define TXT_HEAP_EXTDATA_TYPE_DTPR 14 +#define TXT_HEAP_EXTDATA_TYPE_CEDT 15 + +/* +* Self-describing data structure that is used for extensions to TXT heap +* tables. +*/ +struct txt_ext_data_element { +uint32_t type;/* One of TXT_HEAP_EXTDATA_TYPE_*. */ +uint32_t size;/* Size of the whole element (header + data), in bytes. */ +uint8_t data[0 ]; +} __packed; + +/* +* Extended data describing TPM 2.0 log. +*/ +struct heap_event_log_pointer_element2_1 { +uint64_t physical_address; +uint32_t allocated_event_container_size; +uint32_t first_record_offset; +uint32_t next_record_offset; +} __packed; +/* * Functions to extract data from the Intel TXT Heap Memory. *
@@ -268,6 +316,27 @@ static inline void *txt_init(void)return txt_heap; } +/* +* Find the given element in the TXT heap extended data. +*/ +static inline struct txt_ext_data_element * +txt_find_ext_data_element (struct txt_os_sinit_data *os_sinit,uint32_t type) +{ +struct txt_ext_data_element *ext_elem; + + ext_elem = (void *)os_sinit +sizeof (struct txt_os_sinit_data ); + +while ( ext_elem->type !=TXT_HEAP_EXTDATA_TYPE_END ) + { +if ( ext_elem->type == type ) +return ext_elem; + + ext_elem = (void *)ext_elem + ext_elem->size; + } + +return NULL ; +} +static inline bool is_in_pmr (const struct txt_os_sinit_data *os_sinit,uint64_t base,uint32_t size,bool check_high) {
xen/arch/x86/slaunch-tpm.c +163 -25
211 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 15/23 x86/hvm: check for VMX in SMX if Slaunch is active
In reply to Sergii DmytrukFrom: Michał Żygowski <[email protected]>
Check whther IA32_FEATURE_CONTROL has the proper bits enabled to run VMX in SMX when slaunch is active.
---
Notes:
v4: added Acked-by
xen/arch/x86/hvm/vmx/vmcs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vmcs.c +2 -1
@@ -30,6 +30,7 @@#include <asm/msr.h> #include <asm/processor.h> #include <asm/shadow.h> +#include <asm/slaunch.h> #include <asm/spec_ctrl.h> #include <asm/tboot.h> #include <asm/xstate.h>
@@ -742,7 +743,7 @@ static int _vmx_cpu_up(bool bsp) bios_locked = !!(eax &IA32_FEATURE_CONTROL_LOCK );if ( bios_locked ) { -if ( !(eax & (tboot_in_measured_env () +if ( !(eax & (tboot_in_measured_env () || slaunch_active ?IA32_FEATURE_CONTROL_ENABLE_VMXON_INSIDE_SMX :IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX )) ) {
Signature · 1 line
2.55.0
PATCH v4 16/23 x86/boot: choose AP stack based on APIC ID
In reply to Sergii DmytrukFrom: Krystian Hebel <[email protected]>
This is made as the first step of making parallel AP bring-up possible. It should be enough for pre-C code.
Parallel AP bring-up is necessary because TXT by design releases all APs at once. In addition to that it reduces number of IPIs (and more importantly, delays between them) required to start all logical processors. This results in significant reduction of boot time, even when DRTM is not used, with performance gain growing with the number of logical CPUs.
---
Notes:
v4: better comments in boot/trampoline.S
v4: use %ebp instead of %esp to pass data to boot/x86_64.S
v4: use nr_cpu_ids(%rip) instead of $NR_CPUS in boot/x86_64.S
v4: L_stack_set => L_after_stack_setup
v4: __ASSEMBLY__ => __ASSEMBLER__
xen/arch/x86/boot/head.S | 1 + xen/arch/x86/boot/trampoline.S | 23 +++++++++++++++++++++ xen/arch/x86/boot/x86_64.S | 31 +++++++++++++++++++++++++++- xen/arch/x86/include/asm/apicdef.h | 4 ++++ xen/arch/x86/include/asm/msr-index.h | 3 +++ xen/arch/x86/setup.c | 7 +++++++ 6 files changed, 68 insertions(+), 1 deletion(-)
xen/arch/x86/boot/head.S +1 -0
@@ -8,6 +8,7 @@ #include <asm/page.h> #include <asm/processor.h> #include <asm/msr-index.h> +#include <asm/apicdef.h> #include <asm/cpufeature.h> #include <asm/trampoline.h>
xen/arch/x86/boot/trampoline.S +23 -0
@@ -71,6 +71,29 @@ trampoline_protmode_entry: mov $X86_CR4_PAE,%ecx mov %ecx,%cr4 + /* + * Get APIC ID while we're in non-paged mode to later derive Xen CPU + * index and determine CPU-specific stack. Start by checking if x2APIC + * is enabled. + */ + mov $MSR_APIC_BASE, %ecx + rdmsr + test $APIC_BASE_EXTD, %eax + jnz .Lx2apic + + /* Not x2APIC, read APIC ID from MMIO. */ + and $APIC_BASE_ADDR_MASK, %eax + mov APIC_ID(%eax), %eax + shr $24, %eax + jmp 1f + +.Lx2apic: + mov $(MSR_X2APIC_FIRST + (APIC_ID >> MSR_X2APIC_SHIFT)), %ecx + rdmsr +1: + /* The value of the APIC ID will be consumed in __high_start. */ + mov %eax, %ebp + /* Load pagetable base register. */ mov $sym_offs(idle_pg_table),%eax add bootsym_rel(trampoline_xen_phys_start,4,%eax)
xen/arch/x86/boot/x86_64.S +30 -1
@@ -11,7 +11,36 @@ ENTRY(__high_start) mov %ecx,%gs mov %ecx,%ss - mov stack_start(%rip),%rsp + /* %ebx is set to non-zero in trampoline.S to indicate an AP. */ + test %ebx, %ebx + cmovz stack_start(%rip), %rsp + jz .L_after_stack_setup + + /* + * APs only: get stack base from APIC ID saved to %ebp in trampoline.S. + */ + mov $-1, %rax + lea x86_cpu_to_apicid(%rip), %rcx +1: + inc %rax + cmp nr_cpu_ids(%rip), %eax + jb 2f + hlt +2: + cmp %ebp, (%rcx, %rax, 4) + jne 1b + + /* %eax is now Xen CPU index. */ + lea stack_base(%rip), %rcx + mov (%rcx, %rax, 8), %rsp + + test %rsp, %rsp + jnz 1f + hlt +1: + add $(STACK_SIZE - CPUINFO_sizeof), %rsp + +.L_after_stack_setup: /* Reset EFLAGS (subsumes CLI and CLD). */ pushq $0
xen/arch/x86/include/asm/apicdef.h +4 -0
@@ -120,6 +120,10 @@#define MAX_IO_APICS 128 +#ifndef __ASSEMBLER__ +extern bool x2apic_enabled; +#endif /* !__ASSEMBLER__ */ +#endif
xen/arch/x86/include/asm/msr-index.h +3 -0
@@ -186,6 +186,9 @@#define MSR_X2APIC_FIRST 0x00000800#define MSR_X2APIC_LAST 0x000008ff +/* MSR offset can be obtained by shifting MMIO offset this number of bits to the right. */ +#define MSR_X2APIC_SHIFT 4 +#define MSR_X2APIC_TPR 0x00000808#define MSR_X2APIC_PPR 0x0000080a#define MSR_X2APIC_EOI 0x0000080b
xen/arch/x86/setup.c +7 -0
@@ -2141,6 +2141,7 @@ void asmlinkage __init noreturn __start_xen(void)*/ if ( !pv_shim ) { +/* Separate loop to make parallel AP bringup possible. */ for_each_present_cpu ( i ) {/* Set up cpu_to_node[]. */
@@ -2148,6 +2149,12 @@ void asmlinkage __init noreturn __start_xen(void)/* Set up node_to_cpumask based on cpu_to_node[]. */ numa_add_cpu (i); +if ( stack_base[i] ==NULL ) + stack_base[i] =cpu_alloc_stack (i); + } + +for_each_present_cpu ( i ) + {if ( (park_offline_cpus ||num_online_cpus () < max_cpus) && !cpu_online (i) ) {
Signature · 1 line
2.55.0
PATCH v4 17/23 x86/smpboot.c: TXT AP bringup
In reply to Sergii DmytrukFrom: Krystian Hebel <[email protected]>
On Intel TXT, APs are started in one of two ways, depending on ACM which reports it in its information table. In both cases, all APs are started simultaneously after BSP requests them to do so. Two possible ways are:
- GETSEC[WAKEUP] instruction,
- MONITOR address.
GETSEC[WAKEUP] requires versions >= 7 of SINIT to MLE Data, but there is no clear mapping of that version with regard to processor family and it's not known which CPUs actually use it. It could have been designed for TXT support on CPUs that lack MONITOR/MWAIT, because GETSEC[WAKEUP] seems to be more complicated, in software and hardware alike.
This patch implements only MONITOR approach, GETSEC[WAKEUP] support will be added later once more details and means of testing are available and if there is a practical need for it.
With this patch, every AP goes through assembly part, and only when in start_secondary() in C they re-enter MONITOR/MWAIT iff they are not the AP that was asked to boot. The same address is reused for simplicity, and on next wakeup call APs don't have to go through assembly part again (GDT, paging, stack setting).
---
Notes:
v4: replace TXT_AP_BOOT_CS and TXT_AP_BOOT_DS with trampoline_gdt_txt and computing CS
v4: make APs call C from __high_start to synchronize with BSP
v4: recheck condition between monitor and mwait instructions
v4: write to wakeup address only once (all APs are woken up at once)
v4: make JOIN variable static as it's not read synchronously
v4: when an AP waits for a wakeup, monitor the variable that's expected to change
xen/arch/x86/boot/trampoline.S | 19 ++++++- xen/arch/x86/boot/x86_64.S | 24 ++++++++- xen/arch/x86/include/asm/intel-txt.h | 5 ++ xen/arch/x86/include/asm/processor.h | 1 + xen/arch/x86/smpboot.c | 75 ++++++++++++++++++++++++++++ xen/arch/x86/x86_64/asm-offsets.c | 3 ++ 6 files changed, 125 insertions(+), 2 deletions(-)
xen/arch/x86/boot/trampoline.S +18 -1
@@ -58,6 +58,16 @@ GLOBAL(entry_SIPI16) ljmpl $BOOT_CS32,$bootsym_rel(trampoline_protmode_entry,6) .code32 +GLOBAL(txt_ap_entry) + /* + * APs enter here in protected mode without paging. GDT is set in JOIN + * structure, it points to trampoline_gdt. Interrupts are disabled by + * TXT (including NMI and SMI), so IDT doesn't matter at this point. + * The only missing point is telling that we are AP by saving non-zero + * value in EBX. + */ + mov $1, %ebx + trampoline_protmode_entry: /* Set up a few descriptors: on entry only CS is guaranteed good. */ mov $BOOT_DS,%eax
@@ -145,7 +155,7 @@ start64: .word 0 idt_48: .word 0, 0, 0 # base = limit = 0 -trampoline_gdt: +GLOBAL(trampoline_gdt) .word 0 /* 0x0000: unused (reused for GDTR) */ gdt_48: .word .Ltrampoline_gdt_end - trampoline_gdt - 1
@@ -156,6 +166,13 @@ gdt_48: .quad 0x00cf93000000ffff /* 0x0018: ring 0 data */ .quad 0x00009b000000ffff /* 0x0020: real-mode code @ BOOT_TRAMPOLINE */ .quad 0x000093000000ffff /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */ + /* + * Intel TXT requires these two in exact order. This isn't compatible + * with the order required by syscall, so we have duplicated entries... + */ +GLOBAL(trampoline_gdt_txt) + .quad 0x00cf9b000000ffff /* 0x0030: ring 0 code, 32-bit mode */ + .quad 0x00cf93000000ffff /* 0x0038: ring 0 data */ .Ltrampoline_gdt_end: /* Relocations for trampoline Real Mode segments. */
xen/arch/x86/boot/x86_64.S +23 -1
@@ -30,7 +30,10 @@ ENTRY(__high_start) cmp %ebp, (%rcx, %rax, 4) jne 1b - /* %eax is now Xen CPU index. */ + mov %ebp, %edx + + /* %eax is now Xen CPU index, %edx is APIC ID. */ + lea stack_base(%rip), %rcx mov (%rcx, %rax, 8), %rsp
@@ -40,6 +43,25 @@ ENTRY(__high_start) 1: add $(STACK_SIZE - CPUINFO_sizeof), %rsp + /* + * TXT AP gate. + * + * In TXT boot, SINIT releases all APs at once and they race into + * __high_start in parallel. We serialize APs initialization here + * to force them waking up in order expected by the BSP. + * + * The gate must be placed before STACK_CPUINFO_FIELD(cr4) is written + * below: for each AP, the BSP memsets that AP's cpu_info struct in + * cpu_smpboot_alloc() just before releasing it through the gate, so + * anything written earlier would be clobbered. + * + * In non-TXT boot, APs wake one-by-one via SIPI. + */ + cmpl $ASM_AP_BOOT_TXT, ap_boot_method(%rip) + jne .L_after_stack_setup + mov %edx, %edi + call txt_ap_gate + .L_after_stack_setup: /* Reset EFLAGS (subsumes CLI and CLD). */
xen/arch/x86/include/asm/intel-txt.h +5 -0
@@ -83,6 +83,11 @@#define _txt (x) __va(x)#endif +extern char txt_ap_entry[]; +extern uint64_t trampoline_gdt[]; +/* Points at CS selector for TXT, DS selector follows. */ +extern uint64_t trampoline_gdt_txt[]; +/* * Always use private space as some of registers are either read-only or not * present in public space.
xen/arch/x86/include/asm/processor.h +1 -0
@@ -436,6 +436,7 @@ void set_in_pb_opt_ctrl(uint32_t mask, uint32_t val);enum ap_boot_method {AP_BOOT_NORMAL ,AP_BOOT_SKINIT , +AP_BOOT_TXT , };extern enum ap_boot_method ap_boot_method;
xen/arch/x86/smpboot.c +75 -0
117 lines not on this page · raw message
xen/arch/x86/x86_64/asm-offsets.c +3 -0
@@ -246,4 +246,7 @@ void __dummy__(void)DEFINE (SL_EIR_size,sizeof (struct slaunch_early_init_results ));BLANK ();#endif + +DEFINE (ASM_AP_BOOT_TXT ,AP_BOOT_TXT ); +BLANK (); }
Signature · 1 line
2.55.0
PATCH v4 18/23 x86/slaunch: process DRTM policy
In reply to Sergii DmytrukGo through entires in the DRTM policy of SLRT to hash and extend data that they describe into corresponding PCRs.
Addresses are being zeroed on measuring platform-specific data to prevent measurements from changing when the only thing that has changed is an address. Addresses can vary due to bootloader, firmware or user doing something differently or just if GRUB gets bigger in size due to inclusion of more modules and ends up offsetting newly allocated memory.
---
Notes:
v4: use SLR_TABLE_REVISION in slaunch_measure_slrt()
v4: don't cast away const of slr_next_entry_by_tag()
v4: use container_of()
v4: take changes of struct boot_module into account
xen/arch/x86/include/asm/slaunch.h | 14 ++ xen/arch/x86/setup.c | 15 ++ xen/arch/x86/slaunch.c | 217 +++++++++++++++++++++++++++++ 3 files changed, 246 insertions(+)
xen/arch/x86/include/asm/slaunch.h +14 -0
@@ -31,6 +31,8 @@#define DLE_EVTYPE_SLAUNCH_START (DLE_EVTYPE_BASE + 0x103)#define DLE_EVTYPE_SLAUNCH_END (DLE_EVTYPE_BASE + 0x104) +struct boot_info ; +struct slaunch_early_init_results {uint32_t mbi_pa;
@@ -67,6 +69,18 @@ void slaunch_map_mem_regions(void);/* Marks regions of memory as used to avoid their corruption. */ void slaunch_reserve_mem_regions (void ); +/* Measures essential parts of SLR table before making use of them. */ +void slaunch_measure_slrt (void ); + +/* +* Takes measurements of DRTM policy entries except for MBI and SLRT which +* should have been measured by the time this is called. Also performs sanity +* checks of the policy and panics on failure. In particular, the function +* verifies that DRTM is consistent with modules obtained from MultibootInfo +* (MBI) and written to struct boot_info in setup.c. +*/ +void slaunch_process_drtm_policy (const struct boot_info *bi); +/* * This helper function is used to map memory below 4 GiB using L2 page tables * by aligning mapped regions to 2MB. This way page allocator (which at this
xen/arch/x86/setup.c +15 -0
@@ -1473,6 +1473,13 @@ void asmlinkage __init noreturn __start_xen(void)if ( slaunch_active ) {slaunch_map_mem_regions (); + +/* +* SLRT needs to be measured here because it is used by init_e820(), the +* rest is measured slightly below by slaunch_process_drtm_policy(). +*/ +slaunch_measure_slrt (); +slaunch_reserve_mem_regions (); }
@@ -1494,6 +1501,14 @@ void asmlinkage __init noreturn __start_xen(void)/* Create a temporary copy of the E820 map. */ memcpy (&boot_e820, &e820,sizeof (e820)); +/* +* Process all yet unmeasured DRTM entries after E820 initialization to not +* do this while memory is uncached (too slow). This must also happen before +* modules are relocated or used. +*/ +if ( slaunch_active ) +slaunch_process_drtm_policy (bi); +/* Early kexec reservation (explicit static start address). */ nr_pages =0 ;for ( i =0 ; i < e820.nr_map; i++ )
xen/arch/x86/slaunch.c +217 -0
237 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 19/23 x86/acpi: disallow S3 on Secure Launch boot
In reply to Sergii DmytrukSecure Launch won't initiate DRTM on S3 resume (the code for starting DRTM is not part of Xen), so abort a request to perform S3 suspend to not lose the state of DRTM PCRs.
---
Notes:
v4: return EACCES instead of EPERM
xen/arch/x86/acpi/power.c | 8 ++++++++ 1 file changed, 8 insertions(+)
xen/arch/x86/acpi/power.c +8 -0
@@ -30,6 +30,7 @@#include <asm/microcode.h> #include <asm/mwait.h> #include <asm/prot-key.h> +#include <asm/slaunch.h> #include <asm/spec_ctrl.h> #include <asm/tboot.h> #include <asm/trampoline.h>
@@ -335,6 +336,13 @@ int acpi_enter_sleep(const struct xenpf_enter_acpi_sleep *sleep) PAGE_SIZE - acpi_sinfo.vector_width / 8)) )return -EOPNOTSUPP ; +/* Secure Launch won't initiate DRTM on S3 resume, so abort S3 suspend. */ +if ( sleep->sleep_state ==ACPI_STATE_S3 && slaunch_active ) + { +printk (XENLOG_INFO "SLAUNCH: refusing switching into ACPI S3 state.\n" ); +return -EACCES ; + } +if ( sleep->flags &XENPF_ACPI_SLEEP_EXTENDED ) { if ( !acpi_sinfo.sleep_control.address ||
Signature · 1 line
2.55.0
PATCH v4 20/23 x86/slaunch: support AMD CPUs
In reply to Sergii DmytrukHandle the state after secure-kernel-loader (SKL) in boot/head.S.
Use slr_entry_amd_info::boot_params_base on AMD with SKINIT to get MBI location.
Locate SLRT which is bootloader's data after SKL on AMD.
Measure AMD-specific data in slaunch_measure_slrt().
Find Intel-compatible TPM event log structure within vendor data of TCG-compliant event logs.
---
Notes:
v4: squashed "x86/slaunch: support AMD SKINIT" and "x86/boot/slaunch-early: find MBI and SLRT on AMD"
v4: use CONFIG_SLAUNCH
v4: update large comment in head.S
v4: define slaunch_is_amd_drtm() in a header and use twice to avoid duplication
v4: %#04x => %#x in panic("SLRT is for unexpected architecture ...")
v4: use container_of()
v4: don't drop const from the result of slr_next_entry_by_tag()
xen/arch/x86/boot/head.S | 42 ++++++++++++--- xen/arch/x86/boot/slaunch-early.c | 52 ++++++++++++++++++ xen/arch/x86/e820.c | 2 +- xen/arch/x86/include/asm/slaunch.h | 30 +++++++++++ xen/arch/x86/include/asm/tpm1.h | 15 ++++++ xen/arch/x86/slaunch-tpm.c | 26 +++++++++ xen/arch/x86/slaunch.c | 87 ++++++++++++++++++++++++------ 7 files changed, 231 insertions(+), 23 deletions(-)
xen/arch/x86/boot/head.S +36 -6
@@ -358,10 +358,14 @@ cs32_switch: #if CONFIG_SLAUNCH /* - * Entry point for TrenchBoot Secure Launch on Intel TXT platforms. + * Entry point for TrenchBoot Secure Launch, common for Intel TXT and + * AMD Secure Startup, but state is slightly different. + * + * On Intel + * -------- * * CPU is in 32b protected mode with paging disabled. On entry: - * - %ebx = %eip = MLE entry point, + * - %ebx = %eip = this entry point, * - stack pointer is undefined, * - CS is flat 4GB code segment, * - DS, ES, SS, FS and GS are undefined according to TXT SDG, but this
@@ -382,13 +386,36 @@ cs32_switch: * writing a non-zero value at a MONITORed address or via * GETSEC[WAKEUP] instruction, depending on which is supported by a * given SINIT ACM + * + * On AMD (as implemented by TrenchBoot's secure-kernel-loader or SKL) + * ------------------------------------------------------------------- + * + * CPU is in 32b protected mode with paging disabled. On entry: + * - %ebx = %eip = this entry point, + * - %ebp holds base address of SKL + * - stack pointer is treated as undefined for parity with TXT, + * - CS is flat 4GB code segment, + * - DS, ES, SS are flat 4GB data segments, but treated as undefined for + * parity with TXT. + * + * Additional restrictions: + * - interrupts (including NMIs and SMIs) are disabled and must be + * enabled later + * - APs must be brought up by SIPI without an INIT */ slaunch_stub_entry: /* Calculate the load base address. */ mov %ebx, %esi sub $sym_offs(slaunch_stub_entry), %esi - /* Mark Secure Launch boot protocol and jump to common entry. */ + /* On AMD, %ebp holds the base address of SLB, save it for later. */ + mov %ebp, %ebx + + /* + * Mark Secure Launch boot protocol and jump to common entry. Note that + * all general purpose registers except %ebx and %esi are clobbered + * between here and .Lslaunch_proto. + */ mov $SLAUNCH_BOOTLOADER_MAGIC, %eax jmp .Lset_stack #endif /* CONFIG_SLAUNCH */
@@ -524,15 +551,18 @@ __start: sub $SL_EIR_size, %esp push %esp /* pointer to output structure */ + push %ebx /* Slaunch parameter on AMD */ mov $sym_offs(__2M_rwdata_end), %ecx /* end of target image */ mov $sym_offs(_start), %edx /* target base address */ mov %esi, %eax /* load base address */ /* - * slaunch_early_init(load/eax, tgt/edx, tgt_end/ecx, ret/stk) using - * fastcall calling convention. + * slaunch_early_init(load/eax, tgt/edx, tgt_end/ecx, + * slaunch/stk, ret/stk) + * + * Uses fastcall calling convention. */ call slaunch_early_init - add $4, %esp /* pop the fourth parameter */ + add $8, %esp /* pop last two parameters */ /* Move outputs of slaunch_early_init() from the stack. */ pop %ebx /* store physical MBI address in EBX where
xen/arch/x86/boot/slaunch-early.c +52 -0
67 lines not on this page · raw message
xen/arch/x86/e820.c +1 -1
@@ -501,7 +501,7 @@ static void __init machine_specific_memory_setup(struct e820map *raw)uint64_t top_of_ram, size;unsigned int i; -if ( slaunch_active ) +if ( slaunch_active && boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL )txt_restore_mtrrs (e820_verbose);sanitize_e820_map (raw->map, &raw->nr_map);
xen/arch/x86/include/asm/slaunch.h +30 -0
@@ -17,6 +17,8 @@#include <xen/slr-table.h> #include <xen/types.h> +#include <asm/x86-vendors.h> +#define DRTM_LOC 2#define DRTM_CODE_PCR 17#define DRTM_DATA_PCR 18
@@ -56,6 +58,34 @@ static bool slaunch_active = false;*/ extern uint32_t slaunch_slrt; +#ifdef __EARLY_SLAUNCH__ + +static inline bool slaunch_is_amd_drtm (void ) +{ +/* +* asm/processor.h can't be included in early code, which means neither +* cpuid() function nor boot_cpu_data can be used here. +*/ +uint32_t eax, ebx, ecx, edx; + asmvolatile ("cpuid" + :"=a" (eax),"=b" (ebx),"=c" (ecx),"=d" (edx) + :"0" (0 ),"c" (0 ) ); +return ebx ==X86_VENDOR_AMD_EBX + && ecx ==X86_VENDOR_AMD_ECX + && edx ==X86_VENDOR_AMD_EDX ; +} + +#else /* __EARLY_SLAUNCH__ */ + +#include <asm/cpufeature.h> + +static inline bool slaunch_is_amd_drtm (void ) +{ +return boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ; +} + +#endif /* __EARLY_SLAUNCH__ */ +/* * Retrieves pointer to SLRT. Checks table's validity and maps it as necessary. */
xen/arch/x86/include/asm/tpm1.h +15 -0
@@ -76,4 +76,19 @@ struct TPM12_PCREvent { uint8_t Data[]; }; +struct tpm1_spec_id_event { +uint32_t pcrIndex; +uint32_t eventType; +uint8_t digest[20 ]; +uint32_t eventSize; +uint8_t signature[16 ]; +uint32_t platformClass; +uint8_t specVersionMinor; +uint8_t specVersionMajor; +uint8_t specErrata; +uint8_t uintnSize; +uint8_t vendorInfoSize; +uint8_t vendorInfo[0 ];/* variable number of members */ +} __packed; +#endif /* X86_TPM1_H */
xen/arch/x86/slaunch-tpm.c +26 -0
@@ -79,6 +79,16 @@ create_log_event12(struct txt_ev_log_container_12 *evt_log,if (evt_log ==NULL )return log_hashes; +if (slaunch_is_amd_drtm () ) + { +/* +* On AMD, TXT-compatible structure is stored as vendor data of +* TCG-defined event log header. +*/ +struct tpm1_spec_id_event *spec_id = (void *)evt_log; + evt_log = (struct txt_ev_log_container_12 *)&spec_id->vendorInfo[0 ]; + } + new_entry = (void *)evt_log + evt_log->NextEventOffset;/*
@@ -114,6 +124,22 @@ find_evt_log_ext_data(struct tpm2_spec_id_event *evt_log)struct txt_os_sinit_data *os_sinit;struct txt_ext_data_element *ext_data; +if (slaunch_is_amd_drtm () ) + { +/* +* Event log pointer is defined by TXT specification, but +* secure-kernel-loader provides a compatible structure in vendor data +* of the log. +*/ +uint8_t *data_size = + (uint8_t *)&evt_log->digestSizes[evt_log->digestCount]; +if ( *data_size !=sizeof (struct heap_event_log_pointer_element2_1 ) ) +return NULL ; + +/* Vendor data directly follows a single-byte size. */ +return (struct heap_event_log_pointer_element2_1 *)(data_size +1 ); + } + os_sinit =txt_start (__va (txt_read (TXTCR_HEAP_BASE )),TXT_OS2SINIT ); ext_data =txt_find_ext_data_element (os_sinit,TXT_HEAP_EXTDATA_TYPE_EVENT_LOG_POINTER2_1 );
xen/arch/x86/slaunch.c +71 -16
140 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 21/23 x86/slaunch: support EFI boot
In reply to Sergii DmytrukWhen running on an EFI-enabled system, Xen needs to have access to Boot Services in order to initialize itself properly and reach a state in which a dom0 kernel can operate without issues.
This means that DRTM must be started in the middle of Xen's initialization process. This effect is achieved via a callback into a TrenchBoot-enabled bootloader (GRUB) which is responsible for initiating DRTM and continuing Xen's initialization process. The latter is done by branching in Slaunch entry point on a flag to switch back into long mode before calling the same function which Xen would execute as the next step without DRTM.
---
Notes:
v4: -DXEN_BUILD_EFI => -DXEN_BUILD_EFI=1
v4: use CONFIG_SLAUNCH
v4: use pointers to const SLRT and TXT heap data
v4: use container_of()
v4: take updates to struct boot_module into account
v4: now UEFI_SLR_TABLE_GUID is defined here in efi/boot.c
.gitignore | 1 + .../eclair_analysis/ECLAIR/out_of_scope.ecl | 1 + docs/hypervisor-guide/x86/how-xen-boots.rst | 14 +- xen/arch/x86/Makefile | 12 +- xen/arch/x86/boot/head.S | 124 +++++++++++++++++ xen/arch/x86/boot/x86_64.S | 14 +- xen/arch/x86/efi/efi-boot.h | 94 ++++++++++++- xen/arch/x86/efi/fixmlehdr.c | 127 ++++++++++++++++++ xen/arch/x86/slaunch.c | 75 ++++++++++- xen/common/efi/boot.c | 6 + xen/common/efi/runtime.c | 1 + xen/include/xen/efi.h | 1 + 12 files changed, 455 insertions(+), 15 deletions(-) create mode 100644 xen/arch/x86/efi/fixmlehdr.c
.gitignore +1 -0
@@ -177,6 +177,7 @@ xen/.xen.elf32 xen/System.map xen/arch/x86/efi.lds xen/arch/x86/efi/check.efi +xen/arch/x86/efi/fixmlehdr xen/arch/x86/efi/mkreloc xen/arch/x86/include/asm/asm-macros.h xen/arch/*/xen.lds
automation/eclair_analysis/ECLAIR/out_of_scope.ecl +1 -0
@@ -19,6 +19,7 @@ -doc_begin="Build tools are out of scope." -file_tag+={out_of_scope_tools,"^xen/tools/.*$"} +-file_tag+={out_of_scope_tools,"^xen/arch/x86/efi/fixmlehdr\\.c$"} -file_tag+={out_of_scope_tools,"^xen/arch/x86/efi/mkreloc\\.c$"} -file_tag+={out_of_scope_tools,"^xen/arch/x86/boot/mkelf32\\.c$"} -doc_end
docs/hypervisor-guide/x86/how-xen-boots.rst +8 -6
@@ -56,12 +56,14 @@ which indicates the ability to use the PVH boot protocol, and registers ``__pvh_start`` as the entrypoint, entered in 32bit mode. A combination of Multiboot 2 and Measured Launched Environment (MLE) headers -is used to support Dynamic Root of Trust for Measurement (DRTM) for legacy -(BIOS) boot. DRTM is a way to establish hardware root of trust which -excludes firmware and is not directly tied to hardware's boot process. The -separate entry point called ``slaunch_stub_entry`` is used mainly to -differentiate from other kinds of boots. It moves a magic number to ``EAX`` -before jumping into common startup code. More details about Secure Launch +is used to support Dynamic Root of Trust for Measurement (DRTM). DRTM is a +way to establish hardware root of trust which excludes firmware and is not +directly tied to hardware's boot process. The separate entry point called +``slaunch_stub_entry`` is used mainly to differentiate from other kinds of +boots. For a legacy (BIOS) boot, it moves a magic number to ``EAX`` before +jumping into common startup code. For a EFI boot, it resumes execution of +Xen.efi which was paused by handing control to a part of a bootloader +responsible for initiating DRTM sequence. More details about Secure Launch data structures processed by Xen in this boot mode can be found in `<https://trenchboot.org/specifications/Secure_Launch/>`_.
xen/arch/x86/Makefile +11 -1
@@ -89,6 +89,7 @@ extra-y += xen.lds hostprogs-y += boot/mkelf32 hostprogs-y += efi/mkreloc +hostprogs-y += efi/fixmlehdr $(obj)/efi/mkreloc: HOSTCFLAGS += -I$(srctree)/include
@@ -123,6 +124,11 @@ $(TARGET): $(TARGET)-syms $(efi-y) $(obj)/boot/mkelf32 CFLAGS-$(XEN_BUILD_EFI) += -DXEN_BUILD_EFI +# Expose this build flag as a macro when compiling assembly files. +ifeq ($(XEN_BUILD_EFI),y) +XEN_AFLAGS += -DXEN_BUILD_EFI=1 +endif + $(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds $(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S $(MAKE) $(build)=$(@D) $(dot-target).0.o
@@ -196,7 +202,7 @@ note_file_option ?= $(note_file) extra-$(XEN_BUILD_PE) += efi.lds ifeq ($(XEN_BUILD_PE),y) $(TARGET).efi: $(obj)/efi/relocs-dummy.o $(obj)/efi/relocs-empty.o $(obj)/efi/mkreloc -$(TARGET).efi: $(objtree)/prelink.o $(note_file) $(obj)/efi.lds +$(TARGET).efi: $(objtree)/prelink.o $(note_file) $(obj)/efi.lds $(obj)/efi/fixmlehdr ifeq ($(CONFIG_DEBUG_INFO),y) $(if $(filter --strip-debug,$(EFI_LDFLAGS)),echo,:) "Will strip debug info from $(@F)" endif
@@ -230,6 +236,10 @@ endif $(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds $< $(obj)/efi/relocs-empty.o \ $(dot-target).2r.o $(dot-target).2s.o $(orphan-handling-y) \ $(note_file_option) -o $@ +ifeq ($(CONFIG_SLAUNCH),y) + # update entry point's address by taking image offset into account + $(obj)/efi/fixmlehdr $@ $(XEN_IMG_OFFSET) +endif $(NM) -pa --format=sysv $@ \ | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \ > [email protected]
xen/arch/x86/boot/head.S +124 -0
136 lines not on this page · raw message
xen/arch/x86/boot/x86_64.S +11 -3
@@ -267,14 +267,22 @@ GLOBAL(__page_tables_end) /* Init pagetables. Enough page directories to map into 4GB. */ .section .init.data.page_aligned, "aw", @progbits -DATA_LOCAL(l1_bootmap, PAGE_SIZE) +bootmap_start: + +DATA_LOCAL(l1_bootmap, PAGE_SIZE) /* 1x L1 page, mapping 2M of RAM. */ .fill L1_PAGETABLE_ENTRIES, 8, 0 END(l1_bootmap) -DATA(l2_bootmap, PAGE_SIZE) +DATA(l2_bootmap, PAGE_SIZE) /* 4x L2 pages, each mapping 1G of RAM. */ .fill 4 * L2_PAGETABLE_ENTRIES, 8, 0 END(l2_bootmap) -DATA(l3_bootmap, PAGE_SIZE) +DATA(l3_bootmap, PAGE_SIZE) /* 1x L3 page, mapping the 4x L2 pages. */ .fill L3_PAGETABLE_ENTRIES, 8, 0 END(l3_bootmap) + +DATA_LOCAL(l4_bootmap, PAGE_SIZE) /* 1x L4 page, mapping the L3 page. */ + .fill L4_PAGETABLE_ENTRIES, 8, 0 +END(l4_bootmap) + +bootmap_end:
xen/arch/x86/efi/efi-boot.h +93 -1
131 lines not on this page · raw message
xen/arch/x86/efi/fixmlehdr.c new file +127 -0
127 lines not on this page · raw message
xen/arch/x86/slaunch.c +71 -4
106 lines not on this page · raw message
xen/common/efi/boot.c +6 -0
@@ -19,6 +19,7 @@#if EFI_PAGE_SIZE !=PAGE_SIZE # error Cannot use xen/pfn.h here!#endif +#include <xen/slr-table.h> #include <xen/string.h> #include <xen/stringify.h> #ifdef CONFIG_X86
@@ -45,6 +46,8 @@#define EFI_SYSTEM_RESOURCE_TABLE_GUID \ { 0xb122a263U, 0x3661, 0x4f68, {0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80} }#define EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURCE_VERSION 1 +#define UEFI_SLR_TABLE_GUID \ + { 0x877a9b2aU, 0x0385, 0x45d1, { 0xa0, 0x34, 0x9d, 0xac, 0x9c, 0x9e, 0x56, 0x5f } } typedef struct { EFI_GUID FwClass;
@@ -1154,6 +1157,7 @@ static void __init efi_tables(void)static EFI_GUID __initdata mps_guid =MPS_TABLE_GUID ;static EFI_GUID __initdata smbios_guid =SMBIOS_TABLE_GUID ;static EFI_GUID __initdata smbios3_guid =SMBIOS3_TABLE_GUID ; +static EFI_GUID __initdata slr_guid =UEFI_SLR_TABLE_GUID ;if (match_guid (&acpi2_guid, &efi_ct[i].VendorGuid) ) efi.acpi20 = (unsigned long )efi_ct[i].VendorTable;
@@ -1165,6 +1169,8 @@ static void __init efi_tables(void) efi.smbios = (unsigned long )efi_ct[i].VendorTable;if (match_guid (&smbios3_guid, &efi_ct[i].VendorGuid) ) efi.smbios3 = (unsigned long )efi_ct[i].VendorTable; +if (match_guid (&slr_guid, &efi_ct[i].VendorGuid) ) + efi.slr = (unsigned long )efi_ct[i].VendorTable;if (match_guid (&esrt_guid, &efi_ct[i].VendorGuid) ) esrt = (UINTN )efi_ct[i].VendorTable; }
xen/common/efi/runtime.c +1 -0
@@ -72,6 +72,7 @@ struct efi __read_mostly efi = { .mps = EFI_INVALID_TABLE_ADDR, .smbios = EFI_INVALID_TABLE_ADDR, .smbios3 = EFI_INVALID_TABLE_ADDR, + .slr = EFI_INVALID_TABLE_ADDR, };const struct efi_pci_rom *__read_mostly efi_pci_roms;
xen/include/xen/efi.h +1 -0
@@ -17,6 +17,7 @@ struct efi {unsigned long acpi20;/* ACPI table (ACPI 2.0) */ unsigned long smbios;/* SM BIOS table */ unsigned long smbios3;/* SMBIOS v3 table */ +unsigned long slr;/* SLR table */ };extern struct efi efi;
Signature · 1 line
2.55.0
Re: [PATCH v4 21/23] x86/slaunch: support EFI boot
Quoted 73 lines · Sergii Dmytruk
When running on an EFI-enabled system, Xen needs to have access to Boot Services in order to initialize itself properly and reach a state in which a dom0 kernel can operate without issues.
This means that DRTM must be started in the middle of Xen's initialization process. This effect is achieved via a callback into a TrenchBoot-enabled bootloader (GRUB) which is responsible for initiating DRTM and continuing Xen's initialization process. The latter is done by branching in Slaunch entry point on a flag to switch back into long mode before calling the same function which Xen would execute as the next step without DRTM.
Signed-off-by Krystian Hebel <[email protected]>Signed-off-by Sergii Dmytruk <[email protected]>---
Notes:
v4: -DXEN_BUILD_EFI => -DXEN_BUILD_EFI=1
v4: useCONFIG_SLAUNCH
v4: use pointers toconstSLRT and TXT heap data
v4: usecontainer_of()
v4: take updates tostruct boot_moduleinto account
v4: nowUEFI_SLR_TABLE_GUIDis defined here inefi/boot.c.gitignore | 1 + .../eclair_analysis/ECLAIR/out_of_scope.ecl | 1 + docs/hypervisor-guide/x86/how-xen-boots.rst | 14 +- xen/arch/x86/Makefile | 12 +- xen/arch/x86/boot/head.S | 124 +++++++++++++++++ xen/arch/x86/boot/x86_64.S | 14 +- xen/arch/x86/efi/efi-boot.h | 94 ++++++++++++- xen/arch/x86/efi/fixmlehdr.c | 127 ++++++++++++++++++ xen/arch/x86/slaunch.c | 75 ++++++++++- xen/common/efi/boot.c | 6 + xen/common/efi/runtime.c | 1 + xen/include/xen/efi.h | 1 + 12 files changed, 455 insertions(+), 15 deletions(-) create mode 100644 xen/arch/x86/efi/fixmlehdr.cxen/arch/x86/Makefile +7
-1@@ -89,6 +89,7 @@ extra-y += xen.lds hostprogs-y += boot/mkelf32 hostprogs-y += efi/mkreloc +hostprogs-y += efi/fixmlehdr $(obj)/efi/mkreloc: HOSTCFLAGS += -I$(srctree)/include@@ -123,6 +124,11 @@ $(TARGET): $(TARGET)-syms $(efi-y) $(obj)/boot/mkelf32 CFLAGS-$(XEN_BUILD_EFI) += -DXEN_BUILD_EFI +# Expose this build flag as a macro when compiling assembly files. +ifeq ($(XEN_BUILD_EFI),y) +XEN_AFLAGS += -DXEN_BUILD_EFI=1 +endif + $(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds $(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S $(MAKE) $(build)=$(@D) $(dot-target).0.o@@ -196,7 +202,7 @@ note_file_option ?= $(note_file) extra-$(XEN_BUILD_PE) += efi.lds ifeq ($(XEN_BUILD_PE),y) $(TARGET).efi: $(obj)/efi/relocs-dummy.o $(obj)/efi/relocs-empty.o $(obj)/efi/mkreloc -$(TARGET).efi: $(objtree)/prelink.o $(note_file) $(obj)/efi.lds +$(TARGET).efi: $(objtree)/prelink.o $(note_file) $(obj)/efi.lds $(obj)/efi/fixmlehdr ifeq ($(CONFIG_DEBUG_INFO),y) $(if $(filter --strip-debug,$(EFI_LDFLAGS)),echo,:) "Will strip debug info from $(@F)" endif
xen/arch/x86/Makefile endif · line 245
Quoted 10 lines
xen/arch/x86/Makefile +4
-0@@ -230,6 +236,10 @@ endif $(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds $< $(obj)/efi/relocs-empty.o \ $(dot-target).2r.o $(dot-target).2s.o $(orphan-handling-y) \ $(note_file_option) -o $@ +ifeq ($(CONFIG_SLAUNCH),y) + # update entry point's address by taking image offset into account + $(obj)/efi/fixmlehdr $@ $(XEN_IMG_OFFSET) +endif $(NM) -pa --format=sysv $@ \ | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \ > [email protected]
This has collided completely with changes to how we link Xen.
Also, as a general rule we don't like post-processing the binary like this. What's the real problem trying to be solved? Is it really just the address in one field of the MLE header? If so, why can't this be fixed by adding the offset at build time?
~Andrew
PATCH v4 22/23 xen/arch/x86: add TPR (TXT Protected Range) DMA protection support
In reply to Sergii DmytrukFrom: Szymon Acedański <[email protected]>
Pointer to txt_os_sinit_data variables lost constness due to the use of txt_find_ext_data_element() which needs to work in a non-const context as well for its other use.
This is required for modern Intel CPUs (at least LunarLake) that no longer support PMR (Protected Memory Regions) protection mechanism. Unlike PMR, TPR is not related to Intel VT-d, independent from IOMMU and, despite its name, is not tied to TXT.
The next generation (PantherLake) similarly supports only PMR but seems to have an undocumented requirement that TPR protection must be disabled or device initialization fails (NVMe/USB/NIC). This is not done by this patch.
---
Notes:
v4: new commit in this version, needed for modern devices
xen/arch/x86/boot/head.S | 4 +- xen/arch/x86/boot/slaunch-early.c | 6 +- xen/arch/x86/efi/efi-boot.h | 7 +- xen/arch/x86/include/asm/intel-txt.h | 182 +++++++++++++++++++++------ 4 files changed, 151 insertions(+), 48 deletions(-)
xen/arch/x86/boot/head.S +2 -2
@@ -136,12 +136,12 @@ SYM(mle_header, DATA, LOCAL, 16) .long 0xa2555c0f /* UUID2 */ .long 0x42b651cb /* UUID3 */ .long (.Lmle_header_end - mle_header) /* MLE header size */ - .long 0x00020002 /* MLE version 2.2 */ + .long 0x00020003 /* MLE version 2.3 */ .long (slaunch_stub_entry - start) /* Linear entry point of MLE (SINIT virt. address) */ .long 0x00000000 /* First valid page of MLE */ .long 0x00000000 /* Offset within binary of first byte of MLE */ .long (__base_relocs_end - start) /* Offset within binary of last byte + 1 of MLE */ - .long 0x00000723 /* Bit vector of MLE-supported capabilities */ + .long 0x00004723 /* Bit vector of MLE-supported capabilities */ .long 0x00000000 /* Starting linear address of command line (unused) */ .long 0x00000000 /* Ending linear address of command line (unused) */ .Lmle_header_end:
xen/arch/x86/boot/slaunch-early.c +3 -3
@@ -35,7 +35,7 @@ void asmlinkage slaunch_early_init(uint32_t load_base_addr,void *txt_heap;const struct txt_os_mle_data *os_mle;const struct slr_table *slrt; -const struct txt_os_sinit_data *os_sinit; +struct txt_os_sinit_data *os_sinit;const struct slr_entry_hdr *entry;const struct slr_entry_intel_info *intel_info;uint32_t size = tgt_end_addr - tgt_base_addr;
@@ -99,6 +99,6 @@ void asmlinkage slaunch_early_init(uint32_t load_base_addr, result->mbi_pa = intel_info->boot_params_base; -txt_verify_pmr_ranges (os_mle, os_sinit, intel_info, - load_base_addr, tgt_base_addr, size); +txt_verify_dma_protection (os_mle, os_sinit, intel_info, + load_base_addr, tgt_base_addr, size); }
xen/arch/x86/efi/efi-boot.h +4 -3
@@ -261,11 +261,12 @@ void __init asmlinkage noreturn start_xen_from_efi(void)void *txt_heap =txt_init ();const struct txt_os_mle_data *os_mle =txt_start (txt_heap,TXT_OS2MLE ); -const struct txt_os_sinit_data *os_sinit = +struct txt_os_sinit_data *os_sinit =txt_start (txt_heap,TXT_OS2SINIT ); -txt_verify_pmr_ranges (os_mle, os_sinit, intel_info, xen_phys_start, - xen_phys_start, xen_image_size); +txt_verify_dma_protection (os_mle, os_sinit, intel_info, + xen_phys_start, xen_phys_start, + xen_image_size); } }
xen/arch/x86/include/asm/intel-txt.h +142 -40
249 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v4 23/23 MAINTAINERS: add a section for TrenchBoot Slaunch
In reply to Sergii Dmytruk---
Notes:
v4: updated list of files to match this patchset
MAINTAINERS | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
MAINTAINERS +19 -0
@@ -565,6 +565,25 @@ F: */configure F: */*.ac F: tools/ +TRENCHBOOT SECURE LAUNCH +R: Daniel P. Smith <[email protected]> +R: Ross Philipson <[email protected]> +R: Sergii Dmytruk <[email protected]> +S: Supported +F: xen/arch/x86/boot/slaunch-early.c +F: xen/arch/x86/efi/fixmlehdr.c +F: xen/arch/x86/include/asm/intel-txt.h +F: xen/arch/x86/include/asm/slaunch-tpm.h +F: xen/arch/x86/include/asm/slaunch.h +F: xen/arch/x86/include/asm/tpm.h +F: xen/arch/x86/include/asm/tpm1.h +F: xen/arch/x86/include/asm/tpm2.h +F: xen/arch/x86/intel-txt.c +F: xen/arch/x86/slaunch-tpm.c +F: xen/arch/x86/slaunch.c +F: xen/arch/x86/tpm.c +F: xen/include/xen/slr-table.h + VM EVENT, MEM ACCESS and MONITOR M: Tamas K Lengyel <[email protected]> S: Supported
Signature · 1 line
2.55.0