From patchwork Fri Sep 29 15:01:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 9978257 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 7A5F160311 for ; Fri, 29 Sep 2017 15:04:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CF9E2766D for ; Fri, 29 Sep 2017 15:04:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61E9C28448; Fri, 29 Sep 2017 15:04:17 +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 F0BE32766D for ; Fri, 29 Sep 2017 15:04:16 +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 1dxwnp-0003dq-6F; Fri, 29 Sep 2017 15:02:09 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dxwno-0003dX-Dl for xen-devel@lists.xenproject.org; Fri, 29 Sep 2017 15:02:08 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 16/C0-03283-F606EC95; Fri, 29 Sep 2017 15:02:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRWlGSWpSXmKPExsXitHSDvW5+wrl Ig9lvOCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ownC26zF7QoVeyYcJ+pgXGndBcjJ4eEgL9E 861mJhCbTUBPYt7xryxdjBwcIgIqErf3GnQxcnEwC7xnlOh5cJcFpEZYIEai5fsBVpAaFgFVi UnLqkHCvAI2EqdWn2aCGCkvce7BbWYQm1PAVmJTfzeYLQRU8+zaXXYIW1Vi8YOj7BC9ghInZz 4BG88sICFx8MUL5gmMvLOQpGYhSS1gZFrFqFGcWlSWWqRraKCXVJSZnlGSm5iZA+SZ6eWmFhc npqfmJCYV6yXn525iBIYOAxDsYDz+Pu4QoyQHk5Ior0DsuUghvqT8lMqMxOKM+KLSnNTiQ4wy HBxKErwb44FygkWp6akVaZk5wCCGSUtw8CiJ8O4BSfMWFyTmFmemQ6ROMepydNy8+4dJiCUvP y9VSpy3B6RIAKQoozQPbgQsoi4xykoJ8zICHSXEU5BalJtZgir/ilGcg1FJmNcfZApPZl4J3K ZXQEcwAR0xeeIZkCNKEhFSUg2MYW8evRCQ4Jmavy1EfsZSF03HYpY7u89ZWZ7Zv6no/bzNu/W +S/0xZZwZ/jlV6qjD5tqmtw8Lz/MnV5gme+h9z+24vTr97q39L1MyzJQNm7OnzZnVtnv/p4qy Wf8bPU7nCi+8+kzewyNso3PNcv2ynC0KAS0cb7qXlW3NnLT+5B6eJdzNE0Q8lViKMxINtZiLi hMB1fc7QaMCAAA= X-Env-Sender: prvs=438a79e6a=George.Dunlap@citrix.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1506697324!79105423!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: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61323 invoked from network); 29 Sep 2017 15:02:06 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-4.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 29 Sep 2017 15:02:06 -0000 X-IronPort-AV: E=Sophos;i="5.42,452,1500940800"; d="scan'208";a="449785851" From: George Dunlap To: Date: Fri, 29 Sep 2017 16:01:37 +0100 Message-ID: <20170929150144.7602-2-george.dunlap@citrix.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170929150144.7602-1-george.dunlap@citrix.com> References: <20170929150144.7602-1-george.dunlap@citrix.com> MIME-Version: 1.0 Cc: Sergey Dyasli , Kevin Tian , Jan Beulich , Andrew Cooper , George Dunlap , Jun Nakajima Subject: [Xen-devel] [PATCH 2/9] x86/np2m: Have invept flush all np2m entries with the same base pointer 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 nvmx_handle_invept() updates current's np2m just to flush it. This is not only wasteful, but ineffective: if several L2 vcpus share the same np2m base pointer, they all need to be flushed (not only the current one). Introduce a new function, np2m_flush_base() which will flush all shadow p2m's that match a given base pointer. Convert p2m_flush_table() into p2m_flush_table_locked() in order not to release the p2m_lock after np2m_base check. Signed-off-by: Sergey Dyasli Signed-off-by: George Dunlap Signed-off-by: Sergey Dyasli Signed-off-by: George Dunlap --- Changes since v1: - Combine patches 2 and 3 ("x86/np2m: add np2m_flush_base()" and "x86/vvmx: use np2m_flush_base() for INVEPT_SINGLE_CONTEXT") - Reword commit text CC: Andrew Cooper CC: Jan Beulich CC: Jun Nakajima CC: Kevin Tian --- xen/arch/x86/hvm/vmx/vvmx.c | 7 +------ xen/arch/x86/mm/p2m.c | 35 +++++++++++++++++++++++++++++------ xen/include/asm-x86/p2m.h | 2 ++ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c index cd0ee0a307..d333aa6d78 100644 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -1910,12 +1910,7 @@ int nvmx_handle_invept(struct cpu_user_regs *regs) { case INVEPT_SINGLE_CONTEXT: { - struct p2m_domain *p2m = p2m_get_nestedp2m(current, eptp); - if ( p2m ) - { - p2m_flush(current, p2m); - ept_sync_domain(p2m); - } + np2m_flush_base(current, eptp); break; } case INVEPT_ALL_CONTEXT: diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 27b90eb815..b7588b2ec1 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1711,15 +1711,14 @@ p2m_getlru_nestedp2m(struct domain *d, struct p2m_domain *p2m) return p2m; } -/* Reset this p2m table to be empty */ static void -p2m_flush_table(struct p2m_domain *p2m) +p2m_flush_table_locked(struct p2m_domain *p2m) { struct page_info *top, *pg; struct domain *d = p2m->domain; mfn_t mfn; - p2m_lock(p2m); + ASSERT(p2m_locked_by_me(p2m)); /* * "Host" p2m tables can have shared entries &c that need a bit more care @@ -1732,10 +1731,7 @@ p2m_flush_table(struct p2m_domain *p2m) /* No need to flush if it's already empty */ if ( p2m_is_nestedp2m(p2m) && p2m->np2m_base == P2M_BASE_EADDR ) - { - p2m_unlock(p2m); return; - } /* This is no longer a valid nested p2m for any address space */ p2m->np2m_base = P2M_BASE_EADDR; @@ -1755,7 +1751,14 @@ p2m_flush_table(struct p2m_domain *p2m) d->arch.paging.free_page(d, pg); } page_list_add(top, &p2m->pages); +} +/* Reset this p2m table to be empty */ +static void +p2m_flush_table(struct p2m_domain *p2m) +{ + p2m_lock(p2m); + p2m_flush_table_locked(p2m); p2m_unlock(p2m); } @@ -1776,6 +1779,26 @@ p2m_flush_nestedp2m(struct domain *d) p2m_flush_table(d->arch.nested_p2m[i]); } +void np2m_flush_base(struct vcpu *v, unsigned long np2m_base) +{ + struct domain *d = v->domain; + struct p2m_domain *p2m; + unsigned int i; + + np2m_base &= ~(0xfffull); + + nestedp2m_lock(d); + for ( i = 0; i < MAX_NESTEDP2M; i++ ) + { + p2m = d->arch.nested_p2m[i]; + p2m_lock(p2m); + if ( p2m->np2m_base == np2m_base ) + p2m_flush_table_locked(p2m); + p2m_unlock(p2m); + } + nestedp2m_unlock(d); +} + static void assign_np2m(struct vcpu *v, struct p2m_domain *p2m) { struct nestedvcpu *nv = &vcpu_nestedhvm(v); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 78f51a6ce6..5501ccc455 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -779,6 +779,8 @@ int p2m_pt_handle_deferred_changes(uint64_t gpa); void p2m_flush(struct vcpu *v, struct p2m_domain *p2m); /* Flushes all nested p2m tables */ void p2m_flush_nestedp2m(struct domain *d); +/* Flushes all np2m objects with the specified np2m_base */ +void np2m_flush_base(struct vcpu *v, unsigned long np2m_base); void nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, l1_pgentry_t *p, l1_pgentry_t new, unsigned int level);