[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86: implement cpuid() in terms of cpuid_count()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 9 Aug 2023 14:29:42 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LELKa6p2/OKxQTGmguNp2vkQIbLmcSv+nDELPfyHX3Y=; b=gGJ82yNCR2LEMpVVcCFkfrGA6drxkegawsZ6Wg6HtZZpujN111RzldSRXQUTwZL5ZxXC9bAf9Nbrie79xEcRGgmf7eDWBTIUMvXnSgWY9qPVLX5xxtBG1m1U4QQmjVhZ4hpIzpmZ/m2/YefIhwEoj6d1d8wx+/M1fBmz8OG6fAEO1FmwYeV7HT3B/csq1nXTqiNMjbAJki7i2BPQd4qLiW2P2DW/UCxBALAZyJSzDfyUYd6HuSbp/sG/6Qkpch51gAMum23fjp7nqjgBq8Z/WlmbyvHCWQWjDmnE/8ZpwHKW76F+NHk9vkew9pXfBuN5USJHH9C+cjUCdcZuBHZZ7Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U7sGYmwSz5Wa0LUVrmfr0xxJ7Ngy/9ayMytBl/nykxdwou5fWxq52x8g+y94tMN+vvXvXG9v+aVQ3FwNrDhXb4YnzFS/LsDs3CaTv7Jj3I56a5iw/wSUKoiTVBt29KA7fRlIQ01gWGoZN/nIgG/TRuhtB/YjgQaWeVxJcWcpS2IaqN2iLMfXmow/XMXMt7e2TT+4C31sANGTlMkdwTd8wljSHSQZ9SAgIe0ZMv8oLRNa3Q2kZqPowCGZR1ORIDxA/mZGVYwN6wo34pG0vNBiveioj38j2H0+RYr6bBV52QHTko/wZXdRvJTXsNR3jgFTmaMR6RCp3eO5GQR3qM3MRQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 09 Aug 2023 12:29:51 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Since as a bug workaround (likely inapplicable to any 64-bit CPUs, but
it probably doesn't hurt to keep this) we clear %ecx on input anyway,
we can as well fall back to cpuid_count(). This allows getting rid of
four risky casts and makes things type-safe. The latter aspect requires
two type adjustments elsewhere. While adjusting init_intel_cacheinfo(),
convert three other local variables there as well. For the struct
cpuinfo_x86 change it is relevant to note that no 64-bit CPU comes
without CPUID support, and hence cpuid_level is never set to -1; the
comment there was simply stale.

No functional change intended, yet of course generated code isn't
identical.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
It may also be interesting to see whether this addresses issues Coverity
recently spotted (in error), in spec-ctrl.c:print_details(). Andrew
considers cpuid() being (just) a macro as a possible reason.

I'm willing to switch to an inline function, but I chose the macro route
because this way it's less code (and hence less redundancy) overall,
without any loss of functionality.

--- a/xen/arch/x86/cpu/intel_cacheinfo.c
+++ b/xen/arch/x86/cpu/intel_cacheinfo.c
@@ -172,8 +172,7 @@ void init_intel_cacheinfo(struct cpuinfo
            c->x86_vendor != X86_VENDOR_SHANGHAI)
        {
                /* supports eax=2  call */
-               int i, j, n;
-               int regs[4];
+               unsigned int i, j, n, regs[4];
                unsigned char *dp = (unsigned char *)regs;
                int only_trace = 0;
 
--- a/xen/arch/x86/include/asm/cpufeature.h
+++ b/xen/arch/x86/include/asm/cpufeature.h
@@ -23,7 +23,7 @@ struct cpuinfo_x86 {
     unsigned char x86_vendor;          /* CPU vendor */
     unsigned char x86_model;
     unsigned char x86_mask;
-    int cpuid_level;                   /* Maximum supported CPUID level, -1=no 
CPUID */
+    unsigned int cpuid_level;          /* Maximum supported CPUID level */
     unsigned int extended_cpuid_level; /* Maximum supported CPUID extended 
level */
     unsigned int x86_capability[NCAPINTS];
     char x86_vendor_id[16];
--- a/xen/arch/x86/include/asm/processor.h
+++ b/xen/arch/x86/include/asm/processor.h
@@ -131,13 +131,8 @@ static inline int cpu_nr_siblings(unsign
  * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx
  * resulting in stale register contents being returned.
  */
-#define cpuid(_op,_eax,_ebx,_ecx,_edx)          \
-    asm volatile ( "cpuid"                      \
-          : "=a" (*(int *)(_eax)),              \
-            "=b" (*(int *)(_ebx)),              \
-            "=c" (*(int *)(_ecx)),              \
-            "=d" (*(int *)(_edx))               \
-          : "0" (_op), "2" (0) )
+#define cpuid(op, eax, ebx, ecx, edx)          \
+        cpuid_count(op, 0, eax, ebx, ecx, edx)
 
 /* Some CPUID calls want 'count' to be placed in ecx */
 static inline void cpuid_count(



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.