All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration
@ 2013-07-22 11:14 Orit Wasserman
  2013-07-22 11:14 ` [Qemu-devel] [PATCH v2 1/2] Fix real mode guest migration Orit Wasserman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Orit Wasserman @ 2013-07-22 11:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: aliguori, ehabkost, gleb, quintela, mtosatti, Orit Wasserman,
	pbonzini, afaerber

Older KVM versions save CS dpl value to an invalid value for real mode guests
(0x3). This caused migration to fail from older KVM on host without unrestricted guest to hosts with restricted guest support with "kvm: unhandled exit 80000021".
For example migration from a Penryn host (with kernel 2.6.32) to
a Westmere host (for real mode guest) 

This series fixing it both in the destination and source QEMU.

Changes from v1:
  Fix typos and style

Orit Wasserman (2):
  Fix real mode guest migration
  Fix real mode guest segments dpl value in savevm

 target-i386/machine.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

-- 
1.8.1.4

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

* [Qemu-devel] [PATCH v2 1/2] Fix real mode guest migration
  2013-07-22 11:14 [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration Orit Wasserman
@ 2013-07-22 11:14 ` Orit Wasserman
  2013-07-22 11:14 ` [Qemu-devel] [PATCH v2 2/2] Fix real mode guest segments dpl value in savevm Orit Wasserman
  2013-07-22 15:53 ` [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration Juan Quintela
  2 siblings, 0 replies; 4+ messages in thread
From: Orit Wasserman @ 2013-07-22 11:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: aliguori, ehabkost, gleb, quintela, mtosatti, Orit Wasserman,
	pbonzini, afaerber

Older KVM versions save CS dpl value to an invalid value for real mode guests
(0x3). This patch detect this situation when loading CPU state and set all the
segments dpl to zero.
This will allow migration from older KVM on host without unrestricted guest
to hosts with restricted guest support.
For example migration from a Penryn host (with kernel 2.6.32) to
a Westmere host (for real mode guest) will fail with "kvm: unhandled exit 80000021".

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 target-i386/machine.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/target-i386/machine.c b/target-i386/machine.c
index 3659db9..83ea6ac 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -260,6 +260,24 @@ static int cpu_post_load(void *opaque, int version_id)
     CPUX86State *env = &cpu->env;
     int i;
 
+    /*
+     * Real mode guest segments register DPL should be zero.
+     * Older KVM version were setting it wrongly.
+     * Fixing it will allow live migration from such host that don't have
+     * restricted guest support to an host with unrestricted guest support
+     * (otherwise the migration will fail with invalid guest state
+     * error).
+     */
+    if (!(env->cr[0] & CR0_PE_MASK) &&
+        (env->segs[R_CS].flags >> DESC_DPL_SHIFT & 3) != 0) {
+        env->segs[R_CS].flags &= ~(env->segs[R_CS].flags & DESC_DPL_MASK);
+        env->segs[R_DS].flags &= ~(env->segs[R_DS].flags & DESC_DPL_MASK);
+        env->segs[R_ES].flags &= ~(env->segs[R_ES].flags & DESC_DPL_MASK);
+        env->segs[R_FS].flags &= ~(env->segs[R_FS].flags & DESC_DPL_MASK);
+        env->segs[R_GS].flags &= ~(env->segs[R_GS].flags & DESC_DPL_MASK);
+        env->segs[R_SS].flags &= ~(env->segs[R_SS].flags & DESC_DPL_MASK);
+    }
+
     /* XXX: restore FPU round state */
     env->fpstt = (env->fpus_vmstate >> 11) & 7;
     env->fpus = env->fpus_vmstate & ~0x3800;
-- 
1.8.1.4

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

* [Qemu-devel] [PATCH v2 2/2] Fix real mode guest segments dpl value in savevm
  2013-07-22 11:14 [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration Orit Wasserman
  2013-07-22 11:14 ` [Qemu-devel] [PATCH v2 1/2] Fix real mode guest migration Orit Wasserman
@ 2013-07-22 11:14 ` Orit Wasserman
  2013-07-22 15:53 ` [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration Juan Quintela
  2 siblings, 0 replies; 4+ messages in thread
From: Orit Wasserman @ 2013-07-22 11:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: aliguori, ehabkost, gleb, quintela, mtosatti, Orit Wasserman,
	pbonzini, afaerber

Older KVM version put invalid value in the segments registers dpl field for
real mode guests (0x3).
This breaks migration from those hosts to hosts with unrestricted guest support.
We detect it by checking CS dpl value for real mode guest and fix the dpl values
of all the segment registers.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
---
 target-i386/machine.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/target-i386/machine.c b/target-i386/machine.c
index 83ea6ac..c98f1c9 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -252,6 +252,24 @@ static void cpu_pre_save(void *opaque)
     }
 
     env->fpregs_format_vmstate = 0;
+
+    /*
+     * Real mode guest segments register DPL should be zero.
+     * Older KVM version were setting it wrongly.
+     * Fixing it will allow live migration to host with unrestricted guest
+     * support (otherwise the migration will fail with invalid guest state
+     * error).
+     */
+    if (!(env->cr[0] & CR0_PE_MASK) &&
+        (env->segs[R_CS].flags >> DESC_DPL_SHIFT & 3) != 0) {
+        env->segs[R_CS].flags &= ~(env->segs[R_CS].flags & DESC_DPL_MASK);
+        env->segs[R_DS].flags &= ~(env->segs[R_DS].flags & DESC_DPL_MASK);
+        env->segs[R_ES].flags &= ~(env->segs[R_ES].flags & DESC_DPL_MASK);
+        env->segs[R_FS].flags &= ~(env->segs[R_FS].flags & DESC_DPL_MASK);
+        env->segs[R_GS].flags &= ~(env->segs[R_GS].flags & DESC_DPL_MASK);
+        env->segs[R_SS].flags &= ~(env->segs[R_SS].flags & DESC_DPL_MASK);
+    }
+
 }
 
 static int cpu_post_load(void *opaque, int version_id)
-- 
1.8.1.4

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

* Re: [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration
  2013-07-22 11:14 [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration Orit Wasserman
  2013-07-22 11:14 ` [Qemu-devel] [PATCH v2 1/2] Fix real mode guest migration Orit Wasserman
  2013-07-22 11:14 ` [Qemu-devel] [PATCH v2 2/2] Fix real mode guest segments dpl value in savevm Orit Wasserman
@ 2013-07-22 15:53 ` Juan Quintela
  2 siblings, 0 replies; 4+ messages in thread
From: Juan Quintela @ 2013-07-22 15:53 UTC (permalink / raw)
  To: Orit Wasserman
  Cc: aliguori, ehabkost, gleb, mtosatti, qemu-devel, pbonzini, afaerber

Orit Wasserman <owasserm@redhat.com> wrote:
> Older KVM versions save CS dpl value to an invalid value for real mode guests
> (0x3). This caused migration to fail from older KVM on host without unrestricted guest to hosts with restricted guest support with "kvm: unhandled exit 80000021".
> For example migration from a Penryn host (with kernel 2.6.32) to
> a Westmere host (for real mode guest) 
>
> This series fixing it both in the destination and source QEMU.
>
> Changes from v1:
>   Fix typos and style
>
> Orit Wasserman (2):
>   Fix real mode guest migration
>   Fix real mode guest segments dpl value in savevm
>
>  target-i386/machine.c | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)

Reviewed-by: Juan Quintela <quintela@redhat.com>

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

end of thread, other threads:[~2013-07-22 17:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-22 11:14 [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration Orit Wasserman
2013-07-22 11:14 ` [Qemu-devel] [PATCH v2 1/2] Fix real mode guest migration Orit Wasserman
2013-07-22 11:14 ` [Qemu-devel] [PATCH v2 2/2] Fix real mode guest segments dpl value in savevm Orit Wasserman
2013-07-22 15:53 ` [Qemu-devel] [PATCH v2 0/2] Fix real mode guest live migration Juan Quintela

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.