From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH 4/6] x86/xstate: Fix latent bugs in expand_xsave_states()
Date: Mon, 12 Sep 2016 13:29:12 +0100 [thread overview]
Message-ID: <b81d965d-2cb2-5f2d-6ca8-3a74bf93219e@citrix.com> (raw)
In-Reply-To: <57D6B071020000780010E008@prv-mh.provo.novell.com>
On 12/09/16 12:41, Jan Beulich wrote:
>>>> On 12.09.16 at 11:51, <andrew.cooper3@citrix.com> wrote:
>> @@ -176,6 +187,11 @@ void expand_xsave_states(struct vcpu *v, void *dest, unsigned int size)
>> u64 xstate_bv = xsave->xsave_hdr.xstate_bv;
>> u64 valid;
>>
>> + /* Check there is state to serialise (i.e. at least an XSAVE_HDR) */
>> + BUG_ON(!v->arch.xcr0_accum);
>> + /* Check there is the correct room to decompress into. */
>> + BUG_ON(size != xstate_ctxt_size(v->arch.xcr0_accum));
> Further down I see you convert an ASSERT() to BUG_ON(), but I
> wonder why you do that and why the two above can't be ASSERT()
> too. xstate_ctxt_size() is not always cheap.
This isn't a fastpath, and the cpuid work will make xstate_ctxt_size()
into an O(1) operation.
Furthermore, following the investigation of XSA-186, I will not use
assertions for bounds checking. The potential damage of omitting the
check far outweighs the overhead of the unconditional check.
>
>> @@ -189,6 +205,7 @@ void expand_xsave_states(struct vcpu *v, void *dest, unsigned int size)
>> * Copy legacy XSAVE area and XSAVE hdr area.
>> */
>> memcpy(dest, xsave, XSTATE_AREA_MIN_SIZE);
>> + memset(dest + XSTATE_AREA_MIN_SIZE, 0, size - XSTATE_AREA_MIN_SIZE);
>>
>> ((struct xsave_struct *)dest)->xsave_hdr.xcomp_bv = 0;
>>
>> @@ -205,11 +222,9 @@ void expand_xsave_states(struct vcpu *v, void *dest, unsigned int size)
>>
>> if ( src )
>> {
>> - ASSERT((xstate_offsets[index] + xstate_sizes[index]) <= size);
>> + BUG_ON((xstate_offsets[index] + xstate_sizes[index]) <= size);
> Surely converting an ASSERT() to BUG_ON() means inverting the
> relational operator used?
Very true. It is unfortunate that all of this is dead code, and
impossible to test. I also had half a mind to explicitly #if 0 it out
to leave people in no illusion that it ever might have been tested.
>
>> memcpy(dest + xstate_offsets[index], src, xstate_sizes[index]);
>> }
>> - else
>> - memset(dest + xstate_offsets[index], 0, xstate_sizes[index]);
> So I have difficulty seeing why this memset() wasn't sufficient: It
> precisely covers for the respective component being in default
> state.
No it doesn't. The loop skips over all bits which are not set in xstate_bv.
I had (erroneously) come to the conclusion that the "if ( src )" check
only caught the case where we had bad comp_offsets[] information, but
rereading the logic, that case would actually corrupt the legacy SSE header.
Overall, it turns out that the "if ( src )" is unconditionally taken.
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-09-12 12:29 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-12 9:51 [PATCH 0/6] Fix multiple issues with xsave state handling on migrate Andrew Cooper
2016-09-12 9:51 ` [PATCH 1/6] x86/domctl: Introduce PV_XSAVE_HDR_SIZE and remove its opencoding Andrew Cooper
2016-09-12 11:05 ` Jan Beulich
2016-09-12 9:51 ` [PATCH 2/6] x86/domctl: Fix TOCTOU race with the use of XEN_DOMCTL_getvcpuextstate Andrew Cooper
2016-09-12 11:17 ` Jan Beulich
2016-09-12 12:02 ` Andrew Cooper
2016-09-12 12:33 ` Jan Beulich
2016-09-12 13:09 ` Andrew Cooper
2016-09-12 13:35 ` Jan Beulich
2016-09-12 13:37 ` Jan Beulich
2016-09-12 9:51 ` [PATCH 3/6] x86/domctl: Simplfy XEN_DOMCTL_getvcpuextstate when xsave is not in use Andrew Cooper
2016-09-12 11:26 ` Jan Beulich
2016-09-12 9:51 ` [PATCH 4/6] x86/xstate: Fix latent bugs in expand_xsave_states() Andrew Cooper
2016-09-12 11:41 ` Jan Beulich
2016-09-12 12:29 ` Andrew Cooper [this message]
2016-09-12 12:41 ` Jan Beulich
2016-09-12 12:43 ` Jan Beulich
2016-09-12 13:57 ` Andrew Cooper
2016-09-12 14:13 ` Jan Beulich
2016-09-12 9:51 ` [PATCH 5/6] x86/domctl: Fix migration of guests which are not using xsave Andrew Cooper
2016-09-12 12:14 ` Jan Beulich
2016-09-12 12:46 ` Andrew Cooper
2016-09-12 13:41 ` Jan Beulich
2016-09-12 9:51 ` [PATCH 6/6] x86/xstate: Fix latent bugs in compress_xsave_states() Andrew Cooper
2016-09-12 12:27 ` Jan Beulich
2016-09-12 12:59 ` Andrew Cooper
2016-09-12 13:47 ` Jan Beulich
2016-09-12 15:28 ` Andrew Cooper
2016-09-12 16:10 ` 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=b81d965d-2cb2-5f2d-6ca8-3a74bf93219e@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.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).