From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686281; cv=none; d=zohomail.com; s=zohoarc; b=n3DYBot7a0/vQcu73TUaO/XqVS272bhAc4zMZzuXee4cd+4/+Ac0H+FNznZF/8IH7lCOb2TSKG5EAu3Z7vFym/2hi7Er9rdYjZHK5ByQOrzW2EPLpQO+JlKxqFFBmjfacgdLMIW0JgxgYZKmXBlsP3Lf4eRmi3TUjYSKAYvXPhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686281; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/xTvsa+ViAqHINj5oJb/iz6qO9j2BBr+FG4wAjwt7ac=; b=Rn+aFZ/GwZdl8pQeEDog1VIaFJyfTTGEmK/SIqDzMulEDzBh0qhFRWYswuLtmaoW4PFgeanPWtO3SnvKUr0TDHbmxG+m5Fz8ubwZmdu1yoAlsCXY/lcQiXsShekSbO1dzgNDvuboiiG07sFO+pKepGH/Hf+IPwl+rMkk/DiVsQA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172468628100041.9157170526006; Mon, 26 Aug 2024 08:31:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibfd-00088q-Jx; Mon, 26 Aug 2024 11:30:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfb-00084b-8z for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:15 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfZ-0003bV-AZ for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:14 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-7cda0453766so1368771a12.2 for ; Mon, 26 Aug 2024 08:30:12 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686212; x=1725291012; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/xTvsa+ViAqHINj5oJb/iz6qO9j2BBr+FG4wAjwt7ac=; b=l2pnxELVSFt7Wn4v13X6dOR4Lw8kR4P2bvPMPZbIWUaKIKSUCsknz+ICd6dE/Js5Ke /Ji8MJx9vPcky5QMXB7jpCbK1xrahAsVQLrxWDHkloZ7IZOtLWuhbwtw5Nipo7R7yEs8 se8YVTBSGxwoURtBHk4dfW5II8W5RLu0mTkiHSFJKWDuvKChuv1MaLanll5HAGzeodQc CDgKUNSNzolschT+F/h5PizMRTQcgWtBM3ZdNedFHK8PI9qzOpxxCwALfAIFJvSnnz4C dY5nxuuor6JlVwCXkCPDZOsF/5bTf3blxciWRsaQ9+OECbxQ5SwP39OnEZ+iHjeo43MM 0P2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686212; x=1725291012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/xTvsa+ViAqHINj5oJb/iz6qO9j2BBr+FG4wAjwt7ac=; b=PoOBe/HUjpC/T9zjorFfH9jhD9yoWxnR0T5PdZkAEe2anc7o2FZnV+G9r7Xf7Z7YEy Iasj9tEOjXwcI2ADAQke2UGp7lNlTNyVdmv4vilkXThZs33lhsnAC1SAV95s/cus2P8H DV1sh085FgcaQ6cNUf+mm6UepQ6eH2IZ3SjPKLRc5zGbRysDuoyTNDMjCCa3L6Mkj1+G H7XJksIDIl0yt2iK5PJP8u8pITfnnhKMFmt9jy0pNUZfiwkjSrDK3cLYiDMGbWqaKDGx AE5adOQ5Gla7eELYwm4npvzKAX1vIqpEvcOlTo49g8/IfU8SJXxTo36a284kog6CjMNF MYgA== X-Forwarded-Encrypted: i=1; AJvYcCV6MqhHRaV+nFZR2uwbTpLx4U84kRKGutppsyatudFRMHUoX2JBKvgIY8oorSGTkZPYyBCeFefdi4W0@nongnu.org X-Gm-Message-State: AOJu0YyeghVamdIB9kjQKYmLj+ravXWnfvBCv5UwUazKei2gC0Fb9eS+ wKJGe9T97di04JPPxuHaeBHfxZmNXdn9qvlLksUeKOjl+vPvZgJRVlQ59A3YHq8= X-Google-Smtp-Source: AGHT+IGXZOD7lUonxiusPhafAwxJOXgJrPe/DG7AJ19264w8bUDd0a5Ps6ejf+fZRFPnoLlpUrw6WQ== X-Received: by 2002:a05:6a21:e591:b0:1c0:e46a:1643 with SMTP id adf61e73a8af0-1cc89dd1588mr12856982637.31.1724686211705; Mon, 26 Aug 2024 08:30:11 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 01/17] target/riscv: Add zicfilp extension Date: Mon, 26 Aug 2024 08:29:33 -0700 Message-ID: <20240826152949.294506-2-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::52c; envelope-from=debug@rivosinc.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686281621116600 Content-Type: text/plain; charset="utf-8" zicfilp [1] riscv cpu extension enables forward control flow integrity. If enabled, all indirect calls must land on a landing pad instruction. This patch sets up space for zicfilp extension in cpuconfig. zicfilp is dependend on zicsr. [1] - https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu --- target/riscv/cpu.c | 2 ++ target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 33ef4eb795..5dfb3f39ab 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -106,6 +106,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(ziccif, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(zicclsm, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(ziccrse, PRIV_VERSION_1_11_0, has_priv_1_11), + ISA_EXT_DATA_ENTRY(zicfilp, PRIV_VERSION_1_12_0, ext_zicfilp), ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond), ISA_EXT_DATA_ENTRY(zicntr, PRIV_VERSION_1_12_0, ext_zicntr), ISA_EXT_DATA_ENTRY(zicsr, PRIV_VERSION_1_10_0, ext_zicsr), @@ -1472,6 +1473,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { /* Defaults for standard extensions */ MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), + MULTI_EXT_CFG_BOOL("zicfilp", ext_zicfilp, false), MULTI_EXT_CFG_BOOL("zicsr", ext_zicsr, true), MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), MULTI_EXT_CFG_BOOL("zihintpause", ext_zihintpause, true), diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 120905a254..88d5defbb5 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -67,6 +67,7 @@ struct RISCVCPUConfig { bool ext_zicbom; bool ext_zicbop; bool ext_zicboz; + bool ext_zicfilp; bool ext_zicond; bool ext_zihintntl; bool ext_zihintpause; diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index b8814ab753..ed19586c9d 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -623,6 +623,11 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, = Error **errp) cpu->pmu_avail_ctrs =3D 0; } =20 + if (cpu->cfg.ext_zicfilp && !cpu->cfg.ext_zicsr) { + error_setg(errp, "zicfilp extension requires zicsr extension"); + return; + } + /* * Disable isa extensions based on priv spec after we * validated and set everything we need. --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686249; cv=none; d=zohomail.com; s=zohoarc; b=L1dY2z541ZUQTNdlCanBIYJbKTU4GVv7YgpNWoMIn3uR/XF25cY7eCUt2hvrp3y8CxvwZhbhcVYwiRzuVmZIhDL8rKGa3gDHMjSJ0f9+3tGF7uUD/jczeIdmYN4fqXK2HaV2mEA7ZPM0+5FbhoeiU0EUU6+pbal8DeS3qYvlg00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686249; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PRQLflAmXFEQshk7wJA80BTXWF9mr3mMeQvq+HP93Dg=; b=XN3bDb1EnsVzWJ3yV9yd1kkzvIMUXntqmTzKqzHex4uxRhkiqbM/yUt/7XJb2u5RtxMdoL+HOGXtAFfmV+7+512CGAU9WP9oLk9SV5UMZdmC3uJRd/5Q+luAxJ1HiEkjr/HABlc5dT9mjTbNWBIg7EuY5fFHZz2tU9KNs0zeOCg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686249094911.2368403538568; Mon, 26 Aug 2024 08:30:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibfk-0008Ho-6c; Mon, 26 Aug 2024 11:30:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfd-00086S-2N for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:17 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfa-0003bn-O5 for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:16 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-7c691c8f8dcso2753422a12.1 for ; Mon, 26 Aug 2024 08:30:14 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686213; x=1725291013; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PRQLflAmXFEQshk7wJA80BTXWF9mr3mMeQvq+HP93Dg=; b=FBm/WqftuE+iVzCvVjn2ghdVZjOnLS1iGE4zczSV2mwzUwE/LQQihWh7DaalN+mFcG Sm0FLeM4oGKLTXCmq+tG2g3F/i02RX5uPD+CQkMmnA5ytDjM52HJlUW9Y8mPSVZr2r8b Kr/UzYIzJz2jY7nHp5gToDoK+dqnv0gk+wsplDno2vrBcKrI/yZeh1MPwzj/yOUuoo2G cOA+b12mz+aLUvUfl2q9if+C7TT00p87ZpEddb9dZ8Lxz5fPhkIoqjAgdTqG29COF1Fs ewx4Gqca0/wZk55OZGaoh1df2Aq3NzKp+ZARvHMTr42pdUGjSk62lgqNL21QFle6SZsp ykxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686213; x=1725291013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PRQLflAmXFEQshk7wJA80BTXWF9mr3mMeQvq+HP93Dg=; b=Hs7Swh82EUjXLs4eyLY/5U7tpWeeaS79y5Px5epCW4BHlU2f3XKjZOqBjHeQDwL5QP 1SDhCxNp0/oqkEsVS9syjNMKL50VtMaQHVkSZ52MEQ0XfzizL8rceyWMUR5HxnyTB/nm ISg0HJyn42u/mul//C6nd7Ne3pMBWBMarXBePTlQkkA4LdfY87Ur01NgGIk/Ga/gEdWu QLddNlvEAM4nJu70wmSqK3tdn60ALyTqn8pompMBh+I6/A3/D4e4yqcotFvStUlq5Ghf SiuSCm6W/hzPWSQ/zT/XD4pRM437cXsgSD4iqbFytuYT1/32i0BODwpBRDcylHW3R6sC uzlg== X-Forwarded-Encrypted: i=1; AJvYcCXKQBCRJaRCaubUHh/kErW9M16cVFUtnDJYO28nrXd2R/q5oOroOmS62lAFI8ixe35fah4LpVwxRY+u@nongnu.org X-Gm-Message-State: AOJu0Yx+L9W5zIjxjrXp0jRdtCPnssAbBNepQa+IyrbeOMampco4DHgd zcNsRrYeAPWr52sTlF/uLMBXBjKL2+vNPo7p5T62WLmil+O/clns8knwrEXqnSV74+8BSF/nL2b J X-Google-Smtp-Source: AGHT+IGrSgB5Fv3T9b5iaE8TIEtji4beFQn+eBn/r5qxQBOnIyZuB4pivC2nR7NcykQqt1FVM+xxLw== X-Received: by 2002:a05:6a20:9f8c:b0:1c4:bf4a:6c0e with SMTP id adf61e73a8af0-1cc89d7e451mr11545534637.26.1724686213021; Mon, 26 Aug 2024 08:30:13 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 02/17] target/riscv: Introduce elp state and enabling controls for zicfilp Date: Mon, 26 Aug 2024 08:29:34 -0700 Message-ID: <20240826152949.294506-3-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::52d; envelope-from=debug@rivosinc.com; helo=mail-pg1-x52d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686252609116600 Content-Type: text/plain; charset="utf-8" zicfilp introduces a new state elp ("expected landing pad") in cpu. During normal execution, elp is idle (NO_LP_EXPECTED) i.e not expecting landing pad. On an indirect call, elp moves LP_EXPECTED. When elp is LP_EXPECTED, only a subsquent landing pad instruction can set state back to NO_LP_EXPECTED. On reset, elp is set to NO_LP_EXPECTED. zicfilp is enabled via bit2 in *envcfg CSRs. Enabling control for M-mode is in mseccfg CSR at bit position 10. On trap, elp state is saved away in *status. Adds elp to the migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 3 +++ target/riscv/cpu.h | 2 ++ target/riscv/cpu_bits.h | 6 ++++++ target/riscv/csr.c | 31 +++++++++++++++++++++++++++++++ target/riscv/machine.c | 19 +++++++++++++++++++ target/riscv/pmp.c | 5 +++++ target/riscv/pmp.h | 3 ++- 7 files changed, 68 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 5dfb3f39ab..8e1f05e5b1 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -994,6 +994,9 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType= type) /* mmte is supposed to have pm.current hardwired to 1 */ env->mmte |=3D (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT); =20 + /* on reset elp is clear */ + env->elp =3D false; + /* * Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor * extension is enabled. diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 87742047ce..f966c36a31 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -222,6 +222,8 @@ struct CPUArchState { =20 target_ulong jvt; =20 + /* elp state for zicfilp extension */ + bool elp; #ifdef CONFIG_USER_ONLY uint32_t elf_flags; #endif diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index c257c5ed7d..b05ebe6f29 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -545,6 +545,8 @@ #define MSTATUS_TVM 0x00100000 /* since: priv-1.10 */ #define MSTATUS_TW 0x00200000 /* since: priv-1.10 */ #define MSTATUS_TSR 0x00400000 /* since: priv-1.10 */ +#define MSTATUS_SPELP 0x00800000 /* zicfilp */ +#define MSTATUS_MPELP 0x020000000000 /* zicfilp */ #define MSTATUS_GVA 0x4000000000ULL #define MSTATUS_MPV 0x8000000000ULL =20 @@ -575,6 +577,7 @@ typedef enum { #define SSTATUS_XS 0x00018000 #define SSTATUS_SUM 0x00040000 /* since: priv-1.10 */ #define SSTATUS_MXR 0x00080000 +#define SSTATUS_SPELP MSTATUS_SPELP /* zicfilp */ =20 #define SSTATUS64_UXL 0x0000000300000000ULL =20 @@ -747,6 +750,7 @@ typedef enum RISCVException { =20 /* Execution environment configuration bits */ #define MENVCFG_FIOM BIT(0) +#define MENVCFG_LPE BIT(2) /* zicfilp */ #define MENVCFG_CBIE (3UL << 4) #define MENVCFG_CBCFE BIT(6) #define MENVCFG_CBZE BIT(7) @@ -760,11 +764,13 @@ typedef enum RISCVException { #define MENVCFGH_STCE BIT(31) =20 #define SENVCFG_FIOM MENVCFG_FIOM +#define SENVCFG_LPE MENVCFG_LPE #define SENVCFG_CBIE MENVCFG_CBIE #define SENVCFG_CBCFE MENVCFG_CBCFE #define SENVCFG_CBZE MENVCFG_CBZE =20 #define HENVCFG_FIOM MENVCFG_FIOM +#define HENVCFG_LPE MENVCFG_LPE #define HENVCFG_CBIE MENVCFG_CBIE #define HENVCFG_CBCFE MENVCFG_CBCFE #define HENVCFG_CBZE MENVCFG_CBZE diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 432c59dc66..5771a14848 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1400,6 +1400,11 @@ static RISCVException write_mstatus(CPURISCVState *e= nv, int csrno, } } =20 + /* If cfi lp extension is available, then apply cfi lp mask */ + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D (MSTATUS_MPELP | MSTATUS_SPELP); + } + mstatus =3D (mstatus & ~mask) | (val & mask); =20 env->mstatus =3D mstatus; @@ -2101,6 +2106,10 @@ static RISCVException write_menvcfg(CPURISCVState *e= nv, int csrno, mask |=3D (cfg->ext_svpbmt ? MENVCFG_PBMTE : 0) | (cfg->ext_sstc ? MENVCFG_STCE : 0) | (cfg->ext_svadu ? MENVCFG_ADUE : 0); + + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D MENVCFG_LPE; + } } env->menvcfg =3D (env->menvcfg & ~mask) | (val & mask); =20 @@ -2153,6 +2162,10 @@ static RISCVException write_senvcfg(CPURISCVState *e= nv, int csrno, return ret; } =20 + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D SENVCFG_LPE; + } + env->senvcfg =3D (env->senvcfg & ~mask) | (val & mask); return RISCV_EXCP_NONE; } @@ -2190,6 +2203,10 @@ static RISCVException write_henvcfg(CPURISCVState *e= nv, int csrno, =20 if (riscv_cpu_mxl(env) =3D=3D MXL_RV64) { mask |=3D env->menvcfg & (HENVCFG_PBMTE | HENVCFG_STCE | HENVCFG_A= DUE); + + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D HENVCFG_LPE; + } } =20 env->henvcfg =3D (env->henvcfg & ~mask) | (val & mask); @@ -2654,6 +2671,10 @@ static RISCVException read_sstatus_i128(CPURISCVStat= e *env, int csrno, mask |=3D SSTATUS64_UXL; } =20 + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D SSTATUS_SPELP; + } + *val =3D int128_make128(sstatus, add_status_sd(MXL_RV128, sstatus)); return RISCV_EXCP_NONE; } @@ -2665,6 +2686,11 @@ static RISCVException read_sstatus(CPURISCVState *en= v, int csrno, if (env->xl !=3D MXL_RV32 || env->debugger) { mask |=3D SSTATUS64_UXL; } + + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D SSTATUS_SPELP; + } + /* TODO: Use SXL not MXL. */ *val =3D add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask); return RISCV_EXCP_NONE; @@ -2680,6 +2706,11 @@ static RISCVException write_sstatus(CPURISCVState *e= nv, int csrno, mask |=3D SSTATUS64_UXL; } } + + if (env_archcpu(env)->cfg.ext_zicfilp) { + mask |=3D SSTATUS_SPELP; + } + target_ulong newval =3D (env->mstatus & ~mask) | (val & mask); return write_mstatus(env, CSR_MSTATUS, newval); } diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 76f2150f78..873957c4ab 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -351,6 +351,24 @@ static const VMStateDescription vmstate_jvt =3D { } }; =20 +static bool elp_needed(void *opaque) +{ + RISCVCPU *cpu =3D opaque; + + return cpu->cfg.ext_zicfilp; +} + +static const VMStateDescription vmstate_elp =3D { + .name =3D "cpu/elp", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D elp_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_BOOL(env.elp, RISCVCPU), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_riscv_cpu =3D { .name =3D "cpu", .version_id =3D 10, @@ -423,6 +441,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { &vmstate_debug, &vmstate_smstateen, &vmstate_jvt, + &vmstate_elp, NULL } }; diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 9eea397e72..1111d08d08 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -598,6 +598,11 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulon= g val) val &=3D ~(MSECCFG_MMWP | MSECCFG_MML | MSECCFG_RLB); } =20 + /* M-mode forward cfi to be enabled if cfi extension is implemented */ + if (env_archcpu(env)->cfg.ext_zicfilp) { + val |=3D (val & MSECCFG_MLPE); + } + env->mseccfg =3D val; } =20 diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index f5c10ce85c..e0530a17a3 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -44,7 +44,8 @@ typedef enum { MSECCFG_MMWP =3D 1 << 1, MSECCFG_RLB =3D 1 << 2, MSECCFG_USEED =3D 1 << 8, - MSECCFG_SSEED =3D 1 << 9 + MSECCFG_SSEED =3D 1 << 9, + MSECCFG_MLPE =3D 1 << 10, } mseccfg_field_t; =20 typedef struct { --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686375; cv=none; d=zohomail.com; s=zohoarc; b=Gq4k8AUwKyBl7DrnDN/aSumH7kNO1XA/hxYHXzTWaPGhQthGm6m//q1zt9ab1kS3WvRMg4FqgonVRQY5U8SDcSC5zQZcPIO3A+vPHb5a/rmXf6VRrImrIMPXFGBAoddymL2Ns4IALDXqLqX8qMFRXEntGMSGa7iSPPM//VCyyas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686375; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5JtrgC4+fHlAa4XAwLJHyCFy+eiQX4gwNZ2q8o9OZBM=; b=Ufb7GcmJ2Y5czxgkWhDQ+WFkxHq5MbOcP/lqSrYPCRAkOdStDCcAkU1KagV2Vt18e/rWkxp+QUCPIwMdEU8x0p0dPwWFC7zg2DAb6GA2g7bOCXFf2UM3i/RCluNypdkjl/ygbWFZp/mX3D79bmjXxaQEGbxpIWHy1d1+1ChUVRk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686375164997.6663543926788; Mon, 26 Aug 2024 08:32:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibfo-0000Hs-1W; Mon, 26 Aug 2024 11:30:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibff-0008Fm-3s for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:21 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfb-0003c1-Sg for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:18 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-7cda2695893so1393457a12.1 for ; Mon, 26 Aug 2024 08:30:15 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686214; x=1725291014; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5JtrgC4+fHlAa4XAwLJHyCFy+eiQX4gwNZ2q8o9OZBM=; b=p6R1m88uSVtoplHkFeOnt6+rGXs+yG8zzHwEfelaZg4/10RkL4mYOnXe8kTwSp0RLY 5e6rFTRe/eV/OzLRA+/haezae7zpTQpDCJyIi3O7J1HDGirPwLXQbCdmq0AD641/2mkl egFpUSntZd3YM4V8GYKtig05pJERwQUR2sQIqtVzBqh+rv2FffMvfOZ/fbWfq3NtQ9FE szdVu2ZasIm1ZlIueCIWwQUO9/3mSQkF1C9ZgQiAy9LB6GMP9jU7L5m4r0eYIQMYDtqX 8nsHG4uYpyTqYnuPCTgWHTHu56RSFiFEZ64Ctr/Wli3W1YvxHqONXSlaCA8ZOmwubNf9 1lzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686214; x=1725291014; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5JtrgC4+fHlAa4XAwLJHyCFy+eiQX4gwNZ2q8o9OZBM=; b=XOX9P7mQIUY6hqpqCt+JHiJ7IOG2YDSZffiCHnhXRpznY0jzTWUuvVdNVE8T9Luue9 pOUv+HKyxc7GUHbI3W9r7KsDCqDB4sqP/unxJvZwnN63iFyibkkcNifsKRFpAaGySEQM GD1U9WhxRspIQ2dNLQhJ4el9AxSd7w8jdIVibtcJgaT/fuI4DGWvUQOSmjdokwx7ozJh skJvgFKD57dbWtXHgih+DTJQDG9qInTJghmjhxVD47Mq6TMPbp30p+ppUi9UgcDXb0Gv oyZB0W9HT9NGvzlgTku7augnnIlJgTyUDObHh91+mmKaKb+BTnXNiYrgdr4DpIYxorza J2Ug== X-Forwarded-Encrypted: i=1; AJvYcCWafo3z7YdvnpfOC3jez0qIFoo0b3wVzit57RYG9aeYhJxLPWxNNdv27yM15Z6hP6zjru9VOV7KD+W8@nongnu.org X-Gm-Message-State: AOJu0Yyze1PHywfIWp14hqKCnL9Ny1tqdxwNAPMnXNX2sLuaBxuZsOZi MmxazmkJhso+d4oHJFdCGF/zVN8ZaRz+Sq2COF0yx2D6MZJIbcQwZCBMLj9NBkc= X-Google-Smtp-Source: AGHT+IG6vjlnK1eBiUx65bldQWmLg2zJfquuzlfJJqaPLzT4/2MlL5YkM8im4uuPV9/xJW4X35E2wg== X-Received: by 2002:a05:6a20:6f89:b0:1c6:a048:45a2 with SMTP id adf61e73a8af0-1cc89d999femr11227933637.24.1724686214228; Mon, 26 Aug 2024 08:30:14 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 03/17] target/riscv: save and restore elp state on priv transitions Date: Mon, 26 Aug 2024 08:29:35 -0700 Message-ID: <20240826152949.294506-4-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::532; envelope-from=debug@rivosinc.com; helo=mail-pg1-x532.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686375905116600 Content-Type: text/plain; charset="utf-8" elp state is recorded in *status on trap entry (less privilege to higher privilege) and restored in elp from *status on trap exit (higher to less privilege). Additionally this patch introduces a forward cfi helper function to determine if current privilege has forward cfi is enabled or not based on *envcfg (for U, VU, S, VU, HS) or mseccfg csr (for M). For qemu-user, a new field `ufcfien` is introduced which is by default set to false and helper function returns value deposited in `ufcfien` for qemu-user. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson --- target/riscv/cpu.c | 5 ++++ target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 55 +++++++++++++++++++++++++++++++++++++++ target/riscv/op_helper.c | 18 +++++++++++++ 4 files changed, 80 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 8e1f05e5b1..083d405516 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1022,6 +1022,11 @@ static void riscv_cpu_reset_hold(Object *obj, ResetT= ype type) env->load_res =3D -1; set_default_nan_mode(1, &env->fp_status); =20 +#ifdef CONFIG_USER_ONLY + /* qemu-user for riscv, fcfi is off by default */ + env->ufcfien =3D false; +#endif + #ifndef CONFIG_USER_ONLY if (cpu->cfg.debug) { riscv_trigger_reset_hold(env); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f966c36a31..7be0fa30f7 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -226,6 +226,7 @@ struct CPUArchState { bool elp; #ifdef CONFIG_USER_ONLY uint32_t elf_flags; + bool ufcfien; #endif =20 #ifndef CONFIG_USER_ONLY @@ -530,6 +531,7 @@ void riscv_cpu_set_geilen(CPURISCVState *env, target_ul= ong geilen); bool riscv_cpu_vector_enabled(CPURISCVState *env); void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); int riscv_env_mmu_index(CPURISCVState *env, bool ifetch); +bool cpu_get_fcfien(CPURISCVState *env); G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t reta= ddr); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 6709622dd3..12484ca7d2 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -33,6 +33,7 @@ #include "cpu_bits.h" #include "debug.h" #include "tcg/oversized-guest.h" +#include "pmp.h" =20 int riscv_env_mmu_index(CPURISCVState *env, bool ifetch) { @@ -63,6 +64,34 @@ int riscv_env_mmu_index(CPURISCVState *env, bool ifetch) #endif } =20 +bool cpu_get_fcfien(CPURISCVState *env) +{ + /* no cfi extension, return false */ + if (!env_archcpu(env)->cfg.ext_zicfilp) { + return false; + } +#ifdef CONFIG_USER_ONLY + return env->ufcfien; +#else + switch (env->priv) { + case PRV_U: + if (riscv_has_ext(env, RVS)) { + return env->senvcfg & MENVCFG_LPE; + } + return env->menvcfg & MENVCFG_LPE; + case PRV_S: + if (env->virt_enabled) { + return env->henvcfg & HENVCFG_LPE; + } + return env->menvcfg & MENVCFG_LPE; + case PRV_M: + return env->mseccfg & MSECCFG_MLPE; + default: + g_assert_not_reached(); + } +#endif +} + void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, uint64_t *cs_base, uint32_t *pflags) { @@ -546,6 +575,15 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) } bool current_virt =3D env->virt_enabled; =20 + /* + * If zicfilp extension available and henvcfg.LPE =3D 1, + * then apply SPELP mask on mstatus + */ + if (env_archcpu(env)->cfg.ext_zicfilp && + get_field(env->henvcfg, HENVCFG_LPE)) { + mstatus_mask |=3D SSTATUS_SPELP; + } + g_assert(riscv_has_ext(env, RVH)); =20 if (current_virt) { @@ -1754,6 +1792,11 @@ void riscv_cpu_do_interrupt(CPUState *cs) if (env->priv <=3D PRV_S && cause < 64 && (((deleg >> cause) & 1) || s_injected || vs_injected)) { /* handle the trap in S-mode */ + /* save elp status */ + if (cpu_get_fcfien(env)) { + env->mstatus =3D set_field(env->mstatus, MSTATUS_SPELP, env->e= lp); + } + if (riscv_has_ext(env, RVH)) { uint64_t hdeleg =3D async ? env->hideleg : env->hedeleg; =20 @@ -1802,6 +1845,11 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_set_mode(env, PRV_S); } else { /* handle the trap in M-mode */ + /* save elp status */ + if (cpu_get_fcfien(env)) { + env->mstatus =3D set_field(env->mstatus, MSTATUS_MPELP, env->e= lp); + } + if (riscv_has_ext(env, RVH)) { if (env->virt_enabled) { riscv_cpu_swap_hypervisor_regs(env); @@ -1833,6 +1881,13 @@ void riscv_cpu_do_interrupt(CPUState *cs) riscv_cpu_set_mode(env, PRV_M); } =20 + /* + * Interrupt/exception/trap delivery is asynchronous event and as per + * zicfilp spec CPU should clear up the ELP state. No harm in clearing + * unconditionally. + */ + env->elp =3D false; + /* * NOTE: it is not necessary to yield load reservations here. It is on= ly * necessary for an SC from "another hart" to cause a load reservation diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 2baf5bc3ca..5848aaf437 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -313,6 +313,15 @@ target_ulong helper_sret(CPURISCVState *env) =20 riscv_cpu_set_mode(env, prev_priv); =20 + /* + * If forward cfi enabled for new priv, restore elp status + * and clear spelp in mstatus + */ + if (cpu_get_fcfien(env)) { + env->elp =3D get_field(env->mstatus, MSTATUS_SPELP); + } + env->mstatus =3D set_field(env->mstatus, MSTATUS_SPELP, 0); + return retpc; } =20 @@ -357,6 +366,15 @@ target_ulong helper_mret(CPURISCVState *env) riscv_cpu_set_virt_enabled(env, prev_virt); } =20 + /* + * If forward cfi enabled for new priv, restore elp status + * and clear mpelp in mstatus + */ + if (cpu_get_fcfien(env)) { + env->elp =3D get_field(env->mstatus, MSTATUS_MPELP); + } + env->mstatus =3D set_field(env->mstatus, MSTATUS_MPELP, 0); + return retpc; } =20 --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686345; cv=none; d=zohomail.com; s=zohoarc; b=kpkSJkNvjIl5e/BWuTrUvSNkzJ9bllH4nUlAz5fZSbhPzCpWyjV+ig0p2M8bcAl9qgtE7ENdy4e3vSr/c+YDnRZ7AMrXHInpVw8CF7C9Zf5ZjPns8HpUf/dIJQC5+okjYGEK1uCCCXhjKOl/b5JRr5T/t3qSXHSzHh3yqFWfrEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686345; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UsiagUrA8byZnAGLoeRuYpUl3zN9h7ZESSjwciHMwsQ=; b=OAZjVRUo9eT2BVIDBWpSDxB+xQy1kYg7Gu34bFaYUfl9teYVF4XFaKJ5UdzqGWgW/My6FvSiz5ByjruFs5nUWRE3d9nf+SChPLkDc/7GVJot+PDtaXjxk79GqekHvGUvkZtJOE5OwaEfXYFgWjmozjuYfjnw6W+Xd35hvudOers= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686345247293.30879664003226; Mon, 26 Aug 2024 08:32:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgE-0001YU-LE; Mon, 26 Aug 2024 11:30:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibff-0008Fj-2p for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:21 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfd-0003cL-1N for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:18 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7140ff4b1e9so3503867b3a.3 for ; Mon, 26 Aug 2024 08:30:16 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686215; x=1725291015; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UsiagUrA8byZnAGLoeRuYpUl3zN9h7ZESSjwciHMwsQ=; b=G37q3cbEPPsiscU4CF9D6yizneGS10+GtN5kxwGx2jwaOEvm3fLwZyEU1OG/Eys61G 0oC5yNO6PP0Dmlb/07+z2uZ6RAUD0+JZb2I2SZ7O2hjOVCCC2FeFKqTqLt0n5kAJHU1b S+taC+tcWqHUo+UNwJulxrK/84HP9LzEXDpk5muhZI9+ZIQrLrh6+w/FsxFWt4hs44CI YpA4C+YqHLFZYfNDx3LYynCkDjp5s4TVmJvxWd2zrg3WqoOhjDXqPYDDULt4V9R+2CkN XpkiSu74hqnL3l/jY3ry15jXb5LXL1w5p/WDPq70djeupl0Wod/yq+HWwWfOl83RiTSH 9uiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686215; x=1725291015; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UsiagUrA8byZnAGLoeRuYpUl3zN9h7ZESSjwciHMwsQ=; b=os1Vbw4RYfXvH0tRdsNdLDNBhSUtm2dvtkzvQ7H4es2TJ4LR1SWAnh50oXEIj+AC5f rmP/ELP6rhDoFWP3DPSmWu02mMm6j+raUBPgRuEoo3jJdgw/MEuKj74RQnIWpunxW11c TL6OH58fzGchf5emRRjzr4fcB3KVzP0Ff45QLe4z+1WlSJxMWid85gTyjnALoBcbANbC UWiC8QIH34mBOb6Oih1KF2ts/Qhdx2s7Jt12zX9X3yF18Rseui5k7ngbMMaIqeXQNkyJ avUOGYa4jA8njZPQqApqONtT94Sw3bgBOaojB3HISIxdVTqdC+rHOI01URaQDGGYUdYr gjtQ== X-Forwarded-Encrypted: i=1; AJvYcCVpFlKACSattf8tNPhuAQMl9dW1pZcjHMCnqdbZPH8UD3bTz/rpaF7WRPRscw+IPMlGhuYGfHlDsatH@nongnu.org X-Gm-Message-State: AOJu0Yy8V9sKWoVBQhIt637gxPAJNyBNofY8lYvnkJnVKE+FL8vh6ugB ed2HsyuA7cSYcnW/ZbtTaL8C0/M/w43zu5sA189RvM0mGbJ5qQlKmQIMgTS0o9c= X-Google-Smtp-Source: AGHT+IF4UqzMHvV6CtfFYOWgUDbolv4bSQEUcjkFrVDBCcFRbPBbnzwRK6BZBSgNWXArki+q3/xzqA== X-Received: by 2002:a05:6a00:2383:b0:706:3329:5533 with SMTP id d2e1a72fcca58-7144587f44fmr11446176b3a.24.1724686215437; Mon, 26 Aug 2024 08:30:15 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 04/17] target/riscv: additional code information for sw check Date: Mon, 26 Aug 2024 08:29:36 -0700 Message-ID: <20240826152949.294506-5-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::430; envelope-from=debug@rivosinc.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686345643116600 Content-Type: text/plain; charset="utf-8" sw check exception support was recently added. This patch further augments sw check exception by providing support for additional code which is provided in *tval. Adds `sw_check_code` field in cpuarchstate. Whenever sw check exception is raised *tval gets the value deposited in `sw_check_code`. Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 3 +++ target/riscv/csr.c | 1 + 3 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7be0fa30f7..11c6513a90 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -224,6 +224,8 @@ struct CPUArchState { =20 /* elp state for zicfilp extension */ bool elp; + /* sw check code for sw check exception */ + target_ulong sw_check_code; #ifdef CONFIG_USER_ONLY uint32_t elf_flags; bool ufcfien; diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 12484ca7d2..121fef1be6 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1761,6 +1761,9 @@ void riscv_cpu_do_interrupt(CPUState *cs) cs->watchpoint_hit =3D NULL; } break; + case RISCV_EXCP_SW_CHECK: + tval =3D env->sw_check_code; + break; default: break; } diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 5771a14848..a5a969a377 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1179,6 +1179,7 @@ static const uint64_t all_ints =3D M_MODE_INTERRUPTS = | S_MODE_INTERRUPTS | (1ULL << (RISCV_EXCP_INST_PAGE_FAULT)) | \ (1ULL << (RISCV_EXCP_LOAD_PAGE_FAULT)) | \ (1ULL << (RISCV_EXCP_STORE_PAGE_FAULT)) | \ + (1ULL << (RISCV_EXCP_SW_CHECK)) | \ (1ULL << (RISCV_EXCP_INST_GUEST_PAGE_FAULT)) | \ (1ULL << (RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT)) | \ (1ULL << (RISCV_EXCP_VIRT_INSTRUCTION_FAULT)) | \ --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686331; cv=none; d=zohomail.com; s=zohoarc; b=YIzEggNxhmt82HezLhHoAX0APyb2eP/AXs2B7+8KS56nE3wHd6ETfEwnasdjFR+eA0Gwzsyd4FE8CV/Pi0+J4RlRSm1O62JAFMnnYUCcyo8nPYlDNSc25Pp5pqS+cKrF80gMqeL5ZlkCHtr6pI2Zyzm2+89ACEjWbZyO0mbjPbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686331; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZnJjA3VaZye0fI1AXKs9fkhm38j5AiuwIOBNjAG2RnI=; b=bbb1bfTV+9kBxvY47Q2ydl462unmTnMFppDDNeAb4ocUfFUA8wPt9ir6fqiLL46vaY+ELZnmbpOGcOy8V/mrdU5I1+Nosu3JznSXn8IJFHmsstaOmbq3oAWmuX2KKCcSJn5Fj81R2j+l287yr36htnv7heR3fbEX6KhYqpU96wk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686331307369.1225161164033; Mon, 26 Aug 2024 08:32:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgE-0001bf-UN; Mon, 26 Aug 2024 11:30:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfg-0008Mf-UD for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:21 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfe-0003cz-Q1 for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:20 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7142a93ea9cso3110052b3a.3 for ; Mon, 26 Aug 2024 08:30:18 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686217; x=1725291017; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZnJjA3VaZye0fI1AXKs9fkhm38j5AiuwIOBNjAG2RnI=; b=DNYhRAH0N3yIBLp0gIEtMI7maQTH3i2sf5Cys2kKzIO0jgVjVz/UxXnCx+YZG67s/U GS23u6ebM6uB7AGNptpp2Ugp/fTHpJK7RTbHEoPBRl59D7ZaoQgyBHEtSxffcHtUM6tH Yf6knxeUzNTrINzjUEb0arR94SNvCR6mohFZOaJEscX1TW+CrVj+P+1bcmDL9uptM/EY fwqTRJ1xxPFarSWFLkt9jKHaWDekaZe0XqMHytejw1KNa+NIlOSvRezXw17cEMtu7l9z ARC5qPVNpY2f6eLDw40OXpXdCDzUoK8SkR449DDfY3G0nReBohuGJiZU+39dYEgVteFd b7Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686217; x=1725291017; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZnJjA3VaZye0fI1AXKs9fkhm38j5AiuwIOBNjAG2RnI=; b=RXfqCQhdOdddM+dOxbaOeepqCTbXj7i+kvfCri3Nkb5xASG87IUNsuvlTYiZX7RMwH XXpVab5E9jYt715f1IJpZFe8J7v5ArOtkrjdefKLO4MwhwFJBlSoLV+vLDgLr4FyykEh QI8OPqVykUiA4pYvPMX9iBWwvDdHL3tFFrWdiI/UTbEmgTPinChyesPMmKc11hbbyr1p 2y+0uhOH5yzpWFPCMJ/7fkG1afLvEN5c5YX/jUGCd7rNVhNxuIovXTKqQhP+bC2114an lFaRer5ts//guCa7FXFVww9wLYrGy15FMoiE98Say3CxhWi8P6yDvD1CLE5lMDEQvjyg tcyg== X-Forwarded-Encrypted: i=1; AJvYcCXFDwFLtkfUY4EbGcF28xzGEwDGAPXhZ/i9bCVTYQDnrhzJa5f0cwC2HQulKIPF2cWuEZL9u7wuLiFe@nongnu.org X-Gm-Message-State: AOJu0YyVURjzToG+yklXo685TBGcD+sN4OaSH8opUfFjCZT+Kt7IIIZQ aLzqf8D1xHMdrlr9kDQKsIsZxi16sMfowc9csi/m/A1LSzSfoYMJqqsUT8oNlma0Sq62kGLIHqj R X-Google-Smtp-Source: AGHT+IGyvwDpdxlAb+Oz5QelfVwKEf7b26gzb0vgq2P/FsHui1VnXYHv/pK6n/Kaouxcp5REW8Ml1w== X-Received: by 2002:a05:6a20:43a9:b0:1ca:edd5:9254 with SMTP id adf61e73a8af0-1cc89d6b90dmr10664225637.16.1724686216667; Mon, 26 Aug 2024 08:30:16 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 05/17] target/riscv: tracking indirect branches (fcfi) for zicfilp Date: Mon, 26 Aug 2024 08:29:37 -0700 Message-ID: <20240826152949.294506-6-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::435; envelope-from=debug@rivosinc.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686331688116600 Content-Type: text/plain; charset="utf-8" zicfilp protects forward control flow (if enabled) by enforcing all indirect call and jmp must land on a landing pad instruction `lpad`. If target of an indirect call or jmp is not `lpad` then cpu/hart must raise a sw check exception with tval =3D 2. This patch implements the mechanism using TCG. Target architecture branch instruction must define the end of a TB. Using this property, during translation of branch instruction, TB flag =3D FCFI_LP_EXPECTED can be set. Translation of target TB can check if FCFI_LP_EXPECTED flag is set and a flag (fcfi_lp_expected) can be set in DisasContext. If `lpad` gets translated, fcfi_lp_expected flag in DisasContext can be cleared. Else it'll fault. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 3 +++ target/riscv/cpu_bits.h | 3 +++ target/riscv/cpu_helper.c | 10 ++++++++++ target/riscv/translate.c | 23 +++++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 11c6513a90..edf540339a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -606,6 +606,9 @@ FIELD(TB_FLAGS, ITRIGGER, 22, 1) FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1) FIELD(TB_FLAGS, PRIV, 24, 2) FIELD(TB_FLAGS, AXL, 26, 2) +/* zicfilp needs a TB flag to track indirect branches */ +FIELD(TB_FLAGS, FCFI_ENABLED, 28, 1) +FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 29, 1) =20 #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index b05ebe6f29..900769ce60 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -685,6 +685,9 @@ typedef enum RISCVException { RISCV_EXCP_SEMIHOST =3D 0x3f, } RISCVException; =20 +/* zicfilp defines lp violation results in sw check with tval =3D 2*/ +#define RISCV_EXCP_SW_CHECK_FCFI_TVAL 2 + #define RISCV_EXCP_INT_FLAG 0x80000000 #define RISCV_EXCP_INT_MASK 0x7fffffff =20 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 121fef1be6..172c945bf3 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -133,6 +133,16 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, flags =3D FIELD_DP32(flags, TB_FLAGS, VILL, 1); } =20 + if (cpu_get_fcfien(env)) { + /* + * For Forward CFI, only the expectation of a lpad at + * the start of the block is tracked via env->elp. env->elp + * is turned on during jalr translation. + */ + flags =3D FIELD_DP32(flags, TB_FLAGS, FCFI_LP_EXPECTED, env->elp); + flags =3D FIELD_DP32(flags, TB_FLAGS, FCFI_ENABLED, 1); + } + #ifdef CONFIG_USER_ONLY fs =3D EXT_STATUS_DIRTY; vs =3D EXT_STATUS_DIRTY; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index acba90f170..b5c0511b4b 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -116,6 +116,9 @@ typedef struct DisasContext { bool frm_valid; bool insn_start_updated; const GPtrArray *decoders; + /* zicfilp extension. fcfi_enabled, lp expected or not */ + bool fcfi_enabled; + bool fcfi_lp_expected; } DisasContext; =20 static inline bool has_ext(DisasContext *ctx, uint32_t ext) @@ -1238,6 +1241,8 @@ static void riscv_tr_init_disas_context(DisasContextB= ase *dcbase, CPUState *cs) ctx->pm_base_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLE= D); ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); + ctx->fcfi_lp_expected =3D FIELD_EX32(tb_flags, TB_FLAGS, FCFI_LP_EXPEC= TED); + ctx->fcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, FCFI_ENABLED); ctx->zero =3D tcg_constant_tl(0); ctx->virt_inst_excp =3D false; ctx->decoders =3D cpu->decoders; @@ -1270,6 +1275,24 @@ static void riscv_tr_translate_insn(DisasContextBase= *dcbase, CPUState *cpu) decode_opc(env, ctx, opcode16); ctx->base.pc_next +=3D ctx->cur_insn_len; =20 + /* + * If 'fcfi_lp_expected' is still true after processing the instructio= n, + * then we did not see an 'lpad' instruction, and must raise an except= ion. + * Insert code to raise the exception at the start of the insn; any ot= her + * code the insn may have emitted will be deleted as dead code followi= ng + * the noreturn exception + */ + if (ctx->fcfi_lp_expected) { + /* Emit after insn_start, i.e. before the op following insn_start.= */ + tcg_ctx->emit_before_op =3D QTAILQ_NEXT(ctx->base.insn_start, link= ); + tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + tcg_ctx->emit_before_op =3D NULL; + ctx->base.is_jmp =3D DISAS_NORETURN; + } + /* Only the first insn within a TB is allowed to cross a page boundary= . */ if (ctx->base.is_jmp =3D=3D DISAS_NEXT) { if (ctx->itrigger || !is_same_page(&ctx->base, ctx->base.pc_next))= { --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686346; cv=none; d=zohomail.com; s=zohoarc; b=RsH+rdn7YpHZnRM3iHwyHMe717uqw9kgi8W10ZGKlMG/EXChvQWrP0M2tNpMha8pV2i1g7xh4eBzrrALgWuIr5sXyFITug9tFu5vE0TcXGEbYO1rcYPvKSZDCry99d3qg2WVTnxSWPhsqa4knnNvnHsmJ20IRFklBJrIRZzz1HU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686346; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nxyYMlb3x6bp85BnzPPZWZ8Bp+UukqIv0ly48+tdD3U=; b=He6wsxlUot75TTLYCKpF7ABeSyXifC9OcROvhIudniuIZxaNUjSqz84imPKCFOYKL8bfKd8mThcnjkBLVWi0+Lc3MZHX29wc+s3EppWD8JmLvYrUFCzQEfX1VLrS6lISNALY+2i+x5M4nwYPqpi631AaNOUTko+clYXj1qphZqg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686346915326.52216832840077; Mon, 26 Aug 2024 08:32:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgH-00020Z-6T; Mon, 26 Aug 2024 11:30:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfl-0000FT-Vs for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:26 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibff-0003dJ-IT for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:22 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-7143ae1b48fso2480072b3a.1 for ; Mon, 26 Aug 2024 08:30:19 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686218; x=1725291018; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nxyYMlb3x6bp85BnzPPZWZ8Bp+UukqIv0ly48+tdD3U=; b=lzux0G0yrzGdsQOpS6A8R/jQMoMTJNotQCXscIef5aL7jvnzvNiaEkkdzmXZT/5Q+r 6jaEE1jura8MKbajx7QOy7XQ88YLcThy6m2weIEixOhFatZdtwJmzREzPdvWeIh/vVKh DFK0p0cpp4A4WYZ82zWOdAOW8yrJBENh8BnmVYs3YjjCz9H5GkzV56w8jk+qmfaA3PfS mgr0h1xI8Xhjkk+MffEZ2Kytyjb8qqIHbYUc2/pvTkZl/vN7F85t/xUY5KWdchNjDARj hrSwL/I4xOMeH9Mv0O9hwJ9ADc+0GhVoU96sLfzclfwvUL93j6vv3JvqyPIkxanK+PfN 4fAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686218; x=1725291018; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nxyYMlb3x6bp85BnzPPZWZ8Bp+UukqIv0ly48+tdD3U=; b=AIQWf+nn1P/jz7qK5eFPSmKJDdZY3TpB86zHLRzPHDelOPJlYKG+JRMTYYGMz2oP/T 3+oM3AUKihaBC+wLVpYGTZ+zSeg91SLijeofm0dnPQXVkFORpZm4RvUH7nhvecfyNuIW Y9n22oY/2Sf36YYNnxVQvX2N5ZyczYfAxtOaqfdjRaWZfjPZ+94s2Wvp+VNpixdZWhce iLnZGBph0ZKHgGWtMeRCvTmducOb6ovfirkIVG881QSO+X6x4cDkkJNP+l+HgXGdbQDO 41ZLFEvfDX9mgcFaINK8SiE4DZkmKQ+jBfjAp+ivZ3s2ScOHVGlL5BBi2D1dco+yVgrS AvHQ== X-Forwarded-Encrypted: i=1; AJvYcCVeEY2F7LrR3FGV3KdOudfbYusc8DuhXO7njj+uFkpg3aboTGiSn6VlYVBFCoPmGgPu5qfTu7FgTYcA@nongnu.org X-Gm-Message-State: AOJu0YyG6gBOm5F963phbjPknHuAarkQnra3d9iCSQhNa9sm9h+PgyNg ruPltJUp39XZOOZm1Z5kfr52rmnepvWUF0MjGXC6G4gPj302kK5ldkkeAPQZ/UQ= X-Google-Smtp-Source: AGHT+IETEcGoP8eGNEqW861fyfSOhiYCwWYCS6fRre0Z+ZICDwWcPxcHEyGTXaIvpibJ77srchLJ2A== X-Received: by 2002:a05:6a20:cd91:b0:1c6:a825:8bc1 with SMTP id adf61e73a8af0-1cc8b49da25mr10278340637.29.1724686217916; Mon, 26 Aug 2024 08:30:17 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 06/17] target/riscv: zicfilp `lpad` impl and branch tracking Date: Mon, 26 Aug 2024 08:29:38 -0700 Message-ID: <20240826152949.294506-7-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::42a; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686347732116600 Content-Type: text/plain; charset="utf-8" Implements setting lp expected when `jalr` is encountered and implements `lpad` instruction of zicfilp. `lpad` instruction is taken out of auipc x0, . This is an existing HINTNOP space. If `lpad` is target of an indirect branch, cpu checks for 20 bit value in x7 upper with 20 bit value embedded in `lpad`. If they don't match, cpu raises a sw check exception with tval =3D 2. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu_user.h | 1 + target/riscv/insn32.decode | 5 ++- target/riscv/insn_trans/trans_rvi.c.inc | 55 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu_user.h b/target/riscv/cpu_user.h index 02afad608b..e6927ff847 100644 --- a/target/riscv/cpu_user.h +++ b/target/riscv/cpu_user.h @@ -15,5 +15,6 @@ #define xA6 16 #define xA7 17 /* syscall number for RVI ABI */ #define xT0 5 /* syscall number for RVE ABI */ +#define xT2 7 =20 #endif diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index c45b8fa1d8..27108b992b 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -123,7 +123,10 @@ sfence_vm 0001000 00100 ..... 000 00000 1110011 @= sfence_vm =20 # *** RV32I Base Instruction Set *** lui .................... ..... 0110111 @u -auipc .................... ..... 0010111 @u +{ + lpad label:20 00000 0010111 + auipc .................... ..... 0010111 @u +} jal .................... ..... 1101111 @j jalr ............ ..... 000 ..... 1100111 @i beq ....... ..... ..... 000 ..... 1100011 @b diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index 98e3806d5e..b427f3a939 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -36,6 +36,49 @@ static bool trans_lui(DisasContext *ctx, arg_lui *a) return true; } =20 +static bool trans_lpad(DisasContext *ctx, arg_lpad *a) +{ + /* + * fcfi_lp_expected can set only if fcfi was eanbled. + * translate further only if fcfi_lp_expected set. + * lpad comes from NOP space anyways, so return true if + * fcfi_lp_expected is false. + */ + if (!ctx->fcfi_lp_expected) { + return true; + } + + ctx->fcfi_lp_expected =3D false; + if ((ctx->base.pc_next) & 0x3) { + /* + * misaligned, according to spec we should raise sw check exception + */ + tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + return true; + } + + /* per spec, label check performed only when embedded label non-zero */ + if (a->label !=3D 0) { + TCGLabel *skip =3D gen_new_label(); + TCGv tmp =3D tcg_temp_new(); + tcg_gen_extract_tl(tmp, get_gpr(ctx, xT2, EXT_NONE), 12, 20); + tcg_gen_brcondi_tl(TCG_COND_EQ, tmp, a->label, skip); + tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_FCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + gen_set_label(skip); + } + + tcg_gen_st8_tl(tcg_constant_tl(0), tcg_env, + offsetof(CPURISCVState, elp)); + + return true; +} + static bool trans_auipc(DisasContext *ctx, arg_auipc *a) { TCGv target_pc =3D dest_gpr(ctx, a->rd); @@ -75,6 +118,18 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) gen_set_gpr(ctx, a->rd, succ_pc); =20 tcg_gen_mov_tl(cpu_pc, target_pc); + if (ctx->fcfi_enabled) { + /* + * return from functions (i.e. rs1 =3D=3D xRA || rs1 =3D=3D xT0) a= re not + * tracked. zicfilp introduces sw guarded branch as well. sw guard= ed + * branch are not tracked. rs1 =3D=3D xT2 is a sw guarded branch. + */ + if (a->rs1 !=3D xRA && a->rs1 !=3D xT0 && a->rs1 !=3D xT2) { + tcg_gen_st8_tl(tcg_constant_tl(1), + tcg_env, offsetof(CPURISCVState, elp)); + } + } + lookup_and_goto_ptr(ctx); =20 if (misaligned) { --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686268; cv=none; d=zohomail.com; s=zohoarc; b=eGtmNUEwMk1muOppSXLhGrDjIFhckJJolFFEjRPUqyTFRrn7A0IelO41ycotrGcEVUiWU0npz5sDvD5TrBBryAZo4CVGOEae+PomuMSwYzkWk9xvsebF9ATcBMAqWCu2UAli77pCQy3gEpoC/StcMAweptw/ND74rG3b6H8jn84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686268; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bOp3QknnppYKc6NqQXS9ioOC0GJa+R1wT3E/uYEWjyw=; b=POk08J54J3OHbIBp3RUkC7bWZXnqd93G0qO0IbWTLWLSg79IgnxDkNdbHSNZZGVxPzfQYOXWu2J4M9/5d4wGe684Nl2X2V0iKllYxJYbSYmlwYZ8GXPWGGgPMB9tKvkQleZDWhSBnuh4aOD18fxlxPrKfyY0DBO3B80MfIMxH7o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686268537843.7285080930005; Mon, 26 Aug 2024 08:31:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgG-0001oR-3E; Mon, 26 Aug 2024 11:30:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfl-0000FS-Vr for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:26 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfh-0003dt-6t for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:24 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-714302e7285so3739989b3a.2 for ; Mon, 26 Aug 2024 08:30:20 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686219; x=1725291019; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bOp3QknnppYKc6NqQXS9ioOC0GJa+R1wT3E/uYEWjyw=; b=P0o8itv0URkAR66chknWT8IUZ6qeAjsJfrmUf2cZry74zpcQmlu+cm+2LFrpsiB3Rn CvgUeB2FhlKsdrfrzhzF9PGSA713nxpy8ujQ5b0F0YS5+rkjEr/1HcBXerO/S8KazGOc psGDzw5EunHRMu1rsVgZJL5wi4cg0lQU0d7Ftxbce8snctQWW31cYsYW5cZkJfpDqsKm Wnn3Pn3KF6HCNPuZjhDfFojOnCXFeCk5gLNOTU/ZDFb8bEptb40F7HMYea8ICj4yTnIW +d4uyc+oFNm89ZJ1zhpI93qzX16ZvwEQL32qUUI+4dmWQg1Gs7ipZdt0m4qF1ZG/VGGS rxXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686219; x=1725291019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bOp3QknnppYKc6NqQXS9ioOC0GJa+R1wT3E/uYEWjyw=; b=KIiqrNHyMBA6CdDnaCZWvzrx7giNYkN6FW6kNcjOXBNyF9e5TDCCWEob4ba3DvloVw fd6ClFoMo+9ypyIMzBMzQ+ZGdk6KuO5r9lwGibpJH+b0dvEwCEyGYH1TEeDpZjmDA08C +SDUnTPw1ATbc5DP55AHlfZ4+XyyjcQZk8JO9pYHPmHIFfw7MhgpbljzHOcCWGRIsam3 7bvHi0/lARLhgJXrrRqWjHWZcnkk0Da1MyKCfAv2vm54mx58iUSC6XdhifF29DzzMGYm /PMHXaLDj6Ff3c1ndurFqL2KzxTWTCrM6kuusKS1xHJx4CQbs9EojuqXUnsiZPht600u aBWg== X-Forwarded-Encrypted: i=1; AJvYcCWum6GA63Wpxdlom/FHlkF9pYC3tzQUt5U4B47j/PNJSYUmrQAlFkRxbfZgXn2qTDqSP3QETVZkvNOv@nongnu.org X-Gm-Message-State: AOJu0YyEaqpDIU0Z3W1r+10KLsfYHiYO4vlRo0DZ/KOGaduk6f8NEKBX Dgh4pC72yv6geXwujMKv21W3UkGyfwV7ALf9RPityjKjL+ekvzg9LRIqxpdD2U0= X-Google-Smtp-Source: AGHT+IGdl35Idm1EusXF3TP5+nf4UF1EPWklSPJu93W73eTnZ/V+7n+z6PIUErKFRCb/2VRJgPXAYw== X-Received: by 2002:a05:6a20:2d13:b0:1c6:ed5e:24f with SMTP id adf61e73a8af0-1cc89d7dde9mr12273804637.23.1724686219149; Mon, 26 Aug 2024 08:30:19 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 07/17] disas/riscv: enable `lpad` disassembly Date: Mon, 26 Aug 2024 08:29:39 -0700 Message-ID: <20240826152949.294506-8-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::42b; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686269407116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- disas/riscv.c | 18 +++++++++++++++++- disas/riscv.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas/riscv.c index c8364c2b07..c7c92acef7 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -974,6 +974,7 @@ typedef enum { rv_op_amomaxu_h =3D 943, rv_op_amocas_b =3D 944, rv_op_amocas_h =3D 945, + rv_op_lpad =3D 946, } rv_op; =20 /* register names */ @@ -2232,6 +2233,7 @@ const rv_opcode_data rvi_opcode_data[] =3D { { "amomaxu.h", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "amocas.b", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "amocas.h", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, + { "lpad", rv_codec_lp, rv_fmt_imm, NULL, 0, 0, 0 }, }; =20 /* CSR names */ @@ -2925,7 +2927,13 @@ static void decode_inst_opcode(rv_decode *dec, rv_is= a isa) case 7: op =3D rv_op_andi; break; } break; - case 5: op =3D rv_op_auipc; break; + case 5: + op =3D rv_op_auipc; + if (dec->cfg->ext_zicfilp && + (((inst >> 7) & 0b11111) =3D=3D 0b00000)) { + op =3D rv_op_lpad; + } + break; case 6: switch ((inst >> 12) & 0b111) { case 0: op =3D rv_op_addiw; break; @@ -4482,6 +4490,11 @@ static uint32_t operand_tbl_index(rv_inst inst) return ((inst << 54) >> 56); } =20 +static uint32_t operand_lpl(rv_inst inst) +{ + return inst >> 12; +} + /* decode operands */ =20 static void decode_inst_operands(rv_decode *dec, rv_isa isa) @@ -4869,6 +4882,9 @@ static void decode_inst_operands(rv_decode *dec, rv_i= sa isa) dec->imm =3D sextract32(operand_rs2(inst), 0, 5); dec->imm1 =3D operand_imm2(inst); break; + case rv_codec_lp: + dec->imm =3D operand_lpl(inst); + break; }; } =20 diff --git a/disas/riscv.h b/disas/riscv.h index 16a08e4895..1182457aff 100644 --- a/disas/riscv.h +++ b/disas/riscv.h @@ -166,6 +166,7 @@ typedef enum { rv_codec_r2_immhl, rv_codec_r2_imm2_imm5, rv_codec_fli, + rv_codec_lp, } rv_codec; =20 /* structures */ @@ -228,6 +229,7 @@ enum { #define rv_fmt_rs1_rs2 "O\t1,2" #define rv_fmt_rd_imm "O\t0,i" #define rv_fmt_rd_uimm "O\t0,Ui" +#define rv_fmt_imm "O\ti" #define rv_fmt_rd_offset "O\t0,o" #define rv_fmt_rd_uoffset "O\t0,Uo" #define rv_fmt_rd_rs1_rs2 "O\t0,1,2" --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686333; cv=none; d=zohomail.com; s=zohoarc; b=PRA6PCc4emZVGrBYmo6Hxy1TXnDuy2s+GMuo1KxxNrOwjTJenv60wzEpBH//Ys0Vfx1+fWIRH7YKG+TB0LUolIYlmC/l4iMi/bRusbwReCGVGk7tVASI6GV02ZGa4HgM+GmXNLqNfnpXllkW1YlpqBMpKXxMkDKVWV7yPV7mb1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686333; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=N4mAJdMCJKnSHTZBg24BmY/PI6LJMup/le/nWxFZ0Nw=; b=JDvic5rT0lQF1lzYrpasf6eejH5SrNqWH27SBYdLJc8Tvt/NeuqddpveRpn6UroNVZC0CI2+blMAl6nXHIEgDMLp4bouB3BX4DdBzQ6kZrhzwjRoYdS7J3hx9b3K7AMvCuc1bi3z95ghHdyukSxOLT7LHkZjofK2CzTvqiILLlA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686332998134.00929712080517; Mon, 26 Aug 2024 08:32:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgL-0002LD-2y; Mon, 26 Aug 2024 11:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfp-0000W9-3A for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:35 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfi-0003eG-P8 for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:28 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-71446fefddfso2278020b3a.0 for ; Mon, 26 Aug 2024 08:30:21 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686220; x=1725291020; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N4mAJdMCJKnSHTZBg24BmY/PI6LJMup/le/nWxFZ0Nw=; b=OEVO0An5SxdoYseLIXxJwpJXmCHXp7Q0SbBwAsIezCoWS/Cu/zeIjF8+uCHba/2EXQ QgT5gSXf0NWwMvma6uWt9FbYLsjlUBNck5yvrpsrExGYZKzxskqUnt5SpS3nO9gsm1Ku 8zdeJp6XXFMl9ifI/J4taLYVb5OhNCzr33S72rg3TH5SF53WEz2znKrgPBXEdyBwSTyA N5K3kbqiiTugwspJNFqKMRLB3A0cJs7ZBiJ37OukN17HQd/6PJlSip4nl9HK6pTj1DkT VQhy5IhwisM3rB1252P9iXfQZq7lI6objd8URjYSiA6lc9QwKOcQzBDsdLY66bVx5Yt9 MtiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686220; x=1725291020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N4mAJdMCJKnSHTZBg24BmY/PI6LJMup/le/nWxFZ0Nw=; b=Y3vKob5RTk65jrqFz3AkU5742y4Vesmr4DQ688P36cdUw6KrrSgCjB5U2cDI84cXb1 QJ5OKRNw9VBN8JwlwgYy3dRqH6JmoHQKFLQcE9NpTwdPYC9+ifBHAPkyMLS831FcvehJ iJ1mPasV9APu7l8t2vmE0KohdRJDUiflh5t/+y3BMMBuNoDAhqT40Pd6xnJy4s5sKvIu CMIzjnzWrJNWxr2ECVMg4E17BVal3WvhLnl4cdF62Q4Eyn1vDMgDfRdo6kJ96VA0QFit qcD1NXtS9M0Pj4cYNYVzkxiF2eVQtwjXYA32zmIT1PVFQNSHMdTq3ivuXd7PDgcInEYd 9Y/g== X-Forwarded-Encrypted: i=1; AJvYcCUNCEhxC5W5g5xlytOUSZAIz/hLjS/faBBAGcHUEI2wZToZO0AF8WX1EHrlw1LB2Kg3vSfal9lAr4m9@nongnu.org X-Gm-Message-State: AOJu0Ywiqpo3Y3cTeJR9FCJgLyXRI92Tqs1dO2p/0nO4mzd9A3AquOl+ RrbCTtlmpoE37fmf+lWDUNRvhrSfxjY34oZGUhFpZb60uTossu65AMLiWj3lLQI= X-Google-Smtp-Source: AGHT+IG2bXTgG5KHjgkxE3SIq0YhLD/vIAVBYHQCWfCMmRG+J8Hm3JaLaf97Dpja3Kz0qG03LE3J3Q== X-Received: by 2002:a05:6a20:9e49:b0:1c4:818c:2986 with SMTP id adf61e73a8af0-1cc89d6b580mr12270988637.13.1724686220357; Mon, 26 Aug 2024 08:30:20 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 08/17] target/riscv: Add zicfiss extension Date: Mon, 26 Aug 2024 08:29:40 -0700 Message-ID: <20240826152949.294506-9-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::435; envelope-from=debug@rivosinc.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686333572116600 Content-Type: text/plain; charset="utf-8" zicfiss [1] riscv cpu extension enables backward control flow integrity. This patch sets up space for zicfiss extension in cpuconfig. And imple- ments dependency on A, zicsr, zimop and zcmop extensions. [1] - https://github.com/riscv/riscv-cfi Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu --- target/riscv/cpu.c | 2 ++ target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 083d405516..10a2a32345 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -107,6 +107,7 @@ const RISCVIsaExtData isa_edata_arr[] =3D { ISA_EXT_DATA_ENTRY(zicclsm, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(ziccrse, PRIV_VERSION_1_11_0, has_priv_1_11), ISA_EXT_DATA_ENTRY(zicfilp, PRIV_VERSION_1_12_0, ext_zicfilp), + ISA_EXT_DATA_ENTRY(zicfiss, PRIV_VERSION_1_13_0, ext_zicfiss), ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond), ISA_EXT_DATA_ENTRY(zicntr, PRIV_VERSION_1_12_0, ext_zicntr), ISA_EXT_DATA_ENTRY(zicsr, PRIV_VERSION_1_10_0, ext_zicsr), @@ -1482,6 +1483,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = =3D { MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), MULTI_EXT_CFG_BOOL("zifencei", ext_zifencei, true), MULTI_EXT_CFG_BOOL("zicfilp", ext_zicfilp, false), + MULTI_EXT_CFG_BOOL("zicfiss", ext_zicfiss, false), MULTI_EXT_CFG_BOOL("zicsr", ext_zicsr, true), MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), MULTI_EXT_CFG_BOOL("zihintpause", ext_zihintpause, true), diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 88d5defbb5..2499f38407 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -68,6 +68,7 @@ struct RISCVCPUConfig { bool ext_zicbop; bool ext_zicboz; bool ext_zicfilp; + bool ext_zicfiss; bool ext_zicond; bool ext_zihintntl; bool ext_zihintpause; diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index ed19586c9d..4da26cb926 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -618,6 +618,25 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, = Error **errp) cpu->cfg.ext_zihpm =3D false; } =20 + if (cpu->cfg.ext_zicfiss) { + if (!cpu->cfg.ext_zicsr) { + error_setg(errp, "zicfiss extension requires zicsr extension"); + return; + } + if (!riscv_has_ext(env, RVA)) { + error_setg(errp, "zicfiss extension requires A extension"); + return; + } + if (!cpu->cfg.ext_zimop) { + error_setg(errp, "zicfiss extension requires zimop extension"); + return; + } + if (cpu->cfg.ext_zca && !cpu->cfg.ext_zcmop) { + error_setg(errp, "zicfiss with zca requires zcmop extension"); + return; + } + } + if (!cpu->cfg.ext_zihpm) { cpu->cfg.pmu_mask =3D 0; cpu->pmu_avail_ctrs =3D 0; --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686332; cv=none; d=zohomail.com; s=zohoarc; b=DW0761oAc6zhu6CmBNIu9MtIUsIw3mNagMhpWNREK+P/TffuLzteWrxqWOsSSkTTmGlnmMVbpuWWy04LAkIgEOpDCF2pTl5i5mRWFU6yva7AMKYskq++OEpyus+Skmvg9wxNvKlvqUlL3GPPdPTFk9l3QCMU2iwYIZfdjXpdS3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686332; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MxUoZGEp5zDLbQSI45yWtGq0f34Gvz4lFSbU4saiGc8=; b=YmALUN0rma6+dOdVipG64v96pTEIJxtR/2Vi5BLOdd1s7XZ3AzPNzmQnrgJyIHCbfCIxWj4rjt3uWuV55Oeajkmkq0Z/BaSInz4mN3XYKuwK8UbkFWLgXhlubiHeXO3hJTM9Z2NZsntDs+IZSy8nYAMtxJ+uExMJc0FTa0ZlXNw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686332395721.4984231490041; Mon, 26 Aug 2024 08:32:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgG-0001n0-05; Mon, 26 Aug 2024 11:30:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfq-0000bA-U8 for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:39 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfl-0003eT-Lz for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:29 -0400 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-7c3ebba7fbbso3211639a12.1 for ; Mon, 26 Aug 2024 08:30:22 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686222; x=1725291022; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MxUoZGEp5zDLbQSI45yWtGq0f34Gvz4lFSbU4saiGc8=; b=XAZM2Ve3usf751uGUUuDP1d0LznvUmxnBjeKJizLPTyqcT1VIoa61WHr0YEu4j6Kvf atboyQ0BCK70M+bjrfUiInHDoQwbJIYxd8AjM3apqTWfjrG/Lzy0sl0F+dS4cYEZaz/Z 0QprRT0QJo+ZTZaxKdS7I0naOjwlc/C+aMvPhGF9AuVSjLlIUcesMhW72N3KBSeOsZ3x PCFPR6iJ7/zICDvo44w7xNup+FKZ8RU0+K6kk19TsAQSyFCNhma9bmMgXEg1PXBKOLE+ NcqeQKznjIm+W5bKIUovjZhcwttXS4sDk40yPvU7Lg9nrkHmzZaEy9YXu8+335e7yBmx 3Shw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686222; x=1725291022; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MxUoZGEp5zDLbQSI45yWtGq0f34Gvz4lFSbU4saiGc8=; b=kU8lZ1JEIPpiyHc3HD245dn5cxEyosLX5oPZKGewDh8VwlK88/ddfEsStaBi0ZgLhu mXjylUifz58inbbvtjRV/dPcbHY0LyXymAVtW5R11+X21f49Emcr9Y3+4zehLLO1/w55 HYnMOhAWbLlDkTBgBnn2oivZIGkcJzwr5hOQwADBMdT+vqeicL2wa+O6D1GJgNeipFp8 mHyB4WebqeWH5oW7Z3vJy7OhyASG8px9wqjMCvVwP5x6ThajUvBZ8+qtZH33KBsfcloG CvaVe6qr+BlhKXzwKVJtQuf0/0tzcBoSqNafYSZU4bOu53xJdhw2GbpIrvJMTczWfAIQ 2+5Q== X-Forwarded-Encrypted: i=1; AJvYcCXPKjISZJWhBorokK3nCtIhMgwEXQPs8eUzBb85OKQxlgNDK8lFmkIIf4ufXZNvWPgVbsK+uXKUWveC@nongnu.org X-Gm-Message-State: AOJu0YxDXcBhL88ee3yaSpWyOqCgO3RV8xHEd/scOCXxmXownI0CVaj+ vKeuQpPD4RA6lZIShFwKGBAwvAWO0MJgHA9ZHnU/4TQsJrYzM09ozExXS1E9qLo= X-Google-Smtp-Source: AGHT+IHVP3w+o7ck1wGVf813MrBZreusftgochDkJtCYoXXUWK8oWy0mKxeMr3iOjMXRY7yu0M5BEg== X-Received: by 2002:a05:6300:4c:b0:1c4:c160:2859 with SMTP id adf61e73a8af0-1cc89dcf828mr13068578637.31.1724686221578; Mon, 26 Aug 2024 08:30:21 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 09/17] target/riscv: introduce ssp and enabling controls for zicfiss Date: Mon, 26 Aug 2024 08:29:41 -0700 Message-ID: <20240826152949.294506-10-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::52b; envelope-from=debug@rivosinc.com; helo=mail-pg1-x52b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686333781116600 Content-Type: text/plain; charset="utf-8" zicfiss introduces a new state ssp ("shadow stack register") in cpu. ssp is expressed as a new unprivileged csr (CSR_SSP=3D0x11) and holds virtual address for shadow stack as programmed by software. Shadow stack (for each mode) is enabled via bit3 in *envcfg CSRs. Shadow stack can be enabled for a mode only if it's higher privileged mode had it enabled for itself. M mode doesn't need enabling control, it's always available if extension is available on cpu. This patch also implements helper bcfi function which determines if bcfi is enabled at current privilege or not. qemu-user also gets field `ubcfien` indicating whether qemu user has shadow stack enabled or not. Adds ssp to migration state as well. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson --- target/riscv/cpu.c | 5 ++++ target/riscv/cpu.h | 4 +++ target/riscv/cpu_bits.h | 6 +++++ target/riscv/cpu_helper.c | 25 +++++++++++++++++++ target/riscv/csr.c | 52 +++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 19 ++++++++++++++ 6 files changed, 111 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 10a2a32345..76f1edd15a 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -998,6 +998,9 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType= type) /* on reset elp is clear */ env->elp =3D false; =20 + /* on reset ssp is set to 0 */ + env->ssp =3D 0; + /* * Bits 10, 6, 2 and 12 of mideleg are read only 1 when the Hypervisor * extension is enabled. @@ -1026,6 +1029,8 @@ static void riscv_cpu_reset_hold(Object *obj, ResetTy= pe type) #ifdef CONFIG_USER_ONLY /* qemu-user for riscv, fcfi is off by default */ env->ufcfien =3D false; + /* qemu-user for riscv, bcfi is off by default */ + env->ubcfien =3D false; #endif =20 #ifndef CONFIG_USER_ONLY diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index edf540339a..5a57099d59 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -224,11 +224,14 @@ struct CPUArchState { =20 /* elp state for zicfilp extension */ bool elp; + /* shadow stack register for zicfiss extension */ + target_ulong ssp; /* sw check code for sw check exception */ target_ulong sw_check_code; #ifdef CONFIG_USER_ONLY uint32_t elf_flags; bool ufcfien; + bool ubcfien; #endif =20 #ifndef CONFIG_USER_ONLY @@ -534,6 +537,7 @@ bool riscv_cpu_vector_enabled(CPURISCVState *env); void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); int riscv_env_mmu_index(CPURISCVState *env, bool ifetch); bool cpu_get_fcfien(CPURISCVState *env); +bool cpu_get_bcfien(CPURISCVState *env); G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t reta= ddr); diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 900769ce60..48ce24dc32 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -34,6 +34,9 @@ =20 /* Control and Status Registers */ =20 +/* zicfiss user ssp csr */ +#define CSR_SSP 0x011 + /* User Trap Setup */ #define CSR_USTATUS 0x000 #define CSR_UIE 0x004 @@ -754,6 +757,7 @@ typedef enum RISCVException { /* Execution environment configuration bits */ #define MENVCFG_FIOM BIT(0) #define MENVCFG_LPE BIT(2) /* zicfilp */ +#define MENVCFG_SSE BIT(3) /* zicfiss */ #define MENVCFG_CBIE (3UL << 4) #define MENVCFG_CBCFE BIT(6) #define MENVCFG_CBZE BIT(7) @@ -768,12 +772,14 @@ typedef enum RISCVException { =20 #define SENVCFG_FIOM MENVCFG_FIOM #define SENVCFG_LPE MENVCFG_LPE +#define SENVCFG_SSE MENVCFG_SSE #define SENVCFG_CBIE MENVCFG_CBIE #define SENVCFG_CBCFE MENVCFG_CBCFE #define SENVCFG_CBZE MENVCFG_CBZE =20 #define HENVCFG_FIOM MENVCFG_FIOM #define HENVCFG_LPE MENVCFG_LPE +#define HENVCFG_SSE MENVCFG_SSE #define HENVCFG_CBIE MENVCFG_CBIE #define HENVCFG_CBCFE MENVCFG_CBCFE #define HENVCFG_CBZE MENVCFG_CBZE diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 172c945bf3..c9165b1d86 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -92,6 +92,31 @@ bool cpu_get_fcfien(CPURISCVState *env) #endif } =20 +bool cpu_get_bcfien(CPURISCVState *env) +{ + /* no cfi extension, return false */ + if (!env_archcpu(env)->cfg.ext_zicfiss) { + return false; + } +#ifdef CONFIG_USER_ONLY + return env->ubcfien; +#else + switch (env->priv) { + case PRV_U: + return env->senvcfg & SENVCFG_SSE; + case PRV_S: + if (env->virt_enabled) { + return env->henvcfg & HENVCFG_SSE; + } + return env->menvcfg & MENVCFG_SSE; + case PRV_M: /* M-mode shadow stack is always on if hart implements */ + return true; + default: + g_assert_not_reached(); + } +#endif +} + void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, uint64_t *cs_base, uint32_t *pflags) { diff --git a/target/riscv/csr.c b/target/riscv/csr.c index a5a969a377..ec04b2b32b 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -185,6 +185,25 @@ static RISCVException zcmt(CPURISCVState *env, int csr= no) return RISCV_EXCP_NONE; } =20 +static RISCVException cfi_ss(CPURISCVState *env, int csrno) +{ + if (!env_archcpu(env)->cfg.ext_zicfiss) { + return RISCV_EXCP_ILLEGAL_INST; + } + + /* if bcfi not active for current env, access to csr is illegal */ + if (!cpu_get_bcfien(env)) { +#if !defined(CONFIG_USER_ONLY) + if (env->debugger) { + return RISCV_EXCP_NONE; + } +#endif + return RISCV_EXCP_ILLEGAL_INST; + } + + return RISCV_EXCP_NONE; +} + #if !defined(CONFIG_USER_ONLY) static RISCVException mctr(CPURISCVState *env, int csrno) { @@ -596,6 +615,19 @@ static RISCVException seed(CPURISCVState *env, int csr= no) #endif } =20 +/* zicfiss CSR_SSP read and write */ +static int read_ssp(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val =3D env->ssp; + return RISCV_EXCP_NONE; +} + +static int write_ssp(CPURISCVState *env, int csrno, target_ulong val) +{ + env->ssp =3D val; + return RISCV_EXCP_NONE; +} + /* User Floating-Point CSRs */ static RISCVException read_fflags(CPURISCVState *env, int csrno, target_ulong *val) @@ -2111,6 +2143,10 @@ static RISCVException write_menvcfg(CPURISCVState *e= nv, int csrno, if (env_archcpu(env)->cfg.ext_zicfilp) { mask |=3D MENVCFG_LPE; } + + if (env_archcpu(env)->cfg.ext_zicfiss) { + mask |=3D MENVCFG_SSE; + } } env->menvcfg =3D (env->menvcfg & ~mask) | (val & mask); =20 @@ -2167,6 +2203,13 @@ static RISCVException write_senvcfg(CPURISCVState *e= nv, int csrno, mask |=3D SENVCFG_LPE; } =20 + /* Higher mode SSE must be ON for next-less mode SSE to be ON */ + if (env_archcpu(env)->cfg.ext_zicfiss && + get_field(env->menvcfg, MENVCFG_SSE) && + (env->virt_enabled ? get_field(env->henvcfg, HENVCFG_SSE) : true))= { + mask |=3D SENVCFG_SSE; + } + env->senvcfg =3D (env->senvcfg & ~mask) | (val & mask); return RISCV_EXCP_NONE; } @@ -2208,6 +2251,12 @@ static RISCVException write_henvcfg(CPURISCVState *e= nv, int csrno, if (env_archcpu(env)->cfg.ext_zicfilp) { mask |=3D HENVCFG_LPE; } + + /* H can light up SSE for VS only if HS had it from menvcfg */ + if (env_archcpu(env)->cfg.ext_zicfiss && + get_field(env->menvcfg, MENVCFG_SSE)) { + mask |=3D HENVCFG_SSE; + } } =20 env->henvcfg =3D (env->henvcfg & ~mask) | (val & mask); @@ -4663,6 +4712,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { /* Zcmt Extension */ [CSR_JVT] =3D {"jvt", zcmt, read_jvt, write_jvt}, =20 + /* zicfiss Extension, shadow stack register */ + [CSR_SSP] =3D { "ssp", cfi_ss, read_ssp, write_ssp }, + #if !defined(CONFIG_USER_ONLY) /* Machine Timers and Counters */ [CSR_MCYCLE] =3D { "mcycle", any, read_hpmcounter, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 873957c4ab..84d5ecf436 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -369,6 +369,24 @@ static const VMStateDescription vmstate_elp =3D { } }; =20 +static bool ssp_needed(void *opaque) +{ + RISCVCPU *cpu =3D opaque; + + return cpu->cfg.ext_zicfiss; +} + +static const VMStateDescription vmstate_ssp =3D { + .name =3D "cpu/ssp", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D ssp_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_UINTTL(env.ssp, RISCVCPU), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_riscv_cpu =3D { .name =3D "cpu", .version_id =3D 10, @@ -442,6 +460,7 @@ const VMStateDescription vmstate_riscv_cpu =3D { &vmstate_smstateen, &vmstate_jvt, &vmstate_elp, + &vmstate_ssp, NULL } }; --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686361; cv=none; d=zohomail.com; s=zohoarc; b=IU6EKEmsvJUrJcV3MjDz8iZaM/fc/+wR50pgwHT1HfSytLdN+wDEHmuj1gtxWbaie9tZ9fpgc1JPexXQqZXmiaJxJEoANZ0NEgXurNCfMIhhFczHtOK1fKc1PITcUYFFMf+YFVt6l2wt0kmH/osZLUS3a41rhLRCvCiU5PIHrJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686361; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jYm8/9jgywmCj/ElgHn9yuTvP9ALyRJoBpxeWehJuBk=; b=FAtGbclxgaRqyfXhY9/aY3Gx0Ibw3ynjelgbhIoK0gXcxgkTm9Oh2j6xNg222pqAZEsYvU+jeLHLPqpl+1LdngGOI8uMMMzcAY6pJ6FeKwZP+M8rTXhfnXEJRVFHfJYWHGpkIzswXgYMNfVtNK6d6MWpv9aH6VFx6BePBM2Grt4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686361901873.3040387897288; Mon, 26 Aug 2024 08:32:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgI-00026m-2Q; Mon, 26 Aug 2024 11:30:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfy-0000m4-5n for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:39 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfl-0003ei-MW for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:37 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7148912a1ebso793556b3a.0 for ; Mon, 26 Aug 2024 08:30:24 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686223; x=1725291023; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jYm8/9jgywmCj/ElgHn9yuTvP9ALyRJoBpxeWehJuBk=; b=f/NQzXbp5n/DNyPHiB43h0Ex2dtZMOQBcIdwuLQKtJTaUNePrlyr5qEBENAEFwi2DI aoduYM+cNqLo4uzMm78nEP/b+LWP8bLHJs+FuN11q4KMVZJjnrvbEq4LZLc+1SVsN4rT PaP2xrtmsqVqeN/imRZd/55sAQYefWmZ3m466TzTkLvCQUqdxkrCk0Kn78JPAiqz7bId Dop32uqBabdw6UFxN3HUV5d53YPTx6Bvb4EDpEUR7CX8RXshgUxNk6eWTy0uFsikRYhO UjNyAcWEC59xbXKj226YsDDOpYd839W7JIz+XTWWSBJDLxPgCg0JruosnR8hjbWmskBS IWBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686223; x=1725291023; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jYm8/9jgywmCj/ElgHn9yuTvP9ALyRJoBpxeWehJuBk=; b=coW6yxNJ2zJtF4beXkkhx52fIhRErFMSdXeHsLOKGPCr5d8dgNj6AOyln+rz1lXj3R Oeoe3gVVRkmX6Ha3gI2QArEAi2Vrswlwd8cvoJgkTUFHkcp+f/CxdIjbzeVgSNE2r8FU D+zRIEowTI/sCyiJCcHm5kw7KLfpVdrgOTDcM/aN10oEtIFKH1mHXbr7TD0FfQLf9tzi D06ZJlGi2SxvJBQD1xxkbVvnUhFztEdd0TkZ+jtEASl0pRmWvjFhTVDzrSxJRn/3X8ux NWdZMGAH2qwBPxyC5/fNYXecrtjFVdhWw+Z8EUtTbVSGAGH88Lm/Yi5gaT5ErqtPhDk7 npnw== X-Forwarded-Encrypted: i=1; AJvYcCWy4psSDvOs0zQYIY47KFVkiWMn7LzUkugaACitBIN09kCr6LsxOOYAycDblMhKVyU6e3r5kSZBmFrD@nongnu.org X-Gm-Message-State: AOJu0YxPphoqSMknozYuo7dNZP087rpP6XVw2fUWzZmgvOjU9XratN8t c0xm3vPpg7R02gd8+NHvrigBKtwIQN3mudInil6ELMwjOYruRd4jDQEonLBQOkA= X-Google-Smtp-Source: AGHT+IGo+tIUq/8H49AUo3vmrri+wH3+hcMHom63AMWUGze8MVhLU2kAUMgZYhG+nYdDfoHsKE1z7A== X-Received: by 2002:a05:6a00:23c7:b0:706:375e:220d with SMTP id d2e1a72fcca58-714458b2edcmr8875711b3a.30.1724686222751; Mon, 26 Aug 2024 08:30:22 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 10/17] target/riscv: tb flag for shadow stack instructions Date: Mon, 26 Aug 2024 08:29:42 -0700 Message-ID: <20240826152949.294506-11-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::432; envelope-from=debug@rivosinc.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686363739116600 Content-Type: text/plain; charset="utf-8" Shadow stack instructions can be decoded as zimop / zcmop or shadow stack instructions depending on whether shadow stack are enabled at current privilege. This requires a TB flag so that correct TB generation and correct TB lookup happens. `DisasContext` gets a field indicating whether bcfi is enabled or not. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 4 ++++ target/riscv/translate.c | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 5a57099d59..dcc3bc9d93 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -613,6 +613,8 @@ FIELD(TB_FLAGS, AXL, 26, 2) /* zicfilp needs a TB flag to track indirect branches */ FIELD(TB_FLAGS, FCFI_ENABLED, 28, 1) FIELD(TB_FLAGS, FCFI_LP_EXPECTED, 29, 1) +/* zicfiss needs a TB flag so that correct TB is located based on tb flags= */ +FIELD(TB_FLAGS, BCFI_ENABLED, 30, 1) =20 #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index c9165b1d86..ca6d8f1f39 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -168,6 +168,10 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *p= c, flags =3D FIELD_DP32(flags, TB_FLAGS, FCFI_ENABLED, 1); } =20 + if (cpu_get_bcfien(env)) { + flags =3D FIELD_DP32(flags, TB_FLAGS, BCFI_ENABLED, 1); + } + #ifdef CONFIG_USER_ONLY fs =3D EXT_STATUS_DIRTY; vs =3D EXT_STATUS_DIRTY; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index b5c0511b4b..b1d251e893 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -119,6 +119,8 @@ typedef struct DisasContext { /* zicfilp extension. fcfi_enabled, lp expected or not */ bool fcfi_enabled; bool fcfi_lp_expected; + /* zicfiss extension, if shadow stack was enabled during TB gen */ + bool bcfi_enabled; } DisasContext; =20 static inline bool has_ext(DisasContext *ctx, uint32_t ext) @@ -1241,6 +1243,8 @@ static void riscv_tr_init_disas_context(DisasContextB= ase *dcbase, CPUState *cs) ctx->pm_base_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, PM_BASE_ENABLE= D); ctx->ztso =3D cpu->cfg.ext_ztso; ctx->itrigger =3D FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); + ctx->bcfi_enabled =3D cpu_get_bcfien(env) && + FIELD_EX32(tb_flags, TB_FLAGS, BCFI_ENABLED); ctx->fcfi_lp_expected =3D FIELD_EX32(tb_flags, TB_FLAGS, FCFI_LP_EXPEC= TED); ctx->fcfi_enabled =3D FIELD_EX32(tb_flags, TB_FLAGS, FCFI_ENABLED); ctx->zero =3D tcg_constant_tl(0); --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686332; cv=none; d=zohomail.com; s=zohoarc; b=lT+uuMeS6Y3cQKFpgMmRq3KKhoYm06BDAbaOZs5m21JPRWdjWFaqF/yIUezLiwVs/Zn71teq2Jr6smT4MdusEMyu7l5lBoLxrMG8BOduZ3xmLo63ES7Zsbzv2Nbd287+6Hvkje4JF0zEtzaYdzsaQYLUEfhS5B4GB8Q8YR7DwpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686332; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Me2VGPUEXV7YOq9Qji0+deQmkhrMet0QMl6ntOV33uw=; b=YBns7dqd1JuvjtovT91cfmvawOqSeSAcyMCGowSJiZBgaiXMVlPxIYqz8DTAwpCICMVxfkJXiHiVRNnx6XwAQD7VomXFoOOC8Ldhev8E3rRd48oufllOAZz+YuCkmfXVVskJO/7Ge54/Fq9SvmMF6MgT1e71mShQibGgVUn2GzM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686332801856.6915750605677; Mon, 26 Aug 2024 08:32:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgL-0002LS-3n; Mon, 26 Aug 2024 11:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfq-0000b9-Tv for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:39 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfm-0003ev-Q3 for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:30 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-71423273c62so3151854b3a.0 for ; Mon, 26 Aug 2024 08:30:25 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686224; x=1725291024; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Me2VGPUEXV7YOq9Qji0+deQmkhrMet0QMl6ntOV33uw=; b=USXuF81LQmn4xiw51E6bu68/wWAppgcY1my/B/ec8Gm7rexhXcLnZHa/BmQHkRGbXM nJ7aQBH+mwevCgkJm8fHi/fsMf95RNkQKBkOp7Lw6D+G8rCixt9UX9GC+U9Q/ZpnIKK3 M1kuAWPNl36+pL6Ux3AIR1o8xObdGCC1LaO3LyeIXP6NwHdjb+T5j2Mx4icO9Eqa/AG9 Uxah5+BN/Y0YtO0bMAITi+fx+5cFUlwNmMGpXI0/bQpBUcnMWewrQGXRzIrsHyF1ixhu aQi29lYgCZWxztW/MmPy8+FlxBbhbOp/iGLhrvpB5gQAwncu0ilin/BX4cnJivt5i2we rpYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686224; x=1725291024; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Me2VGPUEXV7YOq9Qji0+deQmkhrMet0QMl6ntOV33uw=; b=vIXAgK5xSxGInK5gRPqKi05YulrP5e5pdhvMb0QbWe2ZR0j0MwzAepEophLd3frrUz mFPQ9/4dq3rD+a0rmVgY6dPAqS1PUr0FBW1gIBOPeEd6oWjavw8qWDufaeg2thTTjjLb Ja3+pYZ4dnWkk0kRcW5LF1Dcqps0f1sKDaKkIK+kvNym661tvFQauhGpZjQski/tzet4 5gTKyIFOjpUHCpXU5OWpbuYSQnQqKeHQzIAe1upa8vBe/tIeBgR6NkXp7cCoymmpnhc5 pZYwXkgq52/ahzNOfF0uNHfr+8k/jTZYsTpQTM8mrQeVQIb/BQj6tW31LcLHaKrrcbUy TuIQ== X-Forwarded-Encrypted: i=1; AJvYcCV4HQR0fnVwa8jLXM2/At9PsXEWqBUsQq2e4qmvqioI0rdlbwqFYUmvnvTJNhYcM9TbmnLhejRGPJUC@nongnu.org X-Gm-Message-State: AOJu0YzdI7KWBmTDVMJKL31P/eh+IGzm2Ij9uGyltpJBpshNT4K45YCT AOTFhYR/8nQ2UbHC2Z3kHxdFEaZ3DYETdSZ8TjpHvOVxuSdHCSodhJNWqeUJhR0= X-Google-Smtp-Source: AGHT+IFwOw5kp3XgTbFhJRYQIwFeEoS8rdxy9x5UXeI39UT3sPlDcioazsW120yFodYQ7cZKZkSrRw== X-Received: by 2002:a05:6a00:27a0:b0:70d:3337:7820 with SMTP id d2e1a72fcca58-71445d2dc44mr11632926b3a.8.1724686224137; Mon, 26 Aug 2024 08:30:24 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 11/17] target/riscv: mmu changes for zicfiss shadow stack protection Date: Mon, 26 Aug 2024 08:29:43 -0700 Message-ID: <20240826152949.294506-12-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::42c; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686333672116600 Content-Type: text/plain; charset="utf-8" zicfiss protects shadow stack using new page table encodings PTE.W=3D0, PTE.R=3D0 and PTE.X=3D0. This encoding is reserved if zicfiss is not implemented or if shadow stack are not enabled. Loads on shadow stack memory are allowed while stores to shadow stack memory leads to access faults. Shadow stack accesses to RO memory leads to store page fault. To implement special nature of shadow stack memory where only selected stores (shadow stack stores from sspush) have to be allowed while rest of regular stores disallowed, new MMU TLB index is created for shadow stack. Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson --- target/riscv/cpu_helper.c | 37 +++++++++++++++++++++++++++++++------ target/riscv/internals.h | 3 +++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index ca6d8f1f39..b10c3a35c4 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -892,6 +892,8 @@ static int get_physical_address(CPURISCVState *env, hwa= ddr *physical, hwaddr ppn; int napot_bits =3D 0; target_ulong napot_mask; + bool is_sstack_idx =3D ((mmu_idx & MMU_IDX_SS_WRITE) =3D=3D MMU_IDX_SS= _WRITE); + bool sstack_page =3D false; =20 /* * Check if we should use the background registers for the two @@ -1100,21 +1102,36 @@ restart: return TRANSLATE_FAIL; } =20 + target_ulong rwx =3D pte & (PTE_R | PTE_W | PTE_X); /* Check for reserved combinations of RWX flags. */ - switch (pte & (PTE_R | PTE_W | PTE_X)) { - case PTE_W: + switch (rwx) { case PTE_W | PTE_X: return TRANSLATE_FAIL; + case PTE_W: + /* if bcfi enabled, PTE_W is not reserved and shadow stack page */ + if (cpu_get_bcfien(env) && first_stage) { + sstack_page =3D true; + /* if ss index, read and write allowed. else only read allowed= */ + rwx =3D is_sstack_idx ? PTE_R | PTE_W : PTE_R; + break; + } + return TRANSLATE_FAIL; + case PTE_R: + /* shadow stack writes to readonly memory are page faults */ + if (is_sstack_idx && access_type =3D=3D MMU_DATA_STORE) { + return TRANSLATE_FAIL; + } + break; } =20 int prot =3D 0; - if (pte & PTE_R) { + if (rwx & PTE_R) { prot |=3D PAGE_READ; } - if (pte & PTE_W) { + if (rwx & PTE_W) { prot |=3D PAGE_WRITE; } - if (pte & PTE_X) { + if (rwx & PTE_X) { bool mxr =3D false; =20 /* @@ -1159,7 +1176,7 @@ restart: =20 if (!((prot >> access_type) & 1)) { /* Access check failed */ - return TRANSLATE_FAIL; + return sstack_page ? TRANSLATE_PMP_FAIL : TRANSLATE_FAIL; } =20 target_ulong updated_pte =3D pte; @@ -1346,9 +1363,17 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vad= dr addr, break; case MMU_DATA_LOAD: cs->exception_index =3D RISCV_EXCP_LOAD_ADDR_MIS; + /* shadow stack mis aligned accesses are access faults */ + if (mmu_idx & MMU_IDX_SS_WRITE) { + cs->exception_index =3D RISCV_EXCP_LOAD_ACCESS_FAULT; + } break; case MMU_DATA_STORE: cs->exception_index =3D RISCV_EXCP_STORE_AMO_ADDR_MIS; + /* shadow stack mis aligned accesses are access faults */ + if (mmu_idx & MMU_IDX_SS_WRITE) { + cs->exception_index =3D RISCV_EXCP_STORE_AMO_ACCESS_FAULT; + } break; default: g_assert_not_reached(); diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 0ac17bc5ad..ddbdee885b 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -30,12 +30,15 @@ * - U+2STAGE 0b100 * - S+2STAGE 0b101 * - S+SUM+2STAGE 0b110 + * - Shadow stack+U 0b1000 + * - Shadow stack+S 0b1001 */ #define MMUIdx_U 0 #define MMUIdx_S 1 #define MMUIdx_S_SUM 2 #define MMUIdx_M 3 #define MMU_2STAGE_BIT (1 << 2) +#define MMU_IDX_SS_WRITE (1 << 3) =20 static inline int mmuidx_priv(int mmu_idx) { --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686347; cv=none; d=zohomail.com; s=zohoarc; b=AYcC/EOd+i4oDs2s8JgLHjrXwWRM0DhLDroTpasL0obtbl1PgVAs3mb8ipqIOYg3/94CPb3+xb4DBiwVlxnOBWdXskXGCd79BgNYVuA8U60iA8e4xE7HdQmutIcsxxduewiZFnrccNVy05dQhfxaXSSpCtAxNcMN+ssBuZPWLKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686347; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=znWNnYeOmzcJgHiS5ciDaeObhwJSpJoTTA6dHVUZVcc=; b=NrgsDMZ016tXbOKtnL3ZRKzeUJ9vw6leB6T/eDJNmR6kNp7/pPBR4rpyn/+gpfRcOTClKuXHDS8/X+ySC2hp3uJ6XPKh0krsT3QFj+2pIdnS2pEDUehO0AUrY348HslSMB6TdsWCe0sevOBu6cWm5WhMrVlo+pfuAIS9zH24pkg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686347741475.82481667423076; Mon, 26 Aug 2024 08:32:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgI-0002C1-UV; Mon, 26 Aug 2024 11:30:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibft-0000h8-54 for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:39 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfo-0003fN-4M for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:32 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-71430e7eaf8so3433608b3a.1 for ; Mon, 26 Aug 2024 08:30:27 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686225; x=1725291025; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=znWNnYeOmzcJgHiS5ciDaeObhwJSpJoTTA6dHVUZVcc=; b=AkeMYODIBTNXU6Stf0BeMqNVUrfyrACD7kMgfC9gQCGrOGQ5vL7SoEwiJWTzriqjRo 3okJIGygDkyRaG+2ChqlEIwUR1NK9ZwK4V2GioeYUg54sRLvLQvGQZk/Tq68otxy+DoJ aWssAoIoziC6AFKz+BMlqVr6TRNU0XdjcQ2QhuypftrxOpJVmfwmfSFwPFviNjiQtsPj qZT/fsW4eSsOU3SW0rjPuZl5ie++743T8/FQLTbHaWZeWzvtRjlwG2Orok+hfNanNyNb uQN8d9rM/IB+qymhemhkL7zG2lLJDw8XU09wsxj6+2L8fF+cmdsyPOSKF0GTOAh6ix9y GPxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686225; x=1725291025; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=znWNnYeOmzcJgHiS5ciDaeObhwJSpJoTTA6dHVUZVcc=; b=LpLrjZfmHjjK1a6ZdURHm6pmj7U6hehAVwCliETndOeZb6i2ky/u7o5fRXJYLYWqPe KOozRz4mCXE4FSptRlmfKCwDjAieZpMIS0zqzQ1mlcG6Inzz48BRzoaIhYD9WZdcp755 e9fos5wOQTjiTzA0fHEs/PyVumrcXykzkoMmjmP11WMO2dEef77UJQUcmaLKvBvThV6Y tgPSCAMSq+y2j7o99ymSIscEGn2akieo6uRsqx2enuyTDT6TQgiPFsDAKcINbZMdpGBv 8u6KbLodlM6pJKgobMiQjNu0Y2VAXDet8H9NlD/8NKOYjaoHpJD9OI8et17kkF13uZv+ 15hA== X-Forwarded-Encrypted: i=1; AJvYcCXLipnkkL0QljRjoEMHU/nQS/+LVlRuLXgEaEVzmw66U6IiyiDDeOrxm1axojEYi46w/Zu+t3iKl6XO@nongnu.org X-Gm-Message-State: AOJu0YyJ3Nxvw5q9EcQtxfgywwCcYuXBI4PMR58djhHuJY5n13uGvPRX M3qdAm7IYcEcnYwyz/WVculHgTiUcrUR4qxk9f7hkcvsKyVK2ITNQi7512KLa6A= X-Google-Smtp-Source: AGHT+IGImoilKat6Lyq2mxYdMH2qRFsR4upGeF3pCc0VCdbzxaLNMbLGn6KIglHBrdT/jeNaA+1EEA== X-Received: by 2002:a05:6a20:d497:b0:1ca:ccd0:582b with SMTP id adf61e73a8af0-1cc89d29eb6mr9903634637.10.1724686225350; Mon, 26 Aug 2024 08:30:25 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 12/17] target/riscv: AMO operations always raise store/AMO fault Date: Mon, 26 Aug 2024 08:29:44 -0700 Message-ID: <20240826152949.294506-13-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::432; envelope-from=debug@rivosinc.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686349708116600 Content-Type: text/plain; charset="utf-8" This patch adds one more word for tcg compile which can be obtained during unwind time to determine fault type for original operation (example AMO). Depending on that, fault can be promoted to store/AMO fault. Signed-off-by: Deepak Gupta Suggested-by: Richard Henderson Reviewed-by: Richard Henderson --- target/riscv/cpu.h | 9 ++++++++- target/riscv/cpu_helper.c | 20 ++++++++++++++++++++ target/riscv/tcg/tcg-cpu.c | 1 + target/riscv/translate.c | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index dcc3bc9d93..3143141863 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -46,8 +46,13 @@ typedef struct CPUArchState CPURISCVState; /* * RISC-V-specific extra insn start words: * 1: Original instruction opcode + * 2: more information about instruction */ -#define TARGET_INSN_START_EXTRA_WORDS 1 +#define TARGET_INSN_START_EXTRA_WORDS 2 +/* + * b0: Whether a instruction always raise a store AMO or not. + */ +#define RISCV_UW2_ALWAYS_STORE_AMO 1 =20 #define RV(x) ((target_ulong)1 << (x - 'A')) =20 @@ -226,6 +231,8 @@ struct CPUArchState { bool elp; /* shadow stack register for zicfiss extension */ target_ulong ssp; + /* env place holder for extra word 2 during unwind */ + target_ulong excp_uw2; /* sw check code for sw check exception */ target_ulong sw_check_code; #ifdef CONFIG_USER_ONLY diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index b10c3a35c4..cb5cf1ce36 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1740,6 +1740,22 @@ static target_ulong riscv_transformed_insn(CPURISCVS= tate *env, return xinsn; } =20 +static target_ulong promote_load_fault(target_ulong orig_cause) +{ + switch (orig_cause) { + case RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT: + return RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT; + + case RISCV_EXCP_LOAD_ACCESS_FAULT: + return RISCV_EXCP_STORE_AMO_ACCESS_FAULT; + + case RISCV_EXCP_LOAD_PAGE_FAULT: + return RISCV_EXCP_STORE_PAGE_FAULT; + } + + /* if no promotion, return original cause */ + return orig_cause; +} /* * Handle Traps * @@ -1751,6 +1767,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; bool write_gva =3D false; + bool always_storeamo =3D (env->excp_uw2 & RISCV_UW2_ALWAYS_STORE_AMO); uint64_t s; =20 /* @@ -1784,6 +1801,9 @@ void riscv_cpu_do_interrupt(CPUState *cs) case RISCV_EXCP_STORE_AMO_ACCESS_FAULT: case RISCV_EXCP_LOAD_PAGE_FAULT: case RISCV_EXCP_STORE_PAGE_FAULT: + if (always_storeamo) { + cause =3D promote_load_fault(cause); + } write_gva =3D env->two_stage_lookup; tval =3D env->badaddr; if (env->two_stage_indirect_lookup) { diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 4da26cb926..83771303a8 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -129,6 +129,7 @@ static void riscv_restore_state_to_opc(CPUState *cs, env->pc =3D pc; } env->bins =3D data[1]; + env->excp_uw2 =3D data[2]; } =20 static const TCGCPUOps riscv_tcg_ops =3D { diff --git a/target/riscv/translate.c b/target/riscv/translate.c index b1d251e893..16fff70dac 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1265,7 +1265,7 @@ static void riscv_tr_insn_start(DisasContextBase *dcb= ase, CPUState *cpu) pc_next &=3D ~TARGET_PAGE_MASK; } =20 - tcg_gen_insn_start(pc_next, 0); + tcg_gen_insn_start(pc_next, 0, 0); ctx->insn_start_updated =3D false; } =20 --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686302; cv=none; d=zohomail.com; s=zohoarc; b=WV7ddjCBnhqgR+kq7x4eHB+EskPE9ku66evbyMWXqJXoNAlt8y4n/E35/qoMVaGbca+H3kW9JtPPEMz+QD12VKKPydgeEC4bn7WCjyCdFrY4aBgZ6lnUE8Q2TCkmy8R4vNCLX7XVVANSdNhdb77217B5187/05uAQvAyFvWYe/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686302; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CyQLd4VEiaZEDU+IbEBX2JDDfbtQtncP24IK0QpEAqA=; b=HoCpwZHwMh6pwpfWOVrhi8sEUpinIREe/Iv9LH1VeGdLjuLkVfBHVsTLxkg8sDceLzzyh7U/h/6wvvgTQDwMIHbkQDUYMV+SSWUw9jTcAWBSuR3+WKhFvObgmI2Z8f3Frbr88ob1vBXqI2aF4I7LQ5qUy4K8yHAztB6nc9NEvvM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686302021300.6434398441163; Mon, 26 Aug 2024 08:31:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgJ-0002G9-S2; Mon, 26 Aug 2024 11:30:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfy-0000m8-Ha for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:39 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfq-0003fZ-LI for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:37 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-714263cb074so3043629b3a.1 for ; Mon, 26 Aug 2024 08:30:28 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686227; x=1725291027; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CyQLd4VEiaZEDU+IbEBX2JDDfbtQtncP24IK0QpEAqA=; b=pp5HvCoqkGxnrl7pYKJG9Y6x/+SX9HfKeACkCZuQfa8MDAnn8snHkmDSgNghkPOo3c D5TWbkwYy1O+IMA6nY5idJHPr9gqBDjOZCufi4kh96Ugk+BDfIPb3TNiCb4/Z7d5FesD 7+rHaNKdRBYRp4wHLJ4mKSNK81CRa1K5baHfoT2DaAaOsD8+KQQgW0Zp8ACw5J4OIxGS bvvkqS7zUN73BHlfNpoliNS6MZwL7C3QnIylVZ1i7v1CAhsA1klGpp/prXuOzaItd8n6 Io0+2hp1WVigAY1PlXdQjLhuZWlEsgmNyfJwHQlxKl7IfWoFKdZMNYG0obIH7PC3fYFj HnUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686227; x=1725291027; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CyQLd4VEiaZEDU+IbEBX2JDDfbtQtncP24IK0QpEAqA=; b=re2PAfYAxtV222xvmAXOnVyMVL/nQlruAqrRL/gUC5lQjaLlYjyQQkjVmX06mYBH7T PSQQrczLqOY5emvwwAeV8+eWZj8dy7k7rwuBgRTwzT78RfGgKy95AiNSjKWSlJ+MkV2h 91pLTdWaMA7TuNmZTVjeye1zbxcVLRf454D2XFza9JJ2zLNwA/+G26r565KmakyylvDP xMXT6UWse0Otb8Rd51GAKyaM1GnafotjLYzLS4Qe0XBALXt1Zqqu2CTyxl1ETY15QrGE mKWlVc8jYalXpjyvHnk3F6iQenp0+5KxTJPLzXK7oVeuhz6qwKmDBgY+TEZH7ghdK9NG VRRw== X-Forwarded-Encrypted: i=1; AJvYcCWB5St8WneZEMmE/rA4COKFsx1vE+0XSjifKo7oxfAgnOQ17FCAI2g2vgerTZY3q9DYlnlugoey0pX2@nongnu.org X-Gm-Message-State: AOJu0YzvSIf6VIryHUHUHjSrYJJMZcdG+gKYrZ7CaDJrvbSgA7YM+RMC UiU+L5qyDv+voMuHFNFOpbv9qEpbdeQ+jAV9jterc5amrld7VZDfqffk8Xb3J32WjqswN9JtT22 i X-Google-Smtp-Source: AGHT+IE1iMEAXjDtga4rtZ6Ol7WsFlT5gepQE25yGQv3z6JDorIHPyTeWpABNYn3sUm4TqjndcPApQ== X-Received: by 2002:a05:6a00:190a:b0:70a:fb91:66d7 with SMTP id d2e1a72fcca58-71445dfe521mr12475699b3a.20.1724686226595; Mon, 26 Aug 2024 08:30:26 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 13/17] target/riscv: update `decode_save_opc` to store extra word2 Date: Mon, 26 Aug 2024 08:29:45 -0700 Message-ID: <20240826152949.294506-14-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::42a; envelope-from=debug@rivosinc.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686303727116600 Content-Type: text/plain; charset="utf-8" Extra word 2 is stored during tcg compile and `decode_save_opc` needs additional argument in order to pass the value. This will be used during unwind to get extra information about instruction like how to massage exceptions. Updated all callsites as well. Signed-off-by: Deepak Gupta Reviewed-by: Richard Henderson --- target/riscv/insn_trans/trans_privileged.c.inc | 8 ++++---- target/riscv/insn_trans/trans_rva.c.inc | 4 ++-- target/riscv/insn_trans/trans_rvd.c.inc | 4 ++-- target/riscv/insn_trans/trans_rvf.c.inc | 4 ++-- target/riscv/insn_trans/trans_rvh.c.inc | 8 ++++---- target/riscv/insn_trans/trans_rvi.c.inc | 6 +++--- target/riscv/insn_trans/trans_rvvk.c.inc | 10 +++++----- target/riscv/insn_trans/trans_rvzacas.c.inc | 4 ++-- target/riscv/insn_trans/trans_rvzfh.c.inc | 4 ++-- target/riscv/insn_trans/trans_svinval.c.inc | 6 +++--- target/riscv/translate.c | 11 ++++++----- 11 files changed, 35 insertions(+), 34 deletions(-) diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/= insn_trans/trans_privileged.c.inc index bc5263a4e0..ecd3b8b2c9 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -78,7 +78,7 @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) { #ifndef CONFIG_USER_ONLY if (has_ext(ctx, RVS)) { - decode_save_opc(ctx); + decode_save_opc(ctx, 0); translator_io_start(&ctx->base); gen_helper_sret(cpu_pc, tcg_env); exit_tb(ctx); /* no chaining */ @@ -95,7 +95,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); + decode_save_opc(ctx, 0); translator_io_start(&ctx->base); gen_helper_mret(cpu_pc, tcg_env); exit_tb(ctx); /* no chaining */ @@ -109,7 +109,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); + decode_save_opc(ctx, 0); gen_update_pc(ctx, ctx->cur_insn_len); gen_helper_wfi(tcg_env); return true; @@ -121,7 +121,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); + decode_save_opc(ctx, 0); gen_helper_tlb_flush(tcg_env); return true; #endif diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_tr= ans/trans_rva.c.inc index 39bbf60f3c..9cf3ae8019 100644 --- a/target/riscv/insn_trans/trans_rva.c.inc +++ b/target/riscv/insn_trans/trans_rva.c.inc @@ -34,7 +34,7 @@ static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemO= p mop) { TCGv src1; =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); src1 =3D get_address(ctx, a->rs1, 0); if (a->rl) { tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); @@ -61,7 +61,7 @@ static bool gen_sc(DisasContext *ctx, arg_atomic *a, MemO= p mop) TCGLabel *l1 =3D gen_new_label(); TCGLabel *l2 =3D gen_new_label(); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); src1 =3D get_address(ctx, a->rs1, 0); tcg_gen_brcond_tl(TCG_COND_NE, load_res, src1, l1); =20 diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_tr= ans/trans_rvd.c.inc index 1f5fac65a2..d779ec75c7 100644 --- a/target/riscv/insn_trans/trans_rvd.c.inc +++ b/target/riscv/insn_trans/trans_rvd.c.inc @@ -51,7 +51,7 @@ static bool trans_fld(DisasContext *ctx, arg_fld *a) memop |=3D MO_ATOM_WITHIN16; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); addr =3D get_address(ctx, a->rs1, a->imm); tcg_gen_qemu_ld_i64(cpu_fpr[a->rd], addr, ctx->mem_idx, memop); =20 @@ -71,7 +71,7 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a) memop |=3D MO_ATOM_WITHIN16; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); addr =3D get_address(ctx, a->rs1, a->imm); tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, memop); return true; diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_tr= ans/trans_rvf.c.inc index f771aa1939..084c184e65 100644 --- a/target/riscv/insn_trans/trans_rvf.c.inc +++ b/target/riscv/insn_trans/trans_rvf.c.inc @@ -52,7 +52,7 @@ static bool trans_flw(DisasContext *ctx, arg_flw *a) memop |=3D MO_ATOM_WITHIN16; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); addr =3D get_address(ctx, a->rs1, a->imm); dest =3D cpu_fpr[a->rd]; tcg_gen_qemu_ld_i64(dest, addr, ctx->mem_idx, memop); @@ -74,7 +74,7 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a) memop |=3D MO_ATOM_WITHIN16; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); addr =3D get_address(ctx, a->rs1, a->imm); tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, memop); return true; diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_tr= ans/trans_rvh.c.inc index aa9d41c18c..03c6694430 100644 --- a/target/riscv/insn_trans/trans_rvh.c.inc +++ b/target/riscv/insn_trans/trans_rvh.c.inc @@ -44,7 +44,7 @@ static bool do_hlv(DisasContext *ctx, arg_r2 *a, TCGv dest =3D dest_gpr(ctx, a->rd); TCGv addr =3D get_gpr(ctx, a->rs1, EXT_NONE); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); func(dest, tcg_env, addr); gen_set_gpr(ctx, a->rd, dest); return true; @@ -56,7 +56,7 @@ static bool do_hsv(DisasContext *ctx, arg_r2_s *a, TCGv addr =3D get_gpr(ctx, a->rs1, EXT_NONE); TCGv data =3D get_gpr(ctx, a->rs2, EXT_NONE); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); func(tcg_env, addr, data); return true; } @@ -147,7 +147,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); + decode_save_opc(ctx, 0); gen_helper_hyp_gvma_tlb_flush(tcg_env); return true; #endif @@ -158,7 +158,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); + decode_save_opc(ctx, 0); gen_helper_hyp_tlb_flush(tcg_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 b427f3a939..a619ea7c0e 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -326,7 +326,7 @@ static bool gen_load(DisasContext *ctx, arg_lb *a, MemO= p memop) if (ctx->cfg_ptr->ext_zama16b && (ctx->cur_insn_len !=3D 2)) { memop |=3D MO_ATOM_WITHIN16; } - decode_save_opc(ctx); + decode_save_opc(ctx, 0); if (get_xl(ctx) =3D=3D MXL_RV128) { out =3D gen_load_i128(ctx, a, memop); } else { @@ -427,7 +427,7 @@ static bool gen_store(DisasContext *ctx, arg_sb *a, Mem= Op memop) if (ctx->cfg_ptr->ext_zama16b && (ctx->cur_insn_len !=3D 2)) { memop |=3D MO_ATOM_WITHIN16; } - decode_save_opc(ctx); + decode_save_opc(ctx, 0); if (get_xl(ctx) =3D=3D MXL_RV128) { return gen_store_i128(ctx, a, memop); } else { @@ -889,7 +889,7 @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_= i *a) static bool do_csr_post(DisasContext *ctx) { /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ - decode_save_opc(ctx); + decode_save_opc(ctx, 0); /* We may have changed important cpu state -- exit to main loop. */ gen_update_pc(ctx, ctx->cur_insn_len); exit_tb(ctx); diff --git a/target/riscv/insn_trans/trans_rvvk.c.inc b/target/riscv/insn_t= rans/trans_rvvk.c.inc index ae1f40174a..27bf3f0b68 100644 --- a/target/riscv/insn_trans/trans_rvvk.c.inc +++ b/target/riscv/insn_trans/trans_rvvk.c.inc @@ -249,7 +249,7 @@ GEN_OPIVI_WIDEN_TRANS(vwsll_vi, IMM_ZX, vwsll_vx, vwsll= _vx_check) = \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { = \ /* save opcode for unwinding in case we throw an exception= */ \ - decode_save_opc(s); = \ + decode_save_opc(s, 0); = \ egs =3D tcg_constant_i32(EGS); = \ gen_helper_egs_check(egs, tcg_env); = \ } = \ @@ -322,7 +322,7 @@ GEN_V_UNMASKED_TRANS(vaesem_vs, vaes_check_vs, ZVKNED_E= GS) = \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { = \ /* save opcode for unwinding in case we throw an exception= */ \ - decode_save_opc(s); = \ + decode_save_opc(s, 0); = \ egs =3D tcg_constant_i32(EGS); = \ gen_helper_egs_check(egs, tcg_env); = \ } = \ @@ -389,7 +389,7 @@ GEN_VI_UNMASKED_TRANS(vaeskf2_vi, vaeskf2_check, ZVKNED= _EGS) = \ if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { = \ /* save opcode for unwinding in case we throw an exception= */ \ - decode_save_opc(s); = \ + decode_save_opc(s, 0); = \ egs =3D tcg_constant_i32(EGS); = \ gen_helper_egs_check(egs, tcg_env); = \ } = \ @@ -440,7 +440,7 @@ static bool trans_vsha2cl_vv(DisasContext *s, arg_rmrr = *a) =20 if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { /* save opcode for unwinding in case we throw an exception */ - decode_save_opc(s); + decode_save_opc(s, 0); egs =3D tcg_constant_i32(ZVKNH_EGS); gen_helper_egs_check(egs, tcg_env); } @@ -471,7 +471,7 @@ static bool trans_vsha2ch_vv(DisasContext *s, arg_rmrr = *a) =20 if (!s->vstart_eq_zero || !s->vl_eq_vlmax) { /* save opcode for unwinding in case we throw an exception */ - decode_save_opc(s); + decode_save_opc(s, 0); egs =3D tcg_constant_i32(ZVKNH_EGS); gen_helper_egs_check(egs, tcg_env); } diff --git a/target/riscv/insn_trans/trans_rvzacas.c.inc b/target/riscv/ins= n_trans/trans_rvzacas.c.inc index fcced99fc7..15e688a033 100644 --- a/target/riscv/insn_trans/trans_rvzacas.c.inc +++ b/target/riscv/insn_trans/trans_rvzacas.c.inc @@ -76,7 +76,7 @@ static bool gen_cmpxchg64(DisasContext *ctx, arg_atomic *= a, MemOp mop) TCGv src1 =3D get_address(ctx, a->rs1, 0); TCGv_i64 src2 =3D get_gpr_pair(ctx, a->rs2); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); tcg_gen_atomic_cmpxchg_i64(dest, src1, dest, src2, ctx->mem_idx, mop); =20 gen_set_gpr_pair(ctx, a->rd, dest); @@ -121,7 +121,7 @@ static bool trans_amocas_q(DisasContext *ctx, arg_amoca= s_q *a) =20 tcg_gen_concat_i64_i128(src2, src2l, src2h); tcg_gen_concat_i64_i128(dest, destl, desth); - decode_save_opc(ctx); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); tcg_gen_atomic_cmpxchg_i128(dest, src1, dest, src2, ctx->mem_idx, (MO_ALIGN | MO_TEUO)); =20 diff --git a/target/riscv/insn_trans/trans_rvzfh.c.inc b/target/riscv/insn_= trans/trans_rvzfh.c.inc index 1eb458b491..bece48e600 100644 --- a/target/riscv/insn_trans/trans_rvzfh.c.inc +++ b/target/riscv/insn_trans/trans_rvzfh.c.inc @@ -48,7 +48,7 @@ static bool trans_flh(DisasContext *ctx, arg_flh *a) REQUIRE_FPU; REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); t0 =3D get_gpr(ctx, a->rs1, EXT_NONE); if (a->imm) { TCGv temp =3D tcg_temp_new(); @@ -71,7 +71,7 @@ static bool trans_fsh(DisasContext *ctx, arg_fsh *a) REQUIRE_FPU; REQUIRE_ZFHMIN_OR_ZFBFMIN(ctx); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, 0); t0 =3D get_gpr(ctx, a->rs1, EXT_NONE); if (a->imm) { TCGv temp =3D tcg_temp_new(); diff --git a/target/riscv/insn_trans/trans_svinval.c.inc b/target/riscv/ins= n_trans/trans_svinval.c.inc index 0f692a1088..a06c3b214f 100644 --- a/target/riscv/insn_trans/trans_svinval.c.inc +++ b/target/riscv/insn_trans/trans_svinval.c.inc @@ -28,7 +28,7 @@ static bool trans_sinval_vma(DisasContext *ctx, arg_sinva= l_vma *a) /* Do the same as sfence.vma currently */ REQUIRE_EXT(ctx, RVS); #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_tlb_flush(tcg_env); return true; #endif @@ -57,7 +57,7 @@ static bool trans_hinval_vvma(DisasContext *ctx, arg_hinv= al_vvma *a) /* Do the same as hfence.vvma currently */ REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_hyp_tlb_flush(tcg_env); return true; #endif @@ -70,7 +70,7 @@ static bool trans_hinval_gvma(DisasContext *ctx, arg_hinv= al_gvma *a) /* Do the same as hfence.gvma currently */ REQUIRE_EXT(ctx, RVH); #ifndef CONFIG_USER_ONLY - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_hyp_gvma_tlb_flush(tcg_env); return true; #endif diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 16fff70dac..e677062a10 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -209,11 +209,12 @@ 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) +static void decode_save_opc(DisasContext *ctx, target_ulong excp_uw2) { assert(!ctx->insn_start_updated); ctx->insn_start_updated =3D true; tcg_set_insn_start_param(ctx->base.insn_start, 1, ctx->opcode); + tcg_set_insn_start_param(ctx->base.insn_start, 2, excp_uw2); } =20 static void gen_pc_plus_diff(TCGv target, DisasContext *ctx, @@ -699,7 +700,7 @@ static void gen_set_rm(DisasContext *ctx, int rm) } =20 /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_set_rounding_mode(tcg_env, tcg_constant_i32(rm)); } =20 @@ -712,7 +713,7 @@ static void gen_set_rm_chkfrm(DisasContext *ctx, int rm) ctx->frm_valid =3D true; =20 /* The helper may raise ILLEGAL_INSN -- record binv for unwind. */ - decode_save_opc(ctx); + decode_save_opc(ctx, 0); gen_helper_set_rounding_mode_chkfrm(tcg_env, tcg_constant_i32(rm)); } =20 @@ -1096,7 +1097,7 @@ static bool gen_amo(DisasContext *ctx, arg_atomic *a, mop |=3D MO_ALIGN; } =20 - decode_save_opc(ctx); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); src1 =3D get_address(ctx, a->rs1, 0); func(dest, src1, src2, ctx->mem_idx, mop); =20 @@ -1110,7 +1111,7 @@ static bool gen_cmpxchg(DisasContext *ctx, arg_atomic= *a, MemOp mop) TCGv src1 =3D get_address(ctx, a->rs1, 0); TCGv src2 =3D get_gpr(ctx, a->rs2, EXT_NONE); =20 - decode_save_opc(ctx); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); tcg_gen_atomic_cmpxchg_tl(dest, src1, dest, src2, ctx->mem_idx, mop); =20 gen_set_gpr(ctx, a->rd, dest); --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686362; cv=none; d=zohomail.com; s=zohoarc; b=XkbIV5LiQFV1jtvgNSdJQ3+VNkGHTEj00jG1GfrFHKEfpA2S3fIR6Fym1OFtKB7HG6mulr9QFh0QTpiVkmBMZG3KGlrLI7M1NrkNyk7JHD7eSsz1t0s/gcWIqlk84B4WxSO71xxfbEMPOBQ/zZY+rr9+SkSH0HzaJA8i5l+YHCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686362; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Y69mKXxyPX8y1KNCgiTZCjHNjCyFk/Zv9Q4fHwap7hc=; b=Hi9TTRC8RxV1hIDpG16YrKCWSFA5DLDNFW0JxJcNZkDFzcN8qyC9WPMHW1893Djvzon38rYpbWM2xsn9qOu13kxM1L+Ir0d0mptMwhmPC/VUFg0b/aSKO/6R9kBqlrxxKSyFWCe4lJxeiKysPjQ4ZMGJ85vhdKDJNsGdjxfBAic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686362683668.9634353628861; Mon, 26 Aug 2024 08:32:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgO-0002ip-PL; Mon, 26 Aug 2024 11:31:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfw-0000k6-Dw for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:39 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfq-0003fm-MD for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:35 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-7143ae1b48fso2480249b3a.1 for ; Mon, 26 Aug 2024 08:30:29 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686228; x=1725291028; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y69mKXxyPX8y1KNCgiTZCjHNjCyFk/Zv9Q4fHwap7hc=; b=fIFv3CYIxnc2Y6YA8tq2gBKBngjrq/XOa6zeTMduSwoz3kG9MF121UsusLYj5CiDny Qd0N+HcVIcPSInSZWRwfQUvmiJ16gV6n9cPFhbL8OdnTLymCXRDilYOO0HyOfkHdHjCT 3RZRCrZfVvjOoLnY5aI3qVfrMhRpyS6ViWqIh0S+kHhqm3tA11V9P/9UOigrjEca7vwd G/2kRR3+yk3XMO0f+4jafQ8KWY77DG2MNpTrAHoozi2WT7tJkEAD21rjYQGYT5nWbAwI JMZuKLwokrqelljIL4w8B4C31Sz/J9oYYGGynDZczTCe4/WfpCxGnm76bjKPknXGdJqy cEZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686228; x=1725291028; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y69mKXxyPX8y1KNCgiTZCjHNjCyFk/Zv9Q4fHwap7hc=; b=tZFFCVh0eXA07XgABWdBpGOpCVvLZAU04axQ2G/4Cq5F2ngKGYMej/wGaQeIFlZB+d nHgxwXYHFTvgWiPx/sV7Ld1YOv5XQNIU2kEjhSytdHKlypag6G79WFPhwAd3Nsbcv19I Y5xYoHf0GRKuAHxizukrEUADrzYsWyJadKA0F5f4gMFZiw1OInP7J21FpavFVYhJpczI Hyg2lkPuH4BZK68PKsbd4BIVdFZ8oNa/fZckdM7HvFWiS+SBKTp6bq2Vy62RQspioQfc 5TDbVdwsfErricltIJtiox6YLrGfw/J4sZ9KNM30385gOW7EhxGJlAwVUoiFJjlf/76N JWGg== X-Forwarded-Encrypted: i=1; AJvYcCW2KYhWLXkExXFnxbISs5ogifv/5EJcy7vSIcdcplxC2c9Nz2PwHZNqXBhAa/LfS5vjvC3nWMwSm+MV@nongnu.org X-Gm-Message-State: AOJu0YxKviaFS0xk7XdVpTSRbNAQVogycl1dUOCX68UD+ArjS98GEGKQ DfzwWwGLfwWQdhGtxxpczUgeT9U1q24lRhtLieIm+Bx6rMHi2UPaLP0/Zx45ej8= X-Google-Smtp-Source: AGHT+IGUPMxYsf3pWWoiRhHyOVtW+HbXVaU8Iu6u7K91kEIyWIqr0Qo0kIGsM0LJP375Y+VXrIHBQA== X-Received: by 2002:a05:6a20:38a0:b0:1cc:9f24:43 with SMTP id adf61e73a8af0-1cc9f240184mr4205176637.12.1724686227827; Mon, 26 Aug 2024 08:30:27 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 14/17] target/riscv: implement zicfiss instructions Date: Mon, 26 Aug 2024 08:29:46 -0700 Message-ID: <20240826152949.294506-15-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::433; envelope-from=debug@rivosinc.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686363870116600 Content-Type: text/plain; charset="utf-8" zicfiss has following instructions - sspopchk: pops a value from shadow stack and compares with x1/x5. If they dont match, reports a sw check exception with tval =3D 3. - sspush: pushes value in x1/x5 on shadow stack - ssrdp: reads current shadow stack - ssamoswap: swaps contents of shadow stack atomically sspopchk/sspush/ssrdp default to zimop if zimop implemented and SSE=3D0 If SSE=3D0, ssamoswap is illegal instruction exception. This patch implements shadow stack operations for qemu-user and shadow stack is not protected. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu --- target/riscv/cpu_bits.h | 2 + target/riscv/insn32.decode | 21 +++++- target/riscv/insn_trans/trans_rva.c.inc | 39 ++++++++++ target/riscv/insn_trans/trans_rvzicfiss.c.inc | 75 +++++++++++++++++++ target/riscv/translate.c | 5 ++ 5 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 target/riscv/insn_trans/trans_rvzicfiss.c.inc diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 48ce24dc32..bb62fbe9ec 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -690,6 +690,8 @@ typedef enum RISCVException { =20 /* zicfilp defines lp violation results in sw check with tval =3D 2*/ #define RISCV_EXCP_SW_CHECK_FCFI_TVAL 2 +/* zicfiss defines ss violation results in sw check with tval =3D 3*/ +#define RISCV_EXCP_SW_CHECK_BCFI_TVAL 3 =20 #define RISCV_EXCP_INT_FLAG 0x80000000 #define RISCV_EXCP_INT_MASK 0x7fffffff diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode index 27108b992b..e9139ec1b9 100644 --- a/target/riscv/insn32.decode +++ b/target/riscv/insn32.decode @@ -246,6 +246,7 @@ remud 0000001 ..... ..... 111 ..... 1111011 @r lr_w 00010 . . 00000 ..... 010 ..... 0101111 @atom_ld sc_w 00011 . . ..... ..... 010 ..... 0101111 @atom_st amoswap_w 00001 . . ..... ..... 010 ..... 0101111 @atom_st +ssamoswap_w 01001 . . ..... ..... 010 ..... 0101111 @atom_st amoadd_w 00000 . . ..... ..... 010 ..... 0101111 @atom_st amoxor_w 00100 . . ..... ..... 010 ..... 0101111 @atom_st amoand_w 01100 . . ..... ..... 010 ..... 0101111 @atom_st @@ -259,6 +260,7 @@ amomaxu_w 11100 . . ..... ..... 010 ..... 0101111 @ato= m_st lr_d 00010 . . 00000 ..... 011 ..... 0101111 @atom_ld sc_d 00011 . . ..... ..... 011 ..... 0101111 @atom_st amoswap_d 00001 . . ..... ..... 011 ..... 0101111 @atom_st +ssamoswap_d 01001 . . ..... ..... 011 ..... 0101111 @atom_st amoadd_d 00000 . . ..... ..... 011 ..... 0101111 @atom_st amoxor_d 00100 . . ..... ..... 011 ..... 0101111 @atom_st amoand_d 01100 . . ..... ..... 011 ..... 0101111 @atom_st @@ -1022,8 +1024,23 @@ amocas_d 00101 . . ..... ..... 011 ..... 0101111 = @atom_st amocas_q 00101 . . ..... ..... 100 ..... 0101111 @atom_st =20 # *** Zimop may-be-operation extension *** -mop_r_n 1 . 00 .. 0111 .. ..... 100 ..... 1110011 @mop5 -mop_rr_n 1 . 00 .. 1 ..... ..... 100 ..... 1110011 @mop3 +{ + # zicfiss instructions carved out of mop.r + [ + ssrdp 1100110 11100 00000 100 rd:5 1110011 + sspopchk 1100110 11100 00001 100 00000 1110011 &r2 rs1=3D1 rd=3D0 + sspopchk 1100110 11100 00101 100 00000 1110011 &r2 rs1=3D5 rd=3D0 + ] + mop_r_n 1 . 00 .. 0111 .. ..... 100 ..... 1110011 @mop5 +} +{ + # zicfiss instruction carved out of mop.rr + [ + sspush 1100111 00001 00000 100 00000 1110011 &r2_s rs2=3D1 rs1=3D0 + sspush 1100111 00101 00000 100 00000 1110011 &r2_s rs2=3D5 rs1=3D0 + ] + mop_rr_n 1 . 00 .. 1 ..... ..... 100 ..... 1110011 @mop3 +} =20 # *** Zabhb Standard Extension *** amoswap_b 00001 . . ..... ..... 000 ..... 0101111 @atom_st diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_tr= ans/trans_rva.c.inc index 9cf3ae8019..a2119393a6 100644 --- a/target/riscv/insn_trans/trans_rva.c.inc +++ b/target/riscv/insn_trans/trans_rva.c.inc @@ -114,6 +114,25 @@ static bool trans_amoswap_w(DisasContext *ctx, arg_amo= swap_w *a) return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, MO_TESL); } =20 +static bool trans_ssamoswap_w(DisasContext *ctx, arg_amoswap_w *a) +{ + REQUIRE_A_OR_ZAAMO(ctx); + if (!ctx->bcfi_enabled) { + return false; + } + + TCGv dest =3D dest_gpr(ctx, a->rd); + TCGv src1, src2 =3D get_gpr(ctx, a->rs2, EXT_NONE); + + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); + src1 =3D get_address(ctx, a->rs1, 0); + + tcg_gen_atomic_xchg_tl(dest, src1, src2, SS_MMU_INDEX(ctx), + (MO_ALIGN | MO_TESL)); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + static bool trans_amoadd_w(DisasContext *ctx, arg_amoadd_w *a) { REQUIRE_A_OR_ZAAMO(ctx); @@ -183,6 +202,26 @@ static bool trans_amoswap_d(DisasContext *ctx, arg_amo= swap_d *a) return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, MO_TEUQ); } =20 +static bool trans_ssamoswap_d(DisasContext *ctx, arg_amoswap_w *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_A_OR_ZAAMO(ctx); + if (!ctx->bcfi_enabled) { + return false; + } + + TCGv dest =3D dest_gpr(ctx, a->rd); + TCGv src1, src2 =3D get_gpr(ctx, a->rs2, EXT_NONE); + + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); + src1 =3D get_address(ctx, a->rs1, 0); + + tcg_gen_atomic_xchg_tl(dest, src1, src2, SS_MMU_INDEX(ctx), + (MO_ALIGN | MO_TESQ)); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a) { REQUIRE_64BIT(ctx); diff --git a/target/riscv/insn_trans/trans_rvzicfiss.c.inc b/target/riscv/i= nsn_trans/trans_rvzicfiss.c.inc new file mode 100644 index 0000000000..741459003d --- /dev/null +++ b/target/riscv/insn_trans/trans_rvzicfiss.c.inc @@ -0,0 +1,75 @@ +/* + * RISC-V translation routines for the Control-Flow Integrity Extension + * + * Copyright (c) 2024 Rivos Inc. + * + * 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 . + */ +static bool trans_sspopchk(DisasContext *ctx, arg_sspopchk *a) +{ + if (!ctx->bcfi_enabled) { + return false; + } + + TCGv addr =3D tcg_temp_new(); + TCGLabel *skip =3D gen_new_label(); + uint32_t tmp =3D (get_xl(ctx) =3D=3D MXL_RV64) ? 8 : 4; + TCGv data =3D tcg_temp_new(); + tcg_gen_ld_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); + tcg_gen_qemu_ld_tl(data, addr, SS_MMU_INDEX(ctx), + mxl_memop(ctx) | MO_ALIGN); + TCGv rs1 =3D get_gpr(ctx, a->rs1, EXT_NONE); + tcg_gen_brcond_tl(TCG_COND_EQ, data, rs1, skip); + tcg_gen_st_tl(tcg_constant_tl(RISCV_EXCP_SW_CHECK_BCFI_TVAL), + tcg_env, offsetof(CPURISCVState, sw_check_code)); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_SW_CHECK)); + gen_set_label(skip); + tcg_gen_addi_tl(addr, addr, tmp); + tcg_gen_st_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + + return true; +} + +static bool trans_sspush(DisasContext *ctx, arg_sspush *a) +{ + if (!ctx->bcfi_enabled) { + return false; + } + + TCGv addr =3D tcg_temp_new(); + int tmp =3D (get_xl(ctx) =3D=3D MXL_RV64) ? -8 : -4; + TCGv data =3D get_gpr(ctx, a->rs2, EXT_NONE); + decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO); + tcg_gen_ld_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + tcg_gen_addi_tl(addr, addr, tmp); + tcg_gen_qemu_st_tl(data, addr, SS_MMU_INDEX(ctx), + mxl_memop(ctx) | MO_ALIGN); + tcg_gen_st_tl(addr, tcg_env, offsetof(CPURISCVState, ssp)); + + return true; +} + +static bool trans_ssrdp(DisasContext *ctx, arg_ssrdp *a) +{ + if (!ctx->bcfi_enabled || a->rd =3D=3D 0) { + return false; + } + + TCGv dest =3D dest_gpr(ctx, a->rd); + tcg_gen_ld_tl(dest, tcg_env, offsetof(CPURISCVState, ssp)); + gen_set_gpr(ctx, a->rd, dest); + + return true; +} diff --git a/target/riscv/translate.c b/target/riscv/translate.c index e677062a10..2753c154ba 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -144,6 +144,8 @@ static inline bool has_ext(DisasContext *ctx, uint32_t = ext) #define get_address_xl(ctx) ((ctx)->address_xl) #endif =20 +#define mxl_memop(ctx) ((get_xl(ctx) + 1) | MO_TE) + /* The word size for this machine mode. */ static inline int __attribute__((unused)) get_xlen(DisasContext *ctx) { @@ -1127,6 +1129,8 @@ static uint32_t opcode_at(DisasContextBase *dcbase, t= arget_ulong pc) return translator_ldl(env, &ctx->base, pc); } =20 +#define SS_MMU_INDEX(ctx) (ctx->mem_idx | MMU_IDX_SS_WRITE) + /* Include insn module translation function */ #include "insn_trans/trans_rvi.c.inc" #include "insn_trans/trans_rvm.c.inc" @@ -1157,6 +1161,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, t= arget_ulong pc) #include "decode-insn16.c.inc" #include "insn_trans/trans_rvzce.c.inc" #include "insn_trans/trans_rvzcmop.c.inc" +#include "insn_trans/trans_rvzicfiss.c.inc" =20 /* Include decoders for factored-out extensions */ #include "decode-XVentanaCondOps.c.inc" --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686322; cv=none; d=zohomail.com; s=zohoarc; b=Yl2pS3Qz4KM/gD3xFClvQgnbONIisJ0OviZxnO6J6msegmf+e4PyFuyRKfZlLh1wPwIfz0HjSmj6/p4rf00a6TwoU9mf1wlQTnlbUnyhyOZgn8mejCowq9wKHVpeMNLMfcVEip1gIBsCWzeuqIJphaJIoYxjqtOFa5kEDBTaIVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686322; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hmHRx8s/W32kMwfWaFprt4Qicp4zWaDvYB7fNr0JPCQ=; b=W7rf67AqUc59A7INVrcU8XGUVe50TJeUEpGSxgHrEMJ+sOsIjDd8cAuJO+jXcjVtjg24ERPFMBWgFz+EYOuDOhsMAsLrllv8Scj5OEsfUHmN3yz5ApNmsUs+UlR47iw9WSFEIfDUac56iBOYLTSuIz/AFKlzJvj+d+gBY0IPWyM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17246863219987.842181158964877; Mon, 26 Aug 2024 08:32:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgN-0002VO-Av; Mon, 26 Aug 2024 11:31:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfu-0000hl-Gx for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:39 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfq-0003gD-Lw for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:33 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-714226888dfso3999304b3a.1 for ; Mon, 26 Aug 2024 08:30:30 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686229; x=1725291029; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hmHRx8s/W32kMwfWaFprt4Qicp4zWaDvYB7fNr0JPCQ=; b=QDcE22P6ZrhG3aLZMADRlECD5YxSfFnV1cu/xm4yquqygzTSH1zCG5GUr0Vcho3jR1 O7ODshj2aespQY2Lc/59Hs+YJZSAWCSCCBtZ3rIMzkN5YvE7i48KYGctav4BEJZQP3Dc KGCxSw79bsusHGf1473w4Gas29Sj/Ya+EN7a9i14lMSHUiLPS87KaSc3HtEaTBuRgyXL 9kcM6p9gP1LzhO64ahVVtZItFt1ikB22y4vwCq6Tld/FDItQPOrFWzeqEy/2FZNlrQfv Ww41VMI4nn0G400rd3/AyeOtR4ZWNUDKYp6Ir97y1XA+N+X8d2BtKGdRNqwXRWcSGsP+ tieg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686229; x=1725291029; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hmHRx8s/W32kMwfWaFprt4Qicp4zWaDvYB7fNr0JPCQ=; b=iCaCcOzAv7KjfRYbGKBKHkqagYforZ5J1i7tfdRzzpGHD4iLBMpIBs20oNLbHxywcL GjdnHoXmARJFA0wQDcPNGXgL32DkLQSRUeNRKV4eWyVCk9CTdiTXW3QrtLmYYqes/5gx 2gzwxVZJjfhqUhxy7WbNEiseCHItBNd0hAW3KNLDAH959GulsPTDje1HE0K/USZS2dyV 3aZmi00oCreaD83xSOPcGL13/hEjJ3KQA4cDFV7gW1oEZaep8lDYfqz7wWb/Zg463PVK rfbKcTDG4sVKFMKj25RGH9diJJHREtg/hDV29VOgvdR3h9CFG3L5ghMt4sONYEqz+8sm lL4w== X-Forwarded-Encrypted: i=1; AJvYcCVajq57MwioQvT05EOBlYIKfO9/Ff6M6iY+M1FZI0ZxRFpcG+QS5C1xhGuRDv1XI3p01ZwMe4IA+yDB@nongnu.org X-Gm-Message-State: AOJu0YxfRKKEAGh+6KLdWgGAZBzaEnuj4ZIUtwy5dL6fPveWmkClFUZT TrlHd5l3EbvX341U0jgsyeG+Fqxi5Y+02+Y53jVmH7vr6V6QytdGKGcIKeTubss= X-Google-Smtp-Source: AGHT+IHvS+jW3nPSNvl5yWY07+f8UFZBD+qNzPtfGzfVQ6lIKEqeYP7hpy4D/uY5Ak31I+PcF4Wy6w== X-Received: by 2002:a05:6a20:c909:b0:1c6:ae03:670b with SMTP id adf61e73a8af0-1cc89d29dadmr13222715637.9.1724686229058; Mon, 26 Aug 2024 08:30:29 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 15/17] target/riscv: compressed encodings for sspush and sspopchk Date: Mon, 26 Aug 2024 08:29:47 -0700 Message-ID: <20240826152949.294506-16-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::432; envelope-from=debug@rivosinc.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686323586116600 Content-Type: text/plain; charset="utf-8" sspush/sspopchk have compressed encodings carved out of zcmops. compressed sspush is designated as c.mop.1 while compressed sspopchk is designated as c.mop.5. Note that c.sspush x1 exists while c.sspush x5 doesn't. Similarly c.sspopchk x5 exists while c.sspopchk x1 doesn't. Signed-off-by: Deepak Gupta Co-developed-by: Jim Shu Co-developed-by: Andy Chiu Reviewed-by: Richard Henderson --- target/riscv/insn16.decode | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/riscv/insn16.decode b/target/riscv/insn16.decode index 3953bcf82d..bf893d1c2e 100644 --- a/target/riscv/insn16.decode +++ b/target/riscv/insn16.decode @@ -140,6 +140,10 @@ sw 110 ... ... .. ... 00 @cs_w addi 000 . ..... ..... 01 @ci addi 010 . ..... ..... 01 @c_li { + # c.sspush x1 carving out of zcmops + sspush 011 0 00001 00000 01 &r2_s rs2=3D1 rs1=3D0 + # c.sspopchk x5 carving out of zcmops + sspopchk 011 0 00101 00000 01 &r2 rs1=3D5 rd=3D0 c_mop_n 011 0 0 n:3 1 00000 01 illegal 011 0 ----- 00000 01 # c.addi16sp and c.lui, RES nzimm= =3D0 addi 011 . 00010 ..... 01 @c_addi16sp --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686339; cv=none; d=zohomail.com; s=zohoarc; b=AysiYHhJmYgjqZR94gnt5SpLvSbO0O9W3WYBtrAuOOqgUTDtGHNP1hdomq4fnSzW8feWElzrtySNST5ecR0bbmChCctpPxTkvjUdO57gFU5cqiSwjMzyZyydi+RBfcIzvoTeMR6J0HwbGSVYegL5XDa/pQbMbhJ5XvCSl4UCMm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686339; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O8YdqZUU8+ncezbzq+2x/I5a8BTFehZZsPQ1BjWfojs=; b=IHnjWgZQOVE5sGZbTGhY9YNLIBY6kItJVlYxnHw0nWDNQGKRjU2dlrKg8cavyg4Vh03yehp8S2LETxcspDY8X8SQonrfcxJZKaW5AUkRBrEe8NLb45sU8HThl+LZDvzy+OQTX0zlfoAgfrSnAihXbx+Lp434bEzDxkS21co5yUQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686339348462.8949677090993; Mon, 26 Aug 2024 08:32:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgL-0002NM-G9; Mon, 26 Aug 2024 11:31:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibfz-0000pd-KP for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:42 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibfs-0003gc-Hp for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:39 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-714114be925so3869557b3a.2 for ; Mon, 26 Aug 2024 08:30:31 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686230; x=1725291030; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O8YdqZUU8+ncezbzq+2x/I5a8BTFehZZsPQ1BjWfojs=; b=Xb7QPcwGQBikvC9mG0+/Dhs5CpjPk2pyXkqqeHwoiXwL/p8pcPCjaCkc2ygWnEpmZf 2Ff9npNh4wpKFrrwlTnIFyUElUsaAYTvooXWVtTsbizy7/tJvfUu548xTBrQMKcMNqIr +h14qATPrfZmoFHukkAQEssPLLFSaKZE4zavv4vKKLdO55AGxToc+hR3ROU8UN1P9Pd4 7PUy1CvTcgQ4dozkRLbL/qb1tGHQt39owr1YqBImLkAWm0F6nFBPeZ5SzbufoDBO74fQ HWwEXYd3PqvR20nRLtsFcT+DZA8MFYJ0tU/sjqDTUWJ5iWXj3e6iPuNwYg+noRifI5rA Vo+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686230; x=1725291030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O8YdqZUU8+ncezbzq+2x/I5a8BTFehZZsPQ1BjWfojs=; b=YdnGN0lAVLxLZBj/laPPvf8va6nZ1gZQN1DrpFhj98jNTCxZTuzp2z7tRzCjIj5o+2 gqnBs5TO3pOqjvYPC2Ruzj3uBDcteMzK0KnSllh/zQNHS3OZqW9uB1sOF15SL4W2w0DM VkX5MADbYrswvyr+L0sguBYCsnxIan91baeM+9Gd7BrgGTPbmX1ikg/m02Rnkd/xLwcV OoTQTdMtwHdqWKaPKuy7UWHTQlZictzQuR5I2Lpq6ZJXjDTcSd/DnWApW5rr0hMkHTeF iyc34Feb9RuWXQGWbTY66kxFfvvfMEhKWlk9B8lQm+gkBqUrCiHdtgeRhJ/GoJ84lCpw 7Aig== X-Forwarded-Encrypted: i=1; AJvYcCUdUG56sEKRaU6SMTHxlKdi3j+S+irMLWoqNXvHV/Y2CmfJEAIeIRhWsHXQ2MgWE2zJBfduuQqN9V/5@nongnu.org X-Gm-Message-State: AOJu0YyXiTfImeWwIF5nLHWtRWh6s7I+Cmi74dkanXgfX/p3e8f1+W8X OWyppdvRF19JY0tntP3QHgGu85jdKvMS8sh1je/nmv9uYoGi5X67RDulJIetxjY= X-Google-Smtp-Source: AGHT+IFvCWHO7Fx8C0DFM8aZnCtEK0BNdwrz8agxYvQawE1NGmXZGbxH7P3aKoYsA+Dvh47MaOrwKw== X-Received: by 2002:a05:6a21:3417:b0:1c6:9e5e:2ec4 with SMTP id adf61e73a8af0-1cc8a0846c5mr13634294637.50.1724686230282; Mon, 26 Aug 2024 08:30:30 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 16/17] disas/riscv: enable disassembly for zicfiss instructions Date: Mon, 26 Aug 2024 08:29:48 -0700 Message-ID: <20240826152949.294506-17-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::430; envelope-from=debug@rivosinc.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686339731116600 Content-Type: text/plain; charset="utf-8" Enable disassembly for sspush, sspopchk, ssrdp & ssamoswap. Disasembly is only enabled if zimop and zicfiss ext is set to true. Signed-off-by: Deepak Gupta --- disas/riscv.c | 40 +++++++++++++++++++++++++++++++++++++++- disas/riscv.h | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas/riscv.c index c7c92acef7..5eafb7f7f3 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -975,6 +975,11 @@ typedef enum { rv_op_amocas_b =3D 944, rv_op_amocas_h =3D 945, rv_op_lpad =3D 946, + rv_op_sspush =3D 947, + rv_op_sspopchk =3D 948, + rv_op_ssrdp =3D 949, + rv_op_ssamoswap_w =3D 950, + rv_op_ssamoswap_d =3D 951, } rv_op; =20 /* register names */ @@ -2234,6 +2239,11 @@ const rv_opcode_data rvi_opcode_data[] =3D { { "amocas.b", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "amocas.h", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "lpad", rv_codec_lp, rv_fmt_imm, NULL, 0, 0, 0 }, + { "sspush", rv_codec_r, rv_fmt_rs2, NULL, 0, 0, 0 }, + { "sspopchk", rv_codec_r, rv_fmt_rs1, NULL, 0, 0, 0 }, + { "ssrdp", rv_codec_r, rv_fmt_rd, NULL, 0, 0, 0 }, + { "ssamoswap.w", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, + { "ssamoswap.d", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, }; =20 /* CSR names */ @@ -2251,6 +2261,7 @@ static const char *csr_name(int csrno) case 0x0009: return "vxsat"; case 0x000a: return "vxrm"; case 0x000f: return "vcsr"; + case 0x0011: return "ssp"; case 0x0015: return "seed"; case 0x0017: return "jvt"; case 0x0040: return "uscratch"; @@ -3077,6 +3088,8 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa= isa) case 66: op =3D rv_op_amoor_w; break; case 67: op =3D rv_op_amoor_d; break; case 68: op =3D rv_op_amoor_q; break; + case 74: op =3D rv_op_ssamoswap_w; break; + case 75: op =3D rv_op_ssamoswap_d; break; case 96: op =3D rv_op_amoand_b; break; case 97: op =3D rv_op_amoand_h; break; case 98: op =3D rv_op_amoand_w; break; @@ -4028,7 +4041,7 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa= isa) case 3: op =3D rv_op_csrrc; break; case 4: if (dec->cfg->ext_zimop) { - int imm_mop5, imm_mop3; + int imm_mop5, imm_mop3, reg_num; if ((extract32(inst, 22, 10) & 0b1011001111) =3D=3D 0b1000000111) { imm_mop5 =3D deposit32(deposit32(extract32(inst, 2= 0, 2), @@ -4036,11 +4049,36 @@ static void decode_inst_opcode(rv_decode *dec, rv_i= sa isa) extract32(inst, 26,= 2)), 4, 1, extract32(inst, 30, 1)); op =3D rv_mop_r_0 + imm_mop5; + /* if zicfiss enabled and mop5 is shadow stack */ + if (dec->cfg->ext_zicfiss && + ((imm_mop5 & 0b11100) =3D=3D 0b11100)) { + /* rs1=3D0 means ssrdp */ + if ((inst & (0b011111 << 15)) =3D=3D 0) { + op =3D rv_op_ssrdp; + } + /* rd=3D0 means sspopchk */ + reg_num =3D (inst >> 15) & 0b011111; + if (((inst & (0b011111 << 7)) =3D=3D 0) && + ((reg_num =3D=3D 1) || (reg_num =3D=3D= 5))) { + op =3D rv_op_sspopchk; + } + } } else if ((extract32(inst, 25, 7) & 0b1011001) =3D=3D 0b1000001) { imm_mop3 =3D deposit32(extract32(inst, 26, 2), 2, 1, extract32(inst, 30, 1)); op =3D rv_mop_rr_0 + imm_mop3; + /* if zicfiss enabled and mop3 is shadow stack */ + if (dec->cfg->ext_zicfiss && + ((imm_mop3 & 0b111) =3D=3D 0b111)) { + /* rs1=3D0 and rd=3D0 means sspush */ + reg_num =3D (inst >> 20) & 0b011111; + if (((inst & (0b011111 << 15)) =3D=3D 0) && + ((inst & (0b011111 << 7)) =3D=3D 0) && + ((reg_num =3D=3D 1) || (reg_num =3D=3D= 5))) { + op =3D rv_op_sspush; + } + } } } break; diff --git a/disas/riscv.h b/disas/riscv.h index 1182457aff..4895c5a301 100644 --- a/disas/riscv.h +++ b/disas/riscv.h @@ -224,6 +224,7 @@ enum { =20 #define rv_fmt_none "O\t" #define rv_fmt_rs1 "O\t1" +#define rv_fmt_rs2 "O\t2" #define rv_fmt_offset "O\to" #define rv_fmt_pred_succ "O\tp,s" #define rv_fmt_rs1_rs2 "O\t1,2" --=20 2.44.0 From nobody Sun Nov 24 07:56:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1724686334; cv=none; d=zohomail.com; s=zohoarc; b=BoExJZQ8GeMPK2Fpg/bmOU0p4I9G4g62KCFiW/zE/a6oBbZwKzw+9aIkqzMIdTaOn/416cAxuo2Z+FP0x6Li2UEV9r40OhkRdMUcqZ73MxM+nEjDixiD9HN85gRGDEA5n+ja/XH5ldpiu3NwhXXzkr1PBRywIXx635oS+OLkTmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724686334; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SjZWcB+IcGQyCSoIg5tycoGHZJtgwFG54PQXYRnVDCY=; b=Ofrnt5cYGU+M8oP5WNT8MX9ZyP8n6ABmLrALzaO+1tO1YIU88TN1WbtYr/Nq6ErleJTLB+nIWEcfC4V5C84YUEmktrGNgyrWGfmJMaHYrYOfoCl0S6k5nKP3bfbWsYOpjNZe75h6ZNhSFeoxHr4Yier/f1tfrMY/JAB9IPpBLFY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1724686334723125.24825863622743; Mon, 26 Aug 2024 08:32:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sibgN-0002Xx-Hy; Mon, 26 Aug 2024 11:31:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sibg0-0000uG-SA for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:42 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sibft-0003go-0p for qemu-devel@nongnu.org; Mon, 26 Aug 2024 11:30:40 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-71431524f3aso3540173b3a.0 for ; Mon, 26 Aug 2024 08:30:32 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7143422eaabsm7396525b3a.12.2024.08.26.08.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 08:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724686232; x=1725291032; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SjZWcB+IcGQyCSoIg5tycoGHZJtgwFG54PQXYRnVDCY=; b=iaBot+4rInrNl+2sKxCKrSzLdPFG5sWCrI6PYLyhiIXnwX0nTlNgUabX8nk+8JDAEa QNdxzNA4MMkmUQm5hEjLTwISL1ztiCd+irjcQbSsF/B5hbqB0QnvWqKwWLN0EvtV5kYy OnyAplc4zWqz9402MVXYJ0VgubsVq2jktN2eR80ikXVIgR3V3/WfwSSY5acb0zTETim4 fgu8ek89irQMqKXdlbd5eYgYFE2AzuA6UMdJBpg8HcC5ZoPBntgmM04yH/o2NA8X0eF9 3I7ba4HQrDswnfsoVtmMEnoLL0/YLmjCRW693Fas2bktgfesfWyiZSWbMyUIOBKjiOA0 /tsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724686232; x=1725291032; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SjZWcB+IcGQyCSoIg5tycoGHZJtgwFG54PQXYRnVDCY=; b=iWd6SlzytlqJi107Xhi6btJmYg+gA6oRAoymDF/hxw05GixXZBWLyqI4Wkcf2MjsFR JZh8Sk6FkyW/biP5iuASsQbOIImFrJvCwj8sp+X7fK+zq788Yzh2K39dVAjjTQzT/9cx 5yMoLdkbexELhbDJ+8epa3RoHT/CESKacf1AUs2uVonmJhDxGe5urLtU3jSUmiHOT+J/ gCABZl4NaH/QHNdhMTHOuxUNqVQAFJxF7W2dlzF+4Uz4gNwRsF4g1nB4VGiQKoZ2UCXP Qr9tp+Mp6oRtAhWE4pL7GrKUCtIDnhaOzekBaTFY5v0CfggcevNGFuQr5TTb+ZMEVlbb Y8WA== X-Forwarded-Encrypted: i=1; AJvYcCXZvzdMlHK/XijBawE/OQp5Xe9pwvWNea5iI2rytSm80CrdB5MXm8XKM9TcwGyM+XNVMEQn1D0P4Yls@nongnu.org X-Gm-Message-State: AOJu0YyXiNn5u5YPYHAWaxzPPB+3RSGWTXlueR3yMZvrOIJ0g/7Gfvuk XlCZpEf2m/Qf7RXoAUYSMPqRRBAGjWSKUFmfVWJHvGTav1AVbfD23406cnY1ZQM= X-Google-Smtp-Source: AGHT+IGnExbwGp8sDMFL9jO1C8jeoxGNOm6sbUQeq5mTwBeMglnMQQCEnZVUS3wlSuOen1Nb2o3ODg== X-Received: by 2002:a05:6a20:e608:b0:1c2:a0b2:e69 with SMTP id adf61e73a8af0-1cc89ee5ebfmr11053654637.33.1724686231500; Mon, 26 Aug 2024 08:30:31 -0700 (PDT) From: Deepak Gupta To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jim.shu@sifive.com, andy.chiu@sifive.com, richard.henderson@linaro.org, kito.cheng@sifive.com, Deepak Gupta Subject: [PATCH v9 17/17] disas/riscv: enable disassembly for compressed sspush/sspopchk Date: Mon, 26 Aug 2024 08:29:49 -0700 Message-ID: <20240826152949.294506-18-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826152949.294506-1-debug@rivosinc.com> References: <20240826152949.294506-1-debug@rivosinc.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=2607:f8b0:4864:20::434; envelope-from=debug@rivosinc.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1724686335564116600 Content-Type: text/plain; charset="utf-8" sspush and sspopchk have equivalent compressed encoding taken from zcmop. cmop.1 is sspush x1 while cmop.5 is sspopchk x5. Due to unusual encoding for both rs1 and rs2 from space bitfield, this required a new codec. Signed-off-by: Deepak Gupta --- disas/riscv.c | 19 ++++++++++++++++++- disas/riscv.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/disas/riscv.c b/disas/riscv.c index 5eafb7f7f3..6e9ba42edd 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -980,6 +980,8 @@ typedef enum { rv_op_ssrdp =3D 949, rv_op_ssamoswap_w =3D 950, rv_op_ssamoswap_d =3D 951, + rv_op_c_sspush =3D 952, + rv_op_c_sspopchk =3D 953, } rv_op; =20 /* register names */ @@ -2244,6 +2246,10 @@ const rv_opcode_data rvi_opcode_data[] =3D { { "ssrdp", rv_codec_r, rv_fmt_rd, NULL, 0, 0, 0 }, { "ssamoswap.w", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, { "ssamoswap.d", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1, NULL, 0, 0, 0 }, + { "c.sspush", rv_codec_cmop_ss, rv_fmt_rs2, NULL, rv_op_sspush, + rv_op_sspush, 0 }, + { "c.sspopchk", rv_codec_cmop_ss, rv_fmt_rs1, NULL, rv_op_sspopchk, + rv_op_sspopchk, 0 }, }; =20 /* CSR names */ @@ -2604,7 +2610,13 @@ static void decode_inst_opcode(rv_decode *dec, rv_is= a isa) if (dec->cfg->ext_zcmop) { if ((((inst >> 2) & 0b111111) =3D=3D 0b100000) && (((inst >> 11) & 0b11) =3D=3D 0b0)) { - op =3D rv_c_mop_1 + ((inst >> 8) & 0b111); + unsigned int cmop_code =3D 0; + cmop_code =3D ((inst >> 8) & 0b111); + op =3D rv_c_mop_1 + cmop_code; + if (dec->cfg->ext_zicfiss) { + op =3D (cmop_code =3D=3D 0) ? rv_op_c_sspush : op; + op =3D (cmop_code =3D=3D 2) ? rv_op_c_sspopchk : o= p; + } break; } } @@ -4923,6 +4935,11 @@ static void decode_inst_operands(rv_decode *dec, rv_= isa isa) case rv_codec_lp: dec->imm =3D operand_lpl(inst); break; + case rv_codec_cmop_ss: + dec->rd =3D rv_ireg_zero; + dec->rs1 =3D dec->rs2 =3D operand_crs1(inst); + dec->imm =3D 0; + break; }; } =20 diff --git a/disas/riscv.h b/disas/riscv.h index 4895c5a301..6a3b371cd3 100644 --- a/disas/riscv.h +++ b/disas/riscv.h @@ -167,6 +167,7 @@ typedef enum { rv_codec_r2_imm2_imm5, rv_codec_fli, rv_codec_lp, + rv_codec_cmop_ss, } rv_codec; =20 /* structures */ --=20 2.44.0