From nobody Sun Feb 8 19:59:46 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@gnu.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@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506632260836861.8212839478279; Thu, 28 Sep 2017 13:57:40 -0700 (PDT) Received: from localhost ([::1]:60868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxfsB-0004mC-3G for importer@patchew.org; Thu, 28 Sep 2017 16:57:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxfaR-00059H-L9 for qemu-devel@nongnu.org; Thu, 28 Sep 2017 16:39:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxfaQ-0003n9-Eo for qemu-devel@nongnu.org; Thu, 28 Sep 2017 16:39:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxfaQ-0003me-6G for qemu-devel@nongnu.org; Thu, 28 Sep 2017 16:39:10 -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 2FEC081DEE; Thu, 28 Sep 2017 20:39:09 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-18.ams2.redhat.com [10.36.116.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 433576E506; Thu, 28 Sep 2017 20:39:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2FEC081DEE Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 28 Sep 2017 22:37:07 +0200 Message-Id: <20170928203708.9376-30-david@redhat.com> In-Reply-To: <20170928203708.9376-1-david@redhat.com> References: <20170928203708.9376-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.25]); Thu, 28 Sep 2017 20:39:09 +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 v2 29/30] s390x/tcg: refactor stfl(e) to use s390_get_feat_block() X-BeenThere: qemu-devel@gnu.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 Hildenbrand , cohuck@redhat.com, Richard Henderson , Alexander Graf , Christian Borntraeger Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.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" Refactor it to use s390_get_feat_block(). Directly write into the mapped lowcore with stfl and make sure it is really only compiled if needed. While at it, add an alignment check for STFLE and avoid potential_page_fault() by properly restoring the CPU state. Due to s390_get_feat_block(), we will now also indicate the "Configuration-z-architectural-mode", which is with new SIGP code the right thing to do. Signed-off-by: David Hildenbrand Reviewed-by: Richard Henderson --- target/s390x/misc_helper.c | 67 ++++++++++++++++++++----------------------= ---- target/s390x/translate.c | 1 - 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c index 0b3613ea5f..4afd90b969 100644 --- a/target/s390x/misc_helper.c +++ b/target/s390x/misc_helper.c @@ -475,66 +475,57 @@ void HELPER(per_ifetch)(CPUS390XState *env, uint64_t = addr) } #endif =20 -/* The maximum bit defined at the moment is 129. */ -#define MAX_STFL_WORDS 3 +static uint8_t stfl_bytes[2048]; +static unsigned int used_stfl_bytes; =20 -/* Canonicalize the current cpu's features into the 64-bit words required - by STFLE. Return the index-1 of the max word that is non-zero. */ -static unsigned do_stfle(CPUS390XState *env, uint64_t words[MAX_STFL_WORDS= ]) +static void prepare_stfl(void) { - S390CPU *cpu =3D s390_env_get_cpu(env); - const unsigned long *features =3D cpu->model->features; - unsigned max_bit =3D 0; - S390Feat feat; - - memset(words, 0, sizeof(uint64_t) * MAX_STFL_WORDS); + static bool initialized; + int i; =20 - if (test_bit(S390_FEAT_ZARCH, features)) { - /* z/Architecture is always active if around */ - words[0] =3D 1ull << (63 - 2); + /* racy, but we don't care, the same values are always written */ + if (initialized) { + return; } =20 - for (feat =3D find_first_bit(features, S390_FEAT_MAX); - feat < S390_FEAT_MAX; - feat =3D find_next_bit(features, S390_FEAT_MAX, feat + 1)) { - const S390FeatDef *def =3D s390_feat_def(feat); - if (def->type =3D=3D S390_FEAT_TYPE_STFL) { - unsigned bit =3D def->bit; - if (bit > max_bit) { - max_bit =3D bit; - } - assert(bit / 64 < MAX_STFL_WORDS); - words[bit / 64] |=3D 1ULL << (63 - bit % 64); + s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes); + for (i =3D 0; i < sizeof(stfl_bytes); i++) { + if (stfl_bytes[i]) { + used_stfl_bytes =3D i + 1; } } - - return max_bit / 64; + initialized =3D true; } =20 #ifndef CONFIG_USER_ONLY void HELPER(stfl)(CPUS390XState *env) { - uint64_t words[MAX_STFL_WORDS]; LowCore *lowcore; =20 lowcore =3D cpu_map_lowcore(env); - do_stfle(env, words); - lowcore->stfl_fac_list =3D cpu_to_be32(words[0] >> 32); + prepare_stfl(); + memcpy(&lowcore->stfl_fac_list, stfl_bytes, sizeof(lowcore->stfl_fac_l= ist)); cpu_unmap_lowcore(lowcore); } #endif =20 uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr) { - uint64_t words[MAX_STFL_WORDS]; - unsigned count_m1 =3D env->regs[0] & 0xff; - unsigned max_m1 =3D do_stfle(env, words); - unsigned i; + const uintptr_t ra =3D GETPC(); + const int count_bytes =3D ((env->regs[0] & 0xff) + 1) * 8; + const int max_bytes =3D ROUND_UP(used_stfl_bytes, 8); + int i; + + if (addr & 0x7) { + cpu_restore_state(ENV_GET_CPU(env), ra); + program_interrupt(env, PGM_SPECIFICATION, 4); + } =20 - for (i =3D 0; i <=3D count_m1; ++i) { - cpu_stq_data(env, addr + 8 * i, words[i]); + prepare_stfl(); + for (i =3D 0; i < count_bytes; ++i) { + cpu_stb_data_ra(env, addr + i, stfl_bytes[i], ra); } =20 - env->regs[0] =3D deposit64(env->regs[0], 0, 8, max_m1); - return (count_m1 >=3D max_m1 ? 0 : 3); + env->regs[0] =3D deposit64(env->regs[0], 0, 8, (max_bytes / 8) - 1); + return count_bytes >=3D max_bytes ? 0 : 3; } diff --git a/target/s390x/translate.c b/target/s390x/translate.c index 6a2e084f87..6fad20f75d 100644 --- a/target/s390x/translate.c +++ b/target/s390x/translate.c @@ -4143,7 +4143,6 @@ static ExitStatus op_sturg(DisasContext *s, DisasOps = *o) =20 static ExitStatus op_stfle(DisasContext *s, DisasOps *o) { - potential_page_fault(s); gen_helper_stfle(cc_op, cpu_env, o->in2); set_cc_static(s); return NO_EXIT; --=20 2.13.5