QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3 1/3] target/riscv: Fix tb->flags FS status
@ 2020-01-15  6:17 shihpo.hung
  2020-01-15  6:17 ` [PATCH v3 2/3] target/riscv: fsd/fsw doesn't dirty FP state shihpo.hung
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: shihpo.hung @ 2020-01-15  6:17 UTC (permalink / raw)
  To: qemu-riscv
  Cc: Sagar Karandikar, Bastian Koppelmann, Richard Henderson,
	qemu-devel, Alistair Francis, Palmer Dabbelt, ShihPo Hung

It was found that running libquantum on riscv-linux qemu produced an
incorrect result. After investigation, FP registers are not saved
during context switch due to incorrect mstatus.FS.

In current implementation tb->flags merges all non-disabled state to
dirty. This means the code in mark_fs_dirty in translate.c that
handles initial and clean states is unreachable.

This patch fixes it and is successfully tested with:
  libquantum

Thanks to Richard for pointing out the actual bug.

v3: remove the redundant condition
v2: root cause FS problem

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/riscv/cpu.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index e59343e..de0a8d8 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -293,10 +293,7 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
 #ifdef CONFIG_USER_ONLY
     *flags = TB_FLAGS_MSTATUS_FS;
 #else
-    *flags = cpu_mmu_index(env, 0);
-    if (riscv_cpu_fp_enabled(env)) {
-        *flags |= TB_FLAGS_MSTATUS_FS;
-    }
+    *flags = cpu_mmu_index(env, 0) | (env->mstatus & MSTATUS_FS);
 #endif
 }
 
-- 
2.7.4



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 2/3] target/riscv: fsd/fsw doesn't dirty FP state
  2020-01-15  6:17 [PATCH v3 1/3] target/riscv: Fix tb->flags FS status shihpo.hung
@ 2020-01-15  6:17 ` shihpo.hung
  2020-01-15  6:29   ` Alistair Francis
  2020-01-15  6:17 ` [PATCH v3 3/3] target/riscv: update mstatus.SD when FS is set dirty shihpo.hung
  2020-01-15  6:28 ` [PATCH v3 1/3] target/riscv: Fix tb->flags FS status Alistair Francis
  2 siblings, 1 reply; 9+ messages in thread
From: shihpo.hung @ 2020-01-15  6:17 UTC (permalink / raw)
  To: qemu-riscv
  Cc: Sagar Karandikar, Bastian Koppelmann, Richard Henderson,
	qemu-devel, Alistair Francis, Palmer Dabbelt, ShihPo Hung

Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/riscv/insn_trans/trans_rvd.inc.c | 1 -
 target/riscv/insn_trans/trans_rvf.inc.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/target/riscv/insn_trans/trans_rvd.inc.c b/target/riscv/insn_trans/trans_rvd.inc.c
index 393fa02..ea1044f 100644
--- a/target/riscv/insn_trans/trans_rvd.inc.c
+++ b/target/riscv/insn_trans/trans_rvd.inc.c
@@ -43,7 +43,6 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a)
 
     tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], t0, ctx->mem_idx, MO_TEQ);
 
-    mark_fs_dirty(ctx);
     tcg_temp_free(t0);
     return true;
 }
diff --git a/target/riscv/insn_trans/trans_rvf.inc.c b/target/riscv/insn_trans/trans_rvf.inc.c
index 172dbfa..e23cd63 100644
--- a/target/riscv/insn_trans/trans_rvf.inc.c
+++ b/target/riscv/insn_trans/trans_rvf.inc.c
@@ -52,7 +52,6 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a)
     tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], t0, ctx->mem_idx, MO_TEUL);
 
     tcg_temp_free(t0);
-    mark_fs_dirty(ctx);
     return true;
 }
 
-- 
2.7.4



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 3/3] target/riscv: update mstatus.SD when FS is set dirty
  2020-01-15  6:17 [PATCH v3 1/3] target/riscv: Fix tb->flags FS status shihpo.hung
  2020-01-15  6:17 ` [PATCH v3 2/3] target/riscv: fsd/fsw doesn't dirty FP state shihpo.hung
@ 2020-01-15  6:17 ` shihpo.hung
  2020-01-15  6:30   ` Alistair Francis
  2020-01-15  6:28 ` [PATCH v3 1/3] target/riscv: Fix tb->flags FS status Alistair Francis
  2 siblings, 1 reply; 9+ messages in thread
From: shihpo.hung @ 2020-01-15  6:17 UTC (permalink / raw)
  To: qemu-riscv
  Cc: Sagar Karandikar, Bastian Koppelmann, Richard Henderson,
	qemu-devel, Alistair Francis, Palmer Dabbelt, ShihPo Hung

remove the check becuase SD bit should summarize FS and XS fields
unconditionally.

Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/riscv/csr.c       | 3 +--
 target/riscv/translate.c | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index da02f9f..0e34c29 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -341,8 +341,7 @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val)
 
     mstatus = (mstatus & ~mask) | (val & mask);
 
-    dirty = (riscv_cpu_fp_enabled(env) &&
-             ((mstatus & MSTATUS_FS) == MSTATUS_FS)) |
+    dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) |
             ((mstatus & MSTATUS_XS) == MSTATUS_XS);
     mstatus = set_field(mstatus, MSTATUS_SD, dirty);
     env->mstatus = mstatus;
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index ab6a891..8e40ed3 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -394,7 +394,7 @@ static void mark_fs_dirty(DisasContext *ctx)
 
     tmp = tcg_temp_new();
     tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
-    tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS);
+    tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD);
     tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
     tcg_temp_free(tmp);
 }
-- 
2.7.4



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/3] target/riscv: Fix tb->flags FS status
  2020-01-15  6:17 [PATCH v3 1/3] target/riscv: Fix tb->flags FS status shihpo.hung
  2020-01-15  6:17 ` [PATCH v3 2/3] target/riscv: fsd/fsw doesn't dirty FP state shihpo.hung
  2020-01-15  6:17 ` [PATCH v3 3/3] target/riscv: update mstatus.SD when FS is set dirty shihpo.hung
@ 2020-01-15  6:28 ` Alistair Francis
  2020-01-15 14:27   ` ShihPo Hung
  2020-01-15 21:46   ` Richard Henderson
  2 siblings, 2 replies; 9+ messages in thread
From: Alistair Francis @ 2020-01-15  6:28 UTC (permalink / raw)
  To: shihpo.hung
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	Richard Henderson, qemu-devel@nongnu.org Developers,
	Alistair Francis, Palmer Dabbelt

On Wed, Jan 15, 2020 at 4:18 PM <shihpo.hung@sifive.com> wrote:
>
> It was found that running libquantum on riscv-linux qemu produced an
> incorrect result. After investigation, FP registers are not saved
> during context switch due to incorrect mstatus.FS.
>
> In current implementation tb->flags merges all non-disabled state to
> dirty. This means the code in mark_fs_dirty in translate.c that
> handles initial and clean states is unreachable.
>
> This patch fixes it and is successfully tested with:
>   libquantum
>
> Thanks to Richard for pointing out the actual bug.
>
> v3: remove the redundant condition
> v2: root cause FS problem
>
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  target/riscv/cpu.h | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index e59343e..de0a8d8 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -293,10 +293,7 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
>  #ifdef CONFIG_USER_ONLY
>      *flags = TB_FLAGS_MSTATUS_FS;
>  #else
> -    *flags = cpu_mmu_index(env, 0);
> -    if (riscv_cpu_fp_enabled(env)) {
> -        *flags |= TB_FLAGS_MSTATUS_FS;
> -    }
> +    *flags = cpu_mmu_index(env, 0) | (env->mstatus & MSTATUS_FS);

I don't think this is right, you should use the riscv_cpu_fp_enabled() function.

Right now it's the same as env->mstatus & MSTATUS_FS but when the
Hypervisor extension goes in riscv_cpu_fp_enabled() will be more
complex.

Alistair

>  #endif
>  }
>
> --
> 2.7.4
>
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 2/3] target/riscv: fsd/fsw doesn't dirty FP state
  2020-01-15  6:17 ` [PATCH v3 2/3] target/riscv: fsd/fsw doesn't dirty FP state shihpo.hung
@ 2020-01-15  6:29   ` Alistair Francis
  0 siblings, 0 replies; 9+ messages in thread
From: Alistair Francis @ 2020-01-15  6:29 UTC (permalink / raw)
  To: shihpo.hung
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	Richard Henderson, qemu-devel@nongnu.org Developers,
	Alistair Francis, Palmer Dabbelt

On Wed, Jan 15, 2020 at 4:18 PM <shihpo.hung@sifive.com> wrote:
>
> Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  target/riscv/insn_trans/trans_rvd.inc.c | 1 -
>  target/riscv/insn_trans/trans_rvf.inc.c | 1 -
>  2 files changed, 2 deletions(-)
>
> diff --git a/target/riscv/insn_trans/trans_rvd.inc.c b/target/riscv/insn_trans/trans_rvd.inc.c
> index 393fa02..ea1044f 100644
> --- a/target/riscv/insn_trans/trans_rvd.inc.c
> +++ b/target/riscv/insn_trans/trans_rvd.inc.c
> @@ -43,7 +43,6 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a)
>
>      tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], t0, ctx->mem_idx, MO_TEQ);
>
> -    mark_fs_dirty(ctx);
>      tcg_temp_free(t0);
>      return true;
>  }
> diff --git a/target/riscv/insn_trans/trans_rvf.inc.c b/target/riscv/insn_trans/trans_rvf.inc.c
> index 172dbfa..e23cd63 100644
> --- a/target/riscv/insn_trans/trans_rvf.inc.c
> +++ b/target/riscv/insn_trans/trans_rvf.inc.c
> @@ -52,7 +52,6 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a)
>      tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], t0, ctx->mem_idx, MO_TEUL);
>
>      tcg_temp_free(t0);
> -    mark_fs_dirty(ctx);
>      return true;
>  }
>
> --
> 2.7.4
>
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 3/3] target/riscv: update mstatus.SD when FS is set dirty
  2020-01-15  6:17 ` [PATCH v3 3/3] target/riscv: update mstatus.SD when FS is set dirty shihpo.hung
@ 2020-01-15  6:30   ` Alistair Francis
  0 siblings, 0 replies; 9+ messages in thread
From: Alistair Francis @ 2020-01-15  6:30 UTC (permalink / raw)
  To: shihpo.hung
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	Richard Henderson, qemu-devel@nongnu.org Developers,
	Alistair Francis, Palmer Dabbelt

On Wed, Jan 15, 2020 at 4:19 PM <shihpo.hung@sifive.com> wrote:
>
> remove the check becuase SD bit should summarize FS and XS fields
> unconditionally.
>
> Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  target/riscv/csr.c       | 3 +--
>  target/riscv/translate.c | 2 +-
>  2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index da02f9f..0e34c29 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -341,8 +341,7 @@ static int write_mstatus(CPURISCVState *env, int csrno, target_ulong val)
>
>      mstatus = (mstatus & ~mask) | (val & mask);
>
> -    dirty = (riscv_cpu_fp_enabled(env) &&
> -             ((mstatus & MSTATUS_FS) == MSTATUS_FS)) |
> +    dirty = ((mstatus & MSTATUS_FS) == MSTATUS_FS) |
>              ((mstatus & MSTATUS_XS) == MSTATUS_XS);
>      mstatus = set_field(mstatus, MSTATUS_SD, dirty);
>      env->mstatus = mstatus;
> diff --git a/target/riscv/translate.c b/target/riscv/translate.c
> index ab6a891..8e40ed3 100644
> --- a/target/riscv/translate.c
> +++ b/target/riscv/translate.c
> @@ -394,7 +394,7 @@ static void mark_fs_dirty(DisasContext *ctx)
>
>      tmp = tcg_temp_new();
>      tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
> -    tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS);
> +    tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD);
>      tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
>      tcg_temp_free(tmp);
>  }
> --
> 2.7.4
>
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/3] target/riscv: Fix tb->flags FS status
  2020-01-15  6:28 ` [PATCH v3 1/3] target/riscv: Fix tb->flags FS status Alistair Francis
@ 2020-01-15 14:27   ` ShihPo Hung
  2020-01-15 21:46   ` Richard Henderson
  1 sibling, 0 replies; 9+ messages in thread
From: ShihPo Hung @ 2020-01-15 14:27 UTC (permalink / raw)
  To: Alistair Francis
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	Richard Henderson, qemu-devel@nongnu.org Developers,
	Alistair Francis, Palmer Dabbelt

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

On Wed, Jan 15, 2020 at 2:29 PM Alistair Francis <alistair23@gmail.com>
wrote:

> > -    *flags = cpu_mmu_index(env, 0);
> > -    if (riscv_cpu_fp_enabled(env)) {
> > -        *flags |= TB_FLAGS_MSTATUS_FS;
> > -    }
> > +    *flags = cpu_mmu_index(env, 0) | (env->mstatus & MSTATUS_FS);
>
> I don't think this is right, you should use the riscv_cpu_fp_enabled()
> function.
>
> Right now it's the same as env->mstatus & MSTATUS_FS but when the
> Hypervisor extension goes in riscv_cpu_fp_enabled() will be more
> complex.
>
> Alistair
>
> I agree using riscv_cpu_fp_enabled() to hide the complexity when checking
FP,
but here I only duplicate the FP status (disabled/initial/clean/dirty) to
tb->flags
no matter FP is enabled or not.

Is it still necessary to check this before duplicating it?

I think it is not as long as TB_FLAGS_MSTATUS_FS is equivalent to
MSTATUS_FS.
But I don't know what changes hypervisor extension brings, please correct
me if I am wrong.

ShihPo

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

<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 15, 2020 at 2:29 PM Alistair Francis &lt;<a href="mailto:alistair23@gmail.com">alistair23@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">&gt; -    *flags = cpu_mmu_index(env, 0);<br>
&gt; -    if (riscv_cpu_fp_enabled(env)) {<br>
&gt; -        *flags |= TB_FLAGS_MSTATUS_FS;<br>
&gt; -    }<br>
&gt; +    *flags = cpu_mmu_index(env, 0) | (env-&gt;mstatus &amp; MSTATUS_FS);<br>
<br>
I don&#39;t think this is right, you should use the riscv_cpu_fp_enabled() function.<br>
<br>
Right now it&#39;s the same as env-&gt;mstatus &amp; MSTATUS_FS but when the<br>
Hypervisor extension goes in riscv_cpu_fp_enabled() will be more<br>
complex.<br>
<br>
Alistair<br><br></blockquote><div>I agree using riscv_cpu_fp_enabled() to hide the complexity when checking FP,</div><div>but here I only duplicate the FP status (disabled/initial/clean/dirty) to tb-&gt;flags</div><div>no matter FP is enabled or not.</div><div><br></div><div>Is it still necessary to check this before duplicating it?</div><div><br></div><div>I think it is not as long as TB_FLAGS_MSTATUS_FS is equivalent to MSTATUS_FS.</div><div>But I don&#39;t know what changes hypervisor extension brings, please correct me if I am wrong.</div><div><br></div><div>ShihPo</div><div><br></div></div></div>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/3] target/riscv: Fix tb->flags FS status
  2020-01-15  6:28 ` [PATCH v3 1/3] target/riscv: Fix tb->flags FS status Alistair Francis
  2020-01-15 14:27   ` ShihPo Hung
@ 2020-01-15 21:46   ` Richard Henderson
  2020-01-15 23:06     ` Alistair Francis
  1 sibling, 1 reply; 9+ messages in thread
From: Richard Henderson @ 2020-01-15 21:46 UTC (permalink / raw)
  To: Alistair Francis, shihpo.hung
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	qemu-devel@nongnu.org Developers, Alistair Francis,
	Palmer Dabbelt

On 1/14/20 8:28 PM, Alistair Francis wrote:
> On Wed, Jan 15, 2020 at 4:18 PM <shihpo.hung@sifive.com> wrote:
>>
>> It was found that running libquantum on riscv-linux qemu produced an
>> incorrect result. After investigation, FP registers are not saved
>> during context switch due to incorrect mstatus.FS.
>>
>> In current implementation tb->flags merges all non-disabled state to
>> dirty. This means the code in mark_fs_dirty in translate.c that
>> handles initial and clean states is unreachable.
>>
>> This patch fixes it and is successfully tested with:
>>   libquantum
>>
>> Thanks to Richard for pointing out the actual bug.
>>
>> v3: remove the redundant condition
>> v2: root cause FS problem
>>
>> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
>> Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>  target/riscv/cpu.h | 5 +----
>>  1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
>> index e59343e..de0a8d8 100644
>> --- a/target/riscv/cpu.h
>> +++ b/target/riscv/cpu.h
>> @@ -293,10 +293,7 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
>>  #ifdef CONFIG_USER_ONLY
>>      *flags = TB_FLAGS_MSTATUS_FS;
>>  #else
>> -    *flags = cpu_mmu_index(env, 0);
>> -    if (riscv_cpu_fp_enabled(env)) {
>> -        *flags |= TB_FLAGS_MSTATUS_FS;
>> -    }
>> +    *flags = cpu_mmu_index(env, 0) | (env->mstatus & MSTATUS_FS);
> 
> I don't think this is right, you should use the riscv_cpu_fp_enabled() function.
> 
> Right now it's the same as env->mstatus & MSTATUS_FS but when the
> Hypervisor extension goes in riscv_cpu_fp_enabled() will be more
> complex.

Hmm.  Are you sure something like

  flags |= riscv_cpu_effective_mstatus(env) & MSTATUS_FS;

wouldn't be more appropriate for the hypervisor extension?

I guess I should have another browse through your hv patchset, but I worry now
about bare uses of env->mstatus, if they no longer mean what they appear to mean.


r~


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 1/3] target/riscv: Fix tb->flags FS status
  2020-01-15 21:46   ` Richard Henderson
@ 2020-01-15 23:06     ` Alistair Francis
  0 siblings, 0 replies; 9+ messages in thread
From: Alistair Francis @ 2020-01-15 23:06 UTC (permalink / raw)
  To: Richard Henderson
  Cc: open list:RISC-V, Sagar Karandikar, Bastian Koppelmann,
	qemu-devel@nongnu.org Developers, Alistair Francis,
	Palmer Dabbelt, shihpo.hung

On Thu, Jan 16, 2020 at 7:46 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 1/14/20 8:28 PM, Alistair Francis wrote:
> > On Wed, Jan 15, 2020 at 4:18 PM <shihpo.hung@sifive.com> wrote:
> >>
> >> It was found that running libquantum on riscv-linux qemu produced an
> >> incorrect result. After investigation, FP registers are not saved
> >> during context switch due to incorrect mstatus.FS.
> >>
> >> In current implementation tb->flags merges all non-disabled state to
> >> dirty. This means the code in mark_fs_dirty in translate.c that
> >> handles initial and clean states is unreachable.
> >>
> >> This patch fixes it and is successfully tested with:
> >>   libquantum
> >>
> >> Thanks to Richard for pointing out the actual bug.
> >>
> >> v3: remove the redundant condition
> >> v2: root cause FS problem
> >>
> >> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> >> Signed-off-by: ShihPo Hung <shihpo.hung@sifive.com>
> >> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> >> ---
> >>  target/riscv/cpu.h | 5 +----
> >>  1 file changed, 1 insertion(+), 4 deletions(-)
> >>
> >> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> >> index e59343e..de0a8d8 100644
> >> --- a/target/riscv/cpu.h
> >> +++ b/target/riscv/cpu.h
> >> @@ -293,10 +293,7 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
> >>  #ifdef CONFIG_USER_ONLY
> >>      *flags = TB_FLAGS_MSTATUS_FS;
> >>  #else
> >> -    *flags = cpu_mmu_index(env, 0);
> >> -    if (riscv_cpu_fp_enabled(env)) {
> >> -        *flags |= TB_FLAGS_MSTATUS_FS;
> >> -    }
> >> +    *flags = cpu_mmu_index(env, 0) | (env->mstatus & MSTATUS_FS);
> >
> > I don't think this is right, you should use the riscv_cpu_fp_enabled() function.
> >
> > Right now it's the same as env->mstatus & MSTATUS_FS but when the
> > Hypervisor extension goes in riscv_cpu_fp_enabled() will be more
> > complex.
>
> Hmm.  Are you sure something like
>
>   flags |= riscv_cpu_effective_mstatus(env) & MSTATUS_FS;
>
> wouldn't be more appropriate for the hypervisor extension?

I was more thinking:

    if (riscv_cpu_fp_enabled(env)) {
        *flags |= env->mstatus & MSTATUS_FS;
    }

as floating point can be disabled from multiple places when we have
the H extension.

>
> I guess I should have another browse through your hv patchset, but I worry now
> about bare uses of env->mstatus, if they no longer mean what they appear to mean.

That was why this was all refacted in the first place as we now need
to check against env->vsstatus as well (depending on virt status).

Alistair

>
>
> r~


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15  6:17 [PATCH v3 1/3] target/riscv: Fix tb->flags FS status shihpo.hung
2020-01-15  6:17 ` [PATCH v3 2/3] target/riscv: fsd/fsw doesn't dirty FP state shihpo.hung
2020-01-15  6:29   ` Alistair Francis
2020-01-15  6:17 ` [PATCH v3 3/3] target/riscv: update mstatus.SD when FS is set dirty shihpo.hung
2020-01-15  6:30   ` Alistair Francis
2020-01-15  6:28 ` [PATCH v3 1/3] target/riscv: Fix tb->flags FS status Alistair Francis
2020-01-15 14:27   ` ShihPo Hung
2020-01-15 21:46   ` Richard Henderson
2020-01-15 23:06     ` Alistair Francis

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git