From nobody Mon Feb 9 06:49:19 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=1557125917; cv=none; d=zoho.com; s=zohoarc; b=Ome3E2JkV5UwingBS3BgbWv0UgrRDaCxksuX7fB0t4PRVExFGndv1v4yzoXr3uAARKSPxXI6es6mcrYEInRYJPi17pok4AH2Ss16sskWWGEU9m52LO7sYDWQkPCPBnynveDIPaeySxYXx+AE/KSjg4Z6UTvKcyI01nf2WbB8kSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557125917; 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=7UBYupyfwfHPgZIfFj01l6K7oF+qdxyJcHYT2iRSpS0=; b=KYg0u5JrpSR4NyLzVm7jLIKG5yhuLFh7tqEuKjlPoxN9Nm5HvrsvRlZnN+/TY+3d/0+6jfwjP4st+khaTGAXbkC3vJg8G4CqoncX+1cAGCn4MTBVoSLgLG8XzpsQmm91xxkrujMg+AbelQq74e5Nmgqx8oZR/e8u4JcWcyz999k= 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 155712591752699.71155201874194; Sun, 5 May 2019 23:58:37 -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 1hNXYv-0002c9-1C; Mon, 06 May 2019 06:57:21 +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 1hNXYl-0002FD-B7 for xen-devel@lists.xenproject.org; Mon, 06 May 2019 06:57:11 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 26ebd8d4-6fcc-11e9-9cee-1bf5b8f7eaa9; 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 8B1B3AF3B; Mon, 6 May 2019 06:56:58 +0000 (UTC) X-Inumbo-ID: 26ebd8d4-6fcc-11e9-9cee-1bf5b8f7eaa9 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:35 +0200 Message-Id: <20190506065644.7415-37-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 36/45] x86: make loading of GDT at context switch more modular 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" In preparation for core scheduling carve out the GDT related functionality (writing GDT related PTEs, loading default of full GDT) into sub-functions. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- RFC V2: split off non-refactoring part --- xen/arch/x86/domain.c | 57 +++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 1525ccd8e5..72a365ff6a 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1619,6 +1619,37 @@ static inline bool need_full_gdt(const struct domain= *d) return is_pv_domain(d) && !is_idle_domain(d); } =20 +static inline void write_full_gdt_ptes(seg_desc_t *gdt, struct vcpu *v) +{ + unsigned long mfn =3D virt_to_mfn(gdt); + l1_pgentry_t *pl1e =3D pv_gdt_ptes(v); + unsigned int i; + + for ( i =3D 0; i < NR_RESERVED_GDT_PAGES; i++ ) + l1e_write(pl1e + FIRST_RESERVED_GDT_PAGE + i, + l1e_from_pfn(mfn + i, __PAGE_HYPERVISOR_RW)); +} + +static inline void load_full_gdt(struct vcpu *v, unsigned int cpu) +{ + struct desc_ptr gdt_desc; + + gdt_desc.limit =3D LAST_RESERVED_GDT_BYTE; + gdt_desc.base =3D GDT_VIRT_START(v); + + lgdt(&gdt_desc); +} + +static inline void load_default_gdt(seg_desc_t *gdt, unsigned int cpu) +{ + struct desc_ptr gdt_desc; + + gdt_desc.limit =3D LAST_RESERVED_GDT_BYTE; + gdt_desc.base =3D (unsigned long)(gdt - FIRST_RESERVED_GDT_ENTRY); + + lgdt(&gdt_desc); +} + static void __context_switch(void) { struct cpu_user_regs *stack_regs =3D guest_cpu_user_regs(); @@ -1627,7 +1658,6 @@ static void __context_switch(void) struct vcpu *n =3D current; struct domain *pd =3D p->domain, *nd =3D n->domain; seg_desc_t *gdt; - struct desc_ptr gdt_desc; =20 ASSERT(p !=3D n); ASSERT(!vcpu_cpu_dirty(n)); @@ -1669,25 +1699,13 @@ static void __context_switch(void) =20 gdt =3D !is_pv_32bit_domain(nd) ? per_cpu(gdt_table, cpu) : per_cpu(compat_gdt_table, cpu); - if ( need_full_gdt(nd) ) - { - unsigned long mfn =3D virt_to_mfn(gdt); - l1_pgentry_t *pl1e =3D pv_gdt_ptes(n); - unsigned int i; =20 - for ( i =3D 0; i < NR_RESERVED_GDT_PAGES; i++ ) - l1e_write(pl1e + FIRST_RESERVED_GDT_PAGE + i, - l1e_from_pfn(mfn + i, __PAGE_HYPERVISOR_RW)); - } + if ( need_full_gdt(nd) ) + write_full_gdt_ptes(gdt, n); =20 if ( need_full_gdt(pd) && ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt(nd)) ) - { - gdt_desc.limit =3D LAST_RESERVED_GDT_BYTE; - gdt_desc.base =3D (unsigned long)(gdt - FIRST_RESERVED_GDT_ENTRY); - - lgdt(&gdt_desc); - } + load_default_gdt(gdt, cpu); =20 write_ptbase(n); =20 @@ -1700,12 +1718,7 @@ static void __context_switch(void) =20 if ( need_full_gdt(nd) && ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt(pd)) ) - { - gdt_desc.limit =3D LAST_RESERVED_GDT_BYTE; - gdt_desc.base =3D GDT_VIRT_START(n); - - lgdt(&gdt_desc); - } + load_full_gdt(n, cpu); =20 if ( pd !=3D nd ) cpumask_clear_cpu(cpu, pd->dirty_cpumask); --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel