diff mbox series

[kvm-unit-tests,4/5] s390x: Clear first stack frame and end backtrace early

Message ID 20221123084656.19864-5-frankja@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: Snippet fixes | expand

Commit Message

Janosch Frank Nov. 23, 2022, 8:46 a.m. UTC
When setting the first stack frame to 0, we can check for a 0
backchain pointer when doing backtraces to know when to stop.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/stack.c | 2 ++
 s390x/cstart64.S  | 2 ++
 2 files changed, 4 insertions(+)

Comments

Nico Boehr Nov. 23, 2022, 11:05 a.m. UTC | #1
Quoting Janosch Frank (2022-11-23 09:46:55)
> When setting the first stack frame to 0, we can check for a 0
> backchain pointer when doing backtraces to know when to stop.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
Claudio Imbrenda Nov. 23, 2022, 12:47 p.m. UTC | #2
On Wed, 23 Nov 2022 08:46:55 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> When setting the first stack frame to 0, we can check for a 0
> backchain pointer when doing backtraces to know when to stop.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>

> ---
>  lib/s390x/stack.c | 2 ++
>  s390x/cstart64.S  | 2 ++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/lib/s390x/stack.c b/lib/s390x/stack.c
> index e714e07c..9f234a12 100644
> --- a/lib/s390x/stack.c
> +++ b/lib/s390x/stack.c
> @@ -22,6 +22,8 @@ int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
>  	for (depth = 0; stack && depth < max_depth; depth++) {
>  		return_addrs[depth] = (void *)stack->grs[8];
>  		stack = stack->back_chain;
> +		if (!stack)
> +			break;
>  	}
>  
>  	return depth;
> diff --git a/s390x/cstart64.S b/s390x/cstart64.S
> index 666a9567..6f83da2a 100644
> --- a/s390x/cstart64.S
> +++ b/s390x/cstart64.S
> @@ -37,6 +37,8 @@ start:
>  	sam64				# Set addressing mode to 64 bit
>  	/* setup stack */
>  	larl	%r15, stackptr
> +	/* Clear first stack frame */
> +	xc      0(160,%r15), 0(%r15)
>  	/* setup initial PSW mask + control registers*/
>  	larl	%r1, initial_psw
>  	lpswe	0(%r1)
diff mbox series

Patch

diff --git a/lib/s390x/stack.c b/lib/s390x/stack.c
index e714e07c..9f234a12 100644
--- a/lib/s390x/stack.c
+++ b/lib/s390x/stack.c
@@ -22,6 +22,8 @@  int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
 	for (depth = 0; stack && depth < max_depth; depth++) {
 		return_addrs[depth] = (void *)stack->grs[8];
 		stack = stack->back_chain;
+		if (!stack)
+			break;
 	}
 
 	return depth;
diff --git a/s390x/cstart64.S b/s390x/cstart64.S
index 666a9567..6f83da2a 100644
--- a/s390x/cstart64.S
+++ b/s390x/cstart64.S
@@ -37,6 +37,8 @@  start:
 	sam64				# Set addressing mode to 64 bit
 	/* setup stack */
 	larl	%r15, stackptr
+	/* Clear first stack frame */
+	xc      0(160,%r15), 0(%r15)
 	/* setup initial PSW mask + control registers*/
 	larl	%r1, initial_psw
 	lpswe	0(%r1)