[PATCH] target/riscv: Do not hide Sstc CSRs from gdbstub

Zephyr Li posted 1 patch 5 days, 14 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260525024220.39027-1-fritchleybohrer@gmail.com
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu.zevorn@gmail.com>
target/riscv/csr.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] target/riscv: Do not hide Sstc CSRs from gdbstub
Posted by Zephyr Li 5 days, 14 hours ago
The Sstc predicate currently checks both ext_sstc and rdtime_fn. This
causes the gdbstub CSR XML generation to skip Sstc CSRs when rdtime_fn
has not been initialized yet, even if the CPU supports Sstc.

As a result, GDB reports $stimecmp as void with a CPU that exposes the
sstc extension.

Only use ext_sstc for the early existence check, and keep the rdtime_fn
check for non-debugger accesses.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
Signed-off-by: Zephyr Li <fritchleybohrer@gmail.com>
---

Testing:
    Start QEMU with:
        qemu-system-riscv64 -M virt,aclint=on -cpu max,sstc=true -s -S -nographic

    Before:
        (gdb) p $stimecmp
        $1 = void

    After:
        (gdb) p $stimecmp
        $1 = 0

 target/riscv/csr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index da366cf562..c17df147f7 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -586,7 +586,7 @@ static RISCVException sstc(CPURISCVState *env, int csrno)
 {
     bool hmode_check = false;
 
-    if (!riscv_cpu_cfg(env)->ext_sstc || !env->rdtime_fn) {
+    if (!riscv_cpu_cfg(env)->ext_sstc) {
         return RISCV_EXCP_ILLEGAL_INST;
     }
 
@@ -603,6 +603,10 @@ static RISCVException sstc(CPURISCVState *env, int csrno)
         return RISCV_EXCP_NONE;
     }
 
+    if (!env->rdtime_fn) {
+        return RISCV_EXCP_ILLEGAL_INST;
+    }
+
     if (env->priv == PRV_M) {
         return RISCV_EXCP_NONE;
     }
-- 
2.43.0
Re: [PATCH] target/riscv: Do not hide Sstc CSRs from gdbstub
Posted by Alistair Francis 3 days, 16 hours ago
On Mon, 2026-05-25 at 10:42 +0800, Zephyr Li wrote:
> The Sstc predicate currently checks both ext_sstc and rdtime_fn. This
> causes the gdbstub CSR XML generation to skip Sstc CSRs when
> rdtime_fn
> has not been initialized yet, even if the CPU supports Sstc.
> 
> As a result, GDB reports $stimecmp as void with a CPU that exposes
> the
> sstc extension.
> 
> Only use ext_sstc for the early existence check, and keep the
> rdtime_fn
> check for non-debugger accesses.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
> Signed-off-by: Zephyr Li <fritchleybohrer@gmail.com>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
> 
> Testing:
>     Start QEMU with:
>         qemu-system-riscv64 -M virt,aclint=on -cpu max,sstc=true -s -
> S -nographic
> 
>     Before:
>         (gdb) p $stimecmp
>         $1 = void
> 
>     After:
>         (gdb) p $stimecmp
>         $1 = 0
> 
>  target/riscv/csr.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index da366cf562..c17df147f7 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -586,7 +586,7 @@ static RISCVException sstc(CPURISCVState *env,
> int csrno)
>  {
>      bool hmode_check = false;
>  
> -    if (!riscv_cpu_cfg(env)->ext_sstc || !env->rdtime_fn) {
> +    if (!riscv_cpu_cfg(env)->ext_sstc) {
>          return RISCV_EXCP_ILLEGAL_INST;
>      }
>  
> @@ -603,6 +603,10 @@ static RISCVException sstc(CPURISCVState *env,
> int csrno)
>          return RISCV_EXCP_NONE;
>      }
>  
> +    if (!env->rdtime_fn) {
> +        return RISCV_EXCP_ILLEGAL_INST;
> +    }
> +
>      if (env->priv == PRV_M) {
>          return RISCV_EXCP_NONE;
>      }
Re: [PATCH] target/riscv: Do not hide Sstc CSRs from gdbstub
Posted by Alistair Francis 3 days, 16 hours ago
On Mon, 2026-05-25 at 10:42 +0800, Zephyr Li wrote:
> The Sstc predicate currently checks both ext_sstc and rdtime_fn. This
> causes the gdbstub CSR XML generation to skip Sstc CSRs when
> rdtime_fn
> has not been initialized yet, even if the CPU supports Sstc.
> 
> As a result, GDB reports $stimecmp as void with a CPU that exposes
> the
> sstc extension.
> 
> Only use ext_sstc for the early existence check, and keep the
> rdtime_fn
> check for non-debugger accesses.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
> Signed-off-by: Zephyr Li <fritchleybohrer@gmail.com>

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

Alistair

> ---
> 
> Testing:
>     Start QEMU with:
>         qemu-system-riscv64 -M virt,aclint=on -cpu max,sstc=true -s -
> S -nographic
> 
>     Before:
>         (gdb) p $stimecmp
>         $1 = void
> 
>     After:
>         (gdb) p $stimecmp
>         $1 = 0
> 
>  target/riscv/csr.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index da366cf562..c17df147f7 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -586,7 +586,7 @@ static RISCVException sstc(CPURISCVState *env,
> int csrno)
>  {
>      bool hmode_check = false;
>  
> -    if (!riscv_cpu_cfg(env)->ext_sstc || !env->rdtime_fn) {
> +    if (!riscv_cpu_cfg(env)->ext_sstc) {
>          return RISCV_EXCP_ILLEGAL_INST;
>      }
>  
> @@ -603,6 +603,10 @@ static RISCVException sstc(CPURISCVState *env,
> int csrno)
>          return RISCV_EXCP_NONE;
>      }
>  
> +    if (!env->rdtime_fn) {
> +        return RISCV_EXCP_ILLEGAL_INST;
> +    }
> +
>      if (env->priv == PRV_M) {
>          return RISCV_EXCP_NONE;
>      }
Re: [PATCH] target/riscv: Do not hide Sstc CSRs from gdbstub
Posted by Chao Liu 5 days, 12 hours ago
On Mon, May 25, 2026 at 10:42:20AM +0800, Zephyr Li wrote:
> The Sstc predicate currently checks both ext_sstc and rdtime_fn. This
> causes the gdbstub CSR XML generation to skip Sstc CSRs when rdtime_fn
> has not been initialized yet, even if the CPU supports Sstc.
> 
> As a result, GDB reports $stimecmp as void with a CPU that exposes the
> sstc extension.
> 
> Only use ext_sstc for the early existence check, and keep the rdtime_fn
> check for non-debugger accesses.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
> Signed-off-by: Zephyr Li <fritchleybohrer@gmail.com>

Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>

> ---
> 
> Testing:
>     Start QEMU with:
>         qemu-system-riscv64 -M virt,aclint=on -cpu max,sstc=true -s -S -nographic
> 
>     Before:
>         (gdb) p $stimecmp
>         $1 = void
> 
>     After:
>         (gdb) p $stimecmp
>         $1 = 0
> 
>  target/riscv/csr.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index da366cf562..c17df147f7 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -586,7 +586,7 @@ static RISCVException sstc(CPURISCVState *env, int csrno)
>  {
>      bool hmode_check = false;
>  
> -    if (!riscv_cpu_cfg(env)->ext_sstc || !env->rdtime_fn) {
> +    if (!riscv_cpu_cfg(env)->ext_sstc) {
>          return RISCV_EXCP_ILLEGAL_INST;
>      }
>  
> @@ -603,6 +603,10 @@ static RISCVException sstc(CPURISCVState *env, int csrno)
>          return RISCV_EXCP_NONE;
>      }
>  
> +    if (!env->rdtime_fn) {
> +        return RISCV_EXCP_ILLEGAL_INST;
> +    }
> +
>      if (env->priv == PRV_M) {
>          return RISCV_EXCP_NONE;
>      }
> -- 
> 2.43.0
>