@@ -1158,7 +1158,15 @@ long arch_do_domctl(
goto vcpuextstate_out;
}
- if ( evc->size <= PV_XSAVE_SIZE(_xcr0_accum) )
+ if ( evc->size == PV_XSAVE_HDR_SIZE )
+ ; /* Nothing to restore. */
+ else if ( evc->size < PV_XSAVE_HDR_SIZE + XSTATE_AREA_MIN_SIZE )
+ ret = -EINVAL; /* Can't be legitimate data. */
+ else if ( xsave_area_compressed(_xsave_area) )
+ ret = -EOPNOTSUPP; /* Don't support compressed data. */
+ else if ( evc->size != PV_XSAVE_SIZE(_xcr0_accum) )
+ ret = -EINVAL; /* Not legitimate data. */
+ else
{
vcpu_pause(v);
v->arch.xcr0 = _xcr0;
@@ -1169,8 +1177,6 @@ long arch_do_domctl(
evc->size - PV_XSAVE_HDR_SIZE);
vcpu_unpause(v);
}
- else
- ret = -EINVAL;
xfree(receive_buf);
}
@@ -1265,8 +1265,8 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
int err;
struct vcpu *v;
struct hvm_hw_cpu_xsave *ctxt;
- struct hvm_save_descriptor *desc;
- unsigned int i, desc_start;
+ const struct hvm_save_descriptor *desc;
+ unsigned int i, desc_start, desc_length;
/* Which vcpu is this? */
vcpuid = hvm_load_instance(h);
@@ -1325,7 +1325,8 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
return err;
}
size = HVM_CPU_XSAVE_SIZE(ctxt->xcr0_accum);
- if ( desc->length > size )
+ desc_length = desc->length;
+ if ( desc_length > size )
{
/*
* Xen 4.3.0, 4.2.3 and older used to send longer-than-needed
@@ -1345,6 +1346,23 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
printk(XENLOG_G_WARNING
"HVM%d.%u restore mismatch: xsave length %#x > %#x\n",
d->domain_id, vcpuid, desc->length, size);
+ /* Rewind desc_length to ignore the extraneous zeros. */
+ desc_length = size;
+ }
+
+ if ( xsave_area_compressed((const void *)&ctxt->save_area) )
+ {
+ printk(XENLOG_G_WARNING
+ "HVM%d.%u restore: compressed xsave state not supported\n",
+ d->domain_id, vcpuid);
+ return -EOPNOTSUPP;
+ }
+ else if ( desc_length != size )
+ {
+ printk(XENLOG_G_WARNING
+ "HVM%d.%u restore mismatch: xsave length %#x != %#x\n",
+ d->domain_id, vcpuid, desc_length, size);
+ return -EINVAL;
}
/* Checking finished */
@@ -1353,8 +1371,7 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
if ( ctxt->xcr0_accum & XSTATE_NONLAZY )
v->arch.nonlazy_xstate_used = 1;
compress_xsave_states(v, &ctxt->save_area,
- min(desc->length, size) -
- offsetof(struct hvm_hw_cpu_xsave,save_area));
+ size - offsetof(struct hvm_hw_cpu_xsave, save_area));
return 0;
}
@@ -86,12 +86,6 @@ uint64_t get_msr_xss(void)
return this_cpu(xss);
}
-static bool_t xsave_area_compressed(const struct xsave_struct *xsave_area)
-{
- return xsave_area && (xsave_area->xsave_hdr.xcomp_bv
- & XSTATE_COMPACTION_ENABLED);
-}
-
static int setup_xstate_features(bool_t bsp)
{
unsigned int leaf, eax, ebx, ecx, edx;
@@ -131,4 +131,10 @@ static inline bool_t xstate_all(const struct vcpu *v)
(v->arch.xcr0_accum & XSTATE_LAZY & ~XSTATE_FP_SSE);
}
+static inline bool __nonnull(1)
+xsave_area_compressed(const struct xsave_struct *xsave_area)
+{
+ return xsave_area->xsave_hdr.xcomp_bv & XSTATE_COMPACTION_ENABLED;
+}
+
#endif /* __ASM_XSTATE_H */