[PATCH v8 18/25] target/s390x: call plugin trap callbacks

Julian Ganz posted 25 patches 3 weeks, 5 days ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Richard Henderson <richard.henderson@linaro.org>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, Helge Deller <deller@gmx.de>, Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Song Gao <gaosong@loongson.cn>, Laurent Vivier <laurent@vivier.eu>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Stafford Horne <shorne@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Max Filippov <jcmvbkbc@gmail.com>
[PATCH v8 18/25] target/s390x: call plugin trap callbacks
Posted by Julian Ganz 3 weeks, 5 days ago
We recently introduced API for registering callbacks for trap related
events as well as the corresponding hook functions. Due to differences
between architectures, the latter need to be called from target specific
code.

This change places hooks for IBM System/390 targets. We treat "program
interrupts" and service calls as exceptions. We treat external and io
"exceptions" as well as resets as interrupts.

Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Julian Ganz <neither@nut.email>
---
 target/s390x/tcg/excp_helper.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/target/s390x/tcg/excp_helper.c b/target/s390x/tcg/excp_helper.c
index 0ae4e26606..c6641280bc 100644
--- a/target/s390x/tcg/excp_helper.c
+++ b/target/s390x/tcg/excp_helper.c
@@ -35,6 +35,7 @@
 #include "hw/s390x/s390_flic.h"
 #include "hw/boards.h"
 #endif
+#include "qemu/plugin.h"
 
 G_NORETURN void tcg_s390_program_interrupt(CPUS390XState *env,
                                            uint32_t code, uintptr_t ra)
@@ -502,6 +503,7 @@ void s390_cpu_do_interrupt(CPUState *cs)
     S390CPU *cpu = S390_CPU(cs);
     CPUS390XState *env = &cpu->env;
     bool stopped = false;
+    uint64_t last_pc = cpu->env.psw.addr;
 
     qemu_log_mask(CPU_LOG_INT, "%s: %d at psw=%" PRIx64 ":%" PRIx64 "\n",
                   __func__, cs->exception_index, env->psw.mask, env->psw.addr);
@@ -531,21 +533,27 @@ try_deliver:
     switch (cs->exception_index) {
     case EXCP_PGM:
         do_program_interrupt(env);
+        qemu_plugin_vcpu_exception_cb(cs, last_pc);
         break;
     case EXCP_SVC:
         do_svc_interrupt(env);
+        qemu_plugin_vcpu_exception_cb(cs, last_pc);
         break;
     case EXCP_EXT:
         do_ext_interrupt(env);
+        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
         break;
     case EXCP_IO:
         do_io_interrupt(env);
+        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
         break;
     case EXCP_MCHK:
         do_mchk_interrupt(env);
+        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
         break;
     case EXCP_RESTART:
         do_restart_interrupt(env);
+        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
         break;
     case EXCP_STOP:
         do_stop_interrupt(env);
-- 
2.49.1
Re: [PATCH v8 18/25] target/s390x: call plugin trap callbacks
Posted by Philippe Mathieu-Daudé 3 weeks, 2 days ago
Hi Julian,

On 19/10/25 17:15, Julian Ganz wrote:
> We recently introduced API for registering callbacks for trap related
> events as well as the corresponding hook functions. Due to differences
> between architectures, the latter need to be called from target specific
> code.
> 
> This change places hooks for IBM System/390 targets. We treat "program
> interrupts" and service calls as exceptions. We treat external and io
> "exceptions" as well as resets as interrupts.
> 
> Acked-by: David Hildenbrand <david@redhat.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Julian Ganz <neither@nut.email>
> ---
>   target/s390x/tcg/excp_helper.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/target/s390x/tcg/excp_helper.c b/target/s390x/tcg/excp_helper.c
> index 0ae4e26606..c6641280bc 100644
> --- a/target/s390x/tcg/excp_helper.c
> +++ b/target/s390x/tcg/excp_helper.c
> @@ -35,6 +35,7 @@
>   #include "hw/s390x/s390_flic.h"
>   #include "hw/boards.h"
>   #endif
> +#include "qemu/plugin.h"
>   
>   G_NORETURN void tcg_s390_program_interrupt(CPUS390XState *env,
>                                              uint32_t code, uintptr_t ra)
> @@ -502,6 +503,7 @@ void s390_cpu_do_interrupt(CPUState *cs)
>       S390CPU *cpu = S390_CPU(cs);
>       CPUS390XState *env = &cpu->env;
>       bool stopped = false;
> +    uint64_t last_pc = cpu->env.psw.addr;
>   
>       qemu_log_mask(CPU_LOG_INT, "%s: %d at psw=%" PRIx64 ":%" PRIx64 "\n",
>                     __func__, cs->exception_index, env->psw.mask, env->psw.addr);
> @@ -531,21 +533,27 @@ try_deliver:
>       switch (cs->exception_index) {
>       case EXCP_PGM:
>           do_program_interrupt(env);
> +        qemu_plugin_vcpu_exception_cb(cs, last_pc);
>           break;
>       case EXCP_SVC:
>           do_svc_interrupt(env);
> +        qemu_plugin_vcpu_exception_cb(cs, last_pc);
>           break;
>       case EXCP_EXT:
>           do_ext_interrupt(env);
> +        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
>           break;
>       case EXCP_IO:
>           do_io_interrupt(env);
> +        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
>           break;
>       case EXCP_MCHK:
>           do_mchk_interrupt(env);
> +        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
>           break;
>       case EXCP_RESTART:
>           do_restart_interrupt(env);
> +        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
>           break;
>       case EXCP_STOP:
>           do_stop_interrupt(env);

Shouldn't we also track the STOP interrupt?

            qemu_plugin_vcpu_interrupt_cb(cs, last_pc);

If not, please mention why in the patch description.
Re: [PATCH v8 18/25] target/s390x: call plugin trap callbacks
Posted by Julian Ganz 3 weeks, 2 days ago
Hi Philippe,

October 21, 2025 at 10:07 PM, "Philippe Mathieu-Daudé" wrote:
> On 19/10/25 17:15, Julian Ganz wrote:
> >  @@ -531,21 +533,27 @@ try_deliver:
> >  switch (cs->exception_index) {
> >  case EXCP_PGM:
> >  do_program_interrupt(env);
> >  + qemu_plugin_vcpu_exception_cb(cs, last_pc);
> >  break;
> >  case EXCP_SVC:
> >  do_svc_interrupt(env);
> >  + qemu_plugin_vcpu_exception_cb(cs, last_pc);
> >  break;
> >  case EXCP_EXT:
> >  do_ext_interrupt(env);
> >  + qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
> >  break;
> >  case EXCP_IO:
> >  do_io_interrupt(env);
> >  + qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
> >  break;
> >  case EXCP_MCHK:
> >  do_mchk_interrupt(env);
> >  + qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
> >  break;
> >  case EXCP_RESTART:
> >  do_restart_interrupt(env);
> >  + qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
> >  break;
> >  case EXCP_STOP:
> >  do_stop_interrupt(env);
> > 
> Shouldn't we also track the STOP interrupt?
> 
>  qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
> 
> If not, please mention why in the patch description.

My expectation was that this exception is not observable in software
running on the target anyway, and that is would lead to a VCPU exit. For
which we already have qemu_plugin_register_vcpu_exit_cb. If I'm wrong
about that than we do want to also track STOP interrupts. If not I'll
add a sentence about that in the commit message.

Regards,
Julian