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
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 { · 525 unmodified lines
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 { · 43 unmodified lines
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 { · 452 unmodified lines
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 { · 84 unmodified lines
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 { · 459 unmodified lines
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

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