diff mbox series

[v5,59/67] accel/tcg: Report unaligned load/store for user-only

Message ID 20211015041053.2769193-60-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
Use the new cpu_loop_exit_sigbus for cpu_mmu_lookup.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

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

---
 accel/tcg/user-exec.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

-- 
2.25.1

Comments

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

> Use the new cpu_loop_exit_sigbus for cpu_mmu_lookup.

>

> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

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

> ---

>  accel/tcg/user-exec.c | 7 ++++++-

>  1 file changed, 6 insertions(+), 1 deletion(-)

>


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




> diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c

> index 92cbffd7c6..7d50dd54f6 100644

> --- a/accel/tcg/user-exec.c

> +++ b/accel/tcg/user-exec.c

> @@ -220,9 +220,14 @@ static void validate_memop(MemOpIdx oi, MemOp

> expected)

>  static void *cpu_mmu_lookup(CPUArchState *env, target_ulong addr,

>                              MemOpIdx oi, uintptr_t ra, MMUAccessType type)

>  {

> +    MemOp mop = get_memop(oi);

> +    int a_bits = get_alignment_bits(mop);

>      void *ret;

>

> -    /* TODO: Enforce guest required alignment.  */

> +    /* Enforce guest required alignment.  */

> +    if (unlikely(addr & ((1 << a_bits) - 1))) {

> +        cpu_loop_exit_sigbus(env_cpu(env), addr, type, ra);

> +    }

>

>      ret = g2h(env_cpu(env), addr);

>      set_helper_retaddr(ra);

> --

> 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">Use the new cpu_loop_exit_sigbus for cpu_mmu_lookup.<br>
<br>
Reviewed-by: Peter Maydell &lt;<a href="mailto:peter.maydell@linaro.org" target="_blank">peter.maydell@linaro.org</a>&gt;<br>

Signed-off-by: Richard Henderson &lt;<a href="mailto:richard.henderson@linaro.org" target="_blank">richard.henderson@linaro.org</a>&gt;<br>

---<br>
 accel/tcg/user-exec.c | 7 ++++++-<br>
 1 file changed, 6 insertions(+), 1 deletion(-)<br></blockquote><div><br></div><div><div>Reviewed-by: Warner Losh &lt;<a href="mailto:imp@bsdimp.com">imp@bsdimp.com</a>&gt;</div><div><br></div></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/accel/tcg/user-exec.c b/accel/tcg/user-exec.c<br>
index 92cbffd7c6..7d50dd54f6 100644<br>
--- a/accel/tcg/user-exec.c<br>
+++ b/accel/tcg/user-exec.c<br>
@@ -220,9 +220,14 @@ static void validate_memop(MemOpIdx oi, MemOp expected)<br>
 static void *cpu_mmu_lookup(CPUArchState *env, target_ulong addr,<br>
                             MemOpIdx oi, uintptr_t ra, MMUAccessType type)<br>
 {<br>
+    MemOp mop = get_memop(oi);<br>
+    int a_bits = get_alignment_bits(mop);<br>
     void *ret;<br>
<br>
-    /* TODO: Enforce guest required alignment.  */<br>
+    /* Enforce guest required alignment.  */<br>
+    if (unlikely(addr &amp; ((1 &lt;&lt; a_bits) - 1))) {<br>
+        cpu_loop_exit_sigbus(env_cpu(env), addr, type, ra);<br>
+    }<br>
<br>
     ret = g2h(env_cpu(env), addr);<br>
     set_helper_retaddr(ra);<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div></div>
diff mbox series

Patch

diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c
index 92cbffd7c6..7d50dd54f6 100644
--- a/accel/tcg/user-exec.c
+++ b/accel/tcg/user-exec.c
@@ -220,9 +220,14 @@  static void validate_memop(MemOpIdx oi, MemOp expected)
 static void *cpu_mmu_lookup(CPUArchState *env, target_ulong addr,
                             MemOpIdx oi, uintptr_t ra, MMUAccessType type)
 {
+    MemOp mop = get_memop(oi);
+    int a_bits = get_alignment_bits(mop);
     void *ret;
 
-    /* TODO: Enforce guest required alignment.  */
+    /* Enforce guest required alignment.  */
+    if (unlikely(addr & ((1 << a_bits) - 1))) {
+        cpu_loop_exit_sigbus(env_cpu(env), addr, type, ra);
+    }
 
     ret = g2h(env_cpu(env), addr);
     set_helper_retaddr(ra);