All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target/riscv: fix invalid sstc predicate in gdbstub
@ 2026-05-30  5:32 Abhigyan Kumar
  2026-05-31 20:21 ` Daniel Henrique Barboza
  2026-08-14 13:12 ` abh
  0 siblings, 2 replies; 3+ messages in thread
From: Abhigyan Kumar @ 2026-05-30  5:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, Alistair Francis, Weiwei Li, Daniel Henrique Barboza,
	Liu Zhiwei, Chao Liu, Palmer Dabbelt, Abhigyan Kumar

sstc function incorrectly checks for avaibility of env->rdtime_fn.
This causes it to fail each time it's called because rdtime_fn is setup
later in the procedure (when timer devices are created). This prevents
stimecmp's addition to gdb.

This change ensures only the riscv_cpu_cfg(env) check is done. rdtime_fn
will always be NULL otherwise and fail.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
Signed-off-by: Abhigyan Kumar <314abh@gmail.com>
---
 target/riscv/csr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index f5b0895fd..d72df945f 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -590,7 +590,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;
     }
 
-- 
2.54.0



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

* Re: [PATCH] target/riscv: fix invalid sstc predicate in gdbstub
  2026-05-30  5:32 [PATCH] target/riscv: fix invalid sstc predicate in gdbstub Abhigyan Kumar
@ 2026-05-31 20:21 ` Daniel Henrique Barboza
  2026-08-14 13:12 ` abh
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Henrique Barboza @ 2026-05-31 20:21 UTC (permalink / raw)
  To: Abhigyan Kumar, qemu-devel
  Cc: qemu-riscv, Alistair Francis, Weiwei Li, Liu Zhiwei, Chao Liu,
	Palmer Dabbelt



On 5/30/2026 2:32 AM, Abhigyan Kumar wrote:
> sstc function incorrectly checks for avaibility of env->rdtime_fn.
> This causes it to fail each time it's called because rdtime_fn is setup
> later in the procedure (when timer devices are created). This prevents
> stimecmp's addition to gdb.
> 
> This change ensures only the riscv_cpu_cfg(env) check is done. rdtime_fn
> will always be NULL otherwise and fail.

I am not sure we can do that - there are several boards that don't create
the timer that implements rdtime_fn (e.g. spike).  If we just remove the
check we'll break the sstc check for them.

I suggest using the 'env->debugger' flag to skip the rdtimer check if
we're running the gdbstub:

$ git diff
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 5514e0f455..63f4795ac7 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -590,7 +590,8 @@ 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
+        || (!env->debugger && !env->rdtime_fn)) {
          return RISCV_EXCP_ILLEGAL_INST;
      }

Testing with gitlab 3496 this seems to work:


$ riscv64-unknown-elf-gdb
(gdb) target extended-remote :1234
(gdb)  p $stimecmp
$1 = 0
(gdb)


Thanks,
Daniel

> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
> Signed-off-by: Abhigyan Kumar <314abh@gmail.com>
> ---
>   target/riscv/csr.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index f5b0895fd..d72df945f 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -590,7 +590,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;
>       }
>   



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

* Re: [PATCH] target/riscv: fix invalid sstc predicate in gdbstub
  2026-05-30  5:32 [PATCH] target/riscv: fix invalid sstc predicate in gdbstub Abhigyan Kumar
  2026-05-31 20:21 ` Daniel Henrique Barboza
@ 2026-08-14 13:12 ` abh
  1 sibling, 0 replies; 3+ messages in thread
From: abh @ 2026-08-14 13:12 UTC (permalink / raw)
  To: qemu-riscv
  Cc: alistair.francis, palmer, liwei1518, daniel.barboza, zhiwei_liu,
	chao.liu, qemu-devel

On 5/30/26 11:02 AM, Abhigyan Kumar wrote:
> sstc function incorrectly checks for avaibility of env->rdtime_fn.
> This causes it to fail each time it's called because rdtime_fn is setup
> later in the procedure (when timer devices are created). This prevents
> stimecmp's addition to gdb.
> 
> This change ensures only the riscv_cpu_cfg(env) check is done. rdtime_fn
> will always be NULL otherwise and fail.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3496
> Signed-off-by: Abhigyan Kumar <314abh@gmail.com>
> ---
>   target/riscv/csr.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/riscv/csr.c b/target/riscv/csr.c
> index f5b0895fd..d72df945f 100644
> --- a/target/riscv/csr.c
> +++ b/target/riscv/csr.c
> @@ -590,7 +590,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;
>       }
>   

Greetings. It has been over two and a half months since I submitted this 
patch. It's my humble request to know the status of the 
review/acceptance for my patch. Please inform me about any required amends.

Thank you for your patience and attention.

-- 
Abhigyan Kumar


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

end of thread, other threads:[~2026-08-14 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-30  5:32 [PATCH] target/riscv: fix invalid sstc predicate in gdbstub Abhigyan Kumar
2026-05-31 20:21 ` Daniel Henrique Barboza
2026-08-14 13:12 ` abh

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.