[RFC PATCH 5/9] system/memory: Add plugin callbacks to intercept MMIO accesses

Ruslan Ruslichenko posted 9 patches 2 weeks, 5 days ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Eric Auger <eric.auger@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
[RFC PATCH 5/9] system/memory: Add plugin callbacks to intercept MMIO accesses
Posted by Ruslan Ruslichenko 2 weeks, 5 days ago
From: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>

Add plugin callback to dispatch memory_region_dispath_read/write,
allowing plugins to intercept MMIO operations before they reach
device models, which enable to spoof read values and drop write
accesses.

Signed-off-by: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
---
 system/memory.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/system/memory.c b/system/memory.c
index c51d0798a8..67a59f6e0a 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -35,6 +35,7 @@
 #include "hw/core/boards.h"
 #include "migration/vmstate.h"
 #include "system/address-spaces.h"
+#include "qemu/plugin.h"
 
 #include "memory-internal.h"
 
@@ -1448,6 +1449,10 @@ static MemTxResult memory_region_dispatch_read1(MemoryRegion *mr,
 {
     *pval = 0;
 
+
+    if (plugin_mmio_override_cb_invoke(mr->addr + addr, size, false, pval))
+        return MEMTX_OK;
+
     if (mr->ops->read) {
         return access_with_adjusted_size(addr, pval, size,
                                          mr->ops->impl.min_access_size,
@@ -1533,6 +1538,9 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,
 
     adjust_endianness(mr, &data, op);
 
+    if (plugin_mmio_override_cb_invoke(mr->addr + addr, size, true, &data))
+        return MEMTX_OK;
+
     /*
      * FIXME: it's not clear why under KVM the write would be processed
      * directly, instead of going through eventfd.  This probably should
-- 
2.43.0