[PATCH v8 05/25] target/alpha: 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 05/25] target/alpha: 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 Alpha targets.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Julian Ganz <neither@nut.email>
---
 target/alpha/helper.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/target/alpha/helper.c b/target/alpha/helper.c
index 096eac3445..a9af52a928 100644
--- a/target/alpha/helper.c
+++ b/target/alpha/helper.c
@@ -27,6 +27,7 @@
 #include "exec/helper-proto.h"
 #include "qemu/qemu-print.h"
 #include "system/memory.h"
+#include "qemu/plugin.h"
 
 
 #define CONVERT_BIT(X, SRC, DST) \
@@ -328,6 +329,7 @@ void alpha_cpu_do_interrupt(CPUState *cs)
 {
     CPUAlphaState *env = cpu_env(cs);
     int i = cs->exception_index;
+    uint64_t last_pc = env->pc;
 
     if (qemu_loglevel_mask(CPU_LOG_INT)) {
         static int count;
@@ -431,6 +433,17 @@ void alpha_cpu_do_interrupt(CPUState *cs)
 
     /* Switch to PALmode.  */
     env->flags |= ENV_FLAG_PAL_MODE;
+
+    switch (i) {
+    case EXCP_SMP_INTERRUPT:
+    case EXCP_CLK_INTERRUPT:
+    case EXCP_DEV_INTERRUPT:
+        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
+        break;
+    default:
+        qemu_plugin_vcpu_exception_cb(cs, last_pc);
+        break;
+    }
 }
 
 bool alpha_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
-- 
2.49.1
Re: [PATCH v8 05/25] target/alpha: call plugin trap callbacks
Posted by Philippe Mathieu-Daudé 3 weeks, 2 days ago
Hi Julian,

On 19/10/25 17:14, 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 Alpha targets.
> 
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Julian Ganz <neither@nut.email>
> ---
>   target/alpha/helper.c | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
> 
> diff --git a/target/alpha/helper.c b/target/alpha/helper.c
> index 096eac3445..a9af52a928 100644
> --- a/target/alpha/helper.c
> +++ b/target/alpha/helper.c
> @@ -27,6 +27,7 @@
>   #include "exec/helper-proto.h"
>   #include "qemu/qemu-print.h"
>   #include "system/memory.h"
> +#include "qemu/plugin.h"
>   
>   
>   #define CONVERT_BIT(X, SRC, DST) \
> @@ -328,6 +329,7 @@ void alpha_cpu_do_interrupt(CPUState *cs)
>   {
>       CPUAlphaState *env = cpu_env(cs);
>       int i = cs->exception_index;
> +    uint64_t last_pc = env->pc;
>   
>       if (qemu_loglevel_mask(CPU_LOG_INT)) {
>           static int count;
> @@ -431,6 +433,17 @@ void alpha_cpu_do_interrupt(CPUState *cs)
>   
>       /* Switch to PALmode.  */
>       env->flags |= ENV_FLAG_PAL_MODE;
> +
> +    switch (i) {
> +    case EXCP_SMP_INTERRUPT:
> +    case EXCP_CLK_INTERRUPT:
> +    case EXCP_DEV_INTERRUPT:
> +        qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
> +        break;
> +    default:
> +        qemu_plugin_vcpu_exception_cb(cs, last_pc);
> +        break;

Shouldn't we handle EXCP_CALL_PAL with qemu_plugin_vcpu_hostcall_cb()?

> +    }
>   }
Re: [PATCH v8 05/25] target/alpha: call plugin trap callbacks
Posted by Julian Ganz 3 weeks, 2 days ago
Hi Philippe,

October 21, 2025 at 10:10 PM, "Philippe Mathieu-Daudé" wrote:
> On 19/10/25 17:14, 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 Alpha targets.
> >  Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> >  Signed-off-by: Julian Ganz <neither@nut.email>
> >  ---
> >  target/alpha/helper.c | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> >  diff --git a/target/alpha/helper.c b/target/alpha/helper.c
> >  index 096eac3445..a9af52a928 100644
> >  --- a/target/alpha/helper.c
> >  +++ b/target/alpha/helper.c
> >  @@ -27,6 +27,7 @@
> >  #include "exec/helper-proto.h"
> >  #include "qemu/qemu-print.h"
> >  #include "system/memory.h"
> >  +#include "qemu/plugin.h"
> >  > > #define CONVERT_BIT(X, SRC, DST) \
> >  @@ -328,6 +329,7 @@ void alpha_cpu_do_interrupt(CPUState *cs)
> >  {
> >  CPUAlphaState *env = cpu_env(cs);
> >  int i = cs->exception_index;
> >  + uint64_t last_pc = env->pc;
> >  > if (qemu_loglevel_mask(CPU_LOG_INT)) {
> >  static int count;
> >  @@ -431,6 +433,17 @@ void alpha_cpu_do_interrupt(CPUState *cs)
> >  > /* Switch to PALmode. */
> >  env->flags |= ENV_FLAG_PAL_MODE;
> >  +
> >  + switch (i) {
> >  + case EXCP_SMP_INTERRUPT:
> >  + case EXCP_CLK_INTERRUPT:
> >  + case EXCP_DEV_INTERRUPT:
> >  + qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
> >  + break;
> >  + default:
> >  + qemu_plugin_vcpu_exception_cb(cs, last_pc);
> >  + break;
> > 
> Shouldn't we handle EXCP_CALL_PAL with qemu_plugin_vcpu_hostcall_cb()?

Host calls are exclusively calls that are handled outside the emulation,
on the host, regardless of whether they are hypervisor calls or not. In
that respect EXCP_CALL_PAL looks to me like a regular exception that is
handled by translated code within the emulation.

Regards,
Julian
Re: [PATCH v8 05/25] target/alpha: call plugin trap callbacks
Posted by Philippe Mathieu-Daudé 3 weeks, 2 days ago
On 21/10/25 22:38, Julian Ganz wrote:
> Hi Philippe,
> 
> October 21, 2025 at 10:10 PM, "Philippe Mathieu-Daudé" wrote:
>> On 19/10/25 17:14, 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 Alpha targets.
>>>   Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>>>   Signed-off-by: Julian Ganz <neither@nut.email>
>>>   ---
>>>   target/alpha/helper.c | 13 +++++++++++++
>>>   1 file changed, 13 insertions(+)
>>>   diff --git a/target/alpha/helper.c b/target/alpha/helper.c
>>>   index 096eac3445..a9af52a928 100644
>>>   --- a/target/alpha/helper.c
>>>   +++ b/target/alpha/helper.c
>>>   @@ -27,6 +27,7 @@
>>>   #include "exec/helper-proto.h"
>>>   #include "qemu/qemu-print.h"
>>>   #include "system/memory.h"
>>>   +#include "qemu/plugin.h"
>>>   > > #define CONVERT_BIT(X, SRC, DST) \
>>>   @@ -328,6 +329,7 @@ void alpha_cpu_do_interrupt(CPUState *cs)
>>>   {
>>>   CPUAlphaState *env = cpu_env(cs);
>>>   int i = cs->exception_index;
>>>   + uint64_t last_pc = env->pc;
>>>   > if (qemu_loglevel_mask(CPU_LOG_INT)) {
>>>   static int count;
>>>   @@ -431,6 +433,17 @@ void alpha_cpu_do_interrupt(CPUState *cs)
>>>   > /* Switch to PALmode. */
>>>   env->flags |= ENV_FLAG_PAL_MODE;
>>>   +
>>>   + switch (i) {
>>>   + case EXCP_SMP_INTERRUPT:
>>>   + case EXCP_CLK_INTERRUPT:
>>>   + case EXCP_DEV_INTERRUPT:
>>>   + qemu_plugin_vcpu_interrupt_cb(cs, last_pc);
>>>   + break;
>>>   + default:
>>>   + qemu_plugin_vcpu_exception_cb(cs, last_pc);
>>>   + break;
>>>
>> Shouldn't we handle EXCP_CALL_PAL with qemu_plugin_vcpu_hostcall_cb()?
> 
> Host calls are exclusively calls that are handled outside the emulation,
> on the host, regardless of whether they are hypervisor calls or not. In
> that respect EXCP_CALL_PAL looks to me like a regular exception that is
> handled by translated code within the emulation.

OK, thanks.