Skip to contentSkip to conversation

xen: don't save/restore the physmap on VM save/restore

PATCH In review Igor Druzhinin 2 participants 6 messages Mar 15, 2017 – Mar 16, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 xen: don't save/restore the physmap on VM save/restore

Saving/restoring the physmap to/from xenstore was introduced to QEMU majorly in order to cover up the VRAM region restore issue. The sequence of restore operations implies that we should know the effective guest VRAM address *before* we have the VRAM region restored (which happens later). Unfortunately, in Xen environment VRAM memory does actually belong to a guest - not QEMU itself - which means the position of this region is unknown beforehand and can't be mapped into QEMU address space immediately.

Previously, recreating xenstore keys, holding the physmap, by the toolstack helped to get this information in place at the right moment ready to be consumed by QEMU to map the region properly.

The extraneous complexity of having those keys transferred by the toolstack and unnecessary redundancy prompted us to propose a solution which doesn't require any extra data in xenstore. The idea is to defer the VRAM region mapping till the point we actually know the effective address and able to map it. To that end, we initially just skip the mapping request for the framebuffer if we unable to map it now. Then, after the memory region restore phase, we perform the mapping again, this time successfully, and update the VRAM region metadata accordingly.

---
v5:
* Add an assertion and debug printf

v4:
* Use VGA post_load handler for vram_ptr update

v3:
* Modify qemu_ram_ptr_length similarly with qemu_map_ram_ptr
* Add a comment explaining qemu_map_ram_ptr and qemu_ram_ptr_length semantic change for Xen
* Dropped some redundant changes

v2:
* Fix some building and coding style issues

---
 exec.c           |  16 +++++++++
 hw/display/vga.c |  11 ++++++
 xen-hvm.c        | 104 ++++++++++---------------------------------------------
 3 files changed, 46 insertions(+), 85 deletions(-)
exec.c +16 -0
index aabb035..a1ac8cd 100644
@@ -2008,6 +2008,14 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr)
         }
 
         block->host = xen_map_cache(block->offset, block->max_length, 1);
+        if (block->host == NULL) {
+            /* In case we cannot establish the mapping right away we might
+             * still be able to do it later e.g. on a later stage of restore.
+             * We don't touch the block and return NULL here to indicate
+             * that intention.
+             */
+            return NULL;
+        }
     }
     return ramblock_ptr(block, addr);
 }
@@ -2041,6 +2049,14 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
         }
 
         block->host = xen_map_cache(block->offset, block->max_length, 1);
+        if (block->host == NULL) {
+            /* In case we cannot establish the mapping right away we might
+             * still be able to do it later e.g. on a later stage of restore.
+             * We don't touch the block and return NULL here to indicate
+             * that intention.
+             */
+            return NULL;
+        }
     }
 
     return ramblock_ptr(block, addr);
hw/display/vga.c +11 -0
index 69c3e1d..7d85fd8 100644
@@ -2035,6 +2035,12 @@ static int vga_common_post_load(void *opaque, int version_id)
 {
     VGACommonState *s = opaque;
 
+    if (xen_enabled() && !s->vram_ptr) {
+        /* update VRAM region pointer in case we've failed
+         * the last time during init phase */
+        s->vram_ptr = memory_region_get_ram_ptr(&s->vram);
+        assert(s->vram_ptr);
+    }
     /* force refresh */
     s->graphic_mode = -1;
     vbe_update_vgaregs(s);
@@ -2165,6 +2171,11 @@ void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate)
     vmstate_register_ram(&s->vram, global_vmstate ? NULL : DEVICE(obj));
     xen_register_framebuffer(&s->vram);
     s->vram_ptr = memory_region_get_ram_ptr(&s->vram);
+    /* VRAM pointer might still be NULL here if we are restoring on Xen.
+       We try to get it again later at post-load phase. */
+#ifdef DEBUG_VGA_MEM
+    printf("vga: vram ptr: %p\n", s->vram_ptr);
+#endif
     s->get_bpp = vga_get_bpp;
     s->get_offsets = vga_get_offsets;
     s->get_resolution = vga_get_resolution;
xen-hvm.c +19 -85

142 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 23 lines · Igor Druzhinin

Saving/restoring the physmap to/from xenstore was introduced to QEMU majorly in order to cover up the VRAM region restore issue. The sequence of restore operations implies that we should know the effective guest VRAM address *before* we have the VRAM region restored (which happens later). Unfortunately, in Xen environment VRAM memory does actually belong to a guest - not QEMU itself - which means the position of this region is unknown beforehand and can't be mapped into QEMU address space immediately.

Previously, recreating xenstore keys, holding the physmap, by the toolstack helped to get this information in place at the right moment ready to be consumed by QEMU to map the region properly.

The extraneous complexity of having those keys transferred by the toolstack and unnecessary redundancy prompted us to propose a solution which doesn't require any extra data in xenstore. The idea is to defer the VRAM region mapping till the point we actually know the effective address and able to map it. To that end, we initially just skip the mapping request for the framebuffer if we unable to map it now. Then, after the memory region restore phase, we perform the mapping again, this time successfully, and update the VRAM region metadata accordingly.

Quoted 1 line

I've tried to migrate a guest with this patch, but once migrated, the screen is black (via VNC, keyboard is working fine).

I haven't try to migrate a guest from QEMU without this patch to a QEMU with it.

Signature · 1 line
Anthony PERARD
#2 lore raw
Quoted 24 lines · Anthony PERARD
Quoted 23 lines · Igor Druzhinin

Saving/restoring the physmap to/from xenstore was introduced to QEMU majorly in order to cover up the VRAM region restore issue. The sequence of restore operations implies that we should know the effective guest VRAM address *before* we have the VRAM region restored (which happens later). Unfortunately, in Xen environment VRAM memory does actually belong to a guest - not QEMU itself - which means the position of this region is unknown beforehand and can't be mapped into QEMU address space immediately.

Previously, recreating xenstore keys, holding the physmap, by the toolstack helped to get this information in place at the right moment ready to be consumed by QEMU to map the region properly.

The extraneous complexity of having those keys transferred by the toolstack and unnecessary redundancy prompted us to propose a solution which doesn't require any extra data in xenstore. The idea is to defer the VRAM region mapping till the point we actually know the effective address and able to map it. To that end, we initially just skip the mapping request for the framebuffer if we unable to map it now. Then, after the memory region restore phase, we perform the mapping again, this time successfully, and update the VRAM region metadata accordingly.

Quoted 8 lines
Quoted 1 line

I've tried to migrate a guest with this patch, but once migrated, the screen is black (via VNC, keyboard is working fine).

I haven't try to migrate a guest from QEMU without this patch to a QEMU with it.

Hmm. It works for me - I've tried to migrate between identical QEMUs with this patch on localhost. Save/restore also works fine.

What do you mean 'the screen is black'? Could you describe your actions so I could try to reproduce it?

Igor

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 34 lines · Igor Druzhinin
Quoted 24 lines · Anthony PERARD
Quoted 23 lines · Igor Druzhinin

Saving/restoring the physmap to/from xenstore was introduced to QEMU majorly in order to cover up the VRAM region restore issue. The sequence of restore operations implies that we should know the effective guest VRAM address *before* we have the VRAM region restored (which happens later). Unfortunately, in Xen environment VRAM memory does actually belong to a guest - not QEMU itself - which means the position of this region is unknown beforehand and can't be mapped into QEMU address space immediately.

Previously, recreating xenstore keys, holding the physmap, by the toolstack helped to get this information in place at the right moment ready to be consumed by QEMU to map the region properly.

The extraneous complexity of having those keys transferred by the toolstack and unnecessary redundancy prompted us to propose a solution which doesn't require any extra data in xenstore. The idea is to defer the VRAM region mapping till the point we actually know the effective address and able to map it. To that end, we initially just skip the mapping request for the framebuffer if we unable to map it now. Then, after the memory region restore phase, we perform the mapping again, this time successfully, and update the VRAM region metadata accordingly.

Quoted 8 lines
Quoted 1 line

I've tried to migrate a guest with this patch, but once migrated, the screen is black (via VNC, keyboard is working fine).

I haven't try to migrate a guest from QEMU without this patch to a QEMU with it.

Quoted 5 lines

Hmm. It works for me - I've tried to migrate between identical QEMUs with this patch on localhost. Save/restore also works fine.

What do you mean 'the screen is black'? Could you describe your actions so I could try to reproduce it?

Ok. I could track down the issue - starting from v4 the patch doesn't work for cirrus. The reason is that post_load handler is different for cirrus and doesn't call the parent handler from common vga code.

I manage to fix it by updating the corresponding handler by duplicating the code. But is it a good solution? Would it be better to have the common handler called in this function instead?

Quoted 8 lines

Igor

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 8 lines · Igor Druzhinin
Quoted 7 lines · Igor Druzhinin
Quoted 3 lines · Anthony PERARD

I've tried to migrate a guest with this patch, but once migrated, the screen is black (via VNC, keyboard is working fine).

Hmm. It works for me - I've tried to migrate between identical QEMUs with this patch on localhost. Save/restore also works fine.

Quoted 7 lines

Ok. I could track down the issue - starting from v4 the patch doesn't work for cirrus. The reason is that post_load handler is different for cirrus and doesn't call the parent handler from common vga code.

I manage to fix it by updating the corresponding handler by duplicating the code. But is it a good solution? Would it be better to have the common handler called in this function instead?

:(, vga_common_post_load have a misleading name. Yes, I think it would be better to have a common post_load been called by every vga cards.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw
Quoted 13 lines · Anthony PERARD
Quoted 12 lines · Igor Druzhinin
Quoted 7 lines · Igor Druzhinin
Quoted 3 lines · Anthony PERARD

I've tried to migrate a guest with this patch, but once migrated, the screen is black (via VNC, keyboard is working fine).

Hmm. It works for me - I've tried to migrate between identical QEMUs with this patch on localhost. Save/restore also works fine.

Ok. I could track down the issue - starting from v4 the patch doesn't work for cirrus. The reason is that post_load handler is different for cirrus and doesn't call the parent handler from common vga code.

Quoted 6 lines
Quoted 3 lines

I manage to fix it by updating the corresponding handler by duplicating the code. But is it a good solution? Would it be better to have the common handler called in this function instead?

:(, vga_common_post_load have a misleading name. Yes, I think it would be better to have a common post_load been called by every vga cards.

The issue is probably more complicated than I thought, as vga_common_post_load is probably not called because cirrus does not use vmstate_vga_common struct.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel