From patchwork Fri Feb 16 13:57:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13560042 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CAD60C48BC4 for ; Fri, 16 Feb 2024 13:58:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rayiz-0006Xa-QS; Fri, 16 Feb 2024 08:57:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rayig-0006GB-Bz for qemu-devel@nongnu.org; Fri, 16 Feb 2024 08:57:39 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rayib-0003eL-Tm for qemu-devel@nongnu.org; Fri, 16 Feb 2024 08:57:36 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1d746856d85so6769795ad.0 for ; Fri, 16 Feb 2024 05:57:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708091851; x=1708696651; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1pILAc4QGfEWQVoqeGm6TwPW8gXNmDL3KNUvGgdYo3Y=; b=D8t+XLv1MjkVJ81CFq343dAtMU3B6LNhYMm+RfGrVl7FeWtfukd2mGDmEM6z2gVrPo IOO9KkJsbiFTdN4CkOiG6aEL/V1MAP0wvIQBVNp5IOo3N5jB5tE+luuUlWhjFCEaMFRX OiuOdfO+XDg1OguL3zKnDxiPVeK8DWZIuNCLOWGdGvwF3EbnLuBKsxMBNcWfMthDxOaj jkgdUpC2QNE9LHX1hr8jQ1PXMPwZ/wJ4xd/Y53sxOdC35zUVtTtuExZUrrgNtyJq4q1E NIUh9zq2+Y97I5UL0YHFMu7nElXDPb1GIKa98YEfQtBKFBbXYngnhW30UEiPHyVRBUQH t/Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708091851; x=1708696651; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1pILAc4QGfEWQVoqeGm6TwPW8gXNmDL3KNUvGgdYo3Y=; b=f/Jr3+gbFpEz9+alDlqLGNpcDJV/+ftUCKZ/sCzOVxqzwAGER+jeF7K5jW1pmnA/I4 AiFt19cj74h0SEJUXUBGvwwHEoQlofkwQ6hDnwNWHCaDUetZkCaydVHiXOZQlvHKCLKM NCTSCQZDUsVep4Es9IbVndoR2HPMLboMN/urPbV1opwnGhWLy1QKMODhJZQxw08iOCIV ug85H6it4YSEHZbRH95/EXr0zmI61UeHhVqzt8BQeC3Ef/knSweYs5k6I0yhpkdp3fSP 5aXIBOZaVPQmlYmnL1YqbQtwAhW+XgPXMxwCoZAwH5KH7gOCE/qZnSi2SENP/d6IPaPL IKCg== X-Gm-Message-State: AOJu0YzNqT0jNmtFGS2UgAtbJQWoC/9vRdPlJywqVYUyhn//CBMY8Vcy f4cfiAhrOF8Ls5r7vmAP1+bqBLINUmKomaYKDEO5Cs6G6lbgO8bQyGP5vouwYzwdQwcWQLWR4x6 Y X-Google-Smtp-Source: AGHT+IFp9m72nD3whodcQWSNQXB1YZ6oZB0wyflG0dNdFBFA/5lFZkTT+/5Qy1oYjVIBYg78blyo4w== X-Received: by 2002:a17:903:244e:b0:1da:20c4:5110 with SMTP id l14-20020a170903244e00b001da20c45110mr6161282pls.16.1708091851596; Fri, 16 Feb 2024 05:57:31 -0800 (PST) Received: from grind.. ([177.94.15.159]) by smtp.gmail.com with ESMTPSA id j18-20020a170902c3d200b001dbb06b6138sm889606plj.252.2024.02.16.05.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 05:57:31 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, richard.henderson@linaro.org, max.chou@sifive.com, Daniel Henrique Barboza Subject: [PATCH v2 1/3] trans_rvv.c.inc: write CSRs must call mark_vs_dirty() too Date: Fri, 16 Feb 2024 10:57:17 -0300 Message-ID: <20240216135719.1034289-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216135719.1034289-1-dbarboza@ventanamicro.com> References: <20240216135719.1034289-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In the Vector spec section 3.2 [1]: "When mstatus.VS is set to Initial or Clean, executing any instruction that changes vector state, including the vector CSRs, will change mstatus.VS to Dirty." ldst_us_trans(), ldst_stride_trans(), ldst_index_trans() and ldst_whole_trans() will change vector state regardless of being a store op or not. Stores will set env->vstart to zero after execution (see vext_ldst_us() in vector_helper.c), and this is vector CSR state change. [1] https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#vector-start-index-csr-vstart Fixes: 8e1ee1fb57 ("target/riscv: rvv-1.0: add translation-time vector context status") Signed-off-by: Daniel Henrique Barboza --- target/riscv/insn_trans/trans_rvv.c.inc | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc index 9e101ab434..044c9c903e 100644 --- a/target/riscv/insn_trans/trans_rvv.c.inc +++ b/target/riscv/insn_trans/trans_rvv.c.inc @@ -638,10 +638,7 @@ static bool ldst_us_trans(uint32_t vd, uint32_t rs1, uint32_t data, fn(dest, mask, base, tcg_env, desc); - if (!is_store) { - mark_vs_dirty(s); - } - + mark_vs_dirty(s); gen_set_label(over); return true; } @@ -799,10 +796,7 @@ static bool ldst_stride_trans(uint32_t vd, uint32_t rs1, uint32_t rs2, fn(dest, mask, base, stride, tcg_env, desc); - if (!is_store) { - mark_vs_dirty(s); - } - + mark_vs_dirty(s); gen_set_label(over); return true; } @@ -906,10 +900,7 @@ static bool ldst_index_trans(uint32_t vd, uint32_t rs1, uint32_t vs2, fn(dest, mask, base, index, tcg_env, desc); - if (!is_store) { - mark_vs_dirty(s); - } - + mark_vs_dirty(s); gen_set_label(over); return true; } @@ -1104,9 +1095,7 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, fn(dest, base, tcg_env, desc); - if (!is_store) { - mark_vs_dirty(s); - } + mark_vs_dirty(s); gen_set_label(over); return true; From patchwork Fri Feb 16 13:57:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13560044 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83220C48BC4 for ; Fri, 16 Feb 2024 13:59:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rayj1-0006fH-Lz; Fri, 16 Feb 2024 08:57:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rayit-0006PV-30 for qemu-devel@nongnu.org; Fri, 16 Feb 2024 08:57:52 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rayig-0003eq-1e for qemu-devel@nongnu.org; Fri, 16 Feb 2024 08:57:50 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d51ba18e1bso21359955ad.0 for ; Fri, 16 Feb 2024 05:57:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708091855; x=1708696655; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9OrXw+6O3YfHBgx/rcrbMpH4N4DiM1hCF2q4fYF8Wxg=; b=FqkTN44MQtqcuX/vOxhBrN7YTUrjnTmOZ3nsl3aa+0nArV4XGmV81fFmwPx1hO/4WE lpb4NUzxKUdE8BGLY6mp0nkXWOw9l8LWhsLZl1rHCoDA+FfXBzDr0WR7wwKcgQ/G3WfK Hs8FH3X2m0ZlogcF/ZVp00bsBYL9NWwefzMeRq7yhC8+t2rhAEDFH2tgU6D74l/OBLbX cfyplsUbb/z3fLtYZhRHsTpMtv8CmgoP24//CFWUrb5o4WmjgrljY5xyUM/3cUkjgum1 GtOhX4uSmr+CC/BqJtJg7DYKmVbkRRUHMjHlpleeJqWDE7HR345DpJWGxenYeOY4jcmG 3vCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708091855; x=1708696655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9OrXw+6O3YfHBgx/rcrbMpH4N4DiM1hCF2q4fYF8Wxg=; b=VGYDfp+Wv6JTbOXr9N/1XSv2MhjFlEoKBM7fxNZxcyPzJ5E9dsXsvyDAD83XUTNhtm 8O+OjPUbZzM55ZkFAKvJWkVqgzi4gX+CDRdu/7Yyp6CIMFnGe0Ra6FwddMlQthYshkd8 aIrcBEJmtysnOU3zsDBC16xPHjVVlclzj3tPyhJb4dRdFWmNiQ5R1vNoA+UVHtl/zt7y p8MFUcbCFSikBPiJMSgEf5wletr0QVIRkcPjHXqHbxOXzwONgHlBNLptVpVCujzMErFj 2jkvr8opGjWNoo8Lgb2QMTHVlD40ZCdcXEBBdLIqh93O0koWN6BZdfQN/G7McGF99wzY SYKQ== X-Gm-Message-State: AOJu0Yx7WOfffkDIc1TiPB1QndwCU36DnADCrWSC5xU92tl8u2PYPJ9R am91wMyI7geuirDx0ZR2cu4mNlUl8mCNjQ/zOcAFlssIupn9wrJjJ4ZSkhYIN39DQZo5CnSPzdj c X-Google-Smtp-Source: AGHT+IFJF2oXWFQmk6xSFLyBlJHYiAxF5+BVNm1lZRmieSMhei1KpZsiSGuBo0CHEzogemPNtt7DtA== X-Received: by 2002:a17:903:183:b0:1db:35b5:7e3e with SMTP id z3-20020a170903018300b001db35b57e3emr6520446plg.29.1708091854863; Fri, 16 Feb 2024 05:57:34 -0800 (PST) Received: from grind.. ([177.94.15.159]) by smtp.gmail.com with ESMTPSA id j18-20020a170902c3d200b001dbb06b6138sm889606plj.252.2024.02.16.05.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 05:57:34 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, richard.henderson@linaro.org, max.chou@sifive.com, Daniel Henrique Barboza Subject: [PATCH v2 2/3] trans_rvv.c.inc: remove redundant mark_vs_dirty() calls Date: Fri, 16 Feb 2024 10:57:18 -0300 Message-ID: <20240216135719.1034289-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216135719.1034289-1-dbarboza@ventanamicro.com> References: <20240216135719.1034289-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org trans_vmv_v_i , trans_vfmv_v_f and the trans_##NAME macro from GEN_VMV_WHOLE_TRANS() are calling mark_vs_dirty() in both branches of their 'ifs'. conditionals. Call it just once in the end like other functions are doing. Signed-off-by: Daniel Henrique Barboza --- target/riscv/insn_trans/trans_rvv.c.inc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc index 044c9c903e..778e2723dd 100644 --- a/target/riscv/insn_trans/trans_rvv.c.inc +++ b/target/riscv/insn_trans/trans_rvv.c.inc @@ -2094,7 +2094,6 @@ static bool trans_vmv_v_i(DisasContext *s, arg_vmv_v_i *a) if (s->vl_eq_vlmax && !(s->vta && s->lmul < 0)) { tcg_gen_gvec_dup_imm(s->sew, vreg_ofs(s, a->rd), MAXSZ(s), MAXSZ(s), simm); - mark_vs_dirty(s); } else { TCGv_i32 desc; TCGv_i64 s1; @@ -2115,9 +2114,9 @@ static bool trans_vmv_v_i(DisasContext *s, arg_vmv_v_i *a) tcg_gen_addi_ptr(dest, tcg_env, vreg_ofs(s, a->rd)); fns[s->sew](dest, s1, tcg_env, desc); - mark_vs_dirty(s); gen_set_label(over); } + mark_vs_dirty(s); return true; } return false; @@ -2660,7 +2659,6 @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) tcg_gen_gvec_dup_i64(s->sew, vreg_ofs(s, a->rd), MAXSZ(s), MAXSZ(s), t1); - mark_vs_dirty(s); } else { TCGv_ptr dest; TCGv_i32 desc; @@ -2686,9 +2684,9 @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) fns[s->sew - 1](dest, t1, tcg_env, desc); - mark_vs_dirty(s); gen_set_label(over); } + mark_vs_dirty(s); return true; } return false; @@ -3632,15 +3630,14 @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ if (s->vstart_eq_zero) { \ tcg_gen_gvec_mov(s->sew, vreg_ofs(s, a->rd), \ vreg_ofs(s, a->rs2), maxsz, maxsz); \ - mark_vs_dirty(s); \ } else { \ TCGLabel *over = gen_new_label(); \ tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, maxsz, over); \ tcg_gen_gvec_2_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, a->rs2), \ tcg_env, maxsz, maxsz, 0, gen_helper_vmvr_v); \ - mark_vs_dirty(s); \ gen_set_label(over); \ } \ + mark_vs_dirty(s); \ return true; \ } \ return false; \ From patchwork Fri Feb 16 13:57:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13560043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F393CC48BC4 for ; Fri, 16 Feb 2024 13:59:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rayj0-0006cy-TN; Fri, 16 Feb 2024 08:57:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rayix-0006Uq-LT for qemu-devel@nongnu.org; Fri, 16 Feb 2024 08:57:56 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rayij-0003hE-NH for qemu-devel@nongnu.org; Fri, 16 Feb 2024 08:57:55 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d7431e702dso19904955ad.1 for ; Fri, 16 Feb 2024 05:57:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708091858; x=1708696658; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=emRBlYfSXu9vP7I1QBtZCcEqJWprux2dWk/RvM2p2b0=; b=gANxoqyaQUtGX1fBHnnqHLB/nYhd3DDPMBO4dGoBfCWWg+XSUwxXdK6Y5wCPyDQyDa D800TjCiTUy7tVDN5VH+d4c0IFZqXRNp05SImi6n4LkhBQTEtm+TtCrl12B9MsgHtECo L3vTfTPrgLtyrpXq8GdHoTWR7lcuC9zhlKOiCzgxvrSBe0ap2+etGFO/IzKoMrsg2Wsy nDcPljChHHjdJ+rEIWmEddJTvxln47QjduL8t99+khbGkIghOpy/Z3pyIfB06NfSJndV S1b39oXXqp/16QR80yp9sJA8fOk3/5yZZX+Zauxw5pmK0b4WH7Ir4E2DKWbD+CiUZv2s PUbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708091858; x=1708696658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=emRBlYfSXu9vP7I1QBtZCcEqJWprux2dWk/RvM2p2b0=; b=AWvjHPJFbIOCyidlNuZ/iT5r6x1zN2m9vFr2QB4QwvkfT5z9CCssG3+39uwO5QOJc/ J/corqW5jIQSJoStBra+Ueljw4Jyqlo3/vs6kONVNHGR0eXl9AUUN3ZF0b0LbBhOh9AY S2gMr8RfkrAQX85+VAtS7xIadOnF+i2Hpnshsc245DHd9IDw0cHjfAaREqQpu5BxjfkJ 9PpZ+dMQC//UVrL4lYWZUlMKJlF1BUJiEKJ5KfXQarlGzK1g6PI5nNDUzt5FuanGDdC1 9vt+IWRim0bURqBqBWTg/zl75+13DJSWA6mSd9qjW2mcvX7AbYhJn62FkOLOn7KAHzcO O3HA== X-Gm-Message-State: AOJu0YxZ875gCflAYyQMOqLl4cGfeWBsKPpV98quNt2h7GFQ/L/lg+Qi r2eH5geptbS1/5v+JTke7Q3Cmu8bzfmvI8+QGjhHsPN7V6hgi0yU4MxsqItEC07wYXKiV8pPZQ+ C X-Google-Smtp-Source: AGHT+IEpFVh1teugTIhWzmpa0BmlHAKIRLToaSF+9jY/mbLwrUHXzGEomeIsmOx0mwyciZ864jGGNg== X-Received: by 2002:a17:903:245:b0:1da:22d9:e7fd with SMTP id j5-20020a170903024500b001da22d9e7fdmr3501227plh.20.1708091858195; Fri, 16 Feb 2024 05:57:38 -0800 (PST) Received: from grind.. ([177.94.15.159]) by smtp.gmail.com with ESMTPSA id j18-20020a170902c3d200b001dbb06b6138sm889606plj.252.2024.02.16.05.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 05:57:37 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, richard.henderson@linaro.org, max.chou@sifive.com, Daniel Henrique Barboza Subject: [PATCH v2 3/3] target/riscv/translate.c: set vstart_eq_zero in mark_vs_dirty() Date: Fri, 16 Feb 2024 10:57:19 -0300 Message-ID: <20240216135719.1034289-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240216135719.1034289-1-dbarboza@ventanamicro.com> References: <20240216135719.1034289-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The 'vstart_eq_zero' flag which is used to determine if some insns, like vector reductor operations, should SIGILL. At this moment the flag is being updated only during cpu_get_tb_cpu_state(), at the start of each translation block. This cadence isn't enough and we're facing situations where a vector instruction successfully updated 'vstart' to zero, but the flag was still marked as 'false', resulting in a SIGILL because instructions are checking the flag. mark_vs_dirty() is called after any instruction changes Vector CSR state, making it a good place to update 'vstart_eq_zero'. Fixes: 8e1ee1fb57 ("target/riscv: rvv-1.0: add translation-time vector context status") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1976 Signed-off-by: Daniel Henrique Barboza --- target/riscv/translate.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 177418b2b9..f9ff7b6173 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -652,6 +652,8 @@ static inline void mark_fs_dirty(DisasContext *ctx) { } */ static void mark_vs_dirty(DisasContext *ctx) { + TCGLabel *vstart_zero = gen_new_label(); + TCGLabel *done = gen_new_label(); TCGv tmp; if (ctx->mstatus_vs != EXT_STATUS_DIRTY) { @@ -669,6 +671,24 @@ static void mark_vs_dirty(DisasContext *ctx) tcg_gen_st_tl(tmp, tcg_env, offsetof(CPURISCVState, mstatus_hs)); } } + + /* + * We can safely make 'vl_eq_vlmax = false' if we marked + * VS as dirty with non-zero 'vstart', i.e. there's a fault + * to be handled. If 'vstart' is zero then we should retain + * the existing 'vl_eq_vlmax' - it'll be recalculated on the + * start of the next TB or during vset{i}vl{i} (that forces a + * TB end). + */ + tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vstart, 0, vstart_zero); + ctx->vstart_eq_zero = false; + ctx->vl_eq_vlmax = false; + tcg_gen_br(done); + + gen_set_label(vstart_zero); + ctx->vstart_eq_zero = true; + + gen_set_label(done); } #else static inline void mark_vs_dirty(DisasContext *ctx) { }