From patchwork Wed Apr 26 15:54:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9701639 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 6D91B60245 for ; Wed, 26 Apr 2017 15:59:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E314285EC for ; Wed, 26 Apr 2017 15:59:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52D03285F3; Wed, 26 Apr 2017 15:59:00 +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 C1122285EC for ; Wed, 26 Apr 2017 15:58:59 +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 1d3PJK-0006Pr-IZ; Wed, 26 Apr 2017 15:56:58 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3PJJ-0006PU-Bk for xen-devel@lists.xenproject.org; Wed, 26 Apr 2017 15:56:57 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id C5/9B-03557-843C0095; Wed, 26 Apr 2017 15:56:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrohUtfjMEO kwe1ZEhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bmp8dYCpaJVLxoWsbcwLiQr4uRk0NCwF9i 6bqL7CA2m4CyxM/OXjYQW0RAT6LpwHNGEJtZIE/i8apWsLiwQKrEk70zwWwWAVWJiz3nmEBsX gELiZP7jrJAzJSX2NV2kRXE5hSwlHi3bxpYvRBQzeP5zVC2gkTH9GNQvYISJ2c+YYHYJSFx8M UL5gmMvLOQpGYhSS1gZFrFqFGcWlSWWqRraKqXVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKy XnJ+7iREYPAxAsIPx27KAQ4ySHExKorzrVzBECvEl5adUZiQWZ8QXleakFh9ilOHgUJLg/XYQ KCdYlJqeWpGWmQMMY5i0BAePkgjvH5A0b3FBYm5xZjpE6hSjopQ4r+ohoIQASCKjNA+uDRY7l xhlpYR5GYEOEeIpSC3KzSxBlX/FKM7BqCTMywwyhSczrwRu+iugxUxAi1lcwBaXJCKkpBoYK6 YWJavrViZ+O3/TTmaf/mGjLNUcvmc37I/UGV99aVN0d8ODVzvLTWY9q78V0cda4yXboHHJN+y 1cdZ8099Pw4KPvRLwvvewzixX5WjitMfuL2o2RcQzlXTEsARGN+5VcGvf9czmbGVxnO1/g8aj 2s/YtfuyL1t9Xahwetm7mPi+9LlXbdmVWIozEg21mIuKEwF7QhGImAIAAA== X-Env-Sender: prvs=28229795a=wei.liu2@citrix.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1493222214!51548280!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57194 invoked from network); 26 Apr 2017 15:56:56 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-2.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 26 Apr 2017 15:56:56 -0000 X-IronPort-AV: E=Sophos;i="5.37,255,1488844800"; d="scan'208";a="421143113" From: Wei Liu To: Xen-devel Date: Wed, 26 Apr 2017 16:54:47 +0100 Message-ID: <20170426155457.10799-3-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 02/12] x86/domain: provide pv_{create, destroy}_gdt_ldt_l1tab and use them 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 This patch encapsulates the perdomain creation and destruction into helper functions and use them where appropriate. Since destroy_perdomain_mapping is idempotent, it is safe to call the destruction function multiple times. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- v2: new v3: use 1U and eliminate d as parameter Cc: Jan Beulich Cc: Andrew Cooper --- xen/arch/x86/domain.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 90e2b1f82a..31ef4c0293 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -387,6 +387,20 @@ int switch_compat(struct domain *d) return rc; } +static int pv_create_gdt_ldt_l1tab(struct vcpu *v) +{ + return create_perdomain_mapping(v->domain, GDT_VIRT_START(v), + 1U << GDT_LDT_VCPU_SHIFT, + v->domain->arch.pv_domain.gdt_ldt_l1tab, + NULL); +} + +static void pv_destroy_gdt_ldt_l1tab(struct vcpu *v) +{ + destroy_perdomain_mapping(v->domain, GDT_VIRT_START(v), + 1U << GDT_LDT_VCPU_SHIFT); +} + int vcpu_initialise(struct vcpu *v) { struct domain *d = v->domain; @@ -423,9 +437,7 @@ int vcpu_initialise(struct vcpu *v) if ( !is_idle_domain(d) ) { - rc = create_perdomain_mapping(d, GDT_VIRT_START(v), - 1 << GDT_LDT_VCPU_SHIFT, - d->arch.pv_domain.gdt_ldt_l1tab, NULL); + rc = pv_create_gdt_ldt_l1tab(v); if ( rc ) goto done; @@ -435,6 +447,7 @@ int vcpu_initialise(struct vcpu *v) NR_VECTORS); if ( !v->arch.pv_vcpu.trap_ctxt ) { + pv_destroy_gdt_ldt_l1tab(v); rc = -ENOMEM; goto done; } @@ -464,7 +477,10 @@ int vcpu_initialise(struct vcpu *v) 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); @@ -491,7 +507,10 @@ void vcpu_destroy(struct vcpu *v) if ( is_hvm_vcpu(v) ) hvm_vcpu_destroy(v); else + { + pv_destroy_gdt_ldt_l1tab(v); xfree(v->arch.pv_vcpu.trap_ctxt); + } } static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)