mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-25 11:55:37 +00:00
x86/sev-es: Handle RDTSC(P) Events
Implement a handler for #VC exceptions caused by RDTSC and RDTSCP instructions. Also make it available in the pre-decompression stage because the KASLR code uses RDTSC/RDTSCP to gather entropy and some hypervisors intercept these instructions. Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> [ jroedel@suse.de: - Adapt to #VC handling infrastructure - Make it available early ] Co-developed-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20200907131613.12703-55-joro@8bytes.org
This commit is contained in:
parent
a14a92fc4b
commit
4711e7acaa
3 changed files with 31 additions and 0 deletions
|
@ -181,6 +181,10 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)
|
|||
goto finish;
|
||||
|
||||
switch (exit_code) {
|
||||
case SVM_EXIT_RDTSC:
|
||||
case SVM_EXIT_RDTSCP:
|
||||
result = vc_handle_rdtsc(boot_ghcb, &ctxt, exit_code);
|
||||
break;
|
||||
case SVM_EXIT_IOIO:
|
||||
result = vc_handle_ioio(boot_ghcb, &ctxt);
|
||||
break;
|
||||
|
|
|
@ -467,3 +467,26 @@ static enum es_result vc_handle_cpuid(struct ghcb *ghcb,
|
|||
|
||||
return ES_OK;
|
||||
}
|
||||
|
||||
static enum es_result vc_handle_rdtsc(struct ghcb *ghcb,
|
||||
struct es_em_ctxt *ctxt,
|
||||
unsigned long exit_code)
|
||||
{
|
||||
bool rdtscp = (exit_code == SVM_EXIT_RDTSCP);
|
||||
enum es_result ret;
|
||||
|
||||
ret = sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, 0, 0);
|
||||
if (ret != ES_OK)
|
||||
return ret;
|
||||
|
||||
if (!(ghcb_rax_is_valid(ghcb) && ghcb_rdx_is_valid(ghcb) &&
|
||||
(!rdtscp || ghcb_rcx_is_valid(ghcb))))
|
||||
return ES_VMM_ERROR;
|
||||
|
||||
ctxt->regs->ax = ghcb->save.rax;
|
||||
ctxt->regs->dx = ghcb->save.rdx;
|
||||
if (rdtscp)
|
||||
ctxt->regs->cx = ghcb->save.rcx;
|
||||
|
||||
return ES_OK;
|
||||
}
|
||||
|
|
|
@ -866,6 +866,10 @@ static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt,
|
|||
case SVM_EXIT_WRITE_DR7:
|
||||
result = vc_handle_dr7_write(ghcb, ctxt);
|
||||
break;
|
||||
case SVM_EXIT_RDTSC:
|
||||
case SVM_EXIT_RDTSCP:
|
||||
result = vc_handle_rdtsc(ghcb, ctxt, exit_code);
|
||||
break;
|
||||
case SVM_EXIT_CPUID:
|
||||
result = vc_handle_cpuid(ghcb, ctxt);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue