Skip to contentSkip to conversation

SIGSEGV fixes

PATCH Superseded Taylor Simpson 2 participants 5 messages Jul 13, 2021 – Jul 14, 2021

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover SIGSEGV fixes

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(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 Hexagon (target/hexagon) do probe_write in HELPER(commit_store)

Check that access is OK before doing put_user_*

---
 target/hexagon/op_helper.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
target/hexagon/op_helper.c +14 -9
index 4595559..d7f53a2 100644
@@ -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();
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/2] Hexagon (target/hexagon) do probe_write in HELPER(commit_store)

Quoted 7 lines · Taylor Simpson
  void HELPER(commit_store)(CPUHexagonState *env, int slot_num)
  {
target/hexagon/op_helper.c +4 -1
-    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

target/hexagon/op_helper.c void HELPER(debug_check_store_width)(CPUHexagonState *env, int slot, int check) · line 154

Quoted 10 lines
target/hexagon/op_helper.c +7 -2
+    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~

#3 lore raw

PATCH 2/2 linux-test (tests/tcg/multiarch/linux-test.c) add check

In reply to Taylor Simpson

Add a check that the SIGSEGV handler is called

---
 tests/tcg/multiarch/linux-test.c | 7 +++++++
 1 file changed, 7 insertions(+)
tests/tcg/multiarch/linux-test.c +7 -0
index c8c6aed..cb845c9 100644
@@ -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;
Signature · 1 line
2.7.4
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] linux-test (tests/tcg/multiarch/linux-test.c) add check

Quoted 12 lines · Taylor Simpson

Add a check that the SIGSEGV handler is called

---
  tests/tcg/multiarch/linux-test.c | 7 +++++++
  1 file changed, 7 insertions(+)
tests/tcg/multiarch/linux-test.c +0 -0
index c8c6aed..cb845c9 100644

tests/tcg/multiarch/linux-test.c static void sig_alarm(int sig) · line 448

Quoted 10 lines
tests/tcg/multiarch/linux-test.c +3 -0
@@ -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,

r~

Quoted 15 lines
tests/tcg/multiarch/linux-test.c +4 -0
      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;