diff mbox series

[kvm-unit-tests,v2,8/8] s390x: uv-host: Fix init storage origin and length check

Message ID 20220706064024.16573-9-frankja@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: uv-host: Access check extensions and improvements | expand

Commit Message

Janosch Frank July 6, 2022, 6:40 a.m. UTC
The origin and length are masked with the HPAGE_MASK and PAGE_MASK
respectively so adding a few bytes doesn't matter at all.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 s390x/uv-host.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Steffen Eiden July 8, 2022, 10:19 a.m. UTC | #1
On 7/6/22 08:40, Janosch Frank wrote:
> The origin and length are masked with the HPAGE_MASK and PAGE_MASK
> respectively so adding a few bytes doesn't matter at all.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
>   s390x/uv-host.c | 19 ++++++++++++-------
>   1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/s390x/uv-host.c b/s390x/uv-host.c
> index 1ed8ded1..b1412a20 100644
> --- a/s390x/uv-host.c
> +++ b/s390x/uv-host.c
> @@ -516,17 +516,22 @@ static void test_init(void)
>   	       "storage invalid length");
>   	uvcb_init.stor_len += 8;
>   
> -	uvcb_init.stor_origin =  get_max_ram_size() + 8;
> +	/* Storage origin is 1MB aligned, the length is 4KB aligned */
> +	uvcb_init.stor_origin = get_max_ram_size();
>   	rc = uv_call(0, (uint64_t)&uvcb_init);
> -	report(rc == 1 && uvcb_init.header.rc == 0x104,
> +	report(rc == 1 && (uvcb_init.header.rc == 0x104 || uvcb_init.header.rc == 0x105),
>   	       "storage origin invalid");
>   	uvcb_init.stor_origin = mem;
>   
> -	uvcb_init.stor_origin = get_max_ram_size() - 8;
> -	rc = uv_call(0, (uint64_t)&uvcb_init);
> -	report(rc == 1 && uvcb_init.header.rc == 0x105,
> -	       "storage + length invalid");
> -	uvcb_init.stor_origin = mem;
> +	if (uvcb_init.stor_len >= HPAGE_SIZE) {
> +		uvcb_init.stor_origin = get_max_ram_size() - HPAGE_SIZE;
> +		rc = uv_call(0, (uint64_t)&uvcb_init);
> +		report(rc == 1 && uvcb_init.header.rc == 0x105,
> +		       "storage + length invalid");
> +		uvcb_init.stor_origin = mem;
> +	} else {
> +		report_skip("storage + length invalid, stor_len < HPAGE_SIZE");
> +	}
>   
>   	uvcb_init.stor_origin = 1UL << 30;
>   	rc = uv_call(0, (uint64_t)&uvcb_init);
diff mbox series

Patch

diff --git a/s390x/uv-host.c b/s390x/uv-host.c
index 1ed8ded1..b1412a20 100644
--- a/s390x/uv-host.c
+++ b/s390x/uv-host.c
@@ -516,17 +516,22 @@  static void test_init(void)
 	       "storage invalid length");
 	uvcb_init.stor_len += 8;
 
-	uvcb_init.stor_origin =  get_max_ram_size() + 8;
+	/* Storage origin is 1MB aligned, the length is 4KB aligned */
+	uvcb_init.stor_origin = get_max_ram_size();
 	rc = uv_call(0, (uint64_t)&uvcb_init);
-	report(rc == 1 && uvcb_init.header.rc == 0x104,
+	report(rc == 1 && (uvcb_init.header.rc == 0x104 || uvcb_init.header.rc == 0x105),
 	       "storage origin invalid");
 	uvcb_init.stor_origin = mem;
 
-	uvcb_init.stor_origin = get_max_ram_size() - 8;
-	rc = uv_call(0, (uint64_t)&uvcb_init);
-	report(rc == 1 && uvcb_init.header.rc == 0x105,
-	       "storage + length invalid");
-	uvcb_init.stor_origin = mem;
+	if (uvcb_init.stor_len >= HPAGE_SIZE) {
+		uvcb_init.stor_origin = get_max_ram_size() - HPAGE_SIZE;
+		rc = uv_call(0, (uint64_t)&uvcb_init);
+		report(rc == 1 && uvcb_init.header.rc == 0x105,
+		       "storage + length invalid");
+		uvcb_init.stor_origin = mem;
+	} else {
+		report_skip("storage + length invalid, stor_len < HPAGE_SIZE");
+	}
 
 	uvcb_init.stor_origin = 1UL << 30;
 	rc = uv_call(0, (uint64_t)&uvcb_init);