KVM: Export KVM-internal symbols for sub-modules only
Sean Christopherson
maintainerv2 cover KVM: Export KVM-internal symbols for sub-modules only
Use the newfangled EXPORT_SYMBOL_FOR_MODULES() along with some macro shenanigans to export KVM-internal symbols if and only if KVM has one or more sub-modules, and only for those sub-modules, e.g. x86's kvm-amd.ko and/or kvm-intel.ko.
Patch 5 gives KVM x86 the full treatment. If anyone wants to tackle PPC, it should be doable to restrict KVM PPC's exports as well.
Based on kvm-x86. My plan is to take this through the KVM x86 tree as there's an annoying conflict with an in-flight patch, and except for the vfio-ap change that's been acked, PPC is the only other architecture that's at all affected, and KVM PPC is maintained separately.
v2:
- Omit the x86 patch, for now.
- Drop "GPL" from KVM's macro to match EXPORT_SYMBOL_FOR_MODULES. [Vlastimil]
v1: https://lkml.kernel.org/r/20250729174238.593070-1-seanjc%40google.com
Sean Christopherson (5):
KVM: s390/vfio-ap: Use kvm_is_gpa_in_memslot() instead of open coded
equivalent
KVM: Export KVM-internal symbols for sub-modules only
KVM: x86: Move kvm_intr_is_single_vcpu() to lapic.c
KVM: x86: Drop pointless exports of kvm_arch_xxx() hooks
KVM: x86: Export KVM-internal symbols for sub-modules only
arch/powerpc/include/asm/kvm_types.h | 15 ++ arch/s390/include/asm/kvm_host.h | 2 + arch/s390/kvm/priv.c | 8 + arch/x86/include/asm/kvm_host.h | 3 - arch/x86/include/asm/kvm_types.h | 10 ++ arch/x86/kvm/cpuid.c | 10 +- arch/x86/kvm/hyperv.c | 4 +- arch/x86/kvm/irq.c | 34 +---- arch/x86/kvm/kvm_onhyperv.c | 6 +- arch/x86/kvm/lapic.c | 71 ++++++--- arch/x86/kvm/lapic.h | 4 +- arch/x86/kvm/mmu/mmu.c | 36 ++--- arch/x86/kvm/mmu/spte.c | 10 +- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- arch/x86/kvm/pmu.c | 10 +- arch/x86/kvm/smm.c | 2 +- arch/x86/kvm/x86.c | 219 +++++++++++++-------------- drivers/s390/crypto/vfio_ap_ops.c | 2 +- include/linux/kvm_types.h | 25 ++- virt/kvm/eventfd.c | 2 +- virt/kvm/guest_memfd.c | 4 +- virt/kvm/kvm_main.c | 128 ++++++++-------- 22 files changed, 324 insertions(+), 283 deletions(-) create mode 100644 arch/powerpc/include/asm/kvm_types.h
base-commit: c8fbf7ceb2ae3f64b0c377c8c21f6df577a13eb4
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
Sean Christopherson
maintainerPATCH v2 1/5 KVM: s390/vfio-ap: Use kvm_is_gpa_in_memslot() instead of open coded equivalent
Use kvm_is_gpa_in_memslot() to check the validity of the notification indicator byte address instead of open coding equivalent logic in the VFIO AP driver.
Opportunistically use a dedicated wrapper that exists and is exported expressly for the VFIO AP module. kvm_is_gpa_in_memslot() is generally unsuitable for use outside of KVM; other drivers typically shouldn't rely on KVM's memslots, and using the API requires kvm->srcu (or slots_lock) to be held for the entire duration of the usage, e.g. to avoid TOCTOU bugs. handle_pqap() is a bit of a special case, as it's explicitly invoked from KVM with kvm->srcu already held, and the VFIO AP driver is in many ways an extension of KVM that happens to live in a separate module.
Providing a dedicated API for the VFIO AP driver will allow restricting the vast majority of generic KVM's exports to KVM submodules (e.g. to x86's kvm-{amd,intel}.ko vendor mdoules).
No functional change intended.
--- arch/s390/include/asm/kvm_host.h | 2 ++ arch/s390/kvm/priv.c | 8 ++++++++ drivers/s390/crypto/vfio_ap_ops.c | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-)
arch/s390/include/asm/kvm_host.h +2 -0
@@ -722,6 +722,8 @@ extern int kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,extern int kvm_s390_gisc_register (struct kvm *kvm,u32 gisc);extern int kvm_s390_gisc_unregister (struct kvm *kvm,u32 gisc); +bool kvm_s390_is_gpa_in_memslot (struct kvm *kvm,gpa_t gpa); +static inline void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *slot) {}static inline void kvm_arch_memslots_updated (struct kvm *kvm,u64 gen) {}
arch/s390/kvm/priv.c +8 -0
@@ -605,6 +605,14 @@ static int handle_io_inst(struct kvm_vcpu *vcpu) } } +#if IS_ENABLED (CONFIG_VFIO_AP ) +bool kvm_s390_is_gpa_in_memslot (struct kvm *kvm,gpa_t gpa) +{ +return kvm_is_gpa_in_memslot (kvm, gpa); +} +EXPORT_SYMBOL_FOR_MODULES (kvm_s390_is_gpa_in_memslot,"vfio_ap" ); +#endif +/* * handle_pqap: Handling pqap interception * @vcpu: the vcpu having issue the pqap instruction
drivers/s390/crypto/vfio_ap_ops.c +1 -1
@@ -354,7 +354,7 @@ static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, dma_addr_t *nib)if (!*nib)return -EINVAL ; -if (kvm_is_error_hva (gfn_to_hva (vcpu->kvm, *nib >>PAGE_SHIFT ))) +if (!kvm_s390_is_gpa_in_memslot (vcpu->kvm, *nib))return -EINVAL ;return 0 ;
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
Re: [PATCH v2 1/5] KVM: s390/vfio-ap: Use kvm_is_gpa_in_memslot() instead of open coded equivalent
Am 19.09.25 um 02:32 schrieb Sean Christopherson:
Quoted 13 lines
Use
kvm_is_gpa_in_memslot()to check the validity of the notification indicator byte address instead of open coding equivalent logic in the VFIO AP driver.Opportunistically use a dedicated wrapper that exists and is exported expressly for the VFIO AP module.
kvm_is_gpa_in_memslot()is generally unsuitable for use outside of KVM; other drivers typically shouldn't rely on KVM's memslots, and using the API requireskvm->srcu(orslots_lock) to be held for the entire duration of the usage, e.g. to avoid TOCTOU bugs.handle_pqap()is a bit of a special case, as it's explicitly invoked from KVM withkvm->srcualready held, and the VFIO AP driver is in many ways an extension of KVM that happens to live in a separate module.
Quoted 8 lines
Providing a dedicated API for the VFIO AP driver will allow restricting the vast majority of generic KVM's exports to KVM submodules (e.g. to x86's kvm-{amd,intel}.ko vendor mdoules).
No functional change intended.
Acked-by Anthony Krowiak <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Quoted 51 lines
--- arch/s390/include/asm/kvm_host.h | 2 ++ arch/s390/kvm/priv.c | 8 ++++++++ drivers/s390/crypto/vfio_ap_ops.c | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-)arch/s390/include/asm/kvm_host.h +2
-0@@ -722,6 +722,8 @@ extern int kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,extern int kvm_s390_gisc_register (struct kvm *kvm,u32 gisc);extern int kvm_s390_gisc_unregister (struct kvm *kvm,u32 gisc); +bool kvm_s390_is_gpa_in_memslot (struct kvm *kvm,gpa_t gpa); +static inline void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *slot) {}static inline void kvm_arch_memslots_updated (struct kvm *kvm,u64 gen) {}arch/s390/kvm/priv.c +8
-0@@ -605,6 +605,14 @@ static int handle_io_inst(struct kvm_vcpu *vcpu) } } +#if IS_ENABLED (CONFIG_VFIO_AP ) +bool kvm_s390_is_gpa_in_memslot (struct kvm *kvm,gpa_t gpa) +{ +return kvm_is_gpa_in_memslot (kvm, gpa); +} +EXPORT_SYMBOL_FOR_MODULES (kvm_s390_is_gpa_in_memslot,"vfio_ap" ); +#endif +/* * handle_pqap: Handling pqap interception * @vcpu: the vcpu having issue the pqap instruction drivers/s390/crypto/vfio_ap_ops.c +1
-1@@ -354,7 +354,7 @@ static int vfio_ap_validate_nib(struct kvm_vcpu *vcpu, dma_addr_t *nib)if (!*nib)return -EINVAL ; -if (kvm_is_error_hva (gfn_to_hva (vcpu->kvm, *nib >>PAGE_SHIFT ))) +if (!kvm_s390_is_gpa_in_memslot (vcpu->kvm, *nib))return -EINVAL ;return 0 ;
Sean Christopherson
maintainerPATCH v2 2/5 KVM: Export KVM-internal symbols for sub-modules only
In reply to Sean ChristophersonRework the vast majority of KVM's exports to expose symbols only to KVM submodules, i.e. to x86's kvm-{amd,intel}.ko and PPC's kvm-{pr,hv}.ko. With few exceptions, KVM's exported APIs are intended (and safe) for KVM- internal usage only.
Keep kvm_get_kvm(), kvm_get_kvm_safe(), and kvm_put_kvm() as normal exports, as they are needed by VFIO, and are generally safe for external usage (though ideally even the get/put APIs would be KVM-internal, and VFIO would pin a VM by grabbing a reference to its associated file).
Implement a framework in kvm_types.h in anticipation of providing a macro to restrict KVM-specific kernel exports, i.e. to provide symbol exports for KVM if and only if KVM is built as one or more modules.
--- arch/powerpc/include/asm/kvm_types.h | 15 ++++ arch/x86/include/asm/kvm_types.h | 10 +++ include/linux/kvm_types.h | 25 ++++-- virt/kvm/eventfd.c | 2 +- virt/kvm/guest_memfd.c | 4 +- virt/kvm/kvm_main.c | 128 +++++++++++++-------------- 6 files changed, 110 insertions(+), 74 deletions(-) create mode 100644 arch/powerpc/include/asm/kvm_types.h
arch/powerpc/include/asm/kvm_types.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_PPC_KVM_TYPES_H +#define _ASM_PPC_KVM_TYPES_H + +#if IS_MODULE (CONFIG_KVM_BOOK3S_64_PR ) &&IS_MODULE (CONFIG_KVM_BOOK3S_64_HV ) +#define KVM_SUB_MODULES kvm-pr,kvm-hv +#elif IS_MODULE (CONFIG_KVM_BOOK3S_64_PR ) +#define KVM_SUB_MODULES kvm-pr +#elif IS_MODULE (CONFIG_KVM_INTEL ) +#define KVM_SUB_MODULES kvm-hv +#else +#undef KVM_SUB_MODULES +#endif + +#endif
arch/x86/include/asm/kvm_types.h +10 -0
@@ -2,6 +2,16 @@#ifndef _ASM_X86_KVM_TYPES_H#define _ASM_X86_KVM_TYPES_H +#if IS_MODULE (CONFIG_KVM_AMD ) &&IS_MODULE (CONFIG_KVM_INTEL ) +#define KVM_SUB_MODULES kvm-amd,kvm-intel +#elif IS_MODULE (CONFIG_KVM_AMD ) +#define KVM_SUB_MODULES kvm-amd +#elif IS_MODULE (CONFIG_KVM_INTEL ) +#define KVM_SUB_MODULES kvm-intel +#else +#undef KVM_SUB_MODULES +#endif +#define KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE 40#endif /* _ASM_X86_KVM_TYPES_H */
include/linux/kvm_types.h +18 -7
@@ -3,6 +3,23 @@#ifndef __KVM_TYPES_H__#define __KVM_TYPES_H__ +#include <linux/bits.h> +#include <linux/export.h> +#include <linux/types.h> +#include <asm/kvm_types.h> + +#ifdef KVM_SUB_MODULES +#define EXPORT_SYMBOL_FOR_KVM_INTERNAL (symbol) \ + EXPORT_SYMBOL_FOR_MODULES(symbol, __stringify(KVM_SUB_MODULES)) +#else +#define EXPORT_SYMBOL_FOR_KVM_INTERNAL (symbol) +#endif + +#ifndef __ASSEMBLER__ + +#include <linux/mutex.h> +#include <linux/spinlock_types.h> +struct kvm ;struct kvm_async_pf ;struct kvm_device_ops ;
@@ -19,13 +36,6 @@ struct kvm_memslots;enum kvm_mr_change ; -#include <linux/bits.h> -#include <linux/mutex.h> -#include <linux/types.h> -#include <linux/spinlock_types.h> - -#include <asm/kvm_types.h> -/* * Address types: *
@@ -116,5 +126,6 @@ struct kvm_vcpu_stat_generic { };#define KVM_STATS_NAME_SIZE 48 +#endif /* !__ASSEMBLER__ */ #endif /* __KVM_TYPES_H__ */
virt/kvm/eventfd.c +1 -1
@@ -525,7 +525,7 @@ bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin)return false; } -EXPORT_SYMBOL_GPL (kvm_irq_has_notifier); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_irq_has_notifier);void kvm_notify_acked_gsi (struct kvm *kvm,int gsi) {
virt/kvm/guest_memfd.c +2 -2
@@ -702,7 +702,7 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot,fput (file);return r; } -EXPORT_SYMBOL_GPL (kvm_gmem_get_pfn); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_gmem_get_pfn);#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_POPULATE long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long npages,
@@ -784,5 +784,5 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, longfput (file); return ret && !i ? ret : i; } -EXPORT_SYMBOL_GPL (kvm_gmem_populate); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_gmem_populate);#endif
virt/kvm/kvm_main.c +64 -64
497 lines not on this page · raw message
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
Hi Sean,
Quoted 6 lines · Sean Christopherson
arch/powerpc/include/asm/kvm_types.h new file +0
-0
arch/powerpc/include/asm/kvm_types.h line 9
Quoted 9 lines
arch/powerpc/include/asm/kvm_types.h new file +9
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_PPC_KVM_TYPES_H +#define _ASM_PPC_KVM_TYPES_H + +#if IS_MODULE (CONFIG_KVM_BOOK3S_64_PR ) &&IS_MODULE (CONFIG_KVM_BOOK3S_64_HV ) +#define KVM_SUB_MODULES kvm-pr,kvm-hv +#elif IS_MODULE (CONFIG_KVM_BOOK3S_64_PR ) +#define KVM_SUB_MODULES kvm-pr +#elif IS_MODULE (CONFIG_KVM_INTEL )
Typo :) which obviously breaks the ppc64_guest_defconfig build. Changing that to CONFIG_KVM_BOOK3S_64_HV fixes it.
arch/powerpc/include/asm/kvm_types.h line 15
Quoted 6 lines
arch/powerpc/include/asm/kvm_types.h new file +6
-0+#define KVM_SUB_MODULES kvm-hv +#else +#undef KVM_SUB_MODULES +#endif + +#endif
Also, you'll want to drop kvm_types.h from generic-y to avoid
scripts/Makefile.asm-headers:39: redundant generic-y found in arch/powerpc/include/asm/Kbuild: kvm_types.h
arch/powerpc/include/asm/Kbuild +0 -1
@@ -3,7 +3,6 @@ generated-y += syscall_table_32.h generated-y += syscall_table_64.h generated-y += syscall_table_spu.h generic-y += agp.h -generic-y += kvm_types.h generic-y += mcs_spinlock.h generic-y += qrwlock.h generic-y += early_ioremap.h
--
Cheers,
Nathan
Sean Christopherson
maintainerQuoted 13 lines · Nathan Chancellor
Hi Sean,
Quoted 10 lines · Sean Christopherson
arch/powerpc/include/asm/kvm_types.h new file +4
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_PPC_KVM_TYPES_H +#define _ASM_PPC_KVM_TYPES_H +
Quoted 8 lines
arch/powerpc/include/asm/kvm_types.h line 9
Quoted 5 lines
arch/powerpc/include/asm/kvm_types.h new file +5
-0+#if IS_MODULE (CONFIG_KVM_BOOK3S_64_PR ) &&IS_MODULE (CONFIG_KVM_BOOK3S_64_HV ) +#define KVM_SUB_MODULES kvm-pr,kvm-hv +#elif IS_MODULE (CONFIG_KVM_BOOK3S_64_PR ) +#define KVM_SUB_MODULES kvm-pr +#elif IS_MODULE (CONFIG_KVM_INTEL )Typo :) which obviously breaks the
ppc64_guest_defconfigbuild. Changing that toCONFIG_KVM_BOOK3S_64_HVfixes it.
Argh, so many flavors of PPC KVM (says the x86 person :-D).
Quoted 16 lines
arch/powerpc/include/asm/kvm_types.h line 15
Quoted 6 lines
arch/powerpc/include/asm/kvm_types.h new file +6
-0+#define KVM_SUB_MODULES kvm-hv +#else +#undef KVM_SUB_MODULES +#endif + +#endif Also, you'll want to drop
kvm_types.hfrom generic-y to avoid
scripts/Makefile.asm-headers:39: redundant generic-y found inarch/powerpc/include/asm/Kbuild:kvm_types.harch/powerpc/include/asm/Kbuild +0
-0
arch/powerpc/include/asm/Kbuild generated-y += syscall_table_32.h · line 6
Quoted 4 lines
arch/powerpc/include/asm/Kbuild +0
-1@@ -3,7 +3,6 @@ generated-y += syscall_table_32.h generated-y += syscall_table_64.h generated-y += syscall_table_spu.h generic-y += agp.h -generic-y += kvm_types.h
Thanks much!
Quoted 7 lines
arch/powerpc/include/asm/Kbuild +0
-1generic-y += mcs_spinlock.h generic-y += qrwlock.h generic-y += early_ioremap.h --Cheers,
Nathan
Sean Christopherson
maintainerPATCH v2 3/5 KVM: x86: Move kvm_intr_is_single_vcpu() to lapic.c
In reply to Sean ChristophersonMove kvm_intr_is_single_vcpu() to lapic.c, drop its export, and make its "fast" helper local to lapic.c. kvm_intr_is_single_vcpu() is only usable if the local APIC is in-kernel, i.e. it most definitely belongs in the local APIC code.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 3 --- arch/x86/kvm/irq.c | 28 ---------------------------- arch/x86/kvm/lapic.c | 33 +++++++++++++++++++++++++++++++-- arch/x86/kvm/lapic.h | 4 ++-- 4 files changed, 33 insertions(+), 35 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -3
@@ -2412,9 +2412,6 @@ void __user *__x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,bool kvm_vcpu_is_reset_bsp (struct kvm_vcpu *vcpu);bool kvm_vcpu_is_bsp (struct kvm_vcpu *vcpu); -bool kvm_intr_is_single_vcpu (struct kvm *kvm,struct kvm_lapic_irq *irq, -struct kvm_vcpu **dest_vcpu); -static inline bool kvm_irq_is_postable (struct kvm_lapic_irq *irq) {/* We can only post Fixed and LowPrio IRQs */
arch/x86/kvm/irq.c +0 -28
@@ -354,34 +354,6 @@ int kvm_set_routing_entry(struct kvm *kvm,return 0 ; } -bool kvm_intr_is_single_vcpu (struct kvm *kvm,struct kvm_lapic_irq *irq, -struct kvm_vcpu **dest_vcpu) -{ -int r =0 ; -unsigned long i; -struct kvm_vcpu *vcpu; - -if (kvm_intr_is_single_vcpu_fast (kvm, irq, dest_vcpu)) -return true; - -kvm_for_each_vcpu (i, vcpu, kvm) { -if (!kvm_apic_present (vcpu)) -continue ; - -if (!kvm_apic_match_dest (vcpu,NULL , irq->shorthand, - irq->dest_id, irq->dest_mode)) -continue ; - -if (++r ==2 ) -return false; - - *dest_vcpu = vcpu; - } - -return r ==1 ; -} -EXPORT_SYMBOL_GPL (kvm_intr_is_single_vcpu); -void kvm_scan_ioapic_irq (struct kvm_vcpu *vcpu,u32 dest_id,u16 dest_mode,u8 vector,unsigned long *ioapic_handled_vectors) {
arch/x86/kvm/lapic.c +31 -2
@@ -1237,8 +1237,9 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,* interrupt. * - Otherwise, use remapped mode to inject the interrupt. */ -bool kvm_intr_is_single_vcpu_fast (struct kvm *kvm,struct kvm_lapic_irq *irq, -struct kvm_vcpu **dest_vcpu) +static bool kvm_intr_is_single_vcpu_fast (struct kvm *kvm, +struct kvm_lapic_irq *irq, +struct kvm_vcpu **dest_vcpu) {struct kvm_apic_map *map;unsigned long bitmap;
@@ -1265,6 +1266,34 @@ bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,return ret; } +bool kvm_intr_is_single_vcpu (struct kvm *kvm,struct kvm_lapic_irq *irq, +struct kvm_vcpu **dest_vcpu) +{ +int r =0 ; +unsigned long i; +struct kvm_vcpu *vcpu; + +if (kvm_intr_is_single_vcpu_fast (kvm, irq, dest_vcpu)) +return true; + +kvm_for_each_vcpu (i, vcpu, kvm) { +if (!kvm_apic_present (vcpu)) +continue ; + +if (!kvm_apic_match_dest (vcpu,NULL , irq->shorthand, + irq->dest_id, irq->dest_mode)) +continue ; + +if (++r ==2 ) +return false; + + *dest_vcpu = vcpu; + } + +return r ==1 ; +} +EXPORT_SYMBOL_GPL (kvm_intr_is_single_vcpu); +int kvm_irq_delivery_to_apic (struct kvm *kvm,struct kvm_lapic *src,struct kvm_lapic_irq *irq,struct dest_map *dest_map) {
arch/x86/kvm/lapic.h +2 -2
@@ -236,8 +236,8 @@ void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu);void kvm_bitmap_or_dest_vcpus (struct kvm *kvm,struct kvm_lapic_irq *irq,unsigned long *vcpu_bitmap); -bool kvm_intr_is_single_vcpu_fast (struct kvm *kvm,struct kvm_lapic_irq *irq, -struct kvm_vcpu **dest_vcpu); +bool kvm_intr_is_single_vcpu (struct kvm *kvm,struct kvm_lapic_irq *irq, +struct kvm_vcpu **dest_vcpu);void kvm_lapic_switch_to_sw_timer (struct kvm_vcpu *vcpu);void kvm_lapic_switch_to_hv_timer (struct kvm_vcpu *vcpu);void kvm_lapic_expired_hv_timer (struct kvm_vcpu *vcpu);
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
Sean Christopherson
maintainerPATCH v2 4/5 KVM: x86: Drop pointless exports of kvm_arch_xxx() hooks
In reply to Sean ChristophersonDrop the exporting of several kvm_arch_xxx() hooks that are only called from arch-neutral code, i.e. that are only called from kvm.ko.
--- arch/x86/kvm/x86.c | 3 --- 1 file changed, 3 deletions(-)
arch/x86/kvm/x86.c +0 -3
@@ -13542,14 +13542,12 @@ void kvm_arch_register_noncoherent_dma(struct kvm *kvm)if (atomic_inc_return (&kvm->arch.noncoherent_dma_count) ==1 )kvm_noncoherent_dma_assignment_start_or_stop (kvm); } -EXPORT_SYMBOL_GPL (kvm_arch_register_noncoherent_dma);void kvm_arch_unregister_noncoherent_dma (struct kvm *kvm) {if (!atomic_dec_return (&kvm->arch.noncoherent_dma_count))kvm_noncoherent_dma_assignment_start_or_stop (kvm); } -EXPORT_SYMBOL_GPL (kvm_arch_unregister_noncoherent_dma);bool kvm_arch_has_noncoherent_dma (struct kvm *kvm) {
@@ -13561,7 +13559,6 @@ bool kvm_arch_no_poll(struct kvm_vcpu *vcpu) {return (vcpu->arch.msr_kvm_poll_control &1 ) ==0 ; } -EXPORT_SYMBOL_GPL (kvm_arch_no_poll);#ifdef CONFIG_KVM_GUEST_MEMFD /*
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
Sean Christopherson
maintainerPATCH v2 5/5 KVM: x86: Export KVM-internal symbols for sub-modules only
In reply to Sean ChristophersonRework almost all of KVM x86's exports to expose symbols only to KVM's vendor modules, i.e. to kvm-{amd,intel}.ko. Keep the generic exports that are guarded by CONFIG_KVM_EXTERNAL_WRITE_TRACKING=y, as they're explicitly designed/intended for external usage.
--- arch/x86/kvm/cpuid.c | 10 +- arch/x86/kvm/hyperv.c | 4 +- arch/x86/kvm/irq.c | 6 +- arch/x86/kvm/kvm_onhyperv.c | 6 +- arch/x86/kvm/lapic.c | 40 +++---- arch/x86/kvm/mmu/mmu.c | 36 +++--- arch/x86/kvm/mmu/spte.c | 10 +- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- arch/x86/kvm/pmu.c | 10 +- arch/x86/kvm/smm.c | 2 +- arch/x86/kvm/x86.c | 216 ++++++++++++++++++------------------ 11 files changed, 171 insertions(+), 171 deletions(-)
arch/x86/kvm/cpuid.c +5 -5
@@ -34,7 +34,7 @@* aligned to sizeof(unsigned long) because it's not accessed via bitops. */ u32 kvm_cpu_caps[NR_KVM_CPU_CAPS ]__read_mostly ; -EXPORT_SYMBOL_GPL (kvm_cpu_caps); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_cpu_caps);struct cpuid_xstate_sizes {u32 eax;
@@ -131,7 +131,7 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry2(return NULL ; } -EXPORT_SYMBOL_GPL (kvm_find_cpuid_entry2); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_find_cpuid_entry2);static int kvm_check_cpuid (struct kvm_vcpu *vcpu) {
@@ -1228,7 +1228,7 @@ void kvm_set_cpu_caps(void)kvm_cpu_cap_clear (X86_FEATURE_RDPID ); } } -EXPORT_SYMBOL_GPL (kvm_set_cpu_caps); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_set_cpu_caps);#undef F#undef SCATTERED_F
@@ -2052,7 +2052,7 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, used_max_basic);return exact; } -EXPORT_SYMBOL_GPL (kvm_cpuid); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_cpuid);int kvm_emulate_cpuid (struct kvm_vcpu *vcpu) {
@@ -2070,4 +2070,4 @@ int kvm_emulate_cpuid(struct kvm_vcpu *vcpu)kvm_rdx_write (vcpu, edx);return kvm_skip_emulated_instruction (vcpu); } -EXPORT_SYMBOL_GPL (kvm_emulate_cpuid); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_emulate_cpuid);
arch/x86/kvm/hyperv.c +2 -2
@@ -923,7 +923,7 @@ bool kvm_hv_assist_page_enabled(struct kvm_vcpu *vcpu)return false;return vcpu->arch.pv_eoi.msr_val &KVM_MSR_ENABLED ; } -EXPORT_SYMBOL_GPL (kvm_hv_assist_page_enabled); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_hv_assist_page_enabled);int kvm_hv_get_assist_page (struct kvm_vcpu *vcpu) {
@@ -935,7 +935,7 @@ int kvm_hv_get_assist_page(struct kvm_vcpu *vcpu)return kvm_read_guest_cached (vcpu->kvm, &vcpu->arch.pv_eoi.data, &hv_vcpu->vp_assist_page,sizeof (struct hv_vp_assist_page )); } -EXPORT_SYMBOL_GPL (kvm_hv_get_assist_page); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_hv_get_assist_page);static void stimer_prepare_msg (struct kvm_vcpu_hv_stimer *stimer) {
arch/x86/kvm/irq.c +3 -3
@@ -103,7 +103,7 @@ int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v)return kvm_apic_has_interrupt (v) !=-1 ;/* LAPIC */ } -EXPORT_SYMBOL_GPL (kvm_cpu_has_injectable_intr); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_cpu_has_injectable_intr);/* * check if there is pending interrupt without
@@ -119,7 +119,7 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v)return kvm_apic_has_interrupt (v) !=-1 ;/* LAPIC */ } -EXPORT_SYMBOL_GPL (kvm_cpu_has_interrupt); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_cpu_has_interrupt);/* * Read pending interrupt(from non-APIC source)
@@ -148,7 +148,7 @@ int kvm_cpu_get_extint(struct kvm_vcpu *v)WARN_ON_ONCE (!irqchip_split (v->kvm));return get_userspace_extint (v); } -EXPORT_SYMBOL_GPL (kvm_cpu_get_extint); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_cpu_get_extint);/* * Read pending interrupt vector and intack.
arch/x86/kvm/kvm_onhyperv.c +3 -3
@@ -101,13 +101,13 @@ int hv_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn, gfn_t nr_pages)return __hv_flush_remote_tlbs_range (kvm, &range); } -EXPORT_SYMBOL_GPL (hv_flush_remote_tlbs_range); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (hv_flush_remote_tlbs_range);int hv_flush_remote_tlbs (struct kvm *kvm) {return __hv_flush_remote_tlbs_range (kvm,NULL ); } -EXPORT_SYMBOL_GPL (hv_flush_remote_tlbs); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (hv_flush_remote_tlbs);void hv_track_root_tdp (struct kvm_vcpu *vcpu,hpa_t root_tdp) {
@@ -121,4 +121,4 @@ void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp)spin_unlock (&kvm_arch->hv_root_tdp_lock); } } -EXPORT_SYMBOL_GPL (hv_track_root_tdp); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (hv_track_root_tdp);
arch/x86/kvm/lapic.c +20 -20
@@ -106,7 +106,7 @@ bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector) }__read_mostly DEFINE_STATIC_KEY_FALSE (kvm_has_noapic_vcpu); -EXPORT_SYMBOL_GPL (kvm_has_noapic_vcpu); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_has_noapic_vcpu);__read_mostly DEFINE_STATIC_KEY_DEFERRED_FALSE (apic_hw_disabled,HZ );__read_mostly DEFINE_STATIC_KEY_DEFERRED_FALSE (apic_sw_disabled,HZ );
@@ -646,7 +646,7 @@ bool __kvm_apic_update_irr(unsigned long *pir, void *regs, int *max_irr)return ((max_updated_irr !=-1 ) && (max_updated_irr == *max_irr)); } -EXPORT_SYMBOL_GPL (__kvm_apic_update_irr); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (__kvm_apic_update_irr);bool kvm_apic_update_irr (struct kvm_vcpu *vcpu,unsigned long *pir,int *max_irr) {
@@ -657,7 +657,7 @@ bool kvm_apic_update_irr(struct kvm_vcpu *vcpu, unsigned long *pir, int *max_irr apic->irr_pending = true;return irr_updated; } -EXPORT_SYMBOL_GPL (kvm_apic_update_irr); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_update_irr);static inline int apic_search_irr (struct kvm_lapic *apic) {
@@ -697,7 +697,7 @@ void kvm_apic_clear_irr(struct kvm_vcpu *vcpu, int vec) {apic_clear_irr (vec, vcpu->arch.apic); } -EXPORT_SYMBOL_GPL (kvm_apic_clear_irr); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_clear_irr);static void *apic_vector_to_isr (int vec,struct kvm_lapic *apic) {
@@ -779,7 +779,7 @@ void kvm_apic_update_hwapic_isr(struct kvm_vcpu *vcpu)kvm_x86_call (hwapic_isr_update)(vcpu,apic_find_highest_isr (apic)); } -EXPORT_SYMBOL_GPL (kvm_apic_update_hwapic_isr); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_update_hwapic_isr);int kvm_lapic_find_highest_irr (struct kvm_vcpu *vcpu) {
@@ -790,7 +790,7 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu)*/ return apic_find_highest_irr (vcpu->arch.apic); } -EXPORT_SYMBOL_GPL (kvm_lapic_find_highest_irr); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_lapic_find_highest_irr); static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, int vector, int level, int trig_mode,
@@ -954,7 +954,7 @@ void kvm_apic_update_ppr(struct kvm_vcpu *vcpu) {apic_update_ppr (vcpu->arch.apic); } -EXPORT_SYMBOL_GPL (kvm_apic_update_ppr); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_update_ppr);static void apic_set_tpr (struct kvm_lapic *apic,u32 tpr) {
@@ -1065,7 +1065,7 @@ bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source,return false; } } -EXPORT_SYMBOL_GPL (kvm_apic_match_dest); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_match_dest);static int kvm_vector_to_index (u32 vector,u32 dest_vcpus,const unsigned long *bitmap,u32 bitmap_size)
@@ -1292,7 +1292,7 @@ bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq,return r ==1 ; } -EXPORT_SYMBOL_GPL (kvm_intr_is_single_vcpu); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_intr_is_single_vcpu);int kvm_irq_delivery_to_apic (struct kvm *kvm,struct kvm_lapic *src,struct kvm_lapic_irq *irq,struct dest_map *dest_map)
@@ -1569,7 +1569,7 @@ void kvm_apic_set_eoi_accelerated(struct kvm_vcpu *vcpu, int vector)kvm_ioapic_send_eoi (apic, vector);kvm_make_request (KVM_REQ_EVENT , apic->vcpu); } -EXPORT_SYMBOL_GPL (kvm_apic_set_eoi_accelerated); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_set_eoi_accelerated);static void kvm_icr_to_lapic_irq (struct kvm_lapic *apic,u32 icr_low,u32 icr_high,struct kvm_lapic_irq *irq)
@@ -1600,7 +1600,7 @@ void kvm_apic_send_ipi(struct kvm_lapic *apic, u32 icr_low, u32 icr_high)kvm_irq_delivery_to_apic (apic->vcpu->kvm, apic, &irq,NULL ); } -EXPORT_SYMBOL_GPL (kvm_apic_send_ipi); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_send_ipi);static u32 apic_get_tmcct (struct kvm_lapic *apic) {
@@ -1717,7 +1717,7 @@ u64 kvm_lapic_readable_reg_mask(struct kvm_lapic *apic)return valid_reg_mask; } -EXPORT_SYMBOL_GPL (kvm_lapic_readable_reg_mask); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_lapic_readable_reg_mask);static int kvm_lapic_reg_read (struct kvm_lapic *apic,u32 offset,int len,void *data)
@@ -1958,7 +1958,7 @@ void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu) lapic_timer_int_injected(vcpu))__kvm_wait_lapic_expire (vcpu); } -EXPORT_SYMBOL_GPL (kvm_wait_lapic_expire); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_wait_lapic_expire);static void kvm_apic_inject_pending_timer_irqs (struct kvm_lapic *apic) {
@@ -2272,7 +2272,7 @@ void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu) out:preempt_enable (); } -EXPORT_SYMBOL_GPL (kvm_lapic_expired_hv_timer); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_lapic_expired_hv_timer);void kvm_lapic_switch_to_hv_timer (struct kvm_vcpu *vcpu) {
@@ -2525,7 +2525,7 @@ void kvm_lapic_set_eoi(struct kvm_vcpu *vcpu) {kvm_lapic_reg_write (vcpu->arch.apic,APIC_EOI ,0 ); } -EXPORT_SYMBOL_GPL (kvm_lapic_set_eoi); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_lapic_set_eoi);#define X2APIC_ICR_RESERVED_BITS (GENMASK_ULL(31, 20) | GENMASK_ULL(17, 16) | BIT(13))
@@ -2608,7 +2608,7 @@ void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset)else kvm_lapic_reg_write (apic, offset,kvm_lapic_get_reg (apic, offset)); } -EXPORT_SYMBOL_GPL (kvm_apic_write_nodecode); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_write_nodecode);void kvm_free_lapic (struct kvm_vcpu *vcpu) {
@@ -2746,7 +2746,7 @@ int kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value, bool host_initiated)kvm_recalculate_apic_map (vcpu->kvm);return 0 ; } -EXPORT_SYMBOL_GPL (kvm_apic_set_base); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_set_base);void kvm_apic_update_apicv (struct kvm_vcpu *vcpu) {
@@ -2794,7 +2794,7 @@ int kvm_alloc_apic_access_page(struct kvm *kvm)return 0 ; } -EXPORT_SYMBOL_GPL (kvm_alloc_apic_access_page); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_alloc_apic_access_page);void kvm_inhibit_apic_access_page (struct kvm_vcpu *vcpu) {
@@ -3058,7 +3058,7 @@ int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu)__apic_update_ppr (apic, &ppr);return apic_has_interrupt_for_ppr (apic, ppr); } -EXPORT_SYMBOL_GPL (kvm_apic_has_interrupt); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_has_interrupt);int kvm_apic_accept_pic_intr (struct kvm_vcpu *vcpu) {
@@ -3117,7 +3117,7 @@ void kvm_apic_ack_interrupt(struct kvm_vcpu *vcpu, int vector) } } -EXPORT_SYMBOL_GPL (kvm_apic_ack_interrupt); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_apic_ack_interrupt);static int kvm_apic_state_fixup (struct kvm_vcpu *vcpu,struct kvm_lapic_state *s,bool set)
arch/x86/kvm/mmu/mmu.c +18 -18
@@ -110,7 +110,7 @@ static bool __ro_after_init tdp_mmu_allowed;#ifdef CONFIG_X86_64 bool __read_mostly tdp_mmu_enabled = true;module_param_named (tdp_mmu, tdp_mmu_enabled, bool,0444 ); -EXPORT_SYMBOL_GPL (tdp_mmu_enabled); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (tdp_mmu_enabled);#endif static int max_huge_page_level__read_mostly ;
@@ -3865,7 +3865,7 @@ void kvm_mmu_free_roots(struct kvm *kvm, struct kvm_mmu *mmu,write_unlock (&kvm->mmu_lock); } } -EXPORT_SYMBOL_GPL (kvm_mmu_free_roots); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_free_roots);void kvm_mmu_free_guest_mode_roots (struct kvm *kvm,struct kvm_mmu *mmu) {
@@ -3892,7 +3892,7 @@ void kvm_mmu_free_guest_mode_roots(struct kvm *kvm, struct kvm_mmu *mmu)kvm_mmu_free_roots (kvm, mmu, roots_to_free); } -EXPORT_SYMBOL_GPL (kvm_mmu_free_guest_mode_roots); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_free_guest_mode_roots);static hpa_t mmu_alloc_root (struct kvm_vcpu *vcpu,gfn_t gfn,int quadrant,u8 level)
@@ -4876,7 +4876,7 @@ int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,return r; } -EXPORT_SYMBOL_GPL (kvm_handle_page_fault); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_handle_page_fault);#ifdef CONFIG_X86_64 static int kvm_tdp_mmu_page_fault(struct kvm_vcpu *vcpu,
@@ -4966,7 +4966,7 @@ int kvm_tdp_map_page(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code, u8 *levelreturn -EIO ; } } -EXPORT_SYMBOL_GPL (kvm_tdp_map_page); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_tdp_map_page);long kvm_arch_vcpu_pre_fault_memory (struct kvm_vcpu *vcpu,struct kvm_pre_fault_memory *range)
@@ -5162,7 +5162,7 @@ void kvm_mmu_new_pgd(struct kvm_vcpu *vcpu, gpa_t new_pgd)__clear_sp_write_flooding_count (sp); } } -EXPORT_SYMBOL_GPL (kvm_mmu_new_pgd); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_new_pgd);static bool sync_mmio_spte (struct kvm_vcpu *vcpu,u64 *sptep,gfn_t gfn,unsigned int access)
@@ -5808,7 +5808,7 @@ void kvm_init_shadow_npt_mmu(struct kvm_vcpu *vcpu, unsigned long cr0,shadow_mmu_init_context (vcpu, context, cpu_role, root_role);kvm_mmu_new_pgd (vcpu, nested_cr3); } -EXPORT_SYMBOL_GPL (kvm_init_shadow_npt_mmu); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_init_shadow_npt_mmu); static union kvm_cpu_role kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty,
@@ -5862,7 +5862,7 @@ void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly,kvm_mmu_new_pgd (vcpu, new_eptp); } -EXPORT_SYMBOL_GPL (kvm_init_shadow_ept_mmu); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_init_shadow_ept_mmu);static void init_kvm_softmmu (struct kvm_vcpu *vcpu,union kvm_cpu_role cpu_role)
@@ -5927,7 +5927,7 @@ void kvm_init_mmu(struct kvm_vcpu *vcpu)else init_kvm_softmmu (vcpu, cpu_role); } -EXPORT_SYMBOL_GPL (kvm_init_mmu); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_init_mmu);void kvm_mmu_after_set_cpuid (struct kvm_vcpu *vcpu) {
@@ -5963,7 +5963,7 @@ void kvm_mmu_reset_context(struct kvm_vcpu *vcpu)kvm_mmu_unload (vcpu);kvm_init_mmu (vcpu); } -EXPORT_SYMBOL_GPL (kvm_mmu_reset_context); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_reset_context);int kvm_mmu_load (struct kvm_vcpu *vcpu) {
@@ -5997,7 +5997,7 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu) out:return r; } -EXPORT_SYMBOL_GPL (kvm_mmu_load); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_load);void kvm_mmu_unload (struct kvm_vcpu *vcpu) {
@@ -6059,7 +6059,7 @@ void kvm_mmu_free_obsolete_roots(struct kvm_vcpu *vcpu)__kvm_mmu_free_obsolete_roots (vcpu->kvm, &vcpu->arch.root_mmu);__kvm_mmu_free_obsolete_roots (vcpu->kvm, &vcpu->arch.guest_mmu); } -EXPORT_SYMBOL_GPL (kvm_mmu_free_obsolete_roots); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_free_obsolete_roots);static u64 mmu_pte_write_fetch_gpte (struct kvm_vcpu *vcpu,gpa_t *gpa,int *bytes)
@@ -6385,7 +6385,7 @@ int noinline kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 errreturn x86_emulate_instruction (vcpu, cr2_or_gpa, emulation_type, insn, insn_len); } -EXPORT_SYMBOL_GPL (kvm_mmu_page_fault); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_page_fault);void kvm_mmu_print_sptes (struct kvm_vcpu *vcpu,gpa_t gpa,const char *msg) {
@@ -6401,7 +6401,7 @@ void kvm_mmu_print_sptes(struct kvm_vcpu *vcpu, gpa_t gpa, const char *msg)pr_cont (", spte[%d] = 0x%llx" , level, sptes[level]);pr_cont ("\n" ); } -EXPORT_SYMBOL_GPL (kvm_mmu_print_sptes); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_print_sptes);static void __kvm_mmu_invalidate_addr (struct kvm_vcpu *vcpu,struct kvm_mmu *mmu,u64 addr,hpa_t root_hpa)
@@ -6467,7 +6467,7 @@ void kvm_mmu_invalidate_addr(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,__kvm_mmu_invalidate_addr (vcpu, mmu, addr, mmu->prev_roots[i].hpa); } } -EXPORT_SYMBOL_GPL (kvm_mmu_invalidate_addr); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_invalidate_addr);void kvm_mmu_invlpg (struct kvm_vcpu *vcpu,gva_t gva) {
@@ -6484,7 +6484,7 @@ void kvm_mmu_invlpg(struct kvm_vcpu *vcpu, gva_t gva)kvm_mmu_invalidate_addr (vcpu, vcpu->arch.walk_mmu, gva,KVM_MMU_ROOTS_ALL ); ++vcpu->stat.invlpg; } -EXPORT_SYMBOL_GPL (kvm_mmu_invlpg); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_invlpg);void kvm_mmu_invpcid_gva (struct kvm_vcpu *vcpu,gva_t gva,unsigned long pcid)
@@ -6537,7 +6537,7 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level,else max_huge_page_level =PG_LEVEL_2M ; } -EXPORT_SYMBOL_GPL (kvm_configure_mmu); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_configure_mmu);static void free_mmu_pages (struct kvm_mmu *mmu) {
@@ -7204,7 +7204,7 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm,return need_tlb_flush; } -EXPORT_SYMBOL_GPL (kvm_zap_gfn_range); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_zap_gfn_range);static void kvm_rmap_zap_collapsible_sptes (struct kvm *kvm,const struct kvm_memory_slot *slot)
arch/x86/kvm/mmu/spte.c +5 -5
@@ -22,7 +22,7 @@bool __read_mostly enable_mmio_caching = true;static bool __ro_after_init allow_mmio_caching;module_param_named (mmio_caching, enable_mmio_caching, bool,0444 ); -EXPORT_SYMBOL_GPL (enable_mmio_caching); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (enable_mmio_caching);bool __read_mostly kvm_ad_enabled;
@@ -470,13 +470,13 @@ void kvm_mmu_set_mmio_spte_mask(u64 mmio_value, u64 mmio_mask, u64 access_mask) shadow_mmio_mask = mmio_mask; shadow_mmio_access_mask = access_mask; } -EXPORT_SYMBOL_GPL (kvm_mmu_set_mmio_spte_mask); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_set_mmio_spte_mask);void kvm_mmu_set_mmio_spte_value (struct kvm *kvm,u64 mmio_value) { kvm->arch.shadow_mmio_value = mmio_value; } -EXPORT_SYMBOL_GPL (kvm_mmu_set_mmio_spte_value); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_set_mmio_spte_value);void kvm_mmu_set_me_spte_mask (u64 me_value,u64 me_mask) {
@@ -487,7 +487,7 @@ void kvm_mmu_set_me_spte_mask(u64 me_value, u64 me_mask) shadow_me_value = me_value; shadow_me_mask = me_mask; } -EXPORT_SYMBOL_GPL (kvm_mmu_set_me_spte_mask); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_set_me_spte_mask);void kvm_mmu_set_ept_masks (bool has_ad_bits,bool has_exec_only) {
@@ -513,7 +513,7 @@ void kvm_mmu_set_ept_masks(bool has_ad_bits, bool has_exec_only)kvm_mmu_set_mmio_spte_mask (VMX_EPT_MISCONFIG_WX_VALUE ,VMX_EPT_RWX_MASK |VMX_EPT_SUPPRESS_VE_BIT ,0 ); } -EXPORT_SYMBOL_GPL (kvm_mmu_set_ept_masks); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_mmu_set_ept_masks);void kvm_mmu_reset_all_pte_masks (void ) {
arch/x86/kvm/mmu/tdp_mmu.c +1 -1
@@ -1982,7 +1982,7 @@ bool kvm_tdp_mmu_gpa_is_mapped(struct kvm_vcpu *vcpu, u64 gpa) spte = sptes[leaf];return is_shadow_present_pte (spte) &&is_last_spte (spte, leaf); } -EXPORT_SYMBOL_GPL (kvm_tdp_mmu_gpa_is_mapped); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_tdp_mmu_gpa_is_mapped);/* * Returns the last level spte pointer of the shadow page walk for the given
arch/x86/kvm/pmu.c +5 -5
@@ -31,7 +31,7 @@ static struct x86_pmu_capability __read_mostly kvm_host_pmu;/* KVM's PMU capabilities, i.e. the intersection of KVM and hardware support. */ struct x86_pmu_capability __read_mostly kvm_pmu_cap; -EXPORT_SYMBOL_GPL (kvm_pmu_cap); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_pmu_cap);struct kvm_pmu_emulated_event_selectors {u64 INSTRUCTIONS_RETIRED;
@@ -373,7 +373,7 @@ void pmc_write_counter(struct kvm_pmc *pmc, u64 val) pmc->counter &=pmc_bitmask (pmc);pmc_update_sample_period (pmc); } -EXPORT_SYMBOL_GPL (pmc_write_counter); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (pmc_write_counter);static int filter_cmp (const void *pa,const void *pb,u64 mask) {
@@ -581,7 +581,7 @@ void kvm_pmu_recalc_pmc_emulation(struct kvm_pmu *pmu, struct kvm_pmc *pmc)if (pmc_is_event_match (pmc, kvm_pmu_eventsel.BRANCH_INSTRUCTIONS_RETIRED))bitmap_set (pmu->pmc_counting_branches, pmc->idx,1 ); } -EXPORT_SYMBOL_GPL (kvm_pmu_recalc_pmc_emulation); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_pmu_recalc_pmc_emulation);void kvm_pmu_handle_event (struct kvm_vcpu *vcpu) {
@@ -996,13 +996,13 @@ void kvm_pmu_instruction_retired(struct kvm_vcpu *vcpu) {kvm_pmu_trigger_event (vcpu,vcpu_to_pmu (vcpu)->pmc_counting_instructions); } -EXPORT_SYMBOL_GPL (kvm_pmu_instruction_retired); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_pmu_instruction_retired);void kvm_pmu_branch_retired (struct kvm_vcpu *vcpu) {kvm_pmu_trigger_event (vcpu,vcpu_to_pmu (vcpu)->pmc_counting_branches); } -EXPORT_SYMBOL_GPL (kvm_pmu_branch_retired); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_pmu_branch_retired);static bool is_masked_filter_valid (const struct kvm_x86_pmu_event_filter *filter) {
arch/x86/kvm/smm.c +1 -1
@@ -131,7 +131,7 @@ void kvm_smm_changed(struct kvm_vcpu *vcpu, bool entering_smm)kvm_mmu_reset_context (vcpu); } -EXPORT_SYMBOL_GPL (kvm_smm_changed); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_smm_changed);void process_smi (struct kvm_vcpu *vcpu) {
arch/x86/kvm/x86.c +108 -108
841 lines not on this page · raw message
Signature · 1 line
2.51.0.470.ga7dc726c21-goog
PATCH 1/1 KVM: Re-export kvm_enable_virtualization() and kvm_disable_virtualization() as normal (global) exports rather than only to KVM's vendor modules
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.
--- virt/kvm/kvm_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
virt/kvm/kvm_main.c +2 -2
@@ -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 ) {
Signature · 1 line
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
Quoted 10 lines · Ramshankar Venkataraman
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()andkvm_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.
Sean Christopherson
maintainerQuoted 9 lines · Sean Christopherson
Use the newfangled
EXPORT_SYMBOL_FOR_MODULES()along with some macro shenanigans to export KVM-internal symbols if and only if KVM has one or more sub-modules, and only for those sub-modules, e.g. x86's kvm-amd.ko and/or kvm-intel.ko.Patch 5 gives KVM x86 the full treatment. If anyone wants to tackle PPC, it should be doable to restrict KVM PPC's exports as well.
[...]
Quite belatedly (forgot to send the "thanks"), applied to kvm-x86 exports.
[1/5] KVM: s390/vfio-ap: Use kvm_is_gpa_in_memslot() instead of open coded equivalent
https://github.com/kvm-x86/linux/commit/66d1a7ac946c [2/5] KVM: Export KVM-internal symbols for sub-modules only https://github.com/kvm-x86/linux/commit/d66078b8c990 [3/5] KVM: x86: Move kvm_intr_is_single_vcpu() to lapic.c https://github.com/kvm-x86/linux/commit/16e53ef18450 [4/5] KVM: x86: Drop pointless exports of kvm_arch_xxx() hooks https://github.com/kvm-x86/linux/commit/26caf4d04e01 [5/5] KVM: x86: Export KVM-internal symbols for sub-modules only https://github.com/kvm-x86/linux/commit/aca2a0fa7796