hw/hyperv: add QEMU_PACKED to uapi structs
The uapi definitions are marked with __packed hints in the kernel headers, since we want to keep the contract of the Microsoft Hypervisor ABI explicit, we should also added them in our vendored files, with a few notable exceptions where the attribute is a noop. Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260323120613.355019-1-magnuskulke@linux.microsoft.com> [PMD: Do not include "qemu/compiler.h"] Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Magnus Kulke committed
Mar 23, 2026 at 13:06 UTC
070fc710251809c4d8d2a84f24527a174e843423
2 files changed
+28
-19
include/hw/hyperv/hvgdk_mini.h
+22
-13
@@ -211,7 +211,7 @@ enum hv_intercept_type {
211
struct hv_u128 {
212
uint64_t low_part;
213
uint64_t high_part;
214
-};
214
+} QEMU_PACKED;
215
216
union hv_x64_xmm_control_status_register {
217
struct hv_u128 as_uint128;
@@ -326,13 +326,13 @@ typedef struct hv_x64_segment_register {
326
};
327
uint16_t attributes;
328
};
329
-} hv_x64_segment_register;
329
+} QEMU_PACKED hv_x64_segment_register;
330
331
typedef struct hv_x64_table_register {
332
uint16_t pad[3];
333
uint16_t limit;
334
uint64_t base;
335
-} hv_x64_table_register;
335
+} QEMU_PACKED hv_x64_table_register;
336
337
union hv_x64_fp_control_status_register {
338
struct hv_u128 as_uint128;
@@ -416,6 +416,10 @@ typedef union hv_register_value {
416
union hv_x64_register_sev_control sev_control;
417
} hv_register_value;
418
419
+/*
420
+ * This struct is __packed in the kernel. Since all members are naturally
421
+ * aligned, we can omit QEMU_PACKED to avoid address-of-packed-member warnings.
422
+ */
423
typedef struct hv_register_assoc {
424
uint32_t name; /* enum hv_register_name */
425
uint32_t reserved1;
@@ -439,7 +443,7 @@ typedef struct hv_input_get_vp_registers {
443
uint8_t rsvd_z8;
444
uint16_t rsvd_z16;
445
uint32_t names[];
442
-} hv_input_get_vp_registers;
446
+} QEMU_PACKED hv_input_get_vp_registers;
447
448
typedef struct hv_input_set_vp_registers {
449
uint64_t partition_id;
@@ -448,7 +452,7 @@ typedef struct hv_input_set_vp_registers {
452
uint8_t rsvd_z8;
453
uint16_t rsvd_z16;
454
struct hv_register_assoc elements[];
451
-} hv_input_set_vp_registers;
455
+} QEMU_PACKED hv_input_set_vp_registers;
456
457
union hv_interrupt_control {
458
uint64_t as_uint64;
@@ -468,7 +472,7 @@ struct hv_input_assert_virtual_interrupt {
472
uint8_t target_vtl;
473
uint8_t rsvd_z0;
474
uint16_t rsvd_z1;
471
-};
475
+} QEMU_PACKED;
476
477
/* /dev/mshv */
478
#define MSHV_CREATE_PARTITION _IOW(MSHV_IOCTL, 0x00, struct mshv_create_partition)
@@ -487,6 +491,11 @@ struct hv_input_assert_virtual_interrupt {
491
********************************
492
*/
493
494
+/*
495
+ * This struct is __packed in the kernel, but since all members are naturally
496
+ * aligned, so we can omit QEMU_PACKED to avoid address-of-packed-member
497
+ * warnings.
498
+ */
499
struct hv_local_interrupt_controller_state {
500
/* HV_X64_INTERRUPT_CONTROLLER_STATE */
501
uint32_t apic_id;
@@ -644,7 +653,7 @@ struct hv_x64_intercept_message_header {
653
struct hv_x64_segment_register cs_segment;
654
uint64_t rip;
655
uint64_t rflags;
647
-};
656
+} QEMU_PACKED;
657
658
union hv_x64_io_port_access_info {
659
uint8_t as_uint8;
@@ -669,7 +678,7 @@ typedef struct hv_x64_io_port_intercept_message {
678
uint64_t rcx;
679
uint64_t rsi;
680
uint64_t rdi;
672
-} hv_x64_io_port_intercept_message;
681
+} QEMU_PACKED hv_x64_io_port_intercept_message;
682
683
union hv_x64_memory_access_info {
684
uint8_t as_uint8;
@@ -692,7 +701,7 @@ struct hv_x64_memory_intercept_message {
701
uint64_t guest_virtual_address;
702
uint64_t guest_physical_address;
703
uint8_t instruction_bytes[16];
695
-};
704
+} QEMU_PACKED;
705
706
union hv_message_flags {
707
uint8_t asu8;
@@ -711,14 +720,14 @@ struct hv_message_header {
720
uint64_t sender;
721
union hv_port_id port;
722
};
714
-};
723
+} QEMU_PACKED;
724
725
struct hv_message {
726
struct hv_message_header header;
727
union {
728
uint64_t payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
729
} u;
721
-};
730
+} QEMU_PACKED;
731
732
/* From github.com/rust-vmm/mshv-bindings/src/x86_64/regs.rs */
733
@@ -731,13 +740,13 @@ struct hv_cpuid_entry {
740
uint32_t ecx;
741
uint32_t edx;
742
uint32_t padding[3];
734
-};
743
+} QEMU_PACKED;
744
745
struct hv_cpuid {
746
uint32_t nent;
747
uint32_t padding;
748
struct hv_cpuid_entry entries[0];
740
-};
749
+} QEMU_PACKED;
750
751
#define IA32_MSR_TSC 0x00000010
752
#define IA32_MSR_EFER 0xC0000080
include/hw/hyperv/hvhdk.h
+6
-6
@@ -16,7 +16,7 @@ struct hv_input_set_partition_property {
16
uint32_t property_code; /* enum hv_partition_property_code */
17
uint32_t padding;
18
uint64_t property_value;
19
-};
19
+} QEMU_PACKED;
20
21
union hv_partition_synthetic_processor_features {
22
uint64_t as_uint64[HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS];
@@ -201,12 +201,12 @@ typedef struct hv_input_translate_virtual_address {
201
uint32_t padding;
202
uint64_t control_flags;
203
uint64_t gva_page;
204
-} hv_input_translate_virtual_address;
204
+} QEMU_PACKED hv_input_translate_virtual_address;
205
206
typedef struct hv_output_translate_virtual_address {
207
union hv_translate_gva_result translation_result;
208
uint64_t gpa_page;
209
-} hv_output_translate_virtual_address;
209
+} QEMU_PACKED hv_output_translate_virtual_address;
210
211
typedef struct hv_register_x64_cpuid_result_parameters {
212
struct {
@@ -226,13 +226,13 @@ typedef struct hv_register_x64_cpuid_result_parameters {
226
uint32_t edx;
227
uint32_t edx_mask;
228
} result;
229
-} hv_register_x64_cpuid_result_parameters;
229
+} QEMU_PACKED hv_register_x64_cpuid_result_parameters;
230
231
typedef struct hv_register_x64_msr_result_parameters {
232
uint32_t msr_index;
233
uint32_t access_type;
234
uint32_t action; /* enum hv_unimplemented_msr_action */
235
-} hv_register_x64_msr_result_parameters;
235
+} QEMU_PACKED hv_register_x64_msr_result_parameters;
236
237
union hv_register_intercept_result_parameters {
238
struct hv_register_x64_cpuid_result_parameters cpuid;
@@ -244,6 +244,6 @@ typedef struct hv_input_register_intercept_result {
244
uint32_t vp_index;
245
uint32_t intercept_type; /* enum hv_intercept_type */
246
union hv_register_intercept_result_parameters parameters;
247
-} hv_input_register_intercept_result;
247
+} QEMU_PACKED hv_input_register_intercept_result;
248
249
#endif /* HW_HYPERV_HVHDK_H */