From: Shuai Ruan <shuai.ruan@linux.intel.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: andrew.cooper3@citrix.com, keir@xen.org, xen-devel@lists.xen.org
Subject: Re: [V5] x86/xsaves: fix overwriting between non-lazy/lazy xsaves
Date: Wed, 23 Mar 2016 14:14:55 +0800 [thread overview]
Message-ID: <21085.0971438505$1458713930@news.gmane.org> (raw)
In-Reply-To: <20160323020224.GB4131@shuai.ruan@linux.intel.com>
On Wed, Mar 23, 2016 at 10:02:24AM +0800, Shuai Ruan wrote:
> > > - /* Set XSTATE_BV and XCOMP_BV. */
> > > + /* Set XSTATE_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);
> >
> > I see you set xcomp_bv (and hence the compaction bit) in xrstor()
> > now, but afaict that doesn't allow you to completely drop initializing
> > the field here, as the code there looks at the compaction bit.
> >
> > > + if ( unlikely(!(ptr->xsave_hdr.xcomp_bv &
> > > + XSTATE_COMPACTION_ENABLED)) )
> > > + ptr->xsave_hdr.xcomp_bv = ptr->xsave_hdr.xstate_bv
> > > + |XSTATE_COMPACTION_ENABLED;
> > > +
> > > + XRSTOR("0x48,","0x0f,0xc7,0x1f"); /* xrstors */
> > > + }
> > > + else
> > > + XRSTOR("0x48,","0x0f,0xae,0x2f"); /* xrstor */
> >
> > At this point, what guarantees that xcomp_bv is zero, no matter
> > where the state to be loaded originates from? I think at least in
> > arch_set_info_guest(), hvm_load_cpu_ctxt(), and
> > hvm_vcpu_reset_state() you went too far deleting code, and you
> > really need to keep the storing of zero there. Did you draw, just
> > for yourself, mentally or on a sheet of paper, a diagram illustrating
> > the various state transitions?
> >
> For above two comments.
>
> The patch is base on [v4]x86/xsaves: calculate the xstate_comp_offsets base
> on xstate_bv and I answer your question on why caculate xstate_comp_offset
> based on xstate_bv in previous thread. If that is right, drop
> initializing xcomp_bv is ok. Now xcomp_bv can guarantee to be zero for
> arch_set_info_guest() and hvm_load_cpu_ctxt(). If the drop is wrong
> (due to my misunderstand of the SDM), I will change the if () here.
>
Ignore the above paragraph, I realized that [v4]x86/xsaves: calculate
the xstate_comp_offsets base on xstate_bv is wrong(should be base on
xcomp_bv as previous version). Then I should not delete the code
initializing the xcomp_bv in compress_xsave_state()
But for hvm_vcpu_reset_state(), I think we should deleting the code
initializing the xcomp_bv as said below.
> For hvm_vcpu_reset_state(), we should depend on whether xsaves is used
> to decide whether to init xcomp_bv or not. And currently we use
> xcr0_accum to indicate the use of xsaves, when hvm_vcpu_reset_state()
> is called , can vcpu->xcr0_accum indicate using of xsaves ?
> I think in hvm_vcpu_reset_state(), we should leave xcomp_bv zero.
>
> > Since again you repeat the same logic twice, this should again have
> > been a signal that all your changes should go into the XRSTOR()
> > macro. Or alternatively, since the exception fixup also differs, you
> > may want to convert the whole logic into an XSAVES and an XSAVE
> > path. My only really sincere request here is - as little redundancy as
> > possible, since having to change the same thing twice in more than
> > one place is always calling for trouble.
I will do all changes only in XRSTOR(). Code like :
#define _XRSTOR(pfx, xrstor_ins)
asm volatile ( "1: .byte " pfx xrstor_ins"\n" \
"3:\n" \
" .section .fixup,\"ax\"\n" \
"2: incl %[faults]\n" \
" jmp 3b\n" \
" .previous\n" \
_ASM_EXTABLE(1b, 2b) \
: [mem] "+m" (*ptr), [faults] "+g" (faults) \
: [lmask] "a" (lmask), [hmask] "d" (hmask), \
[ptr] "D" (ptr) )
#define XRSTOR(pfx) \
if ( v->arch.xcr0_accum & XSTATE_XSAVES_ONLY ) \
{ \
if ( unlikely(!(ptr->xsave_hdr.xcomp_bv \
& XSTATE_COMPACTION_ENABLED)) ) \
ptr->xsave_hdr.xcomp_bv |= (ptr->xsave_hdr.xstate_bv \
| XSTATE_COMPACTION_ENABLED); \
_XRSTOR("0x48, ", "0x0f,0xc7,0x1f"); \
} \
else \
{ \
_XRSTOR("0x48, ", "0x0f,0xae,0x2f"); \
}
....
#undef XRSTOR
#undef _XRSTOR
A now wapper is intruduced as "_XRSTOR"( maybe the macro name is not
good ).
> > Xen-devel@lists.xen.org
> > http://lists.xen.org/xen-devel
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-03-23 6:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-18 3:01 [V5] x86/xsaves: fix overwriting between non-lazy/lazy xsaves Shuai Ruan
2016-03-22 14:34 ` Jan Beulich
2016-03-23 2:02 ` Shuai Ruan
[not found] ` <20160323020224.GB4131@shuai.ruan@linux.intel.com>
2016-03-23 6:14 ` Shuai Ruan [this message]
[not found] ` <20160323061455.GA12388@shuai.ruan@linux.intel.com>
2016-03-23 10:21 ` Jan Beulich
2016-03-23 11:01 ` 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='21085.0971438505$1458713930@news.gmane.org' \
--to=shuai.ruan@linux.intel.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.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 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).