Skip to content

Commit fa58774

Browse files
Carsten Otteavikivity
authored andcommitted
s390: KVM guest: detect when running on kvm
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 <[email protected]> Acked-by: Martin Schwidefsky <[email protected]> Signed-off-by: Carsten Otte <[email protected]> Signed-off-by: Avi Kivity <[email protected]>
1 parent 85f8fff commit fa58774

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

arch/s390/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,13 @@ config ZFCPDUMP
520520
Select this option if you want to build an zfcpdump enabled kernel.
521521
Refer to <file:Documentation/s390/zfcpdump.txt> for more details on this.
522522

523+
config S390_GUEST
524+
bool "s390 guest support (EXPERIMENTAL)"
525+
depends on 64BIT && EXPERIMENTAL
526+
select VIRTIO
527+
select VIRTIO_RING
528+
help
529+
Select this option if you want to run the kernel under s390 linux
523530
endmenu
524531

525532
source "net/Kconfig"

arch/s390/kernel/early.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ static noinline __init void detect_machine_type(void)
144144
/* Running on a P/390 ? */
145145
if (cpuinfo->cpu_id.machine == 0x7490)
146146
machine_flags |= 4;
147+
148+
/* Running under KVM ? */
149+
if (cpuinfo->cpu_id.version == 0xfe)
150+
machine_flags |= 64;
147151
}
148152

149153
#ifdef CONFIG_64BIT

arch/s390/kernel/setup.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,13 @@ setup_arch(char **cmdline_p)
801801
"This machine has an IEEE fpu\n" :
802802
"This machine has no IEEE fpu\n");
803803
#else /* CONFIG_64BIT */
804-
printk((MACHINE_IS_VM) ?
805-
"We are running under VM (64 bit mode)\n" :
806-
"We are running native (64 bit mode)\n");
804+
if (MACHINE_IS_VM)
805+
printk("We are running under VM (64 bit mode)\n");
806+
else if (MACHINE_IS_KVM) {
807+
printk("We are running under KVM (64 bit mode)\n");
808+
add_preferred_console("ttyS", 1, NULL);
809+
} else
810+
printk("We are running native (64 bit mode)\n");
807811
#endif /* CONFIG_64BIT */
808812

809813
/* Save unparsed command line copy for /proc/cmdline */

include/asm-s390/setup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern unsigned long machine_flags;
6262
#define MACHINE_IS_VM (machine_flags & 1)
6363
#define MACHINE_IS_P390 (machine_flags & 4)
6464
#define MACHINE_HAS_MVPG (machine_flags & 16)
65+
#define MACHINE_IS_KVM (machine_flags & 64)
6566
#define MACHINE_HAS_IDTE (machine_flags & 128)
6667
#define MACHINE_HAS_DIAG9C (machine_flags & 256)
6768

0 commit comments

Comments
 (0)