From patchwork Tue Jul 26 16:15:37 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: 9248393 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 5DBA6607D8 for ; Tue, 26 Jul 2016 16:18:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EAFF1FF10 for ; Tue, 26 Jul 2016 16:18:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4335626B41; Tue, 26 Jul 2016 16:18:44 +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 BC0651FF10 for ; Tue, 26 Jul 2016 16:18:43 +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 1bS51F-00029A-12; Tue, 26 Jul 2016 16:15:45 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bS51E-000292-Ac for xen-devel@lists.xenproject.org; Tue, 26 Jul 2016 16:15:44 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 5D/DB-30284-FAC87975; Tue, 26 Jul 2016 16:15:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42JxWrrBXnd9z/R wg/3d3Bbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0Z7d37BU+GKw6cnMDYwdvN3MXJySAj4S+x6 c4oNxGYT0JG4OHcnkM3BISKgInF7rwGIySxQLjHjRjxIhbCAn8S9nmtMIDaLgKrEm6+7wGxeA ReJ9/MOskFM1JV4eO43K0RcUOLkzCcsIDazgKZE6/bf7BC2vETz1tnMILaQgKJE/7wHUL3cEr dPT2WewMg7C0n7LCTts5C0L2BkXsWoUZxaVJZapGtkqJdUlJmeUZKbmJmja2hgqpebWlycmJ6 ak5hUrJecn7uJERhO9QwMjDsY7072O8QoycGkJMrLNGFauBBfUn5KZUZicUZ8UWlOavEhRhkO DiUJXtfu6eFCgkWp6akVaZk5wMCGSUtw8CiJ8F4ASfMWFyTmFmemQ6ROMSpKifPKgyQEQBIZp XlwbbBousQoKyXMy8jAwCDEU5BalJtZgir/ilGcg1FJmDcAZApPZl4J3PRXQIuZgBYv4JkMsr gkESEl1cAYFNLz7uKGfw+kZ/74KN9411bdkVt4yQ2FV8ITS4XOmXQ4zL48T6akzSyL2U5r5WG ZdbeNDllWLou3uLNvv0FN9kyzfVb5UVsPfjZ+k2lXfe7/J8WU53XaX7bIpE+z1mV7ltF56Nej ouc+Bcrfr+ZVHz798a++4cM9hyd53i2PYH8xU8ZEwXSVEktxRqKhFnNRcSIAJEdw/KECAAA= X-Env-Sender: prvs=008a5108a=roger.pau@citrix.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1469549741!39412549!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 39781 invoked from network); 26 Jul 2016 16:15:42 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-15.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 26 Jul 2016 16:15:42 -0000 X-IronPort-AV: E=Sophos;i="5.28,425,1464652800"; d="scan'208";a="375516161" From: Roger Pau Monne To: Date: Tue, 26 Jul 2016 18:15:37 +0200 Message-ID: <1469549737-19668-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] 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. Signed-off-by: Roger Pau Monné --- Cc: Jan Beulich Cc: Andrew Cooper --- xen/arch/x86/hvm/hvm.c | 4 ++++ xen/arch/x86/hvm/mtrr.c | 15 +++++++++++---- 2 files changed, 15 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..778e85a 100644 --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -814,10 +814,17 @@ 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 && v->arch.hvm_vcpu.mtrr.enabled ) + /* MTRR is enabled, use MTRR */ + gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, gfn << PAGE_SHIFT, + order); + else if ( v && !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;