Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Christian Borntraeger and committed by
Martin Schwidefsky
92e6ecf3 702d9e58

+17 -10
+1
arch/s390/include/asm/sysinfo.h
··· 100 100 char reserved_1[24]; 101 101 102 102 } vm[8]; 103 + char reserved_544[3552]; 103 104 }; 104 105 105 106 static inline int stsi(void *sysinfo, int fc, int sel1, int sel2)
+13 -9
arch/s390/kernel/early.c
··· 6 6 * Heiko Carstens <heiko.carstens@de.ibm.com> 7 7 */ 8 8 9 + #include <linux/compiler.h> 9 10 #include <linux/init.h> 10 11 #include <linux/errno.h> 11 12 #include <linux/string.h> ··· 21 20 #include <asm/processor.h> 22 21 #include <asm/sections.h> 23 22 #include <asm/setup.h> 23 + #include <asm/sysinfo.h> 24 24 #include <asm/cpcmd.h> 25 25 #include <asm/sclp.h> 26 26 #include "entry.h" ··· 175 173 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY); 176 174 } 177 175 176 + static __initdata struct sysinfo_3_2_2 vmms __aligned(PAGE_SIZE); 177 + 178 178 static noinline __init void detect_machine_type(void) 179 179 { 180 - struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data; 180 + /* No VM information? Looks like LPAR */ 181 + if (stsi(&vmms, 3, 2, 2) == -ENOSYS) 182 + return; 183 + if (!vmms.count) 184 + return; 181 185 182 - get_cpu_id(&S390_lowcore.cpu_data.cpu_id); 183 - 184 - /* Running under z/VM ? */ 185 - if (cpuinfo->cpu_id.version == 0xff) 186 - machine_flags |= MACHINE_FLAG_VM; 187 - 188 - /* Running under KVM ? */ 189 - if (cpuinfo->cpu_id.version == 0xfe) 186 + /* Running under KVM? If not we assume z/VM */ 187 + if (!memcmp(vmms.vm[0].cpi, "\xd2\xe5\xd4", 3)) 190 188 machine_flags |= MACHINE_FLAG_KVM; 189 + else 190 + machine_flags |= MACHINE_FLAG_VM; 191 191 } 192 192 193 193 static __init void early_pgm_check_handler(void)
+2
arch/s390/kernel/vmlinux.lds.S
··· 108 108 EXIT_TEXT 109 109 } 110 110 111 + /* early.c uses stsi, which requires page aligned data. */ 112 + . = ALIGN(PAGE_SIZE); 111 113 .init.data : { 112 114 INIT_DATA 113 115 }
+1 -1
arch/s390/kvm/kvm-s390.c
··· 286 286 setup_timer(&vcpu->arch.ckc_timer, kvm_s390_idle_wakeup, 287 287 (unsigned long) vcpu); 288 288 get_cpu_id(&vcpu->arch.cpu_id); 289 - vcpu->arch.cpu_id.version = 0xfe; 289 + vcpu->arch.cpu_id.version = 0xff; 290 290 return 0; 291 291 } 292 292