Skip to content

Commit 2619da7

Browse files
dwmw2sean-jc
authored andcommitted
KVM: x86: Use __DECLARE_FLEX_ARRAY() for UAPI structures with VLAs
Commit 94dfc73 ("treewide: uapi: Replace zero-length arrays with flexible-array members") broke the userspace API for C++. These structures ending in VLAs are typically a *header*, which can be followed by an arbitrary number of entries. Userspace typically creates a larger structure with some non-zero number of entries, for example in QEMU's kvm_arch_get_supported_msr_feature(): struct { struct kvm_msrs info; struct kvm_msr_entry entries[1]; } msr_data = {}; While that works in C, it fails in C++ with an error like: flexible array member 'kvm_msrs::entries' not at end of 'struct msr_data' Fix this by using __DECLARE_FLEX_ARRAY() for the VLA, which uses [0] for C++ compilation. Fixes: 94dfc73 ("treewide: uapi: Replace zero-length arrays with flexible-array members") Cc: stable@vger.kernel.org Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Link: https://patch.msgid.link/3abaf6aefd6e5efeff3b860ac38421d9dec908db.camel@infradead.org [sean: tag for stable@] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent d2ea4ff commit 2619da7

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

  • arch/x86/include/uapi/asm
  • include/uapi/linux

arch/x86/include/uapi/asm/kvm.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ struct kvm_msrs {
197197
__u32 nmsrs; /* number of msrs in entries */
198198
__u32 pad;
199199

200-
struct kvm_msr_entry entries[];
200+
__DECLARE_FLEX_ARRAY(struct kvm_msr_entry, entries);
201201
};
202202

203203
/* for KVM_GET_MSR_INDEX_LIST */
204204
struct kvm_msr_list {
205205
__u32 nmsrs; /* number of msrs in entries */
206-
__u32 indices[];
206+
__DECLARE_FLEX_ARRAY(__u32, indices);
207207
};
208208

209209
/* Maximum size of any access bitmap in bytes */
@@ -245,7 +245,7 @@ struct kvm_cpuid_entry {
245245
struct kvm_cpuid {
246246
__u32 nent;
247247
__u32 padding;
248-
struct kvm_cpuid_entry entries[];
248+
__DECLARE_FLEX_ARRAY(struct kvm_cpuid_entry, entries);
249249
};
250250

251251
struct kvm_cpuid_entry2 {
@@ -267,7 +267,7 @@ struct kvm_cpuid_entry2 {
267267
struct kvm_cpuid2 {
268268
__u32 nent;
269269
__u32 padding;
270-
struct kvm_cpuid_entry2 entries[];
270+
__DECLARE_FLEX_ARRAY(struct kvm_cpuid_entry2, entries);
271271
};
272272

273273
/* for KVM_GET_PIT and KVM_SET_PIT */
@@ -398,7 +398,7 @@ struct kvm_xsave {
398398
* the contents of CPUID leaf 0xD on the host.
399399
*/
400400
__u32 region[1024];
401-
__u32 extra[];
401+
__DECLARE_FLEX_ARRAY(__u32, extra);
402402
};
403403

404404
#define KVM_MAX_XCRS 16
@@ -566,7 +566,7 @@ struct kvm_pmu_event_filter {
566566
__u32 fixed_counter_bitmap;
567567
__u32 flags;
568568
__u32 pad[4];
569-
__u64 events[];
569+
__DECLARE_FLEX_ARRAY(__u64, events);
570570
};
571571

572572
#define KVM_PMU_EVENT_ALLOW 0

include/uapi/linux/kvm.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/const.h>
1212
#include <linux/types.h>
1313
#include <linux/compiler.h>
14+
#include <linux/stddef.h>
1415
#include <linux/ioctl.h>
1516
#include <asm/kvm.h>
1617

@@ -542,7 +543,7 @@ struct kvm_coalesced_mmio {
542543

543544
struct kvm_coalesced_mmio_ring {
544545
__u32 first, last;
545-
struct kvm_coalesced_mmio coalesced_mmio[];
546+
__DECLARE_FLEX_ARRAY(struct kvm_coalesced_mmio, coalesced_mmio);
546547
};
547548

548549
#define KVM_COALESCED_MMIO_MAX \
@@ -592,7 +593,7 @@ struct kvm_clear_dirty_log {
592593
/* for KVM_SET_SIGNAL_MASK */
593594
struct kvm_signal_mask {
594595
__u32 len;
595-
__u8 sigset[];
596+
__DECLARE_FLEX_ARRAY(__u8, sigset);
596597
};
597598

598599
/* for KVM_TPR_ACCESS_REPORTING */
@@ -1051,7 +1052,7 @@ struct kvm_irq_routing_entry {
10511052
struct kvm_irq_routing {
10521053
__u32 nr;
10531054
__u32 flags;
1054-
struct kvm_irq_routing_entry entries[];
1055+
__DECLARE_FLEX_ARRAY(struct kvm_irq_routing_entry, entries);
10551056
};
10561057

10571058
#define KVM_IRQFD_FLAG_DEASSIGN (1 << 0)
@@ -1142,7 +1143,7 @@ struct kvm_dirty_tlb {
11421143

11431144
struct kvm_reg_list {
11441145
__u64 n; /* number of regs */
1145-
__u64 reg[];
1146+
__DECLARE_FLEX_ARRAY(__u64, reg);
11461147
};
11471148

11481149
struct kvm_one_reg {
@@ -1608,7 +1609,7 @@ struct kvm_stats_desc {
16081609
#ifdef __KERNEL__
16091610
char name[KVM_STATS_NAME_SIZE];
16101611
#else
1611-
char name[];
1612+
__DECLARE_FLEX_ARRAY(char, name);
16121613
#endif
16131614
};
16141615

0 commit comments

Comments
 (0)