From patchwork Mon Sep 4 08:14:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9936807 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 39FAE601EB for ; Mon, 4 Sep 2017 08:17:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B7B62877D for ; Mon, 4 Sep 2017 08:17:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2001028770; Mon, 4 Sep 2017 08:17:51 +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 51A8B28791 for ; Mon, 4 Sep 2017 08:17:47 +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 1domXJ-0006lA-QZ; Mon, 04 Sep 2017 08:15:13 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1domXI-0006k7-Hk for xen-devel@lists.xen.org; Mon, 04 Sep 2017 08:15:12 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id FD/13-03423-F8B0DA95; Mon, 04 Sep 2017 08:15:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeJIrShJLcpLzFFi42JxWrrBXrefe22 kwa954hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8avY9/ZCk5IVvS+W8nYwHhdpIuRk0NCwF/i y77/7CA2m4CexMbZr5hAbBEBWYnVXXPA4swCn5gkGo45gtjCApYS559NAYpzcLAIqEj8fGIOE uYVsJVYMHMNK8RIeYldbRfBbE4BO4mzq98wgthCQDU9iw8zQ9iqEq9f7GKB6BWUODnzCQvEKg mJgy9eME9g5J2FJDULSWoBI9MqRo3i1KKy1CJdY2O9pKLM9IyS3MTMHF1DAzO93NTi4sT01Jz EpGK95PzcTYzA0GEAgh2MO9cHHmKU5GBSEuW9/3hNpBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ 3uOcayOFBItS01Mr0jJzgEEMk5bg4FES4dUGSfMWFyTmFmemQ6ROMSpKifMeBUkIgCQySvPg2 mCRc4lRVkqYlxHoECGegtSi3MwSVPlXjOIcjErCvExcQFN4MvNK4Ka/AlrMBLS46uUakMUliQ gpqQZG7+1BpxdPMQl+qP1WVlknzbaJpyf421mB+L9fczn3Stwz0hdpK8gsL3smKJUn1NcdZ6p 0S7rQU+FP2tnLHxf+ZXc63/H52Odlas2e+ixqC1Y8unGs0mF15qfdV3nY4rbP7M/z+FakrbMq 7feLE+keojwfv8n9yTq/soTLNbvt2NySO1dV9fiUWIozEg21mIuKEwGtgZ7blwIAAA== X-Env-Sender: prvs=413848043=sergey.dyasli@citrix.com X-Msg-Ref: server-3.tower-21.messagelabs.com!1504512908!77498317!3 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 41665 invoked from network); 4 Sep 2017 08:15:11 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-3.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 4 Sep 2017 08:15:11 -0000 X-IronPort-AV: E=Sophos;i="5.41,473,1498521600"; d="scan'208";a="446424743" From: Sergey Dyasli To: Date: Mon, 4 Sep 2017 09:14:40 +0100 Message-ID: <20170904081452.12960-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170904081452.12960-1-sergey.dyasli@citrix.com> References: <20170904081452.12960-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Sergey Dyasli , Kevin Tian , Jun Nakajima , George Dunlap , Andrew Cooper , Tim Deegan , Jan Beulich , Boris Ostrovsky , Suravee Suthikulpanit Subject: [Xen-devel] [PATCH v1 02/14] x86/np2m: add np2m_flush_base() 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 The new function finds all np2m objects with the specified np2m_base and flushes them. 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 Reviewed-by: George Dunlap --- RFC --> v1: - p2m_unlock(p2m) is moved from p2m_flush_table_locked() to p2m_flush_table() for balanced lock/unlock - np2m_flush_eptp() is renamed to np2m_flush_base() xen/arch/x86/mm/p2m.c | 35 +++++++++++++++++++++++++++++------ xen/include/asm-x86/p2m.h | 2 ++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index b8c8bba421..94a42400ad 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1708,15 +1708,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 @@ -1729,10 +1728,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; @@ -1752,7 +1748,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); } @@ -1773,6 +1776,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 9086bb35dc..cfb00591cd 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);