Enable TDX module extensions
Subsystems (3)
v2 cover Enable TDX module extensions
Hi,
This is the first respin of the TDX module extensions series. Thank you all for the design discussion and architectural review. Hope the design could be settled and some more RBs got in this version.
Dave please feel free to ignore. Kiryl, Rick and TDX developers, please help take a look.
== Changes ==
A major change is that the add-on feature re-configuration and extensions re-initialization operations during runtime update have been dropped. IOW, the update flow is left untouched. This stems from the architectural discussion that the basic update flow should start with a simple functional requirement - just restore everything (for example, the add-on features re-enabling, TDH.EXT.INIT) that was configured during boot, no extra input from the host is needed. Do improvement later if any new requirement arise.
The extensions consume tens of megabytes memory that will never be returned to the host. How to consume this amount of memory forever is an open question though v1 uses alloc_contig_pages() for memory de-fragmentation. Kiryl implied fragmentation is an important concern. He answered that de-fragmentation is to prevent 2M pageblocks from being partially occupied. alloc_contig_pages() can be more than needed but should be good enough when we do it once during the boot time. In patch 4, keep the alloc_contig_pages() but add a code comment for clarification.
Dave asked why pass the addon_features0 around as a function parameter, it can always be return from the global, static get_tdx_addon_features0() helper. Yilun admitted this is redundant. In patch 2, change to call the helper a second time where the value is needed.
Rick pointed out that in patch 1, the changelog said we introduced a kernel data type for TDMR info PA array argument but the code is still setting TDX ABI data type (u64) for PAs. He suggested justifying that this is to avoid duplicating allocations and copies in SEAMCALL wrappers. Yilun noted this is a general in-memory ABI pattern which exists in several places in TDX. Add the statement of in-memory ABI handling in the changelog.
Other changes:
- Patch 2: Drop the changelog section explaining why add-on feature enabling is needed in this series, as it is a generally understood pattern (Rick)
- Patch 2: Add a note in the changelog that Dynamic PAMT is not enabled via the new bitmap argument of TDH.SYS.CONFIG (Rick)
- Patch 4: Add code comments for hpa_list container page allocation
(Kiryl)
- Patch 4: s/PFN array/HPA array in changelog (Kiryl)
- Patch 4: State the alternative memory adding solution and why we don't use it in changelog (Rick)
v1: https://lore.kernel.org/all/[email protected]/
Quoting v2: https://lore.kernel.org/lkml/[email protected]/
Quoting v1: https://lore.kernel.org/all/[email protected]/
== Overview ==
To date, SEAMCALL execution must either complete quickly to avoid stalling the host, or yield quickly at pre-defined interrupt checkpoints. This is acceptable for the existing SEAMCALL leafs, which perform simple, bounded operations.
However, some new features such as attestation and TD migration require higher level security protocols inside the TDX module, which cannot fit within that constraint. TDX solves this by making those operations inherently preemptible and resumable like OS tasks. TDX provides a separate SEAMCALL execution environment - the TDX module extensions - for those operations.
This capability allows for higher-level SEAMCALL ABI design - like "create a DICE-based attestation quote". Several new features, such as DICE-based attestation, TDISP and TD migration, use SEAMCALL leafs backed by the TDX module extensions.
The TDX module extensions need memory for their execution environment to serve these SEAMCALL leafs, so they need extra setup steps during TDX module initialization. The bulk of this series implements these setup steps.
At runtime, the host invokes these SEAMCALL leafs just as normal ones - if interrupted, simply re-invoke the leaf to resume.
For more information on TDX module extensions, please refer to [1].
[1] https://lore.kernel.org/lkml/[email protected]/
== Branch stack ==
This is based on v7.3-rc1. You can find the full branch stack at [2]. The DICE part is in the full branch as an example for extensions. But it does not include the other DICE feedbacks.
The full branch contains:
Dependency: Patch 1: SEAMCALL version patch [3] which is WIP on
community review.
This series: Patch 2~7: This series, including this cover-letter.
Use case: Patch 8~N: The old DICE part as an example.
[2] https://github.com/intel-staging/tdx/tree/tdx-module-ext
[3] https://lore.kernel.org/all/[email protected]/
Xu Yilun (5):
x86/virt/tdx: Move TDH.SYS.CONFIG operations into a wrapper x86/virt/tdx: Configure add-on features on TDX module init x86/virt/tdx: Detect if the extensions initialization is required x86/virt/tdx: Add extra memory to TDX module for the extensions x86/virt/tdx: Make TDX module initialize the extensions
arch/x86/include/asm/tdx.h | 1 + arch/x86/include/asm/tdx_global_metadata.h | 6 + arch/x86/virt/vmx/tdx/tdx.h | 2 + arch/x86/virt/vmx/tdx/tdx.c | 230 +++++++++++++++++++- arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 20 ++ 5 files changed, 252 insertions(+), 7 deletions(-)
base-commit: 3bfade11ab7be0a90eecc8a549b181863960b14e
Signature · 1 line
2.25.1
PATCH v2 1/5 x86/virt/tdx: Move TDH.SYS.CONFIG operations into a wrapper
In Linux, SEAMCALL wrappers are introduced to avoid broad SEAMCALL access by exposing only a selection of SEAMCALL leafs, but also to abstract the SEAMCALL register ABIs. The latter improves readability and reuse for SEAMCALL leafs that are called multiple times.
Some SEAMCALL leafs are not explicitly wrapped because the level of TDX ABI details needed to perform the call is low enough to flow well with the calling code.
For some of the currently unwrapped SEAMCALL leafs, TDX architecture adjusts the ABI and adds SEAMCALL version selection for backward compatibility. Future kernel will need to support the changes. This will leak more ABI details into the surrounding caller code and decrease readability of the other logic. To keep the ABI details contained, move the SEAMCALL leafs that will need version selection into wrappers.
The cleanest separation would be to have kernel data types for the SEAMCALL wrapper arguments, and have them marshaled into SEAMCALL leaf ABI types (often u64s) inside the wrapper. This works for many SEAMCALL leafs but becomes cumbersome when the register ABI type is a physical address which points to a buffer for an in-memory ABI. If the SEAMCALL wrapper only accepts kernel data types, it may need duplicate buffer allocation and copies to match the in-memory ABI. Another solution is to define a named helper structure that mirrors the in-memory ABI, populate it in a separate flow, then pass it to the SEAMCALL wrapper. struct seamldr_params is an existing example of this pattern.
TDH.SYS.CONFIG requires a list of TDMR information in the form of a PA array. The PA array is the in-memory ABI. Create a structure for the PA array, use it as the argument when creating the wrapper for TDH.SYS.CONFIG.
---
v2:
- Remove TDH.SYS.UPDATE wrapper (Dave & Rick)
- Talk about the handling of in-memory ABIs for SEAMCALL wrappers (Rick)
- Refactor the entire changelog according to Rick's suggestion (Rick)
- Add code comment for struct tdmr_info_pa_array (AI nitpicker)
- Use kernel data type for nr_tdmr_pa parameter (AI nitpicker)
v1:
- This patch is split out from the last series (Rick)
--- arch/x86/virt/vmx/tdx/tdx.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-)
arch/x86/virt/vmx/tdx/tdx.c +27 -7
@@ -998,11 +998,33 @@ static __init int construct_tdmrs(struct list_head *tmb_list,return ret; } +/* +* This is an array of HPAs, each points to a TDMR_INFO data structure (see +* struct tdmr_info). +* +* It is the in-memory ABI that the kernel passes to the TDX module to specify +* the ranges of TD Memory Regions (TDMRs) and their associated PAMT memory. +*/ +struct tdmr_info_pa_array { + DECLARE_FLEX_ARRAY(u64, phys); +}; + +static __init int tdx_sys_config (struct tdmr_info_pa_array *tdmr_pa_array, +unsigned int nr_tdmr_pa,u64 global_keyid) +{ +struct tdx_module_args args = { + .rcx =__pa (tdmr_pa_array), + .rdx = nr_tdmr_pa, + .r8 = global_keyid, + }; + +return seamcall_prerr (TDH_SYS_CONFIG , &args); +} +static __init int config_tdx_module (struct tdmr_info_list *tdmr_list,u64 global_keyid) { -struct tdx_module_args args = {}; -u64 *tdmr_pa_array; +struct tdmr_info_pa_array *tdmr_pa_array;size_t array_sz;int i, ret;
@@ -1021,12 +1043,10 @@ static __init int config_tdx_module(struct tdmr_info_list *tdmr_list,return -ENOMEM ;for (i =0 ; i < tdmr_list->nr_consumed_tdmrs; i++) - tdmr_pa_array[i] =__pa (tdmr_entry (tdmr_list, i)); + tdmr_pa_array->phys[i] =__pa (tdmr_entry (tdmr_list, i)); - args.rcx =__pa (tdmr_pa_array); - args.rdx = tdmr_list->nr_consumed_tdmrs; - args.r8 = global_keyid; - ret =seamcall_prerr (TDH_SYS_CONFIG , &args); + ret =tdx_sys_config (tdmr_pa_array, tdmr_list->nr_consumed_tdmrs, + global_keyid);/* Free the array as it is not required anymore. */ kfree (tdmr_pa_array);
Signature · 1 line
2.25.1
Edgecombe, Rick P
maintainerRe: [PATCH v2 1/5] x86/virt/tdx: Move TDH.SYS.CONFIG operations into a wrapper
Quoted 8 lines · Xu Yilun
In Linux, SEAMCALL wrappers are introduced to avoid broad SEAMCALL access by exposing only a selection of SEAMCALL leafs, but also to abstract the SEAMCALL register ABIs.
The latter improves readability and
reuse for SEAMCALL leafs that are called multiple times.
I'm trying to adjust to not using former/latter. The feedback I've seen is that it is too much to remember as you read along. How about:
The abstraction improves...
Quoted 3 lines
Some SEAMCALL leafs are not explicitly wrapped because the level of TDX ABI details needed to perform the call is low enough to flow well with
^are
Quoted 6 lines
the calling code.
For some of the currently unwrapped SEAMCALL leafs, TDX architecture adjusts the ABI and adds SEAMCALL version selection for backward compatibility.
Reads a little weird to me. Like I'm not sure when this adjusting is happening. How about:
..., the TDX architecture has evolved the ABI to introduce new versions of existing SEAMCALLs. VMM code can select the version to call based on what is supported by the loaded TDX module.
Quoted 2 lines
Future kernel will need to support the changes.
?? I guess you mean selecting between SEAMCALL versions?
Quoted 8 lines
This will
leak more ABI details into the surrounding caller code and decrease readability of the other logic. To keep the ABI details contained, move the SEAMCALL leafs that will need version selection into wrappers.The cleanest separation would be to have kernel data types for the SEAMCALL wrapper arguments,
This is now talking about general seamcall wrapper design. It could read like it's instead talking about clean separation of SEAMCALL versions?
Quoted 73 lines
and have them marshaled into SEAMCALL leaf
ABI types (often u64s) inside the wrapper. This works for many SEAMCALL leafs but becomes cumbersome when the register ABI type is a physical address which points to a buffer for an in-memory ABI. If the SEAMCALL wrapper only accepts kernel data types, it may need duplicate buffer allocation and copies to match the in-memory ABI. Another solution is to define a named helper structure that mirrors the in-memory ABI, populate it in a separate flow, then pass it to the SEAMCALL wrapper. structseamldr_paramsis an existing example of this pattern.TDH.SYS.CONFIG requires a list of TDMR information in the form of a PA array. The PA array is the in-memory ABI. Create a structure for the PA array, use it as the argument when creating the wrapper for TDH.SYS.CONFIG.
Signed-off-by Xu Yilun <[email protected]>Reviewed-by Nikolay Borisov <[email protected]>---
v2:
- Remove TDH.SYS.UPDATE wrapper (Dave & Rick)
- Talk about the handling of in-memory ABIs for SEAMCALL wrappers (Rick)
- Refactor the entire changelog according to Rick's suggestion (Rick)
- Add code comment for structtdmr_info_pa_array(AI nitpicker)
- Use kernel data type fornr_tdmr_paparameter (AI nitpicker)v1:
- This patch is split out from the last series (Rick)
---
arch/x86/virt/vmx/tdx/tdx.c | 34 +++++++++++++++++++++++++++-------1 file changed, 27 insertions(+), 7 deletions(-)arch/x86/virt/vmx/tdx/tdx.c +0
-0@@ -998,11 +998,33 @@ static __init int construct_tdmrs(struct list_head *tmb_list, return ret; }arch/x86/virt/vmx/tdx/tdx.c +23
-0+/* +* This is an array of HPAs, each points to a TDMR_INFO data structure (see +* struct tdmr_info). +* +* It is the in-memory ABI that the kernel passes to the TDX module to specify +* the ranges of TD Memory Regions (TDMRs) and their associated PAMT memory. +*/ +struct tdmr_info_pa_array { + DECLARE_FLEX_ARRAY(u64, phys); +}; + +static __init int tdx_sys_config (struct tdmr_info_pa_array *tdmr_pa_array, +unsigned int nr_tdmr_pa,u64 global_keyid) +{ +struct tdx_module_args args = { + .rcx =__pa (tdmr_pa_array), + .rdx = nr_tdmr_pa, + .r8 = global_keyid, + }; + +return seamcall_prerr (TDH_SYS_CONFIG , &args); +} +static
__initintconfig_tdx_module(struct tdmr_info_list *tdmr_list, u64 global_keyid)
{arch/x86/virt/vmx/tdx/tdx.c +1
-2-struct tdx_module_args args = {}; -u64 *tdmr_pa_array; +struct tdmr_info_pa_array *tdmr_pa_array;
size_tarray_sz;
int i, ret;
arch/x86/virt/vmx/tdx/tdx.c static __init int config_tdx_module(struct tdmr_info_list *tdmr_list, · line 1043
Quoted 1 line
arch/x86/virt/vmx/tdx/tdx.c +0
-0@@ -1021,12 +1043,10 @@ static __init int config_tdx_module(struct tdmr_info_list *tdmr_list, return -ENOMEM;
Outside the diff it has:array_sz = tdmr_list->nr_consumed_tdmrs * sizeof(u64);
Could be now changed to:array_sz = tdmr_list->nr_consumed_tdmrs * sizeof(*tdmr_pa_array->phys);
A bit of existing cleanup, but the u64 is especially tucked away compared to before, so I'd argue its maintaining readability of the existing code.
Quoted 16 lines
for (i = 0; i <tdmr_list->nr_consumed_tdmrs; i++)arch/x86/virt/vmx/tdx/tdx.c +1
-1- tdmr_pa_array[i] =__pa (tdmr_entry (tdmr_list, i)); + tdmr_pa_array->phys[i] =__pa (tdmr_entry (tdmr_list, i));arch/x86/virt/vmx/tdx/tdx.c +2
-4- args.rcx =__pa (tdmr_pa_array); - args.rdx = tdmr_list->nr_consumed_tdmrs; - args.r8 = global_keyid; - ret =seamcall_prerr (TDH_SYS_CONFIG , &args); + ret =tdx_sys_config (tdmr_pa_array, tdmr_list->nr_consumed_tdmrs, + global_keyid);
/* Free the array as it is not required anymore. */kfree(tdmr_pa_array);
--
2.25.1
Re: [PATCH v2 1/5] x86/virt/tdx: Move TDH.SYS.CONFIG operations into a wrapper
Quoted 7 lines · Rick P
Quoted 4 lines · Xu Yilun
In Linux, SEAMCALL wrappers are introduced to avoid broad SEAMCALL access by exposing only a selection of SEAMCALL leafs, but also to abstract the SEAMCALL register ABIs.
Quoted 6 lines
Quoted 2 lines
The latter improves readability and
reuse for SEAMCALL leafs that are called multiple times.I'm trying to adjust to not using former/latter. The feedback I've seen is that it is too much to remember as you read along. How about:
The abstraction improves...
Yes.
Quoted 5 lines
Quoted 4 lines
Some SEAMCALL leafs are not explicitly wrapped because the level of TDX ABI details needed to perform the call is low enough to flow well with
^are
the level ... is low enough, seems "is" is the right one? AI also prefers "is".
Quoted 7 lines
Quoted 6 lines
the calling code.
For some of the currently unwrapped SEAMCALL leafs, TDX architecture adjusts the ABI and adds SEAMCALL version selection for backward compatibility.
Quoted 6 lines
Reads a little weird to me. Like I'm not sure when this adjusting is happening. How about:
..., the TDX architecture has evolved the ABI to introduce new versions of existing SEAMCALLs. VMM code can select the version to call based on what is supported by the loaded TDX module.
good to me.
Quoted 5 lines
Quoted 3 lines
Future kernel will need to support the changes.
?? I guess you mean selecting between SEAMCALL versions?
Yes. I refactored the whole paragraph:
For some of the currently unwrapped SEAMCALL leafs, the TDX architecture has evolved the ABI to introduce new leaf versions. The host can select the version to call based on what is supported by the loaded TDX module. When future kernel implements this version selection, more ABI details will leak into the surrounding caller code, which decreases the readability of the caller logic. To keep the ABI details contained, move the SEAMCALL leaf that will need version selection into a wrapper.
Quoted 6 lines
Quoted 6 lines
This will
leak more ABI details into the surrounding caller code and decrease readability of the other logic. To keep the ABI details contained, move the SEAMCALL leafs that will need version selection into wrappers.
Quoted 6 lines
Quoted 3 lines
The cleanest separation would be to have kernel data types for the SEAMCALL wrapper arguments,
This is now talking about general seamcall wrapper design. It could read like it's instead talking about clean separation of SEAMCALL versions?
OK, the transition is not good here.
When defining the wrapper, the cleanest separation would be...
[...]
Quoted 5 lines
Outside the diff it has:
array_sz=tdmr_list->nr_consumed_tdmrs* sizeof(u64);Could be now changed to:
array_sz=tdmr_list->nr_consumed_tdmrs*sizeof(*tdmr_pa_array->phys);
Good to me. I tweaked it a bit on my preference:
array_sz = tdmr_list->nr_consumed_tdmrs * sizeof(tdmr_pa_array->phys[0]);
Quoted 3 lines
A bit of existing cleanup, but the u64 is especially tucked away compared to before, so I'd argue its maintaining readability of the existing code.
Re: [PATCH v2 1/5] x86/virt/tdx: Move TDH.SYS.CONFIG operations into a wrapper
In reply to Xu YilunQuoted 6 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +0
-0@@ -998,11 +998,33 @@ static __init int construct_tdmrs(struct list_head *tmb_list,return ret; }
arch/x86/virt/vmx/tdx/tdx.c static __init int construct_tdmrs(struct list_head *tmb_list, · line 1010
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+/* +* This is an array of HPAs, each points to a TDMR_INFO data structure (see +* struct tdmr_info). +* +* It is the in-memory ABI that the kernel passes to the TDX module to specify +* the ranges of TD Memory Regions (TDMRs) and their associated PAMT memory. +*/ +struct tdmr_info_pa_array { + DECLARE_FLEX_ARRAY(u64, phys); +};
I think you can simplify the comments above a bit, how about:
TDX module in-memory ABI to specify the TD Memory Regions (TDMRs) and their associated PAMT memory. An array of HPAs. Each element points to a TDMR_INFO, see struct tdmr_info.
Other than that:
PATCH v2 2/5 x86/virt/tdx: Configure add-on features on TDX module init
In reply to Xu YilunThe TDX architecture identifies some features that are off by default but can be enabled by the host during TDX module initialization. They are classified as add-on features because enabling them affects existing TDX systems: they may change existing feature behavior, or reserve more memory.
The TDX module extends TDH.SYS.CONFIG with a new register argument to specify which add-on features to enable. This new argument is a bitmap that uses the same feature bits as TDX_FEATURES0. Note that Dynamic PAMT is an exception: although it is an add-on feature, it is controlled via a legacy, dedicated register argument [1].
The kernel needs to enable these add-on features when it supports them. Add a get_tdx_addon_features0() helper to return the bitmap of the add-on features that the module & kernel both support. Initially, this helper returns 0. It will be updated to return specific feature bits as full kernel support lands. Pass this extra bitmap to TDH.SYS.CONFIG wrapper.
The TDX module requires SEAMCALL leaf version 1 for TDH.SYS.CONFIG when passing the new bitmap argument. A previous change [2] supports the versioned SEAMCALL leafs by adding a "version" field in struct tdx_module_args. Set the version field to 1 if the new bitmap argument is used to enable any add-on feature, otherwise keep the version as 0. This retains backward compatibility with older modules that don't recognize version 1.
---
v2:
- Don't pass addon_features0 parameter around, get it in the wrappers (Dave)
- Remove TDH.SYS.UPDATE wrapper (Dave & Rick)
- Drop the changelog section explaining why add-on feature enabling is needed in this series, as it is a generally understood pattern (Rick)
- Add a note in the changelog that Dynamic PAMT is not enabled via the new bitmap argument (Rick)
- Add __init tag for get_tdx_addon_features0() (AI nitpicker)
v1:
- Use tdx_module_args.version to assign SEAMCALL leaf versions (Dave)
- Remove DICE specific descriptions (Rick)
- Remove the global var tdx_addon_features0 (Chao)
- Add a Macro to collect kernel supported add-on feature bits (Rick)
- Changelog & code comments change
--- arch/x86/virt/vmx/tdx/tdx.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
arch/x86/virt/vmx/tdx/tdx.c +19 -0
@@ -998,6 +998,15 @@ static __init int construct_tdmrs(struct list_head *tmb_list,return ret; } +/* List all kernel supported add-on features0 bits here */ +#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) + +static __init u64 get_tdx_addon_features0 (void ) +{ +return tdx_sysinfo.features.tdx_features0 & +TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 ; +} +/* * This is an array of HPAs, each points to a TDMR_INFO data structure (see * struct tdmr_info).
@@ -1012,12 +1021,22 @@ struct tdmr_info_pa_array {static __init int tdx_sys_config (struct tdmr_info_pa_array *tdmr_pa_array,unsigned int nr_tdmr_pa,u64 global_keyid) { +u64 addon_features0 =get_tdx_addon_features0 ();struct tdx_module_args args = { .rcx =__pa (tdmr_pa_array), .rdx = nr_tdmr_pa, .r8 = global_keyid, }; +/* +* Use SEAMCALL version 1 that supports add-on features if any are +* requested. Otherwise use version 0 for backward compatibility. +*/ +if (addon_features0) { + args.r9 = addon_features0; + args.version =1 ; + } +return seamcall_prerr (TDH_SYS_CONFIG , &args); }
Signature · 1 line
2.25.1
Edgecombe, Rick P
maintainerRe: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
arch/x86/virt/vmx/tdx/tdx.c struct tdmr_info_pa_array { · line 1029
Quoted 10 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +1
-0@@ -1012,12 +1021,22 @@ struct tdmr_info_pa_array { static __init int tdx_sys_config(struct tdmr_info_pa_array *tdmr_pa_array, unsigned int nr_tdmr_pa, u64 global_keyid) { +u64 addon_features0 =get_tdx_addon_features0 (); struct tdx_module_args args = { .rcx = __pa(tdmr_pa_array), .rdx = nr_tdmr_pa, .r8 = global_keyid, };
It seems inconsistent that global_keyid is passed in even though it is basically global state, while addon_features0 is retrieved from the global state. Passing the result of get_tdx_addon_features0() in from the caller doesn't make a ton of sense. And we already reference tdx_global_keyid globally from another seamcall wrapper. So I'd think dropping the arg when you create the wrapper would be best in the end.
The smallest change to stay consistent would be go add an addon_features0 arg to tdx_sys_config(), but it's hard to justify as good code. I'd maybe go with the global_keyid change and it probably is a separate patch, but we are brushing up against mixing cleanup and feature enabling... thoughts?
Quoted 12 lines
arch/x86/virt/vmx/tdx/tdx.c +9
-0+/* +* Use SEAMCALL version 1 that supports add-on features if any are +* requested. Otherwise use version 0 for backward compatibility. +*/ +if (addon_features0) { + args.r9 = addon_features0; + args.version =1 ; + } +return
seamcall_prerr(TDH_SYS_CONFIG, &args); }
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
Quoted 19 lines · Rick P
arch/x86/virt/vmx/tdx/tdx.c struct tdmr_info_pa_array { · line 1029
Quoted 10 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +1
-0@@ -1012,12 +1021,22 @@ struct tdmr_info_pa_array { static __init int tdx_sys_config(struct tdmr_info_pa_array *tdmr_pa_array, unsigned int nr_tdmr_pa, u64 global_keyid) { +u64 addon_features0 =get_tdx_addon_features0 (); struct tdx_module_args args = { .rcx = __pa(tdmr_pa_array), .rdx = nr_tdmr_pa, .r8 = global_keyid, };It seems inconsistent that
global_keyidis passed in even though it is basically global state, whileaddon_features0is retrieved from the global state. Passing the result ofget_tdx_addon_features0()in from the caller doesn't make a ton of sense. And we already referencetdx_global_keyidglobally from another seamcall wrapper. So I'd think dropping the arg when you create the wrapper would be best in the end.
Quoted 4 lines
The smallest change to stay consistent would be go add an
addon_features0arg totdx_sys_config(), but it's hard to justify as good code. I'd maybe go with theglobal_keyidchange and it probably is a separate patch, but we are brushing up against mixing cleanup and feature enabling... thoughts?
I'm not sure. My thought would be removing "u64 global_keyid" argument for the new added tdx_sys_config(), to make this patch reasonable.
And the cleaning up of its caller - config_tdx_module() - could be in a separate cleanup patch out of this series, make sense?
make W=1 doesn't complain, but maybe shashiko will.
Quoted 15 lines
Quoted 14 lines
arch/x86/virt/vmx/tdx/tdx.c +9
-0+/* +* Use SEAMCALL version 1 that supports add-on features if any are +* requested. Otherwise use version 0 for backward compatibility. +*/ +if (addon_features0) { + args.r9 = addon_features0; + args.version =1 ; + } +return
seamcall_prerr(TDH_SYS_CONFIG, &args); }
Edgecombe, Rick P
maintainerRe: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
Quoted 7 lines · Xu Yilun
Quoted 7 lines
It seems inconsistent that
global_keyidis passed in even though it is basically global state, whileaddon_features0is retrieved from the global state. Passing the result ofget_tdx_addon_features0()in from the caller doesn't make a ton of sense. And we already referencetdx_global_keyidglobally from another seamcall wrapper. So I'd think dropping the arg when you create the wrapper would be best in the end.
Quoted 7 lines
Quoted 4 lines
The smallest change to stay consistent would be go add an
addon_features0arg totdx_sys_config(), but it's hard to justify as good code. I'd maybe go with theglobal_keyidchange and it probably is a separate patch, but we are brushing up against mixing cleanup and feature enabling... thoughts?I'm not sure. My thought would be removing "u64
global_keyid" argument for the new addedtdx_sys_config(), to make this patch reasonable.
Ok.
Quoted 3 lines
And the cleaning up of its caller -
config_tdx_module()- could be in a separate cleanup patch out of this series, make sense?
Hmm, I'm not sure about that. I'd think you would need one patch to remove global_keyid arg and use the global reference. That stands on its own.
Another patch to extract the helper. BTW, since the goal of this series is to get acked, I'd think the cleanup patches could still go ahead.
Quoted 2 lines
make W=1 doesn't complain, but maybe shashiko will.
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
Quoted 19 lines · Rick P
Quoted 7 lines · Xu Yilun
Quoted 7 lines
It seems inconsistent that
global_keyidis passed in even though it is basically global state, whileaddon_features0is retrieved from the global state. Passing the result ofget_tdx_addon_features0()in from the caller doesn't make a ton of sense. And we already referencetdx_global_keyidglobally from another seamcall wrapper. So I'd think dropping the arg when you create the wrapper would be best in the end.Quoted 7 lines
Quoted 4 lines
The smallest change to stay consistent would be go add an
addon_features0arg totdx_sys_config(), but it's hard to justify as good code. I'd maybe go with theglobal_keyidchange and it probably is a separate patch, but we are brushing up against mixing cleanup and feature enabling... thoughts?I'm not sure. My thought would be removing "u64
global_keyid" argument for the new addedtdx_sys_config(), to make this patch reasonable.Ok.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
And the cleaning up of its caller -
config_tdx_module()- could be in a separate cleanup patch out of this series, make sense?Hmm, I'm not sure about that. I'd think you would need one patch to remove
global_keyidarg and use the global reference. That stands on its own.Another patch to extract the helper. BTW, since the goal of this series is to get acked, I'd think the cleanup patches could still go ahead.
Per the discussion [1], I'll leave the global_keyid unchanged. It's good to pass the value of a global var around, to show we are not modifying it.
Thanks for connecting the 2 discussions.
[1]: https://lore.kernel.org/lkml/[email protected]/
Quoted 5 lines
Quoted 3 lines
make W=1 doesn't complain, but maybe shashiko will.
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
In reply to Xu YilunQuoted 12 lines · Xu Yilun
The TDX architecture identifies some features that are off by default but can be enabled by the host during TDX module initialization. They are classified as add-on features because enabling them affects existing TDX systems: they may change existing feature behavior, or reserve more memory.
The TDX module extends TDH.SYS.CONFIG with a new register argument to specify which add-on features to enable. This new argument is a bitmap that uses the same feature bits as
TDX_FEATURES0. Note that Dynamic PAMT is an exception: although it is an add-on feature, it is controlled via a legacy, dedicated register argument [1].
Quoted 5 lines
The kernel needs to enable these add-on features when it supports them. Add a
get_tdx_addon_features0()helper to return the bitmap of the add-on features that the module & kernel both support. Initially, this helper returns 0. It will be updated to return specific feature bits as full kernel support lands. Pass this extra bitmap to TDH.SYS.CONFIG wrapper.
The last sentence is stale: the bitmap is no longer passed to the wrapper.
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
Quoted 13 lines · Chao Gao
Quoted 12 lines · Xu Yilun
The TDX architecture identifies some features that are off by default but can be enabled by the host during TDX module initialization. They are classified as add-on features because enabling them affects existing TDX systems: they may change existing feature behavior, or reserve more memory.
The TDX module extends TDH.SYS.CONFIG with a new register argument to specify which add-on features to enable. This new argument is a bitmap that uses the same feature bits as
TDX_FEATURES0. Note that Dynamic PAMT is an exception: although it is an add-on feature, it is controlled via a legacy, dedicated register argument [1].
Quoted 7 lines
Quoted 5 lines
The kernel needs to enable these add-on features when it supports them. Add a
get_tdx_addon_features0()helper to return the bitmap of the add-on features that the module & kernel both support. Initially, this helper returns 0. It will be updated to return specific feature bits as full kernel support lands. Pass this extra bitmap to TDH.SYS.CONFIG wrapper.The last sentence is stale: the bitmap is no longer passed to the wrapper.
Good catch.
Pass this bitmap as an argument to TDH.SYS.CONFIG.
Thanks.
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
In reply to Xu YilunQuoted 4 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +0
-0@@ -998,6 +998,15 @@ static __init int construct_tdmrs(struct list_head *tmb_list,return ret;
arch/x86/virt/vmx/tdx/tdx.c static __init int construct_tdmrs(struct list_head *tmb_list, · line 1008
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +8
-0} +/* List all kernel supported add-on features0 bits here */ +#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) + +static __init u64 get_tdx_addon_features0 (void ) +{ +return tdx_sysinfo.features.tdx_features0 & +TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 ; +}
How about get_tdx_supported_addon_features() for the above? It makes the calling code a bit more readable without having to figure out what it returns.
Other than that:
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
Quoted 7 lines · Tony Lindgren
Quoted 6 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +0
-0@@ -998,6 +998,15 @@ static __init int construct_tdmrs(struct list_head *tmb_list,return ret; }
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c static __init int construct_tdmrs(struct list_head *tmb_list, · line 1008
Quoted 8 lines
arch/x86/virt/vmx/tdx/tdx.c +8
-0+/* List all kernel supported add-on features0 bits here */ +#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) + +static __init u64 get_tdx_addon_features0 (void ) +{ +return tdx_sysinfo.features.tdx_features0 & +TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 ; +}How about
get_tdx_supported_addon_features()for the above? It makes the
mm.. I think this would make a bit confusion. "tdx_supported" reads like the module supported features, which is just .tdx_features0. But here we want both the module & kernel support. I'm thinking of:
get_tdx_addon_features0(), just as is
or
tdx_get_supported_addon_features0(), maybe this is better?
Quoted 6 lines
calling code a bit more readable without having to figure out what it returns.
Other than that:
Reviewed-by Tony Lindgren <[email protected]>
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
Quoted 23 lines · Xu Yilun
Quoted 7 lines · Tony Lindgren
Quoted 6 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +0
-0@@ -998,6 +998,15 @@ static __init int construct_tdmrs(struct list_head *tmb_list,return ret; }Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c static __init int construct_tdmrs(struct list_head *tmb_list, · line 1008
Quoted 8 lines
arch/x86/virt/vmx/tdx/tdx.c +8
-0+/* List all kernel supported add-on features0 bits here */ +#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) + +static __init u64 get_tdx_addon_features0 (void ) +{ +return tdx_sysinfo.features.tdx_features0 & +TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 ; +}How about
get_tdx_supported_addon_features()for the above? It makes themm.. I think this would make a bit confusion. "
tdx_supported" reads like the module supported features, which is just .tdx_features0. But here we want both the module & kernel support. I'm thinking of:
Quoted 5 lines
get_tdx_addon_features0(), just as isor
tdx_get_supported_addon_features0(), maybe this is better?
Something to describe it's masked with Linux supported features would be nicest.
Maybe something like get_tdx_masked_features0() or just get_tdx_usable_features0()?
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
Quoted 28 lines · Tony Lindgren
Quoted 27 lines · Xu Yilun
Quoted 7 lines · Tony Lindgren
Quoted 6 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +0
-0@@ -998,6 +998,15 @@ static __init int construct_tdmrs(struct list_head *tmb_list,return ret; }Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c static __init int construct_tdmrs(struct list_head *tmb_list, · line 1008
Quoted 8 lines
arch/x86/virt/vmx/tdx/tdx.c +8
-0+/* List all kernel supported add-on features0 bits here */ +#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) + +static __init u64 get_tdx_addon_features0 (void ) +{ +return tdx_sysinfo.features.tdx_features0 & +TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 ; +}How about
get_tdx_supported_addon_features()for the above? It makes themm.. I think this would make a bit confusion. "
tdx_supported" reads like the module supported features, which is just .tdx_features0. But here we want both the module & kernel support. I'm thinking of:
get_tdx_addon_features0(), just as isor
Quoted 7 lines
Quoted 1 line
tdx_get_supported_addon_features0(), maybe this is better?Something to describe it's masked with Linux supported features would be nicest.
Maybe something like
get_tdx_masked_features0()or justget_tdx_usable_features0()?
I like "usable", and I want to keep "addon", not all usable features are listed here:
get_tdx_usable_addon_features0()
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
Quoted 34 lines · Xu Yilun
Quoted 33 lines · Tony Lindgren
Quoted 23 lines · Xu Yilun
Quoted 7 lines · Tony Lindgren
Quoted 6 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +0
-0@@ -998,6 +998,15 @@ static __init int construct_tdmrs(struct list_head *tmb_list,return ret; }Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c static __init int construct_tdmrs(struct list_head *tmb_list, · line 1008
Quoted 8 lines
arch/x86/virt/vmx/tdx/tdx.c +8
-0+/* List all kernel supported add-on features0 bits here */ +#define TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 (0) + +static __init u64 get_tdx_addon_features0 (void ) +{ +return tdx_sysinfo.features.tdx_features0 & +TDX_KERNEL_SUPPORTED_ADDON_FEATURES0 ; +}How about
get_tdx_supported_addon_features()for the above? It makes themm.. I think this would make a bit confusion. "
tdx_supported" reads like the module supported features, which is just .tdx_features0. But here we want both the module & kernel support. I'm thinking of:Quoted 5 lines
get_tdx_addon_features0(), just as isor
tdx_get_supported_addon_features0(), maybe this is better?Something to describe it's masked with Linux supported features would be nicest.
Quoted 7 lines
Quoted 2 lines
Maybe something like
get_tdx_masked_features0()or justget_tdx_usable_features0()?I like "usable", and I want to keep "addon", not all usable features are listed here:
get_tdx_usable_addon_features0()
Sounds good to me.
Re: [PATCH v2 2/5] x86/virt/tdx: Configure add-on features on TDX module init
In reply to Xu YilunQuoted 26 lines · Xu Yilun
The TDX architecture identifies some features that are off by default but can be enabled by the host during TDX module initialization. They are classified as add-on features because enabling them affects existing TDX systems: they may change existing feature behavior, or reserve more memory.
The TDX module extends TDH.SYS.CONFIG with a new register argument to specify which add-on features to enable. This new argument is a bitmap that uses the same feature bits as
TDX_FEATURES0. Note that Dynamic PAMT is an exception: although it is an add-on feature, it is controlled via a legacy, dedicated register argument [1].The kernel needs to enable these add-on features when it supports them. Add a
get_tdx_addon_features0()helper to return the bitmap of the add-on features that the module & kernel both support. Initially, this helper returns 0. It will be updated to return specific feature bits as full kernel support lands. Pass this extra bitmap to TDH.SYS.CONFIG wrapper.The TDX module requires SEAMCALL leaf version 1 for TDH.SYS.CONFIG when passing the new bitmap argument. A previous change [2] supports the versioned SEAMCALL leafs by adding a "version" field in struct
tdx_module_args. Set the version field to 1 if the new bitmap argument is used to enable any add-on feature, otherwise keep the version as 0. This retains backward compatibility with older modules that don't recognize version 1.
Quoted 3 lines
Signed-off-by Xu Yilun <[email protected]>
PATCH v2 3/5 x86/virt/tdx: Detect if the extensions initialization is required
In reply to Xu YilunSome add-on features require TDX module extensions. The TDX module provides a metadata field "ext_required" to indicate this requirement.
Add the first step of TDX module extensions initialization by detecting if the extensions are required:
1. Check if the extensions are supported via TDX_FEATURES0_EXT. If not, ext_required is not readable.
2. Check if any TDX feature needs the extensions via ext_required.
Skip the extensions initialization when it is not required.
Currently all metadata fields are read at the very beginning of TDX module initialization. However, ext_required is only valid after the add-on feature configuration, so it cannot use the existing metadata reading method.
Add a dedicated metadata reading interface for the extensions, call it after add-on feature configuration.
---
v1:
- Include struct tdx_sys_info_ext in struct tdx_sys_info.
--- arch/x86/include/asm/tdx.h | 1 + arch/x86/include/asm/tdx_global_metadata.h | 5 ++++ arch/x86/virt/vmx/tdx/tdx.c | 28 +++++++++++++++++++++ arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 14 +++++++++++ 4 files changed, 48 insertions(+)
arch/x86/include/asm/tdx.h +1 -0
@@ -36,6 +36,7 @@/* Bit definitions of TDX_FEATURES0 metadata field */ #define TDX_FEATURES0_TD_PRESERVING BIT_ULL(1)#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18) +#define TDX_FEATURES0_EXT BIT_ULL(39)#ifndef __ASSEMBLER__
arch/x86/include/asm/tdx_global_metadata.h +5 -0
@@ -44,12 +44,17 @@ struct tdx_sys_info_handoff { u16 module_hv; }; +struct tdx_sys_info_ext { +bool ext_required; +}; +struct tdx_sys_info {struct tdx_sys_info_version version;struct tdx_sys_info_features features;struct tdx_sys_info_tdmr tdmr;struct tdx_sys_info_td_ctrl td_ctrl;struct tdx_sys_info_td_conf td_conf; +struct tdx_sys_info_ext ext; };#endif
arch/x86/virt/vmx/tdx/tdx.c +28 -0
@@ -1181,6 +1181,30 @@ static __init int init_tdmrs(struct tdmr_info_list *tdmr_list)return 0 ; } +static __init int init_tdx_module_extensions (void ) +{ +int ret; + +if (!(tdx_sysinfo.features.tdx_features0 &TDX_FEATURES0_EXT )) +return 0 ; + + ret =get_tdx_sys_info_ext (&tdx_sysinfo.ext); +if (ret) +return ret; + +/* +* ext_required indicates if any add-on features requiring TDX module +* extensions are configured via TDH.SYS.CONFIG. If none, skip the +* initialization. +*/ +if (!tdx_sysinfo.ext.ext_required) +return 0 ; + +/* TODO: add the extensions enabling steps here */ + +return 0 ; +} +static __init int init_tdx_module (void ) {int ret;
@@ -1235,6 +1259,10 @@ static __init int init_tdx_module(void)if (ret) goto err_reset_pamts; + ret =init_tdx_module_extensions (); +if (ret) + goto err_reset_pamts; +pr_info ("%lu KB allocated for PAMT\n" ,tdmrs_count_pamt_kb (&tdx_tdmr_list)); out_put_tdxmem:
arch/x86/virt/vmx/tdx/tdx_global_metadata.c +14 -0
@@ -131,3 +131,17 @@ static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo)return ret; } + +static __init int get_tdx_sys_info_ext (struct tdx_sys_info_ext *sysinfo_ext) +{ +int ret; +u64 val; + + ret =read_sys_metadata_field (0x3100000000000001 , &val); +if (ret) +return ret; + + sysinfo_ext->ext_required = val; + +return 0 ; +}
Signature · 1 line
2.25.1
Edgecombe, Rick P
maintainerRe: [PATCH v2 3/5] x86/virt/tdx: Detect if the extensions initialization is required
Quoted 82 lines · Xu Yilun
Some add-on features require TDX module extensions. The TDX module provides a metadata field "
ext_required" to indicate this requirement.Add the first step of TDX module extensions initialization by detecting if the extensions are required:
1. Check if the extensions are supported via
TDX_FEATURES0_EXT. If not,ext_requiredis not readable.
2. Check if any TDX feature needs the extensions viaext_required.Skip the extensions initialization when it is not required.
Currently all metadata fields are read at the very beginning of TDX module initialization. However,
ext_requiredis only valid after the add-on feature configuration, so it cannot use the existing metadata reading method.Add a dedicated metadata reading interface for the extensions, call it after add-on feature configuration.
Signed-off-by Xu Yilun <[email protected]>Reviewed-by Tony Lindgren <[email protected]>---
v1:
- Include structtdx_sys_info_extin structtdx_sys_info.--- arch/x86/include/asm/tdx.h | 1 + arch/x86/include/asm/tdx_global_metadata.h | 5 ++++ arch/x86/virt/vmx/tdx/tdx.c | 28 +++++++++++++++++++++ arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 14 +++++++++++ 4 files changed, 48 insertions(+)arch/x86/include/asm/tdx.h +1
-0@@ -36,6 +36,7 @@/* Bit definitions of TDX_FEATURES0 metadata field */ #define TDX_FEATURES0_TD_PRESERVING BIT_ULL(1)#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18) +#define TDX_FEATURES0_EXT BIT_ULL(39)#ifndef __ASSEMBLER__arch/x86/include/asm/tdx_global_metadata.h +5
-0@@ -44,12 +44,17 @@ struct tdx_sys_info_handoff { u16 module_hv; }; +struct tdx_sys_info_ext { +bool ext_required; +}; +struct tdx_sys_info {struct tdx_sys_info_version version;struct tdx_sys_info_features features;struct tdx_sys_info_tdmr tdmr;struct tdx_sys_info_td_ctrl td_ctrl;struct tdx_sys_info_td_conf td_conf; +struct tdx_sys_info_ext ext; };#endif arch/x86/virt/vmx/tdx/tdx.c +8
-0@@ -1181,6 +1181,30 @@ static __init int init_tdmrs(struct tdmr_info_list *tdmr_list)return 0 ; } +static __init int init_tdx_module_extensions (void ) +{ +int ret; + +if (!(tdx_sysinfo.features.tdx_features0 &TDX_FEATURES0_EXT )) +return 0 ; + + ret =get_tdx_sys_info_ext (&tdx_sysinfo.ext);
arch/x86/virt/vmx/tdx/tdx.c static __init int init_tdmrs(struct tdmr_info_list *tdmr_list) · line 1201
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+if (ret) +return ret; + +/* +* ext_required indicates if any add-on features requiring TDX module +* extensions are configured via TDH.SYS.CONFIG. If none, skip the +* initialization. +*/ +if (!tdx_sysinfo.ext.ext_required) +return 0 ;
Hmm, now that we don't need to do this on update, we don't need to save ext.ext_required metadata.
Also, per:
https://lore.kernel.org/all/aox8DgpnSnhZRfCv@yilunxu-OptiPlex-7050/
the reason we even need to check anything is because TDH_EXT_INIT returns a strange error code TDX_EXT_MEMORY_POOL_REQUIRED. In the case of a TDX module that supports extensions, but none that the kernel knows about... what if TDH_EXT_INIT returned SUCCESS meaning that all requested extensions (0 of them) are initialized.
AFAICT the specs don't describe what to do in this situation. But does describe SUCCESS as a possible error code. And TDX_EXT_MEMORY_POOL_REQUIRED is wrong. So its probably the most sensible bug fix anyway.
Then basically this patch goes away? We still check TDX_FEATURES0_EXT, but it can be squashed into the other one?
Quoted 42 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+ +/* TODO: add the extensions enabling steps here */ + +return 0 ; +} +static __init int init_tdx_module (void ) {int ret;@@ -1235,6 +1259,10 @@ static __init int init_tdx_module(void)if (ret) goto err_reset_pamts; + ret =init_tdx_module_extensions (); +if (ret) + goto err_reset_pamts; +pr_info ("%lu KB allocated for PAMT\n" ,tdmrs_count_pamt_kb (&tdx_tdmr_list)); out_put_tdxmem:arch/x86/virt/vmx/tdx/tdx_global_metadata.c +14
-0@@ -131,3 +131,17 @@ static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo)return ret; } + +static __init int get_tdx_sys_info_ext (struct tdx_sys_info_ext *sysinfo_ext) +{ +int ret; +u64 val; + + ret =read_sys_metadata_field (0x3100000000000001 , &val); +if (ret) +return ret; + + sysinfo_ext->ext_required = val; + +return 0 ; +}
Re: [PATCH v2 3/5] x86/virt/tdx: Detect if the extensions initialization is required
Quoted 13 lines
Quoted 13 lines
arch/x86/virt/vmx/tdx/tdx.c +13
-0+static __init int init_tdx_module_extensions (void ) +{ +int ret; + +if (!(tdx_sysinfo.features.tdx_features0 &TDX_FEATURES0_EXT )) +return 0 ; + + ret =get_tdx_sys_info_ext (&tdx_sysinfo.ext); +if (ret) +return ret; + +/* +* ext_required indicates if any add-on features requiring TDX module
Quoted 8 lines
arch/x86/virt/vmx/tdx/tdx.c static __init int init_tdmrs(struct tdmr_info_list *tdmr_list) · line 1201
Quoted 5 lines
arch/x86/virt/vmx/tdx/tdx.c +5
-0+* extensions are configured via TDH.SYS.CONFIG. If none, skip the +* initialization. +*/ +if (!tdx_sysinfo.ext.ext_required) +return 0 ;Hmm, now that we don't need to do this on update, we don't need to save ext.ext_required metadata.
Good to me.
Quoted 9 lines
Also, per:
https://lore.kernel.org/all/aox8DgpnSnhZRfCv@yilunxu-OptiPlex-7050/
the reason we even need to check anything is becauseTDH_EXT_INITreturns a strange error codeTDX_EXT_MEMORY_POOL_REQUIRED. In the case of a TDX module that supports extensions, but none that the kernel knows about... what ifTDH_EXT_INITreturned SUCCESS meaning that all requested extensions (0 of them) are initialized.
Quoted 3 lines
AFAICT the specs don't describe what to do in this situation. But does describe SUCCESS as a possible error code. And
TDX_EXT_MEMORY_POOL_REQUIREDis wrong. So its probably the most sensible bug fix anyway.
I raised to the module team, and they will fix it.
Quoted 3 lines
Then basically this patch goes away? We still check
TDX_FEATURES0_EXT, but it can be squashed into the other one?
Good to me.
Edgecombe, Rick P
maintainerRe: [PATCH v2 3/5] x86/virt/tdx: Detect if the extensions initialization is required
In reply to Edgecombe, Rick PQuoted 1 line · Rick Edgecombe
now that we don't need to do this on update
Per an off-list discussion, we agreed to not have TDH.SYS.UPDATE do the TDH.EXT.INIT work internally so that another VMM can have more flexibility. So we now need to go back to something like we had in v1 where it is called after update. But given the change in error codes for TDH.EXT.INIT, I think we still don't need to save the ext_required metadata field? We can just call it unconditionally, right? So it should still be a bit simpler than v1.
Re: [PATCH v2 3/5] x86/virt/tdx: Detect if the extensions initialization is required
Quoted 9 lines · Rick P
Quoted 1 line · Rick Edgecombe
now that we don't need to do this on update
Per an off-list discussion, we agreed to not have TDH.SYS.UPDATE do the TDH.EXT.INIT work internally so that another VMM can have more flexibility. So we now need to go back to something like we had in v1 where it is called after update. But given the change in error codes for TDH.EXT.INIT, I think we still don't need to save the
ext_requiredmetadata field? We can just call it unconditionally, right?
right.
Quoted 1 line
So it should still be a bit simpler than v1.
Another thing is about the addon_features0 argument for TDH.SYS.UPDATE. In v1 -> v2, in order to meet the goal of "just restore everything that was configured during boot", this bitmap argument is removed. I think this argument removal is orthogonal to the TDH.EXT.INIT discussion and still has merit.
TDH.SYS.UPDATE(v0): TDX module reconfigures same features as specified by
TDH.SYS.CONFIG, Linux would use this SEAMCALL version.
TDH.SYS.UPDATE(v1, addon_featues0): VMM can configure new features specified
by addon_features0 argument. For other VMM.
Then we can just add one patch based on v2 series:
----8<----
x86/virt/tdx: Re-initialize the extensions on runtime TDX module update
xxxxx
arch/x86/virt/vmx/tdx/tdx.c +18 -1
@@ -1309,7 +1309,7 @@ static __init int tdx_ext_mem_setup(void)return ret; } -static __init int tdx_ext_init (void ) +static int tdx_ext_init (void ) {struct tdx_module_args args = {};u64 ret;
@@ -1340,6 +1340,19 @@ static __init int init_tdx_module_extensions(void)return tdx_ext_init (); } +/* +* Don't update the memory requirement or try memory allocation in +* stop_machine(). If an incompatible update requires more memory, let the +* extensions re-initialization fail. +*/ +static int reinit_tdx_module_extensions (void ) +{ +if (!(tdx_sysinfo.features.tdx_features0 &TDX_FEATURES0_EXT )) +return 0 ; + +return tdx_ext_init (); +} +static __init int init_tdx_module (void ) {int ret;
@@ -1517,6 +1530,10 @@ int tdx_module_run_update(void)if (ret)return ret; + ret =reinit_tdx_module_extensions (); +if (ret) +return ret; + ret =get_tdx_sys_info_version (&tdx_sysinfo.version);/* * Only fails if there is something unexpected
Edgecombe, Rick P
maintainerRe: [PATCH v2 3/5] x86/virt/tdx: Detect if the extensions initialization is required
Quoted 6 lines · Xu Yilun
Another thing is about the
addon_features0argument for TDH.SYS.UPDATE. In v1 -> v2, in order to meet the goal of "just restore everything that was configured during boot", this bitmap argument is removed. I think this argument removal is orthogonal to the TDH.EXT.INIT discussion and still has merit.
Quoted 8 lines
TDH.SYS.UPDATE(v0): TDX module reconfigures same features as specified by
TDH.SYS.CONFIG, Linux would use this SEAMCALL version.
TDH.SYS.UPDATE(v1, addon_featues0): VMM can configure new features specified
byaddon_features0argument. For other
VMM.Then we can just add one patch based on v2 series:
Yea that seems like a good way to do this.
Some of the nuance that was extracted was that there is a difference between update and changing configuration. For example TDH.QUOTE.INIT was considered reconfiguration because it generates a new key. Similarly, changing which add- ons are enabled seems like reconfiguration. So it could be a separate knob.
Let's follow up internally with the TDX folks to clarify that we don't want to pass addon bits into update. And see if anyone yells. I'm not sure the previous discussion covered this case.
Re: [PATCH v2 3/5] x86/virt/tdx: Detect if the extensions initialization is required
In reply to Xu YilunQuoted 82 lines · Xu Yilun
Some add-on features require TDX module extensions. The TDX module provides a metadata field "
ext_required" to indicate this requirement.Add the first step of TDX module extensions initialization by detecting if the extensions are required:
1. Check if the extensions are supported via
TDX_FEATURES0_EXT. If not,ext_requiredis not readable.
2. Check if any TDX feature needs the extensions viaext_required.Skip the extensions initialization when it is not required.
Currently all metadata fields are read at the very beginning of TDX module initialization. However,
ext_requiredis only valid after the add-on feature configuration, so it cannot use the existing metadata reading method.Add a dedicated metadata reading interface for the extensions, call it after add-on feature configuration.
Signed-off-by Xu Yilun <[email protected]>Reviewed-by Tony Lindgren <[email protected]>---
v1:
- Include structtdx_sys_info_extin structtdx_sys_info.--- arch/x86/include/asm/tdx.h | 1 + arch/x86/include/asm/tdx_global_metadata.h | 5 ++++ arch/x86/virt/vmx/tdx/tdx.c | 28 +++++++++++++++++++++ arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 14 +++++++++++ 4 files changed, 48 insertions(+)arch/x86/include/asm/tdx.h +1
-0@@ -36,6 +36,7 @@/* Bit definitions of TDX_FEATURES0 metadata field */ #define TDX_FEATURES0_TD_PRESERVING BIT_ULL(1)#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18) +#define TDX_FEATURES0_EXT BIT_ULL(39)#ifndef __ASSEMBLER__arch/x86/include/asm/tdx_global_metadata.h +5
-0@@ -44,12 +44,17 @@ struct tdx_sys_info_handoff { u16 module_hv; }; +struct tdx_sys_info_ext { +bool ext_required; +}; +struct tdx_sys_info {struct tdx_sys_info_version version;struct tdx_sys_info_features features;struct tdx_sys_info_tdmr tdmr;struct tdx_sys_info_td_ctrl td_ctrl;struct tdx_sys_info_td_conf td_conf; +struct tdx_sys_info_ext ext; };#endif arch/x86/virt/vmx/tdx/tdx.c +8
-0@@ -1181,6 +1181,30 @@ static __init int init_tdmrs(struct tdmr_info_list *tdmr_list)return 0 ; } +static __init int init_tdx_module_extensions (void ) +{ +int ret; + +if (!(tdx_sysinfo.features.tdx_features0 &TDX_FEATURES0_EXT )) +return 0 ; + + ret =get_tdx_sys_info_ext (&tdx_sysinfo.ext);
arch/x86/virt/vmx/tdx/tdx.c static __init int init_tdmrs(struct tdmr_info_list *tdmr_list) · line 1201
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+if (ret) +return ret; + +/* +* ext_required indicates if any add-on features requiring TDX module +* extensions are configured via TDH.SYS.CONFIG. If none, skip the +* initialization. +*/ +if (!tdx_sysinfo.ext.ext_required) +return 0 ;
I'm slightly confused by the parlance introduced here. TDX_FEATURES0_EXT indicates whether this tdx module supports extensions. And ext_required aka 0x3100000000000001 is, as per td_scope_metadata.json: "Extended Features Available Mask: indicates the extended user and system features which are available for the TD." So aren't by definition all add-on features extensions. How do you distinguish add-on which are extensions and those which aren't? I think it's best if ext_required is referred to as "ext_mask" or some such and not ext_required. That value is not about what is required but rather what is available, no ?
<snip>
Re: [PATCH v2 3/5] x86/virt/tdx: Detect if the extensions initialization is required
Quoted 94 lines · Nikolay Borisov
Quoted 77 lines · Xu Yilun
Some add-on features require TDX module extensions. The TDX module provides a metadata field "
ext_required" to indicate this requirement.Add the first step of TDX module extensions initialization by detecting if the extensions are required:
1. Check if the extensions are supported via
TDX_FEATURES0_EXT. If not,ext_requiredis not readable.
2. Check if any TDX feature needs the extensions viaext_required.Skip the extensions initialization when it is not required.
Currently all metadata fields are read at the very beginning of TDX module initialization. However,
ext_requiredis only valid after the add-on feature configuration, so it cannot use the existing metadata reading method.Add a dedicated metadata reading interface for the extensions, call it after add-on feature configuration.
Signed-off-by Xu Yilun <[email protected]>Reviewed-by Tony Lindgren <[email protected]>---
v1:
- Include structtdx_sys_info_extin structtdx_sys_info.--- arch/x86/include/asm/tdx.h | 1 + arch/x86/include/asm/tdx_global_metadata.h | 5 ++++ arch/x86/virt/vmx/tdx/tdx.c | 28 +++++++++++++++++++++ arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 14 +++++++++++ 4 files changed, 48 insertions(+)arch/x86/include/asm/tdx.h +1
-0@@ -36,6 +36,7 @@/* Bit definitions of TDX_FEATURES0 metadata field */ #define TDX_FEATURES0_TD_PRESERVING BIT_ULL(1)#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18) +#define TDX_FEATURES0_EXT BIT_ULL(39)#ifndef __ASSEMBLER__arch/x86/include/asm/tdx_global_metadata.h +5
-0@@ -44,12 +44,17 @@ struct tdx_sys_info_handoff { u16 module_hv; }; +struct tdx_sys_info_ext { +bool ext_required; +}; +struct tdx_sys_info {struct tdx_sys_info_version version;struct tdx_sys_info_features features;struct tdx_sys_info_tdmr tdmr;struct tdx_sys_info_td_ctrl td_ctrl;struct tdx_sys_info_td_conf td_conf; +struct tdx_sys_info_ext ext; };#endif arch/x86/virt/vmx/tdx/tdx.c +8
-0@@ -1181,6 +1181,30 @@ static __init int init_tdmrs(struct tdmr_info_list *tdmr_list)return 0 ; } +static __init int init_tdx_module_extensions (void ) +{ +int ret; + +if (!(tdx_sysinfo.features.tdx_features0 &TDX_FEATURES0_EXT )) +return 0 ; + + ret =get_tdx_sys_info_ext (&tdx_sysinfo.ext);arch/x86/virt/vmx/tdx/tdx.c static __init int init_tdmrs(struct tdmr_info_list *tdmr_list) · line 1200
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+if (ret) +return ret; + +/* +* ext_required indicates if any add-on features requiring TDX module +* extensions are configured via TDH.SYS.CONFIG. If none, skip the +* initialization. +*/ +if (!tdx_sysinfo.ext.ext_required) +return 0 ;I'm slightly confused by the parlance introduced here.
TDX_FEATURES0_EXTindicates whether this tdx module supports extensions.
Quoted 5 lines
And
ext_requiredaka0x3100000000000001is, as per td_scope_metadata.json: "Extended Features Available Mask: indicates the extended user and system features which are available for the TD." So aren't by definition all add-on features extensions.
I checked the latest json files [1]. I think there is misreading somehow.
ext_required - 0x3100000000000001 is in global_metadata.json: "Return true if the TDH.EXT.INIT is required to be called".
And what you've read is:
XFAM - 0x1110000300000001 - td_scope_metadata.json: "Extended Features Available Mask: indicates the extended user and system features which are available for the TD."
[1] https://cdrdv2.intel.com/v1/dl/getContent/795381
Quoted 2 lines
How do you distinguish add-on which are extensions and those which aren't?
In general TDX initialization phase, the host doesn't have to tell. The TDX module knows which features are backed by extensions then decide whether the extensions initialization is needed according to which features host wants to enable.
According to TDX module ABI spec, now there are 5 add-on feature bits:TDX_CONNECT, QUOTE, MIG_SETUP which need the extensions; NON_BLOCKING_EXPORT, TDID_VMID_REPORTING which not need.
So for example:
TDH.SYS.CONFIG(QUOTE | TDX_CONNECT | NON_BLOCKING_EXPORT) => ext_required == 1
TDH.SYS.CONFIG(NON_BLOCKING_EXPORT | TDID_VMID_REPORTING) => ext_required == 0
Note that tdx module updates the ext_required after TDH.SYS.CONFIG, so it is about what is required.
BTW: we've discussed that ext_required reading is not necessary [2], just make TDH.EXT.INIT return SUCCESS if extensions are not required.
[2] https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
I think it's best if
ext_requiredis referred to as "ext_mask" or some such and notext_required. That value is not about what is required but rather what is available, no ?<snip>
PATCH v2 4/5 x86/virt/tdx: Add extra memory to TDX module for the extensions
In reply to Xu YilunTDX module extensions need memory for their execution environment to serve SEAMCALL leafs. The TDX architecture implements the extensions in such a way that they use the memory outside of SEAM range, so the kernel should add the memory upfront at initialization time.
Introduce a new memory adding process backed by a new SEAMCALL leaf TDH.EXT.MEM.ADD. The kernel queries TDX module how much memory needed, allocates it, add it to the module, and never gets it back.
The TDX module accepts the memory in the form of an HPA array. This array is passed via a single 64-bit SEAMCALL leaf parameter, which encodes two values: the PFN of the container page holding the array, and the number of entries in the array. Create a helper to encode this format and name it after the TDX module term: HPA_LIST_INFO.
TDX module extensions consume tens of megabytes memory that will never be returned to the host. Use contiguous page allocation to isolate these large blocks entirely. This is a simple way to avoid permanent memory
fragmentation: requiring the full size to be contiguous is more expensive than needed but should be good during the boot time. Print the allocation amount on TDX module extensions initialization for visibility.
---
An alternative solution is to use a loop that gives memory on a memory error code - TDX_EXT_MEMORY_POOL_REQUIRED, add one page per iteration until TDH.EXT.INIT succeeds. Something like:
do {
ret = tdh_sys_init();
if (ret == TDX_EXT_MEMORY_POOL_REQUIRED)
tdh_ext_mem_add(); //single page
} while (ret == TDX_EXT_MEMORY_POOL_REQUIRED);This approach is slightly simpler as we don't have to query the module for the total memory, no memory pre-allocation or segmentation math. But allocating a single 4K page per iteration may cause permanent memory fragmentation.
v2:
- Add code comments for container page allocation (Kiryl)
- Adjust comments/changelog for contiguous allocation of extensions memory (Kiryl)
- s/PFN array/HPA array in commit log (Kiryl)
- State the alternative solution (Rick)
- Add code comment for struct tdx_hpa_list
v1:
- Fix return value for SEAMCALL wrappers (Chao)
- Print SEAMCALL error code for SEAMCALL wrappers (Xiaoyao)
- Rename local vars to make the ext memory adding loop clear (Rick)
- Remove input parameters for tdx_ext_mem_setup() (Kevin)
- Add a Macro for tdh_hpa_list size.
- Change the SEAMALL wrapper parameter type,
struct page *hpa_list => struct tdx_hpa_list *hpa_list
- changelog & code comments
--- arch/x86/include/asm/tdx_global_metadata.h | 1 + arch/x86/virt/vmx/tdx/tdx.h | 1 + arch/x86/virt/vmx/tdx/tdx.c | 134 +++++++++++++++++++- arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 6 + 4 files changed, 139 insertions(+), 3 deletions(-)
arch/x86/include/asm/tdx_global_metadata.h +1 -0
@@ -45,6 +45,7 @@ struct tdx_sys_info_handoff { };struct tdx_sys_info_ext { +u32 memory_pool_required_pages;bool ext_required; };
arch/x86/virt/vmx/tdx/tdx.h +1 -0
@@ -48,6 +48,7 @@#define TDH_SYS_CONFIG 45#define TDH_SYS_SHUTDOWN 52#define TDH_SYS_UPDATE 53 +#define TDH_EXT_MEM_ADD 61#define TDH_SYS_DISABLE 69/* TDX page types */
arch/x86/virt/vmx/tdx/tdx.c +131 -3
146 lines not on this page · raw message
arch/x86/virt/vmx/tdx/tdx_global_metadata.c +6 -0
@@ -137,6 +137,12 @@ static __init int get_tdx_sys_info_ext(struct tdx_sys_info_ext *sysinfo_ext)int ret;u64 val; + ret =read_sys_metadata_field (0x3100000200000000 , &val); +if (ret) +return ret; + + sysinfo_ext->memory_pool_required_pages = val; + ret =read_sys_metadata_field (0x3100000000000001 , &val);if (ret)return ret;
Signature · 1 line
2.25.1
Edgecombe, Rick P
maintainerRe: [PATCH v2 4/5] x86/virt/tdx: Add extra memory to TDX module for the extensions
Hey Kiryl,
Quoted 10 lines · Xu Yilun
An alternative solution is to use a loop that gives memory on a memory error code -
TDX_EXT_MEMORY_POOL_REQUIRED, add one page per iteration until TDH.EXT.INIT succeeds. Something like:do { ret = tdh_sys_init(); if (ret == TDX_EXT_MEMORY_POOL_REQUIRED) tdh_ext_mem_add(); //single page } while (ret == TDX_EXT_MEMORY_POOL_REQUIRED);
Quoted 4 lines
This approach is slightly simpler as we don't have to query the module for the total memory, no memory pre-allocation or segmentation math. But allocating a single 4K page per iteration may cause permanent memory fragmentation.
So this is definitely a bad thing to do? Even if this is running at boot before much fragmentation could have happened? Don't early boot allocations tend to be more physically contiguous?
Kiryl Shutsemau
maintainerRe: [PATCH v2 4/5] x86/virt/tdx: Add extra memory to TDX module for the extensions
Quoted 13 lines · Rick P
Hey Kiryl,
Quoted 10 lines · Xu Yilun
An alternative solution is to use a loop that gives memory on a memory error code -
TDX_EXT_MEMORY_POOL_REQUIRED, add one page per iteration until TDH.EXT.INIT succeeds. Something like:do { ret = tdh_sys_init(); if (ret == TDX_EXT_MEMORY_POOL_REQUIRED) tdh_ext_mem_add(); //single page } while (ret == TDX_EXT_MEMORY_POOL_REQUIRED);
Quoted 8 lines
Quoted 4 lines
This approach is slightly simpler as we don't have to query the module for the total memory, no memory pre-allocation or segmentation math. But allocating a single 4K page per iteration may cause permanent memory fragmentation.
So this is definitely a bad thing to do? Even if this is running at boot before much fragmentation could have happened? Don't early boot allocations tend to be more physically contiguous?
Not necessarily. See CONFIG_SHUFFLE_PAGE_ALLOCATOR, which default Y.
But even with shuffling, page allocator shouldn't claim new non-movable page block just to keep shuffling satisfied.
It is better to check what happens in practice.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Edgecombe, Rick P
maintainerRe: [PATCH v2 4/5] x86/virt/tdx: Add extra memory to TDX module for the extensions
Quoted 6 lines · Kiryl Shutsemau
Not necessarily. See
CONFIG_SHUFFLE_PAGE_ALLOCATOR, which default Y.But even with shuffling, page allocator shouldn't claim new non-movable page block just to keep shuffling satisfied.
It is better to check what happens in practice.
Fair enough, thanks!
Re: [PATCH v2 4/5] x86/virt/tdx: Add extra memory to TDX module for the extensions
In reply to Xu YilunQuoted 7 lines
arch/x86/virt/vmx/tdx/tdx.c +7
-0+static __init int tdx_ext_mem_setup (void ) +{ +unsigned int required_pages = tdx_sysinfo.ext.memory_pool_required_pages; +struct tdx_hpa_list *hpa_list; +unsigned int added_pages; +struct page *page; +int ret;
arch/x86/virt/vmx/tdx/tdx.c static __init int init_tdmrs(struct tdmr_info_list *tdmr_list) · line 1252
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+ +/* +* TDX module uses the metadata memory_pool_required_pages to indicate +* how much memory is still needed. This value decreases each time +* memory is added via TDH.EXT.MEM.ADD. +* +* On first time initialization, a value of 0 before any memory is +* added is unusual. But host makes no assumptions. Skip the memory +* setup and let subsequent steps catch any actual errors. +*/
The fact that the value decreases on each TDH.EXT.MEM.ADD is not relevant here.
Also, calling 0 "unusual" does not help the reader. It is either a valid value the kernel needs to handle, or an invalid one the kernel can assert on.
How about:
/* * The TDX module may require no memory at all. Skip the memory * setup in that case. */
Quoted 2 lines
arch/x86/virt/vmx/tdx/tdx.c +2
-0+if (!required_pages) +return 0 ;
Re: [PATCH v2 4/5] x86/virt/tdx: Add extra memory to TDX module for the extensions
Quoted 25 lines · Chao Gao
Quoted 7 lines
arch/x86/virt/vmx/tdx/tdx.c +7
-0+static __init int tdx_ext_mem_setup (void ) +{ +unsigned int required_pages = tdx_sysinfo.ext.memory_pool_required_pages; +struct tdx_hpa_list *hpa_list; +unsigned int added_pages; +struct page *page; +int ret;arch/x86/virt/vmx/tdx/tdx.c static __init int init_tdmrs(struct tdmr_info_list *tdmr_list) · line 1252
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+ +/* +* TDX module uses the metadata memory_pool_required_pages to indicate +* how much memory is still needed. This value decreases each time +* memory is added via TDH.EXT.MEM.ADD. +* +* On first time initialization, a value of 0 before any memory is +* added is unusual. But host makes no assumptions. Skip the memory +* setup and let subsequent steps catch any actual errors. +*/ The fact that the value decreases on each TDH.EXT.MEM.ADD is not relevant here.
Also, calling 0 "unusual" does not help the reader. It is either a valid value the kernel needs to handle, or an invalid one the kernel can assert on.
Quoted 6 lines
How about:
/* * The TDX module may require no memory at all. Skip the memory * setup in that case. */
Since we will drop ext_required check, I've found a reason why no memory is required.
/*
* Skip the memory setup if no memory is required. This may happen when
* no add-on features requiring TDX module extensions are configured
* via TDH.SYS.CONFIG.
*/
Quoted 3 lines
Quoted 3 lines
arch/x86/virt/vmx/tdx/tdx.c +2
-0+if (!required_pages) +return 0 ;
Re: [PATCH v2 4/5] x86/virt/tdx: Add extra memory to TDX module for the extensions
In reply to Xu YilunQuoted 8 lines · Xu Yilun
arch/x86/virt/vmx/tdx/tdx.c +2
-0@@ -1181,6 +1181,136 @@ static __init int init_tdmrs(struct tdmr_info_list *tdmr_list)return 0 ; } +#define TDX_HPA_LIST_MAX_NR_PAGES (PAGE_SIZE / sizeof(u64)) +
arch/x86/virt/vmx/tdx/tdx.c static __init int init_tdmrs(struct tdmr_info_list *tdmr_list) · line 1195
Quoted 10 lines
arch/x86/virt/vmx/tdx/tdx.c +10
-0+/* +* This is the "HPA_LIST" data structure defined in the "Intel TDX Module ABI +* Specification". +* +* It is the in-memory ABI that the kernel uses to add memory to the TDX +* module. +*/ +struct tdx_hpa_list { +u64 phys[TDX_HPA_LIST_MAX_NR_PAGES ]; +};
Here too you could simplify the comments similar to what I suggested for patch 1/5.
Other than that:
PATCH v2 5/5 x86/virt/tdx: Make TDX module initialize the extensions
In reply to Xu YilunTDX module extensions need memory for their execution environment to serve SEAMCALL leafs. Several add-on features depend on the extensions to execute their SEAMCALL leafs.
After providing all required memory to the TDX module, initialize TDX module extensions via TDH.EXT.INIT, then those add-on features can use their SEAMCALL leafs normally.
---
v1:
- Fix return value for SEAMCALL wrappers (Chao)
- Print SEAMCALL error code for SEAMCALL wrappers (Xiaoyao)
- Changelog & code comments
--- arch/x86/virt/vmx/tdx/tdx.h | 1 + arch/x86/virt/vmx/tdx/tdx.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-)
arch/x86/virt/vmx/tdx/tdx.h +1 -0
@@ -48,6 +48,7 @@#define TDH_SYS_CONFIG 45#define TDH_SYS_SHUTDOWN 52#define TDH_SYS_UPDATE 53 +#define TDH_EXT_INIT 60#define TDH_EXT_MEM_ADD 61#define TDH_SYS_DISABLE 69
arch/x86/virt/vmx/tdx/tdx.c +22 -1
@@ -1311,6 +1311,23 @@ static __init int tdx_ext_mem_setup(void)return ret; } +static __init int tdx_ext_init (void ) +{ +struct tdx_module_args args = {}; +u64 ret; + +do { + ret =seamcall (TDH_EXT_INIT , &args); + }while (ret ==TDX_INTERRUPTED_RESUMABLE ); + +if (ret !=TDX_SUCCESS ) { +pr_err ("TDH.EXT.INIT failed: 0x%016llx\n" , ret); +return -EIO ; + } + +return 0 ; +} +static __init int init_tdx_module_extensions (void ) {int ret;
@@ -1330,7 +1347,11 @@ static __init int init_tdx_module_extensions(void)if (!tdx_sysinfo.ext.ext_required)return 0 ; -return tdx_ext_mem_setup (); + ret =tdx_ext_mem_setup (); +if (ret) +return ret; + +return tdx_ext_init (); }static __init int init_tdx_module (void )
Signature · 1 line
2.25.1
Edgecombe, Rick P
maintainerQuoted 10 lines · Xu Yilun
This is based on v7.3-rc1. You can find the full branch stack at [2]. The DICE part is in the full branch as an example for extensions. But it does not include the other DICE feedbacks.
The full branch contains:
Dependency: Patch 1: SEAMCALL version patch [3] which is WIP on
community review.
This series: Patch 2~7: This series, including this cover-letter. Use case: Patch 8~N: The old DICE part as an example.
A downside to these stacks is that we don't get Sashiko review. I wonder if it would pick this up:
https://b4.docs.kernel.org/en/latest/contributor/prep.html#using-the-message-id