[PATCH v4 18/30] KVM: x86: Move "struct kvm_x86_msr_filter" definition to msrs.c

From: Sean Christopherson

Date: Fri Jun 12 2026 - 20:07:09 EST


Move the definition of "struct kvm_x86_msr_filter" and its associate,
"struct msr_bitmap_range", to msrs.c, as the details of the filters are
very much implementation details that can and should be buried in msrs.c.
While the _existence_ of filters is public knowledge, almost by definition,
the contents don't need to be exposed outside of the MSR code as the filter
data is provided by userspace, i.e. it pretty much has to be dynamically
allocated, and thus never should be fully embedded in a globally visible
structure.

Note, this creates a discrepancy with the PMU event filter structure; that
will be remedied shortly.

No functional change intended.

Suggested-by: Kai Huang <kai.huang@xxxxxxxxx>
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/include/asm/kvm_host.h | 15 ++-------------
arch/x86/kvm/msrs.c | 13 +++++++++++++
2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 09e437c947a9..4ff6304c02d0 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -315,6 +315,8 @@ enum x86_intercept_stage;
struct kvm_kernel_irqfd;
struct kvm_kernel_irq_routing_entry;

+struct kvm_x86_msr_filter;
+
struct kvm_caps {
/* control of guest tsc rate supported? */
bool has_tsc_control;
@@ -1291,13 +1293,6 @@ struct kvm_hv {
};
#endif

-struct msr_bitmap_range {
- u32 flags;
- u32 nmsrs;
- u32 base;
- unsigned long *bitmap;
-};
-
#ifdef CONFIG_KVM_XEN
/* Xen emulation context */
struct kvm_xen {
@@ -1328,12 +1323,6 @@ enum kvm_suppress_eoi_broadcast_mode {
KVM_SUPPRESS_EOI_BROADCAST_DISABLED /* Disable Suppress EOI broadcast */
};

-struct kvm_x86_msr_filter {
- u8 count;
- bool default_allow:1;
- struct msr_bitmap_range ranges[16];
-};
-
struct kvm_x86_pmu_event_filter {
__u32 action;
__u32 nevents;
diff --git a/arch/x86/kvm/msrs.c b/arch/x86/kvm/msrs.c
index 07f2a22d2607..c230b18d87e3 100644
--- a/arch/x86/kvm/msrs.c
+++ b/arch/x86/kvm/msrs.c
@@ -32,6 +32,19 @@ static u64 __read_mostly efer_reserved_bits = ~((u64)EFER_SCE);

#define MAX_IO_MSRS 256

+struct msr_bitmap_range {
+ u32 flags;
+ u32 nmsrs;
+ u32 base;
+ unsigned long *bitmap;
+};
+
+struct kvm_x86_msr_filter {
+ u8 count;
+ bool default_allow:1;
+ struct msr_bitmap_range ranges[16];
+};
+
/*
* Restoring the host value for MSRs that are only consumed when running in
* usermode, e.g. SYSCALL MSRs and TSC_AUX, can be deferred until the CPU
--
2.54.0.1136.gdb2ca164c4-goog