public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: mikelley@microsoft.com, Juergen Gross <jgross@suse.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH v6 08/16] x86/mtrr: move 32-bit code from mtrr.c to legacy.c
Date: Tue,  2 May 2023 14:09:23 +0200	[thread overview]
Message-ID: <20230502120931.20719-9-jgross@suse.com> (raw)
In-Reply-To: <20230502120931.20719-1-jgross@suse.com>

There is some code in mtrr.c which is relevant for old 32-bit CPUs
only. Move it to a new source legacy.c.

While modifying mtrr_init_finalize() fix spelling of its name.

Suggested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
V6:
- new patch
---
 arch/x86/kernel/cpu/mtrr/Makefile |  2 +-
 arch/x86/kernel/cpu/mtrr/legacy.c | 84 +++++++++++++++++++++++++++++++
 arch/x86/kernel/cpu/mtrr/mtrr.c   | 80 +++--------------------------
 arch/x86/kernel/cpu/mtrr/mtrr.h   |  7 +++
 4 files changed, 98 insertions(+), 75 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/mtrr/legacy.c

diff --git a/arch/x86/kernel/cpu/mtrr/Makefile b/arch/x86/kernel/cpu/mtrr/Makefile
index cc4f9f1cb94c..aee4bc5ad496 100644
--- a/arch/x86/kernel/cpu/mtrr/Makefile
+++ b/arch/x86/kernel/cpu/mtrr/Makefile
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-y		:= mtrr.o if.o generic.o cleanup.o
-obj-$(CONFIG_X86_32) += amd.o cyrix.o centaur.o
+obj-$(CONFIG_X86_32) += amd.o cyrix.o centaur.o legacy.o
 
diff --git a/arch/x86/kernel/cpu/mtrr/legacy.c b/arch/x86/kernel/cpu/mtrr/legacy.c
new file mode 100644
index 000000000000..7d379fb26cce
--- /dev/null
+++ b/arch/x86/kernel/cpu/mtrr/legacy.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/types.h>
+#include <linux/syscore_ops.h>
+#include <asm/cpufeature.h>
+#include <asm/mtrr.h>
+#include <asm/processor.h>
+#include "mtrr.h"
+
+void mtrr_set_if(void)
+{
+	switch (boot_cpu_data.x86_vendor) {
+	case X86_VENDOR_AMD:
+		/* Pre-Athlon (K6) AMD CPU MTRRs */
+		if (cpu_feature_enabled(X86_FEATURE_K6_MTRR))
+			mtrr_if = &amd_mtrr_ops;
+		break;
+	case X86_VENDOR_CENTAUR:
+		if (cpu_feature_enabled(X86_FEATURE_CENTAUR_MCR))
+			mtrr_if = &centaur_mtrr_ops;
+		break;
+	case X86_VENDOR_CYRIX:
+		if (cpu_feature_enabled(X86_FEATURE_CYRIX_ARR))
+			mtrr_if = &cyrix_mtrr_ops;
+		break;
+	default:
+		break;
+	}
+}
+
+/*
+ * The suspend/resume methods are only for CPUs without MTRR. CPUs using generic
+ * MTRR driver don't require this.
+ */
+struct mtrr_value {
+	mtrr_type	ltype;
+	unsigned long	lbase;
+	unsigned long	lsize;
+};
+
+static struct mtrr_value mtrr_value[MTRR_MAX_VAR_RANGES];
+
+static int mtrr_save(void)
+{
+	int i;
+
+	for (i = 0; i < num_var_ranges; i++) {
+		mtrr_if->get(i, &mtrr_value[i].lbase,
+				&mtrr_value[i].lsize,
+				&mtrr_value[i].ltype);
+	}
+	return 0;
+}
+
+static void mtrr_restore(void)
+{
+	int i;
+
+	for (i = 0; i < num_var_ranges; i++) {
+		if (mtrr_value[i].lsize) {
+			mtrr_if->set(i, mtrr_value[i].lbase,
+				     mtrr_value[i].lsize,
+				     mtrr_value[i].ltype);
+		}
+	}
+}
+
+static struct syscore_ops mtrr_syscore_ops = {
+	.suspend	= mtrr_save,
+	.resume		= mtrr_restore,
+};
+
+void mtrr_register_syscore(void)
+{
+	/*
+	 * The CPU has no MTRR and seems to not support SMP. They have
+	 * specific drivers, we use a tricky method to support
+	 * suspend/resume for them.
+	 *
+	 * TBD: is there any system with such CPU which supports
+	 * suspend/resume? If no, we should remove the code.
+	 */
+	register_syscore_ops(&mtrr_syscore_ops);
+}
diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.c b/arch/x86/kernel/cpu/mtrr/mtrr.c
index 3a38f34bf289..0eeb03d92d8c 100644
--- a/arch/x86/kernel/cpu/mtrr/mtrr.c
+++ b/arch/x86/kernel/cpu/mtrr/mtrr.c
@@ -545,49 +545,6 @@ int arch_phys_wc_index(int handle)
 }
 EXPORT_SYMBOL_GPL(arch_phys_wc_index);
 
-/* The suspend/resume methods are only for CPU without MTRR. CPU using generic
- * MTRR driver doesn't require this
- */
-struct mtrr_value {
-	mtrr_type	ltype;
-	unsigned long	lbase;
-	unsigned long	lsize;
-};
-
-static struct mtrr_value mtrr_value[MTRR_MAX_VAR_RANGES];
-
-static int mtrr_save(void)
-{
-	int i;
-
-	for (i = 0; i < num_var_ranges; i++) {
-		mtrr_if->get(i, &mtrr_value[i].lbase,
-				&mtrr_value[i].lsize,
-				&mtrr_value[i].ltype);
-	}
-	return 0;
-}
-
-static void mtrr_restore(void)
-{
-	int i;
-
-	for (i = 0; i < num_var_ranges; i++) {
-		if (mtrr_value[i].lsize) {
-			mtrr_if->set(i, mtrr_value[i].lbase,
-				     mtrr_value[i].lsize,
-				     mtrr_value[i].ltype);
-		}
-	}
-}
-
-
-
-static struct syscore_ops mtrr_syscore_ops = {
-	.suspend	= mtrr_save,
-	.resume		= mtrr_restore,
-};
-
 int __initdata changed_by_mtrr_cleanup;
 
 /**
@@ -615,27 +572,10 @@ void __init mtrr_bp_init(void)
 		return;
 	}
 
-	if (generic_mtrrs) {
+	if (generic_mtrrs)
 		mtrr_if = &generic_mtrr_ops;
-	} else {
-		switch (boot_cpu_data.x86_vendor) {
-		case X86_VENDOR_AMD:
-			/* Pre-Athlon (K6) AMD CPU MTRRs */
-			if (cpu_feature_enabled(X86_FEATURE_K6_MTRR))
-				mtrr_if = &amd_mtrr_ops;
-			break;
-		case X86_VENDOR_CENTAUR:
-			if (cpu_feature_enabled(X86_FEATURE_CENTAUR_MCR))
-				mtrr_if = &centaur_mtrr_ops;
-			break;
-		case X86_VENDOR_CYRIX:
-			if (cpu_feature_enabled(X86_FEATURE_CYRIX_ARR))
-				mtrr_if = &cyrix_mtrr_ops;
-			break;
-		default:
-			break;
-		}
-	}
+	else
+		mtrr_set_if();
 
 	if (mtrr_enabled()) {
 		/* Get the number of variable MTRR ranges. */
@@ -677,7 +617,7 @@ void mtrr_save_state(void)
 	smp_call_function_single(first_cpu, mtrr_save_fixed_ranges, NULL, 1);
 }
 
-static int __init mtrr_init_finialize(void)
+static int __init mtrr_init_finalize(void)
 {
 	if (!mtrr_enabled())
 		return 0;
@@ -688,16 +628,8 @@ static int __init mtrr_init_finialize(void)
 		return 0;
 	}
 
-	/*
-	 * The CPU has no MTRR and seems to not support SMP. They have
-	 * specific drivers, we use a tricky method to support
-	 * suspend/resume for them.
-	 *
-	 * TBD: is there any system with such CPU which supports
-	 * suspend/resume? If no, we should remove the code.
-	 */
-	register_syscore_ops(&mtrr_syscore_ops);
+	mtrr_register_syscore();
 
 	return 0;
 }
-subsys_initcall(mtrr_init_finialize);
+subsys_initcall(mtrr_init_finalize);
diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
index 0dd11e41baa6..f626febeb545 100644
--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
@@ -61,6 +61,13 @@ void mtrr_set_mask(void);
 void mtrr_state_warn(void);
 const char *mtrr_attrib_to_str(int x);
 void mtrr_wrmsr(unsigned, unsigned, unsigned);
+#ifdef CONFIG_X86_32
+void mtrr_set_if(void);
+void mtrr_register_syscore(void);
+#else
+static inline void mtrr_set_if(void) { }
+static inline void mtrr_register_syscore(void) { }
+#endif
 
 /* CPU specific mtrr_ops vectors. */
 extern const struct mtrr_ops amd_mtrr_ops;
-- 
2.35.3


  parent reply	other threads:[~2023-05-02 12:11 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 12:09 [PATCH v6 00/16] x86/mtrr: fix handling with PAT but without MTRR Juergen Gross
2023-05-02 12:09 ` [PATCH v6 01/16] x86/mtrr: remove physical address size calculation Juergen Gross
2023-05-04  7:47   ` Borislav Petkov
2023-05-04  8:02     ` Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Remove " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 02/16] x86/mtrr: replace some constants with defines Juergen Gross
2023-05-05 18:49   ` Borislav Petkov
2023-05-08 13:00     ` Juergen Gross
2023-05-08 14:07       ` Borislav Petkov
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Replace size_or_mask and size_and_mask with a much easier concept tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 03/16] x86/mtrr: support setting MTRR state for software defined MTRRs Juergen Gross
2023-05-02 12:09 ` [PATCH v6 04/16] x86/hyperv: set MTRR state when running as SEV-SNP Hyper-V guest Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/hyperv: Set " tip-bot2 for Juergen Gross
2023-06-08  4:31     ` Michael Kelley (LINUX)
2023-05-02 12:09 ` [PATCH v6 05/16] x86/xen: set MTRR state when running as Xen PV initial domain Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/xen: Set " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 06/16] x86/mtrr: replace vendor tests in MTRR code Juergen Gross
2023-05-09 18:37   ` Borislav Petkov
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Replace " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 07/16] x86/mtrr: have only one set_mtrr() variant Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Have " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` Juergen Gross [this message]
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Move 32-bit code from mtrr.c to legacy.c tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 09/16] x86/mtrr: allocate mtrr_value array dynamically Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Allocate " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 10/16] x86/mtrr: add get_effective_type() service function Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Add " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 11/16] x86/mtrr: construct a memory map with cache modes Juergen Gross
2023-05-09 11:36   ` Borislav Petkov
2023-05-09 11:47     ` Juergen Gross
2023-05-09 12:10       ` Borislav Petkov
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Construct " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 12/16] x86/mtrr: add mtrr=debug command line option Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Add " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 13/16] x86/mtrr: use new cache_map in mtrr_type_lookup() Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Use " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 14/16] x86/mtrr: don't let mtrr_type_lookup() return MTRR_TYPE_INVALID Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Don't " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 15/16] x86/mm: only check uniform after calling mtrr_type_lookup() Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mm: Only " tip-bot2 for Juergen Gross
2023-05-02 12:09 ` [PATCH v6 16/16] x86/mtrr: remove unused code Juergen Gross
2023-06-05 14:08   ` [tip: x86/mtrr] x86/mtrr: Remove " tip-bot2 for Juergen Gross
2023-05-03  4:22 ` [PATCH v6 00/16] x86/mtrr: fix handling with PAT but without MTRR Michael Kelley (LINUX)
2023-05-03 18:14 ` Sohil Mehta
2023-05-03 19:12   ` Borislav Petkov
2023-05-09 20:14 ` Borislav Petkov
2023-05-09 23:36   ` Borislav Petkov
2023-05-10 13:30     ` Borislav Petkov
2023-05-10 13:31       ` Borislav Petkov
2023-05-10 15:53       ` Juergen Gross
2023-05-11 16:32         ` Borislav Petkov
2023-05-22 14:17           ` Juergen Gross
2023-05-30 15:28             ` Borislav Petkov
2023-05-31  7:28               ` Juergen Gross
2023-05-31  8:35                 ` Borislav Petkov
2023-05-31  9:31                   ` Juergen Gross
2023-05-31  9:58                     ` Borislav Petkov
2023-05-31 14:20                   ` Juergen Gross
2023-05-31 17:48                     ` Borislav Petkov
2023-06-01  6:39                       ` Juergen Gross
2023-06-01 12:48                         ` Borislav Petkov
2023-06-01 12:53                           ` Juergen Gross
2023-06-01  8:19                       ` Juergen Gross
2023-06-01 13:22                         ` Borislav Petkov
2023-06-01 14:33                           ` Borislav Petkov
2023-06-01 14:34                             ` Juergen Gross
2023-06-01 13:10                       ` Juergen Gross
2023-06-05 14:08                       ` [tip: x86/mtrr] x86/mtrr: Unify debugging printing tip-bot2 for Borislav Petkov (AMD)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230502120931.20719-9-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox