From: Christian Borntraeger <borntraeger at de.ibm.com>
From: Carsten Otte <cotte at de.ibm.com>
This patch adds functionality to detect if the kernel runs under the KVM
hypervisor. A macro MACHINE_IS_KVM is exported for device drivers. This
allows drivers to skip device detection if the systems runs non-virtualized.
We also define a preferred console to avoid having the ttyS0, which is a line
mode only console.
Signed-off-by: Christian Borntraeger <borntraeger at de.ibm.com>
Acked-by: Martin Schwidefsky <schwidefsky at de.ibm.com>
Signed-off-by: Carsten Otte <cotte at de.ibm.com>
---
arch/s390/Kconfig | 7 +++++++
arch/s390/kernel/early.c | 4 ++++
arch/s390/kernel/setup.c | 10 +++++++---
include/asm-s390/setup.h | 1 +
4 files changed, 19 insertions(+), 3 deletions(-)
Index: kvm/arch/s390/Kconfig
==================================================================---
kvm.orig/arch/s390/Kconfig
+++ kvm/arch/s390/Kconfig
@@ -533,6 +533,13 @@ config ZFCPDUMP
Select this option if you want to build an zfcpdump enabled kernel.
Refer to <file:Documentation/s390/zfcpdump.txt> for more details on
this.
+config S390_GUEST
+bool "s390 guest support (EXPERIMENTAL)"
+ depends on 64BIT && EXPERIMENTAL
+ select VIRTIO
+ select VIRTIO_RING
+ help
+ Select this option if you want to run the kernel under s390 linux
endmenu
source "net/Kconfig"
Index: kvm/arch/s390/kernel/early.c
==================================================================---
kvm.orig/arch/s390/kernel/early.c
+++ kvm/arch/s390/kernel/early.c
@@ -143,6 +143,10 @@ static noinline __init void detect_machi
/* Running on a P/390 ? */
if (cpuinfo->cpu_id.machine == 0x7490)
machine_flags |= 4;
+
+ /* Running under KVM ? */
+ if (cpuinfo->cpu_id.version == 0xfe)
+ machine_flags |= 64;
}
#ifdef CONFIG_64BIT
Index: kvm/arch/s390/kernel/setup.c
==================================================================---
kvm.orig/arch/s390/kernel/setup.c
+++ kvm/arch/s390/kernel/setup.c
@@ -793,9 +793,13 @@ setup_arch(char **cmdline_p)
"This machine has an IEEE fpu\n" :
"This machine has no IEEE fpu\n");
#else /* CONFIG_64BIT */
- printk((MACHINE_IS_VM) ?
- "We are running under VM (64 bit mode)\n" :
- "We are running native (64 bit mode)\n");
+ if (MACHINE_IS_VM)
+ printk("We are running under VM (64 bit mode)\n");
+ else if (MACHINE_IS_KVM) {
+ printk("We are running under KVM (64 bit mode)\n");
+ add_preferred_console("ttyS", 1, NULL);
+ } else
+ printk("We are running native (64 bit mode)\n");
#endif /* CONFIG_64BIT */
/* Save unparsed command line copy for /proc/cmdline */
Index: kvm/include/asm-s390/setup.h
==================================================================---
kvm.orig/include/asm-s390/setup.h
+++ kvm/include/asm-s390/setup.h
@@ -62,6 +62,7 @@ extern unsigned long machine_flags;
#define MACHINE_IS_VM (machine_flags & 1)
#define MACHINE_IS_P390 (machine_flags & 4)
#define MACHINE_HAS_MVPG (machine_flags & 16)
+#define MACHINE_IS_KVM (machine_flags & 64)
#define MACHINE_HAS_IDTE (machine_flags & 128)
#define MACHINE_HAS_DIAG9C (machine_flags & 256)
On Thu, 20 Mar 2008 17:25:26 +0100 Carsten Otte wrote:> From: Christian Borntraeger <borntraeger at de.ibm.com> > From: Carsten Otte <cotte at de.ibm.com> > > This patch adds functionality to detect if the kernel runs under the KVM > hypervisor. A macro MACHINE_IS_KVM is exported for device drivers. This > allows drivers to skip device detection if the systems runs non-virtualized. > We also define a preferred console to avoid having the ttyS0, which is a line > mode only console. > > Signed-off-by: Christian Borntraeger <borntraeger at de.ibm.com> > Acked-by: Martin Schwidefsky <schwidefsky at de.ibm.com> > Signed-off-by: Carsten Otte <cotte at de.ibm.com> > --- > arch/s390/Kconfig | 7 +++++++ > arch/s390/kernel/early.c | 4 ++++ > arch/s390/kernel/setup.c | 10 +++++++--- > include/asm-s390/setup.h | 1 + > 4 files changed, 19 insertions(+), 3 deletions(-) > > Index: kvm/arch/s390/kernel/early.c > ==================================================================> --- kvm.orig/arch/s390/kernel/early.c > +++ kvm/arch/s390/kernel/early.c > @@ -143,6 +143,10 @@ static noinline __init void detect_machi > /* Running on a P/390 ? */ > if (cpuinfo->cpu_id.machine == 0x7490) > machine_flags |= 4; > + > + /* Running under KVM ? */ > + if (cpuinfo->cpu_id.version == 0xfe)Hi, Where are these magic numbers documented? (0x7490, 0xfe, etc.)> + machine_flags |= 64; > } > > #ifdef CONFIG_64BIT--- ~Randy
Randy Dunlap wrote:>> Index: kvm/arch/s390/kernel/early.c >> ==================================================================>> --- kvm.orig/arch/s390/kernel/early.c >> +++ kvm/arch/s390/kernel/early.c >> @@ -143,6 +143,10 @@ static noinline __init void detect_machi >> /* Running on a P/390 ? */ >> if (cpuinfo->cpu_id.machine == 0x7490) >> machine_flags |= 4; >> + >> + /* Running under KVM ? */ >> + if (cpuinfo->cpu_id.version == 0xfe) > > Hi, > > Where are these magic numbers documented? (0x7490, 0xfe, etc.) > > >> + machine_flags |= 64; >> } >> >> #ifdef CONFIG_64BITThe cpuid (and most other things about s390 arch) are documented in the principles of operation: http://publibz.boulder.ibm.com/epubs/pdf/a2278324.pdf http://publibz.boulder.ibm.com/epubs/pdf/dz9zs001.pdf (see chapter "control instructions" - store cpu id) The 0xfe however is convention, the kvm arch code sets this value where it implements that instruction. See "privileged instructions" patch.
Christoph Hellwig
2008-Mar-20 17:53 UTC
[kvm-devel] [RFC/PATCH 14/15] guest: detect when running on kvm
On Thu, Mar 20, 2008 at 05:25:26PM +0100, Carsten Otte wrote:> @@ -143,6 +143,10 @@ static noinline __init void detect_machi > /* Running on a P/390 ? */ > if (cpuinfo->cpu_id.machine == 0x7490) > machine_flags |= 4; > + > + /* Running under KVM ? */ > + if (cpuinfo->cpu_id.version == 0xfe) > + machine_flags |= 64;Shouldn't these have symbolic names?