From nobody Mon Feb 9 12:26:11 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1557125912; cv=none; d=zoho.com; s=zohoarc; b=GhCBho+GXlKvDIZojuC9PBTxr+1CSmNkINi5YQNuWKIzM9YBc1gNz7jfs5GtgvuEysaKMiszruim/Vczjszy2iOCqTNjKiLQSRqRMK7Ncs3al7dyacOLVrNxt3ubo++7M9089MJdXy41aXFFHys8MMgCfSq5z5Sb0I4D8+u7qz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557125912; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gtoU8zI9xqHWpXpJPH7PE46rNx2p18fykc5WnTvARsM=; b=KV8DatP1riIcyuX7W6Fb/EFiAd0C7bVSYmu77wWWIgTAhqqTO4fMf/ZyL1Voo7PFMkBjg2rOg3FaHqMjw2llDk8I+8vaKnKDih+4tehjHGXiVuhXflydWKA3sMeuDv5UfV9O56+a0u+HSIu2fIUIlcGTypV+8SkRjtUVt6ibMaE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1557125912978505.7570127786255; Sun, 5 May 2019 23:58:32 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hNXYt-0002XM-EA; Mon, 06 May 2019 06:57:19 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hNXYk-0002Cl-5u for xen-devel@lists.xenproject.org; Mon, 06 May 2019 06:57:10 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 271b43fa-6fcc-11e9-843c-bc764e045a96; Mon, 06 May 2019 06:57:03 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B9250AF3E; Mon, 6 May 2019 06:56:58 +0000 (UTC) X-Inumbo-ID: 271b43fa-6fcc-11e9-843c-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 6 May 2019 08:56:36 +0200 Message-Id: <20190506065644.7415-38-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190506065644.7415-1-jgross@suse.com> References: <20190506065644.7415-1-jgross@suse.com> Subject: [Xen-devel] [PATCH RFC V2 37/45] 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=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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) --- xen/arch/x86/domain.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 72a365ff6a..d04e704116 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -72,6 +72,8 @@ =20 DEFINE_PER_CPU(struct vcpu *, curr_vcpu); =20 +static DEFINE_PER_CPU(bool, full_gdt_loaded); + static void default_idle(void); void (*pm_idle) (void) __read_mostly =3D default_idle; void (*dead_idle) (void) __read_mostly =3D default_dead_idle; @@ -1638,6 +1640,8 @@ static inline void load_full_gdt(struct vcpu *v, unsi= gned int cpu) gdt_desc.base =3D GDT_VIRT_START(v); =20 lgdt(&gdt_desc); + + per_cpu(full_gdt_loaded, cpu) =3D true; } =20 static inline void load_default_gdt(seg_desc_t *gdt, unsigned int cpu) @@ -1648,6 +1652,8 @@ static inline void load_default_gdt(seg_desc_t *gdt, = unsigned int cpu) gdt_desc.base =3D (unsigned long)(gdt - FIRST_RESERVED_GDT_ENTRY); =20 lgdt(&gdt_desc); + + per_cpu(full_gdt_loaded, cpu) =3D false; } =20 static void __context_switch(void) @@ -1658,6 +1664,7 @@ static void __context_switch(void) struct vcpu *n =3D current; struct domain *pd =3D p->domain, *nd =3D n->domain; seg_desc_t *gdt; + bool need_full_gdt_n; =20 ASSERT(p !=3D n); ASSERT(!vcpu_cpu_dirty(n)); @@ -1700,11 +1707,13 @@ static void __context_switch(void) gdt =3D !is_pv_32bit_domain(nd) ? per_cpu(gdt_table, cpu) : per_cpu(compat_gdt_table, cpu); =20 - if ( need_full_gdt(nd) ) + need_full_gdt_n =3D need_full_gdt(nd); + + if ( need_full_gdt_n ) write_full_gdt_ptes(gdt, n); =20 - if ( need_full_gdt(pd) && - ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt(nd)) ) + if ( per_cpu(full_gdt_loaded, cpu) && + ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt_n) ) load_default_gdt(gdt, cpu); =20 write_ptbase(n); @@ -1716,8 +1725,7 @@ static void __context_switch(void) svm_load_segs(0, 0, 0, 0, 0, 0, 0); #endif =20 - if ( need_full_gdt(nd) && - ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt(pd)) ) + if ( need_full_gdt_n && !per_cpu(full_gdt_loaded, cpu) ) load_full_gdt(n, cpu); =20 if ( pd !=3D nd ) --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel