All of lore.kernel.org
 help / color / mirror / Atom feed
From: LIU Zhiwei <zhiwei_liu@c-sky.com>
To: Jose Martins <josemartins90@gmail.com>
Cc: "open list:RISC-V TCG CPUs" <qemu-riscv@nongnu.org>,
	Sagar Karandikar <sagark@eecs.berkeley.edu>,
	Bastian Koppelmann <kbastian@mail.uni-paderborn.de>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	Alistair Francis <Alistair.Francis@wdc.com>,
	Palmer Dabbelt <palmer@dabbelt.com>
Subject: Re: [PATCH v3] target/riscv: fix VS interrupts forwarding to HS
Date: Thu, 27 May 2021 16:40:46 +0800	[thread overview]
Message-ID: <578409c2-c267-7f93-d9b5-c408ed8aa10e@c-sky.com> (raw)
In-Reply-To: <CAC41xo3XAWZrqtFxiLDQ+H4fr=FVkWmZfe8P+PaTx-MPU_fpfw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4018 bytes --]


On 5/26/21 7:50 PM, Jose Martins wrote:
> Hello Zhiwei, thank you for reviewing the patch.
>
> I'll split the patch in a series as you suggest. But first can you
> help me understand what the problems are with
> riscv_cpu_local_irq_pending?
>
>> I think there are two errors in riscv_cpu_local_irq_pending.
>>
>> 1) VS interrupts can't be forwarded to hs-mode rightly . It has
>> nothing to do with delegate or not in hideleg. The reason is that
>> VS interrupts are always discarded when V=0 in
>> riscv_cpu_local_irq_pending.
> I don't see why this is the case. The way I see it, VS interrupts are
> only discarded for V=0 *iff* they are delegated in mideleg/hideleg.
First I paste the code to ensure we are talking about the same version.

  static int riscv_cpu_local_irq_pending(CPURISCVState *env)

  {

      target_ulong irqs;

  

      target_ulong mstatus_mie = get_field(env->mstatus, MSTATUS_MIE);

      target_ulong mstatus_sie = get_field(env->mstatus, MSTATUS_SIE);

      target_ulong hs_mstatus_sie = get_field(env->mstatus_hs, MSTATUS_SIE);

  

      target_ulong pending = env->mip & env->mie &

                                 ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP);

      target_ulong vspending = (env->mip & env->mie &

                                (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP));

  

      target_ulong mie    = env->priv < PRV_M ||

                            (env->priv == PRV_M && mstatus_mie);

      target_ulong sie    = env->priv < PRV_S ||

                            (env->priv == PRV_S && mstatus_sie);

      target_ulong hs_sie = env->priv < PRV_S ||

                            (env->priv == PRV_S && hs_mstatus_sie);

  

      if (riscv_cpu_virt_enabled(env)) {

          target_ulong pending_hs_irq = pending & -hs_sie;

  

          if (pending_hs_irq) {

              riscv_cpu_set_force_hs_excep(env, FORCE_HS_EXCEP);

              return ctz64(pending_hs_irq);

          }

  

          pending = vspending;

      }

  

      irqs = (pending & ~env->mideleg & -mie) | (pending &  env->mideleg & -sie);

  

      if (irqs) {

          return ctz64(irqs); /* since non-zero */

      } else {

          return RISCV_EXCP_NONE; /* indicates no pending interrupt */

      }

  }

Only when VS = 0, the variable vspending can transfer to
variable pending. Any interrupt not included in variable pending
is discarded.

That's why I say VS interrupts are always discarded
when V=0 in riscv_cpu_local_irq_pending.
> I
> actually tested it and I see the correct forwarding of vs-mode
> interrupts to hs-mode. I tested it by running in hs-mode with all the
> needed interrupt enables set, the interrupts not delegated in hideleg,
> and forcing the trigger of the interrupt by writing hvip. But maybe
> there are some corner cases I'm not taking into account. Can you
> explain this further? Maybe walk me through an example of when this
> issue might occur.
>
>> 2) Use MSTATUS_SIE in mstatus_hs to select pending_hs_irqs.

I mean the second error is to misuse MSATUS_SIE in mstatus_hs to
select pending_hs_irqs.

> I don't think you need to go through mstatus_hs to get the correct sie
> state.
Agree.
> My logic behind this is: env->mstatus will have the vs-level
> sie if V=1 and hs-level sie if V=0. Due to the short-circuiting
> property of the logic operators the sie variable will only have an
> effect on hsie if V=0 and on vsie if V=1. So the value of sie is only
> used in the correct context.

The  swap regs funciton has done the right thing.

I think V mode and hideleg/mideleg  make it possible to process

VS interrupt or HS interrupt like other interrupts.

Zhiwei

>
> Again, please correct me if I'm wrong. I might be missing something.
>
> Best,
> José

[-- Attachment #2: Type: text/html, Size: 6059 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: LIU Zhiwei <zhiwei_liu@c-sky.com>
To: Jose Martins <josemartins90@gmail.com>
Cc: "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	"open list:RISC-V TCG CPUs" <qemu-riscv@nongnu.org>,
	Sagar Karandikar <sagark@eecs.berkeley.edu>,
	Bastian Koppelmann <kbastian@mail.uni-paderborn.de>,
	Alistair Francis <Alistair.Francis@wdc.com>,
	Palmer Dabbelt <palmer@dabbelt.com>
Subject: Re: [PATCH v3] target/riscv: fix VS interrupts forwarding to HS
Date: Thu, 27 May 2021 16:40:46 +0800	[thread overview]
Message-ID: <578409c2-c267-7f93-d9b5-c408ed8aa10e@c-sky.com> (raw)
In-Reply-To: <CAC41xo3XAWZrqtFxiLDQ+H4fr=FVkWmZfe8P+PaTx-MPU_fpfw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4018 bytes --]


On 5/26/21 7:50 PM, Jose Martins wrote:
> Hello Zhiwei, thank you for reviewing the patch.
>
> I'll split the patch in a series as you suggest. But first can you
> help me understand what the problems are with
> riscv_cpu_local_irq_pending?
>
>> I think there are two errors in riscv_cpu_local_irq_pending.
>>
>> 1) VS interrupts can't be forwarded to hs-mode rightly . It has
>> nothing to do with delegate or not in hideleg. The reason is that
>> VS interrupts are always discarded when V=0 in
>> riscv_cpu_local_irq_pending.
> I don't see why this is the case. The way I see it, VS interrupts are
> only discarded for V=0 *iff* they are delegated in mideleg/hideleg.
First I paste the code to ensure we are talking about the same version.

  static int riscv_cpu_local_irq_pending(CPURISCVState *env)

  {

      target_ulong irqs;

  

      target_ulong mstatus_mie = get_field(env->mstatus, MSTATUS_MIE);

      target_ulong mstatus_sie = get_field(env->mstatus, MSTATUS_SIE);

      target_ulong hs_mstatus_sie = get_field(env->mstatus_hs, MSTATUS_SIE);

  

      target_ulong pending = env->mip & env->mie &

                                 ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP);

      target_ulong vspending = (env->mip & env->mie &

                                (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP));

  

      target_ulong mie    = env->priv < PRV_M ||

                            (env->priv == PRV_M && mstatus_mie);

      target_ulong sie    = env->priv < PRV_S ||

                            (env->priv == PRV_S && mstatus_sie);

      target_ulong hs_sie = env->priv < PRV_S ||

                            (env->priv == PRV_S && hs_mstatus_sie);

  

      if (riscv_cpu_virt_enabled(env)) {

          target_ulong pending_hs_irq = pending & -hs_sie;

  

          if (pending_hs_irq) {

              riscv_cpu_set_force_hs_excep(env, FORCE_HS_EXCEP);

              return ctz64(pending_hs_irq);

          }

  

          pending = vspending;

      }

  

      irqs = (pending & ~env->mideleg & -mie) | (pending &  env->mideleg & -sie);

  

      if (irqs) {

          return ctz64(irqs); /* since non-zero */

      } else {

          return RISCV_EXCP_NONE; /* indicates no pending interrupt */

      }

  }

Only when VS = 0, the variable vspending can transfer to
variable pending. Any interrupt not included in variable pending
is discarded.

That's why I say VS interrupts are always discarded
when V=0 in riscv_cpu_local_irq_pending.
> I
> actually tested it and I see the correct forwarding of vs-mode
> interrupts to hs-mode. I tested it by running in hs-mode with all the
> needed interrupt enables set, the interrupts not delegated in hideleg,
> and forcing the trigger of the interrupt by writing hvip. But maybe
> there are some corner cases I'm not taking into account. Can you
> explain this further? Maybe walk me through an example of when this
> issue might occur.
>
>> 2) Use MSTATUS_SIE in mstatus_hs to select pending_hs_irqs.

I mean the second error is to misuse MSATUS_SIE in mstatus_hs to
select pending_hs_irqs.

> I don't think you need to go through mstatus_hs to get the correct sie
> state.
Agree.
> My logic behind this is: env->mstatus will have the vs-level
> sie if V=1 and hs-level sie if V=0. Due to the short-circuiting
> property of the logic operators the sie variable will only have an
> effect on hsie if V=0 and on vsie if V=1. So the value of sie is only
> used in the correct context.

The  swap regs funciton has done the right thing.

I think V mode and hideleg/mideleg  make it possible to process

VS interrupt or HS interrupt like other interrupts.

Zhiwei

>
> Again, please correct me if I'm wrong. I might be missing something.
>
> Best,
> José

[-- Attachment #2: Type: text/html, Size: 6059 bytes --]

  reply	other threads:[~2021-05-27  8:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-22 15:44 [PATCH v3] target/riscv: fix VS interrupts forwarding to HS Jose Martins
2021-05-22 15:44 ` Jose Martins
2021-05-26  7:02 ` LIU Zhiwei
2021-05-26  7:02   ` LIU Zhiwei
2021-05-26 11:50   ` Jose Martins
2021-05-26 11:50     ` Jose Martins
2021-05-27  8:40     ` LIU Zhiwei [this message]
2021-05-27  8:40       ` LIU Zhiwei
2021-05-27 22:34 ` Alistair Francis
2021-05-27 22:34   ` Alistair Francis
2021-05-28  0:36   ` LIU Zhiwei
2021-05-28  0:36     ` LIU Zhiwei
2021-06-02 19:14     ` Jose Martins
2021-06-02 19:14       ` Jose Martins
2021-10-17 20:30       ` Jose Martins
2021-10-17 20:30         ` Jose Martins
2021-10-18  1:13         ` Alistair Francis
2021-10-18  1:13           ` Alistair Francis
2021-10-25  9:47           ` Jose Martins
2021-10-25  9:47             ` Jose Martins
2021-10-26  6:57             ` Alistair Francis
2021-10-26  6:57               ` 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=578409c2-c267-7f93-d9b5-c408ed8aa10e@c-sky.com \
    --to=zhiwei_liu@c-sky.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=josemartins90@gmail.com \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=sagark@eecs.berkeley.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.