Skip to content

Commit 38cc649

Browse files
nikunjadbp3tk0v
authored andcommitted
x86/sev: Prevent GUEST_TSC_FREQ MSR interception for Secure TSC enabled guests
The hypervisor should not be intercepting GUEST_TSC_FREQ MSR(0xcOO10134) when Secure TSC is enabled. A #VC exception will be generated otherwise. If this should occur and Secure TSC is enabled, terminate guest execution. Signed-off-by: Nikunj A Dadhania <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0f0502b commit 38cc649

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

arch/x86/coco/sev/core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,12 +1436,19 @@ static enum es_result __vc_handle_msr_caa(struct pt_regs *regs, bool write)
14361436
/*
14371437
* TSC related accesses should not exit to the hypervisor when a guest is
14381438
* executing with Secure TSC enabled, so special handling is required for
1439-
* accesses of MSR_IA32_TSC.
1439+
* accesses of MSR_IA32_TSC and MSR_AMD64_GUEST_TSC_FREQ.
14401440
*/
14411441
static enum es_result __vc_handle_secure_tsc_msrs(struct pt_regs *regs, bool write)
14421442
{
14431443
u64 tsc;
14441444

1445+
/*
1446+
* GUEST_TSC_FREQ should not be intercepted when Secure TSC is enabled.
1447+
* Terminate the SNP guest when the interception is enabled.
1448+
*/
1449+
if (regs->cx == MSR_AMD64_GUEST_TSC_FREQ)
1450+
return ES_VMM_ERROR;
1451+
14451452
/*
14461453
* Writes: Writing to MSR_IA32_TSC can cause subsequent reads of the TSC
14471454
* to return undefined values, so ignore all writes.
@@ -1474,6 +1481,7 @@ static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt)
14741481
case MSR_SVSM_CAA:
14751482
return __vc_handle_msr_caa(regs, write);
14761483
case MSR_IA32_TSC:
1484+
case MSR_AMD64_GUEST_TSC_FREQ:
14771485
if (sev_status & MSR_AMD64_SNP_SECURE_TSC)
14781486
return __vc_handle_secure_tsc_msrs(regs, write);
14791487
else

arch/x86/include/asm/msr-index.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@
608608
#define MSR_AMD_PERF_CTL 0xc0010062
609609
#define MSR_AMD_PERF_STATUS 0xc0010063
610610
#define MSR_AMD_PSTATE_DEF_BASE 0xc0010064
611+
#define MSR_AMD64_GUEST_TSC_FREQ 0xc0010134
611612
#define MSR_AMD64_OSVW_ID_LENGTH 0xc0010140
612613
#define MSR_AMD64_OSVW_STATUS 0xc0010141
613614
#define MSR_AMD_PPIN_CTL 0xc00102f0

0 commit comments

Comments
 (0)