goto vcpuextstate_out;
}
- if ( evc->size <= PV_XSAVE_SIZE(_xcr0_accum) )
+ if ( evc->size == 2 * sizeof(uint64_t) )
+ ; /* Nothing to restore. */
+ else if ( evc->size < 2 * sizeof(uint64_t) + 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;
evc->size - 2 * sizeof(uint64_t));
vcpu_unpause(v);
}
- else
- ret = -EINVAL;
xfree(receive_buf);
}
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);
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
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 */
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;
}
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;