7f1c5b
From ab68e13b7628f2348d41a4518a92508542af712f Mon Sep 17 00:00:00 2001
7f1c5b
From: Eric Auger <eric.auger@redhat.com>
7f1c5b
Date: Fri, 3 Feb 2023 18:15:10 +0100
7f1c5b
Subject: [PATCH 05/20] accel/tcg: Test CPUJumpCache in tb_jmp_cache_clear_page
7f1c5b
7f1c5b
RH-Author: Eric Auger <eric.auger@redhat.com>
7f1c5b
RH-MergeRequest: 144: accel/tcg: Test CPUJumpCache in tb_jmp_cache_clear_page
7f1c5b
RH-Bugzilla: 2165280
7f1c5b
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
7f1c5b
RH-Acked-by: Gavin Shan <gshan@redhat.com>
7f1c5b
RH-Acked-by: Shaoqin Huang <None>
7f1c5b
RH-Commit: [1/1] 5b0863c34ba06c01c4e343d1ecd72402779c7de3 (eauger1/centos-qemu-kvm)
7f1c5b
7f1c5b
Bugzilla: https://bugzilla.redhat.com/2165280
7f1c5b
Upstream: yes
7f1c5b
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=50530041
7f1c5b
Test: 'kvm unit test ./run_tests.sh -g debug' does not SIGSEV anymore
7f1c5b
7f1c5b
After commit 4e4fa6c12d ("accel/tcg: Complete cpu initialization
7f1c5b
before registration"), it looks the CPUJumpCache pointer can be NULL.
7f1c5b
This causes a SIGSEV when running debug-wp-migration kvm unit test.
7f1c5b
7f1c5b
At the first place it should be clarified why this TCG code is called
7f1c5b
with KVM acceleration. This may hide another bug.
7f1c5b
7f1c5b
Fixes: 4e4fa6c12d ("accel/tcg: Complete cpu initialization before registration")
7f1c5b
Signed-off-by: Eric Auger <eric.auger@redhat.com>
7f1c5b
Message-Id: <20230203171510.2867451-1-eric.auger@redhat.com>
7f1c5b
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7f1c5b
(cherry picked from commit 99ab4d500af638ba3ebb20e8aa89d72201b70860)
7f1c5b
Signed-off-by: Eric Auger <eric.auger@redhat.com>
7f1c5b
---
7f1c5b
 accel/tcg/cputlb.c | 7 ++++++-
7f1c5b
 1 file changed, 6 insertions(+), 1 deletion(-)
7f1c5b
7f1c5b
diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
7f1c5b
index 6f1c00682b..4244b0e4e3 100644
7f1c5b
--- a/accel/tcg/cputlb.c
7f1c5b
+++ b/accel/tcg/cputlb.c
7f1c5b
@@ -100,9 +100,14 @@ static void tlb_window_reset(CPUTLBDesc *desc, int64_t ns,
7f1c5b
 
7f1c5b
 static void tb_jmp_cache_clear_page(CPUState *cpu, target_ulong page_addr)
7f1c5b
 {
7f1c5b
-    int i, i0 = tb_jmp_cache_hash_page(page_addr);
7f1c5b
     CPUJumpCache *jc = cpu->tb_jmp_cache;
7f1c5b
+    int i, i0;
7f1c5b
 
7f1c5b
+    if (unlikely(!jc)) {
7f1c5b
+        return;
7f1c5b
+    }
7f1c5b
+
7f1c5b
+    i0 = tb_jmp_cache_hash_page(page_addr);
7f1c5b
     for (i = 0; i < TB_JMP_PAGE_SIZE; i++) {
7f1c5b
         qatomic_set(&jc->array[i0 + i].tb, NULL);
7f1c5b
     }
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b