All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Anthony Perard <anthony.perard@citrix.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: Mon, 12 Dec 2011 15:03:43 +0100	[thread overview]
Message-ID: <4EE609BF.1070307@siemens.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1112121259180.3517@kaball-desktop>

On 2011-12-12 14:18, Stefano Stabellini wrote:
> On Sat, 10 Dec 2011, Jan Kiszka wrote:
>> On 2011-12-09 22:54, Anthony PERARD wrote:
>>> During the initialisation of the machine at restore time, the access to the
>>> VRAM will fail because QEMU does not know yet the right guest address to map,
>>> so the vram_ptr is NULL.
>>>
>>> So this patch avoid using a NULL pointer during initialisation, and try to get
>>> another vram_ptr if the call failed the first time.
>>>
>>> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
>>> ---
>>>  hw/cirrus_vga.c |   16 +++++++++++++---
>>>  1 files changed, 13 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
>>> index c7e365b..2e049c9 100644
>>> --- a/hw/cirrus_vga.c
>>> +++ b/hw/cirrus_vga.c
>>> @@ -32,6 +32,7 @@
>>>  #include "console.h"
>>>  #include "vga_int.h"
>>>  #include "loader.h"
>>> +#include "sysemu.h"
>>>  
>>>  /*
>>>   * TODO:
>>> @@ -2696,6 +2697,13 @@ static int cirrus_post_load(void *opaque, int version_id)
>>>      s->vga.gr[0x01] = s->cirrus_shadow_gr1 & 0x0f;
>>>  
>>>      cirrus_update_memory_access(s);
>>> +    if (!s->vga.vram_ptr) {
>>> +        /* At this point vga.vram_ptr can be invalid on Xen because we need to
>>> +         * know the position of the videoram in the guest physical address space in
>>> +         * order to be able to map it. After cirrus_update_memory_access we do know
>>> +         * where the videoram is, so let's map it now. */
>>> +        s->vga.vram_ptr = memory_region_get_ram_ptr(&s->vga.vram);
>>> +    }
>>>      /* force refresh */
>>>      s->vga.graphic_mode = -1;
>>>      cirrus_update_bank_ptr(s, 0);
>>> @@ -2784,9 +2792,11 @@ static void cirrus_reset(void *opaque)
>>>      }
>>>      s->vga.cr[0x27] = s->device_id;
>>>  
>>> -    /* Win2K seems to assume that the pattern buffer is at 0xff
>>> -       initially ! */
>>> -    memset(s->vga.vram_ptr, 0xff, s->real_vram_size);
>>> +    if (!runstate_check(RUN_STATE_PREMIGRATE)) {
>>> +        /* Win2K seems to assume that the pattern buffer is at 0xff
>>> +           initially ! */
>>> +        memset(s->vga.vram_ptr, 0xff, s->real_vram_size);
>>> +    }
>>>  
>>>      s->cirrus_hidden_dac_lockindex = 5;
>>>      s->cirrus_hidden_dac_data = 0;
>>
>> Is there really no way to fix this properly in the Xen layer?
> 
> We thought about this issue for some time but we couldn't come up with
> anything better.
> To summarize the problem:
> 
> - on restore the videoram has already been loaded in the guest physical
>   address space by Xen;
> 
> - we don't know exactly where it is yet, because it has been loaded at
>   the *last* address it was mapped to (see map_linear_vram_bank that
>   moves the videoram);
> 
> - we want to avoid allocating the videoram twice (actually the second
>   allocation would fail because of memory constraints);
> 
> 
> 
> So the solution (I acknowledge that it looks more like an hack than a
> solution) is:
> 
> - wait for cirrus to load its state so that we know where the videoram
>   is;

Why can't you store this information in some additional Xen-specific
vmstate? The fact that memory_region_get_ram_ptr has to return NULL
looks bogus to me. It's against the QEMU semantics. Other devices may
only be fine as they are not (yet) used with Xen.

> 
> - map the videoram into qemu's address space at that point.
> 
> 
> 
> Anything else we came up with was even worse, for example:
> 
> - independently save the position of the videoram and then when
>   vga_common_init tries to allocate it for a second time give back the
>   old videoram instead;
> 
> - move back the videoram to the original position and then move it again
>   to the new position.
> 
> 
> 
>> This looks
>> highly fragile as specifically the second hunk appears unrelated to Xen.
> 
> I think that the second chuck should be in a separate patch because it
> is unrelated to Xen. On restore it is useless to memset the videoram, so
> for performance reasons it would be a good idea to avoid it on all
> platforms. Also it happens to crash Qemu on Xen but that is another
> story  ;-)
> 
> I think we should also add a comment:
> 
> "useles to memset the videoram on restore, the old videoram is going to
> be copied over soon anyway"

That's in fact a different story and maybe worth optimizing due to the
size of that buffer. But please do not call the state "PREMIGRATE". It's
rather "INCOMING[_MIGRATION]".

Thanks,
Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

WARNING: multiple messages have this Message-ID (diff)
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Anthony Perard <anthony.perard@citrix.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: Mon, 12 Dec 2011 15:03:43 +0100	[thread overview]
Message-ID: <4EE609BF.1070307@siemens.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1112121259180.3517@kaball-desktop>

On 2011-12-12 14:18, Stefano Stabellini wrote:
> On Sat, 10 Dec 2011, Jan Kiszka wrote:
>> On 2011-12-09 22:54, Anthony PERARD wrote:
>>> During the initialisation of the machine at restore time, the access to the
>>> VRAM will fail because QEMU does not know yet the right guest address to map,
>>> so the vram_ptr is NULL.
>>>
>>> So this patch avoid using a NULL pointer during initialisation, and try to get
>>> another vram_ptr if the call failed the first time.
>>>
>>> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
>>> ---
>>>  hw/cirrus_vga.c |   16 +++++++++++++---
>>>  1 files changed, 13 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
>>> index c7e365b..2e049c9 100644
>>> --- a/hw/cirrus_vga.c
>>> +++ b/hw/cirrus_vga.c
>>> @@ -32,6 +32,7 @@
>>>  #include "console.h"
>>>  #include "vga_int.h"
>>>  #include "loader.h"
>>> +#include "sysemu.h"
>>>  
>>>  /*
>>>   * TODO:
>>> @@ -2696,6 +2697,13 @@ static int cirrus_post_load(void *opaque, int version_id)
>>>      s->vga.gr[0x01] = s->cirrus_shadow_gr1 & 0x0f;
>>>  
>>>      cirrus_update_memory_access(s);
>>> +    if (!s->vga.vram_ptr) {
>>> +        /* At this point vga.vram_ptr can be invalid on Xen because we need to
>>> +         * know the position of the videoram in the guest physical address space in
>>> +         * order to be able to map it. After cirrus_update_memory_access we do know
>>> +         * where the videoram is, so let's map it now. */
>>> +        s->vga.vram_ptr = memory_region_get_ram_ptr(&s->vga.vram);
>>> +    }
>>>      /* force refresh */
>>>      s->vga.graphic_mode = -1;
>>>      cirrus_update_bank_ptr(s, 0);
>>> @@ -2784,9 +2792,11 @@ static void cirrus_reset(void *opaque)
>>>      }
>>>      s->vga.cr[0x27] = s->device_id;
>>>  
>>> -    /* Win2K seems to assume that the pattern buffer is at 0xff
>>> -       initially ! */
>>> -    memset(s->vga.vram_ptr, 0xff, s->real_vram_size);
>>> +    if (!runstate_check(RUN_STATE_PREMIGRATE)) {
>>> +        /* Win2K seems to assume that the pattern buffer is at 0xff
>>> +           initially ! */
>>> +        memset(s->vga.vram_ptr, 0xff, s->real_vram_size);
>>> +    }
>>>  
>>>      s->cirrus_hidden_dac_lockindex = 5;
>>>      s->cirrus_hidden_dac_data = 0;
>>
>> Is there really no way to fix this properly in the Xen layer?
> 
> We thought about this issue for some time but we couldn't come up with
> anything better.
> To summarize the problem:
> 
> - on restore the videoram has already been loaded in the guest physical
>   address space by Xen;
> 
> - we don't know exactly where it is yet, because it has been loaded at
>   the *last* address it was mapped to (see map_linear_vram_bank that
>   moves the videoram);
> 
> - we want to avoid allocating the videoram twice (actually the second
>   allocation would fail because of memory constraints);
> 
> 
> 
> So the solution (I acknowledge that it looks more like an hack than a
> solution) is:
> 
> - wait for cirrus to load its state so that we know where the videoram
>   is;

Why can't you store this information in some additional Xen-specific
vmstate? The fact that memory_region_get_ram_ptr has to return NULL
looks bogus to me. It's against the QEMU semantics. Other devices may
only be fine as they are not (yet) used with Xen.

> 
> - map the videoram into qemu's address space at that point.
> 
> 
> 
> Anything else we came up with was even worse, for example:
> 
> - independently save the position of the videoram and then when
>   vga_common_init tries to allocate it for a second time give back the
>   old videoram instead;
> 
> - move back the videoram to the original position and then move it again
>   to the new position.
> 
> 
> 
>> This looks
>> highly fragile as specifically the second hunk appears unrelated to Xen.
> 
> I think that the second chuck should be in a separate patch because it
> is unrelated to Xen. On restore it is useless to memset the videoram, so
> for performance reasons it would be a good idea to avoid it on all
> platforms. Also it happens to crash Qemu on Xen but that is another
> story  ;-)
> 
> I think we should also add a comment:
> 
> "useles to memset the videoram on restore, the old videoram is going to
> be copied over soon anyway"

That's in fact a different story and maybe worth optimizing due to the
size of that buffer. But please do not call the state "PREMIGRATE". It's
rather "INCOMING[_MIGRATION]".

Thanks,
Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

  reply	other threads:[~2011-12-12 14:04 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       ` Jan Kiszka [this message]
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                       ` [Qemu-devel] " Avi Kivity
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=4EE609BF.1070307@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=anthony.perard@citrix.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.