Re: [PATCH v5 04/12] x86/tdx: Add protected guest support for TDX guest

Kuppuswamy, Sathyanarayanan
2021-08-20T16:43:01Z

On 8/20/21 7:28 AM, Borislav Petkov wrote:
> On Thu, Aug 12, 2021 at 10:18:39AM -0700, Kuppuswamy, Sathyanarayanan wrote:
>> I can implement intel_prot_guest_has() in arch/x86/kernel/cpu/intel.c.
>> And call tdx_prot_guest_has() from it.
>
> No, you should simply implement intel_prot_guest_has() or whatever we
> end up calling it and have the generic routine call it. Not two routines
> - tdx_* and intel_*
>

Reason for suggesting seperate function for tdx_* specific protected guest
check is, we will be adding some exceptions for TDX features (like command
line option used to override the default flags or when device filter
support is disabled). Our current final version looks like below. Such
customization are not good in generic intel_* function right?

bool tdx_prot_guest_has(unsigned long flag)
{
bool tdx_guest_enabled = cpu_feature_enabled(X86_FEATURE_TDX_GUEST);

if (flag == tdg_disable_prot)
return false;

switch (flag) {
case PATTR_GUEST_TDX:
case PATTR_GUEST_UNROLL_STRING_IO:
case PATTR_GUEST_MEM_ENCRYPT:
case PATTR_GUEST_SHARED_MAPPING_INIT:
case PATTR_MEM_ENCRYPT:
case PATTR_GUEST_SECURE_TIME:
case PATTR_GUEST_CPUID_FILTER:
case PATTR_GUEST_RAND_LOOP:
return tdx_guest_enabled;
case PATTR_GUEST_DRIVER_FILTER:
return tdg_filter_enabled() && tdx_guest_enabled;
}

return false;
}

--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer