Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+20 -1
+1
arch/x86/include/asm/kvm_emulate.h
··· 181 181 int (*set_dr)(struct x86_emulate_ctxt *ctxt, int dr, ulong value); 182 182 int (*set_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 data); 183 183 int (*get_msr)(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata); 184 + int (*read_pmc)(struct x86_emulate_ctxt *ctxt, u32 pmc, u64 *pdata); 184 185 void (*halt)(struct x86_emulate_ctxt *ctxt); 185 186 void (*wbinvd)(struct x86_emulate_ctxt *ctxt); 186 187 int (*fix_hypercall)(struct x86_emulate_ctxt *ctxt);
+12 -1
arch/x86/kvm/emulate.c
··· 2645 2645 return X86EMUL_CONTINUE; 2646 2646 } 2647 2647 2648 + static int em_rdpmc(struct x86_emulate_ctxt *ctxt) 2649 + { 2650 + u64 pmc; 2651 + 2652 + if (ctxt->ops->read_pmc(ctxt, ctxt->regs[VCPU_REGS_RCX], &pmc)) 2653 + return emulate_gp(ctxt, 0); 2654 + ctxt->regs[VCPU_REGS_RAX] = (u32)pmc; 2655 + ctxt->regs[VCPU_REGS_RDX] = pmc >> 32; 2656 + return X86EMUL_CONTINUE; 2657 + } 2658 + 2648 2659 static int em_mov(struct x86_emulate_ctxt *ctxt) 2649 2660 { 2650 2661 ctxt->dst.val = ctxt->src.val; ··· 3422 3411 II(ImplicitOps | Priv, em_wrmsr, wrmsr), 3423 3412 IIP(ImplicitOps, em_rdtsc, rdtsc, check_rdtsc), 3424 3413 II(ImplicitOps | Priv, em_rdmsr, rdmsr), 3425 - DIP(ImplicitOps, rdpmc, check_rdpmc), 3414 + IIP(ImplicitOps, em_rdpmc, rdpmc, check_rdpmc), 3426 3415 I(ImplicitOps | VendorSpecific, em_sysenter), 3427 3416 I(ImplicitOps | Priv | VendorSpecific, em_sysexit), 3428 3417 N, N,
+7
arch/x86/kvm/x86.c
··· 4146 4146 return kvm_set_msr(emul_to_vcpu(ctxt), msr_index, data); 4147 4147 } 4148 4148 4149 + static int emulator_read_pmc(struct x86_emulate_ctxt *ctxt, 4150 + u32 pmc, u64 *pdata) 4151 + { 4152 + return kvm_pmu_read_pmc(emul_to_vcpu(ctxt), pmc, pdata); 4153 + } 4154 + 4149 4155 static void emulator_halt(struct x86_emulate_ctxt *ctxt) 4150 4156 { 4151 4157 emul_to_vcpu(ctxt)->arch.halt_request = 1; ··· 4204 4198 .set_dr = emulator_set_dr, 4205 4199 .set_msr = emulator_set_msr, 4206 4200 .get_msr = emulator_get_msr, 4201 + .read_pmc = emulator_read_pmc, 4207 4202 .halt = emulator_halt, 4208 4203 .wbinvd = emulator_wbinvd, 4209 4204 .fix_hypercall = emulator_fix_hypercall,