[PATCH] KVM: Re-export kvm_enable_virtualization() and kvm_disable_virtualization() as normal (global) exports rather than only to KVM's vendor modules

Ramshankar Venkataraman posted 1 patch 3 months, 2 weeks ago
virt/kvm/kvm_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] KVM: Re-export kvm_enable_virtualization() and kvm_disable_virtualization() as normal (global) exports rather than only to KVM's vendor modules
Posted by Ramshankar Venkataraman 3 months, 2 weeks ago
Starting with 6.12.0 (3efc57369a0ce8f76bf0804f7e673982384e4ac9) KVM modules
enabled virtualization in hardware during module init rather than when the
first VM is started. This meant that VirtualBox users had to manually
unload/disable KVM modules in-order to use VirtualBox.

Starting with 6.16.0, kvm_enable_virtualization() and
kvm_disable_virtualization() functions were exported. VirtualBox made use
of these functions so our users did not need to unload/disable KVM kernel
modules in-order to use VirtualBox. This made it possible to run KVM and
VirtualBox side by side.

Starting with 6.18-rc1, commit 20c48920583675e67b3824f147726e0fbda735ce
("KVM: Export KVM-internal symbols for sub-modules only") removed the
global export of these functions effectively disallowing third-party code
from using them. Users of VirtualBox would be back to unloading/disabling
KVM modules themselves.

This patch re-exports these 2 functions as normal (global) exports which
VirtualBox could use. It would greatly simplify life for users, especially
when switching between KVM and VirtualBox.

Signed-off-by: Ramshankar Venkataraman <ramshankar.venkataraman@oracle.com>
---
 virt/kvm/kvm_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index b7a0ae2a7b20..0abfcb4d2e82 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5723,7 +5723,7 @@ int kvm_enable_virtualization(void)
 	--kvm_usage_count;
 	return r;
 }
-EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_enable_virtualization);
+EXPORT_SYMBOL_GPL(kvm_enable_virtualization);
 
 void kvm_disable_virtualization(void)
 {
@@ -5736,7 +5736,7 @@ void kvm_disable_virtualization(void)
 	cpuhp_remove_state(CPUHP_AP_KVM_ONLINE);
 	kvm_arch_disable_virtualization();
 }
-EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_disable_virtualization);
+EXPORT_SYMBOL_GPL(kvm_disable_virtualization);
 
 static int kvm_init_virtualization(void)
 {
-- 
2.51.0
Re: [PATCH] KVM: Re-export kvm_enable_virtualization() and kvm_disable_virtualization() as normal (global) exports rather than only to KVM's vendor modules
Posted by Christoph Hellwig 3 months, 2 weeks ago
On Fri, Oct 24, 2025 at 06:08:38PM +0530, Ramshankar Venkataraman wrote:
> Starting with 6.12.0 (3efc57369a0ce8f76bf0804f7e673982384e4ac9) KVM modules
> enabled virtualization in hardware during module init rather than when the
> first VM is started. This meant that VirtualBox users had to manually
> unload/disable KVM modules in-order to use VirtualBox.
> 
> Starting with 6.16.0, kvm_enable_virtualization() and
> kvm_disable_virtualization() functions were exported. VirtualBox made use
> of these functions so our users did not need to unload/disable KVM kernel
> modules in-order to use VirtualBox. This made it possible to run KVM and
> VirtualBox side by side.

So?  We never export modules for out of tree drivers.  This should be
a reminder to the virtualbox project that they really should have
switched to using the kvm kernel code 10 years ago instead of wasting
time on their own buggy version.  They managed to get that memo on
other platforms the hard way, and maybe this is the final wink for
Linux for folks to understand.