From patchwork Mon Sep 18 16:00:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 815025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xwrs00Gxmz9s78 for ; Tue, 19 Sep 2017 02:23:00 +1000 (AEST) Received: from localhost ([::1]:37680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtyp0-0000aN-2X for incoming@patchwork.ozlabs.org; Mon, 18 Sep 2017 12:22:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtyV0-0007y6-8o for qemu-devel@nongnu.org; Mon, 18 Sep 2017 12:02:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtyUx-0008Nj-LO for qemu-devel@nongnu.org; Mon, 18 Sep 2017 12:02:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8055) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dtyUx-0008NR-DV for qemu-devel@nongnu.org; Mon, 18 Sep 2017 12:02:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 637E7D7127; Mon, 18 Sep 2017 16:02:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 637E7D7127 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com Received: from t460s.redhat.com (unknown [10.36.118.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 838A95D6A8; Mon, 18 Sep 2017 16:02:11 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 18:00:12 +0200 Message-Id: <20170918160012.4317-28-david@redhat.com> In-Reply-To: <20170918160012.4317-1-david@redhat.com> References: <20170918160012.4317-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 18 Sep 2017 16:02:14 +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 27/27] s390x/tcg: refactor stfl(e) to use s390_get_feat_block() 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: Matthew Rosato , thuth@redhat.com, david@redhat.com, cohuck@redhat.com, Richard Henderson , Alexander Graf , borntraeger@de.ibm.com, Igor Mammedov , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- target/s390x/helper.h | 2 +- target/s390x/misc_helper.c | 72 ++++++++++++++++++++++------------------------ target/s390x/translate.c | 1 - 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/target/s390x/helper.h b/target/s390x/helper.h index a0e4bfb850..a6d94d2d82 100644 --- a/target/s390x/helper.h +++ b/target/s390x/helper.h @@ -104,7 +104,6 @@ DEF_HELPER_FLAGS_5(calc_cc, TCG_CALL_NO_RWG_SE, i32, env, i32, i64, i64, i64) DEF_HELPER_FLAGS_2(sfpc, TCG_CALL_NO_RWG, void, env, i64) DEF_HELPER_FLAGS_2(sfas, TCG_CALL_NO_WG, void, env, i64) DEF_HELPER_FLAGS_1(popcnt, TCG_CALL_NO_RWG_SE, i64, i64) -DEF_HELPER_FLAGS_1(stfl, TCG_CALL_NO_RWG, void, env) DEF_HELPER_2(stfle, i32, env, i64) DEF_HELPER_FLAGS_2(lpq, TCG_CALL_NO_WG, i64, env, i64) DEF_HELPER_FLAGS_4(stpq, TCG_CALL_NO_WG, void, env, i64, i64, i64) @@ -152,6 +151,7 @@ DEF_HELPER_FLAGS_3(sturg, TCG_CALL_NO_WG, void, env, i64, i64) DEF_HELPER_1(per_check_exception, void, env) DEF_HELPER_FLAGS_3(per_branch, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(per_ifetch, TCG_CALL_NO_RWG, void, env, i64) +DEF_HELPER_FLAGS_1(stfl, TCG_CALL_NO_RWG, void, env) DEF_HELPER_2(xsch, void, env, i64) DEF_HELPER_2(csch, void, env, i64) diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c index 1e4d3c8526..4afd90b969 100644 --- a/target/s390x/misc_helper.c +++ b/target/s390x/misc_helper.c @@ -475,61 +475,57 @@ void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr) } #endif -/* 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; -/* 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 = s390_env_get_cpu(env); - const unsigned long *features = cpu->model->features; - unsigned max_bit = 0; - S390Feat feat; - - memset(words, 0, sizeof(uint64_t) * MAX_STFL_WORDS); + static bool initialized; + int i; - if (test_bit(S390_FEAT_ZARCH, features)) { - /* z/Architecture is always active if around */ - words[0] = 1ull << (63 - 2); + /* racy, but we don't care, the same values are always written */ + if (initialized) { + return; } - for (feat = find_first_bit(features, S390_FEAT_MAX); - feat < S390_FEAT_MAX; - feat = find_next_bit(features, S390_FEAT_MAX, feat + 1)) { - const S390FeatDef *def = s390_feat_def(feat); - if (def->type == S390_FEAT_TYPE_STFL) { - unsigned bit = def->bit; - if (bit > max_bit) { - max_bit = bit; - } - assert(bit / 64 < MAX_STFL_WORDS); - words[bit / 64] |= 1ULL << (63 - bit % 64); + s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes); + for (i = 0; i < sizeof(stfl_bytes); i++) { + if (stfl_bytes[i]) { + used_stfl_bytes = i + 1; } } - - return max_bit / 64; + initialized = true; } +#ifndef CONFIG_USER_ONLY void HELPER(stfl)(CPUS390XState *env) { - uint64_t words[MAX_STFL_WORDS]; + LowCore *lowcore; - do_stfle(env, words); - cpu_stl_data(env, 200, words[0] >> 32); + lowcore = cpu_map_lowcore(env); + prepare_stfl(); + memcpy(&lowcore->stfl_fac_list, stfl_bytes, sizeof(lowcore->stfl_fac_list)); + cpu_unmap_lowcore(lowcore); } +#endif uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr) { - uint64_t words[MAX_STFL_WORDS]; - unsigned count_m1 = env->regs[0] & 0xff; - unsigned max_m1 = do_stfle(env, words); - unsigned i; + const uintptr_t ra = GETPC(); + const int count_bytes = ((env->regs[0] & 0xff) + 1) * 8; + const int max_bytes = 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); + } - for (i = 0; i <= count_m1; ++i) { - cpu_stq_data(env, addr + 8 * i, words[i]); + prepare_stfl(); + for (i = 0; i < count_bytes; ++i) { + cpu_stb_data_ra(env, addr + i, stfl_bytes[i], ra); } - env->regs[0] = deposit64(env->regs[0], 0, 8, max_m1); - return (count_m1 >= max_m1 ? 0 : 3); + env->regs[0] = deposit64(env->regs[0], 0, 8, (max_bytes / 8) - 1); + return count_bytes >= max_bytes ? 0 : 3; } diff --git a/target/s390x/translate.c b/target/s390x/translate.c index abf2feb7aa..0e05942fe9 100644 --- a/target/s390x/translate.c +++ b/target/s390x/translate.c @@ -4082,7 +4082,6 @@ static ExitStatus op_sturg(DisasContext *s, DisasOps *o) 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;