Commit 90b926e6 authored by Juergen Gross's avatar Juergen Gross Committed by Borislav Petkov (AMD)

x86/pat: Fix pat_x_mtrr_type() for MTRR disabled case

Since

  72cbc8f0 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen")

PAT can be enabled without MTRR.

This has resulted in problems e.g. for a SEV-SNP guest running under Hyper-V,
when trying to establish a new mapping via memremap() with WB caching mode, as
pat_x_mtrr_type() will call mtrr_type_lookup(), which in turn is returning
MTRR_TYPE_INVALID due to MTRR being disabled in this configuration.

The result is a mapping with UC- caching, leading to severe performance
degradation.

Fix that by handling MTRR_TYPE_INVALID the same way as MTRR_TYPE_WRBACK
in pat_x_mtrr_type() because MTRR_TYPE_INVALID means MTRRs are disabled.

  [ bp: Massage commit message. ]

Fixes: 72cbc8f0 ("x86/PAT: Have pat_enabled() properly reflect state when running on Xen")
Reported-by: default avatarMichael Kelley (LINUX) <mikelley@microsoft.com>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
Tested-by: default avatarMichael Kelley <mikelley@microsoft.com>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20230110065427.20767-1-jgross@suse.com
parent 7c6dd961
...@@ -387,7 +387,8 @@ static unsigned long pat_x_mtrr_type(u64 start, u64 end, ...@@ -387,7 +387,8 @@ static unsigned long pat_x_mtrr_type(u64 start, u64 end,
u8 mtrr_type, uniform; u8 mtrr_type, uniform;
mtrr_type = mtrr_type_lookup(start, end, &uniform); mtrr_type = mtrr_type_lookup(start, end, &uniform);
if (mtrr_type != MTRR_TYPE_WRBACK) if (mtrr_type != MTRR_TYPE_WRBACK &&
mtrr_type != MTRR_TYPE_INVALID)
return _PAGE_CACHE_MODE_UC_MINUS; return _PAGE_CACHE_MODE_UC_MINUS;
return _PAGE_CACHE_MODE_WB; return _PAGE_CACHE_MODE_WB;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment