]>
Commit | Line | Data |
---|---|---|
00e5a55c BS |
1 | From: Alok Kataria <akataria@vmware.com> |
2 | Subject: x86: Hypervisor detection and get tsc_freq from hypervisor | |
3 | Patch-mainline: | |
4 | References: bnc#441338 | |
5 | ||
6 | Impact: Changes timebase calibration on Vmware. | |
7 | ||
8 | v3->v2 : Abstract the hypervisor detection and feature (tsc_freq) request | |
9 | behind a hypervisor.c file | |
10 | v2->v1 : Add a x86_hyper_vendor field to the cpuinfo_x86 structure. | |
11 | This avoids multiple calls to the hypervisor detection function. | |
12 | ||
13 | This patch adds function to detect if we are running under VMware. | |
14 | The current way to check if we are on VMware is following, | |
15 | # check if "hypervisor present bit" is set, if so read the 0x40000000 | |
16 | cpuid leaf and check for "VMwareVMware" signature. | |
17 | # if the above fails, check the DMI vendors name for "VMware" string | |
18 | if we find one we query the VMware hypervisor port to check if we are | |
19 | under VMware. | |
20 | ||
21 | The DMI + "VMware hypervisor port check" is needed for older VMware products, | |
22 | which don't implement the hypervisor signature cpuid leaf. | |
23 | Also note that since we are checking for the DMI signature the hypervisor | |
24 | port should never be accessed on native hardware. | |
25 | ||
26 | This patch also adds a hypervisor_get_tsc_freq function, instead of | |
27 | calibrating the frequency which can be error prone in virtualized | |
28 | environment, we ask the hypervisor for it. We get the frequency from | |
29 | the hypervisor by accessing the hypervisor port if we are running on VMware. | |
30 | Other hypervisors too can add code to the generic routine to get frequency on | |
31 | their platform. | |
32 | ||
33 | Signed-off-by: Alok N Kataria <akataria@vmware.com> | |
34 | Signed-off-by: Dan Hecht <dhecht@vmware.com> | |
35 | Signed-off-by: H. Peter Anvin <hpa@zytor.com> | |
36 | Signed-off-by: Takashi Iwai <tiwai@suse.de> | |
37 | ||
38 | Automatically created from "patches.arch/x86-vmware-tsc-03-detect-from-hypervisor" by xen-port-patches.py | |
39 | ||
40 | --- sle11-2009-03-04.orig/arch/x86/kernel/cpu/Makefile 2009-03-12 16:02:36.000000000 +0100 | |
41 | +++ sle11-2009-03-04/arch/x86/kernel/cpu/Makefile 2009-02-16 17:03:24.000000000 +0100 | |
42 | @@ -23,3 +23,5 @@ obj-$(CONFIG_MTRR) += mtrr/ | |
43 | obj-$(CONFIG_CPU_FREQ) += cpufreq/ | |
44 | ||
45 | obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o | |
46 | + | |
47 | +disabled-obj-$(CONFIG_XEN) := hypervisor.o vmware.o | |
48 | --- sle11-2009-03-04.orig/arch/x86/kernel/cpu/common-xen.c 2009-03-04 11:29:03.000000000 +0100 | |
49 | +++ sle11-2009-03-04/arch/x86/kernel/cpu/common-xen.c 2009-02-16 17:03:24.000000000 +0100 | |
50 | @@ -14,6 +14,7 @@ | |
51 | #include <asm/mce.h> | |
52 | #include <asm/pat.h> | |
53 | #include <asm/asm.h> | |
54 | +#include <asm/hypervisor.h> | |
55 | #ifdef CONFIG_X86_LOCAL_APIC | |
56 | #include <asm/mpspec.h> | |
57 | #include <asm/apic.h> | |
58 | @@ -514,6 +515,7 @@ static void __cpuinit identify_cpu(struc | |
59 | c->x86, c->x86_model); | |
60 | } | |
61 | ||
62 | + init_hypervisor(c); | |
63 | /* | |
64 | * On SMP, boot_cpu_data holds the common feature set between | |
65 | * all CPUs; so make sure that we indicate which features are | |
66 | --- sle11-2009-03-04.orig/arch/x86/kernel/cpu/common_64-xen.c 2009-03-04 11:29:03.000000000 +0100 | |
67 | +++ sle11-2009-03-04/arch/x86/kernel/cpu/common_64-xen.c 2009-02-16 17:03:24.000000000 +0100 | |
68 | @@ -36,6 +36,7 @@ | |
69 | #include <asm/sections.h> | |
70 | #include <asm/setup.h> | |
71 | #include <asm/genapic.h> | |
72 | +#include <asm/hypervisor.h> | |
73 | ||
74 | #include "cpu.h" | |
75 | ||
76 | @@ -399,6 +400,7 @@ static void __cpuinit identify_cpu(struc | |
77 | ||
78 | detect_ht(c); | |
79 | ||
80 | + init_hypervisor(c); | |
81 | /* | |
82 | * On SMP, boot_cpu_data holds the common feature set between | |
83 | * all CPUs; so make sure that we indicate which features are | |
84 | --- sle11-2009-03-04.orig/arch/x86/kernel/setup-xen.c 2008-12-23 09:40:12.000000000 +0100 | |
85 | +++ sle11-2009-03-04/arch/x86/kernel/setup-xen.c 2009-02-16 17:03:24.000000000 +0100 | |
86 | @@ -98,6 +98,7 @@ | |
87 | ||
88 | #include <mach_apic.h> | |
89 | #include <asm/paravirt.h> | |
90 | +#include <asm/hypervisor.h> | |
91 | ||
92 | #include <asm/percpu.h> | |
93 | #include <asm/topology.h> | |
94 | @@ -1120,6 +1121,12 @@ void __init setup_arch(char **cmdline_p) | |
95 | e820_reserve_resources(); | |
96 | #endif | |
97 | ||
98 | + /* | |
99 | + * VMware detection requires dmi to be available, so this | |
100 | + * needs to be done after dmi_scan_machine, for the BP. | |
101 | + */ | |
102 | + init_hypervisor(&boot_cpu_data); | |
103 | + | |
104 | #ifdef CONFIG_X86_32 | |
105 | request_resource(&iomem_resource, &video_ram_resource); | |
106 | #endif | |
107 | --- sle11-2009-03-04.orig/include/asm-x86/hypervisor.h 2009-03-12 16:02:36.000000000 +0100 | |
108 | +++ sle11-2009-03-04/include/asm-x86/hypervisor.h 2009-02-16 17:03:24.000000000 +0100 | |
109 | @@ -24,3 +24,7 @@ extern unsigned long get_hypervisor_tsc_ | |
110 | extern void init_hypervisor(struct cpuinfo_x86 *c); | |
111 | ||
112 | #endif | |
113 | + | |
114 | +#ifdef HAVE_XEN_PLATFORM_COMPAT_H | |
115 | +#include_next <asm/hypervisor.h> | |
116 | +#endif | |
117 | --- sle11-2009-03-04.orig/include/asm-x86/mach-xen/asm/hypervisor.h 2009-03-12 16:27:52.000000000 +0100 | |
118 | +++ sle11-2009-03-04/include/asm-x86/mach-xen/asm/hypervisor.h 2009-03-12 16:42:09.000000000 +0100 | |
119 | @@ -67,6 +67,8 @@ extern start_info_t *xen_start_info; | |
120 | #define is_initial_xendomain() 0 | |
121 | #endif | |
122 | ||
123 | +#define init_hypervisor(c) ((void)((c)->x86_hyper_vendor = X86_HYPER_VENDOR_XEN)) | |
124 | + | |
125 | /* arch/xen/kernel/evtchn.c */ | |
126 | /* Force a proper event-channel callback from Xen. */ | |
127 | void force_evtchn_callback(void); | |
128 | --- sle11-2009-03-04.orig/include/asm-x86/mach-xen/asm/processor.h 2009-03-12 00:00:00.000000000 +0100 | |
129 | +++ sle11-2009-03-04/include/asm-x86/mach-xen/asm/processor.h 2009-02-16 17:03:24.000000000 +0100 | |
130 | @@ -110,6 +110,7 @@ struct cpuinfo_x86 { | |
131 | /* Index into per_cpu list: */ | |
132 | u16 cpu_index; | |
133 | #endif | |
134 | + unsigned int x86_hyper_vendor; | |
135 | } __attribute__((__aligned__(SMP_CACHE_BYTES))); | |
136 | ||
137 | #define X86_VENDOR_INTEL 0 | |
138 | @@ -123,6 +124,10 @@ struct cpuinfo_x86 { | |
139 | ||
140 | #define X86_VENDOR_UNKNOWN 0xff | |
141 | ||
142 | +#define X86_HYPER_VENDOR_NONE 0 | |
143 | +#define X86_HYPER_VENDOR_VMWARE 1 | |
144 | +#define X86_HYPER_VENDOR_XEN 'X' | |
145 | + | |
146 | /* | |
147 | * capabilities of CPUs | |
148 | */ |