]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
[S390] Fix hypervisor detection for KVM
authorChristian Borntraeger <borntraeger@de.ibm.com>
Thu, 26 Mar 2009 14:23:58 +0000 (15:23 +0100)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Thu, 26 Mar 2009 14:24:09 +0000 (15:24 +0100)
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>
arch/s390/include/asm/sysinfo.h
arch/s390/kernel/early.c
arch/s390/kernel/vmlinux.lds.S
arch/s390/kvm/kvm-s390.c

index ad93212d9e16a3099087f846edb942612de0694c..9d70057d828c604796082b21d61535eebcd19f87 100644 (file)
@@ -100,6 +100,7 @@ struct sysinfo_3_2_2 {
                char reserved_1[24];
 
        } vm[8];
+       char reserved_544[3552];
 };
 
 static inline int stsi(void *sysinfo, int fc, int sel1, int sel2)
index 2a2ca268b1dd6e6bc38115496674ee965f8ef29a..d61eb3334edf8858b9aa9e32ff6d8f630935bb38 100644 (file)
@@ -6,6 +6,7 @@
  *              Heiko Carstens <heiko.carstens@de.ibm.com>
  */
 
+#include <linux/compiler.h>
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/string.h>
@@ -20,6 +21,7 @@
 #include <asm/processor.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
+#include <asm/sysinfo.h>
 #include <asm/cpcmd.h>
 #include <asm/sclp.h>
 #include "entry.h"
@@ -173,19 +175,21 @@ static noinline __init void init_kernel_storage_key(void)
                page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
 }
 
+static __initdata struct sysinfo_3_2_2 vmms __aligned(PAGE_SIZE);
+
 static noinline __init void detect_machine_type(void)
 {
-       struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data;
-
-       get_cpu_id(&S390_lowcore.cpu_data.cpu_id);
-
-       /* Running under z/VM ? */
-       if (cpuinfo->cpu_id.version == 0xff)
-               machine_flags |= MACHINE_FLAG_VM;
+       /* No VM information? Looks like LPAR */
+       if (stsi(&vmms, 3, 2, 2) == -ENOSYS)
+               return;
+       if (!vmms.count)
+               return;
 
-       /* Running under KVM ? */
-       if (cpuinfo->cpu_id.version == 0xfe)
+       /* Running under KVM? If not we assume z/VM */
+       if (!memcmp(vmms.vm[0].cpi, "\xd2\xe5\xd4", 3))
                machine_flags |= MACHINE_FLAG_KVM;
+       else
+               machine_flags |= MACHINE_FLAG_VM;
 }
 
 static __init void early_pgm_check_handler(void)
index d796d05c9c01ac1be6779682a730485d73502bd2..7a2063eb88f0ffac77a573d24d2653dc7aaf3c24 100644 (file)
@@ -108,6 +108,8 @@ SECTIONS
                EXIT_TEXT
        }
 
+       /* early.c uses stsi, which requires page aligned data. */
+       . = ALIGN(PAGE_SIZE);
        .init.data : {
                INIT_DATA
        }
index 0d33893e1e898448c05b7ec2573904a81850180b..c55a4b9ffd88ee8afb44fda4b531cf1c0ae74dce 100644 (file)
@@ -286,7 +286,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
        setup_timer(&vcpu->arch.ckc_timer, kvm_s390_idle_wakeup,
                 (unsigned long) vcpu);
        get_cpu_id(&vcpu->arch.cpu_id);
-       vcpu->arch.cpu_id.version = 0xfe;
+       vcpu->arch.cpu_id.version = 0xff;
        return 0;
 }