Skip to contentSkip to conversation

accel/tcg: Trace tb_flush() and tb_gen_code() buffer overflow

PATCH In review Philippe Mathieu-Daudé 2 participants 5 messages Sep 25, 2025 – Nov 10, 2025

lore
Share & tools
lore
#0 lore raw

cover accel/tcg: Trace tb_flush() and tb_gen_code() buffer overflow

Add trace events to better understand the changes introduced by the "accel/tcg: Improve tb_flush usage" series recently merged.

Philippe Mathieu-Daudé (2):
accel/tcg: Trace tb_flush() calls
accel/tcg: Trace tb_gen_code() buffer overflow

 accel/tcg/tb-maint.c      | 3 ++-
 accel/tcg/translate-all.c | 3 +++
 accel/tcg/trace-events    | 4 ++++
 3 files changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/2 accel/tcg: Trace tb_flush() calls

---
 accel/tcg/tb-maint.c   | 3 ++-
 accel/tcg/trace-events | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)
accel/tcg/tb-maint.c +2 -1
index 5a8d0784e7a..cd7c32361bb 100644
@@ -40,7 +40,7 @@
 #else
 #include "system/runstate.h"
 #endif
-
+#include "trace.h"
 
 /* List iterators for lists of tagged pointers in TranslationBlock. */
 #define TB_FOR_EACH_TAGGED(head, tb, n, field)                          \
@@ -771,6 +771,7 @@ void tb_flush__exclusive_or_serial(void)
 {
     CPUState *cpu;
 
+    trace_tb_flush();
     assert(tcg_enabled());
     /* Note that cpu_in_serial_context checks cpu_in_exclusive_context. */
     assert(!runstate_is_running() ||
accel/tcg/trace-events +3 -0
index 14f638810c6..121d6b5081b 100644
@@ -24,3 +24,6 @@ store_atom2_fallback(uint32_t memop, uintptr_t ra) "mop:0x%"PRIx32", ra:0x%"PRIx
 store_atom4_fallback(uint32_t memop, uintptr_t ra) "mop:0x%"PRIx32", ra:0x%"PRIxPTR""
 store_atom8_fallback(uint32_t memop, uintptr_t ra) "mop:0x%"PRIx32", ra:0x%"PRIxPTR""
 store_atom16_fallback(uint32_t memop, uintptr_t ra) "mop:0x%"PRIx32", ra:0x%"PRIxPTR""
+
+# tb-maint.c
+tb_flush(void) ""
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/2 accel/tcg: Trace tb_gen_code() buffer overflow

In reply to Philippe Mathieu-Daudé
---
 accel/tcg/translate-all.c | 3 +++
 accel/tcg/trace-events    | 1 +
 2 files changed, 4 insertions(+)
accel/tcg/translate-all.c +3 -0
index da9d7f16752..fba4e9dc21c 100644
@@ -290,6 +290,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGTBCPUState s)
     if (unlikely(!tb)) {
         /* flush must be done */
         if (cpu_in_serial_context(cpu)) {
+            trace_tb_gen_code_buffer_overflow("tcg_tb_alloc");
             tb_flush__exclusive_or_serial();
             goto buffer_overflow;
         }
@@ -325,6 +326,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGTBCPUState s)
     if (unlikely(gen_code_size < 0)) {
         switch (gen_code_size) {
         case -1:
+            trace_tb_gen_code_buffer_overflow("setjmp_gen_code");
             /*
              * Overflow of code_gen_buffer, or the current slice of it.
              *
@@ -389,6 +391,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGTBCPUState s)
 
     search_size = encode_search(tb, (void *)gen_code_buf + gen_code_size);
     if (unlikely(search_size < 0)) {
+        trace_tb_gen_code_buffer_overflow("encode_search");
         tb_unlock_pages(tb);
         goto buffer_overflow;
     }
accel/tcg/trace-events +1 -0
index 121d6b5081b..0816cafd336 100644
@@ -12,6 +12,7 @@ memory_notdirty_set_dirty(uint64_t vaddr) "0x%" PRIx64
 
 # translate-all.c
 translate_block(void *tb, uintptr_t pc, const void *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p"
+tb_gen_code_buffer_overflow(const char *reason) "reason: %s"
 
 # ldst_atomicity
 load_atom2_fallback(uint32_t memop, uintptr_t ra) "mop:0x%"PRIx32", ra:0x%"PRIxPTR""
Signature · 1 line
2.51.0
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

Add trace events to better understand the changes introduced by the "accel/tcg: Improve tb_flush usage" series recently merged.

Quoted 9 lines

Philippe Mathieu-Daudé (2):
accel/tcg: Trace tb_flush() calls
accel/tcg: Trace tb_gen_code() buffer overflow

  accel/tcg/tb-maint.c      | 3 ++-
  accel/tcg/translate-all.c | 3 +++
  accel/tcg/trace-events    | 4 ++++
  3 files changed, 9 insertions(+), 1 deletion(-)

ping?

Reviewed-by
#4 lore raw
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Add trace events to better understand the changes introduced by the "accel/tcg: Improve tb_flush usage" series recently merged.

Philippe Mathieu-Daudé (2):
   accel/tcg: Trace tb_flush() calls
   accel/tcg: Trace tb_gen_code() buffer overflow

Quoted 7 lines
Quoted 5 lines

  accel/tcg/tb-maint.c      | 3 ++-
  accel/tcg/translate-all.c | 3 +++
  accel/tcg/trace-events    | 4 ++++

  3 files changed, 9 insertions(+), 1 deletion(-)

ping?

and queued.

r~