From patchwork Tue May 28 10:32:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 10964663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 642E692A for ; Tue, 28 May 2019 10:35:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 526692863F for ; Tue, 28 May 2019 10:35:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46FA1285C9; Tue, 28 May 2019 10:35:39 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C2E032839C for ; Tue, 28 May 2019 10:35:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hVZQk-00061Y-MC; Tue, 28 May 2019 10:34:06 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hVZQD-0004rh-TP for xen-devel@lists.xenproject.org; Tue, 28 May 2019 10:33:33 +0000 X-Inumbo-ID: 071abf92-8134-11e9-8144-97777117baca Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 071abf92-8134-11e9-8144-97777117baca; Tue, 28 May 2019 10:33:27 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A79BBB040; Tue, 28 May 2019 10:33:26 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Tue, 28 May 2019 12:32:52 +0200 Message-Id: <20190528103313.1343-40-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190528103313.1343-1-jgross@suse.com> References: <20190528103313.1343-1-jgross@suse.com> Subject: [Xen-devel] [PATCH 39/60] x86: optimize loading of GDT at context switch X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Andrew Cooper , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of dynamically decide whether the previous vcpu was using full or default GDT just add a percpu variable for that purpose. This at once removes the need for testing vcpu_ids to differ twice. Cache the need_full_gdt(nd) value in a local variable. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- RFC V2: new patch (split from previous one) V1: init percpu flag at cpu startup rename variable (Jan Beulich) --- xen/arch/x86/cpu/common.c | 3 +++ xen/arch/x86/domain.c | 16 +++++++++++----- xen/include/asm-x86/desc.h | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index 33f5d32557..8b90356fe5 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -49,6 +49,8 @@ unsigned int vaddr_bits __read_mostly = VADDR_BITS; static unsigned int cleared_caps[NCAPINTS]; static unsigned int forced_caps[NCAPINTS]; +DEFINE_PER_CPU(bool, full_gdt_loaded); + void __init setup_clear_cpu_cap(unsigned int cap) { const uint32_t *dfs; @@ -745,6 +747,7 @@ void load_system_tables(void) offsetof(struct tss_struct, __cacheline_filler) - 1, SYS_DESC_tss_busy); + per_cpu(full_gdt_loaded, cpu) = false; lgdt(&gdtr); lidt(&idtr); ltr(TSS_ENTRY << 3); diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index adc06154ee..98d2939daf 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1645,6 +1645,8 @@ static inline void load_full_gdt(const struct vcpu *v, unsigned int cpu) }; lgdt(&gdt_desc); + + per_cpu(full_gdt_loaded, cpu) = true; } static inline void load_default_gdt(const seg_desc_t *gdt, unsigned int cpu) @@ -1655,6 +1657,8 @@ static inline void load_default_gdt(const seg_desc_t *gdt, unsigned int cpu) }; lgdt(&gdt_desc); + + per_cpu(full_gdt_loaded, cpu) = false; } static void __context_switch(void) @@ -1665,6 +1669,7 @@ static void __context_switch(void) struct vcpu *n = current; struct domain *pd = p->domain, *nd = n->domain; seg_desc_t *gdt; + bool full_gdt; ASSERT(p != n); ASSERT(!vcpu_cpu_dirty(n)); @@ -1707,11 +1712,13 @@ static void __context_switch(void) gdt = !is_pv_32bit_domain(nd) ? per_cpu(gdt_table, cpu) : per_cpu(compat_gdt_table, cpu); - if ( need_full_gdt(nd) ) + full_gdt = need_full_gdt(nd); + + if ( full_gdt ) write_full_gdt_ptes(gdt, n); - if ( need_full_gdt(pd) && - ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(nd)) ) + if ( per_cpu(full_gdt_loaded, cpu) && + ((p->vcpu_id != n->vcpu_id) || !full_gdt) ) load_default_gdt(gdt, cpu); write_ptbase(n); @@ -1723,8 +1730,7 @@ static void __context_switch(void) svm_load_segs(0, 0, 0, 0, 0, 0, 0); #endif - if ( need_full_gdt(nd) && - ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(pd)) ) + if ( full_gdt && !per_cpu(full_gdt_loaded, cpu) ) load_full_gdt(n, cpu); if ( pd != nd ) diff --git a/xen/include/asm-x86/desc.h b/xen/include/asm-x86/desc.h index 85e83bcefb..ff9ac5f15d 100644 --- a/xen/include/asm-x86/desc.h +++ b/xen/include/asm-x86/desc.h @@ -208,6 +208,7 @@ extern seg_desc_t boot_cpu_gdt_table[]; DECLARE_PER_CPU(seg_desc_t *, gdt_table); extern seg_desc_t boot_cpu_compat_gdt_table[]; DECLARE_PER_CPU(seg_desc_t *, compat_gdt_table); +DECLARE_PER_CPU(bool, full_gdt_loaded); extern void load_TR(void);