Re: [PATCH] x86/PAT: have pat_enabled() properly reflect state when running on e.g. Xen

From: Borislav Petkov
Date: Tue Jul 05 2022 - 11:08:14 EST


On Thu, Apr 28, 2022 at 04:50:29PM +0200, Jan Beulich wrote:
> --- a/arch/x86/mm/pat/memtype.c
> +++ b/arch/x86/mm/pat/memtype.c
> @@ -62,6 +62,7 @@
>
> static bool __read_mostly pat_bp_initialized;
> static bool __read_mostly pat_disabled = !IS_ENABLED(CONFIG_X86_PAT);
> +static bool __initdata pat_force_disabled = !IS_ENABLED(CONFIG_X86_PAT);
> static bool __read_mostly pat_bp_enabled;
> static bool __read_mostly pat_cm_initialized;

Why yet another boolean var?

Why not extend pat_enabled() to reflect the Xen case and explain it
properly above it?

My comment is likely wrong because I don't know what the Xen HV hides or
doesn't but you get the idea...

diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c
index d5ef64ddd35e..a8f1a02f9bc2 100644
--- a/arch/x86/mm/pat/memtype.c
+++ b/arch/x86/mm/pat/memtype.c
@@ -92,6 +92,13 @@ early_param("nopat", nopat);

bool pat_enabled(void)
{
+ /*
+ * Xen PV doesn't expose the PAT MSR to dom0 so the proper init path
+ * there cannot be exercised. Announce PAT is enabled in that case too.
+ */
+ if (cpu_feature_enabled(X86_FEATURE_XENPV) && !pat_disabled)
+ return true;
+
return pat_bp_enabled;
}
EXPORT_SYMBOL_GPL(pat_enabled);

--
Regards/Gruss,
Boris.

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