From patchwork Fri Jun 8 12:33:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 137988 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp850603lji; Fri, 8 Jun 2018 06:06:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJuIaGV33IdthP/1Uie8+N6W5ltEBczsaqrXFrTAj/258IDPAktcrfYIJsWDP6RsP2wgfas X-Received: by 2002:a0c:d911:: with SMTP id p17-v6mr5445738qvj.78.1528463175444; Fri, 08 Jun 2018 06:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528463175; cv=none; d=google.com; s=arc-20160816; b=sz1c006I1n5tlheNmkC/EvU+6xyrWBGhKjr9NUqq8oS2UcoHKfdQVgr8Ec+yAmJfHd 8DqYGzijnk18MP5Yu+tKY11OALDEjKd8XXpmnfYTrOZJoAkzAAnrUB9sJBEXMt95IPgD SaJrkiadC7X0WzGAAvXOq6GGIFOz1q93ORr//t/v1Z3sdfi76o3AFsL9I4K4uey5nABj rexzpl+SBE/rLy89sGLQgLEpfRXqSk+EwAjz4fO1Iv4VdzH3CXJ2g7fO4CLsKGcjAEoP T780z89w60gIo5Y8NPzXrU8gH7LLRuE8Ctsqxjg2QgRaQOry1n7NSDDBxl4dpwm5RAl7 H1xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=03rV33qUneZ0VWuXXnl7qUcf6DTIyhEX8zh3XbK/+XA=; b=TxJ4VrEHiQqNE5Ik5eWyqYK5YnlUNM/OUkzxCxJY4BRYTrwFhzoTuRBp4zOthT+woy uremSkYTuCd7cqt67FqE+8afx4sRAF9y1SeRFBJhc5ttzAsKC1Yr/1mcYFn1DCAjk8wJ XIpWKz7x2bualmFtPGhF6JUzYw/i1IMWR7ptYNWCX05O9Hymt8vqaAkK5XOM4dhzT86z PT4lcelfBttSwp7BipOczBIfO/He80DDJc9RTAFF5e2dF1HmoKSrwq80+FJv53UT1IDU EmFk+kGTsVIWohJJH/j0UrNOekcTGo9j5tGLv49if2Dxbw/yBp7yOMO2kpk5xQI3aN1F VdYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NybfIPDt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l88-v6si13683052qva.48.2018.06.08.06.06.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 08 Jun 2018 06:06:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NybfIPDt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRH5q-00038x-Uk for patch@linaro.org; Fri, 08 Jun 2018 09:06:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRGfj-0005n1-Qo for qemu-devel@nongnu.org; Fri, 08 Jun 2018 08:39:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRGff-0000uC-LN for qemu-devel@nongnu.org; Fri, 08 Jun 2018 08:39:15 -0400 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]:38079) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRGff-0000td-BD for qemu-devel@nongnu.org; Fri, 08 Jun 2018 08:39:11 -0400 Received: by mail-wm0-x229.google.com with SMTP id 69-v6so3451627wmf.3 for ; Fri, 08 Jun 2018 05:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=03rV33qUneZ0VWuXXnl7qUcf6DTIyhEX8zh3XbK/+XA=; b=NybfIPDt4Lau0HZGVJmDIVXlW0X70GrUU0upGOASzYSSRK1DUN0W9L1IGHZa1KN/aE jHUUa3C4a6CBvemRGshPAGriWdW9PH71cUqozerSyjt7lRePoxqtVHcdYcHWXITlvUyz ztarwjR4oNDY8rqgUpiBtAxU/iAYpZyPEaFS0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=03rV33qUneZ0VWuXXnl7qUcf6DTIyhEX8zh3XbK/+XA=; b=bpO3Ef/+ZmsNHh+Binj30g5Zd1NWmvqIYFhF44YoHRgTvIpf4nycfxlguF8RqY+ltn qZhbfvGcFMsXdSBzsihQHUGCNLfzNl0zhBUsGtL10WO87AbNv4ByIJeJldN3seYyy4d0 b9JgXs4naUXwq0ZgA1oL+dtHiB5Eaay/LCK9+cLJMyvOMjOlQccQblXceXEjtf/3eL4t lsQOrqR4ldY3F+IyZCmsg+7K9renGvIVjF4fz59WzgqVrhnMoWzHxH56dqiHJvWEe5+O jLG1Wq+B3qJoAiBuG82p826HTjUq/92eg/PKKALV2SCBomJwaqdFS02AzmcHHGsYmcvP z5sg== X-Gm-Message-State: APt69E2xbSpM1H7aa+M8xUqh4qrxo31DRBr+9hm7TJlfgj0rKkhe1WfU brGrDiShJDrdQgbEjxM05QXLeg== X-Received: by 2002:a1c:30d7:: with SMTP id w206-v6mr1369454wmw.153.1528461550194; Fri, 08 Jun 2018 05:39:10 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f81-v6sm2177905wmh.32.2018.06.08.05.39.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Jun 2018 05:39:08 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 29E063E0DD5; Fri, 8 Jun 2018 13:33:11 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: cota@braap.org, famz@redhat.com, berrange@redhat.com, f4bug@amsat.org, richard.henderson@linaro.org, balrogg@gmail.com, aurelien@aurel32.net, agraf@suse.de, pbonzini@redhat.com, stefanha@redhat.com, stefanb@linux.vnet.ibm.com, marcandre.lureau@redhat.com Date: Fri, 8 Jun 2018 13:33:04 +0100 Message-Id: <20180608123307.24773-47-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180608123307.24773-1-alex.bennee@linaro.org> References: <20180608123307.24773-1-alex.bennee@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::229 Subject: [Qemu-devel] [PATCH v6 46/49] target/sh4: Fix translator.c assertion failure for gUSA 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: Richard Henderson , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The translator loop does not allow the tb_start hook to set dc->base.is_jmp; the only hook allowed to do that is translate_insn. Split the work between init_disas_context where we validate the gUSA parameters, and translate_insn where we emit code. Signed-off-by: Richard Henderson --- target/sh4/translate.c | 81 +++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 37 deletions(-) -- 2.17.1 diff --git a/target/sh4/translate.c b/target/sh4/translate.c index c716b74a0f..1b9a201d6d 100644 --- a/target/sh4/translate.c +++ b/target/sh4/translate.c @@ -1895,35 +1895,18 @@ static void decode_opc(DisasContext * ctx) any sequence via cpu_exec_step_atomic, we can recognize the "normal" sequences and transform them into atomic operations as seen by the host. */ -static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) +static void decode_gusa(DisasContext *ctx, CPUSH4State *env) { uint16_t insns[5]; int ld_adr, ld_dst, ld_mop; int op_dst, op_src, op_opc; int mv_src, mt_dst, st_src, st_mop; TCGv op_arg; - uint32_t pc = ctx->base.pc_next; uint32_t pc_end = ctx->base.tb->cs_base; - int backup = sextract32(ctx->tbflags, GUSA_SHIFT, 8); int max_insns = (pc_end - pc) / 2; int i; - if (pc != pc_end + backup || max_insns < 2) { - /* This is a malformed gUSA region. Don't do anything special, - since the interpreter is likely to get confused. */ - ctx->envflags &= ~GUSA_MASK; - return 0; - } - - if (ctx->tbflags & GUSA_EXCLUSIVE) { - /* Regardless of single-stepping or the end of the page, - we must complete execution of the gUSA region while - holding the exclusive lock. */ - *pmax_insns = max_insns; - return 0; - } - /* The state machine below will consume only a few insns. If there are more than that in a region, fail now. */ if (max_insns > ARRAY_SIZE(insns)) { @@ -2140,7 +2123,6 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) /* * Emit the operation. */ - tcg_gen_insn_start(pc, ctx->envflags); switch (op_opc) { case -1: /* No operation found. Look for exchange pattern. */ @@ -2235,7 +2217,8 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) /* The entire region has been translated. */ ctx->envflags &= ~GUSA_MASK; ctx->base.pc_next = pc_end; - return max_insns; + ctx->base.num_insns += max_insns - 1; + return; fail: qemu_log_mask(LOG_UNIMP, "Unrecognized gUSA sequence %08x-%08x\n", @@ -2243,7 +2226,6 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) /* Restart with the EXCLUSIVE bit set, within a TB run via cpu_exec_step_atomic holding the exclusive lock. */ - tcg_gen_insn_start(pc, ctx->envflags); ctx->envflags |= GUSA_EXCLUSIVE; gen_save_cpu_state(ctx, false); gen_helper_exclusive(cpu_env); @@ -2254,7 +2236,7 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) entire region consumed via ctx->base.pc_next so that it's immediately available in the disassembly dump. */ ctx->base.pc_next = pc_end; - return 1; + ctx->base.num_insns += max_insns - 1; } #endif @@ -2262,19 +2244,39 @@ static void sh4_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) { DisasContext *ctx = container_of(dcbase, DisasContext, base); CPUSH4State *env = cs->env_ptr; + uint32_t tbflags; int bound; - ctx->tbflags = (uint32_t)ctx->base.tb->flags; - ctx->envflags = ctx->base.tb->flags & TB_FLAG_ENVFLAGS_MASK; - ctx->memidx = (ctx->tbflags & (1u << SR_MD)) == 0 ? 1 : 0; + ctx->tbflags = tbflags = ctx->base.tb->flags; + ctx->envflags = tbflags & TB_FLAG_ENVFLAGS_MASK; + ctx->memidx = (tbflags & (1u << SR_MD)) == 0 ? 1 : 0; /* We don't know if the delayed pc came from a dynamic or static branch, so assume it is a dynamic branch. */ ctx->delayed_pc = -1; /* use delayed pc from env pointer */ ctx->features = env->features; - ctx->has_movcal = (ctx->tbflags & TB_FLAG_PENDING_MOVCA); - ctx->gbank = ((ctx->tbflags & (1 << SR_MD)) && - (ctx->tbflags & (1 << SR_RB))) * 0x10; - ctx->fbank = ctx->tbflags & FPSCR_FR ? 0x10 : 0; + ctx->has_movcal = (tbflags & TB_FLAG_PENDING_MOVCA); + ctx->gbank = ((tbflags & (1 << SR_MD)) && + (tbflags & (1 << SR_RB))) * 0x10; + ctx->fbank = tbflags & FPSCR_FR ? 0x10 : 0; + + if (tbflags & GUSA_MASK) { + uint32_t pc = ctx->base.pc_next; + uint32_t pc_end = ctx->base.tb->cs_base; + int backup = sextract32(ctx->tbflags, GUSA_SHIFT, 8); + int max_insns = (pc_end - pc) / 2; + + if (pc != pc_end + backup || max_insns < 2) { + /* This is a malformed gUSA region. Don't do anything special, + since the interpreter is likely to get confused. */ + ctx->envflags &= ~GUSA_MASK; + } else if (tbflags & GUSA_EXCLUSIVE) { + /* Regardless of single-stepping or the end of the page, + we must complete execution of the gUSA region while + holding the exclusive lock. */ + ctx->base.max_insns = max_insns; + return; + } + } /* Since the ISA is fixed-width, we can bound by the number of instructions remaining on the page. */ @@ -2284,14 +2286,6 @@ static void sh4_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) static void sh4_tr_tb_start(DisasContextBase *dcbase, CPUState *cs) { -#ifdef CONFIG_USER_ONLY - DisasContext *ctx = container_of(dcbase, DisasContext, base); - CPUSH4State *env = cs->env_ptr; - - if (ctx->tbflags & GUSA_MASK) { - ctx->base.num_insns = decode_gusa(ctx, env, &ctx->base.max_insns); - } -#endif } static void sh4_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) @@ -2323,6 +2317,19 @@ static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) CPUSH4State *env = cs->env_ptr; DisasContext *ctx = container_of(dcbase, DisasContext, base); +#ifdef CONFIG_USER_ONLY + if (unlikely(ctx->envflags & GUSA_MASK) + && !(ctx->envflags & GUSA_EXCLUSIVE)) { + /* We're in an gUSA region, and we have not already fallen + back on using an exclusive region. Attempt to parse the + region into a single supported atomic operation. Failure + is handled within the parser by raising an exception to + retry using an exclusive region. */ + decode_gusa(ctx, env); + return; + } +#endif + ctx->opcode = cpu_lduw_code(env, ctx->base.pc_next); decode_opc(ctx); ctx->base.pc_next += 2;