History

KVM: x86: Use __DECLARE_FLEX_ARRAY() for UAPI structures with VLAs

Commit 94dfc73e7cf4 ("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.

David Woodhouse committed 8 months ago

Commit 2619da71 parent d2ea4ff2 files · +12 −11Browse files

Showing the changes to include/uapi (1 of 2 files). Show all

Unified · Split

include/uapi/linux/kvm.h+6−5
@@ -11,6 +11,7 @@ · 10 unmodified lines
11#include <linux/const.h>11#include <linux/const.h>
12#include <linux/types.h>12#include <linux/types.h>
13#include <linux/compiler.h>13#include <linux/compiler.h>
14#include <linux/stddef.h>
14#include <linux/ioctl.h>15#include <linux/ioctl.h>
15#include <asm/kvm.h>16#include <asm/kvm.h>
16 17
@@ -542,7 +543,7 @@ struct kvm_coalesced_mmio { · 525 unmodified lines
542 543
543struct kvm_coalesced_mmio_ring {544struct kvm_coalesced_mmio_ring {
544 __u32 first, last;545 __u32 first, last;
545 struct kvm_coalesced_mmio coalesced_mmio[];546 __DECLARE_FLEX_ARRAY(struct kvm_coalesced_mmio, coalesced_mmio);
546};547};
547 548
548#define KVM_COALESCED_MMIO_MAX \549#define KVM_COALESCED_MMIO_MAX \
@@ -592,7 +593,7 @@ struct kvm_clear_dirty_log { · 43 unmodified lines
592/* for KVM_SET_SIGNAL_MASK */593/* for KVM_SET_SIGNAL_MASK */
593struct kvm_signal_mask {594struct kvm_signal_mask {
594 __u32 len;595 __u32 len;
595 __u8 sigset[];596 __DECLARE_FLEX_ARRAY(__u8, sigset);
596};597};
597 598
598/* for KVM_TPR_ACCESS_REPORTING */599/* for KVM_TPR_ACCESS_REPORTING */
@@ -1051,7 +1052,7 @@ struct kvm_irq_routing_entry { · 452 unmodified lines
1051struct kvm_irq_routing {1052struct kvm_irq_routing {
1052 __u32 nr;1053 __u32 nr;
1053 __u32 flags;1054 __u32 flags;
1054 struct kvm_irq_routing_entry entries[];1055 __DECLARE_FLEX_ARRAY(struct kvm_irq_routing_entry, entries);
1055};1056};
1056 1057
1057#define KVM_IRQFD_FLAG_DEASSIGN (1 << 0)1058#define KVM_IRQFD_FLAG_DEASSIGN (1 << 0)
@@ -1142,7 +1143,7 @@ struct kvm_dirty_tlb { · 84 unmodified lines
1142 1143
1143struct kvm_reg_list {1144struct kvm_reg_list {
1144 __u64 n; /* number of regs */1145 __u64 n; /* number of regs */
1145 __u64 reg[];1146 __DECLARE_FLEX_ARRAY(__u64, reg);
1146};1147};
1147 1148
1148struct kvm_one_reg {1149struct kvm_one_reg {
@@ -1608,7 +1609,7 @@ struct kvm_stats_desc { · 459 unmodified lines
1608#ifdef __KERNEL__1609#ifdef __KERNEL__
1609 char name[KVM_STATS_NAME_SIZE];1610 char name[KVM_STATS_NAME_SIZE];
1610#else1611#else
1611 char name[];1612 __DECLARE_FLEX_ARRAY(char, name);
1612#endif1613#endif
1613};1614};
1614 1615

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t