[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with pat_enable() and commit 72cbc8f04fe2


  • To: Juergen Gross <jgross@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 10 Jan 2023 10:38:58 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cQeJ+AwqmXPde5CI4yD7WgZRUy/cEGl1FvE9Pxjw4uo=; b=Pb5kvVqbkdul5nXndrGV/glMMGxVlJLV1kxCJ8JeGneI6jiCUR9muX3qwug4nfFAKPVIgsOxkuYaS9/GAApaWcpNoGd+O2/vxq99QIgyV7RhnrR/jQE+UKD+8Ejjgi2FqWNW86te8ePn49lBSRhf7czh+oyv6jQFrtI2nrfcXCviyAwB47Mup8cKjv96z2JdlyXKlPE7b/Q2w7rsY8//lOmPi0CiQ7mZggaIQPuj7w7h2ugU1kxieHK7R49ZVSYyXoeqlGPDQnVh0YqEakyjgcbtIxRvbMeJgLLKfCh2VhoU9igl1XOtGpjllL7J9dCJMIiOIXgOAiQ1GFD3sW+LEA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L5ot5e+fyTFJl10hHH2zNFBcd+L6Tp8bmnCN/NLItreBH1uf6vR78S9YUJHnxTp6f777fP3qXPIpb/zEd/QNsKlD1msvfVBLES2fE51BiQgzwTlg/KFf5Q3YxljM6TU81khylg3s4BDERJ24IGbkxRQJoIZFAPmaFBgQbJUeIHG8E5SGjt3kNXj6tmC6hOKWHY4eMYCBxGYkp2HAHhpPiEu5QOHw5DkUkfgkd09q7cWMek4APWYvbjj4NNwq+CjiYC65tJE8XgYrl9Cl9Qh+9siHmRPlbfMvV7uudwcaYluc939DTmQxzYF+Hzx9HH0STsgKTi7or0V5oSkm67TYbg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Michael Kelley (LINUX)" <mikelley@xxxxxxxxxxxxx>, Andrew Lutomirski <luto@xxxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>
  • Delivery-date: Tue, 10 Jan 2023 09:39:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 10.01.2023 06:59, Juergen Gross wrote:
> On 10.01.23 06:47, Juergen Gross wrote:
>> 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 agree.

> Another idea would be to let the mtrr_type_lookup() stub in
> arch/x86/include/asm/mtrr.h return MTRR_TYPE_WRBACK, enabling to simplify
> pud_set_huge() and pmd_set_huge() by removing the check for MTRR_TYPE_INVALID.

But that has a risk of ending up misleading: When there are no MTRRs, there
simply is no default type (in the absence of inspecting other criteria).

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.