All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] Sanity check xsave area when migrating or restoring from older Xen verions
@ 2014-10-21 18:40 Don Koch
  2014-10-21 19:00 ` Andrew Cooper
  0 siblings, 1 reply; 11+ messages in thread
From: Don Koch @ 2014-10-21 18:40 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Keir Fraser, Don Koch, Jan Beulich

Xen 4.3 and older transferred a maximum sized xsave area (as if all
the available XCR0 bits were set); the new version only transfers
based on the actual XCR0 bits. This may result in a smaller area if
the last sections were missing (e.g., the LWP area from an AMD
machine). If the size doesn't match the XCR0 derived size, the part of
the xsave area between the XCR0 specified and transferred size is
checked for zero data. If any part of the overflow area is non-zero,
we return with an error.

Signed-off-by: Don Koch <dkoch@verizon.com>
---
Changes in V4:
- Removed check of size base on xfeature_mask.
- Unsign some ints.
- Change %d to %u for unsigned ints.
- Move printk to only print if non-zero data found.

Changes in V3:
- use h->data for zero check
- remove max size check (use size that was sent)
- fix error message (drop first byte value)
- fix "for" issues

Changes in V2:
- Add check for size.
- Add check for non-zero data in unused part of block.

 xen/arch/x86/hvm/hvm.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index f0e1edc..c2780d2 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -1971,6 +1971,7 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
     struct vcpu *v;
     struct hvm_hw_cpu_xsave *ctxt;
     struct hvm_save_descriptor *desc;
+    unsigned int i, overflow_start;
 
     /* Which vcpu is this? */
     vcpuid = hvm_load_instance(h);
@@ -2011,15 +2012,8 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
                         save_area) + XSTATE_AREA_MIN_SIZE);
         return -EINVAL;
     }
-    size = HVM_CPU_XSAVE_SIZE(xfeature_mask);
-    if ( desc->length > size )
-    {
-        printk(XENLOG_G_WARNING
-               "HVM%d.%d restore mismatch: xsave length %u > %u\n",
-               d->domain_id, vcpuid, desc->length, size);
-        return -EOPNOTSUPP;
-    }
     h->cur += sizeof (*desc);
+    overflow_start = h->cur;
 
     ctxt = (struct hvm_hw_cpu_xsave *)&h->data[h->cur];
     h->cur += desc->length;
@@ -2038,10 +2032,20 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
     size = HVM_CPU_XSAVE_SIZE(ctxt->xcr0_accum);
     if ( desc->length > size )
     {
-        printk(XENLOG_G_WARNING
-               "HVM%d.%d restore mismatch: xsave length %u > %u\n",
-               d->domain_id, vcpuid, desc->length, size);
-        return -EOPNOTSUPP;
+        /* Make sure missing bytes are all zero. */
+        for ( i = size; i < desc->length; i++ )
+        {
+            if ( h->data[overflow_start + i] )
+            {
+                printk(XENLOG_G_WARNING
+                       "HVM%u.%u restore mismatch: xsave length %u > %u\n",
+                       d->domain_id, vcpuid, desc->length, size);
+                printk(XENLOG_G_WARNING
+                       "HVM%u.%u restore mismatch: xsave has non-zero data starting at %#x\n",
+                       d->domain_id, vcpuid, i);
+                return -EOPNOTSUPP;
+            }
+        }
     }
     /* Checking finished */
 
-- 
1.8.3.1

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

end of thread, other threads:[~2014-10-22 14:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-21 18:40 [PATCH v4] Sanity check xsave area when migrating or restoring from older Xen verions Don Koch
2014-10-21 19:00 ` Andrew Cooper
2014-10-21 19:25   ` Don Koch
2014-10-22 10:00     ` Jan Beulich
2014-10-22 13:19       ` Don Koch
2014-10-22 13:21         ` Andrew Cooper
2014-10-22 13:37           ` Don Koch
2014-10-22 14:03         ` Jan Beulich
2014-10-22 14:11           ` Don Koch
2014-10-22 14:21             ` Jan Beulich
2014-10-22 14:28               ` Don Koch

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.