From c417e20ce0697a7922f56614beb6808049c5bed7 Mon Sep 17 00:00:00 2001 From: David Venhoff Date: Wed, 10 Sep 2025 15:27:00 +0200 Subject: [PATCH] Add flag that toggles tracing --- nyx/interface.c | 5 +++++ nyx/pt.c | 10 ++++++++-- nyx/pt.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/nyx/interface.c b/nyx/interface.c index 6d1ced61b3..af1952b265 100644 --- a/nyx/interface.c +++ b/nyx/interface.c @@ -92,6 +92,8 @@ typedef struct nyx_interface_state { bool dump_pt_trace; bool edge_cb_trace; + bool global_pt_enable; + bool redqueen; uint32_t aux_buffer_size; @@ -394,6 +396,8 @@ static void nyx_realize(DeviceState *dev, Error **errp) { nyx_interface_state *s = NYX_MEM(dev); + set_global_pt_enabled(s->global_pt_enable); + if (s->bitmap_size <= 0) { s->bitmap_size = DEFAULT_NYX_BITMAP_SIZE; } @@ -465,6 +469,7 @@ static Property nyx_interface_properties[] = { input_buffer_size, DEFAULT_NYX_BITMAP_SIZE), DEFINE_PROP_BOOL("dump_pt_trace", nyx_interface_state, dump_pt_trace, false), + DEFINE_PROP_BOOL("global_pt_enable", nyx_interface_state, global_pt_enable, true), DEFINE_PROP_BOOL("edge_cb_trace", nyx_interface_state, edge_cb_trace, false), DEFINE_PROP_UINT32("aux_buffer_size", nyx_interface_state, diff --git a/nyx/pt.c b/nyx/pt.c index 16acceedc4..f733742e41 100644 --- a/nyx/pt.c +++ b/nyx/pt.c @@ -52,6 +52,12 @@ along with QEMU-PT. If not, see . #define PT_BUFFER_MMAP_ADDR 0x3ffff0000000 +static bool PT_ENABLED = false; + +void set_global_pt_enabled(bool pt_enabled) { + PT_ENABLED = pt_enabled; +} + static void pt_set(CPUState *cpu, run_on_cpu_data arg) { asm volatile("" ::: "memory"); @@ -257,7 +263,7 @@ void pt_pre_kvm_run(CPUState *cpu) GET_GLOBAL_STATE()->redqueen_disable_pending = false; } - if (GET_GLOBAL_STATE()->pt_trace_mode || GET_GLOBAL_STATE()->pt_trace_mode_force) + if (PT_ENABLED && (GET_GLOBAL_STATE()->pt_trace_mode || GET_GLOBAL_STATE()->pt_trace_mode_force)) { if (!cpu->pt_fd) { cpu->pt_fd = kvm_vcpu_ioctl(cpu, KVM_VMX_PT_SETUP_FD, (unsigned long)0); @@ -357,7 +363,7 @@ void pt_handle_overflow(CPUState *cpu) void pt_post_kvm_run(CPUState *cpu) { - if (GET_GLOBAL_STATE()->pt_trace_mode || GET_GLOBAL_STATE()->pt_trace_mode_force) + if (PT_ENABLED && (GET_GLOBAL_STATE()->pt_trace_mode || GET_GLOBAL_STATE()->pt_trace_mode_force)) { pt_handle_overflow(cpu); } diff --git a/nyx/pt.h b/nyx/pt.h index b78a484b87..06f13a5003 100644 --- a/nyx/pt.h +++ b/nyx/pt.h @@ -22,6 +22,8 @@ along with QEMU-PT. If not, see . #ifndef PT_H #define PT_H +void set_global_pt_enabled(bool pt_enabled); + int pt_enable(CPUState *cpu, bool hmp_mode); int pt_disable(CPUState *cpu, bool hmp_mode); int pt_enable_ip_filtering(CPUState *cpu, uint8_t addrn, bool redqueen, bool hmp_mode);