Skip to contentSkip to conversation

x86/mtrr, pat: make PAT independent from MTRR

PATCH In review Isaku Yamahata 3 participants 9 messages Aug 9, 2019 – Aug 13, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover x86/mtrr, pat: make PAT independent from MTRR

Make PAT(Page Attribute Table) independent from
MTRR(Memory Type Range Register).
Some environments (mainly virtual ones) support only PAT, but not MTRR because PAT replaces MTRR.
It's tricky and no gain to support both MTRR and PAT except compatibility. So some VM technologies don't support MTRR, but only PAT.
This patch series makes PAT available on such environments without MTRR.

patch 1 and 2 are only preparation. no logic change, function rename (mtrr_ => mtrr_pat_ which is commonly used by both MTRR and PAT) and moving functions out from mtrr specific files to a common file. patch 3 is an essential patch which makes PAT independent from MTRR.

Isaku Yamahata (3):
x86/mtrr: split common funcs from mtrr.c
x86/mtrr: split common funcs from generic.c
x86/mtrr, pat: make PAT independent from MTRR

 arch/x86/Kconfig                      |   1 -
 arch/x86/include/asm/mtrr.h           |  37 ++-
 arch/x86/include/asm/pat.h            |   2 +
 arch/x86/kernel/cpu/common.c          |   2 +-
 arch/x86/kernel/cpu/mtrr/Makefile     |   2 +-
 arch/x86/kernel/cpu/mtrr/generic.c    | 116 +--------
 arch/x86/kernel/cpu/mtrr/mtrr.c       | 211 +----------------
 arch/x86/kernel/cpu/mtrr/mtrr.h       |   8 +-
 arch/x86/kernel/cpu/mtrr/rendezvous.c | 324 ++++++++++++++++++++++++++
 arch/x86/kernel/setup.c               |   4 +-
 arch/x86/kernel/smpboot.c             |   8 +-
 arch/x86/mm/Makefile                  |   3 +
 arch/x86/mm/pat.c                     |  99 +++++++-
 arch/x86/power/cpu.c                  |   2 +-
 14 files changed, 479 insertions(+), 340 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/mtrr/rendezvous.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 x86/mtrr: split common funcs from mtrr.c

This is a preparation for make PAT(Page Attribute Table) independent from MTRR(Memory Type Range Register).
It renames prefix of common functions in mtrr.c from mtrr_ to mtrr_pat_ which are commonly used by both MTRR and PAT and moves out them from mtrr.c to rendezvous.c.
Only prefix rename and movement, no logic change.

---
 arch/x86/include/asm/mtrr.h           |  25 +--
 arch/x86/kernel/cpu/common.c          |   2 +-
 arch/x86/kernel/cpu/mtrr/Makefile     |   2 +-
 arch/x86/kernel/cpu/mtrr/mtrr.c       | 201 ++---------------------
 arch/x86/kernel/cpu/mtrr/mtrr.h       |   6 +
 arch/x86/kernel/cpu/mtrr/rendezvous.c | 221 ++++++++++++++++++++++++++
 arch/x86/kernel/setup.c               |   4 +-
 arch/x86/kernel/smpboot.c             |   8 +-
 arch/x86/power/cpu.c                  |   2 +-
 9 files changed, 260 insertions(+), 211 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/mtrr/rendezvous.c
arch/x86/include/asm/mtrr.h +15 -10
index dbff1456d215..d90e87c55302 100644
@@ -32,6 +32,7 @@
  * arch_phys_wc_add and arch_phys_wc_del.
  */
 # ifdef CONFIG_MTRR
+extern bool mtrr_enabled(void);
 extern u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform);
 extern void mtrr_save_fixed_ranges(void *);
 extern void mtrr_save_state(void);
@@ -42,14 +43,18 @@ extern int mtrr_add_page(unsigned long base, unsigned long size,
 extern int mtrr_del(int reg, unsigned long base, unsigned long size);
 extern int mtrr_del_page(int reg, unsigned long base, unsigned long size);
 extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
-extern void mtrr_ap_init(void);
-extern void mtrr_bp_init(void);
-extern void set_mtrr_aps_delayed_init(void);
-extern void mtrr_aps_init(void);
-extern void mtrr_bp_restore(void);
+extern void mtrr_pat_ap_init(void);
+extern void mtrr_pat_bp_init(void);
+extern void set_mtrr_pat_aps_delayed_init(void);
+extern void mtrr_pat_aps_init(void);
+extern void mtrr_pat_bp_restore(void);
 extern int mtrr_trim_uncached_memory(unsigned long end_pfn);
 extern int amd_special_default_mtrr(void);
 #  else
+static inline bool mtrr_enabled(void)
+{
+	return false;
+}
 static inline u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform)
 {
 	/*
@@ -84,15 +89,15 @@ static inline int mtrr_trim_uncached_memory(unsigned long end_pfn)
 static inline void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi)
 {
 }
-static inline void mtrr_bp_init(void)
+static inline void mtrr_pat_bp_init(void)
 {
 	pat_disable("MTRRs disabled, skipping PAT initialization too.");
 }
 
-#define mtrr_ap_init() do {} while (0)
-#define set_mtrr_aps_delayed_init() do {} while (0)
-#define mtrr_aps_init() do {} while (0)
-#define mtrr_bp_restore() do {} while (0)
+static inline void mtrr_pat_ap_init(void) { };
+static inline void set_mtrr_pat_aps_delayed_init(void) { };
+static inline void mtrr_pat_aps_init(void) { };
+static inline void mtrr_pat_bp_restore(void) { };
 #  endif
 
 #ifdef CONFIG_COMPAT
arch/x86/kernel/cpu/common.c +1 -1
index 11472178e17f..39b7942cb6fc 100644
@@ -1550,7 +1550,7 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c)
 #ifdef CONFIG_X86_32
 	enable_sep_cpu();
 #endif
-	mtrr_ap_init();
+	mtrr_pat_ap_init();
 	validate_apic_and_package_id(c);
 	x86_spec_ctrl_setup_ap();
 }
arch/x86/kernel/cpu/mtrr/Makefile +1 -1
index cc4f9f1cb94c..e339d729f349 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-y		:= mtrr.o if.o generic.o cleanup.o
+obj-y		:= mtrr.o if.o generic.o cleanup.o rendezvous.o
 obj-$(CONFIG_X86_32) += amd.o cyrix.o centaur.o
 
arch/x86/kernel/cpu/mtrr/mtrr.c +9 -192

290 lines not on this page · raw message

arch/x86/kernel/cpu/mtrr/mtrr.h +6 -0
index 2ac99e561181..e9aeeeac9a3e 100644
@@ -71,6 +71,12 @@ void mtrr_state_warn(void);
 const char *mtrr_attrib_to_str(int x);
 void mtrr_wrmsr(unsigned, unsigned, unsigned);
 
+/* rendezvous */
+void set_mtrr_pat(unsigned int reg, unsigned long base,
+		  unsigned long size, mtrr_type type);
+void set_mtrr_pat_cpuslocked(unsigned int reg, unsigned long base,
+			     unsigned long size, mtrr_type type);
+
 /* CPU specific mtrr init functions */
 int amd_init_mtrr(void);
 int cyrix_init_mtrr(void);
arch/x86/kernel/cpu/mtrr/rendezvous.c new file +221 -0

221 lines not on this page · raw message

arch/x86/kernel/setup.c +2 -2
index bbe35bf879f5..ca06370c7a13 100644
@@ -1064,7 +1064,7 @@ void __init setup_arch(char **cmdline_p)
 	max_pfn = e820__end_of_ram_pfn();
 
 	/* update e820 for memory not covered by WB MTRRs */
-	mtrr_bp_init();
+	mtrr_pat_bp_init();
 	if (mtrr_trim_uncached_memory(max_pfn))
 		max_pfn = e820__end_of_ram_pfn();
 
@@ -1072,7 +1072,7 @@ void __init setup_arch(char **cmdline_p)
 
 	/*
 	 * This call is required when the CPU does not support PAT. If
-	 * mtrr_bp_init() invoked it already via pat_init() the call has no
+	 * mtrr_pat_bp_init() invoked it already via pat_init() the call has no
 	 * effect.
 	 */
 	init_cache_modes();
arch/x86/kernel/smpboot.c +4 -4
index fdbd47ceb84d..3e16e7e3a01b 100644
@@ -1370,7 +1370,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
 
 	uv_system_init();
 
-	set_mtrr_aps_delayed_init();
+	set_mtrr_pat_aps_delayed_init();
 
 	smp_quirk_init_udelay();
 
@@ -1379,12 +1379,12 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
 
 void arch_enable_nonboot_cpus_begin(void)
 {
-	set_mtrr_aps_delayed_init();
+	set_mtrr_pat_aps_delayed_init();
 }
 
 void arch_enable_nonboot_cpus_end(void)
 {
-	mtrr_aps_init();
+	mtrr_pat_aps_init();
 }
 
 /*
@@ -1424,7 +1424,7 @@ void __init native_smp_cpus_done(unsigned int max_cpus)
 
 	nmi_selftest();
 	impress_friends();
-	mtrr_aps_init();
+	mtrr_pat_aps_init();
 }
 
 static int __initdata setup_possible_cpus = -1;
arch/x86/power/cpu.c +1 -1
index 24b079e94bc2..860d33b0dd1b 100644
@@ -263,7 +263,7 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
 	do_fpu_end();
 	tsc_verify_tsc_adjust(true);
 	x86_platform.restore_sched_clock_state();
-	mtrr_bp_restore();
+	mtrr_pat_bp_restore();
 	perf_restore_debug_store();
 	msr_restore_context(ctxt);
 }
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/3 x86/mtrr: split common funcs from generic.c

In reply to Isaku Yamahata

This is a preparation for make PAT(Page Attribute Table) independent from MTRR(Memory Type Range Register).
It renames prefix of common functions in mtrr/generic.c from mtrr_ to mtrr_pat_ which are commonly used by both MTRR and PAT and moves out them from mtrr/generic.c to rendezvous.c.
Only prefix rename and movement, no logic change.

---
 arch/x86/include/asm/mtrr.h           |   4 +
 arch/x86/kernel/cpu/mtrr/generic.c    | 111 ++------------------------
 arch/x86/kernel/cpu/mtrr/mtrr.c       |   2 +-
 arch/x86/kernel/cpu/mtrr/mtrr.h       |   3 +-
 arch/x86/kernel/cpu/mtrr/rendezvous.c |  91 +++++++++++++++++++++
 5 files changed, 106 insertions(+), 105 deletions(-)
arch/x86/include/asm/mtrr.h +4 -0
index d90e87c55302..5b056374f5a6 100644
@@ -33,6 +33,8 @@
  */
 # ifdef CONFIG_MTRR
 extern bool mtrr_enabled(void);
+extern void mtrr_pat_prepare_set(void) __acquires(set_atomicity_lock);
+extern void mtrr_pat_post_set(void) __releases(set_atomicity_lock);
 extern u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform);
 extern void mtrr_save_fixed_ranges(void *);
 extern void mtrr_save_state(void);
@@ -55,6 +57,8 @@ static inline bool mtrr_enabled(void)
 {
 	return false;
 }
+static inline void mtrr_pat_prepare_set(void) { };
+static inline void mtrr_pat_post_set(void) { };
 static inline u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform)
 {
 	/*
arch/x86/kernel/cpu/mtrr/generic.c +8 -103

166 lines not on this page · raw message

arch/x86/kernel/cpu/mtrr/mtrr.c +1 -1
index 3d35edb1aa42..475627ca2c1b 100644
@@ -646,7 +646,7 @@ void __init mtrr_pat_bp_init(void)
 			__mtrr_enabled = get_mtrr_state();
 
 			if (mtrr_enabled())
-				mtrr_bp_pat_init();
+				pat_bp_init();
 
 			if (mtrr_cleanup(phys_addr)) {
 				changed_by_mtrr_cleanup = 1;
arch/x86/kernel/cpu/mtrr/mtrr.h +2 -1
index e9aeeeac9a3e..57948b651b8e 100644
@@ -53,7 +53,7 @@ void set_mtrr_prepare_save(struct set_mtrr_context *ctxt);
 void fill_mtrr_var_range(unsigned int index,
 		u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
 bool get_mtrr_state(void);
-void mtrr_bp_pat_init(void);
+void pat_bp_init(void);
 
 extern void __init set_mtrr_ops(const struct mtrr_ops *ops);
 
@@ -76,6 +76,7 @@ void set_mtrr_pat(unsigned int reg, unsigned long base,
 		  unsigned long size, mtrr_type type);
 void set_mtrr_pat_cpuslocked(unsigned int reg, unsigned long base,
 			     unsigned long size, mtrr_type type);
+extern u32 mtrr_deftype_lo, mtrr_deftype_hi;
 
 /* CPU specific mtrr init functions */
 int amd_init_mtrr(void);
arch/x86/kernel/cpu/mtrr/rendezvous.c +91 -0

105 lines not on this page · raw message

Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/3 x86/mtrr, pat: make PAT independent from MTRR

In reply to Isaku Yamahata

This patch makes PAT(Page Attribute Table) independent from MTRR(Memory Type Range Register)
Some environments (mainly virtual ones) support only PAT, not MTRR. It's tricky and no gain to support both MTRR and PAT at the same time except compatibility because PAT replaces MTRR. So some VM technologies don't support MTRR, but only PAT. This patch make PAT available on such environments without MTRR.

---
 arch/x86/Kconfig                      |  1 -
 arch/x86/include/asm/mtrr.h           | 32 +++++----
 arch/x86/include/asm/pat.h            |  2 +
 arch/x86/kernel/cpu/mtrr/generic.c    |  5 --
 arch/x86/kernel/cpu/mtrr/mtrr.c       |  8 +--
 arch/x86/kernel/cpu/mtrr/mtrr.h       |  1 -
 arch/x86/kernel/cpu/mtrr/rendezvous.c | 76 +++++++++++---------
 arch/x86/mm/Makefile                  |  3 +
 arch/x86/mm/pat.c                     | 99 ++++++++++++++++++++++++---
 9 files changed, 158 insertions(+), 69 deletions(-)
arch/x86/Kconfig +0 -1
index 222855cc0158..5654283e010f 100644
@@ -1838,7 +1838,6 @@ config MTRR_SANITIZER_SPARE_REG_NR_DEFAULT
 config X86_PAT
 	def_bool y
 	prompt "x86 PAT support" if EXPERT
-	depends on MTRR
 	---help---
 	  Use PAT attributes to setup page level cache control.
 
arch/x86/include/asm/mtrr.h +18 -14
index 5b056374f5a6..a401ad106c28 100644
@@ -31,10 +31,25 @@
  * The following functions are for use by other drivers that cannot use
  * arch_phys_wc_add and arch_phys_wc_del.
  */
-# ifdef CONFIG_MTRR
-extern bool mtrr_enabled(void);
+#if defined(CONFIG_MTRR) || defined(CONFIG_X86_PAT)
+/* common method for MTRR and PAT */
 extern void mtrr_pat_prepare_set(void) __acquires(set_atomicity_lock);
 extern void mtrr_pat_post_set(void) __releases(set_atomicity_lock);
+extern void mtrr_pat_ap_init(void);
+extern void set_mtrr_pat_aps_delayed_init(void);
+extern void mtrr_pat_aps_init(void);
+extern void mtrr_pat_bp_restore(void);
+#else
+static inline void mtrr_pat_prepare_set(void) { }
+static inline void mtrr_pat_post_set(void) { }
+static inline void mtrr_pat_ap_init(void) { };
+static inline void set_mtrr_pat_aps_delayed_init(void) { };
+static inline void mtrr_pat_aps_init(void) { };
+static inline void mtrr_pat_bp_restore(void) { };
+#endif
+
+# ifdef CONFIG_MTRR
+extern bool mtrr_enabled(void);
 extern u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform);
 extern void mtrr_save_fixed_ranges(void *);
 extern void mtrr_save_state(void);
@@ -45,11 +60,7 @@ extern int mtrr_add_page(unsigned long base, unsigned long size,
 extern int mtrr_del(int reg, unsigned long base, unsigned long size);
 extern int mtrr_del_page(int reg, unsigned long base, unsigned long size);
 extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
-extern void mtrr_pat_ap_init(void);
 extern void mtrr_pat_bp_init(void);
-extern void set_mtrr_pat_aps_delayed_init(void);
-extern void mtrr_pat_aps_init(void);
-extern void mtrr_pat_bp_restore(void);
 extern int mtrr_trim_uncached_memory(unsigned long end_pfn);
 extern int amd_special_default_mtrr(void);
 #  else
@@ -57,8 +68,6 @@ static inline bool mtrr_enabled(void)
 {
 	return false;
 }
-static inline void mtrr_pat_prepare_set(void) { };
-static inline void mtrr_pat_post_set(void) { };
 static inline u8 mtrr_type_lookup(u64 addr, u64 end, u8 *uniform)
 {
 	/*
@@ -95,13 +104,8 @@ static inline void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi)
 }
 static inline void mtrr_pat_bp_init(void)
 {
-	pat_disable("MTRRs disabled, skipping PAT initialization too.");
+	pat_bp_init();
 }
-
-static inline void mtrr_pat_ap_init(void) { };
-static inline void set_mtrr_pat_aps_delayed_init(void) { };
-static inline void mtrr_pat_aps_init(void) { };
-static inline void mtrr_pat_bp_restore(void) { };
 #  endif
 
 #ifdef CONFIG_COMPAT
arch/x86/include/asm/pat.h +2 -0
index 92015c65fa2a..2a355ce94ebf 100644
@@ -7,7 +7,9 @@
 
 bool pat_enabled(void);
 void pat_disable(const char *reason);
+extern void pat_set(void);
 extern void pat_init(void);
+extern void pat_bp_init(void);
 extern void init_cache_modes(void);
 
 extern int reserve_memtype(u64 start, u64 end,
arch/x86/kernel/cpu/mtrr/generic.c +0 -5
index a44f05f64846..f9a7ca79e2c2 100644
@@ -6,13 +6,8 @@
 #define DEBUG
 
 #include <linux/export.h>
-#include <linux/init.h>
-#include <linux/io.h>
 #include <linux/mm.h>
 
-#include <asm/processor-flags.h>
-#include <asm/cpufeature.h>
-#include <asm/tlbflush.h>
 #include <asm/mtrr.h>
 #include <asm/msr.h>
 #include <asm/pat.h>
arch/x86/kernel/cpu/mtrr/mtrr.c +1 -7
index 475627ca2c1b..2d28c9b37ae7 100644
@@ -657,13 +657,7 @@ void __init mtrr_pat_bp_init(void)
 
 	if (!mtrr_enabled()) {
 		pr_info("Disabled\n");
-
-		/*
-		 * PAT initialization relies on MTRR's rendezvous handler.
-		 * Skip PAT init until the handler can initialize both
-		 * features independently.
-		 */
-		pat_disable("MTRRs disabled, skipping PAT initialization too.");
+		pat_bp_init();
 	}
 }
 
arch/x86/kernel/cpu/mtrr/mtrr.h +0 -1
index 57948b651b8e..dfc1094cae27 100644
@@ -53,7 +53,6 @@ void set_mtrr_prepare_save(struct set_mtrr_context *ctxt);
 void fill_mtrr_var_range(unsigned int index,
 		u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
 bool get_mtrr_state(void);
-void pat_bp_init(void);
 
 extern void __init set_mtrr_ops(const struct mtrr_ops *ops);
 
arch/x86/kernel/cpu/mtrr/rendezvous.c +44 -32

148 lines not on this page · raw message

arch/x86/mm/Makefile +3 -0
index 84373dc9b341..841820553a62 100644
@@ -24,6 +24,9 @@ CFLAGS_mem_encrypt_identity.o	:= $(nostackp)
 CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/trace
 
 obj-$(CONFIG_X86_PAT)		+= pat_rbtree.o
+ifndef CONFIG_MTRR
+obj-$(CONFIG_X86_PAT)		+= ../kernel/cpu/mtrr/rendezvous.o
+endif
 
 obj-$(CONFIG_X86_32)		+= pgtable_32.o iomap_32.o
 
arch/x86/mm/pat.c +90 -9

143 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#4 lore raw
In reply to Isaku Yamahata
Quoted 7 lines · Isaku Yamahata

Make PAT(Page Attribute Table) independent from
MTRR(Memory Type Range Register).
Some environments (mainly virtual ones) support only PAT, but not MTRR because PAT replaces MTRR.
It's tricky and no gain to support both MTRR and PAT except compatibility. So some VM technologies don't support MTRR, but only PAT.
This patch series makes PAT available on such environments without MTRR.

And this "justification" is not even trying. Which "VM technologies" are those? Why do we care? What's the impact? Why do we want this?

You need to sell this properly.

Also, your patches are huge. You'd need to split them sensibly.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#5 lore raw
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · Isaku Yamahata

Make PAT(Page Attribute Table) independent from
MTRR(Memory Type Range Register).
Some environments (mainly virtual ones) support only PAT, but not MTRR because PAT replaces MTRR.
It's tricky and no gain to support both MTRR and PAT except compatibility. So some VM technologies don't support MTRR, but only PAT.

I do not think it is technically correct on bare metal. AFAIK, MTRR is still the only way to setup cache attribute in real-mode, which BIOS SMI handler relies on in SMM.

Quoted 6 lines
Quoted 1 line

This patch series makes PAT available on such environments without MTRR.

And this "justification" is not even trying. Which "VM technologies" are those? Why do we care? What's the impact? Why do we want this?

You need to sell this properly.

Agreed. If the situation is still the same, Xen does not support MTRR, and the kernel sets the PAT table to the BIOS hand-off state when MTRR is disabled. The change below accommodated the fact that Xen hypervisor enables WC before hand-off, which is different from the default BIOS hand-off state. The kernel does not support setting PAT when MTRR is disabled due to the dependency Isaku mentioned.

https://www.mail-archive.com/[email protected]/msg1107094.html

-Toshi

#6 lore raw
Quoted 9 lines · Toshi
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · Isaku Yamahata

Make PAT(Page Attribute Table) independent from
MTRR(Memory Type Range Register).
Some environments (mainly virtual ones) support only PAT, but not MTRR because PAT replaces MTRR.
It's tricky and no gain to support both MTRR and PAT except compatibility. So some VM technologies don't support MTRR, but only PAT.

Quoted 3 lines

I do not think it is technically correct on bare metal. AFAIK, MTRR is still the only way to setup cache attribute in real-mode, which BIOS SMI handler relies on in SMM.

Then you're claiming if it's baremetal, both MTRR and PAT should be enabled/disabled at the same time?

Quoted 15 lines
Quoted 6 lines
Quoted 1 line

This patch series makes PAT available on such environments without MTRR.

And this "justification" is not even trying. Which "VM technologies" are those? Why do we care? What's the impact? Why do we want this?

You need to sell this properly.

Agreed. If the situation is still the same, Xen does not support MTRR, and the kernel sets the PAT table to the BIOS hand-off state when MTRR is disabled. The change below accommodated the fact that Xen hypervisor enables WC before hand-off, which is different from the default BIOS hand-off state. The kernel does not support setting PAT when MTRR is disabled due to the dependency Isaku mentioned.

Quoted 1 line

https://www.mail-archive.com/[email protected]/msg1107094.html

Thanks for supplement.
In addition to Xen, KVM+qemu can enable/disable MTRR, PAT independently. So user may want to disable MTRR to reduce attack surface. ACRN doesn't support MTRR.

Let me include those description for next respin.

Signature · 1 line
Isaku Yamahata <[email protected]>
maintainer
#7 lore raw
Quoted 2 lines · Isaku Yamahata

In addition to Xen, KVM+qemu can enable/disable MTRR, PAT independently. So user may want to disable MTRR to reduce attack surface.

No, no "user may want" etc vague formulations. Just because some virt thing "can" do stuff doesn't mean we should change the kernel. What are the clear benefits of your proposal, why should it go upstream and why should it be exposed to everybody?

How is going to be used it and what would it bring?

Are there any downsides?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#8 lore raw
In reply to Isaku Yamahata
Quoted 12 lines · Isaku Yamahata
Quoted 9 lines · Toshi
Quoted 7 lines · Borislav Petkov
Quoted 6 lines · Isaku Yamahata

Make PAT(Page Attribute Table) independent from
MTRR(Memory Type Range Register).
Some environments (mainly virtual ones) support only PAT, but not MTRR because PAT replaces MTRR.
It's tricky and no gain to support both MTRR and PAT except compatibility. So some VM technologies don't support MTRR, but only PAT.

Quoted 6 lines
Quoted 3 lines

I do not think it is technically correct on bare metal. AFAIK, MTRR is still the only way to setup cache attribute in real-mode, which BIOS SMI handler relies on in SMM.

Then you're claiming if it's baremetal, both MTRR and PAT should be enabled/disabled at the same time?

No, I did not say that. My point:
- Your statement of MTTR being useless is not correct. It's still used. The OS should leave the MTTR hand-off state.

I agree with you in general that PAT and MTTR init should be independent. However, as Boris said, please verify the impact of your change. As I mentioned in the Xen's example, hypervisor may have non- default PAT hand-off setting.

Thanks,
-Toshi