I am emulating some hardware in QEMU, which correspond to some drivers in the kernel of linux guest.
Right now, I can use memory_region_init_io
to setup mmio regions so that whenever the kernel driver read/write to mmio address, I would get a callback.
How could I get the stack trace of the kernel that triggers mmio access within the callback? I want to know which line in the kernel driver triggers which mmio access.
I know that mmiotrace
may be an option, but that trace occurs in guest kernel. Is there anyway I could achieve that with qemu-kvm.
static uint64_t mmio_read(void *opaque, hwaddr addr,
unsigned size) {
/* Here, I want to get the stacktrace inside VM
* that caused this mmio read */
printf("mmio_read: %lx[%u] returns %lx\n", addr, size, ret);
return 0;
}
static void stream_dma_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size) {
/* Here, I want to get the stacktrace inside VM
* that caused this mmio write */
printf("mmio_write: %lx[%u]=%lx \n", addr, size, val);
}
static const MemoryRegionOps mmio_ops {
.read = mmio_read,
.write = mmio_write,
}
void init_region(uintptr_t addr, size_t size) {
MemoryRegion *subregion = malloc(sizeof(MemoryRegion));
memory_region_init_io(subregion, OBJECT(opaque),
&mmio_ops, NULL, "mmio-region", size);
memory_region_add_subregion_overlap(get_system_memory(),
addr, subregion, 100);
}