From patchwork Wed Aug 9 18:21:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9891537 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 27B4E60384 for ; Wed, 9 Aug 2017 18:24:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03E7D28816 for ; Wed, 9 Aug 2017 18:24:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECD9728A3D; Wed, 9 Aug 2017 18:24:05 +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 73B9028B19 for ; Wed, 9 Aug 2017 18:24:00 +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 1dfVbS-0006Pb-FQ; Wed, 09 Aug 2017 18:21:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfVbR-0006PV-AV for xen-devel@lists.xen.org; Wed, 09 Aug 2017 18:21:09 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 27/CA-02181-4925B895; Wed, 09 Aug 2017 18:21:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOLMWRWlGSWpSXmKPExsXitHSDve7koO5 Ig6Y2fYslHxezODB6HN39mymAMYo1My8pvyKBNePLUZ+C3RoVLVO2MjYwHpfrYuTkkBDwl5g3 9QoTiM0moC+x+8UnMFtEQF3idMdF1i5GLg5mgUWMEteWT2LpYuTgEBbwktj0pwakhkVAReJH+ wUWEJtXwFPi1oSzTBAz5STOH//JDGILCahJXOu/xA5RIyhxcuYTsHpmAQmJgy9eME9g5J6FJD ULSWoBI9MqRvXi1KKy1CJdM72kosz0jJLcxMwcXUMDY73c1OLixPTUnMSkYr3k/NxNjMBAqGd gYNzBeKXN+RCjJAeTkijvJu3OSCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvDyB3ZFCgkWp6akV aZk5wJCESUtw8CiJ8H4OAErzFhck5hZnpkOkTjHqcrya8P8bkxBLXn5eqpQ4by3IDAGQoozSP LgRsPi4xCgrJczLyMDAIMRTkFqUm1mCKv+KUZyDUUmYtxBkCk9mXgncpldARzABHRHh2wlyRE kiQkqqgbFE1++2d3nLJqd1u9XaXtadnvN9d7xuQ0C9kDbf/P+/l4r+Ld5qKXuib7Jq7rSWb+9 uSkVtTVp8vuawfcoF16OMF+vE/koGn404Kfqai+fmxldZoTNsHpVY9SS/rvZh+tKUuNB6aUNQ t1z4hhe5irH68Q/29ulEVK395yYUcnml4qepi5ze1CqxFGckGmoxFxUnAgBeAK9eigIAAA== X-Env-Sender: prvs=38757f4df=Andrew.Cooper3@citrix.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1502302866!104744519!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 46327 invoked from network); 9 Aug 2017 18:21:07 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 9 Aug 2017 18:21:07 -0000 X-IronPort-AV: E=Sophos;i="5.41,348,1498521600"; d="scan'208";a="443209381" From: Andrew Cooper To: Xen-devel Date: Wed, 9 Aug 2017 19:21:02 +0100 Message-ID: <1502302862-13104-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Cc: Andrew Cooper , Julien Grall , Stefano Stabellini , Jan Beulich Subject: [Xen-devel] [PATCH] common/domain_page: Drop domain_mmap_cache infrastructure 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 This infrastructure is used exclusively by the x86 do_mmu_update() hypercall. Mapping and unmapping domain pages is probably not the slow part of that function, but even with an opencoded caching implementation, Bloat-o-meter reports: function old new delta do_mmu_update 6815 6573 -242 The !CONFIG_DOMAIN_PAGE stub code has a mismatch between mapping and unmapping, which is a latent bug. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Stefano Stabellini CC: Julien Grall --- xen/arch/x86/mm.c | 22 ++++++++------ xen/include/xen/domain_page.h | 68 ------------------------------------------- 2 files changed, 13 insertions(+), 77 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 97b3b4b..88bf4f6 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3440,13 +3440,13 @@ long do_mmu_update( unsigned int foreigndom) { struct mmu_update req; - void *va; + void *va = NULL; unsigned long gpfn, gmfn, mfn; struct page_info *page; unsigned int cmd, i = 0, done = 0, pt_dom; struct vcpu *curr = current, *v = curr; struct domain *d = v->domain, *pt_owner = d, *pg_owner; - struct domain_mmap_cache mapcache; + mfn_t map_mfn = INVALID_MFN; uint32_t xsm_needed = 0; uint32_t xsm_checked = 0; int rc = put_old_guest_table(curr); @@ -3503,8 +3503,6 @@ long do_mmu_update( goto out; } - domain_mmap_cache_init(&mapcache); - for ( i = 0; i < count; i++ ) { if ( curr->arch.old_guest_table || (i && hypercall_preempt_check()) ) @@ -3573,9 +3571,15 @@ long do_mmu_update( } mfn = page_to_mfn(page); - va = map_domain_page_with_cache(mfn, &mapcache); - va = (void *)((unsigned long)va + - (unsigned long)(req.ptr & ~PAGE_MASK)); + + if ( !mfn_eq(_mfn(mfn), map_mfn) ) + { + if ( va ) + unmap_domain_page(va); + va = map_domain_page(_mfn(mfn)); + map_mfn = _mfn(mfn); + } + va = _p(((unsigned long)va & PAGE_MASK) + (req.ptr & ~PAGE_MASK)); if ( page_lock(page) ) { @@ -3653,7 +3657,6 @@ long do_mmu_update( put_page_type(page); } - unmap_domain_page_with_cache(va, &mapcache); put_page(page); } break; @@ -3734,7 +3737,8 @@ long do_mmu_update( put_pg_owner(pg_owner); - domain_mmap_cache_destroy(&mapcache); + if ( va ) + unmap_domain_page(va); perfc_add(num_page_updates, i); diff --git a/xen/include/xen/domain_page.h b/xen/include/xen/domain_page.h index c1d630c..93f2a5a 100644 --- a/xen/include/xen/domain_page.h +++ b/xen/include/xen/domain_page.h @@ -51,66 +51,6 @@ static inline void *__map_domain_page_global(const struct page_info *pg) return map_domain_page_global(_mfn(__page_to_mfn(pg))); } -#define DMCACHE_ENTRY_VALID 1U -#define DMCACHE_ENTRY_HELD 2U - -struct domain_mmap_cache { - unsigned long mfn; - void *va; - unsigned int flags; -}; - -static inline void -domain_mmap_cache_init(struct domain_mmap_cache *cache) -{ - ASSERT(cache != NULL); - cache->flags = 0; - cache->mfn = 0; - cache->va = NULL; -} - -static inline void * -map_domain_page_with_cache(unsigned long mfn, struct domain_mmap_cache *cache) -{ - ASSERT(cache != NULL); - BUG_ON(cache->flags & DMCACHE_ENTRY_HELD); - - if ( likely(cache->flags & DMCACHE_ENTRY_VALID) ) - { - cache->flags |= DMCACHE_ENTRY_HELD; - if ( likely(mfn == cache->mfn) ) - goto done; - unmap_domain_page(cache->va); - } - - cache->mfn = mfn; - cache->va = map_domain_page(_mfn(mfn)); - cache->flags = DMCACHE_ENTRY_HELD | DMCACHE_ENTRY_VALID; - - done: - return cache->va; -} - -static inline void -unmap_domain_page_with_cache(const void *va, struct domain_mmap_cache *cache) -{ - ASSERT(cache != NULL); - cache->flags &= ~DMCACHE_ENTRY_HELD; -} - -static inline void -domain_mmap_cache_destroy(struct domain_mmap_cache *cache) -{ - ASSERT(cache != NULL); - BUG_ON(cache->flags & DMCACHE_ENTRY_HELD); - - if ( likely(cache->flags & DMCACHE_ENTRY_VALID) ) - { - unmap_domain_page(cache->va); - cache->flags = 0; - } -} - #else /* !CONFIG_DOMAIN_PAGE */ #define map_domain_page(mfn) mfn_to_virt(mfn_x(mfn)) @@ -130,14 +70,6 @@ static inline void *__map_domain_page_global(const struct page_info *pg) static inline void unmap_domain_page_global(const void *va) {}; -struct domain_mmap_cache { -}; - -#define domain_mmap_cache_init(c) ((void)(c)) -#define map_domain_page_with_cache(mfn,c) (map_domain_page(mfn)) -#define unmap_domain_page_with_cache(va,c) ((void)(va)) -#define domain_mmap_cache_destroy(c) ((void)(c)) - #endif /* !CONFIG_DOMAIN_PAGE */ #endif /* __XEN_DOMAIN_PAGE_H__ */