qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] log: Add separate debug option for logging invalid memory accesses
@ 2023-01-19 21:40 BALATON Zoltan
  2023-01-31 14:28 ` BALATON Zoltan
  2023-02-13 13:45 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 23+ messages in thread
From: BALATON Zoltan @ 2023-01-19 21:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: philmd

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 memaccess option to make it possible to
control it independently of other guest error logs.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 include/qemu/log.h | 1 +
 softmmu/memory.c   | 6 +++---
 softmmu/physmem.c  | 2 +-
 util/log.c         | 2 ++
 4 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/qemu/log.h b/include/qemu/log.h
index c5643d8dd5..4bf0a65a85 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -35,6 +35,7 @@ bool qemu_log_separate(void);
 /* LOG_STRACE is used for user-mode strace logging. */
 #define LOG_STRACE         (1 << 19)
 #define LOG_PER_THREAD     (1 << 20)
+#define LOG_MEM_ACCESS     (1 << 21)
 
 /* Lock/unlock output. */
 
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 9d64efca26..0a9fa67d32 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1379,7 +1379,7 @@ bool memory_region_access_valid(MemoryRegion *mr,
 {
     if (mr->ops->valid.accepts
         && !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_MEM_ACCESS, "Invalid %s at addr 0x%" HWADDR_PRIX
                       ", size %u, region '%s', reason: rejected\n",
                       is_write ? "write" : "read",
                       addr, size, memory_region_name(mr));
@@ -1387,7 +1387,7 @@ bool memory_region_access_valid(MemoryRegion *mr,
     }
 
     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_MEM_ACCESS, "Invalid %s at addr 0x%" HWADDR_PRIX
                       ", size %u, region '%s', reason: unaligned\n",
                       is_write ? "write" : "read",
                       addr, size, memory_region_name(mr));
@@ -1401,7 +1401,7 @@ bool memory_region_access_valid(MemoryRegion *mr,
 
     if (size > mr->ops->valid.max_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_MEM_ACCESS, "Invalid %s at addr 0x%" HWADDR_PRIX
                       ", size %u, region '%s', reason: invalid size "
                       "(min:%u max:%u)\n",
                       is_write ? "write" : "read",
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index bf585e45a8..bca679ee01 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -2792,7 +2792,7 @@ static bool flatview_access_allowed(MemoryRegion *mr, MemTxAttrs attrs,
     if (memory_region_is_ram(mr)) {
         return true;
     }
-    qemu_log_mask(LOG_GUEST_ERROR,
+    qemu_log_mask(LOG_MEM_ACCESS,
                   "Invalid access to non-RAM device at "
                   "addr 0x%" HWADDR_PRIX ", size %" HWADDR_PRIu ", "
                   "region '%s'\n", addr, len, memory_region_name(mr));
diff --git a/util/log.c b/util/log.c
index 7837ff9917..a3c097f320 100644
--- a/util/log.c
+++ b/util/log.c
@@ -495,6 +495,8 @@ const QEMULogItem qemu_log_items[] = {
       "log every user-mode syscall, its input, and its result" },
     { LOG_PER_THREAD, "tid",
       "open a separate log file per thread; filename must contain '%d'" },
+    { LOG_MEM_ACCESS, "memaccess",
+      "log invalid memory accesses" },
     { 0, NULL, NULL },
 };
 
-- 
2.30.6



^ permalink raw reply related	[flat|nested] 23+ messages in thread
* [PATCH 0/2] Separate memory access logs from guest_errors
@ 2024-10-06 16:49 BALATON Zoltan
  2024-10-06 16:49 ` [PATCH 1/2] log: Add separate debug option for logging invalid memory accesses BALATON Zoltan
  0 siblings, 1 reply; 23+ messages in thread
From: BALATON Zoltan @ 2024-10-06 16:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: philmd

Originally memory access logs were a debug define that then were
converted to log messages but were classified as guest_errors which
already logs misc errors. As invalid memory access logs can come from
accessing not emulated peripherals or memory areas, these often
generate a lot of messages that are better be controlled separately
from other errors to avoid obscuring those. As an example try
'qemu-system-ppc -d guest_errors' to see the problem. After this
series the actual guest error logs are easier to spot. I've tried to
submit this before but there were some people who liked the current
behaviour so now this series has another patch that preserves the old
optino printing a warning to allow time to get used to the new
behaviour (which actually brings back the old behaviour when mem
access logs were a debug define).

Regards,
BALATON Zoltan

BALATON Zoltan (2):
  log: Add separate debug option for logging invalid memory accesses
  log: Suggest using -d guest_error,memaccess instead of guest_errors

 docs/devel/secure-coding-practices.rst | 2 +-
 include/qemu/log.h                     | 1 +
 system/memory.c                        | 6 +++---
 system/physmem.c                       | 2 +-
 tests/avocado/smmu.py                  | 2 +-
 tests/qtest/pnv-host-i2c-test.c        | 2 +-
 util/log.c                             | 8 +++++++-
 7 files changed, 15 insertions(+), 8 deletions(-)

-- 
2.30.9



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2024-10-14 16:48 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-19 21:40 [PATCH 1/2] log: Add separate debug option for logging invalid memory accesses BALATON Zoltan
2023-01-31 14:28 ` BALATON Zoltan
2023-02-07 16:33   ` BALATON Zoltan
2023-02-13 11:41     ` Thomas Huth
2023-02-13 14:45       ` Peter Xu
2023-02-13 14:47         ` BALATON Zoltan
2023-02-13 14:58           ` Philippe Mathieu-Daudé
2023-02-13 15:09             ` Philippe Mathieu-Daudé
2023-02-13 16:36               ` BALATON Zoltan
2023-02-13 16:20             ` BALATON Zoltan
2023-02-13 16:15           ` Peter Xu
2023-02-13 16:34             ` BALATON Zoltan
2023-02-13 17:17               ` Peter Xu
2023-02-13 17:26                 ` Philippe Mathieu-Daudé
2023-02-13 18:34                 ` BALATON Zoltan
2023-02-13 21:25                   ` Peter Xu
2023-02-13 22:43                     ` BALATON Zoltan
2023-02-28 22:19                       ` BALATON Zoltan
2023-02-13 13:45 ` Philippe Mathieu-Daudé
2023-02-13 14:32   ` BALATON Zoltan
  -- strict thread matches above, loose matches on Subject: below --
2024-10-06 16:49 [PATCH 0/2] Separate memory access logs from guest_errors BALATON Zoltan
2024-10-06 16:49 ` [PATCH 1/2] log: Add separate debug option for logging invalid memory accesses BALATON Zoltan
2024-10-14 14:13   ` Peter Maydell
2024-10-14 16:48     ` BALATON Zoltan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).