aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Borntraeger <borntraeger@de.ibm.com>2009-03-26 10:23:58 -0400
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2009-03-26 10:24:09 -0400
commit92e6ecf392fac3082653ac9d84b1bdf53d0ea160 (patch)
treef5169e11ecce5d6ac13b2b2bb99088bdd9fe03e4
parent702d9e584feb028ed7e2a6d2b103b8ea57622ff2 (diff)
[S390] Fix hypervisor detection for KVM
Currently we use the cpuid (via STIDP instruction) to recognize LPAR, z/VM and KVM. The architecture states, that bit 0-7 of STIDP returns all zero, and if STIDP is executed in a virtual machine, the VM operating system will replace bits 0-7 with FF. KVM should not use FE to distinguish z/VM from KVM for interested guests. The proper way to detect the hypervisor is the STSI (Store System Information) instruction, which return information about the hypervisors via function code 3, selector1=2, selector2=2. This patch changes the detection routine of Linux to use STSI instead of STIDP. This detection is earlier than bootmem, we have to use a static buffer. Since STSI expects a 4kb block (4kb aligned) this patch also changes the init.data alignment for s390. As this section will be freed during boot, this should be no problem. Patch is tested with LPAR, z/VM, KVM on LPAR, and KVM under z/VM. Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
-rw-r--r--arch/s390/include/asm/sysinfo.h1
-rw-r--r--arch/s390/kernel/early.c22
-rw-r--r--arch/s390/kernel/vmlinux.lds.S2
-rw-r--r--arch/s390/kvm/kvm-s390.c2
4 files changed, 17 insertions, 10 deletions
diff --git a/arch/s390/include/asm/sysinfo.h b/arch/s390/include/asm/sysinfo.h
index ad93212d9e16..9d70057d828c 100644
--- a/arch/s390/include/asm/sysinfo.h
+++ b/arch/s390/include/asm/sysinfo.h
@@ -100,6 +100,7 @@ struct sysinfo_3_2_2 {
100 char reserved_1[24]; 100 char reserved_1[24];
101 101
102 } vm[8]; 102 } vm[8];
103 char reserved_544[3552];
103}; 104};
104 105
105static inline int stsi(void *sysinfo, int fc, int sel1, int sel2) 106static inline int stsi(void *sysinfo, int fc, int sel1, int sel2)
diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index 2a2ca268b1dd..d61eb3334edf 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -6,6 +6,7 @@
6 * Heiko Carstens <heiko.carstens@de.ibm.com> 6 * Heiko Carstens <heiko.carstens@de.ibm.com>
7 */ 7 */
8 8
9#include <linux/compiler.h>
9#include <linux/init.h> 10#include <linux/init.h>
10#include <linux/errno.h> 11#include <linux/errno.h>
11#include <linux/string.h> 12#include <linux/string.h>
@@ -20,6 +21,7 @@
20#include <asm/processor.h> 21#include <asm/processor.h>
21#include <asm/sections.h> 22#include <asm/sections.h>
22#include <asm/setup.h> 23#include <asm/setup.h>
24#include <asm/sysinfo.h>
23#include <asm/cpcmd.h> 25#include <asm/cpcmd.h>
24#include <asm/sclp.h> 26#include <asm/sclp.h>
25#include "entry.h" 27#include "entry.h"
@@ -173,19 +175,21 @@ static noinline __init void init_kernel_storage_key(void)
173 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY); 175 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
174} 176}
175 177
178static __initdata struct sysinfo_3_2_2 vmms __aligned(PAGE_SIZE);
179
176static noinline __init void detect_machine_type(void) 180static noinline __init void detect_machine_type(void)
177{ 181{
178 struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data; 182 /* No VM information? Looks like LPAR */
179 183 if (stsi(&vmms, 3, 2, 2) == -ENOSYS)
180 get_cpu_id(&S390_lowcore.cpu_data.cpu_id); 184 return;
181 185 if (!vmms.count)
182 /* Running under z/VM ? */ 186 return;
183 if (cpuinfo->cpu_id.version == 0xff)
184 machine_flags |= MACHINE_FLAG_VM;
185 187
186 /* Running under KVM ? */ 188 /* Running under KVM? If not we assume z/VM */
187 if (cpuinfo->cpu_id.version == 0xfe) 189 if (!memcmp(vmms.vm[0].cpi, "\xd2\xe5\xd4", 3))
188 machine_flags |= MACHINE_FLAG_KVM; 190 machine_flags |= MACHINE_FLAG_KVM;
191 else
192 machine_flags |= MACHINE_FLAG_VM;
189} 193}
190 194
191static __init void early_pgm_check_handler(void) 195static __init void early_pgm_check_handler(void)
diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S
index d796d05c9c01..7a2063eb88f0 100644
--- a/arch/s390/kernel/vmlinux.lds.S
+++ b/arch/s390/kernel/vmlinux.lds.S
@@ -108,6 +108,8 @@ SECTIONS
108 EXIT_TEXT 108 EXIT_TEXT
109 } 109 }
110 110
111 /* early.c uses stsi, which requires page aligned data. */
112 . = ALIGN(PAGE_SIZE);
111 .init.data : { 113 .init.data : {
112 INIT_DATA 114 INIT_DATA
113 } 115 }
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 0d33893e1e89..c55a4b9ffd88 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -286,7 +286,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
286 setup_timer(&vcpu->arch.ckc_timer, kvm_s390_idle_wakeup, 286 setup_timer(&vcpu->arch.ckc_timer, kvm_s390_idle_wakeup,
287 (unsigned long) vcpu); 287 (unsigned long) vcpu);
288 get_cpu_id(&vcpu->arch.cpu_id); 288 get_cpu_id(&vcpu->arch.cpu_id);
289 vcpu->arch.cpu_id.version = 0xfe; 289 vcpu->arch.cpu_id.version = 0xff;
290 return 0; 290 return 0;
291} 291}
292 292