diff mbox series

[v3,25/26] target/s390x: fake instruction loading when handling 'ex'

Message ID 20221020115209.1761864-26-alex.bennee@linaro.org
State Superseded
Headers show
Series testing/next (docker, avocado, s390x, MAINTAINERS) | expand

Commit Message

Alex Bennée Oct. 20, 2022, 11:52 a.m. UTC
The s390x EXecute instruction is a bit weird as we synthesis the
executed instruction from what we have stored in memory. This missed
the plugin instrumentation.

Work around this with a special helper to inform the rest of the
translator about the instruction so things stay consistent.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Richard Henderson <richard.henderson@linaro.org>

---
v2
  - s/w/b/ for translator_fake_ldb
  - add comment to extract_insn
  - reword commit message
---
 include/exec/translator.h    | 17 +++++++++++++++++
 target/s390x/tcg/translate.c |  6 ++++++
 2 files changed, 23 insertions(+)

Comments

Richard Henderson Oct. 20, 2022, 12:06 p.m. UTC | #1
On 10/20/22 21:52, Alex Bennée wrote:
> The s390x EXecute instruction is a bit weird as we synthesis the
> executed instruction from what we have stored in memory. This missed
> the plugin instrumentation.
> 
> Work around this with a special helper to inform the rest of the
> translator about the instruction so things stay consistent.
> 
> Signed-off-by: Alex Bennée<alex.bennee@linaro.org>
> Cc: Richard Henderson<richard.henderson@linaro.org>
> 
> ---
> v2
>    - s/w/b/ for translator_fake_ldb
>    - add comment to extract_insn
>    - reword commit message
> ---
>   include/exec/translator.h    | 17 +++++++++++++++++
>   target/s390x/tcg/translate.c |  6 ++++++
>   2 files changed, 23 insertions(+)

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

r~
Ilya Leoshkevich Oct. 21, 2022, 10:56 a.m. UTC | #2
On Thu, 2022-10-20 at 12:52 +0100, Alex Bennée wrote:
> The s390x EXecute instruction is a bit weird as we synthesis the
> executed instruction from what we have stored in memory. This missed
> the plugin instrumentation.
> 
> Work around this with a special helper to inform the rest of the
> translator about the instruction so things stay consistent.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Cc: Richard Henderson <richard.henderson@linaro.org>
> 
> ---
> v2
>   - s/w/b/ for translator_fake_ldb
>   - add comment to extract_insn
>   - reword commit message
> ---
>  include/exec/translator.h    | 17 +++++++++++++++++
>  target/s390x/tcg/translate.c |  6 ++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/include/exec/translator.h b/include/exec/translator.h
> index 3b77f5f4aa..af2ff95cd5 100644
> --- a/include/exec/translator.h
> +++ b/include/exec/translator.h
> @@ -211,6 +211,23 @@ translator_ldq_swap(CPUArchState *env,
> DisasContextBase *db,
>      return ret;
>  }
>  
> +/**
> + * translator_fake_ldb - fake instruction load
> + * @insn8: byte of instruction
> + * @pc: program counter of instruction
> + *
> + * This is a special case helper used where the instruction we are
> + * about to translate comes from somewhere else (e.g. being
> + * re-synthesised for s390x "ex"). It ensures we update other areas
> of
> + * the translator with details of the executed instruction.
> + */
> +
> +static inline void translator_fake_ldb(uint8_t insn8, abi_ptr pc)
> +{
> +    plugin_insn_append(pc, &insn8, sizeof(insn8));
> +}
> +
> +
>  /*
>   * Return whether addr is on the same page as where disassembly
> started.
>   * Translators can use this to enforce the rule that only single-
> insn
> diff --git a/target/s390x/tcg/translate.c
> b/target/s390x/tcg/translate.c
> index 95279e5dc3..8101f5f569 100644
> --- a/target/s390x/tcg/translate.c
> +++ b/target/s390x/tcg/translate.c
> @@ -6317,12 +6317,18 @@ static const DisasInsn
> *extract_insn(CPUS390XState *env, DisasContext *s)
>      if (unlikely(s->ex_value)) {
>          /* Drop the EX data now, so that it's clear on exception
> paths.  */
>          TCGv_i64 zero = tcg_const_i64(0);
> +        int i;
>          tcg_gen_st_i64(zero, cpu_env, offsetof(CPUS390XState,
> ex_value));
>          tcg_temp_free_i64(zero);
>  
>          /* Extract the values saved by EXECUTE.  */
>          insn = s->ex_value & 0xffffffffffff0000ull;
>          ilen = s->ex_value & 0xf;
> +        /* register insn bytes with translator so plugins work */
> +        for (i = 0; i < ilen; i++) {
> +            uint8_t byte = extract64(insn, 56 - (i * 8), 8);
> +            translator_fake_ldb(byte, pc + i);
> +        }
>          op = insn >> 56;
>      } else {
>          insn = ld_code2(env, s, pc);

Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
diff mbox series

Patch

diff --git a/include/exec/translator.h b/include/exec/translator.h
index 3b77f5f4aa..af2ff95cd5 100644
--- a/include/exec/translator.h
+++ b/include/exec/translator.h
@@ -211,6 +211,23 @@  translator_ldq_swap(CPUArchState *env, DisasContextBase *db,
     return ret;
 }
 
+/**
+ * translator_fake_ldb - fake instruction load
+ * @insn8: byte of instruction
+ * @pc: program counter of instruction
+ *
+ * This is a special case helper used where the instruction we are
+ * about to translate comes from somewhere else (e.g. being
+ * re-synthesised for s390x "ex"). It ensures we update other areas of
+ * the translator with details of the executed instruction.
+ */
+
+static inline void translator_fake_ldb(uint8_t insn8, abi_ptr pc)
+{
+    plugin_insn_append(pc, &insn8, sizeof(insn8));
+}
+
+
 /*
  * Return whether addr is on the same page as where disassembly started.
  * Translators can use this to enforce the rule that only single-insn
diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c
index 95279e5dc3..8101f5f569 100644
--- a/target/s390x/tcg/translate.c
+++ b/target/s390x/tcg/translate.c
@@ -6317,12 +6317,18 @@  static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s)
     if (unlikely(s->ex_value)) {
         /* Drop the EX data now, so that it's clear on exception paths.  */
         TCGv_i64 zero = tcg_const_i64(0);
+        int i;
         tcg_gen_st_i64(zero, cpu_env, offsetof(CPUS390XState, ex_value));
         tcg_temp_free_i64(zero);
 
         /* Extract the values saved by EXECUTE.  */
         insn = s->ex_value & 0xffffffffffff0000ull;
         ilen = s->ex_value & 0xf;
+        /* register insn bytes with translator so plugins work */
+        for (i = 0; i < ilen; i++) {
+            uint8_t byte = extract64(insn, 56 - (i * 8), 8);
+            translator_fake_ldb(byte, pc + i);
+        }
         op = insn >> 56;
     } else {
         insn = ld_code2(env, s, pc);