mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: "Michael Kelley (LINUX)" <mikelley@microsoft.com>,
	Andrew Lutomirski <luto@kernel.org>,
	Jan Beulich <jbeulich@suse.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: Problem with pat_enable() and commit 72cbc8f04fe2
Date: Tue, 10 Jan 2023 06:47:57 +0100	[thread overview]
Message-ID: <03edcbc5-2dd7-1ddb-bafe-8412d8fc95aa@suse.com> (raw)
In-Reply-To: <BYAPR21MB16883ABC186566BD4D2A1451D7FE9@BYAPR21MB1688.namprd21.prod.outlook.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 1904 bytes --]

On 09.01.23 19:28, Michael Kelley (LINUX) wrote:
> I've come across a case with a VM running on Hyper-V that doesn't get
> MTRRs, but the PAT is functional.  (This is a Confidential VM using
> AMD's SEV-SNP encryption technology with the vTOM option.)  In this
> case, the changes in commit 72cbc8f04fe2 ("x86/PAT: Have pat_enabled()
> properly reflect state when running on Xen") apply.   pat_enabled() returns
> "true", but the MTRRs are not enabled.
> 
> But with this commit, there's a problem.  Consider memremap() on a RAM
> region, called with MEMREMAP_WB plus MEMREMAP_DEC as the 3rd
> argument. Because of the request for a decrypted mapping,
> arch_memremap_can_ram_remap() returns false, and a new mapping
> must be created, which is appropriate.
> 
> The following call stack results:
> 
>    memremap()
>    arch_memremap_wb()
>    ioremap_cache()
>    __ioremap_caller()
>    memtype_reserve()  <--- pcm is _PAGE_CACHE_MODE_WB
>    pat_x_mtrr_type()  <-- only called after commit 72cbc8f04fe2
> 
> pat_x_mtrr_type() returns _PAGE_CACHE_MODE_UC_MINUS because
> mtrr_type_lookup() fails.  As a result, memremap() erroneously creates the
> new mapping as uncached.   This uncached mapping is causing a significant
> performance problem in certain Hyper-V Confidential VM configurations.
> 
> Any thoughts on resolving this?  Should memtype_reserve() be checking
> both pat_enabled() *and* whether MTRRs are enabled before calling
> pat_x_mtrr_type()?  Or does that defeat the purpose of commit
> 72cbc8f04fe2 in the Xen environment?

I think pat_x_mtrr_type() should return _PAGE_CACHE_MODE_UC_MINUS only if
mtrr_type_lookup() is not failing and is returning a mode other than WB.

I'll send a patch.

> I'm also looking at how to avoid this combination in a Hyper-V Confidential
> VM, but that doesn't address underlying the flaw.

Yes.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

  reply	other threads:[~2023-01-10  5:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09 18:28 Michael Kelley (LINUX)
2023-01-10  5:47 ` Juergen Gross [this message]
2023-01-10  5:59   ` Juergen Gross
2023-01-10  9:38     ` Jan Beulich
2023-01-10 10:01       ` Juergen Gross

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=03edcbc5-2dd7-1ddb-bafe-8412d8fc95aa@suse.com \
    --to=jgross@suse.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jbeulich@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=peterz@infradead.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®