From nobody Wed Nov 5 22:16:02 2025 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538036763121177.215372663381; Thu, 27 Sep 2018 01:26:03 -0700 (PDT) Received: from localhost ([::1]:34417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5RcU-0002Wh-03 for importer@patchew.org; Thu, 27 Sep 2018 04:25:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5RaS-0001N2-IE for qemu-devel@nongnu.org; Thu, 27 Sep 2018 04:23:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5RaR-0003Xt-Lo for qemu-devel@nongnu.org; Thu, 27 Sep 2018 04:23:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5RaR-0003Xe-BY; Thu, 27 Sep 2018 04:23:51 -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 AD49B308AA0E; Thu, 27 Sep 2018 08:23:50 +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 3044D600C7; Thu, 27 Sep 2018 08:23:47 +0000 (UTC) From: Thomas Huth To: qemu-s390x@nongnu.org, Cornelia Huck Date: Thu, 27 Sep 2018 10:23:34 +0200 Message-Id: <1538036615-32542-3-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.41]); Thu, 27 Sep 2018 08:23:50 +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 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: Christian Borntraeger , qemu-devel@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 Reviewed-by: David Hildenbrand --- hw/s390x/css.c | 38 ++++++++++++++++++++++---------------- include/hw/s390x/css.h | 2 +- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 5a9fe45..04ec5cc 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -750,20 +750,25 @@ static void sch_handle_halt_func(SubchDev *sch) =20 } =20 -static void copy_sense_id_to_guest(SenseId *dest, SenseId *src) +/* + * As the SenseId struct cannot be packed (would cause unaligned accesses)= , we + * have to copy the individual fields to an unstructured area using the co= rrect + * layout (see SA22-7204-01 "Common I/O-Device Commands"). + */ +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; + stw_be_p(dest + 1, src->cu_type); + dest[3] =3D src->cu_model; + stw_be_p(dest + 4, src->dev_type); + 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; + stw_be_p(dest + 10 + i * 4, src->ciw[i].count); } } =20 @@ -1044,9 +1049,10 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr c= cw_addr, break; case CCW_CMD_SENSE_ID: { - SenseId sense_id; + /* According to SA22-7204-01, Sense-ID can store up to 256 bytes */ + 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 +1066,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