qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] SIGSEGV fixes
@ 2021-07-13 19:46 Taylor Simpson
  2021-07-13 19:46 ` [PATCH 1/2] Hexagon (target/hexagon) do probe_write in HELPER(commit_store) Taylor Simpson
  2021-07-13 19:46 ` [PATCH 2/2] linux-test (tests/tcg/multiarch/linux-test.c) add check Taylor Simpson
  0 siblings, 2 replies; 5+ messages in thread
From: Taylor Simpson @ 2021-07-13 19:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: ale, bcain, alex.bennee, richard.henderson, tsimpson, philmd

The Hexagon target was silently failing the SIGSEGV test because
the signal handler was not called.

Patch 1/2 fixes the Hexagon target
Patch 2/2 adds a check that the signal handler is called

Taylor Simpson (2):
  Hexagon (target/hexagon) do probe_write in HELPER(commit_store)
  linux-test (tests/tcg/multiarch/linux-test.c) add check

 target/hexagon/op_helper.c       | 23 ++++++++++++++---------
 tests/tcg/multiarch/linux-test.c |  7 +++++++
 2 files changed, 21 insertions(+), 9 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] Hexagon (target/hexagon) do probe_write in HELPER(commit_store)
  2021-07-13 19:46 [PATCH 0/2] SIGSEGV fixes Taylor Simpson
@ 2021-07-13 19:46 ` Taylor Simpson
  2021-07-14 12:33   ` Richard Henderson
  2021-07-13 19:46 ` [PATCH 2/2] linux-test (tests/tcg/multiarch/linux-test.c) add check Taylor Simpson
  1 sibling, 1 reply; 5+ messages in thread
From: Taylor Simpson @ 2021-07-13 19:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: ale, bcain, alex.bennee, richard.henderson, tsimpson, philmd

Check that access is OK before doing put_user_*

Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
---
 target/hexagon/op_helper.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c
index 4595559..d7f53a2 100644
--- a/target/hexagon/op_helper.c
+++ b/target/hexagon/op_helper.c
@@ -140,22 +140,27 @@ void HELPER(debug_check_store_width)(CPUHexagonState *env, int slot, int check)
 
 void HELPER(commit_store)(CPUHexagonState *env, int slot_num)
 {
-    switch (env->mem_log_stores[slot_num].width) {
+    uint8_t width = env->mem_log_stores[slot_num].width;
+    target_ulong va = env->mem_log_stores[slot_num].va;
+
+#ifdef CONFIG_USER_ONLY
+    g_assert(width == 1 || width == 2 || width == 4 || width == 8);
+    /* We perform this check elsewhere in system mode */
+    probe_write(env, va, width, MMU_USER_IDX, 0);
+#endif
+
+    switch (width) {
     case 1:
-        put_user_u8(env->mem_log_stores[slot_num].data32,
-                    env->mem_log_stores[slot_num].va);
+        put_user_u8(env->mem_log_stores[slot_num].data32, va);
         break;
     case 2:
-        put_user_u16(env->mem_log_stores[slot_num].data32,
-                     env->mem_log_stores[slot_num].va);
+        put_user_u16(env->mem_log_stores[slot_num].data32, va);
         break;
     case 4:
-        put_user_u32(env->mem_log_stores[slot_num].data32,
-                     env->mem_log_stores[slot_num].va);
+        put_user_u32(env->mem_log_stores[slot_num].data32, va);
         break;
     case 8:
-        put_user_u64(env->mem_log_stores[slot_num].data64,
-                     env->mem_log_stores[slot_num].va);
+        put_user_u64(env->mem_log_stores[slot_num].data64, va);
         break;
     default:
         g_assert_not_reached();
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] linux-test (tests/tcg/multiarch/linux-test.c) add check
  2021-07-13 19:46 [PATCH 0/2] SIGSEGV fixes Taylor Simpson
  2021-07-13 19:46 ` [PATCH 1/2] Hexagon (target/hexagon) do probe_write in HELPER(commit_store) Taylor Simpson
@ 2021-07-13 19:46 ` Taylor Simpson
  2021-07-14 12:35   ` Richard Henderson
  1 sibling, 1 reply; 5+ messages in thread
From: Taylor Simpson @ 2021-07-13 19:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: ale, bcain, alex.bennee, richard.henderson, tsimpson, philmd

Add a check that the SIGSEGV handler is called

Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
---
 tests/tcg/multiarch/linux-test.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
index c8c6aed..cb845c9 100644
--- a/tests/tcg/multiarch/linux-test.c
+++ b/tests/tcg/multiarch/linux-test.c
@@ -439,10 +439,13 @@ static void sig_alarm(int sig)
     alarm_count++;
 }
 
+static int sig_segv_called;
+
 static void sig_segv(int sig, siginfo_t *info, void *puc)
 {
     if (sig != SIGSEGV)
         error("signal");
+    sig_segv_called = 1;
     longjmp(jmp_env, 1);
 }
 
@@ -492,6 +495,10 @@ static void test_signal(void)
         *(volatile uint8_t *)0 = 0;
     }
 
+    if (sig_segv_called == 0) {
+        error("SIGSEGV handler not called");
+    }
+
     act.sa_handler = SIG_DFL;
     sigemptyset(&act.sa_mask);
     act.sa_flags = 0;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] Hexagon (target/hexagon) do probe_write in HELPER(commit_store)
  2021-07-13 19:46 ` [PATCH 1/2] Hexagon (target/hexagon) do probe_write in HELPER(commit_store) Taylor Simpson
@ 2021-07-14 12:33   ` Richard Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2021-07-14 12:33 UTC (permalink / raw)
  To: Taylor Simpson, qemu-devel; +Cc: ale, bcain, philmd, alex.bennee

On 7/13/21 12:46 PM, Taylor Simpson wrote:
>   void HELPER(commit_store)(CPUHexagonState *env, int slot_num)
>   {
> -    switch (env->mem_log_stores[slot_num].width) {
> +    uint8_t width = env->mem_log_stores[slot_num].width;
> +    target_ulong va = env->mem_log_stores[slot_num].va;
> +
> +#ifdef CONFIG_USER_ONLY
> +    g_assert(width == 1 || width == 2 || width == 4 || width == 8);
> +    /* We perform this check elsewhere in system mode */
> +    probe_write(env, va, width, MMU_USER_IDX, 0);
> +#endif
> +
> +    switch (width) {
>       case 1:
> -        put_user_u8(env->mem_log_stores[slot_num].data32,
> -                    env->mem_log_stores[slot_num].va);
> +        put_user_u8(env->mem_log_stores[slot_num].data32, va);

The primary problem here is that put_user_* is the wrong set of functions to use.  You 
should have been using exec/cpu_ldst.h, in particular cpu_ld*_data_ra and cpu_st*_data_ra.


r~


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] linux-test (tests/tcg/multiarch/linux-test.c) add check
  2021-07-13 19:46 ` [PATCH 2/2] linux-test (tests/tcg/multiarch/linux-test.c) add check Taylor Simpson
@ 2021-07-14 12:35   ` Richard Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2021-07-14 12:35 UTC (permalink / raw)
  To: Taylor Simpson, qemu-devel; +Cc: ale, bcain, philmd, alex.bennee

On 7/13/21 12:46 PM, Taylor Simpson wrote:
> Add a check that the SIGSEGV handler is called
> 
> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
> ---
>   tests/tcg/multiarch/linux-test.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
> index c8c6aed..cb845c9 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -439,10 +439,13 @@ static void sig_alarm(int sig)
>       alarm_count++;
>   }
>   
> +static int sig_segv_called;
> +
>   static void sig_segv(int sig, siginfo_t *info, void *puc)
>   {
>       if (sig != SIGSEGV)
>           error("signal");
> +    sig_segv_called = 1;

Either bool or a count.

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~

>       longjmp(jmp_env, 1);
>   }
>   
> @@ -492,6 +495,10 @@ static void test_signal(void)
>           *(volatile uint8_t *)0 = 0;
>       }
>   
> +    if (sig_segv_called == 0) {
> +        error("SIGSEGV handler not called");
> +    }
> +
>       act.sa_handler = SIG_DFL;
>       sigemptyset(&act.sa_mask);
>       act.sa_flags = 0;
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-07-14 12:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 19:46 [PATCH 0/2] SIGSEGV fixes Taylor Simpson
2021-07-13 19:46 ` [PATCH 1/2] Hexagon (target/hexagon) do probe_write in HELPER(commit_store) Taylor Simpson
2021-07-14 12:33   ` Richard Henderson
2021-07-13 19:46 ` [PATCH 2/2] linux-test (tests/tcg/multiarch/linux-test.c) add check Taylor Simpson
2021-07-14 12:35   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).