qemu-discuss
[Top][All Lists]
Advanced

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

Re: How to get host virtual address from guest physical address?


From: Berto Furth
Subject: Re: How to get host virtual address from guest physical address?
Date: Mon, 07 Jun 2021 09:31:40 +1000
User-agent: Cyrus-JMAP/3.5.0-alpha0-519-g27a961944e-fm-20210531.001-g27a96194

Hi Chan,

Thanks for documenting the information below. I note you mention "you need 
cache flush in the guest for this to work."

Do you know how to trigger this from the host side? That is, how do you make 
QEMU running on the host force the guest CPU to flush it's cache? Is there a 
QEMU function that can be called to do that?

Thanks very much Chan!

Berto.

On Mon, 31 May 2021, at 16:57, ckim@etri.re.kr wrote:
> Hello, Peter Maydell,
> 
> Thanks for the help.
> I've seen that I can read the guest physical memory using 
> cpu_physical_memory_read function.
> I followed the function, but couldn't find a nicely cut 'guest physical 
> to host virtual' address conversion function.
> But I found I can do what I need (passing host virtual address to an 
> .so file) using memory_region_get_ram_ptr function (keeping the return 
> value and adding the offset from the start of known memory region to 
> it).
> 
> This is for others why might get help from here : 
> I passed the guest physical address to a register write function, and I 
> can use the register value to access the guess memory like below.
>         uint64_t membuf;
>         cpu_physical_memory_read(guest_phys_addr, &membuf, 8);   // you 
> need cache flush in the guest for this to work.
> I've also seen that I can keep the start address (host virtual address 
> seen from qemu) of a guest memory region like below after you do 
> memory_region_init_ram().
>          ram_ptr = memory_region_get_ram_ptr(my_memory_region);
> 
> Thank you!
> Chan Kim
> 
> > -----Original Message-----
> > From: Peter Maydell <peter.maydell@linaro.org>
> > Sent: Friday, May 28, 2021 11:37 PM
> > To: Chan Kim <ckim@etri.re.kr>
> > Cc: qemu-discuss <qemu-discuss@nongnu.org>
> > Subject: Re: How to get host virtual address from guest physical address?
> > 
> > On Fri, 28 May 2021 at 03:50, <ckim@etri.re.kr> wrote:
> > > In my baremetal test on aarch64, I pass the guest physical address of an
> > array of a structure to the qemu peripheral code using peripherals
> > register.
> > >
> > > I soon realized the adderss is from another world and to access this
> > address in qemu, I need the host virtual address.
> > >
> > > I tried reading the document (and will read more) but it shows the load
> > and store APIs, and not the address translation API.
> > >
> > > I need that address because I have to pass the “address” to a function
> > in a dynamic library ( a .so file). I don’t myself load or store using
> > that address.
> > >
> > > What is the function for this “guest physical address to host virtual
> > address” translation?
> > 
> > There is address_space_map(), but watch out for the caveats documented in
> > its doc comment in memory.h.
> > 
> > thanks
> > -- PMM
> 
> 
> 
> 
> 
> 



reply via email to

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