@@ -367,8 +367,9 @@ void kvm_destroy_vcpu(CPUState *cpu)
}
}
-static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
+static int kvm_get_vcpu(KVMState *s, CPUState *cs)
{
+ unsigned long vcpu_id = kvm_arch_vcpu_id(cs);
struct KVMParkedVcpu *cpu;
QLIST_FOREACH(cpu, &s->kvm_parked_vcpus, node) {
@@ -382,6 +383,8 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
}
}
+ kvm_arch_pre_create_vcpu(cs);
+
return kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)vcpu_id);
}
@@ -393,7 +396,7 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)
trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
- ret = kvm_get_vcpu(s, kvm_arch_vcpu_id(cpu));
+ ret = kvm_get_vcpu(s, cpu);
if (ret < 0) {
error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed (%lu)",
kvm_arch_vcpu_id(cpu));
@@ -371,6 +371,8 @@ int kvm_arch_put_registers(CPUState *cpu, int level);
int kvm_arch_init(MachineState *ms, KVMState *s);
+void kvm_arch_pre_create_vcpu(CPUState *cs);
+
int kvm_arch_init_vcpu(CPUState *cpu);
int kvm_arch_destroy_vcpu(CPUState *cpu);
@@ -834,6 +834,10 @@ static int kvm_arm_sve_set_vls(CPUState *cs)
return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
}
+void kvm_arch_pre_create_vcpu(CPUState *cs)
+{
+}
+
#define ARM_CPU_ID_MPIDR 3, 0, 0, 0, 5
int kvm_arch_init_vcpu(CPUState *cs)
@@ -1723,6 +1723,10 @@ static void kvm_init_nested_state(CPUX86State *env)
}
}
+void kvm_arch_pre_create_vcpu(CPUState *cs)
+{
+}
+
int kvm_arch_init_vcpu(CPUState *cs)
{
struct {
@@ -61,6 +61,10 @@ int kvm_arch_irqchip_create(KVMState *s)
return 0;
}
+void kvm_arch_pre_create_vcpu(CPUState *cs)
+{
+}
+
int kvm_arch_init_vcpu(CPUState *cs)
{
MIPSCPU *cpu = MIPS_CPU(cs);
@@ -462,6 +462,10 @@ static void kvmppc_hw_debug_points_init(CPUPPCState *cenv)
}
}
+void kvm_arch_pre_create_vcpu(CPUState *cs)
+{
+}
+
int kvm_arch_init_vcpu(CPUState *cs)
{
PowerPCCPU *cpu = POWERPC_CPU(cs);
@@ -394,6 +394,10 @@ void kvm_arch_init_irq_routing(KVMState *s)
{
}
+void kvm_arch_pre_create_vcpu(CPUState *cs)
+{
+}
+
int kvm_arch_init_vcpu(CPUState *cs)
{
int ret = 0;
@@ -404,6 +404,10 @@ unsigned long kvm_arch_vcpu_id(CPUState *cpu)
return cpu->cpu_index;
}
+void kvm_arch_pre_create_vcpu(CPUState *cs)
+{
+}
+
int kvm_arch_init_vcpu(CPUState *cs)
{
unsigned int max_cpus = MACHINE(qdev_get_machine())->smp.max_cpus;
Some per-VM kvm caps (e.g., KVM_CAP_PMU_CAPABILITY) can only be enabled/disabled before creating the 1st vcpu, that is, when (!kvm->created_vcpus) at the KVM side. Unfortunately, some properties are still not set during kvm_arch_init(). The values of those properties are obtained during the init of each vcpu. This is to add a new helper to provide the last chance before creating the 1st vcpu, in order for the QEMU to set kvm caps based on the per-vcpu properties (e.g., "pmu"). In the future patch, we may disable KVM_CAP_PMU_CAPABILITY in the helper if the "-pmu" is set for the vcpu. Cc: Joe Jin <joe.jin@oracle.com> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com> --- accel/kvm/kvm-all.c | 7 +++++-- include/sysemu/kvm.h | 2 ++ target/arm/kvm64.c | 4 ++++ target/i386/kvm/kvm.c | 4 ++++ target/mips/kvm.c | 4 ++++ target/ppc/kvm.c | 4 ++++ target/riscv/kvm.c | 4 ++++ target/s390x/kvm/kvm.c | 4 ++++ 8 files changed, 31 insertions(+), 2 deletions(-)