From nobody Mon Feb 9 08:28:01 2026 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