From patchwork Wed Nov 29 11:22:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 171277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp267891vqn; Wed, 29 Nov 2023 03:23:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEo/qFRYjaOVd7XNa4GoqfY55MBIPI3H5xl1SouD6wj/eajA7EsLFBbENR2wZ/rqbYlaiep X-Received: by 2002:a05:6830:1412:b0:6d7:f8f6:5406 with SMTP id v18-20020a056830141200b006d7f8f65406mr19082002otp.0.1701257005065; Wed, 29 Nov 2023 03:23:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701257005; cv=none; d=google.com; s=arc-20160816; b=ovWpD/3C98QO+RK0zpXwjqxPyoDmkY2GyfjyTkGSW7J5bE8uZw6IBewOFpRwgXy4qj Q5lnlRwCFZquRRTvuAeaFN4cCgxqEX0zmufpMF9niW0wA+zdPAWcVG0KbFMBO7NMQBMU E7OebGqcnFnZG0Fx7XTF+FkWP9Kt0c6rOzTiSkxu0X1lTwHewFHaoNjN+wUjGH//DCYH J2dPwDbVdxU2LcWIhNbjFc3RBv51DEvDBEUpH+tdIW9PhghnkP9R8kEMb1Zc43mHUSGX JvO47k6aT99gPfwxyZpUFQrR0x1GGfs0nc0RkSgz8DyUxShWNbxc3JE1eDkSN/0HfPcz 7V5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=NTJP4GuZWQvoaacJKCszms5BpWIpa1KbHZbw56B8K0g=; fh=KTJn8+ZdwgwdlHqXhAkkiLlxWhMeGzsHMBkKzKlp1ck=; b=qfR3VGZWbYfYDKI3v9eJ7X9pr8rXEPl0xUvo0BjzOLSqMiH4SSjwX/eEK8wPDaT7WA W0P66BHcnrdz1psQCVM88DD3mMQksss31KFPzVeTUlTIRfvtEqBKD5c5eegP2isWUrlO f+ENDSqzYBk17t2E1tvKCbeIva3i69RjrjWdxhRyp4AQV8e+HZCLzvBmqidh6/9Av8qu OXX0muICdheuD8IRkbv6SZcEm5er+tdsXpU+xNliIOgl2ZXPZ4JtYECCOBgcRIipJnPJ /YIJ4fdIT/irMD70MiNAcckUake3YsWcVkSYJGpOn8W9nl54yxQ5U/JbZklrlTo+Y3zE KSwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SSPMj8Ib; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=XtVCgPEG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id d7-20020a656207000000b005c2135c5018si13970388pgv.571.2023.11.29.03.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 03:23:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SSPMj8Ib; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=XtVCgPEG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1E9D180AE201; Wed, 29 Nov 2023 03:23:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233203AbjK2LXE (ORCPT + 99 others); Wed, 29 Nov 2023 06:23:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232731AbjK2LWf (ORCPT ); Wed, 29 Nov 2023 06:22:35 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBAC51BCC; Wed, 29 Nov 2023 03:22:35 -0800 (PST) Date: Wed, 29 Nov 2023 11:22:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701256954; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NTJP4GuZWQvoaacJKCszms5BpWIpa1KbHZbw56B8K0g=; b=SSPMj8IbwjwyeBVkVJdNQHR7DEjHlWQEIs1TnppVcy6pMj+UEuvl4/2DkFkY7gJWZxoOeU PRXs6+xJKMY32x1N3rQlsvG47lEN0Gn1H7RSUkA1aKX5nnrk9N1Elwhi02Pvbju3U/QYLE MAvoxKpjEN+BFpZSArd9cpuapuC9xCyTIQPIsZ8t8TUwFUdS6np81zd9ZQSoJnFRGx5WP5 6XzXUmU9t5PGUDBuXvYVxRzCHV5+EIRLpLX8EhB7ZkZavTlgWhFXcRFwKLeV3RrpukGdYr 2s3U702weYiUdU5Zru1DaxQ7MnkwBU7mHfS9CNc/dR8YhhYVyf1LtBwswFPdAQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701256954; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NTJP4GuZWQvoaacJKCszms5BpWIpa1KbHZbw56B8K0g=; b=XtVCgPEGtZq+DBYtql/jMQXlVRkaWVYLSVzlJAakL4uVuFbj+E0dmydaE2Dny5ynqupN2L dzEWTcKBijon8fAg== From: "tip-bot2 for Borislav Petkov (AMD)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cpu] x86/CPU/AMD: Add ZenX generations flags Cc: "Borislav Petkov (AMD)" , Nikolay Borisov , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231120104152.13740-2-bp@alien8.de> References: <20231120104152.13740-2-bp@alien8.de> MIME-Version: 1.0 Message-ID: <170125695376.398.6501830714490872202.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 29 Nov 2023 03:23:17 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783079419903797655 X-GMAIL-MSGID: 1783897264887646653 The following commit has been merged into the x86/cpu branch of tip: Commit-ID: 30fa92832f405d5ac9f263e99f62445fa3084008 Gitweb: https://git.kernel.org/tip/30fa92832f405d5ac9f263e99f62445fa3084008 Author: Borislav Petkov (AMD) AuthorDate: Tue, 31 Oct 2023 23:30:59 +01:00 Committer: Borislav Petkov (AMD) CommitterDate: Wed, 29 Nov 2023 12:11:01 +01:00 x86/CPU/AMD: Add ZenX generations flags Add X86_FEATURE flags for each Zen generation. They should be used from now on instead of checking f/m/s. Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Nikolay Borisov Acked-by: Thomas Gleixner Link: http://lore.kernel.org/r/20231120104152.13740-2-bp@alien8.de --- arch/x86/include/asm/cpufeatures.h | 5 +- arch/x86/kernel/cpu/amd.c | 70 ++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 3e973ff..149cc5d 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -218,7 +218,7 @@ #define X86_FEATURE_IBRS ( 7*32+25) /* Indirect Branch Restricted Speculation */ #define X86_FEATURE_IBPB ( 7*32+26) /* Indirect Branch Prediction Barrier */ #define X86_FEATURE_STIBP ( 7*32+27) /* Single Thread Indirect Branch Predictors */ -#define X86_FEATURE_ZEN (7*32+28) /* "" CPU based on Zen microarchitecture */ +#define X86_FEATURE_ZEN ( 7*32+28) /* "" CPU based on Zen microarchitecture */ #define X86_FEATURE_L1TF_PTEINV ( 7*32+29) /* "" L1TF workaround PTE inversion */ #define X86_FEATURE_IBRS_ENHANCED ( 7*32+30) /* Enhanced IBRS */ #define X86_FEATURE_MSR_IA32_FEAT_CTL ( 7*32+31) /* "" MSR IA32_FEAT_CTL configured */ @@ -312,6 +312,9 @@ #define X86_FEATURE_SRSO_ALIAS (11*32+25) /* "" AMD BTB untrain RETs through aliasing */ #define X86_FEATURE_IBPB_ON_VMEXIT (11*32+26) /* "" Issue an IBPB only on VMEXIT */ #define X86_FEATURE_APIC_MSRS_FENCE (11*32+27) /* "" IA32_TSC_DEADLINE and X2APIC MSRs need fencing */ +#define X86_FEATURE_ZEN2 (11*32+28) /* "" CPU based on Zen2 microarchitecture */ +#define X86_FEATURE_ZEN3 (11*32+29) /* "" CPU based on Zen3 microarchitecture */ +#define X86_FEATURE_ZEN4 (11*32+30) /* "" CPU based on Zen4 microarchitecture */ /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */ diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 841e212..6aba224 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -616,6 +616,49 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) } resctrl_cpu_detect(c); + + /* Figure out Zen generations: */ + switch (c->x86) { + case 0x17: { + switch (c->x86_model) { + case 0x00 ... 0x2f: + case 0x50 ... 0x5f: + setup_force_cpu_cap(X86_FEATURE_ZEN); + break; + case 0x30 ... 0x4f: + case 0x60 ... 0x7f: + case 0x90 ... 0x91: + case 0xa0 ... 0xaf: + setup_force_cpu_cap(X86_FEATURE_ZEN2); + break; + default: + goto warn; + } + break; + } + case 0x19: { + switch (c->x86_model) { + case 0x00 ... 0x0f: + case 0x20 ... 0x5f: + setup_force_cpu_cap(X86_FEATURE_ZEN3); + break; + case 0x10 ... 0x1f: + case 0x60 ... 0xaf: + setup_force_cpu_cap(X86_FEATURE_ZEN4); + break; + default: + goto warn; + } + break; + } + default: + break; + } + + return; + +warn: + WARN_ONCE(1, "Family 0x%x, model: 0x%x??\n", c->x86, c->x86_model); } static void early_detect_mem_encrypt(struct cpuinfo_x86 *c) @@ -974,8 +1017,6 @@ void init_spectral_chicken(struct cpuinfo_x86 *c) static void init_amd_zn(struct cpuinfo_x86 *c) { - set_cpu_cap(c, X86_FEATURE_ZEN); - #ifdef CONFIG_NUMA node_reclaim_distance = 32; #endif @@ -1037,6 +1078,22 @@ static void zenbleed_check(struct cpuinfo_x86 *c) } } +static void init_amd_zen(struct cpuinfo_x86 *c) +{ +} + +static void init_amd_zen2(struct cpuinfo_x86 *c) +{ +} + +static void init_amd_zen3(struct cpuinfo_x86 *c) +{ +} + +static void init_amd_zen4(struct cpuinfo_x86 *c) +{ +} + static void init_amd(struct cpuinfo_x86 *c) { u64 vm_cr; @@ -1077,6 +1134,15 @@ static void init_amd(struct cpuinfo_x86 *c) case 0x19: init_amd_zn(c); break; } + if (boot_cpu_has(X86_FEATURE_ZEN)) + init_amd_zen(c); + else if (boot_cpu_has(X86_FEATURE_ZEN2)) + init_amd_zen2(c); + else if (boot_cpu_has(X86_FEATURE_ZEN3)) + init_amd_zen3(c); + else if (boot_cpu_has(X86_FEATURE_ZEN4)) + init_amd_zen4(c); + /* * Enable workaround for FXSAVE leak on CPUs * without a XSaveErPtr feature