[PATCH 2/2] KVM: x86: Defer "already loaded" check until after basic support checks

From: Sean Christopherson
Date: Mon Oct 18 2021 - 14:39:47 EST


Move KVM's check for a vendor module already being loaded below the basic
functionality checks so that attempting to load an unsupported module
provides the same result regardless of whether or not a supported vendor
module is already loaded.

Intentionally keep the err non-ratelimited; if userspace is probing two
different modules for the same vendor on all CPUs, it deserves the spam.

Reported-by: Paul Menzel <pmenzel@xxxxxxxxxxxxx>
Cc: Maciej S. Szmigiero <mail@xxxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/x86.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e966e9cdd805..f67da77be267 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8538,12 +8538,6 @@ int kvm_arch_init(void *opaque)
struct kvm_x86_init_ops *ops = opaque;
int r;

- if (kvm_x86_ops.hardware_enable) {
- 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 for '%s'\n",
ops->runtime_ops->name);
@@ -8556,6 +8550,11 @@ int kvm_arch_init(void *opaque)
r = -EOPNOTSUPP;
goto out;
}
+ if (kvm_x86_ops.hardware_enable) {
+ pr_err("kvm: already loaded vendor module '%s'\n", kvm_x86_ops.name);
+ r = -EEXIST;
+ goto out;
+ }

/*
* KVM explicitly assumes that the guest has an FPU and
--
2.33.0.1079.g6e70778dc9-goog