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

[PATCH 07/12] x86: Have x86_emulate/ implement the single-vendor optimisation


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Fri, 6 Feb 2026 17:15:29 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=rQHgXMWkC3Mm8J2pKE1eUqP0egx2Jwst5WiZnP3oWB0=; b=Ks8KuTI4oUYf1+j+FssvYdUB5v5cG7423mzUXeuCxVp1ubWI8gB0YYw3CbuGIzMaPnjd9rL6R2vFFnLYPtgDxT0GMukp6bdmgkHTJG8n1vinGhMG8WubW7c8cr7Uf7BfKftVqzH2StBFeHolsM5qUqf3h8vN6v7CryPti2r5IzqAkouBntNCs3w5sw21pDSYPwT7DkixcJ/gy/Z9vl/IHXggGU/TtD94gl1AejabuaSAxXQWbB7K0Mh/106H1gNXtOlKu1R3LXzoZm+I5FSsN9sg8j/7j0WfEcQ7C8Yta2qHHLfQPiHyOhUAGxODetppv7V8X2cT5+WLNmLKurmw3Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P/Up0Hp6fakxlzktGJH0t9/n8gGdORpWklY+8KO1WF07o27VJI54MhLbMkRX7VkOR9y5JjhH4Hh2JtG/L7JNFU/NRntHFxW8lW+UHBUrwz24oyRrY82AD9q+VDDm55w2/l3QZtYEJo1MWybyyUs57E9R3w1DE/YnV18qFi94dmcn16o63FCVjINTYPTHfJIwm/NTBsfwYYz4F1uLIPlcpKbM26Fs/SXXQR2OdjfjtRbOHb3SQsMkqox/AHqmA02u+sed+/IwTs2lJmFIYG7FujFup/isO32Q1irOk75Gtjr/BaBO9SY/PRAitvAyvYAWAgK1EecHKIESyq8N8jZZJQ==
  • Cc: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Fri, 06 Feb 2026 16:16:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Open code the vendor check through the policy as a one-off. The emulator
embeds amd_like() in macros and is called in MANY places. Using a
local variable (cp->x86_vendor) makes it a lot smaller (300-400 bytes
smaller). So treat this as the exception it is and let it use the policy
rather than boot_cpu_data.

Also keep the current behaviour of using the policy vendor when
compiled for userspace, where cross-vendor configurations are expected.

Not a functional change.

Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
---
 xen/arch/x86/x86_emulate/private.h     | 10 +++++++++-
 xen/arch/x86/x86_emulate/x86_emulate.c |  2 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/x86_emulate/private.h 
b/xen/arch/x86/x86_emulate/private.h
index 24c79c4e8f..95f2015c44 100644
--- a/xen/arch/x86/x86_emulate/private.h
+++ b/xen/arch/x86/x86_emulate/private.h
@@ -15,6 +15,7 @@
 # include <xen/kernel.h>
 
 # include <asm/cpu-user-regs.h>
+# include <asm/cpufeature.h>
 # include <asm/endbr.h>
 # include <asm/msr-index.h>
 # include <asm/stubs.h>
@@ -30,8 +31,15 @@ void BUG(void);
 #  define X86EMUL_NO_SIMD
 # endif
 
+/* intentionally avoid cpu_vendor(), as it produces much worse codegen */
+# define x86emul_cpu(cp) ((X86_ENABLED_VENDORS ==            \
+                           ISOLATE_LSB(X86_ENABLED_VENDORS)) \
+                               ? X86_ENABLED_VENDORS         \
+                               : ((cp)->x86_vendor & X86_ENABLED_VENDORS))
+
 #else /* !__XEN__ */
 # include "x86-emulate.h"
+# define x86emul_cpu(cp) ((cp)->x86_vendor)
 #endif
 
 #ifdef __i386__
@@ -520,7 +528,7 @@ in_protmode(
 static inline bool
 _amd_like(const struct cpu_policy *cp)
 {
-    return cp->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON);
+    return x86emul_cpu(cp) & (X86_VENDOR_AMD | X86_VENDOR_HYGON);
 }
 
 static inline bool
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c 
b/xen/arch/x86/x86_emulate/x86_emulate.c
index 7751a67130..308ec3579f 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -3104,7 +3104,7 @@ x86_emulate(
          * in fact risking to make guest OSes vulnerable to the equivalent of
          * XSA-7 (CVE-2012-0217).
          */
-        generate_exception_if(cp->x86_vendor == X86_VENDOR_INTEL &&
+        generate_exception_if((x86emul_cpu(cp) & X86_VENDOR_INTEL) &&
                               op_bytes == 8 && 
!is_canonical_address(_regs.rcx),
                               X86_EXC_GP, 0);
 #endif
-- 
2.43.0




 


Rackspace

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