From patchwork Thu Nov 10 23:45:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Lai X-Patchwork-Id: 9422253 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 03FFD60720 for ; Thu, 10 Nov 2016 23:46:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED1E429858 for ; Thu, 10 Nov 2016 23:46:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1E742985A; Thu, 10 Nov 2016 23:46:30 +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 89C5D29858 for ; Thu, 10 Nov 2016 23:46:30 +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 1c4z0i-0005kf-2u; Thu, 10 Nov 2016 23:44:00 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c4z0h-0005kY-0h for xen-devel@lists.xensource.com; Thu, 10 Nov 2016 23:43:59 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id B6/29-18083-E3605285; Thu, 10 Nov 2016 23:43:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42I5YG4SoWvLphp hsHu3scW9Ke/ZHRg9tvftYg9gjGLNzEvKr0hgzZiypY+5YJt0xea3Z5gaGK+IdjFycggJVEis 6b3CAmJLCPBKHFk2gxXCDpDYu76HHaZmdeNuxi5GLiB7OaPE1r3NbBCJEolpk/+ANbMJqEosP zeJEcQWEVCUWLf6HVicWSBNYu2mL2D1wgLRElu37AGLswDVP+76DmbzCjhLfD+4hhFisZzEzX OdzCA2p4CLxMM7P1ghdjlLrDz6nXkCI/8CRoZVjBrFqUVlqUW6huZ6SUWZ6RkluYmZObqGBmZ 6uanFxYnpqTmJScV6yfm5mxiB4cMABDsYb28MOMQoycGkJMqrOF0lQogvKT+lMiOxOCO+qDQn tfgQowwHh5IEryuraoSQYFFqempFWmYOMJBh0hIcPEoivPEgad7igsTc4sx0iNQpRkUpcV4xk IQASCKjNA+uDRY9lxhlpYR5GYEOEeIpSC3KzSxBlX/FKM7BqCTMmw8yhSczrwRu+iugxUxAi2 fEqYAsLklESEk1MCb9+ZwyPbXn3Py5wSoaB/0XByuJGLDUcmzjW8DUyd2r3qv9gK/tUeCcPlY tpg1/vhc2TWbe6iVz5s4pg89W+tOEO6ReGfUdZfzsKCXH4y8W/eCgsyd7/f5LLbL/4mL0atQZ pELttsyvv30/hGPmuUkvLjZtEmD0yg1unD69q2iGzvwk10lGSizFGYmGWsxFxYkAySCB4JkCA AA= X-Env-Sender: pclai@intel.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1478821435!42639794!1 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6988 invoked from network); 10 Nov 2016 23:43:57 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-15.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Nov 2016 23:43:57 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 10 Nov 2016 15:43:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,620,1473145200"; d="scan'208"; a="1058063589" Received: from scymds02.sc.intel.com ([10.82.195.37]) by orsmga001.jf.intel.com with ESMTP; 10 Nov 2016 15:43:54 -0800 Received: from pclaidev.sc.intel.com (pclaidev.sc.intel.com [143.183.85.157]) by scymds02.sc.intel.com with ESMTP id uAANhsB8016918; Thu, 10 Nov 2016 15:43:54 -0800 Received: by pclaidev.sc.intel.com (Postfix, from userid 1002) id B432B203E5; Thu, 10 Nov 2016 15:45:52 -0800 (PST) From: Paul Lai To: xen-devel@lists.xensource.com Date: Thu, 10 Nov 2016 15:45:50 -0800 Message-Id: <1478821552-1497-2-git-send-email-paul.c.lai@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478821552-1497-1-git-send-email-paul.c.lai@intel.com> References: <1478821552-1497-1-git-send-email-paul.c.lai@intel.com> Cc: ravi.sahita@intel.com, george.dunlap@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH Altp2m cleanup 2/3 v12 1/3] Move altp2m specific functions to altp2m files. 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Moving altp2m domain startup and teardown into altp2m_domain_init() and altp2m_domain_teardown() respectively. Moving hvm_altp2m_supported() check into functions that use it for better readability. Got rid of stray blanks after open paren after function names. Defining _XEN_ASM_X86_P2M_H instead of _XEN_P2M_H for xen/include/asm-x86/p2m.h. Signed-off-by: Paul Lai --- xen/arch/x86/mm/altp2m.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/mm/hap/hap.c | 14 +---------- xen/include/asm-x86/altp2m.h | 4 +++- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c index 930bdc2..317c8f7 100644 --- a/xen/arch/x86/mm/altp2m.c +++ b/xen/arch/x86/mm/altp2m.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -66,6 +67,60 @@ altp2m_vcpu_destroy(struct vcpu *v) } /* + * allocate and initialize memory for altp2m portion of domain + * + * returns < 0 on error + * returns 0 on no operation & success + */ +int +altp2m_domain_init(struct domain *d) +{ + int rc; + unsigned int i; + + if ( !hvm_altp2m_supported() ) + return 0; + + /* Init alternate p2m data. */ + if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL ) + return -ENOMEM; + + for ( i = 0; i < MAX_EPTP; i++ ) + d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN); + + for ( i = 0; i < MAX_ALTP2M; i++ ) + { + rc = p2m_alloc_table(d->arch.altp2m_p2m[i]); + if ( rc != 0 ) + { + altp2m_domain_teardown(d); + return rc; + } + } + + d->arch.altp2m_active = 0; + + return rc; +} + +void +altp2m_domain_teardown(struct domain *d) +{ + unsigned int i; + + if ( !hvm_altp2m_supported() ) + return; + + d->arch.altp2m_active = 0; + + for ( i = 0; i < MAX_ALTP2M; i++ ) + p2m_teardown(d->arch.altp2m_p2m[i]); + + free_xenheap_page(d->arch.altp2m_eptp); + d->arch.altp2m_eptp = NULL; +} + +/* * Local variables: * mode: C * c-file-style: "BSD" diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 3218fa2..7fe6f83 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -533,19 +533,7 @@ void hap_final_teardown(struct domain *d) { unsigned int i; - if ( hvm_altp2m_supported() ) - { - d->arch.altp2m_active = 0; - - if ( d->arch.altp2m_eptp ) - { - free_xenheap_page(d->arch.altp2m_eptp); - d->arch.altp2m_eptp = NULL; - } - - for ( i = 0; i < MAX_ALTP2M; i++ ) - p2m_teardown(d->arch.altp2m_p2m[i]); - } + altp2m_domain_teardown(d); /* Destroy nestedp2m's first */ for (i = 0; i < MAX_NESTEDP2M; i++) { diff --git a/xen/include/asm-x86/altp2m.h b/xen/include/asm-x86/altp2m.h index 64c7618..0090c89 100644 --- a/xen/include/asm-x86/altp2m.h +++ b/xen/include/asm-x86/altp2m.h @@ -18,7 +18,6 @@ #ifndef __ASM_X86_ALTP2M_H #define __ASM_X86_ALTP2M_H -#include #include /* for struct vcpu, struct domain */ #include /* for vcpu_altp2m */ @@ -38,4 +37,7 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v) return vcpu_altp2m(v).p2midx; } +int altp2m_domain_init(struct domain *d); +void altp2m_domain_teardown(struct domain *d); + #endif /* __ASM_X86_ALTP2M_H */