Skip to content

Commit d5f6f44

Browse files
bysuigregkh
authored andcommitted
KVM: x86/emulator: Emulate RDPID only if it is enabled in guest
[ Upstream commit a836839 ] When RDTSCP is supported but RDPID is not supported in host, RDPID emulation is available. However, __kvm_get_msr() would only fail when RDTSCP/RDPID both are disabled in guest, so the emulator wouldn't inject a #UD when RDPID is disabled but RDTSCP is enabled in guest. Fixes: fb6d4d3 ("KVM: x86: emulate RDPID") Signed-off-by: Hou Wenlong <[email protected]> Message-Id: <1dfd46ae5b76d3ed87bde3154d51c64ea64c99c1.1646226788.git.houwenlong.hwl@antgroup.com> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a997e0f commit d5f6f44

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

arch/x86/kvm/emulate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3514,8 +3514,10 @@ static int em_rdpid(struct x86_emulate_ctxt *ctxt)
35143514
{
35153515
u64 tsc_aux = 0;
35163516

3517-
if (ctxt->ops->get_msr(ctxt, MSR_TSC_AUX, &tsc_aux))
3517+
if (!ctxt->ops->guest_has_rdpid(ctxt))
35183518
return emulate_ud(ctxt);
3519+
3520+
ctxt->ops->get_msr(ctxt, MSR_TSC_AUX, &tsc_aux);
35193521
ctxt->dst.val = tsc_aux;
35203522
return X86EMUL_CONTINUE;
35213523
}

arch/x86/kvm/kvm_emulate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ struct x86_emulate_ops {
226226
bool (*guest_has_long_mode)(struct x86_emulate_ctxt *ctxt);
227227
bool (*guest_has_movbe)(struct x86_emulate_ctxt *ctxt);
228228
bool (*guest_has_fxsr)(struct x86_emulate_ctxt *ctxt);
229+
bool (*guest_has_rdpid)(struct x86_emulate_ctxt *ctxt);
229230

230231
void (*set_nmi_mask)(struct x86_emulate_ctxt *ctxt, bool masked);
231232

arch/x86/kvm/x86.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7393,6 +7393,11 @@ static bool emulator_guest_has_fxsr(struct x86_emulate_ctxt *ctxt)
73937393
return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_FXSR);
73947394
}
73957395

7396+
static bool emulator_guest_has_rdpid(struct x86_emulate_ctxt *ctxt)
7397+
{
7398+
return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_RDPID);
7399+
}
7400+
73967401
static ulong emulator_read_gpr(struct x86_emulate_ctxt *ctxt, unsigned reg)
73977402
{
73987403
return kvm_register_read_raw(emul_to_vcpu(ctxt), reg);
@@ -7475,6 +7480,7 @@ static const struct x86_emulate_ops emulate_ops = {
74757480
.guest_has_long_mode = emulator_guest_has_long_mode,
74767481
.guest_has_movbe = emulator_guest_has_movbe,
74777482
.guest_has_fxsr = emulator_guest_has_fxsr,
7483+
.guest_has_rdpid = emulator_guest_has_rdpid,
74787484
.set_nmi_mask = emulator_set_nmi_mask,
74797485
.get_hflags = emulator_get_hflags,
74807486
.exiting_smm = emulator_exiting_smm,

0 commit comments

Comments
 (0)