qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] Mapping of the guests user and kernel pages to host mem


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] Mapping of the guests user and kernel pages to host memory
Date: Fri, 28 Jun 2019 10:12:38 +0100
User-agent: Mutt/1.12.0 (2019-05-25)

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: signature.asc
Description: PGP signature


reply via email to

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