[PATCH] [19/50] Experimental: detect if SVM is disabled by BIOS

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <patches@...>, <linux-kernel@...>
Date: Friday, September 21, 2007 - 6:32 pm

Also allow to set svm lock.

TBD double check, documentation, i386 support

Signed-off-by: Andi Kleen <ak@suse.de>

---
 arch/x86_64/kernel/setup.c    |   25 +++++++++++++++++++++++--
 include/asm-i386/cpufeature.h |    1 +
 include/asm-i386/msr-index.h  |    3 +++
 3 files changed, 27 insertions(+), 2 deletions(-)

Index: linux/arch/x86_64/kernel/setup.c
===================================================================
--- linux.orig/arch/x86_64/kernel/setup.c
+++ linux/arch/x86_64/kernel/setup.c
@@ -565,7 +565,7 @@ static void __cpuinit early_init_amd(str
 
 static void __cpuinit init_amd(struct cpuinfo_x86 *c)
 {
-	unsigned level;
+	unsigned level, flags, dummy;
 
 #ifdef CONFIG_SMP
 	unsigned long value;
@@ -634,7 +634,28 @@ static void __cpuinit init_amd(struct cp
 	/* Family 10 doesn't support C states in MWAIT so don't use it */
 	if (c->x86 == 0x10 && !force_mwait)
 		clear_bit(X86_FEATURE_MWAIT, &c->x86_capability);
+
+	if (c->x86 >= 0xf && c->x86 <= 0x11 &&
+	    !rdmsr_safe(MSR_VM_CR, &flags, &dummy) &&
+	    (flags & 0x18))
+		set_bit(X86_FEATURE_VIRT_DISABLED, &c->x86_capability);
+}
+
+static int enable_svm_lock(char *s)
+{
+	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+		boot_cpu_data.x86 >= 0xf && boot_cpu_data.x86 <= 0x11) {
+		unsigned a,b;
+		if (rdmsr_safe(MSR_VM_CR, &a, &b))
+			return 0;
+		a |= (1 << 3);	/* set SVM lock */
+		if (!wrmsr_safe(MSR_VM_CR, &a, &b))
+			return 1;
+	}
+	printk(KERN_ERR "CPU does not support svm_lock\n");
+	return 0;
 }
+__setup("svm_lock", enable_svm_lock);
 
 static void __cpuinit detect_ht(struct cpuinfo_x86 *c)
 {
@@ -985,7 +1006,7 @@ static int show_cpuinfo(struct seq_file 
 		NULL, NULL, NULL, NULL,
 		"constant_tsc", "up", NULL, "arch_perfmon",
 		"pebs", "bts", NULL, "sync_rdtsc",
-		"rep_good", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+		"rep_good", "virtualization_bios_disabled", NULL, NULL, NULL, NULL, NULL, NULL,
 		NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 
 		/* Intel-defined (#2) */
Index: linux/include/asm-i386/cpufeature.h
===================================================================
--- linux.orig/include/asm-i386/cpufeature.h
+++ linux/include/asm-i386/cpufeature.h
@@ -82,6 +82,7 @@
 /* 14 free */
 #define X86_FEATURE_SYNC_RDTSC	(3*32+15)  /* RDTSC synchronizes the CPU */
 #define X86_FEATURE_REP_GOOD   (3*32+16) /* rep microcode works well on this CPU */
+#define X86_FEATURE_VIRT_DISABLED (3*32+17) /* Hardware virt. BIOS disabled */
 
 /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
 #define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
Index: linux/include/asm-i386/msr-index.h
===================================================================
--- linux.orig/include/asm-i386/msr-index.h
+++ linux/include/asm-i386/msr-index.h
@@ -98,6 +98,9 @@
 #define K8_MTRRFIXRANGE_DRAM_MODIFY	0x00080000 /* MtrrFixDramModEn bit */
 #define K8_MTRR_RDMEM_WRMEM_MASK	0x18181818 /* Mask: RdMem|WrMem    */
 
+/* SVM */
+#define MSR_VM_CR       0xc0010114
+
 /* K7 MSRs */
 #define MSR_K7_EVNTSEL0			0xc0010000
 #define MSR_K7_PERFCTR0			0xc0010004
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] [0/50] x86 2.6.24 patches review II, Andi Kleen, (Fri Sep 21, 6:31 pm)
[PATCH] [50/50] x86_64: Remove fpu io port resource, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [42/50] i386: constify wd_ops, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [40/50] i386: Fix section mismatch, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [36/50] x86: Use raw locks during oopses, Andi Kleen, (Fri Sep 21, 6:32 pm)
Re: [PATCH] [34/50] i386: Fix argument signedness warnings, Jan Engelhardt, (Sat Sep 22, 6:01 am)
[PATCH] [30/50] x86_64: remove some dead code, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [28/50] i386: remove stub early_printk.c, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [22/50] i386: Misc cpuinit annotations, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [21/50] i386: Misc cpuinit annotations, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [19/50] Experimental: detect if SVM is disabled by B..., Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [17/50] x86_64: remove STR() macros, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [6/50] i386: clean up oops/bug reports, Andi Kleen, (Fri Sep 21, 6:32 pm)
Re: [PATCH] [6/50] i386: clean up oops/bug reports, Chuck Ebbert, (Fri Sep 21, 6:41 pm)
Re: [PATCH] [6/50] i386: clean up oops/bug reports, Jan Engelhardt, (Sat Sep 22, 5:47 am)
[PATCH] [8/50] x86_64: remove x86_cpu_to_log_apicid, Andi Kleen, (Fri Sep 21, 6:32 pm)
[PATCH] [5/50] i386: change order in Kconfig.cpu, Andi Kleen, (Fri Sep 21, 6:32 pm)
Re: [PATCH] [4/50] x86: add cpu codenames for Kconfig.cpu, Thomas Gleixner, (Sat Sep 22, 1:50 pm)
Re: [PATCH] [4/50] x86: add cpu codenames for Kconfig.cpu, Jan Engelhardt, (Sat Sep 22, 5:46 am)
[PATCH] [3/50] x86_64: remove never used apic_mapped, Andi Kleen, (Fri Sep 21, 6:32 pm)