@samitouri / QOSamiQemu / commits / 78420b59f0

accel/tcg: move jit thread manipulation into do_tb_phys_invalidate

To invalidate a TB on MacOS we need to enable write access to the JIT buffer. We were doing this for tb_phys_invalidate__locked but that is not the only path into do_tb_phys_invalidate. Move the manipulation into the shared function that does the work. As a result we can drop the tb_phys_invalidate__locked function and update the calls directly. This enables watchpoints to work in MacOS TCG guests. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3444 Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260526110243.470002-5-alex.bennee@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Alex Bennée committed May 26, 2026 at 12:02 UTC 78420b59f0fe227605bd67e1e232df9dc1ec539b
1 file changed +19 -24
accel/tcg/tb-maint.c
+19 -24
@@ -925,6 +925,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
925 uint32_t orig_cflags = tb_cflags(tb);
926
927 assert_memory_lock();
928 + qemu_thread_jit_write();
929
930 /* make sure no further incoming jumps will be chained to this TB */
931 qemu_spin_lock(&tb->jmp_lock);
@@ -935,33 +936,27 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
936 phys_pc = tb_page_addr0(tb);
937 h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb->pc),
938 tb->flags, tb->cs_base, orig_cflags);
938 - if (!qht_remove(&tb_ctx.htable, tb, h)) {
939 - return;
940 - }
939 + if (qht_remove(&tb_ctx.htable, tb, h)) {
940
942 - /* remove the TB from the page list */
943 - if (rm_from_page_list) {
944 - tb_remove(tb);
945 - }
941 + /* remove the TB from the page list */
942 + if (rm_from_page_list) {
943 + tb_remove(tb);
944 + }
945
947 - /* remove the TB from the hash list */
948 - tb_jmp_cache_inval_tb(tb);
946 + /* remove the TB from the hash list */
947 + tb_jmp_cache_inval_tb(tb);
948
950 - /* suppress this TB from the two jump lists */
951 - tb_remove_from_jmp_list(tb, 0);
952 - tb_remove_from_jmp_list(tb, 1);
949 + /* suppress this TB from the two jump lists */
950 + tb_remove_from_jmp_list(tb, 0);
951 + tb_remove_from_jmp_list(tb, 1);
952
954 - /* suppress any remaining jumps to this TB */
955 - tb_jmp_unlink(tb);
953 + /* suppress any remaining jumps to this TB */
954 + tb_jmp_unlink(tb);
955
957 - qatomic_set(&tb_ctx.tb_phys_invalidate_count,
958 - tb_ctx.tb_phys_invalidate_count + 1);
959 -}
956 + qatomic_set(&tb_ctx.tb_phys_invalidate_count,
957 + tb_ctx.tb_phys_invalidate_count + 1);
958 + }
959
961 -static void tb_phys_invalidate__locked(TranslationBlock *tb)
962 -{
963 - qemu_thread_jit_write();
964 - do_tb_phys_invalidate(tb, true);
960 qemu_thread_jit_execute();
961 }
962
@@ -1030,7 +1025,7 @@ void tb_invalidate_phys_range(CPUState *cpu, tb_page_addr_t start,
1025 assert_memory_lock();
1026
1027 PAGE_FOR_EACH_TB(start, last, unused, tb, n) {
1033 - tb_phys_invalidate__locked(tb);
1028 + do_tb_phys_invalidate(tb, true);
1029 }
1030 }
1031
@@ -1091,7 +1086,7 @@ bool tb_invalidate_phys_page_unwind(CPUState *cpu, tb_page_addr_t addr,
1086 current_tb_modified = true;
1087 cpu_restore_state_from_tb(cpu, current_tb, pc);
1088 }
1094 - tb_phys_invalidate__locked(tb);
1089 + do_tb_phys_invalidate(tb, true);
1090 }
1091
1092 if (current_tb_modified) {
@@ -1156,7 +1151,7 @@ tb_invalidate_phys_page_range__locked(CPUState *cpu,
1151 current_tb_modified = true;
1152 cpu_restore_state_from_tb(cpu, current_tb, retaddr);
1153 }
1159 - tb_phys_invalidate__locked(tb);
1154 + do_tb_phys_invalidate(tb, true);
1155 }
1156 }
1157