Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] x86/mtrr: Check if fixed-range MTRR exists in `mtrr_save_fixed_ranges`
@ 2025-05-09  8:56 Jiaqing Zhao
  2025-05-09 10:44 ` Borislav Petkov
  0 siblings, 1 reply; 2+ messages in thread
From: Jiaqing Zhao @ 2025-05-09  8:56 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Bernhard Kaindl, Andi Kleen
  Cc: Li Fei, Jiaqing Zhao, stable, linux-kernel

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")
Cc: stable@vger.kernel.org
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@linux.intel.com>
---
 arch/x86/kernel/cpu/mtrr/generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index e2c6b471d230..ca37b374d1b0 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -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);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86/mtrr: Check if fixed-range MTRR exists in `mtrr_save_fixed_ranges`
  2025-05-09  8:56 [PATCH] x86/mtrr: Check if fixed-range MTRR exists in `mtrr_save_fixed_ranges` Jiaqing Zhao
@ 2025-05-09 10:44 ` Borislav Petkov
  0 siblings, 0 replies; 2+ messages in thread
From: Borislav Petkov @ 2025-05-09 10:44 UTC (permalink / raw)
  To: Jiaqing Zhao
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
	Bernhard Kaindl, Andi Kleen, Li Fei, stable, linux-kernel

On Fri, May 09, 2025 at 08:56:12AM +0000, Jiaqing Zhao wrote:
> When suspending, `save_processor_state` calls `mtrr_save_fixed_ranges`

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

> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jiaqing Zhao <jiaqing.zhao@linux.intel.com>
> ---
>  arch/x86/kernel/cpu/mtrr/generic.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
> index e2c6b471d230..ca37b374d1b0 100644
> --- a/arch/x86/kernel/cpu/mtrr/generic.c
> +++ b/arch/x86/kernel/cpu/mtrr/generic.c
> @@ -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...

-- 
Regards/Gruss,
    Boris.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-09 10:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-09  8:56 [PATCH] x86/mtrr: Check if fixed-range MTRR exists in `mtrr_save_fixed_ranges` Jiaqing Zhao
2025-05-09 10:44 ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox