All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Anthony Perard <anthony.perard@citrix.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Xen Devel <xen-devel@lists.xensource.com>,
	QEMU-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH V2 5/5] vga-cirrus: Workaround during restore when using Xen.
Date: Thu, 05 Jan 2012 14:50:20 +0200	[thread overview]
Message-ID: <4F059C8C.2030303@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1201051134150.3150@kaball-desktop>

On 01/05/2012 02:30 PM, Stefano Stabellini wrote:
> > >
> > > I cannot see how this is going to fix the save/restore issue we are
> > > trying to solve.
> > > The problem, unfortunately very complex, is that at restore time the
> > > videoram is already allocated at the physical address it was mapped
> > > before the save operation. If it was not mapped, it is at the end of the
> > > physical memory of the guest (where qemu_ram_alloc_from_ptr decides to
> > > allocate it).
> > 
> > Sorry, I don't follow, please be specific as to which type of address
> > you're referring to:
> > 
> > ram_addr?
> > physical address (as seen by guest - but if it is not mapped, what does
> > your last sentence mean?)
> > something else?
>
> ram_addr_t as returned by qemu_ram_alloc_from_ptr.
>
> In fact on xen qemu_ram_alloc_from_ptr asks the hypervisor to add
> the specified amount of memory to the guest physmap at
> new_block->offset. So in a way the videoram is always visible by the
> guest, initially at new_block->offset, chosen by find_ram_offset, then
> at cirrus_bank_base, when map_linear_vram_bank is called.

Okay.  So we will need to hook this differently from the memory API.

There are two places we can hook:
- memory_region_init_ram() - similar to qemu_ram_alloc() - at region
construction time
- MemoryListener::region_add() - called the first time the region is
made visible, probably not what we want

> > > So the issue is that the videoram appears to qemu as part of the
> > > physical memory of the guest at an unknown address.
> > >
> > > The proposal of introducing early_savevm would easily solve this last
> > > problem: letting us know where the videoram is. The other problem, the
> > > fact that under Xen the videoram would be already allocated while under
> > > native it would not, remains unsolved. 
> > > We cannot simply allocate the videoram twice because the operation
> > > would fail (Xen would realize that we are trying to allocate more memory
> > > than it we are supposed to, returning an error).
> > > However, once we know where the videoram is, we could probably figure out
> > > a smart (see hacky) way to avoid allocating it twice without changes to
> > > the cirrus code.
> > 
> > I'm missing some context.  Can you please explain in more detail?
> > Note that with the memory API changes, ram addresses are going away. 
> > There will not be a linear space for guest RAM.  We'll have
> > (MemoryRegion *, offset) pairs that will be mapped into discontiguous
> > guest physical address ranges (perhaps with overlaps).
>
>
> This is how memory is currently allocated and mapped in qemu on xen:
>
> - qemu_ram_alloc_from_ptr asks the hypervisor to allocate memory for
> the guest, the memory is added to the guest p2m (physical to machine
> translation table) at the given guest physical address
> (new_block->offset, as chosen by find_ram_offset);
>
> - qemu_get_ram_ptr uses the xen mapcache to map guest physical address
> ranges into qemu's address space, so that qemu can read/write guest
> memory;
>
> - xen_set_memory, called by the memory_listener interface, effectively
> moves a guest physical memory address range from one address to another.
> So the memory that was initially allocated at new_block->offset, as
> chosen by find_ram_offset, is going to be moved to a new destination,
> section->offset_within_address_space.

So, where qemu has two different address spaces (ram_addr_t and guest
physical addresses), Xen has just one, and any time the translation
between the two changes, you have to move memory around.


> So the videoram lifecycle is the following:
>
> - qemu_ram_alloc_from_ptr allocates the videoram and adds it to the end
>   of the physmap;
>
> - qemu_get_ram_ptr maps the videoram into qemu's address space;
>
> - xen_set_memory moves the videoram to cirrus_bank_base;
>
>
>
> Now let's introduce save/restore into the picture: the videoram is part
> of the guest's memory from the hypervisor POV, so xen will take care of
> saving and restoring it as part of the normal guest memory, out of
> qemu's control.
> At restore time, we know that the videoram is already allocated and
> mapped somewhere in the guest physical address space: it could be
> cirrus_bank_base, which we don't know yet, or the initial
> new_block->offset.
> A second videoram allocation by qemu_ram_alloc_from_ptr will fail
> because of memory constraints enforced by the hypervisor. Trying to map
> the already allocated videoram into qemu's address space is not easy
> because we don't know where it is yet (keep in mind that machine->init
> is called before the machine restore functions).
>
> The "solution" I am proposing is introducing an early_savevm set of
> save/restore functions so that at restore time we can get to know at
> what address the videoram is mapped into the guest address space. Once we
> know the address we can remap it into qemu's address space and/or move it
> to another guest physical address.

Why can we not simply track it?  For every MemoryRegion, have a field
called xen_address which tracks its location in the Xen address space
(as determined by the last call to xen_set_memory or qemu_ram_alloc). 
xen_address would be maintained by callbacks called from the memory API
into xen-all.c.

> The problem of avoiding a second allocation remains, but could be
> solved by passing the "name" parameter from qemu_ram_alloc_from_ptr to
> xen_ram_alloc: xen_ram_alloc could avoid doing any work for anything
> called "vga.vram" at restore time, and use the reference to the already
> allocated videoram instead.

Hacky.  The allocation is not driven by qemu then?

For the long term I suggest making qemu control the allocations (perhaps
by rpcing dom0); otherwise how can you do memory hotplug or PCI cards
with RAM (like ivshmem)?

-- 
error compiling committee.c: too many arguments to function

WARNING: multiple messages have this Message-ID (diff)
From: Avi Kivity <avi@redhat.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Anthony Perard <anthony.perard@citrix.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Xen Devel <xen-devel@lists.xensource.com>,
	QEMU-devel <qemu-devel@nongnu.org>
Subject: Re: [PATCH V2 5/5] vga-cirrus: Workaround during restore when using Xen.
Date: Thu, 05 Jan 2012 14:50:20 +0200	[thread overview]
Message-ID: <4F059C8C.2030303@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1201051134150.3150@kaball-desktop>

On 01/05/2012 02:30 PM, Stefano Stabellini wrote:
> > >
> > > I cannot see how this is going to fix the save/restore issue we are
> > > trying to solve.
> > > The problem, unfortunately very complex, is that at restore time the
> > > videoram is already allocated at the physical address it was mapped
> > > before the save operation. If it was not mapped, it is at the end of the
> > > physical memory of the guest (where qemu_ram_alloc_from_ptr decides to
> > > allocate it).
> > 
> > Sorry, I don't follow, please be specific as to which type of address
> > you're referring to:
> > 
> > ram_addr?
> > physical address (as seen by guest - but if it is not mapped, what does
> > your last sentence mean?)
> > something else?
>
> ram_addr_t as returned by qemu_ram_alloc_from_ptr.
>
> In fact on xen qemu_ram_alloc_from_ptr asks the hypervisor to add
> the specified amount of memory to the guest physmap at
> new_block->offset. So in a way the videoram is always visible by the
> guest, initially at new_block->offset, chosen by find_ram_offset, then
> at cirrus_bank_base, when map_linear_vram_bank is called.

Okay.  So we will need to hook this differently from the memory API.

There are two places we can hook:
- memory_region_init_ram() - similar to qemu_ram_alloc() - at region
construction time
- MemoryListener::region_add() - called the first time the region is
made visible, probably not what we want

> > > So the issue is that the videoram appears to qemu as part of the
> > > physical memory of the guest at an unknown address.
> > >
> > > The proposal of introducing early_savevm would easily solve this last
> > > problem: letting us know where the videoram is. The other problem, the
> > > fact that under Xen the videoram would be already allocated while under
> > > native it would not, remains unsolved. 
> > > We cannot simply allocate the videoram twice because the operation
> > > would fail (Xen would realize that we are trying to allocate more memory
> > > than it we are supposed to, returning an error).
> > > However, once we know where the videoram is, we could probably figure out
> > > a smart (see hacky) way to avoid allocating it twice without changes to
> > > the cirrus code.
> > 
> > I'm missing some context.  Can you please explain in more detail?
> > Note that with the memory API changes, ram addresses are going away. 
> > There will not be a linear space for guest RAM.  We'll have
> > (MemoryRegion *, offset) pairs that will be mapped into discontiguous
> > guest physical address ranges (perhaps with overlaps).
>
>
> This is how memory is currently allocated and mapped in qemu on xen:
>
> - qemu_ram_alloc_from_ptr asks the hypervisor to allocate memory for
> the guest, the memory is added to the guest p2m (physical to machine
> translation table) at the given guest physical address
> (new_block->offset, as chosen by find_ram_offset);
>
> - qemu_get_ram_ptr uses the xen mapcache to map guest physical address
> ranges into qemu's address space, so that qemu can read/write guest
> memory;
>
> - xen_set_memory, called by the memory_listener interface, effectively
> moves a guest physical memory address range from one address to another.
> So the memory that was initially allocated at new_block->offset, as
> chosen by find_ram_offset, is going to be moved to a new destination,
> section->offset_within_address_space.

So, where qemu has two different address spaces (ram_addr_t and guest
physical addresses), Xen has just one, and any time the translation
between the two changes, you have to move memory around.


> So the videoram lifecycle is the following:
>
> - qemu_ram_alloc_from_ptr allocates the videoram and adds it to the end
>   of the physmap;
>
> - qemu_get_ram_ptr maps the videoram into qemu's address space;
>
> - xen_set_memory moves the videoram to cirrus_bank_base;
>
>
>
> Now let's introduce save/restore into the picture: the videoram is part
> of the guest's memory from the hypervisor POV, so xen will take care of
> saving and restoring it as part of the normal guest memory, out of
> qemu's control.
> At restore time, we know that the videoram is already allocated and
> mapped somewhere in the guest physical address space: it could be
> cirrus_bank_base, which we don't know yet, or the initial
> new_block->offset.
> A second videoram allocation by qemu_ram_alloc_from_ptr will fail
> because of memory constraints enforced by the hypervisor. Trying to map
> the already allocated videoram into qemu's address space is not easy
> because we don't know where it is yet (keep in mind that machine->init
> is called before the machine restore functions).
>
> The "solution" I am proposing is introducing an early_savevm set of
> save/restore functions so that at restore time we can get to know at
> what address the videoram is mapped into the guest address space. Once we
> know the address we can remap it into qemu's address space and/or move it
> to another guest physical address.

Why can we not simply track it?  For every MemoryRegion, have a field
called xen_address which tracks its location in the Xen address space
(as determined by the last call to xen_set_memory or qemu_ram_alloc). 
xen_address would be maintained by callbacks called from the memory API
into xen-all.c.

> The problem of avoiding a second allocation remains, but could be
> solved by passing the "name" parameter from qemu_ram_alloc_from_ptr to
> xen_ram_alloc: xen_ram_alloc could avoid doing any work for anything
> called "vga.vram" at restore time, and use the reference to the already
> allocated videoram instead.

Hacky.  The allocation is not driven by qemu then?

For the long term I suggest making qemu control the allocations (perhaps
by rpcing dom0); otherwise how can you do memory hotplug or PCI cards
with RAM (like ivshmem)?

-- 
error compiling committee.c: too many arguments to function

  reply	other threads:[~2012-01-05 12:50 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-09 21:54 [Qemu-devel] [PATCH V2 0/5] Have a working migration with Xen Anthony PERARD
2011-12-09 21:54 ` Anthony PERARD
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 1/5] vl.c: Do not save RAM state when Xen is used Anthony PERARD
2011-12-09 21:54   ` Anthony PERARD
2011-12-15 15:12   ` [Qemu-devel] " Anthony Liguori
2011-12-15 15:12     ` Anthony Liguori
2011-12-18 17:44     ` [Qemu-devel] " Avi Kivity
2011-12-18 17:44       ` Avi Kivity
2011-12-20 16:46       ` [Qemu-devel] " Anthony PERARD
2011-12-20 16:46         ` Anthony PERARD
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 2/5] xen mapcache: Check if a memory space has moved Anthony PERARD
2011-12-09 21:54   ` Anthony PERARD
2011-12-12 12:53   ` [Qemu-devel] " Stefano Stabellini
2011-12-12 12:53     ` Stefano Stabellini
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 3/5] Introduce premigrate RunState Anthony PERARD
2011-12-09 21:54   ` Anthony PERARD
2011-12-15 15:14   ` [Qemu-devel] " Anthony Liguori
2011-12-15 15:14     ` Anthony Liguori
2011-12-15 16:31     ` [Qemu-devel] " Luiz Capitulino
2011-12-15 16:31       ` Luiz Capitulino
2011-12-19 17:27       ` [Qemu-devel] " Anthony PERARD
2011-12-19 17:27         ` Anthony PERARD
2012-01-03 19:05         ` [Qemu-devel] " Luiz Capitulino
2012-01-03 19:05           ` Luiz Capitulino
2012-01-05 12:26           ` [Qemu-devel] " Anthony PERARD
2012-01-05 12:26             ` Anthony PERARD
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 4/5] xen: Change memory access behavior during migration Anthony PERARD
2011-12-09 21:54   ` Anthony PERARD
2011-12-12 12:55   ` [Qemu-devel] " Stefano Stabellini
2011-12-12 12:55     ` Stefano Stabellini
2011-12-09 21:54 ` [Qemu-devel] [PATCH V2 5/5] vga-cirrus: Workaround during restore when using Xen Anthony PERARD
2011-12-09 21:54   ` Anthony PERARD
2011-12-10 10:45   ` [Qemu-devel] " Jan Kiszka
2011-12-10 10:45     ` Jan Kiszka
2011-12-12 13:18     ` [Qemu-devel] " Stefano Stabellini
2011-12-12 13:18       ` Stefano Stabellini
2011-12-12 14:03       ` [Qemu-devel] " Jan Kiszka
2011-12-12 14:03         ` Jan Kiszka
2011-12-12 14:41         ` [Qemu-devel] " Stefano Stabellini
2011-12-12 14:41           ` Stefano Stabellini
2011-12-12 15:03           ` [Qemu-devel] " Jan Kiszka
2011-12-12 15:03             ` Jan Kiszka
2011-12-12 15:32             ` [Qemu-devel] " Stefano Stabellini
2011-12-12 15:32               ` Stefano Stabellini
2011-12-13 11:55               ` [Qemu-devel] early_savevm (was: [PATCH V2 5/5] vga-cirrus: Workaround during restore when using Xen.) Stefano Stabellini
2011-12-13 11:55                 ` Stefano Stabellini
2011-12-13 12:35                 ` [Qemu-devel] early_savevm Jan Kiszka
2011-12-13 12:35                   ` early_savevm Jan Kiszka
2011-12-13 13:59                   ` [Qemu-devel] early_savevm Stefano Stabellini
2011-12-13 13:59                     ` early_savevm Stefano Stabellini
2011-12-18 17:43                 ` [Qemu-devel] early_savevm Avi Kivity
2011-12-18 17:43                   ` early_savevm Avi Kivity
2012-01-11 17:55                 ` [Qemu-devel] early_savevm Anthony Liguori
2011-12-18 17:41               ` [Qemu-devel] [PATCH V2 5/5] vga-cirrus: Workaround during restore when using Xen Avi Kivity
2011-12-18 17:41                 ` Avi Kivity
2012-01-04 16:38                 ` [Qemu-devel] " Stefano Stabellini
2012-01-04 16:38                   ` Stefano Stabellini
2012-01-04 17:23                   ` [Qemu-devel] " Avi Kivity
2012-01-04 17:23                     ` Avi Kivity
2012-01-05 12:30                     ` [Qemu-devel] " Stefano Stabellini
2012-01-05 12:30                       ` Stefano Stabellini
2012-01-05 12:50                       ` Avi Kivity [this message]
2012-01-05 12:50                         ` Avi Kivity
2012-01-05 13:17                         ` [Qemu-devel] " Stefano Stabellini
2012-01-05 13:17                           ` Stefano Stabellini
2012-01-05 13:32                           ` [Qemu-devel] " Avi Kivity
2012-01-05 13:32                             ` Avi Kivity
2012-01-05 14:34                             ` [Qemu-devel] " Stefano Stabellini
2012-01-05 14:34                               ` Stefano Stabellini
2012-01-05 15:19                               ` [Qemu-devel] " Avi Kivity
2012-01-05 15:19                                 ` Avi Kivity
2012-01-05 15:53                                 ` [Qemu-devel] " Stefano Stabellini
2012-01-05 15:53                                   ` Stefano Stabellini
2012-01-05 16:33                                   ` [Qemu-devel] " Avi Kivity
2012-01-05 16:33                                     ` Avi Kivity
2012-01-05 17:21                                     ` [Qemu-devel] " Stefano Stabellini
2012-01-05 17:21                                       ` Stefano Stabellini
2012-01-05 17:50                                       ` [Qemu-devel] " Avi Kivity
2012-01-05 17:50                                         ` Avi Kivity
2012-01-05 18:49                                         ` [Qemu-devel] " Jan Kiszka
2012-01-05 18:49                                           ` Jan Kiszka
2012-01-06 10:50                                           ` [Qemu-devel] " Stefano Stabellini
2012-01-06 10:50                                             ` Stefano Stabellini
2012-01-06 13:30                                             ` [Qemu-devel] " Jan Kiszka
2012-01-06 13:30                                               ` Jan Kiszka
2012-01-06 14:40                                               ` [Qemu-devel] " Stefano Stabellini
2012-01-06 14:40                                                 ` Stefano Stabellini
2012-01-08 10:39                                                 ` [Qemu-devel] " Avi Kivity
2012-01-08 10:39                                                   ` Avi Kivity
2012-01-09 15:25                                                   ` [Qemu-devel] " Stefano Stabellini
2012-01-09 15:25                                                     ` Stefano Stabellini
2012-01-09 15:28                                                     ` [Qemu-devel] " Jan Kiszka
2012-01-09 15:28                                                       ` Jan Kiszka
2012-01-09 15:36                                                       ` [Qemu-devel] " Avi Kivity
2012-01-09 15:36                                                         ` Avi Kivity
2012-01-06 15:58                                               ` [Qemu-devel] " Peter Maydell
2012-01-06 15:58                                                 ` Peter Maydell
2012-01-06 16:50                                                 ` [Qemu-devel] " Jan Kiszka
2012-01-06 16:50                                                   ` Jan Kiszka
2012-01-06 12:19                                           ` [Qemu-devel] " Avi Kivity
2012-01-06 12:19                                             ` Avi Kivity
2012-01-06 12:22                                             ` [Qemu-devel] " Jan Kiszka
2012-01-06 12:22                                               ` Jan Kiszka
2012-01-06 12:47                                               ` [Qemu-devel] " Avi Kivity
2012-01-06 12:47                                                 ` Avi Kivity
2011-12-12 12:58   ` [Qemu-devel] " Stefano Stabellini
2011-12-12 12:58     ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F059C8C.2030303@redhat.com \
    --to=avi@redhat.com \
    --cc=anthony.perard@citrix.com \
    --cc=jan.kiszka@siemens.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.