[RFC PATCH 17/18] KVM: x86: Remove cpus_hardware_enabled and related sanity check

From: isaku . yamahata
Date: Sat Aug 20 2022 - 02:02:14 EST


From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>

cpus_hardware_enabled mask seems incomplete protection against other kernel
component using CPU virtualization feature. Because it's obscure and
incomplete, remove the check.

Signed-off-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
---
arch/x86/kvm/x86.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5aa6d5308ee8..f43caa8919ea 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11830,22 +11830,15 @@ void kvm_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector)
}
EXPORT_SYMBOL_GPL(kvm_vcpu_deliver_sipi_vector);

-static cpumask_t cpus_hardware_enabled = CPU_MASK_NONE;
-
static int __hardware_enable(void)
{
- int cpu = raw_smp_processor_id();
int r;

WARN_ON_ONCE(preemptible());

- if (cpumask_test_cpu(cpu, &cpus_hardware_enabled))
- return 0;
r = static_call(kvm_x86_hardware_enable)();
if (r)
- pr_info("kvm: enabling virtualization on CPU%d failed\n", cpu);
- else
- cpumask_set_cpu(cpu, &cpus_hardware_enabled);
+ pr_info("kvm: enabling virtualization on CPU%d failed\n", smp_processor_id());
return r;
}

@@ -11859,13 +11852,7 @@ static void hardware_enable(void *arg)

static void hardware_disable(void *junk)
{
- int cpu = raw_smp_processor_id();
-
WARN_ON_ONCE(preemptible());
-
- if (!cpumask_test_cpu(cpu, &cpus_hardware_enabled))
- return;
- cpumask_clear_cpu(cpu, &cpus_hardware_enabled);
static_call(kvm_x86_hardware_disable)();
drop_user_return_notifiers();
}
--
2.25.1