Skip to contentSkip to conversation

RISC-V Patches for the 5.0 Soft Freeze, Part 1

GIT PULL Applied Palmer Dabbelt 2 participants 11 messages Jan 21, 2020 – Jan 27, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The following changes since commit 28b58f19d269633b3d14b6aebf1e92b3cd3ab56e:

ui/gtk: Get display refresh rate with GDK version 3.22 or later (2020-01-16 14:03:45 +0000)

are available in the Git repository at:

[email protected]:palmer-dabbelt/qemu.git tags/riscv-for-master-5.0-sf1

for you to fetch changes up to 82f014671cf057de51c4a577c9e2ad637dcec6f9:

target/riscv: update mstatus.SD when FS is set dirty (2020-01-16 10:03:15 -0800)

----------------------------------------------------------------
RISC-V Patches for the 5.0 Soft Freeze, Part 1

This patch set contains a handful of collected fixes that I'd like to target for the 5.0 soft freeze (I know that's a long way away, I just don't know what else to call these):

* A fix for a memory leak initializing the sifive_u board.
* Fixes to privilege mode emulation related to interrupts and fstatus.

Notably absent is the H extension implementation. That's pretty much reviewed, but not quite ready to go yet and I didn't want to hold back these important fixes. This boots 32-bit and 64-bit Linux (buildroot this time, just for fun) and passes "make check".

----------------------------------------------------------------
Pan Nengyuan (1):
riscv/sifive_u: fix a memory leak in soc_realize()

ShihPo Hung (3):
target/riscv: Fix tb->flags FS status target/riscv: fsd/fsw doesn't dirty FP state target/riscv: update mstatus.SD when FS is set dirty

Yiting Wang (1):
riscv: Set xPIE to 1 after xRET

 hw/riscv/sifive_u.c                     | 1 +
 target/riscv/cpu.h                      | 5 +----
 target/riscv/csr.c                      | 3 +--
 target/riscv/insn_trans/trans_rvd.inc.c | 1 -
 target/riscv/insn_trans/trans_rvf.inc.c | 1 -
 target/riscv/op_helper.c                | 4 ++--
 target/riscv/translate.c                | 2 +-
 7 files changed, 6 insertions(+), 11 deletions(-)
#1 lore raw

[PULL 1/5] riscv/sifive_u: fix a memory leak in soc_realize()

From: Pan Nengyuan <[email protected]>

Fix a minor memory leak in riscv_sifive_u_soc_realize()

---
 hw/riscv/sifive_u.c | 1 +
 1 file changed, 1 insertion(+)
hw/riscv/sifive_u.c +1 -0
index 0140e95732..0e12b3ccef 100644
@@ -542,6 +542,7 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)
         SIFIVE_U_PLIC_CONTEXT_BASE,
         SIFIVE_U_PLIC_CONTEXT_STRIDE,
         memmap[SIFIVE_U_PLIC].size);
+    g_free(plic_hart_config);
     sifive_uart_create(system_memory, memmap[SIFIVE_U_UART0].base,
         serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART0_IRQ));
     sifive_uart_create(system_memory, memmap[SIFIVE_U_UART1].base,
Signature · 1 line
2.25.0.341.g760bfbb309-goog
#2 lore raw

[PULL 2/5] riscv: Set xPIE to 1 after xRET

In reply to Palmer Dabbelt

From: Yiting Wang <[email protected]>

When executing an xRET instruction, supposing xPP holds the value y, xIE is set to xPIE; the privilege mode is changed to y; xPIE is set to 1. But QEMU sets xPIE to 0 incorrectly.

---
 target/riscv/op_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/op_helper.c +2 -2
index 331cc36232..e87c9115bc 100644
@@ -93,7 +93,7 @@ target_ulong helper_sret(CPURISCVState *env, target_ulong cpu_pc_deb)
         env->priv_ver >= PRIV_VERSION_1_10_0 ?
         MSTATUS_SIE : MSTATUS_UIE << prev_priv,
         get_field(mstatus, MSTATUS_SPIE));
-    mstatus = set_field(mstatus, MSTATUS_SPIE, 0);
+    mstatus = set_field(mstatus, MSTATUS_SPIE, 1);
     mstatus = set_field(mstatus, MSTATUS_SPP, PRV_U);
     riscv_cpu_set_mode(env, prev_priv);
     env->mstatus = mstatus;
@@ -118,7 +118,7 @@ target_ulong helper_mret(CPURISCVState *env, target_ulong cpu_pc_deb)
         env->priv_ver >= PRIV_VERSION_1_10_0 ?
         MSTATUS_MIE : MSTATUS_UIE << prev_priv,
         get_field(mstatus, MSTATUS_MPIE));
-    mstatus = set_field(mstatus, MSTATUS_MPIE, 0);
+    mstatus = set_field(mstatus, MSTATUS_MPIE, 1);
     mstatus = set_field(mstatus, MSTATUS_MPP, PRV_U);
     riscv_cpu_set_mode(env, prev_priv);
     env->mstatus = mstatus;
Signature · 1 line
2.25.0.341.g760bfbb309-goog
#3 lore raw

[PULL 3/5] target/riscv: Fix tb->flags FS status

In reply to Palmer Dabbelt

From: ShihPo Hung <[email protected]>

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

---
 target/riscv/cpu.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
target/riscv/cpu.h +1 -4
index e59343e13c..de0a8d893a 100644
@@ -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
 }
 
Signature · 1 line
2.25.0.341.g760bfbb309-goog
#4 lore raw

[PULL 4/5] target/riscv: fsd/fsw doesn't dirty FP state

In reply to Palmer Dabbelt

From: ShihPo Hung <[email protected]>

---
 target/riscv/insn_trans/trans_rvd.inc.c | 1 -
 target/riscv/insn_trans/trans_rvf.inc.c | 1 -
 2 files changed, 2 deletions(-)
target/riscv/insn_trans/trans_rvd.inc.c +0 -1
index 393fa0248c..ea1044f13b 100644
@@ -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;
 }
target/riscv/insn_trans/trans_rvf.inc.c +0 -1
index 172dbfa919..e23cd639a6 100644
@@ -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;
 }
 
Signature · 1 line
2.25.0.341.g760bfbb309-goog
#5 lore raw

[PULL 5/5] target/riscv: update mstatus.SD when FS is set dirty

In reply to Palmer Dabbelt

From: ShihPo Hung <[email protected]>

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

---
 target/riscv/csr.c       | 3 +--
 target/riscv/translate.c | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
target/riscv/csr.c +1 -2
index da02f9f0b1..0e34c292c5 100644
@@ -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;
target/riscv/translate.c +1 -1
index ab6a891dc3..8e40ed3ac4 100644
@@ -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);
 }
Signature · 1 line
2.25.0.341.g760bfbb309-goog
#6 lore raw
In reply to Palmer Dabbelt
Quoted 20 lines · Palmer Dabbelt

The following changes since commit 28b58f19d269633b3d14b6aebf1e92b3cd3ab56e:

ui/gtk: Get display refresh rate with GDK version 3.22 or later (2020-01-16 14:03:45 +0000)

are available in the Git repository at:

[email protected]:palmer-dabbelt/qemu.git tags/riscv-for-master-5.0-sf1

for you to fetch changes up to 82f014671cf057de51c4a577c9e2ad637dcec6f9:

target/riscv: update mstatus.SD when FS is set dirty (2020-01-16 10:03:15 -0800)

----------------------------------------------------------------
RISC-V Patches for the 5.0 Soft Freeze, Part 1

This patch set contains a handful of collected fixes that I'd like to target for the 5.0 soft freeze (I know that's a long way away, I just don't know what else to call these):

Quoted 7 lines

* A fix for a memory leak initializing the sifive_u board.
* Fixes to privilege mode emulation related to interrupts and fstatus.

Notably absent is the H extension implementation. That's pretty much reviewed, but not quite ready to go yet and I didn't want to hold back these important fixes. This boots 32-bit and 64-bit Linux (buildroot this time, just for fun) and passes "make check".

Hi. This pull request doesn't seem to be signed with the GPG key that I have on record for you...

thanks
-- PMM

#7 lore raw
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Palmer Dabbelt

The following changes since commit 28b58f19d269633b3d14b6aebf1e92b3cd3ab56e:

ui/gtk: Get display refresh rate with GDK version 3.22 or later (2020-01-16 14:03:45 +0000)

are available in the Git repository at:

[email protected]:palmer-dabbelt/qemu.git tags/riscv-for-master-5.0-sf1

for you to fetch changes up to 82f014671cf057de51c4a577c9e2ad637dcec6f9:

target/riscv: update mstatus.SD when FS is set dirty (2020-01-16 10:03:15 -0800)

----------------------------------------------------------------
RISC-V Patches for the 5.0 Soft Freeze, Part 1

This patch set contains a handful of collected fixes that I'd like to target for the 5.0 soft freeze (I know that's a long way away, I just don't know what else to call these):

* A fix for a memory leak initializing the sifive_u board.
* Fixes to privilege mode emulation related to interrupts and fstatus.

Quoted 7 lines
Quoted 4 lines

Notably absent is the H extension implementation. That's pretty much reviewed, but not quite ready to go yet and I didn't want to hold back these important fixes. This boots 32-bit and 64-bit Linux (buildroot this time, just for fun) and passes "make check".

Hi. This pull request doesn't seem to be signed with the GPG key that I have on record for you...

When I moved to Google I got a Yubikey and made new subkeys for it. If I understand correctly the new subkeys should be signed by my main key, but maybe that didn't make it to your keyring? I see

   $ gpg --list-keys [email protected]
   pub   rsa4096 2017-06-06 [SC] [expires: 2027-11-13]
         00CE76D1834960DFCE886DF8EF4CA1502CCBAB41
   uid           [ultimate] Palmer Dabbelt <[email protected]>
   uid           [ultimate] Palmer Dabbelt <[email protected]>
   sub   rsa4096 2017-06-06 [E]
   sub   rsa4096 2019-11-26 [S] [expires: 2024-11-24]
   sub   rsa4096 2019-11-26 [A] [expires: 2024-11-24]
   sub   rsa4096 2019-11-26 [E] [expires: 2024-11-24]

I have the master key at home, so if I didn't do this right I can re-spin things tonight.

Quoted 3 lines

thanks
-- PMM

#8 lore raw
Quoted 8 lines · Palmer Dabbelt
Quoted 2 lines · Peter Maydell

Hi. This pull request doesn't seem to be signed with the GPG key that I have on record for you...

When I moved to Google I got a Yubikey and made new subkeys for it. If I understand correctly the new subkeys should be signed by my main key, but maybe that didn't make it to your keyring? I see

Quoted 9 lines
    $ gpg --list-keys [email protected]
    pub   rsa4096 2017-06-06 [SC] [expires: 2027-11-13]
          00CE76D1834960DFCE886DF8EF4CA1502CCBAB41
    uid           [ultimate] Palmer Dabbelt <[email protected]>
    uid           [ultimate] Palmer Dabbelt <[email protected]>
    sub   rsa4096 2017-06-06 [E]
    sub   rsa4096 2019-11-26 [S] [expires: 2024-11-24]
    sub   rsa4096 2019-11-26 [A] [expires: 2024-11-24]
    sub   rsa4096 2019-11-26 [E] [expires: 2024-11-24]

Yeah, I have those. I think I must have fumbled something when I retried the pullreq after doing a refresh of your gpg key, because I just did a retry now and it's fine. (I'm just running the pull through my tests now.)

thanks
-- PMM

#9 lore raw
Quoted 19 lines · Peter Maydell
Quoted 8 lines · Palmer Dabbelt
Quoted 2 lines · Peter Maydell

Hi. This pull request doesn't seem to be signed with the GPG key that I have on record for you...

When I moved to Google I got a Yubikey and made new subkeys for it. If I understand correctly the new subkeys should be signed by my main key, but maybe that didn't make it to your keyring? I see

Quoted 9 lines
    $ gpg --list-keys [email protected]
    pub   rsa4096 2017-06-06 [SC] [expires: 2027-11-13]
          00CE76D1834960DFCE886DF8EF4CA1502CCBAB41
    uid           [ultimate] Palmer Dabbelt <[email protected]>
    uid           [ultimate] Palmer Dabbelt <[email protected]>
    sub   rsa4096 2017-06-06 [E]
    sub   rsa4096 2019-11-26 [S] [expires: 2024-11-24]
    sub   rsa4096 2019-11-26 [A] [expires: 2024-11-24]
    sub   rsa4096 2019-11-26 [E] [expires: 2024-11-24]
Quoted 4 lines

Yeah, I have those. I think I must have fumbled something when I retried the pullreq after doing a refresh of your gpg key, because I just did a retry now and it's fine. (I'm just running the pull through my tests now.)

Thanks!

#10 lore raw
In reply to Palmer Dabbelt
Quoted 32 lines · Palmer Dabbelt

The following changes since commit 28b58f19d269633b3d14b6aebf1e92b3cd3ab56e:

ui/gtk: Get display refresh rate with GDK version 3.22 or later (2020-01-16 14:03:45 +0000)

are available in the Git repository at:

[email protected]:palmer-dabbelt/qemu.git tags/riscv-for-master-5.0-sf1

for you to fetch changes up to 82f014671cf057de51c4a577c9e2ad637dcec6f9:

target/riscv: update mstatus.SD when FS is set dirty (2020-01-16 10:03:15 -0800)

----------------------------------------------------------------
RISC-V Patches for the 5.0 Soft Freeze, Part 1

This patch set contains a handful of collected fixes that I'd like to target for the 5.0 soft freeze (I know that's a long way away, I just don't know what else to call these):

* A fix for a memory leak initializing the sifive_u board.
* Fixes to privilege mode emulation related to interrupts and fstatus.

Notably absent is the H extension implementation. That's pretty much reviewed, but not quite ready to go yet and I didn't want to hold back these important fixes. This boots 32-bit and 64-bit Linux (buildroot this time, just for fun) and passes "make check".

----------------------------------------------------------------
Pan Nengyuan (1):
riscv/sifive_u: fix a memory leak in soc_realize()

Quoted 8 lines

ShihPo Hung (3):
target/riscv: Fix tb->flags FS status target/riscv: fsd/fsw doesn't dirty FP state target/riscv: update mstatus.SD when FS is set dirty

Yiting Wang (1):
riscv: Set xPIE to 1 after xRET

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.0
for any user-visible changes.

-- PMM