From patchwork Thu Sep 27 08:23:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 975607 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42LSXP18hNz9s3Z for ; Thu, 27 Sep 2018 18:24:35 +1000 (AEST) Received: from localhost ([::1]:34405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5Rb6-0001M2-47 for incoming@patchwork.ozlabs.org; Thu, 27 Sep 2018 04:24:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5RaP-0001Lq-9N for qemu-devel@nongnu.org; Thu, 27 Sep 2018 04:23:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5RaO-0003Wt-H6 for qemu-devel@nongnu.org; Thu, 27 Sep 2018 04:23:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5RaO-0003Wi-Af; Thu, 27 Sep 2018 04:23:48 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 990963082128; Thu, 27 Sep 2018 08:23:47 +0000 (UTC) Received: from thuth.com (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FA1E600C7; Thu, 27 Sep 2018 08:23:44 +0000 (UTC) From: Thomas Huth To: qemu-s390x@nongnu.org, Cornelia Huck Date: Thu, 27 Sep 2018 10:23:33 +0200 Message-Id: <1538036615-32542-2-git-send-email-thuth@redhat.com> In-Reply-To: <1538036615-32542-1-git-send-email-thuth@redhat.com> References: <1538036615-32542-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 27 Sep 2018 08:23:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/3] hw/s390x/ipl: Fix alignment problems of S390IPLState members X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christian Borntraeger , qemu-devel@nongnu.org, "Dr. David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The IplParameterBlock and QemuIplParameters structures are declared with QEMU_PACKED, so the compiler assumes that the structures do not need to be aligned in memory. Since the are listed after a "bool" within the S390IPLState, the IplParameterBlock and QemuIplParameters are also indeed mis-aligned in memory. This causes problems on Sparc during migration, since we use VMSTATE_UINT16 in vmstate_iplb to access the devno member for example, and the corresponding migration functions (like qemu_get_be16s) then try to access a 16-bit value from a misaligned memory address. The easiest solution to fix this problem is to move the packed structures to the beginning of the S390IPLState, right after the DeviceState of course which has to stay first for QOM reasons. But since DeviceState is a non-packed struct, we can be sure that it will be padded to the correct alignment at the end. If not, the QEMU_BUILD_BUG_MSG in this patch will tell us. Signed-off-by: Thomas Huth Reviewed-by: David Hildenbrand --- hw/s390x/ipl.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h index 4e87b89..b3a07a1 100644 --- a/hw/s390x/ipl.h +++ b/hw/s390x/ipl.h @@ -132,15 +132,15 @@ typedef struct QemuIplParameters QemuIplParameters; struct S390IPLState { /*< private >*/ DeviceState parent_obj; + IplParameterBlock iplb; + QemuIplParameters qipl; uint64_t start_addr; uint64_t compat_start_addr; uint64_t bios_start_addr; uint64_t compat_bios_start_addr; bool enforce_bios; - IplParameterBlock iplb; bool iplb_valid; bool netboot; - QemuIplParameters qipl; /* reset related properties don't have to be migrated or reset */ enum s390_reset reset_type; int reset_cpu_index; @@ -157,6 +157,7 @@ struct S390IPLState { bool iplbext_migration; }; typedef struct S390IPLState S390IPLState; +QEMU_BUILD_BUG_MSG(offsetof(S390IPLState, iplb) & 3, "alignment of iplb wrong"); #define S390_IPL_TYPE_FCP 0x00 #define S390_IPL_TYPE_CCW 0x02