Re: [PATCH v14 04/19] x86/cpufeatures: Add SGX feature bits

From: Borislav Petkov
Date: Tue Sep 25 2018 - 12:48:54 EST


On Tue, Sep 25, 2018 at 04:06:41PM +0300, Jarkko Sakkinen wrote:
> From: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
>
> Add SGX feature bits as part of the Linux defined leaf 8, which
> currently contains virtualization flags. There are currently four
> documented SGX feature bits, with more expected in the not-too-distant
> future.

...

> +static void detect_sgx(struct cpuinfo_x86 *c)
> +{
> +#define _X86_FEATURE_SGX1 BIT(0)
> +#define _X86_FEATURE_SGX2 BIT(1)
> +#define _X86_FEATURE_SGX_ENCLV BIT(5)
> +#define _X86_FEATURE_SGX_ENCLS_C BIT(6)
> +
> + unsigned int eax;
> +
> + clear_cpu_cap(c, X86_FEATURE_SGX1);
> + clear_cpu_cap(c, X86_FEATURE_SGX2);
> + clear_cpu_cap(c, X86_FEATURE_SGX_ENCLV);
> + clear_cpu_cap(c, X86_FEATURE_SGX_ENCLS_C);
> +
> + if (c->cpuid_level < SGX_CPUID) {
> + pr_err_once("x86/sgx: cannot enumerate CPUID leaf (0x%x)\n",
> + SGX_CPUID);
> + clear_cpu_cap(c, X86_FEATURE_SGX);
> + return;
> + }
> +
> + eax = cpuid_eax(SGX_CPUID);
> +
> + if (eax & _X86_FEATURE_SGX1)
> + set_cpu_cap(c, X86_FEATURE_SGX1);
> +
> + if (eax & _X86_FEATURE_SGX2)
> + set_cpu_cap(c, X86_FEATURE_SGX2);
> +
> + if (eax & _X86_FEATURE_SGX_ENCLV)
> + set_cpu_cap(c, X86_FEATURE_SGX_ENCLV);
> +
> + if (eax & _X86_FEATURE_SGX_ENCLS_C)
> + set_cpu_cap(c, X86_FEATURE_SGX_ENCLS_C);


Look at arch/x86/kernel/cpu/scattered.c for how to do this properly.

--
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.