diff mbox series

[v2] broken_sc1: check for H_PRIVILEGE

Message ID 20180403042142.14134-1-nikunj@linux.vnet.ibm.com
State Accepted
Headers show
Series [v2] broken_sc1: check for H_PRIVILEGE | expand

Commit Message

Nikunj A Dadhania April 3, 2018, 4:21 a.m. UTC
Recently, found that when DAWR was disabled by linux kernel, the hcall started
returning H_UNSUPPORTED, and VM did not boot up as broken_sc1 patched up SC
calls falsely.

Instead of checking for various returns, check if its not in privilege mode and
patch sc1 in that case.

CC: Michael Ellerman <michael@ellerman.id.au>
CC: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
---
 lib/libhvcall/brokensc1.c | 10 +++++-----
 lib/libhvcall/libhvcall.h |  1 +
 2 files changed, 6 insertions(+), 5 deletions(-)

Comments

Thomas Huth April 3, 2018, 5:17 a.m. UTC | #1
On 03.04.2018 06:21, Nikunj A Dadhania wrote:
> Recently, found that when DAWR was disabled by linux kernel, the hcall started
> returning H_UNSUPPORTED, and VM did not boot up as broken_sc1 patched up SC
> calls falsely.
> 
> Instead of checking for various returns, check if its not in privilege mode and
> patch sc1 in that case.
> 
> CC: Michael Ellerman <michael@ellerman.id.au>
> CC: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
> ---
>  lib/libhvcall/brokensc1.c | 10 +++++-----
>  lib/libhvcall/libhvcall.h |  1 +
>  2 files changed, 6 insertions(+), 5 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>
Michael Ellerman April 3, 2018, 1:21 p.m. UTC | #2
Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> writes:

> Recently, found that when DAWR was disabled by linux kernel, the hcall started
> returning H_UNSUPPORTED, and VM did not boot up as broken_sc1 patched up SC
> calls falsely.
>
> Instead of checking for various returns, check if its not in privilege mode and
> patch sc1 in that case.
>
> CC: Michael Ellerman <michael@ellerman.id.au>
> CC: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>

Thanks for doing this.

We may never update the kernel to return H_UNSUPPORTED, but at least we
won't get bitten by this horrible^H^H^Hawesome PR KVM hack again.

cheers

> diff --git a/lib/libhvcall/brokensc1.c b/lib/libhvcall/brokensc1.c
> index e6387e0..d97ae77 100644
> --- a/lib/libhvcall/brokensc1.c
> +++ b/lib/libhvcall/brokensc1.c
> @@ -47,13 +47,13 @@ static int check_broken_sc1(void)
>  	 * supervisor mode.
>  	 */
>  	r = hcall(INS_SC1, H_SET_DABR, 0);
> -	if (r == H_SUCCESS || r == H_HARDWARE) {
> -		/* All is fine */
> -		return 0;
> +	if (r == H_PRIVILEGE) {
> +		/* We found a broken sc1 host! */
> +		return 1;
>  	}
>  
> -	/* We found a broken sc1 host! */
> -	return 1;
> +	/* All is fine */
> +	return 0;
>  }
>  
>  int patch_broken_sc1(void *start, void *end, uint32_t *test_ins)
> diff --git a/lib/libhvcall/libhvcall.h b/lib/libhvcall/libhvcall.h
> index 3fa4398..caa4d6d 100644
> --- a/lib/libhvcall/libhvcall.h
> +++ b/lib/libhvcall/libhvcall.h
> @@ -3,6 +3,7 @@
>  
>  #define H_SUCCESS		0
>  #define H_HARDWARE		-1
> +#define H_PRIVILEGE		-3   /* Caller not privileged */
>  
>  #define H_GET_TCE		0x1C
>  #define H_PUT_TCE		0x20
> -- 
> 2.14.3
Alexey Kardashevskiy April 4, 2018, 2:39 a.m. UTC | #3
On 3/4/18 2:21 pm, Nikunj A Dadhania wrote:
> Recently, found that when DAWR was disabled by linux kernel, the hcall started
> returning H_UNSUPPORTED, and VM did not boot up as broken_sc1 patched up SC
> calls falsely.
> 
> Instead of checking for various returns, check if its not in privilege mode and
> patch sc1 in that case.
> 
> CC: Michael Ellerman <michael@ellerman.id.au>
> CC: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>

Thanks, applied.


> ---
>  lib/libhvcall/brokensc1.c | 10 +++++-----
>  lib/libhvcall/libhvcall.h |  1 +
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/libhvcall/brokensc1.c b/lib/libhvcall/brokensc1.c
> index e6387e0..d97ae77 100644
> --- a/lib/libhvcall/brokensc1.c
> +++ b/lib/libhvcall/brokensc1.c
> @@ -47,13 +47,13 @@ static int check_broken_sc1(void)
>  	 * supervisor mode.
>  	 */
>  	r = hcall(INS_SC1, H_SET_DABR, 0);
> -	if (r == H_SUCCESS || r == H_HARDWARE) {
> -		/* All is fine */
> -		return 0;
> +	if (r == H_PRIVILEGE) {
> +		/* We found a broken sc1 host! */
> +		return 1;
>  	}
>  
> -	/* We found a broken sc1 host! */
> -	return 1;
> +	/* All is fine */
> +	return 0;
>  }
>  
>  int patch_broken_sc1(void *start, void *end, uint32_t *test_ins)
> diff --git a/lib/libhvcall/libhvcall.h b/lib/libhvcall/libhvcall.h
> index 3fa4398..caa4d6d 100644
> --- a/lib/libhvcall/libhvcall.h
> +++ b/lib/libhvcall/libhvcall.h
> @@ -3,6 +3,7 @@
>  
>  #define H_SUCCESS		0
>  #define H_HARDWARE		-1
> +#define H_PRIVILEGE		-3   /* Caller not privileged */
>  
>  #define H_GET_TCE		0x1C
>  #define H_PUT_TCE		0x20
>
diff mbox series

Patch

diff --git a/lib/libhvcall/brokensc1.c b/lib/libhvcall/brokensc1.c
index e6387e0..d97ae77 100644
--- a/lib/libhvcall/brokensc1.c
+++ b/lib/libhvcall/brokensc1.c
@@ -47,13 +47,13 @@  static int check_broken_sc1(void)
 	 * supervisor mode.
 	 */
 	r = hcall(INS_SC1, H_SET_DABR, 0);
-	if (r == H_SUCCESS || r == H_HARDWARE) {
-		/* All is fine */
-		return 0;
+	if (r == H_PRIVILEGE) {
+		/* We found a broken sc1 host! */
+		return 1;
 	}
 
-	/* We found a broken sc1 host! */
-	return 1;
+	/* All is fine */
+	return 0;
 }
 
 int patch_broken_sc1(void *start, void *end, uint32_t *test_ins)
diff --git a/lib/libhvcall/libhvcall.h b/lib/libhvcall/libhvcall.h
index 3fa4398..caa4d6d 100644
--- a/lib/libhvcall/libhvcall.h
+++ b/lib/libhvcall/libhvcall.h
@@ -3,6 +3,7 @@ 
 
 #define H_SUCCESS		0
 #define H_HARDWARE		-1
+#define H_PRIVILEGE		-3   /* Caller not privileged */
 
 #define H_GET_TCE		0x1C
 #define H_PUT_TCE		0x20