From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eduardo Habkost Subject: [PULL 3/4] target/i386/kvm.c: Don't mark cpuid_data as QEMU_PACKED Date: Tue, 11 Dec 2018 18:53:45 -0200 Message-ID: <20181211205346.11118-4-ehabkost@redhat.com> References: <20181211205346.11118-1-ehabkost@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , Marcelo Tosatti , Paolo Bonzini , Richard Henderson To: Peter Maydell , qemu-devel@nongnu.org Return-path: In-Reply-To: <20181211205346.11118-1-ehabkost@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel2=m.gmane.org@nongnu.org Sender: "Qemu-devel" List-Id: kvm.vger.kernel.org From: 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 'cpui= d' of class or structure '' may result in an unaligned pointer value [-Wa= ddress-of-packed-member] c =3D cpuid_find_entry(&cpuid_data.cpuid, 1, 0); ^~~~~~~~~~~~~~~~ target/i386/kvm.c:1297:31: warning: taking address of packed member 'cpui= d' of class or structure '' may result in an unaligned pointer value [-Wa= ddress-of-packed-member] c =3D 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. Signed-off-by: Peter Maydell Message-Id: <20181210114654.31433-1-peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Signed-off-by: Eduardo Habkost --- target/i386/kvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index b2401d13ea..739cf8c8ea 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -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) !=3D + sizeof(struct kvm_cpuid2) + + sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_EN= TRIES); + X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; uint32_t limit, i, j, cpuid_i; --=20 2.18.0.rc1.1.g3f1ff2140