From patchwork Mon Sep 4 08:14:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9936819 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 46001603F9 for ; Mon, 4 Sep 2017 08:18:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37CA328777 for ; Mon, 4 Sep 2017 08:18:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C64F28781; Mon, 4 Sep 2017 08:18:36 +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 CD35428779 for ; Mon, 4 Sep 2017 08:18:35 +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 1domYb-0007TD-Rf; Mon, 04 Sep 2017 08:16:33 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1domYa-0007Si-Jx for xen-devel@lists.xen.org; Mon, 04 Sep 2017 08:16:32 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 80/6D-03454-0EB0DA95; Mon, 04 Sep 2017 08:16:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXvc+99p Ig/2/FC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ox10x6zFVwQrli2o5+5gXEDfxcjJ4eEgL/E sZONbCA2m4CexMbZr5hAbBEBWYnVXXPYQWxmgU9MEg3HHEFsYQFfif1d21hAbBYBFYlDj+ayg ti8AnYSS7bOYIGYKS+xq+0iWJwTKH529RtGEFtIwFaiZ/FhZghbVeL1i10sEL2CEidnPmGB2C UhcfDFC+YJjLyzkKRmIUktYGRaxahRnFpUllqka2yol1SUmZ5RkpuYmaNraGCml5taXJyYnpq TmFSsl5yfu4kRGDwMQLCDsWlR4CFGSQ4mJVHe+4/XRArxJeWnVGYkFmfEF5XmpBYfYpTh4FCS 4D3ItTZSSLAoNT21Ii0zBxjGMGkJDh4lEV5+YCgL8RYXJOYWZ6ZDpE4xKkqJ894H6RMASWSU5 sG1wWLnEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5t4FM4cnMK4Gb/gpoMRPQ4qqXa0AWly QipKQaGKfMWMpa9nFFS4SY9+LbEtwWjlPazu9K737r+PfUI9GZWiuKo3IK6ncl9vE5HFkoorN /e0WP7xLNxl1ZUpzxnW++nVj8viTvTEVVvU4kt0UL/wT7sIsf1+qrnEhttq66LfDQU0TzzDPB q3y9vyM/LE3ZatM05UK83p2SVGsNv2qWrZyfRWaGKrEUZyQaajEXFScCALnuttGYAgAA X-Env-Sender: prvs=413848043=sergey.dyasli@citrix.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1504512990!83049964!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 31702 invoked from network); 4 Sep 2017 08:16:31 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 4 Sep 2017 08:16:31 -0000 X-IronPort-AV: E=Sophos;i="5.41,473,1498521600"; d="scan'208";a="446424856" From: Sergey Dyasli To: Date: Mon, 4 Sep 2017 09:14:48 +0100 Message-ID: <20170904081452.12960-11-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 10/14] x86/np2m: improve nestedhvm_hap_nested_page_fault() 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 There is a possibility for nested_p2m to became stale between nestedhvm_hap_nested_page_fault() and nestedhap_fix_p2m(). Simply use p2m_get_nestedp2m_lock() to guarantee that correct np2m is used. Signed-off-by: Sergey Dyasli --- xen/arch/x86/mm/hap/nested_hap.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/mm/hap/nested_hap.c b/xen/arch/x86/mm/hap/nested_hap.c index ed137fa784..96afe632b5 100644 --- a/xen/arch/x86/mm/hap/nested_hap.c +++ b/xen/arch/x86/mm/hap/nested_hap.c @@ -101,28 +101,21 @@ nestedhap_fix_p2m(struct vcpu *v, struct p2m_domain *p2m, unsigned int page_order, p2m_type_t p2mt, p2m_access_t p2ma) { int rc = 0; + unsigned long gfn, mask; + mfn_t mfn; + ASSERT(p2m); ASSERT(p2m->set_entry); + ASSERT(p2m_locked_by_me(p2m)); - p2m_lock(p2m); - - /* If this p2m table has been flushed or recycled under our feet, - * leave it alone. We'll pick up the right one as we try to - * vmenter the guest. */ - if ( p2m->np2m_base == nhvm_vcpu_p2m_base(v) ) - { - unsigned long gfn, mask; - mfn_t mfn; - - /* If this is a superpage mapping, round down both addresses - * to the start of the superpage. */ - mask = ~((1UL << page_order) - 1); + /* If this is a superpage mapping, round down both addresses + * to the start of the superpage. */ + mask = ~((1UL << page_order) - 1); - gfn = (L2_gpa >> PAGE_SHIFT) & mask; - mfn = _mfn((L0_gpa >> PAGE_SHIFT) & mask); + gfn = (L2_gpa >> PAGE_SHIFT) & mask; + mfn = _mfn((L0_gpa >> PAGE_SHIFT) & mask); - rc = p2m_set_entry(p2m, gfn, mfn, page_order, p2mt, p2ma); - } + rc = p2m_set_entry(p2m, gfn, mfn, page_order, p2mt, p2ma); p2m_unlock(p2m); @@ -212,7 +205,6 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t *L2_gpa, uint8_t p2ma_21 = p2m_access_rwx; p2m = p2m_get_hostp2m(d); /* L0 p2m */ - nested_p2m = p2m_get_nestedp2m(v); /* walk the L1 P2M table */ rv = nestedhap_walk_L1_p2m(v, *L2_gpa, &L1_gpa, &page_order_21, &p2ma_21, @@ -278,6 +270,7 @@ nestedhvm_hap_nested_page_fault(struct vcpu *v, paddr_t *L2_gpa, p2ma_10 &= (p2m_access_t)p2ma_21; /* fix p2m_get_pagetable(nested_p2m) */ + nested_p2m = p2m_get_nestedp2m_locked(v); nestedhap_fix_p2m(v, nested_p2m, *L2_gpa, L0_gpa, page_order_20, p2mt_10, p2ma_10);