target/i386/kvm.c: Don't mark cpuid_data as QEMU_PACKED
PATCH 1/1 target/i386/kvm.c: Don't mark cpuid_data as QEMU_PACKED
clang complains about taking the address of a packed member of a struct:
target/i386/kvm.c:1245:27: warning: taking address of packed member 'cpuid' of class or structure '' may result in an unaligned pointer value [-Waddress-of-packed-member]
c = cpuid_find_entry(&cpuid_data.cpuid, 1, 0);
^~~~~~~~~~~~~~~~
target/i386/kvm.c:1297:31: warning: taking address of packed member 'cpuid' of class or structure '' may result in an unaligned pointer value [-Waddress-of-packed-member]
c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0);
^~~~~~~~~~~~~~~~The kernel's definitions of struct kvm_cpuid2 and struct kvm_cpuid_entry2 are carefully set up with padding fields so that there is no between-struct padding anyway, so the QEMU_PACKED annotation is unnecessary and might result in the compiler generating worse code. Drop it, and instead assert at build time that there is no stray padding.
--- target/i386/kvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
target/i386/kvm.c +9 -1
@@ -864,7 +864,15 @@ int kvm_arch_init_vcpu(CPUState *cs)struct {struct kvm_cpuid2 cpuid;struct kvm_cpuid_entry2 entries[KVM_MAX_CPUID_ENTRIES ]; - } QEMU_PACKED cpuid_data; + } cpuid_data; +/* +* The kernel defines these structs with padding fields so there +* should be no extra padding in our cpuid_data struct. +*/ +QEMU_BUILD_BUG_ON (sizeof (cpuid_data) != +sizeof (struct kvm_cpuid2 ) + +sizeof (struct kvm_cpuid_entry2 ) *KVM_MAX_CPUID_ENTRIES ); +X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env;uint32_t limit, i, j, cpuid_i;
Signature · 1 line
2.19.2
Quoted 10 lines · Peter Maydell
clang complains about taking the address of a packed member of a struct:
target/i386/kvm.c:1245:27: warning: taking address of packed member 'cpuid' of class or structure '' may result in an unaligned pointer value [-Waddress-of-packed-member]c = cpuid_find_entry(&cpuid_data.cpuid, 1, 0); ^~~~~~~~~~~~~~~~ target/i386/kvm.c:1297:31: warning: taking address of packed member 'cpuid' of class or structure '' may result in an unaligned pointer value [-Waddress-of-packed-member] c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0); ^~~~~~~~~~~~~~~~
Quoted 8 lines
The kernel's definitions of struct
kvm_cpuid2and structkvm_cpuid_entry2are carefully set up with padding fields so that there is no between-struct padding anyway, so theQEMU_PACKEDannotation is unnecessary and might result in the compiler generating worse code. Drop it, and instead assert at build time that there is no stray padding.Signed-off-by Peter Maydell <[email protected]>
Quoted 26 lines
--- target/i386/kvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)target/i386/kvm.c +9
-1@@ -864,7 +864,15 @@ int kvm_arch_init_vcpu(CPUState *cs)struct {struct kvm_cpuid2 cpuid;struct kvm_cpuid_entry2 entries[KVM_MAX_CPUID_ENTRIES ]; - } QEMU_PACKED cpuid_data; + } cpuid_data; +/* +* The kernel defines these structs with padding fields so there +* should be no extra padding in our cpuid_data struct. +*/ +QEMU_BUILD_BUG_ON (sizeof (cpuid_data) != +sizeof (struct kvm_cpuid2 ) + +sizeof (struct kvm_cpuid_entry2 ) *KVM_MAX_CPUID_ENTRIES ); +X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env;uint32_t limit, i, j, cpuid_i;
Quoted 17 lines · Peter Maydell
clang complains about taking the address of a packed member of a struct:
target/i386/kvm.c:1245:27: warning: taking address of packed member 'cpuid' of class or structure '' may result in an unaligned pointer value [-Waddress-of-packed-member]c = cpuid_find_entry(&cpuid_data.cpuid, 1, 0); ^~~~~~~~~~~~~~~~ target/i386/kvm.c:1297:31: warning: taking address of packed member 'cpuid' of class or structure '' may result in an unaligned pointer value [-Waddress-of-packed-member] c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0); ^~~~~~~~~~~~~~~~The kernel's definitions of struct
kvm_cpuid2and structkvm_cpuid_entry2are carefully set up with padding fields so that there is no between-struct padding anyway, so theQEMU_PACKEDannotation is unnecessary and might result in the compiler generating worse code. Drop it, and instead assert at build time that there is no stray padding.
Quoted 4 lines
Signed-off-by Peter Maydell <[email protected]>--- target/i386/kvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
r~
Eduardo Habkost
AppliedQuoted 10 lines · Peter Maydell
clang complains about taking the address of a packed member of a struct:
target/i386/kvm.c:1245:27: warning: taking address of packed member 'cpuid' of class or structure '' may result in an unaligned pointer value [-Waddress-of-packed-member]c = cpuid_find_entry(&cpuid_data.cpuid, 1, 0); ^~~~~~~~~~~~~~~~ target/i386/kvm.c:1297:31: warning: taking address of packed member 'cpuid' of class or structure '' may result in an unaligned pointer value [-Waddress-of-packed-member] c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0); ^~~~~~~~~~~~~~~~
Quoted 8 lines
The kernel's definitions of struct
kvm_cpuid2and structkvm_cpuid_entry2are carefully set up with padding fields so that there is no between-struct padding anyway, so theQEMU_PACKEDannotation is unnecessary and might result in the compiler generating worse code. Drop it, and instead assert at build time that there is no stray padding.Signed-off-by Peter Maydell <[email protected]>
Queued, thanks.
Signature · 1 line
Eduardo