From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807648418535.49734759246; Sat, 2 Jul 2022 17:20:48 -0700 (PDT) Received: from localhost ([::1]:36316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nLy-0004vw-N4 for importer@patchew.org; Sat, 02 Jul 2022 20:20:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEJ-0007uY-6j for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:51 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46148) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEC-0001pG-Nz for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:50 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:42 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:04 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:42 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XB2dlCz1RtVk for ; Sat, 2 Jul 2022 17:12:42 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id UNB4ZV_VgtY9 for ; Sat, 2 Jul 2022 17:12:42 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8X83gq7z1Rwnl; Sat, 2 Jul 2022 17:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807164; x=1688343164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=313dBeAD/+njONzvGGqB/x71wYKkT7Nvi+L1/eUJaqk=; b=RnyD9N/VJQMonnAOi5tiMYM19Z/Sqaq60uq1rHvub/+DrdEc9OQekUJz ZLZht3XFrBc8mGSCyqYKLpiAsODm3H7hw6Vv46yljwq2T5fEwo3OOnsGj 7O5BrkOQwMBHU2hl2AwSYtBthsLDNkZXd79CTyvWsHMlHq5Q/FmmzjgZ5 jfqN7xz7VYb3FZOn/ka0elL8wMmpCntSarCmEz7cuj/gjdVJb6CYzyqNc 6pCI71U9A84jSi2fFXJoGuUyjSJqVHKxqQmA3eoitZ42ve2OPflfvH/VD UDh9lpFeQ8Tw34+4RG3IM7qJ1KJ4T909rmP9l8Sl223xHv5lkZEfvQh2b w==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667214" IronPort-SDR: UmC7nf6Q5Wa8YHwIA+AD9xs/fyH9e7ZEwC8UHwrzPOYhsmE+cU0V2PHPpVYJJAQvq4FgSYU6/T +hC9uSBzcRn2F8IqgRWHFF/6U0AYWaF6l1oFySP6JRgD8ff16ikRSEndEUfUX1OhN8N98H+bhb o0qcJOoXuzTh/hML8gmNraqDJkY92cq7MychZX5GijeRMviZyhRkpQQrLJDFH/ZzqKhdpEfA5e Cnoa2cbQBGm8jh/hzvroQ1GAmEyQAG/Zrr/sZDlKT3D0jpPHwl4NLrfGp+HYkXdEA/3c6az2mG wd3suvAFW+iZ6Ycg+EBP7A5V IronPort-SDR: d4oUsDFhkoqw3mPKEyTWMdA36N+RBNAVifOuTaWC3qz89J6dWIbQ5JRPr0e1zNmWV18dRaQDQU y1INpSVzu7KRmaRS00dhqlH+1uFI4YY9ORNu6MeczF4lt+BdLiKk1EHwpgLYZu010g3Xx9T1Jb J7OLpH6XzklyFgE7ZJ+8WOn4gq9QVbl3o/aIuqMnuC39Msg1F5F/RrSARavhINgDEIpy7EbXZo IjECtLBfJiilJ/44EkpwcHLUWcnjtbiZSdxjsc7FOGSQ/ACWv+1+82g7fkiJo/DUz8CnQ33u0l rsY= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :mime-version:references:in-reply-to:x-mailer:message-id:date :subject:to:from; s=dkim; t=1656807162; x=1659399163; bh=313dBeA D/+njONzvGGqB/x71wYKkT7Nvi+L1/eUJaqk=; b=ebyoAjBog8TmC3yy2rbuFU1 FgWe+8Ix4GhhK4Rvsur+T/UbzNBVjdyADWHpE+PEe/fnBAMD9G50OUp84ohD7m4g r9R/6HpzEVRQE8sojFw4Kg4NxjzTeSDpP0GCcee1WQCPVVU7FjTRfttvU8rUk4D4 xZkk9ZQ7ibSDAGPYGkPKTDwcf9APoUaIKABKCign7pfU2i6T0G6irfypcXqTL4tj wo3K/A0LLdvbAbef7zCPXgUoJ/8CVpP51ypv9KrEvxfZNWl9z0ELvOJMyhAA//OK rB378FxzExorFsHLGtDxLOeBQZ0ukMT5EiQE0Dh9BaY6kxFqWtUXaRLRFwoDzjw= = X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, =?UTF-8?q?V=C3=ADctor=20Colombo?= , Richard Henderson , Alistair Francis Subject: [PULL v2 01/19] target/riscv: Remove condition guarding register zero for auipc and lui Date: Sun, 3 Jul 2022 10:12:16 +1000 Message-Id: <20220703001234.439716-2-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807649753100001 Content-Type: text/plain; charset="utf-8" From: V=C3=ADctor Colombo Commit 57c108b8646 introduced gen_set_gpri(), which already contains a check for if the destination register is 'zero'. The check in auipc and lui are then redundant. This patch removes those checks. Signed-off-by: V=C3=ADctor Colombo Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis Message-Id: <20220610165517.47517-1-victor.colombo@eldorado.org.br> Signed-off-by: Alistair Francis --- target/riscv/insn_trans/trans_rvi.c.inc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index f1342f30f8..c190a59f22 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -32,17 +32,13 @@ static bool trans_c64_illegal(DisasContext *ctx, arg_em= pty *a) =20 static bool trans_lui(DisasContext *ctx, arg_lui *a) { - if (a->rd !=3D 0) { - gen_set_gpri(ctx, a->rd, a->imm); - } + gen_set_gpri(ctx, a->rd, a->imm); return true; } =20 static bool trans_auipc(DisasContext *ctx, arg_auipc *a) { - if (a->rd !=3D 0) { - gen_set_gpri(ctx, a->rd, a->imm + ctx->base.pc_next); - } + gen_set_gpri(ctx, a->rd, a->imm + ctx->base.pc_next); return true; } =20 --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807449377450.97973685882323; Sat, 2 Jul 2022 17:17:29 -0700 (PDT) Received: from localhost ([::1]:55872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nIm-0007dD-3L for importer@patchew.org; Sat, 02 Jul 2022 20:17:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEL-00081l-3Y for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:53 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEE-0001pZ-Kv for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:52 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:44 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:06 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:44 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XD2LLcz1Rwnx for ; Sat, 2 Jul 2022 17:12:44 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Z6KGGKlI_3Ew for ; Sat, 2 Jul 2022 17:12:43 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XB2zbRz1Rwnm; Sat, 2 Jul 2022 17:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807166; x=1688343166; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iFrMNgZb795PtkupPWdOdfi4pfpHCJ8j6NfcibHYPh4=; b=hiXloEAtZwpSXZQ4shP9Pk/36JdTYA4WkNNThz69OW6z/9wgemsSESNw taYBv5ec8RRWs4SkS6W6e+bRo4FGRHERCxl7vVoKj2fQdHA4mvtfekMGs h/KrXQU2tmYbUDSbBdD5EKn/oKZAVQHyWVXyh2lFOmdopkWwzQEmCR9Q+ fqksar8uQ6QpVToDoamk93C8tF5PqYnUpDOHYovVJVUGh3MxmC1+mptJt LFH3shd/z2D3rMKON5iHSSoMGIhzYamdHVKjNyargt5N6N5Vl7M3KCV/B +QLWlH+3r84UtMs77Zv0zlLnKf0dpHmnkdspSucN9yO5hInOW3bapDy4e A==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667215" IronPort-SDR: p8iB/Rt4sq1rGQ+DeYwpjP2O4lVibGwtcPrK3zGgtFZR6YpLbVZNcZb8ecyX5N6y7J6fObR1Lh gerS1n5FtFMtxuvBGQaxmfi1X201h6V5XuxTzCZaZoH7opUXzPObDmL0b1MgglLsDXXMZTzz8j Ba5YCO97IU64o1VQbVIoO5A2i+nzDsugSac/kr9B83UwaQ25R9T75vZsd56YTJBBbcH1oosJNI hpPQE57I8oVA+b5sflLqbuB6SJV8LBQFSzMmg0ffXES98M0Ul5rKBIaW0TLZFVXanZ1c2ZvTAH x76GedHeWnb53aj1mAWJChrN IronPort-SDR: uK/qH1EDRPnJ9jqcs0KdpQhAZ5mqX6NkupXZUmWvZARsU1dVLKpRH/pytYatRS8CEsLE9De6S0 EHkhetleCcqf/4WOgbEOoFO4K4TtsGdr9/Lf2dcTbHpzfh6mSQepa6oN8h6ix9SPmvb9vKq2hw DIcFb4745LXfhdVzjE7ZMj8Loa4IE71CR+U7k3h9puXSHuvccKpWHpkF4Yu3lsy0oQf8P4Btqm lPEWbW79vzgTb8ZRKyWWMPg+5MFimKZemAuBUCdz3pgG6QlwIjn9/JxMDgyuAq4IRodkrCxQlU 7jg= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807163; x=1659399164; bh=iFrMNgZb795PtkupPW dOdfi4pfpHCJ8j6NfcibHYPh4=; b=SxXixKRXfoibeN/S1VmI2Q7tEh/bZrQiLA d90EpKB7Xv1D+cXpTbb57wBHHfRSi2dv8Wdg+nk6FsJsLzElZPDOhximYGxhzSlA 19HRMhm8aZGVBHkAe4/TT2UNvkZqB3exO58lYyjl6BqWw6JwCTY9N4+JgcmWZ10/ I5EvPfP/XtxLnf30fQLAM97F5MKcsx1Fp5j1s1mEzuABCh6yFaYm/PVSGu8F//gc Nowq1z+LtHX+dd9oKKztlXr+mGMGNal783ZP4xkICVioIAiEmG2bbLStaqotC7gJ X60eXkGVp+laQFCVXtxs0hYQMZ5E8gdxt2YBsGxX9x5fLH5HJ74g== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Richard Henderson , Alistair Francis Subject: [PULL v2 02/19] target/riscv: Set env->bins in gen_exception_illegal Date: Sun, 3 Jul 2022 10:12:17 +1000 Message-Id: <20220703001234.439716-3-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807450846100003 Content-Type: text/plain; charset="utf-8" From: Richard Henderson While we set env->bins when unwinding for ILLEGAL_INST, from e.g. csrrw, we weren't setting it for immediately illegal instructions. Add a testcase for mtval via both exception paths. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1060 Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Message-Id: <20220604231004.49990-2-richard.henderson@linaro.org> Signed-off-by: Alistair Francis --- target/riscv/translate.c | 2 + tests/tcg/riscv64/Makefile.softmmu-target | 21 +++++++++ tests/tcg/riscv64/issue1060.S | 53 +++++++++++++++++++++++ tests/tcg/riscv64/semihost.ld | 21 +++++++++ 4 files changed, 97 insertions(+) create mode 100644 tests/tcg/riscv64/Makefile.softmmu-target create mode 100644 tests/tcg/riscv64/issue1060.S create mode 100644 tests/tcg/riscv64/semihost.ld diff --git a/target/riscv/translate.c b/target/riscv/translate.c index b151c20674..a10f3f939c 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -240,6 +240,8 @@ static void generate_exception_mtval(DisasContext *ctx,= int excp) =20 static void gen_exception_illegal(DisasContext *ctx) { + tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env, + offsetof(CPURISCVState, bins)); generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST); } =20 diff --git a/tests/tcg/riscv64/Makefile.softmmu-target b/tests/tcg/riscv64/= Makefile.softmmu-target new file mode 100644 index 0000000000..e22cdb34c5 --- /dev/null +++ b/tests/tcg/riscv64/Makefile.softmmu-target @@ -0,0 +1,21 @@ +# +# RISC-V system tests +# + +TEST_SRC =3D $(SRC_PATH)/tests/tcg/riscv64 +VPATH +=3D $(TEST_SRC) + +LINK_SCRIPT =3D $(TEST_SRC)/semihost.ld +LDFLAGS =3D -T $(LINK_SCRIPT) +CFLAGS +=3D -g -Og + +%.o: %.S + $(CC) $(CFLAGS) $< -c -o $@ +%: %.o $(LINK_SCRIPT) + $(LD) $(LDFLAGS) $< -o $@ + +QEMU_OPTS +=3D -M virt -display none -semihosting -device loader,file=3D + +EXTRA_RUNS +=3D run-issue1060 +run-issue1060: issue1060 + $(call run-test, $<, $(QEMU) $(QEMU_OPTS)$<) diff --git a/tests/tcg/riscv64/issue1060.S b/tests/tcg/riscv64/issue1060.S new file mode 100644 index 0000000000..17b7fe1be2 --- /dev/null +++ b/tests/tcg/riscv64/issue1060.S @@ -0,0 +1,53 @@ + .option norvc + + .text + .global _start +_start: + lla t0, trap + csrw mtvec, t0 + + # These are all illegal instructions + csrw time, x0 + .insn i CUSTOM_0, 0, x0, x0, 0x321 + csrw time, x0 + .insn i CUSTOM_0, 0, x0, x0, 0x123 + csrw cycle, x0 + + # Success! + li a0, 0 + j _exit + +trap: + # When an instruction traps, compare it to the insn in memory. + csrr t0, mepc + csrr t1, mtval + lwu t2, 0(t0) + bne t1, t2, fail + + # Skip the insn and continue. + addi t0, t0, 4 + csrw mepc, t0 + mret + +fail: + li a0, 1 + +# Exit code in a0 +_exit: + lla a1, semiargs + li t0, 0x20026 # ADP_Stopped_ApplicationExit + sd t0, 0(a1) + sd a0, 8(a1) + li a0, 0x20 # TARGET_SYS_EXIT_EXTENDED + + # Semihosting call sequence + .balign 16 + slli zero, zero, 0x1f + ebreak + srai zero, zero, 0x7 + j . + + .data + .balign 16 +semiargs: + .space 16 diff --git a/tests/tcg/riscv64/semihost.ld b/tests/tcg/riscv64/semihost.ld new file mode 100644 index 0000000000..a59cc56b28 --- /dev/null +++ b/tests/tcg/riscv64/semihost.ld @@ -0,0 +1,21 @@ +ENTRY(_start) + +SECTIONS +{ + /* virt machine, RAM starts at 2gb */ + . =3D 0x80000000; + .text : { + *(.text) + } + .rodata : { + *(.rodata) + } + /* align r/w section to next 2mb */ + . =3D ALIGN(1 << 21); + .data : { + *(.data) + } + .bss : { + *(.bss) + } +} --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807643941710.8450810313116; Sat, 2 Jul 2022 17:20:43 -0700 (PDT) Received: from localhost ([::1]:36042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nLu-0004kf-UI for importer@patchew.org; Sat, 02 Jul 2022 20:20:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEN-0008An-BX for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:55 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEJ-0001p4-3P for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:55 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:45 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:07 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:45 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XF3qycz1Rwnx for ; Sat, 2 Jul 2022 17:12:45 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id cH9kQCcHDNrQ for ; Sat, 2 Jul 2022 17:12:45 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XD0GRWz1RtVk; Sat, 2 Jul 2022 17:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807170; x=1688343170; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XOGoS+LaSNx9ztfN+554+3MJdJHKkwrfOy2g668jrT8=; b=H1qVyptcUusfzZMQ1HJnfwGIuZyJfJEwJxnICU9BQNIsoga2kB3pm5Wq Q7dgdOX0T4Xgh9+vadcbngidx/Jh5H7zvSlKTd2xZi7rPdvRRj0pTilXT X4KaehbEMOE94DHB+C80J5kPfEkMwTvse0ApwIBw+cbYakNY2Szu9j2It 5MigeliB4kXiacED8dUisZVpYu64R9MaeI5VbO207lWtrHg16xISCrfk4 tSUQ+nocRXa2dbizCA3A3TP9DeNIXIb/naussY1qsRxOSx2fMH6m5uEkL CN4dHq9B5OqXj9crmSRG90qJkSajBhymz0G5jgz9jH1QZIXzc8ksD9dUW A==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667216" IronPort-SDR: XnW3QGYg4u5FUyo96/cqSMeWjBbhZfS0MoBAQ0qAk4bFRxbAGQUXNsMSeXYJBuTfUCbt2lMG6a 5UOK2OlRm6JAVgoNBDLuzTgZU3FPApDtrHb4FBqJHyXG5MxEJZYYDLTZ3LOfiO2PyOS0UirTXd cNon0Q9Gp20chBUqK5sPPX2sgL2mWP4CP/a0Ei8rrsznTk9gYffo/TYDnCH4sMjpuG4l9lAhyp blqTidmeRG906veTEtfgR77kwIehSNvyWXX/mW/TMs3lbA9ODd22q/qBgEXoXfiLkxA+wO4+6a NCRc9e6uTmAtOvSzf5wbB+At IronPort-SDR: uUF6PoEQrXIMe8V4hvBcR27OweAzopIxutf7LpNm9rdo9kvMNifvHKzHwodq8E1Vpkko0azWRf Td/3/cDS3uMpsty0YW7qDtcupU/ahYqepnLgIB0H/PA7wGteU24MkBHaIM++BfayziXFrKOAdy 9aueoWMgu7ttS0bdd2kj8tIo9qBlvdWTXtyJ1MJByz59i/bZn+Fb0AscWQbenbzIgaeWaLuyaR vr2xZ4RHaw4L8GUdnqVy9Q76Hfeuo2FbRNzCLX8hIZKZoDA1l3BtkuaRflmjfwLxVFdQxwsNpY ilA= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807165; x=1659399166; bh=XOGoS+LaSNx9ztfN+5 54+3MJdJHKkwrfOy2g668jrT8=; b=sflzhH3t7LMGZBhP29ka1yeSpfjCGZgM1u ZZ0dEmgjYjF0+B1XM+09C9bKz5teb0eMrW7D31dhH/cFMHXa2QnmpxwxpILhk7iV sDtUgoBWWegodfZyGC2gdkOMOB8WC0a8E/afJMpQbLeL5+4LuazsWOJ2rNx37EKa 8ks4k6PDITNgBsazoMbNtzpB4Y1FwT1PQIOMOfHZ04HoouJXgoqELLVroRhlLciR dTOOB6IzCjltd1PkHW+navU8p8anp89KLx8dKymvB20m/f7bz8iR96nfgu0bwzf5 xbK+TrcywGpGWICcXuHShtLaMHL6hhmONCeNJMbPd7fi6ue7CFNw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Richard Henderson , Alistair Francis Subject: [PULL v2 03/19] target/riscv: Remove generate_exception_mtval Date: Sun, 3 Jul 2022 10:12:18 +1000 Message-Id: <20220703001234.439716-4-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807645772100001 Content-Type: text/plain; charset="utf-8" From: Richard Henderson The function doesn't set mtval, it sets badaddr. Move the set of badaddr directly into gen_exception_inst_addr_mis and use generate_exception. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Message-Id: <20220604231004.49990-3-richard.henderson@linaro.org> Signed-off-by: Alistair Francis --- target/riscv/translate.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index a10f3f939c..7205a29603 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -230,14 +230,6 @@ static void generate_exception(DisasContext *ctx, int = excp) ctx->base.is_jmp =3D DISAS_NORETURN; } =20 -static void generate_exception_mtval(DisasContext *ctx, int excp) -{ - gen_set_pc_imm(ctx, ctx->base.pc_next); - tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr)); - gen_helper_raise_exception(cpu_env, tcg_constant_i32(excp)); - ctx->base.is_jmp =3D DISAS_NORETURN; -} - static void gen_exception_illegal(DisasContext *ctx) { tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env, @@ -247,7 +239,8 @@ static void gen_exception_illegal(DisasContext *ctx) =20 static void gen_exception_inst_addr_mis(DisasContext *ctx) { - generate_exception_mtval(ctx, RISCV_EXCP_INST_ADDR_MIS); + tcg_gen_st_tl(cpu_pc, cpu_env, offsetof(CPURISCVState, badaddr)); + generate_exception(ctx, RISCV_EXCP_INST_ADDR_MIS); } =20 static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807448417514.3543043529929; Sat, 2 Jul 2022 17:17:28 -0700 (PDT) Received: from localhost ([::1]:55528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nIl-0007Os-0e for importer@patchew.org; Sat, 02 Jul 2022 20:17:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEO-0008DG-8M for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:56 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46148) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEJ-0001pG-HJ for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:55 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:47 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:09 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:47 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XH1mG8z1Rwnx for ; Sat, 2 Jul 2022 17:12:47 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 1S6PRXZ2UD2x for ; Sat, 2 Jul 2022 17:12:46 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XF3wPjz1RwqM; Sat, 2 Jul 2022 17:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807171; x=1688343171; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/hrKk5p20kxaD0zCjNEk9cveWwf20tx/Gzwy08mr1wY=; b=UlYL7Uce0gP4fpAzAOAab4BsVkL8yKotSCzhXCSRinNReeJlyn/7H9PG 48jWi9x/WTTUyhKLsB64JNrAzJCfaZgc0X9rqACU8LLuLQbDzJNWdiMhh 3a22IBMYujAyS78YkAWnGisctpqzS9WaXz3Th6BX0s0MPHu13x2c+k35l BT71hi0Us2iwwp6uVcuDdtTBe453ClD9Vq3bxt225YQbPrM+rZ1QaCBOv N+zluuhmsfI1W+tXDZO2MZHPUzCq+GMfm9QnEEbNyFfEI+a5It+Dw1zJK RCdJC3AK0LmGRYt2YE2hKVq3wDemfO3QXUVU0wDJ9TQnab5MH3hT/y+6/ Q==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667217" IronPort-SDR: qGGFeDr97wU1LQz/96u05Ob9H5QAyaR21LnPqo4cx05U4yvFWy0J2OlPBJPrDz8/73LEtAKnf5 rjzukPf+8YOUmhWj05sedzxP07SGobrhHGx+f0blTni2n3d4xQ/XCU0/h6GQyab5bZU5j+Jycm IramQIZdDJ7cw4oR/VsOmmEqX9wHsCkL9TD9zyYs4hneWxYTEvqCTl5YRqA2/Ohp4ooTm426rJ bz2IgwMB/R2brDcFm0evvaD4i0ZQZ7wnfnKG3TVvb21vZ43iZo8khAMbaK/IYWFSV7rRCBRQf1 22DT6/YiYvc/mdBuXPjpMWya IronPort-SDR: 2IKWDGLk/wvxNtca1di8HqO98rL7yfkGsotNj86ss246CLIMVbQGxa3I2bqxhawavJQK2XYhLC r6XKqHfnwHNslbDfCZOdpwv96q6fp5YvpotvZjPuKOC57U72CWSch/GSsa0zhXboiet0A+uTS3 Zao95H08QMArTjqRE6r6af9oXMRZj1r2ymFPgpAiUmeTVs2AsU8jfzt/ci5qFL3L8o300ChWz7 r80uZXcvNAwXbPzL8hXe0Rw0xMF/0nMd9nkNqgOSc6pYesOVF4H0e8d1NVtrAa3Wr4AYi7yeCU qfA= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807166; x=1659399167; bh=/hrKk5p20kxaD0zCjN Ek9cveWwf20tx/Gzwy08mr1wY=; b=K2qzhpYij4NdRHv+jpb6p4rXsW5HGH//f0 Er9jEKmo2JMY/KGQsNpePcwLyIFlUyOg+jSMcbG2tl5GOuIcRs37BRlHd1c6QiHL d8bvBQeKKxEUPquf85CF+WE6XjAAlJOmG+EJbSRt3PX2pGzw60CLDyqCffFymWtF 42jCrbWOb++VBPtMyo0cOkQcgS6NXGW02Lrt53bNHpvfEElohYRsgPCq7iXrIV8z TLBxtaeeaxcPB0XhhY1jAEu7wgQHj3WrZujiNRSeOIyOCqmQ3yAOivTWi4KB7oNn IVpSTXbnFp8A8R12OPQRcngZ1HSlBZHD+D9GWs/3OKmQlp3Uk1vw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Richard Henderson , Alistair Francis Subject: [PULL v2 04/19] target/riscv: Minimize the calls to decode_save_opc Date: Sun, 3 Jul 2022 10:12:19 +1000 Message-Id: <20220703001234.439716-5-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807449024100001 Content-Type: text/plain; charset="utf-8" From: Richard Henderson The set of instructions that require decode_save_opc for unwinding is really fairly small -- only insns that can raise ILLEGAL_INSN at runtime. This includes CSR, anything that uses a *new* fp rounding mode, and many privileged insns. Since unwind info is stored as the difference from the previous insn, storing a 0 for most insns minimizes the size of the unwind info. Booting a debian kernel image to the missing rootfs panic yields - gen code size 22226819/1026886656 + gen code size 21601907/1026886656 on 41k TranslationBlocks, a savings of 610kB or a bit less than 3%. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Message-Id: <20220604231004.49990-4-richard.henderson@linaro.org> Signed-off-by: Alistair Francis --- target/riscv/translate.c | 18 +++++++++--------- target/riscv/insn_trans/trans_privileged.c.inc | 4 ++++ target/riscv/insn_trans/trans_rvh.c.inc | 2 ++ target/riscv/insn_trans/trans_rvi.c.inc | 2 ++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 7205a29603..63b04e8a94 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -206,6 +206,13 @@ static void gen_check_nanbox_s(TCGv_i64 out, TCGv_i64 = in) tcg_gen_movcond_i64(TCG_COND_GEU, out, in, t_max, in, t_nan); } =20 +static void decode_save_opc(DisasContext *ctx) +{ + assert(ctx->insn_start !=3D NULL); + tcg_set_insn_start_param(ctx->insn_start, 1, ctx->opcode); + ctx->insn_start =3D NULL; +} + static void gen_set_pc_imm(DisasContext *ctx, target_ulong dest) { if (get_xl(ctx) =3D=3D MXL_RV32) { @@ -635,6 +642,8 @@ static void gen_set_rm(DisasContext *ctx, int rm) return; } =20 + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ + decode_save_opc(ctx); gen_helper_set_rounding_mode(cpu_env, tcg_constant_i32(rm)); } =20 @@ -1013,13 +1022,6 @@ static uint32_t opcode_at(DisasContextBase *dcbase, = target_ulong pc) /* Include decoders for factored-out extensions */ #include "decode-XVentanaCondOps.c.inc" =20 -static inline void decode_save_opc(DisasContext *ctx, target_ulong opc) -{ - assert(ctx->insn_start !=3D NULL); - tcg_set_insn_start_param(ctx->insn_start, 1, opc); - ctx->insn_start =3D NULL; -} - static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opc= ode) { /* @@ -1036,7 +1038,6 @@ static void decode_opc(CPURISCVState *env, DisasConte= xt *ctx, uint16_t opcode) =20 /* Check for compressed insn */ if (extract16(opcode, 0, 2) !=3D 3) { - decode_save_opc(ctx, opcode); if (!has_ext(ctx, RVC)) { gen_exception_illegal(ctx); } else { @@ -1051,7 +1052,6 @@ static void decode_opc(CPURISCVState *env, DisasConte= xt *ctx, uint16_t opcode) opcode32 =3D deposit32(opcode32, 16, 16, translator_lduw(env, &ctx->base, ctx->base.pc_next + 2)); - decode_save_opc(ctx, opcode32); ctx->opcode =3D opcode32; ctx->pc_succ_insn =3D ctx->base.pc_next + 4; =20 diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/= insn_trans/trans_privileged.c.inc index 53613682e8..46f96ad74d 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -75,6 +75,7 @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) { #ifndef CONFIG_USER_ONLY if (has_ext(ctx, RVS)) { + decode_save_opc(ctx); gen_helper_sret(cpu_pc, cpu_env); tcg_gen_exit_tb(NULL, 0); /* no chaining */ ctx->base.is_jmp =3D DISAS_NORETURN; @@ -90,6 +91,7 @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) static bool trans_mret(DisasContext *ctx, arg_mret *a) { #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_helper_mret(cpu_pc, cpu_env); tcg_gen_exit_tb(NULL, 0); /* no chaining */ ctx->base.is_jmp =3D DISAS_NORETURN; @@ -102,6 +104,7 @@ static bool trans_mret(DisasContext *ctx, arg_mret *a) static bool trans_wfi(DisasContext *ctx, arg_wfi *a) { #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_set_pc_imm(ctx, ctx->pc_succ_insn); gen_helper_wfi(cpu_env); return true; @@ -113,6 +116,7 @@ static bool trans_wfi(DisasContext *ctx, arg_wfi *a) static bool trans_sfence_vma(DisasContext *ctx, arg_sfence_vma *a) { #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_helper_tlb_flush(cpu_env); return true; #endif diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_tr= ans/trans_rvh.c.inc index cebcb3f8f6..4f8aecddc7 100644 --- a/target/riscv/insn_trans/trans_rvh.c.inc +++ b/target/riscv/insn_trans/trans_rvh.c.inc @@ -169,6 +169,7 @@ static bool trans_hfence_gvma(DisasContext *ctx, arg_sf= ence_vma *a) { REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_helper_hyp_gvma_tlb_flush(cpu_env); return true; #endif @@ -179,6 +180,7 @@ static bool trans_hfence_vvma(DisasContext *ctx, arg_sf= ence_vma *a) { REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY + decode_save_opc(ctx); gen_helper_hyp_tlb_flush(cpu_env); return true; #endif diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index c190a59f22..ca8e3d1ea1 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -818,6 +818,8 @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_= i *a) =20 static bool do_csr_post(DisasContext *ctx) { + /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ + decode_save_opc(ctx); /* We may have changed important cpu state -- exit to main loop. */ gen_set_pc_imm(ctx, ctx->pc_succ_insn); tcg_gen_exit_tb(NULL, 0); --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807778562554.7724983688446; Sat, 2 Jul 2022 17:22:58 -0700 (PDT) Received: from localhost ([::1]:43902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nO5-0001kx-12 for importer@patchew.org; Sat, 02 Jul 2022 20:22:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEP-0008HP-Ku for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:57 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEL-0001pZ-DP for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:57 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:49 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:11 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:49 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XK3TF4z1Rwnm for ; Sat, 2 Jul 2022 17:12:49 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id dBrKIqrnUwFU for ; Sat, 2 Jul 2022 17:12:49 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XH0XbKz1RtVk; Sat, 2 Jul 2022 17:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807172; x=1688343172; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Keur84s81dftzm7jD69JDIbb8De9fx2cMQzJdkPZ2LE=; b=E14vGwEP7N1YKOPrZFNguKP/BTX5xOqSlLzPkZaY0ulLL8tqcqxs5iTY RIjsPwyHxV0ApP0JPQ1+aIkn06yVLZ9Ywj5UBw1AYZCT3KRmCqSzxjFzA h3emXfWuglhSv2v1xSyFll7zZ+MLLIuM2Zw94ky9iyz+pGMV02u9tnCnN LdxNzOAwIq6A4S93YaiCZEl2uTcxvn9H8UJ+G6UoE3eC+W3TOkKttMNmS eLx4vv5sEV7+wRYY9EyFffEiIcpJ7V3fxxj15RQiMUSgyCOKzT3UlC0WY cEEwCNZmuOK8rpZThbRNDyvbvig8e95sJUlyFygyTCUfdnnMJBy4Qe9hb A==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667225" IronPort-SDR: wMXL38Kdgx+LTbbAfxh01K8602cNdPzSF59mH1pjwZbmJw4PBsXbQnVS7AUP7SKDsMyM3HWUFg 1gTtmDxWxcaQOVkWLKYXAptRqotJB7vRhLAEV9sujMQzXzE0+hxg8rRzf0HpAOIH+IyyqQCElo C0tJNL9DeQkZJjJqBJtLQ+GubpqEo5QVjIqCCIiZCugoH70iVqTBi0qbn6Y8bwLuLjzedk62S/ enbZ5Dv5Cxe2NfogwkbAvm0aZuDDoHx+MjnapNNDQUI6sskdjCPbt//quQSElirsjYdfBNBpew vNegQjs1UYZ/jeTUN63u5LFL IronPort-SDR: iFYAcw5D5UkGugvVR29FwIwBENjdRWpMIhCGs2EahHwQkx2/1kYMnqhl8r35nNI5SGAigTjZ/r XWe9jzxoP3GdU2KffTX5/Ap650+bzu5PbKeRTjrrRJi14xjgA/tSVoy8Zns6G52w3Cl3IvJzNU 3FRD3f4fC5Y844RFK+PqJanbZgWsCagrxIaDQPVXMPQOuWzQC+1J3O1kr1szgJCj+rgDffR6OW BnrlJxDIh2dvOYGi5246XIAoKNWXPUZPdBjFc4RJCtZXRga9O2PVGlSvZkNBvieGtVV2cmwLDm kwU= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807169; x=1659399170; bh=Keur84s81dftzm7jD6 9JDIbb8De9fx2cMQzJdkPZ2LE=; b=YJ23VrhtB2dU2JRKyIPqwyQsyigXQH0FNM hgHF2AvrBj92WE8JZETiNJkAHvju/SjiX+Q+natTglrr5bwIoHT5SyqS12n88JMh /vTXCweNz3XAZY283NTbx3oCLV7Wf1XLFInjCtVfvUK3yR0EYCp2yVWqvJzTP/d5 61gnZJDGBJBtFGRYJXVXeU02Egtgxfv8TRBNBw/aRWWHUIPDcHPzGmZ34CQUrHBB kCBeKbVmU48kw6X1w6vC0au8ENTArBUs7aoEmPKPHOSriEqHQBHNcd3lCkqhp9kA hR0iibVoW7YhI8oE+KZ1/w7D6gQlqeFhwhgB1pxTPyYhjRt1L7xA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Nicolas Pitre , Alistair Francis Subject: [PULL v2 05/19] target/riscv/pmp: guard against PMP ranges with a negative size Date: Sun, 3 Jul 2022 10:12:20 +1000 Message-Id: <20220703001234.439716-6-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807780306100001 Content-Type: text/plain; charset="utf-8" From: Nicolas Pitre For a TOR entry to match, the stard address must be lower than the end address. Normally this is always the case, but correct code might still run into the following scenario: Initial state: pmpaddr3 =3D 0x2000 pmp3cfg =3D OFF pmpaddr4 =3D 0x3000 pmp4cfg =3D TOR Execution: 1. write 0x40ff to pmpaddr3 2. write 0x32ff to pmpaddr4 3. set pmp3cfg to NAPOT with a read-modify-write on pmpcfg0 4. set pmp4cfg to NAPOT with a read-modify-write on pmpcfg1 When (2) is emulated, a call to pmp_update_rule() creates a negative range for pmp4 as pmp4cfg is still set to TOR. And when (3) is emulated, a call to tlb_flush() is performed, causing pmp_get_tlb_size() to return a very creatively large TLB size for pmp4. This, in turn, may result in accesses to non-existent/unitialized memory regions and a fault, so that (4) ends up never being executed. This is in m-mode with MPRV unset, meaning that unlocked PMP entries should have no effect. Therefore such a behavior based on PMP content is very unexpected. Make sure no negative PMP range can be created, whether explicitly by the emulated code or implicitly like the above. Signed-off-by: Nicolas Pitre Reviewed-by: Alistair Francis Message-Id: <3oq0sqs1-67o0-145-5n1s-453o118804q@syhkavp.arg> Signed-off-by: Alistair Francis --- target/riscv/pmp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 151da3fa08..ea2b67d947 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -167,6 +167,9 @@ void pmp_update_rule_addr(CPURISCVState *env, uint32_t = pmp_index) case PMP_AMATCH_TOR: sa =3D prev_addr << 2; /* shift up from [xx:0] to [xx+2:2] */ ea =3D (this_addr << 2) - 1u; + if (sa > ea) { + sa =3D ea =3D 0u; + } break; =20 case PMP_AMATCH_NA4: --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807635392550.2000445935595; Sat, 2 Jul 2022 17:20:35 -0700 (PDT) Received: from localhost ([::1]:35714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nLl-0004XT-5q for importer@patchew.org; Sat, 02 Jul 2022 20:20:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nES-0008Jg-T7 for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:01 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEN-0001p4-Mh for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:12:59 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:51 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:14 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:52 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XM5Rxvz1Rwnl for ; Sat, 2 Jul 2022 17:12:51 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Tx0earCs8J4U for ; Sat, 2 Jul 2022 17:12:51 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XK3f1Pz1RwqM; Sat, 2 Jul 2022 17:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807175; x=1688343175; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A6OJDw1BgSdFL4HZvjQWwfkC9yvCNCZ5EklbtsfpB4o=; b=gYmaoMJJZRGOc/d0ZXT7BSc3O9/XE2nd3OqGFDEyCuu10aEWBOMyBxLF UFNScDHK5cdm7YVr4vkbRPNmw9m7c36eNaD/xjS7xsYj9BBlrWvY4nw+n cqTi+BBnn/p1bJAkpGZQCSOyXSHtlcvgyv5hyiWXVDz8BwTb0pbWQf5dH aCHCZ06TxeUCfY6RCb40RkuHeYMwMaZ/olmQJDGa2eSn7CGiOxDCOKxS8 RbpqK9j2xI3TqNkn8thBn++1xzgmHL1r62p+2AvVxay6BkLb1ehfdynGc /QVriDXaJIoccJZhvbSpUavaDB5NCf+03735Ng8PGqnNLufl3Elud1A3f Q==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667233" IronPort-SDR: McqbzbRIBnER1GLh4vaC5kWeef09UfI6fz5khD57DMjVZ/hy9Ljt9KVqNas4o13NMOwLugFXaa CT0JNFDxJGyfeI8wJGjaUZZbLMZW4UaW0PtU8tH4ePdKahotPROp8ZO/C8GdBQ8BtDfX9E/w5y ag1kppV41mlxy8VN3eM2t1BlDZ/dul9UxjRAOVjVri5k5L78x2PFZGeV5rlVN8gDao6jMr9Mqg 0iXfg3+E2eWGhedDDru+UHoOt6kjVF52I8tY38U07aNmN/ptf2KPFS43e+GKTbyOI2+VdvdVMA gCv+K3cwp8tREm7fmxKSdcJL IronPort-SDR: zREevYZ1vIAq5ccd4dFbvlqPtqEI7Y6vthYXB08nlt67T4tni8Wiw4W6VYQjQ6e7nfm3fH17Yh QbqsD3qnjOVGtAKZ6h5eApHQLf+BOWsi766K1x+Wl9jDR6Yknn6FeX/olUZPuhqobFl5k2dIAp 6wyxIsOuqZyEeBVerGr5+ME17ijnI8K/7K50d5zRARbsuKwgMGEjWt3e5nrrPr+X1NejqdksRo zn3bf7hGKoSUFOilPADhhHrRMaZkX+Ugej/zf8pq2MVmSRSS1tYXQ6+B0CNf9QH1qY0qCi1+MG dOw= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807171; x=1659399172; bh=A6OJDw1BgSdFL4HZvj QWwfkC9yvCNCZ5EklbtsfpB4o=; b=JHsonAptu8AzkNQvJCCGyX8PYu9tnWm4Nq ILMvjO5t6LfRcQYvQ7M0Hk7bQLax3g2osnOODPZoqM5/9/LwSGj0D16TeNCxL7EC Ob2+ub6F80Vz4eA6QOtBO3rw04xY9t08KonDkS8VMPrqE6PrR2S0VeyCZIsJY+JK a8BsKBDW6z0TKT3relaMyjlvNP9ZVhw370gN9/GZJF7iBFmzkViLAphbkXXgeqtq 8Lzk1XKhvz6ZjFIpl897au1HdyU7o4HV5NuypNuPRHlbAsSbn20zbu8YsTMTkG2R wYdtwz87864+lWd8wozTxiuvqSPtdfhABYS2o2BYkxLwpxKx+Qwg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Atish Patra , Alistair Francis , Bin Meng , Atish Patra Subject: [PULL v2 06/19] target/riscv: Fix PMU CSR predicate function Date: Sun, 3 Jul 2022 10:12:21 +1000 Message-Id: <20220703001234.439716-7-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807635745100001 Content-Type: text/plain; charset="utf-8" From: Atish Patra The predicate function calculates the counter index incorrectly for hpmcounterx. Fix the counter index to reflect correct CSR number. Fixes: e39a8320b088 ("target/riscv: Support the Virtual Instruction fault") Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Signed-off-by: Atish Patra Signed-off-by: Atish Patra Message-Id: <20220620231603.2547260-2-atishp@rivosinc.com> Signed-off-by: Alistair Francis --- target/riscv/csr.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 6dbe9b541f..46bd417cc1 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -72,6 +72,7 @@ static RISCVException ctr(CPURISCVState *env, int csrno) #if !defined(CONFIG_USER_ONLY) CPUState *cs =3D env_cpu(env); RISCVCPU *cpu =3D RISCV_CPU(cs); + int ctr_index; =20 if (!cpu->cfg.ext_counters) { /* The Counters extensions is not enabled */ @@ -99,8 +100,9 @@ static RISCVException ctr(CPURISCVState *env, int csrno) } break; case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31: - if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNTER3)= ) && - get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTER3))= ) { + ctr_index =3D csrno - CSR_CYCLE; + if (!get_field(env->hcounteren, 1 << ctr_index) && + get_field(env->mcounteren, 1 << ctr_index)) { return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; @@ -126,8 +128,9 @@ static RISCVException ctr(CPURISCVState *env, int csrno) } break; case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H: - if (!get_field(env->hcounteren, 1 << (csrno - CSR_HPMCOUNT= ER3H)) && - get_field(env->mcounteren, 1 << (csrno - CSR_HPMCOUNTE= R3H))) { + ctr_index =3D csrno - CSR_CYCLEH; + if (!get_field(env->hcounteren, 1 << ctr_index) && + get_field(env->mcounteren, 1 << ctr_index)) { return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; } break; --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807937761266.2531742063362; Sat, 2 Jul 2022 17:25:37 -0700 (PDT) Received: from localhost ([::1]:50308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nQe-00066H-Lm for importer@patchew.org; Sat, 02 Jul 2022 20:25:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nES-0008Jh-TC for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:01 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46148) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEO-0001pG-IK for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:00 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:53 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:16 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:54 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XP6Z5Nz1RwqM for ; Sat, 2 Jul 2022 17:12:53 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id c0e2I7rkLC_q for ; Sat, 2 Jul 2022 17:12:53 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XM4Y75z1RtVk; Sat, 2 Jul 2022 17:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807176; x=1688343176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y/XwE9R9nGzJ5iezcVevZDhZ1loD3ydAxDj6a+PTtec=; b=Iy1RUPHPyVs9H7L6Y24TJXsWwtmM7XiXj8uC7GpZJLWaF/Choh6SKtk9 0JE3F01UoFRVMSnUZy8rvQOi6cAZ9qSFphBNrKmPr8Va7PoRN8pjeBjbd 8nfbXKm2gH0exJ+ifarzwT6TKYc/u/DLihthmyWpOJ4O5374Z8d6L1RM9 AY1pDQJ7tAuyfGuqITWHxBYDcplkzWg/YGUQDtUJJPnncYsvEjF9KGFSw prG0Ca82muHsrVuGKrtMrVqDgOb1PCXF/L9TESp2Qr5ntkshimLtcsPnx iXzxKIdGBZQXikmTR0RExIuIMnAcCfqXsRUblCSWVyIjVITINpsKnDlWp w==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667236" IronPort-SDR: dTJX9oquJ95whu0QO7kg3BLZJ2Dy7x+2hO6iWDXJLSuEvxKP1myS///WJItVvK73hzkluDVjE0 9eLUtj1vE0QHFy6ifBwDTZIFN6BATl0aEhLCL6QsS+VcnLpKkvfkk49Wsye6/uk+A0RhzyTj4l IbqJBatSGrIzNDT2rmzwjZuLT1DoeHQ/xpKNP+jWgn4Q/AHChthpa1nNO/c8hchhTcs01VgHua dO41IcJ44+y9dlsT9uMLpQAYICMfiaJ6SsENUW8by5IefsJ4q82G+BzEJXarEq6Q2anOXgEEFv XttEd/S0U+GzeY+NUOJW7HEZ IronPort-SDR: A4XfNxOQUijt1zkz2kvp70BFVNZUrfiA0Dkm0E3PsBkDDAd6/i3jjnQT/b766oft3GsXAssrux Ow2FSUgLFuItEb4cTk2gl7oN49p9Yzy0iJq9JuJ4T/PR8JrQAEZilETykY+mwU7Sp6NRTFy4Mm XnLSfJYuwLXDeJTSCZxNb6/xoHfGa1pz8pu8ExxWx5XX234unKD7kp84hKf7Su0VAOI3uVjZ/P Oa4XyaXtE6JfETOWKr7GrKOQqb2bf/Gz2ZuGtKqwxqv9lAASsEmErioZTzvO2+mRxj8ZoXS6fl pgA= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807173; x=1659399174; bh=Y/XwE9R9nGzJ5iezcV evZDhZ1loD3ydAxDj6a+PTtec=; b=JtkhjMu1nXVrSC7gRN8AJHt7bCzBBQCPla DjiMBQdKvqkjic+A8Sh2IpQFggc6dSEzPerjavbw/hCm+wdsP0JF6ALzFOt45aX0 OYzrKsyZy/a9AvHvFYXnTNlZteBAh6WdRMu6R6bkakk8NDyaR8o+zL66yDNNGJMX 4e+xs18VNPTlDbpU8rLV292rzlhIFLHVlmn6gaD/JcvEEO1PMlxHJc/OWSG8PhzJ wORbVC8MUJLo9vkUhfHt8fZB4+IDuAHGxt48SNHxt4wKkd+CQeiIplfeR97tzPMh QO2NQoVjwzmyqZhJ3lAkOjDK1fAY9JzjX+7DtVtRpqdai7yg0ISg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Atish Patra , Alistair Francis , Bin Meng , Atish Patra Subject: [PULL v2 07/19] target/riscv: Implement PMU CSR predicate function for S-mode Date: Sun, 3 Jul 2022 10:12:22 +1000 Message-Id: <20220703001234.439716-8-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807938892100001 Content-Type: text/plain; charset="utf-8" From: Atish Patra Currently, the predicate function for PMU related CSRs only works if virtualization is enabled. It also does not check mcounteren bits before before cycle/minstret/hpmcounterx access. Support supervisor mode access in the predicate function as well. Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Signed-off-by: Atish Patra Signed-off-by: Atish Patra Message-Id: <20220620231603.2547260-3-atishp@rivosinc.com> Signed-off-by: Alistair Francis --- target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 46bd417cc1..58d07c511f 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -79,6 +79,57 @@ static RISCVException ctr(CPURISCVState *env, int csrno) return RISCV_EXCP_ILLEGAL_INST; } =20 + if (env->priv =3D=3D PRV_S) { + switch (csrno) { + case CSR_CYCLE: + if (!get_field(env->mcounteren, COUNTEREN_CY)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_TIME: + if (!get_field(env->mcounteren, COUNTEREN_TM)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_INSTRET: + if (!get_field(env->mcounteren, COUNTEREN_IR)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_HPMCOUNTER3...CSR_HPMCOUNTER31: + ctr_index =3D csrno - CSR_CYCLE; + if (!get_field(env->mcounteren, 1 << ctr_index)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + } + if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + switch (csrno) { + case CSR_CYCLEH: + if (!get_field(env->mcounteren, COUNTEREN_CY)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_TIMEH: + if (!get_field(env->mcounteren, COUNTEREN_TM)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_INSTRETH: + if (!get_field(env->mcounteren, COUNTEREN_IR)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + case CSR_HPMCOUNTER3H...CSR_HPMCOUNTER31H: + ctr_index =3D csrno - CSR_CYCLEH; + if (!get_field(env->mcounteren, 1 << ctr_index)) { + return RISCV_EXCP_ILLEGAL_INST; + } + break; + } + } + } + if (riscv_cpu_virt_enabled(env)) { switch (csrno) { case CSR_CYCLE: --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807803938743.5607201034283; Sat, 2 Jul 2022 17:23:23 -0700 (PDT) Received: from localhost ([::1]:45724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nOU-0002zy-7S for importer@patchew.org; Sat, 02 Jul 2022 20:23:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEU-0008NF-3z for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:03 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEP-0001pZ-TQ for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:01 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:56 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:18 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:57 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XS3sLpz1Rwnl for ; Sat, 2 Jul 2022 17:12:56 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 8-YRti9nUvSb for ; Sat, 2 Jul 2022 17:12:55 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XP6XNYz1Rwnx; Sat, 2 Jul 2022 17:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807177; x=1688343177; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F7to0UWjjt5Pk0ojr+uQDLDz+6a/Avq+GVpGx/8qt7U=; b=PPnRF4vmPgulHmROOzwNGk64RgW4JaU8bs6DT0VRGSbqfeAu+RfXaYej hnF40QBSsTsY9qGWgniIcWmkewoYNpx7zeqrCNAen06qxU5xUpWnSqal/ HGrwQ3V7iKbnuPy+YlxKUn5Z9blGcMGcJbRegbct4NQbe+ytTPJds8exP 3SSIiOvmUTQQHKyzG+M7U2IFTy7jZdkvtd53+s1BhCf4dUHQQUJRq2yyB LRRjlzLvstnPys1RN+nmOLTMwHjg4XewHi/wS5cckZeNLwtBCsCaFUQiR 0yRfhuhwmCd74sqkktwuIMBKr3s9ICciXJVm9fuc9EGXOLcb5NsnAoUZJ w==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667239" IronPort-SDR: hH8HNqzfFmL9bb+XeK5k+4/czOljbBtk/H2d8u/SOsOYYXpkp0iGyHFwAzSAxi99tZDrNH6u68 HrtJNFGg37PHVO5pTPqLeop8eov0qEmo5x869swDudp2Jp/CaAlf5YgZrYa3RLMkAYI76R5r7y rSEVACvScDR7uXhuNHG5a1EoKCrPBAGFKPCbON27iLXd+Le5LRbQdNi+uTg+zJ1agb3LHATl1W 6dsaK0BMSnjoNvPhNNO0sjAVqOioRhl77WuIz5eshvfMYtRKUlZkJ8dvAs6MkJX5Ed0YTOsps7 jt65zoz+Myy3IdBWIkBQH0G2 IronPort-SDR: D+7MOoKiHprATPiOBJK8xoDVzbx9AUPJaQ+g2j4kQrZyBs2SBqdeegB1BjnGeYiJWs98qLfsvL lJk04+T+QlZD5+uQjc13nDu9+MOHOFvZRFO2ddwaSbX/P6TcEoLhRftQHQ8ER+9E5y/0Iq9niF U4Q8/Y/QIFMdwzMppIz4Ep7A8KWyPoLaG5J8gYZ8KphObe/VzJJGsv3oY4uCvIgO+QbyyhiCJb 8634pdmaaqrk1ogzzIeie4m6NexTMLmUuPayj4dcJc9cHgKRcE9bHbUN/1FAHtEbVFXBxTOlFs Yq0= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807175; x=1659399176; bh=F7to0UWjjt5Pk0ojr+ uQDLDz+6a/Avq+GVpGx/8qt7U=; b=Epl91g8KF2T4D8DzDUOvCVVAEnsoW0hbgp pw5YN1PrT8ZMmSsmnC5gPHcK81Lw19QpkLKY06BqKml5YrBueC3xLIKyDPunaaHH Pw7jvfcYK66gVzbBA9H5lqHLp9C7aSRLAcfQQfOLcPbBdOuxbmG0VEmeNOx+ViRD SduKhP5zQEyR4Yyk272buV1fft4ygXOoaNUOLj69S5mAFIh9wr6uWhZPFEfBQ7RH GTP5Sq1Q/f+fAtkqloZ6Cmrk8dmuv3DPXN+YZ91pKFo0IajjtsUaS6a7Jd71fs+X M19by4ZmY7O7uHg0EkC1bTlw9DbwTt0OwQ45PaLvdXfvd9CNGiGA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Atish Patra , Bin Meng , Alistair Francis , Atish Patra Subject: [PULL v2 08/19] target/riscv: pmu: Rename the counters extension to pmu Date: Sun, 3 Jul 2022 10:12:23 +1000 Message-Id: <20220703001234.439716-9-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807804381100001 Content-Type: text/plain; charset="utf-8" From: Atish Patra The PMU counters are supported via cpu config "Counters" which doesn't indicate the correct purpose of those counters. Rename the config property to pmu to indicate that these counters are performance monitoring counters. This aligns with cpu options for ARM architecture as well. Reviewed-by: Bin Meng Reviewed-by: Alistair Francis Signed-off-by: Atish Patra Signed-off-by: Atish Patra Message-Id: <20220620231603.2547260-4-atishp@rivosinc.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.h | 2 +- target/riscv/cpu.c | 4 ++-- target/riscv/csr.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7d6397acdf..252c30a55d 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -397,7 +397,7 @@ struct RISCVCPUConfig { bool ext_zksed; bool ext_zksh; bool ext_zkt; - bool ext_counters; + bool ext_pmu; bool ext_ifencei; bool ext_icsr; bool ext_svinval; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 05e6521351..1b57b3c439 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -851,7 +851,7 @@ static void riscv_cpu_init(Object *obj) { RISCVCPU *cpu =3D RISCV_CPU(obj); =20 - cpu->cfg.ext_counters =3D true; + cpu->cfg.ext_pmu =3D true; cpu->cfg.ext_ifencei =3D true; cpu->cfg.ext_icsr =3D true; cpu->cfg.mmu =3D true; @@ -879,7 +879,7 @@ static Property riscv_cpu_extensions[] =3D { DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true), DEFINE_PROP_BOOL("v", RISCVCPU, cfg.ext_v, false), DEFINE_PROP_BOOL("h", RISCVCPU, cfg.ext_h, true), - DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true), + DEFINE_PROP_BOOL("pmu", RISCVCPU, cfg.ext_pmu, true), DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false), diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 58d07c511f..0ca05c7788 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -74,8 +74,8 @@ static RISCVException ctr(CPURISCVState *env, int csrno) RISCVCPU *cpu =3D RISCV_CPU(cs); int ctr_index; =20 - if (!cpu->cfg.ext_counters) { - /* The Counters extensions is not enabled */ + if (!cpu->cfg.ext_pmu) { + /* The PMU extension is not enabled */ return RISCV_EXCP_ILLEGAL_INST; } =20 --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807772611836.8609465849763; Sat, 2 Jul 2022 17:22:52 -0700 (PDT) Received: from localhost ([::1]:43570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nNz-0001XP-2g for importer@patchew.org; Sat, 02 Jul 2022 20:22:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEX-0008Pv-En for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:06 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nET-0001p4-6w for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:05 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:12:58 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:21 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:12:59 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XW1VxGz1Rwnm for ; Sat, 2 Jul 2022 17:12:59 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id AzV0ictUfvTl for ; Sat, 2 Jul 2022 17:12:58 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XS3GrKz1RtVk; Sat, 2 Jul 2022 17:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807180; x=1688343180; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=APFVxoA4w+pXZxR4aPhchR0JJ0se4W7/l8p6DPel2nw=; b=OTURtUHjB5W9FOAw1bBHb+FcAqITPpphVCTAjPvIzVrp1qabP7dUjqQh IxWeC49PJQmkmiea/+RdzNC4rhnO9fRAX5pkn2DCJCeiH/ASBi/2gSEYy oi/8tUMU/Op6Qe9Tek1r521DPVHsZJg7NmXKosZjqZg9jzYpGDrcDHKge 4iJnJtl1sVKTdcZyAS5fTTSnILwYBLQl81WvDYR9B+QuBrDB2AlhyScgl QmdKMzUT1yHS77TrCq3CSsgEgqkY5H5bg0qtpKKUDAmjmkxIOvi4c+0bi XWEbJccq0+0gS/n3drcStsAgowMpOT3P88mHdeH3aDj2GI1eI/mlgwGWH g==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667240" IronPort-SDR: ReCIgM24OxwujA/3o+pnrBO4IXyBvpwU3F+vZ6+hwmDP9iypwMa6mUsSTrapqCeboNbxXtNB08 GNILPNHrCLEBnekm3ghhPKzEDKRbAHAJhIY4Ow5cy2qYfSzeSyh4aJj+GpE/k8PWVfA7eVqEs7 lh0L1eJA64RM5uPoaDo+QxAkaas7hAB0w6sUkfXj4oKifudKh+Vvi/OAaMz/vrGSzLHTngLFyl rKycvnlZrb3Peb2m2OLXam9Xww5pLSlLUicmXCaCKSIXLrcc0L2oC71Xij1IKFIEuzSar7fejy it896EAc0JC3KW3oYB1FKGsK IronPort-SDR: sUpUEl7ECVa5uGgOI4DoZBiniqTc5yRqPlIrNZKJ9Z/o6aq+nsmt3ztiU1naFreZrtbRMM8Eox 7nnycoCfpTGJzvu5WmIbLnYNjvwD5uZEsO2igTXjHQJC3JfGMU4f+W8HIDBmiDwuDkGEBUkzXf ktBfC67YKXkb8AQr/Jg7zIr1bjtND82Sl8Bt2b1IoZkPqoW184ZEwyfU08ZILDDtgfwhW9WruS Z3iW9Bp4SHWrcozKtBmPmIwFiZ0l4oDDXzEOFkLRiYgBAvHZi3VAOI8EDzhGuB+f6sC9MauB71 PB8= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807178; x=1659399179; bh=APFVxoA4w+pXZxR4aP hchR0JJ0se4W7/l8p6DPel2nw=; b=V11V1tos0++7ITowmek21aZhQnwJiQ+szd 6g8AfF7zoRCh5vWiE3nbz1+6hYRkTfW+nm2pKLTJY39+4RGQeS1uE+pkj6agk+2N j8NAQhTSoOfqdIr3amA3cornJMA/f+GeNvTIAVVv5w48u1RRXUEDmiZ97abgwNgt nIpm7RvDUYvpCEsicJorLJ8ZB12HighmrAXU6amquUXM40ZYsBSDrlxQYgRKiBJO Q3fCXNzszPq0bJFmyOxgKICadc/4ESR9FiK/Eq4Af8xM5z/qQqFyQCnGUETnImZy 1vnd8Pbo9+swFzYe5ViL8P9ff+kjaxLNb+d48rlkmMpw0oLBnkeA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Atish Patra , Bin Meng , Alistair Francis , Atish Patra Subject: [PULL v2 09/19] target/riscv: pmu: Make number of counters configurable Date: Sun, 3 Jul 2022 10:12:24 +1000 Message-Id: <20220703001234.439716-10-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807774479100001 Content-Type: text/plain; charset="utf-8" From: Atish Patra The RISC-V privilege specification provides flexibility to implement any number of counters from 29 programmable counters. However, the QEMU implements all the counters. Make it configurable through pmu config parameter which now will indicate how many programmable counters should be implemented by the cpu. Reviewed-by: Bin Meng Reviewed-by: Alistair Francis Signed-off-by: Atish Patra Signed-off-by: Atish Patra Message-Id: <20220620231603.2547260-5-atishp@rivosinc.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.h | 2 +- target/riscv/cpu.c | 3 +- target/riscv/csr.c | 94 ++++++++++++++++++++++++++++++---------------- 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 252c30a55d..ffee54ea5c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -397,7 +397,6 @@ struct RISCVCPUConfig { bool ext_zksed; bool ext_zksh; bool ext_zkt; - bool ext_pmu; bool ext_ifencei; bool ext_icsr; bool ext_svinval; @@ -421,6 +420,7 @@ struct RISCVCPUConfig { /* Vendor-specific custom extensions */ bool ext_XVentanaCondOps; =20 + uint8_t pmu_num; char *priv_spec; char *user_spec; char *bext_spec; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 1b57b3c439..d12c6dc630 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -851,7 +851,6 @@ static void riscv_cpu_init(Object *obj) { RISCVCPU *cpu =3D RISCV_CPU(obj); =20 - cpu->cfg.ext_pmu =3D true; cpu->cfg.ext_ifencei =3D true; cpu->cfg.ext_icsr =3D true; cpu->cfg.mmu =3D true; @@ -879,7 +878,7 @@ static Property riscv_cpu_extensions[] =3D { DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true), DEFINE_PROP_BOOL("v", RISCVCPU, cfg.ext_v, false), DEFINE_PROP_BOOL("h", RISCVCPU, cfg.ext_h, true), - DEFINE_PROP_BOOL("pmu", RISCVCPU, cfg.ext_pmu, true), + DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false), diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 0ca05c7788..b4a8e15f49 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -73,9 +73,17 @@ static RISCVException ctr(CPURISCVState *env, int csrno) CPUState *cs =3D env_cpu(env); RISCVCPU *cpu =3D RISCV_CPU(cs); int ctr_index; + int base_csrno =3D CSR_HPMCOUNTER3; + bool rv32 =3D riscv_cpu_mxl(env) =3D=3D MXL_RV32 ? true : false; =20 - if (!cpu->cfg.ext_pmu) { - /* The PMU extension is not enabled */ + if (rv32 && csrno >=3D CSR_CYCLEH) { + /* Offset for RV32 hpmcounternh counters */ + base_csrno +=3D 0x80; + } + ctr_index =3D csrno - base_csrno; + + if (!cpu->cfg.pmu_num || ctr_index >=3D (cpu->cfg.pmu_num)) { + /* No counter is enabled in PMU or the counter is out of range */ return RISCV_EXCP_ILLEGAL_INST; } =20 @@ -103,7 +111,7 @@ static RISCVException ctr(CPURISCVState *env, int csrno) } break; } - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + if (rv32) { switch (csrno) { case CSR_CYCLEH: if (!get_field(env->mcounteren, COUNTEREN_CY)) { @@ -158,7 +166,7 @@ static RISCVException ctr(CPURISCVState *env, int csrno) } break; } - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { + if (rv32) { switch (csrno) { case CSR_CYCLEH: if (!get_field(env->hcounteren, COUNTEREN_CY) && @@ -202,6 +210,26 @@ static RISCVException ctr32(CPURISCVState *env, int cs= rno) } =20 #if !defined(CONFIG_USER_ONLY) +static RISCVException mctr(CPURISCVState *env, int csrno) +{ + CPUState *cs =3D env_cpu(env); + RISCVCPU *cpu =3D RISCV_CPU(cs); + int ctr_index; + int base_csrno =3D CSR_MHPMCOUNTER3; + + if ((riscv_cpu_mxl(env) =3D=3D MXL_RV32) && csrno >=3D CSR_MCYCLEH) { + /* Offset for RV32 mhpmcounternh counters */ + base_csrno +=3D 0x80; + } + ctr_index =3D csrno - base_csrno; + if (!cpu->cfg.pmu_num || ctr_index >=3D cpu->cfg.pmu_num) { + /* The PMU is not enabled or counter is out of range*/ + return RISCV_EXCP_ILLEGAL_INST; + } + + return RISCV_EXCP_NONE; +} + static RISCVException any(CPURISCVState *env, int csrno) { return RISCV_EXCP_NONE; @@ -3687,35 +3715,35 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_HPMCOUNTER30] =3D { "hpmcounter30", ctr, read_zero }, [CSR_HPMCOUNTER31] =3D { "hpmcounter31", ctr, read_zero }, =20 - [CSR_MHPMCOUNTER3] =3D { "mhpmcounter3", any, read_zero }, - [CSR_MHPMCOUNTER4] =3D { "mhpmcounter4", any, read_zero }, - [CSR_MHPMCOUNTER5] =3D { "mhpmcounter5", any, read_zero }, - [CSR_MHPMCOUNTER6] =3D { "mhpmcounter6", any, read_zero }, - [CSR_MHPMCOUNTER7] =3D { "mhpmcounter7", any, read_zero }, - [CSR_MHPMCOUNTER8] =3D { "mhpmcounter8", any, read_zero }, - [CSR_MHPMCOUNTER9] =3D { "mhpmcounter9", any, read_zero }, - [CSR_MHPMCOUNTER10] =3D { "mhpmcounter10", any, read_zero }, - [CSR_MHPMCOUNTER11] =3D { "mhpmcounter11", any, read_zero }, - [CSR_MHPMCOUNTER12] =3D { "mhpmcounter12", any, read_zero }, - [CSR_MHPMCOUNTER13] =3D { "mhpmcounter13", any, read_zero }, - [CSR_MHPMCOUNTER14] =3D { "mhpmcounter14", any, read_zero }, - [CSR_MHPMCOUNTER15] =3D { "mhpmcounter15", any, read_zero }, - [CSR_MHPMCOUNTER16] =3D { "mhpmcounter16", any, read_zero }, - [CSR_MHPMCOUNTER17] =3D { "mhpmcounter17", any, read_zero }, - [CSR_MHPMCOUNTER18] =3D { "mhpmcounter18", any, read_zero }, - [CSR_MHPMCOUNTER19] =3D { "mhpmcounter19", any, read_zero }, - [CSR_MHPMCOUNTER20] =3D { "mhpmcounter20", any, read_zero }, - [CSR_MHPMCOUNTER21] =3D { "mhpmcounter21", any, read_zero }, - [CSR_MHPMCOUNTER22] =3D { "mhpmcounter22", any, read_zero }, - [CSR_MHPMCOUNTER23] =3D { "mhpmcounter23", any, read_zero }, - [CSR_MHPMCOUNTER24] =3D { "mhpmcounter24", any, read_zero }, - [CSR_MHPMCOUNTER25] =3D { "mhpmcounter25", any, read_zero }, - [CSR_MHPMCOUNTER26] =3D { "mhpmcounter26", any, read_zero }, - [CSR_MHPMCOUNTER27] =3D { "mhpmcounter27", any, read_zero }, - [CSR_MHPMCOUNTER28] =3D { "mhpmcounter28", any, read_zero }, - [CSR_MHPMCOUNTER29] =3D { "mhpmcounter29", any, read_zero }, - [CSR_MHPMCOUNTER30] =3D { "mhpmcounter30", any, read_zero }, - [CSR_MHPMCOUNTER31] =3D { "mhpmcounter31", any, read_zero }, + [CSR_MHPMCOUNTER3] =3D { "mhpmcounter3", mctr, read_zero }, + [CSR_MHPMCOUNTER4] =3D { "mhpmcounter4", mctr, read_zero }, + [CSR_MHPMCOUNTER5] =3D { "mhpmcounter5", mctr, read_zero }, + [CSR_MHPMCOUNTER6] =3D { "mhpmcounter6", mctr, read_zero }, + [CSR_MHPMCOUNTER7] =3D { "mhpmcounter7", mctr, read_zero }, + [CSR_MHPMCOUNTER8] =3D { "mhpmcounter8", mctr, read_zero }, + [CSR_MHPMCOUNTER9] =3D { "mhpmcounter9", mctr, read_zero }, + [CSR_MHPMCOUNTER10] =3D { "mhpmcounter10", mctr, read_zero }, + [CSR_MHPMCOUNTER11] =3D { "mhpmcounter11", mctr, read_zero }, + [CSR_MHPMCOUNTER12] =3D { "mhpmcounter12", mctr, read_zero }, + [CSR_MHPMCOUNTER13] =3D { "mhpmcounter13", mctr, read_zero }, + [CSR_MHPMCOUNTER14] =3D { "mhpmcounter14", mctr, read_zero }, + [CSR_MHPMCOUNTER15] =3D { "mhpmcounter15", mctr, read_zero }, + [CSR_MHPMCOUNTER16] =3D { "mhpmcounter16", mctr, read_zero }, + [CSR_MHPMCOUNTER17] =3D { "mhpmcounter17", mctr, read_zero }, + [CSR_MHPMCOUNTER18] =3D { "mhpmcounter18", mctr, read_zero }, + [CSR_MHPMCOUNTER19] =3D { "mhpmcounter19", mctr, read_zero }, + [CSR_MHPMCOUNTER20] =3D { "mhpmcounter20", mctr, read_zero }, + [CSR_MHPMCOUNTER21] =3D { "mhpmcounter21", mctr, read_zero }, + [CSR_MHPMCOUNTER22] =3D { "mhpmcounter22", mctr, read_zero }, + [CSR_MHPMCOUNTER23] =3D { "mhpmcounter23", mctr, read_zero }, + [CSR_MHPMCOUNTER24] =3D { "mhpmcounter24", mctr, read_zero }, + [CSR_MHPMCOUNTER25] =3D { "mhpmcounter25", mctr, read_zero }, + [CSR_MHPMCOUNTER26] =3D { "mhpmcounter26", mctr, read_zero }, + [CSR_MHPMCOUNTER27] =3D { "mhpmcounter27", mctr, read_zero }, + [CSR_MHPMCOUNTER28] =3D { "mhpmcounter28", mctr, read_zero }, + [CSR_MHPMCOUNTER29] =3D { "mhpmcounter29", mctr, read_zero }, + [CSR_MHPMCOUNTER30] =3D { "mhpmcounter30", mctr, read_zero }, + [CSR_MHPMCOUNTER31] =3D { "mhpmcounter31", mctr, read_zero }, =20 [CSR_MHPMEVENT3] =3D { "mhpmevent3", any, read_zero }, [CSR_MHPMEVENT4] =3D { "mhpmevent4", any, read_zero }, --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656808085759376.7059944419874; Sat, 2 Jul 2022 17:28:05 -0700 (PDT) Received: from localhost ([::1]:56022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nT2-0001kq-Ho for importer@patchew.org; Sat, 02 Jul 2022 20:28:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEZ-0008RT-Bc for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:08 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEV-0001zT-3p for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:07 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:00 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:23 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:01 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8XY363xz1Rwnl for ; Sat, 2 Jul 2022 17:13:01 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id es1un0nIQjuS for ; Sat, 2 Jul 2022 17:13:00 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XV4Ymvz1Rw4L; Sat, 2 Jul 2022 17:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807182; x=1688343182; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N99F1/5x4ohiaShjotG2aDGsbpXS1PNRRC2Rj68+zdg=; b=OfsVeQ+/t0S+HSxy7cbh38CvpPKb4VGXigZ7JfAeEE7mdITK7FjqWNuE MdLm78UmUnkQsgSxzXscERw+jZws6s6F2JGvN85O9ie0nS5IksiEgM7Vl NdORvxFfOf8v89jIPRCtdOeH+9RxeX7lcCALGZITvCQk4Y9SR758Zf4LX odEB8hqyycvfOmB1hSRncpH3DLcDfUS22AkMZ303Xf6RIxA4jeAJWQNIx HVKOPRsnmHFRgNM5xLKTXA7HoFWr4DCchtfuT6yc9M2qRMkbNdUopLvlc u1tf3z4N7VcWdY85O4tL04PkRAAhu/3twEHsqb70GpBZ4Opc3mZL/nNft w==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667241" IronPort-SDR: m6XVh0RZJJTAakAA2iiqwz8IUfikgY5ewjcnM3Z2C6tBylbAR1ATg8PcdNX0ZSVkCh1sSdELw8 1mIxMWQjZ1uTJiIASSaBZE1Xd88WLKkbbSB1bm8PONH1mnoeuYpCfz4oh0GP28Klnm3RPgwKQ/ 0JT0VTCYeeKZqImDRm6RKsG0ZcwHei5ONhTcEvICSUWgg7hR9m7jfsEUzaV819hhENdJBb9Vyy TF2EpKVDxn5kDYya5uwGqnDdro/feF6rAKDqyXCTVfyYiAVgCsCfesLxocfd5/Mth+tWEHAiuS Edl7ITkJcJy3TBD23Y+9NyAM IronPort-SDR: Y83OCL7WpkbY5oYWVrLwKhv4QAI2PfLGpSZ410de9v1OP1KN936I4Oc4xDEf63q7ZyNj+P9r7w Bg0HsjOmHeNsyq80+UK6XtsxgLj94YTXNKmxtASgCskDJ4Vc9vsCMsKdfHGzo1fSFejAIRzLSM 0wkQLDeV8p028uOL9tSKYnOeqZKFXON08RGVjfmO5omBFJheai67GPYfiFCeKrKXtexVi2cPCp N9p8AFEkl0oIcwY+pkWMixWi2V12RiXcQG07NNdQUZpfckEUnLWL2oh1iyjREmuBEG3+kaHlCg iVk= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807180; x=1659399181; bh=N99F1/5x4ohiaShjot G2aDGsbpXS1PNRRC2Rj68+zdg=; b=TbbeEi3Uzb/2PAM7RxW1b09BiTRDaFdLVr QJi4ImAsI2o4DQE0L453rPNaw5r8MbHtkc+5h4PbChpPrMD2f7lnNRujRoy8wsiR E+5tfiyXiVv7606+vfs8lt+eENpHvPSW7RTdHB5YPMmNXcNiRvUwBmJWC+YS2wqq jzA8sr8hbwnEcY132vqeb7isbpNOEzAIsZgvrdxDeo2V4sA/clya6UMdlLy9Jlxq kS4x9eiKz3cnXcPafjSxL2NX5iX45iXZuw+MlJHp18A2DFomY9tBfdKj4l2URrPO xQwHEQSfgC9TXdQ4OME9GGOZH24HDtwkvExoz32QFtdNyIDxH5fg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Atish Patra , Bin Meng , Alistair Francis , Atish Patra Subject: [PULL v2 10/19] target/riscv: Implement mcountinhibit CSR Date: Sun, 3 Jul 2022 10:12:25 +1000 Message-Id: <20220703001234.439716-11-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656808087504100001 Content-Type: text/plain; charset="utf-8" From: Atish Patra As per the privilege specification v1.11, mcountinhibit allows to start/stop a pmu counter selectively. Reviewed-by: Bin Meng Reviewed-by: Alistair Francis Signed-off-by: Atish Patra Signed-off-by: Atish Patra Message-Id: <20220620231603.2547260-6-atishp@rivosinc.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.h | 2 ++ target/riscv/cpu_bits.h | 4 ++++ target/riscv/csr.c | 25 +++++++++++++++++++++++++ target/riscv/machine.c | 1 + 4 files changed, 32 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ffee54ea5c..0a916db9f6 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -275,6 +275,8 @@ struct CPUArchState { target_ulong scounteren; target_ulong mcounteren; =20 + target_ulong mcountinhibit; + target_ulong sscratch; target_ulong mscratch; =20 diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 4d04b20d06..b3f7fa7130 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -367,6 +367,10 @@ #define CSR_MHPMCOUNTER29 0xb1d #define CSR_MHPMCOUNTER30 0xb1e #define CSR_MHPMCOUNTER31 0xb1f + +/* Machine counter-inhibit register */ +#define CSR_MCOUNTINHIBIT 0x320 + #define CSR_MHPMEVENT3 0x323 #define CSR_MHPMEVENT4 0x324 #define CSR_MHPMEVENT5 0x325 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index b4a8e15f49..94d39a4ce1 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1475,6 +1475,28 @@ static RISCVException write_mtvec(CPURISCVState *env= , int csrno, return RISCV_EXCP_NONE; } =20 +static RISCVException read_mcountinhibit(CPURISCVState *env, int csrno, + target_ulong *val) +{ + if (env->priv_ver < PRIV_VERSION_1_11_0) { + return RISCV_EXCP_ILLEGAL_INST; + } + + *val =3D env->mcountinhibit; + return RISCV_EXCP_NONE; +} + +static RISCVException write_mcountinhibit(CPURISCVState *env, int csrno, + target_ulong val) +{ + if (env->priv_ver < PRIV_VERSION_1_11_0) { + return RISCV_EXCP_ILLEGAL_INST; + } + + env->mcountinhibit =3D val; + return RISCV_EXCP_NONE; +} + static RISCVException read_mcounteren(CPURISCVState *env, int csrno, target_ulong *val) { @@ -3745,6 +3767,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MHPMCOUNTER30] =3D { "mhpmcounter30", mctr, read_zero }, [CSR_MHPMCOUNTER31] =3D { "mhpmcounter31", mctr, read_zero }, =20 + [CSR_MCOUNTINHIBIT] =3D { "mcountinhibit", any, read_mcountinhib= it, + write_mcountinhibit= }, + [CSR_MHPMEVENT3] =3D { "mhpmevent3", any, read_zero }, [CSR_MHPMEVENT4] =3D { "mhpmevent4", any, read_zero }, [CSR_MHPMEVENT5] =3D { "mhpmevent5", any, read_zero }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 2a437b29a1..87cd55bfd3 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -330,6 +330,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINTTL(env.siselect, RISCVCPU), VMSTATE_UINTTL(env.scounteren, RISCVCPU), VMSTATE_UINTTL(env.mcounteren, RISCVCPU), + VMSTATE_UINTTL(env.mcountinhibit, RISCVCPU), VMSTATE_UINTTL(env.sscratch, RISCVCPU), VMSTATE_UINTTL(env.mscratch, RISCVCPU), VMSTATE_UINT64(env.mfromhost, RISCVCPU), --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807926792494.4074644114497; Sat, 2 Jul 2022 17:25:26 -0700 (PDT) Received: from localhost ([::1]:49778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nQT-0005ju-Li for importer@patchew.org; Sat, 02 Jul 2022 20:25:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEd-0008TT-EM for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:12 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEY-0001p4-TW for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:11 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:05 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:28 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:06 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xd53nFz1Rwry for ; Sat, 2 Jul 2022 17:13:05 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id YXO4n641bq7A for ; Sat, 2 Jul 2022 17:13:03 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8XY2Z9lz1RtVk; Sat, 2 Jul 2022 17:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807186; x=1688343186; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LTM4nMae17Wywtl/G8GO4vUfELZqfaNA4hU9688v3y8=; b=iW8ZkNA0nCjOdpoFqnjS8148hPEttWMdtPMSmVyLPFAI1lZFu/TOCH+e 9lcl74qGNay44UU8JcerijfEkRkUtQP5DS78VkGSBT79GHh7B5XbWFdGA sjY0M7YV4eWnfnsBXWhWQdmBbVr1kjG0YrC2EW9y6UPoxFXl+cn57nYRr nKxBBtO7Sie62GxaBgQK+6S/jFiuZtPA8FyaAbN+m3Fn/XMMR2V4NlffC F2mSMO2+BATi7FYyOgj8RlZKMFuB19brzyyxzgFQ4d2QYBgFTA4o/5MZo QeIZboi7cFamGjenS/EJzFpXg8N9FzvnHlamOCMPCGNqnYcANvXkzTTDK A==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667247" IronPort-SDR: gA6jY2rOet84leSFpR3kNxGlH5C6pt7MAR7fTP8e2dyj3kBD3mZEelhjw1Et6hwDidrI7ulspc uBzQWBqJ7KqzRfluD0j0e2dbjcODhumuiPZvHaHfTEZtFzwk/45boT21gHWkQwIEVDhB/M13Li fNWBTzFEEf7WuD0J4kK8vjSjRHs/qwuNuQJfFTtlWthH6eyzZgJJNdaBMHVlYj+NAqcMOsPO7D DTgeeikHAuOMaGedyupBHy+q7NkBMO7MNHQDw0jVFu2q/D01fuD56JFKs8vJ911nYnzvMULGy4 Y/3yvYUWN5wtp0NLqLTMNjCh IronPort-SDR: AchhTUDkkk3HFZJvRCWZRmAWWagNZ0EdrnCaNW2L7twXiBCVM0KlpKv3IszjxRC63DXs/ziL3r lXfx8xOWeS3BShsoM55ZgjoNGdHa7h/PvVMs1uFFmjgdHsZMpVtOur3xeNyMHhp/v2hSOuRz+m isoSK5I97sralzzWaby+qe4M6lvSwGS6dAOynaXKAPo8UizHE+bf5oJbsOuxFUI/eSXwHkThjH eWihFV+qY1DeM24oV3ISgSRbcTwl4MBJ/LU1ARyNIOCA2Sqj9auEhel8VdH0YUAaxa7BJ/x8Jz Qeo= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807183; x=1659399184; bh=LTM4nMae17Wywtl/G8 GO4vUfELZqfaNA4hU9688v3y8=; b=Xk5RTjsQST1Bm4QD9T0Tzsl4+P54uXuBwe AhlRHYEC7EZ03pRPlljOcpQoijlGPK2n4xemOvgBRjWmiWIIUsZ5/EVrDx38qs4j sXRpvDgZl/vVZ+l5Fl63M687yNKeSc+gy4VEI9ozTofdSeAE3jHdOWGUxUebkCH9 Tad0lznzZ/sCPwWqZeTHFSXT7jPacKhh1fXW3NQw4+SAywoOjA9ZjC4uaADWrTwG sIa3sEUpYFBcPTQgukcNii+1YVS/DqYsctuPwdZY/rkvwODnd1gEe+XrYlnvxnt9 SjOIuCLaOND0i+utVuXzwmfigwkJfLzrjVlmCGxsKx95tn3Wm+MQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Atish Patra , Alistair Francis , Bin Meng , Atish Patra Subject: [PULL v2 11/19] target/riscv: Add support for hpmcounters/hpmevents Date: Sun, 3 Jul 2022 10:12:26 +1000 Message-Id: <20220703001234.439716-12-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807928895100001 Content-Type: text/plain; charset="utf-8" From: Atish Patra With SBI PMU extension, user can use any of the available hpmcounters to track any perf events based on the value written to mhpmevent csr. Add read/write functionality for these csrs. Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Signed-off-by: Atish Patra Signed-off-by: Atish Patra Message-Id: <20220620231603.2547260-7-atishp@rivosinc.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.h | 11 + target/riscv/csr.c | 469 ++++++++++++++++++++++++++++------------- target/riscv/machine.c | 3 + 3 files changed, 331 insertions(+), 152 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0a916db9f6..199d0d570b 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -117,6 +117,8 @@ typedef struct CPUArchState CPURISCVState; #endif =20 #define RV_VLEN_MAX 1024 +#define RV_MAX_MHPMEVENTS 29 +#define RV_MAX_MHPMCOUNTERS 32 =20 FIELD(VTYPE, VLMUL, 0, 3) FIELD(VTYPE, VSEW, 3, 3) @@ -277,6 +279,15 @@ struct CPUArchState { =20 target_ulong mcountinhibit; =20 + /* PMU counter configured values */ + target_ulong mhpmcounter_val[RV_MAX_MHPMCOUNTERS]; + + /* for RV32 */ + target_ulong mhpmcounterh_val[RV_MAX_MHPMCOUNTERS]; + + /* PMU event selector configured values */ + target_ulong mhpmevent_val[RV_MAX_MHPMEVENTS]; + target_ulong sscratch; target_ulong mscratch; =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 94d39a4ce1..b931a3970e 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -230,6 +230,15 @@ static RISCVException mctr(CPURISCVState *env, int csr= no) return RISCV_EXCP_NONE; } =20 +static RISCVException mctr32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) !=3D MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return mctr(env, csrno); +} + static RISCVException any(CPURISCVState *env, int csrno) { return RISCV_EXCP_NONE; @@ -635,6 +644,75 @@ static RISCVException read_timeh(CPURISCVState *env, i= nt csrno, =20 #else /* CONFIG_USER_ONLY */ =20 +static int read_mhpmevent(CPURISCVState *env, int csrno, target_ulong *val) +{ + int evt_index =3D csrno - CSR_MHPMEVENT3; + + *val =3D env->mhpmevent_val[evt_index]; + + return RISCV_EXCP_NONE; +} + +static int write_mhpmevent(CPURISCVState *env, int csrno, target_ulong val) +{ + int evt_index =3D csrno - CSR_MHPMEVENT3; + + env->mhpmevent_val[evt_index] =3D val; + + return RISCV_EXCP_NONE; +} + +static int write_mhpmcounter(CPURISCVState *env, int csrno, target_ulong v= al) +{ + int ctr_index =3D csrno - CSR_MHPMCOUNTER3 + 3; + + env->mhpmcounter_val[ctr_index] =3D val; + + return RISCV_EXCP_NONE; +} + +static int write_mhpmcounterh(CPURISCVState *env, int csrno, target_ulong = val) +{ + int ctr_index =3D csrno - CSR_MHPMCOUNTER3H + 3; + + env->mhpmcounterh_val[ctr_index] =3D val; + + return RISCV_EXCP_NONE; +} + +static int read_hpmcounter(CPURISCVState *env, int csrno, target_ulong *va= l) +{ + int ctr_index; + + if (csrno >=3D CSR_MCYCLE && csrno <=3D CSR_MHPMCOUNTER31) { + ctr_index =3D csrno - CSR_MHPMCOUNTER3 + 3; + } else if (csrno >=3D CSR_CYCLE && csrno <=3D CSR_HPMCOUNTER31) { + ctr_index =3D csrno - CSR_HPMCOUNTER3 + 3; + } else { + return RISCV_EXCP_ILLEGAL_INST; + } + *val =3D env->mhpmcounter_val[ctr_index]; + + return RISCV_EXCP_NONE; +} + +static int read_hpmcounterh(CPURISCVState *env, int csrno, target_ulong *v= al) +{ + int ctr_index; + + if (csrno >=3D CSR_MCYCLEH && csrno <=3D CSR_MHPMCOUNTER31H) { + ctr_index =3D csrno - CSR_MHPMCOUNTER3H + 3; + } else if (csrno >=3D CSR_CYCLEH && csrno <=3D CSR_HPMCOUNTER31H) { + ctr_index =3D csrno - CSR_HPMCOUNTER3H + 3; + } else { + return RISCV_EXCP_ILLEGAL_INST; + } + *val =3D env->mhpmcounterh_val[ctr_index]; + + return RISCV_EXCP_NONE; +} + + static RISCVException read_time(CPURISCVState *env, int csrno, target_ulong *val) { @@ -3707,157 +3785,244 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_SPMBASE] =3D { "spmbase", pointer_masking, read_spmbase, write= _spmbase }, =20 /* Performance Counters */ - [CSR_HPMCOUNTER3] =3D { "hpmcounter3", ctr, read_zero }, - [CSR_HPMCOUNTER4] =3D { "hpmcounter4", ctr, read_zero }, - [CSR_HPMCOUNTER5] =3D { "hpmcounter5", ctr, read_zero }, - [CSR_HPMCOUNTER6] =3D { "hpmcounter6", ctr, read_zero }, - [CSR_HPMCOUNTER7] =3D { "hpmcounter7", ctr, read_zero }, - [CSR_HPMCOUNTER8] =3D { "hpmcounter8", ctr, read_zero }, - [CSR_HPMCOUNTER9] =3D { "hpmcounter9", ctr, read_zero }, - [CSR_HPMCOUNTER10] =3D { "hpmcounter10", ctr, read_zero }, - [CSR_HPMCOUNTER11] =3D { "hpmcounter11", ctr, read_zero }, - [CSR_HPMCOUNTER12] =3D { "hpmcounter12", ctr, read_zero }, - [CSR_HPMCOUNTER13] =3D { "hpmcounter13", ctr, read_zero }, - [CSR_HPMCOUNTER14] =3D { "hpmcounter14", ctr, read_zero }, - [CSR_HPMCOUNTER15] =3D { "hpmcounter15", ctr, read_zero }, - [CSR_HPMCOUNTER16] =3D { "hpmcounter16", ctr, read_zero }, - [CSR_HPMCOUNTER17] =3D { "hpmcounter17", ctr, read_zero }, - [CSR_HPMCOUNTER18] =3D { "hpmcounter18", ctr, read_zero }, - [CSR_HPMCOUNTER19] =3D { "hpmcounter19", ctr, read_zero }, - [CSR_HPMCOUNTER20] =3D { "hpmcounter20", ctr, read_zero }, - [CSR_HPMCOUNTER21] =3D { "hpmcounter21", ctr, read_zero }, - [CSR_HPMCOUNTER22] =3D { "hpmcounter22", ctr, read_zero }, - [CSR_HPMCOUNTER23] =3D { "hpmcounter23", ctr, read_zero }, - [CSR_HPMCOUNTER24] =3D { "hpmcounter24", ctr, read_zero }, - [CSR_HPMCOUNTER25] =3D { "hpmcounter25", ctr, read_zero }, - [CSR_HPMCOUNTER26] =3D { "hpmcounter26", ctr, read_zero }, - [CSR_HPMCOUNTER27] =3D { "hpmcounter27", ctr, read_zero }, - [CSR_HPMCOUNTER28] =3D { "hpmcounter28", ctr, read_zero }, - [CSR_HPMCOUNTER29] =3D { "hpmcounter29", ctr, read_zero }, - [CSR_HPMCOUNTER30] =3D { "hpmcounter30", ctr, read_zero }, - [CSR_HPMCOUNTER31] =3D { "hpmcounter31", ctr, read_zero }, - - [CSR_MHPMCOUNTER3] =3D { "mhpmcounter3", mctr, read_zero }, - [CSR_MHPMCOUNTER4] =3D { "mhpmcounter4", mctr, read_zero }, - [CSR_MHPMCOUNTER5] =3D { "mhpmcounter5", mctr, read_zero }, - [CSR_MHPMCOUNTER6] =3D { "mhpmcounter6", mctr, read_zero }, - [CSR_MHPMCOUNTER7] =3D { "mhpmcounter7", mctr, read_zero }, - [CSR_MHPMCOUNTER8] =3D { "mhpmcounter8", mctr, read_zero }, - [CSR_MHPMCOUNTER9] =3D { "mhpmcounter9", mctr, read_zero }, - [CSR_MHPMCOUNTER10] =3D { "mhpmcounter10", mctr, read_zero }, - [CSR_MHPMCOUNTER11] =3D { "mhpmcounter11", mctr, read_zero }, - [CSR_MHPMCOUNTER12] =3D { "mhpmcounter12", mctr, read_zero }, - [CSR_MHPMCOUNTER13] =3D { "mhpmcounter13", mctr, read_zero }, - [CSR_MHPMCOUNTER14] =3D { "mhpmcounter14", mctr, read_zero }, - [CSR_MHPMCOUNTER15] =3D { "mhpmcounter15", mctr, read_zero }, - [CSR_MHPMCOUNTER16] =3D { "mhpmcounter16", mctr, read_zero }, - [CSR_MHPMCOUNTER17] =3D { "mhpmcounter17", mctr, read_zero }, - [CSR_MHPMCOUNTER18] =3D { "mhpmcounter18", mctr, read_zero }, - [CSR_MHPMCOUNTER19] =3D { "mhpmcounter19", mctr, read_zero }, - [CSR_MHPMCOUNTER20] =3D { "mhpmcounter20", mctr, read_zero }, - [CSR_MHPMCOUNTER21] =3D { "mhpmcounter21", mctr, read_zero }, - [CSR_MHPMCOUNTER22] =3D { "mhpmcounter22", mctr, read_zero }, - [CSR_MHPMCOUNTER23] =3D { "mhpmcounter23", mctr, read_zero }, - [CSR_MHPMCOUNTER24] =3D { "mhpmcounter24", mctr, read_zero }, - [CSR_MHPMCOUNTER25] =3D { "mhpmcounter25", mctr, read_zero }, - [CSR_MHPMCOUNTER26] =3D { "mhpmcounter26", mctr, read_zero }, - [CSR_MHPMCOUNTER27] =3D { "mhpmcounter27", mctr, read_zero }, - [CSR_MHPMCOUNTER28] =3D { "mhpmcounter28", mctr, read_zero }, - [CSR_MHPMCOUNTER29] =3D { "mhpmcounter29", mctr, read_zero }, - [CSR_MHPMCOUNTER30] =3D { "mhpmcounter30", mctr, read_zero }, - [CSR_MHPMCOUNTER31] =3D { "mhpmcounter31", mctr, read_zero }, - - [CSR_MCOUNTINHIBIT] =3D { "mcountinhibit", any, read_mcountinhib= it, - write_mcountinhibit= }, - - [CSR_MHPMEVENT3] =3D { "mhpmevent3", any, read_zero }, - [CSR_MHPMEVENT4] =3D { "mhpmevent4", any, read_zero }, - [CSR_MHPMEVENT5] =3D { "mhpmevent5", any, read_zero }, - [CSR_MHPMEVENT6] =3D { "mhpmevent6", any, read_zero }, - [CSR_MHPMEVENT7] =3D { "mhpmevent7", any, read_zero }, - [CSR_MHPMEVENT8] =3D { "mhpmevent8", any, read_zero }, - [CSR_MHPMEVENT9] =3D { "mhpmevent9", any, read_zero }, - [CSR_MHPMEVENT10] =3D { "mhpmevent10", any, read_zero }, - [CSR_MHPMEVENT11] =3D { "mhpmevent11", any, read_zero }, - [CSR_MHPMEVENT12] =3D { "mhpmevent12", any, read_zero }, - [CSR_MHPMEVENT13] =3D { "mhpmevent13", any, read_zero }, - [CSR_MHPMEVENT14] =3D { "mhpmevent14", any, read_zero }, - [CSR_MHPMEVENT15] =3D { "mhpmevent15", any, read_zero }, - [CSR_MHPMEVENT16] =3D { "mhpmevent16", any, read_zero }, - [CSR_MHPMEVENT17] =3D { "mhpmevent17", any, read_zero }, - [CSR_MHPMEVENT18] =3D { "mhpmevent18", any, read_zero }, - [CSR_MHPMEVENT19] =3D { "mhpmevent19", any, read_zero }, - [CSR_MHPMEVENT20] =3D { "mhpmevent20", any, read_zero }, - [CSR_MHPMEVENT21] =3D { "mhpmevent21", any, read_zero }, - [CSR_MHPMEVENT22] =3D { "mhpmevent22", any, read_zero }, - [CSR_MHPMEVENT23] =3D { "mhpmevent23", any, read_zero }, - [CSR_MHPMEVENT24] =3D { "mhpmevent24", any, read_zero }, - [CSR_MHPMEVENT25] =3D { "mhpmevent25", any, read_zero }, - [CSR_MHPMEVENT26] =3D { "mhpmevent26", any, read_zero }, - [CSR_MHPMEVENT27] =3D { "mhpmevent27", any, read_zero }, - [CSR_MHPMEVENT28] =3D { "mhpmevent28", any, read_zero }, - [CSR_MHPMEVENT29] =3D { "mhpmevent29", any, read_zero }, - [CSR_MHPMEVENT30] =3D { "mhpmevent30", any, read_zero }, - [CSR_MHPMEVENT31] =3D { "mhpmevent31", any, read_zero }, - - [CSR_HPMCOUNTER3H] =3D { "hpmcounter3h", ctr32, read_zero }, - [CSR_HPMCOUNTER4H] =3D { "hpmcounter4h", ctr32, read_zero }, - [CSR_HPMCOUNTER5H] =3D { "hpmcounter5h", ctr32, read_zero }, - [CSR_HPMCOUNTER6H] =3D { "hpmcounter6h", ctr32, read_zero }, - [CSR_HPMCOUNTER7H] =3D { "hpmcounter7h", ctr32, read_zero }, - [CSR_HPMCOUNTER8H] =3D { "hpmcounter8h", ctr32, read_zero }, - [CSR_HPMCOUNTER9H] =3D { "hpmcounter9h", ctr32, read_zero }, - [CSR_HPMCOUNTER10H] =3D { "hpmcounter10h", ctr32, read_zero }, - [CSR_HPMCOUNTER11H] =3D { "hpmcounter11h", ctr32, read_zero }, - [CSR_HPMCOUNTER12H] =3D { "hpmcounter12h", ctr32, read_zero }, - [CSR_HPMCOUNTER13H] =3D { "hpmcounter13h", ctr32, read_zero }, - [CSR_HPMCOUNTER14H] =3D { "hpmcounter14h", ctr32, read_zero }, - [CSR_HPMCOUNTER15H] =3D { "hpmcounter15h", ctr32, read_zero }, - [CSR_HPMCOUNTER16H] =3D { "hpmcounter16h", ctr32, read_zero }, - [CSR_HPMCOUNTER17H] =3D { "hpmcounter17h", ctr32, read_zero }, - [CSR_HPMCOUNTER18H] =3D { "hpmcounter18h", ctr32, read_zero }, - [CSR_HPMCOUNTER19H] =3D { "hpmcounter19h", ctr32, read_zero }, - [CSR_HPMCOUNTER20H] =3D { "hpmcounter20h", ctr32, read_zero }, - [CSR_HPMCOUNTER21H] =3D { "hpmcounter21h", ctr32, read_zero }, - [CSR_HPMCOUNTER22H] =3D { "hpmcounter22h", ctr32, read_zero }, - [CSR_HPMCOUNTER23H] =3D { "hpmcounter23h", ctr32, read_zero }, - [CSR_HPMCOUNTER24H] =3D { "hpmcounter24h", ctr32, read_zero }, - [CSR_HPMCOUNTER25H] =3D { "hpmcounter25h", ctr32, read_zero }, - [CSR_HPMCOUNTER26H] =3D { "hpmcounter26h", ctr32, read_zero }, - [CSR_HPMCOUNTER27H] =3D { "hpmcounter27h", ctr32, read_zero }, - [CSR_HPMCOUNTER28H] =3D { "hpmcounter28h", ctr32, read_zero }, - [CSR_HPMCOUNTER29H] =3D { "hpmcounter29h", ctr32, read_zero }, - [CSR_HPMCOUNTER30H] =3D { "hpmcounter30h", ctr32, read_zero }, - [CSR_HPMCOUNTER31H] =3D { "hpmcounter31h", ctr32, read_zero }, - - [CSR_MHPMCOUNTER3H] =3D { "mhpmcounter3h", any32, read_zero }, - [CSR_MHPMCOUNTER4H] =3D { "mhpmcounter4h", any32, read_zero }, - [CSR_MHPMCOUNTER5H] =3D { "mhpmcounter5h", any32, read_zero }, - [CSR_MHPMCOUNTER6H] =3D { "mhpmcounter6h", any32, read_zero }, - [CSR_MHPMCOUNTER7H] =3D { "mhpmcounter7h", any32, read_zero }, - [CSR_MHPMCOUNTER8H] =3D { "mhpmcounter8h", any32, read_zero }, - [CSR_MHPMCOUNTER9H] =3D { "mhpmcounter9h", any32, read_zero }, - [CSR_MHPMCOUNTER10H] =3D { "mhpmcounter10h", any32, read_zero }, - [CSR_MHPMCOUNTER11H] =3D { "mhpmcounter11h", any32, read_zero }, - [CSR_MHPMCOUNTER12H] =3D { "mhpmcounter12h", any32, read_zero }, - [CSR_MHPMCOUNTER13H] =3D { "mhpmcounter13h", any32, read_zero }, - [CSR_MHPMCOUNTER14H] =3D { "mhpmcounter14h", any32, read_zero }, - [CSR_MHPMCOUNTER15H] =3D { "mhpmcounter15h", any32, read_zero }, - [CSR_MHPMCOUNTER16H] =3D { "mhpmcounter16h", any32, read_zero }, - [CSR_MHPMCOUNTER17H] =3D { "mhpmcounter17h", any32, read_zero }, - [CSR_MHPMCOUNTER18H] =3D { "mhpmcounter18h", any32, read_zero }, - [CSR_MHPMCOUNTER19H] =3D { "mhpmcounter19h", any32, read_zero }, - [CSR_MHPMCOUNTER20H] =3D { "mhpmcounter20h", any32, read_zero }, - [CSR_MHPMCOUNTER21H] =3D { "mhpmcounter21h", any32, read_zero }, - [CSR_MHPMCOUNTER22H] =3D { "mhpmcounter22h", any32, read_zero }, - [CSR_MHPMCOUNTER23H] =3D { "mhpmcounter23h", any32, read_zero }, - [CSR_MHPMCOUNTER24H] =3D { "mhpmcounter24h", any32, read_zero }, - [CSR_MHPMCOUNTER25H] =3D { "mhpmcounter25h", any32, read_zero }, - [CSR_MHPMCOUNTER26H] =3D { "mhpmcounter26h", any32, read_zero }, - [CSR_MHPMCOUNTER27H] =3D { "mhpmcounter27h", any32, read_zero }, - [CSR_MHPMCOUNTER28H] =3D { "mhpmcounter28h", any32, read_zero }, - [CSR_MHPMCOUNTER29H] =3D { "mhpmcounter29h", any32, read_zero }, - [CSR_MHPMCOUNTER30H] =3D { "mhpmcounter30h", any32, read_zero }, - [CSR_MHPMCOUNTER31H] =3D { "mhpmcounter31h", any32, read_zero }, + [CSR_HPMCOUNTER3] =3D { "hpmcounter3", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER4] =3D { "hpmcounter4", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER5] =3D { "hpmcounter5", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER6] =3D { "hpmcounter6", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER7] =3D { "hpmcounter7", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER8] =3D { "hpmcounter8", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER9] =3D { "hpmcounter9", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER10] =3D { "hpmcounter10", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER11] =3D { "hpmcounter11", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER12] =3D { "hpmcounter12", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER13] =3D { "hpmcounter13", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER14] =3D { "hpmcounter14", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER15] =3D { "hpmcounter15", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER16] =3D { "hpmcounter16", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER17] =3D { "hpmcounter17", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER18] =3D { "hpmcounter18", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER19] =3D { "hpmcounter19", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER20] =3D { "hpmcounter20", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER21] =3D { "hpmcounter21", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER22] =3D { "hpmcounter22", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER23] =3D { "hpmcounter23", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER24] =3D { "hpmcounter24", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER25] =3D { "hpmcounter25", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER26] =3D { "hpmcounter26", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER27] =3D { "hpmcounter27", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER28] =3D { "hpmcounter28", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER29] =3D { "hpmcounter29", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER30] =3D { "hpmcounter30", ctr, read_hpmcounter }, + [CSR_HPMCOUNTER31] =3D { "hpmcounter31", ctr, read_hpmcounter }, + + [CSR_MHPMCOUNTER3] =3D { "mhpmcounter3", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER4] =3D { "mhpmcounter4", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER5] =3D { "mhpmcounter5", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER6] =3D { "mhpmcounter6", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER7] =3D { "mhpmcounter7", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER8] =3D { "mhpmcounter8", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER9] =3D { "mhpmcounter9", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER10] =3D { "mhpmcounter10", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER11] =3D { "mhpmcounter11", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER12] =3D { "mhpmcounter12", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER13] =3D { "mhpmcounter13", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER14] =3D { "mhpmcounter14", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER15] =3D { "mhpmcounter15", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER16] =3D { "mhpmcounter16", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER17] =3D { "mhpmcounter17", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER18] =3D { "mhpmcounter18", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER19] =3D { "mhpmcounter19", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER20] =3D { "mhpmcounter20", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER21] =3D { "mhpmcounter21", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER22] =3D { "mhpmcounter22", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER23] =3D { "mhpmcounter23", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER24] =3D { "mhpmcounter24", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER25] =3D { "mhpmcounter25", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER26] =3D { "mhpmcounter26", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER27] =3D { "mhpmcounter27", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER28] =3D { "mhpmcounter28", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER29] =3D { "mhpmcounter29", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER30] =3D { "mhpmcounter30", mctr, read_hpmcounter, + write_mhpmcounter }, + [CSR_MHPMCOUNTER31] =3D { "mhpmcounter31", mctr, read_hpmcounter, + write_mhpmcounter }, + + [CSR_MCOUNTINHIBIT] =3D { "mcountinhibit", any, read_mcountinhibit, + write_mcountinhibit }, + + [CSR_MHPMEVENT3] =3D { "mhpmevent3", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT4] =3D { "mhpmevent4", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT5] =3D { "mhpmevent5", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT6] =3D { "mhpmevent6", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT7] =3D { "mhpmevent7", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT8] =3D { "mhpmevent8", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT9] =3D { "mhpmevent9", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT10] =3D { "mhpmevent10", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT11] =3D { "mhpmevent11", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT12] =3D { "mhpmevent12", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT13] =3D { "mhpmevent13", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT14] =3D { "mhpmevent14", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT15] =3D { "mhpmevent15", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT16] =3D { "mhpmevent16", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT17] =3D { "mhpmevent17", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT18] =3D { "mhpmevent18", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT19] =3D { "mhpmevent19", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT20] =3D { "mhpmevent20", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT21] =3D { "mhpmevent21", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT22] =3D { "mhpmevent22", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT23] =3D { "mhpmevent23", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT24] =3D { "mhpmevent24", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT25] =3D { "mhpmevent25", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT26] =3D { "mhpmevent26", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT27] =3D { "mhpmevent27", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT28] =3D { "mhpmevent28", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT29] =3D { "mhpmevent29", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT30] =3D { "mhpmevent30", any, read_mhpmevent, + write_mhpmevent }, + [CSR_MHPMEVENT31] =3D { "mhpmevent31", any, read_mhpmevent, + write_mhpmevent }, + + [CSR_HPMCOUNTER3H] =3D { "hpmcounter3h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER4H] =3D { "hpmcounter4h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER5H] =3D { "hpmcounter5h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER6H] =3D { "hpmcounter6h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER7H] =3D { "hpmcounter7h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER8H] =3D { "hpmcounter8h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER9H] =3D { "hpmcounter9h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER10H] =3D { "hpmcounter10h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER11H] =3D { "hpmcounter11h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER12H] =3D { "hpmcounter12h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER13H] =3D { "hpmcounter13h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER14H] =3D { "hpmcounter14h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER15H] =3D { "hpmcounter15h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER16H] =3D { "hpmcounter16h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER17H] =3D { "hpmcounter17h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER18H] =3D { "hpmcounter18h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER19H] =3D { "hpmcounter19h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER20H] =3D { "hpmcounter20h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER21H] =3D { "hpmcounter21h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER22H] =3D { "hpmcounter22h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER23H] =3D { "hpmcounter23h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER24H] =3D { "hpmcounter24h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER25H] =3D { "hpmcounter25h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER26H] =3D { "hpmcounter26h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER27H] =3D { "hpmcounter27h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER28H] =3D { "hpmcounter28h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER29H] =3D { "hpmcounter29h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER30H] =3D { "hpmcounter30h", ctr32, read_hpmcounterh = }, + [CSR_HPMCOUNTER31H] =3D { "hpmcounter31h", ctr32, read_hpmcounterh = }, + + [CSR_MHPMCOUNTER3H] =3D { "mhpmcounter3h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER4H] =3D { "mhpmcounter4h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER5H] =3D { "mhpmcounter5h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER6H] =3D { "mhpmcounter6h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER7H] =3D { "mhpmcounter7h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER8H] =3D { "mhpmcounter8h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER9H] =3D { "mhpmcounter9h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER10H] =3D { "mhpmcounter10h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER11H] =3D { "mhpmcounter11h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER12H] =3D { "mhpmcounter12h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER13H] =3D { "mhpmcounter13h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER14H] =3D { "mhpmcounter14h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER15H] =3D { "mhpmcounter15h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER16H] =3D { "mhpmcounter16h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER17H] =3D { "mhpmcounter17h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER18H] =3D { "mhpmcounter18h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER19H] =3D { "mhpmcounter19h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER20H] =3D { "mhpmcounter20h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER21H] =3D { "mhpmcounter21h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER22H] =3D { "mhpmcounter22h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER23H] =3D { "mhpmcounter23h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER24H] =3D { "mhpmcounter24h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER25H] =3D { "mhpmcounter25h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER26H] =3D { "mhpmcounter26h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER27H] =3D { "mhpmcounter27h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER28H] =3D { "mhpmcounter28h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER29H] =3D { "mhpmcounter29h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER30H] =3D { "mhpmcounter30h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, + [CSR_MHPMCOUNTER31H] =3D { "mhpmcounter31h", mctr32, read_hpmcounterh, + write_mhpmcounterh = }, #endif /* !CONFIG_USER_ONLY */ }; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 87cd55bfd3..99193c85bb 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -331,6 +331,9 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINTTL(env.scounteren, RISCVCPU), VMSTATE_UINTTL(env.mcounteren, RISCVCPU), VMSTATE_UINTTL(env.mcountinhibit, RISCVCPU), + VMSTATE_UINTTL_ARRAY(env.mhpmcounter_val, RISCVCPU, RV_MAX_MHPMCOU= NTERS), + VMSTATE_UINTTL_ARRAY(env.mhpmcounterh_val, RISCVCPU, RV_MAX_MHPMCO= UNTERS), + VMSTATE_UINTTL_ARRAY(env.mhpmevent_val, RISCVCPU, RV_MAX_MHPMEVENT= S), VMSTATE_UINTTL(env.sscratch, RISCVCPU), VMSTATE_UINTTL(env.mscratch, RISCVCPU), VMSTATE_UINT64(env.mfromhost, RISCVCPU), --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656808082233371.3224800311035; Sat, 2 Jul 2022 17:28:02 -0700 (PDT) Received: from localhost ([::1]:55820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nSy-0001cC-VF for importer@patchew.org; Sat, 02 Jul 2022 20:28:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEq-0000Se-CM for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:24 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEk-0001zT-O6 for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:23 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:07 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:30 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:08 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xg50mDz1Rwnl for ; Sat, 2 Jul 2022 17:13:07 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 2cpsbEofOlsn for ; Sat, 2 Jul 2022 17:13:06 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Xc06CWz1Rw4L; Sat, 2 Jul 2022 17:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807197; x=1688343197; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uUq9OCPFvXQkN1DLfjeUGk4+XsY/6I1kHELLlwatxUI=; b=IH5qQSQwjXHucF9Z4nHr4EDXj1AwovEZMyPvRbiFD+jk5nDyXgwxFzOW 18yVdSggtLes9Yddfm+dR/dP7X6iL2LKomKEcm/KyiGynZXPv5p99kzdR 81fpOXoL1Zkz8w76pf+DTti/Cq5V1PhDVTkeFTF720WDiL0r1FDMN7HqB wxMIxSxbWYTBcQBq8thn4L40NyaVf3+Jc8ZeT2Y1kmWGP7yiCMc5dVk/G avAQ7qmBm1BrbghI7hDmNxlQPCMkgxerz2FDVZRrGMWg7c5551tsGT0oI HmNgeCuPQFjMJvyYAwKYXDfBq2QySQq5hU6Ieb+fG1p80t/xlnKGiGJkn g==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667254" IronPort-SDR: JX/DEf4psfltLT1nDKiwMbUyrw5jnjkbofr0dFZ9vN/Qw7gcKkrw8KFji19Dkau6maY91HTKM/ uBwL6YO+r4+/3PgQhDoh2uBul9xq2vSzSiRIJwtHr/aD7vmQRO3WB13mX8hVS7aFqKLrW4B9Oi e+fiBh5vCPDhUSe2zohdeeheDWOegBeG1Av5I+xsGaYrzdsQwBNI1WutiyNv3QhYdhePw8T29k 5HYP2NR2WEMkDYSn5awUV1Mt49VGsrP2i1yUQnEjcU4MOvnmBy10ofbLfyhlB01XDJCWUF/+p9 4MYqG4B57B/V49KhMSR1XwFA IronPort-SDR: He1qo/THLKnn2WSiuAZ2DOHt7G7TOqDyQQQ7gLryNJdVQzJOsHWgKsTVR9fnHbZTtQ/q5HJ7zd qcba2GYfww4ELW6rdmVSKR5OUEcjXhsKdhAtrOS6v4S3pZC/TQLzhB/T6iCv8+W1U7o7xm2SR3 z5zytAbYkcjrncwrKWO1O0rp2vtIEDLVWiWQsrX1FEvSEjCtYGdXuI6f1dX62cx2HOjvSFPscv wSh/l03BoGTidgVnsMIe2eNG0evNTEMBF+GW0tF/vLafOHUIvGb+9dfmqDgdYego3G7bYhCO8I eto= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807186; x=1659399187; bh=uUq9OCPFvXQkN1DLfj eUGk4+XsY/6I1kHELLlwatxUI=; b=mdI5GelRbMD2XpehRj3jY4zCbN97pIZk6V vd0aLJjWAP7BfTjpJGoWh+EGJA4qfLvqwMH9LUeSiJAIoGyfWdZ+avCTZ0PtJz2C m5V4sIeW1qlO7Ykw0L+4txRw1X/5kF/Ivm1O2idtKiqM5TQOmLVkm4b0rQOJV0i5 K14XXwAho2mFML1GBXa2DqwU4NXHQSTIbvqIdhPwD+GxtU55vLuykh+XNahZcHoj ueA4Oxc9nwH3/d+w0odu5cgtBsQ7VYSnWiwPsPN3FviWwQm0Wla+Uwt6asP/0mnO wCd5x0LAUhdb8XMRwId3Iwyy46mdsi8RDVssZAst4THvlgFiY44w== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Atish Patra , Alistair Francis , Atish Patra Subject: [PULL v2 12/19] target/riscv: Support mcycle/minstret write operation Date: Sun, 3 Jul 2022 10:12:27 +1000 Message-Id: <20220703001234.439716-13-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656808083813100001 Content-Type: text/plain; charset="utf-8" From: Atish Patra mcycle/minstret are actually WARL registers and can be written with any given value. With SBI PMU extension, it will be used to store a initial value provided from supervisor OS. The Qemu also need prohibit the counter increment if mcountinhibit is set. Support mcycle/minstret through generic counter infrastructure. Reviewed-by: Alistair Francis Signed-off-by: Atish Patra Signed-off-by: Atish Patra Message-Id: <20220620231603.2547260-8-atishp@rivosinc.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.h | 23 ++++-- target/riscv/pmu.h | 28 +++++++ target/riscv/csr.c | 155 ++++++++++++++++++++++++++++----------- target/riscv/machine.c | 25 ++++++- target/riscv/pmu.c | 32 ++++++++ target/riscv/meson.build | 3 +- 6 files changed, 213 insertions(+), 53 deletions(-) create mode 100644 target/riscv/pmu.h create mode 100644 target/riscv/pmu.c diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 199d0d570b..5c7acc055a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -117,7 +117,7 @@ typedef struct CPUArchState CPURISCVState; #endif =20 #define RV_VLEN_MAX 1024 -#define RV_MAX_MHPMEVENTS 29 +#define RV_MAX_MHPMEVENTS 32 #define RV_MAX_MHPMCOUNTERS 32 =20 FIELD(VTYPE, VLMUL, 0, 3) @@ -127,6 +127,18 @@ FIELD(VTYPE, VMA, 7, 1) FIELD(VTYPE, VEDIV, 8, 2) FIELD(VTYPE, RESERVED, 10, sizeof(target_ulong) * 8 - 11) =20 +typedef struct PMUCTRState { + /* Current value of a counter */ + target_ulong mhpmcounter_val; + /* Current value of a counter in RV32*/ + target_ulong mhpmcounterh_val; + /* Snapshot values of counter */ + target_ulong mhpmcounter_prev; + /* Snapshort value of a counter in RV32 */ + target_ulong mhpmcounterh_prev; + bool started; +} PMUCTRState; + struct CPUArchState { target_ulong gpr[32]; target_ulong gprh[32]; /* 64 top bits of the 128-bit registers */ @@ -279,13 +291,10 @@ struct CPUArchState { =20 target_ulong mcountinhibit; =20 - /* PMU counter configured values */ - target_ulong mhpmcounter_val[RV_MAX_MHPMCOUNTERS]; - - /* for RV32 */ - target_ulong mhpmcounterh_val[RV_MAX_MHPMCOUNTERS]; + /* PMU counter state */ + PMUCTRState pmu_ctrs[RV_MAX_MHPMCOUNTERS]; =20 - /* PMU event selector configured values */ + /* PMU event selector configured values. First three are unused*/ target_ulong mhpmevent_val[RV_MAX_MHPMEVENTS]; =20 target_ulong sscratch; diff --git a/target/riscv/pmu.h b/target/riscv/pmu.h new file mode 100644 index 0000000000..58a5bc3a40 --- /dev/null +++ b/target/riscv/pmu.h @@ -0,0 +1,28 @@ +/* + * RISC-V PMU header file. + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "cpu.h" +#include "qemu/main-loop.h" +#include "exec/exec-all.h" + +bool riscv_pmu_ctr_monitor_instructions(CPURISCVState *env, + uint32_t target_ctr); +bool riscv_pmu_ctr_monitor_cycles(CPURISCVState *env, + uint32_t target_ctr); diff --git a/target/riscv/csr.c b/target/riscv/csr.c index b931a3970e..d65318dcc6 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -21,6 +21,7 @@ #include "qemu/log.h" #include "qemu/timer.h" #include "cpu.h" +#include "pmu.h" #include "qemu/main-loop.h" #include "exec/exec-all.h" #include "sysemu/cpu-timers.h" @@ -597,34 +598,28 @@ static int write_vcsr(CPURISCVState *env, int csrno, = target_ulong val) } =20 /* User Timers and Counters */ -static RISCVException read_instret(CPURISCVState *env, int csrno, - target_ulong *val) +static target_ulong get_ticks(bool shift) { + int64_t val; + target_ulong result; + #if !defined(CONFIG_USER_ONLY) if (icount_enabled()) { - *val =3D icount_get(); + val =3D icount_get(); } else { - *val =3D cpu_get_host_ticks(); + val =3D cpu_get_host_ticks(); } #else - *val =3D cpu_get_host_ticks(); + val =3D cpu_get_host_ticks(); #endif - return RISCV_EXCP_NONE; -} =20 -static RISCVException read_instreth(CPURISCVState *env, int csrno, - target_ulong *val) -{ -#if !defined(CONFIG_USER_ONLY) - if (icount_enabled()) { - *val =3D icount_get() >> 32; + if (shift) { + result =3D val >> 32; } else { - *val =3D cpu_get_host_ticks() >> 32; + result =3D val; } -#else - *val =3D cpu_get_host_ticks() >> 32; -#endif - return RISCV_EXCP_NONE; + + return result; } =20 #if defined(CONFIG_USER_ONLY) @@ -642,11 +637,23 @@ static RISCVException read_timeh(CPURISCVState *env, = int csrno, return RISCV_EXCP_NONE; } =20 +static int read_hpmcounter(CPURISCVState *env, int csrno, target_ulong *va= l) +{ + *val =3D get_ticks(false); + return RISCV_EXCP_NONE; +} + +static int read_hpmcounterh(CPURISCVState *env, int csrno, target_ulong *v= al) +{ + *val =3D get_ticks(true); + return RISCV_EXCP_NONE; +} + #else /* CONFIG_USER_ONLY */ =20 static int read_mhpmevent(CPURISCVState *env, int csrno, target_ulong *val) { - int evt_index =3D csrno - CSR_MHPMEVENT3; + int evt_index =3D csrno - CSR_MCOUNTINHIBIT; =20 *val =3D env->mhpmevent_val[evt_index]; =20 @@ -655,7 +662,7 @@ static int read_mhpmevent(CPURISCVState *env, int csrno= , target_ulong *val) =20 static int write_mhpmevent(CPURISCVState *env, int csrno, target_ulong val) { - int evt_index =3D csrno - CSR_MHPMEVENT3; + int evt_index =3D csrno - CSR_MCOUNTINHIBIT; =20 env->mhpmevent_val[evt_index] =3D val; =20 @@ -664,55 +671,105 @@ static int write_mhpmevent(CPURISCVState *env, int c= srno, target_ulong val) =20 static int write_mhpmcounter(CPURISCVState *env, int csrno, target_ulong v= al) { - int ctr_index =3D csrno - CSR_MHPMCOUNTER3 + 3; + int ctr_idx =3D csrno - CSR_MCYCLE; + PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; =20 - env->mhpmcounter_val[ctr_index] =3D val; + counter->mhpmcounter_val =3D val; + if (riscv_pmu_ctr_monitor_cycles(env, ctr_idx) || + riscv_pmu_ctr_monitor_instructions(env, ctr_idx)) { + counter->mhpmcounter_prev =3D get_ticks(false); + } else { + /* Other counters can keep incrementing from the given value */ + counter->mhpmcounter_prev =3D val; + } =20 return RISCV_EXCP_NONE; } =20 static int write_mhpmcounterh(CPURISCVState *env, int csrno, target_ulong = val) { - int ctr_index =3D csrno - CSR_MHPMCOUNTER3H + 3; + int ctr_idx =3D csrno - CSR_MCYCLEH; + PMUCTRState *counter =3D &env->pmu_ctrs[ctr_idx]; =20 - env->mhpmcounterh_val[ctr_index] =3D val; + counter->mhpmcounterh_val =3D val; + if (riscv_pmu_ctr_monitor_cycles(env, ctr_idx) || + riscv_pmu_ctr_monitor_instructions(env, ctr_idx)) { + counter->mhpmcounterh_prev =3D get_ticks(true); + } else { + counter->mhpmcounterh_prev =3D val; + } + + return RISCV_EXCP_NONE; +} + +static RISCVException riscv_pmu_read_ctr(CPURISCVState *env, target_ulong = *val, + bool upper_half, uint32_t ctr_idx) +{ + PMUCTRState counter =3D env->pmu_ctrs[ctr_idx]; + target_ulong ctr_prev =3D upper_half ? counter.mhpmcounterh_prev : + counter.mhpmcounter_prev; + target_ulong ctr_val =3D upper_half ? counter.mhpmcounterh_val : + counter.mhpmcounter_val; + + if (get_field(env->mcountinhibit, BIT(ctr_idx))) { + /** + * Counter should not increment if inhibit bit is set. We can't re= ally + * stop the icount counting. Just return the counter value written= by + * the supervisor to indicate that counter was not incremented. + */ + if (!counter.started) { + *val =3D ctr_val; + return RISCV_EXCP_NONE; + } else { + /* Mark that the counter has been stopped */ + counter.started =3D false; + } + } + + /** + * The kernel computes the perf delta by subtracting the current value= from + * the value it initialized previously (ctr_val). + */ + if (riscv_pmu_ctr_monitor_cycles(env, ctr_idx) || + riscv_pmu_ctr_monitor_instructions(env, ctr_idx)) { + *val =3D get_ticks(upper_half) - ctr_prev + ctr_val; + } else { + *val =3D ctr_val; + } =20 return RISCV_EXCP_NONE; } =20 static int read_hpmcounter(CPURISCVState *env, int csrno, target_ulong *va= l) { - int ctr_index; + uint16_t ctr_index; =20 if (csrno >=3D CSR_MCYCLE && csrno <=3D CSR_MHPMCOUNTER31) { - ctr_index =3D csrno - CSR_MHPMCOUNTER3 + 3; + ctr_index =3D csrno - CSR_MCYCLE; } else if (csrno >=3D CSR_CYCLE && csrno <=3D CSR_HPMCOUNTER31) { - ctr_index =3D csrno - CSR_HPMCOUNTER3 + 3; + ctr_index =3D csrno - CSR_CYCLE; } else { return RISCV_EXCP_ILLEGAL_INST; } - *val =3D env->mhpmcounter_val[ctr_index]; =20 - return RISCV_EXCP_NONE; + return riscv_pmu_read_ctr(env, val, false, ctr_index); } =20 static int read_hpmcounterh(CPURISCVState *env, int csrno, target_ulong *v= al) { - int ctr_index; + uint16_t ctr_index; =20 if (csrno >=3D CSR_MCYCLEH && csrno <=3D CSR_MHPMCOUNTER31H) { - ctr_index =3D csrno - CSR_MHPMCOUNTER3H + 3; + ctr_index =3D csrno - CSR_MCYCLEH; } else if (csrno >=3D CSR_CYCLEH && csrno <=3D CSR_HPMCOUNTER31H) { - ctr_index =3D csrno - CSR_HPMCOUNTER3H + 3; + ctr_index =3D csrno - CSR_CYCLEH; } else { return RISCV_EXCP_ILLEGAL_INST; } - *val =3D env->mhpmcounterh_val[ctr_index]; =20 - return RISCV_EXCP_NONE; + return riscv_pmu_read_ctr(env, val, true, ctr_index); } =20 - static RISCVException read_time(CPURISCVState *env, int csrno, target_ulong *val) { @@ -1567,11 +1624,23 @@ static RISCVException read_mcountinhibit(CPURISCVSt= ate *env, int csrno, static RISCVException write_mcountinhibit(CPURISCVState *env, int csrno, target_ulong val) { + int cidx; + PMUCTRState *counter; + if (env->priv_ver < PRIV_VERSION_1_11_0) { return RISCV_EXCP_ILLEGAL_INST; } =20 env->mcountinhibit =3D val; + + /* Check if any other counter is also monitoring cycles/instructions */ + for (cidx =3D 0; cidx < RV_MAX_MHPMCOUNTERS; cidx++) { + if (!get_field(env->mcountinhibit, BIT(cidx))) { + counter =3D &env->pmu_ctrs[cidx]; + counter->started =3D true; + } + } + return RISCV_EXCP_NONE; } =20 @@ -3533,10 +3602,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_VLENB] =3D { "vlenb", vs, read_vlenb, .min_priv_ver =3D PRIV_VERSION_1= _12_0 }, /* User Timers and Counters */ - [CSR_CYCLE] =3D { "cycle", ctr, read_instret }, - [CSR_INSTRET] =3D { "instret", ctr, read_instret }, - [CSR_CYCLEH] =3D { "cycleh", ctr32, read_instreth }, - [CSR_INSTRETH] =3D { "instreth", ctr32, read_instreth }, + [CSR_CYCLE] =3D { "cycle", ctr, read_hpmcounter }, + [CSR_INSTRET] =3D { "instret", ctr, read_hpmcounter }, + [CSR_CYCLEH] =3D { "cycleh", ctr32, read_hpmcounterh }, + [CSR_INSTRETH] =3D { "instreth", ctr32, read_hpmcounterh }, =20 /* * In privileged mode, the monitor will have to emulate TIME CSRs only= if @@ -3550,10 +3619,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { =20 #if !defined(CONFIG_USER_ONLY) /* Machine Timers and Counters */ - [CSR_MCYCLE] =3D { "mcycle", any, read_instret }, - [CSR_MINSTRET] =3D { "minstret", any, read_instret }, - [CSR_MCYCLEH] =3D { "mcycleh", any32, read_instreth }, - [CSR_MINSTRETH] =3D { "minstreth", any32, read_instreth }, + [CSR_MCYCLE] =3D { "mcycle", any, read_hpmcounter, write_mhpmc= ounter}, + [CSR_MINSTRET] =3D { "minstret", any, read_hpmcounter, write_mhpmc= ounter}, + [CSR_MCYCLEH] =3D { "mcycleh", any32, read_hpmcounterh, write_mhpm= counterh}, + [CSR_MINSTRETH] =3D { "minstreth", any32, read_hpmcounterh, write_mhpm= counterh}, =20 /* Machine Information Registers */ [CSR_MVENDORID] =3D { "mvendorid", any, read_mvendorid }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 99193c85bb..dc182ca811 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -279,7 +279,28 @@ static const VMStateDescription vmstate_envcfg =3D { VMSTATE_UINT64(env.menvcfg, RISCVCPU), VMSTATE_UINTTL(env.senvcfg, RISCVCPU), VMSTATE_UINT64(env.henvcfg, RISCVCPU), + VMSTATE_END_OF_LIST() + } +}; + +static bool pmu_needed(void *opaque) +{ + RISCVCPU *cpu =3D opaque; =20 + return cpu->cfg.pmu_num; +} + +static const VMStateDescription vmstate_pmu_ctr_state =3D { + .name =3D "cpu/pmu", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D pmu_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINTTL(mhpmcounter_val, PMUCTRState), + VMSTATE_UINTTL(mhpmcounterh_val, PMUCTRState), + VMSTATE_UINTTL(mhpmcounter_prev, PMUCTRState), + VMSTATE_UINTTL(mhpmcounterh_prev, PMUCTRState), + VMSTATE_BOOL(started, PMUCTRState), VMSTATE_END_OF_LIST() } }; @@ -331,8 +352,8 @@ const VMStateDescription vmstate_riscv_cpu =3D { VMSTATE_UINTTL(env.scounteren, RISCVCPU), VMSTATE_UINTTL(env.mcounteren, RISCVCPU), VMSTATE_UINTTL(env.mcountinhibit, RISCVCPU), - VMSTATE_UINTTL_ARRAY(env.mhpmcounter_val, RISCVCPU, RV_MAX_MHPMCOU= NTERS), - VMSTATE_UINTTL_ARRAY(env.mhpmcounterh_val, RISCVCPU, RV_MAX_MHPMCO= UNTERS), + VMSTATE_STRUCT_ARRAY(env.pmu_ctrs, RISCVCPU, RV_MAX_MHPMCOUNTERS, = 0, + vmstate_pmu_ctr_state, PMUCTRState), VMSTATE_UINTTL_ARRAY(env.mhpmevent_val, RISCVCPU, RV_MAX_MHPMEVENT= S), VMSTATE_UINTTL(env.sscratch, RISCVCPU), VMSTATE_UINTTL(env.mscratch, RISCVCPU), diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c new file mode 100644 index 0000000000..000fe8da45 --- /dev/null +++ b/target/riscv/pmu.c @@ -0,0 +1,32 @@ +/* + * RISC-V PMU file. + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "pmu.h" + +bool riscv_pmu_ctr_monitor_instructions(CPURISCVState *env, + uint32_t target_ctr) +{ + return (target_ctr =3D=3D 0) ? true : false; +} + +bool riscv_pmu_ctr_monitor_cycles(CPURISCVState *env, uint32_t target_ctr) +{ + return (target_ctr =3D=3D 2) ? true : false; +} diff --git a/target/riscv/meson.build b/target/riscv/meson.build index 096249f3a3..2c1975e72c 100644 --- a/target/riscv/meson.build +++ b/target/riscv/meson.build @@ -30,7 +30,8 @@ riscv_softmmu_ss.add(files( 'pmp.c', 'debug.c', 'monitor.c', - 'machine.c' + 'machine.c', + 'pmu.c' )) =20 target_arch +=3D {'riscv': riscv_ss} --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656808178777974.6125978763927; Sat, 2 Jul 2022 17:29:38 -0700 (PDT) Received: from localhost ([::1]:59448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nUV-00045F-L5 for importer@patchew.org; Sat, 02 Jul 2022 20:29:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEr-0000U7-GJ for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:25 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46191) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEm-00021g-QQ for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:25 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:08 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:31 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:09 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xh6vk9z1Rw4L for ; Sat, 2 Jul 2022 17:13:08 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id LzTfSnyJ_qjT for ; Sat, 2 Jul 2022 17:13:08 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Xf4sHFz1RtVk; Sat, 2 Jul 2022 17:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807199; x=1688343199; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KjDePeIKI821vT6seFNfS6IPOF15yN0jaOy7uSzvrr0=; b=WUjLJUdXVO62fds2eRFi7nX9XGiG7VYZlBEsB56bwGZkVEqBXAr7YN+E DKSeJKKKI8l0TLOmmKOTEwr67o0ZSkZMN2e2A97UdSTtbNn5PZC5J1m0X FiLDzRqWp81RzhNx3qyZystxCx9QfwDGkogHqmiGgvkf5HuP6QeoB+ser VaTwFDVtSxjD7dFHfd5awse53lO+UaDj3pE1mrZ1O1Xb32TlXImV3T8k5 EX0Kpqb663PCnhKGqO+MPyg6/9DtPe+nSqKXPtRiNzp3zL0GO10J9U23j BjnxfQ6dSNQUlqUcBAgsbpLjRFv3a5sHInUdMWIXujjQOQ/saMSLGW9lJ Q==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667257" IronPort-SDR: VFJKuwqJDyG/cqyN4GQ+z3jaZP6f8MIGGqhFfOK5kXxnSO6hVImo6KINag/I5O/bLi4Ow/4jqS alfTVHALzs2+TlQ1WGeKyi5HlSpMhF2Z2YGgBuvZ3o0Av9OlENqYuMy9O3ukZ4mF4GiJDH+7Yp srNFFcwgdOAhA78QXa3oBsMJvfg/HDO21DM2ZtQIelLwGxqKPZRUfmbOUAbKf8Ef5//jsSsftt SjaL+grniSJsDHe42wNL6OWNU1/7EKOxkmju0yzxGIvbWIPBLqjDYZEpee24fhUM0/pYC8f48S l+T5UupJ52Eusvr0cNu3rUtS IronPort-SDR: bjRa3v4OJiCOEs8L/9WueTrGB4hFqQ79+HMURcUMO79vAqZr+WRtP5re+ihaQs++PxM2o/tD45 0qDJMyBbrCvxsuEhPtOnjje2u1eqM4U0xrDCXaUMAFYU2IhFOBglsrtc7bo6HypAKX/uOFLnec G3MQ3fr06F0maFqhQ0SQcJUU51OwWi5X7+gCNIqc1hBK1ZHbOMbD+/BBiToRlvUKXi1OlsQjBy ta8F48dBxysWV0MHx+SwPHnFD1n8YTNa56hrNqoZpNogkgSha2FDGqn0HKIAQH2SLOg7j9KuLO vII= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807188; x=1659399189; bh=KjDePeIKI821vT6seF NfS6IPOF15yN0jaOy7uSzvrr0=; b=ILGGr2ViSffMCTbODARLdZ+19DcLocoRBX POrOIHC7LvVDZkJnK58Okq3pnxHrIrVcETm2WXXavzEak+YSGYEnm3vjuHBEiSBW 8RR1BnN0UH1mwOcV313tOl718vRYJoZlaKzox4v8gVmneRfxOAC0/eK/wQkV2UWB TVJLAhtxeAewvvHVff5hUMrjY3vOBbRnN83Ai/2Kvh8e+Yzgoti8be+EJBQ6G2eE Dzw5UBkjlNOXvBm1ghS2TwijXCLQuhvplDK4y4PoOQ0r2uJOSo20WdM997QkstVy qZv+QUQ+tsryZXweBaRpSjIOWqplJuq0Klc11m1eLQpFM/oBaYtQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Alistair Francis , Bin Meng Subject: [PULL v2 13/19] target/riscv: Fixup MSECCFG minimum priv check Date: Sun, 3 Jul 2022 10:12:28 +1000 Message-Id: <20220703001234.439716-14-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656808180192100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis There is nothing in the RISC-V spec that mandates version 1.12 is required for ePMP and there is currently hardware [1] that implements ePMP (a draft version though) with the 1.11 priv spec. 1: https://ibex-core.readthedocs.io/en/latest/01_overview/compliance.html Fixes: a4b2fa433125 ("target/riscv: Introduce privilege version field in th= e CSR ops.") Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Message-Id: <20220629233102.275181-2-alistair.francis@opensource.wdc.com> --- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d65318dcc6..d14a0cb0a0 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3812,7 +3812,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { =20 /* Physical Memory Protection */ [CSR_MSECCFG] =3D { "mseccfg", epmp, read_mseccfg, write_mseccfg, - .min_priv_ver =3D PRIV_VERSION_1_12_0= }, + .min_priv_ver =3D PRIV_VERSION_1_11_0= }, [CSR_PMPCFG0] =3D { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] =3D { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG2] =3D { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg }, --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656808313769920.4696105278464; Sat, 2 Jul 2022 17:31:53 -0700 (PDT) Received: from localhost ([::1]:33392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nWi-0005bI-N7 for importer@patchew.org; Sat, 02 Jul 2022 20:31:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEu-0000XH-B4 for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:28 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nEo-0001p4-Jv for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:28 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:10 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:33 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:12 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xl4Lm2z1Rwnx for ; Sat, 2 Jul 2022 17:13:11 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id kfxB1Hj_c8tU for ; Sat, 2 Jul 2022 17:13:11 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Xj10FKz1RtVk; Sat, 2 Jul 2022 17:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807201; x=1688343201; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SBRzBpEor0Dw6AJYQyfJP6yZs8/fFYYqZlfbL2SMAw0=; b=Zzi2xPKC3T44fy0M/NEii3j00eyJZl7RMbikyBJwPJtZcebjegB0yji+ BeKbRTTs+qPlfdrDAcdLtq7TOCqO+Esk5tcTHnOVoUeyRiN42RvskPPT1 bNWzM8DD4UTsCEPjYkLRhr/nynOMVT4gbCdVX1r42IFc0+VV4vOEWowjA mi3kFZpa/q3Ue12VZcYkHcF99kOaksX2VFoUVkvMZA3ESwxOYat0Jhncv TLmFfRPGgpFIsC0B6NjQ5Az29V2hDypLa62Hr25Q9OzPscr7fE+fVQ0zW T5+LWHJehPbmVPzphO/hmyr34njokmb4aM3rY2b/v8OfkjBAnoLcCUQsW A==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667261" IronPort-SDR: LnFx9cLbRaskkZ+wtfJ0ZZbTBIZcYVeXvbrE8pkrg6sswYZgO/TCaKU8PV5mCo8wnIlDNRNxqW Ro/Ce9ZZm+JX1KyJ3I74hZ8CWa4gfECbcr2cAKDzYdUsFY6Z7qtWTcvgiLMK8QtUK1dN9y41sF nXiRkS7/8pubo8sACNDGq5SPWy7NM0uyxNp+qzmwG9l5CVCcHUk4baRgsHtmF22TYGKPhwCIdg 7NeDOMzZkzuPc+Jnh6ZOfPiXxgsbGOv58k7KRYtp9mJ3XhtAIxfddzBXWOTRQsfNUzWeBN45xj OfJjtPb/SdltS4OuZIRRkpRn IronPort-SDR: seYnWD3xatZ/gn8EZj7+lCMvwgS7BZbXMX8RggSSrjWSI431AqJoaqK9y9cSuwxpkY7aA+DFa6 CwhvMR/BRwk+VImhiYPm6r7xj6+L/uwBV6cxeINIjkWRCN1Hoej8pGXVO2dEBSs1BZ+SjvNyBN S9Fk4Hz1A09fqoxPwlGb7p31kg9/ukzu7Z8In2TAXDYIg5aRIbuqzPlOE+WpdnGBfoxIZfXD/6 wem1uXpMTqJ5Ixq2o+rf37/a7ONMt8OFACyYRktosBWZZCoqXO6Km48u38fzRVYc0saOnNqkUW QAQ= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807191; x=1659399192; bh=SBRzBpEor0Dw6AJYQy fJP6yZs8/fFYYqZlfbL2SMAw0=; b=ZBMLNWcZR+pvAupjytYwDmMrRtHDTvUlnd oCl3PsZQWQL41MAhASkfQCC22v9lQsU2vY3j3CspQSV96I1JT/ZspMf50D5yq3OQ o7ueZlg1+u53CbBMQvjLtjsa/ubqVDyLWLofK++dTConapBuYu0gZb7fYND08ma+ RMi/IowNf+EKmoC6qp9HcnTfr6Kfv8XR1ocuTSqN02vMB+uAeJ1aSsr7JDoPtuXC 3fRIrHaEGFNCmHvJA2KM6tPv4f8PawxN1Vfua163JwHYuP5ecV7cSuezyqs6mM81 25Tx2mMr1M2jb5JO1/ErXUEpceChLpTeJxr9itza8hjSgdrNsR5Q== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Alistair Francis , Bin Meng Subject: [PULL v2 14/19] target/riscv: Ibex: Support priv version 1.11 Date: Sun, 3 Jul 2022 10:12:29 +1000 Message-Id: <20220703001234.439716-15-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656808314757100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis The Ibex CPU supports version 1.11 of the priv spec [1], so let's correct that in QEMU as well. 1: https://ibex-core.readthedocs.io/en/latest/01_overview/compliance.html Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Message-Id: <20220629233102.275181-3-alistair.francis@opensource.wdc.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d12c6dc630..aac0576fe1 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -237,7 +237,7 @@ static void rv32_ibex_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + set_priv_version(env, PRIV_VERSION_1_11_0); cpu->cfg.mmu =3D false; cpu->cfg.epmp =3D true; } --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807466666752.5722498235937; Sat, 2 Jul 2022 17:17:46 -0700 (PDT) Received: from localhost ([::1]:56638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nJ3-00089i-ME for importer@patchew.org; Sat, 02 Jul 2022 20:17:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nF2-0000l2-Gn for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:36 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nF0-0001zT-LM for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:36 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:12 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:36 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:14 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xn735qz1Rw4L for ; Sat, 2 Jul 2022 17:13:13 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id u1SsZldSuRj1 for ; Sat, 2 Jul 2022 17:13:13 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Xl45XQz1Rwnl; Sat, 2 Jul 2022 17:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807213; x=1688343213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aBbkY/5eQz39KTBVgbT03tYExu0XWDBj7TWYoIjAih0=; b=TvJ5wPfLfckB0v/cl+Og+Q9VEB5jc3PCKqfqBofMaUmeVWa7RRJr/O7F Ar+fWUAyUwClzQmzlc+kKq+WZfHkF/iPumTEIwF+gwSUUrVKJ5Ukvlrh1 neZmtSJmXDRSh8R3v1L5aOvZFF00mvqccdSjmZb0HNXoAeqR6lgpB9UNQ 8qnlxX43eUKcMCZ/DN2d0gokIp+vG43cMSd403wywRaCY/ADfzZh0Iwc7 mCBwd4DeQFOREtPbVtMxcUzEhu8QkMW1Jwmi2t3TSXMz2JXrC46ZpKXrv jeCN/ZKP70gamoP2RnGzTxxvzTOYPGxk8t4WMh+37296m5wmZrPVRjUDz Q==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667264" IronPort-SDR: m6li6zP9HOkWDtc6Vdep+ETbXhdLlraXf9rKmqpBuQ4Qqb/UYOy3AMe5Mqcqq0ad2jpNUms0z0 oAuFgxe7xgSvudFCDMk1g2yPWtNHmlr5HywZ2kK4xQFUGCDUvSc8W1wBR2m1HiZRFh0Amv+Mw+ g1s6RxUBzD+CTeJOs4tY4kEEtMzWHJHlkmHNOapv0S/+0Z9ScES5V47iknsNWG0P7u3oZE4Of/ yJv8FhXY4YGpoFRlAF0ZlTevjJyT3FJJyS3ZVpfMHn+UVYP/FgAeTwKs0gTLJuoKMaMQpX1Ecw 1kWFS/VgpHBJ00zzfzOMb4uW IronPort-SDR: KXHbc/djo14+Tn/99TIQhVaZPhkRYgaUci1Csh+d7T/hdPIkXnl4ooCLf2cGMoOV31+w3VX3DJ UrEDY8nOUMqWFui2OvoySBBPeUKJo/esgSDEagVbrvRDeBLVTUd+WptUHu5qsa2/fXdtE+TkXU 02GyiP30XnzWcGVoiDhfQcgUqo9nhdgvgqwSVB0B2afxR5MC2xXtm9JPIMWfN+9f4J4jowjCaG yvmweRgedWyXc4m516cw5iyLj/5yFSEtAkmD7CUWZaVXdct/ZPfN/ySRndLsy2697qnaS5FGYb LyI= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807193; x=1659399194; bh=aBbkY/5eQz39KTBVgb T03tYExu0XWDBj7TWYoIjAih0=; b=jsHYT1/yt/XU7arDIZ+n6BBN418kl4Pb7o fk+NJdMgZpuGogrKvhVPv07rv69z2Jg4LMhEkMCCqyh56YsOTdLsYYCMUXlyb2fN jPHPAxWs8yzIrvjXXAKuJwzw5JPWhunVmRoKoEC6Olp7zWPdXVKHPM7ZNIFQp7MZ 1CO6/cQXzXjyyRzAP+RnSL7iO0QPLYsV5sLmOk6vBbjszB+JcULBtQPYe2wTzTes yk5zTNNxcOxMVcG9DbToAfjL9kmcQIQ7dbcEbzQmvf0kqaY9QONibou4xuNzYc+S sUvrzYyI8yLuiMoAZRDzK7HO41xSB5gWxZb8bxiivCIXvVA07SyA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Anup Patel , Frank Chang , Alistair Francis , Atish Patra , Bin Meng Subject: [PULL v2 15/19] target/riscv: Don't force update priv spec version to latest Date: Sun, 3 Jul 2022 10:12:30 +1000 Message-Id: <20220703001234.439716-16-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807467144100003 Content-Type: text/plain; charset="utf-8" From: Anup Patel The riscv_cpu_realize() sets priv spec version to v1.12 when it is when "env->priv_ver =3D=3D 0" (i.e. default v1.10) because the enum value of priv spec v1.10 is zero. Due to above issue, the sifive_u machine will see priv spec v1.12 instead of priv spec v1.10. To fix this issue, we set latest priv spec version (i.e. v1.12) for base rv64/rv32 cpu and riscv_cpu_realize() will override priv spec version only when "cpu->cfg.priv_spec !=3D NULL". Fixes: 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12") Signed-off-by: Anup Patel Reviewed-by: Frank Chang Reviewed-by: Alistair Francis Reviewed-by: Atish Patra Reviewed-by: Bin Meng Message-Id: <20220611080107.391981-2-apatel@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index aac0576fe1..1bb3973806 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -173,6 +173,8 @@ static void rv64_base_cpu_init(Object *obj) /* We set this in the realise function */ set_misa(env, MXL_RV64, 0); register_cpu_props(DEVICE(obj)); + /* Set latest version of privileged specification */ + set_priv_version(env, PRIV_VERSION_1_12_0); } =20 static void rv64_sifive_u_cpu_init(Object *obj) @@ -204,6 +206,8 @@ static void rv128_base_cpu_init(Object *obj) /* We set this in the realise function */ set_misa(env, MXL_RV128, 0); register_cpu_props(DEVICE(obj)); + /* Set latest version of privileged specification */ + set_priv_version(env, PRIV_VERSION_1_12_0); } #else static void rv32_base_cpu_init(Object *obj) @@ -212,6 +216,8 @@ static void rv32_base_cpu_init(Object *obj) /* We set this in the realise function */ set_misa(env, MXL_RV32, 0); register_cpu_props(DEVICE(obj)); + /* Set latest version of privileged specification */ + set_priv_version(env, PRIV_VERSION_1_12_0); } =20 static void rv32_sifive_u_cpu_init(Object *obj) @@ -524,7 +530,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error *= *errp) CPURISCVState *env =3D &cpu->env; RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); CPUClass *cc =3D CPU_CLASS(mcc); - int priv_version =3D 0; + int priv_version =3D -1; Error *local_err =3D NULL; =20 cpu_exec_realizefn(cs, &local_err); @@ -548,10 +554,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error = **errp) } } =20 - if (priv_version) { + if (priv_version >=3D PRIV_VERSION_1_10_0) { set_priv_version(env, priv_version); - } else if (!env->priv_ver) { - set_priv_version(env, PRIV_VERSION_1_12_0); } =20 if (cpu->cfg.mmu) { --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656808441085288.26553602086096; Sat, 2 Jul 2022 17:34:01 -0700 (PDT) Received: from localhost ([::1]:37180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nYl-0008KE-Hm for importer@patchew.org; Sat, 02 Jul 2022 20:33:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nF3-0000pb-MC for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:37 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46191) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nF1-00021g-Qc for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:37 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:15 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:38 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:16 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xr2dk8z1Rw4L for ; Sat, 2 Jul 2022 17:13:16 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 1KrqrpYZIDjZ for ; Sat, 2 Jul 2022 17:13:15 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Xp0Q6Sz1Rwnx; Sat, 2 Jul 2022 17:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807214; x=1688343214; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=trjbl88ky0sGG/muJvpQZxcW4cE0pwW8mhBbBDB/fRw=; b=gvaccfpW8FCi8Cx7KDKuir2HzBYKOEXGLMpacrDyPL3ba4LlgmXiPa5F EB7pDNrPJrADVwMM45DV+MXhGpGSJg4EGArwcqFKGxLlejHQQhnXrhwNw 1iDIx2qYC3JSdnzb+hqGb+nQyoaNbLfc9Boz7tU63o7/5CMoM8UP3VoOC ndQAxYu52XWNPjN+5GF3xbxUe0DcROwaIhgreBqtHoS4a4j/sH5A5kyHG zxu0t+W1gg2Mc3mazUMKz4OGQ2KXuuC2BZ3kJPOmYrFarj/1SatiL9hQs MYiU9ywXlNH43jddeR9ItHgZNOO4OZjSJbfeLk0NBLFH6jI73vc00yAHz Q==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667266" IronPort-SDR: YU1JJqdAvEhNBgyOLgdZ825u+SPVdgYtksCEhMQghHsr3sYnv5faHd68pvxYHoKs4qVSCRARr/ u5hufCVLNqbTehl0YUX5fSdXcCChfHqcOtczhMzYgB/HzjeyrBlkLKnKjgY/am1IOD4YPuLSct n/u2jRsY82wL4PB6PxCOroDH++Ct9vd5llF/ATOfLzpEgIF0yTQOL/W2gsf/K37o2iwt0nV8+1 n8uuwunDolt2rkdZFTQeqUUIHibzHoVVXFr+yIUj3NBxEwAQD4dhxlYx/MORfZbW83AuBwHpMp 65KFf9OLhb25eVFWi8r7h2b7 IronPort-SDR: Fxhs9sf9GQ2JN4dcjNgxNo0ov6eTCoMQHRISp6dOipq3sN9TDMZUne137/JFktQYb773nNUiJ1 JElLJlGh3d5KopDeOLLKAbNVd/XfHXiAsgI7hoC0IJFomTgA/19GiRbpqx7GQrSODqp0QVdT81 Gb+gsqYRoR6zGnuM8R/jBd5D45G3IfF//o+T6DJ4Mw3Py5udX25uT6uGWYqOFPo4Kb8YTZVkNS f8q8zoM4AdNUThYG930rJ1FdQULBdFcQ1k2fZC5tzu3B08HfGvHWDeh+NhKC6YcFl7ySXzeONq Pzo= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807195; x=1659399196; bh=trjbl88ky0sGG/muJv pQZxcW4cE0pwW8mhBbBDB/fRw=; b=Wwinz60RxBiPjq1NXrDcmaM4tfOOFQ4FLV itUqLAOClCs17rvarjlDQppHA8Mtva7IGr8APuzaFTgaPsuwFMxH/4C3I7k3hpE2 wBO+ApUDGZA8C040rPE5XCQTbQmsV0zY6VV2sm58oAPT7oQ8BHmnPlL5Aw0Ey3kn eulXXbJ0kT5eAK2rZ9T3EyjG5sjRxv6CyZ/8DzUaK5Qvbd1+Aw9rixKi5c0QejlD orXz9N2HviUIKGq4jc5PyUIAypRcGzNtnOTWmUq1yStWL9c9v3+4FMgfC6+vhaCr fgkgguEBn1C8jiGm20MyJ0r9HVVj0Me7l45nOKPml/lOY+Jzud2g== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Alistair Francis , Atish Patra , Bin Meng Subject: [PULL v2 16/19] hw/riscv: boot: Reduce FDT address alignment constraints Date: Sun, 3 Jul 2022 10:12:31 +1000 Message-Id: <20220703001234.439716-17-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656808443607100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis We previously stored the device tree at a 16MB alignment from the end of memory (or 3GB). This means we need at least 16MB of memory to be able to do this. We don't actually need the FDT to be 16MB aligned, so let's drop it down to 2MB so that we can support systems with less memory, while also allowing FDT size expansion. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/992 Signed-off-by: Alistair Francis Reviewed-by: Atish Patra Reviewed-by: Bin Meng Tested-by: Bin Meng Message-Id: <20220608062015.317894-1-alistair.francis@opensource.wdc.com> Signed-off-by: Alistair Francis --- hw/riscv/boot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index 2d80f40b31..06b4fc5ac3 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -227,11 +227,11 @@ uint64_t riscv_load_fdt(hwaddr dram_base, uint64_t me= m_size, void *fdt) /* * We should put fdt as far as possible to avoid kernel/initrd overwri= ting * its content. But it should be addressable by 32 bit system as well. - * Thus, put it at an 16MB aligned address that less than fdt size fro= m the + * Thus, put it at an 2MB aligned address that less than fdt size from= the * end of dram or 3GB whichever is lesser. */ temp =3D (dram_base < 3072 * MiB) ? MIN(dram_end, 3072 * MiB) : dram_e= nd; - fdt_addr =3D QEMU_ALIGN_DOWN(temp - fdtsize, 16 * MiB); + fdt_addr =3D QEMU_ALIGN_DOWN(temp - fdtsize, 2 * MiB); =20 ret =3D fdt_pack(fdt); /* Should only fail if we've built a corrupted tree */ --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656807656405567.9965296755574; Sat, 2 Jul 2022 17:20:56 -0700 (PDT) Received: from localhost ([::1]:37074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nM7-0005Qy-6o for importer@patchew.org; Sat, 02 Jul 2022 20:20:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nF6-0000zs-9h for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:40 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nF4-0001p4-KK for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:39 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:17 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:40 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:18 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xt1H56z1Rwnl for ; Sat, 2 Jul 2022 17:13:18 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id bOYlZ0t_PwKN for ; Sat, 2 Jul 2022 17:13:17 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Xr1RBGz1RtVk; Sat, 2 Jul 2022 17:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807218; x=1688343218; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1ehQPeXVDCRNJyyAM0xISShVT9BsMx2tyfiNeoIZKpY=; b=OoJg7OZ9KsJvI5XNtLG8B5tQLHzWiX8xExx656TBI2KjLFeRRNbHRkMI x8XhHfE2amAYWELIHQgsWElrj9+gbziHVsw4zCpPWifL65MnAz37pVBwk Ou+7QqrEllgsinwGnijsY55ZyS3LjKedIwV7gpuIPzw8VxAGd6ubaaRR0 /cb8WnjRvii9Ihe+pek1zyOuwYThWamKZshHYSaJkCrUnUcUfiwC/iIC3 3g5i05Xb5IieKKIYrFaSiz7raL7wHyYP/EXROPMMkpm3NiqSFEABMF4hw ZSYmKnyDEKpk+bfSxyiYIxi7n0qL8kvSG5mCakbsLm95cI7JFy9pZHs+r g==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667267" IronPort-SDR: 4Jj3mRpCs7vh9Xrt6bhwxuUPoZgS+iEuzFiqyJtQpShNx5NkX/aiKflo/3WhBXrlFhCRzZYfwg fBLcZAAJOaYpJ39n5LuteztIfny0xzKLVtp8D5dF1ZP9NLjOMsuWpd3h/VgPFqQ63LZSPQicAl WbC0z0oAgG2seKR+vXIic/CWCv5Q1Pa4PJkccxSG+pKmTp78Gjf9Lbj2dUvKrXlZEXGcyVg3It N20bvKyCgRCYXQuwKdHFIyx/VPk3C4orla2s/ERx/su2s2pSBKU6Rp2f/5DvX/6s3RZ6QfDug5 G8fCS2gz0w1/+jxPkR67pHJK IronPort-SDR: 88LRsagqZEkYDYoZwhHKC4qAEGsn+YL5n4jtwukht0DuAIJLS3MhPNcYKJ3X7xsq4QJe0SdcN2 BNlRAXVcD0wk0zAtlPYEUx3GyDJ1U28e1TZT3dAP3XeDM+ouw8obhXCaKUTy1xuMIHs4YOvVek 5ZcnNm7e9LChdxFFC2PKRwyfWT00C4+1OQK2xm/5Yqfr5kC05jtzOf6zWcitzXtvEO3Gnys5XQ 36LxGqabc2vQOwdj6BD+MNmvBRVici/eSkR0i1CQbYhI0mVAk6n4fUyRvMsCXpvE7E2jaOgwF+ cQQ= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807197; x=1659399198; bh=1ehQPeXVDCRNJyyAM0 xISShVT9BsMx2tyfiNeoIZKpY=; b=ZiRYlnlNxRCmib36xqhNd87XbItrBeV8Ew OIcAFXA64Be+E+ZkVG4gLBPGKLjK7cYVXsCAThefH2EBL7i0bTS7uSoxY6NLeDhN 566+Ga67eLbKS3Jp0K2X1ijBVwlckqHD4sDqkM2vXI8bDCEISSbGKxC+vN0ixA/B qBqXojhp3Ip6AyrMRQ1YhdssvHtXHK65cyKAnVp9gsdROG+R42qcscOAY/riz7v+ 4xndWJqRdcdI3zWskK4mnZLVyy3ix0BZIAlw3BKZBrlRT0d4VVTd33BdGP8ONtaH A4hpY16sYHtLGgzT2IhHLrM9rCwh8idcd3xEAL6VZoK0xBXJTT8g== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Anup Patel , Alistair Francis Subject: [PULL v2 17/19] target/riscv: Set minumum priv spec version for mcountinhibit Date: Sun, 3 Jul 2022 10:12:32 +1000 Message-Id: <20220703001234.439716-18-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807657787100003 Content-Type: text/plain; charset="utf-8" From: Anup Patel The minimum priv spec versino for mcountinhibit to v1.11 so that it is not available for v1.10 (or lower). Fixes: eab4776b2bad ("target/riscv: Add support for hpmcounters/hpmevents") Signed-off-by: Anup Patel Reviewed-by: Alistair Francis Message-Id: <20220628101737.786681-3-apatel@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d14a0cb0a0..4982e98735 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3944,7 +3944,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { write_mhpmcounter }, =20 [CSR_MCOUNTINHIBIT] =3D { "mcountinhibit", any, read_mcountinhibit, - write_mcountinhibit }, + write_mcountinhibit, .min_priv_ver =3D PRIV_VERSION_1_11_0 = }, =20 [CSR_MHPMEVENT3] =3D { "mhpmevent3", any, read_mhpmevent, write_mhpmevent }, --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656808457782114.59065775605234; Sat, 2 Jul 2022 17:34:17 -0700 (PDT) Received: from localhost ([::1]:37946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nZ2-0000R1-Ia for importer@patchew.org; Sat, 02 Jul 2022 20:34:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nFF-0001V9-3M for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:49 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nFC-0001zT-Pq for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:48 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:20 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:43 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:21 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xw60tJz1RwqM for ; Sat, 2 Jul 2022 17:13:20 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id CHyLKckgBVGa for ; Sat, 2 Jul 2022 17:13:19 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Xt2WHJz1RtVk; Sat, 2 Jul 2022 17:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807225; x=1688343225; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pHuvF8R26SN2gMqYKCO1XIj3tlF9Xk0AZHCTtMpzao4=; b=WEcm/hF0+fyZ3vDlzm0O7hek85mu2kQc01HLEjaP8nrlCIjtIyTBfYCM fEX1mQaKS7iChZznJBC55koWIHvlv5IeBL6OG7/hgZ5ueoGKzpDO4TmhF AxsplkS05D6QZtuLPWI4gRuE0zUWUIWzbuG6yrZAhR9lHJb33+ECaW708 XyLVBY09ViFutpqgRLoSg0rZblmoLnY147/oBFEtDtpK71GxVio7+M4ry zuMxATZj5zVz2ROSAiHaXRpvK3vrrcEO59Mcx2+x8SikqZxtHK133UcJm oYaK73+0eAL9RMcjOB7YcucwERuAQlAvREztYMtisbMpiKBUY6m5wrcFQ g==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667276" IronPort-SDR: QovwY8ryVaeFDZqKuj0+DwpcKTP0Jw1qV7r/R61aA3PzNqDpend5rMGCd7+9dOREVR3vePOPo1 WzGlZ8pvvbQmvynN+L+1DvSxfJMYuCljYCKpCqjSLLgce1SPrkBV0BjViLHPMVIhsM6XFrM1u7 bH1isaZUoLSqShZi8NIvq5YHbmgb0jlrsFgtP8oNYDkLGFgHBOaWbz/T1eynOp105SR8Xe+19b LYNdS+CI9oatoZUrDQTts/8uia7rU/iRhGvwvssGvMMBZfibC/FsWekVjS3in5bSlh8t2qIm0W vbsBJZph3FL4AttFK3WPu+qn IronPort-SDR: IWgS69m+SdaaTXQQh3IALy1MpI4qDde2gOD9xYQpUlI79dw2V2J44NdkN8xlgLAN9u/or1FSH0 wzIE/8WrjewDL/WGqm8fra3xOPX5s8hXJT2I2kOxJnmU+kT5/JDInlID/iOrxFti9g42/MKCJ2 tZeCg3bm8ZP8pXN18TLc1vb2D70d1KSd+iPJR6C6Q9wVyJSseqxXPLks1FzJLvt2jTWi7b61Qn kk3fkiECkDnX0XS4EFZDT/WgQZH1Pizu4sI9kWJTsYwU4KuM1MwL7Jrx5kiB91XCGgIUgKUhhq wSY= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807199; x=1659399200; bh=pHuvF8R26SN2gMqYKC O1XIj3tlF9Xk0AZHCTtMpzao4=; b=kVw6YOzTH7RiRuLqpXYJsAgtUsTYOMqcmO fKgphMhPd/VCy3ioNdOMHHEZM28yJCx3oyr4QQIQQIHdAbCwVNDgLrdPLvLBW2pN r0oto2E3CXpTLNLh7ZK3dN08sRyqRBWyd1RPAvDf0Yv8CKHxTUTG1DNt+MtDzAkO 0Myhla8Uz8ChGuFNQDc0Ik8UcmkDWxHyCJ6iGrfFM1qlfJ38V3KTbXHjbdVBT/fj P5z902dfYQ3T7iKfguSotTr5O3pHvLpWkw4AvbuOjZpPJnFVkViwjSky0XcwmJAd A+8UXVu6n8bArUlAsiuw4u6nP9zrKoVm20ajeh1UIySD3+OmM3Qw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Anup Patel , Alistair Francis Subject: [PULL v2 18/19] target/riscv: Remove CSRs that set/clear an IMSIC interrupt file bits Date: Sun, 3 Jul 2022 10:12:33 +1000 Message-Id: <20220703001234.439716-19-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656808459354100001 Content-Type: text/plain; charset="utf-8" From: Anup Patel Based on architecture review committee feedback, the [m|s|vs]seteienum, [m|s|vs]clreienum, [m|s|vs]seteipnum, and [m|s|vs]clreipnum CSRs are removed in the latest AIA draft v0.3.0 specification. (Refer, https://github.com/riscv/riscv-aia/releases/tag/0.3.0-draft.31) These CSRs were mostly for software convenience and software can always use [m|s|vs]iselect and [m|s|vs]ireg CSRs to update the IMSIC interrupt file bits. We update the IMSIC CSR emulation as-per above to match the latest AIA draft specification. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis Message-Id: <20220616031543.953776-2-apatel@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/cpu_bits.h | 24 +------ target/riscv/csr.c | 150 +--------------------------------------- 2 files changed, 6 insertions(+), 168 deletions(-) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index b3f7fa7130..157d7069f6 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -174,14 +174,8 @@ #define CSR_MIREG 0x351 =20 /* Machine-Level Interrupts (AIA) */ -#define CSR_MTOPI 0xfb0 - -/* Machine-Level IMSIC Interface (AIA) */ -#define CSR_MSETEIPNUM 0x358 -#define CSR_MCLREIPNUM 0x359 -#define CSR_MSETEIENUM 0x35a -#define CSR_MCLREIENUM 0x35b #define CSR_MTOPEI 0x35c +#define CSR_MTOPI 0xfb0 =20 /* Virtual Interrupts for Supervisor Level (AIA) */ #define CSR_MVIEN 0x308 @@ -221,14 +215,8 @@ #define CSR_SIREG 0x151 =20 /* Supervisor-Level Interrupts (AIA) */ -#define CSR_STOPI 0xdb0 - -/* Supervisor-Level IMSIC Interface (AIA) */ -#define CSR_SSETEIPNUM 0x158 -#define CSR_SCLREIPNUM 0x159 -#define CSR_SSETEIENUM 0x15a -#define CSR_SCLREIENUM 0x15b #define CSR_STOPEI 0x15c +#define CSR_STOPI 0xdb0 =20 /* Supervisor-Level High-Half CSRs (AIA) */ #define CSR_SIEH 0x114 @@ -279,14 +267,8 @@ #define CSR_VSIREG 0x251 =20 /* VS-Level Interrupts (H-extension with AIA) */ -#define CSR_VSTOPI 0xeb0 - -/* VS-Level IMSIC Interface (H-extension with AIA) */ -#define CSR_VSSETEIPNUM 0x258 -#define CSR_VSCLREIPNUM 0x259 -#define CSR_VSSETEIENUM 0x25a -#define CSR_VSCLREIENUM 0x25b #define CSR_VSTOPEI 0x25c +#define CSR_VSTOPI 0xeb0 =20 /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ #define CSR_HIDELEGH 0x613 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 4982e98735..235f2a011e 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1257,14 +1257,6 @@ static int aia_xlate_vs_csrno(CPURISCVState *env, in= t csrno) return CSR_VSISELECT; case CSR_SIREG: return CSR_VSIREG; - case CSR_SSETEIPNUM: - return CSR_VSSETEIPNUM; - case CSR_SCLREIPNUM: - return CSR_VSCLREIPNUM; - case CSR_SSETEIENUM: - return CSR_VSSETEIENUM; - case CSR_SCLREIENUM: - return CSR_VSCLREIENUM; case CSR_STOPEI: return CSR_VSTOPEI; default: @@ -1419,124 +1411,6 @@ done: return RISCV_EXCP_NONE; } =20 -static int rmw_xsetclreinum(CPURISCVState *env, int csrno, target_ulong *v= al, - target_ulong new_val, target_ulong wr_mask) -{ - int ret =3D -EINVAL; - bool set, pend, virt; - target_ulong priv, isel, vgein, xlen, nval, wmask; - - /* Translate CSR number for VS-mode */ - csrno =3D aia_xlate_vs_csrno(env, csrno); - - /* Decode register details from CSR number */ - virt =3D set =3D pend =3D false; - switch (csrno) { - case CSR_MSETEIPNUM: - priv =3D PRV_M; - set =3D true; - pend =3D true; - break; - case CSR_MCLREIPNUM: - priv =3D PRV_M; - pend =3D true; - break; - case CSR_MSETEIENUM: - priv =3D PRV_M; - set =3D true; - break; - case CSR_MCLREIENUM: - priv =3D PRV_M; - break; - case CSR_SSETEIPNUM: - priv =3D PRV_S; - set =3D true; - pend =3D true; - break; - case CSR_SCLREIPNUM: - priv =3D PRV_S; - pend =3D true; - break; - case CSR_SSETEIENUM: - priv =3D PRV_S; - set =3D true; - break; - case CSR_SCLREIENUM: - priv =3D PRV_S; - break; - case CSR_VSSETEIPNUM: - priv =3D PRV_S; - virt =3D true; - set =3D true; - pend =3D true; - break; - case CSR_VSCLREIPNUM: - priv =3D PRV_S; - virt =3D true; - pend =3D true; - break; - case CSR_VSSETEIENUM: - priv =3D PRV_S; - virt =3D true; - set =3D true; - break; - case CSR_VSCLREIENUM: - priv =3D PRV_S; - virt =3D true; - break; - default: - goto done; - }; - - /* IMSIC CSRs only available when machine implements IMSIC. */ - if (!env->aia_ireg_rmw_fn[priv]) { - goto done; - } - - /* Find the selected guest interrupt file */ - vgein =3D (virt) ? get_field(env->hstatus, HSTATUS_VGEIN) : 0; - - /* Selected guest interrupt file should be valid */ - if (virt && (!vgein || env->geilen < vgein)) { - goto done; - } - - /* Set/Clear CSRs always read zero */ - if (val) { - *val =3D 0; - } - - if (wr_mask) { - /* Get interrupt number */ - new_val &=3D wr_mask; - - /* Find target interrupt pending/enable register */ - xlen =3D riscv_cpu_mxl_bits(env); - isel =3D (new_val / xlen); - isel *=3D (xlen / IMSIC_EIPx_BITS); - isel +=3D (pend) ? ISELECT_IMSIC_EIP0 : ISELECT_IMSIC_EIE0; - - /* Find the interrupt bit to be set/clear */ - wmask =3D ((target_ulong)1) << (new_val % xlen); - nval =3D (set) ? wmask : 0; - - /* Call machine specific IMSIC register emulation */ - ret =3D env->aia_ireg_rmw_fn[priv](env->aia_ireg_rmw_fn_arg[priv], - AIA_MAKE_IREG(isel, priv, virt, - vgein, xlen), - NULL, nval, wmask); - } else { - ret =3D 0; - } - -done: - if (ret) { - return (riscv_cpu_virt_enabled(env) && virt) ? - RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; - } - return RISCV_EXCP_NONE; -} - static int rmw_xtopei(CPURISCVState *env, int csrno, target_ulong *val, target_ulong new_val, target_ulong wr_mask) { @@ -3658,14 +3532,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MIREG] =3D { "mireg", aia_any, NULL, NULL, rmw_xireg }, =20 /* Machine-Level Interrupts (AIA) */ - [CSR_MTOPI] =3D { "mtopi", aia_any, read_mtopi }, - - /* Machine-Level IMSIC Interface (AIA) */ - [CSR_MSETEIPNUM] =3D { "mseteipnum", aia_any, NULL, NULL, rmw_xsetclre= inum }, - [CSR_MCLREIPNUM] =3D { "mclreipnum", aia_any, NULL, NULL, rmw_xsetclre= inum }, - [CSR_MSETEIENUM] =3D { "mseteienum", aia_any, NULL, NULL, rmw_xsetclre= inum }, - [CSR_MCLREIENUM] =3D { "mclreienum", aia_any, NULL, NULL, rmw_xsetclre= inum }, [CSR_MTOPEI] =3D { "mtopei", aia_any, NULL, NULL, rmw_xtopei }, + [CSR_MTOPI] =3D { "mtopi", aia_any, read_mtopi }, =20 /* Virtual Interrupts for Supervisor Level (AIA) */ [CSR_MVIEN] =3D { "mvien", aia_any, read_zero, write_ignore }, @@ -3713,14 +3581,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_SIREG] =3D { "sireg", aia_smode, NULL, NULL, rmw_xireg = }, =20 /* Supervisor-Level Interrupts (AIA) */ - [CSR_STOPI] =3D { "stopi", aia_smode, read_stopi }, - - /* Supervisor-Level IMSIC Interface (AIA) */ - [CSR_SSETEIPNUM] =3D { "sseteipnum", aia_smode, NULL, NULL, rmw_xsetcl= reinum }, - [CSR_SCLREIPNUM] =3D { "sclreipnum", aia_smode, NULL, NULL, rmw_xsetcl= reinum }, - [CSR_SSETEIENUM] =3D { "sseteienum", aia_smode, NULL, NULL, rmw_xsetcl= reinum }, - [CSR_SCLREIENUM] =3D { "sclreienum", aia_smode, NULL, NULL, rmw_xsetcl= reinum }, [CSR_STOPEI] =3D { "stopei", aia_smode, NULL, NULL, rmw_xtopei= }, + [CSR_STOPI] =3D { "stopi", aia_smode, read_stopi }, =20 /* Supervisor-Level High-Half CSRs (AIA) */ [CSR_SIEH] =3D { "sieh", aia_smode32, NULL, NULL, rmw_sieh }, @@ -3792,14 +3654,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_VSIREG] =3D { "vsireg", aia_hmode, NULL, NULL, rmw= _xireg }, =20 /* VS-Level Interrupts (H-extension with AIA) */ - [CSR_VSTOPI] =3D { "vstopi", aia_hmode, read_vstopi }, - - /* VS-Level IMSIC Interface (H-extension with AIA) */ - [CSR_VSSETEIPNUM] =3D { "vsseteipnum", aia_hmode, NULL, NULL, rmw_xset= clreinum }, - [CSR_VSCLREIPNUM] =3D { "vsclreipnum", aia_hmode, NULL, NULL, rmw_xset= clreinum }, - [CSR_VSSETEIENUM] =3D { "vsseteienum", aia_hmode, NULL, NULL, rmw_xset= clreinum }, - [CSR_VSCLREIENUM] =3D { "vsclreienum", aia_hmode, NULL, NULL, rmw_xset= clreinum }, [CSR_VSTOPEI] =3D { "vstopei", aia_hmode, NULL, NULL, rmw_xtop= ei }, + [CSR_VSTOPI] =3D { "vstopi", aia_hmode, read_vstopi }, =20 /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] =3D { "hidelegh", aia_hmode32, NULL, NULL, rmw_hi= delegh }, --=20 2.36.1 From nobody Fri Dec 19 06:18:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165680796960977.77616911201619; Sat, 2 Jul 2022 17:26:09 -0700 (PDT) Received: from localhost ([::1]:51828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7nRA-0007DE-I7 for importer@patchew.org; Sat, 02 Jul 2022 20:26:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nFG-0001Ys-1I for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:50 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:46191) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7nFE-00021g-02 for qemu-devel@nongnu.org; Sat, 02 Jul 2022 20:13:49 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jul 2022 08:13:21 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 16:30:44 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Jul 2022 17:13:22 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Lb8Xy0szJz1Rwnl for ; Sat, 2 Jul 2022 17:13:22 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id CAa3zX7atjTl for ; Sat, 2 Jul 2022 17:13:21 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.123]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Lb8Xw2nLFz1Rw4L; Sat, 2 Jul 2022 17:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656807226; x=1688343226; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lveJUEN4lzVWHZY7Q+NLuNHznSV4Bm0HQn0yhdEnRSo=; b=P3LFQgWteJ/pe8fCDk7fxNNfd2uNOhaXaLHC0oapPKLM7SSS+NmkbFAQ GdA5WtpISm1LtXYsL4EkJJRUNywxvHbKjkrzU9TgTiGeYcyxFt3iPamDb jxmnhT/Vs7cX8cwk417rajP2Mo4SyZHsCyiw6yAewKrmnCynXJ23GhT7s Y6z9B5+c2dmkSoM09P2jW4Tpnzt8EaImOg4scISWmKl/Wg77prYNz3QQw sQzzkTNw1/UIbgs6YDLbyo27fvd+Omiot703cHib8x/wwYsTs9fABDnZv zpbQJADI01KMAKxpMn7R3QgW4PXixk3ghTf7aQe4Q+QOgqjii9EBWVX6z g==; X-IronPort-AV: E=Sophos;i="5.92,241,1650902400"; d="scan'208";a="204667279" IronPort-SDR: 2VRPJCrupan0sJeHQqXGNhl9uaUnTqAFUS6KE22ZtI0SUHOlmcu6Ckrt2hYxmKKmFzezC0cYin 56VlFjglNN3O+DEhbbNOFcGiUXLiyvUECAlssmuKtLjTVdn/kteCm7R6HPL/Me2P3nwei/Z1Wu TOzai+aBiNJJWy8QFwvPu+gIQ9JrYboxCUXYN2gkH7CRY3Kp7BC/TGgYkCp9ca4HK3KqRLJJVE zDfhIBIB2wgUju/nJelNx2hRng56PSoz8pg5UPUFdErwWYdbVpXUsFtb8Sg+Qw90zgigcbaZbH sGC9C42tN5G5MY0UAilIv9/X IronPort-SDR: ql4Jrzzr7eZHPrDXMwvUbYwm0xuqxmq0R8aK88lFWprDXAousbJZijI0CBjUL7RPdM9WtwsqvC AJIez90EHUtrDtZ1GwoGBmeam3zxiyjiWxXZjFdtZUTqPtaNhgCsPj2S81Rl/6NGwzi6F/kOaS mZBn71Ai8eDLreV/tWYDipOG3NvyXAm+iTIMFXh5dGLeZxarfXIDpgleQSd4W061Na8kaP/Jof pr+z3BSpq4/mS/XM2kJQqOaJcXAsVNN4auQaCqUgFc1NP5Tiu5U5NcmftS2kyjS5HB+xjDvNxI uNw= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1656807201; x=1659399202; bh=lveJUEN4lzVWHZY7Q+ NLuNHznSV4Bm0HQn0yhdEnRSo=; b=Q7mZybKhfbcVx5kQ1AlEqua+PK6UE0WeFt BeaRoMCyByTQYXGncw4PX96+H8dtjqFghmWKNkpazzhL5vwPyR/FmM1Zt2TmIfPV YRiJEhicMjwLBU55RwVdXGrfMUf+wAkf9OvSnDgDj6VKlJil47+IyLm3bBsSpUIE fc3EVOfGi+FHUm/LRKtYKMphA2ICgEUJJei4UMApWteDkpLhVXLRwoddXJ8eEw5A QmVTjNnCDx9iFUWNSEB2XLZL28ghhBokU8LEEofJt+Cg1nEOdurVNOSAyPqnFNVg vKk1zFR63QAiAXFvzSmJgwrqyF5htPEdPaEMjBtLXrfbg7rIFC7w== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Anup Patel , Alistair Francis Subject: [PULL v2 19/19] target/riscv: Update default priority table for local interrupts Date: Sun, 3 Jul 2022 10:12:34 +1000 Message-Id: <20220703001234.439716-20-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> References: <20220703001234.439716-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=176813b30=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1656807971028100001 Content-Type: text/plain; charset="utf-8" From: Anup Patel The latest AIA draft v0.3.0 defines a relatively simpler scheme for default priority assignments where: 1) local interrupts 24 to 31 and 48 to 63 are reserved for custom use and have implementation specific default priority. 2) remaining local interrupts 0 to 23 and 32 to 47 have a recommended (not mandatory) priority assignments. We update the default priority table and hviprio mapping as-per above. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis Message-Id: <20220616031543.953776-3-apatel@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/cpu_bits.h | 2 +- target/riscv/cpu_helper.c | 134 ++++++++++++++++++-------------------- 2 files changed, 66 insertions(+), 70 deletions(-) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 157d7069f6..6be5a9e9f0 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -774,7 +774,7 @@ typedef enum RISCVException { #define IPRIO_IRQ_BITS 8 #define IPRIO_MMAXIPRIO 255 #define IPRIO_DEFAULT_UPPER 4 -#define IPRIO_DEFAULT_MIDDLE (IPRIO_DEFAULT_UPPER + 24) +#define IPRIO_DEFAULT_MIDDLE (IPRIO_DEFAULT_UPPER + 12) #define IPRIO_DEFAULT_M IPRIO_DEFAULT_MIDDLE #define IPRIO_DEFAULT_S (IPRIO_DEFAULT_M + 3) #define IPRIO_DEFAULT_SGEXT (IPRIO_DEFAULT_S + 3) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index be28615e23..59b3680b1b 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -168,17 +168,17 @@ void riscv_cpu_update_mask(CPURISCVState *env) * 14 " * 15 " * 16 " - * 18 Debug/trace interrupt - * 20 (Reserved interrupt) + * 17 " + * 18 " + * 19 " + * 20 " + * 21 " * 22 " - * 24 " - * 26 " - * 28 " - * 30 (Reserved for standard reporting of bus or system errors) + * 23 " */ =20 static const int hviprio_index2irq[] =3D { - 0, 1, 4, 5, 8, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30 }; + 0, 1, 4, 5, 8, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }; static const int hviprio_index2rdzero[] =3D { 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; =20 @@ -207,50 +207,60 @@ int riscv_cpu_hviprio_index2irq(int index, int *out_i= rq, int *out_rdzero) * Default | * Priority | Major Interrupt Numbers * ---------------------------------------------------------------- - * Highest | 63 (3f), 62 (3e), 31 (1f), 30 (1e), 61 (3d), 60 (3c), - * | 59 (3b), 58 (3a), 29 (1d), 28 (1c), 57 (39), 56 (38), - * | 55 (37), 54 (36), 27 (1b), 26 (1a), 53 (35), 52 (34), - * | 51 (33), 50 (32), 25 (19), 24 (18), 49 (31), 48 (30) + * Highest | 47, 23, 46, 45, 22, 44, + * | 43, 21, 42, 41, 20, 40 * | * | 11 (0b), 3 (03), 7 (07) * | 9 (09), 1 (01), 5 (05) * | 12 (0c) * | 10 (0a), 2 (02), 6 (06) * | - * | 47 (2f), 46 (2e), 23 (17), 22 (16), 45 (2d), 44 (2c), - * | 43 (2b), 42 (2a), 21 (15), 20 (14), 41 (29), 40 (28), - * | 39 (27), 38 (26), 19 (13), 18 (12), 37 (25), 36 (24), - * Lowest | 35 (23), 34 (22), 17 (11), 16 (10), 33 (21), 32 (20) + * | 39, 19, 38, 37, 18, 36, + * Lowest | 35, 17, 34, 33, 16, 32 * ---------------------------------------------------------------- */ static const uint8_t default_iprio[64] =3D { - [63] =3D IPRIO_DEFAULT_UPPER, - [62] =3D IPRIO_DEFAULT_UPPER + 1, - [31] =3D IPRIO_DEFAULT_UPPER + 2, - [30] =3D IPRIO_DEFAULT_UPPER + 3, - [61] =3D IPRIO_DEFAULT_UPPER + 4, - [60] =3D IPRIO_DEFAULT_UPPER + 5, - - [59] =3D IPRIO_DEFAULT_UPPER + 6, - [58] =3D IPRIO_DEFAULT_UPPER + 7, - [29] =3D IPRIO_DEFAULT_UPPER + 8, - [28] =3D IPRIO_DEFAULT_UPPER + 9, - [57] =3D IPRIO_DEFAULT_UPPER + 10, - [56] =3D IPRIO_DEFAULT_UPPER + 11, - - [55] =3D IPRIO_DEFAULT_UPPER + 12, - [54] =3D IPRIO_DEFAULT_UPPER + 13, - [27] =3D IPRIO_DEFAULT_UPPER + 14, - [26] =3D IPRIO_DEFAULT_UPPER + 15, - [53] =3D IPRIO_DEFAULT_UPPER + 16, - [52] =3D IPRIO_DEFAULT_UPPER + 17, - - [51] =3D IPRIO_DEFAULT_UPPER + 18, - [50] =3D IPRIO_DEFAULT_UPPER + 19, - [25] =3D IPRIO_DEFAULT_UPPER + 20, - [24] =3D IPRIO_DEFAULT_UPPER + 21, - [49] =3D IPRIO_DEFAULT_UPPER + 22, - [48] =3D IPRIO_DEFAULT_UPPER + 23, + /* Custom interrupts 48 to 63 */ + [63] =3D IPRIO_MMAXIPRIO, + [62] =3D IPRIO_MMAXIPRIO, + [61] =3D IPRIO_MMAXIPRIO, + [60] =3D IPRIO_MMAXIPRIO, + [59] =3D IPRIO_MMAXIPRIO, + [58] =3D IPRIO_MMAXIPRIO, + [57] =3D IPRIO_MMAXIPRIO, + [56] =3D IPRIO_MMAXIPRIO, + [55] =3D IPRIO_MMAXIPRIO, + [54] =3D IPRIO_MMAXIPRIO, + [53] =3D IPRIO_MMAXIPRIO, + [52] =3D IPRIO_MMAXIPRIO, + [51] =3D IPRIO_MMAXIPRIO, + [50] =3D IPRIO_MMAXIPRIO, + [49] =3D IPRIO_MMAXIPRIO, + [48] =3D IPRIO_MMAXIPRIO, + + /* Custom interrupts 24 to 31 */ + [31] =3D IPRIO_MMAXIPRIO, + [30] =3D IPRIO_MMAXIPRIO, + [29] =3D IPRIO_MMAXIPRIO, + [28] =3D IPRIO_MMAXIPRIO, + [27] =3D IPRIO_MMAXIPRIO, + [26] =3D IPRIO_MMAXIPRIO, + [25] =3D IPRIO_MMAXIPRIO, + [24] =3D IPRIO_MMAXIPRIO, + + [47] =3D IPRIO_DEFAULT_UPPER, + [23] =3D IPRIO_DEFAULT_UPPER + 1, + [46] =3D IPRIO_DEFAULT_UPPER + 2, + [45] =3D IPRIO_DEFAULT_UPPER + 3, + [22] =3D IPRIO_DEFAULT_UPPER + 4, + [44] =3D IPRIO_DEFAULT_UPPER + 5, + + [43] =3D IPRIO_DEFAULT_UPPER + 6, + [21] =3D IPRIO_DEFAULT_UPPER + 7, + [42] =3D IPRIO_DEFAULT_UPPER + 8, + [41] =3D IPRIO_DEFAULT_UPPER + 9, + [20] =3D IPRIO_DEFAULT_UPPER + 10, + [40] =3D IPRIO_DEFAULT_UPPER + 11, =20 [11] =3D IPRIO_DEFAULT_M, [3] =3D IPRIO_DEFAULT_M + 1, @@ -266,33 +276,19 @@ static const uint8_t default_iprio[64] =3D { [2] =3D IPRIO_DEFAULT_VS + 1, [6] =3D IPRIO_DEFAULT_VS + 2, =20 - [47] =3D IPRIO_DEFAULT_LOWER, - [46] =3D IPRIO_DEFAULT_LOWER + 1, - [23] =3D IPRIO_DEFAULT_LOWER + 2, - [22] =3D IPRIO_DEFAULT_LOWER + 3, - [45] =3D IPRIO_DEFAULT_LOWER + 4, - [44] =3D IPRIO_DEFAULT_LOWER + 5, - - [43] =3D IPRIO_DEFAULT_LOWER + 6, - [42] =3D IPRIO_DEFAULT_LOWER + 7, - [21] =3D IPRIO_DEFAULT_LOWER + 8, - [20] =3D IPRIO_DEFAULT_LOWER + 9, - [41] =3D IPRIO_DEFAULT_LOWER + 10, - [40] =3D IPRIO_DEFAULT_LOWER + 11, - - [39] =3D IPRIO_DEFAULT_LOWER + 12, - [38] =3D IPRIO_DEFAULT_LOWER + 13, - [19] =3D IPRIO_DEFAULT_LOWER + 14, - [18] =3D IPRIO_DEFAULT_LOWER + 15, - [37] =3D IPRIO_DEFAULT_LOWER + 16, - [36] =3D IPRIO_DEFAULT_LOWER + 17, - - [35] =3D IPRIO_DEFAULT_LOWER + 18, - [34] =3D IPRIO_DEFAULT_LOWER + 19, - [17] =3D IPRIO_DEFAULT_LOWER + 20, - [16] =3D IPRIO_DEFAULT_LOWER + 21, - [33] =3D IPRIO_DEFAULT_LOWER + 22, - [32] =3D IPRIO_DEFAULT_LOWER + 23, + [39] =3D IPRIO_DEFAULT_LOWER, + [19] =3D IPRIO_DEFAULT_LOWER + 1, + [38] =3D IPRIO_DEFAULT_LOWER + 2, + [37] =3D IPRIO_DEFAULT_LOWER + 3, + [18] =3D IPRIO_DEFAULT_LOWER + 4, + [36] =3D IPRIO_DEFAULT_LOWER + 5, + + [35] =3D IPRIO_DEFAULT_LOWER + 6, + [17] =3D IPRIO_DEFAULT_LOWER + 7, + [34] =3D IPRIO_DEFAULT_LOWER + 8, + [33] =3D IPRIO_DEFAULT_LOWER + 9, + [16] =3D IPRIO_DEFAULT_LOWER + 10, + [32] =3D IPRIO_DEFAULT_LOWER + 11, }; =20 uint8_t riscv_cpu_default_priority(int irq) --=20 2.36.1