Skip to contentSkip to conversation

x86/mtrr: Check if fixed-range MTRR exists in `mtrr_save_fixed_ranges`

PATCH Superseded Jiaqing Zhao 2 participants 2 messages May 9, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mtrr: Check if fixed-range MTRR exists in `mtrr_save_fixed_ranges`

When suspending, save_processor_state calls mtrr_save_fixed_ranges to save fixed-range MTRRs. On platforms without MTRR or fixed-range MTRR support, accessing MTRR MSRs triggers unchecked MSR access error. Make sure fixed-range MTRR is supported before access to prevent such error.

Fixes 3ebad5905609 ("[PATCH] x86: Save and restore the fixed-range MTRRs of the BSP when suspending")
---
 arch/x86/kernel/cpu/mtrr/generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mtrr/generic.c +1 -1
index e2c6b471d230..ca37b374d1b0 100644
@@ -593,7 +593,7 @@ static void get_fixed_ranges(mtrr_type *frs)
 
 void mtrr_save_fixed_ranges(void *info)
 {
-	if (boot_cpu_has(X86_FEATURE_MTRR))
+	if (boot_cpu_has(X86_FEATURE_MTRR) && mtrr_state.have_fixed)
 		get_fixed_ranges(mtrr_state.fixed_ranges);
 }
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 1 line · Jiaqing Zhao

When suspending, save_processor_state calls mtrr_save_fixed_ranges

Put () after the function names and drop the ``.

Quoted 17 lines

to save fixed-range MTRRs. On platforms without MTRR or fixed-range MTRR support, accessing MTRR MSRs triggers unchecked MSR access error. Make sure fixed-range MTRR is supported before access to prevent such error.

Fixes 3ebad5905609 ("[PATCH] x86: Save and restore the fixed-range MTRRs of the BSP when suspending")
---
 arch/x86/kernel/cpu/mtrr/generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mtrr/generic.c +0 -0
index e2c6b471d230..ca37b374d1b0 100644

arch/x86/kernel/cpu/mtrr/generic.c static void get_fixed_ranges(mtrr_type *frs) · line 596

Quoted 5 lines
arch/x86/kernel/cpu/mtrr/generic.c +1 -1
@@ -593,7 +593,7 @@ static void get_fixed_ranges(mtrr_type *frs)
 
 void mtrr_save_fixed_ranges(void *info)
 {
-	if (boot_cpu_has(X86_FEATURE_MTRR))
+	if (boot_cpu_has(X86_FEATURE_MTRR) && mtrr_state.have_fixed)

Does it work too if you check only mtrr_state.have_fixed?

Without the feature check...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette