xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Isaila Alexandru <aisaila@bitdefender.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Paul Durrant <paul.durrant@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	xen-devel@lists.xen.org
Subject: Re: [PATCH v14 06/11] x86/hvm: Introduce hvm_save_mtrr_msr_one func
Date: Wed, 01 Aug 2018 17:57:33 +0300	[thread overview]
Message-ID: <1533135453.21125.41.camel@bitdefender.com> (raw)
In-Reply-To: <5B60530602000078001D9719@prv1-mh.provo.novell.com>

On Ma, 2018-07-31 at 06:16 -0600, Jan Beulich wrote:
> > 
> > > 
> > > > 
> > > > On 25.07.18 at 14:14, <aisaila@bitdefender.com> wrote:
> > This is used to save data from a single instance.
> > 
> > Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>
> > 
> > ---
> > Changes since v11:
> > 	- hvm_save_mtrr_msr() now returns err from
> > hvm_save_mtrr_msr_one().
> > 
> > Note: This patch is based on Roger Pau Monne's series[1]
> > ---
> >  xen/arch/x86/hvm/mtrr.c | 81 +++++++++++++++++++++++++++--------
> > --------------
> >  1 file changed, 44 insertions(+), 37 deletions(-)
> > 
> > diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c
> > index 48facbb..47a5c29 100644
> > --- a/xen/arch/x86/hvm/mtrr.c
> > +++ b/xen/arch/x86/hvm/mtrr.c
> > @@ -718,52 +718,59 @@ int hvm_set_mem_pinned_cacheattr(struct
> > domain *d, 
> > uint64_t gfn_start,
> >      return 0;
> >  }
> >  
> > -static int hvm_save_mtrr_msr(struct domain *d,
> > hvm_domain_context_t *h)
> > +static int hvm_save_mtrr_msr_one(struct vcpu *v,
> > hvm_domain_context_t *h)
> >  {
> > -    struct vcpu *v;
> > +    const struct mtrr_state *mtrr_state = &v->arch.hvm_vcpu.mtrr;
> > +    struct hvm_hw_mtrr hw_mtrr = {
> > +        .msr_mtrr_def_type = mtrr_state->def_type |
> > +                             MASK_INSR(mtrr_state->fixed_enabled,
> > +                                       MTRRdefType_FE) |
> > +                             MASK_INSR(mtrr_state->enabled,
> > MTRRdefType_E),
> > +        .msr_mtrr_cap      = mtrr_state->mtrr_cap,
> > +    };
> > +    unsigned int i;
> >  
> > -    /* save mtrr&pat */
> > -    for_each_vcpu(d, v)
> > +    if ( MASK_EXTR(hw_mtrr.msr_mtrr_cap, MTRRcap_VCNT) >
> > +         (ARRAY_SIZE(hw_mtrr.msr_mtrr_var) / 2) )
> >      {
> > -        const struct mtrr_state *mtrr_state = &v-
> > >arch.hvm_vcpu.mtrr;
> > -        struct hvm_hw_mtrr hw_mtrr = {
> > -            .msr_mtrr_def_type = mtrr_state->def_type |
> > -                                 MASK_INSR(mtrr_state-
> > >fixed_enabled,
> > -                                           MTRRdefType_FE) |
> > -                                 MASK_INSR(mtrr_state->enabled, 
> > MTRRdefType_E),
> > -            .msr_mtrr_cap      = mtrr_state->mtrr_cap,
> > -        };
> > -        unsigned int i;
> > +        dprintk(XENLOG_G_ERR,
> > +                "HVM save: %pv: too many (%lu) variable range
> > MTRRs\n",
> > +                v, MASK_EXTR(hw_mtrr.msr_mtrr_cap, MTRRcap_VCNT));
> > +        return -EINVAL;
> > +    }
> >  
> > -        if ( MASK_EXTR(hw_mtrr.msr_mtrr_cap, MTRRcap_VCNT) >
> > -             (ARRAY_SIZE(hw_mtrr.msr_mtrr_var) / 2) )
> > -        {
> > -            dprintk(XENLOG_G_ERR,
> > -                    "HVM save: %pv: too many (%lu) variable range
> > MTRRs\n",
> > -                    v, MASK_EXTR(hw_mtrr.msr_mtrr_cap,
> > MTRRcap_VCNT));
> > -            return -EINVAL;
> > -        }
> > +    hvm_get_guest_pat(v, &hw_mtrr.msr_pat_cr);
> >  
> > -        hvm_get_guest_pat(v, &hw_mtrr.msr_pat_cr);
> > +    for ( i = 0; i < MASK_EXTR(hw_mtrr.msr_mtrr_cap,
> > MTRRcap_VCNT); i++ )
> > +    {
> > +        /* save physbase */
> > +        hw_mtrr.msr_mtrr_var[i*2] =
> > +            ((uint64_t*)mtrr_state->var_ranges)[i*2];
> > +        /* save physmask */
> > +        hw_mtrr.msr_mtrr_var[i*2+1] =
> > +            ((uint64_t*)mtrr_state->var_ranges)[i*2+1];
> > +    }
> As you move/re-indent code, please fix obvious style violations
> (here: missing blanks around binary operators). It also would be
> really nice if you got rid of the ugly and risky casts, and used
> the actual structure fields instead.

Couldn't we just use a 
memcpy(hw_mtrr.msr_mtrr_var, mtrr_state->var_ranges,
MASK_EXTR(hw_mtrr.msr_mtrr_cap, MTRRcap_VCNT)) ?

Same as you suggested...
> 
> > 
> > -        for ( i = 0; i < MASK_EXTR(hw_mtrr.msr_mtrr_cap,
> > MTRRcap_VCNT); i++ )
> > -        {
> > -            /* save physbase */
> > -            hw_mtrr.msr_mtrr_var[i*2] =
> > -                ((uint64_t*)mtrr_state->var_ranges)[i*2];
> > -            /* save physmask */
> > -            hw_mtrr.msr_mtrr_var[i*2+1] =
> > -                ((uint64_t*)mtrr_state->var_ranges)[i*2+1];
> > -        }
> > +    for ( i = 0; i < NUM_FIXED_MSR; i++ )
> > +        hw_mtrr.msr_mtrr_fixed[i] =
> > +            ((uint64_t*)mtrr_state->fixed_ranges)[i];
> Whereas here I think you would best simply use memcpy(), again
> to get rid of the cast.
> 
... here

Thanks, 
Alex

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-08-01 14:57 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-25 12:14 [PATCH v14 00/11] x86/domctl: Save info for one vcpu instance Alexandru Isaila
2018-07-25 12:14 ` [PATCH v14 01/11] x86/cpu: Introduce vmce_save_vcpu_ctxt_one() func Alexandru Isaila
2018-07-31 11:56   ` Jan Beulich
2018-07-31 12:06     ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 02/11] x86/hvm: Introduce hvm_save_tsc_adjust_one() func Alexandru Isaila
2018-07-25 12:14 ` [PATCH v14 03/11] x86/hvm: Introduce hvm_save_cpu_ctxt_one func Alexandru Isaila
2018-07-31 12:01   ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 04/11] x86/hvm: Introduce hvm_save_cpu_xsave_states_one Alexandru Isaila
2018-07-31 12:04   ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 05/11] x86/hvm: Introduce hvm_save_cpu_msrs_one func Alexandru Isaila
2018-07-31 12:10   ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 06/11] x86/hvm: Introduce hvm_save_mtrr_msr_one func Alexandru Isaila
2018-07-31 12:16   ` Jan Beulich
2018-08-01 14:57     ` Isaila Alexandru [this message]
2018-08-01 15:03       ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 07/11] x86/hvm: Introduce viridian_save_vcpu_ctxt_one() func Alexandru Isaila
2018-07-31 12:17   ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 08/11] x86/hvm: Add handler for save_one funcs Alexandru Isaila
2018-07-31 12:34   ` Jan Beulich
2018-07-31 12:55     ` Isaila Alexandru
2018-07-31 13:32       ` Jan Beulich
2018-07-31 13:45         ` Isaila Alexandru
2018-07-31 14:22           ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 09/11] x86/domctl: Don't pause the whole domain if only getting vcpu state Alexandru Isaila
2018-07-31 13:08   ` Jan Beulich
2018-08-01 14:50     ` Isaila Alexandru
2018-08-01 15:10       ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 10/11] x86/hvm: Remove redundant save functions Alexandru Isaila
2018-07-31 13:24   ` Jan Beulich
2018-07-31 13:32     ` Isaila Alexandru
2018-07-31 14:26       ` Jan Beulich
2018-07-25 12:14 ` [PATCH v14 11/11] x86/hvm: Remove save_one handler Alexandru Isaila
2018-07-25 12:38 ` [PATCH v14 00/11] x86/domctl: Save info for one vcpu instance Jan Beulich

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=1533135453.21125.41.camel@bitdefender.com \
    --to=aisaila@bitdefender.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=paul.durrant@citrix.com \
    --cc=wei.liu2@citrix.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).