From patchwork Thu May 4 19:39:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13231677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2956C7EE21 for ; Thu, 4 May 2023 19:39:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.530041.825297 (Exim 4.92) (envelope-from ) id 1pueni-00075v-I2; Thu, 04 May 2023 19:39:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 530041.825297; Thu, 04 May 2023 19:39:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pueni-00075k-7a; Thu, 04 May 2023 19:39:38 +0000 Received: by outflank-mailman (input) for mailman id 530041; Thu, 04 May 2023 19:39:37 +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 1pueng-00069W-U1 for xen-devel@lists.xenproject.org; Thu, 04 May 2023 19:39:36 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6527462a-eab3-11ed-8611-37d641c3527e; Thu, 04 May 2023 21:39:35 +0200 (CEST) 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: 6527462a-eab3-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1683229174; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zzSgC6HAWJ6nHal+JPSc8THZj+muKjktvIIOzu9Oncs=; b=cF83aT6l8/tYaKNgyls/1FiSDoGc3pHbN7ueZNsHgXjfweStpxpGCjNB 9Grpmg7tQVQrJPgsP20Zp3i3wYVHnpu49BVSF89fePxiD6t0VRn8DbpC+ LltchoHfx0suwzmsR/SCrKDtZCxHRv8PTg2jjU98cfuc3KHEbEA+VZtft 8=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 107797746 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:xtR7A6qaSWy9tRyHh+JDUNRPxhxeBmJpZRIvgKrLsJaIsI4StFCzt garIBmGOPmMM2XyKNhzaYXkpEwE78ODmoRhSFNqrHs3ES1D85uZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpA1c/Ek/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKm06WJwUmAWP6gR5weDzyVNVvrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXAHMmVTCFi8aX/Orhe7FXjPoxM8XoDrpK7xmMzRmBZRonaZXKQqGM7t5ExjYgwMtJGJ4yZ eJAN2ApNk6ZJUQSZBFOUslWcOSA3xETdxVxrl6PqLVxyG/U1AFri5DmMcbPe8zMTsJQ9qqdj jueoDuoXU5GarRzzxKgzkywvu+MwhrbG5xOMLel79JAkly6kzl75Bo+CgLg/KjRZlSFc8JSL QkY9zQjqYA29Ve3VZ/tUhugunmGsxUAHd1KHIUSyiuA167V6AaxHXUfQ3hKb9lOnNAybSwn0 BmOhdyBONB0mOTLEzTHrO7S9G7sf3FPdgfueBPoUyNGyOLDpo0Xry6XFOc7K6SLnML5GgPJl mXiQDcFu1kDsSIa//zlrQuf2mj8+cehoh0dvVuOAD/8hu9tTMv8PtHztwCGhRpVBNzBJmRtq kTojCR3AAomKZiW3BKAT+wWdF1Cz6bUaWaM6bKD8nRIythMx5JAVdoKiN2GDB01WvvogBewC KMphStf5YVIIFyhZrJtboS6BqwClPawTo6/CKyNP4IVPfCdkTO6ENxGPxbMjwgBbmB1+U3AB XtrWZn1VitLYUiW5DG3W/0cwdcW+8zK/kuKHcqT503+gdKjiIu9Fe9t3K2mMrpos8tpYWz9r 75iCid9408CC7OjOHOMqdF7wJJjBSFTOK0aYvd/LoarSjeK0kl7YxMN6dvNo7BYopk= IronPort-HdrOrdr: A9a23:P+/wOKvIVTjVFEL5TrabSDgW7skDTtV00zEX/kB9WHVpmszxra 6TdZMgpGbJYVcqKRcdcL+7WJVoLUmxyXcx2/h1AV7AZniAhILLFvAA0WKK+VSJcEeSygce79 YFT0EXMqyJMbEQt6fHCWeDfOrIuOP3kpyVuQ== X-Talos-CUID: 9a23:CHfxhGkBUSk+04PNzU9cOw5MZdHXOT7291fWL2uZNT4zeeWuQ2GC569nofM7zg== X-Talos-MUID: 9a23:qQyYbA5W6tsc8JvWB0+MugbDxoxN35qyMEBOzqwm+NfYESZtIhu3njWeF9o= X-IronPort-AV: E=Sophos;i="5.99,250,1677560400"; d="scan'208";a="107797746" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH 1/6] x86/cpu-policy: Drop build time cross-checks of featureset sizes Date: Thu, 4 May 2023 20:39:19 +0100 Message-ID: <20230504193924.3305496-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230504193924.3305496-1-andrew.cooper3@citrix.com> References: <20230504193924.3305496-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 These BUILD_BUG_ON()s exist to cover the curious absence of a diagnostic for code which looks like: uint32_t foo[1] = { 1, 2, 3 }; However, GCC 12 at least does now warn for this: foo.c:1:24: error: excess elements in array initializer [-Werror] 884 | uint32_t foo[1] = { 1, 2, 3 }; | ^ foo.c:1:24: note: (near initialization for 'foo') and has found other array length issues which we want to fix. Drop the cross check now tools can spot the problem case directly. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu --- xen/arch/x86/cpu-policy.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/xen/arch/x86/cpu-policy.c b/xen/arch/x86/cpu-policy.c index ef6a2d0d180a..44c88debf958 100644 --- a/xen/arch/x86/cpu-policy.c +++ b/xen/arch/x86/cpu-policy.c @@ -883,12 +883,6 @@ void __init init_dom0_cpuid_policy(struct domain *d) static void __init __maybe_unused build_assertions(void) { - BUILD_BUG_ON(ARRAY_SIZE(known_features) != FSCAPINTS); - BUILD_BUG_ON(ARRAY_SIZE(pv_max_featuremask) != FSCAPINTS); - BUILD_BUG_ON(ARRAY_SIZE(hvm_shadow_max_featuremask) != FSCAPINTS); - BUILD_BUG_ON(ARRAY_SIZE(hvm_hap_max_featuremask) != FSCAPINTS); - BUILD_BUG_ON(ARRAY_SIZE(deep_features) != FSCAPINTS); - /* Find some more clever allocation scheme if this trips. */ BUILD_BUG_ON(sizeof(struct cpu_policy) > PAGE_SIZE); From patchwork Thu May 4 19:39:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13231676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF27BC7EE25 for ; Thu, 4 May 2023 19:39:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.530039.825266 (Exim 4.92) (envelope-from ) id 1pueng-0006HW-IR; Thu, 04 May 2023 19:39:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 530039.825266; Thu, 04 May 2023 19:39:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pueng-0006Gh-DF; Thu, 04 May 2023 19:39:36 +0000 Received: by outflank-mailman (input) for mailman id 530039; Thu, 04 May 2023 19:39:35 +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 1puenf-00069W-P1 for xen-devel@lists.xenproject.org; Thu, 04 May 2023 19:39:35 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 650fb147-eab3-11ed-8611-37d641c3527e; Thu, 04 May 2023 21:39:33 +0200 (CEST) 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: 650fb147-eab3-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1683229173; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8aejV8Ms7L6eLYNlIrFeJCAd+u3GgX1dUF2hUOuDAqc=; b=bMSQa8HD9Y18I4fZhvRN50W3irUMT2e5OkugtiVFEZE4Z08s0osCLB4d HELX/3mbHSlNMjclQvB6gSOsw1BvdnyGtPb1elFhhtfroxLORJgJTpMkt uIhxLmTPrB6IjEYxqmM04ClpxrojiJAjmd5z9xWvixpV09Y1ss8n6ORPB A=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 107797743 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:JkhA6Ki0Gqj2jcP4KvVDUeTmX161ERAKZh0ujC45NGQN5FlHY01je htvWmvUa/uPM2L1e41zYI7go0tSvpPQm9c2SQZvqSBjEigb9cadCdqndUqhZCn6wu8v7q5Ex 55HNoSfdpBcolv0/ErF3m3J9CEkvU2wbuOgTrWCYmYpHlUMpB4J0XpLg/Q+jpNjne+3CgaMv cKai8DEMRqu1iUc3lg8sspvkzsy+qWj0N8klgZmP6sT4QeCzyN94K83fsldEVOpGuG4IcbiL wrz5OnR1n/U+R4rFuSknt7TGqHdauePVeQmoiM+t5mK2nCulARrukoIHKN0hXNsoyeIh7hMJ OBl7vRcf+uL0prkw4zxWzEAe8130DYvFLXveRBTuuTLp6HKnueFL1yDwyjaMKVBktubD12i+ tRCCQ8DUBahqd7mxavnRPBrxeYKC+/CadZ3VnFIlVk1DN4jSJHHBa7L+cVZzHE7gcUm8fT2P pRDL2A1NVKZPkMJYw1MYH49tL7Aan3XWjtUsl+K44Ew5HDe1ldZ27nxKtvFPNeNQK25m27B/ j2ZrjumXkpy2Nq31Xmhz2m2xcbzmj7/YqIMF4+p+/pnjwjGroAUIEJPDgbqyRWjsWahX/pPJ kpS/TAhxYAi+UruQtTjUhmQpH+fogVaS9dWC/c96gyG1uzT+QnxLkouQyNFadcmnNQrXjFs3 ViM9+4FHhQ27ufTEyjEsO7J83XrY3N9wXI+iTEsFyo67eflgq8P3hfWEth6F+2Xp/rTMGSlq 9yVlxTSl4n/nOZSifXgpQmd023zznTaZlVrv1uKBwpJ+is8Pdf4PNLwtDA3+N4adO6kok+9U G/ociR0xMQHFtmzmSOEW43h95n5tq/eYFUwbbOCdqTNFghBGFb5J+i8GBkkeC9U3j8sIFcFm nP7twJL/4N0N3C3d6JxaI/ZI510nfO6T4q5D6GMNYUmjn1NSeN61Hs2OR74M57FySDAbp3Ty b/EKJ3xXB72+IxszSasRvd17ILHMhsWnDuJLbiilkTP7FZrTCLNIVvzGAfUP79RAWLtiFm9z uuzwOPQlk4BDbekOXGImWPRRHhTRUUG6VnNg5Q/Xoa+zsBOQgnN19e5LWsdRrFY IronPort-HdrOrdr: A9a23:eEuL2qBISPMCaULlHemW55DYdb4zR+YMi2TC1yhKKCC9Ffbo7/ xG/c5rrCMc5wxhO03I9eruBEDEewK5yXcX2/h2AV7BZniFhILAFugLhuGOrwEIWReOkdK1vZ 0QCJSWY+eRMbEVt6jHCXGDYrMd/OU= X-Talos-CUID: 9a23:ePTaoW5hLF61aKfludssrm8rFP4jUFPhnHLJf0GhDiVLYZqzYArF X-Talos-MUID: 9a23:klefQgWJbJvTq6Xq/COvoAx5LoRB36OzDHotj5Y0qsSAOCMlbg== X-IronPort-AV: E=Sophos;i="5.99,250,1677560400"; d="scan'208";a="107797743" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH 2/6] x86/cpuid: Rename NCAPINTS to X86_NR_CAPS Date: Thu, 4 May 2023 20:39:20 +0100 Message-ID: <20230504193924.3305496-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230504193924.3305496-1-andrew.cooper3@citrix.com> References: <20230504193924.3305496-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 The latter is more legible, and consistent with X86_NR_{SYNTH,BUG} which already exist. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu --- xen/arch/x86/alternative.c | 2 +- xen/arch/x86/cpu/common.c | 12 ++++++------ xen/arch/x86/cpuid.c | 2 +- xen/arch/x86/include/asm/cpufeature.h | 2 +- xen/arch/x86/include/asm/cpufeatures.h | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index 99482766b51f..0434030693a9 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -200,7 +200,7 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start, BUG_ON(a->repl_len > total_len); BUG_ON(total_len > sizeof(buf)); - BUG_ON(a->cpuid >= NCAPINTS * 32); + BUG_ON(a->cpuid >= X86_NR_CAPS * 32); /* * Detect sequences of alt_instr's patching the same origin site, and diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index edc4db1335eb..1be049e332ce 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -55,8 +55,8 @@ unsigned int paddr_bits __read_mostly = 36; unsigned int hap_paddr_bits __read_mostly = 36; unsigned int vaddr_bits __read_mostly = VADDR_BITS; -static unsigned int cleared_caps[NCAPINTS]; -static unsigned int forced_caps[NCAPINTS]; +static unsigned int cleared_caps[X86_NR_CAPS]; +static unsigned int forced_caps[X86_NR_CAPS]; DEFINE_PER_CPU(bool, full_gdt_loaded); @@ -501,7 +501,7 @@ void identify_cpu(struct cpuinfo_x86 *c) #ifdef NOISY_CAPS printk(KERN_DEBUG "CPU: After vendor identify, caps:"); - for (i = 0; i < NCAPINTS; i++) + for (i = 0; i < X86_NR_CAPS; i++) printk(" %08x", c->x86_capability[i]); printk("\n"); #endif @@ -530,7 +530,7 @@ void identify_cpu(struct cpuinfo_x86 *c) for (i = 0; i < FSCAPINTS; ++i) c->x86_capability[i] &= known_features[i]; - for (i = 0 ; i < NCAPINTS ; ++i) { + for (i = 0 ; i < X86_NR_CAPS ; ++i) { c->x86_capability[i] |= forced_caps[i]; c->x86_capability[i] &= ~cleared_caps[i]; } @@ -548,7 +548,7 @@ void identify_cpu(struct cpuinfo_x86 *c) #ifdef NOISY_CAPS printk(KERN_DEBUG "CPU: After all inits, caps:"); - for (i = 0; i < NCAPINTS; i++) + for (i = 0; i < X86_NR_CAPS; i++) printk(" %08x", c->x86_capability[i]); printk("\n"); #endif @@ -585,7 +585,7 @@ void identify_cpu(struct cpuinfo_x86 *c) */ if ( c != &boot_cpu_data ) { /* AND the already accumulated flags with these */ - for ( i = 0 ; i < NCAPINTS ; i++ ) + for ( i = 0 ; i < X86_NR_CAPS ; i++ ) boot_cpu_data.x86_capability[i] &= c->x86_capability[i]; mcheck_init(c, false); diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 455a09b2dd22..fd8021c6f16c 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -19,7 +19,7 @@ bool recheck_cpu_features(unsigned int cpu) identify_cpu(&c); - for ( i = 0; i < NCAPINTS; ++i ) + for ( i = 0; i < X86_NR_CAPS; ++i ) { if ( !(~c.x86_capability[i] & bsp->x86_capability[i]) ) continue; diff --git a/xen/arch/x86/include/asm/cpufeature.h b/xen/arch/x86/include/asm/cpufeature.h index 4140ec0938b2..66bd4e296a18 100644 --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -26,7 +26,7 @@ struct cpuinfo_x86 { unsigned char x86_mask; int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */ unsigned int extended_cpuid_level; /* Maximum supported CPUID extended level */ - unsigned int x86_capability[NCAPINTS]; + unsigned int x86_capability[X86_NR_CAPS]; char x86_vendor_id[16]; char x86_model_id[64]; unsigned int x86_cache_size; /* in KB - valid only when supported */ diff --git a/xen/arch/x86/include/asm/cpufeatures.h b/xen/arch/x86/include/asm/cpufeatures.h index da0593de8542..e982ee920ce1 100644 --- a/xen/arch/x86/include/asm/cpufeatures.h +++ b/xen/arch/x86/include/asm/cpufeatures.h @@ -53,4 +53,4 @@ XEN_CPUFEATURE(IBPB_ENTRY_HVM, X86_SYNTH(29)) /* MSR_PRED_CMD used by Xen for #define X86_BUG_IBPB_NO_RET X86_BUG( 3) /* IBPB doesn't flush the RSB/RAS */ /* Total number of capability words, inc synth and bug words. */ -#define NCAPINTS (FSCAPINTS + X86_NR_SYNTH + X86_NR_BUG) /* N 32-bit words worth of info */ +#define X86_NR_CAPS (FSCAPINTS + X86_NR_SYNTH + X86_NR_BUG) /* N 32-bit words worth of info */ From patchwork Thu May 4 19:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13231674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F187C7EE22 for ; Thu, 4 May 2023 19:39:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.530042.825306 (Exim 4.92) (envelope-from ) id 1puenj-0007PH-MJ; Thu, 04 May 2023 19:39:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 530042.825306; Thu, 04 May 2023 19:39:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1puenj-0007O9-GG; Thu, 04 May 2023 19:39:39 +0000 Received: by outflank-mailman (input) for mailman id 530042; Thu, 04 May 2023 19:39:38 +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 1pueni-00069W-8I for xen-devel@lists.xenproject.org; Thu, 04 May 2023 19:39:38 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 667cad8e-eab3-11ed-8611-37d641c3527e; Thu, 04 May 2023 21:39:36 +0200 (CEST) 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: 667cad8e-eab3-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1683229175; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8ce56R8LVcBJfEp4OPYpZgXky/uTBbu+6PODD4ktX/M=; b=ZXVEiBV20OPRjcoDnNVtzOJ1n+Lj96JLE/C8t1e13lI6XzGI6GEBXtwT e+Bs5Y6qp6Re/UNCNLJep03roQCqjs1dON45tTGjjsbOd+HooNKVzad6x dvtFg7Sie1VFlqNPmr70II+Iz2dKDNh1PNTFKcZWokZNYlXU7VZAVscW1 k=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 107797745 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:xdERWaOw/3iHgwzvrR3Ul8FynXyQoLVcMsEvi/4bfWQNrUoh32NSz mZNWWuBPvrYM2agKd5yatng8EoP7JfWzYVkGwto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvPrRC9H5qyo42tF5gBmP5ingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0rxWPm9w8 942FGAId0yNnuX14pucbMA506zPLOGzVG8eknRpzDWfBvc6W5HTBa7N4Le03h9p2JoIR6yHI ZNEN3w2Nk+ojx5nYz/7DLoXmuuyi2a5WDpfsF+P/oI84nTJzRw327/oWDbQUoXSGpoEwRnE+ woq+UyjJBhdLvKWlwaMrGuKusSRxnmmQI87QejQGvlC3wTImz175ActfUu2p7y1h1CzX/pbK lcI4Ww+oK4q7kupQ9LhGRqirxasnDQRRt5RGO0S8xyWx+zf5APxLncAZi5MbpohrsBeeNAx/ gbXxZWzX2Up6eDLDyvHrd94sA9eJwBPDFAMWykmYzdV5sC/rpg0zTDmafBKRfvdYsLOJd3g/ 9ybhHFg1+5L1JRbiPrTEUPv2Gz1+MWQJuIhzkCOBz/+sFskDGKwT9bwgWU3+8qsO2pworOpm HEf0/aT4+kVZX1mvHzcGb5ddF1FChvsDdE9vbKMN8N7n9hV0yT/Fb28GRknTKuTDu4KeCXyf GjYsh5L6ZlYMROCNPEnONjrVZhznPC7SrwJs8zpgidmOMAtJGdrAgk3DaJv44wduBd1yvxuU XtqWc2tEWwbGcxa8dZCfM9EieVD7nlnlQvuqWXTk0zPPUy2OCTEFt/o8TKmMogE0U9ziF+Iq IgCbZHRk0o3vS+XSnC/zLP/5GsidRATba0aYeQNHgJfCmKKwF0cNsI= IronPort-HdrOrdr: A9a23:t+PfxKxYwKdSpjb00wbfKrPw6L1zdoMgy1knxilNoHxuH/Bw9v re+cjzsCWftN9/Yh4dcLy7VpVoIkmsl6Kdg7NwAV7KZmCP1FdARLsI0WKI+UyCJ8SRzI9gPa cLSdkFNDXzZ2IK8PoTNmODYqodKNrsytHWuQ/HpU0dKT2D88tbnn9E4gDwKDwQeCB2QaAXOb C7/cR9qz+paR0sH7+G7ilsZZmkmzXT/qiWGCI7Ow== X-Talos-CUID: 9a23:P7UCjG75lPudlrpMN9ssrm8rFP4jUFPhnHLJf0GhDiVLYZqzYArF X-Talos-MUID: 9a23:zCLoiww91vxrdQwpVr1UkB6due2aqP6IAQcXv5xYh8DaLApMEGnG1mmvT6Zyfw== X-IronPort-AV: E=Sophos;i="5.99,250,1677560400"; d="scan'208";a="107797745" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH 3/6] x86/cpuid: Rename FSCAPINTS to X86_NR_FEAT Date: Thu, 4 May 2023 20:39:21 +0100 Message-ID: <20230504193924.3305496-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230504193924.3305496-1-andrew.cooper3@citrix.com> References: <20230504193924.3305496-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 The latter is more legible, and consistent with X86_NR_{CAPS,SYNTH,BUG} which already exist. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu --- xen/arch/x86/cpu-policy.c | 22 +++++++++++----------- xen/arch/x86/cpu/common.c | 4 ++-- xen/arch/x86/include/asm/cpufeatures.h | 8 ++++---- xen/arch/x86/include/asm/cpuid.h | 2 +- xen/arch/x86/sysctl.c | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/cpu-policy.c b/xen/arch/x86/cpu-policy.c index 44c88debf958..774c512a03bd 100644 --- a/xen/arch/x86/cpu-policy.c +++ b/xen/arch/x86/cpu-policy.c @@ -130,8 +130,8 @@ static int __init cf_check parse_xen_cpuid(const char *s) custom_param("cpuid", parse_xen_cpuid); static bool __initdata dom0_cpuid_cmdline; -static uint32_t __initdata dom0_enable_feat[FSCAPINTS]; -static uint32_t __initdata dom0_disable_feat[FSCAPINTS]; +static uint32_t __initdata dom0_enable_feat[X86_NR_FEAT]; +static uint32_t __initdata dom0_disable_feat[X86_NR_FEAT]; static void __init cf_check _parse_dom0_cpuid(unsigned int feat, bool val) { @@ -158,10 +158,10 @@ static void sanitise_featureset(uint32_t *fs) { /* for_each_set_bit() uses unsigned longs. Extend with zeroes. */ uint32_t disabled_features[ - ROUNDUP(FSCAPINTS, sizeof(unsigned long)/sizeof(uint32_t))] = {}; + ROUNDUP(X86_NR_FEAT, sizeof(unsigned long)/sizeof(uint32_t))] = {}; unsigned int i; - for ( i = 0; i < FSCAPINTS; ++i ) + for ( i = 0; i < X86_NR_FEAT; ++i ) { /* Clamp to known mask. */ fs[i] &= known_features[i]; @@ -181,7 +181,7 @@ static void sanitise_featureset(uint32_t *fs) ASSERT(dfs); /* deep_features[] should guarentee this. */ - for ( j = 0; j < FSCAPINTS; ++j ) + for ( j = 0; j < X86_NR_FEAT; ++j ) { fs[j] &= ~dfs[j]; disabled_features[j] &= ~dfs[j]; @@ -476,7 +476,7 @@ static void __init guest_common_feature_adjustments(uint32_t *fs) static void __init calculate_pv_max_policy(void) { struct cpu_policy *p = &pv_max_cpu_policy; - uint32_t fs[FSCAPINTS]; + uint32_t fs[X86_NR_FEAT]; unsigned int i; *p = host_cpu_policy; @@ -509,7 +509,7 @@ static void __init calculate_pv_max_policy(void) static void __init calculate_pv_def_policy(void) { struct cpu_policy *p = &pv_def_cpu_policy; - uint32_t fs[FSCAPINTS]; + uint32_t fs[X86_NR_FEAT]; unsigned int i; *p = pv_max_cpu_policy; @@ -529,7 +529,7 @@ static void __init calculate_pv_def_policy(void) static void __init calculate_hvm_max_policy(void) { struct cpu_policy *p = &hvm_max_cpu_policy; - uint32_t fs[FSCAPINTS]; + uint32_t fs[X86_NR_FEAT]; unsigned int i; const uint32_t *mask; @@ -625,7 +625,7 @@ static void __init calculate_hvm_max_policy(void) static void __init calculate_hvm_def_policy(void) { struct cpu_policy *p = &hvm_def_cpu_policy; - uint32_t fs[FSCAPINTS]; + uint32_t fs[X86_NR_FEAT]; unsigned int i; const uint32_t *mask; @@ -723,7 +723,7 @@ void recalculate_cpuid_policy(struct domain *d) const struct cpu_policy *max = is_pv_domain(d) ? (IS_ENABLED(CONFIG_PV) ? &pv_max_cpu_policy : NULL) : (IS_ENABLED(CONFIG_HVM) ? &hvm_max_cpu_policy : NULL); - uint32_t fs[FSCAPINTS], max_fs[FSCAPINTS]; + uint32_t fs[X86_NR_FEAT], max_fs[X86_NR_FEAT]; unsigned int i; if ( !max ) @@ -864,7 +864,7 @@ void __init init_dom0_cpuid_policy(struct domain *d) /* Apply dom0-cpuid= command line settings, if provided. */ if ( dom0_cpuid_cmdline ) { - uint32_t fs[FSCAPINTS]; + uint32_t fs[X86_NR_FEAT]; unsigned int i; x86_cpu_policy_to_featureset(p, fs); diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index 1be049e332ce..d12ccea20350 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -80,7 +80,7 @@ void __init setup_clear_cpu_cap(unsigned int cap) if (!dfs) return; - for (i = 0; i < FSCAPINTS; ++i) { + for (i = 0; i < X86_NR_FEAT; ++i) { cleared_caps[i] |= dfs[i]; boot_cpu_data.x86_capability[i] &= ~dfs[i]; if (!(forced_caps[i] & dfs[i])) @@ -527,7 +527,7 @@ void identify_cpu(struct cpuinfo_x86 *c) * The vendor-specific functions might have changed features. Now * we do "generic changes." */ - for (i = 0; i < FSCAPINTS; ++i) + for (i = 0; i < X86_NR_FEAT; ++i) c->x86_capability[i] &= known_features[i]; for (i = 0 ; i < X86_NR_CAPS ; ++i) { diff --git a/xen/arch/x86/include/asm/cpufeatures.h b/xen/arch/x86/include/asm/cpufeatures.h index e982ee920ce1..408ab4ba16a5 100644 --- a/xen/arch/x86/include/asm/cpufeatures.h +++ b/xen/arch/x86/include/asm/cpufeatures.h @@ -5,11 +5,11 @@ #include /* Number of capability words covered by the featureset words. */ -#define FSCAPINTS FEATURESET_NR_ENTRIES +#define X86_NR_FEAT FEATURESET_NR_ENTRIES /* Synthetic words follow the featureset words. */ #define X86_NR_SYNTH 1 -#define X86_SYNTH(x) (FSCAPINTS * 32 + (x)) +#define X86_SYNTH(x) (X86_NR_FEAT * 32 + (x)) /* Synthetic features */ XEN_CPUFEATURE(CONSTANT_TSC, X86_SYNTH( 0)) /* TSC ticks at a constant rate */ @@ -45,7 +45,7 @@ XEN_CPUFEATURE(IBPB_ENTRY_HVM, X86_SYNTH(29)) /* MSR_PRED_CMD used by Xen for /* Bug words follow the synthetic words. */ #define X86_NR_BUG 1 -#define X86_BUG(x) ((FSCAPINTS + X86_NR_SYNTH) * 32 + (x)) +#define X86_BUG(x) ((X86_NR_FEAT + X86_NR_SYNTH) * 32 + (x)) #define X86_BUG_FPU_PTRS X86_BUG( 0) /* (F)X{SAVE,RSTOR} doesn't save/restore FOP/FIP/FDP. */ #define X86_BUG_NULL_SEG X86_BUG( 1) /* NULL-ing a selector preserves the base and limit. */ @@ -53,4 +53,4 @@ XEN_CPUFEATURE(IBPB_ENTRY_HVM, X86_SYNTH(29)) /* MSR_PRED_CMD used by Xen for #define X86_BUG_IBPB_NO_RET X86_BUG( 3) /* IBPB doesn't flush the RSB/RAS */ /* Total number of capability words, inc synth and bug words. */ -#define X86_NR_CAPS (FSCAPINTS + X86_NR_SYNTH + X86_NR_BUG) /* N 32-bit words worth of info */ +#define X86_NR_CAPS (X86_NR_FEAT + X86_NR_SYNTH + X86_NR_BUG) /* N 32-bit words worth of info */ diff --git a/xen/arch/x86/include/asm/cpuid.h b/xen/arch/x86/include/asm/cpuid.h index b32ba0bbfe5c..85b6ca0edb91 100644 --- a/xen/arch/x86/include/asm/cpuid.h +++ b/xen/arch/x86/include/asm/cpuid.h @@ -10,7 +10,7 @@ #include -extern const uint32_t known_features[FSCAPINTS]; +extern const uint32_t known_features[X86_NR_FEAT]; /* * Expected levelling capabilities (given cpuid vendor/family information), diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index c107f40c6283..9be0e796628c 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -308,13 +308,13 @@ long arch_do_sysctl( #endif }; const struct cpu_policy *p = NULL; - uint32_t featureset[FSCAPINTS]; + uint32_t featureset[X86_NR_FEAT]; unsigned int nr; /* Request for maximum number of features? */ if ( guest_handle_is_null(sysctl->u.cpu_featureset.features) ) { - sysctl->u.cpu_featureset.nr_features = FSCAPINTS; + sysctl->u.cpu_featureset.nr_features = X86_NR_FEAT; if ( __copy_field_to_guest(u_sysctl, sysctl, u.cpu_featureset.nr_features) ) ret = -EFAULT; @@ -323,7 +323,7 @@ long arch_do_sysctl( /* Clip the number of entries. */ nr = min_t(unsigned int, sysctl->u.cpu_featureset.nr_features, - FSCAPINTS); + X86_NR_FEAT); /* Look up requested featureset. */ if ( sysctl->u.cpu_featureset.index < ARRAY_SIZE(policy_table) ) @@ -352,7 +352,7 @@ long arch_do_sysctl( ret = -EFAULT; /* Inform the caller if there was more data to provide. */ - if ( !ret && nr < FSCAPINTS ) + if ( !ret && nr < X86_NR_FEAT ) ret = -ENOBUFS; break; From patchwork Thu May 4 19:39:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13231679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D5B4C7EE22 for ; Thu, 4 May 2023 19:39:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.530043.825311 (Exim 4.92) (envelope-from ) id 1puenk-0007Td-2O; Thu, 04 May 2023 19:39:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 530043.825311; Thu, 04 May 2023 19:39:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1puenj-0007Sm-SF; Thu, 04 May 2023 19:39:39 +0000 Received: by outflank-mailman (input) for mailman id 530043; Thu, 04 May 2023 19:39:39 +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 1puenj-00069W-3g for xen-devel@lists.xenproject.org; Thu, 04 May 2023 19:39:39 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 672ce9c0-eab3-11ed-8611-37d641c3527e; Thu, 04 May 2023 21:39:37 +0200 (CEST) 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: 672ce9c0-eab3-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1683229177; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9R0YIYGzst7iA1qXqPxFQ9NZvJDOOPfxgM5CuGK9bi0=; b=bikuqNEzzDFQ2Sf6I2FAkoVPskOLa973sYNn8vEWFMOGFl5lyQrQ30u5 /EvVrVGWRbweLgs+i7XQUjnYfXHVTIXd4p4/DevXudG10pLMYhfYpkXPR PAg1dK2hch0j0mGjogzNY5HlVx/oy0M8kYNXuVd2LpG1AOtgp2vPOf6vB w=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 107797747 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:+Wvn1ajqcahEGyv37WPFhN36X161ERAKZh0ujC45NGQN5FlHY01je htvWz2HafyDMGTye4twad+0o0gB75PXm4dqHQptpCo8Qigb9cadCdqndUqhZCn6wu8v7q5Ex 55HNoSfdpBcolv0/ErF3m3J9CEkvU2wbuOgTrWCYmYpHlUMpB4J0XpLg/Q+jpNjne+3CgaMv cKai8DEMRqu1iUc3lg8sspvkzsy+qWj0N8klgZmP6sT4QeCzyN94K83fsldEVOpGuG4IcbiL wrz5OnR1n/U+R4rFuSknt7TGqHdauePVeQmoiM+t5mK2nCulARrukoIHKN0hXNsoyeIh7hMJ OBl7vRcf+uL0prkw4zxWzEAe8130DYvFLXveRBTuuTLp6HKnueFL1yDwyjaMKVBktubD12i+ tRbAwstaBynpt7umoPjceNSlNsvL/vSadZ3VnFIlVk1DN4jSJHHBa7L+cVZzHE7gcUm8fT2P pRDL2A1NVKZPkMJYw1MYH49tL7Aan3XWjtUsl+K44Ew5HDe1ldZ27nxKtvFPNeNQK25m27B/ j2ZrjumXk5y2Nq3zBiv6U2mh+v1hWD3XcFPRIGqyO86nwjGroAUIEJPDgbqyRWjsWauVtQaJ 0EK9y4Gqakp6FftXtT7Rwe/onOPolgbQdU4O88Q5RyJy6HUyx2EHWVCRTlEAPQ5sOcmSDps0 UWG9+4FHhQ27ufTEyjEsO7J83XrY3N9wXI+iTEsDiA+w9/vhKAP1kj+Fu1pLryqgt7HIGSlq 9yVlxTSl4n/nOZSifXgpQmd023zznTaZlVrv1uKBwpJ+is8Pdf4PNLwtDA3+N4adO6kok+9U G/ociR0xMQHFtmzmSOEW43h95n5tq/eYFUwbbOCdqTNFghBGFb5J+i8GBkkeC9U3j8sIFcFm nP7twJL/4N0N3C3d6JxaI/ZI510nfO6T4q5D6GMNYUmjn1NSeN61Hs2OR74M57FySDAbp3Ty b/EKJ3xXB72+IxszSasRvd17ILHMhsWnDuJLbiilkTP7FZrTCLNIVvzGAfUP79RAWLtiFm9z uuzwOPQlk4BDbekOXGImWPRRHhTRUUG6VnNg5Q/Xoa+zsBOQgnN19e5LWsdRrFY IronPort-HdrOrdr: A9a23:DDCJwqG4+wEztRPFpLqELMeALOsnbusQ8zAXPiBKJCC9E/bo8v xG+c5w6faaslkssR0b9+xoW5PwI080l6QU3WB5B97LMDUO0FHCEGgI1/qA/9SPIUzDHu4279 YbT0B9YueAcGSTW6zBkXWF+9VL+qj5zEix792uq0uE1WtRGtldBwESMHf9LmRGADNoKLAeD5 Sm6s9Ot1ObCA8qhpTSPAhiYwDbzee77a7bXQ== X-Talos-CUID: 9a23:nvwvZWqHZzaKT4gwBTMBk1PmUYMOSV3bwFPxHxfiOD5SQoOHVlOTypoxxg== X-Talos-MUID: 9a23:yZW1TQnAhHGdUB5UFoWydnpnFu1z3K6vDHoV0pkD+JTUCT5OKmeC2WE= X-IronPort-AV: E=Sophos;i="5.99,250,1677560400"; d="scan'208";a="107797747" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH 4/6] x86/cpu-policy: Split cpuid-consts.h out of cpu-policy.h Date: Thu, 4 May 2023 20:39:22 +0100 Message-ID: <20230504193924.3305496-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230504193924.3305496-1-andrew.cooper3@citrix.com> References: <20230504193924.3305496-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 In order to disentangle X86_NR_FEAT from FEATURESET_NR_ENTRIES, we need to adjust asm/cpufeatures.h's inclusion of cpuid-autogen.h, and including all of cpu-policy.h ends with cyclic dependences and a mess. Split the FEATURESET_* constants out into a new header. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu I don't particularly like this, but I can't find a better alternative. --- xen/include/xen/lib/x86/cpu-policy.h | 19 +------------- xen/include/xen/lib/x86/cpuid-consts.h | 34 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 xen/include/xen/lib/x86/cpuid-consts.h diff --git a/xen/include/xen/lib/x86/cpu-policy.h b/xen/include/xen/lib/x86/cpu-policy.h index bfa425060464..e9bda14a7595 100644 --- a/xen/include/xen/lib/x86/cpu-policy.h +++ b/xen/include/xen/lib/x86/cpu-policy.h @@ -2,24 +2,7 @@ #ifndef XEN_LIB_X86_POLICIES_H #define XEN_LIB_X86_POLICIES_H -#include - -#define FEATURESET_1d 0 /* 0x00000001.edx */ -#define FEATURESET_1c 1 /* 0x00000001.ecx */ -#define FEATURESET_e1d 2 /* 0x80000001.edx */ -#define FEATURESET_e1c 3 /* 0x80000001.ecx */ -#define FEATURESET_Da1 4 /* 0x0000000d:1.eax */ -#define FEATURESET_7b0 5 /* 0x00000007:0.ebx */ -#define FEATURESET_7c0 6 /* 0x00000007:0.ecx */ -#define FEATURESET_e7d 7 /* 0x80000007.edx */ -#define FEATURESET_e8b 8 /* 0x80000008.ebx */ -#define FEATURESET_7d0 9 /* 0x00000007:0.edx */ -#define FEATURESET_7a1 10 /* 0x00000007:1.eax */ -#define FEATURESET_e21a 11 /* 0x80000021.eax */ -#define FEATURESET_7b1 12 /* 0x00000007:1.ebx */ -#define FEATURESET_7d2 13 /* 0x00000007:2.edx */ -#define FEATURESET_7c1 14 /* 0x00000007:1.ecx */ -#define FEATURESET_7d1 15 /* 0x00000007:1.edx */ +#include struct cpuid_leaf { diff --git a/xen/include/xen/lib/x86/cpuid-consts.h b/xen/include/xen/lib/x86/cpuid-consts.h new file mode 100644 index 000000000000..6ca8c39a3df4 --- /dev/null +++ b/xen/include/xen/lib/x86/cpuid-consts.h @@ -0,0 +1,34 @@ +/* Common data structures and functions consumed by hypervisor and toolstack */ +#ifndef XEN_LIB_X86_CONSTS_H +#define XEN_LIB_X86_CONSTS_H + +#include + +#define FEATURESET_1d 0 /* 0x00000001.edx */ +#define FEATURESET_1c 1 /* 0x00000001.ecx */ +#define FEATURESET_e1d 2 /* 0x80000001.edx */ +#define FEATURESET_e1c 3 /* 0x80000001.ecx */ +#define FEATURESET_Da1 4 /* 0x0000000d:1.eax */ +#define FEATURESET_7b0 5 /* 0x00000007:0.ebx */ +#define FEATURESET_7c0 6 /* 0x00000007:0.ecx */ +#define FEATURESET_e7d 7 /* 0x80000007.edx */ +#define FEATURESET_e8b 8 /* 0x80000008.ebx */ +#define FEATURESET_7d0 9 /* 0x00000007:0.edx */ +#define FEATURESET_7a1 10 /* 0x00000007:1.eax */ +#define FEATURESET_e21a 11 /* 0x80000021.eax */ +#define FEATURESET_7b1 12 /* 0x00000007:1.ebx */ +#define FEATURESET_7d2 13 /* 0x00000007:2.edx */ +#define FEATURESET_7c1 14 /* 0x00000007:1.ecx */ +#define FEATURESET_7d1 15 /* 0x00000007:1.edx */ + +#endif /* !XEN_LIB_X86_CONSTS_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Thu May 4 19:39:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13231673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C3EFC7EE21 for ; Thu, 4 May 2023 19:39:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.530040.825273 (Exim 4.92) (envelope-from ) id 1pueng-0006Mu-UU; Thu, 04 May 2023 19:39:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 530040.825273; Thu, 04 May 2023 19:39:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pueng-0006K7-L0; Thu, 04 May 2023 19:39:36 +0000 Received: by outflank-mailman (input) for mailman id 530040; Thu, 04 May 2023 19:39:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1puenf-00069l-T7 for xen-devel@lists.xenproject.org; Thu, 04 May 2023 19:39:35 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 65d9d6e2-eab3-11ed-b226-6b7b168915f2; Thu, 04 May 2023 21:39:35 +0200 (CEST) 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: 65d9d6e2-eab3-11ed-b226-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1683229175; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jr5O2ho0oh2dy6YyNewvIFzCxvBrXOJlZmgmV269Q/k=; b=bs2AD/Fs7u8FRnFxMUlW3QRP1fUgBjsvmJorU8NJ2LZzdeKpZyrIfaSb rQ2yZAo16A/RlrVY1gQts8UuiF7iGAYzQCItZCYZL0ULaQrhMQKMFzNtb eoYjBsI3CgDXHg1XQhIOH1X6K3KnJgElM2PMXI6s+2SOKNi1vd1xQ4dxF k=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 107931611 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:kJpQzKuPcYcZMGFx809kXMhjeOfnVCdeMUV32f8akzHdYApBsoF/q tZmKTyCa6yKMGX2foh0aY209hkDu5SAxtFrHQVkpHsxHigR+JbJXdiXEBz9bniYRiHhoOCLz O1FM4Wdc5pkJpP4jk3wWlQ0hSAkjclkfpKlVKiffHg3HVQ+IMsYoUoLs/YjhYJ1isSODQqIu Nfjy+XSI1bg0DNvWo4uw/vrRChH4bKj6Vv0gnRkPaoQ5AKGyyFPZH4iDfrZw0XQE9E88tGSH 44v/JnhlkvF8hEkDM+Sk7qTWiXmlZaLYGBiIlIPM0STqkAqSh4ai87XB9JFAatjsB2bnsgZ9 Tl4ncfYpTHFnEH7sL91vxFwS0mSNEDdkVPNCSDXXce7lyUqf5ZwqhnH4Y5f0YAwo45K7W9yG fMwEz8saE25nNiPkY2FStA3r50DE5HxBdZK0p1g5Wmx4fcORJnCR+PB5MNC3Sd2jcdLdRrcT 5NHM3w1Nk2GOkARfA5NU/rSn8/x7pX7WxRepEiYuuwc5G/LwRYq+LPsLMDUapqBQsA9ckOw/ zqZrj+gXEhDXDCZ4WSP9nzzud3dpwDce4NIN7GX7uYyonTGkwT/DzVJDADm8JFVkHWWRNZ3O 0ESvC00osAa5EGtC9XwQRC8iHqFpQIHHcpdFfUg7wOAwbaS5ByWbkAGRDNcbN0ttOctWCcnk FSOmrvU6SdH6ePPDyjHr/HN8G30YHJORYMfWcMaZTAKwt++mpoJt0PwcNZaS4fsruKtAwill lhmsxMCa6UvYd8jjvvrpgie2WLz+fAlXSZuuFyJAzvNAhdRIdf8Otf2sQWzAeNodt7xc7WXg JQTdyFyBsgqBIrFqiGCSf5l8FqBt6fca220bbKC8vAcG9WRF52LJ9o4DMlWfhsBDyr9UWaBj LXvkQ1Q/oRPG3ChcLV6ZYm8Y+xzk/i7T467CqmFNoERCnSUSDJrAQk0PRLAt4wTuBFEfV4D1 WezLp/3UCdy5VVPxzuqXeYNuYIWKtQF7TqLH/jTlk33uYdykVbJEd/pxnPSNLFmhE5FyS2Jm +ti2zyikUgEDrCkOHKPrub+7zkidBAGOHw/kOQPHsbrH+asMDtJ5yP5qV/5R7FYog== IronPort-HdrOrdr: A9a23:dcGjLqjOHA+0jiMQx7THnu5Q8nBQXg4ji2hC6mlwRA09TyX4rb HKoB1/73LJYVkqN03I9ervBED4ewK5yXct2/h3AV7AZniFhILLFu1fBOLZqlWLJ8SZzI9gPM 9bGJSWY+eAbmSS4/yb3OFte+xQueVu78iT9JjjJ2YEd3ANV0l/hz0JcjpzGHcGODWvWPICZe GhDtIunUvbRZwNBv7Le0U4Yw== X-Talos-CUID: 9a23:ujj73W9qBqA70R+GzX2Vv3UbO8Z4SGbn9SbvHU+BUk8waILNU2bFrQ== X-Talos-MUID: 9a23:oOu8Lw9dfBjUJW2cTSXRQG6Qf5li56rxN3Ifq7YhmMjeFiBfIy/Frh3iFw== X-IronPort-AV: E=Sophos;i="5.99,250,1677560400"; d="scan'208";a="107931611" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH 5/6] x86/cpu-policy: Disentangle X86_NR_FEAT and FEATURESET_NR_ENTRIES Date: Thu, 4 May 2023 20:39:23 +0100 Message-ID: <20230504193924.3305496-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230504193924.3305496-1-andrew.cooper3@citrix.com> References: <20230504193924.3305496-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 When adding new words to a featureset, there is a reasonable amount of boilerplate and it is preforable to split the addition into multiple patches. GCC 12 spotted a real (transient) error which occurs when splitting additions like this. Right now, FEATURESET_NR_ENTRIES is dynamically generated from the highest numeric XEN_CPUFEATURE() value, and can be less than what the FEATURESET_* constants suggest the length of a featureset bitmap ought to be. This causes the policy <-> featureset converters to genuinely access out-of-bounds on the featureset array. Rework X86_NR_FEAT to be related to FEATURESET_* alone, allowing it specifically to grow larger than FEATURESET_NR_ENTRIES. Reported-by: Jan Beulich Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné CC: Wei Liu To preempt what I expect will be the first review question, no FEATURESET_* can't become an enumeration, because the constants undergo token concatination in the preprocess as part of making DECL_BITFIELD() work. --- xen/arch/x86/cpu-policy.c | 7 +++++++ xen/arch/x86/include/asm/cpufeatures.h | 5 +---- xen/include/xen/lib/x86/cpu-policy.h | 4 ++-- xen/include/xen/lib/x86/cpuid-consts.h | 2 ++ xen/lib/x86/cpuid.c | 6 +++--- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/cpu-policy.c b/xen/arch/x86/cpu-policy.c index 774c512a03bd..00416244a3d8 100644 --- a/xen/arch/x86/cpu-policy.c +++ b/xen/arch/x86/cpu-policy.c @@ -883,6 +883,13 @@ void __init init_dom0_cpuid_policy(struct domain *d) static void __init __maybe_unused build_assertions(void) { + /* + * Generally these are the same, but tend to differ when adding new + * infrastructure split across several patches. Simply confirm that the + * gen-cpuid.py X86_FEATURE_* bits fit within the bitmaps we operate on. + */ + BUILD_BUG_ON(FEATURESET_NR_ENTRIES > X86_NR_FEAT); + /* Find some more clever allocation scheme if this trips. */ BUILD_BUG_ON(sizeof(struct cpu_policy) > PAGE_SIZE); diff --git a/xen/arch/x86/include/asm/cpufeatures.h b/xen/arch/x86/include/asm/cpufeatures.h index 408ab4ba16a5..8989291bbfd6 100644 --- a/xen/arch/x86/include/asm/cpufeatures.h +++ b/xen/arch/x86/include/asm/cpufeatures.h @@ -2,10 +2,7 @@ * Explicitly intended for multiple inclusion. */ -#include - -/* Number of capability words covered by the featureset words. */ -#define X86_NR_FEAT FEATURESET_NR_ENTRIES +#include /* Synthetic words follow the featureset words. */ #define X86_NR_SYNTH 1 diff --git a/xen/include/xen/lib/x86/cpu-policy.h b/xen/include/xen/lib/x86/cpu-policy.h index e9bda14a7595..01431de056c8 100644 --- a/xen/include/xen/lib/x86/cpu-policy.h +++ b/xen/include/xen/lib/x86/cpu-policy.h @@ -370,12 +370,12 @@ struct cpu_policy_errors * Copy the featureset words out of a cpu_policy object. */ void x86_cpu_policy_to_featureset(const struct cpu_policy *p, - uint32_t fs[FEATURESET_NR_ENTRIES]); + uint32_t fs[X86_NR_FEAT]); /** * Copy the featureset words back into a cpu_policy object. */ -void x86_cpu_featureset_to_policy(const uint32_t fs[FEATURESET_NR_ENTRIES], +void x86_cpu_featureset_to_policy(const uint32_t fs[X86_NR_FEAT], struct cpu_policy *p); static inline uint64_t cpu_policy_xcr0_max(const struct cpu_policy *p) diff --git a/xen/include/xen/lib/x86/cpuid-consts.h b/xen/include/xen/lib/x86/cpuid-consts.h index 6ca8c39a3df4..9fe931b8e31f 100644 --- a/xen/include/xen/lib/x86/cpuid-consts.h +++ b/xen/include/xen/lib/x86/cpuid-consts.h @@ -21,6 +21,8 @@ #define FEATURESET_7c1 14 /* 0x00000007:1.ecx */ #define FEATURESET_7d1 15 /* 0x00000007:1.edx */ +#define X86_NR_FEAT (FEATURESET_7d1 + 1) + #endif /* !XEN_LIB_X86_CONSTS_H */ /* diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 68aafb404927..76f26e92af8d 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -61,7 +61,7 @@ const char *x86_cpuid_vendor_to_str(unsigned int vendor) } void x86_cpu_policy_to_featureset( - const struct cpu_policy *p, uint32_t fs[FEATURESET_NR_ENTRIES]) + const struct cpu_policy *p, uint32_t fs[X86_NR_FEAT]) { fs[FEATURESET_1d] = p->basic._1d; fs[FEATURESET_1c] = p->basic._1c; @@ -82,7 +82,7 @@ void x86_cpu_policy_to_featureset( } void x86_cpu_featureset_to_policy( - const uint32_t fs[FEATURESET_NR_ENTRIES], struct cpu_policy *p) + const uint32_t fs[X86_NR_FEAT], struct cpu_policy *p) { p->basic._1d = fs[FEATURESET_1d]; p->basic._1c = fs[FEATURESET_1c]; @@ -285,7 +285,7 @@ const uint32_t *x86_cpu_policy_lookup_deep_deps(uint32_t feature) static const uint32_t deep_features[] = INIT_DEEP_FEATURES; static const struct { uint32_t feature; - uint32_t fs[FEATURESET_NR_ENTRIES]; + uint32_t fs[X86_NR_FEAT]; } deep_deps[] = INIT_DEEP_DEPS; unsigned int start = 0, end = ARRAY_SIZE(deep_deps); From patchwork Thu May 4 19:39:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13231675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01BDEC77B78 for ; Thu, 4 May 2023 19:39:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.530038.825260 (Exim 4.92) (envelope-from ) id 1pueng-0006DJ-9m; Thu, 04 May 2023 19:39:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 530038.825260; Thu, 04 May 2023 19:39:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pueng-0006CW-5q; Thu, 04 May 2023 19:39:36 +0000 Received: by outflank-mailman (input) for mailman id 530038; Thu, 04 May 2023 19:39:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1puenf-00069l-6I for xen-devel@lists.xenproject.org; Thu, 04 May 2023 19:39:35 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6293b883-eab3-11ed-b226-6b7b168915f2; Thu, 04 May 2023 21:39:31 +0200 (CEST) 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: 6293b883-eab3-11ed-b226-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1683229173; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kA0CoCvs9w9UnA8Cp8g4Yf97SdqOL/znbdWvnuGRE/s=; b=GnQ7M7m/PYMymFfO92HSaHE497UtluP5svWs9DlZzqe7Qz4/NVEZ7yFc SNOwy88h+tzBRKikEIvgkNjKm9UEk0eIk7+2rXO97u1XLaT3gqEQF36Fo bYC46F7kTGjUkJYhBvFbdGT99CB0NmFLcm6u4YIde+YxlJuoau2r/cfvb I=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 107931606 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:6OvrB6+gnEOK1t08d7VHDrUD0H6TJUtcMsCJ2f8bNWPcYEJGY0x3y 2QdD2+COPzcZmShc9p+PY3n9k9SupGDz4MwHgVl+yw8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKicYXoZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kI+1BjOkGlA5AdmOKgX5AW2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDkkTs thJBmEQXyqv3fOTwLyxYfZRvN0aeZyD0IM34hmMzBncBPciB5vCX7/L9ZlT2zJYasJmRKiEI ZBDMHw2MUqGOkcUUrsUIMtWcOOAr3/zaTBH7nmSorI6+TP7xw1tyrn9dtHSf7RmQO0MxhnJ/ TuYpzqR7hcyK5/HmAS1rC6WgLXQvgb0Q9o/G+aB+as/6LGU7jNKU0BHPbehmtGph0j7V99BJ kg8/is1sbN05EGtVsP6XRCzvDiDpBF0ZjZLO7RkskfXkPOSulvHQDFeFVatdeDKqudrAhh7+ A6UrunFXy1KsLOfYm2gzK6t+Gba1TcuEYMSWcMVZVJbs4K7+dtj0U2nosVLS/Ds0ICscd3k6 3XT9XVl2e1O5SIe///jlW0rlQ5AsXQgouQdwgzMFlyo4QpiDGJOT9z5sAOLhRqswWvwc7Vgg JTns5LEhAz2JcvR/BFhuc1UdF1T296LMSfHnXlkFIQ7+jKm9haLJN4Au2skehswY55fJlcFh XPuVf55vscPbBNGk4cuC25ONyja5fe5Tom0PhwlRtFPfoJwZGe6wc2aXmbJhzqFuBF1wckC1 WKzLZ7E4YAyVf42k1Jbho41jdcW+8zJ7TmOHs6mlU78ieX2ibz8Ye5tDWZip9sRtMusyDg5O f4GXydW432ziNHDXxQ= IronPort-HdrOrdr: A9a23:n00BHKOCaufrE8BcThWjsMiBIKoaSvp037BL7TEVdfUxSKGlfq +V88jzuSWbtN9pYgBFpTnYAtjmfZq+z+8W3WByB9uftWDd0QPDEGgF1+rfKlXbcBEWndQttp uIHZIfNDUlZWIK9PoT/2GDYqkdKMjuytHPuQ/Bp00dNT2CYZsQkzuQV26gYzZLrBEvP+tCKH KGjvA32gadRQ== X-Talos-CUID: 9a23:+Jhv3GwLDU6bHbvpqSYMBgVJXeR0XCzA/U38eV6dCWhjY6Koc0aprfY= X-Talos-MUID: 9a23:gY02lgpSBOzTJi5FAIAezy4hbJZW0/ryMkZXjrYjtNLcGCMrAjjI2Q== X-IronPort-AV: E=Sophos;i="5.99,250,1677560400"; d="scan'208";a="107931606" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper Subject: [PATCH 6/6] DO NOT APPLY: Example breakage Date: Thu, 4 May 2023 20:39:24 +0100 Message-ID: <20230504193924.3305496-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230504193924.3305496-1-andrew.cooper3@citrix.com> References: <20230504193924.3305496-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Prior to disentangling X86_NR_FEAT from FEATURESET_NR_ENTRIES, GCC 12 correctly notices: lib/x86/cpuid.c: In function 'x86_cpu_policy_to_featureset': lib/x86/cpuid.c:82:7: error: array subscript 16 is outside array bounds of 'uint32_t[16]' {aka 'unsigned int[16]'} [-Werror=array-bounds=] 82 | fs[FEATURESET_7a2] = p->feat._7a2; | ~~^~~~~~~~~~~~~~~~ lib/x86/cpuid.c:64:42: note: at offset 64 into object 'fs' of size [0, 64] Signed-off-by: Andrew Cooper --- xen/include/xen/lib/x86/cpu-policy.h | 6 +++++- xen/include/xen/lib/x86/cpuid-consts.h | 2 ++ xen/lib/x86/cpuid.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/xen/include/xen/lib/x86/cpu-policy.h b/xen/include/xen/lib/x86/cpu-policy.h index 01431de056c8..164b3f4aac13 100644 --- a/xen/include/xen/lib/x86/cpu-policy.h +++ b/xen/include/xen/lib/x86/cpu-policy.h @@ -192,7 +192,11 @@ struct cpu_policy }; /* Subleaf 2. */ - uint32_t /* a */:32, /* b */:32, /* c */:32; + union { + uint32_t _7a2; + struct { DECL_BITFIELD(7a2); }; + }; + uint32_t /* b */:32, /* c */:32; union { uint32_t _7d2; struct { DECL_BITFIELD(7d2); }; diff --git a/xen/include/xen/lib/x86/cpuid-consts.h b/xen/include/xen/lib/x86/cpuid-consts.h index 9fe931b8e31f..5dd9727fec79 100644 --- a/xen/include/xen/lib/x86/cpuid-consts.h +++ b/xen/include/xen/lib/x86/cpuid-consts.h @@ -20,8 +20,10 @@ #define FEATURESET_7d2 13 /* 0x00000007:2.edx */ #define FEATURESET_7c1 14 /* 0x00000007:1.ecx */ #define FEATURESET_7d1 15 /* 0x00000007:1.edx */ +#define FEATURESET_7a2 16 #define X86_NR_FEAT (FEATURESET_7d1 + 1) +//#define X86_NR_FEAT (FEATURESET_7a2 + 1) #endif /* !XEN_LIB_X86_CONSTS_H */ diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 76f26e92af8d..90bc82a18c30 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -79,6 +79,7 @@ void x86_cpu_policy_to_featureset( fs[FEATURESET_7d2] = p->feat._7d2; fs[FEATURESET_7c1] = p->feat._7c1; fs[FEATURESET_7d1] = p->feat._7d1; + fs[FEATURESET_7a2] = p->feat._7a2; } void x86_cpu_featureset_to_policy( @@ -100,6 +101,7 @@ void x86_cpu_featureset_to_policy( p->feat._7d2 = fs[FEATURESET_7d2]; p->feat._7c1 = fs[FEATURESET_7c1]; p->feat._7d1 = fs[FEATURESET_7d1]; + p->feat._7a2 = fs[FEATURESET_7a2]; } void x86_cpu_policy_recalc_synth(struct cpu_policy *p)