[PATCH] accel/tcg/cpu-exec.c: Fix false awakening of gdb

Aleksandr Sergeev posted 1 patch 3 weeks, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261028072308.839836-1-al.sergeev@syntacore.com
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>
accel/tcg/cpu-exec.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
[PATCH] accel/tcg/cpu-exec.c: Fix false awakening of gdb
Posted by Aleksandr Sergeev 3 weeks, 4 days ago
From: Aleksandr Sergeev <sergeev0xef@gmail.com>

In qemu there is a mechanism to cancel execution of tb.
If `cpu->neg.icount_decr` is <0, translation block
will exit in prolog.
E.g. such may happen when RCU thread kicks out vCPU.

If tb is not executed, we shall not raise EXCP_DEBUG,
because no step actually happened.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4766
Signed-off-by: Aleksandr Sergeev <sergeev0xef@gmail.com>
---
 accel/tcg/cpu-exec.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 9ead35418d..4497701486 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -478,16 +478,16 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
                          last_tb->tc.ptr, pc, lookup_symbol(pc));
             }
         }
-    }
-
-    /*
-     * If gdb single-step, and we haven't raised another exception,
-     * raise a debug exception.  Single-step with another exception
-     * is handled in cpu_handle_exception.
-     */
-    if (unlikely(cpu_single_stepping(cpu)) && cpu->exception_index == -1) {
-        cpu->exception_index = EXCP_DEBUG;
-        cpu_loop_exit(cpu);
+    } else {
+        /*
+         * If gdb single-step, and we haven't raised another exception,
+         * raise a debug exception.  Single-step with another exception
+         * is handled in cpu_handle_exception.
+         */
+        if (unlikely(cpu_single_stepping(cpu)) && cpu->exception_index == -1) {
+            cpu->exception_index = EXCP_DEBUG;
+            cpu_loop_exit(cpu);
+        }
     }
 
     return last_tb;
-- 
2.55.0
Re: [PATCH] accel/tcg/cpu-exec.c: Fix false awakening of gdb
Posted by Richard Henderson 3 weeks, 4 days ago
On 10/28/26 02:23, Aleksandr Sergeev wrote:
> From: Aleksandr Sergeev <sergeev0xef@gmail.com>
> 
> In qemu there is a mechanism to cancel execution of tb.
> If `cpu->neg.icount_decr` is <0, translation block
> will exit in prolog.
> E.g. such may happen when RCU thread kicks out vCPU.
> 
> If tb is not executed, we shall not raise EXCP_DEBUG,
> because no step actually happened.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4766
> Signed-off-by: Aleksandr Sergeev <sergeev0xef@gmail.com>
> ---
>   accel/tcg/cpu-exec.c | 20 ++++++++++----------
>   1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
> index 9ead35418d..4497701486 100644
> --- a/accel/tcg/cpu-exec.c
> +++ b/accel/tcg/cpu-exec.c
> @@ -478,16 +478,16 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
>                            last_tb->tc.ptr, pc, lookup_symbol(pc));
>               }
>           }
> -    }
> -
> -    /*
> -     * If gdb single-step, and we haven't raised another exception,
> -     * raise a debug exception.  Single-step with another exception
> -     * is handled in cpu_handle_exception.
> -     */
> -    if (unlikely(cpu_single_stepping(cpu)) && cpu->exception_index == -1) {
> -        cpu->exception_index = EXCP_DEBUG;
> -        cpu_loop_exit(cpu);
> +    } else {
> +        /*
> +         * If gdb single-step, and we haven't raised another exception,
> +         * raise a debug exception.  Single-step with another exception
> +         * is handled in cpu_handle_exception.
> +         */
> +        if (unlikely(cpu_single_stepping(cpu)) && cpu->exception_index == -1) {
> +            cpu->exception_index = EXCP_DEBUG;
> +            cpu_loop_exit(cpu);
> +        }
>       }
>   
>       return last_tb;

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

And queued to tcg-next.

r~