xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Shuai Ruan <shuai.ruan@linux.intel.com>
Cc: andrew.cooper3@citrix.com, keir@xen.org, xen-devel@lists.xen.org
Subject: Re: [V4] x86/xsaves: calculate the xstate_comp_offsets base on xstate_bv
Date: Tue, 22 Mar 2016 04:53:02 -0600	[thread overview]
Message-ID: <56F1321E02000078000DF1CD@prv-mh.provo.novell.com> (raw)
In-Reply-To: <1458130372-7377-1-git-send-email-shuai.ruan@linux.intel.com>

>>> On 16.03.16 at 13:12, <shuai.ruan@linux.intel.com> wrote:

Please have patch subjects have [PATCH at their beginning.

> @@ -111,57 +111,70 @@ static int setup_xstate_features(bool_t bsp)
>      for ( leaf = 2; leaf < xstate_features; leaf++ )
>      {
>          if ( bsp )
> +        {
>              cpuid_count(XSTATE_CPUID, leaf, &xstate_sizes[leaf],
> -                        &xstate_offsets[leaf], &tmp, &tmp);
> +                        &xstate_offsets[leaf], &ecx, &edx);
> +            if ( ecx & XSTATE_ALIGN64 )
> +                __set_bit(leaf, &xstate_align);
> +        }
>          else
>          {
>              cpuid_count(XSTATE_CPUID, leaf, &eax,
> -                        &ebx, &tmp, &tmp);
> +                        &ebx, &ecx, &edx);
>              BUG_ON(eax != xstate_sizes[leaf]);
>              BUG_ON(ebx != xstate_offsets[leaf]);
> +            BUG_ON((ecx & XSTATE_ALIGN64) != test_bit(leaf, &xstate_align));

Neither side of the != seems correct: The left side would produce
0 or 2 (instead of 0 or 1), while the right side may produce any
non-zero value for truth.

> -static void __init setup_xstate_comp(void)
> +static void setup_xstate_comp(uint16_t *xstate_comp_offsets,
> +                              const u64 xstate_bv)
>  {
>      unsigned int i;
> +    uint16_t offset;
>  
>      /*
>       * The FP xstates and SSE xstates are legacy states. They are always
>       * in the fixed offsets in the xsave area in either compacted form
>       * or standard form.
>       */
> -    xstate_comp_offsets[0] = 0;

With the array now being uninitialized again you should no
longer delete this.

>      xstate_comp_offsets[1] = XSAVE_SSE_OFFSET;
>  
>      xstate_comp_offsets[2] = FXSAVE_SIZE + XSAVE_HDR_SIZE;
>  
> -    for ( i = 3; i < xstate_features; i++ )
> +    offset = xstate_comp_offsets[2];
> +    for ( i = 2; i < xstate_features; i++ )
>      {
> -        xstate_comp_offsets[i] = xstate_comp_offsets[i - 1] +
> -                                 (((1ul << i) & xfeature_mask)
> -                                  ? xstate_sizes[i - 1] : 0);
> -        ASSERT(xstate_comp_offsets[i] + xstate_sizes[i] <= xsave_cntxt_size);
> +        if ( (1ul << i) & xstate_bv )
> +        {
> +            if ( test_bit(i, &xstate_align) )
> +                offset = ROUNDUP(offset, 64);
> +            xstate_comp_offsets[i] = offset;
> +            offset += xstate_sizes[i];
> +            ASSERT(offset <= xsave_cntxt_size);

This would seem to better go after the loop now that it's
independent of the loop variable. Also at least for this purpose
I think it would be better is "offset" was "unsigned int".

>  static void *get_xsave_addr(struct xsave_struct *xsave,
> -        unsigned int xfeature_idx)
> +                            const uint16_t *xstate_comp_offsets,
> +                            unsigned int xfeature_idx)
>  {
>      if ( !((1ul << xfeature_idx) & xsave->xsave_hdr.xstate_bv) )
>          return NULL;
>  
> -    return (void *)xsave + (xsave_area_compressed(xsave)
> -            ? xstate_comp_offsets
> -            : xstate_offsets)[xfeature_idx];
> +    return (void *)xsave + ( xsave_area_compressed(xsave) ?
> +                             xstate_comp_offsets[xfeature_idx] :
> +                             xstate_offsets[xfeature_idx] );

Stray blanks inside the parentheses.

>  void expand_xsave_states(struct vcpu *v, void *dest, unsigned int size)
>  {
>      struct xsave_struct *xsave = v->arch.xsave_area;
> +    uint16_t xstate_comp_offsets[sizeof(xfeature_mask)*8];

There's no point in prefixing a local variable in this file with xstate_.
And the same goes for the function parameters earlier on.

> @@ -172,6 +185,8 @@ void expand_xsave_states(struct vcpu *v, void *dest, unsigned int size)
>      }
>  
>      ASSERT(xsave_area_compressed(xsave));
> +    setup_xstate_comp(xstate_comp_offsets, xstate_bv);

Don't you need to use xcomp_bv here? That's what "Extended
Region of an XSAVE Area" in SDM Vol 1 suggests to me.

> @@ -222,6 +238,7 @@ void compress_xsave_states(struct vcpu *v, const void *src, unsigned int size)
>      /* Set XSTATE_BV and XCOMP_BV.  */
>      xsave->xsave_hdr.xstate_bv = xstate_bv;
>      xsave->xsave_hdr.xcomp_bv = v->arch.xcr0_accum | XSTATE_COMPACTION_ENABLED;
> +    setup_xstate_comp(xstate_comp_offsets, xstate_bv);

Same here then I think.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-03-22 10:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16 12:12 Shuai Ruan
2016-03-22 10:53 ` Jan Beulich [this message]
2016-03-23  1:28   ` Shuai Ruan
     [not found]   ` <20160323012803.GA4131@shuai.ruan@linux.intel.com>
2016-03-23  3:28     ` Shuai Ruan

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=56F1321E02000078000DF1CD@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=keir@xen.org \
    --cc=shuai.ruan@linux.intel.com \
    --cc=xen-devel@lists.xen.org \
    --subject='Re: [V4] x86/xsaves: calculate the xstate_comp_offsets base on xstate_bv' \
    /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

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).