accel/hvf: Trace VM memory mapping

Trace memory mapped / unmapped in the guest.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20250623121845.7214-8-philmd@linaro.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Philippe Mathieu-Daudé 2025-07-01 15:08:33 +01:00 committed by Peter Maydell
parent 4dcba9072b
commit d17d5cc0d6
4 changed files with 16 additions and 0 deletions

View file

@ -59,6 +59,7 @@
#include "system/hvf_int.h" #include "system/hvf_int.h"
#include "system/runstate.h" #include "system/runstate.h"
#include "qemu/guest-random.h" #include "qemu/guest-random.h"
#include "trace.h"
HVFState *hvf_state; HVFState *hvf_state;
@ -97,6 +98,7 @@ static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
if (macslot->present) { if (macslot->present) {
if (macslot->size != slot->size) { if (macslot->size != slot->size) {
macslot->present = 0; macslot->present = 0;
trace_hvf_vm_unmap(macslot->gpa_start, macslot->size);
ret = hv_vm_unmap(macslot->gpa_start, macslot->size); ret = hv_vm_unmap(macslot->gpa_start, macslot->size);
assert_hvf_ok(ret); assert_hvf_ok(ret);
} }
@ -109,6 +111,10 @@ static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
macslot->present = 1; macslot->present = 1;
macslot->gpa_start = slot->start; macslot->gpa_start = slot->start;
macslot->size = slot->size; macslot->size = slot->size;
trace_hvf_vm_map(slot->start, slot->size, slot->mem, flags,
flags & HV_MEMORY_READ ? 'R' : '-',
flags & HV_MEMORY_WRITE ? 'W' : '-',
flags & HV_MEMORY_EXEC ? 'E' : '-');
ret = hv_vm_map(slot->mem, slot->start, slot->size, flags); ret = hv_vm_map(slot->mem, slot->start, slot->size, flags);
assert_hvf_ok(ret); assert_hvf_ok(ret);
return 0; return 0;

7
accel/hvf/trace-events Normal file
View file

@ -0,0 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# See docs/devel/tracing.rst for syntax documentation.
# hvf-accel-ops.c
hvf_vm_map(uint64_t paddr, uint64_t size, void *vaddr, uint8_t flags, const char r, const char w, const char e) "paddr:0x%016"PRIx64" size:0x%08"PRIx64" vaddr:%p flags:0x%02x/%c%c%c"
hvf_vm_unmap(uint64_t paddr, uint64_t size) "paddr:0x%016"PRIx64" size:0x%08"PRIx64

2
accel/hvf/trace.h Normal file
View file

@ -0,0 +1,2 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "trace/trace-accel_hvf.h"

View file

@ -3630,6 +3630,7 @@ if have_block
endif endif
if have_system if have_system
trace_events_subdirs += [ trace_events_subdirs += [
'accel/hvf',
'accel/kvm', 'accel/kvm',
'audio', 'audio',
'backends', 'backends',