Skip to content

Commit 7a915dc

Browse files
binbinwu1acrnsi
authored andcommitted
hv: vmsr: present sgx related msr to guest
Present SGX related MSRs to guest if SGX is supported. - MSR_IA32_SGXLEPUBKEYHASH0 ~ MSR_IA32_SGXLEPUBKEYHASH3: SGX Launch Control is not supported, so these MSRs are read only. - MSR_IA32_SGX_SVN_STATUS: read only - MSR_IA32_FEATURE_CONTROL: If SGX is support in VM, opt-in SGX in this MSR. - MSR_SGXOWNEREPOCH0 ~ MSR_SGXOWNEREPOCH1: The two MSRs' scope is package level, not allow guest to change them. Still leave them in unsupported_msrs array. Tracked-On: #3179 Signed-off-by: Binbin Wu <binbin.wu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 1724996 commit 7a915dc

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

hypervisor/arch/x86/guest/vmsr.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <vm.h>
1414
#include <vmcs.h>
1515
#include <vmx.h>
16+
#include <sgx.h>
1617
#include <guest_pm.h>
1718
#include <ucode.h>
1819
#include <trace.h>
@@ -49,6 +50,14 @@ static const uint32_t emulated_guest_msrs[NUM_GUEST_MSRS] = {
4950
MSR_IA32_MCG_CAP,
5051
MSR_IA32_MCG_STATUS,
5152
MSR_IA32_MISC_ENABLE,
53+
54+
/* Don't support SGX Launch Control yet, read only */
55+
MSR_IA32_SGXLEPUBKEYHASH0,
56+
MSR_IA32_SGXLEPUBKEYHASH1,
57+
MSR_IA32_SGXLEPUBKEYHASH2,
58+
MSR_IA32_SGXLEPUBKEYHASH3,
59+
/* Read only */
60+
MSR_IA32_SGX_SVN_STATUS,
5261
};
5362

5463
#define NUM_MTRR_MSRS 13U
@@ -69,7 +78,7 @@ static const uint32_t mtrr_msrs[NUM_MTRR_MSRS] = {
6978
};
7079

7180
/* Following MSRs are intercepted, but it throws GPs for any guest accesses */
72-
#define NUM_UNSUPPORTED_MSRS 104U
81+
#define NUM_UNSUPPORTED_MSRS 99U
7382
static const uint32_t unsupported_msrs[NUM_UNSUPPORTED_MSRS] = {
7483
/* Variable MTRRs are not supported */
7584
MSR_IA32_MTRR_PHYSBASE_0,
@@ -116,15 +125,6 @@ static const uint32_t unsupported_msrs[NUM_UNSUPPORTED_MSRS] = {
116125
MSR_IA32_VMX_TRUE_ENTRY_CTLS,
117126
MSR_IA32_VMX_VMFUNC,
118127

119-
/* SGX disabled: CPUID.12H.EAX[0], CPUID.07H.ECX[30] */
120-
MSR_IA32_SGXLEPUBKEYHASH0,
121-
MSR_IA32_SGXLEPUBKEYHASH1,
122-
MSR_IA32_SGXLEPUBKEYHASH2,
123-
MSR_IA32_SGXLEPUBKEYHASH3,
124-
125-
/* SGX disabled : CPUID.07H.EBX[2] */
126-
MSR_IA32_SGX_SVN_STATUS,
127-
128128
/* MPX disabled: CPUID.07H.EBX[14] */
129129
MSR_IA32_BNDCFGS,
130130

@@ -399,6 +399,9 @@ int32_t rdmsr_vmexit_handler(struct acrn_vcpu *vcpu)
399399
case MSR_IA32_FEATURE_CONTROL:
400400
{
401401
v = MSR_IA32_FEATURE_CONTROL_LOCK;
402+
if (is_vsgx_supported(vcpu->vm->vm_id)) {
403+
v |= MSR_IA32_FEATURE_CONTROL_SGX_GE;
404+
}
402405
break;
403406
}
404407
case MSR_IA32_MCG_CAP:
@@ -412,6 +415,19 @@ int32_t rdmsr_vmexit_handler(struct acrn_vcpu *vcpu)
412415
v = vcpu_get_guest_msr(vcpu, MSR_IA32_MISC_ENABLE);
413416
break;
414417
}
418+
case MSR_IA32_SGXLEPUBKEYHASH0:
419+
case MSR_IA32_SGXLEPUBKEYHASH1:
420+
case MSR_IA32_SGXLEPUBKEYHASH2:
421+
case MSR_IA32_SGXLEPUBKEYHASH3:
422+
case MSR_IA32_SGX_SVN_STATUS:
423+
{
424+
if (is_vsgx_supported(vcpu->vm->vm_id)) {
425+
v = msr_read(msr);
426+
} else {
427+
err = -EACCES;
428+
}
429+
break;
430+
}
415431
default:
416432
{
417433
if (is_x2apic_msr(msr)) {
@@ -622,6 +638,11 @@ int32_t wrmsr_vmexit_handler(struct acrn_vcpu *vcpu)
622638
case MSR_IA32_MCG_CAP:
623639
case MSR_IA32_MCG_STATUS:
624640
case MSR_IA32_FEATURE_CONTROL:
641+
case MSR_IA32_SGXLEPUBKEYHASH0:
642+
case MSR_IA32_SGXLEPUBKEYHASH1:
643+
case MSR_IA32_SGXLEPUBKEYHASH2:
644+
case MSR_IA32_SGXLEPUBKEYHASH3:
645+
case MSR_IA32_SGX_SVN_STATUS:
625646
{
626647
err = -EACCES;
627648
break;

hypervisor/include/arch/x86/guest/vcpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ struct ext_context {
259259
#define SECURE_WORLD 1
260260

261261
#define NUM_WORLD_MSRS 2U
262-
#define NUM_COMMON_MSRS 10U
262+
#define NUM_COMMON_MSRS 15U
263263
#define NUM_GUEST_MSRS (NUM_WORLD_MSRS + NUM_COMMON_MSRS)
264264

265265
#define EOI_EXIT_BITMAP_SIZE 256U

0 commit comments

Comments
 (0)