Re: [PATCH v4 24/24] [NOT-FOR-REVIEW] x86/virt/seamldr: Save and restore current VMCS

From: Chao Gao

Date: Thu Mar 12 2026 - 04:48:49 EST


On Thu, Mar 12, 2026 at 06:06:22AM +0800, Huang, Kai wrote:
>
>> static const struct x86_cpu_id tdx_host_ids[] = {
>> X86_MATCH_FEATURE(X86_FEATURE_TDX_HOST_PLATFORM, NULL),
>> @@ -175,6 +177,7 @@ static int seamldr_init(struct device *dev)
>> {
>> const struct tdx_sys_info *tdx_sysinfo = tdx_get_sysinfo();
>> struct fw_upload *tdx_fwl;
>> + u64 basic_msr;
>>
>> if (WARN_ON_ONCE(!tdx_sysinfo))
>> return -EIO;
>> @@ -182,6 +185,15 @@ static int seamldr_init(struct device *dev)
>> if (!tdx_supports_runtime_update(tdx_sysinfo))
>> return 0;
>>
>> + /*
>> + * Some TDX-capable CPUs have an erratum where the current VMCS may
>> + * be cleared after calling into P-SEAMLDR. Ensure no such erratum
>> + * exists before exposing any P-SEAMLDR functions.
>> + */
>> + rdmsrq(MSR_IA32_VMX_BASIC, basic_msr);
>> + if (!(basic_msr & VMX_BASIC_PRESERVE_CURRENT_VMCS))
>> + return 0;
>> +
>
>IIUC this silently disables runtime update and user won't be able to have
>any clue to tell what went wrong (while the user can see the module supports
>this feature and apparently the kernel should support it)?

I'll add some logging.

>
>Since we already have a X86_BUG_TDX_PW_MCE which is detected during kernel
>boot in tdx_init(), shouldn't we just follow so that the user can at least
>see the CPU has this erratum?
>
>Another advantage is, if in the future some other kernel code needs to know
>this erratum, it can just consult this flag.

Thanks!

I didn't do that because I wasn't sure if adding a bug bit was justified
without another use case (i.e., this is a one-off check).

But I agree that following the X86_BUG_TDX_PW_MCE is better in consistency
and extensibility. So, here is the refined patch: