qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Get host virtual address corresponding to guest physica


From: Peter Maydell
Subject: Re: [Qemu-devel] Get host virtual address corresponding to guest physical address?
Date: Sat, 25 Aug 2012 11:56:13 +0100

On 24 August 2012 04:14, 陳韋任 (Wei-Ren Chen) <address@hidden> wrote:
>   I would like to know if there is a function in QEMU which converts
> a guest physical address into corresponding host virtual address.

So the question is, what do you want to do with the host virtual
address when you've got it? cpu_physical_memory_map() is really intended
(as Blue says) for the case where you have a bit of host code that wants
to write a chunk of data and doesn't want to do a sequence of
cpu_physical_memory_read()/_write() calls. Instead you _map() the memory,
write to it and then _unmap() it.

Note that not all guest physical addresses have a meaningful host
virtual address -- in particular memory mapped devices won't.

>   1. I am running x86 guest on a x86_64 host and using the cod below
>      to get the host virtual address, I am not sure what value of len
>      should be.

The length should be the length of the area of memory you want to
either read or write from.

>         static inline void *gpa2hva(target_phys_addr_t addr)
>         {
>             target_phys_addr_t len = 4;
>             return cpu_physical_memory_map(addr, &len, 0);
>         }

If you try this on a memory mapped device address then the first
time round it will give you back the address of a "bounce buffer",
ie a bit of temporary RAM you can read/write and which unmap will
then actually feed to the device's read/write functions. Since you
never call unmap, this means that anybody else who tries to use
cpu_physical_memory_map() on a device from now on will get back
NULL (meaning resource exhaustion, because the bouncebuffer is in
use).

-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]