From nobody Tue Feb 10 11:15:54 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1770394592; cv=pass; d=zohomail.com; s=zohoarc; b=a7W7s59TCkM0gjs9t/+f1r0NQfLAz0MIXk8lgZeq1CVCgJiUTzVS7L4y9GMw/rQfb8JhYsgIC9x9W4QmGz24WqqN39fDJp4+qCIfOmvz4whbq6botF+uVvSQXa62qyso/YsCqS2rWjkXDw6a5SGUcsl6JKCzI4Kyir5xdSlF8yk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770394592; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3XqRfkRYraueuo3h0D16mjrku9u0GK6eRvjfilF9NFM=; b=IlyI1Ri45xHFvHtjfkZHHiu1Cfr68aHYqGmJWIMDkLUqdwmp5BpNLEb173e/TBRKsFuv5lkaizu6b9T1GkKEUtfFh/5Oj9QEehy9Q6t61HNhMU9FvjAO230VrzlyJG1B1/aCexlHxz6QmQCwvo/mGM10K7sxCdUJxjXipq02dOs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1770394592360861.1084874093305; Fri, 6 Feb 2026 08:16:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1223511.1530974 (Exim 4.92) (envelope-from ) id 1voOVB-0005y9-Lf; Fri, 06 Feb 2026 16:16:13 +0000 Received: by outflank-mailman (output) from mailman id 1223511.1530974; Fri, 06 Feb 2026 16:16:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1voOVB-0005y2-II; Fri, 06 Feb 2026 16:16:13 +0000 Received: by outflank-mailman (input) for mailman id 1223511; Fri, 06 Feb 2026 16:16:11 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1voOV9-0005HU-Pd for xen-devel@lists.xenproject.org; Fri, 06 Feb 2026 16:16:11 +0000 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azlp170100001.outbound.protection.outlook.com [2a01:111:f403:c110::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 239fb4e2-0377-11f1-9ccf-f158ae23cfc8; Fri, 06 Feb 2026 17:16:06 +0100 (CET) Received: from SA1PR04CA0005.namprd04.prod.outlook.com (2603:10b6:806:2ce::14) by LV3PR12MB9093.namprd12.prod.outlook.com (2603:10b6:408:19d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9587.14; Fri, 6 Feb 2026 16:16:02 +0000 Received: from SN1PEPF00036F3E.namprd05.prod.outlook.com (2603:10b6:806:2ce:cafe::34) by SA1PR04CA0005.outlook.office365.com (2603:10b6:806:2ce::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9587.16 via Frontend Transport; Fri, 6 Feb 2026 16:16:02 +0000 Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF00036F3E.mail.protection.outlook.com (10.167.248.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9587.10 via Frontend Transport; Fri, 6 Feb 2026 16:16:01 +0000 Received: from xcbagarciav01.xilinx.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Fri, 6 Feb 2026 10:16:00 -0600 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 239fb4e2-0377-11f1-9ccf-f158ae23cfc8 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aRxQ6yAe1818+J4I+sHXFyvZzfwUyY66oinUDS4T9DpKe2gkHtYXncbbaIuKX6F7kmbuyAtF4IdclZuUkwwJme36D0/KhM5FA6rWX5FQgDw7mpINWuK8NYAFmsI/3/P72gfDbXFgGJgzqoAEELduEyYbzG+XcYqOrbS3LwBylNNTdpvi1pfXFA+B5Vx0xM4R+qdNVuzVWVWqmtoSrromM+geD7oU2xKuoUzt+86SIk2C2kxCWJ+xfLGFMakaUgWD2Evn8DDtpQ4HzdlC19c2L+xmWxTxkxPPRa6a4Ne2zB8c4DkNeRl9ewnj86w8YRuUWsmSqWm3mWtMQm30E2Xaag== 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=3XqRfkRYraueuo3h0D16mjrku9u0GK6eRvjfilF9NFM=; b=ELk9Hu02OLTU6CxxZ+0kfq8vUHhPGEJHUd4p4UyI5oZ6k0+L/F8TtgDQy7UuNvZ70KrlE/41OExBqpA3D+bg9FNeeZu1AsjOFpRXBsgGT5fJTHPLlYv9Lodtu32d4LHqaujLpRaCcX6Q6hA/jUv+lZuLIokkupau7z9WjcSSQY66gE3pR+jqI3/I+3NkjYEM+aPlTY4ybvKbz0LzmqkLUAFHrYkPPAh1wYEglh7D1BHg1SG6eMeCIS2zf9mRiv9Q2usWiK59SpYeuUVq60HEJwGYwNCYqTGd4UmCrzRG8c1f7cPXzK8hY4mC5tRMuAEL7LJXfFvlYYUpOMCysbxsPQ== 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3XqRfkRYraueuo3h0D16mjrku9u0GK6eRvjfilF9NFM=; b=zYJ/eu6LSpsz6bl43V+uQ+9hDGo9pTCiN9cOxquqm8ASrOH68yGVf2hNGEJTSH1ZKhct8ogetR9NpUv6ym5LJFE9QUqlPRpfUN5206qMcBsqhGH4W2FsahzxtGpgv6R84MiUfVlL1iR0ya0ZRp4dCoRegG8N+DuFSHyGHPIjqLM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C From: Alejandro Vallejo To: CC: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jason Andryuk Subject: [PATCH 03/12] x86: Add cpu_vendor() as a wrapper for the host's CPU vendor Date: Fri, 6 Feb 2026 17:15:25 +0100 Message-ID: <20260206161539.209922-4-alejandro.garciavallejo@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260206161539.209922-1-alejandro.garciavallejo@amd.com> References: <20260206161539.209922-1-alejandro.garciavallejo@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00036F3E:EE_|LV3PR12MB9093:EE_ X-MS-Office365-Filtering-Correlation-Id: 17db9e9f-2f58-4aae-6f9e-08de659b0583 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?18fERMQhuiiD/6WQBkxfyvj+1suLtedGR2BlGQcTn33+IUtevwEBQ501UM6e?= =?us-ascii?Q?HoWdlaOJSonptG5yU4fuZizmgvguzhkmFAuZrRMchEY5I5+3eUgF3Xff2uXR?= =?us-ascii?Q?+9y31dLoc+XNJrB9DuaUUIzogDT0E7hykk3c4mrqKRtoj6hHsLxhIYnDCE4O?= =?us-ascii?Q?pMPPg1Uywx7iPgy5oTYdNXtqiu4SAe3tFVtIwknE31lykvoFjj3S/62vof15?= =?us-ascii?Q?ZARhOebDCdCFwifYyCweHejnr8qyBCyUKoK9AHk2XfRQ5+szD1k7N7E+bAOJ?= =?us-ascii?Q?Il/S0TQf3CcJPI3lYR4xeQ15fTn3rm1IK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XEyhmm?= =?us-ascii?Q?mWYNO4d4UFgKW1xElqmtwMPciR+HFzV4lCkHu6/uOd8YlCmGjKlbnfGN+8ks?= =?us-ascii?Q?kNCMkg0OfpFkzePU3dItokoqzShGBm+SJis9PuHlVtnMX58Q0A4CcSIX6LiY?= =?us-ascii?Q?HgV24BNJpj+Ip7dAFlk4E59iGkHpAevG9Bs9xVLfiyHQwRNRDEmfmG2B7XEh?= =?us-ascii?Q?QsibPnJILilek5CU1tTTmLwVkVItoSevSzxjhzcRvrgP3GRGEPMjyXX6pxEh?= =?us-ascii?Q?fEGlkvXGKdInUi5DhSoKepjIQAprRwxoiPF7su9g8wh2DjoWDUo7hVON9p8t?= =?us-ascii?Q?KdOINbJ4TMUyfjEZwVhd+od+c+PMghvr/ZMjg55zhIIN9mf5X81ryJUfpWL6?= =?us-ascii?Q?cmufzbg3bZmK9lVjGWbI2aav6zmN08J6KkwtyzYyJxaEj1xn3ktfoLz5flGP?= =?us-ascii?Q?fLsRMZFN0lHE2+wQvvYR+Qds4A4cxDIk8Wfa2NgdmagY2HxqV71lSOE4yG5p?= =?us-ascii?Q?kYqXOw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mZAyRuj5TFPP0OU1r5Y+bt0SyYxuwGmzx5X7vGzc0qfiXyaDPOdORLRyo87TI5fFviM0j5zxAyApYJUoUXbikSZfeVxpJie1Ykofrpbwk4N49jgEk4YGgpl/zhusZ0XZxXr6N2WWTPWtTrxMLutc2Mihy3Sv6n6yo5ejbj//h/pdNmS7DyOGeLKC19EbTY6/GEAPZHyGrmtBVvRxP3jkDeiTz/D3Ok9792sRi1Lg0HluqMqAU7B+9Oi5+KZaz5kv9Co0gzdVYrcQOHG8C7fL+9cjshIFav2NcVv3RITqk/WhyqzUBPR215uSYoP0lKqDmGEL6rr2iQmF3R19NF8pTzYPi5FwseCvm/6KnjgnfHFQKPfIDxNhC8CSNmsAKbOd65+mtNQ+3zsBLwW4LmYC4mFONzd8l4kDYpKYQvA//XYYgBbE71S6tq+CdOdUw2gt X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2026 16:16:01.9325 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17db9e9f-2f58-4aae-6f9e-08de659b0583 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00036F3E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9093 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1770394593009158500 Content-Type: text/plain; charset="utf-8" Introduces various optimisations that rely on constant folding, Value Range Propagation (VRP), and Dead Code Elimination (DCE) to aggressively eliminate code surrounding the uses of the function. * For single-vendor+no-unknown-vendor builds returns a compile-time constant. * For all other cases it ANDs the result with the mask of compiled vendors, with the effect of performing DCE in switch cases, removing dead conditionals, etc. It's difficult to reason about codegen in general in a project this big, but in this case the ANDed constant combines with the values typically checked against, folding into a comparison against zero. Thus, it's better for codegen to AND its result with the desired compared-against vendor, rather than using (in)equality operators. That way the comparison is always against zero. "cpu_vendor() & (X86_VENDOR_AMD | X86_VENDOR_HYGON)" turns into (cpu_vendor() & X86_VENDOR_AMD) in AMD-only builds (AND + cmp with zero). Whereas this... "cpu_vendor() =3D=3D X86_VENDOR_AMD" forces cpu_vendor() to be ANDed and then compared to a non-zero value. Later patches take the opportunity and make this refactor as cpu_vendor() is introduced throughout the tree. Signed-off-by: Alejandro Vallejo --- xen/arch/x86/cpu/common.c | 6 +++++- xen/arch/x86/guest/xen/xen.c | 4 ++++ xen/arch/x86/include/asm/cpufeature.h | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index ebe2baf8b9..6f4e723172 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -328,7 +328,11 @@ void __init early_cpu_init(bool verbose) *(u32 *)&c->x86_vendor_id[4] =3D edx; =20 c->x86_vendor =3D x86_cpuid_lookup_vendor(ebx, ecx, edx); - switch (c->x86_vendor) { + if ( c->x86_vendor !=3D cpu_vendor() ) + panic("CPU vendor not compiled-in: %s", + x86_cpuid_vendor_to_str(c->x86_vendor)); + + switch (cpu_vendor()) { case X86_VENDOR_INTEL: intel_unlock_cpuid_leaves(c); actual_cpu =3D intel_cpu_dev; break; case X86_VENDOR_AMD: actual_cpu =3D amd_cpu_dev; break; diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 77a3a8742a..ec558bcbdb 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -57,6 +57,10 @@ void asmlinkage __init early_hypercall_setup(void) cpuid(0, &eax, &ebx, &ecx, &edx); =20 boot_cpu_data.x86_vendor =3D x86_cpuid_lookup_vendor(ebx, ecx, edx= ); + + if ( cpu_vendor() !=3D boot_cpu_data.x86_vendor ) + panic("CPU vendor not compiled-in: %s", + x86_cpuid_vendor_to_str(boot_cpu_data.x86_vendor)); } =20 switch ( boot_cpu_data.x86_vendor ) diff --git a/xen/arch/x86/include/asm/cpufeature.h b/xen/arch/x86/include/a= sm/cpufeature.h index dcd223d84f..10309e40b6 100644 --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -14,6 +14,7 @@ #include #include #include +#include #else #include #endif @@ -116,6 +117,32 @@ static inline bool boot_cpu_has(unsigned int feat) =20 #define CPUID_PM_LEAF 6 =20 +#define X86_ENABLED_VENDORS \ + ((IS_ENABLED(CONFIG_INTEL) ? X86_VENDOR_INTEL : 0) | \ + (IS_ENABLED(CONFIG_AMD) ? X86_VENDOR_AMD : 0) | \ + (IS_ENABLED(CONFIG_CENTAUR) ? X86_VENDOR_CENTAUR : 0) | \ + (IS_ENABLED(CONFIG_SHANGHAI) ? X86_VENDOR_SHANGHAI : 0) | \ + (IS_ENABLED(CONFIG_HYGON) ? X86_VENDOR_HYGON : 0)) + +static always_inline uint8_t cpu_vendor(void) +{ + uint8_t vendor =3D boot_cpu_data.vendor; + + /* + * const-ify the CPU vendor if we compiled for a single vendor and the= re's + * no boot path for an unknown vendor. + */ + if ( !IS_ENABLED(CONFIG_UNKNOWN_CPU_VENDOR) && + (ISOLATE_LSB(X86_ENABLED_VENDORS) =3D=3D X86_ENABLED_VENDORS) ) + return X86_ENABLED_VENDORS; + + /* + * This allows the compiler to know more in its VRP pass about the val= id + * range of `vendor`. It enhances DCE by eliminating impossible vendor= s. + */ + return vendor & X86_ENABLED_VENDORS; +} + /* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1 #define cpu_has_de 1 --=20 2.43.0