qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: Rowan Hart <rowanbhart@gmail.com>, qemu-devel@nongnu.org
Cc: "Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH v2 1/2] plugins: add plugin API to read guest memory
Date: Tue, 27 Aug 2024 08:59:43 -0700	[thread overview]
Message-ID: <1593cf8c-d46d-43cc-afb4-b532598e96f5@linaro.org> (raw)
In-Reply-To: <20240827021847.218390-2-rowanbhart@gmail.com>

On 8/26/24 19:18, Rowan Hart wrote:
> Signed-off-by: Rowan Hart <rowanbhart@gmail.com>
> ---
>   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 c71c705b69..10f9db8cdc 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
> @@ -852,6 +860,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
> +

Missing '*' on this line, generating an error when building doc.

> + * @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 2ff13d09de..cb7d818918 100644
> --- a/plugins/api.c
> +++ b/plugins/api.c
> @@ -527,6 +527,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, 0);
> +
> +    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 ca773d8d9f..3ad479a924 100644
> --- a/plugins/qemu-plugins.symbols
> +++ b/plugins/qemu-plugins.symbols
> @@ -20,6 +20,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;

Otherwise,
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>

@Rowan, for v3, you can add this "Reviewed-by: ..." line in your commit 
message, so it shows it was reviewed.


  reply	other threads:[~2024-08-27 16:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27  2:18 [PATCH v2 0/2] plugins: add plugin API to read guest memory Rowan Hart
2024-08-27  2:18 ` [PATCH v2 1/2] " Rowan Hart
2024-08-27 15:59   ` Pierrick Bouvier [this message]
2024-08-27  2:18 ` [PATCH v2 2/2] plugins: add option to dump write argument to syscall plugin Rowan Hart
2024-08-27 16:01   ` Pierrick Bouvier

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=1593cf8c-d46d-43cc-afb4-b532598e96f5@linaro.org \
    --to=pierrick.bouvier@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=erdnaxe@crans.org \
    --cc=ma.mandourr@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rowanbhart@gmail.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).