From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A627AEB64DC for ; Tue, 18 Jul 2023 01:37:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qLZe1-0000CS-Ff; Mon, 17 Jul 2023 21:36:53 -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 1qLZdx-00006P-BM; Mon, 17 Jul 2023 21:36:49 -0400 Received: from out30-97.freemail.mail.aliyun.com ([115.124.30.97]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qLZdu-0007md-FW; Mon, 17 Jul 2023 21:36:49 -0400 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R101e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018046049; MF=zhiwei_liu@linux.alibaba.com; NM=1; PH=DS; RN=8; SR=0; TI=SMTPD_---0VnfYrLx_1689644192; Received: from 30.221.100.194(mailfrom:zhiwei_liu@linux.alibaba.com fp:SMTPD_---0VnfYrLx_1689644192) by smtp.aliyun-inc.com; Tue, 18 Jul 2023 09:36:33 +0800 Message-ID: Date: Tue, 18 Jul 2023 09:36:00 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] target/riscv/cpu.c: check priv_ver before auto-enable zca/zcd/zcf Content-Language: en-US To: Daniel Henrique Barboza , qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, palmer@rivosinc.com, Conor Dooley References: <20230717154141.60898-1-dbarboza@ventanamicro.com> From: LIU Zhiwei In-Reply-To: <20230717154141.60898-1-dbarboza@ventanamicro.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=115.124.30.97; envelope-from=zhiwei_liu@linux.alibaba.com; helo=out30-97.freemail.mail.aliyun.com X-Spam_score_int: -99 X-Spam_score: -10.0 X-Spam_bar: ---------- X-Spam_report: (-10.0 / 5.0 requ) BAYES_00=-1.9, ENV_AND_HDR_SPF_MATCH=-0.5, NICE_REPLY_A=-0.097, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 2023/7/17 23:41, Daniel Henrique Barboza wrote: > Commit bd30559568 made changes in how we're checking and disabling > extensions based on env->priv_ver. One of the changes was to move the > extension disablement code to the end of realize(), being able to > disable extensions after we've auto-enabled some of them. > > An unfortunate side effect of this change started to happen with CPUs > that has an older priv version, like sifive-u54. Starting on commit > 2288a5ce43e5 we're auto-enabling zca, zcd and zcf if RVC is enabled, > but these extensions are priv version 1.12.0. When running a cpu that > has an older priv ver (like sifive-u54) the user is spammed with > warnings like these: > > qemu-system-riscv64: warning: disabling zca extension for hart 0x0000000000000000 because privilege spec version does not match > qemu-system-riscv64: warning: disabling zcd extension for hart 0x0000000000000000 because privilege spec version does not match > > The warnings are part of the code that disables the extension, but in this > case we're throwing user warnings for stuff that we enabled on our own, > without user intervention. Users are left wondering what they did wrong. > > A quick 8.1 fix for this nuisance is to check the CPU priv spec before > auto-enabling zca/zcd/zcf. A more appropriate fix will include a more > robust framework that will account for both priv_ver and user choice > when auto-enabling/disabling extensions, but for 8.1 we'll make it do > with this simple check. > > It's also worth noticing that this is the only case where we're > auto-enabling extensions based on a criteria (in this case RVC) that > doesn't match the priv spec of the extensions we're enabling. There's no > need for more 8.1 band-aids. > > Cc: Conor Dooley > Fixes: 2288a5ce43e5 ("target/riscv: add cfg properties for Zc* extension") > Signed-off-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 9339c0241d..6b93b04453 100644 > --- a/target/riscv/cpu.c > +++ b/target/riscv/cpu.c > @@ -1225,7 +1225,8 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) > } > } > > - if (riscv_has_ext(env, RVC)) { > + /* zca, zcd and zcf has a PRIV 1.12.0 restriction */ I think the Zca/zcd/zcf doesn't have much relationship with the privilege specification. The privilege specification doesn't define any CSR or rules that Zca/zcd/zcf depend on. Maybe I missed something.  Does anyone  know why we should check PRIV_VERSION_1_12_0 for zca/zcf/zcd? I think we should remove the check for priv_ver for many user mode extensions. We should set the checking privilege specification version for these extensions to PRIV_VERSION_1_10_0. Zhiwei > + if (riscv_has_ext(env, RVC) && env->priv_ver >= PRIV_VERSION_1_12_0) { > cpu->cfg.ext_zca = true; > if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) { > cpu->cfg.ext_zcf = true;