diff mbox series

target/ppc: Fix pmu_count_insns test in gen_lookup_and_goto_ptr

Message ID 20261104163854.87398-1-richard.henderson@linaro.org
State New
Headers show
Series target/ppc: Fix pmu_count_insns test in gen_lookup_and_goto_ptr | expand

Commit Message

Richard Henderson Nov. 4, 2026, 4:38 p.m. UTC
CF_NO_GOTO_PTR is in cflags, not flags.

Cc: qemu-stable@nongnu.org
Fixes: 46d396bde98 ("target/ppc: enable PMU instruction count")
Reported-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/ppc/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Matt Turner Nov. 4, 2026, 9:51 p.m. UTC | #1
On Wed, Nov 4, 2026 at 11:38 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
> CF_NO_GOTO_PTR is in cflags, not flags.
>
> Cc: qemu-stable@nongnu.org
> Fixes: 46d396bde98 ("target/ppc: enable PMU instruction count")
> Reported-by: Matt Turner <mattst88@gmail.com>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  target/ppc/translate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/ppc/translate.c b/target/ppc/translate.c
> index 467b8f3d4e..dfd09b66ff 100644
> --- a/target/ppc/translate.c
> +++ b/target/ppc/translate.c
> @@ -2645,7 +2645,7 @@ static void gen_lookup_and_goto_ptr(DisasContext *ctx)
>           * tcg_gen_lookup_and_goto_ptr will exit the TB if
>           * CF_NO_GOTO_PTR is set. Count insns now.
>           */
> -        if (ctx->base.tb->flags & CF_NO_GOTO_PTR) {
> +        if (ctx->base.tb->cflags & CF_NO_GOTO_PTR) {
>              pmu_count_insns(ctx);
>          }

The same check is in ppc_tr_tb_stop() under DISAS_CHAIN, from the
same commit. That one needs fixing too.

But I'm not sure the condition should be there at all. With the
correct flag, we only count when CF_NO_GOTO_PTR is set, which is
just cpu_exec_step_atomic() and gdb single-step. When goto_ptr
actually chains to the next TB, nothing counts the instructions in
this one, so PMC5 still comes up short for every TB that ends in an
indirect branch.

Counting before tcg_gen_lookup_and_goto_ptr() looks safe either way:
if the lookup fails we exit through the epilogue after the count has
been added. gen_goto_tb() already counts unconditionally before
goto_tb. So I think both sites should just be:

        pmu_count_insns(ctx);
        tcg_gen_lookup_and_goto_ptr();

For what it's worth, the old test checked bit 10 of hflags, which is
HFLAGS_SE. With that set, singlestep_flags is nonzero and we take the
gen_debug_exception() path first, so the count was never emitted in
either place.

Am I missing a reason for the conditional?
diff mbox series

Patch

diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index 467b8f3d4e..dfd09b66ff 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -2645,7 +2645,7 @@  static void gen_lookup_and_goto_ptr(DisasContext *ctx)
          * tcg_gen_lookup_and_goto_ptr will exit the TB if
          * CF_NO_GOTO_PTR is set. Count insns now.
          */
-        if (ctx->base.tb->flags & CF_NO_GOTO_PTR) {
+        if (ctx->base.tb->cflags & CF_NO_GOTO_PTR) {
             pmu_count_insns(ctx);
         }