diff mbox series

[B,SRU,1/1] s390/early: improve machine detection

Message ID 20190527063931.16303-2-po-hsu.lin@canonical.com
State New
Headers show
Series s390/early: improve machine detection | expand

Commit Message

Po-Hsu Lin May 27, 2019, 6:39 a.m. UTC
From: Christian Borntraeger <borntraeger@de.ibm.com>

BugLink: https://bugs.launchpad.net/bugs/1829972

Right now the early machine detection code check stsi 3.2.2 for "KVM"
and set MACHINE_IS_VM if this is different. As the console detection
uses diagnose 8 if MACHINE_IS_VM returns true this will crash Linux
early for any non z/VM system that sets a different value than KVM.
So instead of assuming z/VM, do not set any of MACHINE_IS_LPAR,
MACHINE_IS_VM, or MACHINE_IS_KVM.

CC: stable@vger.kernel.org
Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
(cherry picked from commit 03aa047ef2db4985e444af6ee1c1dd084ad9fb4c)
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 arch/s390/kernel/early.c | 4 ++--
 arch/s390/kernel/setup.c | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

Comments

Connor Kuehl May 28, 2019, 9:22 p.m. UTC | #1
On 5/26/19 11:39 PM, Po-Hsu Lin wrote:
> From: Christian Borntraeger <borntraeger@de.ibm.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1829972
> 
> Right now the early machine detection code check stsi 3.2.2 for "KVM"
> and set MACHINE_IS_VM if this is different. As the console detection
> uses diagnose 8 if MACHINE_IS_VM returns true this will crash Linux
> early for any non z/VM system that sets a different value than KVM.
> So instead of assuming z/VM, do not set any of MACHINE_IS_LPAR,
> MACHINE_IS_VM, or MACHINE_IS_KVM.
> 
> CC: stable@vger.kernel.org
> Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
> (cherry picked from commit 03aa047ef2db4985e444af6ee1c1dd084ad9fb4c)
> Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>

Acked-by: Connor Kuehl <connor.kuehl@canonical.com>

> ---
>  arch/s390/kernel/early.c | 4 ++--
>  arch/s390/kernel/setup.c | 2 ++
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
> index ac707a9..77f162b 100644
> --- a/arch/s390/kernel/early.c
> +++ b/arch/s390/kernel/early.c
> @@ -90,10 +90,10 @@ static noinline __init void detect_machine_type(void)
>  	if (stsi(vmms, 3, 2, 2) || !vmms->count)
>  		return;
>  
> -	/* Running under KVM? If not we assume z/VM */
> +	/* Detect known hypervisors */
>  	if (!memcmp(vmms->vm[0].cpi, "\xd2\xe5\xd4", 3))
>  		S390_lowcore.machine_flags |= MACHINE_FLAG_KVM;
> -	else
> +	else if (!memcmp(vmms->vm[0].cpi, "\xa9\x61\xe5\xd4", 4))
>  		S390_lowcore.machine_flags |= MACHINE_FLAG_VM;
>  }
>  
> diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
> index 0786a6b..c69f3a3 100644
> --- a/arch/s390/kernel/setup.c
> +++ b/arch/s390/kernel/setup.c
> @@ -880,6 +880,8 @@ void __init setup_arch(char **cmdline_p)
>  		pr_info("Linux is running under KVM in 64-bit mode\n");
>  	else if (MACHINE_IS_LPAR)
>  		pr_info("Linux is running natively in 64-bit mode\n");
> +	else
> +		pr_info("Linux is running as a guest in 64-bit mode\n");
>  
>  	/* Have one command line that is parsed and saved in /proc/cmdline */
>  	/* boot_command_line has been already set up in early.c */
>
diff mbox series

Patch

diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index ac707a9..77f162b 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -90,10 +90,10 @@  static noinline __init void detect_machine_type(void)
 	if (stsi(vmms, 3, 2, 2) || !vmms->count)
 		return;
 
-	/* Running under KVM? If not we assume z/VM */
+	/* Detect known hypervisors */
 	if (!memcmp(vmms->vm[0].cpi, "\xd2\xe5\xd4", 3))
 		S390_lowcore.machine_flags |= MACHINE_FLAG_KVM;
-	else
+	else if (!memcmp(vmms->vm[0].cpi, "\xa9\x61\xe5\xd4", 4))
 		S390_lowcore.machine_flags |= MACHINE_FLAG_VM;
 }
 
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index 0786a6b..c69f3a3 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -880,6 +880,8 @@  void __init setup_arch(char **cmdline_p)
 		pr_info("Linux is running under KVM in 64-bit mode\n");
 	else if (MACHINE_IS_LPAR)
 		pr_info("Linux is running natively in 64-bit mode\n");
+	else
+		pr_info("Linux is running as a guest in 64-bit mode\n");
 
 	/* Have one command line that is parsed and saved in /proc/cmdline */
 	/* boot_command_line has been already set up in early.c */