From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v3 2/2] x86/xstate: Make errors in xstate calculations more obvious by crashing the domain
Date: Thu, 19 Jul 2018 12:44:43 +0100 [thread overview]
Message-ID: <1532000683-23429-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1532000683-23429-1-git-send-email-andrew.cooper3@citrix.com>
If xcr0_max exceeds xfeature_mask, then something is broken with the CPUID
policy derivation or auditing logic. If hardware rejects new_bv, then
something is broken with Xen's xstate logic.
In both cases, crash the domain with an obvious error message, to help
highlight the issues.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
v2:
* Rebase over changes to patch 1.
v3:
* Check xcr0_max against xfeature_mask, rather than new_bv.
* Additional comments explaining what is going on.
---
xen/arch/x86/xstate.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index 1fbb087..c8197d2 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -707,12 +707,32 @@ int handle_xsetbv(u32 index, u64 new_bv)
if ( index != XCR_XFEATURE_ENABLED_MASK )
return -EOPNOTSUPP;
- if ( (new_bv & ~xcr0_max) ||
- (new_bv & ~xfeature_mask) || !valid_xcr0(new_bv) )
+ /*
+ * The CPUID logic shouldn't be able to hand out an XCR0 exceeding Xen's
+ * maximum features, but keep the check for robustness.
+ */
+ if ( unlikely(xcr0_max & ~xfeature_mask) )
+ {
+ gprintk(XENLOG_ERR,
+ "xcr0_max %016" PRIx64 " exceeds hardware max %016" PRIx64 "\n",
+ new_bv, xfeature_mask);
+ domain_crash(curr->domain);
+
+ return -EINVAL;
+ }
+
+ if ( (new_bv & ~xcr0_max) || !valid_xcr0(new_bv) )
return -EINVAL;
- if ( !set_xcr0(new_bv) )
+ /* By this point, new_bv really should be accepted by hardware. */
+ if ( unlikely(!set_xcr0(new_bv)) )
+ {
+ gprintk(XENLOG_ERR, "new_bv %016" PRIx64 " rejected by hardware\n",
+ new_bv);
+ domain_crash(curr->domain);
+
return -EFAULT;
+ }
mask = new_bv & ~curr->arch.xcr0_accum;
curr->arch.xcr0 = new_bv;
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-07-19 11:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-19 11:44 [PATCH v3 0/2] x86/xstate: Fixes and improvements to xsetbv handling Andrew Cooper
2018-07-19 11:44 ` [PATCH v3 1/2] x86/xstate: Use a guests CPUID policy, rather than allowing all features Andrew Cooper
2018-07-27 9:28 ` Jan Beulich
2018-07-27 9:37 ` Andrew Cooper
2018-07-27 10:18 ` Jan Beulich
2018-07-27 14:06 ` Jan Beulich
2018-07-19 11:44 ` Andrew Cooper [this message]
2018-07-27 13:24 ` [PATCH v3 2/2] x86/xstate: Make errors in xstate calculations more obvious by crashing the domain Jan Beulich
2018-07-27 13:35 ` Andrew Cooper
2018-07-31 10:37 ` [PATCH] x86/xstate: correct logging in handle_xsetbv() Jan Beulich
2018-07-31 10:38 ` Andrew Cooper
2018-07-19 18:48 ` [PATCH v3 0/2] x86/xstate: Fixes and improvements to xsetbv handling 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=1532000683-23429-3-git-send-email-andrew.cooper3@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).