From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
devel@lists.libvirt.org, "Thomas Huth" <thuth@redhat.com>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
qemu-ppc@nongnu.org, "Zhao Liu" <zhao1.liu@intel.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
qemu-s390x@nongnu.org, "Alexandre Iooss" <erdnaxe@crans.org>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Rowan Hart" <rowanbhart@gmail.com>
Subject: [PATCH 16/17] plugins: add plugin API to read guest memory
Date: Fri, 13 Sep 2024 18:26:54 +0100 [thread overview]
Message-ID: <20240913172655.173873-17-alex.bennee@linaro.org> (raw)
In-Reply-To: <20240913172655.173873-1-alex.bennee@linaro.org>
From: Rowan Hart <rowanbhart@gmail.com>
Signed-off-by: Rowan Hart <rowanbhart@gmail.com>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Message-Id: <20240827215329.248434-2-rowanbhart@gmail.com>
[AJB: tweaked cpu_memory_rw_debug call]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
vAJB:
- explicit bool for cpu_memory_rw_debug
---
include/qemu/qemu-plugin.h | 32 +++++++++++++++++++++++++++++++-
plugins/api.c | 20 ++++++++++++++++++++
plugins/qemu-plugins.symbols | 1 +
3 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index 649ce89815..2015d6b409 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -57,11 +57,19 @@ typedef uint64_t qemu_plugin_id_t;
* - Remove qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline.
* Those functions are replaced by *_per_vcpu variants, which guarantee
* thread-safety for operations.
+ *
+ * version 3:
+ * - modified arguments and return value of qemu_plugin_insn_data to copy
+ * the data into a user-provided buffer instead of returning a pointer
+ * to the data.
+ *
+ * version 4:
+ * - added qemu_plugin_read_memory_vaddr
*/
extern QEMU_PLUGIN_EXPORT int qemu_plugin_version;
-#define QEMU_PLUGIN_VERSION 3
+#define QEMU_PLUGIN_VERSION 4
/**
* struct qemu_info_t - system information for plugins
@@ -884,6 +892,28 @@ typedef struct {
QEMU_PLUGIN_API
GArray *qemu_plugin_get_registers(void);
+/**
+ * qemu_plugin_read_memory_vaddr() - read from memory using a virtual address
+ *
+ * @addr: A virtual address to read from
+ * @data: A byte array to store data into
+ * @len: The number of bytes to read, starting from @addr
+ *
+ * @len bytes of data is read starting at @addr and stored into @data. If @data
+ * is not large enough to hold @len bytes, it will be expanded to the necessary
+ * size, reallocating if necessary. @len must be greater than 0.
+ *
+ * This function does not ensure writes are flushed prior to reading, so
+ * callers should take care when calling this function in plugin callbacks to
+ * avoid attempting to read data which may not yet be written and should use
+ * the memory callback API instead.
+ *
+ * Returns true on success and false on failure.
+ */
+QEMU_PLUGIN_API
+bool qemu_plugin_read_memory_vaddr(uint64_t addr,
+ GByteArray *data, size_t len);
+
/**
* qemu_plugin_read_register() - read register for current vCPU
*
diff --git a/plugins/api.c b/plugins/api.c
index 3316d4a04d..24ea64e2de 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -560,6 +560,26 @@ GArray *qemu_plugin_get_registers(void)
return create_register_handles(regs);
}
+bool qemu_plugin_read_memory_vaddr(vaddr addr, GByteArray *data, size_t len)
+{
+ g_assert(current_cpu);
+
+ if (len == 0) {
+ return false;
+ }
+
+ g_byte_array_set_size(data, len);
+
+ int result = cpu_memory_rw_debug(current_cpu, addr, data->data,
+ data->len, false);
+
+ if (result < 0) {
+ return false;
+ }
+
+ return true;
+}
+
int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray *buf)
{
g_assert(current_cpu);
diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols
index eed9d8abd9..032661f9ea 100644
--- a/plugins/qemu-plugins.symbols
+++ b/plugins/qemu-plugins.symbols
@@ -21,6 +21,7 @@
qemu_plugin_num_vcpus;
qemu_plugin_outs;
qemu_plugin_path_to_binary;
+ qemu_plugin_read_memory_vaddr;
qemu_plugin_read_register;
qemu_plugin_register_atexit_cb;
qemu_plugin_register_flush_cb;
--
2.39.2
next prev parent reply other threads:[~2024-09-13 17:35 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-13 17:26 [PATCH 00/17] tcg plugins pre-PR (deprecations, mem apis, contrib plugins) Alex Bennée
2024-09-13 17:26 ` [PATCH 01/17] deprecation: don't enable TCG plugins by default on 32 bit hosts Alex Bennée
2024-09-13 17:26 ` [PATCH 02/17] deprecation: don't enable TCG plugins by default with TCI Alex Bennée
2024-09-13 17:26 ` [PATCH 03/17] contrib/plugins: control flow plugin Alex Bennée
2024-09-13 17:26 ` [PATCH 04/17] plugins: save value during memory accesses Alex Bennée
2024-09-13 17:26 ` [PATCH 05/17] plugins: extend API to get latest memory value accessed Alex Bennée
2024-09-13 17:26 ` [PATCH 06/17] tests/tcg: add mechanism to run specific tests with plugins Alex Bennée
2024-09-13 17:26 ` [PATCH 07/17] tests/tcg: allow to check output of plugins Alex Bennée
2024-09-13 17:26 ` [PATCH 08/17] tests/tcg/plugins/mem: add option to print memory accesses Alex Bennée
2024-09-13 17:26 ` [PATCH 09/17] tests/tcg/multiarch: add test for plugin memory access Alex Bennée
2024-09-13 17:26 ` [PATCH 10/17] tests/tcg: clean up output of memory system test Alex Bennée
2024-09-13 17:26 ` [PATCH 11/17] tests/tcg: only read/write 64 bit words on 64 bit systems Alex Bennée
2024-09-13 20:15 ` Philippe Mathieu-Daudé
2024-09-16 8:41 ` Alex Bennée
2024-09-13 17:26 ` [PATCH 12/17] tests/tcg: ensure s390x-softmmu output redirected Alex Bennée
2024-09-16 5:27 ` Thomas Huth
2024-09-16 8:37 ` Alex Bennée
2024-09-13 17:26 ` [PATCH 13/17] tests/tcg: add a system test to check memory instrumentation Alex Bennée
2024-09-13 17:26 ` [PATCH 14/17] util/timer: avoid deadlock when shutting down Alex Bennée
2024-09-13 17:26 ` [PATCH 15/17] contrib/plugins: Add a plugin to generate basic block vectors Alex Bennée
2024-09-13 17:26 ` Alex Bennée [this message]
2024-09-13 20:17 ` [PATCH 16/17] plugins: add plugin API to read guest memory Philippe Mathieu-Daudé
2024-09-13 17:26 ` [PATCH 17/17] plugins: add option to dump write argument to syscall plugin Alex Bennée
2024-09-13 20:18 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240913172655.173873-17-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=danielhb413@gmail.com \
--cc=david@redhat.com \
--cc=devel@lists.libvirt.org \
--cc=eduardo@habkost.net \
--cc=erdnaxe@crans.org \
--cc=iii@linux.ibm.com \
--cc=ma.mandourr@gmail.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=npiggin@gmail.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=rowanbhart@gmail.com \
--cc=thuth@redhat.com \
--cc=wangyanan55@huawei.com \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).