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 039E8C76196 for ; Wed, 12 Apr 2023 01:33:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmPLp-0005Lb-KQ; Tue, 11 Apr 2023 21:32:45 -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 1pmPLn-0005L3-Bj; Tue, 11 Apr 2023 21:32:43 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmPLk-0004Cx-KF; Tue, 11 Apr 2023 21:32:43 -0400 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R161e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018045176; MF=zhiwei_liu@linux.alibaba.com; NM=1; PH=DS; RN=8; SR=0; TI=SMTPD_---0Vfu2U6f_1681263149; Received: from 30.221.97.64(mailfrom:zhiwei_liu@linux.alibaba.com fp:SMTPD_---0Vfu2U6f_1681263149) by smtp.aliyun-inc.com; Wed, 12 Apr 2023 09:32:29 +0800 Message-ID: Date: Wed, 12 Apr 2023 09:32:26 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH] target/riscv: Restore the predicate() NULL check behavior Content-Language: en-US To: Bin Meng , Alistair Francis , Daniel Henrique Barboza , Weiwei Li , Palmer Dabbelt Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Fei Wu References: <20230411090211.3039186-1-bmeng@tinylab.org> From: LIU Zhiwei In-Reply-To: <20230411090211.3039186-1-bmeng@tinylab.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=115.124.30.131; envelope-from=zhiwei_liu@linux.alibaba.com; helo=out30-131.freemail.mail.aliyun.com X-Spam_score_int: -120 X-Spam_score: -12.1 X-Spam_bar: ------------ X-Spam_report: (-12.1 / 5.0 requ) BAYES_00=-1.9, ENV_AND_HDR_SPF_MATCH=-0.5, NICE_REPLY_A=-2.17, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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/4/11 17:02, Bin Meng wrote: > When reading a non-existent CSR QEMU should raise illegal instruction > exception, but currently it just exits due to the g_assert() check. > > This actually reverts commit 0ee342256af9205e7388efdf193a6d8f1ba1a617, > Some comments are also added to indicate that predicate() must be > provided for an implemented CSR. > > Reported-by: Fei Wu > Signed-off-by: Bin Meng Reviewed-by: LIU Zhiwei Zhiwei > --- > > target/riscv/csr.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/target/riscv/csr.c b/target/riscv/csr.c > index d522efc0b6..736ab64275 100644 > --- a/target/riscv/csr.c > +++ b/target/riscv/csr.c > @@ -3797,6 +3797,11 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, > return RISCV_EXCP_ILLEGAL_INST; > } > > + /* ensure CSR is implemented by checking predicate */ > + if (!csr_ops[csrno].predicate) { > + return RISCV_EXCP_ILLEGAL_INST; > + } > + > /* privileged spec version check */ > if (env->priv_ver < csr_min_priv) { > return RISCV_EXCP_ILLEGAL_INST; > @@ -3814,7 +3819,6 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, > * illegal instruction exception should be triggered instead of virtual > * instruction exception. Hence this comes after the read / write check. > */ > - g_assert(csr_ops[csrno].predicate != NULL); > RISCVException ret = csr_ops[csrno].predicate(env, csrno); > if (ret != RISCV_EXCP_NONE) { > return ret; > @@ -3991,7 +3995,10 @@ RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno, > return ret; > } > > -/* Control and Status Register function table */ > +/* > + * Control and Status Register function table > + * riscv_csr_operations::predicate() must be provided for an implemented CSR > + */ > riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { > /* User Floating-Point CSRs */ > [CSR_FFLAGS] = { "fflags", fs, read_fflags, write_fflags },