Re: [PATCH] KVM: x86: Fix C++ user API for structures with variable length arrays

From: David Woodhouse

Date: Fri Feb 27 2026 - 03:31:09 EST


On Thu, 2026-02-26 at 11:02 -0800, Kees Cook wrote:
>
> > Also put the header fields into a struct_group() to provide (in C) a
> > separate struct (e.g 'struct kvm_msrs_hdr') without the trailing VLA.
>
> Right, my only worry is if C++ would want those header structs too. In
> that case, you'd probably want to use a macro to include them (since not
> all compilers are supporting transparent struct members yet):
>
> #define __kvm_msrs_hdr \
> __u32 nmsrs; /* number of msrs in entries */ \
> __u32 pad
>
> struct kvm_msrs_hdr {
> __kvm_msrs_hdr;
> };
>
> struct kvm_msrs {
> __kvm_msrs_hdr;
> __DECLARE_FLEX_ARRAY(struct kvm_msr_entry, entries);
> };

Hm, does the struct_group() not also depend on the compiler supporting
anonymous struct members? Is there a distinction I'm missing?

Attachment: smime.p7s
Description: S/MIME cryptographic signature