Re: [PATCH 12/25] x86/sgx: Add helper to update SGX_LEPUBKEYHASHn MSRs

From: Sean Christopherson
Date: Mon Mar 01 2021 - 14:54:52 EST


On Mon, Mar 01, 2021, Kai Huang wrote:
> diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
> index 8c922e68274d..276220d0e4b5 100644
> --- a/arch/x86/kernel/cpu/sgx/main.c
> +++ b/arch/x86/kernel/cpu/sgx/main.c
> @@ -696,6 +696,21 @@ static bool __init sgx_page_cache_init(void)
> return true;
> }
>
> +
> +/*
> + * Update the SGX_LEPUBKEYHASH MSRs to the values specified by caller.
> + * Bare-metal driver requires to update them to hash of enclave's signer
> + * before EINIT. KVM needs to update them to guest's virtual MSR values
> + * before doing EINIT from guest.
> + */
> +void sgx_update_lepubkeyhash(u64 *lepubkeyhash)
> +{
> + int i;

Probably worth adding:

WARN_ON_ONCE(preemptible());

> +
> + for (i = 0; i < 4; i++)
> + wrmsrl(MSR_IA32_SGXLEPUBKEYHASH0 + i, lepubkeyhash[i]);
> +}
> +
> static int __init sgx_init(void)
> {
> int ret;