Skip to content

Commit 70c0194

Browse files
sean-jcbonzini
authored andcommitted
KVM: Rename symbols related to enabling virtualization hardware
Rename the various functions (and a variable) that enable virtualization to prepare for upcoming changes, and to clean up artifacts of KVM's previous behavior, which required manually juggling locks around kvm_usage_count. Drop the "nolock" qualifier from per-CPU functions now that there are no "nolock" implementations of the "all" variants, i.e. now that calling a non-nolock function from a nolock function isn't confusing (unlike this sentence). Drop "all" from the outer helpers as they no longer manually iterate over all CPUs, and because it might not be obvious what "all" refers to. In lieu of the above qualifiers, append "_cpu" to the end of the functions that are per-CPU helpers for the outer APIs. Opportunistically prepend "kvm" to all functions to help make it clear that they are KVM helpers, but mostly because there's no reason not to. Lastly, use "virtualization" instead of "hardware", because while the functions do enable virtualization in hardware, there are a _lot_ of things that KVM enables in hardware. Defer renaming the arch hooks to future patches, purely to reduce the amount of churn in a single commit. Reviewed-by: Chao Gao <[email protected]> Reviewed-by: Kai Huang <[email protected]> Acked-by: Kai Huang <[email protected]> Tested-by: Farrah Chen <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 9a798b1 commit 70c0194

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

virt/kvm/kvm_main.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ static int kvm_no_compat_open(struct inode *inode, struct file *file)
136136
#define KVM_COMPAT(c) .compat_ioctl = kvm_no_compat_ioctl, \
137137
.open = kvm_no_compat_open
138138
#endif
139-
static int hardware_enable_all(void);
140-
static void hardware_disable_all(void);
139+
static int kvm_enable_virtualization(void);
140+
static void kvm_disable_virtualization(void);
141141

142142
static void kvm_io_bus_destroy(struct kvm_io_bus *bus);
143143

@@ -1220,7 +1220,7 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
12201220
if (r)
12211221
goto out_err_no_arch_destroy_vm;
12221222

1223-
r = hardware_enable_all();
1223+
r = kvm_enable_virtualization();
12241224
if (r)
12251225
goto out_err_no_disable;
12261226

@@ -1263,7 +1263,7 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
12631263
mmu_notifier_unregister(&kvm->mmu_notifier, current->mm);
12641264
#endif
12651265
out_err_no_mmu_notifier:
1266-
hardware_disable_all();
1266+
kvm_disable_virtualization();
12671267
out_err_no_disable:
12681268
kvm_arch_destroy_vm(kvm);
12691269
out_err_no_arch_destroy_vm:
@@ -1360,7 +1360,7 @@ static void kvm_destroy_vm(struct kvm *kvm)
13601360
#endif
13611361
kvm_arch_free_vm(kvm);
13621362
preempt_notifier_dec();
1363-
hardware_disable_all();
1363+
kvm_disable_virtualization();
13641364
mmdrop(mm);
13651365
}
13661366

@@ -5574,13 +5574,13 @@ static struct miscdevice kvm_dev = {
55745574
__visible bool kvm_rebooting;
55755575
EXPORT_SYMBOL_GPL(kvm_rebooting);
55765576

5577-
static DEFINE_PER_CPU(bool, hardware_enabled);
5577+
static DEFINE_PER_CPU(bool, virtualization_enabled);
55785578
static DEFINE_MUTEX(kvm_usage_lock);
55795579
static int kvm_usage_count;
55805580

5581-
static int hardware_enable_nolock(void)
5581+
static int kvm_enable_virtualization_cpu(void)
55825582
{
5583-
if (__this_cpu_read(hardware_enabled))
5583+
if (__this_cpu_read(virtualization_enabled))
55845584
return 0;
55855585

55865586
if (kvm_arch_hardware_enable()) {
@@ -5589,7 +5589,7 @@ static int hardware_enable_nolock(void)
55895589
return -EIO;
55905590
}
55915591

5592-
__this_cpu_write(hardware_enabled, true);
5592+
__this_cpu_write(virtualization_enabled, true);
55935593
return 0;
55945594
}
55955595

@@ -5600,22 +5600,22 @@ static int kvm_online_cpu(unsigned int cpu)
56005600
* be enabled. Otherwise running VMs would encounter unrecoverable
56015601
* errors when scheduled to this CPU.
56025602
*/
5603-
return hardware_enable_nolock();
5603+
return kvm_enable_virtualization_cpu();
56045604
}
56055605

5606-
static void hardware_disable_nolock(void *junk)
5606+
static void kvm_disable_virtualization_cpu(void *ign)
56075607
{
5608-
if (!__this_cpu_read(hardware_enabled))
5608+
if (!__this_cpu_read(virtualization_enabled))
56095609
return;
56105610

56115611
kvm_arch_hardware_disable();
56125612

5613-
__this_cpu_write(hardware_enabled, false);
5613+
__this_cpu_write(virtualization_enabled, false);
56145614
}
56155615

56165616
static int kvm_offline_cpu(unsigned int cpu)
56175617
{
5618-
hardware_disable_nolock(NULL);
5618+
kvm_disable_virtualization_cpu(NULL);
56195619
return 0;
56205620
}
56215621

@@ -5634,7 +5634,7 @@ static void kvm_shutdown(void)
56345634
*/
56355635
pr_info("kvm: exiting hardware virtualization\n");
56365636
kvm_rebooting = true;
5637-
on_each_cpu(hardware_disable_nolock, NULL, 1);
5637+
on_each_cpu(kvm_disable_virtualization_cpu, NULL, 1);
56385638
}
56395639

56405640
static int kvm_suspend(void)
@@ -5650,7 +5650,7 @@ static int kvm_suspend(void)
56505650
lockdep_assert_not_held(&kvm_usage_lock);
56515651
lockdep_assert_irqs_disabled();
56525652

5653-
hardware_disable_nolock(NULL);
5653+
kvm_disable_virtualization_cpu(NULL);
56545654
return 0;
56555655
}
56565656

@@ -5659,7 +5659,7 @@ static void kvm_resume(void)
56595659
lockdep_assert_not_held(&kvm_usage_lock);
56605660
lockdep_assert_irqs_disabled();
56615661

5662-
WARN_ON_ONCE(hardware_enable_nolock());
5662+
WARN_ON_ONCE(kvm_enable_virtualization_cpu());
56635663
}
56645664

56655665
static struct syscore_ops kvm_syscore_ops = {
@@ -5668,7 +5668,7 @@ static struct syscore_ops kvm_syscore_ops = {
56685668
.shutdown = kvm_shutdown,
56695669
};
56705670

5671-
static int hardware_enable_all(void)
5671+
static int kvm_enable_virtualization(void)
56725672
{
56735673
int r;
56745674

@@ -5711,7 +5711,7 @@ static int hardware_enable_all(void)
57115711
return r;
57125712
}
57135713

5714-
static void hardware_disable_all(void)
5714+
static void kvm_disable_virtualization(void)
57155715
{
57165716
guard(mutex)(&kvm_usage_lock);
57175717

@@ -5722,12 +5722,12 @@ static void hardware_disable_all(void)
57225722
cpuhp_remove_state(CPUHP_AP_KVM_ONLINE);
57235723
}
57245724
#else /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */
5725-
static int hardware_enable_all(void)
5725+
static int kvm_enable_virtualization(void)
57265726
{
57275727
return 0;
57285728
}
57295729

5730-
static void hardware_disable_all(void)
5730+
static void kvm_disable_virtualization(void)
57315731
{
57325732

57335733
}

0 commit comments

Comments
 (0)