diff mbox series

[4/4] KVM: Rename functions related to enabling virtualization hardware

Message ID 20240425233951.3344485-5-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: Register cpuhp/syscore callbacks when enabling virt | expand

Commit Message

Sean Christopherson April 25, 2024, 11:39 p.m. UTC
Rename the various functions 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.
Instead, use double-underscores to communicate that the per-CPU functions
are helpers to the outer APIs.

Prepend "kvm" to all functions to prepare for exposing the outermost
enable/disable APIs to external users (Intel's TDX needs to enable
virtualization during KVM initialization).

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.

E.g. calling kvm_hardware_enable() or kvm_hardware_enable_all() from
TDX code is less intuitive than kvm_enable_virtualization().

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 virt/kvm/kvm_main.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

Comments

Huang, Kai May 13, 2024, 12:59 p.m. UTC | #1
On Thu, 2024-04-25 at 16:39 -0700, Sean Christopherson wrote:
> Rename the various functions 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.
> Instead, use double-underscores to communicate that the per-CPU functions
> are helpers to the outer APIs.
> 

I kinda prefer

	cpu_enable_virtualization();

instead of

	__kvm_enable_virtualization();

But obviously not a strong opinion :-)
Sean Christopherson May 13, 2024, 4:20 p.m. UTC | #2
On Mon, May 13, 2024, Kai Huang wrote:
> On Thu, 2024-04-25 at 16:39 -0700, Sean Christopherson wrote:
> > Rename the various functions 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.
> > Instead, use double-underscores to communicate that the per-CPU functions
> > are helpers to the outer APIs.
> > 
> 
> I kinda prefer
> 
> 	cpu_enable_virtualization();
> 
> instead of
> 
> 	__kvm_enable_virtualization();
> 
> But obviously not a strong opinion :-)

I feel quite strongly about using __kvm_enable_virtualization().  While "cpu" is
very precise, to me it implies that the code lives outside of KVM and isn't purely
a helper for kvm_enable_virtualization().
diff mbox series

Patch

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index ad1b5a9e86d4..7579bda0e310 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -139,8 +139,8 @@  static int kvm_no_compat_open(struct inode *inode, struct file *file)
 #define KVM_COMPAT(c)	.compat_ioctl	= kvm_no_compat_ioctl,	\
 			.open		= kvm_no_compat_open
 #endif
-static int hardware_enable_all(void);
-static void hardware_disable_all(void);
+static int kvm_enable_virtualization(void);
+static void kvm_disable_virtualization(void);
 
 static void kvm_io_bus_destroy(struct kvm_io_bus *bus);
 
@@ -1213,7 +1213,7 @@  static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
 	if (r)
 		goto out_err_no_arch_destroy_vm;
 
-	r = hardware_enable_all();
+	r = kvm_enable_virtualization();
 	if (r)
 		goto out_err_no_disable;
 
@@ -1256,7 +1256,7 @@  static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
 		mmu_notifier_unregister(&kvm->mmu_notifier, current->mm);
 #endif
 out_err_no_mmu_notifier:
-	hardware_disable_all();
+	kvm_disable_virtualization();
 out_err_no_disable:
 	kvm_arch_destroy_vm(kvm);
 out_err_no_arch_destroy_vm:
@@ -1345,7 +1345,7 @@  static void kvm_destroy_vm(struct kvm *kvm)
 #endif
 	kvm_arch_free_vm(kvm);
 	preempt_notifier_dec();
-	hardware_disable_all();
+	kvm_disable_virtualization();
 	mmdrop(mm);
 }
 
@@ -5490,7 +5490,7 @@  EXPORT_SYMBOL_GPL(kvm_rebooting);
 static DEFINE_PER_CPU(bool, hardware_enabled);
 static int kvm_usage_count;
 
-static int hardware_enable_nolock(void)
+static int __kvm_enable_virtualization(void)
 {
 	if (__this_cpu_read(hardware_enabled))
 		return 0;
@@ -5512,10 +5512,10 @@  static int kvm_online_cpu(unsigned int cpu)
 	 * be enabled. Otherwise running VMs would encounter unrecoverable
 	 * errors when scheduled to this CPU.
 	 */
-	return hardware_enable_nolock();
+	return __kvm_enable_virtualization();
 }
 
-static void hardware_disable_nolock(void *ign)
+static void __kvm_disable_virtualization(void *ign)
 {
 	if (!__this_cpu_read(hardware_enabled))
 		return;
@@ -5527,7 +5527,7 @@  static void hardware_disable_nolock(void *ign)
 
 static int kvm_offline_cpu(unsigned int cpu)
 {
-	hardware_disable_nolock(NULL);
+	__kvm_disable_virtualization(NULL);
 	return 0;
 }
 
@@ -5546,7 +5546,7 @@  static void kvm_shutdown(void)
 	 */
 	pr_info("kvm: exiting hardware virtualization\n");
 	kvm_rebooting = true;
-	on_each_cpu(hardware_disable_nolock, NULL, 1);
+	on_each_cpu(__kvm_disable_virtualization, NULL, 1);
 }
 
 static int kvm_suspend(void)
@@ -5562,7 +5562,7 @@  static int kvm_suspend(void)
 	lockdep_assert_not_held(&kvm_lock);
 	lockdep_assert_irqs_disabled();
 
-	hardware_disable_nolock(NULL);
+	__kvm_disable_virtualization(NULL);
 	return 0;
 }
 
@@ -5571,7 +5571,7 @@  static void kvm_resume(void)
 	lockdep_assert_not_held(&kvm_lock);
 	lockdep_assert_irqs_disabled();
 
-	WARN_ON_ONCE(hardware_enable_nolock());
+	WARN_ON_ONCE(__kvm_enable_virtualization());
 }
 
 static struct syscore_ops kvm_syscore_ops = {
@@ -5580,7 +5580,7 @@  static struct syscore_ops kvm_syscore_ops = {
 	.shutdown = kvm_shutdown,
 };
 
-static int hardware_enable_all(void)
+static int kvm_enable_virtualization(void)
 {
 	int r;
 
@@ -5617,7 +5617,7 @@  static int hardware_enable_all(void)
 	return 0;
 }
 
-static void hardware_disable_all(void)
+static void kvm_disable_virtualization(void)
 {
 	guard(mutex)(&kvm_lock);
 
@@ -5628,12 +5628,12 @@  static void hardware_disable_all(void)
 	cpuhp_remove_state(CPUHP_AP_KVM_ONLINE);
 }
 #else /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */
-static int hardware_enable_all(void)
+static int kvm_enable_virtualization(void)
 {
 	return 0;
 }
 
-static void hardware_disable_all(void)
+static void kvm_disable_virtualization(void)
 {
 
 }