Subject: Re: [PATCH v2 2/2] selftests/powerpc: Add scv versions of the basic TM syscall tests

From: Michael Ellerman <[email-masked]>
Date: Thu, 02 Sep 2021 15:36:05 +1000

Nicholas Piggin <[email-masked]> writes:
> The basic TM vs syscall test code hard codes an sc instruction for the
> system call, which fails to cover scv even when the userspace libc has
> support for it.
>
> Duplicate the tests with hard coded scv variants so both are tested
> when possible.
>
> Signed-off-by: Nicholas Piggin <[email-masked]>
> ---
>  .../selftests/powerpc/tm/tm-syscall-asm.S     | 46 +++++++++++++++++++
>  .../testing/selftests/powerpc/tm/tm-syscall.c | 36 ++++++++++++---
>  2 files changed, 75 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S b/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
> index bd1ca25febe4..849316831e6a 100644
> --- a/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
> +++ b/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
> @@ -2,6 +2,10 @@
>  #include <ppc-asm.h>
>  #include <asm/unistd.h>
>  
> +/* ppc-asm.h does not define r0 or r1 */
> +#define r0 0
> +#define r1 1
> +
>  	.text
>  FUNC_START(getppid_tm_active)
>  	tbegin.
> @@ -26,3 +30,45 @@ FUNC_START(getppid_tm_suspended)
>  1:
>  	li	r3, -1
>  	blr
> +
> +FUNC_START(getppid_scv_tm_active)
> +	mflr	r0
> +	std	r0,16(r1)
> +	stdu	r1,-32(r1)
> +	tbegin.
> +	beq 1f
> +	li	r0, __NR_getppid
> +	scv	0
> +	tend.
> +	addi	r1,r1,32
> +	ld	r0,16(r1)
> +	mtlr	r0
> +	blr
> +1:
> +	li	r3, -1
> +	addi	r1,r1,32
> +	ld	r0,16(r1)
> +	mtlr	r0
> +	blr

There's some macros in tools/testing/selftests/powerpc/include/basic_asm.h
that can do some of this boiler plate stack setup/teardown.

Incremental diff below to use them, only build tested.

cheers

diff --git a/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S b/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
index 849316831e6a..a73694daca71 100644
--- a/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
+++ b/tools/testing/selftests/powerpc/tm/tm-syscall-asm.S
@@ -1,10 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-#include <ppc-asm.h>
-#include <asm/unistd.h>
-
-/* ppc-asm.h does not define r0 or r1 */
-#define r0 0
-#define r1 1
+#include <basic_asm.h>
 
 	.text
 FUNC_START(getppid_tm_active)
@@ -32,29 +27,21 @@ FUNC_START(getppid_tm_suspended)
 	blr
 
 FUNC_START(getppid_scv_tm_active)
-	mflr	r0
-	std	r0,16(r1)
-	stdu	r1,-32(r1)
+	PUSH_BASIC_STACK(0)
 	tbegin.
 	beq 1f
 	li	r0, __NR_getppid
 	scv	0
 	tend.
-	addi	r1,r1,32
-	ld	r0,16(r1)
-	mtlr	r0
+	POP_BASIC_STACK(0)
 	blr
 1:
 	li	r3, -1
-	addi	r1,r1,32
-	ld	r0,16(r1)
-	mtlr	r0
+	POP_BASIC_STACK(0)
 	blr
 
 FUNC_START(getppid_scv_tm_suspended)
-	mflr	r0
-	std	r0,16(r1)
-	stdu	r1,-32(r1)
+	PUSH_BASIC_STACK(0)
 	tbegin.
 	beq 1f
 	li	r0, __NR_getppid
@@ -62,13 +49,9 @@ FUNC_START(getppid_scv_tm_suspended)
 	scv	0
 	tresume.
 	tend.
-	addi	r1,r1,32
-	ld	r0,16(r1)
-	mtlr	r0
+	POP_BASIC_STACK(0)
 	blr
 1:
 	li	r3, -1
-	addi	r1,r1,32
-	ld	r0,16(r1)
-	mtlr	r0
+	POP_BASIC_STACK(0)
 	blr