All of lore.kernel.org
 help / color / mirror / Atom feed
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 v2 04/14] x86/cpuid: Handle more simple Intel leaves in guest_cpuid()
Date: Mon, 23 Jan 2017 14:39:07 +0000	[thread overview]
Message-ID: <1485182357-18031-5-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1485182357-18031-1-git-send-email-andrew.cooper3@citrix.com>

Intel now document leaf 2 as a plain leaf, with %al always containing the
value 0x01.  Collect this leaf normally in calculate_raw_policy() and expose
it to guests.  The leaf is reserved by AMD.

Intel leaves 3 and 9 (PSN and DCA respectively) are not exposed to guests at
all.  They are reserved by AMD.

Leaves 8 and 0xc are reserved by both vendors.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>

v2:
 * New
---
 xen/arch/x86/cpuid.c        | 32 ++++++++++++++++++++++++++------
 xen/include/asm-x86/cpuid.h |  3 +++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 87ec02f..7af5900 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -17,6 +17,11 @@ static const uint32_t hvm_hap_featuremask[] = INIT_HVM_HAP_FEATURES;
 static const uint32_t deep_features[] = INIT_DEEP_FEATURES;
 
 #define EMPTY_LEAF ((struct cpuid_leaf){})
+static void zero_leaves(struct cpuid_leaf *l,
+                        unsigned int first, unsigned int last)
+{
+    memset(&l[first], 0, sizeof(*l) * (last - first + 1));
+}
 
 struct cpuid_policy __read_mostly raw_policy,
     __read_mostly host_policy,
@@ -153,21 +158,31 @@ static void recalculate_xstate(struct cpuid_policy *p)
 
 /*
  * Misc adjustments to the policy.  Mostly clobbering reserved fields and
- * duplicating shared fields.
+ * duplicating shared fields.  Intentionally hidden fields are annotated.
  */
 static void recalculate_misc(struct cpuid_policy *p)
 {
+    p->basic.raw[0x8] = EMPTY_LEAF;
+    p->basic.raw[0xc] = EMPTY_LEAF;
+
     p->extd.e1d &= ~CPUID_COMMON_1D_FEATURES;
 
     switch ( p->x86_vendor )
     {
     case X86_VENDOR_INTEL:
+        p->basic.l2_nr_queries = 1; /* Fixed to 1 query. */
+        p->basic.raw[0x3] = EMPTY_LEAF; /* PSN - always hidden. */
+        p->basic.raw[0x9] = EMPTY_LEAF; /* DCA - always hidden. */
+
         p->extd.vendor_ebx = 0;
         p->extd.vendor_ecx = 0;
         p->extd.vendor_edx = 0;
         break;
 
     case X86_VENDOR_AMD:
+        zero_leaves(p->basic.raw, 0x2, 0x3);
+        p->basic.raw[0x9] = EMPTY_LEAF;
+
         p->extd.vendor_ebx = p->basic.vendor_ebx;
         p->extd.vendor_ecx = p->basic.vendor_ecx;
         p->extd.vendor_edx = p->basic.vendor_edx;
@@ -188,7 +203,7 @@ static void __init calculate_raw_policy(void)
     {
         switch ( i )
         {
-        case 0x2: case 0x4: case 0x7: case 0xd:
+        case 0x4: case 0x7: case 0xd:
             /* Multi-invocation leaves.  Deferred. */
             continue;
         }
@@ -694,8 +709,9 @@ static void pv_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res)
         break;
 
     case 0x0:
-    case 0x7:
-    case XSTATE_CPUID:
+    case 0x2 ... 0x3:
+    case 0x7 ... 0x9:
+    case 0xc ... XSTATE_CPUID:
     case 0x80000000:
         ASSERT_UNREACHABLE();
         /* Now handled in guest_cpuid(). */
@@ -841,8 +857,9 @@ static void hvm_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res)
         break;
 
     case 0x0:
-    case 0x7:
-    case XSTATE_CPUID:
+    case 0x2 ... 0x3:
+    case 0x7 ... 0x9:
+    case 0xc ... XSTATE_CPUID:
     case 0x80000000:
         ASSERT_UNREACHABLE();
         /* Now handled in guest_cpuid(). */
@@ -894,6 +911,9 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,
             goto legacy;
 
         case 0x0:
+        case 0x2 ... 0x3:
+        case 0x8 ... 0x9:
+        case 0xc:
             *res = p->basic.raw[leaf];
             break;
         }
diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h
index 4712b73..a15270a 100644
--- a/xen/include/asm-x86/cpuid.h
+++ b/xen/include/asm-x86/cpuid.h
@@ -115,6 +115,9 @@ struct cpuid_policy
                 uint32_t _1d;
                 struct { DECL_BITFIELD(1d); };
             };
+
+            /* Leaf 0x2 - TLB/Cache/Prefetch. */
+            uint8_t l2_nr_queries; /* Documented as fixed to 1. */
         };
     } basic;
 
-- 
2.1.4


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

  parent reply	other threads:[~2017-01-23 14:39 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-23 14:39 [PATCH v2 00/14] x86/cpuid: Handling of simple leaves in guest_cpuid() Andrew Cooper
2017-01-23 14:39 ` [PATCH v2 01/14] x86/cpufeatures: Expose self-snoop to all guests Andrew Cooper
2017-01-24 11:08   ` Jan Beulich
2017-01-24 11:28   ` Roger Pau Monné
2017-01-23 14:39 ` [PATCH v2 02/14] x86/cpuid: Handle leaf 0x80000000 in guest_cpuid() Andrew Cooper
2017-01-23 14:39 ` [PATCH v2 03/14] x86/cpuid: Only recalculate the shared feature bits once Andrew Cooper
2017-01-23 14:39 ` Andrew Cooper [this message]
2017-01-24 11:20   ` [PATCH v2 04/14] x86/cpuid: Handle more simple Intel leaves in guest_cpuid() Jan Beulich
2017-01-24 11:35     ` Andrew Cooper
2017-01-24 11:44       ` Jan Beulich
2017-01-23 14:39 ` [PATCH v2 05/14] x86/cpuid: Handle leaf 0x80000001 " Andrew Cooper
2017-01-24 11:51   ` Jan Beulich
2017-01-23 14:39 ` [PATCH v2 06/14] x86/cpuid: Handle the long vendor string " Andrew Cooper
2017-01-23 14:39 ` [PATCH v2 07/14] x86/cpuid: Handle leaves 0x80000005-7 " Andrew Cooper
2017-01-24 11:59   ` Jan Beulich
2017-01-24 14:48     ` Andrew Cooper
2017-01-24 15:05       ` Jan Beulich
2017-01-24 15:32         ` Andrew Cooper
2017-01-23 14:39 ` [PATCH v2 08/14] x86/cpuid: Handle leaf 0x80000008 " Andrew Cooper
2017-01-24 12:16   ` Jan Beulich
2017-01-24 15:31     ` Andrew Cooper
2017-01-24 15:50       ` Jan Beulich
2017-01-24 15:58         ` Andrew Cooper
2017-01-24 16:30   ` [PATCH v3 " Andrew Cooper
2017-01-25  9:22     ` Jan Beulich
2017-01-23 14:39 ` [PATCH v2 09/14] x86/cpuid: Handle leaf 0x80000009 " Andrew Cooper
2017-01-24 12:16   ` Jan Beulich
2017-01-23 14:39 ` [PATCH v2 10/14] x86/cpuid: Handle leaf 0x8000000a " Andrew Cooper
2017-01-24 12:20   ` Jan Beulich
2017-01-23 14:39 ` [PATCH v2 11/14] x86/cpuid: Handle leaves 0x8000000b-1a " Andrew Cooper
2017-01-23 14:47   ` Wei Liu
2017-01-24 12:26   ` Jan Beulich
2017-01-24 16:00     ` Andrew Cooper
2017-01-24 16:31   ` [PATCH v3 " Andrew Cooper
2017-01-25  9:22     ` Jan Beulich
2017-01-23 14:39 ` [PATCH v2 12/14] x86/cpufeatures: Hide Instruction Based Sampling from guests Andrew Cooper
2017-01-24 12:43   ` Jan Beulich
2017-01-23 14:39 ` [PATCH v2 13/14] x86/cpuid: Handle leaf 0x8000001c in guest_cpuid() Andrew Cooper
2017-01-23 18:50   ` Boris Ostrovsky
2017-01-24 16:20   ` Jan Beulich
2017-01-23 14:39 ` [PATCH v2 14/14] x86/cpuid: Remove the legacy path handling extd leaves Andrew Cooper
2017-01-24 16:29   ` 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=1485182357-18031-5-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.