All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Jinsong Liu <jinsong.liu@intel.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
	"keir@xen.org" <keir@xen.org>,
	"Ian.Campbell@citrix.com" <Ian.Campbell@citrix.com>,
	"haoxudong.hao@gmail.com" <haoxudong.hao@gmail.com>
Subject: Re: [PATCH v5 4/7] X86: generic MSRs save/restore
Date: Fri, 13 Dec 2013 09:44:55 +0000	[thread overview]
Message-ID: <52AAE527020000780010CE4C@nat28.tlf.novell.com> (raw)
In-Reply-To: <DE8DF0795D48FD4CA783C40EC829233501425954@SHSMSX101.ccr.corp.intel.com>

>>> On 13.12.13 at 08:50, "Liu, Jinsong" <jinsong.liu@intel.com> wrote:

Please get your reply quoting fixed.

> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -1127,10 +1127,110 @@ static int hvm_load_cpu_xsave_states(str
>      return 0;
>  }
>  
> -/* We need variable length data chunk for xsave area, hence customized
> - * declaration other than HVM_REGISTER_SAVE_RESTORE.
> +#define HVM_CPU_MSR_SIZE(cnt) offsetof(struct hvm_msr, msr[cnt])
> +static unsigned int __read_mostly msr_count_max;
> +
> +static int hvm_save_cpu_msrs(struct domain *d, hvm_domain_context_t *h)
> +{
> +    struct vcpu *v;
> +
> +    if ( !msr_count_max )
> +        return 0;
> 
> ASSERT( msr_count_mas ); ?

Right. Left from before the registration was made conditional.

> +
> +    for_each_vcpu ( d, v )
> +    {
> +        struct hvm_msr *ctxt;
> +        unsigned int i;
> +
> +        if ( _hvm_init_entry(h, CPU_MSR_CODE, v->vcpu_id,
> +                             HVM_CPU_MSR_SIZE(msr_count_max)) )
> +            return 1;
> +        ctxt = (struct hvm_msr *)&h->data[h->cur];
> +        ctxt->count = 0;
> +
> +        if ( hvm_funcs.save_msr )
> +            hvm_funcs.save_msr(v, ctxt);
> +
> +        for ( i = 0; i < ctxt->count; ++i )
> +            ctxt->msr[i]._rsvd = 0;
> 
> What _rsvd for? seems not used at the patches.

See XSA-77 and
http://lists.xenproject.org/archives/html/xen-devel/2013-12/msg01522.html 
- avoid leaking hypervisor data.

> +static int hvm_load_cpu_msrs(struct domain *d, hvm_domain_context_t *h)
> +{
> +    unsigned int i, vcpuid = hvm_load_instance(h);
> +    struct vcpu *v;
> +    const struct hvm_save_descriptor *desc;
> +    const struct hvm_msr *ctxt;
> +    int err = 0;
> +
> +    if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL )
> +    {
> +        dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vcpu%u\n",
> +                d->domain_id, vcpuid);
> +        return -EINVAL;
> +    }
> +
> +    /* Customized checking for entry since our entry is of variable length */
> +    desc = (struct hvm_save_descriptor *)&h->data[h->cur];
> +    if ( sizeof (*desc) > h->size - h->cur)
> +    {
> +        printk(XENLOG_G_WARNING
> +               "HVM%d.%d restore: not enough data left to read MSR descriptor\n",
> +               d->domain_id, vcpuid);
> +        return -ENODATA;
> +    }
> +    if ( desc->length + sizeof (*desc) > h->size - h->cur)
> +    {
> +        printk(XENLOG_G_WARNING
> +               "HVM%d.%d restore: not enough data left to read %u MSR bytes\n",
> +               d->domain_id, vcpuid, desc->length);
> +        return -ENODATA;
> +    }
> +    if ( desc->length < HVM_CPU_MSR_SIZE(1) )
> +    {
> +        printk(XENLOG_G_WARNING
> +               "HVM%d.%d restore mismatch: MSR length %u < %zu\n",
> +               d->domain_id, vcpuid, desc->length, HVM_CPU_MSR_SIZE(1));
> +        return -EINVAL;
> +    }
> +
> +    h->cur += sizeof(*desc);
> +    ctxt = (struct hvm_msr *)&h->data[h->cur];
> +    h->cur += desc->length;
> +
> +    if ( desc->length != HVM_CPU_MSR_SIZE(ctxt->count) )
> +    {
> +        printk(XENLOG_G_WARNING
> +               "HVM%d.%d restore mismatch: MSR length %u != %zu\n",
> +               d->domain_id, vcpuid, desc->length,
> +               HVM_CPU_MSR_SIZE(ctxt->count));
> +        return -EOPNOTSUPP;
> +    }
> +    /* Checking finished */
> +
> +    for ( i = 0; i < ctxt->count; ++i )
> +    {
> +        if ( hvm_funcs.load_msr )
> +            err = hvm_funcs.load_msr(v, &ctxt->msr[i]);
> +        if ( err )
> +            break;
> +    }
> 
> Is it for vmx/svm specific msrs, or, will extend to generic msrs?
> If these patches are generic save/load mechanism supporting generic msrs and 
> vmx/sve specific msrs, it need update here.

In which way?

But I'll re-write this anyway, so that we don't need to handle MSRs
one by one (leveraging the _rsvd field).

> --- a/xen/include/public/arch-x86/hvm/save.h
> +++ b/xen/include/public/arch-x86/hvm/save.h
> @@ -592,9 +592,21 @@ struct hvm_tsc_adjust {
>  
>  DECLARE_HVM_SAVE_TYPE(TSC_ADJUST, 19, struct hvm_tsc_adjust);
>  
> +
> +struct hvm_msr {
> +    uint32_t count;
> +    struct hvm_one_msr {
> +        uint32_t index;
> +        uint32_t _rsvd;
> +        uint64_t val;
> +    } msr[1 /* variable size */];
> +};
> +
> +#define CPU_MSR_CODE  16
> +
> 
> It's incorrect, conflict with CPU_XSAVE_CODE and panic when 
> hvm_register_savevm(CPU_MSR_CODE, ...)
> Why not 20?

Copy-n-paste mistake. Thanks for spotting.

Jan

  reply	other threads:[~2013-12-13  9:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-03 14:50 [PATCH v5 4/7] X86: generic MSRs save/restore Liu, Jinsong
2013-12-04 14:18 ` Jan Beulich
2013-12-13  7:50   ` Liu, Jinsong
2013-12-13  9:44     ` Jan Beulich [this message]
2013-12-13  7:57   ` Liu, Jinsong
2013-12-13  9:47     ` Jan Beulich
2013-12-13 12:04       ` Andrew Cooper
2013-12-13 12:26         ` Jan Beulich
2013-12-13 14:01     ` [PATCH v2] x86: " Jan Beulich
2013-12-13 17:44       ` Andrew Cooper
2013-12-16  3:12         ` Liu, Jinsong
2013-12-16  8:03         ` Jan Beulich
2013-12-16  3:01       ` Liu, Jinsong
2013-12-16  8:04         ` Jan Beulich
2013-12-16  8:39           ` Liu, Jinsong
2013-12-16  8:52             ` Jan Beulich
2013-12-16  9:13               ` Liu, Jinsong
2013-12-16  9:41                 ` Jan Beulich
2013-12-16  9:53                   ` Liu, Jinsong
2013-12-16 10:01                     ` Jan Beulich
2013-12-16 10:05                       ` Liu, Jinsong
2013-12-16 11:11                         ` Jan Beulich
2013-12-16 13:23                           ` Liu, Jinsong
2013-12-16 13:34                             ` Jan Beulich
2013-12-16 13:57                               ` Liu, Jinsong
2013-12-16 14:01                                 ` Liu, Jinsong
2013-12-18 12:20       ` Liu, Jinsong
2013-12-13 14:02     ` [PATCH v2] x86: MSR_IA32_BNDCFGS save/restore Jan Beulich
2013-12-13 17:57       ` Andrew Cooper
2013-12-16  3:22         ` Liu, Jinsong
2013-12-16  8:06         ` Jan Beulich
2013-12-16  3:23       ` Liu, Jinsong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52AAE527020000780010CE4C@nat28.tlf.novell.com \
    --to=jbeulich@suse.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=haoxudong.hao@gmail.com \
    --cc=jinsong.liu@intel.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.