Skip to contentSkip to conversation

accel/tcg: test CPUJumpCache in tb_jmp_cache_clear_page()

PATCH In review Eric Auger 3 participants 4 messages Feb 3, 2023

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH 1/1 accel/tcg: test CPUJumpCache in tb_jmp_cache_clear_page()

After commit 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration"), it looks the CPUJumpCache handle can be NULL. This causes a SIGSEV when running debug-wp-migration kvm unit test.

At the first place it should be clarified why this TCG code is called with KVM acceleration. This may hide another bug.

Fixes 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration")
---
 accel/tcg/cputlb.c | 4 ++++
 1 file changed, 4 insertions(+)
accel/tcg/cputlb.c +4 -0
index 4e040a1cb9..ac0245ee6c 100644
@@ -103,6 +103,10 @@ static void tb_jmp_cache_clear_page(CPUState *cpu, target_ulong page_addr)
     int i, i0 = tb_jmp_cache_hash_page(page_addr);
     CPUJumpCache *jc = cpu->tb_jmp_cache;
 
+    if (!jc) {
+        return;
+    }
+
     for (i = 0; i < TB_JMP_PAGE_SIZE; i++) {
         qatomic_set(&jc->array[i0 + i].tb, NULL);
     }
Signature · 1 line
2.37.3
#1 lore raw
Quoted 3 lines · Eric Auger

After commit 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration"), it looks the CPUJumpCache handle can be NULL. This causes a SIGSEV when running debug-wp-migration kvm unit test.

Do you mean commit a976a99a29 ("include/hw/core: Create struct CPUJumpCache") instead?

Quoted 14 lines

At the first place it should be clarified why this TCG code is called with KVM acceleration. This may hide another bug.

Fixes 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration")
---
  accel/tcg/cputlb.c | 4 ++++
  1 file changed, 4 insertions(+)
accel/tcg/cputlb.c +0 -0
index 4e040a1cb9..ac0245ee6c 100644

accel/tcg/cputlb.c static void tb_jmp_cache_clear_page(CPUState *cpu, target_ulong page_addr) · line 106

Quoted 4 lines
accel/tcg/cputlb.c +1 -0
@@ -103,6 +103,10 @@ static void tb_jmp_cache_clear_page(CPUState *cpu, target_ulong page_addr)
      int i, i0 = tb_jmp_cache_hash_page(page_addr);
      CPUJumpCache *jc = cpu->tb_jmp_cache;
 
+    if (!jc) {

unlikely()?

Quoted 6 lines
accel/tcg/cputlb.c +3 -0
+        return;
+    }
+
      for (i = 0; i < TB_JMP_PAGE_SIZE; i++) {
          qatomic_set(&jc->array[i0 + i].tb, NULL);
      }
author
#2 lore raw

Hi Philippe,

Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Eric Auger

After commit 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration"), it looks the CPUJumpCache handle can be NULL. This causes a SIGSEV when running debug-wp-migration kvm unit test.

Do you mean commit a976a99a29 ("include/hw/core: Create struct CPUJumpCache") instead?

No as reported in
https://lore.kernel.org/all/[email protected]/
my bisection pointed to 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration")

Quoted 11 lines
Quoted 11 lines

At the first place it should be clarified why this TCG code is called with KVM acceleration. This may hide another bug.

Fixes 4e4fa6c12d ("accel/tcg: Complete cpu initialization before

registration")

---
  accel/tcg/cputlb.c | 4 ++++

  1 file changed, 4 insertions(+)
Quoted 11 lines

accel/tcg/cputlb.c static void tb_jmp_cache_clear_page(CPUState · line 106

Quoted 9 lines
accel/tcg/cputlb.c +0 -0
index 4e040a1cb9..ac0245ee6c 100644
@@ -103,6 +103,10 @@ static void tb_jmp_cache_clear_page(CPUState
 *cpu, target_ulong page_addr)
       int i, i0 = tb_jmp_cache_hash_page(page_addr);
       CPUJumpCache *jc = cpu->tb_jmp_cache;
   +    if (!jc) {

unlikely()?

yes maybe

Thanks

Eric

Quoted 8 lines
Quoted 7 lines
accel/tcg/cputlb.c +3 -0
+        return;
+    }
+
       for (i = 0; i < TB_JMP_PAGE_SIZE; i++) {
           qatomic_set(&jc->array[i0 + i].tb, NULL);

      }

#3 lore raw
In reply to Eric Auger
Quoted 18 lines · Eric Auger

After commit 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration"), it looks the CPUJumpCache handle can be NULL. This causes a SIGSEV when running debug-wp-migration kvm unit test.

At the first place it should be clarified why this TCG code is called with KVM acceleration. This may hide another bug.

Fixes 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration")
---
  accel/tcg/cputlb.c | 4 ++++
  1 file changed, 4 insertions(+)
accel/tcg/cputlb.c +0 -0
index 4e040a1cb9..ac0245ee6c 100644

accel/tcg/cputlb.c static void tb_jmp_cache_clear_page(CPUState *cpu, target_ulong page_addr) · line 108

Quoted 6 lines
accel/tcg/cputlb.c +3 -0
@@ -103,6 +103,10 @@ static void tb_jmp_cache_clear_page(CPUState *cpu, target_ulong page_addr)
      int i, i0 = tb_jmp_cache_hash_page(page_addr);
      CPUJumpCache *jc = cpu->tb_jmp_cache;
 
+    if (!jc) {
+        return;
+    }

While I think we shouldn't arrive here for KVM, it was previously not an error to do so. I'm going to go ahead and queue this while the correct cpregs change gets worked out.

r~