From nobody Sat Apr 27 14:30:44 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506029538601618.866010279936; Thu, 21 Sep 2017 14:32:18 -0700 (PDT) Received: from localhost ([::1]:55599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv94j-00047O-Hp for importer@patchew.org; Thu, 21 Sep 2017 17:32:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv93o-0003lB-JX for qemu-devel@nongnu.org; Thu, 21 Sep 2017 17:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dv93j-0005Cd-MB for qemu-devel@nongnu.org; Thu, 21 Sep 2017 17:31:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dv93j-0005CN-Dl for qemu-devel@nongnu.org; Thu, 21 Sep 2017 17:30:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CFBA883D7; Thu, 21 Sep 2017 21:30:58 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEA0F6BF6A; Thu, 21 Sep 2017 21:30:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5CFBA883D7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 21 Sep 2017 23:30:52 +0200 Message-Id: <20170921213052.1765-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 21 Sep 2017 21:30:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1] s390x/kvm: fix and cleanup storing CPU status 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: thuth@redhat.com, david@redhat.com, cohuck@redhat.com, Alexander Graf , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" env->psa is a 64bit value, while we copy 4 bytes into the save area, resulting always in 0 getting stored. Let's try to reduce such errors by using a proper structure. While at it, use correct cpu->be conversion (and get_psw_mask()), as we will be reusing this code for TCG soon. Signed-off-by: David Hildenbrand --- Found with my fancy SIGP kvm-unit-tests I am currently working on. And looks like there is even more ... stay tuned :) target/s390x/kvm.c | 63 +++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index 720cb1d833..21c22f48b9 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -1548,22 +1548,38 @@ static int do_store_adtl_status(S390CPU *cpu, hwadd= r addr, hwaddr len) return 0; } =20 +struct sigp_save_area { + uint64_t fprs[16]; /* 0x0000 */ + uint64_t grs[16]; /* 0x0080 */ + PSW psw; /* 0x0100 */ + uint8_t pad_0x0110[0x0118 - 0x0110]; /* 0x0110 */ + uint32_t prefix; /* 0x0118 */ + uint32_t fpc; /* 0x011c */ + uint8_t pad_0x0120[0x0124 - 0x0120]; /* 0x0120 */ + uint32_t todpr; /* 0x0124 */ + uint64_t cputm; /* 0x0128 */ + uint64_t ckc; /* 0x0130 */ + uint8_t pad_0x0138[0x0140 - 0x0138]; /* 0x0138 */ + uint32_t ars[16]; /* 0x0140 */ + uint64_t crs[16]; /* 0x0384 */ +} QEMU_PACKED; + #define KVM_S390_STORE_STATUS_DEF_ADDR offsetof(LowCore, floating_pt_save_= area) -#define SAVE_AREA_SIZE 512 static int kvm_s390_store_status(S390CPU *cpu, hwaddr addr, bool store_arc= h) { static const uint8_t ar_id =3D 1; - uint64_t ckc =3D cpu->env.ckc >> 8; - void *mem; + struct sigp_save_area *sa; + hwaddr len =3D sizeof(*sa); int i; - hwaddr len =3D SAVE_AREA_SIZE; =20 - mem =3D cpu_physical_memory_map(addr, &len, 1); - if (!mem) { + QEMU_BUILD_BUG_ON(sizeof(*sa) !=3D 512); + + sa =3D cpu_physical_memory_map(addr, &len, 1); + if (!sa) { return -EFAULT; } - if (len !=3D SAVE_AREA_SIZE) { - cpu_physical_memory_unmap(mem, len, 1, 0); + if (len !=3D sizeof(*sa)) { + cpu_physical_memory_unmap(sa, len, 1, 0); return -EFAULT; } =20 @@ -1571,19 +1587,26 @@ static int kvm_s390_store_status(S390CPU *cpu, hwad= dr addr, bool store_arch) cpu_physical_memory_write(offsetof(LowCore, ar_access_id), &ar_id,= 1); } for (i =3D 0; i < 16; ++i) { - *((uint64_t *)mem + i) =3D get_freg(&cpu->env, i)->ll; - } - memcpy(mem + 128, &cpu->env.regs, 128); - memcpy(mem + 256, &cpu->env.psw, 16); - memcpy(mem + 280, &cpu->env.psa, 4); - memcpy(mem + 284, &cpu->env.fpc, 4); - memcpy(mem + 292, &cpu->env.todpr, 4); - memcpy(mem + 296, &cpu->env.cputm, 8); - memcpy(mem + 304, &ckc, 8); - memcpy(mem + 320, &cpu->env.aregs, 64); - memcpy(mem + 384, &cpu->env.cregs, 128); + sa->fprs[i] =3D cpu_to_be64(get_freg(&cpu->env, i)->ll); + } + for (i =3D 0; i < 16; ++i) { + sa->grs[i] =3D cpu_to_be64(cpu->env.regs[i]); + } + sa->psw.addr =3D cpu_to_be64(cpu->env.psw.addr); + sa->psw.mask =3D cpu_to_be64(get_psw_mask(&cpu->env)); + sa->prefix =3D cpu_to_be32(cpu->env.psa); + sa->fpc =3D cpu_to_be32(cpu->env.fpc); + sa->todpr =3D cpu_to_be32(cpu->env.todpr); + sa->cputm =3D cpu_to_be64(cpu->env.cputm); + sa->ckc =3D cpu_to_be64(cpu->env.ckc >> 8); + for (i =3D 0; i < 16; ++i) { + sa->ars[i] =3D cpu_to_be32(cpu->env.aregs[i]); + } + for (i =3D 0; i < 16; ++i) { + sa->ars[i] =3D cpu_to_be64(cpu->env.cregs[i]); + } =20 - cpu_physical_memory_unmap(mem, len, 1, len); + cpu_physical_memory_unmap(sa, len, 1, len); =20 return 0; } --=20 2.13.5