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

From: Binbin Wu

Date: Tue Jun 16 2026 - 02:29:54 EST


On 6/13/2026 8:03 AM, Sean Christopherson wrote:
> 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;


Just FYI, the code failed to build on my desktop with an old gcc version v9.4.
Due to dereferencing pointer to incomplete type ‘struct kvm_x86_msr_filter' via
typeof().

It's not the fault of the patch, the issue was fixed for GCC 10+ according to
the link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44257

But the minimal tool version got for gcc is still v8.1.0, not sure if it needs
to bump the version in scripts/min-tool-version.sh?


--- Build error information below ---

In file included from ./include/linux/rculist.h:11,
from ./include/linux/cgroup.h:15,
from ./include/linux/memcontrol.h:13,
from ./include/linux/resume_user_mode.h:8,
from ./include/linux/entry-virt.h:6,
from ./include/linux/kvm_host.h:5,
from arch/x86/kvm/x86.c:20:
arch/x86/kvm/x86.c: In function ‘kvm_arch_destroy_vm’:
./include/linux/rcupdate.h:502:9: error: dereferencing pointer to incomplete type ‘struct kvm_x86_msr_filter’
502 | typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
./include/linux/srcu.h:240:20: note: in expansion of macro ‘__rcu_dereference_check’
240 | __auto_type __v = __rcu_dereference_check((p), __UNIQUE_ID(rcu), \
| ^~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:9969:22: note: in expansion of macro ‘srcu_dereference_check’
9969 | kvm_free_msr_filter(srcu_dereference_check(kvm->arch.msr_filter, &kvm->srcu, 1));
| ^~~~~~~~~~~~~~~~~~~~~~
In file included from ./include/linux/notifier.h:16,
from ./arch/x86/include/asm/uprobes.h:13,
from ./include/linux/uprobes.h:66,
from ./include/linux/mm_types.h:16,
from ./include/linux/mmzone.h:22,
from ./include/linux/gfp.h:7,
from ./include/linux/xarray.h:16,
from ./include/linux/list_lru.h:14,
from ./include/linux/fs/super_types.h:7,
from ./include/linux/fs/super.h:5,
from ./include/linux/fs.h:5,
from ./include/linux/cgroup.h:17,
from ./include/linux/memcontrol.h:13,
from ./include/linux/resume_user_mode.h:8,
from ./include/linux/entry-virt.h:6,
from ./include/linux/kvm_host.h:5,
from arch/x86/kvm/x86.c:20:
./include/linux/srcu.h:243:2: error: ‘__v’ undeclared (first use in this function)
243 | __v; \
| ^~~
arch/x86/kvm/x86.c:9969:22: note: in expansion of macro ‘srcu_dereference_check’
9969 | kvm_free_msr_filter(srcu_dereference_check(kvm->arch.msr_filter, &kvm->srcu, 1));
| ^~~~~~~~~~~~~~~~~~~~~~
./include/linux/srcu.h:243:2: note: each undeclared identifier is reported only once for each function it appears in
243 | __v; \
| ^~~
arch/x86/kvm/x86.c:9969:22: note: in expansion of macro ‘srcu_dereference_check’
9969 | kvm_free_msr_filter(srcu_dereference_check(kvm->arch.msr_filter, &kvm->srcu, 1));
| ^~~~~~~~~~~~~~~~~~~~~~
In file included from ./include/linux/rculist.h:11,
from ./include/linux/cgroup.h:15,
from ./include/linux/memcontrol.h:13,
from ./include/linux/resume_user_mode.h:8,
from ./include/linux/entry-virt.h:6,
from ./include/linux/kvm_host.h:5,
from arch/x86/kvm/x86.c:20:
./include/linux/rcupdate.h:502:9: error: dereferencing pointer to incomplete type ‘struct kvm_x86_pmu_event_filter’
502 | typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
./include/linux/srcu.h:240:20: note: in expansion of macro ‘__rcu_dereference_check’
240 | __auto_type __v = __rcu_dereference_check((p), __UNIQUE_ID(rcu), \
| ^~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:9975:8: note: in expansion of macro ‘srcu_dereference_check’
9975 | kfree(srcu_dereference_check(kvm->arch.pmu_event_filter, &kvm->srcu, 1));
| ^~~~~~~~~~~~~~~~~~~~~~
make[4]: *** [scripts/Makefile.build:289: arch/x86/kvm/x86.o] Error 1
make[3]: *** [scripts/Makefile.build:548: arch/x86/kvm] Error 2
make[2]: *** [scripts/Makefile.build:548: arch/x86] Error 2
make[1]: *** [/home/litbin/workspace/kvm-x86/Makefile:2143: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2