qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Julian Ganz <neither@nut.email>
To: Rowan Hart <rowanbhart@gmail.com>
Cc: "Julian Ganz" <neither@nut.email>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v3 5/8] Add memory hardware address read/write API
Date: Thu, 22 May 2025 13:59:32 +0200	[thread overview]
Message-ID: <20250522115935.34716-3-neither@nut.email> (raw)
In-Reply-To: <20250521094333.4075796-6-rowanbhart@gmail.com>

Hi Rowan,

> diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
> index eff8430b4a..d4f229abd9 100644
> --- a/include/qemu/qemu-plugin.h
> +++ b/include/qemu/qemu-plugin.h
> @@ -1014,6 +1014,102 @@ QEMU_PLUGIN_API
>  bool qemu_plugin_write_memory_vaddr(uint64_t addr,
>                                     GByteArray *data);
>  
> <snip>
> +/**
> + * qemu_plugin_translate_vaddr() - translate a virtual address to a physical one
> + *
> + * @vaddr: virtual address to translate
> + * @hwaddr: pointer to store the physical address
> + *
> + * This function is only valid in vCPU context (i.e. in callbacks) and is only
> + * valid for softmmu targets.
> + *
> + * Returns true on success and false on failure.
> + */
> +QEMU_PLUGIN_API
> +bool qemu_plugin_translate_vaddr(uint64_t vaddr, uint64_t *hwaddr);

As a (testing) plugin author, I'm quite interested in this function in
particular. For the next iteration, would you be willing to split this
one out into its own patch? This would enhance the chance of it getting
picked up even if other parts of the series should not make it.

> diff --git a/plugins/api.c b/plugins/api.c
> index 19c10bb39e..5983768783 100644
> --- a/plugins/api.c
> +++ b/plugins/api.c
> @@ -569,6 +569,106 @@ bool qemu_plugin_write_memory_vaddr(uint64_t addr, GByteArray *data)
> <snip> 
> +bool qemu_plugin_translate_vaddr(uint64_t vaddr, uint64_t *hwaddr)
> +{
> +#ifdef CONFIG_SOFTMMU
> +    g_assert(current_cpu);
> +
> +    CPUState *cpu = current_cpu;
> +
> +    uint64_t res = cpu_get_phys_page_debug(cpu, vaddr);
> +
> +    if (res == (uint64_t)-1) {
> +        return false;
> +    }
> +
> +    *hwaddr = res | (vaddr & ~TARGET_PAGE_MASK);
> +
> +    return true;
> +#else
> +    return false;
> +#endif
> +}

This definition strikes me as odd. What was your reason to assert
`current_cpu` here, but not in the other two functions? Also a bit
surprising is the declaration of `cpu` if you use it in just one place
(rather than just use `current_cpu` directly as for the assertion).

And there is no reason in particular why the vCPU could not be a
function parameter of `qemu_plugin_translate_vaddr`, right? You don't
have the same restrictions as in `qemu_plugin_read_memory_hwaddr` or
`qemu_plugin_hwaddr_operation_result` where you actually touch memory?

Regards,
Julian


  parent reply	other threads:[~2025-05-22 12:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-21  9:43 [PATCH v3 0/8] Add additional plugin API functions to read and write memory and registers Rowan Hart
2025-05-21  9:43 ` [PATCH v3 1/8] Expose gdb_write_register function to consumers of gdbstub Rowan Hart
2025-05-21 22:52   ` Pierrick Bouvier
2025-05-22  8:53   ` Manos Pitsidianakis
2025-05-22 11:59   ` Julian Ganz
2025-05-21  9:43 ` [PATCH v3 2/8] Add register write API Rowan Hart
2025-05-21 22:52   ` Pierrick Bouvier
2025-05-22 11:59   ` Julian Ganz
2025-05-22 15:02     ` Rowan Hart
2025-05-22 15:16       ` Julian Ganz
2025-05-22 15:39   ` Alex Bennée
2025-05-22 20:11     ` Rowan Hart
2025-05-21  9:43 ` [PATCH v3 3/8] Add address space API Rowan Hart
2025-05-21  9:43 ` [PATCH v3 4/8] Add memory virtual address write API Rowan Hart
2025-05-21 22:53   ` Pierrick Bouvier
2025-05-21  9:43 ` [PATCH v3 5/8] Add memory hardware address read/write API Rowan Hart
2025-05-21 23:18   ` Pierrick Bouvier
2025-05-22  3:34     ` Rowan Hart
2025-05-22 19:46       ` Pierrick Bouvier
2025-05-22 11:59   ` Julian Ganz [this message]
2025-05-22 19:16     ` Pierrick Bouvier
2025-05-22 21:01       ` Rowan Hart
2025-05-22 22:37         ` Pierrick Bouvier
2025-05-21  9:43 ` [PATCH v3 6/8] Add patcher plugin and test Rowan Hart
2025-05-21  9:43 ` [PATCH v3 7/8] Add hypercalls " Rowan Hart
2025-05-21  9:43 ` [PATCH v3 8/8] Update plugin version and add notes Rowan Hart

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=20250522115935.34716-3-neither@nut.email \
    --to=neither@nut.email \
    --cc=alex.bennee@linaro.org \
    --cc=eduardo@habkost.net \
    --cc=erdnaxe@crans.org \
    --cc=ma.mandourr@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).