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>,
	"Sergey Dyasli" <sergey.dyasli@citrix.com>,
	"Wei Liu" <wei.liu2@citrix.com>,
	"Jan Beulich" <JBeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 3/4] tools/libxc: Use x86_cpuid_lookup_vendor() rather than opencoding the logic
Date: Thu, 21 Mar 2019 12:21:05 +0000	[thread overview]
Message-ID: <1553170866-23812-4-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1553170866-23812-1-git-send-email-andrew.cooper3@citrix.com>

This doesn't address any of the assumptions that "anything which isn't AMD is
Intel".  This logic is expected to be replaced wholesale with libx86 in the
longterm.

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>
CC: Sergey Dyasli <sergey.dyasli@citrix.com>
---
 tools/libxc/xc_cpuid_x86.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
index 098affe..71e1ee7 100644
--- a/tools/libxc/xc_cpuid_x86.c
+++ b/tools/libxc/xc_cpuid_x86.c
@@ -32,6 +32,8 @@ enum {
 #include <xen/arch-x86/cpufeatureset.h>
 };
 
+#include <xen/asm/x86-vendors.h>
+
 #include <xen/lib/x86/cpuid.h>
 #include <xen/lib/x86/msr.h>
 
@@ -229,12 +231,7 @@ int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid,
 
 struct cpuid_domain_info
 {
-    enum
-    {
-        VENDOR_UNKNOWN,
-        VENDOR_INTEL,
-        VENDOR_AMD,
-    } vendor;
+    unsigned int vendor; /* X86_VENDOR_* */
 
     bool hvm;
     uint64_t xfeature_mask;
@@ -296,16 +293,7 @@ static int get_cpuid_domain_info(xc_interface *xch, uint32_t domid,
     int rc;
 
     cpuid(in, regs);
-    if ( regs[1] == 0x756e6547U &&      /* "GenuineIntel" */
-         regs[2] == 0x6c65746eU &&
-         regs[3] == 0x49656e69U )
-        info->vendor = VENDOR_INTEL;
-    else if ( regs[1] == 0x68747541U && /* "AuthenticAMD" */
-              regs[2] == 0x444d4163U &&
-              regs[3] == 0x69746e65U )
-        info->vendor = VENDOR_AMD;
-    else
-        info->vendor = VENDOR_UNKNOWN;
+    info->vendor = x86_cpuid_lookup_vendor(regs[1], regs[2], regs[3]);
 
     if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 ||
          di.domid != domid )
@@ -568,7 +556,7 @@ static void xc_cpuid_hvm_policy(const struct cpuid_domain_info *info,
         break;
     }
 
-    if ( info->vendor == VENDOR_AMD )
+    if ( info->vendor == X86_VENDOR_AMD )
         amd_xc_cpuid_policy(info, input, regs);
     else
         intel_xc_cpuid_policy(info, input, regs);
@@ -630,7 +618,7 @@ static void xc_cpuid_pv_policy(const struct cpuid_domain_info *info,
 
     case 0x80000000:
     {
-        unsigned int max = info->vendor == VENDOR_AMD
+        unsigned int max = info->vendor == X86_VENDOR_AMD
             ? DEF_MAX_AMDEXT : DEF_MAX_INTELEXT;
 
         if ( regs[0] > max )
@@ -736,7 +724,7 @@ static void sanitise_featureset(struct cpuid_domain_info *info)
         if ( !info->pv64 )
         {
             clear_bit(X86_FEATURE_LM, info->featureset);
-            if ( info->vendor != VENDOR_AMD )
+            if ( info->vendor != X86_VENDOR_AMD )
                 clear_bit(X86_FEATURE_SYSCALL, info->featureset);
         }
 
@@ -787,7 +775,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     input[0] = 0x80000000;
     cpuid(input, regs);
 
-    if ( info.vendor == VENDOR_AMD )
+    if ( info.vendor == X86_VENDOR_AMD )
         ext_max = (regs[0] <= DEF_MAX_AMDEXT) ? regs[0] : DEF_MAX_AMDEXT;
     else
         ext_max = (regs[0] <= DEF_MAX_INTELEXT) ? regs[0] : DEF_MAX_INTELEXT;
-- 
2.1.4


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

  parent reply	other threads:[~2019-03-21 12:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-21 12:21 [PATCH 0/4] x86/cpuid: Handling of synthetic cpuid_policy fields Andrew Cooper
2019-03-21 12:21 ` [PATCH 1/4] libx86: Introduce x86_cpuid_lookup_vendor() Andrew Cooper
2019-03-26 11:52   ` Jan Beulich
2019-03-26 13:11     ` Andrew Cooper
2019-03-26 14:07       ` Jan Beulich
2019-03-26 14:23         ` Juergen Gross
2019-03-26 14:39           ` Jan Beulich
2019-03-27 15:10             ` Andrew Cooper
     [not found]           ` <5C9A39B00200007800221F23@suse.com>
2019-03-26 14:47             ` Juergen Gross
2019-03-26 15:23               ` Jan Beulich
2019-03-21 12:21 ` [PATCH 2/4] x86/cpuid: Drop get_cpu_vendor() completely Andrew Cooper
2019-03-26 12:08   ` Jan Beulich
2019-03-26 16:41     ` Andrew Cooper
2019-03-21 12:21 ` Andrew Cooper [this message]
2019-03-26 12:09   ` [PATCH 3/4] tools/libxc: Use x86_cpuid_lookup_vendor() rather than opencoding the logic Jan Beulich
2019-03-21 12:21 ` [PATCH 4/4] libx86: Recalculate synthesised cpuid_policy fields when appropriate Andrew Cooper
2019-03-26 12:20   ` Jan Beulich
2019-03-26 12:34     ` Andrew Cooper
     [not found] <1553170866*23812*1*git*send*email*andrew.cooper3@citrix.com>
     [not found] ` <1553170866*23812*2*git*send*email*andrew.cooper3@citrix.com>
     [not found]   ` <5C9A12690200007800221E05@prv1*mh.provo.novell.com>
     [not found]     ` <c5d1df3d*038d*8c0a*97da*a71f8f3fd009@citrix.com>

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=1553170866-23812-4-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=sergey.dyasli@citrix.com \
    --cc=wei.liu2@citrix.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.