Skip to content

Commit

Permalink
kvm: Introduce kvm_arch_get_default_type hook
Browse files Browse the repository at this point in the history
kvm_arch_get_default_type() returns the default KVM type. This hook is
particularly useful to derive a KVM type that is valid for "none"
machine model, which is used by libvirt to probe the availability of
KVM.

For MIPS, the existing mips_kvm_type() is reused. This function ensures
the availability of VZ which is mandatory to use KVM on the current
QEMU.

Cc: qemu-stable@nongnu.org
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-id: 20230727073134.134102-2-akihiko.odaki@daynix.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[PMM: added doc comment for new function]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 5e0d659)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
akihikodaki authored and Michael Tokarev committed Sep 10, 2023
1 parent f2f8e74 commit aa15271
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 13 deletions.
4 changes: 3 additions & 1 deletion accel/kvm/kvm-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ static int kvm_init(MachineState *ms)
KVMState *s;
const KVMCapabilityInfo *missing_cap;
int ret;
int type = 0;
int type;
uint64_t dirty_log_manual_caps;

qemu_mutex_init(&kml_slots_lock);
Expand Down Expand Up @@ -2447,6 +2447,8 @@ static int kvm_init(MachineState *ms)
type = mc->kvm_type(ms, kvm_type);
} else if (mc->kvm_type) {
type = mc->kvm_type(ms, NULL);
} else {
type = kvm_arch_get_default_type(ms);
}

do {
Expand Down
2 changes: 0 additions & 2 deletions hw/mips/loongson3_virt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "qemu/datadir.h"
#include "qapi/error.h"
#include "elf.h"
#include "kvm_mips.h"
#include "hw/char/serial.h"
#include "hw/intc/loongson_liointc.h"
#include "hw/mips/mips.h"
Expand Down Expand Up @@ -617,7 +616,6 @@ static void loongson3v_machine_class_init(ObjectClass *oc, void *data)
mc->max_cpus = LOONGSON_MAX_VCPUS;
mc->default_ram_id = "loongson3.highram";
mc->default_ram_size = 1600 * MiB;
mc->kvm_type = mips_kvm_type;
mc->minimum_page_bits = 14;
}

Expand Down
2 changes: 2 additions & 0 deletions include/sysemu/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ int kvm_arch_get_registers(CPUState *cpu);

int kvm_arch_put_registers(CPUState *cpu, int level);

int kvm_arch_get_default_type(MachineState *ms);

int kvm_arch_init(MachineState *ms, KVMState *s);

int kvm_arch_init_vcpu(CPUState *cpu);
Expand Down
5 changes: 5 additions & 0 deletions target/arm/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ int kvm_arm_get_max_vm_ipa_size(MachineState *ms, bool *fixed_ipa)
return ret > 0 ? ret : 40;
}

int kvm_arch_get_default_type(MachineState *ms)
{
return 0;
}

int kvm_arch_init(MachineState *ms, KVMState *s)
{
int ret = 0;
Expand Down
5 changes: 5 additions & 0 deletions target/i386/kvm/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,11 @@ static void register_smram_listener(Notifier *n, void *unused)
&smram_address_space, 1, "kvm-smram");
}

int kvm_arch_get_default_type(MachineState *ms)
{
return 0;
}

int kvm_arch_init(MachineState *ms, KVMState *s)
{
uint64_t identity_base = 0xfffbc000;
Expand Down
2 changes: 1 addition & 1 deletion target/mips/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)
abort();
}

int mips_kvm_type(MachineState *machine, const char *vm_type)
int kvm_arch_get_default_type(MachineState *machine)
{
#if defined(KVM_CAP_MIPS_VZ)
int r;
Expand Down
9 changes: 0 additions & 9 deletions target/mips/kvm_mips.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,4 @@ void kvm_mips_reset_vcpu(MIPSCPU *cpu);
int kvm_mips_set_interrupt(MIPSCPU *cpu, int irq, int level);
int kvm_mips_set_ipi_interrupt(MIPSCPU *cpu, int irq, int level);

#ifdef CONFIG_KVM
int mips_kvm_type(MachineState *machine, const char *vm_type);
#else
static inline int mips_kvm_type(MachineState *machine, const char *vm_type)
{
return 0;
}
#endif

#endif /* KVM_MIPS_H */
5 changes: 5 additions & 0 deletions target/ppc/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ static int kvm_ppc_register_host_cpu_type(void);
static void kvmppc_get_cpu_characteristics(KVMState *s);
static int kvmppc_get_dec_bits(void);

int kvm_arch_get_default_type(MachineState *ms)
{
return 0;
}

int kvm_arch_init(MachineState *ms, KVMState *s)
{
cap_interrupt_unset = kvm_check_extension(s, KVM_CAP_PPC_UNSET_IRQ);
Expand Down
5 changes: 5 additions & 0 deletions target/riscv/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route,
return 0;
}

int kvm_arch_get_default_type(MachineState *ms)
{
return 0;
}

int kvm_arch_init(MachineState *ms, KVMState *s)
{
return 0;
Expand Down
5 changes: 5 additions & 0 deletions target/s390x/kvm/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ static void ccw_machine_class_foreach(ObjectClass *oc, void *opaque)
mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
}

int kvm_arch_get_default_type(MachineState *ms)
{
return 0;
}

int kvm_arch_init(MachineState *ms, KVMState *s)
{
object_class_foreach(ccw_machine_class_foreach, TYPE_S390_CCW_MACHINE,
Expand Down

0 comments on commit aa15271

Please sign in to comment.