qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-devel@nongnu.org,  pierrick.bouvier@linaro.org
Subject: Re: [PATCH 2/7] accel/tcg: Set CPUState.plugin_ra before all plugin callbacks
Date: Fri, 31 May 2024 17:46:22 +0100	[thread overview]
Message-ID: <8734pyaq01.fsf@draig.linaro.org> (raw)
In-Reply-To: <20240416040609.1313605-3-richard.henderson@linaro.org> (Richard Henderson's message of "Mon, 15 Apr 2024 21:06:04 -0700")

Richard Henderson <richard.henderson@linaro.org> writes:

We really could do with a description of why we are setting plugin_ra
and what we mean to achieve by it. I think it is so we can then do the
same PC/other register recovery as we do at synchronous faulting
exceptions be it generated TCG code or a helper. However we should make
that clear in the commit (and possible some function comments).


> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  include/hw/core/cpu.h  |  1 +
>  accel/tcg/plugin-gen.c | 50 +++++++++++++++++++++++++++++++++++++-----
>  2 files changed, 46 insertions(+), 5 deletions(-)
>
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 10cd492aff..f4af37c13d 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -350,6 +350,7 @@ typedef union IcountDecr {
>  typedef struct CPUNegativeOffsetState {
>      CPUTLB tlb;
>  #ifdef CONFIG_PLUGIN
> +    uintptr_t plugin_ra;
>      GArray *plugin_mem_cbs;
>  #endif
>      IcountDecr icount_decr;
> diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
> index 36e9134a5d..f96b49cce6 100644
> --- a/accel/tcg/plugin-gen.c
> +++ b/accel/tcg/plugin-gen.c
> @@ -37,6 +37,12 @@ enum plugin_gen_from {
>      PLUGIN_GEN_AFTER_TB,
>  };
>  
> +enum plugin_gen_ra {
> +    GEN_RA_DONE,
> +    GEN_RA_FROM_TB,
> +    GEN_RA_FROM_INSN,
> +};
> +
>  /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */
>  void plugin_gen_disable_mem_helpers(void)
>  {
> @@ -151,11 +157,38 @@ static void gen_mem_cb(struct qemu_plugin_dyn_cb *cb,
>      tcg_temp_free_i32(cpu_index);
>  }
>  
> -static void inject_cb(struct qemu_plugin_dyn_cb *cb)
> +static void inject_ra(enum plugin_gen_ra *gen_ra)
> +{
> +    TCGv_ptr ra;
> +
> +    switch (*gen_ra) {
> +    case GEN_RA_DONE:
> +        return;
> +    case GEN_RA_FROM_TB:
> +        ra = tcg_constant_ptr(NULL);
> +        break;
> +    case GEN_RA_FROM_INSN:
> +        ra = tcg_temp_ebb_new_ptr();
> +        tcg_gen_plugin_pc(ra);
> +        break;
> +    default:
> +        g_assert_not_reached();
> +    }
> +
> +    tcg_gen_st_ptr(ra, tcg_env,
> +                   offsetof(CPUState, neg.plugin_ra) -
> +                   offsetof(ArchCPU, env));
> +    tcg_temp_free_ptr(ra);
> +    *gen_ra = GEN_RA_DONE;
> +}
> +
> +static void inject_cb(struct qemu_plugin_dyn_cb *cb,
> +                      enum plugin_gen_ra *gen_ra)
>  
>  {
>      switch (cb->type) {
>      case PLUGIN_CB_REGULAR:
> +        inject_ra(gen_ra);
>          gen_udata_cb(cb);
>          break;
>      case PLUGIN_CB_INLINE:
> @@ -167,16 +200,18 @@ static void inject_cb(struct qemu_plugin_dyn_cb *cb)
>  }
>  
>  static void inject_mem_cb(struct qemu_plugin_dyn_cb *cb,
> +                          enum plugin_gen_ra *gen_ra,
>                            enum qemu_plugin_mem_rw rw,
>                            qemu_plugin_meminfo_t meminfo, TCGv_i64 addr)
>  {
>      if (cb->rw & rw) {
>          switch (cb->type) {
>          case PLUGIN_CB_MEM_REGULAR:
> +            inject_ra(gen_ra);
>              gen_mem_cb(cb, meminfo, addr);
>              break;
>          default:
> -            inject_cb(cb);
> +            inject_cb(cb, gen_ra);
>              break;
>          }
>      }
> @@ -186,6 +221,7 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
>  {
>      TCGOp *op, *next;
>      int insn_idx = -1;
> +    enum plugin_gen_ra gen_ra;
>  
>      if (unlikely(qemu_loglevel_mask(LOG_TB_OP_PLUGIN)
>                   && qemu_log_in_addr_range(plugin_tb->vaddr))) {
> @@ -205,10 +241,12 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
>       */
>      memset(tcg_ctx->free_temps, 0, sizeof(tcg_ctx->free_temps));
>  
> +    gen_ra = GEN_RA_FROM_TB;
>      QTAILQ_FOREACH_SAFE(op, &tcg_ctx->ops, link, next) {
>          switch (op->opc) {
>          case INDEX_op_insn_start:
>              insn_idx++;
> +            gen_ra = GEN_RA_FROM_INSN;
>              break;
>  
>          case INDEX_op_plugin_cb:
> @@ -244,7 +282,8 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
>                  cbs = plugin_tb->cbs;
>                  for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
>                      inject_cb(
> -                        &g_array_index(cbs, struct qemu_plugin_dyn_cb, i));
> +                        &g_array_index(cbs, struct qemu_plugin_dyn_cb, i),
> +                        &gen_ra);
>                  }
>                  break;
>  
> @@ -256,7 +295,8 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
>                  cbs = insn->insn_cbs;
>                  for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
>                      inject_cb(
> -                        &g_array_index(cbs, struct qemu_plugin_dyn_cb, i));
> +                        &g_array_index(cbs, struct qemu_plugin_dyn_cb, i),
> +                        &gen_ra);
>                  }
>                  break;
>  
> @@ -288,7 +328,7 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb)
>              cbs = insn->mem_cbs;
>              for (i = 0, n = (cbs ? cbs->len : 0); i < n; i++) {
>                  inject_mem_cb(&g_array_index(cbs, struct qemu_plugin_dyn_cb, i),
> -                              rw, meminfo, addr);
> +                              &gen_ra, rw, meminfo, addr);
>              }
>  
>              tcg_ctx->emit_before_op = NULL;

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  parent reply	other threads:[~2024-05-31 16:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16  4:06 [PATCH 0/7] plugins: Use unwind info for special gdb registers Richard Henderson
2024-04-16  4:06 ` [PATCH 1/7] tcg: Introduce INDEX_op_plugin_pc Richard Henderson
2024-04-18 17:53   ` Pierrick Bouvier
2024-04-16  4:06 ` [PATCH 2/7] accel/tcg: Set CPUState.plugin_ra before all plugin callbacks Richard Henderson
2024-04-18 17:54   ` Pierrick Bouvier
2024-05-31 16:46   ` Alex Bennée [this message]
2024-04-16  4:06 ` [PATCH 3/7] accel/tcg: Return the TranslationBlock from cpu_unwind_state_data Richard Henderson
2024-04-18 17:54   ` Pierrick Bouvier
2024-05-31 16:52   ` Alex Bennée
2024-04-16  4:06 ` [PATCH 4/7] plugins: Introduce TCGCPUOps callbacks for mid-tb register reads Richard Henderson
2024-04-18 17:55   ` Pierrick Bouvier
2024-04-16  4:06 ` [PATCH 5/7] target/i386: Split out gdb-internal.h Richard Henderson
2024-04-18 17:55   ` Pierrick Bouvier
2024-05-31 17:00   ` Alex Bennée
2024-04-16  4:06 ` [PATCH 6/7] target/i386: Introduce cpu_compute_eflags_ccop Richard Henderson
2024-04-18 17:56   ` Pierrick Bouvier
2024-04-16  4:06 ` [PATCH 7/7] target/i386: Implement TCGCPUOps for plugin register reads Richard Henderson
2024-04-18 17:56   ` Pierrick Bouvier
2024-04-17  0:35 ` [PATCH 0/7] plugins: Use unwind info for special gdb registers Pierrick Bouvier
2024-04-17  2:40   ` Richard Henderson
2024-04-17 15:39     ` Pierrick Bouvier
2024-04-22 16:49 ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8734pyaq01.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).