From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Wei Liu" <wei.liu2@citrix.com>,
"Jan Beulich" <JBeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [Xen-devel] [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
Date: Thu, 23 May 2019 11:27:03 +0100 [thread overview]
Message-ID: <1558607223-19630-1-git-send-email-andrew.cooper3@citrix.com> (raw)
Message-ID: <20190523102703.eha1eNjrTvvFNWYDbrlYfppEVwZLUU-mhcDn5Uf6_mM@z> (raw)
In-Reply-To: <1558540230-26612-1-git-send-email-andrew.cooper3@citrix.com>
This avoids opencoding the slightly-awkward logic. More uses of these
wrappers will be introduced shortly.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
I've decided to introduce this patch ahead of "[PATCH] libx86: Elide more
empty CPUID leaves when serialising a policy" (which simplifies the xstate
hunk a little) as I've found yet more cases where I need to use
cpuid_policy_xstates(), and opencoding them all seemed very silly.
---
xen/arch/x86/xstate.c | 8 ++------
xen/include/xen/lib/x86/cpuid.h | 12 ++++++++++++
xen/lib/x86/cpuid.c | 3 +--
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index 3da609a..04da569 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
const struct xsave_hdr *hdr)
{
- const struct cpuid_policy *cp = d->arch.cpuid;
- uint64_t xcr0_max =
- ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
+ uint64_t xcr0_max = cpuid_policy_xcr0(d->arch.cpuid);
unsigned int i;
if ( (hdr->xstate_bv & ~xcr0_accum) ||
@@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
int handle_xsetbv(u32 index, u64 new_bv)
{
struct vcpu *curr = current;
- const struct cpuid_policy *cp = curr->domain->arch.cpuid;
- uint64_t xcr0_max =
- ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
+ uint64_t xcr0_max = cpuid_policy_xcr0(curr->domain->arch.cpuid);
u64 mask;
if ( index != XCR_XFEATURE_ENABLED_MASK )
diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpuid.h
index 252d2c9..ea4db5b 100644
--- a/xen/include/xen/lib/x86/cpuid.h
+++ b/xen/include/xen/lib/x86/cpuid.h
@@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
p->feat._7a1 = fs[FEATURESET_7a1];
}
+static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
+{
+ return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
+}
+
+static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
+{
+ uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
+
+ return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
+}
+
const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature);
/**
diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c
index 23619c7..74c5b18 100644
--- a/xen/lib/x86/cpuid.c
+++ b/xen/lib/x86/cpuid.c
@@ -144,8 +144,7 @@ void x86_cpuid_policy_fill_native(struct cpuid_policy *p)
cpuid_count_leaf(0xd, 0, &p->xstate.raw[0]);
cpuid_count_leaf(0xd, 1, &p->xstate.raw[1]);
- xstates = ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_high) << 32);
- xstates |= (p->xstate.xcr0_low | p->xstate.xss_low);
+ xstates = cpuid_policy_xstates(p);
for ( i = 2; i < min_t(unsigned int, 63,
ARRAY_SIZE(p->xstate.raw)); ++i )
--
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:[~2019-05-23 10:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-22 15:50 [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy Andrew Cooper
2019-05-22 15:50 ` [Xen-devel] " Andrew Cooper
2019-05-23 8:33 ` Jan Beulich
2019-05-23 8:33 ` [Xen-devel] " Jan Beulich
2019-05-23 10:38 ` Andrew Cooper
2019-05-23 10:38 ` [Xen-devel] " Andrew Cooper
2019-05-23 10:27 ` Andrew Cooper [this message]
2019-05-23 10:27 ` [Xen-devel] [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy Andrew Cooper
2019-05-23 11:52 ` Jan Beulich
2019-05-23 11:52 ` [Xen-devel] " Jan Beulich
2019-05-23 11:59 ` Andrew Cooper
2019-05-23 11:59 ` [Xen-devel] " Andrew Cooper
2019-05-23 12:08 ` Jan Beulich
2019-05-23 12:08 ` [Xen-devel] " 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=1558607223-19630-1-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.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).