x86/sgx: Move the intermediate EINIT helper into the driver
PATCH 1/1 x86/sgx: Move the intermediate EINIT helper into the driver
Move sgx_einit() into the driver code, along with the LE hash MSR management. Providing sgx_einit() in the common SGX code was a bit premature. The thought was that the native SGX driver and KVM would be able to use a common EINIT helper, but that may or may not hold true depending on how KVM's implementation shakes out. For example, KVM may want to pass user pointers directly to EINIT in order to avoid copying large amounts of data to in-kernel temp structures.
---
I hedged a bit in the changelog, but I'm 99% confident KVM support will use a different implementation for EINIT. Figure moving the code is worth doing in the initial series since it eliminates encls.c. My thought is that the KVM series can move just the sgx_lepubkeyhash_cache code into main.c so it can be shared with virtual EPC code.
arch/x86/kernel/cpu/sgx/Makefile | 1 - arch/x86/kernel/cpu/sgx/encls.c | 57 -------------------------------- arch/x86/kernel/cpu/sgx/encls.h | 3 -- arch/x86/kernel/cpu/sgx/ioctl.c | 37 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 61 deletions(-) delete mode 100644 arch/x86/kernel/cpu/sgx/encls.c
arch/x86/kernel/cpu/sgx/Makefile +0 -1
@@ -1,7 +1,6 @@ obj-y += \ driver.o \ encl.o \ - encls.o \ ioctl.o \ main.o \ reclaim.o
arch/x86/kernel/cpu/sgx/encls.c deleted +0 -57
57 lines not on this page · raw message
arch/x86/kernel/cpu/sgx/encls.h +0 -3
@@ -248,7 +248,4 @@ static inline int __ewb(struct sgx_pageinfo *pginfo, void *addr, return __encls_ret_3(EWB, pginfo, addr, va); } -int sgx_einit (struct sgx_sigstruct *sigstruct,struct sgx_einittoken *token, -struct sgx_epc_page *secs,u64 *lepubkeyhash); -#endif /* _X86_ENCLS_H */
arch/x86/kernel/cpu/sgx/ioctl.c +37 -0
@@ -16,6 +16,9 @@#include "encl.h" #include "encls.h" +/* A per-cpu cache for the last known values of IA32_SGXLEPUBKEYHASHx MSRs. */ +static DEFINE_PER_CPU(u64 [4], sgx_lepubkeyhash_cache); +static struct sgx_va_page *sgx_encl_grow (struct sgx_encl *encl) {struct sgx_va_page *va_page =NULL ;
@@ -578,6 +581,40 @@ static int sgx_get_key_hash(const void *modulus, void *hash)return ret; } +static void sgx_update_lepubkeyhash_msrs (u64 *lepubkeyhash,bool enforce) +{ +u64 *cache; +int i; + + cache =per_cpu (sgx_lepubkeyhash_cache,smp_processor_id ()); +for (i =0 ; i <4 ; i++) { +if (enforce || (lepubkeyhash[i] != cache[i])) { +wrmsrl (MSR_IA32_SGXLEPUBKEYHASH0 + i, lepubkeyhash[i]); + cache[i] = lepubkeyhash[i]; + } + } +} + +static int sgx_einit (struct sgx_sigstruct *sigstruct, +struct sgx_einittoken *token, +struct sgx_epc_page *secs,u64 *lepubkeyhash) +{ +int ret; + +if (!boot_cpu_has (X86_FEATURE_SGX_LC )) +return __einit (sigstruct, token,sgx_epc_addr (secs)); + +preempt_disable (); +sgx_update_lepubkeyhash_msrs (lepubkeyhash, false); + ret =__einit (sigstruct, token,sgx_epc_addr (secs)); +if (ret ==SGX_INVALID_EINITTOKEN ) { +sgx_update_lepubkeyhash_msrs (lepubkeyhash, true); + ret =__einit (sigstruct, token,sgx_epc_addr (secs)); + } +preempt_enable (); +return ret; +} +static int sgx_encl_init (struct sgx_encl *encl,struct sgx_sigstruct *sigstruct,struct sgx_einittoken *token) {
Signature · 1 line
2.24.1
Quoted 9 lines · Sean Christopherson
Move
sgx_einit()into the driver code, along with the LE hash MSR management. Providingsgx_einit()in the common SGX code was a bit premature. The thought was that the native SGX driver and KVM would be able to use a common EINIT helper, but that may or may not hold true depending on how KVM's implementation shakes out. For example, KVM may want to pass user pointers directly to EINIT in order to avoid copying large amounts of data to in-kernel temp structures.Signed-off-by Sean Christopherson <[email protected]>
Thank you. I merged this patch and also added a changelog entry about merging driver and EINIT patch.
/Jarkko