All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Fitzhardinge <jeremy@goop.org>
To: bderzhavets@yahoo.com
Cc: xen-devel@lists.xensource.com, "Marc - A. Dahlhaus" <mad@wol.de>
Subject: Re: Failure to load 2.6.29-rc7 under Xen Unstable on Q9550 & ASUS P5Q-E box
Date: Sat, 07 Mar 2009 17:12:26 -0800	[thread overview]
Message-ID: <49B31B7A.1010408@goop.org> (raw)
In-Reply-To: <711557.25237.qm@web56103.mail.re3.yahoo.com>

Boris, Marc,

Does this (completely untested) patch help?

    J

>From b1c3f75e22eef9077caf5204f0c75e5ca0c808e9 Mon Sep 17 00:00:00 2001
From: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Date: Sat, 7 Mar 2009 17:09:27 -0800
Subject: [PATCH] xen: mask XSAVE from cpuid

Xen leaves XSAVE set in cpuid, but doesn't allow cr4.OSXSAVE
to be set.  This confuses the kernel and it ends up crashing on
an xsetbv instruction.

At boot time, try to set cr4.OSXSAVE, and mask XSAVE out of
cpuid it we can't.  This will produce a spurious error from Xen,
but allows us to support XSAVE if/when Xen does.

This also factors out the cpuid mask decisions to boot time.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>

diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index fd184f3..4e16b54 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -175,25 +175,22 @@ static void __init xen_banner(void)
 	       xen_initial_domain() ? " (dom0)" : "");
 }
 
+static __read_mostly unsigned int cpuid_leaf1_edx_mask = ~0;
+static __read_mostly unsigned int cpuid_leaf1_ecx_mask = ~0;
+
 static void xen_cpuid(unsigned int *ax, unsigned int *bx,
 		      unsigned int *cx, unsigned int *dx)
 {
-	unsigned maskedx = 0;
+	unsigned maskecx = ~0;
+	unsigned maskedx = ~0;
 
 	/*
 	 * Mask out inconvenient features, to try and disable as many
 	 * unsupported kernel subsystems as possible.
 	 */
 	if (*ax == 1) {
-		maskedx =
-			(1 << X86_FEATURE_MCE)  |  /* disable MCE */
-			(1 << X86_FEATURE_MCA)  |  /* disable MCA */
-			(1 << X86_FEATURE_ACC);   /* thermal monitoring */
-
-		if (!xen_initial_domain())
-			maskedx |=
-				(1 << X86_FEATURE_APIC) |  /* disable local APIC */
-				(1 << X86_FEATURE_ACPI);  /* disable ACPI */
+		maskecx = cpuid_leaf1_ecx_mask;
+		maskedx = cpuid_leaf1_edx_mask;
 	}
 
 	asm(XEN_EMULATE_PREFIX "cpuid"
@@ -202,7 +199,41 @@ static void xen_cpuid(unsigned int *ax, unsigned int *bx,
 		  "=c" (*cx),
 		  "=d" (*dx)
 		: "0" (*ax), "2" (*cx));
-	*dx &= ~maskedx;
+
+	*cx &= maskecx;
+	*dx &= maskedx;
+}
+
+static __init void xen_init_cpuid_mask(void)
+{
+	unsigned int ax, bx, cx, dx;
+
+	cpuid_leaf1_edx_mask =
+		~((1 << X86_FEATURE_MCE)  |  /* disable MCE */
+		  (1 << X86_FEATURE_MCA)  |  /* disable MCA */
+		  (1 << X86_FEATURE_ACC));   /* thermal monitoring */
+
+	if (!xen_initial_domain())
+		cpuid_leaf1_edx_mask &=
+			~((1 << X86_FEATURE_APIC) |  /* disable local APIC */
+			  (1 << X86_FEATURE_ACPI));  /* disable ACPI */
+
+	ax = 1;
+	xen_cpuid(&ax, &bx, &cx, &dx);
+
+	/* cpuid claims we support xsave; try enabling it to see what happens */
+	if (cx & (1 << (X86_FEATURE_XSAVE % 32))) {
+		unsigned long cr4;
+
+		set_in_cr4(X86_CR4_OSXSAVE);
+		
+		cr4 = read_cr4();
+
+		if ((cr4 & X86_CR4_OSXSAVE) == 0)
+			cpuid_leaf1_ecx_mask &= ~(1 << (X86_FEATURE_XSAVE % 32));
+
+		clear_in_cr4(X86_CR4_OSXSAVE);
+	}
 }
 
 static void xen_set_debugreg(int reg, unsigned long val)
@@ -927,6 +958,8 @@ asmlinkage void __init xen_start_kernel(void)
 
 	xen_init_irq_ops();
 
+	xen_init_cpuid_mask();
+
 #ifdef CONFIG_X86_LOCAL_APIC
 	/*
 	 * set up the basic apic ops.

  reply	other threads:[~2009-03-08  1:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-06 23:34 pv_ops dom0 kernel test Marc - A. Dahlhaus
2009-03-07  0:20 ` Jeremy Fitzhardinge
2009-03-07 10:13   ` Marc - A. Dahlhaus
2009-03-07 10:39     ` Failure to load 2.6.29-rc7 under Xen Unstable on Q9550 & ASUS P5Q-E box Boris Derzhavets
2009-03-08  1:12       ` Jeremy Fitzhardinge [this message]
2009-03-08  9:33         ` Marc - A. Dahlhaus
2009-03-07 10:46     ` Attempt " Boris Derzhavets
  -- strict thread matches above, loose matches on Subject: below --
2009-03-07 18:06 Failure " Jeremy Fitzhardinge

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=49B31B7A.1010408@goop.org \
    --to=jeremy@goop.org \
    --cc=bderzhavets@yahoo.com \
    --cc=mad@wol.de \
    --cc=xen-devel@lists.xensource.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.