[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 11/19] accel/kvm: Introduce kvm_vcpu_state() helper
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 11/19] accel/kvm: Introduce kvm_vcpu_state() helper |
Date: |
Wed, 3 Mar 2021 19:22:11 +0100 |
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
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
- Re: [PATCH 02/19] target/s390x/kvm: Simplify debug code, (continued)
- [PATCH 03/19] target/s390x/kvm: Reduce deref by declaring 'struct kvm_run' on stack, Philippe Mathieu-Daudé, 2021/03/03
- [PATCH 04/19] cpu: Croup accelerator-specific fields altogether, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 05/19] cpu: Introduce AccelvCPUState opaque structure, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 06/19] accel/whpx: Add typedef for 'struct whpx_vcpu', Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 07/19] accel/whpx: Rename struct whpx_vcpu -> AccelvCPUState, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 08/19] accel/whpx: Use 'accel_vcpu' generic pointer, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 09/19] accel/hax: Add typedef for 'struct hax_vcpu_state', Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 10/19] accel/hax: Use 'accel_vcpu' generic pointer, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 11/19] accel/kvm: Introduce kvm_vcpu_state() helper,
Philippe Mathieu-Daudé <=
- [RFC PATCH 12/19] accel/kvm: Use kvm_vcpu_state() when possible, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 13/19] accel/kvm: Declare and allocate AccelvCPUState struct, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 14/19] accel/kvm: Move the 'kvm_fd' field to AccelvCPUState, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 15/19] accel/kvm: Move the 'kvm_state' field to AccelvCPUState, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 16/19] accel/kvm: Move the 'kvm_run' field to AccelvCPUState, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 17/19] accel/hvf: Reduce deref by declaring 'hv_vcpuid_t hvf_fd' on stack, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 18/19] accel/hvf: Declare and allocate AccelvCPUState struct, Philippe Mathieu-Daudé, 2021/03/03
- [RFC PATCH 19/19] accel/hvf: Move the 'hvf_fd' field to AccelvCPUState, Philippe Mathieu-Daudé, 2021/03/03
- Re: [RFC PATCH 00/19] accel: Introduce AccelvCPUState opaque structure, Paolo Bonzini, 2021/03/04