From patchwork Tue Oct 3 15:20:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9983053 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 A7AD5602B8 for ; Tue, 3 Oct 2017 15:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 998F0289AC for ; Tue, 3 Oct 2017 15:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E4A4289C1; Tue, 3 Oct 2017 15:23:42 +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 86939289AC for ; Tue, 3 Oct 2017 15:23:41 +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 1dzP0W-0002vr-7B; Tue, 03 Oct 2017 15:21:16 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzP0U-0002uz-Vi for xen-devel@lists.xen.org; Tue, 03 Oct 2017 15:21:15 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 08/2C-01916-AEAA3D95; Tue, 03 Oct 2017 15:21:14 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprEIsWRWlGSWpSXmKPExsXitHRDpO7LVZc jDSbdVbdY8nExiwOjx9Hdv5kCGKNYM/OS8isSWDNWdm5iKrglX3F4TxNLA+NWyS5GTg4JAX+J z482soLYbAJ6Ehtnv2ICsUUEZCVWd81h72Lk4mAWmMssMXNDL1iRsICnxPq79xhBbBYBFYnmU 6fZQWxeARuJFaeesEMMlZfY1XYRrJ5TwFZiyrH5LCC2EFDN9y97GCFsVYnXL3axQPQKSpyc+Q TMZhaQkDj44gXzBEbeWUhSs5CkFjAyrWLUKE4tKkst0jU010sqykzPKMlNzMzRNTQw1stNLS5 OTE/NSUwq1kvOz93ECAwfBiDYwfjytOchRkkOJiVR3tfLLkcK8SXlp1RmJBZnxBeV5qQWH2KU 4eBQkuD1XQmUEyxKTU+tSMvMAQYyTFqCg0dJhNdyBVCat7ggMbc4Mx0idYpRl6Pj5t0/TEIse fl5qVLivEUgMwRAijJK8+BGwKLqEqOslDAvI9BRQjwFqUW5mSWo8q8YxTkYlYR5S0Gm8GTmlc BtegV0BBPQEXO6LoAcUZKIkJJqYKyWLVtmIa90dUGd9NzuFC/lvt+LWizdWGwWhralLPHgOMp aOul1pJbk1p6CkIqoOo9pVw9mm6yY9q9lrVRJrv7jrwolzLN7e1brVJslbWC56sRctfhewf73 eWu++7d/V+P5z6lXyRHlveGh1hvBfZ27NDdWm1iZWGi66bi0tBj8CM3LS85XYinOSDTUYi4qT gQASTt6/6UCAAA= X-Env-Sender: prvs=4422f64de=sergey.dyasli@citrix.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1507044071!79182981!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37649 invoked from network); 3 Oct 2017 15:21:13 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 3 Oct 2017 15:21:13 -0000 X-IronPort-AV: E=Sophos;i="5.42,474,1500940800"; d="scan'208";a="442358098" From: Sergey Dyasli To: Date: Tue, 3 Oct 2017 16:20:57 +0100 Message-ID: <20171003152104.1432-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171003152104.1432-1-sergey.dyasli@citrix.com> References: <20171003152104.1432-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Sergey Dyasli , Kevin Tian , Jun Nakajima , George Dunlap , Andrew Cooper , Tim Deegan , George Dunlap , Jan Beulich , Boris Ostrovsky , Suravee Suthikulpanit Subject: [Xen-devel] [PATCH v3 2/9] x86/np2m: flush all np2m objects on nested INVEPT 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 At the moment, nvmx_handle_invept() updates the current np2m just to flush it. Instead introduce a function, np2m_flush_base(), which will look up the np2m base pointer and call p2m_flush_table() instead. Unfortunately, since we don't know which p2m a given vcpu is using, we must flush all p2ms that share that 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 --- v2 --> v3: - Commit message update --- 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 338317a782..ce50e37f46 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -772,6 +772,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);