From patchwork Tue Aug 2 13:55:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9257525 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 14E5460754 for ; Tue, 2 Aug 2016 13:57:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 041DE205AF for ; Tue, 2 Aug 2016 13:57:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9817284F4; Tue, 2 Aug 2016 13:57:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 721BF205AF for ; Tue, 2 Aug 2016 13:57:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUaAL-0000Fc-85; Tue, 02 Aug 2016 13:55:29 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUaAK-0000FU-Kd for xen-devel@lists.xenproject.org; Tue, 02 Aug 2016 13:55:28 +0000 Received: from [85.158.139.211] by server-13.bemta-5.messagelabs.com id 77/13-12874-F46A0A75; Tue, 02 Aug 2016 13:55:27 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42JxWrrBXtd32YJ wg48T9S2+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozGS03sBT3iFdOetrA0MN4V7GLk5JAQ8Jf4 8+w/K4jNJqAjcXHuTrYuRg4OEQEVidt7DUBMZoFyiRk34kEqhAUCJV5seM4IYrMAVbQcvg5m8 wq4SHzbdJUFYqKuxMNzv1kh4oISJ2c+AYszC2hKtG7/zQ5hy0s0b53NDGILCShK9M97wAbRyy 1x+/RU5gmMvLOQtM9C0j4LSfsCRuZVjBrFqUVlqUW6hgZ6SUWZ6RkluYmZOUCeqV5uanFxYnp qTmJSsV5yfu4mRmBAMQDBDsY1U50PMUpyMCmJ8rp8mR8uxJeUn1KZkVicEV9UmpNafIhRhoND SYL3/ZIF4UKCRanpqRVpmTnA0IZJS3DwKInw/gJJ8xYXJOYWZ6ZDpE4xKkqJ8x4ESQiAJDJK8 +DaYPF0iVFWSpiXEegQIZ6C1KLczBJU+VeM4hyMSsK890Cm8GTmlcBNfwW0mAlo8QkDsMUliQ gpqQZGr8Ljha3iJsnNtx7nT1/9Z6OaYoBApM0/BVmzV8s0F01b9DP5w9W32XMXa4XqL9Tdemj t/C1a4ebTE7Z316Ser/uXrHqp46V0WtHhvRXux3rOzmg6e3H24z3z3/jP/L3c79isA9+qD0nM 5fiYte5+ZUlz24n9C7gOyDNetUycV1zOuKv/ecKDUCWW4oxEQy3mouJEAKoRd8CiAgAA X-Env-Sender: prvs=015484912=roger.pau@citrix.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1470146124!52642417!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23948 invoked from network); 2 Aug 2016 13:55:25 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-9.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 2 Aug 2016 13:55:25 -0000 X-IronPort-AV: E=Sophos;i="5.28,460,1464652800"; d="scan'208";a="376901306" From: Roger Pau Monne To: Date: Tue, 2 Aug 2016 15:55:19 +0200 Message-ID: <1470146119-18187-1-git-send-email-roger.pau@citrix.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper , Jan Beulich , Roger Pau Monne Subject: [Xen-devel] [PATCH v2] x86/hap: use the right cache attributes when MTRR is disabled X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently the code that calculates the cache attributes of the HAP page tables assume that if MTRR are disabled the memory type is UC, this can cause issues if MTRR are never enabled because the guest only plans to use PAT. In order to solve this modify epte_get_entry_emt so that is takes into account that MTRR can be disabled and that PAT should be used instead, this also implies that when page tables are enabled inside the guest a recalculation of the HAP page table cache attributes must be performed. The special casing that was previously done for PVHv1 guests can now be removed, since PVHv1 guest cannot have MTRR enabled or paging disabled, so the memory type is always going to be MTRR_TYPE_WRBACK in that case. Signed-off-by: Roger Pau Monné --- Cc: Jan Beulich Cc: Andrew Cooper --- Changes since v1: - Fix comments. - Slightly change the if ... else logic. - Correctly check if MTRR are enabled. - Expand description. --- xen/arch/x86/hvm/hvm.c | 4 ++++ xen/arch/x86/hvm/mtrr.c | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index daaee1d..db4b2d6 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2283,7 +2283,11 @@ int hvm_set_cr0(unsigned long value, bool_t may_defer) if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) ) paging_update_nestedmode(v); else + { paging_update_paging_modes(v); + /* Force an update of the memory cache attributes. */ + memory_type_changed(d); + } } return X86EMUL_OKAY; diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c index f7831ff..bf3ab72 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -814,10 +814,19 @@ int epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t mfn, if ( gmtrr_mtype == -EADDRNOTAVAIL ) return -1; - gmtrr_mtype = is_hvm_domain(d) && v ? - get_mtrr_type(&v->arch.hvm_vcpu.mtrr, - gfn << PAGE_SHIFT, order) : - MTRR_TYPE_WRBACK; + if ( !v ) + gmtrr_mtype = MTRR_TYPE_WRBACK; + else if ( v->arch.hvm_vcpu.mtrr.enabled & 0x2 ) + /* MTRR is enabled, use MTRR. */ + gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, gfn << PAGE_SHIFT, + order); + else if ( !hvm_paging_enabled(v) ) + /* MTRR is not enabled and paging is disabled, force UC. */ + gmtrr_mtype = MTRR_TYPE_UNCACHABLE; + else + /* MTRR is not enabled and paging is enabled, use PAT. */ + gmtrr_mtype = MTRR_TYPE_WRBACK; + hmtrr_mtype = get_mtrr_type(&mtrr_state, mfn_x(mfn) << PAGE_SHIFT, order); if ( gmtrr_mtype < 0 || hmtrr_mtype < 0 ) return -1;