KVM: x86 emulator: implement RDPMC (0F 33)
Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
This commit is contained in:
parent
80bdec64c0
commit
222d21aa07
3 changed files with 20 additions and 1 deletions
|
@ -181,6 +181,7 @@ struct x86_emulate_ops {
|
||||||
int (*set_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong value);
|
int (*set_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong value);
|
||||||
int (*set_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 data);
|
int (*set_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 data);
|
||||||
int (*get_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata);
|
int (*get_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata);
|
||||||
|
int (*read_pmc)(struct x86_emulate_ctxt *ctxt, u32 pmc, u64 *pdata);
|
||||||
void (*halt)(struct x86_emulate_ctxt *ctxt);
|
void (*halt)(struct x86_emulate_ctxt *ctxt);
|
||||||
void (*wbinvd)(struct x86_emulate_ctxt *ctxt);
|
void (*wbinvd)(struct x86_emulate_ctxt *ctxt);
|
||||||
int (*fix_hypercall)(struct x86_emulate_ctxt *ctxt);
|
int (*fix_hypercall)(struct x86_emulate_ctxt *ctxt);
|
||||||
|
|
|
@ -2645,6 +2645,17 @@ static int em_rdtsc(struct x86_emulate_ctxt *ctxt)
|
||||||
return X86EMUL_CONTINUE;
|
return X86EMUL_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int em_rdpmc(struct x86_emulate_ctxt *ctxt)
|
||||||
|
{
|
||||||
|
u64 pmc;
|
||||||
|
|
||||||
|
if (ctxt->ops->read_pmc(ctxt, ctxt->regs[VCPU_REGS_RCX], &pmc))
|
||||||
|
return emulate_gp(ctxt, 0);
|
||||||
|
ctxt->regs[VCPU_REGS_RAX] = (u32)pmc;
|
||||||
|
ctxt->regs[VCPU_REGS_RDX] = pmc >> 32;
|
||||||
|
return X86EMUL_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
static int em_mov(struct x86_emulate_ctxt *ctxt)
|
static int em_mov(struct x86_emulate_ctxt *ctxt)
|
||||||
{
|
{
|
||||||
ctxt->dst.val = ctxt->src.val;
|
ctxt->dst.val = ctxt->src.val;
|
||||||
|
@ -3411,7 +3422,7 @@ static struct opcode twobyte_table[256] = {
|
||||||
II(ImplicitOps | Priv, em_wrmsr, wrmsr),
|
II(ImplicitOps | Priv, em_wrmsr, wrmsr),
|
||||||
IIP(ImplicitOps, em_rdtsc, rdtsc, check_rdtsc),
|
IIP(ImplicitOps, em_rdtsc, rdtsc, check_rdtsc),
|
||||||
II(ImplicitOps | Priv, em_rdmsr, rdmsr),
|
II(ImplicitOps | Priv, em_rdmsr, rdmsr),
|
||||||
DIP(ImplicitOps, rdpmc, check_rdpmc),
|
IIP(ImplicitOps, em_rdpmc, rdpmc, check_rdpmc),
|
||||||
I(ImplicitOps | VendorSpecific, em_sysenter),
|
I(ImplicitOps | VendorSpecific, em_sysenter),
|
||||||
I(ImplicitOps | Priv | VendorSpecific, em_sysexit),
|
I(ImplicitOps | Priv | VendorSpecific, em_sysexit),
|
||||||
N, N,
|
N, N,
|
||||||
|
|
|
@ -4146,6 +4146,12 @@ static int emulator_set_msr(struct x86_emulate_ctxt *ctxt,
|
||||||
return kvm_set_msr(emul_to_vcpu(ctxt), msr_index, data);
|
return kvm_set_msr(emul_to_vcpu(ctxt), msr_index, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int emulator_read_pmc(struct x86_emulate_ctxt *ctxt,
|
||||||
|
u32 pmc, u64 *pdata)
|
||||||
|
{
|
||||||
|
return kvm_pmu_read_pmc(emul_to_vcpu(ctxt), pmc, pdata);
|
||||||
|
}
|
||||||
|
|
||||||
static void emulator_halt(struct x86_emulate_ctxt *ctxt)
|
static void emulator_halt(struct x86_emulate_ctxt *ctxt)
|
||||||
{
|
{
|
||||||
emul_to_vcpu(ctxt)->arch.halt_request = 1;
|
emul_to_vcpu(ctxt)->arch.halt_request = 1;
|
||||||
|
@ -4198,6 +4204,7 @@ static struct x86_emulate_ops emulate_ops = {
|
||||||
.set_dr = emulator_set_dr,
|
.set_dr = emulator_set_dr,
|
||||||
.set_msr = emulator_set_msr,
|
.set_msr = emulator_set_msr,
|
||||||
.get_msr = emulator_get_msr,
|
.get_msr = emulator_get_msr,
|
||||||
|
.read_pmc = emulator_read_pmc,
|
||||||
.halt = emulator_halt,
|
.halt = emulator_halt,
|
||||||
.wbinvd = emulator_wbinvd,
|
.wbinvd = emulator_wbinvd,
|
||||||
.fix_hypercall = emulator_fix_hypercall,
|
.fix_hypercall = emulator_fix_hypercall,
|
||||||
|
|
Loading…
Reference in a new issue