From patchwork Thu Oct 12 10:00:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10001437 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 AB3CD60325 for ; Thu, 12 Oct 2017 10:02:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C10628D4F for ; Thu, 12 Oct 2017 10:02:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90EE028D5A; Thu, 12 Oct 2017 10:02:54 +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 14A7028D4F for ; Thu, 12 Oct 2017 10:02:54 +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 1e2aIO-0001et-1I; Thu, 12 Oct 2017 10:00:52 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2aIN-0001ej-Cj for xen-devel@lists.xenproject.org; Thu, 12 Oct 2017 10:00:51 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id 12/18-02748-25D3FD95; Thu, 12 Oct 2017 10:00:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRWlGSWpSXmKPExsXS6fjDSzfQ9n6 kwZxnFhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aDvm72gjWaFS8+PGNuYJwr0cXIySEkkCex rmknO4jNK2An8WfdeWYQW0LAUOL0wpssIDaLgKrEuebnjCA2m4C6RNuz7axdjBwcIgIGEueOJ oGEmQXCJb4/6mUDsYUFIiSOHbrBCjHeTuLJywtMIDangL1Ex9vZzCCtvAKCEn93CEO0akk8/H WLBcLWlli28DVYCbOAtMTyfxwTGPlmITTMQtIwC0nDLISGBYwsqxg1ilOLylKLdA2N9ZKKMtM zSnITM3N0DQ1M9XJTi4sT01NzEpOK9ZLzczcxAkOPAQh2MP7b5nmIUZKDSUmU99q9e5FCfEn5 KZUZicUZ8UWlOanFhxhlODiUJHi5be5HCgkWpaanVqRl5gCjACYtwcGjJMJ73BoozVtckJhbn JkOkTrFqMvRcfPuHyYhlrz8vFQpcV5NkBkCIEUZpXlwI2AReYlRVkqYlxHoKCGegtSi3MwSVP lXjOIcjErCvOEgU3gy80rgNr0COoIJ6AjRtDsgR5QkIqSkGhjVLFwmLK97cezGIYujXA9LjgV llkrW7hVtrumfaVi4/JnZBGGWnZkHLfd8FFWqZA+L/aDCk7pnycG+qDItsbuzvC4yL9trZKv2 xk6+vKU74amXwB7XWIMZBlxB77uj15yrd22oXFI29UiTh/WvmHVn4zLZlwpz7jC4KbNbT+Lyb 7k5lewxT5RYijMSDbWYi4oTAYXXKYLDAgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1507802448!90754479!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 62166 invoked from network); 12 Oct 2017 10:00:49 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-16.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 12 Oct 2017 10:00:49 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Thu, 12 Oct 2017 04:00:47 -0600 Message-Id: <59DF596E020000780018555D@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.2 Date: Thu, 12 Oct 2017 04:00:46 -0600 From: "Jan Beulich" To: "xen-devel" References: <59DF54320200007800185513@prv-mh.provo.novell.com> In-Reply-To: <59DF54320200007800185513@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Cc: Andrew Cooper , Julien Grall Subject: [Xen-devel] [PATCH 2/3] x86: fix do_update_va_mapping_otherdomain() wrt translated domains 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 While I can't seem to find any users of this hypercall (being a likely explanation of why the problem wasn't noticed so far), just like for do_mmu_update() paged-out and shared page handling is needed here. Move all this logic into mod_l1_entry(), which then also results in no longer - doing any of this handling for non-present PTEs, - acquiring two temporary page references when one is already more than enough. Signed-off-by: Jan Beulich --- Now that L1 entry handling in do_mmu_update() is sufficiently similar again to that of L2/L3/L4 entries, I wonder whether it wouldn't it be better for the function to refuse pg_owner != pt_owner for L2/L3/L4 updates. Right now the passed in foreign domain ID is simply ignored in that case (except for the XSM check). --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -1632,7 +1632,6 @@ static int mod_l1_entry(l1_pgentry_t *pl if ( l1e_get_flags(nl1e) & _PAGE_PRESENT ) { - /* Translate foreign guest addresses. */ struct page_info *page = NULL; if ( unlikely(l1e_get_flags(nl1e) & l1_disallow_mask(pt_dom)) ) @@ -1642,9 +1641,35 @@ static int mod_l1_entry(l1_pgentry_t *pl return -EINVAL; } + /* Translate foreign guest address. */ if ( paging_mode_translate(pg_dom) ) { - page = get_page_from_gfn(pg_dom, l1e_get_pfn(nl1e), NULL, P2M_ALLOC); + p2m_type_t p2mt; + p2m_query_t q = l1e_get_flags(nl1e) & _PAGE_RW ? + P2M_ALLOC | P2M_UNSHARE : P2M_ALLOC; + + page = get_page_from_gfn(pg_dom, l1e_get_pfn(nl1e), &p2mt, q); + + if ( p2m_is_paged(p2mt) ) + { + if ( page ) + put_page(page); + p2m_mem_paging_populate(pg_dom, l1e_get_pfn(nl1e)); + return -ENOENT; + } + + if ( p2mt == p2m_ram_paging_in && !page ) + return -ENOENT; + + /* Did our attempt to unshare fail? */ + if ( (q & P2M_UNSHARE) && p2m_is_shared(p2mt) ) + { + /* We could not have obtained a page ref. */ + ASSERT(!page); + /* And mem_sharing_notify has already been called. */ + return -ENOMEM; + } + if ( !page ) return -EINVAL; nl1e = l1e_from_page(page, l1e_get_flags(nl1e)); @@ -3315,47 +3340,10 @@ long do_mmu_update( switch ( page->u.inuse.type_info & PGT_type_mask ) { case PGT_l1_page_table: - { - l1_pgentry_t l1e = l1e_from_intpte(req.val); - p2m_type_t l1e_p2mt = p2m_ram_rw; - struct page_info *target = NULL; - p2m_query_t q = (l1e_get_flags(l1e) & _PAGE_RW) ? - P2M_UNSHARE : P2M_ALLOC; - - if ( paging_mode_translate(pg_owner) ) - target = get_page_from_gfn(pg_owner, l1e_get_pfn(l1e), - &l1e_p2mt, q); - - if ( p2m_is_paged(l1e_p2mt) ) - { - if ( target ) - put_page(target); - p2m_mem_paging_populate(pg_owner, l1e_get_pfn(l1e)); - rc = -ENOENT; - break; - } - else if ( p2m_ram_paging_in == l1e_p2mt && !target ) - { - rc = -ENOENT; - break; - } - /* If we tried to unshare and failed */ - else if ( (q & P2M_UNSHARE) && p2m_is_shared(l1e_p2mt) ) - { - /* We could not have obtained a page ref. */ - ASSERT(target == NULL); - /* And mem_sharing_notify has already been called. */ - rc = -ENOMEM; - break; - } - - rc = mod_l1_entry(va, l1e, mfn, + rc = mod_l1_entry(va, l1e_from_intpte(req.val), mfn, cmd == MMU_PT_UPDATE_PRESERVE_AD, v, pg_owner); - if ( target ) - put_page(target); - } - break; + break; case PGT_l2_page_table: rc = mod_l2_entry(va, l2e_from_intpte(req.val), mfn, cmd == MMU_PT_UPDATE_PRESERVE_AD, v); @@ -3367,7 +3355,7 @@ long do_mmu_update( case PGT_l4_page_table: rc = mod_l4_entry(va, l4e_from_intpte(req.val), mfn, cmd == MMU_PT_UPDATE_PRESERVE_AD, v); - break; + break; case PGT_writable_page: perfc_incr(writable_mmu_updates); if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn)) )