From patchwork Wed Oct 19 20:32:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Lai X-Patchwork-Id: 9385359 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 1E622608A7 for ; Wed, 19 Oct 2016 20:33:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1094628EBB for ; Wed, 19 Oct 2016 20:33:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 055AF29214; Wed, 19 Oct 2016 20:33:13 +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 3E97A29144 for ; Wed, 19 Oct 2016 20:33:11 +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 1bwxVa-0003z9-Cy; Wed, 19 Oct 2016 20:30:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bwxVZ-0003ys-Cq for xen-devel@lists.xensource.com; Wed, 19 Oct 2016 20:30:41 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id 1B/E0-08498-0F7D7085; Wed, 19 Oct 2016 20:30:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42Jpa+tI0f1wnT3 C4PAmFot7U96zOzB6bO/bxR7AGMWamZeUX5HAmrHgdGrBDuuK9a8nMDYwLtXvYuTgEBKolFjX nt/FyMkhIcArcWTZDFYI20/i7PUXzCC2kECFxMqt/SxdjFxA9jJGiY6XV9kgEiUS3z+3sIDYb AKqEsvPTWIEsUUEFCXWrX4HFmcWSJNYu+kLG8guYYFoicl34kDCLEDlr27NByvhFXCReP/lDd ReOYmb5zrB9nIKuEr8PfeBBWKVi8Tdr8tYJzDyL2BkWMWoUZxaVJZapGtkppdUlJmeUZKbmJm ja2hgppebWlycmJ6ak5hUrJecn7uJERg4DECwg/HMgsBDjJIcTEqivDx97BFCfEn5KZUZicUZ 8UWlOanFhxhlODiUJHiTrwHlBItS01Mr0jJzgCEMk5bg4FES4S0ESfMWFyTmFmemQ6ROMepyH Jt7Yy2TEEtefl6qlDjvu6tARQIgRRmleXAjYPF0iVFWSpiXEegoIZ6C1KLczBJU+VeM4hyMSs K8tSCreDLzSuA2vQI6ggnoiHN5LCBHlCQipKQaGKUVFzaVqlUWb2S45K/uemOaZpZVzja/96t Y5OcLO+8N6PvzXGWjfTZTibjSvrQL0huudVmaWoX8Ntl5c5bn1BM/3q/0Erx+9v6LFo/OWVfe Fe38nn92lnGo8O+u9edvty499L/ipM67S/8Vg2a1hPTcTmZ4e0D01IJTM65KlJrEzJA4Vfi+q U6JpTgj0VCLuag4EQDcazlAogIAAA== X-Env-Sender: pclai@intel.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1476909036!16457803!2 X-Originating-IP: [134.134.136.100] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55333 invoked from network); 19 Oct 2016 20:30:39 -0000 Received: from mga07.intel.com (HELO mga07.intel.com) (134.134.136.100) by server-6.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Oct 2016 20:30:39 -0000 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP; 19 Oct 2016 13:30:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,367,1473145200"; d="scan'208";a="21385342" Received: from scymds01.sc.intel.com ([10.82.194.37]) by fmsmga006.fm.intel.com with ESMTP; 19 Oct 2016 13:30:36 -0700 Received: from pclaidev.sc.intel.com (pclaidev.sc.intel.com [143.183.85.56]) by scymds01.sc.intel.com with ESMTP id u9JKUZcT004894; Wed, 19 Oct 2016 13:30:35 -0700 Received: by pclaidev.sc.intel.com (Postfix, from userid 1002) id 2194020487; Wed, 19 Oct 2016 13:32:23 -0700 (PDT) From: Paul Lai To: xen-devel@lists.xensource.com Date: Wed, 19 Oct 2016 13:32:22 -0700 Message-Id: <1476909143-28616-2-git-send-email-paul.c.lai@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476909143-28616-1-git-send-email-paul.c.lai@intel.com> References: <1476909143-28616-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 v11 1/2] 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. In hap_enable(), upon partial success of altp2m_domain_init(), unravel the partial p2m_alloc_table() and unravel hap_set_allocation(). 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 --- v11 Per request.... Removed the check for d == 0 at the head of altp2m_domain_init() per request. Fixing code style issues missed in v10. It was apparent that our eyes are failing to see code style issues, so we started using some vim scripts to assist. Here's one for spaces after parens: pclai@pclaidev:/rhel-home/pclai/p2m_new/xen/output$ cat ~/vim_xen :highlight ForIfLParenNoSpace ctermbg=red guibg=red :highlight ForIfRParenNoSpace ctermbg=red guibg=red :match ForIfLParenNoSpace /['for''if'] ([a-zA-Z0-9]/ :2match ForIfRParenNoSpace /['for''if'] .*[a-zA-Z0-9-+]+[)]$/ Here's another to catch dangling left curly braces: pclai@pclaidev:/rhel-home/pclai/p2m_new/xen/output$ cat ~/vim_xen_curly :highlight RParenCurly ctermbg=red guibg=red :match RParenCurly /) *[{]$/ We specifically unraval p2m_alloc_table() and hap_set_allocation() by hand instead of calling p2m_teardown() during partial success of altp2m_domain_init(). --- xen/arch/x86/mm/altp2m.c | 55 +++++++++++++++++++++++++++++++++++++++ xen/arch/x86/mm/hap/hap.c | 40 +++++++++------------------- xen/include/asm-x86/altp2m.h | 4 ++- xen/include/asm-x86/hvm/vmx/vmx.h | 3 +++ xen/include/asm-x86/p2m.h | 9 +++---- 5 files changed, 76 insertions(+), 35 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..8826e77 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 @@ -499,26 +500,21 @@ int hap_enable(struct domain *d, u32 mode) goto out; } - if ( hvm_altp2m_supported() ) + if ( (rv = altp2m_domain_init(d)) < 0 ) { - /* Init alternate p2m data */ - if ( (d->arch.altp2m_eptp = alloc_xenheap_page()) == NULL ) + /* Unravel the partial p2m_alloc_table() above */ + for ( i = 0; i < MAX_NESTEDP2M; i++ ) { - rv = -ENOMEM; - goto out; + p2m_teardown(d->arch.nested_p2m[i]); } - for ( i = 0; i < MAX_EPTP; i++ ) - d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN); - - for ( i = 0; i < MAX_ALTP2M; i++ ) - { - rv = p2m_alloc_table(d->arch.altp2m_p2m[i]); - if ( rv != 0 ) - goto out; - } + /* Unravel the hap_set_allocation(d, 256, NULL) above */ + paging_lock(d); + hap_set_allocation(d, 0, NULL); + ASSERT(d->arch.paging.hap.p2m_pages == 0); + paging_unlock(d); - d->arch.altp2m_active = 0; + goto out; } /* Now let other users see the new mode */ @@ -533,19 +529,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 */ diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h index 4cdd9b1..9f4c7de 100644 --- a/xen/include/asm-x86/hvm/vmx/vmx.h +++ b/xen/include/asm-x86/hvm/vmx/vmx.h @@ -561,6 +561,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(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 7035860..0e72880 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 @@ -784,9 +784,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); @@ -848,7 +845,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: