From patchwork Thu Feb 16 21:55:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144064 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE4C1C61DA4 for ; Thu, 16 Feb 2023 21:56:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEc-0002vI-J5; Thu, 16 Feb 2023 16:56:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEW-0002rp-E6 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:04 -0500 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEU-0001t8-Ir for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:04 -0500 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-16df32f2ffdso4311406fac.1 for ; Thu, 16 Feb 2023 13:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=E0YbACxmbDVY2djSGNnFWhmaGCk8HOixmpp41hp0ofs=; b=Z72FiW7rcUTLAy4SaVG0IF7x2L57s+ZD+ndQADm6DW+Wn+MffQtSX4C/LTh25gzgb8 37bVIe+27wPz50eCKxSwpK09C7+h+572woKF6uLdKWgzEd3D1nbZ5XqKWTOw6jEcImt8 Db7+1gk0oJ7Nn7+HlzY/ZHHVnzrT4UaY6eKNqOSZqTaV6GaurWHXnITOnBp2Rlej1YnN QkvstyYL4z5lFIy4v3Q4IoowLxWC9iC4u6liPkurEihQaw7CMXo8jGuRYHek9wzVpWCc yOTSKi2O8bp8XRsO0eCUoFPvJepwZTrVa665b26E3kiuje+FPqThCJkaIKUOF4SAMm37 ynGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=E0YbACxmbDVY2djSGNnFWhmaGCk8HOixmpp41hp0ofs=; b=AciVOBXPnqGq5Jqw+y1OjA6ekltfHXvvSuiohget/kTWkSCleaB+0quiuCXA7H+/vt A8dhlWoBKFRAuGj/ePp4q+JK9dWTCuHKIfXBt1lc7lyRK+gP+NMqNedQ7E8Z9uVkXjuZ kBhX3qj2VKOLGggoH85CPhHmILytdBQ9zFIujFORX7pakTMkC+RXYq+rVvIlGn50AeUA 36DMF5lmOUMkmkkfChfkeZogBr4YsC3R565RVruI47U9reBsT97DZ6xpw4tJY0BfUmIl 2BKiBEt951oOLe94noW9Tl/t9H2AqZyQS20tpHcnPtlVBmMxBGhxG++kwga6tMwTo340 85og== X-Gm-Message-State: AO0yUKUE6zSBcEqsYn1Ub+7EakRKabSdUIKLAK3dF7QnH41cbp4dEdxR 2820e8mZ4QHN2vGalXBglLotZ5EZfU1cct8l X-Google-Smtp-Source: AK7set+EQ4aV1H7HGHKkTNPo3PE7r/C1gLPvpEHNZowLC8w0G2+uLS40zQdDq+IlpvG6B8s/pRuvhQ== X-Received: by 2002:a05:6870:961b:b0:16e:94c5:589a with SMTP id d27-20020a056870961b00b0016e94c5589amr254906oaq.4.1676584560123; Thu, 16 Feb 2023 13:56:00 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:55:59 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH v6 1/9] target/riscv: turn write_misa() into an official no-op Date: Thu, 16 Feb 2023 18:55:42 -0300 Message-Id: <20230216215550.1011637-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::33; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x33.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org At this moment, and apparently since ever, we have no way of enabling RISCV_FEATURE_MISA. This means that all the code from write_misa(), all the nuts and bolts that handles how to write this CSR, has always been a no-op as well because write_misa() will always exit earlier. This seems to be benign in the majority of cases. Booting an Ubuntu 'virt' guest and logging all the calls to 'write_misa' shows that no writes to MISA CSR was attempted. Writing MISA, i.e. enabling/disabling RISC-V extensions after the machine is powered on, seems to be a niche use. Before proceeding, let's recap what the spec says about MISA. It is a CSR that is divided in 3 fields: - MXL, Machine XLEN, described as "may be writable"; - MXLEN, the XLEN in M-mode, which is given by the setting of MXL or a fixed value if MISA is zero; - Extensions is defined as "a WARL field that can contain writable bits where the implementation allows the supported ISA to be modified" Thus what we have today (write_misa() being a no-op) is already a valid spec implementation. We're not obliged to have a particular set of MISA writable bits, and at this moment we have none. Given that allowing the dormant code to write MISA can cause tricky bugs to solve later on, and we don't have a particularly interesting case of writing MISA to support today, and we're already not violating the specification, let's erase all the body of write_misa() and turn it into an official no-op instead of an accidental one. We'll keep consistent with what we provide users today but with 50+ less lines to maintain. RISCV_FEATURE_MISA enum is erased in the process since there's no one else using it. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Bin Meng Reviewed-by: Andrew Jones Reviewed-by: Weiwei Li --- target/riscv/cpu.h | 1 - target/riscv/csr.c | 55 ---------------------------------------------- 2 files changed, 56 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7128438d8e..01803a020d 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -89,7 +89,6 @@ enum { RISCV_FEATURE_MMU, RISCV_FEATURE_PMP, RISCV_FEATURE_EPMP, - RISCV_FEATURE_MISA, RISCV_FEATURE_DEBUG }; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 1b0a0c1693..f7862ff4a4 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1329,61 +1329,6 @@ static RISCVException read_misa(CPURISCVState *env, int csrno, static RISCVException write_misa(CPURISCVState *env, int csrno, target_ulong val) { - if (!riscv_feature(env, RISCV_FEATURE_MISA)) { - /* drop write to misa */ - return RISCV_EXCP_NONE; - } - - /* 'I' or 'E' must be present */ - if (!(val & (RVI | RVE))) { - /* It is not, drop write to misa */ - return RISCV_EXCP_NONE; - } - - /* 'E' excludes all other extensions */ - if (val & RVE) { - /* when we support 'E' we can do "val = RVE;" however - * for now we just drop writes if 'E' is present. - */ - return RISCV_EXCP_NONE; - } - - /* - * misa.MXL writes are not supported by QEMU. - * Drop writes to those bits. - */ - - /* Mask extensions that are not supported by this hart */ - val &= env->misa_ext_mask; - - /* Mask extensions that are not supported by QEMU */ - val &= (RVI | RVE | RVM | RVA | RVF | RVD | RVC | RVS | RVU | RVV); - - /* 'D' depends on 'F', so clear 'D' if 'F' is not present */ - if ((val & RVD) && !(val & RVF)) { - val &= ~RVD; - } - - /* Suppress 'C' if next instruction is not aligned - * TODO: this should check next_pc - */ - if ((val & RVC) && (GETPC() & ~3) != 0) { - val &= ~RVC; - } - - /* If nothing changed, do nothing. */ - if (val == env->misa_ext) { - return RISCV_EXCP_NONE; - } - - if (!(val & RVF)) { - env->mstatus &= ~MSTATUS_FS; - } - - /* flush translation cache */ - tb_flush(env_cpu(env)); - env->misa_ext = val; - env->xl = riscv_cpu_mxl(env); return RISCV_EXCP_NONE; } From patchwork Thu Feb 16 21:55:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61F8CC636CC for ; Thu, 16 Feb 2023 21:57:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEe-0002w1-5S; Thu, 16 Feb 2023 16:56:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEY-0002tN-Bm for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:06 -0500 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEW-0001tk-Jf for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:06 -0500 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-16debd2786aso4269266fac.7 for ; Thu, 16 Feb 2023 13:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=FpDj8k3lJo/XtW4BCH3Fxn4DtHHE56QhiG1q9jXxaq4=; b=gPI1AiytdMXSABrJXdbN9mx/efsPw1coxf9Tn7s7Dh45oX/agETYF0pegdKAseAI5m jma4oFGO15GCxehxGPic8mTgPMafv6ZR7lIpaPCniU8/4T5jnIQWbgKyIjltVvetcgRX uxpoOxYpkcxSPR8KVP/SL4k2KRyyKRltfMlRpF6+yKT+tE9twwgX/aYVbWiQFLFEPIeu nsutwTY0bjGu7/tMFQ7RYesGwNF5Qjgep9sYK5cR+N/5Fu+N7/htE0AiT3EuYBZn0VkW Jjw6CI4UWoLG26nrSSSCxYott1gsEhpH+6+P0T43Pv0d6FlmftqyExHNhwykSnbcDdLu WCBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=FpDj8k3lJo/XtW4BCH3Fxn4DtHHE56QhiG1q9jXxaq4=; b=W6LWetWFik8m3eL7j71wONHSPY1ODHPIcANMh6x1iblej+nzkO1FYvZRV9p7snbPKf 4VgP4YlmdjEm1DbuqZG5KtS88wP0r53FO3KmwDTw7G5r5VBeXC18LWxwWphG55M78ECa drm7ZC/UGuLSzOtgTFALLUwY83Dzf2rdIhQu7lpEW4jsgZdmUkVHOxg9yB5PzAsXQ6Lz htp9fR1YOtGmiwuZaxqVaICNYvjmlz4OAmkDcGwECSDcphGbPJrujZ+e/aHE7U+r1lQ3 SaL5L1cgMWp3BEGNlkDXZ9S5kHpQ074gxUQXSkmWmVLcCoFKFlbcebKJtKg+hb/oG3zH umDw== X-Gm-Message-State: AO0yUKXms2xIGTtcHnbgiB6kYY4ObLKt3BGO3ih1Fkl1Lzada6Krg+3F JO3ot7a61Tf1VgkN2pXxuL4WcHEXLhQkDmgg X-Google-Smtp-Source: AK7set9UNP4yCVZA/e5O+IQVD8Nk6jNiD9kL5TyhNQXNd/sxSaBoIb0iPNbHrx61wFiy+yt2W1SHiA== X-Received: by 2002:a05:6870:d0c4:b0:169:c244:8a07 with SMTP id k4-20020a056870d0c400b00169c2448a07mr4366594oaa.58.1676584563206; Thu, 16 Feb 2023 13:56:03 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:56:02 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza Subject: [PATCH v6 2/9] target/riscv: introduce riscv_cpu_cfg() Date: Thu, 16 Feb 2023 18:55:43 -0300 Message-Id: <20230216215550.1011637-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::33; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x33.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We're going to do changes that requires accessing the RISCVCPUConfig struct from the RISCVCPU, having access only to a CPURISCVState 'env' pointer. Add a helper to make the code easier to read. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Bin Meng Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Richard Henderson --- target/riscv/cpu.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 01803a020d..5e9626837b 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -653,6 +653,11 @@ static inline RISCVMXL riscv_cpu_mxl(CPURISCVState *env) #endif #define riscv_cpu_mxl_bits(env) (1UL << (4 + riscv_cpu_mxl(env))) +static inline const RISCVCPUConfig *riscv_cpu_cfg(CPURISCVState *env) +{ + return &env_archcpu(env)->cfg; +} + #if defined(TARGET_RISCV32) #define cpu_recompute_xl(env) ((void)(env), MXL_RV32) #else From patchwork Thu Feb 16 21:55:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC440C636D6 for ; Thu, 16 Feb 2023 21:56:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEm-0002yb-0Y; Thu, 16 Feb 2023 16:56:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEg-0002wd-FR for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:16 -0500 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEc-0001uP-JO for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:14 -0500 Received: by mail-oi1-x230.google.com with SMTP id r28so3113898oiw.3 for ; Thu, 16 Feb 2023 13:56:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=pUDEjXdVhFnDnYuU4NMU3pITYpi9B+DrDNG4MNkmQlM=; b=kOy2UN2+YJwnQsyinddnRVGs4iS+FMF/rgsnPyZDkmvaMcStKEyko8eIRyi7gX1pXf eFV1tj+gzNSEsyLzuhp+tI9nZjkQFMQ5WGYv7yqTEIPP62ebzZlvcxzrcPWWzCtgvBkW tjOkJjRtFgGo/G51jnxwLlhYrcphtGtBXCCjf9Ly9OK5jHC6o7RiXcyb8HgnxtN4jJjO q7QoDE3W34zeoFQgn2GGdS5s9xlZPMNmo6m6Ef815AaV2f9HpPAg9hO2mW7R2G4NHmfw kezvavJWx/yuc0WCupbHCPmgj5x0ihKijNIvMT8MRQZ3LwUrh4d5K7JSIu26Uf65GNZq 5eNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=pUDEjXdVhFnDnYuU4NMU3pITYpi9B+DrDNG4MNkmQlM=; b=p2nlmkP30jvDLDeNIl+9PjhVGUpjlRwr9DAkeZcLsk+5+GcIpIrussPoA80JBaEz26 R7AsqKSIk3QEkfFFA9Uyjka3+3o902twq6OH8rlxOqgbBFZZCB0K5SFPVMzKPMjG/uhF WN0y6GfNZLzOsAqCXb7KYbMDpSY+t+xAUnd6F5tE61Iyt0ep990xsNTYfvbxq0EipuLq fErGDRutvRwpuyf8zf6rXR/3L6wa1mULEFno3kzzs4I0yc+A6eJ9iK2znE4UDYbEOv8o hbnbwstk7PF4zS1+FUVngN0CK6aSs1t0WQIxdkb2UpU7HieFVHV91p0O5Y9fpVSIpAXL RiKw== X-Gm-Message-State: AO0yUKVjcb4iCVJNESlG+8UuBsnEWW9QUsohyIy5eYMc5pM4kbya5Ege S6aLoXzAfbWQGqVLhJxnzpINkA6PeZOv5IJK X-Google-Smtp-Source: AK7set8JhoWaQV69/C7QBvcvPVlhWSNthR8uGV1bgNcy3juEWRLkP5h4ZGbZXCvQyh1Yh76p6EWuhQ== X-Received: by 2002:a05:6808:7c3:b0:378:99e8:4ba8 with SMTP id f3-20020a05680807c300b0037899e84ba8mr3170978oij.39.1676584566268; Thu, 16 Feb 2023 13:56:06 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:56:05 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH v6 3/9] target/riscv: remove RISCV_FEATURE_DEBUG Date: Thu, 16 Feb 2023 18:55:44 -0300 Message-Id: <20230216215550.1011637-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x230.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org RISCV_FEATURE_DEBUG will always follow the value defined by cpu->cfg.debug flag. Read the flag instead. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li Reviewed-by: Bin Meng Reviewed-by: Andrew Jones Reviewed-by: LIU Zhiwei --- target/riscv/cpu.c | 6 +----- target/riscv/cpu.h | 1 - target/riscv/cpu_helper.c | 2 +- target/riscv/csr.c | 2 +- target/riscv/machine.c | 3 +-- 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 93b52b826c..e34a5e3f11 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -637,7 +637,7 @@ static void riscv_cpu_reset_hold(Object *obj) set_default_nan_mode(1, &env->fp_status); #ifndef CONFIG_USER_ONLY - if (riscv_feature(env, RISCV_FEATURE_DEBUG)) { + if (cpu->cfg.debug) { riscv_trigger_init(env); } @@ -935,10 +935,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } - if (cpu->cfg.debug) { - riscv_set_feature(env, RISCV_FEATURE_DEBUG); - } - #ifndef CONFIG_USER_ONLY if (cpu->cfg.ext_sstc) { diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 5e9626837b..2afb705930 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -89,7 +89,6 @@ enum { RISCV_FEATURE_MMU, RISCV_FEATURE_PMP, RISCV_FEATURE_EPMP, - RISCV_FEATURE_DEBUG }; /* Privileged specification version */ diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index ad8d82662c..4cdd247c6c 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -105,7 +105,7 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_VS, get_field(env->mstatus_hs, MSTATUS_VS)); } - if (riscv_feature(env, RISCV_FEATURE_DEBUG) && !icount_enabled()) { + if (cpu->cfg.debug && !icount_enabled()) { flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled); } #endif diff --git a/target/riscv/csr.c b/target/riscv/csr.c index f7862ff4a4..58af2c0e66 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -437,7 +437,7 @@ static RISCVException epmp(CPURISCVState *env, int csrno) static RISCVException debug(CPURISCVState *env, int csrno) { - if (riscv_feature(env, RISCV_FEATURE_DEBUG)) { + if (riscv_cpu_cfg(env)->debug) { return RISCV_EXCP_NONE; } diff --git a/target/riscv/machine.c b/target/riscv/machine.c index c6ce318cce..4634968898 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -226,9 +226,8 @@ static const VMStateDescription vmstate_kvmtimer = { static bool debug_needed(void *opaque) { RISCVCPU *cpu = opaque; - CPURISCVState *env = &cpu->env; - return riscv_feature(env, RISCV_FEATURE_DEBUG); + return cpu->cfg.debug; } static int debug_post_load(void *opaque, int version_id) From patchwork Thu Feb 16 21:55:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08C4AC636CC for ; Thu, 16 Feb 2023 21:57:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEm-0002yq-1A; Thu, 16 Feb 2023 16:56:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEg-0002we-GL for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:16 -0500 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEd-0001uk-Jh for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:14 -0500 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-16346330067so4294436fac.3 for ; Thu, 16 Feb 2023 13:56:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=bzgUQCLPgU6X7MZ2uleR0+KefuKd7NhosDsVObTIs/M=; b=imUYMFZDHZh32yw12+AHcbg267SgQ1y00YFEfNuOnI8KA4OXir12wdqUY6WcMM055m EaCWuDg2ZQ2Do8YD+4xZb9/3mYvSp/tSgJdgBqgYgODGL1feBIMSWwmQ5v9OZ3BT/H4Q QpfVxlUQhbGba9Xi1gpif7aNAxpgDDUWVYdAijjeC/DsgmkzFh+veB0k/sc+7xa/3REv BHx2OUtWk1DCbTWRgvneadz9DfyaRDIVR0i56B6xd97rkxIBJxjilWj2b7rypNQMuJSx azngnMLBkZcnj44o47UyqWEa/ofERI2D9rOgiDoMfZvU/+d7vB9+l4zMdND449/8LiuM XAXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=bzgUQCLPgU6X7MZ2uleR0+KefuKd7NhosDsVObTIs/M=; b=q/TMji5ddwpw7NSYmoOaUdmdlNFVoK7V8YJsfowqu07c5QEami71e2bScOTIwMp9tH sRbGu7V9VRGDF1GmuxDsJHrdmoFra5UxmamZN2/dCLH9pTwrUb3d/laIAfnsgG+U5EmX f8Ab2SWJYMcVa7RmQ2UPRDhMtEF2TDad0PZLkcD1ZaYbLBlDKwuPxBndK28irfcVUQ+9 tB2ToocHrzHqJl65FAnJMl4UybzQs3mV81nq6niWOY8/+r6ekDJxlpzbBN0zjt4Xznr3 qElshqNMIi5qoV3tDBrreTnSd7+qQorIdih7yr7n3esKdGM319E2hpHvBQ/Dwtu2Zsf5 2rUw== X-Gm-Message-State: AO0yUKWnv5ZfR0PEUuHPyKHpy6dK0tXDuMg/WvZbzHPKHyPaSLezUmtE VUuKHnhASNFUeGum2OyS6RWDcZHPFVNIDDrH X-Google-Smtp-Source: AK7set/djE5anyqH9zUeS3zG1f2HtaiE5/NXkrfsmX9aSglmJhrk87UmQvoueoZw2TKWg3P8d8zsVQ== X-Received: by 2002:a05:6871:5cd:b0:16b:398:7322 with SMTP id v13-20020a05687105cd00b0016b03987322mr4267212oan.25.1676584569195; Thu, 16 Feb 2023 13:56:09 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:56:08 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH v6 4/9] target/riscv/cpu.c: error out if EPMP is enabled without PMP Date: Thu, 16 Feb 2023 18:55:45 -0300 Message-Id: <20230216215550.1011637-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::33; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x33.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Instead of silently ignoring the EPMP setting if there is no PMP available, error out informing the user that EPMP depends on PMP support: $ ./qemu-system-riscv64 -cpu rv64,pmp=false,x-epmp=true qemu-system-riscv64: Invalid configuration: EPMP requires PMP support This will force users to pick saner options in the QEMU command line. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li Reviewed-by: Bin Meng Reviewed-by: Andrew Jones Reviewed-by: LIU Zhiwei --- target/riscv/cpu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index e34a5e3f11..4585ca74dc 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -925,13 +925,18 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) if (cpu->cfg.pmp) { riscv_set_feature(env, RISCV_FEATURE_PMP); + } + + if (cpu->cfg.epmp) { + riscv_set_feature(env, RISCV_FEATURE_EPMP); /* * Enhanced PMP should only be available * on harts with PMP support */ - if (cpu->cfg.epmp) { - riscv_set_feature(env, RISCV_FEATURE_EPMP); + if (!cpu->cfg.pmp) { + error_setg(errp, "Invalid configuration: EPMP requires PMP support"); + return; } } From patchwork Thu Feb 16 21:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8736C61DA4 for ; Thu, 16 Feb 2023 21:56:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEm-0002yp-0S; Thu, 16 Feb 2023 16:56:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEh-0002wp-UU for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:16 -0500 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEg-0001we-67 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:15 -0500 Received: by mail-oi1-x22f.google.com with SMTP id j3so1678025oig.10 for ; Thu, 16 Feb 2023 13:56:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=DqOEK63Mc9QLDqVHs79rHT9rPK8OGxBFD1pNt63dIkw=; b=k3wUIYrHuZVA0gNRK3rK0rO91vj1Ka6/1+UxGdZ9FHCpTpxFJvO82Xezh5rYHPUY+4 t1rtEwk9xF5xlNuexpmSV+Va49AZMpfaWG8eSAxEklhhWxV/SneSY3AYZePX2k8ytHyI fXVKs5OiPupLq+UmXDL+6tyvTyoL5YGKe6DdJGDzjSMTdXcEu9DohRtlYZyNX28hzudi 1emNvA9AJrNSabniZgynYro7TZLgA7eEUxhUdqVRFS0DToSfWdpIfvkJc193OZmUdzeY DvI1tAYeQKE5/U3FYHfJkdNr/WoEOlJ/jTQWzn5Q3PYTy3iH1sx1+/iBIaAQA152nyOx WOZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=DqOEK63Mc9QLDqVHs79rHT9rPK8OGxBFD1pNt63dIkw=; b=xLWyXzLTrLWl7X66t4AICkOXtdvlDE6nVIWGKcW31uyGf6762LmwfXtVcs13GD8VUu 3EA9F18ANjiiVA3AdbMtuSDzR/uinTpZcf0IpgOH43rqj3Hw7P/bYTyIf6M/EVUv+9L8 WieFPygbnXkgrB+VPqwBjCnkpY8TsMM1H7/aCO8JvI/VFidcje9SsZ2TRA3ftwU2GVjR 1namb7oyJSezxgPoi74vZQhcqQVARB0y4FvxIURFnNmPQVjOHiFbCqqvqX5QFwNQo8ek yUuqUTcTOz9N1Zo2s0CBkcF9vXtxYaxigbCDSXEuA903wPRZlRjsFdEgRL6SCZjlV5nt XhLQ== X-Gm-Message-State: AO0yUKUXjA66jifZndQHFmzZRRmtHrFkzoGS6xui9k+bhaVXamIwlJ/+ 7TWur/1Jmndcz8NTA7Yzx2ocijRx3UznMtH/ X-Google-Smtp-Source: AK7set8RpjlKAog2iItuKehqfNNJGesBp3TX8ASI5E03XW3TG4NMCIoiJM63e/hnW9p29JLlW4U77A== X-Received: by 2002:a05:6808:911:b0:37a:c2d2:675b with SMTP id w17-20020a056808091100b0037ac2d2675bmr2993409oih.53.1676584572303; Thu, 16 Feb 2023 13:56:12 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:56:11 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH v6 5/9] target/riscv: remove RISCV_FEATURE_EPMP Date: Thu, 16 Feb 2023 18:55:46 -0300 Message-Id: <20230216215550.1011637-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org RISCV_FEATURE_EPMP is always set to the same value as the cpu->cfg.epmp flag. Use the flag directly. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li Reviewed-by: Bin Meng Reviewed-by: Andrew Jones Reviewed-by: LIU Zhiwei --- target/riscv/cpu.c | 10 +++------- target/riscv/cpu.h | 1 - target/riscv/csr.c | 2 +- target/riscv/pmp.c | 4 ++-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4585ca74dc..71b2042d73 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -927,17 +927,13 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) riscv_set_feature(env, RISCV_FEATURE_PMP); } - if (cpu->cfg.epmp) { - riscv_set_feature(env, RISCV_FEATURE_EPMP); - + if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* * Enhanced PMP should only be available * on harts with PMP support */ - if (!cpu->cfg.pmp) { - error_setg(errp, "Invalid configuration: EPMP requires PMP support"); - return; - } + error_setg(errp, "Invalid configuration: EPMP requires PMP support"); + return; } diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 2afb705930..6d659d74fa 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -88,7 +88,6 @@ enum { RISCV_FEATURE_MMU, RISCV_FEATURE_PMP, - RISCV_FEATURE_EPMP, }; /* Privileged specification version */ diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 58af2c0e66..cdc68d3676 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -428,7 +428,7 @@ static RISCVException pmp(CPURISCVState *env, int csrno) static RISCVException epmp(CPURISCVState *env, int csrno) { - if (env->priv == PRV_M && riscv_feature(env, RISCV_FEATURE_EPMP)) { + if (env->priv == PRV_M && riscv_cpu_cfg(env)->epmp) { return RISCV_EXCP_NONE; } diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 4bc4113531..aa4d1996e9 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -88,7 +88,7 @@ static void pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) if (pmp_index < MAX_RISCV_PMPS) { bool locked = true; - if (riscv_feature(env, RISCV_FEATURE_EPMP)) { + if (riscv_cpu_cfg(env)->epmp) { /* mseccfg.RLB is set */ if (MSECCFG_RLB_ISSET(env)) { locked = false; @@ -239,7 +239,7 @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr, { bool ret; - if (riscv_feature(env, RISCV_FEATURE_EPMP)) { + if (riscv_cpu_cfg(env)->epmp) { if (MSECCFG_MMWP_ISSET(env)) { /* * The Machine Mode Whitelist Policy (mseccfg.MMWP) is set From patchwork Thu Feb 16 21:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F403C636CC for ; Thu, 16 Feb 2023 21:58:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEp-000330-Se; Thu, 16 Feb 2023 16:56:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEl-0002zD-G2 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:19 -0500 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEj-0001zd-7m for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:19 -0500 Received: by mail-oi1-x234.google.com with SMTP id 26so1949736oix.7 for ; Thu, 16 Feb 2023 13:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=iJTVGRg5y1OUwF0Xq7v/Y4t4UPRS0fpUHQSzmbdLKi0=; b=bCiEBnREjehUoAltxys8iq0KGELqdKMs6PNj9hGxmAtYvYihc5c6ysiCRMJ8QeABk+ oVJJo9YZaE4vmk/P9nWVIOW/PVdZB9njNNhgOnCHZJ1cQhIR2yjyNY0DaeGyPM2QA9fo nAfmSCTz6JjkUpF0lV0wxS8uWEAMInUN/u3VQQUrAHOrLUKRAYgOaXgbQeKLGCBDRepo 5f65NItr3wRGYTuCqltXNnrwRPVKaVNjNUeI6ZYKh0vTzIIN417rzzUr9T3oKBCVgSzS bB0Q6RvH5yS+Uz9xWeIfb/4GIEdcuWXMJzdZ5WN3c6IA75OW5U8KcaFV0Bn4smL34tPD bqtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iJTVGRg5y1OUwF0Xq7v/Y4t4UPRS0fpUHQSzmbdLKi0=; b=bU5ngLBrKMydDMkIQRqKoCUFAOsD6wKgVrvrScf5aZc1e62BzLBOJX4i2C2j6aUB+L 8CJGIzjT5tFk2Ol2IOwhRXEeV2OzYNHsEMLJE8qO/lRTah6XPZxZKpfO6dR1BDsR5/Cj yCxW8QlDDPR4WLlHxUYtcjcN9xUaQyxv2vSCwSVnlUnde6/FxHqv5pDROsyp2qAsR/96 pKsiMR6GJuQ0sGb+Fj0TATcJPt2OOVvx1zbJu5q7So5Hi/Js2NF+vJX/LNX77A/5wd7X NQ6pKoiPAYaCrVxSnRFLBO6YxZ+OeK6fdqVJFxrNM5/PAtrAx4ol9wedYceu5nqzkz/m yVHw== X-Gm-Message-State: AO0yUKXYmxHhC05sahuZ7ZfyHLCTG/IA5A0CEzHrKfpJLWPHqrhzAzAt iPKrzQrUFhWcFeVbG0PWpcLqJU/tHfBOavdt X-Google-Smtp-Source: AK7set9MaRdSvjIgMbVVSQaCHjs0N9mMXuB7k14VKavpyrpIcQs72nR5PsTAHgW1d2q3UnKL7La6iw== X-Received: by 2002:a05:6808:d8:b0:378:12b9:b31e with SMTP id t24-20020a05680800d800b0037812b9b31emr2833607oic.27.1676584575305; Thu, 16 Feb 2023 13:56:15 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:56:14 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH v6 6/9] target/riscv: remove RISCV_FEATURE_PMP Date: Thu, 16 Feb 2023 18:55:47 -0300 Message-Id: <20230216215550.1011637-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org RISCV_FEATURE_PMP is being set via riscv_set_feature() by mirroring the cpu->cfg.pmp flag. Use the flag instead. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li Reviewed-by: Bin Meng Reviewed-by: Andrew Jones Reviewed-by: LIU Zhiwei --- target/riscv/cpu.c | 4 ---- target/riscv/cpu.h | 1 - target/riscv/cpu_helper.c | 2 +- target/riscv/csr.c | 2 +- target/riscv/machine.c | 3 +-- target/riscv/op_helper.c | 2 +- target/riscv/pmp.c | 2 +- 7 files changed, 5 insertions(+), 11 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 71b2042d73..7b1360d6ba 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -923,10 +923,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) riscv_set_feature(env, RISCV_FEATURE_MMU); } - if (cpu->cfg.pmp) { - riscv_set_feature(env, RISCV_FEATURE_PMP); - } - if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* * Enhanced PMP should only be available diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6d659d74fa..119a022af9 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -87,7 +87,6 @@ so a cpu features bitfield is required, likewise for optional PMP support */ enum { RISCV_FEATURE_MMU, - RISCV_FEATURE_PMP, }; /* Privileged specification version */ diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 4cdd247c6c..292b6b3168 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -706,7 +706,7 @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot, pmp_priv_t pmp_priv; int pmp_index = -1; - if (!riscv_feature(env, RISCV_FEATURE_PMP)) { + if (!riscv_cpu_cfg(env)->pmp) { *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TRANSLATE_SUCCESS; } diff --git a/target/riscv/csr.c b/target/riscv/csr.c index cdc68d3676..d0ab00d870 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -419,7 +419,7 @@ static int aia_hmode32(CPURISCVState *env, int csrno) static RISCVException pmp(CPURISCVState *env, int csrno) { - if (riscv_feature(env, RISCV_FEATURE_PMP)) { + if (riscv_cpu_cfg(env)->pmp) { return RISCV_EXCP_NONE; } diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 4634968898..67e9e56853 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -27,9 +27,8 @@ static bool pmp_needed(void *opaque) { RISCVCPU *cpu = opaque; - CPURISCVState *env = &cpu->env; - return riscv_feature(env, RISCV_FEATURE_PMP); + return cpu->cfg.pmp; } static int pmp_post_load(void *opaque, int version_id) diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 48f918b71b..9c0b91c88f 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -195,7 +195,7 @@ target_ulong helper_mret(CPURISCVState *env) uint64_t mstatus = env->mstatus; target_ulong prev_priv = get_field(mstatus, MSTATUS_MPP); - if (riscv_feature(env, RISCV_FEATURE_PMP) && + if (riscv_cpu_cfg(env)->pmp && !pmp_get_num_rules(env) && (prev_priv != PRV_M)) { riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC()); } diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index aa4d1996e9..205bfbe090 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -265,7 +265,7 @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr, } } - if ((!riscv_feature(env, RISCV_FEATURE_PMP)) || (mode == PRV_M)) { + if (!riscv_cpu_cfg(env)->pmp || (mode == PRV_M)) { /* * Privileged spec v1.10 states if HW doesn't implement any PMP entry * or no PMP entry matches an M-Mode access, the access succeeds. From patchwork Thu Feb 16 21:55:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A253C61DA4 for ; Thu, 16 Feb 2023 21:58:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEq-00033b-FJ; Thu, 16 Feb 2023 16:56:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEo-00032F-TQ for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:22 -0500 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEm-00024D-Ta for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:22 -0500 Received: by mail-oi1-x22c.google.com with SMTP id 26so1949872oix.7 for ; Thu, 16 Feb 2023 13:56:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=Rhjy4ZuFr2J/YQsYfjypiNp1FTwn/nVolIeKKoKX5g0=; b=LugphfGor1gmprUSAby7mJAPaibOuGqZG6te5q8kb9VUbENNZ7y/mZzIlgErXKYVB3 rXI0maowpzY38vuwMLSYcfRMrgGnJ7algLFXIVjYsnt6kxM+GnBX3LFt1NVyuleIYcDt tucThstlg1UiYhMtOJgtRYp8tE1VIUT3B3JJYdf7K3CQZPRrFltPFHJmhuetTZ91S5RL f8mAxtjDsSTfxorD8LjRzToEf5gd1m8gpg87dV39xVLOj6s8W6SSd91YUfsr73joPVG3 4YauKpS5LNdvc9/xr1oLiHe/cXPEwzF7GHNWjT0oERrJO+SiR9inBk+PDwi8kN1fsBBL eHhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Rhjy4ZuFr2J/YQsYfjypiNp1FTwn/nVolIeKKoKX5g0=; b=Vts0mEdxjgMCb0iujNrCIDCt84CtV5FV4pnLHgpm6kuLk3A15oJSSWoN1bEu4FiUK7 HSBASIJ0s2oxEe1md/ySMx5MWpdAq/6TDMlRYeoHMXwvrbbT8sK/Y0e2pshmV6ljFK1S am2+bUBVI2lkEfDCNm5EyUzIju3gGXaUHcOnksVnwmfFAWhKrFfa74ocZXG+tcHnZzER NMjXfdmTReyTi7m1iOVBuHsg2OtaxpiT9GsJl2DUCXvDEvo1gbiA6bxl1bx0ibleEWD/ GYFohv93H85eyOxSRoYNjWcppyK4BnJSXie4WvVqYB44WGsRtMcsFwrCGbEYVM5DlHoY wNJg== X-Gm-Message-State: AO0yUKVoKyv05nFGeLyc/OmgZWzEdJyMDQ/4vmoSmiuEPJ+dn8R5Nslm +26hFtm2No5KREj81Iz8jHfO6XDfv9G2bMan X-Google-Smtp-Source: AK7set+0Hnum3qfi+p5MUU+xhgmardYCuI6QJD5j1j1IUf2xEor0XxwF4CfdT3mJMZczDKfETZGlbw== X-Received: by 2002:a54:4784:0:b0:378:3340:d31c with SMTP id o4-20020a544784000000b003783340d31cmr2802931oic.33.1676584578566; Thu, 16 Feb 2023 13:56:18 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:56:18 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH v6 7/9] hw/riscv/virt.c: do not use RISCV_FEATURE_MMU in create_fdt_socket_cpus() Date: Thu, 16 Feb 2023 18:55:48 -0300 Message-Id: <20230216215550.1011637-8-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22c; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Read cpu_ptr->cfg.mmu directly. As a bonus, use cpu_ptr in riscv_isa_string(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li Reviewed-by: Bin Meng Reviewed-by: Andrew Jones Reviewed-by: LIU Zhiwei --- hw/riscv/virt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 86c4adc0c9..49f2c157f7 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -232,20 +232,21 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, bool is_32_bit = riscv_is_32bit(&s->soc[0]); for (cpu = s->soc[socket].num_harts - 1; cpu >= 0; cpu--) { + RISCVCPU *cpu_ptr = &s->soc[socket].harts[cpu]; + cpu_phandle = (*phandle)++; cpu_name = g_strdup_printf("/cpus/cpu@%d", s->soc[socket].hartid_base + cpu); qemu_fdt_add_subnode(ms->fdt, cpu_name); - if (riscv_feature(&s->soc[socket].harts[cpu].env, - RISCV_FEATURE_MMU)) { + if (cpu_ptr->cfg.mmu) { qemu_fdt_setprop_string(ms->fdt, cpu_name, "mmu-type", (is_32_bit) ? "riscv,sv32" : "riscv,sv48"); } else { qemu_fdt_setprop_string(ms->fdt, cpu_name, "mmu-type", "riscv,none"); } - name = riscv_isa_string(&s->soc[socket].harts[cpu]); + name = riscv_isa_string(cpu_ptr); qemu_fdt_setprop_string(ms->fdt, cpu_name, "riscv,isa", name); g_free(name); qemu_fdt_setprop_string(ms->fdt, cpu_name, "compatible", "riscv"); From patchwork Thu Feb 16 21:55:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF6B0C636CC for ; Thu, 16 Feb 2023 21:56:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEs-000352-Lk; Thu, 16 Feb 2023 16:56:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEq-000341-PN for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:25 -0500 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEp-00025c-5y for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:24 -0500 Received: by mail-oi1-x235.google.com with SMTP id dt8so3150296oib.0 for ; Thu, 16 Feb 2023 13:56:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=NzcPsSFpo8cDJ6sfm1puhtjJzRJAUmlGMIXLVjavbks=; b=YUcGXjs6KNcbJsZvEhjWxAYbfWucm3p3xX/XK7SVo6oAdheKhjKQbyRrqlFlv+Cdli MxBCEeFFL5JRrltVnXrPO0DkKFUxTH+Djy4OdNJiOhq6Mg1/37PQbDY5NrRZPv2Gd+dd SYsNZcWxDq3J218RuGhiZ/lN4gMca0vZWAVuQXC/A9zNbmRbSUt6OeYNZEB4SGTPb9Sn DNHrlQ8JJ14te61xRxxFv2ZMDfPoQRwPgJ4RTyO8l3Ke0YB/Nu470hsx87sNjOOecoIj mpqr4UkpxwaAA0QIVHg27N7hFYS4JfWWkR543i/8lWuB7YXFhbIEuLmSStIAkLqZp7Ec TdQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=NzcPsSFpo8cDJ6sfm1puhtjJzRJAUmlGMIXLVjavbks=; b=ARiWghn5AGz8rZzohWU3rIkVrCF0fYdBVH4uyr42wo+NEhBmK3TqkkZKx7LsowzJ2Q vMtYYhkn/2ZNrUw8Js7QyqoJxUIrl/gXYoF+YdtUv5e7YrCV9gpUMUewS653L1vSaafv l7ig7MEiuCmEjENEMsq7iiPPuFAlUE5OHOlIrV8ZH0me4HQjHQn9ImeDmDIHWsEwyAn3 z4TkSdXypDdWTnwE0Qo3DVRUEdv0UJr1OGQnpDSEQoRwPqRQaotw2bRgnt2u707sTv9v WAYMNsEd1hLSwKDdyk9tyWIk5ppipR5ypmizs4LXm95E1O1CTj4XdD8NymTmvb9PvK3Z +gvQ== X-Gm-Message-State: AO0yUKXGOdU121dWfknzsPw1UO/4Cn6RQkIwlGC+7iQXRvl50KqN2Py7 HwJxr1UmWKaRLXN0DKRhbLFiyKkFkld9mxze X-Google-Smtp-Source: AK7set+vqY4PqchtF7yaTjEOrdKd6wob+HvTprPpyZ5Vg5chjkOPl0HQW/NOSLRtL2UDeYXHPzvp5w== X-Received: by 2002:a54:409a:0:b0:37e:aa97:4660 with SMTP id i26-20020a54409a000000b0037eaa974660mr2834805oii.16.1676584581671; Thu, 16 Feb 2023 13:56:21 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.56.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:56:21 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH v6 8/9] target/riscv: remove RISCV_FEATURE_MMU Date: Thu, 16 Feb 2023 18:55:49 -0300 Message-Id: <20230216215550.1011637-9-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::235; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x235.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org RISCV_FEATURE_MMU is set whether cpu->cfg.mmu is set, so let's just use the flag directly instead. With this change the enum is also removed. It is worth noticing that this enum, and all the RISCV_FEATURES_* that were contained in it, predates the existence of the cpu->cfg object. Today, using cpu->cfg is an easier way to retrieve all the features and extensions enabled in the hart. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li Reviewed-by: Bin Meng Reviewed-by: Andrew Jones Reviewed-by: LIU Zhiwei --- target/riscv/cpu.c | 4 ---- target/riscv/cpu.h | 7 ------- target/riscv/cpu_helper.c | 2 +- target/riscv/csr.c | 4 ++-- target/riscv/monitor.c | 2 +- target/riscv/pmp.c | 2 +- 6 files changed, 5 insertions(+), 16 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7b1360d6ba..075033006c 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -919,10 +919,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } - if (cpu->cfg.mmu) { - riscv_set_feature(env, RISCV_FEATURE_MMU); - } - if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* * Enhanced PMP should only be available diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 119a022af9..0519d2ab0c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -81,13 +81,6 @@ #define RVH RV('H') #define RVJ RV('J') -/* S extension denotes that Supervisor mode exists, however it is possible - to have a core that support S mode but does not have an MMU and there - is currently no bit in misa to indicate whether an MMU exists or not - so a cpu features bitfield is required, likewise for optional PMP support */ -enum { - RISCV_FEATURE_MMU, -}; /* Privileged specification version */ enum { diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 292b6b3168..eda2293470 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -796,7 +796,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, mode = PRV_U; } - if (mode == PRV_M || !riscv_feature(env, RISCV_FEATURE_MMU)) { + if (mode == PRV_M || !riscv_cpu_cfg(env)->mmu) { *physical = addr; *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TRANSLATE_SUCCESS; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d0ab00d870..fcc271c93c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2569,7 +2569,7 @@ static RISCVException rmw_siph(CPURISCVState *env, int csrno, static RISCVException read_satp(CPURISCVState *env, int csrno, target_ulong *val) { - if (!riscv_feature(env, RISCV_FEATURE_MMU)) { + if (!riscv_cpu_cfg(env)->mmu) { *val = 0; return RISCV_EXCP_NONE; } @@ -2588,7 +2588,7 @@ static RISCVException write_satp(CPURISCVState *env, int csrno, { target_ulong vm, mask; - if (!riscv_feature(env, RISCV_FEATURE_MMU)) { + if (!riscv_cpu_cfg(env)->mmu) { return RISCV_EXCP_NONE; } diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c index 236f93b9f5..f36ddfa967 100644 --- a/target/riscv/monitor.c +++ b/target/riscv/monitor.c @@ -218,7 +218,7 @@ void hmp_info_mem(Monitor *mon, const QDict *qdict) return; } - if (!riscv_feature(env, RISCV_FEATURE_MMU)) { + if (!riscv_cpu_cfg(env)->mmu) { monitor_printf(mon, "S-mode MMU unavailable\n"); return; } diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 205bfbe090..a08cd95658 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -315,7 +315,7 @@ int pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, } if (size == 0) { - if (riscv_feature(env, RISCV_FEATURE_MMU)) { + if (riscv_cpu_cfg(env)->mmu) { /* * If size is unknown (0), assume that all bytes * from addr to the end of the page will be accessed. From patchwork Thu Feb 16 21:55:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13144069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63B01C61DA4 for ; Thu, 16 Feb 2023 21:58:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSmEv-00037H-Jo; Thu, 16 Feb 2023 16:56:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSmEu-00036a-4I for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:28 -0500 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pSmEr-0001we-HV for qemu-devel@nongnu.org; Thu, 16 Feb 2023 16:56:27 -0500 Received: by mail-oi1-x22f.google.com with SMTP id j3so1678447oig.10 for ; Thu, 16 Feb 2023 13:56:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=SRUSnKQk8SFmtXGFiuLmHMMhVwT2fGCY0f0QzILH7/c=; b=VCy2t9M0qP5TJEVywngP53PsAfs4+UFWUonwYPvPdruay5lhLn/nID0on7FvQhFziT p7Sn9zt806QRWv/IBXRmoVj4viLt5CVi96eHkQbF1zS0rq74oHIKGBFHCVAYHv0nSTIZ KW9Qfcr5QKeMFN3KDpXWRieqGnAxqdK1vjnIu5SuBFX4jMnnURq1ZHj1trfFqjB0dtMC YD2uTJMUhAV9en5cJzUibdY4ywXAnEw0+UaTG5XTlYOE6sOax5hZgXw2jcJcdwkVzuAF YJYoWev7O7NkvwES/LWaRalhpSI0IoZbOY+jfNnjCiY7yD58j9Hc7cUILgqMPBTzxDvo /J9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=SRUSnKQk8SFmtXGFiuLmHMMhVwT2fGCY0f0QzILH7/c=; b=kH7hEW+4NeuvZkN/dS3PeXo5qpJlAaBztMOp7nf9nTBiGs8CmAkiOy5eqBXuNmONvp M9rHTLiaY/EfCjI21LAVA87MQb0CvFoSHgEI7qjNZt+XmXk732TXclKvTOO/+4HC/K2Z RxFqHCKZzAksmr0AVozYA6dAMkh3EhxjpmQ8rPWJ56+p7pcwXnIgZ82Xs2sb+YCsMceH +NO9WhVMnIxuXB+aLPYmMnZQ46jC5A7ga33i8Qx6np0PVfx+k9mFDp/IVQ82Wae7ty1w zvdtrV+e71LEM/Bh/eYtB4e9HwC/7klWrCReunNblXUb7UYkWKFLjjXvjwSCt5ZZJ9C5 JS/Q== X-Gm-Message-State: AO0yUKXJTItubM2/hJrN2KujdpWV6FTTLQCXvbFB4gDx7/m5xYs4TrxL zaP65X3e0ze078zDBtTh2VtHPW64SNBbfaDD X-Google-Smtp-Source: AK7set/N9C5dCSDO7esr1zlgTH9dFnjMXxGHYMNCO44N1QEX/XI9eqIynfgYbFxyuigpVxGr0bswyA== X-Received: by 2002:a05:6808:6da:b0:378:5987:6df8 with SMTP id m26-20020a05680806da00b0037859876df8mr3144588oih.52.1676584584545; Thu, 16 Feb 2023 13:56:24 -0800 (PST) Received: from grind.dc1.ventanamicro.com ([191.19.40.109]) by smtp.gmail.com with ESMTPSA id i132-20020acaea8a000000b0037d7f4d0890sm1047570oih.26.2023.02.16.13.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 13:56:24 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, Daniel Henrique Barboza , Andrew Jones Subject: [PATCH v6 9/9] target/riscv/cpu: remove CPUArchState::features and friends Date: Thu, 16 Feb 2023 18:55:50 -0300 Message-Id: <20230216215550.1011637-10-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216215550.1011637-1-dbarboza@ventanamicro.com> References: <20230216215550.1011637-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The attribute is no longer used since we can retrieve all the enabled features in the hart by using cpu->cfg instead. Remove env->feature, riscv_feature() and riscv_set_feature(). We also need to bump vmstate_riscv_cpu version_id and minimal_version_id since 'features' is no longer being migrated. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li Reviewed-by: Bin Meng Reviewed-by: Andrew Jones Reviewed-by: LIU Zhiwei --- target/riscv/cpu.h | 12 ------------ target/riscv/machine.c | 5 ++--- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0519d2ab0c..9897305184 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -173,8 +173,6 @@ struct CPUArchState { /* 128-bit helpers upper part return value */ target_ulong retxh; - uint32_t features; - #ifdef CONFIG_USER_ONLY uint32_t elf_flags; #endif @@ -524,16 +522,6 @@ static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext) return (env->misa_ext & ext) != 0; } -static inline bool riscv_feature(CPURISCVState *env, int feature) -{ - return env->features & (1ULL << feature); -} - -static inline void riscv_set_feature(CPURISCVState *env, int feature) -{ - env->features |= (1ULL << feature); -} - #include "cpu_user.h" extern const char * const riscv_int_regnames[]; diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 67e9e56853..9c455931d8 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -331,8 +331,8 @@ static const VMStateDescription vmstate_pmu_ctr_state = { const VMStateDescription vmstate_riscv_cpu = { .name = "cpu", - .version_id = 6, - .minimum_version_id = 6, + .version_id = 7, + .minimum_version_id = 7, .post_load = riscv_cpu_post_load, .fields = (VMStateField[]) { VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), @@ -351,7 +351,6 @@ const VMStateDescription vmstate_riscv_cpu = { VMSTATE_UINT32(env.misa_ext, RISCVCPU), VMSTATE_UINT32(env.misa_mxl_max, RISCVCPU), VMSTATE_UINT32(env.misa_ext_mask, RISCVCPU), - VMSTATE_UINT32(env.features, RISCVCPU), VMSTATE_UINTTL(env.priv, RISCVCPU), VMSTATE_UINTTL(env.virt, RISCVCPU), VMSTATE_UINT64(env.resetvec, RISCVCPU),