All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] TCG plugin API extension to read guest memory content by an address
@ 2023-02-16 16:18 Mikhail Tyutin
  2023-02-16 16:30 ` Alex Bennée
  2023-02-16 16:42 ` Peter Maydell
  0 siblings, 2 replies; 3+ messages in thread
From: Mikhail Tyutin @ 2023-02-16 16:18 UTC (permalink / raw)
  To: qemu-devel@nongnu.org
  Cc: alex.bennee@linaro.org, erdnaxe@crans.org, ma.mandourr@gmail.com

TCG plugin API extension to read guest memory content. qemu_plugin_vcpu_read_phys_mem()
function can be used by TCG plugin inside of qemu_plugin_vcpu_mem_cb_t callback to adjust
received address according to internal memory mappings and read content of guest memory.
Works for both user-level and system-level emulation modes.

Signed-off-by: Mikhail Tyutin <m.tyutin@yadro.com>
Signed-off-by: Aleksey Titov <a.titov@yadro.com>
---
QEMU_PLUGIN_READ_PHYS_MEM_ENABLED define below is to let plugins to check if this API
is available in Qemu build.

  include/qemu/qemu-plugin.h   | 18 ++++++++++++++++++
  plugins/api.c                | 20 ++++++++++++++++++++
  plugins/qemu-plugins.symbols |  1 +
  3 files changed, 39 insertions(+)

diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index d0e9d03adf..576597f601 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -625,4 +625,22 @@ uint64_t qemu_plugin_end_code(void);
   */
  uint64_t qemu_plugin_entry_code(void);
  
+
+#define QEMU_PLUGIN_READ_PHYS_MEM_ENABLED
+/**
+ * qemu_plugin_vcpu_read_phys_mem() - reads guest's memory content
+ *
+ * @vcpu_index: vcpu index
+ * @addr: guest's virtual address
+ * @buf: destination buffer to read data to
+ * @len: number of bytes to read
+ *
+ * Adjusts address according to internal memory mapping and reads
+ * content of guest memory.
+ */
+void qemu_plugin_vcpu_read_phys_mem(unsigned int vcpu_index,
+                                    uint64_t addr,
+                                    void *buf,
+                                    uint64_t len);
+
  #endif /* QEMU_QEMU_PLUGIN_H */
diff --git a/plugins/api.c b/plugins/api.c
index 2078b16edb..95753bce95 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -442,3 +442,23 @@ uint64_t qemu_plugin_entry_code(void)
  #endif
      return entry;
  }
+
+void qemu_plugin_vcpu_read_phys_mem(unsigned int vcpu_index,
+                                    uint64_t addr,
+                                    void *buf,
+                                    uint64_t len) {
+#ifndef CONFIG_USER_ONLY
+    cpu_physical_memory_rw(addr, buf, len, false);
+#else
+    CPUClass *cc;
+    CPUState *cpu;
+
+    cpu = qemu_get_cpu(vcpu_index);
+    cc = CPU_GET_CLASS(cpu);
+    if (cc->memory_rw_debug) {
+        cc->memory_rw_debug(cpu, addr, buf, len, false);
+    } else {
+        cpu_memory_rw_debug(cpu, addr, buf, len, false);
+    }
+#endif
+}
\ No newline at end of file
diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols
index 71f6c90549..f0ce8c730f 100644
--- a/plugins/qemu-plugins.symbols
+++ b/plugins/qemu-plugins.symbols
@@ -42,4 +42,5 @@
    qemu_plugin_tb_vaddr;
    qemu_plugin_uninstall;
    qemu_plugin_vcpu_for_each;
+  qemu_plugin_vcpu_read_phys_mem;
  };
-- 
2.34.1

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

end of thread, other threads:[~2023-02-16 16:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-16 16:18 [PATCH] TCG plugin API extension to read guest memory content by an address Mikhail Tyutin
2023-02-16 16:30 ` Alex Bennée
2023-02-16 16:42 ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.