KVM: x86: Add vendor name to kvm_x86_ops, use it for error messages
authorSean Christopherson <seanjc@google.com>
Mon, 18 Oct 2021 18:39:28 +0000 (11:39 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 22 Oct 2021 09:19:28 +0000 (05:19 -0400)
Paul pointed out the error messages when KVM fails to load are unhelpful
in understanding exactly what went wrong if userspace probes the "wrong"
module.

Add a mandatory kvm_x86_ops field to track vendor module names, kvm_intel
and kvm_amd, and use the name for relevant error message when KVM fails
to load so that the user knows which module failed to load.

Opportunistically tweak the "disabled by bios" error message to clarify
that _support_ was disabled, not that the module itself was magically
disabled by BIOS.

Suggested-by: Paul Menzel <pmenzel@molgen.mpg.de>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20211018183929.897461-2-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm/svm.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c

index 1c523b5c99d1386dc5ad9ca0df1db75c84b918ce..d41699e89d1f8e81d3f8ffaf575b2b45be543ca3 100644 (file)
@@ -1301,6 +1301,8 @@ static inline u16 kvm_lapic_irq_dest_mode(bool dest_mode_logical)
 }
 
 struct kvm_x86_ops {
+       const char *name;
+
        int (*hardware_enable)(void);
        void (*hardware_disable)(void);
        void (*hardware_unsetup)(void);
index 89077160d463f205b6bf5579411b052f925ce6ab..cee4915d2ce3f5c9b6b52d90d2e5a261840e16f4 100644 (file)
@@ -4580,6 +4580,8 @@ static int svm_vm_init(struct kvm *kvm)
 }
 
 static struct kvm_x86_ops svm_x86_ops __initdata = {
+       .name = "kvm_amd",
+
        .hardware_unsetup = svm_hardware_teardown,
        .hardware_enable = svm_hardware_enable,
        .hardware_disable = svm_hardware_disable,
index 79d6af09dbf420123d1c7a56b3fe017e33bad5b3..2f677e72d864805ad0c6eb1397ed971e24878c41 100644 (file)
@@ -7570,6 +7570,8 @@ static bool vmx_check_apicv_inhibit_reasons(ulong bit)
 }
 
 static struct kvm_x86_ops vmx_x86_ops __initdata = {
+       .name = "kvm_intel",
+
        .hardware_unsetup = hardware_unsetup,
 
        .hardware_enable = hardware_enable,
index ac6d31ec909f1a116a47bf087c35cb8842e0e1a9..ac386c085dd087c7e3e7471f29df203d43480025 100644 (file)
@@ -8532,18 +8532,20 @@ int kvm_arch_init(void *opaque)
        int r;
 
        if (kvm_x86_ops.hardware_enable) {
-               printk(KERN_ERR "kvm: already loaded the other module\n");
+               pr_err("kvm: already loaded vendor module '%s'\n", kvm_x86_ops.name);
                r = -EEXIST;
                goto out;
        }
 
        if (!ops->cpu_has_kvm_support()) {
-               pr_err_ratelimited("kvm: no hardware support\n");
+               pr_err_ratelimited("kvm: no hardware support for '%s'\n",
+                                  ops->runtime_ops->name);
                r = -EOPNOTSUPP;
                goto out;
        }
        if (ops->disabled_by_bios()) {
-               pr_err_ratelimited("kvm: disabled by bios\n");
+               pr_err_ratelimited("kvm: support for '%s' disabled by bios\n",
+                                  ops->runtime_ops->name);
                r = -EOPNOTSUPP;
                goto out;
        }