From: Borislav Petkov <bp@alien8.de>
To: Juergen Gross <jgross@suse.com>, Tom Lendacky <thomas.lendacky@amd.com>
Cc: xen-devel@lists.xenproject.org, x86@kernel.org,
linux-kernel@vger.kernel.org,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH v2] x86/pat: fix x86_has_pat_wp()
Date: Mon, 20 Jun 2022 15:22:08 +0200 [thread overview]
Message-ID: <YrB0gNtIfCwV+xnE@zn.tnic> (raw)
In-Reply-To: <20220620113441.23961-1-jgross@suse.com>
+ Tom.
On Mon, Jun 20, 2022 at 01:34:41PM +0200, Juergen Gross wrote:
> x86_has_pat_wp() is using a wrong test, as it relies on the normal
> PAT configuration used by the kernel. In case the PAT MSR has been
> setup by another entity (e.g. BIOS or Xen hypervisor) it might return
> false even if the PAT configuration is allowing WP mappings.
... because Xen doesn't allow writing the PAT MSR. Please explain
exactly what happens because we will forget.
> The correct way to test for WP support is:
>
> 1. Get the PTE protection bits needed to select WP mode by reading
> __cachemode2pte_tbl[_PAGE_CACHE_MODE_WP] (depending on the PAT MSR
> setting this might return protection bits for a stronger mode, e.g.
> UC-)
> 2. Translate those bits back into the real cache mode selected by those
> PTE bits by reading __pte2cachemode_tbl[__pte2cm_idx(prot)]
> 3. Test for the cache mode to be _PAGE_CACHE_MODE_WP
Yes, this is a good explanation albeit a bit too verbose. You can stick
a shorter version of it as a comment over the function so that we don't
have to swap it all back in next time.
> Fixes: 1f6f655e01ad ("x86/mm: Add a x86_has_pat_wp() helper")
If anything, this should be:
f88a68facd9a ("x86/mm: Extend early_memremap() support with additional attrs")
Also, I'm thinking CC:stable here.
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
> V2:
> - fix indexing into __pte2cachemode_tbl[]
Yes, in any case, I see it now. The key aspect being in the comment
above it:
* Index into __pte2cachemode_tbl[] are the caching attribute bits of the pte
* (_PAGE_PWT, _PAGE_PCD, _PAGE_PAT) at index bit positions 0, 1, 2.
which is how one should index into that array.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
prev parent reply other threads:[~2022-06-20 14:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-20 11:34 Juergen Gross
2022-06-20 13:22 ` Borislav Petkov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YrB0gNtIfCwV+xnE@zn.tnic \
--to=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®