From: David Vrabel Subject: [PATCH 3/3] x86/xen: optimize get_phys_to_machine() Date: Wed, 7 Jan 2015 14:47:28 +0000 Message-ID: <1420642048-12236-4-git-send-email-david.vrabel@citrix.com> References: <1420642048-12236-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Y8rtf-0003mW-8K for xen-devel@lists.xenproject.org; Wed, 07 Jan 2015 14:47:43 +0000 In-Reply-To: <1420642048-12236-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Boris Ostrovsky , David Vrabel List-Id: xen-devel@lists.xenproject.org The page table walk is only needed to distinguish between identity and missing, both of which have INVALID_P2M_ENTRY. Signed-off-by: David Vrabel --- arch/x86/xen/p2m.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index edbc7a6..a848201 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -405,8 +405,7 @@ void __init xen_vmalloc_p2m_tree(void) unsigned long get_phys_to_machine(unsigned long pfn) { - pte_t *ptep; - unsigned int level; + unsigned long mfn; if (unlikely(pfn >= xen_p2m_size)) { if (pfn < xen_max_p2m_pfn) @@ -414,19 +413,26 @@ unsigned long get_phys_to_machine(unsigned long pfn) return IDENTITY_FRAME(pfn); } + + mfn = xen_p2m_addr[pfn]; - ptep = lookup_address((unsigned long)(xen_p2m_addr + pfn), &level); - BUG_ON(!ptep || level != PG_LEVEL_4K); + if (unlikely(mfn == INVALID_P2M_ENTRY)) { + pte_t *ptep; + unsigned int level; - /* - * The INVALID_P2M_ENTRY is filled in both p2m_*identity - * and in p2m_*missing, so returning the INVALID_P2M_ENTRY - * would be wrong. - */ - if (pte_pfn(*ptep) == PFN_DOWN(__pa(p2m_identity))) - return IDENTITY_FRAME(pfn); + ptep = lookup_address((unsigned long)(xen_p2m_addr + pfn), &level); + BUG_ON(!ptep || level != PG_LEVEL_4K); + + /* + * The INVALID_P2M_ENTRY is filled in both p2m_*identity + * and in p2m_*missing, so returning the INVALID_P2M_ENTRY + * would be wrong. + */ + if (pte_pfn(*ptep) == PFN_DOWN(__pa(p2m_identity))) + return IDENTITY_FRAME(pfn); + } - return xen_p2m_addr[pfn]; + return mfn; } EXPORT_SYMBOL_GPL(get_phys_to_machine); -- 1.7.10.4