Re: [RFC PATCH v2 06/26] x86/cpu/intel: Allow SGX virtualization without Launch Control support

Dave Hansen
2021-01-20T22:12:28Z

On 1/17/21 7:27 PM, Kai Huang wrote:
> - enable_sgx = cpu_has(c, X86_FEATURE_SGX) &&
> - cpu_has(c, X86_FEATURE_SGX_LC) &&
> - IS_ENABLED(CONFIG_X86_SGX);
> + enable_sgx_driver = cpu_has(c, X86_FEATURE_SGX) &&
> + cpu_has(c, X86_FEATURE_SGX1) &&
> + IS_ENABLED(CONFIG_X86_SGX) &&
> + cpu_has(c, X86_FEATURE_SGX_LC);
> + enable_sgx_virt = cpu_has(c, X86_FEATURE_SGX) &&
> + cpu_has(c, X86_FEATURE_SGX1) &&
> + IS_ENABLED(CONFIG_X86_SGX) &&
> + IS_ENABLED(CONFIG_X86_SGX_VIRTUALIZATION) &&
> + enable_vmx;

Would it be too much to ask that the SGX/SGX1 checks not be duplicated?
Perhaps:

enable_sgx_any = cpu_feature_enabled(CONFIG_X86_SGX) &&
cpu_feature_enabled(CONFIG_X86_SGX1);

enable_sgx_driver = enable_sgx_any &&
cpu_has(c, X86_FEATURE_SGX_LC);

enable_sgx_virt = enable_sgx_any &&
enable_vmx &&
IS_ENABLED(CONFIG_X86_SGX_VIRTUALIZATION)

BTW, CONFIG_X86_SGX_VIRTUALIZATION is a pretty porky name. Maybe just
CONFIG_X86_SGX_VIRT?