[PATCH v5 44/67] linux-user: Add cpu_loop_exit_sigbus

Richard Henderson posted 67 patches 4 years, 3 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Taylor Simpson <tsimpson@quicinc.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, David Hildenbrand <david@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Greg Kurz <groug@kaod.org>, Cornelia Huck <cohuck@redhat.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Richard Henderson <richard.henderson@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Thomas Huth <thuth@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, Artyom Tarasenko <atar4qemu@gmail.com>, Laurent Vivier <laurent@vivier.eu>, Aurelien Jarno <aurelien@aurel32.net>, Eduardo Habkost <ehabkost@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Riku Voipio <riku.voipio@iki.fi>, Peter Maydell <peter.maydell@linaro.org>, Yoshinori Sato <ysato@users.sourceforge.jp>, Jiaxun Yang <jiaxun.yang@flygoat.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>
There is a newer version of this series
[PATCH v5 44/67] linux-user: Add cpu_loop_exit_sigbus
Posted by Richard Henderson 4 years, 3 months ago
This is a new interface to be provided by the os emulator for
raising SIGBUS on fault.  Use the new record_sigbus target hook.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/exec/exec-all.h | 14 ++++++++++++++
 linux-user/signal.c     | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index f74578500c..6bb2a0f7ec 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -700,6 +700,20 @@ void QEMU_NORETURN cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,
                                          MMUAccessType access_type,
                                          bool maperr, uintptr_t ra);
 
+/**
+ * cpu_loop_exit_sigbus:
+ * @cpu: the cpu context
+ * @addr: the guest address of the alignment fault
+ * @access_type: access was read/write/execute
+ * @ra: host pc for unwinding
+ *
+ * Use the TCGCPUOps hook to record cpu state, do guest operating system
+ * specific things to raise SIGBUS, and jump to the main cpu loop.
+ */
+void QEMU_NORETURN cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,
+                                        MMUAccessType access_type,
+                                        uintptr_t ra);
+
 #else
 static inline void mmap_lock(void) {}
 static inline void mmap_unlock(void) {}
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 9d60abc038..df2c8678d0 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -706,6 +706,20 @@ void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,
     cpu_loop_exit_restore(cpu, ra);
 }
 
+void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,
+                          MMUAccessType access_type, uintptr_t ra)
+{
+    const struct TCGCPUOps *tcg_ops = CPU_GET_CLASS(cpu)->tcg_ops;
+
+    if (tcg_ops->record_sigbus) {
+        tcg_ops->record_sigbus(cpu, addr, access_type, ra);
+    }
+
+    force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, addr);
+    cpu->exception_index = EXCP_INTERRUPT;
+    cpu_loop_exit_restore(cpu, ra);
+}
+
 /* abort execution with signal */
 static void QEMU_NORETURN dump_core_and_abort(int target_sig)
 {
-- 
2.25.1


Re: [PATCH v5 44/67] linux-user: Add cpu_loop_exit_sigbus
Posted by Warner Losh 4 years, 3 months ago
On Thu, Oct 14, 2021 at 10:14 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> This is a new interface to be provided by the os emulator for
> raising SIGBUS on fault.  Use the new record_sigbus target hook.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  include/exec/exec-all.h | 14 ++++++++++++++
>  linux-user/signal.c     | 14 ++++++++++++++
>  2 files changed, 28 insertions(+)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>


> diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
> index f74578500c..6bb2a0f7ec 100644
> --- a/include/exec/exec-all.h
> +++ b/include/exec/exec-all.h
> @@ -700,6 +700,20 @@ void QEMU_NORETURN cpu_loop_exit_sigsegv(CPUState
> *cpu, target_ulong addr,
>                                           MMUAccessType access_type,
>                                           bool maperr, uintptr_t ra);
>
> +/**
> + * cpu_loop_exit_sigbus:
> + * @cpu: the cpu context
> + * @addr: the guest address of the alignment fault
> + * @access_type: access was read/write/execute
> + * @ra: host pc for unwinding
> + *
> + * Use the TCGCPUOps hook to record cpu state, do guest operating system
> + * specific things to raise SIGBUS, and jump to the main cpu loop.
> + */
> +void QEMU_NORETURN cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,
> +                                        MMUAccessType access_type,
> +                                        uintptr_t ra);
> +
>  #else
>  static inline void mmap_lock(void) {}
>  static inline void mmap_unlock(void) {}
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 9d60abc038..df2c8678d0 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -706,6 +706,20 @@ void cpu_loop_exit_sigsegv(CPUState *cpu,
> target_ulong addr,
>      cpu_loop_exit_restore(cpu, ra);
>  }
>
> +void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,
> +                          MMUAccessType access_type, uintptr_t ra)
> +{
> +    const struct TCGCPUOps *tcg_ops = CPU_GET_CLASS(cpu)->tcg_ops;
> +
> +    if (tcg_ops->record_sigbus) {
> +        tcg_ops->record_sigbus(cpu, addr, access_type, ra);
> +    }
> +
> +    force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, addr);
> +    cpu->exception_index = EXCP_INTERRUPT;
> +    cpu_loop_exit_restore(cpu, ra);
> +}
> +
>  /* abort execution with signal */
>  static void QEMU_NORETURN dump_core_and_abort(int target_sig)
>  {
> --
> 2.25.1
>
>
Re: [PATCH v5 44/67] linux-user: Add cpu_loop_exit_sigbus
Posted by Philippe Mathieu-Daudé 4 years, 3 months ago
On 10/15/21 06:10, Richard Henderson wrote:
> This is a new interface to be provided by the os emulator for
> raising SIGBUS on fault.  Use the new record_sigbus target hook.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  include/exec/exec-all.h | 14 ++++++++++++++

This header deserves a system/user split.

>  linux-user/signal.c     | 14 ++++++++++++++
>  2 files changed, 28 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>