Signed-off-by: Philippe Mathieu-Daudé <philmd@xxxxxxxxxx> --- include/sysemu/kvm.h | 2 ++ accel/kvm/kvm-all.c | 5 +++++ target/i386/cpu.c | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 687c598be9b..f339be31d1b 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -361,6 +361,8 @@ int kvm_arch_init_vcpu(CPUState *cpu); int kvm_arch_destroy_vcpu(CPUState *cpu); bool kvm_vcpu_id_is_valid(int vcpu_id); +/* Returns a pointer to the KVMState associated with this vCPU */ +KVMState *kvm_vcpu_state(CPUState *cpu); /* Returns VCPU ID to be used on KVM_CREATE_VCPU ioctl() */ unsigned long kvm_arch_vcpu_id(CPUState *cpu); diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 84c943fcdb2..b787d590a9a 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1978,6 +1978,11 @@ bool kvm_vcpu_id_is_valid(int vcpu_id) return vcpu_id >= 0 && vcpu_id < kvm_max_vcpu_id(s); } +KVMState *kvm_vcpu_state(CPUState *cpu) +{ + return cpu->kvm_state; +} + static int kvm_init(MachineState *ms) { MachineClass *mc = MACHINE_GET_CLASS(ms); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6a53446e6a5..0d6376322bb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5755,7 +5755,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, case 0xA: /* Architectural Performance Monitoring Leaf */ if (kvm_enabled() && cpu->enable_pmu) { - KVMState *s = cs->kvm_state; + KVMState *s = kvm_vcpu_state(cs); *eax = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX); *ebx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EBX); @@ -6620,7 +6620,7 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose) if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) && kvm_enabled()) { - KVMState *s = CPU(cpu)->kvm_state; + KVMState *s = kvm_vcpu_state(CPU(cpu)); uint32_t eax_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_EAX); uint32_t ebx_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_EBX); uint32_t ecx_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_ECX); -- 2.26.2