diff mbox series

[kvm-unit-tests,v2,7/7] lib: s390x: Handle debug prints for SIE exceptions correctly

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

Commit Message

Janosch Frank Jan. 12, 2023, 3:45 p.m. UTC
When we leave SIE due to an exception, we'll still have guest values
in registers 0 - 13 and that's not clearly portraied in our debug
prints. So let's fix that.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/interrupt.c | 46 ++++++++++++++++++++++++++++++++++++++-----
 lib/s390x/sie.h       |  2 ++
 s390x/cpu.S           |  6 ++++--
 3 files changed, 47 insertions(+), 7 deletions(-)

Comments

Claudio Imbrenda Jan. 12, 2023, 5:13 p.m. UTC | #1
On Thu, 12 Jan 2023 15:45:48 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> When we leave SIE due to an exception, we'll still have guest values
> in registers 0 - 13 and that's not clearly portraied in our debug
> prints. So let's fix that.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  lib/s390x/interrupt.c | 46 ++++++++++++++++++++++++++++++++++++++-----
>  lib/s390x/sie.h       |  2 ++
>  s390x/cpu.S           |  6 ++++--
>  3 files changed, 47 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
> index dadb7415..ff47c2c2 100644
> --- a/lib/s390x/interrupt.c
> +++ b/lib/s390x/interrupt.c
> @@ -9,6 +9,7 @@
>   */
>  #include <libcflat.h>
>  #include <asm/barrier.h>
> +#include <asm/asm-offsets.h>
>  #include <sclp.h>
>  #include <interrupt.h>
>  #include <sie.h>
> @@ -188,9 +189,12 @@ static void print_storage_exception_information(void)
>  	}
>  }
>  
> -static void print_int_regs(struct stack_frame_int *stack)
> +static void print_int_regs(struct stack_frame_int *stack, bool sie)
>  {
> +	struct kvm_s390_sie_block *sblk;
> +
>  	printf("\n");
> +	printf("%s\n", sie ? "Guest registers:" : "Host registers:");
>  	printf("GPRS:\n");
>  	printf("%016lx %016lx %016lx %016lx\n",
>  	       stack->grs1[0], stack->grs1[1], stack->grs0[0], stack->grs0[1]);
> @@ -198,24 +202,56 @@ static void print_int_regs(struct stack_frame_int *stack)
>  	       stack->grs0[2], stack->grs0[3], stack->grs0[4], stack->grs0[5]);
>  	printf("%016lx %016lx %016lx %016lx\n",
>  	       stack->grs0[6], stack->grs0[7], stack->grs0[8], stack->grs0[9]);
> -	printf("%016lx %016lx %016lx %016lx\n",
> -	       stack->grs0[10], stack->grs0[11], stack->grs0[12], stack->grs0[13]);
> +
> +	if (sie) {
> +		sblk = (struct kvm_s390_sie_block *)stack->grs0[12];
> +		printf("%016lx %016lx %016lx %016lx\n",
> +		       stack->grs0[10], stack->grs0[11], sblk->gg14, sblk->gg15);
> +	} else {
> +		printf("%016lx %016lx %016lx %016lx\n",
> +		       stack->grs0[10], stack->grs0[11], stack->grs0[12], stack->grs0[13]);
> +	}
> +
>  	printf("\n");
>  }
>  
>  static void print_pgm_info(struct stack_frame_int *stack)
>  
>  {
> -	bool in_sie;
> +	bool in_sie, in_sie_gregs;
> +	struct vm_save_area *vregs;
>  
>  	in_sie = (lowcore.pgm_old_psw.addr >= (uintptr_t)sie_entry &&
>  		  lowcore.pgm_old_psw.addr <= (uintptr_t)sie_exit);
> +	in_sie_gregs = (lowcore.pgm_old_psw.addr >= (uintptr_t)sie_entry_gregs &&
> +			lowcore.pgm_old_psw.addr <= (uintptr_t)sie_exit_gregs);

can you explain why <= instead of < ? (I think I know why, but a
comment would not hurt)

with that fixed:

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

>  
>  	printf("\n");
>  	printf("Unexpected program interrupt %s: %#x on cpu %d at %#lx, ilen %d\n",
>  	       in_sie ? "in SIE" : "",
>  	       lowcore.pgm_int_code, stap(), lowcore.pgm_old_psw.addr, lowcore.pgm_int_id);
> -	print_int_regs(stack);
> +
> +	/*
> +	 * If we fall out of SIE before loading the host registers,
> +	 * then we need to do it here so we print the host registers
> +	 * and not the guest registers.
> +	 *
> +	 * Back tracing is actually not a problem since SIE restores gr15.
> +	 */
> +	if (in_sie_gregs) {
> +		print_int_regs(stack, true);
> +		vregs = *((struct vm_save_area **)(stack->grs0[13] + __SF_SIE_SAVEAREA));
> +
> +		/*
> +		 * The grs are not linear on the interrupt stack frame.
> +		 * We copy 0 and 1 here and 2 - 15 with the memcopy below.
> +		 */
> +		stack->grs1[0] = vregs->host.grs[0];
> +		stack->grs1[1] = vregs->host.grs[1];
> +		/*  2 - 15 */
> +		memcpy(stack->grs0, &vregs->host.grs[2], sizeof(stack->grs0) - 8);
> +	}
> +	print_int_regs(stack, false);
>  	dump_stack();
>  
>  	/* Dump stack doesn't end with a \n so we add it here instead */
> diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
> index a27a8401..147cb0f2 100644
> --- a/lib/s390x/sie.h
> +++ b/lib/s390x/sie.h
> @@ -273,6 +273,8 @@ struct vm {
>  
>  extern void sie_entry(void);
>  extern void sie_exit(void);
> +extern void sie_entry_gregs(void);
> +extern void sie_exit_gregs(void);
>  extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_area);
>  void sie(struct vm *vm);
>  void sie_expect_validity(struct vm *vm);
> diff --git a/s390x/cpu.S b/s390x/cpu.S
> index 45bd551a..9155b044 100644
> --- a/s390x/cpu.S
> +++ b/s390x/cpu.S
> @@ -82,7 +82,8 @@ sie64a:
>  	# Store scb and save_area pointer into stack frame
>  	stg	%r2,__SF_SIE_CONTROL(%r15)	# save control block pointer
>  	stg	%r3,__SF_SIE_SAVEAREA(%r15)	# save guest register save area
> -
> +.globl sie_entry_gregs
> +sie_entry_gregs:
>  	# Load guest's gprs, fprs and fpc
>  	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
>  	ld	\i, \i * 8 + SIE_SAVEAREA_GUEST_FPRS(%r3)
> @@ -121,7 +122,8 @@ sie_exit:
>  	.endr
>  	lfpc	SIE_SAVEAREA_HOST_FPC(%r14)
>  	lmg	%r0,%r14,SIE_SAVEAREA_HOST_GRS(%r14)	# restore kernel registers
> -
> +.globl sie_exit_gregs
> +sie_exit_gregs:
>  	br	%r14
>  
>  	.align	8
Janosch Frank Jan. 13, 2023, 3:50 p.m. UTC | #2
On 1/12/23 18:13, Claudio Imbrenda wrote:
> On Thu, 12 Jan 2023 15:45:48 +0000
> Janosch Frank <frankja@linux.ibm.com> wrote:
> 
>> When we leave SIE due to an exception, we'll still have guest values
>> in registers 0 - 13 and that's not clearly portraied in our debug
>> prints. So let's fix that.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
>>   lib/s390x/interrupt.c | 46 ++++++++++++++++++++++++++++++++++++++-----
>>   lib/s390x/sie.h       |  2 ++
>>   s390x/cpu.S           |  6 ++++--
>>   3 files changed, 47 insertions(+), 7 deletions(-)
>>
>> diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
>> index dadb7415..ff47c2c2 100644
>> --- a/lib/s390x/interrupt.c
>> +++ b/lib/s390x/interrupt.c
>> @@ -9,6 +9,7 @@
>>    */
>>   #include <libcflat.h>
>>   #include <asm/barrier.h>
>> +#include <asm/asm-offsets.h>
>>   #include <sclp.h>
>>   #include <interrupt.h>
>>   #include <sie.h>
>> @@ -188,9 +189,12 @@ static void print_storage_exception_information(void)
>>   	}
>>   }
>>   
>> -static void print_int_regs(struct stack_frame_int *stack)
>> +static void print_int_regs(struct stack_frame_int *stack, bool sie)
>>   {
>> +	struct kvm_s390_sie_block *sblk;
>> +
>>   	printf("\n");
>> +	printf("%s\n", sie ? "Guest registers:" : "Host registers:");
>>   	printf("GPRS:\n");
>>   	printf("%016lx %016lx %016lx %016lx\n",
>>   	       stack->grs1[0], stack->grs1[1], stack->grs0[0], stack->grs0[1]);
>> @@ -198,24 +202,56 @@ static void print_int_regs(struct stack_frame_int *stack)
>>   	       stack->grs0[2], stack->grs0[3], stack->grs0[4], stack->grs0[5]);
>>   	printf("%016lx %016lx %016lx %016lx\n",
>>   	       stack->grs0[6], stack->grs0[7], stack->grs0[8], stack->grs0[9]);
>> -	printf("%016lx %016lx %016lx %016lx\n",
>> -	       stack->grs0[10], stack->grs0[11], stack->grs0[12], stack->grs0[13]);
>> +
>> +	if (sie) {
>> +		sblk = (struct kvm_s390_sie_block *)stack->grs0[12];
>> +		printf("%016lx %016lx %016lx %016lx\n",
>> +		       stack->grs0[10], stack->grs0[11], sblk->gg14, sblk->gg15);
>> +	} else {
>> +		printf("%016lx %016lx %016lx %016lx\n",
>> +		       stack->grs0[10], stack->grs0[11], stack->grs0[12], stack->grs0[13]);
>> +	}
>> +
>>   	printf("\n");
>>   }
>>   
>>   static void print_pgm_info(struct stack_frame_int *stack)
>>   
>>   {
>> -	bool in_sie;
>> +	bool in_sie, in_sie_gregs;
>> +	struct vm_save_area *vregs;
>>   
>>   	in_sie = (lowcore.pgm_old_psw.addr >= (uintptr_t)sie_entry &&
>>   		  lowcore.pgm_old_psw.addr <= (uintptr_t)sie_exit);
>> +	in_sie_gregs = (lowcore.pgm_old_psw.addr >= (uintptr_t)sie_entry_gregs &&
>> +			lowcore.pgm_old_psw.addr <= (uintptr_t)sie_exit_gregs);
> 
> can you explain why <= instead of < ? (I think I know why, but a
> comment would not hurt)

This might be wrong now that the exit label points behind a lmg which 
can only cause the operation or the addressing exception.

The operation exception can only happen on a LMY without the long 
displacement HW support and the addressing exception should only happen 
in circumstances where any processed instruction will likely result in a 
new exception being thrown.

> 
> with that fixed:
> 
> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> 
>>   
>>   	printf("\n");
>>   	printf("Unexpected program interrupt %s: %#x on cpu %d at %#lx, ilen %d\n",
>>   	       in_sie ? "in SIE" : "",
>>   	       lowcore.pgm_int_code, stap(), lowcore.pgm_old_psw.addr, lowcore.pgm_int_id);
>> -	print_int_regs(stack);
>> +
>> +	/*
>> +	 * If we fall out of SIE before loading the host registers,
>> +	 * then we need to do it here so we print the host registers
>> +	 * and not the guest registers.
>> +	 *
>> +	 * Back tracing is actually not a problem since SIE restores gr15.
>> +	 */
>> +	if (in_sie_gregs) {
>> +		print_int_regs(stack, true);
>> +		vregs = *((struct vm_save_area **)(stack->grs0[13] + __SF_SIE_SAVEAREA));
>> +
>> +		/*
>> +		 * The grs are not linear on the interrupt stack frame.
>> +		 * We copy 0 and 1 here and 2 - 15 with the memcopy below.
>> +		 */
>> +		stack->grs1[0] = vregs->host.grs[0];
>> +		stack->grs1[1] = vregs->host.grs[1];
>> +		/*  2 - 15 */
>> +		memcpy(stack->grs0, &vregs->host.grs[2], sizeof(stack->grs0) - 8);
>> +	}
>> +	print_int_regs(stack, false);
>>   	dump_stack();
>>   
>>   	/* Dump stack doesn't end with a \n so we add it here instead */
>> diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
>> index a27a8401..147cb0f2 100644
>> --- a/lib/s390x/sie.h
>> +++ b/lib/s390x/sie.h
>> @@ -273,6 +273,8 @@ struct vm {
>>   
>>   extern void sie_entry(void);
>>   extern void sie_exit(void);
>> +extern void sie_entry_gregs(void);
>> +extern void sie_exit_gregs(void);
>>   extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_area);
>>   void sie(struct vm *vm);
>>   void sie_expect_validity(struct vm *vm);
>> diff --git a/s390x/cpu.S b/s390x/cpu.S
>> index 45bd551a..9155b044 100644
>> --- a/s390x/cpu.S
>> +++ b/s390x/cpu.S
>> @@ -82,7 +82,8 @@ sie64a:
>>   	# Store scb and save_area pointer into stack frame
>>   	stg	%r2,__SF_SIE_CONTROL(%r15)	# save control block pointer
>>   	stg	%r3,__SF_SIE_SAVEAREA(%r15)	# save guest register save area
>> -
>> +.globl sie_entry_gregs
>> +sie_entry_gregs:
>>   	# Load guest's gprs, fprs and fpc
>>   	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
>>   	ld	\i, \i * 8 + SIE_SAVEAREA_GUEST_FPRS(%r3)
>> @@ -121,7 +122,8 @@ sie_exit:
>>   	.endr
>>   	lfpc	SIE_SAVEAREA_HOST_FPC(%r14)
>>   	lmg	%r0,%r14,SIE_SAVEAREA_HOST_GRS(%r14)	# restore kernel registers
>> -
>> +.globl sie_exit_gregs
>> +sie_exit_gregs:
>>   	br	%r14
>>   
>>   	.align	8
>
diff mbox series

Patch

diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
index dadb7415..ff47c2c2 100644
--- a/lib/s390x/interrupt.c
+++ b/lib/s390x/interrupt.c
@@ -9,6 +9,7 @@ 
  */
 #include <libcflat.h>
 #include <asm/barrier.h>
+#include <asm/asm-offsets.h>
 #include <sclp.h>
 #include <interrupt.h>
 #include <sie.h>
@@ -188,9 +189,12 @@  static void print_storage_exception_information(void)
 	}
 }
 
-static void print_int_regs(struct stack_frame_int *stack)
+static void print_int_regs(struct stack_frame_int *stack, bool sie)
 {
+	struct kvm_s390_sie_block *sblk;
+
 	printf("\n");
+	printf("%s\n", sie ? "Guest registers:" : "Host registers:");
 	printf("GPRS:\n");
 	printf("%016lx %016lx %016lx %016lx\n",
 	       stack->grs1[0], stack->grs1[1], stack->grs0[0], stack->grs0[1]);
@@ -198,24 +202,56 @@  static void print_int_regs(struct stack_frame_int *stack)
 	       stack->grs0[2], stack->grs0[3], stack->grs0[4], stack->grs0[5]);
 	printf("%016lx %016lx %016lx %016lx\n",
 	       stack->grs0[6], stack->grs0[7], stack->grs0[8], stack->grs0[9]);
-	printf("%016lx %016lx %016lx %016lx\n",
-	       stack->grs0[10], stack->grs0[11], stack->grs0[12], stack->grs0[13]);
+
+	if (sie) {
+		sblk = (struct kvm_s390_sie_block *)stack->grs0[12];
+		printf("%016lx %016lx %016lx %016lx\n",
+		       stack->grs0[10], stack->grs0[11], sblk->gg14, sblk->gg15);
+	} else {
+		printf("%016lx %016lx %016lx %016lx\n",
+		       stack->grs0[10], stack->grs0[11], stack->grs0[12], stack->grs0[13]);
+	}
+
 	printf("\n");
 }
 
 static void print_pgm_info(struct stack_frame_int *stack)
 
 {
-	bool in_sie;
+	bool in_sie, in_sie_gregs;
+	struct vm_save_area *vregs;
 
 	in_sie = (lowcore.pgm_old_psw.addr >= (uintptr_t)sie_entry &&
 		  lowcore.pgm_old_psw.addr <= (uintptr_t)sie_exit);
+	in_sie_gregs = (lowcore.pgm_old_psw.addr >= (uintptr_t)sie_entry_gregs &&
+			lowcore.pgm_old_psw.addr <= (uintptr_t)sie_exit_gregs);
 
 	printf("\n");
 	printf("Unexpected program interrupt %s: %#x on cpu %d at %#lx, ilen %d\n",
 	       in_sie ? "in SIE" : "",
 	       lowcore.pgm_int_code, stap(), lowcore.pgm_old_psw.addr, lowcore.pgm_int_id);
-	print_int_regs(stack);
+
+	/*
+	 * If we fall out of SIE before loading the host registers,
+	 * then we need to do it here so we print the host registers
+	 * and not the guest registers.
+	 *
+	 * Back tracing is actually not a problem since SIE restores gr15.
+	 */
+	if (in_sie_gregs) {
+		print_int_regs(stack, true);
+		vregs = *((struct vm_save_area **)(stack->grs0[13] + __SF_SIE_SAVEAREA));
+
+		/*
+		 * The grs are not linear on the interrupt stack frame.
+		 * We copy 0 and 1 here and 2 - 15 with the memcopy below.
+		 */
+		stack->grs1[0] = vregs->host.grs[0];
+		stack->grs1[1] = vregs->host.grs[1];
+		/*  2 - 15 */
+		memcpy(stack->grs0, &vregs->host.grs[2], sizeof(stack->grs0) - 8);
+	}
+	print_int_regs(stack, false);
 	dump_stack();
 
 	/* Dump stack doesn't end with a \n so we add it here instead */
diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
index a27a8401..147cb0f2 100644
--- a/lib/s390x/sie.h
+++ b/lib/s390x/sie.h
@@ -273,6 +273,8 @@  struct vm {
 
 extern void sie_entry(void);
 extern void sie_exit(void);
+extern void sie_entry_gregs(void);
+extern void sie_exit_gregs(void);
 extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_area);
 void sie(struct vm *vm);
 void sie_expect_validity(struct vm *vm);
diff --git a/s390x/cpu.S b/s390x/cpu.S
index 45bd551a..9155b044 100644
--- a/s390x/cpu.S
+++ b/s390x/cpu.S
@@ -82,7 +82,8 @@  sie64a:
 	# Store scb and save_area pointer into stack frame
 	stg	%r2,__SF_SIE_CONTROL(%r15)	# save control block pointer
 	stg	%r3,__SF_SIE_SAVEAREA(%r15)	# save guest register save area
-
+.globl sie_entry_gregs
+sie_entry_gregs:
 	# Load guest's gprs, fprs and fpc
 	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
 	ld	\i, \i * 8 + SIE_SAVEAREA_GUEST_FPRS(%r3)
@@ -121,7 +122,8 @@  sie_exit:
 	.endr
 	lfpc	SIE_SAVEAREA_HOST_FPC(%r14)
 	lmg	%r0,%r14,SIE_SAVEAREA_HOST_GRS(%r14)	# restore kernel registers
-
+.globl sie_exit_gregs
+sie_exit_gregs:
 	br	%r14
 
 	.align	8