static int hvm_save_cpu_msrs(struct vcpu *v, hvm_domain_context_t *h)
{
+ const struct domain *d = v->domain;
struct hvm_save_descriptor *desc = _p(&h->data[h->cur]);
struct hvm_msr *ctxt;
unsigned int i;
for ( i = 0; i < ARRAY_SIZE(msrs_to_send); ++i )
{
uint64_t val;
- int rc = guest_rdmsr(v, msrs_to_send[i], &val);
+ unsigned int msr = msrs_to_send[i];
+ int rc = guest_rdmsr(v, msr, &val);
/*
* It is the programmers responsibility to ensure that
if ( !val )
continue; /* Skip empty MSRs. */
- ctxt->msr[ctxt->count].index = msrs_to_send[i];
+ /*
+ * Guests are given full access to certain MSRs for performance
+ * reasons. A consequence is that Xen is unable to enforce that all
+ * bits disallowed by the CPUID policy yield #GP, and an enterprising
+ * guest may be able to set and use a bit it ought to leave alone.
+ *
+ * When migrating from a more capable host to a less capable one, such
+ * bits may be rejected by the destination, and the migration failed.
+ *
+ * Discard such bits here on the source side. Such bits have reserved
+ * behaviour, and the guest has only itself to blame.
+ */
+ switch ( msr )
+ {
+ case MSR_SPEC_CTRL:
+ val &= msr_spec_ctrl_valid_bits(d->arch.cpuid);
+ break;
+ }
+
+ ctxt->msr[ctxt->count].index = msr;
ctxt->msr[ctxt->count++].val = val;
}
return X86EMUL_EXCEPTION;
}
+/*
+ * Caller to confirm that MSR_SPEC_CTRL is available. Intel and AMD have
+ * separate CPUID features for this functionality, but only set will be
+ * active.
+ */
+uint64_t msr_spec_ctrl_valid_bits(const struct cpuid_policy *cp)
+{
+ bool ssbd = cp->feat.ssbd;
+
+ /*
+ * Note: SPEC_CTRL_STIBP is specified as safe to use (i.e. ignored)
+ * when STIBP isn't enumerated in hardware.
+ */
+ return (SPEC_CTRL_IBRS | SPEC_CTRL_STIBP |
+ (ssbd ? SPEC_CTRL_SSBD : 0) |
+ 0);
+}
+
int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
{
const struct vcpu *curr = current;
break;
case MSR_SPEC_CTRL:
- if ( !cp->feat.ibrsb )
- goto gp_fault; /* MSR available? */
-
- /*
- * Note: SPEC_CTRL_STIBP is specified as safe to use (i.e. ignored)
- * when STIBP isn't enumerated in hardware.
- */
- rsvd = ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP |
- (cp->feat.ssbd ? SPEC_CTRL_SSBD : 0));
-
- if ( val & rsvd )
- goto gp_fault; /* Rsvd bit set? */
+ if ( !cp->feat.ibrsb ||
+ (val & ~msr_spec_ctrl_valid_bits(cp)) )
+ goto gp_fault;
goto set_reg;
case MSR_PRED_CMD: