From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D79AC47420 for ; Tue, 29 Sep 2020 20:10:03 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 61E9420774 for ; Tue, 29 Sep 2020 20:10:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="ZQhE9NsG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61E9420774 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNLwn-0004KN-E6 for qemu-devel@archiver.kernel.org; Tue, 29 Sep 2020 16:10:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNL0D-0008TC-AU for qemu-devel@nongnu.org; Tue, 29 Sep 2020 15:09:32 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:33509) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNL07-0002YV-Ad for qemu-devel@nongnu.org; Tue, 29 Sep 2020 15:09:28 -0400 Received: by mail-pf1-x441.google.com with SMTP id q123so5552174pfb.0 for ; Tue, 29 Sep 2020 12:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XI3sKczohciBsZgnmxAfhEd2fKi5Y9uKTWUghLaMHXA=; b=ZQhE9NsGUsuhKkZasb4VSRERQYh52kk6iMFmbJ72EpaeZ4QjKo65D973PlyPT6XiMv 1gY9Dre9n/t/eq+m0wZzPjkZA3bmimPF2s6wcNzr1nQwVWbdRCRJX2daw/I0okv49DZ6 CCDGcB2eXQWV62RMEqkM3nn0ZnzFdUsE2U20pDkSYAyCYK7My4mQJI3QdigaSb1if5eF r/pgrySMYlNR7an2ZMztFAHgI1b0P1iDCEj8TvnNuwERE03afP9rBecOwISFgtBx6hVt HrgmmU2dwcLlzhsx7ZFMl+23E8JSrqmlTIVRkc1i7tikAoQte2H8DsUgB1JnztJU3UYG bL4Q== 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=XI3sKczohciBsZgnmxAfhEd2fKi5Y9uKTWUghLaMHXA=; b=OFKks474du7WEr0PAmtTR20yj4Kv7YTYJT2H5mlGYlU8a8ApER+655VpgMywVd5Dyh A6dC+BkeLb8VgP5JJY4xul2nmalrg23aMlurCAnkxaoVBu1tujyKpv+kc9P6bJa//PrN jdwvUXy2cFJMz0gczlfshkGmSsOInDiF/QkMaFuyLJnhpN8vLHynJxCdvY3ea4cCv79k sEKyYi3WCFQw7S9zR6aLqfJcwdSQuYd189IBypA6y2mORgVKPzbqMAe+00vEWFJlImYJ VJEezMwfOhxbpaI6kftaHGP4RuSEx4MCgf81Q0RPD9j/Lj6nvgLndGVN9MIneCDzPP6l TfXg== X-Gm-Message-State: AOAM532t/wXHzKzYfv4/bwpzN/JHFQHCoSjA4fMix+oFus4NgdIL23io 8q8OcWeC5fH328gpQN9KjTrob92yKF8g7A== X-Google-Smtp-Source: ABdhPJxuCkJJbwUe8Kx2i8YITOSsTf5hVWKqb/2oADOIZAqvbLvaMkl4bAYK9gEiZKv7BKDLwSoCag== X-Received: by 2002:a63:db44:: with SMTP id x4mr4290588pgi.435.1601406561700; Tue, 29 Sep 2020 12:09:21 -0700 (PDT) Received: from localhost.localdomain (122-116-72-36.HINET-IP.hinet.net. [122.116.72.36]) by smtp.gmail.com with ESMTPSA id v8sm6003950pgg.58.2020.09.29.12.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 12:09:21 -0700 (PDT) From: frank.chang@sifive.com To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [RFC v5 68/68] target/riscv: trigger illegal instruction exception if frm is not valid Date: Wed, 30 Sep 2020 03:04:43 +0800 Message-Id: <20200929190448.31116-69-frank.chang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200929190448.31116-1-frank.chang@sifive.com> References: <20200929190448.31116-1-frank.chang@sifive.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=frank.chang@sifive.com; helo=mail-pf1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sagar Karandikar , Frank Chang , Bastian Koppelmann , Richard Henderson , Alistair Francis , Palmer Dabbelt , LIU Zhiwei Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Frank Chang If the frm field contains an invalid rounding mode (101-111), attempting to execute any vector floating-point instruction, even those that do not depend on the rounding mode, will raise an illegal instruction exception. Call gen_set_rm() with DYN rounding mode to check and trigger illegal instruction exception if frm field contains invalid value at run-time for vector floating-point instructions. Signed-off-by: Frank Chang --- target/riscv/insn_trans/trans_rvv.c.inc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc index 7a1571cee8..7d4ce9e092 100644 --- a/target/riscv/insn_trans/trans_rvv.c.inc +++ b/target/riscv/insn_trans/trans_rvv.c.inc @@ -2624,8 +2624,11 @@ static bool do_opfv(DisasContext *s, arg_rmr *a, int rm) { if (checkfn(s, a)) { + if (rm != RISCV_FRM_DYN) { + gen_set_rm(s, RISCV_FRM_DYN); + } + uint32_t data = 0; - gen_set_rm(s, RISCV_FRM_DYN); TCGLabel *over = gen_new_label(); gen_set_rm(s, rm); tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); @@ -2710,6 +2713,8 @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) require_rvf(s) && vext_check_isa_ill(s) && require_align(a->rd, s->lmul)) { + gen_set_rm(s, RISCV_FRM_DYN); + TCGv_i64 t1; if (s->vl_eq_vlmax) { @@ -2792,6 +2797,10 @@ static bool opfv_widen_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (opfv_widen_check(s, a)) { \ + if (FRM != RISCV_FRM_DYN) { \ + gen_set_rm(s, RISCV_FRM_DYN); \ + } \ + \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[2] = { \ gen_helper_##HELPER##_h, \ @@ -2877,6 +2886,10 @@ static bool opfv_narrow_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (opfv_narrow_check(s, a)) { \ + if (FRM != RISCV_FRM_DYN) { \ + gen_set_rm(s, RISCV_FRM_DYN); \ + } \ + \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[2] = { \ gen_helper_##HELPER##_h, \ @@ -2917,6 +2930,10 @@ static bool opxfv_narrow_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (opxfv_narrow_check(s, a)) { \ + if (FRM != RISCV_FRM_DYN) { \ + gen_set_rm(s, RISCV_FRM_DYN); \ + } \ + \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[3] = { \ gen_helper_##HELPER##_b, \ @@ -3386,6 +3403,8 @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_f_s *a) if (require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s)) { + gen_set_rm(s, RISCV_FRM_DYN); + unsigned int ofs = (8 << s->sew); unsigned int len = 64 - ofs; TCGv_i64 t_nan; @@ -3411,6 +3430,8 @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) if (require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s)) { + gen_set_rm(s, RISCV_FRM_DYN); + /* The instructions ignore LMUL and vector register group. */ TCGv_i64 t1; TCGLabel *over = gen_new_label(); -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kNL0S-00008m-PA for mharc-qemu-riscv@gnu.org; Tue, 29 Sep 2020 15:09:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNL0D-0008TD-AW for qemu-riscv@nongnu.org; Tue, 29 Sep 2020 15:09:32 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:42040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNL06-0002YR-TZ for qemu-riscv@nongnu.org; Tue, 29 Sep 2020 15:09:28 -0400 Received: by mail-pf1-x444.google.com with SMTP id d6so5524919pfn.9 for ; Tue, 29 Sep 2020 12:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XI3sKczohciBsZgnmxAfhEd2fKi5Y9uKTWUghLaMHXA=; b=ZQhE9NsGUsuhKkZasb4VSRERQYh52kk6iMFmbJ72EpaeZ4QjKo65D973PlyPT6XiMv 1gY9Dre9n/t/eq+m0wZzPjkZA3bmimPF2s6wcNzr1nQwVWbdRCRJX2daw/I0okv49DZ6 CCDGcB2eXQWV62RMEqkM3nn0ZnzFdUsE2U20pDkSYAyCYK7My4mQJI3QdigaSb1if5eF r/pgrySMYlNR7an2ZMztFAHgI1b0P1iDCEj8TvnNuwERE03afP9rBecOwISFgtBx6hVt HrgmmU2dwcLlzhsx7ZFMl+23E8JSrqmlTIVRkc1i7tikAoQte2H8DsUgB1JnztJU3UYG bL4Q== 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=XI3sKczohciBsZgnmxAfhEd2fKi5Y9uKTWUghLaMHXA=; b=lWvVJITgZcra8ffybeCtG3ZYv7zVEI/SuSD4BYo0wSQCNxu0/x0OuO+/JZkuDtRXow F5EXjlvDGk2srCcKZ2QtmCyU7mKs8czIputlM/tlQeIVJRB8+PPAdktvR01NGLV5pVvi tT4g++nwnGgjGm0wP3bxsEKBwowxb00HLEiPZXoyf/8QwhQyED36zoIuDln6oBIKK7Zk Ptj8jY2ZXI4WiM7xa1vXUc7T2ugWrDmif4Sx3wyKJhQHp73EYDkLUSASD1o6I0YdaXAx F4LwdZscs2SLOrrdwG5jmmQr7UrwhWI7r5fxbS/ciBpt8euy3hBjnwxMKfUKcjvPGG6z cu9Q== X-Gm-Message-State: AOAM533q8t9OSPJWUawzbRtzBlqEx7O+ef8YejBkzCrAzhN6A9qtBVZr oepAaIJya1D0kspnCD92KivPeQ== X-Google-Smtp-Source: ABdhPJxuCkJJbwUe8Kx2i8YITOSsTf5hVWKqb/2oADOIZAqvbLvaMkl4bAYK9gEiZKv7BKDLwSoCag== X-Received: by 2002:a63:db44:: with SMTP id x4mr4290588pgi.435.1601406561700; Tue, 29 Sep 2020 12:09:21 -0700 (PDT) Received: from localhost.localdomain (122-116-72-36.HINET-IP.hinet.net. [122.116.72.36]) by smtp.gmail.com with ESMTPSA id v8sm6003950pgg.58.2020.09.29.12.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 12:09:21 -0700 (PDT) From: frank.chang@sifive.com To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Frank Chang , Palmer Dabbelt , Alistair Francis , Sagar Karandikar , Bastian Koppelmann , Richard Henderson , LIU Zhiwei Subject: [RFC v5 68/68] target/riscv: trigger illegal instruction exception if frm is not valid Date: Wed, 30 Sep 2020 03:04:43 +0800 Message-Id: <20200929190448.31116-69-frank.chang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200929190448.31116-1-frank.chang@sifive.com> References: <20200929190448.31116-1-frank.chang@sifive.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=frank.chang@sifive.com; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Sep 2020 19:09:34 -0000 From: Frank Chang If the frm field contains an invalid rounding mode (101-111), attempting to execute any vector floating-point instruction, even those that do not depend on the rounding mode, will raise an illegal instruction exception. Call gen_set_rm() with DYN rounding mode to check and trigger illegal instruction exception if frm field contains invalid value at run-time for vector floating-point instructions. Signed-off-by: Frank Chang --- target/riscv/insn_trans/trans_rvv.c.inc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc index 7a1571cee8..7d4ce9e092 100644 --- a/target/riscv/insn_trans/trans_rvv.c.inc +++ b/target/riscv/insn_trans/trans_rvv.c.inc @@ -2624,8 +2624,11 @@ static bool do_opfv(DisasContext *s, arg_rmr *a, int rm) { if (checkfn(s, a)) { + if (rm != RISCV_FRM_DYN) { + gen_set_rm(s, RISCV_FRM_DYN); + } + uint32_t data = 0; - gen_set_rm(s, RISCV_FRM_DYN); TCGLabel *over = gen_new_label(); gen_set_rm(s, rm); tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); @@ -2710,6 +2713,8 @@ static bool trans_vfmv_v_f(DisasContext *s, arg_vfmv_v_f *a) require_rvf(s) && vext_check_isa_ill(s) && require_align(a->rd, s->lmul)) { + gen_set_rm(s, RISCV_FRM_DYN); + TCGv_i64 t1; if (s->vl_eq_vlmax) { @@ -2792,6 +2797,10 @@ static bool opfv_widen_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (opfv_widen_check(s, a)) { \ + if (FRM != RISCV_FRM_DYN) { \ + gen_set_rm(s, RISCV_FRM_DYN); \ + } \ + \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[2] = { \ gen_helper_##HELPER##_h, \ @@ -2877,6 +2886,10 @@ static bool opfv_narrow_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (opfv_narrow_check(s, a)) { \ + if (FRM != RISCV_FRM_DYN) { \ + gen_set_rm(s, RISCV_FRM_DYN); \ + } \ + \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[2] = { \ gen_helper_##HELPER##_h, \ @@ -2917,6 +2930,10 @@ static bool opxfv_narrow_check(DisasContext *s, arg_rmr *a) static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ { \ if (opxfv_narrow_check(s, a)) { \ + if (FRM != RISCV_FRM_DYN) { \ + gen_set_rm(s, RISCV_FRM_DYN); \ + } \ + \ uint32_t data = 0; \ static gen_helper_gvec_3_ptr * const fns[3] = { \ gen_helper_##HELPER##_b, \ @@ -3386,6 +3403,8 @@ static bool trans_vfmv_f_s(DisasContext *s, arg_vfmv_f_s *a) if (require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s)) { + gen_set_rm(s, RISCV_FRM_DYN); + unsigned int ofs = (8 << s->sew); unsigned int len = 64 - ofs; TCGv_i64 t_nan; @@ -3411,6 +3430,8 @@ static bool trans_vfmv_s_f(DisasContext *s, arg_vfmv_s_f *a) if (require_rvv(s) && require_rvf(s) && vext_check_isa_ill(s)) { + gen_set_rm(s, RISCV_FRM_DYN); + /* The instructions ignore LMUL and vector register group. */ TCGv_i64 t1; TCGLabel *over = gen_new_label(); -- 2.17.1