yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-softmmu-memory-Log-invalid-memory-accesses.patch

dc7afb
From be0a190e3c5c4ff84f7c53630ed5a55644d18acc Mon Sep 17 00:00:00 2001
dc7afb
From: Jon Maloy <jmaloy@redhat.com>
dc7afb
Date: Wed, 21 Apr 2021 22:30:06 -0400
dc7afb
Subject: [PATCH 7/7] softmmu/memory: Log invalid memory accesses
dc7afb
MIME-Version: 1.0
dc7afb
Content-Type: text/plain; charset=UTF-8
dc7afb
Content-Transfer-Encoding: 8bit
dc7afb
dc7afb
RH-Author: Jon Maloy <jmaloy@redhat.com>
dc7afb
Message-id: <20210421223006.19650-7-jmaloy@redhat.com>
dc7afb
Patchwork-id: 101481
dc7afb
O-Subject: [RHEL-8.5.0 qemu-kvm PATCH v2 6/6] softmmu/memory: Log invalid memory accesses
dc7afb
Bugzilla: 1842478
dc7afb
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
dc7afb
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
dc7afb
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
dc7afb
dc7afb
From: Philippe Mathieu-Daudé <philmd@redhat.com>
dc7afb
dc7afb
Log invalid memory accesses with as GUEST_ERROR.
dc7afb
dc7afb
This is particularly useful since commit 5d971f9e67 which reverted
dc7afb
("memory: accept mismatching sizes in memory_region_access_valid").
dc7afb
dc7afb
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
dc7afb
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
dc7afb
Message-Id: <20201005152725.2143444-1-philmd@redhat.com>
dc7afb
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
dc7afb
dc7afb
(cherry picked from commit 21786c7e59847b1612406ff394958f22e5b323f8)
dc7afb
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
dc7afb
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
dc7afb
---
dc7afb
 memory.c | 16 ++++++++++++++++
dc7afb
 1 file changed, 16 insertions(+)
dc7afb
dc7afb
diff --git a/memory.c b/memory.c
dc7afb
index 0cfcb72a5a..660df8159a 100644
dc7afb
--- a/memory.c
dc7afb
+++ b/memory.c
dc7afb
@@ -14,6 +14,7 @@
dc7afb
  */
dc7afb
 
dc7afb
 #include "qemu/osdep.h"
dc7afb
+#include "qemu/log.h"
dc7afb
 #include "qapi/error.h"
dc7afb
 #include "cpu.h"
dc7afb
 #include "exec/memory.h"
dc7afb
@@ -1353,10 +1354,18 @@ bool memory_region_access_valid(MemoryRegion *mr,
dc7afb
 {
dc7afb
     if (mr->ops->valid.accepts
dc7afb
         && !mr->ops->valid.accepts(mr->opaque, addr, size, is_write, attrs)) {
dc7afb
+        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
dc7afb
+                                       "0x%" HWADDR_PRIX ", size %u, "
dc7afb
+                                       "region '%s', reason: rejected\n",
dc7afb
+                      addr, size, memory_region_name(mr));
dc7afb
         return false;
dc7afb
     }
dc7afb
 
dc7afb
     if (!mr->ops->valid.unaligned && (addr & (size - 1))) {
dc7afb
+        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
dc7afb
+                                       "0x%" HWADDR_PRIX ", size %u, "
dc7afb
+                                       "region '%s', reason: unaligned\n",
dc7afb
+                      addr, size, memory_region_name(mr));
dc7afb
         return false;
dc7afb
     }
dc7afb
 
dc7afb
@@ -1367,6 +1376,13 @@ bool memory_region_access_valid(MemoryRegion *mr,
dc7afb
 
dc7afb
     if (size > mr->ops->valid.max_access_size
dc7afb
         || size < mr->ops->valid.min_access_size) {
dc7afb
+        qemu_log_mask(LOG_GUEST_ERROR, "Invalid access at addr "
dc7afb
+                                       "0x%" HWADDR_PRIX ", size %u, "
dc7afb
+                                       "region '%s', reason: invalid size "
dc7afb
+                                       "(min:%u max:%u)\n",
dc7afb
+                      addr, size, memory_region_name(mr),
dc7afb
+                      mr->ops->valid.min_access_size,
dc7afb
+                      mr->ops->valid.max_access_size);
dc7afb
         return false;
dc7afb
     }
dc7afb
     return true;
dc7afb
-- 
dc7afb
2.27.0
dc7afb