Blame SOURCES/kvm-accel-tcg-Test-CPUJumpCache-in-tb_jmp_cache_clear_pa.patch

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