qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Weiwei Li <liweiwei@iscas.ac.cn>
To: Andrew Jones <ajones@ventanamicro.com>, Weiwei Li <liweiwei@iscas.ac.cn>
Cc: palmer@dabbelt.com, alistair.francis@wdc.com,
	bin.meng@windriver.com, qemu-riscv@nongnu.org,
	qemu-devel@nongnu.org, wangjunqiang@iscas.ac.cn,
	lazyparser@gmail.com
Subject: Re: [PATCH V3 6/6] target/riscv: Simplify the check in hmode to resue the check in riscv_csrrw_check
Date: Mon, 18 Jul 2022 22:31:18 +0800	[thread overview]
Message-ID: <fa430f1c-a341-8c2c-4a9f-e2c92f9d9740@iscas.ac.cn> (raw)
In-Reply-To: <20220718134705.3irtvydqu6nn4uys@kamzik>


在 2022/7/18 下午9:47, Andrew Jones 写道:
> Hi Weiwei,
>
> We still need the s/resue/reuse/ typo fix in $SUBJECT.
>
> (That's maybe something that could be fixed up while applying?)
>
> Thanks,
> drew

Thanks a lot.

Sorry for not finding this typo. I'll fix it in next version.

Regards,

Weiwei Li

> On Mon, Jul 18, 2022 at 09:09:55PM +0800, Weiwei Li wrote:
>> Just add 1 to the effective privledge level when in HS mode, then reuse
>> the check of 'effective_priv < csr_priv' in riscv_csrrw_check to replace
>> the privilege level related check in hmode. Then, hmode will only check
>> whether H extension is supported.
>>
>> When accessing Hypervior CSRs:
>>     1) If accessing from M privilege level, the check of
>> 'effective_priv< csr_priv' passes, returns hmode(...) which will return
>> RISCV_EXCP_ILLEGAL_INST when H extension is not supported and return
>> RISCV_EXCP_NONE otherwise.
>>     2) If accessing from HS privilege level, effective_priv will add 1,
>> the check passes and also returns hmode(...) too.
>>     3) If accessing from VS/VU privilege level, the check fails, and
>> returns RISCV_EXCP_VIRT_INSTRUCTION_FAULT
>>     4) If accessing from U privilege level, the check fails, and returns
>> RISCV_EXCP_ILLEGAL_INST
>>
>> Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn>
>> Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn>
>> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
>> ---
>>   target/riscv/csr.c | 18 +++++-------------
>>   1 file changed, 5 insertions(+), 13 deletions(-)
>>
>> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
>> index cf15aa67b7..0fb042b2fd 100644
>> --- a/target/riscv/csr.c
>> +++ b/target/riscv/csr.c
>> @@ -312,13 +312,7 @@ static int aia_smode32(CPURISCVState *env, int csrno)
>>   static RISCVException hmode(CPURISCVState *env, int csrno)
>>   {
>>       if (riscv_has_ext(env, RVH)) {
>> -        /* Hypervisor extension is supported */
>> -        if ((env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) ||
>> -            env->priv == PRV_M) {
>> -            return RISCV_EXCP_NONE;
>> -        } else {
>> -            return RISCV_EXCP_VIRT_INSTRUCTION_FAULT;
>> -        }
>> +        return RISCV_EXCP_NONE;
>>       }
>>   
>>       return RISCV_EXCP_ILLEGAL_INST;
>> @@ -3279,13 +3273,11 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env,
>>   #if !defined(CONFIG_USER_ONLY)
>>       int csr_priv, effective_priv = env->priv;
>>   
>> -    if (riscv_has_ext(env, RVH) && env->priv == PRV_S) {
>> +    if (riscv_has_ext(env, RVH) && env->priv == PRV_S &&
>> +        !riscv_cpu_virt_enabled(env)) {
>>           /*
>> -         * We are in either HS or VS mode.
>> -         * Add 1 to the effective privledge level to allow us to access the
>> -         * Hypervisor CSRs. The `hmode` predicate will determine if access
>> -         * should be allowed(HS) or if a virtual instruction exception should be
>> -         * raised(VS).
>> +         * We are in HS mode. Add 1 to the effective privledge level to
>> +         * allow us to access the Hypervisor CSRs.
>>            */
>>           effective_priv++;
>>       }
>> -- 
>> 2.17.1
>>
>>



  reply	other threads:[~2022-07-18 14:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 13:09 [PATCH V3 0/6] Improve the U/S/H extension related check Weiwei Li
2022-07-18 13:09 ` [PATCH V3 1/6] target/riscv: Add check for supported privilege mode combinations Weiwei Li
2022-07-18 13:09 ` [PATCH V3 2/6] target/riscv: H extension depends on I extension Weiwei Li
2022-07-18 13:09 ` [PATCH V3 3/6] target/riscv: Fix checkpatch warning may triggered in csr_ops table Weiwei Li
2022-07-18 13:09 ` [PATCH V3 4/6] target/riscv: Add check for csrs existed with U extension Weiwei Li
2022-07-18 13:09 ` [PATCH V3 5/6] target/riscv: Fix checks in hmode/hmode32 Weiwei Li
2022-07-18 23:10   ` Alistair Francis
2022-07-18 13:09 ` [PATCH V3 6/6] target/riscv: Simplify the check in hmode to resue the check in riscv_csrrw_check Weiwei Li
2022-07-18 13:47   ` Andrew Jones
2022-07-18 14:31     ` Weiwei Li [this message]
2022-07-19  0:23 ` [PATCH V3 0/6] Improve the U/S/H extension related check Alistair Francis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fa430f1c-a341-8c2c-4a9f-e2c92f9d9740@iscas.ac.cn \
    --to=liweiwei@iscas.ac.cn \
    --cc=ajones@ventanamicro.com \
    --cc=alistair.francis@wdc.com \
    --cc=bin.meng@windriver.com \
    --cc=lazyparser@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=wangjunqiang@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).