From patchwork Wed Apr 26 15:54:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9701671 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 B97AC60245 for ; Wed, 26 Apr 2017 16:01:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA978280CF for ; Wed, 26 Apr 2017 16:01:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F7F1285EC; Wed, 26 Apr 2017 16:01:14 +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 48772280CF for ; Wed, 26 Apr 2017 16:01:14 +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 1d3PLO-0006uj-Sb; Wed, 26 Apr 2017 15:59:06 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3PLN-0006tw-KK for xen-devel@lists.xenproject.org; Wed, 26 Apr 2017 15:59:05 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 48/04-02183-8C3C0095; Wed, 26 Apr 2017 15:59:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeJIrShJLcpLzFFi42JxWrrBXvfEYYZ Ig5d/pC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oym9TMZC1bJVuxvXcXWwPhYpIuRk0NCwF+i ad5tJhCbTUBZ4mdnLxuILSKgJ9F04DkjiM0skCfxeFUrWFxYwEfi2sn3YPUsAqoSz/sOsoDYv AIWEu3bpzJBzJSX2NV2kRXE5hSwlHi3bxpYrxBQzeP5zVC2gkTH9GNMEL2CEidnPmGB2CUhcf DFC+YJjLyzkKRmIUktYGRaxahenFpUllqka66XVJSZnlGSm5iZo2toYKyXm1pcnJiempOYVKy XnJ+7iREYOgxAsIOx8bvTIUZJDiYlUd71KxgihfiS8lMqMxKLM+KLSnNSiw8xynBwKEnw1h4C ygkWpaanVqRl5gCDGCYtwcGjJMK7HiTNW1yQmFucmQ6ROsWoKCXOqwqSEABJZJTmwbXBIucSo 6yUMC8j0CFCPAWpRbmZJajyrxjFORiVhHm3gEzhycwrgZv+CmgxE9BiFhewxSWJCCmpBsbUkG tPg9ZIyLCZRBw6IHTsGkesRozUvmVzgla5Z5ybIlE82/XcTfPdkdqR/xU7VUwi2xKLjh35GXt 3+uGvOkIbg23YJpqbm+mH+Cl0qp4papBpNngXNonPq9O+ZPH56Vu9D7yU0Px9zqc7foFYeJy3 bvuGlXnvD+yOeVyeedPW4tjcufXZW5RYijMSDbWYi4oTAcQA3SGXAgAA X-Env-Sender: prvs=28229795a=wei.liu2@citrix.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1493222337!94304132!3 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.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17569 invoked from network); 26 Apr 2017 15:59:04 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 26 Apr 2017 15:59:04 -0000 X-IronPort-AV: E=Sophos;i="5.37,255,1488844800"; d="scan'208";a="429868932" From: Wei Liu To: Xen-devel Date: Wed, 26 Apr 2017 16:54:50 +0100 Message-ID: <20170426155457.10799-6-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170426155457.10799-1-wei.liu2@citrix.com> References: <20170426155457.10799-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH for-next v3 05/12] x86/domain: factor out pv_vcpu_initialise 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 Move PV specific vcpu initialisation code to said function, but leave the only line needed by idle domain in vcpu_initialise. Use pv_vcpu_destroy in error path to simplify code. It is safe to do so because the destruction function accepts partially initialised vcpu struct. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- v3: address Jan's comments Cc: Jan Beulich Cc: Andrew Cooper --- xen/arch/x86/domain.c | 99 ++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index bdf51785e6..cea80803a5 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -400,6 +400,50 @@ static void pv_destroy_gdt_ldt_l1tab(struct vcpu *v) 1U << GDT_LDT_VCPU_SHIFT); } +static void pv_vcpu_destroy(struct vcpu *v); +static int pv_vcpu_initialise(struct vcpu *v) +{ + struct domain *d = v->domain; + int rc; + + ASSERT(!is_idle_domain(d)); + + spin_lock_init(&v->arch.pv_vcpu.shadow_ldt_lock); + + rc = pv_create_gdt_ldt_l1tab(v); + if ( rc ) + return rc; + + BUILD_BUG_ON(NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt) > + PAGE_SIZE); + v->arch.pv_vcpu.trap_ctxt = xzalloc_array(struct trap_info, + NR_VECTORS); + if ( !v->arch.pv_vcpu.trap_ctxt ) + { + rc = -ENOMEM; + goto done; + } + + /* PV guests by default have a 100Hz ticker. */ + v->periodic_period = MILLISECS(10); + + v->arch.pv_vcpu.ctrlreg[4] = real_cr4_to_pv_guest_cr4(mmu_cr4_features); + + if ( is_pv_32bit_domain(d) ) + { + if ( (rc = setup_compat_arg_xlat(v)) ) + goto done; + + if ( (rc = setup_compat_l4(v)) ) + goto done; + } + + done: + if ( rc ) + pv_vcpu_destroy(v); + return rc; +} + int vcpu_initialise(struct vcpu *v) { struct domain *d = v->domain; @@ -426,61 +470,18 @@ int vcpu_initialise(struct vcpu *v) spin_lock_init(&v->arch.vpmu.vpmu_lock); if ( is_hvm_domain(d) ) - { rc = hvm_vcpu_initialise(v); - goto done; - } - - - spin_lock_init(&v->arch.pv_vcpu.shadow_ldt_lock); - - if ( !is_idle_domain(d) ) - { - rc = pv_create_gdt_ldt_l1tab(v); - if ( rc ) - goto done; - - BUILD_BUG_ON(NR_VECTORS * sizeof(*v->arch.pv_vcpu.trap_ctxt) > - PAGE_SIZE); - v->arch.pv_vcpu.trap_ctxt = xzalloc_array(struct trap_info, - NR_VECTORS); - if ( !v->arch.pv_vcpu.trap_ctxt ) - { - pv_destroy_gdt_ldt_l1tab(v); - rc = -ENOMEM; - goto done; - } - - /* PV guests by default have a 100Hz ticker. */ - v->periodic_period = MILLISECS(10); - } + else if ( !is_idle_domain(d) ) + rc = pv_vcpu_initialise(v); else - v->arch.cr3 = __pa(idle_pg_table); - - v->arch.pv_vcpu.ctrlreg[4] = real_cr4_to_pv_guest_cr4(mmu_cr4_features); - - if ( is_pv_32bit_domain(d) ) { - if ( (rc = setup_compat_arg_xlat(v)) ) - goto done; - - if ( (rc = setup_compat_l4(v)) ) - { - free_compat_arg_xlat(v); - goto done; - } + /* Idle domain */ + v->arch.cr3 = __pa(idle_pg_table); + rc = 0; } - done: + if ( rc ) - { vcpu_destroy_fpu(v); - - if ( is_pv_domain(d) ) - { - pv_destroy_gdt_ldt_l1tab(v); - xfree(v->arch.pv_vcpu.trap_ctxt); - } - } else if ( !is_idle_domain(v->domain) ) vpmu_initialise(v);