From c437843790b9b21a90a41b6d96b2b6db3be3d33a Mon Sep 17 00:00:00 2001
From: Eduardo Habkost <ehabkost@redhat.com>
Date: Wed, 16 Oct 2013 20:00:44 +0200
Subject: [PATCH 18/18] target-i386: support loading of "cpu/xsave" subsection

RH-Author: Eduardo Habkost <ehabkost@redhat.com>
Message-id: <1381953644-6411-1-git-send-email-ehabkost@redhat.com>
Patchwork-id: 54966
O-Subject: [qemu-kvm RHEL7 PATCH] target-i386: support loading of "cpu/xsave" subsection
Bugzilla: 1004743
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>

Bugzilla: 1004743
Scratch build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=6429524
Upstream status: not applicable
  (We could try to make upstream accept the subsection, but I don't
  think it will be accepted because there's no real benefit)

This is a kind of forward-port of RHEL-6 commits ceee3a15c8 and 7f468b80fd, so
the "cpu/xsave" subsection can be loaded when migrating from RHEL-6.

The differences between the RHEL-6 patches and this one are:
 * The xsave state is not being removed from the main "cpu" section,
   so we keep using the same format/version used upstream
 * The subsection is always reported as optional, because the xsave
   state is kept in the main "cpu" section

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/machine.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 target-i386/machine.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/target-i386/machine.c b/target-i386/machine.c
index 8faea62..4f30347 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -446,6 +446,25 @@ static const VMStateDescription vmstate_msr_ia32_misc_enable = {
     }
 };
 
+static bool vmstate_xsave_needed(void *opaque)
+{
+    /* The xsave state is already on the main "cpu" section */
+    return false;
+}
+
+static const VMStateDescription vmstate_xsave ={
+    .name = "cpu/xsave",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+    VMSTATE_UINT64_V(env.xcr0, X86CPU, 1),
+    VMSTATE_UINT64_V(env.xstate_bv, X86CPU, 1),
+    VMSTATE_YMMH_REGS_VARS(env.ymmh_regs, X86CPU, CPU_NB_REGS, 1),
+    VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_x86_cpu = {
     .name = "cpu",
     .version_id = 12,
@@ -571,7 +590,10 @@ const VMStateDescription vmstate_x86_cpu = {
         }, {
             .vmsd = &vmstate_msr_ia32_misc_enable,
             .needed = misc_enable_needed,
-        } , {
+        }, {
+            .vmsd = &vmstate_xsave,
+            .needed = vmstate_xsave_needed,
+        }, {
             /* empty */
         }
     }
-- 
1.7.1