From nobody Thu May 2 02:11:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537890471005510.6647959846947; Tue, 25 Sep 2018 08:47:51 -0700 (PDT) Received: from localhost ([::1]:53839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4pYz-0004m3-NR for importer@patchew.org; Tue, 25 Sep 2018 11:47:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4p8U-0004Z3-Lx for qemu-devel@nongnu.org; Tue, 25 Sep 2018 11:20:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4p8T-0000AO-8M for qemu-devel@nongnu.org; Tue, 25 Sep 2018 11:20:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g4p8T-00008J-0w; Tue, 25 Sep 2018 11:20:25 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2707130001DD; Tue, 25 Sep 2018 15:20:24 +0000 (UTC) Received: from thuth.com (ovpn-116-102.ams2.redhat.com [10.36.116.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F75D5C6B6; Tue, 25 Sep 2018 15:20:21 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Cornelia Huck Date: Tue, 25 Sep 2018 17:20:07 +0200 Message-Id: <1537888809-14705-2-git-send-email-thuth@redhat.com> In-Reply-To: <1537888809-14705-1-git-send-email-thuth@redhat.com> References: <1537888809-14705-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 25 Sep 2018 15:20:24 +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 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: Peter Maydell , Christian Borntraeger , qemu-s390x@nongnu.org, "Dr. David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 mis- aligned memory address. The easiest solution to fix this problem is to move the packed structures to the beginning of the S390IPLState. Also add some additional comments here to prevent that this problem will be introduced again in the future. Signed-off-by: Thomas Huth Reviewed-by: David Hildenbrand --- hw/s390x/ipl.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h index 4e87b89..f72a82f 100644 --- a/hw/s390x/ipl.h +++ b/hw/s390x/ipl.h @@ -132,15 +132,17 @@ typedef struct QemuIplParameters QemuIplParameters; struct S390IPLState { /*< private >*/ DeviceState parent_obj; + /* Packed structs first (to make sure we've got a proper alignment): */ + IplParameterBlock iplb; + QemuIplParameters qipl; + /* Other private members without packed attribute: */ 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; --=20 1.8.3.1 From nobody Thu May 2 02:11:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537890449994753.0665832136547; Tue, 25 Sep 2018 08:47:29 -0700 (PDT) Received: from localhost ([::1]:53838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4pYe-0004VP-OV for importer@patchew.org; Tue, 25 Sep 2018 11:47:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4p8a-0004fI-BF for qemu-devel@nongnu.org; Tue, 25 Sep 2018 11:20:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4p8Z-0000IS-DJ for qemu-devel@nongnu.org; Tue, 25 Sep 2018 11:20:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g4p8Z-0000Hj-5Y; Tue, 25 Sep 2018 11:20:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6819930832D0; Tue, 25 Sep 2018 15:20:30 +0000 (UTC) Received: from thuth.com (ovpn-116-102.ams2.redhat.com [10.36.116.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DD605C6DC; Tue, 25 Sep 2018 15:20:24 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Cornelia Huck Date: Tue, 25 Sep 2018 17:20:08 +0200 Message-Id: <1537888809-14705-3-git-send-email-thuth@redhat.com> In-Reply-To: <1537888809-14705-1-git-send-email-thuth@redhat.com> References: <1537888809-14705-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 25 Sep 2018 15:20:30 +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 2/3] hw/s390x/css: Remove QEMU_PACKED from struct SenseId 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: Peter Maydell , Christian Borntraeger , qemu-s390x@nongnu.org, "Dr. David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The uint16_t member cu_type of struct SenseId is not naturally aligned, and since the struct is marked with QEMU_PACKED, this can lead to unaligned memory accesses - which does not work on architectures like Sparc. Thus remove the QEMU_PACKED here and rather copy the struct byte by byte when we do copy_sense_id_to_guest(). Signed-off-by: Thomas Huth --- hw/s390x/css.c | 35 +++++++++++++++++++---------------- include/hw/s390x/css.h | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 5a9fe45..aaa2efa 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -750,20 +750,23 @@ static void sch_handle_halt_func(SubchDev *sch) =20 } =20 -static void copy_sense_id_to_guest(SenseId *dest, SenseId *src) +static void copy_sense_id_to_guest(uint8_t *dest, SenseId *src) { int i; =20 - dest->reserved =3D src->reserved; - dest->cu_type =3D cpu_to_be16(src->cu_type); - dest->cu_model =3D src->cu_model; - dest->dev_type =3D cpu_to_be16(src->dev_type); - dest->dev_model =3D src->dev_model; - dest->unused =3D src->unused; - for (i =3D 0; i < ARRAY_SIZE(dest->ciw); i++) { - dest->ciw[i].type =3D src->ciw[i].type; - dest->ciw[i].command =3D src->ciw[i].command; - dest->ciw[i].count =3D cpu_to_be16(src->ciw[i].count); + dest[0] =3D src->reserved; + dest[1] =3D src->cu_type >> 8; + dest[2] =3D src->cu_type & 0xff; + dest[3] =3D src->cu_model; + dest[4] =3D src->dev_type >> 8; + dest[5] =3D src->dev_type & 0xff; + dest[6] =3D src->dev_model; + dest[7] =3D src->unused; + for (i =3D 0; i < ARRAY_SIZE(src->ciw); i++) { + dest[8 + i * 4] =3D src->ciw[i].type; + dest[9 + i * 4] =3D src->ciw[i].command; + dest[10 + i * 4] =3D src->ciw[i].count >> 8; + dest[11 + i * 4] =3D src->ciw[i].count & 0xff; } } =20 @@ -1044,9 +1047,9 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr cc= w_addr, break; case CCW_CMD_SENSE_ID: { - SenseId sense_id; + uint8_t sense_id[256]; =20 - copy_sense_id_to_guest(&sense_id, &sch->id); + copy_sense_id_to_guest(sense_id, &sch->id); /* Sense ID information is device specific. */ if (check_len) { if (ccw.count !=3D sizeof(sense_id)) { @@ -1060,11 +1063,11 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr = ccw_addr, * have enough place to store at least bytes 0-3. */ if (len >=3D 4) { - sense_id.reserved =3D 0xff; + sense_id[0] =3D 0xff; } else { - sense_id.reserved =3D 0; + sense_id[0] =3D 0; } - ccw_dstream_write_buf(&sch->cds, &sense_id, len); + ccw_dstream_write_buf(&sch->cds, sense_id, len); sch->curr_status.scsw.count =3D ccw_dstream_residual_count(&sch->c= ds); ret =3D 0; break; diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index 9da5912..bec82d0 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -48,7 +48,7 @@ typedef struct SenseId { uint8_t unused; /* padding byte */ /* extended part */ CIW ciw[MAX_CIWS]; /* variable # of CIWs */ -} QEMU_PACKED SenseId; +} SenseId; /* Note: No QEMU_PACKED due to unaligned memb= ers */ =20 /* Channel measurements, from linux/drivers/s390/cio/cmf.c. */ typedef struct CMB { --=20 1.8.3.1 From nobody Thu May 2 02:11:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537890745197833.5037236357266; Tue, 25 Sep 2018 08:52:25 -0700 (PDT) Received: from localhost ([::1]:53884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4pdP-0000cW-VF for importer@patchew.org; Tue, 25 Sep 2018 11:52:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4p8u-0004wd-S5 for qemu-devel@nongnu.org; Tue, 25 Sep 2018 11:20:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4p8p-0000WD-Uq for qemu-devel@nongnu.org; Tue, 25 Sep 2018 11:20:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g4p8p-0000Vl-Jf; Tue, 25 Sep 2018 11:20:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD13930842AC; Tue, 25 Sep 2018 15:20:46 +0000 (UTC) Received: from thuth.com (ovpn-116-102.ams2.redhat.com [10.36.116.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECE095C730; Tue, 25 Sep 2018 15:20:30 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Cornelia Huck Date: Tue, 25 Sep 2018 17:20:09 +0200 Message-Id: <1537888809-14705-4-git-send-email-thuth@redhat.com> In-Reply-To: <1537888809-14705-1-git-send-email-thuth@redhat.com> References: <1537888809-14705-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 25 Sep 2018 15:20:46 +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 3/3] hw/s390x/ioinst: Fix alignment problem in struct SubchDev 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: Peter Maydell , Christian Borntraeger , qemu-s390x@nongnu.org, "Dr. David Alan Gilbert" , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" struct SubchDev embeds several other structures which are marked with QEMU_PACKED. This causes the compiler to not care for proper alignment of these structures. When we later pass around pointers to the unaligned struct members during migration, this causes problems on host architectures like Sparc that can not do unaligned memory access. Most of the structs in ioinst.h are naturally aligned, so we can fix most of the problem by removing the QEMU_PACKED statements (and use QEMU_BUILD_BUG_MSG() statements instead to make sure that there is no padding). However, for the struct SCHIB, we have to keep the QEMU_PACKED since the compiler adds some padding here otherwise. Move this struct to the beginning of struct SubchDev instead to fix the alignment problem here, too. Signed-off-by: Thomas Huth --- include/hw/s390x/css.h | 4 ++-- include/hw/s390x/ioinst.h | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index bec82d0..aae19c4 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -118,11 +118,12 @@ typedef enum IOInstEnding { typedef struct SubchDev SubchDev; struct SubchDev { /* channel-subsystem related things: */ + SCHIB curr_status; /* Needs alignment and thus must come fir= st */ + ORB orb; uint8_t cssid; uint8_t ssid; uint16_t schid; uint16_t devno; - SCHIB curr_status; uint8_t sense_data[32]; hwaddr channel_prog; CCW1 last_cmd; @@ -131,7 +132,6 @@ struct SubchDev { bool thinint_active; uint8_t ccw_no_data_cnt; uint16_t migrated_schid; /* used for missmatch detection */ - ORB orb; CcwDataStream cds; /* transport-provided data: */ int (*ccw_cb) (SubchDev *, CCW1); diff --git a/include/hw/s390x/ioinst.h b/include/hw/s390x/ioinst.h index 5f2db69..c6737a3 100644 --- a/include/hw/s390x/ioinst.h +++ b/include/hw/s390x/ioinst.h @@ -25,7 +25,8 @@ typedef struct SCSW { uint8_t dstat; uint8_t cstat; uint16_t count; -} QEMU_PACKED SCSW; +} SCSW; +QEMU_BUILD_BUG_MSG(sizeof(SCSW) !=3D 12, "size of SCSW is wrong"); =20 #define SCSW_FLAGS_MASK_KEY 0xf000 #define SCSW_FLAGS_MASK_SCTL 0x0800 @@ -94,7 +95,8 @@ typedef struct PMCW { uint8_t pam; uint8_t chpid[8]; uint32_t chars; -} QEMU_PACKED PMCW; +} PMCW; +QEMU_BUILD_BUG_MSG(sizeof(PMCW) !=3D 28, "size of PMCW is wrong"); =20 #define PMCW_FLAGS_MASK_QF 0x8000 #define PMCW_FLAGS_MASK_W 0x4000 @@ -127,7 +129,8 @@ typedef struct IRB { uint32_t esw[5]; uint32_t ecw[8]; uint32_t emw[8]; -} QEMU_PACKED IRB; +} IRB; +QEMU_BUILD_BUG_MSG(sizeof(IRB) !=3D 96, "size of IRB is wrong"); =20 /* operation request block */ typedef struct ORB { @@ -136,7 +139,8 @@ typedef struct ORB { uint8_t lpm; uint8_t ctrl1; uint32_t cpa; -} QEMU_PACKED ORB; +} ORB; +QEMU_BUILD_BUG_MSG(sizeof(ORB) !=3D 12, "size of ORB is wrong"); =20 #define ORB_CTRL0_MASK_KEY 0xf000 #define ORB_CTRL0_MASK_SPND 0x0800 @@ -165,7 +169,8 @@ typedef struct CCW0 { uint8_t flags; uint8_t reserved; uint16_t count; -} QEMU_PACKED CCW0; +} CCW0; +QEMU_BUILD_BUG_MSG(sizeof(CCW0) !=3D 8, "size of CCW0 is wrong"); =20 /* channel command word (type 1) */ typedef struct CCW1 { @@ -173,7 +178,8 @@ typedef struct CCW1 { uint8_t flags; uint16_t count; uint32_t cda; -} QEMU_PACKED CCW1; +} CCW1; +QEMU_BUILD_BUG_MSG(sizeof(CCW1) !=3D 8, "size of CCW1 is wrong"); =20 #define CCW_FLAG_DC 0x80 #define CCW_FLAG_CC 0x40 @@ -192,7 +198,8 @@ typedef struct CCW1 { typedef struct CRW { uint16_t flags; uint16_t rsid; -} QEMU_PACKED CRW; +} CRW; +QEMU_BUILD_BUG_MSG(sizeof(CRW) !=3D 4, "size of CRW is wrong"); =20 #define CRW_FLAGS_MASK_S 0x4000 #define CRW_FLAGS_MASK_R 0x2000 --=20 1.8.3.1