qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Mapping of the guests user and kernel pages to host memory
@ 2019-06-16 13:48 Dimitris Karnikis
  2019-06-28  9:12 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Dimitris Karnikis @ 2019-06-16 13:48 UTC (permalink / raw)
  To: qemu-devel

Hello,
I am interested in understanding on how QEMU maps the user and kernel
pages of a guest OS to the host OS memory (working on 3.1.0 but any 
version is acceptable with target x86-64 arch).
Since QEMU runs on user space, these pages will be also mapped on the 
user space of the host machine. So my question here is, where do the 
allocations take place, and in which place of the source code I could 
find the mapping.

Thank you for your time,
Dimitris

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] Mapping of the guests user and kernel pages to host memory
  2019-06-16 13:48 [Qemu-devel] Mapping of the guests user and kernel pages to host memory Dimitris Karnikis
@ 2019-06-28  9:12 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2019-06-28  9:12 UTC (permalink / raw)
  To: Dimitris Karnikis; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]

On Sun, Jun 16, 2019 at 04:48:55PM +0300, Dimitris Karnikis wrote:
> I am interested in understanding on how QEMU maps the user and kernel
> pages of a guest OS to the host OS memory (working on 3.1.0 but any version
> is acceptable with target x86-64 arch).
> Since QEMU runs on user space, these pages will be also mapped on the user
> space of the host machine. So my question here is, where do the allocations
> take place, and in which place of the source code I could find the mapping.

The QEMU host userspace process allocates guest RAM or mmaps from a
given file (e.g. /dev/hugepages/).  QEMU keeps track of them using the
RAMBlock structure.

The guest physical memory map is defined using the memory.h API.  The
memory map consists of MemoryRegions pointing to guest RAM (or emulated
devices for MMIO/PIO hardware registers).

The APIs for accessing guest RAM are address_space_read/write(),
address_space_ld/st(), or memory_region_get_ram_ptr().  It's that last
function that can be used to translate a guest physical address to a
host virtual memory address.

For more info, see
http://blog.vmsplice.net/2016/01/qemu-internals-how-guest-physical-ram.html.

The guest CPU's memory management unit may support pagetables,
segmentation, or other memory translation mechanisms that translate
guest virtual addresses to guest physical addresses.  This is especially
relevant when the TCG just-in-time compiler is used to translate machine
instructions because it needs to implement a software MMU.  When
virtualization is used the guest MMU is implemented mostly in hardware.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-28  9:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-16 13:48 [Qemu-devel] Mapping of the guests user and kernel pages to host memory Dimitris Karnikis
2019-06-28  9:12 ` Stefan Hajnoczi

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).