From nobody Mon Feb 9 14:50:24 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=1660987574; cv=none; d=zohomail.com; s=zohoarc; b=VqKOa/nQbTj7Frt+P6kTbRUMaPMBlCsecs5w63U/Egeyi6uNtaio6il3iKj1BCeIaUsV51JvMcxvKOyRK904J6F7zD1CTnuV2Dd4WT2PrNEqvWmnwVR6k8a6zex6m8DTZ53sfKy51SF0DKTvhOzI41nXtYJEKW/KZXJAsyec6j0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660987574; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zH7OrEbGSHDEOBqN5ycZpM6fL4oud1epAjDEuL53dko=; b=Ucm2uRn41EiDJ5t2TUV66Zs25XLKJ3MIBDt6XdYeTroIooVwDBEHGQWW7jUxx3rUIrWSCyATb4k7NfibsH0+wM2EsbmBC2UE1fpeLY5+dGEvicBtbnga/HKfArmsVT/tpLj4TJAY0G16IhjwivjokNJCO2fFFzcTQaAWZeMm5Bs= 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 1660987574271248.05700187577133; Sat, 20 Aug 2022 02:26:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.390679.628189 (Exim 4.92) (envelope-from ) id 1oPKjc-0006dC-W9; Sat, 20 Aug 2022 09:25:40 +0000 Received: by outflank-mailman (output) from mailman id 390679.628189; Sat, 20 Aug 2022 09:25: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 1oPKjc-0006d2-RL; Sat, 20 Aug 2022 09:25:40 +0000 Received: by outflank-mailman (input) for mailman id 390679; Sat, 20 Aug 2022 09:25:39 +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 1oPKjb-0006NL-MY for xen-devel@lists.xenproject.org; Sat, 20 Aug 2022 09:25:39 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0d31c4db-206a-11ed-bd2e-47488cf2e6aa; Sat, 20 Aug 2022 11:25:38 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BDE3234355; Sat, 20 Aug 2022 09:25:37 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7F1DF13440; Sat, 20 Aug 2022 09:25:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mMnGHZGoAGPJMAAAMHmgww (envelope-from ); Sat, 20 Aug 2022 09:25:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0d31c4db-206a-11ed-bd2e-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1660987537; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zH7OrEbGSHDEOBqN5ycZpM6fL4oud1epAjDEuL53dko=; b=uGhdI1IZGR+h8vzojT8JBtc7Y8Sk+yQ8KmTZ+ftXj6xsBac4HIS8dsBha3w9fmzifD4ZjE rcw5kNiNK9kq8REjgLzYRO/hCeVKHLcPlohrxNJHV4ikrUROnhEW/I6B5KGObt+tTnnyFX VfA79XO2ZJQ+P71Og/D4kNvZgwJ+0yk= From: Juergen Gross To: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 03/10] x86/mtrr: replace use_intel() with a local flag Date: Sat, 20 Aug 2022 11:25:26 +0200 Message-Id: <20220820092533.29420-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220820092533.29420-1-jgross@suse.com> References: <20220820092533.29420-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1660987575815100017 Content-Type: text/plain; charset="utf-8" In MTRR code use_intel() is only used in one source file, and the relevant use_intel_if member of struct mtrr_ops is set only in generic_mtrr_ops. Replace use_intel() with a single flag in cacheinfo.c, which can be set when assigning generic_mtrr_ops to mtrr_if. This allows to drop use_intel_if from mtrr_ops, while preparing to support PAT without MTRR. As another preparation for the PAT/MTRR decoupling use a bit for MTRR control and one for PAT control. For now set both bits together, this can be changed later. As the new flag will be set only if mtrr_enabled is set, the test for mtrr_enabled can be dropped at some places. At the same time drop the local mtrr_enabled() function and rename the __mtrr_enabled flag to mtrr_enabled. Signed-off-by: Juergen Gross --- V2: - new patch --- arch/x86/include/asm/cacheinfo.h | 5 +++ arch/x86/kernel/cpu/cacheinfo.c | 3 ++ arch/x86/kernel/cpu/mtrr/generic.c | 1 - arch/x86/kernel/cpu/mtrr/mtrr.c | 58 ++++++++++++++---------------- arch/x86/kernel/cpu/mtrr/mtrr.h | 2 -- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/arch/x86/include/asm/cacheinfo.h b/arch/x86/include/asm/cachei= nfo.h index 86b2e0dcc4bf..1aeafa9888f7 100644 --- a/arch/x86/include/asm/cacheinfo.h +++ b/arch/x86/include/asm/cacheinfo.h @@ -2,6 +2,11 @@ #ifndef _ASM_X86_CACHEINFO_H #define _ASM_X86_CACHEINFO_H =20 +/* Kernel controls MTRR and/or PAT MSRs. */ +extern unsigned int cache_generic; +#define CACHE_GENERIC_MTRR 0x01 +#define CACHE_GENERIC_PAT 0x02 + void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu); void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu); =20 diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 66556833d7af..3b05d3ade7a6 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -35,6 +35,9 @@ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_= map); /* Shared L2 cache maps */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map); =20 +/* Kernel controls MTRR and/or PAT MSRs. */ +unsigned int cache_generic; + struct _cache_table { unsigned char descriptor; char cache_type; diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/= generic.c index 3d185fcf08ca..3c3c7919de5b 100644 --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -921,7 +921,6 @@ int positive_have_wrcomb(void) * Generic structure... */ const struct mtrr_ops generic_mtrr_ops =3D { - .use_intel_if =3D 1, .set_all =3D generic_set_all, .get =3D generic_get_mtrr, .get_free_region =3D generic_get_free_region, diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.c b/arch/x86/kernel/cpu/mtrr/mtr= r.c index 2746cac9d8a9..4cd9c8d1473e 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.c +++ b/arch/x86/kernel/cpu/mtrr/mtrr.c @@ -46,6 +46,7 @@ #include #include =20 +#include #include #include #include @@ -58,12 +59,7 @@ #define MTRR_TO_PHYS_WC_OFFSET 1000 =20 u32 num_var_ranges; -static bool __mtrr_enabled; - -static bool mtrr_enabled(void) -{ - return __mtrr_enabled; -} +static bool mtrr_enabled; =20 unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES]; static DEFINE_MUTEX(mtrr_mutex); @@ -119,11 +115,11 @@ static int have_wrcomb(void) } =20 /* This function returns the number of variable MTRRs */ -static void __init set_num_var_ranges(void) +static void __init set_num_var_ranges(bool use_generic) { unsigned long config =3D 0, dummy; =20 - if (use_intel()) + if (use_generic) rdmsr(MSR_MTRRcap, config, dummy); else if (is_cpu(AMD) || is_cpu(HYGON)) config =3D 2; @@ -303,7 +299,7 @@ int mtrr_add_page(unsigned long base, unsigned long siz= e, int i, replace, error; mtrr_type ltype; =20 - if (!mtrr_enabled()) + if (!mtrr_enabled) return -ENXIO; =20 error =3D mtrr_if->validate_add_page(base, size, type); @@ -451,7 +447,7 @@ static int mtrr_check(unsigned long base, unsigned long= size) int mtrr_add(unsigned long base, unsigned long size, unsigned int type, bool increment) { - if (!mtrr_enabled()) + if (!mtrr_enabled) return -ENODEV; if (mtrr_check(base, size)) return -EINVAL; @@ -480,7 +476,7 @@ int mtrr_del_page(int reg, unsigned long base, unsigned= long size) unsigned long lbase, lsize; int error =3D -EINVAL; =20 - if (!mtrr_enabled()) + if (!mtrr_enabled) return -ENODEV; =20 max =3D num_var_ranges; @@ -540,7 +536,7 @@ int mtrr_del_page(int reg, unsigned long base, unsigned= long size) */ int mtrr_del(int reg, unsigned long base, unsigned long size) { - if (!mtrr_enabled()) + if (!mtrr_enabled) return -ENODEV; if (mtrr_check(base, size)) return -EINVAL; @@ -566,7 +562,7 @@ int arch_phys_wc_add(unsigned long base, unsigned long = size) { int ret; =20 - if (pat_enabled() || !mtrr_enabled()) + if (pat_enabled() || !mtrr_enabled) return 0; /* Success! (We don't need to do anything.) */ =20 ret =3D mtrr_add(base, size, MTRR_TYPE_WRCOMB, true); @@ -687,6 +683,7 @@ int __initdata changed_by_mtrr_cleanup; void __init mtrr_bp_init(void) { u32 phys_addr; + bool use_generic =3D false; =20 init_ifs(); =20 @@ -694,6 +691,7 @@ void __init mtrr_bp_init(void) =20 if (boot_cpu_has(X86_FEATURE_MTRR)) { mtrr_if =3D &generic_mtrr_ops; + use_generic =3D true; size_or_mask =3D SIZE_OR_MASK_BITS(36); size_and_mask =3D 0x00f00000; phys_addr =3D 36; @@ -755,15 +753,18 @@ void __init mtrr_bp_init(void) } =20 if (mtrr_if) { - __mtrr_enabled =3D true; - set_num_var_ranges(); + mtrr_enabled =3D true; + set_num_var_ranges(use_generic); init_table(); - if (use_intel()) { + if (use_generic) { /* BIOS may override */ - __mtrr_enabled =3D get_mtrr_state(); + mtrr_enabled =3D get_mtrr_state(); =20 - if (mtrr_enabled()) + if (mtrr_enabled) { mtrr_bp_pat_init(); + cache_generic |=3D CACHE_GENERIC_MTRR | + CACHE_GENERIC_PAT; + } =20 if (mtrr_cleanup(phys_addr)) { changed_by_mtrr_cleanup =3D 1; @@ -772,7 +773,7 @@ void __init mtrr_bp_init(void) } } =20 - if (!mtrr_enabled()) { + if (!mtrr_enabled) { pr_info("Disabled\n"); =20 /* @@ -786,10 +787,7 @@ void __init mtrr_bp_init(void) =20 void mtrr_ap_init(void) { - if (!mtrr_enabled()) - return; - - if (!use_intel() || mtrr_aps_delayed_init) + if (!cache_generic || mtrr_aps_delayed_init) return; =20 /* @@ -816,7 +814,7 @@ void mtrr_save_state(void) { int first_cpu; =20 - if (!mtrr_enabled()) + if (!mtrr_enabled) return; =20 first_cpu =3D cpumask_first(cpu_online_mask); @@ -825,9 +823,7 @@ void mtrr_save_state(void) =20 void set_mtrr_aps_delayed_init(void) { - if (!mtrr_enabled()) - return; - if (!use_intel()) + if (!cache_generic) return; =20 mtrr_aps_delayed_init =3D true; @@ -838,7 +834,7 @@ void set_mtrr_aps_delayed_init(void) */ void mtrr_aps_init(void) { - if (!use_intel() || !mtrr_enabled()) + if (!cache_generic) return; =20 /* @@ -855,7 +851,7 @@ void mtrr_aps_init(void) =20 void mtrr_bp_restore(void) { - if (!use_intel() || !mtrr_enabled()) + if (!cache_generic) return; =20 mtrr_if->set_all(); @@ -863,10 +859,10 @@ void mtrr_bp_restore(void) =20 static int __init mtrr_init_finialize(void) { - if (!mtrr_enabled()) + if (!mtrr_enabled) return 0; =20 - if (use_intel()) { + if (cache_generic & CACHE_GENERIC_MTRR) { if (!changed_by_mtrr_cleanup) mtrr_state_warn(); return 0; diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtr= r.h index 2ac99e561181..88b1c4b6174a 100644 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h @@ -14,7 +14,6 @@ extern unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES]; =20 struct mtrr_ops { u32 vendor; - u32 use_intel_if; void (*set)(unsigned int reg, unsigned long base, unsigned long size, mtrr_type type); void (*set_all)(void); @@ -61,7 +60,6 @@ extern u64 size_or_mask, size_and_mask; extern const struct mtrr_ops *mtrr_if; =20 #define is_cpu(vnd) (mtrr_if && mtrr_if->vendor =3D=3D X86_VENDOR_##vnd) -#define use_intel() (mtrr_if && mtrr_if->use_intel_if =3D=3D 1) =20 extern unsigned int num_var_ranges; extern u64 mtrr_tom2; --=20 2.35.3