xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org,
	boris.ostrovsky@oracle.com, david.vrabel@citrix.com,
	mukesh.rathor@oracle.com, jbeulich@suse.com
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH v11 06/12] xen/pvh: Load GDT/GS in early PV bootup code for BSP.
Date: Tue, 17 Dec 2013 15:51:37 -0500	[thread overview]
Message-ID: <1387313503-31362-7-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1387313503-31362-1-git-send-email-konrad.wilk@oracle.com>

From: Mukesh Rathor <mukesh.rathor@oracle.com>

During early bootup we start life using the Xen provided
GDT, which means that we are running with %cs segment set
to FLAT_KERNEL_CS (FLAT_RING3_CS64 0xe033, GDT index 261).

But for PVH we want to be use HVM type mechanism for
segment operations. As such we need to switch to the HVM
one and also reload ourselves with the __KERNEL_CS:eip
to run in the proper GDT and segment.

For HVM this is usually done in 'secondary_startup_64' in
(head_64.S) but since we are not taking that bootup
path (we start in PV - xen_start_kernel) we need to do
that in the early PV bootup paths.

For good measure we also zero out the %fs, %ds, and %es
(not strictly needed as Xen has already cleared them
for us). The %gs is loaded by 'switch_to_new_gdt'.

Signed-off-by: Mukesh Rathor <mukesh.rathor@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 arch/x86/xen/enlighten.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index c7341d0..0d13652 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1413,8 +1413,43 @@ static void __init xen_boot_params_init_edd(void)
  * we do this, we have to be careful not to call any stack-protected
  * function, which is most of the kernel.
  */
-static void __init xen_setup_stackprotector(void)
+static void __init xen_setup_gdt(void)
 {
+	if (xen_feature(XENFEAT_auto_translated_physmap)) {
+#ifdef CONFIG_X86_64
+		unsigned long dummy;
+
+		switch_to_new_gdt(0); /* GDT and GS set */
+
+		/* We are switching of the Xen provided GDT to our HVM mode
+		 * GDT. The new GDT has  __KERNEL_CS with CS.L = 1
+		 * and we are jumping to reload it.
+		 */
+		asm volatile ("pushq %0\n"
+			      "leaq 1f(%%rip),%0\n"
+			      "pushq %0\n"
+			      "lretq\n"
+			      "1:\n"
+			      : "=&r" (dummy) : "0" (__KERNEL_CS));
+
+		/*
+		 * While not needed, we also set the %es, %ds, and %fs
+		 * to zero. We don't care about %ss as it is NULL.
+		 * Strictly speaking this is not needed as Xen zeros those
+		 * out (and also MSR_FS_BASE, MSR_GS_BASE, MSR_KERNEL_GS_BASE)
+		 *
+		 * Linux zeros them in cpu_init() and in secondary_startup_64
+		 * (for BSP).
+		 */
+		loadsegment(es, 0);
+		loadsegment(ds, 0);
+		loadsegment(fs, 0);
+#else
+		/* PVH: TODO Implement. */
+		BUG();
+#endif
+		return;
+	}
 	pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
 	pv_cpu_ops.load_gdt = xen_load_gdt_boot;
 
@@ -1499,7 +1534,7 @@ asmlinkage void __init xen_start_kernel(void)
 	 * Set up kernel GDT and segment registers, mainly so that
 	 * -fstack-protector code can be executed.
 	 */
-	xen_setup_stackprotector();
+	xen_setup_gdt();
 
 	xen_init_irq_ops();
 	xen_init_cpuid_mask();
-- 
1.8.3.1

  parent reply	other threads:[~2013-12-17 20:51 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1387313503-31362-1-git-send-email-konrad.wilk@oracle.com>
2013-12-17 20:51 ` [PATCH v11 01/12] xen/p2m: Check for auto-xlat when doing mfn_to_local_pfn Konrad Rzeszutek Wilk
2013-12-18 14:10   ` Stefano Stabellini
2013-12-17 20:51 ` [PATCH v11 02/12] xen/pvh: Define what an PVH guest is Konrad Rzeszutek Wilk
2013-12-17 20:51 ` [PATCH v11 03/12] xen/pvh: Early bootup changes in PV code Konrad Rzeszutek Wilk
2013-12-18 14:27   ` Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1312181423380.8667@kaball.uk.xensource.com>
2013-12-18 14:58     ` Konrad Rzeszutek Wilk
     [not found]     ` <20131218145852.GC4934@phenom.dumpdata.com>
2013-12-18 15:05       ` Stefano Stabellini
2013-12-17 20:51 ` [PATCH v11 04/12] xen/pvh: Don't setup P2M tree Konrad Rzeszutek Wilk
2013-12-18 14:39   ` Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1312181428340.8667@kaball.uk.xensource.com>
2013-12-18 15:05     ` Konrad Rzeszutek Wilk
2013-12-17 20:51 ` [PATCH v11 05/12] xen/pvh: Update E820 to work with PVH Konrad Rzeszutek Wilk
2013-12-17 20:51 ` Konrad Rzeszutek Wilk [this message]
2013-12-17 20:51 ` [PATCH v11 07/12] xen/pvh: Secondary VCPU bringup (non-bootup CPUs) Konrad Rzeszutek Wilk
2013-12-17 20:51 ` [PATCH v11 08/12] xen/pvh: MMU changes for PVH Konrad Rzeszutek Wilk
2013-12-17 20:51 ` [PATCH v11 09/12] xen/pvh: Piggyback on PVHVM XenBus and event channels " Konrad Rzeszutek Wilk
2013-12-18 18:31   ` Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1312181827280.8667@kaball.uk.xensource.com>
2013-12-18 21:17     ` Konrad Rzeszutek Wilk
2013-12-31 18:56     ` Konrad Rzeszutek Wilk
     [not found]     ` <20131231185656.GB3129@phenom.dumpdata.com>
2014-01-03 15:04       ` Stefano Stabellini
     [not found]       ` <alpine.DEB.2.02.1401031501180.8667@kaball.uk.xensource.com>
2014-01-04  0:29         ` Mukesh Rathor
     [not found]     ` <20131218211739.GD11717@phenom.dumpdata.com>
2014-01-04  0:48       ` Mukesh Rathor
     [not found]       ` <20140103164800.00ef581c@mantra.us.oracle.com>
2014-01-05 17:18         ` Stefano Stabellini
2013-12-17 20:51 ` [PATCH v11 10/12] xen/pvh: Piggyback on PVHVM for grant driver Konrad Rzeszutek Wilk
2013-12-18 18:46   ` Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1312181831560.8667@kaball.uk.xensource.com>
2013-12-18 21:21     ` Konrad Rzeszutek Wilk
     [not found]     ` <20131218212150.GE11717@phenom.dumpdata.com>
2014-01-03 15:10       ` Stefano Stabellini
2013-12-17 20:51 ` [PATCH v11 11/12] xen/pvh: Disable PV code that does not work with PVH Konrad Rzeszutek Wilk
2013-12-17 20:51 ` [PATCH v11 12/12] xen/pvh: Support ParaVirtualized Hardware extensions Konrad Rzeszutek Wilk
2013-12-18 14:52   ` Stefano Stabellini
     [not found] ` <1387313503-31362-12-git-send-email-konrad.wilk@oracle.com>
2013-12-18 14:19   ` [PATCH v11 11/12] xen/pvh: Disable PV code that does not work with PVH Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1312181416230.8667@kaball.uk.xensource.com>
2013-12-18 14:56     ` Konrad Rzeszutek Wilk
     [not found]     ` <20131218145602.GA4934@phenom.dumpdata.com>
2013-12-18 15:22       ` Stefano Stabellini
     [not found] ` <1387313503-31362-3-git-send-email-konrad.wilk@oracle.com>
2013-12-18 14:22   ` [PATCH v11 02/12] xen/pvh: Define what an PVH guest is Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1312181421260.8667@kaball.uk.xensource.com>
2013-12-18 14:55     ` Stefano Stabellini
2013-12-18 14:57     ` Konrad Rzeszutek Wilk
     [not found]     ` <alpine.DEB.2.02.1312181453110.8667@kaball.uk.xensource.com>
2013-12-18 16:01       ` Ian Campbell
     [not found]       ` <1387382463.28680.52.camel@kazak.uk.xensource.com>
2013-12-18 16:58         ` Konrad Rzeszutek Wilk
     [not found]         ` <20131218165807.GB4630@phenom.dumpdata.com>
2013-12-18 17:03           ` Ian Campbell
     [not found] ` <1387313503-31362-9-git-send-email-konrad.wilk@oracle.com>
2013-12-18 14:48   ` [PATCH v11 08/12] xen/pvh: MMU changes for PVH Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1312181442050.8667@kaball.uk.xensource.com>
2013-12-18 15:10     ` Konrad Rzeszutek Wilk
     [not found]     ` <20131218151015.GE4934@phenom.dumpdata.com>
2013-12-18 15:15       ` Stefano Stabellini
     [not found] ` <1387313503-31362-6-git-send-email-konrad.wilk@oracle.com>
2013-12-18 18:25   ` [PATCH v11 05/12] xen/pvh: Update E820 to work with PVH Stefano Stabellini
     [not found]   ` <alpine.DEB.2.02.1312181813260.8667@kaball.uk.xensource.com>
2013-12-18 20:30     ` Konrad Rzeszutek Wilk
2013-12-18 23:44     ` Mukesh Rathor
     [not found]     ` <20131218154438.364f6d74@mantra.us.oracle.com>
2013-12-19 11:25       ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1387313503-31362-7-git-send-email-konrad.wilk@oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mukesh.rathor@oracle.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).