diff mbox series

[7/7] accel/kvm: Exit gracefully when KVM is not supported

Message ID 20210219114428.1936109-8-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series hw/kvm: Exit gracefully when KVM is not supported | expand

Commit Message

Philippe Mathieu-Daudé Feb. 19, 2021, 11:44 a.m. UTC
Now that we added the 'kvm_supported' field to MachineClass
and all our machines able to use KVM have this field set,
we can check it in kvm_init() and exit gracefully with
a friendly error message.


  $ qemu-system-aarch64 -M raspi3b -enable-kvm
  qemu-system-aarch64: /build/qemu-ETIdrs/qemu-4.2/exec.c:865: cpu_address_space_init: Assertion `asidx == 0 || !kvm_enabled()' failed.

  $ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6
  qemu-system-aarch64: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argument


  $ qemu-system-aarch64 -M raspi3b -enable-kvm
  Machine 'raspi3b' does not support KVM

  $ qemu-system-aarch64 -M xlnx-zcu102 -enable-kvm -smp 6
  Machine 'xlnx-zcu102' does not support KVM

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
 accel/kvm/kvm-all.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series


diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index b069938d881..8a8d3f64248 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2001,6 +2001,12 @@  static int kvm_init(MachineState *ms)
     s = KVM_STATE(ms->accelerator);
+    if (!mc->kvm_supported) {
+        ret = -EINVAL;
+        fprintf(stderr, "Machine '%s' does not support KVM\n", mc->name);
+        exit(1);
+    }
      * On systems where the kernel can support different base page
      * sizes, host page size may be different from TARGET_PAGE_SIZE,