log: Add separate debug option for logging invalid memory accesses

Currently -d guest_errors enables logging of different invalid actions
by the guest such as misusing hardware, accessing missing features or
invalid memory areas. The memory access logging can be quite verbose
which obscures the other messages enabled by this debug switch so
separate it by adding a new -d invalid_mem option to make it possible
to control it independently of other guest error logs.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <1bb0d0e91ba14aca13056df3b0a774f89cbf966c.1730549443.git.balaton@eik.bme.hu>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
BALATON Zoltan 2024-11-02 13:17:35 +01:00 committed by Philippe Mathieu-Daudé
parent a7e7066b93
commit 678bf8f22a
4 changed files with 7 additions and 4 deletions

View file

@ -37,6 +37,7 @@ bool qemu_log_separate(void);
#define LOG_PER_THREAD (1 << 20) #define LOG_PER_THREAD (1 << 20)
#define CPU_LOG_TB_VPU (1 << 21) #define CPU_LOG_TB_VPU (1 << 21)
#define LOG_TB_OP_PLUGIN (1 << 22) #define LOG_TB_OP_PLUGIN (1 << 22)
#define LOG_INVALID_MEM (1 << 23)
/* Lock/unlock output. */ /* Lock/unlock output. */

View file

@ -1412,7 +1412,7 @@ bool memory_region_access_valid(MemoryRegion *mr,
{ {
if (mr->ops->valid.accepts if (mr->ops->valid.accepts
&& !mr->ops->valid.accepts(mr->opaque, addr, size, is_write, attrs)) { && !mr->ops->valid.accepts(mr->opaque, addr, size, is_write, attrs)) {
qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX qemu_log_mask(LOG_INVALID_MEM, "Invalid %s at addr 0x%" HWADDR_PRIX
", size %u, region '%s', reason: rejected\n", ", size %u, region '%s', reason: rejected\n",
is_write ? "write" : "read", is_write ? "write" : "read",
addr, size, memory_region_name(mr)); addr, size, memory_region_name(mr));
@ -1420,7 +1420,7 @@ bool memory_region_access_valid(MemoryRegion *mr,
} }
if (!mr->ops->valid.unaligned && (addr & (size - 1))) { if (!mr->ops->valid.unaligned && (addr & (size - 1))) {
qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX qemu_log_mask(LOG_INVALID_MEM, "Invalid %s at addr 0x%" HWADDR_PRIX
", size %u, region '%s', reason: unaligned\n", ", size %u, region '%s', reason: unaligned\n",
is_write ? "write" : "read", is_write ? "write" : "read",
addr, size, memory_region_name(mr)); addr, size, memory_region_name(mr));
@ -1434,7 +1434,7 @@ bool memory_region_access_valid(MemoryRegion *mr,
if (size > mr->ops->valid.max_access_size if (size > mr->ops->valid.max_access_size
|| size < mr->ops->valid.min_access_size) { || size < mr->ops->valid.min_access_size) {
qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX qemu_log_mask(LOG_INVALID_MEM, "Invalid %s at addr 0x%" HWADDR_PRIX
", size %u, region '%s', reason: invalid size " ", size %u, region '%s', reason: invalid size "
"(min:%u max:%u)\n", "(min:%u max:%u)\n",
is_write ? "write" : "read", is_write ? "write" : "read",

View file

@ -2745,7 +2745,7 @@ static bool flatview_access_allowed(MemoryRegion *mr, MemTxAttrs attrs,
if (memory_region_is_ram(mr)) { if (memory_region_is_ram(mr)) {
return true; return true;
} }
qemu_log_mask(LOG_GUEST_ERROR, qemu_log_mask(LOG_INVALID_MEM,
"Invalid access to non-RAM device at " "Invalid access to non-RAM device at "
"addr 0x%" HWADDR_PRIX ", size %" HWADDR_PRIu ", " "addr 0x%" HWADDR_PRIX ", size %" HWADDR_PRIu ", "
"region '%s'\n", addr, len, memory_region_name(mr)); "region '%s'\n", addr, len, memory_region_name(mr));

View file

@ -503,6 +503,8 @@ const QEMULogItem qemu_log_items[] = {
"open a separate log file per thread; filename must contain '%d'" }, "open a separate log file per thread; filename must contain '%d'" },
{ CPU_LOG_TB_VPU, "vpu", { CPU_LOG_TB_VPU, "vpu",
"include VPU registers in the 'cpu' logging" }, "include VPU registers in the 'cpu' logging" },
{ LOG_INVALID_MEM, "invalid_mem",
"log invalid memory accesses" },
{ 0, NULL, NULL }, { 0, NULL, NULL },
}; };