From nobody Fri May 17 06:07:50 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=1681740326; cv=none; d=zohomail.com; s=zohoarc; b=ZV6GnMvfzwaQP4w5vyKd0Da8kuuSPK4uM7g8E332IsJpt1SBepY4YI9gN/M7nFH/D5BSPw92P//Em16oqpJVWrZxNLjOjof1Gtw0FTmO92YoSX8wvWDYFAv6Zpct8RWf5xQ4XtFjvrJ11UtcoZiiX3pR0pMFm0cKl78yOqA0GB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740326; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QbQA+yMCDSd/Qe9eA62MqerfK4pNnD6ZE9CO35LbNlM=; b=mZ/+BVkuEunosYL2Eb8CBdUp2GBX7iCPF/1l0q7qg4ltmT87BRcahVMKKBVDTRF8lOyg/XJUGS/JdMjiaVfN7XZEUcnUzKOmF3ertZHgLWSBVMhcT6xb7LVmPfGj2jmY7rv18uhPdIQwquUWJha162xbSHqx9bWyq7UUpZE/c/I= 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 1681740326144256.2845099647509; Mon, 17 Apr 2023 07:05:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPPZ-0004Vk-Pw; Mon, 17 Apr 2023 10:00: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 1poPPI-0003zr-7W for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:37 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPA-00035z-4H for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:35 -0400 Received: by mail-oi1-x236.google.com with SMTP id ec6so9996977oib.8 for ; Mon, 17 Apr 2023 07:00:27 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740026; x=1684332026; 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=QbQA+yMCDSd/Qe9eA62MqerfK4pNnD6ZE9CO35LbNlM=; b=TN/BG7sLZFJjTcO3n4OnP6a81xoKtVI219arBAkWk8Xl3/Ech+1nKBTM3NOob3H5KD sjdFZZZAJ1h094YGTNjwLWjUXIaDNpNAFTrfk6y3tAuhfrRNs5Kw+4PmXHvRHB2RMd/i 1VmvzTASCxQ2UFxW/X6WtcnvyBWj7VemZyZ3LWTDJT+mnimvHvCJy0MoRZpwoPaPC1vf bHftTFt/Xoa9MxrQIyZvI4rCjEK2MGeUHSoqtknPH06ZqCUU2b4+/9WIZgYEzk0dMBC3 k7M64ATHdX1yXC83ZeN9jTDD6zqafRQ2HEua2RcHemHDH+LxGQS/IO07GGJVqbFnX4Mx b6eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740026; x=1684332026; 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=QbQA+yMCDSd/Qe9eA62MqerfK4pNnD6ZE9CO35LbNlM=; b=aoFRXYSpi0qo8AKP0KWMf7DiN9dgCJSQV4PVHF4iJC/Zh690bkyqiYy6wUcprbii2F FuKx816TQJd1WqWn8o54S0Yf+zB0PBJzB7M9hdwJLmEEk8+GWj8hDjqYiIWzUiDPoU66 j8falat97kAZW3g7MAX2IBTdIiWitP3lswzwkDiL1l0t9D5l9qmZ40x09l30p2osAADt 2PG/MK50S4Z34PJzJ5WN4DlSGxae/418vkOR9B1XQGd9BvabHX/XWEJWsoyzh9gYOsPi URHYGZ2N/Gjv03IsBtpxxu5n08DDfqupflYEEN+CEksOF/j8rWwFeQz17mCpTgd7rqkF R6dw== X-Gm-Message-State: AAQBX9fxbZ1ohRWbGA3VewaxAOMS1miQfS3B38X/24BogJCPLn2MfEyF 6AfIX1Rh+0qr4EaRbiTiiuxI71/TFOwSI8gkMQM= X-Google-Smtp-Source: AKy350aDFBNY7LPQ4x+4mhl+pKzIo5FBZVTS4MJXLXf9fBw21+d67QiJ6y9rnSgftNGodOdNwjW3fw== X-Received: by 2002:a05:6808:2086:b0:38d:61e9:12cd with SMTP id s6-20020a056808208600b0038d61e912cdmr4138388oiw.21.1681740026201; Mon, 17 Apr 2023 07:00:26 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 01/12] target/riscv/cpu.c: add riscv_cpu_validate_v() Date: Mon, 17 Apr 2023 11:00:02 -0300 Message-Id: <20230417140013.58893-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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::236; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x236.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=no 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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740345519100001 Content-Type: text/plain; charset="utf-8" The RVV verification will error out if fails and it's being done at the end of riscv_cpu_validate_set_extensions(), after we've already set some extensions that are dependent on RVV. Let's put it in its own function and do it earlier. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Acked-by: Alistair Francis --- target/riscv/cpu.c | 89 +++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index befa64528f..feca13aefb 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -797,6 +797,46 @@ static void riscv_cpu_disas_set_info(CPUState *s, disa= ssemble_info *info) } } =20 +static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, + Error **errp) +{ + int vext_version =3D VEXT_VERSION_1_00_0; + + if (!is_power_of_2(cfg->vlen)) { + error_setg(errp, "Vector extension VLEN must be power of 2"); + return; + } + if (cfg->vlen > RV_VLEN_MAX || cfg->vlen < 128) { + error_setg(errp, + "Vector extension implementation only supports VLEN " + "in the range [128, %d]", RV_VLEN_MAX); + return; + } + if (!is_power_of_2(cfg->elen)) { + error_setg(errp, "Vector extension ELEN must be power of 2"); + return; + } + if (cfg->elen > 64 || cfg->elen < 8) { + error_setg(errp, + "Vector extension implementation only supports ELEN " + "in the range [8, 64]"); + return; + } + if (cfg->vext_spec) { + if (!g_strcmp0(cfg->vext_spec, "v1.0")) { + vext_version =3D VEXT_VERSION_1_00_0; + } else { + error_setg(errp, "Unsupported vector spec version '%s'", + cfg->vext_spec); + return; + } + } else { + qemu_log("vector version is not specified, " + "use the default value v1.0\n"); + } + set_vext_version(env, vext_version); +} + /* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -804,6 +844,7 @@ static void riscv_cpu_disas_set_info(CPUState *s, disas= semble_info *info) static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) { CPURISCVState *env =3D &cpu->env; + Error *local_err =3D NULL; =20 /* Do some ISA extension error checking */ if (riscv_has_ext(env, RVG) && @@ -872,8 +913,14 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU= *cpu, Error **errp) return; } =20 - /* The V vector extension depends on the Zve64d extension */ if (riscv_has_ext(env, RVV)) { + riscv_cpu_validate_v(env, &cpu->cfg, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + + /* The V vector extension depends on the Zve64d extension */ cpu->cfg.ext_zve64d =3D true; } =20 @@ -1008,46 +1055,6 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) cpu->cfg.ext_zksed =3D true; cpu->cfg.ext_zksh =3D true; } - - if (riscv_has_ext(env, RVV)) { - int vext_version =3D VEXT_VERSION_1_00_0; - if (!is_power_of_2(cpu->cfg.vlen)) { - error_setg(errp, - "Vector extension VLEN must be power of 2"); - return; - } - if (cpu->cfg.vlen > RV_VLEN_MAX || cpu->cfg.vlen < 128) { - error_setg(errp, - "Vector extension implementation only supports VLEN= " - "in the range [128, %d]", RV_VLEN_MAX); - return; - } - if (!is_power_of_2(cpu->cfg.elen)) { - error_setg(errp, - "Vector extension ELEN must be power of 2"); - return; - } - if (cpu->cfg.elen > 64 || cpu->cfg.elen < 8) { - error_setg(errp, - "Vector extension implementation only supports ELEN= " - "in the range [8, 64]"); - return; - } - if (cpu->cfg.vext_spec) { - if (!g_strcmp0(cpu->cfg.vext_spec, "v1.0")) { - vext_version =3D VEXT_VERSION_1_00_0; - } else { - error_setg(errp, - "Unsupported vector spec version '%s'", - cpu->cfg.vext_spec); - return; - } - } else { - qemu_log("vector version is not specified, " - "use the default value v1.0\n"); - } - set_vext_version(env, vext_version); - } } =20 #ifndef CONFIG_USER_ONLY --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740142; cv=none; d=zohomail.com; s=zohoarc; b=k6zwhwjn0HP/EY1+lCVfuCWRwnUDTCY5iZ3Onv4DRFswAJmyx03iMWOM/m0f5W1LeDk5nqSOPLwmx9Ps1uk+RmG5/ruVvAIy1TR1Qa4J7EM+YpLRozhNVAwmcugHedBiNcuXVCk7V7Ju9Rjko7chMDDNb4dvGWf+AicmCPFqs60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740142; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/K+x0BBUJKKhnnJD7tcM3hOXjdXSPbLCX01Uxo6rI88=; b=TVUKGnkqAgi6EeqwLax4C5A5BERU1xYJHyQ8RSWd0X+P+dhcmK36dUvIhAxc6LkiNLioQwln1g7ryjkvQNChG0oLNn/TitcQhMYd4xgmITtwmUBBJV1tki9LHVP3GqS/5DLCaWf9nVgxOcKY5BLlnpZi10PbfdXNkyt40Dii4/4= 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 1681740142972219.57561211462928; Mon, 17 Apr 2023 07:02:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPPg-0004pA-Hn; Mon, 17 Apr 2023 10:01:00 -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 1poPPG-0003y6-UG for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:38 -0400 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPD-00036Q-0s for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:34 -0400 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-18779252f7fso18345508fac.12 for ; Mon, 17 Apr 2023 07:00:30 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740029; x=1684332029; 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=/K+x0BBUJKKhnnJD7tcM3hOXjdXSPbLCX01Uxo6rI88=; b=LPAfdBLW/a9ZYX+ZvxXgsDCRN31zDf6hxFY6PKVKtOvmS7zNZRR5JE8wXWltGNnw8t v8LXY25s8isFm6pgujYgh1J3YiNR8JMf8z3r8mYdN1rIMlwizodqqztLdsyuirAYZ7mO vWTH0L+wTS7qNjpV5T3S8bsTspyOIjMXXKpNMAlYljbRjJV6DmCQAqgvaZon9qyrTGuQ tYJzgtfj+5V4e3MTJC4TmiUD9mRarRpE0y/1G9C6s9CgLn6oxOpxcoZjEvxLKC19cmoX wvX0JcSoF59ejpHzEtxIixs3dnyy7vTrnzaoWyODO0SRL7XN6yo7ccJ3R/ijpNDceb3M JJHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740029; x=1684332029; 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=/K+x0BBUJKKhnnJD7tcM3hOXjdXSPbLCX01Uxo6rI88=; b=ZWHyi0a34oOU04fUP9yolhaGyJJlU/ot9NHIj+vhqaW/kqr5jHIa92t1TRFjopfL2l iLxkS8qW/ODklD4518d47WCH6wsEga7ZFNsLUpAu0QRK/tUPUnzjHJDwFz4HMk31DHNd 72/SaetIVlwEBXZHxMawZsO+U2ptUka7iM0BictW/s9H1zDoKcf8dhr0HtKRrNClSqRT 9rticSLaMIPLHFRio2jawrM1q/1pYN3uMuc7oDlmQ8aLtRBoXkIasLeMnwqQ+izePk/z knqxmW+ssqhqhb74NNW8WfggswBVwDO8uKwCFbptFcLZI3/oTDymomlF8tRwFW1njon5 a+/g== X-Gm-Message-State: AAQBX9flZahjvxmo26AAHpoaDMucdqR5kox8Ap56Xchnfe3NK1fejrfq xxsEQoE/dLgpc71/L1A4CzXXyofBygcm526c10g= X-Google-Smtp-Source: AKy350YYyijy87m2GwSRnRs7sgPGDitw9u9ZimFSanH5lPp3slrErFqwxpEr48WYd7uFP9iQ4MnFmg== X-Received: by 2002:a05:6870:c22a:b0:187:9b52:f58a with SMTP id z42-20020a056870c22a00b001879b52f58amr7723925oae.53.1681740029566; Mon, 17 Apr 2023 07:00:29 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 02/12] target/riscv/cpu.c: remove set_vext_version() Date: Mon, 17 Apr 2023 11:00:03 -0300 Message-Id: <20230417140013.58893-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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=2001:4860:4864:20::36; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x36.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740168173100001 Content-Type: text/plain; charset="utf-8" This setter is doing nothing else but setting env->vext_ver. Assign the value directly. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index feca13aefb..fed7b467e4 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -252,11 +252,6 @@ static void set_priv_version(CPURISCVState *env, int p= riv_ver) env->priv_ver =3D priv_ver; } =20 -static void set_vext_version(CPURISCVState *env, int vext_ver) -{ - env->vext_ver =3D vext_ver; -} - #ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str(const char *satp_mode_str) { @@ -834,7 +829,7 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RI= SCVCPUConfig *cfg, qemu_log("vector version is not specified, " "use the default value v1.0\n"); } - set_vext_version(env, vext_version); + env->vext_ver =3D vext_version; } =20 /* --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740071; cv=none; d=zohomail.com; s=zohoarc; b=MJw553o9v0NODEch/annETOmLV/jm91uK/JJr+j/xpLruC0ZK9NqiKngTP0h0ITSzoNMhr4+0bpWHqMEskQgkrUDgBeYdH7jZ75h03ZNYHrEHVVUz07mdeSodMzDtDUswbICi+pq1x8gldTWXzZv32yuC4jr8r7ZhZElyYjIew4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740071; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1Eg4OjIu9XJVebHhIGr1W8Ypo/xVtjz2S0WyrM7TGQ8=; b=bJ6WHH6gwLVfzuNfbrYgkmZ+8Cd9vlMuto/0VWc8Ftta3RVZELBqS1OCpFE4kgzTL0UJv/XFbwLrqy/OcG+5evDzOQtmB0Zyh63fpxXDY/wSx8Ne1S1aUUGiDm2ue8hXVNLHW/2BzEiZKSZ97Gxu32G9R9Qs4CpyY/FyvigMTHM= 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 1681740071472764.0902069486118; Mon, 17 Apr 2023 07:01:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPPM-0004LJ-MQ; Mon, 17 Apr 2023 10:00:42 -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 1poPPJ-0003zw-DV for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:37 -0400 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPG-00038P-KR for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:36 -0400 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-187878a90e6so16625257fac.0 for ; Mon, 17 Apr 2023 07:00:33 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740032; x=1684332032; 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=1Eg4OjIu9XJVebHhIGr1W8Ypo/xVtjz2S0WyrM7TGQ8=; b=nI058Lwwby98hKDu+G6pu6wF2PDO40zcDPuYUG1ErYVggczuwYyy1UCw07fEiihO6q FpYwNrcJKisfFS/R6UEGV/jOUf0GQATMTTySPmDTiEs1h+ExPZU5Bg6Qo0Bv5KijtR/a VI9lLS6VLKU1WlqUu+nhBMQ7Ip+nt47U0pFh1I1PaOFivb59yC2fvdLdyEHyXAaUKOOJ +cAcPbqvR3QqN+39o/7xSjyYckvz0Grc966lrSHHCKShgawy7Os6wFEFmmOEYLoeaDAf mRiIDn2bHcFUati4wtA+oJRncADg9zbkGYUrAEBEVSx3IaRGro1vQRcQDKklqLvYxyAf q22w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740032; x=1684332032; 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=1Eg4OjIu9XJVebHhIGr1W8Ypo/xVtjz2S0WyrM7TGQ8=; b=NQcX5BaBzKLjQU6zw+s4qQOhLrzM1hAzS9xClJSk4btGNNTxeswGJK3Fv/7z+sgopr bUSKTfF6bCOMUa7ZToXBuLSqWzinHf25dSH1dA69NvPHuSkKdJbLkNtDFiy74DiLpkFs w5zLd/02/N+ENaMtGh2DkWohxfQTy+qQWOoal+0veRuPfnwbsefjsLAXHEspxtkuUUFg kn4zyUBLdro+xv3+Zsam5BQXwNyJw6Of1h6wPYUj3wC1WDM3fRedBhWzfpnXDlW/yP1T MTMR16oRJzMM+FnIM9za9e6Bx5ad5KuAFVxa8Lmi9DFb4qVw8yArq2oraiTBhBBeLpQu N+Lw== X-Gm-Message-State: AAQBX9eUehdY1nbDE+ydYk4ro0Iqa+2rocEbPYlOk/IAr1xJukcoNYza otlvubtL1QwHioB3XCGbsr98PNF1Ty+ZnjYxcWI= X-Google-Smtp-Source: AKy350Y4CV8KdrZwC1UtEb0DcCpxDCdM0WhIJw+2x49XOH0Ddlwt3ETlw3UQRFawlHv7yz2Z+T/Y+Q== X-Received: by 2002:a05:6870:d1c7:b0:187:9c57:90c5 with SMTP id b7-20020a056870d1c700b001879c5790c5mr8821910oac.1.1681740032640; Mon, 17 Apr 2023 07:00:32 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 03/12] target/riscv/cpu.c: remove set_priv_version() Date: Mon, 17 Apr 2023 11:00:04 -0300 Message-Id: <20230417140013.58893-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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=2001:4860:4864:20::35; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x35.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740084574100001 Content-Type: text/plain; charset="utf-8" The setter is doing nothing special. Just set env->priv_ver directly. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index fed7b467e4..bec60fe585 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -247,11 +247,6 @@ static void set_misa(CPURISCVState *env, RISCVMXL mxl,= uint32_t ext) env->misa_ext_mask =3D env->misa_ext =3D ext; } =20 -static void set_priv_version(CPURISCVState *env, int priv_ver) -{ - env->priv_ver =3D priv_ver; -} - #ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str(const char *satp_mode_str) { @@ -350,7 +345,7 @@ static void riscv_any_cpu_init(Object *obj) VM_1_10_SV32 : VM_1_10_SV57); #endif =20 - set_priv_version(env, PRIV_VERSION_1_12_0); + env->priv_ver =3D PRIV_VERSION_1_12_0; } =20 #if defined(TARGET_RISCV64) @@ -361,7 +356,7 @@ static void rv64_base_cpu_init(Object *obj) set_misa(env, MXL_RV64, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - set_priv_version(env, PRIV_VERSION_1_12_0); + env->priv_ver =3D PRIV_VERSION_1_12_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57); #endif @@ -371,7 +366,7 @@ static void rv64_sifive_u_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV39); #endif @@ -383,7 +378,7 @@ static void rv64_sifive_e_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -396,7 +391,7 @@ static void rv64_thead_c906_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU); - set_priv_version(env, PRIV_VERSION_1_11_0); + env->priv_ver =3D PRIV_VERSION_1_11_0; =20 cpu->cfg.ext_zfh =3D true; cpu->cfg.mmu =3D true; @@ -430,7 +425,7 @@ static void rv128_base_cpu_init(Object *obj) set_misa(env, MXL_RV128, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - set_priv_version(env, PRIV_VERSION_1_12_0); + env->priv_ver =3D PRIV_VERSION_1_12_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57); #endif @@ -443,7 +438,7 @@ static void rv32_base_cpu_init(Object *obj) set_misa(env, MXL_RV32, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - set_priv_version(env, PRIV_VERSION_1_12_0); + env->priv_ver =3D PRIV_VERSION_1_12_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); #endif @@ -453,7 +448,7 @@ static void rv32_sifive_u_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); #endif @@ -465,7 +460,7 @@ static void rv32_sifive_e_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -478,7 +473,7 @@ static void rv32_ibex_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_11_0); + env->priv_ver =3D PRIV_VERSION_1_11_0; cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -492,7 +487,7 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -1174,7 +1169,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) } =20 if (priv_version >=3D PRIV_VERSION_1_10_0) { - set_priv_version(env, priv_version); + env->priv_ver =3D priv_version; } =20 riscv_cpu_validate_misa_priv(env, &local_err); --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740114; cv=none; d=zohomail.com; s=zohoarc; b=OxSWkMTzQVOllX7Gg3LjHR6C8CoT0ASemdm+lK5BO1koqV19dD0Kfj3lYygC+bYkXl7TIpNSKEuZmx241Dx3YKnz4ipvhjkvnISapuBUtS49NllPe7MmmFJGbSKxEm8bO/oF4lUeonrxP3PbU2WuWrkmhSm6a+LLpNGD6uVnsFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740114; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2uGLi6+ovBWUdoc3kQpi9p838CiXRKVkHH6lHuOuZ54=; b=c40Qjh4b2Rd7m5fgf9gnJ01830ohdfbEWI+mmhrktqxsua5F6QdtZFLoW8CdgSlwcy+1qQxj23ub5SFFgnZWjsoKIYqlVGayJR4G8/OlFoqjRZSxOBnOfS1OikhMj/Skx/KbGdQX0SQV8bX96SRkP4MLbj20+Ftz2kb/rfttO0E= 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 1681740114528971.5187212448134; Mon, 17 Apr 2023 07:01:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPPg-0004p3-Gb; Mon, 17 Apr 2023 10:01:00 -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 1poPPM-0004HG-1t for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:40 -0400 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPK-00039p-4I for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:39 -0400 Received: by mail-oo1-xc35.google.com with SMTP id bb7-20020a056820160700b00546d9935668so383965oob.8 for ; Mon, 17 Apr 2023 07:00:37 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740036; x=1684332036; 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=2uGLi6+ovBWUdoc3kQpi9p838CiXRKVkHH6lHuOuZ54=; b=GQCTuXhVQ7pxZEOBV6eBUwhfBrOX50FYJmrpANLR1aAAsVvbMwSFxW2H6VfRIbptMg Zqfhk62BggHr3Dou/ctv+4IrzV1JkkFmwGbalZEFU+OrqEXJzFoeIsiRjXHbbWqwIeoQ pUZasavthx0ieGFjqiyGTsBhao9iNNsTp38K9ISEiSj+uTcBrBtFdcD8aRuxu/sHR6QG KFLhr9FtMtzF25j9FKxQcQfXhfkpv6Dyb60CqKDZCatCBxU7533Pz0OhpcVvVAV2bL0A Dfimy8FBtPxHWk5BSAgd6MVoJwrA0lTCYzMXI6lzTeA/Aocv+qegfEOj0iNmVmVBX8r5 rGzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740036; x=1684332036; 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=2uGLi6+ovBWUdoc3kQpi9p838CiXRKVkHH6lHuOuZ54=; b=jNmYYSqQpmmJigqK37yFPQGgmttOsdWXExi6eSvhdWVdMB/7KPlAPpqmDuf0X+Z+sU 2IHWs24kOcGWAk03bo1zA7Q01gDlYzXKwRT9aixo23gZtc7gnriIezCkbjRm9a/579aa dl6NqLQIgwHjGGJPov7Tu0OKjzpnfcYBamrDlVWJIronF2joCIgzfL5mklERoRh31/dF D7JANwEVUa3BGnAVpMhmf0zwpkinMG8UTZCcoKqIElbofMWrJQUleFdbZcaM1ZrAfx3w pSXhcdr+x6RncePPZUmFChfP6D4dVgZo/uvkwi/MagxiK1YoknLzvFBmAuMr/q9vGiyY p9XQ== X-Gm-Message-State: AAQBX9eipvWMwQ8yv3TpwlGod4TbGOMyNWB7eNN2yPkQGLNDJO6QyVX7 oDX4YIFBts8mGAf33koUqJTbPWQNWVCUUnDxDRo= X-Google-Smtp-Source: AKy350b+O5+SEuT/yvD8/03rWz2muJ+xLxguYw5a6dt68gmvJOxSxwwAdObGKc4AAFGSyM6TqA9xwg== X-Received: by 2002:a4a:2c86:0:b0:546:3872:f394 with SMTP id o128-20020a4a2c86000000b005463872f394mr2307816ooo.3.1681740035939; Mon, 17 Apr 2023 07:00:35 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza , Richard Henderson Subject: [PATCH v7 04/12] target/riscv: add PRIV_VERSION_LATEST Date: Mon, 17 Apr 2023 11:00:05 -0300 Message-Id: <20230417140013.58893-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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::c35; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc35.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740126165100003 Content-Type: text/plain; charset="utf-8" All these generic CPUs are using the latest priv available, at this moment PRIV_VERSION_1_12_0: - riscv_any_cpu_init() - rv32_base_cpu_init() - rv64_base_cpu_init() - rv128_base_cpu_init() Create a new PRIV_VERSION_LATEST enum and use it in those cases. I'll make it easier to update everything at once when a new priv version is available. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Richard Henderson Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 8 ++++---- target/riscv/cpu.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index bec60fe585..dd35cf378f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -345,7 +345,7 @@ static void riscv_any_cpu_init(Object *obj) VM_1_10_SV32 : VM_1_10_SV57); #endif =20 - env->priv_ver =3D PRIV_VERSION_1_12_0; + env->priv_ver =3D PRIV_VERSION_LATEST; } =20 #if defined(TARGET_RISCV64) @@ -356,7 +356,7 @@ static void rv64_base_cpu_init(Object *obj) set_misa(env, MXL_RV64, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - env->priv_ver =3D PRIV_VERSION_1_12_0; + env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57); #endif @@ -425,7 +425,7 @@ static void rv128_base_cpu_init(Object *obj) set_misa(env, MXL_RV128, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - env->priv_ver =3D PRIV_VERSION_1_12_0; + env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57); #endif @@ -438,7 +438,7 @@ static void rv32_base_cpu_init(Object *obj) set_misa(env, MXL_RV32, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - env->priv_ver =3D PRIV_VERSION_1_12_0; + env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); #endif diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index de7e43126a..15423585d0 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -61,6 +61,8 @@ enum { PRIV_VERSION_1_10_0 =3D 0, PRIV_VERSION_1_11_0, PRIV_VERSION_1_12_0, + + PRIV_VERSION_LATEST =3D PRIV_VERSION_1_12_0, }; =20 #define VEXT_VERSION_1_00_0 0x00010000 --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740484; cv=none; d=zohomail.com; s=zohoarc; b=XNLq/wzvRU4GH6AA3BjOaOZl5qlh4b1md/iTKwOsqFneyGJFBu97gpu/avnptLeKGGhAAkPUJ+eTdACjwcsYHCzW7q6n2xgOQjWhnwImG/vU8HlDl6btXI9poQLBYjre2c2fLsBQqEL5Ns+xynUWh+epFPtar/kt3l6L1x6SbVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740484; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Sgaf/JnDDYPpAXnnL9XBJVICYBNvpJ0R6zun3ny+PWo=; b=OpT98MQ8qaFmwKWjhxzUaOMB+j6ETvqd/s0/i9GqC7+jwS4unP1YDFpQaBzrDx/w8Dtdm72vvMBR/2HBDwgn1bvA9xN5KpQkDyHrfwoGs9jz8D6VV5gzEvG+n6koo1lcXGa95z4buH14GmGfp5v7mGgOSMoJTgojSB5Uw6CHGX0= 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 1681740484912450.25556630579774; Mon, 17 Apr 2023 07:08:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPPh-0004y0-Pi; Mon, 17 Apr 2023 10:01: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 1poPPO-0004UJ-H6 for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:44 -0400 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPM-0003Cp-Mj for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:42 -0400 Received: by mail-oo1-xc35.google.com with SMTP id i10-20020a4ad68a000000b0053b8aa32089so3737425oot.5 for ; Mon, 17 Apr 2023 07:00:40 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740039; x=1684332039; 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=Sgaf/JnDDYPpAXnnL9XBJVICYBNvpJ0R6zun3ny+PWo=; b=fSAN5XjuaCbd3dP/QGvh+rDQNMK5KR/7jhRlaQvDBMEjnQ/XPYs/JXGJPe/PyBP+Ao 7A3oSdSPVbHD8witOkr15JFPvDKSpe59Ky3UNbZQgewXAVo2xp5HwvZkTf/mCulVbFCZ NugIlaAWuVx4V6qF+58N9b6Bsrz+chWv1/un65kzpuEz74hKg1T/6JAQa8m+imrErvBT xEUj55N48ovp6QnCELuiRwh8opEqP/Z90TEM7kZxRzkQYlblN+83Pm4fpyRwKThMEKkU pbO4z8cxalxWyOb/lUWnKQTDmpVfEFRnIBdw/cVho6Dvq+2xQJuFTyrLL4dludvzRLO9 1Kgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740039; x=1684332039; 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=Sgaf/JnDDYPpAXnnL9XBJVICYBNvpJ0R6zun3ny+PWo=; b=X7gQejsv7biDDBznPD9mSBZ8jbQxZYflRqJ2kN564CLpWcSYw+lU9s9JS8SJSK93gk XnVdSuxYqVYjB0aYA+ozi1JB7ayQnrPdBvCxf8blz8gnYq1DfN96TXE5+CYbHv9ImjNC NBsmEyeAsYOiIpWb39RhU9RAieRhmAgPy7y3ZXzKQKMfaso8TjkPLcJ9uBpYTpolpJAe BjwXKMXkGafEfXnS4UbkYwLn1bSk9SMZWtEbCAHrNbMBUmSn6HQ4TR71q+1lVf0xtvwF 4AhKSTt/o0wVnvG3ncd7Ld6KHXeCfR8d60WeJfTF6RbAGuh3xtsA9U/EIEpXOu1gKSBH +UWg== X-Gm-Message-State: AAQBX9drBvuAZv4NUpHSitTwxzP2PKxbhPHs/xrcpbmqknZqL/cP44UZ Z1ZHo7jwjUbs10q1sUPvM1KynP2f11lXiCeIe74= X-Google-Smtp-Source: AKy350Zn+pWXSx99j5wpZbW4W07nhwwzoNCdAY8tz3a3S+8iJYU/JzIvfsnTrkUpzlGQ47NQ3z84bw== X-Received: by 2002:a4a:41cd:0:b0:542:5d35:12a0 with SMTP id x196-20020a4a41cd000000b005425d3512a0mr4260497ooa.3.1681740039110; Mon, 17 Apr 2023 07:00:39 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 05/12] target/riscv: Mask the implicitly enabled extensions in isa_string based on priv version Date: Mon, 17 Apr 2023 11:00:06 -0300 Message-Id: <20230417140013.58893-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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::c35; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc35.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740485712100001 Content-Type: text/plain; charset="utf-8" From: Weiwei Li Using implicitly enabled extensions such as Zca/Zcf/Zcd instead of their super extensions can simplify the extension related check. However, they may have higher priv version than their super extensions. So we should mask them in the isa_string based on priv version to make them invisible to user if the specified priv version is lower than their minimal priv version. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang Reviewed-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index dd35cf378f..9bb0e6b180 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1721,7 +1721,8 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char = **isa_str, int i; =20 for (i =3D 0; i < ARRAY_SIZE(isa_edata_arr); i++) { - if (isa_ext_is_enabled(cpu, &isa_edata_arr[i])) { + if (cpu->env.priv_ver >=3D isa_edata_arr[i].min_version && + isa_ext_is_enabled(cpu, &isa_edata_arr[i])) { new =3D g_strconcat(old, "_", isa_edata_arr[i].name, NULL); g_free(old); old =3D new; --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740317; cv=none; d=zohomail.com; s=zohoarc; b=ZbOvLs1d1EfR3VCywYRVCYXXpNAN5yrI1XhoSwNsvKpWvGy5LOv5XO1aoRWGACSagmfWpSc4Y/sPkILisEj9AcoqnWMrpHnRqT/Mz4zhQ6tlzMHbfnAcxdS3f7UVtGB8Y3YUBElVDiXwF0AHOfRTThihdhlHMHJZ5Zvr/q3IZwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740317; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KqB2KfcNcoO6GPwPuOLp0OWX5+3wJOF/kjk81/S5U88=; b=QM4taJRyAd3mlhhxqvmHa3bIn/dtl64Zgbebg0hU4ZeZ6mfItW87bPnvvzuv1O7z4pXe7aXa9hwVECWNePmCtinHR6K7aWdaSL9DTZOFT+vCUA/vPGSrIPaxrPll3etm47hfABh5fF4mGKqcziCFEBr2412xGU0KH2pdpxEen5A= 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 1681740317038546.7886404651279; Mon, 17 Apr 2023 07:05:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPPq-0005Tm-3U; Mon, 17 Apr 2023 10:01:10 -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 1poPPS-0004Wn-J1 for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:49 -0400 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPP-00039W-5g for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:46 -0400 Received: by mail-oo1-xc32.google.com with SMTP id bg38-20020a056820082600b005421db6ed5bso1939370oob.12 for ; Mon, 17 Apr 2023 07:00:42 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740042; x=1684332042; 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=KqB2KfcNcoO6GPwPuOLp0OWX5+3wJOF/kjk81/S5U88=; b=ml0JhqnY+jC/v5Vt8d3FnCkT4922EsCTFF1bAjSt2LCerxI+b9bqNZ14KB4MiZ62/5 wu9iwOppIcYMtz5TjERfmTT94EJoJAJMDRG094jwWcI1oHdfsE8wEFSNWjJP62yXI0ql MUuxazDcv3ifjGqw8Y7fjj9SzACG5JHJKvNn4b0y+z0SMxBxO9N/9R8appZ98b2M68em /Vk94R8m6ql5ElPW5gSJ12zyrKHw/2bYp9S3E4FwfGV8ZrgXLKuW5+Jp4mAuRfPnADvf mzY9QFxm5TYA1a6klSI0Wby6Cagf3+BxY9YCHb9m+4JyEYaF2+YmKwr67uzPnqoPZgvp xtHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740042; x=1684332042; 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=KqB2KfcNcoO6GPwPuOLp0OWX5+3wJOF/kjk81/S5U88=; b=khvCIaYeDE9AkdDhyrOjf9xRarXdhyclEHLsBrYo1HyooC8TXIEtYa9Wez/0wnDq+k 8fNXDJugXuEhfwbDn9c/MfrDg6liyUw9mcBzuKo5Ax+YwpwkBd2rj5zf4k7N8tplt+EO eCNBp4Bjr4l1F/xXWsuzrHJ7U5QNub10PpJRJN7OgYVq6hUFXnYbKa8sbDO7LA1MQ0QM UoEG0/R6qE9hBsWK2GENe7GubjIWafqocaP9EZRYyzGDSZpEWld/EL+54+9fXvzqsNwL 6Ma/oxjwkBO6Fv8UqWqm8tZnaqRoLSOSCkqwCkrcn3V3R+aM935Y03P1ZEffHKlA6kvS eXQA== X-Gm-Message-State: AAQBX9fwRdpu3OGZX3gogdhwsidvdNNokEMi5gguB5egxvI6caq0wtYg slprhRDuTli2oEg3UDtvPOE4Zj3vEqJfoRgFDXA= X-Google-Smtp-Source: AKy350bNZxH7SYhUXdcb+UbJfNy0Al/FAjnfzGE9YxPbxojIp4ciA6Z5YcBtVq3rJamHzPA5b6peOw== X-Received: by 2002:a4a:4512:0:b0:544:dc2c:9f78 with SMTP id y18-20020a4a4512000000b00544dc2c9f78mr3764060ooa.6.1681740042112; Mon, 17 Apr 2023 07:00:42 -0700 (PDT) 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, palmer@rivosinc.com Subject: [PATCH v7 06/12] target/riscv: Update check for Zca/Zcf/Zcd Date: Mon, 17 Apr 2023 11:00:07 -0300 Message-Id: <20230417140013.58893-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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::c32; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740338015100001 Content-Type: text/plain; charset="utf-8" From: Weiwei Li Even though Zca/Zcf/Zcd can be included by C/F/D, however, their priv version is higher than the priv version of C/F/D. So if we use check for them instead of check for C/F/D totally, it will trigger new problem when we try to disable the extensions based on the configured priv version. Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang Reviewed-by: Alistair Francis --- target/riscv/insn_trans/trans_rvd.c.inc | 12 +++++++----- target/riscv/insn_trans/trans_rvf.c.inc | 14 ++++++++------ target/riscv/insn_trans/trans_rvi.c.inc | 5 +++-- target/riscv/translate.c | 5 +++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_tr= ans/trans_rvd.c.inc index 2c51e01c40..6bdb55ef43 100644 --- a/target/riscv/insn_trans/trans_rvd.c.inc +++ b/target/riscv/insn_trans/trans_rvd.c.inc @@ -31,9 +31,11 @@ } \ } while (0) =20 -#define REQUIRE_ZCD(ctx) do { \ - if (!ctx->cfg_ptr->ext_zcd) { \ - return false; \ +#define REQUIRE_ZCD_OR_DC(ctx) do { \ + if (!ctx->cfg_ptr->ext_zcd) { \ + if (!has_ext(ctx, RVD) || !has_ext(ctx, RVC)) { \ + return false; \ + } \ } \ } while (0) =20 @@ -67,13 +69,13 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a) =20 static bool trans_c_fld(DisasContext *ctx, arg_fld *a) { - REQUIRE_ZCD(ctx); + REQUIRE_ZCD_OR_DC(ctx); return trans_fld(ctx, a); } =20 static bool trans_c_fsd(DisasContext *ctx, arg_fsd *a) { - REQUIRE_ZCD(ctx); + REQUIRE_ZCD_OR_DC(ctx); return trans_fsd(ctx, a); } =20 diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_tr= ans/trans_rvf.c.inc index b2de4fcf3f..c47138575a 100644 --- a/target/riscv/insn_trans/trans_rvf.c.inc +++ b/target/riscv/insn_trans/trans_rvf.c.inc @@ -30,10 +30,12 @@ } \ } while (0) =20 -#define REQUIRE_ZCF(ctx) do { \ - if (!ctx->cfg_ptr->ext_zcf) { \ - return false; \ - } \ +#define REQUIRE_ZCF_OR_FC(ctx) do { \ + if (!ctx->cfg_ptr->ext_zcf) { \ + if (!has_ext(ctx, RVF) || !has_ext(ctx, RVC)) { \ + return false; \ + } \ + } \ } while (0) =20 static bool trans_flw(DisasContext *ctx, arg_flw *a) @@ -69,13 +71,13 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a) =20 static bool trans_c_flw(DisasContext *ctx, arg_flw *a) { - REQUIRE_ZCF(ctx); + REQUIRE_ZCF_OR_FC(ctx); return trans_flw(ctx, a); } =20 static bool trans_c_fsw(DisasContext *ctx, arg_fsw *a) { - REQUIRE_ZCF(ctx); + REQUIRE_ZCF_OR_FC(ctx); return trans_fsw(ctx, a); } =20 diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_tr= ans/trans_rvi.c.inc index c70c495fc5..e33f63bea1 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -56,7 +56,7 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) tcg_gen_andi_tl(cpu_pc, cpu_pc, (target_ulong)-2); =20 gen_set_pc(ctx, cpu_pc); - if (!ctx->cfg_ptr->ext_zca) { + if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca) { TCGv t0 =3D tcg_temp_new(); =20 misaligned =3D gen_new_label(); @@ -169,7 +169,8 @@ static bool gen_branch(DisasContext *ctx, arg_b *a, TCG= Cond cond) =20 gen_set_label(l); /* branch taken */ =20 - if (!ctx->cfg_ptr->ext_zca && ((ctx->base.pc_next + a->imm) & 0x3)) { + if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca && + ((ctx->base.pc_next + a->imm) & 0x3)) { /* misaligned */ gen_exception_inst_addr_mis(ctx); } else { diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 928da0d3f0..a889454137 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -549,7 +549,7 @@ static void gen_jal(DisasContext *ctx, int rd, target_u= long imm) =20 /* check misaligned: */ next_pc =3D ctx->base.pc_next + imm; - if (!ctx->cfg_ptr->ext_zca) { + if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca) { if ((next_pc & 0x3) !=3D 0) { gen_exception_inst_addr_mis(ctx); return; @@ -1123,7 +1123,8 @@ static void decode_opc(CPURISCVState *env, DisasConte= xt *ctx, uint16_t opcode) * The Zca extension is added as way to refer to instructions in t= he C * extension that do not include the floating-point loads and stor= es */ - if (ctx->cfg_ptr->ext_zca && decode_insn16(ctx, opcode)) { + if ((has_ext(ctx, RVC) || ctx->cfg_ptr->ext_zca) && + decode_insn16(ctx, opcode)) { return; } } else { --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740306; cv=none; d=zohomail.com; s=zohoarc; b=QW3nt6Q6mZLwPbrhUd8bs2EaIMt1+lBTH/C06JscQtLzBC1pNnrhtHq44gwH0+XNmsO5UlPGO90RvfXdg+feWF18OOYtpVQlTDBJkb8PHZM+CbJwcZK7ksEH/kU0FRHvilTP/keAZvG2fZrtBFbb+VaU5uII3n7z6qwW+go7Sd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740306; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B9RqWisOWEV3iFXKyP/p1DxzybhrkeUZ+i62ea1L+xs=; b=Odm4L8Kumgp+XZfHoU9bOxs5KNJsAJTJqb+5AalDDDnwJAJ8GsGSaU/KHMgNF4vl0fioJ2M1eIvJ7FXKZisWg9JEImyEIF1Mxcsp7FJ8u5ff4acNWQjDk0ZeKZdSAuaHA9Cff27JHnxjTReBAfHavNwIdYnunyLPOTkBsVGsWi0= 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 1681740305973351.3176888217764; Mon, 17 Apr 2023 07:05:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPQ3-000610-RR; Mon, 17 Apr 2023 10:01: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 1poPPV-0004Xp-1C for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:53 -0400 Received: from mail-oo1-xc2a.google.com ([2607:f8b0:4864:20::c2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPS-0003GI-Qi for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:00:48 -0400 Received: by mail-oo1-xc2a.google.com with SMTP id m20-20020a4ae3d4000000b00538c0ec9567so3758404oov.1 for ; Mon, 17 Apr 2023 07:00:46 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740045; x=1684332045; 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=B9RqWisOWEV3iFXKyP/p1DxzybhrkeUZ+i62ea1L+xs=; b=hBwc2LOHIakwCvs+SN6QPMuW632RyS3ZBOtk0x+Zq0MP1SHnjiQ6bCxdF586sFB+vi 5ifZsfDtrFyhT5wSat3MPw21i/xNs3Z+no0YXsvpBZawqBzBBu1wzK9lc0qVZD8rRM6j Yb1H98GFZFIBgspcVENWNKeDsbMAINOWQadYedwIe98LE6uyZEtn4VpQCEvpyNlKnkE/ 1i96YuKctA9v1y3lkVh32DRd1SSKAO7JrDoINyZs4LEF59FEUL+HKMcnMMN/Bfhs1lHY 4pcKJ6InHs1RFGQlFFTH9MjHw/0JPtvS7YWILlTznB5dAno3evfte845/F5BjpcYW8kM +lyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740045; x=1684332045; 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=B9RqWisOWEV3iFXKyP/p1DxzybhrkeUZ+i62ea1L+xs=; b=fd5RFJAwrwQX2nifdOJv0Q3EJqkPEpUS0gDnuK3SlUBUmL42eqZOPASRdwPToIGK+K wLCOuAi661vfY/AnVfV1ENYcOrz10g5NUECeSQn3T5D9XpLg3TWFef27zZ/nyvYiI0hc t7repPOqj0+joKb1RP9T9vq2gFirCdUlzKemS0qxZOQBL20UDXWVkYpBNiCu0GdFOcKj +O69nd5PoV5A9lzGlDPqpHrCPLFd1BIOv8ZCCib4guyLXtdBz1MlFrYvqC5hMYALg27E 6lPtjHolRt+Wuy5fpyWOcKO5IDmDh3Nuj0g9JBPQDAd6dF2IOp9wmvYD2/XqTnx/1E4a D85g== X-Gm-Message-State: AAQBX9fVTEfxmiq9rK+Lmmx3YVN7GQh+WMHm8mNmrBB6gnryxqa0d/oM 1+MzixvxEww03sT6gzXU1OOVsmxcEstrqDC4O8w= X-Google-Smtp-Source: AKy350bmNjo6elMSgdiOmerMQJMTZTLMUclH5o/gFe+d4VMhMgrwHJ3pz+9tMkMUita6jwJcqfW9oA== X-Received: by 2002:a4a:37c5:0:b0:546:46df:349c with SMTP id r188-20020a4a37c5000000b0054646df349cmr2086075oor.0.1681740045139; Mon, 17 Apr 2023 07:00:45 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 07/12] target/riscv/cpu.c: add priv_spec validate/disable_exts helpers Date: Mon, 17 Apr 2023 11:00:08 -0300 Message-Id: <20230417140013.58893-8-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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::c2a; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc2a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740320084100001 Content-Type: text/plain; charset="utf-8" We're doing env->priv_spec validation and assignment at the start of riscv_cpu_realize(), which is fine, but then we're doing a force disable on extensions that aren't compatible with the priv version. This second step is being done too early. The disabled extensions might be re-enabled again in riscv_cpu_validate_set_extensions() by accident. A better place to put this code is at the end of riscv_cpu_validate_set_extensions() after all the validations are completed. Add a new helper, riscv_cpu_disable_priv_spec_isa_exts(), to disable the extesions after the validation is done. While we're at it, create a riscv_cpu_validate_priv_spec() helper to host all env->priv_spec related validation to unclog riscv_cpu_realize a bit. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 91 ++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 9bb0e6b180..c928925544 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -827,6 +827,52 @@ static void riscv_cpu_validate_v(CPURISCVState *env, R= ISCVCPUConfig *cfg, env->vext_ver =3D vext_version; } =20 +static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) +{ + CPURISCVState *env =3D &cpu->env; + int priv_version =3D -1; + + if (cpu->cfg.priv_spec) { + if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) { + priv_version =3D PRIV_VERSION_1_12_0; + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { + priv_version =3D PRIV_VERSION_1_11_0; + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { + priv_version =3D PRIV_VERSION_1_10_0; + } else { + error_setg(errp, + "Unsupported privilege spec version '%s'", + cpu->cfg.priv_spec); + return; + } + + env->priv_ver =3D priv_version; + } +} + +static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) +{ + CPURISCVState *env =3D &cpu->env; + int i; + + /* Force disable extensions if priv spec version does not match */ + for (i =3D 0; i < ARRAY_SIZE(isa_edata_arr); i++) { + if (isa_ext_is_enabled(cpu, &isa_edata_arr[i]) && + (env->priv_ver < isa_edata_arr[i].min_version)) { + isa_ext_update_enabled(cpu, &isa_edata_arr[i], false); +#ifndef CONFIG_USER_ONLY + warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx + " because privilege spec version does not match", + isa_edata_arr[i].name, env->mhartid); +#else + warn_report("disabling %s extension because " + "privilege spec version does not match", + isa_edata_arr[i].name); +#endif + } + } +} + /* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -1045,6 +1091,12 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) cpu->cfg.ext_zksed =3D true; cpu->cfg.ext_zksh =3D true; } + + /* + * Disable isa extensions based on priv spec after we + * validated and set everything we need. + */ + riscv_cpu_disable_priv_spec_isa_exts(cpu); } =20 #ifndef CONFIG_USER_ONLY @@ -1144,7 +1196,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) CPURISCVState *env =3D &cpu->env; RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); CPUClass *cc =3D CPU_CLASS(mcc); - int i, priv_version =3D -1; Error *local_err =3D NULL; =20 cpu_exec_realizefn(cs, &local_err); @@ -1153,23 +1204,10 @@ static void riscv_cpu_realize(DeviceState *dev, Err= or **errp) return; } =20 - if (cpu->cfg.priv_spec) { - if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) { - priv_version =3D PRIV_VERSION_1_12_0; - } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { - priv_version =3D PRIV_VERSION_1_11_0; - } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { - priv_version =3D PRIV_VERSION_1_10_0; - } else { - error_setg(errp, - "Unsupported privilege spec version '%s'", - cpu->cfg.priv_spec); - return; - } - } - - if (priv_version >=3D PRIV_VERSION_1_10_0) { - env->priv_ver =3D priv_version; + riscv_cpu_validate_priv_spec(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; } =20 riscv_cpu_validate_misa_priv(env, &local_err); @@ -1178,23 +1216,6 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 - /* Force disable extensions if priv spec version does not match */ - for (i =3D 0; i < ARRAY_SIZE(isa_edata_arr); i++) { - if (isa_ext_is_enabled(cpu, &isa_edata_arr[i]) && - (env->priv_ver < isa_edata_arr[i].min_version)) { - isa_ext_update_enabled(cpu, &isa_edata_arr[i], false); -#ifndef CONFIG_USER_ONLY - warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx - " because privilege spec version does not match", - isa_edata_arr[i].name, env->mhartid); -#else - warn_report("disabling %s extension because " - "privilege spec version does not match", - isa_edata_arr[i].name); -#endif - } - } - if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* * Enhanced PMP should only be available --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740158; cv=none; d=zohomail.com; s=zohoarc; b=FCKBXa92afT1CoajbVQF2jweeqokZFmyNN3GJVltHP7huEpOG6ghGDsgWBbznPm/EQ2Ly3vpNpSzuBKJoSLA+lT42K3l+QFOAkMnRuOi2sxFAQ48Iv1ScKwiEkD8c15eWNNhw2No+cIjgXg0gsnUyimn6t4a5wpEXLcfGb37QFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740158; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2nanoWdEOCS8aleFtiQT4lFRR5GhUFB/wRnqpy8wWN8=; b=CU9jxK5xpLIVU+3fLPLfx2D1TWhrQIhlINsXl6XzQTak+UPRc4YUhOUZ9acRcjja2k3WjQTRXiAwso+nPiDCF+AewEiNe3RLG6wsbwrIM1No1+dhEjOe4ThyZC9vw927R5HaIej48PNBOajE3EmhvTgfWqaehFnFHNNz4EKMZOk= 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 1681740158912551.3271464356778; Mon, 17 Apr 2023 07:02:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPQ4-00065x-Dd; Mon, 17 Apr 2023 10:01:25 -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 1poPPn-0005Ns-AI for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:07 -0400 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPW-00036O-4x for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:06 -0400 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-18782426c4bso17429134fac.9 for ; Mon, 17 Apr 2023 07:00:49 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740048; x=1684332048; 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=2nanoWdEOCS8aleFtiQT4lFRR5GhUFB/wRnqpy8wWN8=; b=I9218DVOEm4QwDNFjfWAV7NdQW5WSf5lz3M961MP1usxc4YcE3myBEp+aYhULhFQNY WMHNklh0gjbmL9PNeNMhnd9rM2GSX/zq1Dpg4OzxpggE6Lf7xI4y9pbZz0OAOJJcHuCZ 6c2Wk5Glq0g4fI6Kclr3LSS2e47+PoWKWwbhyMRFhjnY9R771b6sDVKd6eTTUELbePhO T0+3YuWFhJZ1YovWPEIxqdZAoig5Heo3a2P36/aDEfdh3ddJh5Pkay1JykpNQ9uaM2Qw kYeYjnn1wqKk+1VJfk4LODkvHpNlEund2I0hYF0K0vju/4Nb77VbJ0fnMEJAIIvvb+X7 Dv1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740048; x=1684332048; 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=2nanoWdEOCS8aleFtiQT4lFRR5GhUFB/wRnqpy8wWN8=; b=I6GKXLjJqogRgxKavAwrgK1qg36MzsHnccvPzy4HkSYKx3Vs9mfJOyuQFbdrqRE9DL +aOGPZA5zfw+0SwXPzIUTjJ0t6IkWBD8ZyB5Y6Biw/hEdebmjuQvzY0C0S43lcd4nN0p Ti9i8KrpooHvA+X4UH0Sllb4PE7qUTmUO6BlW9NvyTb1ndr/cERxfDyrbewXMdr6wkoD tN4ed/+ZAFq0BRzFMy0nXT/2FdkVneYEAognS/jmayx8mA9HeFwHNC9mBovBtnXGYXjo 0wqqPXUMc9NapJYxAFbHxcXulrJC3Qnzs9DDpDGCRKX2jK8MIHw5I2CTzjsGALQR2lwS ZuwA== X-Gm-Message-State: AAQBX9ceACLPDYqn/b9d6qPKjCl8m7NU3bQWz4erlqMJhROhikK+kMhi vs+ekUBZ19omdBsAZoTlnrd0FW+grKAuuT9wfns= X-Google-Smtp-Source: AKy350Z/kC+05oTTcitYzikJPQFj3cBKfmbdTmvPXRSbszeChMR/BPGA3Y1glf/2ghYBp9mir0/48Q== X-Received: by 2002:a05:6870:d60b:b0:186:906d:5b0b with SMTP id a11-20020a056870d60b00b00186906d5b0bmr7957977oaq.40.1681740048336; Mon, 17 Apr 2023 07:00:48 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 08/12] target/riscv/cpu.c: add riscv_cpu_validate_misa_mxl() Date: Mon, 17 Apr 2023 11:00:09 -0300 Message-Id: <20230417140013.58893-9-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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=2001:4860:4864:20::2c; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1681740193395100003 Content-Type: text/plain; charset="utf-8" Let's remove more code that is open coded in riscv_cpu_realize() and put it into a helper. Let's also add an error message instead of just asserting out if env->misa_mxl_max !=3D env->misa_mlx. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 50 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index c928925544..43635144bd 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -873,6 +873,33 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCV= CPU *cpu) } } =20 +static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) +{ + RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(cpu); + CPUClass *cc =3D CPU_CLASS(mcc); + CPURISCVState *env =3D &cpu->env; + + /* Validate that MISA_MXL is set properly. */ + switch (env->misa_mxl_max) { +#ifdef TARGET_RISCV64 + case MXL_RV64: + case MXL_RV128: + cc->gdb_core_xml_file =3D "riscv-64bit-cpu.xml"; + break; +#endif + case MXL_RV32: + cc->gdb_core_xml_file =3D "riscv-32bit-cpu.xml"; + break; + default: + g_assert_not_reached(); + } + + if (env->misa_mxl_max !=3D env->misa_mxl) { + error_setg(errp, "misa_mxl_max must be equal to misa_mxl"); + return; + } +} + /* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -1195,7 +1222,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) RISCVCPU *cpu =3D RISCV_CPU(dev); CPURISCVState *env =3D &cpu->env; RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); - CPUClass *cc =3D CPU_CLASS(mcc); Error *local_err =3D NULL; =20 cpu_exec_realizefn(cs, &local_err); @@ -1204,6 +1230,12 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 + riscv_cpu_validate_misa_mxl(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + riscv_cpu_validate_priv_spec(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); @@ -1232,22 +1264,6 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) } #endif /* CONFIG_USER_ONLY */ =20 - /* Validate that MISA_MXL is set properly. */ - switch (env->misa_mxl_max) { -#ifdef TARGET_RISCV64 - case MXL_RV64: - case MXL_RV128: - cc->gdb_core_xml_file =3D "riscv-64bit-cpu.xml"; - break; -#endif - case MXL_RV32: - cc->gdb_core_xml_file =3D "riscv-32bit-cpu.xml"; - break; - default: - g_assert_not_reached(); - } - assert(env->misa_mxl_max =3D=3D env->misa_mxl); - riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740523; cv=none; d=zohomail.com; s=zohoarc; b=dyO+ilzVNFlS3uObz6EN5ljVau5gj/rY33aK1kmxiIMMMZYI6iQkhqDfKkGOMnaqtVSR/gJSQ4WuopzEr8zaplHHgtnbemFr4ALARCsuJXZxAWdXTQ4pfPimU/IIF9vyktM0OVGX06ZiK1LHvlfcM4UnviCAFDvYsPeokQl2DI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740523; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mA9TaJor3VOov64Jl6vxePW5HOjf4tVu/fsDcc2X43Y=; b=dH8/qK7IIZHBgeeZFGfQTikV52YO6yrC8DyMFlwvsVPS2fa739rVt/zaZLIWq7rKHol3zzWwPgHT6TM87OnNS6tZVfzHBaBLbSWzNtG+7EQwLeM2gyulHTX9giGUHk+Fcu8JpfFktLhsyfC7mfOkb0HiGXdNAuYGudb4ZTX/+4A= 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 1681740523216367.71881949171916; Mon, 17 Apr 2023 07:08:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPQ9-0006qv-B5; Mon, 17 Apr 2023 10:01: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 1poPPo-0005Ud-Rg for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:09 -0400 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPY-00038P-Gw for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:08 -0400 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-187878a90e6so16626524fac.0 for ; Mon, 17 Apr 2023 07:00:52 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740051; x=1684332051; 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=mA9TaJor3VOov64Jl6vxePW5HOjf4tVu/fsDcc2X43Y=; b=U40/VaMv/8KJ8YuCSZCiVMpgOk8/WnEGxPPnD5RAAVYCem2Yu76MG+1w1/HM3CPsu7 uBjxB+iabNRqbLNGzngmx9zi/XlJFU71eusdxIdlmDiYjTpqa97oCRQzr/4uCyYEaYS3 SwCxKV10Iqtfuz+ss7HL0igNdm21JGw3aLtJSkZZyHkcY2AmmuUJzc/dNRIpLQ0obdoE BO8T93nID+mSMc5A15g+dT5gDGGyB2M3+KfNPAmmkBdhD6IxA2niKePtuMZrqgjG+9dP UXLlFtIm2HImmc7H4jOzLyWE/lnjxsDrxrB8tpJMWJaQtxZ4OOBn7XqdTnXkFSqHKy0S s8BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740051; x=1684332051; 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=mA9TaJor3VOov64Jl6vxePW5HOjf4tVu/fsDcc2X43Y=; b=gHcU8nypz/qaZqFFijBRlU5UdRNtDk/ZL2FvI/rq6Unu+hJRxKp1Oc68gyNviAY5sV 7hyt/g/IaDhLu7QodwA9A8yKVvUY8qYP27NnbU9aLErH+kPv8rpoR/mc4+6C+vby3wlD Inuwj7XskQkiycRWmPv9/Gom12nb8qQogtimVwm/fzD3ikqazDNvkOGynbIsUjlDoYCx eo+hDROhTqgBpO4YBoZg/4NnssdO44r9LVgIDz7S03lVuNff5nUA2lQMb55BjjgXxeEB e0FDeYr16eI7z5lpeYXQlNFSd/Gx+eSguIHm/7ly9JiRDiMy4u4UFLwvLDm+7o7yCMAP TH2g== X-Gm-Message-State: AAQBX9fCCFHTOPAELE9SjNqm+xgk8La5ij7jWRXkRbJmWAJRaRN7qo+B Nogc/jUF+TWW3bCg+1Sl7nI4R3dvi/Qbs8i3vUI= X-Google-Smtp-Source: AKy350ZrLo/Zg/BsDLiVrpjG3+CJ+aLAMQvzYKS19lBRho+4Qn0/ttcGqFijH8ehZ9uNflL5PZswnQ== X-Received: by 2002:a05:6870:4694:b0:184:266a:1700 with SMTP id a20-20020a056870469400b00184266a1700mr9423605oap.47.1681740051469; Mon, 17 Apr 2023 07:00:51 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 09/12] target/riscv/cpu.c: validate extensions before riscv_timer_init() Date: Mon, 17 Apr 2023 11:00:10 -0300 Message-Id: <20230417140013.58893-10-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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=2001:4860:4864:20::35; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x35.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740523560100001 Content-Type: text/plain; charset="utf-8" There is no need to init timers if we're not even sure that our extensions are valid. Execute riscv_cpu_validate_set_extensions() before riscv_timer_init(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 43635144bd..2d7f0ac785 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1257,13 +1257,6 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 - -#ifndef CONFIG_USER_ONLY - if (cpu->cfg.ext_sstc) { - riscv_timer_init(cpu); - } -#endif /* CONFIG_USER_ONLY */ - riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); @@ -1271,6 +1264,10 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) } =20 #ifndef CONFIG_USER_ONLY + if (cpu->cfg.ext_sstc) { + riscv_timer_init(cpu); + } + if (cpu->cfg.pmu_num) { if (!riscv_pmu_init(cpu, cpu->cfg.pmu_num) && cpu->cfg.ext_sscofpm= f) { cpu->pmu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740143; cv=none; d=zohomail.com; s=zohoarc; b=VGAsVPTpgO/3IWtFSXfwi/1rtmnZ+jcJdTltvfc6iObqk2o3odGydKqDHrDUl02sBnZwZXEyFqqpmO50x9uXKqGmFtTX2UPzZACtm6UZOiUOGva58OJrZ3tmydFkeP2Uyy+f1OihOm64dvvwZgV4RltDM9FzibWxPzeYzZ1oom4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740143; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jMCTGdt7yyYe67FVtEGzMaaaOKFc4IYbk+5c5Yx/Vfg=; b=iVkndICVIlmVEaPHAGI/Gcp4RjmkxNev68RPjD95YtCfQEyVjvduwFRwm2h9+JCXXtziV8jSoCb9fLw9VapNYmQCzfX7tZgXS4bKSN4sh1Ue42mDBTAAE+c9zKcXdMXHspPcRCEk6AeOxpaW7x0xVV4H5brBszDkIRBeAIHEaAc= 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 1681740143298872.8708520581129; Mon, 17 Apr 2023 07:02:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPQ4-00065b-D8; Mon, 17 Apr 2023 10:01:25 -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 1poPPq-0005Zb-Hm for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:10 -0400 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPc-0003HZ-C2 for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:09 -0400 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-187dc84637aso4886686fac.2 for ; Mon, 17 Apr 2023 07:00:55 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740054; x=1684332054; 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=jMCTGdt7yyYe67FVtEGzMaaaOKFc4IYbk+5c5Yx/Vfg=; b=Yf2dp5FpcmfVAsfnMIsnJ6FXlaVSzDWXg6ZKUdIPw+zC4jtwH659DbV4E1FFq7rgts G0Vm2vdD+bFzONav5H/tduIFtNUQm3PqlATWimJh18e7KJY7eY5aE5UzJxtfR+Ubf5gU io8nmibRJddpIRGrnN73x2/7pmNDlAPr8fmvfSFkWJIuArXKHvDYG5OjzSZqzJ2z9RrN Rrrjhj26mlMHf6S3mn42IFolRxCNXztwzasWaLG5aqkaqzeY6xSNUkigb7lciHcXAAXP TUamUe/DJ3a8Q0FDE+dM4v7vFSYMGyIU8HyCz9B24eRoptjjqXSy6u98yqF/0WTPRb1J x9mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740054; x=1684332054; 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=jMCTGdt7yyYe67FVtEGzMaaaOKFc4IYbk+5c5Yx/Vfg=; b=FCpipk6XC5KiSprTq/kLj79cSTv8+lJy8AkhJ5QqMhKoHkB8nPQ3SqSErVqMWxqDjH /tzINq5aXSS9oBAoRcnIz+IHG72zqTsnoaLU1ctO75ue4vYoga53Jqm7LnFKt6MKA0TT lVfuW+lG/K9TJkYtN4TdtFnLexpVAT8ofsEljGNZTRXZrlJ+ul2QXGxpS9s1o7Rz3KbK 2my0JDpmjngIGg3Ol9Qhn5iyEYXh8F0GIN1pvc7SM0leWInkL5SWBmzkHxAc/kaVni/E SCx4du2nPyfaLdT7JuodSyoA/pJvFIpmsfYLjGyPllYF3ENkc7CF00ZTAD2Z2ss3niuQ sZSw== X-Gm-Message-State: AAQBX9dHuZ2ounp0DGN7+Brnyza4K+NFWm/wKJqNOE+R7yAcXBD+Gtzk bfgc1FN7wAa8HNcJkscBki4lTSMnEzZhbGUuKds= X-Google-Smtp-Source: AKy350bOglq+JMX/2IelHod+TBF/c/nhCM4usA286OJr+/z2tgw6u2CVQII/UswHwNuUB9wTzq9FKQ== X-Received: by 2002:a05:6870:241d:b0:187:eb83:84e0 with SMTP id n29-20020a056870241d00b00187eb8384e0mr1493521oap.38.1681740054549; Mon, 17 Apr 2023 07:00:54 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 10/12] target/riscv/cpu.c: remove cfg setup from riscv_cpu_init() Date: Mon, 17 Apr 2023 11:00:11 -0300 Message-Id: <20230417140013.58893-11-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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=2001:4860:4864:20::31; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x31.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1681740177441100001 Content-Type: text/plain; charset="utf-8" We have 4 config settings being done in riscv_cpu_init(): ext_ifencei, ext_icsr, mmu and pmp. This is also the constructor of the "riscv-cpu" device, which happens to be the parent device of every RISC-V cpu. The result is that these 4 configs are being set every time, and every other CPU should always account for them. CPUs such as sifive_e need to disable settings that aren't enabled simply because the parent class happens to be enabling it. Moving all configurations from the parent class to each CPU will centralize the config of each CPU into its own init(), which is clearer than having to account to whatever happens to be set in the parent device. These settings are also being set in register_cpu_props() when no 'misa_ext' is set, so for these CPUs we don't need changes. Named CPUs will receive all cfgs that the parent were setting into their init(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 59 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 2d7f0ac785..7d407321aa 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -332,7 +332,8 @@ static void set_satp_mode_default_map(RISCVCPU *cpu) =20 static void riscv_any_cpu_init(Object *obj) { - CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + CPURISCVState *env =3D &cpu->env; #if defined(TARGET_RISCV32) set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVU); #elif defined(TARGET_RISCV64) @@ -346,6 +347,12 @@ static void riscv_any_cpu_init(Object *obj) #endif =20 env->priv_ver =3D PRIV_VERSION_LATEST; + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.mmu =3D true; + cpu->cfg.pmp =3D true; } =20 #if defined(TARGET_RISCV64) @@ -364,12 +371,19 @@ static void rv64_base_cpu_init(Object *obj) =20 static void rv64_sifive_u_cpu_init(Object *obj) { - CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + CPURISCVState *env =3D &cpu->env; set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV39); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.mmu =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv64_sifive_e_cpu_init(Object *obj) @@ -379,10 +393,14 @@ static void rv64_sifive_e_cpu_init(Object *obj) =20 set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; - cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv64_thead_c906_cpu_init(Object *obj) @@ -410,6 +428,9 @@ static void rv64_thead_c906_cpu_init(Object *obj) #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_SV39); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.pmp =3D true; } =20 static void rv128_base_cpu_init(Object *obj) @@ -446,12 +467,19 @@ static void rv32_base_cpu_init(Object *obj) =20 static void rv32_sifive_u_cpu_init(Object *obj) { - CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + CPURISCVState *env =3D &cpu->env; set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.mmu =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv32_sifive_e_cpu_init(Object *obj) @@ -461,10 +489,14 @@ static void rv32_sifive_e_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; - cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv32_ibex_cpu_init(Object *obj) @@ -474,11 +506,15 @@ static void rv32_ibex_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); env->priv_ver =3D PRIV_VERSION_1_11_0; - cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); #endif cpu->cfg.epmp =3D true; + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv32_imafcu_nommu_cpu_init(Object *obj) @@ -488,10 +524,14 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; - cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.pmp =3D true; } #endif =20 @@ -1404,11 +1444,6 @@ static void riscv_cpu_init(Object *obj) { RISCVCPU *cpu =3D RISCV_CPU(obj); =20 - cpu->cfg.ext_ifencei =3D true; - cpu->cfg.ext_icsr =3D true; - cpu->cfg.mmu =3D true; - cpu->cfg.pmp =3D true; - cpu_set_cpustate_pointers(cpu); =20 #ifndef CONFIG_USER_ONLY --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740297; cv=none; d=zohomail.com; s=zohoarc; b=gLenfGVHbHD5cAWA1EBPvjqOU9pgrpmlSY9xJg7l4yyD6md2qdOe7eOme5Sj6OgemJIDWdMC/YcJXMtKiv1HFwR5JpWSTclvKaPKWAXqE51EWAGDz0p22ylAi1lXPTvIQ+34vS7aZj0emeSPIO28e6RpMxlcOJ0nkWLEzl4iuPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740297; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JcqNCNsVQ3paimwEis+Vo60YMD0mDVoMWhtluBDpeeU=; b=KEjOIbOl3fWPpEESCfXLtZeK3SfH8z39dsyTwnQj3kohvsjzfX5bomLlwDlcobUAkzyZs3HBmdK5zGsCq/t35xV+l3YLPJHLcnfpXlIT4K5HRqPax/Mcq9maozPQslP78j/04CKrw5qEBF4hS3eu2oh+yuLsvKqWRhM1nxJY+Fw= 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 1681740297799594.4089465262277; Mon, 17 Apr 2023 07:04:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPQA-00074a-Sm; Mon, 17 Apr 2023 10:01:30 -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 1poPPs-0005h3-M2 for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:14 -0400 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPg-0003ID-0o for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:12 -0400 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-187916b6543so14894727fac.7 for ; Mon, 17 Apr 2023 07:00:59 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740058; x=1684332058; 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=JcqNCNsVQ3paimwEis+Vo60YMD0mDVoMWhtluBDpeeU=; b=NlgfOwNpFB/U2P2hb5QiwrPZ354HaEeZH8weNdHQ5JCea1WFiMFjtauZt9b8zNZnN9 xL1kOgjABM2ebjTMa3K2QOv2oqJSTvPZuLbXhuYMVLq7Rf3x9L4qA4HZBJJ435GKgSSh 6AebgKpDdftNInbL9tgz5d+DjuuadZcKg3lUjEapFKa5SZ8WuLqGxiYPNX37POI5XqKm y45HeQpsnMpbJ7Nt3sdSRWbX4IRpaHxPHMKUDMgg/Wqpj3jgrSt2Fls0E9tXsZgKejQB hQlJ/czTCSy1zFdKkbS1ZSScuVWruRjtDfYXnKFGfHkw8+baHcc7qkgbyvfwyJRq78gY 4Eow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740058; x=1684332058; 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=JcqNCNsVQ3paimwEis+Vo60YMD0mDVoMWhtluBDpeeU=; b=AWQuk17laffUCqMwxyFagYalJGKFOavD66l01G6quL7nLsfZ8o5Ftvwzb6Dxk5qOy2 QK/uDkOIpDZW4fnkEFaVLepQD+MZq9EdTMb94O7IB0mU8/EBKmabfLiZQiscyNV9O+uS 9wgsNqK+GHrXpisNiDSsCK0Pgxp8VC5vbBNsYZdsXeEkGttXXeNF1aJVDZFzBLG19GHi 8/+HxV+xzqd8gq5Y54jDCa/R2f/JYKSGUTTG8QApOZykLKPJs6nH8ZlTr2BwRmPmS2yi udjTlK2uaCVpIgC4SmShqKZcPsu92zAiYqBcMnkY39yiRXDAnlORT027ReB3JV8gXlEP TLww== X-Gm-Message-State: AAQBX9c/8T+lK7KUYZiyPcDSskQ7Ri47M8XBGeXyMf9Dtw6exoJJ4gKW XyUyWP5KZRJtcHzE+3KAe480/nIqP4w8TgJzvVA= X-Google-Smtp-Source: AKy350bxmP9fRO5wtPkZo446i+FQNQu2dixZ88svKyf8jUvGLkWaFcUkCBRYiD34NwMAZSAfGzVDPg== X-Received: by 2002:a05:6870:d38c:b0:185:cf91:188b with SMTP id k12-20020a056870d38c00b00185cf91188bmr6449659oag.42.1681740057835; Mon, 17 Apr 2023 07:00:57 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 11/12] target/riscv: rework write_misa() Date: Mon, 17 Apr 2023 11:00:12 -0300 Message-Id: <20230417140013.58893-12-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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=2001:4860:4864:20::2c; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740314129100001 Content-Type: text/plain; charset="utf-8" write_misa() must use as much common logic as possible. We want to open code just the bits that are exclusive to the CSR write operation and TCG internals. Our validation is done with riscv_cpu_validate_set_extensions(), but we need a small tweak first. When enabling RVG we're doing: env->misa_ext |=3D RVI | RVM | RVA | RVF | RVD; env->misa_ext_mask =3D env->misa_ext; This works fine for realize() time but this can potentially overwrite env->misa_ext_mask if we reutilize the function for write_misa(). Instead of doing misa_ext_mask =3D misa_ext, sum up the RVG extensions in misa_ext_mask as well. This won't change realize() time behavior (misa_ext_mask is still =3D=3D misa_ext) and will ensure that write_misa() won't change misa_ext_mask by accident. After that, rewrite write_misa() to work as follows: - mask the write using misa_ext_mask to avoid enabling unsupported extensions; - suppress RVC if the next insn isn't aligned; - disable RVG if any of RVG dependencies are being disabled by the user; - assign env->misa_ext and run riscv_cpu_validate_set_extensions(). On error, rollback to the previous values of misa_ext and misa_ext_mask; - on success, check if there's a chance that misa_ext_mask was overwritten during the process and restore it; - handle RVF and MSTATUS_FS and continue as usual. Let's keep write_misa() as experimental for now until this logic gains enough mileage. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 4 ++-- target/riscv/cpu.h | 1 + target/riscv/csr.c | 47 ++++++++++++++++++++-------------------------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7d407321aa..4fa720a39d 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -944,7 +944,7 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, = Error **errp) * Check consistency between chosen extensions while setting * cpu->cfg accordingly. */ -static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) +void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) { CPURISCVState *env =3D &cpu->env; Error *local_err =3D NULL; @@ -960,7 +960,7 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU = *cpu, Error **errp) cpu->cfg.ext_ifencei =3D true; =20 env->misa_ext |=3D RVI | RVM | RVA | RVF | RVD; - env->misa_ext_mask =3D env->misa_ext; + env->misa_ext_mask |=3D RVI | RVM | RVA | RVF | RVD; } =20 if (riscv_has_ext(env, RVI) && riscv_has_ext(env, RVE)) { diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 15423585d0..1f39edc687 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -548,6 +548,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, bool probe, uintptr_t retaddr); char *riscv_isa_string(RISCVCPU *cpu); void riscv_cpu_list(void); +void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); =20 #define cpu_list riscv_cpu_list #define cpu_mmu_index riscv_cpu_mmu_index diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 865ee9efda..d449da2657 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1387,39 +1387,18 @@ static RISCVException read_misa(CPURISCVState *env,= int csrno, static RISCVException write_misa(CPURISCVState *env, int csrno, target_ulong val) { + RISCVCPU *cpu =3D env_archcpu(env); + uint32_t orig_misa_ext =3D env->misa_ext; + Error *local_err =3D NULL; + if (!riscv_cpu_cfg(env)->misa_w) { /* drop write to misa */ return RISCV_EXCP_NONE; } =20 - /* '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 =3D 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 &=3D env->misa_ext_mask; =20 - /* 'D' depends on 'F', so clear 'D' if 'F' is not present */ - if ((val & RVD) && !(val & RVF)) { - val &=3D ~RVD; - } - /* * Suppress 'C' if next instruction is not aligned * TODO: this should check next_pc @@ -1428,18 +1407,32 @@ static RISCVException write_misa(CPURISCVState *env= , int csrno, val &=3D ~RVC; } =20 + /* Disable RVG if any of its dependencies are disabled */ + if (!(val & RVI && val & RVM && val & RVA && + val & RVF && val & RVD)) { + val &=3D ~RVG; + } + /* If nothing changed, do nothing. */ if (val =3D=3D env->misa_ext) { return RISCV_EXCP_NONE; } =20 - if (!(val & RVF)) { + env->misa_ext =3D val; + riscv_cpu_validate_set_extensions(cpu, &local_err); + if (local_err !=3D NULL) { + /* Rollback on validation error */ + env->misa_ext =3D orig_misa_ext; + + return RISCV_EXCP_NONE; + } + + if (!(env->misa_ext & RVF)) { env->mstatus &=3D ~MSTATUS_FS; } =20 /* flush translation cache */ tb_flush(env_cpu(env)); - env->misa_ext =3D val; env->xl =3D riscv_cpu_mxl(env); return RISCV_EXCP_NONE; } --=20 2.39.2 From nobody Fri May 17 06:07:50 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=1681740510; cv=none; d=zohomail.com; s=zohoarc; b=K9PAXFLJZc1xsVRsiKVFz8B29FAxy7Z0o4bdeYq7q6AQT9VejP63I8cVSkXX6iPV1gLZ50bn7qgjB2BRs1CdoHz65fbNtQe1qEoMNJk9qOZdHQyAFwX1zrDiGKkrs5FCoVhTel4zi+SnUtGURm6Lm8ADZjCHWoRHabcLtd34+gQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681740510; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uyptJ4c227hjyJcT2iaCzQnVJjxff8HhOsI7SdfqkhU=; b=aBXTBrEJTmGRZn/2+SiNFqPRuoCqEVXjaJ/o5DrkPltTLoHHMmhmvkj8rrmuGTH1ttdrod/A522URMZkXgw6gFr/BGdCFsfEgeTLy8WB38Z1k+zT3hs0QJNKoF4fO29zDheBGta0oAYQn4BVzMDkJtSJmDiuQ2FPfqEkXa7qJcY= 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 168174051061327.11391524202054; Mon, 17 Apr 2023 07:08:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poPQ9-0006qk-Bj; Mon, 17 Apr 2023 10:01: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 1poPPs-0005h4-Th for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:14 -0400 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poPPj-0003Id-8I for qemu-devel@nongnu.org; Mon, 17 Apr 2023 10:01:12 -0400 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-1878504c22aso17053400fac.8 for ; Mon, 17 Apr 2023 07:01:02 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([191.255.108.232]) by smtp.gmail.com with ESMTPSA id x16-20020a05687031d000b001726cfeea97sm4531868oac.29.2023.04.17.07.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 07:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1681740061; x=1684332061; 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=uyptJ4c227hjyJcT2iaCzQnVJjxff8HhOsI7SdfqkhU=; b=hOg2bLQbdrz9NH90BQEAyfXly1NTfd9xXxLId8qfPYNjs1jMZhinhZRyL2DZtE4IKc WNrzQI2MagzK5j5IzSiK5GoJ6tsBi7aeo5gDHpuSQ0ZP8dEGdJja+9gKJQMtdHthwMF3 wS4xswzqGLlDVhDy79ook2sVeZ+ClBjH6VHFneOyGan2f2QNe7JIG6Rd8Nw/QwvQ0tWY vSqJVzbW2Yw/XmbbAtbIYeKiehje3pf3RSqCEGKHvunNKQUD9R4hnU3ondxJhj/t3R8B 8ogX8wgEuYxJV6cLHP1675SlprPMuyNoq17oi2F2xg+s2eVzsAi3upBY1ol1MXQGjpkn Cm4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681740061; x=1684332061; 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=uyptJ4c227hjyJcT2iaCzQnVJjxff8HhOsI7SdfqkhU=; b=i8QcpCbrx4l2oKFDipNisdMWClr/usT+HuS+KqWlY/aiFr6s7x0X0W+rOXhIhVlpYA PyYUSxVmibze+onU1I6Ma1m9YfbJAprw2a3rcVmXMAdOnjx4txcKRGseVh5hi5eacw83 7z4sRVyHRkin6SLm67dFAoPbrecNupl4IZ65LLL8HoO34taQh162QREtBcm5CO7ruFhp 8SANcxjFfc0K7PQQV756Iyg6ggCCf7pnBaXcn5gDSZ2fij7UsUoEPVfBDHb0EFsZj3Vr ywB+xpNy48ik33exZwkRkIWT0b4iEp2jqCH99uE/LXEkNx4xUYwSFywsQh0Q+2wZrjO+ KrGA== X-Gm-Message-State: AAQBX9dO5RpZOcv/5NPh0/TcxMpvB9Xx54RkSVLBO9rvChubehcCTmbi ataTHyydjTrfMdML+V62Ikus8NAp/1hdLSDES+k= X-Google-Smtp-Source: AKy350ZWeLv9CYD/ZYc3J1NDjayRYlCaOLSMLlKQhBwFLiDmBXFQqOL3EJx1hLe4cNfUGfaW1R5f8A== X-Received: by 2002:a05:6870:17aa:b0:177:be5e:4532 with SMTP id r42-20020a05687017aa00b00177be5e4532mr10407379oae.10.1681740061271; Mon, 17 Apr 2023 07:01:01 -0700 (PDT) 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, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v7 12/12] target/riscv: forbid write_misa() for static CPUs Date: Mon, 17 Apr 2023 11:00:13 -0300 Message-Id: <20230417140013.58893-13-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230417140013.58893-1-dbarboza@ventanamicro.com> References: <20230417140013.58893-1-dbarboza@ventanamicro.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=2001:4860:4864:20::35; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x35.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=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 @ventanamicro.com) X-ZM-MESSAGEID: 1681740511311100001 Content-Type: text/plain; charset="utf-8" Static CPUs don't want their extensions changed by user interaction. We can prevent it during init by not exposing user facing properties, but write_misa() is also capable of disabling/enabling extension during runtime. We have a way of telling whether a CPU is static or not by checking for TYPE_RISCV_DYNAMIC_CPU. Use it to make write_misa() a no-op for these CPUs. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 5 +++++ target/riscv/cpu.h | 2 ++ target/riscv/csr.c | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4fa720a39d..3cbcf6d320 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1452,6 +1452,11 @@ static void riscv_cpu_init(Object *obj) #endif /* CONFIG_USER_ONLY */ } =20 +bool riscv_cpu_is_static(RISCVCPU *cpu) +{ + return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_DYNAMIC_CPU) =3D=3D= NULL; +} + typedef struct RISCVCPUMisaExtConfig { const char *name; const char *description; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 1f39edc687..1913ab9d8d 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -587,6 +587,8 @@ G_NORETURN void riscv_raise_exception(CPURISCVState *en= v, target_ulong riscv_cpu_get_fflags(CPURISCVState *env); void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong); =20 +bool riscv_cpu_is_static(RISCVCPU *cpu); + #include "exec/cpu-all.h" =20 FIELD(TB_FLAGS, MEM_IDX, 0, 3) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d449da2657..929c5477dd 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1391,6 +1391,11 @@ static RISCVException write_misa(CPURISCVState *env,= int csrno, uint32_t orig_misa_ext =3D env->misa_ext; Error *local_err =3D NULL; =20 + if (riscv_cpu_is_static(cpu)) { + /* never write MISA for static CPUs */ + return RISCV_EXCP_NONE; + } + if (!riscv_cpu_cfg(env)->misa_w) { /* drop write to misa */ return RISCV_EXCP_NONE; --=20 2.39.2