From nobody Mon Nov 23 22:39:36 2026 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1792055413; cv=none; d=zohomail.com; s=zohoarc; b=lgRCXBIp9zL1QIcDxqa76xtuSxjth0dkXKoMknA4G9K9Q39Tg2A4FKsRtbPXygZHhNCljHe44UEBsXocbFgRw9/6vFT6g3lkkXxAeSZNuuQEBTu1l8VREFogtfFzWpdM7m/wcqTQQGUgFXsIPQNXB2ZqUdNRhFUDbLjqpT/8Dgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792055413; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FfAytH9CoSsG/4JADULfMO0l9a68bQmjhOGtCcq3NAA=; b=VrYLZ4IjYaT1RvNns1zMof+PR0zGbguMhta/5LJfnbo4NtTn1JG+nJXXIGnEPsCKOCuIhFGYg3HS04nFR2PHCcbmvj764scdRe+pe6FSenbMWnF2P8shPQjoMhMB0D5HOGytzzhq4Aj7uTOQnQPu2nIrmQrW1mtB99X7NunpXfI= ARC-Authentication-Results: i=1; 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; 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 1792055413625516.50907126441; Thu, 15 Oct 2026 02:10:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1450084.1665597 (Exim 4.92) (envelope-from ) id 1xHHTL-00086r-N2; Thu, 15 Oct 2026 09:09:59 +0000 Received: by outflank-mailman (output) from mailman id 1450084.1665597; Thu, 15 Oct 2026 09:09:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xHHTL-00086k-Jw; Thu, 15 Oct 2026 09:09:59 +0000 Received: by outflank-mailman (input) for mailman id 1450084; Thu, 15 Oct 2026 09:09:57 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xHHTJ-00086Z-LS for xen-devel@lists.xenproject.org; Thu, 15 Oct 2026 09:09:57 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xHHTJ-006f9K-2B for xen-devel@lists.xenproject.org; Thu, 15 Oct 2026 11:09:57 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ad0985e-bab6-0a2a0a5309dd-0a2a450ab7d4-16 for ; Thu, 15 Oct 2026 11:09:56 +0200 Received: from [209.85.128.44] (helo=mail-wm1-f44.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ad09864-f2d2-0a2a450a0019-d155802ce43a-3 for ; Thu, 15 Oct 2026 11:09:56 +0200 Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a17baef589so16282335e9.0 for ; Thu, 15 Oct 2026 02:09:56 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48de0bc50e0sm23382287f8f.49.2026.10.15.02.09.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Oct 2026 02:09:55 -0700 (PDT) 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1792055396; x=1792660196; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=FfAytH9CoSsG/4JADULfMO0l9a68bQmjhOGtCcq3NAA=; b=Qhazoehu8wvdjyV5UZzIK/akNa2WTK7B4puZhUEbYlJqYZ1WUt8YUeiVRYxcjfeQkI FdyAJbGGUUCetuFUYWfJ8gXf9Rjha0R+o5jonpI3FKpCOUlzCAQOLv5yxUhgTgRz3ZLs yeGwwg//T0hY8Q4Rrdh9xXwrg6kMJB4PSxvgH6qaWZsJL9kZohJjrWZciKZt9uyPJryF wNFV0hZdq2f/JKHHMtsq42EftVceekRKWfHZqOkNhlK4x4kjxwjqVYv5eZ+GWvK0L+ur 4YbRfRrWJbBDpuuhmAsbAUbiWCv1Ungmogdxiz9pgd6xCOLF9u+JHEaeaWhger/uzmm6 2szQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792055396; x=1792660196; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=FfAytH9CoSsG/4JADULfMO0l9a68bQmjhOGtCcq3NAA=; b=ytFHv8V3fvTcX2UlFk1jw5ZnCWP5oRLwDfw44ueh1+WNTwN8lI3Pq1mGJwbZGOyK9r k2C0J88LaiFRWY7luFe1Bp5nNRmdQzS6fJBow2kmwT2JCXGO9ZBpE/qWm77ZiHvnbsNh 6k6MqxLnluYoak/bWH5Eran5jlhmkPB0Z3kbn2j1fzuYdcv+wnRTr8VXlWXxJrTlGPM0 Leve0ngVDvsctaz+ByvNg1X0qHlU3et0Yxa2TYSDqn9vzxrpGfa2dgO+aTQtqPJUlWvt mSGuUg0Ot0YNmeu7WWVBz1CL5YX3fsdeo5bkcBWRXNUzcgcx+gXdyslRFqg53SiFJHaB GcdA== X-Gm-Message-State: AFq9FYLljtyYKbGvwK9eXYSQljaOK8xMjFnp2ndWcA14dMAj3pnx+cRY Arqgqtpw8ABjMofXUCjKG6vP/cPxqgTciQh43SUA0IcRIkSikfLdLt205JIdPf8sbsn0yoJTITr C0LC5Xw== X-Gm-Gg: AYBFou2ynX9E8FOECapOKcuGmUp+Dm1vhyAoTMHEtMQfZFxCJV3s52FjoPKotHgEU8F 6dUIW+gJAccKsCYSF95YPalcQ7j5srecWhz5qRC0a5o7X6CWocN27ylgZvGHcrZr3c12riTgfwC 1M9HA24os9KT4hauOI87YuERTyKNdisILS9QRwJ3e+iwYQGQyGFa3EDweiafrsuJZ/Bey/BfCQ2 mKaKjeakE1d5NvFDMCQ9IDAfldIyiclH45DQaAi4Ghr3/SGNe94hH8pZL/IJVRBtPyN98gNOab9 niCpi5x/DILebyHGIJuNsY9J3m26sC8UkXseH+qXD6Em8tq2rVDTFZNRFnbwjGumdR+fUdyKULE fG+3QZ8y0qxwzU2wnUXFrCZyihtZTYLKnuJiSaAP5tdQChiIuP02kZ5nwqLPjgYtbRXciD+IK28 8VyqDfewX95dvAgNCx1caLGh1aF5myE1tZnBxlcjvND4kDz/UwTgU7xDfD0Xa1ki7unCOnOQqgz Vn6g6PuBRd/xGGWJs+BrfVMhiMu9apdTTGoemzzoad5nPNxadrFUwyMmFUVYA== X-Received: by 2002:a05:600c:818d:b0:4a1:6c79:fd31 with SMTP id 5b1f17b1804b1-4a18e483231mr358300555e9.12.1792055396258; Thu, 15 Oct 2026 02:09:56 -0700 (PDT) Message-ID: Date: Thu, 15 Oct 2026 11:09:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 1/3] x86: allow Kconfig control over psABI level to use From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Jason Andryuk References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1792055396-5A3DCCFC-D6A4BF8D/10/78276251493 X-purgate-type: spam X-purgate-size: 10756 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1792055414189158500 Content-Type: text/plain; charset="utf-8" Newer hardware offers more efficient and/or flexible and/or capable instructions, some of which we can make good use of in the hypervisor as well. Allow a basic way (no alternatives patching) of enabling their use. Of course this means that hypervisors thus built won't work anymore on older, less capable hardware. Since older compilers (apparently gcc10 / clang11 and older) won't recognize -march=3Dx86-64-v2 etc, also add fallback logic passing -mpopcnt and alike explicitly. Note that in efi_arch_cpu() the filling of 7c0 and 7d0 are forward- looking; we only require 7b0, but we need to use cpuid_count() anyway. Signed-off-by: Jan Beulich --- TBD: While the added assembly code goes strictly from the CONFIG_* settings, EFI code uses the compiler provided manifest constants where available (just like the subsequent "x86: short-circuit certain cpu_has_* when x86-64-v{2,3} are in effect"). While I generally prefer it that way, this comes with a downside: If we ever started to use one of the ISA extensions in assembly code (and then keyed to the CONFIG_* settings), things could break. I don't view us doing this as very likely though, as then we'd need to have two (or more) variants of such assembly code, which we would likely want to avoid. (What I'd like to avoid is using the compiler manifest constants in assembly code: In principle we ought to filter out any -march=3D when constructing AFLAGS, and perhaps at least all -m... and -f... options. Compilers might rightfully complain about their use as inapplicable, much like we've seen for -Wl,... when no linking is done.) TBD: While we don't document most "cpuid=3Dno-*" options (and hence imply their use to be unsupported), using e.g. "cpuid=3Dno-popcnt" with a V2=3Dy hypervisor clearly can't have the intended effect, and hence might perhaps better be flagged in some way. TBD: v2 also includes LAHF/SAHF. Since we don't use floating point and hence FPU insns, we ought to be okay not explicitly checking for it. But there is a certain amount of risk of the compiler finding some "smart" use for one or both of the insns. However, if we were to check the feature, we'd need to account for the quirk that init_amd() also works around. Whereas the baseline -> v2 step isn't much of a difference (we'll gain more there by a subsequent patch), v2 -> v3, while presumably (or shall I say hopefully) faster, yields an overall growth of .text size by (in my build) about 2k. The primary reason for this appear to be conversions of SHL-by-immediate to SHLX. The VGA output attempt in early (MB/MB2) boot code does not appear to work (anymore?). The serial output may work, but only if - without any setup in Xen - both sides agree on the serial settings (baud rate etc). Hence the feature checks added on the legacy paths are of limited use. --- v4: Correct __LZCNT__ check in efi_arch_cpu(). Drop CONFIG_UNSATISFIED_* part. Simplify logic in arch.mk, now that gcc5 is our baseline. Reduce code size in trampoline_setup. Re-base. v3: Add fallback logic and use logic from new prereq change. v2: Also cover XSAVE. Add early boot feature checking. --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -116,6 +116,36 @@ config PV_LINEAR_PT =20 If unsure, say Y. =20 +choice + prompt "base psABI level" + default X86_64_BASELINE + help + The psABI defines 4 levels of ISA extension sets as a coarse granular + way of identifying advanced functionality that would be uniformly + available in respectively newer hardware. While v4 is not really of + interest for Xen, the others can be selected here, making the + resulting Xen no longer work on older hardware. This option won't + have any effect if the toolchain doesn't support the distinction. + + If unsure, stick to the default. + +config X86_64_BASELINE + bool "baseline" + +config X86_64_V2 + bool "v2" + help + This enables POPCNT and CX16, besides other extensions which are of + no interest here. + +config X86_64_V3 + bool "v3" + help + This enables BMI, BMI2, LZCNT, MOVBE, and XSAVE, besides other + extensions which are of no interest here. + +endchoice + source "arch/x86/hvm/Kconfig" =20 config XEN_SHSTK --- a/xen/arch/x86/arch.mk +++ b/xen/arch/x86/arch.mk @@ -34,6 +34,27 @@ CFLAGS +=3D -mno-red-zone -fpic # the SSE setup for variadic function calls. CFLAGS +=3D -mno-mmx -mno-sse $(call cc-option,$(CC),-mskip-rax-setup) =20 +# Enable the selected baseline ABI, if supported by the compiler. +x86-64-$(CONFIG_X86_64_BASELINE) :=3D +x86-64-$(CONFIG_X86_64_V2) :=3D x86-64-v2 +x86-64-$(CONFIG_X86_64_V3) :=3D x86-64-v3 + +ifneq ($(x86-64-y),) + +CFLAGS-psabi :=3D $(call cc-option,$(CC),-march=3D$(x86-64-y)) + +ifneq ($(CFLAGS-psabi),) +CFLAGS +=3D $(CFLAGS-psabi) +else +# Fall back to using the subset of -m... options that are of interest. +x86-64-v2 :=3D -mpopcnt -mcx16 +x86-64-v3 :=3D $(x86-64-v2) -mbmi -mbmi2 -mlzcnt -mmovbe -mxsave +CFLAGS-$(CONFIG_X86_64_V2) +=3D $(x86-64-v2) +CFLAGS-$(CONFIG_X86_64_V3) +=3D $(x86-64-v3) +endif # CFLAGS-psabi + +endif # x86-64-y + ifeq ($(CONFIG_INDIRECT_THUNK),y) # Compile with gcc thunk-extern, indirect-branch-register if available. CFLAGS-$(CONFIG_CC_IS_GCC) +=3D -mindirect-branch=3Dthunk-extern --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -136,6 +136,12 @@ multiboot2_header: #ifdef CONFIG_REQUIRE_NX .Lno_nx_msg: .asciz "ERR: Not an NX-capable CPU!" #endif +#if defined(CONFIG_X86_64_V2) || defined(CONFIG_X86_64_V3) +.Lno_x86_64_v2_msg: .asciz "ERR: Not an x86-64-v2 capable CPU!" +#endif +#ifdef CONFIG_X86_64_V3 +.Lno_x86_64_v3_msg: .asciz "ERR: Not an x86-64-v3 capable CPU!" +#endif =20 .section .init.data, "aw", @progbits .subsection 1 /* Put data here after the page tables (in x86_64.S)= . */ @@ -169,9 +175,20 @@ early_error: /* Here to improve the disa jmp .Lget_vtb #ifdef CONFIG_REQUIRE_NX .Lno_nx: + pop %ecx mov $sym_offs(.Lno_nx_msg), %ecx jmp .Lget_vtb #endif +#if defined(CONFIG_X86_64_V2) || defined(CONFIG_X86_64_V3) +.Lno_x86_64_v2: + mov $sym_offs(.Lno_x86_64_v2_msg), %ecx + jmp .Lget_vtb +#endif +#ifdef CONFIG_X86_64_V3 +.Lno_x86_64_v3: + mov $sym_offs(.Lno_x86_64_v3_msg), %ecx + jmp .Lget_vtb +#endif .Lmb2_no_bs: /* * Ditto. Additionally, here there is a chance that Xen was started @@ -532,6 +549,7 @@ trampoline_setup: mov $1, %eax cpuid mov %ecx, CPUINFO_FEATURE_OFFSET(X86_FEATURE_HYPERVISOR) + sym= _esi(boot_cpu_data) + mov %ecx, %edi =20 mov $0x80000000,%eax cpuid @@ -549,6 +567,9 @@ trampoline_setup: bt $cpufeat_bit(X86_FEATURE_LM),%edx jnc .Lbad_cpu =20 + /* Preserve %ecx for later use. */ + push %ecx + /* * Check for NX * - If Xen was compiled requiring it simply assert it's @@ -599,6 +620,36 @@ trampoline_setup: .Lno_nx: #endif =20 + /* Restore CPUID[80000001].ecx output. */ + pop %ecx + +#if defined(CONFIG_X86_64_V2) || defined(CONFIG_X86_64_V3) + mov %edi, %eax + or $cpufeat_mask(X86_FEATURE_POPCNT) | cpufeat_mask(X86_FEATU= RE_CX16), %eax + cmp %edi, %eax + jne .Lno_x86_64_v2 +#endif + +#ifdef CONFIG_X86_64_V3 + mov %edi, %eax + or $cpufeat_mask(X86_FEATURE_MOVBE) | cpufeat_mask(X86_FEATUR= E_XSAVE), %eax + cmp %edi, %eax + jne .Lno_x86_64_v3 + bt $cpufeat_bit(X86_FEATURE_ABM), %ecx + jnc .Lno_x86_64_v3 + xor %eax, %eax + cpuid + cmp $7, %eax + jb .Lno_x86_64_v3 + mov $7, %eax + xor %ecx, %ecx + cpuid + mov %ebx, %eax + or $cpufeat_mask(X86_FEATURE_BMI1) | cpufeat_mask(X86_FEATURE= _BMI2), %eax + cmp %ebx, %eax + jne .Lno_x86_64_v3 +#endif + /* Stash TSC to calculate a good approximation of time-since-boot = */ rdtsc mov %eax, sym_esi(boot_tsc_stamp) --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -742,29 +742,53 @@ static void __init efi_arch_handle_modul =20 static void __init efi_arch_cpu(void) { - uint32_t eax =3D cpuid_eax(0x80000000U); + uint32_t eax =3D cpuid_eax(0), dummy; uint32_t *caps =3D boot_cpu_data.x86_capability; =20 boot_tsc_stamp =3D rdtsc(); =20 - caps[FEATURESET_1c] =3D cpuid_ecx(1); + if ( eax ) + caps[FEATURESET_1c] =3D cpuid_ecx(1); =20 + if ( eax >=3D 7 ) + cpuid_count(7, 0, &dummy, + &caps[FEATURESET_7b0], + &caps[FEATURESET_7c0], + &caps[FEATURESET_7d0]); + + eax =3D cpuid_eax(0x80000000U); if ( (eax >> 16) =3D=3D 0x8000 && eax > 0x80000000U ) - { - caps[FEATURESET_e1d] =3D cpuid_edx(0x80000001U); + cpuid(0x80000001U, &dummy, &dummy, + &caps[FEATURESET_e1c], &caps[FEATURESET_e1d]); + + /* + * Checks here purposefully don't use cpu_has_* because they bypass + * boot_cpu_data reads if Xen was compiled with respective CONFIG_*. + */ +#define CHK(ppsym, feat) do { \ + if ( IS_ENABLED(ppsym) && \ + !boot_cpu_has(X86_FEATURE_ ## feat) ) \ + blexit(L"This build of Xen requires " #feat " support"); \ + } while ( false ) + + CHK(CONFIG_REQUIRE_NX, NX); + + /* x86-64-v2 */ + CHK(__POPCNT__, POPCNT); + CHK(CONFIG_X86_64_V2, CX16); + CHK(CONFIG_X86_64_V3, CX16); + + /* x86-64-v3 */ + CHK(__LZCNT__, ABM); + CHK(__BMI__, BMI1); + CHK(__BMI2__, BMI2); + CHK(__MOVBE__, MOVBE); + CHK(__XSAVE__, XSAVE); + +#undef CHK =20 - /* - * This check purposefully doesn't use cpu_has_nx because - * cpu_has_nx bypasses the boot_cpu_data read if Xen was compiled - * with CONFIG_REQUIRE_NX - */ - if ( IS_ENABLED(CONFIG_REQUIRE_NX) && - !boot_cpu_has(X86_FEATURE_NX) ) - blexit(L"This build of Xen requires NX support"); - - if ( cpu_has_nx ) - trampoline_efer |=3D EFER_NXE; - } + if ( cpu_has_nx ) + trampoline_efer |=3D EFER_NXE; } =20 static void __init efi_arch_blexit(void) From nobody Mon Nov 23 22:39:36 2026 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1792055447; cv=none; d=zohomail.com; s=zohoarc; b=ToR6V8SaFqY0kTbBhlCDr/YZJb0Qnu5cqilxT/NDToV6/9TMDkAn1OdbFGcoOWRbNQUXGKg2OA6aPbvUjpiXR5ngAJd9Mk9PvtMk7pLGu1O6JkQkud3QL3QiSjFGWw75lIG9T0TZjD3snVu1Hye8I8+ACdvQVJS3gBvvt+cUpBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792055447; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Pajwugmxj1oAgJF5ydgGa4DsXBBn331IhkZGgrXGYHc=; b=MNqPqhA28VyjBjsq3n9w+JQbHW9pRVWi474nT9Xyai2/S3TAhSbTFn4DJMu23a0NAuR5fj5GsYCb4jV0XAZhKsdReKMYpgUXNVSuCuemVobosoUEzXkZufHSq3jx61+Gw7E4C4rgY7Fh5hOsy1GyLKZBPVaZ5gBF0skUrr0NeXA= ARC-Authentication-Results: i=1; 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; 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 1792055447113686.8004177080057; Thu, 15 Oct 2026 02:10:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1450088.1665605 (Exim 4.92) (envelope-from ) id 1xHHTp-0001Aa-Tu; Thu, 15 Oct 2026 09:10:29 +0000 Received: by outflank-mailman (output) from mailman id 1450088.1665605; Thu, 15 Oct 2026 09:10:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xHHTp-0001AT-RI; Thu, 15 Oct 2026 09:10:29 +0000 Received: by outflank-mailman (input) for mailman id 1450088; Thu, 15 Oct 2026 09:10:29 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xHHTp-0001AL-69 for xen-devel@lists.xenproject.org; Thu, 15 Oct 2026 09:10:29 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xHHTo-006fO4-Iw for xen-devel@lists.xenproject.org; Thu, 15 Oct 2026 11:10:28 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ad09882-2eae-0a2a0a5409dd-0a2a4502b82e-12 for ; Thu, 15 Oct 2026 11:10:28 +0200 Received: from [209.85.221.53] (helo=mail-wr1-f53.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ad09884-6ca4-0a2a45020019-d155dd35cc54-3 for ; Thu, 15 Oct 2026 11:10:28 +0200 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-48df8fe8513so109819f8f.0 for ; Thu, 15 Oct 2026 02:10:28 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a1bd7319c6sm65192075e9.0.2026.10.15.02.10.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Oct 2026 02:10:24 -0700 (PDT) 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1792055428; x=1792660228; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=Pajwugmxj1oAgJF5ydgGa4DsXBBn331IhkZGgrXGYHc=; b=FMw/Y86RfncWzut8AncSoaoBsjhtH3nS+5b3TGRqP2vncDOXW1+am1Xqx0dc1TAtLK vu+ALHufVPDaXGfHcRpMqbCZZJWEA90jq/vWh9XUvcZEFdRmbSz9QGBgV6iJChbPPzpm juBUGoIBKgwIOhP8KmnqMWQE4ZdTYraPRx+vICzqlZTi8qVgggiZ+svPYlyg1rbsmSaq 0DR5zKfM/i4erxJMTnY38PrbocnCRv+fh7suPnuNSAIzVyac18TMZ6n/f9ZfuRL6mNBb WxP0rKKUfmBOpknRdBNBOSBOe9CcCOD7qizpJPliPTNdxCTy44WCVKq7WuH+H69JnGFP iv0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792055428; x=1792660228; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=Pajwugmxj1oAgJF5ydgGa4DsXBBn331IhkZGgrXGYHc=; b=nfD39YaDdKVsSF0UsEXZLZsCXgTGkWl2MwXBgWGNwapgBSyG6PbXXpp7epmhV73FV8 rLE667eZujYxdTkbYDW9LV+NAnHRpjhbl2dSuGx3hRnPLX0HYX/Wo+myL59RCHHq6e2d ZdHZ5fSsjAwH9JElAvi6ED9poKrgS9rA7ld85WN3wVhN+JDdz72HYUbnThmPdhzB1jLN hzdkEvgo3bRojvZOFFcQ/LIx2oTqZRx2UAlNTYr/xL0mTv2QCj/+vzjikDV5qx+tdKS0 ijRKISwRE80s6mNZ/m7MJOPJZsTvr2ouqu5Gv2EP6lJAGD3JvMsnvpxK0H9tRiM9n/gm jvVg== X-Gm-Message-State: AFq9FYL9Z6tZQAkqCpzE8utD8VMMYV405zUXJ8sQ4/pEE4sxNnvGeSAZ WUd8Y0BXP5g2oETMXgRFvh8K0/NGmqVSAGntY+ElYiY61jlt5RhqlqPmyh28OW4j5xzesTtY7f3 TLoP2vg== X-Gm-Gg: AYBFou18QUk11LuRL+2WzIjCY/szpgPaqPgZ8crTE+EZZOeSM+71UdzVCaCCT2PHA3d qlrD5Dsdyfz2RYRk7eKmrMg301XqZ6KnW7cGOnvrNAFoATiEUMh8gNbp43lJxijJ0ce2PXIShqK dW5O2U8Y5TvZ9seUPBK/BetPnzAyoEwHzFK/C81DCMhGSCBHgTS1x29ZC86srnfSBFFy6JIxgpO fTUGEbpSsGEGISM4SVwf+oDcMTzCGmbSdO+1p9wTCjsdUqigEQP93g78WnXxTMiIidhqB9GdDxU pJMas5BY1WKHhVlkEHYXX2Ti+ArMvrcqofYQLheHfqBnuUs6CSVkOyQDK4Te3CwiI85NldJk7Rp 6+I4c3CqZ5v1umu+ET0MkC+ARms49jERPxgT9KAmLOcHL9obIuIGIshkJoezPxaDc3qZtP1zr7u YkI5NNvz2K0ubMRsjloDSCef/QvPIrK3BW39DFTa7bvJK0+hmsJQuSN/U5dv4Wan3+sbLdET62j cUnOEInZxzPaYI7x2wmTCg3m9uu4XUX+U1hNvr/2zDTWOUg5Up0OAmp6E0HF0k= X-Received: by 2002:a05:600c:a112:b0:4a1:9663:7633 with SMTP id 5b1f17b1804b1-4a1966379f7mr258555625e9.11.1792055425863; Thu, 15 Oct 2026 02:10:25 -0700 (PDT) Message-ID: <9e48f405-4e99-4258-921e-2948f0d6754d@suse.com> Date: Thu, 15 Oct 2026 11:10:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 2/3] x86: use __builtin_popcountl() for arch_hweightl() when available From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Jason Andryuk References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1792055428-F24B62AC-CC136329/10/78276251493 X-purgate-type: spam X-purgate-size: 764 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1792055448955158501 Content-Type: text/plain; charset="utf-8" Use the respective compiler builtin when available; no need to play any alternatives games in such configurations. Signed-off-by: Jan Beulich --- v4: Re-base (re-do). --- a/xen/arch/x86/include/asm/bitops.h +++ b/xen/arch/x86/include/asm/bitops.h @@ -500,6 +500,9 @@ static always_inline unsigned int arch_f =20 unsigned int arch_generic_hweightl(unsigned long x); =20 +#ifdef __POPCNT__ +#define arch_hweightl __builtin_popcountl +#else /* !__POPCNT__ */ static always_inline unsigned int arch_hweightl(unsigned long x) { unsigned int r; @@ -525,5 +528,6 @@ static always_inline unsigned int arch_h return r; } #define arch_hweightl arch_hweightl +#endif /* __POPCNT__ */ =20 #endif /* _X86_BITOPS_H */ From nobody Mon Nov 23 22:39:36 2026 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1792055518; cv=none; d=zohomail.com; s=zohoarc; b=AgcgVJFk+JwpjxgqFv4vo0RmzEdmH9hxhnVw/a3yvV6+seeeN5zDbTasihPlgcMfPohuihPPHkCp2tsMfAruFLZc+XokN7IhiFWUTjl9DMnYDSMKZlMYNVV2wtPi1d+dENVnfU1zAN/ooKDZ5m1hY+AYTADJ7V8eZwNOO/SiUNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1792055518; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s6zV7zy/jpwXP1/SxtIpDn9sHbXfLtS9AvR38rCCZyw=; b=Ee5jXp6Q2MSe9UxOi8fs6pnsiEhX4PICjnrPWqHxaKi+4bQn8d7mvYy6PlWDX/1cV2CQYSy1Mq5h1jouvU5T9olVsuknuJBFVaZlWVPvgZjHe3k9anubbyzXPdOTC2ogBSRSAIVXJxRtKsNRUTrhPn+8cKuLkzwvblUJX9u+VJA= ARC-Authentication-Results: i=1; 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; 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 1792055518750140.09121405641736; Thu, 15 Oct 2026 02:11:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1450098.1665615 (Exim 4.92) (envelope-from ) id 1xHHV0-000237-AF; Thu, 15 Oct 2026 09:11:42 +0000 Received: by outflank-mailman (output) from mailman id 1450098.1665615; Thu, 15 Oct 2026 09:11:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xHHV0-000230-6Y; Thu, 15 Oct 2026 09:11:42 +0000 Received: by outflank-mailman (input) for mailman id 1450098; Thu, 15 Oct 2026 09:11:41 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) id 1xHHUz-00022u-3k for xen-devel@lists.xenproject.org; Thu, 15 Oct 2026 09:11:41 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xHHUy-00GA8m-Gj for xen-devel@lists.xenproject.org; Thu, 15 Oct 2026 11:11:40 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ad098c6-bab6-0a2a0a5309dd-0a2a4504edaa-22 for ; Thu, 15 Oct 2026 11:11:40 +0200 Received: from [209.85.221.46] (helo=mail-wr1-f46.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ad098cc-b57f-0a2a45040019-d155dd2ea4bf-3 for ; Thu, 15 Oct 2026 11:11:40 +0200 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-48df0fa43c5so653518f8f.0 for ; Thu, 15 Oct 2026 02:11:40 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48ded185de7sm9011910f8f.31.2026.10.15.02.11.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Oct 2026 02:11:39 -0700 (PDT) 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1792055500; x=1792660300; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=s6zV7zy/jpwXP1/SxtIpDn9sHbXfLtS9AvR38rCCZyw=; b=OzIfdVEVxScS9plilewXEE4j6hNWp+66tpVXK2aB5LBVLH6tsEbqP6w2UcErP0ndeF Q4D0tYJ+IaAGrdCpLFA0OxvfCMFvyMISa2Os3WfJAixF9XV2CDFPgJCN48ZcjvymaVpO 4s2Wbav1dQ1IVgEZOAbvBmYlcN+0N05Y+3ZPFo7URojjSl6RmxD42smTKkat8Awirn9g mepv8grbySjD+fK0JPh1y3zvAG8zEVzSCl0QYSYjAA4ePEt29Dp24dfVYw+OkZriIgYJ PcQjlAVNarXy1FAosNpfBNTyXmKa+YXWrsIOSjazbpsfesxl5e51a+u7PYiOCCAPC9e3 mnkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792055500; x=1792660300; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=s6zV7zy/jpwXP1/SxtIpDn9sHbXfLtS9AvR38rCCZyw=; b=pUKD0OsYuMfLembIIgpTjop5wBCf6GT9kq2ZiOytp+Br5XxS6awIZX9vwF3yaR1sb8 YpSAEVDJ3dVgX4JWmW//fJnH4GHNbziZ0+menbwhEr/7i11mlIC2CVKClhvV3MRYZK5h 6Iv9wGAtg3NKEuH9qVI11WrCK1AiPNt4Fyi3a4DAGnDoZvxpm81ttSiabOw5RF6ZKCqw ZaobduQ8/O204UKlEjRQq6qHV21mdpT/Sime20gCYDFiJ+yU0cFPiJk1jC91C03iIQND llLhIdqr2S1JBUbvAxbKaE6YrmBggUR0Q2A6Aqxhz+fjpYLsaDNDo/i98UJUiZnA57vs I3nQ== X-Gm-Message-State: AFq9FYKP74p2NXyiBlnd8SPFO+0vLY0eOHakQWa3ipuGqFY6GTQzQqUD vn2xa6fl/hOS2NfZgJW1EXEKLJMxQYUIWd5qiEPqyjy+NmLvy4Htybh4lZwqQQskXPXkrC7cagu +ikVTLA== X-Gm-Gg: AYBFou3FOuJTNPtiO6Otd3giqbPGnkt7gEK5pl0A75Woe6ezpZ4KW7nOcGFUNBYmPEP w9a4+ALoQSuXNe+u5J+y64hwCoUCyrF7R2rsPUSmO8CzjdJ6Ckg6cr7wgqxbUQadTA3x1jf+Gtk JH4FNZHI57yFLig/ajVw+dmqYX/ekm3qz0BFcJ3a1Yv50ASm1ad0/zBtAKVVAWFJcB/OS5DUJIn 0RJyxASH9dxJ1N16AVVwjluS45CarHQqgJGyyDcLN2PYRsfPXP/Pe9wbr8IovaFBCpnNQEtxDAk yjqdkYUVttmrybJiMyLg6faSm15KK/kGn3zurQXSSFAZ3EAMmCYR4193WXjh4PPJvpO4aH9Yhwf kUGSHKspa3CAQit5tuiGxs4H1SJvkoex5YPHyiUePKSuBDwOuBQxH2Ra+41HRpaFrcUwirEqgXi 1D5MzBiKXfo/WcoOtSz8EpzP/mgX4/Qawm2IFGGMUzX/pvRFy5sa0Yxfq5ssm/Vbl5uZCSxUs2Y eFMnjKRM9aPHLUsYYHKNGk1zlDT2TJnAmOhvPLO8FjAYUw7Wi1Cs84soN8e/O8= X-Received: by 2002:a05:6000:240d:b0:48c:55c1:fb7e with SMTP id ffacd0b85a97d-48db94743e8mr38953128f8f.11.1792055499917; Thu, 15 Oct 2026 02:11:39 -0700 (PDT) Message-ID: <18b38bd8-bc6b-4925-8880-234c7d2b9497@suse.com> Date: Thu, 15 Oct 2026 11:11:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 3/3] x86: short-circuit certain cpu_has_* when x86-64-v{2,3} are in effect From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Teddy Astie , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Jason Andryuk References: Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ebf023/1792055500-508D9B50-6FC0B8B9/10/78276251493 X-purgate-type: spam X-purgate-size: 2208 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1792055520161158500 Content-Type: text/plain; charset="utf-8" Certain fallback code can be made subject to DCE this way. Note that CX16 has no compiler provided manifest constant, so CONFIG_* are used there instead. Note also that we don't have cpu_has_movbe nor cpu_has_lzcnt (aka cpu_has_abm), and we no longer have cpu_has_{popcnt,bmi1,bmi2}. Signed-off-by: Jan Beulich Reviewed-by: Jason Andryuk --- Of course we could use IS_ENABLED(CONFIG_X86_64_V) everywhere, but as CX16 shows this isn't necessarily better than the #if/#else approach based on compiler-provided manifest symbols. While not really intended to be used that way, it looks as if we could also use IS_ENABLED(__POPCNT__) and alike if we thought this would end up neater (because of avoiding the #ifdef). We could go further and also short-circuit SSE*, AVX and alike, which we don't use outside of the emulator. This then would of course call for also having a way to select x86-64-v4. --- v4: Re-base (over dropped cpu_has_{popcnt,bmi1,bmi2}). v2: Also cover XSAVE. --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -132,11 +132,17 @@ static inline bool boot_cpu_has(unsigned #define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) #define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) #define cpu_has_eist boot_cpu_has(X86_FEATURE_EIST) -#define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16) +#define cpu_has_cx16 (IS_ENABLED(CONFIG_X86_64_V2) || \ + IS_ENABLED(CONFIG_X86_64_V3) || \ + boot_cpu_has(X86_FEATURE_CX16)) #define cpu_has_pdcm boot_cpu_has(X86_FEATURE_PDCM) #define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID) #define cpu_has_x2apic boot_cpu_has(X86_FEATURE_X2APIC) +#ifdef __XSAVE__ +#define cpu_has_xsave true +#else #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE) +#endif #define cpu_has_avx boot_cpu_has(X86_FEATURE_AVX) #define cpu_has_rdrand boot_cpu_has(X86_FEATURE_RDRAND) #define cpu_has_hypervisor boot_cpu_has(X86_FEATURE_HYPERVISOR)