[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] TCG plugin API extension to read guest memory content by an
From: |
Peter Maydell |
Subject: |
Re: [PATCH] TCG plugin API extension to read guest memory content by an address |
Date: |
Thu, 16 Feb 2023 16:42:02 +0000 |
On Thu, 16 Feb 2023 at 16:18, Mikhail Tyutin <m.tyutin@yadro.com> wrote:
>
> 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_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);
This is the wrong API to use, because "physical memory at
address X" can differ depending on what CPU you are and
what state that CPU is in.
> +#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);
> + }
These ones are a bit better.
> +#endif
> +}
> \ No newline at end of file
-- PMM