From nobody Mon Feb 9 04:41:17 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@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; 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=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527899002383154.59186376234368; Fri, 1 Jun 2018 17:23:22 -0700 (PDT) Received: from localhost ([::1]:57897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOuKH-0005Tv-Ic for importer@patchew.org; Fri, 01 Jun 2018 20:23:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOuJH-00053n-US for qemu-devel@nongnu.org; Fri, 01 Jun 2018 20:22:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOuJE-0007Rq-Mq for qemu-devel@nongnu.org; Fri, 01 Jun 2018 20:22:19 -0400 Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]:33466) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fOuJE-0007Oo-CV for qemu-devel@nongnu.org; Fri, 01 Jun 2018 20:22:16 -0400 Received: by mail-pf0-x22c.google.com with SMTP id b17-v6so1691339pfi.0 for ; Fri, 01 Jun 2018 17:22:16 -0700 (PDT) Received: from localhost.localdomain (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id n70-v6sm9334806pfh.140.2018.06.01.17.22.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jun 2018 17:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=0RJgc5vzW7l1q+L2Wp1LmX0ma7lVdchmjyTyYwNfOmo=; b=TlFYXbPDNymmiMaE9mT/Z3IueJdqwu1aSXl0jqk3V65ImIxM29seXpakcNb3t2SRh9 k6N1VIEM2Gb2t5pUWs5zCijQ5miG1LOZLTD4Vh03SealmOzBSX8RsrsMzDMN9iQ5CH4D KFgq/jrFFSXGRT3LzloK5KqOT410Z+/akvSw5VJEKv4o1adCI7SxqXu2lUs0eiH2rFqU tinEApVbY3LUeDaZ87iHbDPsrWVjs6pkBs6wPV5xB4nO7rW60BaXEaHP12EHax1er5XF ULpkk4MdV52XOEa/c/fSzIC9JDfzA4OGqJOZI92Aly1AUEjrW2XROpTxNEpeNYjmstmg 4Ruw== 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; bh=0RJgc5vzW7l1q+L2Wp1LmX0ma7lVdchmjyTyYwNfOmo=; b=ThvrcXg/h8166ioR4/CPSrtdxJzxbZ+tB+5juAA1djHpi9anwnW6wQ8WcOuPLJYD+s QRfrsqdWDVPfDy57ZbxVjH25KFKwFkOv7RF/g7WrQkbvlls4NlCSZFk9okSmNwm3Rn/C NJtykAz5zSVpDZWA02OQYhnc5fIdx8dJEmlCWp2OD2ph8oCRgwCBCugvdQ43/ZLL3JgT 0bMJPy5g/x/+l63FaLPb2lAPoHu+cL9OaNLQU0ab6xyG9LS6kX2a9RIlcWUQZeiltH0D i9OCH7XYL1WMX0M4jaUMcZ7kMc5ryR/vrhQB07vpZqoLgfrAKxGXOloUSKVT/HzPDxcR GaGg== X-Gm-Message-State: ALKqPwcY212xbcxysiJPcvbze7Cm1NbEwJ4ZxfiJqH86TwxymEVhLa4Z 7fAE5FboLEMs1McftND2MtCk6pnF X-Google-Smtp-Source: ADUXVKKkZUrZCOyoniORr+rzJNPpfslD9KyJDRxLdaT6MZDY76PyQzvlX//Uhfevso2Xaozrg6pVnQ== X-Received: by 2002:a65:4309:: with SMTP id j9-v6mr10231633pgq.375.1527898934825; Fri, 01 Jun 2018 17:22:14 -0700 (PDT) From: Richard Henderson X-Google-Original-From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 1 Jun 2018 17:22:03 -0700 Message-Id: <20180602002203.19725-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22c Subject: [Qemu-devel] [PATCH] 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: alex.bennee@linaro.org, aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alex Benn=C3=A9e Tested-by: Alex Benn=C3=A9e --- This fixes the threadtest failure on Alex's check-tcg branch. r~ --- target/sh4/translate.c | 81 +++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/target/sh4/translate.c b/target/sh4/translate.c index 58bdfeb4fb..5295d9cb0d 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_insn= s) +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 =3D ctx->base.pc_next; uint32_t pc_end =3D ctx->base.tb->cs_base; - int backup =3D sextract32(ctx->tbflags, GUSA_SHIFT, 8); int max_insns =3D (pc_end - pc) / 2; int i; =20 - if (pc !=3D 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 &=3D ~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 =3D 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 &=3D ~GUSA_MASK; ctx->base.pc_next =3D pc_end; - return max_insns; + ctx->base.num_insns +=3D max_insns - 1; + return; =20 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) =20 /* 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 |=3D 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 immediate= ly available in the disassembly dump. */ ctx->base.pc_next =3D pc_end; - return 1; + ctx->base.num_insns +=3D max_insns - 1; } #endif =20 @@ -2262,19 +2244,39 @@ static void sh4_tr_init_disas_context(DisasContextB= ase *dcbase, CPUState *cs) { DisasContext *ctx =3D container_of(dcbase, DisasContext, base); CPUSH4State *env =3D cs->env_ptr; + uint32_t tbflags; int bound; =20 - ctx->tbflags =3D (uint32_t)ctx->base.tb->flags; - ctx->envflags =3D ctx->base.tb->flags & TB_FLAG_ENVFLAGS_MASK; - ctx->memidx =3D (ctx->tbflags & (1u << SR_MD)) =3D=3D 0 ? 1 : 0; + ctx->tbflags =3D tbflags =3D ctx->base.tb->flags; + ctx->envflags =3D tbflags & TB_FLAG_ENVFLAGS_MASK; + ctx->memidx =3D (tbflags & (1u << SR_MD)) =3D=3D 0 ? 1 : 0; /* We don't know if the delayed pc came from a dynamic or static branc= h, so assume it is a dynamic branch. */ ctx->delayed_pc =3D -1; /* use delayed pc from env pointer */ ctx->features =3D env->features; - ctx->has_movcal =3D (ctx->tbflags & TB_FLAG_PENDING_MOVCA); - ctx->gbank =3D ((ctx->tbflags & (1 << SR_MD)) && - (ctx->tbflags & (1 << SR_RB))) * 0x10; - ctx->fbank =3D ctx->tbflags & FPSCR_FR ? 0x10 : 0; + ctx->has_movcal =3D (tbflags & TB_FLAG_PENDING_MOVCA); + ctx->gbank =3D ((tbflags & (1 << SR_MD)) && + (tbflags & (1 << SR_RB))) * 0x10; + ctx->fbank =3D tbflags & FPSCR_FR ? 0x10 : 0; + + if (tbflags & GUSA_MASK) { + uint32_t pc =3D ctx->base.pc_next; + uint32_t pc_end =3D ctx->base.tb->cs_base; + int backup =3D sextract32(ctx->tbflags, GUSA_SHIFT, 8); + int max_insns =3D (pc_end - pc) / 2; + + if (pc !=3D 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 &=3D ~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 =3D max_insns; + return; + } + } =20 /* 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(DisasContextBa= se *dcbase, CPUState *cs) =20 static void sh4_tr_tb_start(DisasContextBase *dcbase, CPUState *cs) { -#ifdef CONFIG_USER_ONLY - DisasContext *ctx =3D container_of(dcbase, DisasContext, base); - CPUSH4State *env =3D cs->env_ptr; - - if (ctx->tbflags & GUSA_MASK) { - ctx->base.num_insns =3D decode_gusa(ctx, env, &ctx->base.max_insns= ); - } -#endif } =20 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 =3D cs->env_ptr; DisasContext *ctx =3D container_of(dcbase, DisasContext, base); =20 +#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 =3D cpu_lduw_code(env, ctx->base.pc_next); decode_opc(ctx); ctx->base.pc_next +=3D 2; --=20 2.17.0