From: Kees Cook <kees@kernel.org>
To: David Woodhouse <dwmw2@infradead.org>
Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
daniel@iogearbox.net, gustavoars@kernel.org, jgg@ziepe.ca,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] KVM: x86: Fix C++ user API for structures with variable length arrays
Date: Fri, 27 Feb 2026 16:43:16 -0800 [thread overview]
Message-ID: <948BD627-E51D-4959-9745-3AB390F04D0D@kernel.org> (raw)
In-Reply-To: <718cbe24ffb546b97db8af94521da067d7437d70.camel@infradead.org>
On February 27, 2026 12:29:11 AM PST, David Woodhouse <dwmw2@infradead.org> wrote:
>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?
Sorry, I should have been mor clear: the _tag_ that struct_group creates isn't supported for all C++ compilers (so is commented out for C++) so if a C++ project wanted to use the struct by its tag ("struct kvm_msrs_hdr"), you'd need the construct I wrote above.
-Kees
--
Kees Cook
next prev parent reply other threads:[~2026-02-28 0:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 18:04 [PATCH][next] treewide: uapi: Replace zero-length arrays with flexible-array members Gustavo A. R. Silva
2022-06-27 18:27 ` Daniel Borkmann
2022-06-27 18:35 ` Gustavo A. R. Silva
2022-06-28 0:40 ` Jason Gunthorpe
2022-06-28 0:58 ` Gustavo A. R. Silva
2022-06-28 2:21 ` Gustavo A. R. Silva
2022-06-28 13:36 ` Jason Gunthorpe
2022-06-28 13:56 ` Gustavo A. R. Silva
2022-06-28 17:54 ` Kees Cook
2022-06-28 18:44 ` Jason Gunthorpe
2026-02-23 14:28 ` David Woodhouse
2026-02-23 3:38 ` Gustavo A. R. Silva
2026-02-23 19:57 ` David Woodhouse
2026-02-26 11:44 ` [PATCH] KVM: x86: Fix C++ user API for structures with variable length arrays David Woodhouse
2026-02-26 19:02 ` Kees Cook
2026-02-27 8:29 ` David Woodhouse
2026-02-28 0:43 ` Kees Cook [this message]
2026-02-28 8:54 ` David Woodhouse
2026-03-05 18:36 ` Sean Christopherson
2026-03-05 19:18 ` David Woodhouse
2026-03-05 19:31 ` Sean Christopherson
2026-03-05 19:49 ` [PATCH v2] KVM: x86: Use __DECLARE_FLEX_ARRAY() for UAPI structures with VLAs David Woodhouse
2026-04-03 15:13 ` Sean Christopherson
2022-06-27 19:53 ` [PATCH][next] treewide: uapi: Replace zero-length arrays with flexible-array members Stephen Hemminger
2022-06-28 14:18 ` Gustavo A. R. Silva
2022-06-27 22:31 ` Dan Williams
2022-06-28 7:27 ` Geert Uytterhoeven
2022-06-28 18:05 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=948BD627-E51D-4959-9745-3AB390F04D0D@kernel.org \
--to=kees@kernel.org \
--cc=bp@alien8.de \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=gustavo@embeddedor.com \
--cc=gustavoars@kernel.org \
--cc=hpa@zytor.com \
--cc=jgg@ziepe.ca \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®