Commit 6276c67f authored by Sean Christopherson's avatar Sean Christopherson Committed by Dave Hansen
Browse files

x86: Restrict KVM-induced symbol exports to KVM modules where obvious/possible



Extend KVM's export macro framework to provide EXPORT_SYMBOL_FOR_KVM(),
and use the helper macro to export symbols for KVM throughout x86 if and
only if KVM will build one or more modules, and only for those modules.

To avoid unnecessary exports when CONFIG_KVM=m but kvm.ko will not be
built (because no vendor modules are selected), let arch code #define
EXPORT_SYMBOL_FOR_KVM to suppress/override the exports.

Note, the set of symbols to restrict to KVM was generated by manual search
and audit; any "misses" are due to human error, not some grand plan.

Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
Acked-by: default avatarKai Huang <kai.huang@intel.com>
Tested-by: default avatarKai Huang <kai.huang@intel.com>
Link: https://patch.msgid.link/20251112173944.1380633-5-seanjc%40google.com
parent e6f2d586
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
 */

#include <linux/export.h>
#include <linux/kvm_types.h>
#include <linux/linkage.h>
#include <linux/objtool.h>
#include <asm/msr-index.h>
@@ -29,8 +30,7 @@ SYM_FUNC_START(write_ibpb)
	FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_BUG_IBPB_NO_RET
	RET
SYM_FUNC_END(write_ibpb)
/* For KVM */
EXPORT_SYMBOL_GPL(write_ibpb);
EXPORT_SYMBOL_FOR_KVM(write_ibpb);

.popsection

@@ -48,8 +48,7 @@ SYM_CODE_START_NOALIGN(x86_verw_sel)
	.word __KERNEL_DS
.align L1_CACHE_BYTES, 0xcc
SYM_CODE_END(x86_verw_sel);
/* For KVM */
EXPORT_SYMBOL_GPL(x86_verw_sel);
EXPORT_SYMBOL_FOR_KVM(x86_verw_sel);

.popsection

+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
 * - idtentry:		Define exception entry points.
 */
#include <linux/export.h>
#include <linux/kvm_types.h>
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/cache.h>
@@ -1566,5 +1567,5 @@ SYM_FUNC_START(clear_bhb_loop)
	pop	%rbp
	RET
SYM_FUNC_END(clear_bhb_loop)
EXPORT_SYMBOL_GPL(clear_bhb_loop)
EXPORT_SYMBOL_FOR_KVM(clear_bhb_loop)
STACK_FRAME_NON_STANDARD(clear_bhb_loop)
+2 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
 */

#include <linux/export.h>
#include <linux/kvm_types.h>

#include <asm/asm.h>
#include <asm/fred.h>
@@ -146,5 +147,5 @@ SYM_FUNC_START(asm_fred_entry_from_kvm)
	RET

SYM_FUNC_END(asm_fred_entry_from_kvm)
EXPORT_SYMBOL_GPL(asm_fred_entry_from_kvm);
EXPORT_SYMBOL_FOR_KVM(asm_fred_entry_from_kvm);
#endif
+3 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#include <linux/perf_event.h>
#include <linux/jump_label.h>
#include <linux/export.h>
#include <linux/kvm_types.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/slab.h>
@@ -1569,7 +1570,7 @@ void amd_pmu_enable_virt(void)
	/* Reload all events */
	amd_pmu_reload_virt();
}
EXPORT_SYMBOL_GPL(amd_pmu_enable_virt);
EXPORT_SYMBOL_FOR_KVM(amd_pmu_enable_virt);

void amd_pmu_disable_virt(void)
{
@@ -1586,4 +1587,4 @@ void amd_pmu_disable_virt(void)
	/* Reload all events */
	amd_pmu_reload_virt();
}
EXPORT_SYMBOL_GPL(amd_pmu_disable_virt);
EXPORT_SYMBOL_FOR_KVM(amd_pmu_disable_virt);
+4 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <linux/export.h>
#include <linux/init.h>
#include <linux/kdebug.h>
#include <linux/kvm_types.h>
#include <linux/sched/mm.h>
#include <linux/sched/clock.h>
#include <linux/uaccess.h>
@@ -714,7 +715,7 @@ struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, void *data)
{
	return static_call(x86_pmu_guest_get_msrs)(nr, data);
}
EXPORT_SYMBOL_GPL(perf_guest_get_msrs);
EXPORT_SYMBOL_FOR_KVM(perf_guest_get_msrs);

/*
 * There may be PMI landing after enabled=0. The PMI hitting could be before or
@@ -3106,7 +3107,7 @@ void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap)
	cap->events_mask_len	= x86_pmu.events_mask_len;
	cap->pebs_ept		= x86_pmu.pebs_ept;
}
EXPORT_SYMBOL_GPL(perf_get_x86_pmu_capability);
EXPORT_SYMBOL_FOR_KVM(perf_get_x86_pmu_capability);

u64 perf_get_hw_event_config(int hw_event)
{
@@ -3117,4 +3118,4 @@ u64 perf_get_hw_event_config(int hw_event)

	return 0;
}
EXPORT_SYMBOL_GPL(perf_get_hw_event_config);
EXPORT_SYMBOL_FOR_KVM(perf_get_hw_event_config);
Loading