From patchwork Wed Aug 3 19:16:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Lai X-Patchwork-Id: 9262177 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 B272460754 for ; Wed, 3 Aug 2016 20:17:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A342F28210 for ; Wed, 3 Aug 2016 20:17:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97AD02823D; Wed, 3 Aug 2016 20:17:45 +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 B504528210 for ; Wed, 3 Aug 2016 20:17:44 +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 1bV2Z0-0001Q4-KH; Wed, 03 Aug 2016 20:14:50 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bV2Yz-0001Ps-0Y for xen-devel@lists.xensource.com; Wed, 03 Aug 2016 20:14:49 +0000 Received: from [193.109.254.147] by server-6.bemta-14.messagelabs.com id 85/13-16889-8B052A75; Wed, 03 Aug 2016 20:14:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXS1tYhobs9YFG 4wbMfihb3prxnd2D02N63iz2AMYo1My8pvyKBNWPT5TmMBdc9K+a//cHWwNht2cXIySEkUCmx +/ACdhBbQoBX4siyGawQdoDEjwszGSFqKiRadx0CsrmA7KWMEqfnwSRKJO4cOglmswmoSiw/N wnMFhFQlFi3+h0LiM0sYC9xd/0OsLiwQJjE9IkTgeIcHCxA9Rf/gN3AK+As0fxrM9QNchI3z3 Uyg9icAi4SC/f+ZYZY5SzR3fuTaQIj/wJGhlWMGsWpRWWpRbpGRnpJRZnpGSW5iZk5uoaGJnq 5qcXFiempOYlJxXrJ+bmbGIHBU8/AwLiD8fYlv0OMkhxMSqK8Ew8uDBfiS8pPqcxILM6ILyrN SS0+xCjDwaEkwTvZf1G4kGBRanpqRVpmDjCMYdISHDxKIrxWIGne4oLE3OLMdIjUKUZdjmNzb 6xlEmLJy89LlRLnTQApEgApyijNgxsBi6lLjLJSwryMDAwMQjwFqUW5mSWo8q8YxTkYlYR5N4 JM4cnMK4Hb9AroCCagI04YLAA5oiQRISXVwNjGF7slLewhwxpOgfwstUtMz+rlyyI2+FUfXRC Y5OO6QH4R1+GDb/a+EvQ8+nKGXEyywlG7JaxMXTESBxc94wn/rb/sOeeU3uyXTsvfSOzb3FOS Lvm86faKeY8/sa851vrosdT0Yy8+z+I9fSY+9PrKQ3Pyuvet3Pdxb53FkTf8B56cPF/JlrNTi aU4I9FQi7moOBEAUxiE4KQCAAA= X-Env-Sender: pclai@intel.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1470255286!56696390!1 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4712 invoked from network); 3 Aug 2016 20:14:47 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-12.tower-27.messagelabs.com with SMTP; 3 Aug 2016 20:14:47 -0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 03 Aug 2016 13:14:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,467,1464678000"; d="scan'208"; a="1019158849" Received: from scymds02.sc.intel.com ([10.82.195.37]) by fmsmga001.fm.intel.com with ESMTP; 03 Aug 2016 13:14:45 -0700 Received: from pclaidev.sc.intel.com (pclaidev.sc.intel.com [143.183.85.59]) by scymds02.sc.intel.com with ESMTP id u73KEjwK007220; Wed, 3 Aug 2016 13:14:45 -0700 Received: by pclaidev.sc.intel.com (Postfix, from userid 1002) id 69B071FF9D; Wed, 3 Aug 2016 12:17:17 -0700 (PDT) From: Paul Lai To: xen-devel@lists.xensource.com Date: Wed, 3 Aug 2016 12:16:57 -0700 Message-Id: <1470251818-9301-3-git-send-email-paul.c.lai@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470251818-9301-1-git-send-email-paul.c.lai@intel.com> References: <1470251818-9301-1-git-send-email-paul.c.lai@intel.com> Cc: dunlapg@gmail.com, ravi.sahita@intel.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v2 Altp2m cleanup 2/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 Move altp2m specific functions to altp2m files. This makes the code a little easier to read. Also moving ept code to ept specific files as requested in: https://lists.xenproject.org/archives/html/xen-devel/2015-07/msg04323.html Signed-off-by: Paul Lai --- xen/arch/x86/mm/altp2m.c | 45 +++++++++++++++++++++++++++++++++++++++ xen/arch/x86/mm/hap/hap.c | 35 +++++------------------------- xen/arch/x86/mm/p2m-ept.c | 39 +++++++++++++++++++++++++++++++++ xen/arch/x86/mm/p2m.c | 45 +++------------------------------------ xen/include/asm-x86/altp2m.h | 4 +++- xen/include/asm-x86/hvm/vmx/vmx.h | 3 +++ xen/include/asm-x86/p2m.h | 9 +++----- 7 files changed, 101 insertions(+), 79 deletions(-) diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c index 10605c8..ec812dd 100644 --- a/xen/arch/x86/mm/altp2m.c +++ b/xen/arch/x86/mm/altp2m.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -65,6 +66,50 @@ altp2m_vcpu_destroy(struct vcpu *v) vcpu_unpause(v); } +int +hvm_altp2m_init( struct domain *d) +{ + int rc = 0; + unsigned int i = 0; + + /* Init alternate p2m data. */ + if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL ) + { + rc = -ENOMEM; + goto out; + } + + for ( i = 0; i < MAX_EPTP; i++ ) + d->arch.altp2m_eptp[i] = INVALID_MFN; + + for ( i = 0; i < MAX_ALTP2M; i++ ) + { + rc = p2m_alloc_table(d->arch.altp2m_p2m[i]); + if ( rc != 0 ) + goto out; + } + + d->arch.altp2m_active = 0; + out: + return rc; +} + +void +hvm_altp2m_teardown( struct domain *d) +{ + unsigned int i = 0; + 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]); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 9c2cd49..07833b7 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -501,24 +502,9 @@ int hap_enable(struct domain *d, u32 mode) if ( hvm_altp2m_supported() ) { - /* Init alternate p2m data */ - if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL ) - { - rv = -ENOMEM; - goto out; - } - - for ( i = 0; i < MAX_EPTP; i++ ) - d->arch.altp2m_eptp[i] = INVALID_MFN; - - for ( i = 0; i < MAX_ALTP2M; i++ ) - { - rv = p2m_alloc_table(d->arch.altp2m_p2m[i]); - if ( rv != 0 ) - goto out; - } - - d->arch.altp2m_active = 0; + rv = hvm_altp2m_init(d); + if ( rv != 0 ) + goto out; } /* Now let other users see the new mode */ @@ -534,18 +520,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]); - } + hvm_altp2m_teardown(d); /* Destroy nestedp2m's first */ for (i = 0; i < MAX_NESTEDP2M; i++) { diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 7166c71..b68806d 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -1329,6 +1329,45 @@ void setup_ept_dump(void) register_keyhandler('D', ept_dump_p2m_table, "dump VT-x EPT tables", 0); } +void p2m_init_altp2m_ept_helper( struct domain *d, unsigned int i) +{ + struct p2m_domain *p2m = d->arch.altp2m_p2m[i]; + struct ept_data *ept; + + p2m->min_remapped_gfn = INVALID_GFN; + p2m->max_remapped_gfn = 0; + ept = &p2m->ept; + ept->asr = pagetable_get_pfn(p2m_get_pagetable(p2m)); + d->arch.altp2m_eptp[i] = ept_get_eptp(ept); +} + +unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp) +{ + struct p2m_domain *p2m; + struct ept_data *ept; + unsigned int i; + + altp2m_list_lock(d); + + for ( i = 0; i < MAX_ALTP2M; i++ ) + { + if ( d->arch.altp2m_eptp[i] == INVALID_MFN ) + continue; + + p2m = d->arch.altp2m_p2m[i]; + ept = &p2m->ept; + + if ( eptp == ept_get_eptp(ept) ) + goto out; + } + + i = INVALID_ALTP2M; + + out: + altp2m_list_unlock(d); + return i; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 89462b2..b48cf4b 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -196,8 +196,8 @@ static void p2m_teardown_altp2m(struct domain *d) if ( !d->arch.altp2m_p2m[i] ) continue; p2m = d->arch.altp2m_p2m[i]; - d->arch.altp2m_p2m[i] = NULL; p2m_free_one(p2m); + d->arch.altp2m_p2m[i] = NULL; } } @@ -2270,33 +2270,6 @@ int unmap_mmio_regions(struct domain *d, return i == nr ? 0 : i ?: ret; } -unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp) -{ - struct p2m_domain *p2m; - struct ept_data *ept; - unsigned int i; - - altp2m_list_lock(d); - - for ( i = 0; i < MAX_ALTP2M; i++ ) - { - if ( d->arch.altp2m_eptp[i] == INVALID_MFN ) - continue; - - p2m = d->arch.altp2m_p2m[i]; - ept = &p2m->ept; - - if ( eptp == ept_get_eptp(ept) ) - goto out; - } - - i = INVALID_ALTP2M; - - out: - altp2m_list_unlock(d); - return i; -} - bool_t p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx) { struct domain *d = v->domain; @@ -2402,18 +2375,6 @@ void p2m_flush_altp2m(struct domain *d) altp2m_list_unlock(d); } -static void p2m_init_altp2m_helper(struct domain *d, unsigned int i) -{ - struct p2m_domain *p2m = d->arch.altp2m_p2m[i]; - struct ept_data *ept; - - p2m->min_remapped_gfn = INVALID_GFN; - p2m->max_remapped_gfn = 0; - ept = &p2m->ept; - ept->asr = pagetable_get_pfn(p2m_get_pagetable(p2m)); - d->arch.altp2m_eptp[i] = ept_get_eptp(ept); -} - int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx) { int rc = -EINVAL; @@ -2425,7 +2386,7 @@ int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx) if ( d->arch.altp2m_eptp[idx] == INVALID_MFN ) { - p2m_init_altp2m_helper(d, idx); + p2m_init_altp2m_ept_helper(d, idx); rc = 0; } @@ -2445,7 +2406,7 @@ int p2m_init_next_altp2m(struct domain *d, uint16_t *idx) if ( d->arch.altp2m_eptp[i] != INVALID_MFN ) continue; - p2m_init_altp2m_helper(d, i); + p2m_init_altp2m_ept_helper(d, i); *idx = i; rc = 0; diff --git a/xen/include/asm-x86/altp2m.h b/xen/include/asm-x86/altp2m.h index 64c7618..a236ed7 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 hvm_altp2m_init(struct domain *d); +void hvm_altp2m_teardown(struct domain *d); + #endif /* __ASM_X86_ALTP2M_H */ diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h index 359b2a9..5b495a2 100644 --- a/xen/include/asm-x86/hvm/vmx/vmx.h +++ b/xen/include/asm-x86/hvm/vmx/vmx.h @@ -556,6 +556,9 @@ void ept_p2m_uninit(struct p2m_domain *p2m); void ept_walk_table(struct domain *d, unsigned long gfn); bool_t ept_handle_misconfig(uint64_t gpa); void setup_ept_dump(void); +void p2m_init_altp2m_ept_helper( struct domain *d, unsigned int i); +/* Locate an alternate p2m by its EPTP */ +unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp); void update_guest_eip(void); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 65675a2..d7c8c12 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -23,8 +23,8 @@ * along with this program; If not, see . */ -#ifndef _XEN_P2M_H -#define _XEN_P2M_H +#ifndef _XEN_ASM_X86_P2M_H +#define _XEN_ASM_X86_P2M_H #include #include @@ -779,9 +779,6 @@ static inline struct p2m_domain *p2m_get_altp2m(struct vcpu *v) return v->domain->arch.altp2m_p2m[index]; } -/* Locate an alternate p2m by its EPTP */ -unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp); - /* Switch alternate p2m for a single vcpu */ bool_t p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx); @@ -843,7 +840,7 @@ static inline unsigned int p2m_get_iommu_flags(p2m_type_t p2mt) return flags; } -#endif /* _XEN_P2M_H */ +#endif /* _XEN_ASM_X86_P2M_H */ /* * Local variables: