Commit 20c48920 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini
Browse files

KVM: Export KVM-internal symbols for sub-modules only

Rework 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.

Link: https://lore.kernel.org/r/20250919003303.1355064-3-seanjc@google.com


Cc: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 15463eec
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -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
+15 −0
Original line number Diff line number Diff line
/* 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_BOOK3S_64_HV)
#define KVM_SUB_MODULES kvm-hv
#else
#undef KVM_SUB_MODULES
#endif

#endif
+10 −0
Original line number Diff line number Diff line
@@ -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 */
+18 −7
Original line number Diff line number Diff line
@@ -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__ */
+1 −1
Original line number Diff line number Diff line
@@ -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)
{
Loading