diff mbox series

[v5,43/67] hw/core: Add TCGCPUOps.record_sigbus

Message ID 20211015041053.2769193-44-richard.henderson@linaro.org
State Superseded
Headers show
Series user-only: Cleanup SIGSEGV and SIGBUS handling | expand

Commit Message

Richard Henderson Oct. 15, 2021, 4:10 a.m. UTC
Add a new user-only interface for updating cpu state before
raising a signal.  This will take the place of do_unaligned_access
for user-only and should result in less boilerplate for each guest.

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

---
 include/hw/core/tcg-cpu-ops.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

-- 
2.25.1

Comments

Warner Losh Oct. 15, 2021, 6:47 p.m. UTC | #1
On Thu, Oct 14, 2021 at 10:14 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> Add a new user-only interface for updating cpu state before

> raising a signal.  This will take the place of do_unaligned_access

> for user-only and should result in less boilerplate for each guest.

>

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

> ---

>  include/hw/core/tcg-cpu-ops.h | 23 +++++++++++++++++++++++

>  1 file changed, 23 insertions(+)

>


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




> diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h

> index 8eadd404c8..e13898553a 100644

> --- a/include/hw/core/tcg-cpu-ops.h

> +++ b/include/hw/core/tcg-cpu-ops.h

> @@ -135,6 +135,29 @@ struct TCGCPUOps {

>      void (*record_sigsegv)(CPUState *cpu, vaddr addr,

>                             MMUAccessType access_type,

>                             bool maperr, uintptr_t ra);

> +    /**

> +     * record_sigbus:

> +     * @cpu: cpu context

> +     * @addr: misaligned guest address

> +     * @access_type: access was read/write/execute

> +     * @ra: host pc for unwinding

> +     *

> +     * We are about to raise SIGBUS with si_code BUS_ADRALN,

> +     * and si_addr set for @addr.  Record anything further needed

> +     * for the signal ucontext_t.

> +     *

> +     * If the emulated kernel does not provide the signal handler with

> +     * anything besides the user context registers, and the siginfo_t,

> +     * then this hook need do nothing and may be omitted.

> +     * Otherwise, record the data and return; the caller will raise

> +     * the signal, unwind the cpu state, and return to the main loop.

> +     *

> +     * If it is simpler to re-use the sysemu do_unaligned_access code,

> +     * @ra is provided so that a "normal" cpu exception can be raised.

> +     * In this case, the signal must be raised by the architecture

> cpu_loop.

> +     */

> +    void (*record_sigbus)(CPUState *cpu, vaddr addr,

> +                          MMUAccessType access_type, uintptr_t ra);

>  #endif /* CONFIG_SOFTMMU */

>  #endif /* NEED_CPU_H */

>

> --

> 2.25.1

>

>
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 14, 2021 at 10:14 PM Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org">richard.henderson@linaro.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Add a new user-only interface for updating cpu state before<br>
raising a signal.  This will take the place of do_unaligned_access<br>
for user-only and should result in less boilerplate for each guest.<br>
<br>
Signed-off-by: Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org" target="_blank">richard.henderson@linaro.org</a>&gt;<br>

---<br>
 include/hw/core/tcg-cpu-ops.h | 23 +++++++++++++++++++++++<br>
 1 file changed, 23 insertions(+)<br></blockquote><div><br></div><div><div>Reviewed-by: Warner Losh &lt;<a href="mailto:imp@bsdimp.com">imp@bsdimp.com</a>&gt;</div><br class="gmail-Apple-interchange-newline"></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h<br>
index 8eadd404c8..e13898553a 100644<br>
--- a/include/hw/core/tcg-cpu-ops.h<br>
+++ b/include/hw/core/tcg-cpu-ops.h<br>
@@ -135,6 +135,29 @@ struct TCGCPUOps {<br>
     void (*record_sigsegv)(CPUState *cpu, vaddr addr,<br>
                            MMUAccessType access_type,<br>
                            bool maperr, uintptr_t ra);<br>
+    /**<br>
+     * record_sigbus:<br>
+     * @cpu: cpu context<br>
+     * @addr: misaligned guest address<br>
+     * @access_type: access was read/write/execute<br>
+     * @ra: host pc for unwinding<br>
+     *<br>
+     * We are about to raise SIGBUS with si_code BUS_ADRALN,<br>
+     * and si_addr set for @addr.  Record anything further needed<br>
+     * for the signal ucontext_t.<br>
+     *<br>
+     * If the emulated kernel does not provide the signal handler with<br>
+     * anything besides the user context registers, and the siginfo_t,<br>
+     * then this hook need do nothing and may be omitted.<br>
+     * Otherwise, record the data and return; the caller will raise<br>
+     * the signal, unwind the cpu state, and return to the main loop.<br>
+     *<br>
+     * If it is simpler to re-use the sysemu do_unaligned_access code,<br>
+     * @ra is provided so that a &quot;normal&quot; cpu exception can be raised.<br>
+     * In this case, the signal must be raised by the architecture cpu_loop.<br>
+     */<br>
+    void (*record_sigbus)(CPUState *cpu, vaddr addr,<br>
+                          MMUAccessType access_type, uintptr_t ra);<br>
 #endif /* CONFIG_SOFTMMU */<br>
 #endif /* NEED_CPU_H */<br>
<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div></div>
diff mbox series

Patch

diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h
index 8eadd404c8..e13898553a 100644
--- a/include/hw/core/tcg-cpu-ops.h
+++ b/include/hw/core/tcg-cpu-ops.h
@@ -135,6 +135,29 @@  struct TCGCPUOps {
     void (*record_sigsegv)(CPUState *cpu, vaddr addr,
                            MMUAccessType access_type,
                            bool maperr, uintptr_t ra);
+    /**
+     * record_sigbus:
+     * @cpu: cpu context
+     * @addr: misaligned guest address
+     * @access_type: access was read/write/execute
+     * @ra: host pc for unwinding
+     *
+     * We are about to raise SIGBUS with si_code BUS_ADRALN,
+     * and si_addr set for @addr.  Record anything further needed
+     * for the signal ucontext_t.
+     *
+     * If the emulated kernel does not provide the signal handler with
+     * anything besides the user context registers, and the siginfo_t,
+     * then this hook need do nothing and may be omitted.
+     * Otherwise, record the data and return; the caller will raise
+     * the signal, unwind the cpu state, and return to the main loop.
+     *
+     * If it is simpler to re-use the sysemu do_unaligned_access code,
+     * @ra is provided so that a "normal" cpu exception can be raised.
+     * In this case, the signal must be raised by the architecture cpu_loop.
+     */
+    void (*record_sigbus)(CPUState *cpu, vaddr addr,
+                          MMUAccessType access_type, uintptr_t ra);
 #endif /* CONFIG_SOFTMMU */
 #endif /* NEED_CPU_H */