@@ -105,7 +105,6 @@ LIST_HEAD(vm_list);
static cpumask_t cpus_hardware_enabled = CPU_MASK_NONE;
static int kvm_usage_count;
-static atomic_t hardware_enable_failed;
static struct kmem_cache *kvm_vcpu_cache;
@@ -5007,30 +5006,36 @@ static struct miscdevice kvm_dev = {
&kvm_chardev_ops,
};
-static void hardware_enable_nolock(void *junk)
+static int __hardware_enable_nolock(void)
{
int cpu = raw_smp_processor_id();
int r;
- if (cpumask_test_cpu(cpu, &cpus_hardware_enabled))
- return;
-
- cpumask_set_cpu(cpu, &cpus_hardware_enabled);
+ if (cpumask_test_and_set_cpu(cpu, &cpus_hardware_enabled))
+ return 0;
r = kvm_arch_hardware_enable();
if (r) {
cpumask_clear_cpu(cpu, &cpus_hardware_enabled);
- atomic_inc(&hardware_enable_failed);
pr_info("kvm: enabling virtualization on CPU%d failed\n", cpu);
}
+ return r;
+}
+
+static void hardware_enable_nolock(void *arg)
+{
+ atomic_t *failed = arg;
+
+ if (__hardware_enable_nolock())
+ atomic_inc(failed);
}
static int kvm_starting_cpu(unsigned int cpu)
{
raw_spin_lock(&kvm_count_lock);
if (kvm_usage_count)
- hardware_enable_nolock(NULL);
+ (void)__hardware_enable_nolock();
raw_spin_unlock(&kvm_count_lock);
return 0;
}
@@ -5072,16 +5077,16 @@ static void hardware_disable_all(void)
static int hardware_enable_all(void)
{
+ atomic_t failed = ATOMIC_INIT(0);
int r = 0;
raw_spin_lock(&kvm_count_lock);
kvm_usage_count++;
if (kvm_usage_count == 1) {
- atomic_set(&hardware_enable_failed, 0);
- on_each_cpu(hardware_enable_nolock, NULL, 1);
+ on_each_cpu(hardware_enable_nolock, &failed, 1);
- if (atomic_read(&hardware_enable_failed)) {
+ if (atomic_read(&failed)) {
hardware_disable_all_nolock();
r = -EBUSY;
}
@@ -5702,7 +5707,7 @@ static void kvm_resume(void)
{
if (kvm_usage_count) {
lockdep_assert_not_held(&kvm_count_lock);
- hardware_enable_nolock(NULL);
+ (void)__hardware_enable_nolock();
}
}