KVM: s390: vsie: Avoid injecting machine check on signal
Christian Borntraeger
maintainerPATCH v3 1/1 KVM: s390: vsie: Avoid injecting machine check on signal
The recent XFER_TO_GUEST_WORK change resulted in a situation, where the vsie code would interpret a signal during work as a machine check during SIE as both use the EINTR return code.
The exit_reason of the sie64a function has nothing to do with the kvm_run exit_reason. Rename it and define a specific code for machine checks instead of abusing -EINTR.
rename exit_reason into sie_return to avoid the naming conflict and change the code flow in vsie.c to have a separate variable for rc and sie_return.
---v1->v2:
instead of a band-aid, make the machine check more direct v2->v3:
avoid overloading the rc variable in vsie.c
arch/s390/include/asm/kvm_host.h | 3 +++ arch/s390/include/asm/stacktrace.h | 2 +- arch/s390/kernel/asm-offsets.c | 2 +- arch/s390/kernel/entry.S | 4 ++-- arch/s390/kernel/nmi.c | 4 ++-- arch/s390/kvm/kvm-s390.c | 15 ++++++++------- arch/s390/kvm/vsie.c | 7 +++++-- 7 files changed, 22 insertions(+), 15 deletions(-)
arch/s390/include/asm/kvm_host.h +3 -0
@@ -710,6 +710,9 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm);void kvm_arch_crypto_set_masks (struct kvm *kvm,unsigned long *apm,unsigned long *aqm,unsigned long *adm); +#define SIE64_RETURN_NORMAL 0 +#define SIE64_RETURN_MCCK 1 +int __sie64a (phys_addr_t sie_block_phys,struct kvm_s390_sie_block *sie_block,u64 *rsa,unsigned long gasce);
arch/s390/include/asm/stacktrace.h +1 -1
@@ -62,7 +62,7 @@ struct stack_frame {struct {unsigned long sie_control_block;unsigned long sie_savearea; -unsigned long sie_reason; +unsigned long sie_return;unsigned long sie_flags;unsigned long sie_control_block_phys;unsigned long sie_guest_asce;
arch/s390/kernel/asm-offsets.c +1 -1
@@ -63,7 +63,7 @@ int main(void)OFFSET (__SF_EMPTY, stack_frame, empty[0 ]);OFFSET (__SF_SIE_CONTROL, stack_frame, sie_control_block);OFFSET (__SF_SIE_SAVEAREA, stack_frame, sie_savearea); -OFFSET (__SF_SIE_REASON, stack_frame, sie_reason); +OFFSET (__SF_SIE_RETURN, stack_frame, sie_return);OFFSET (__SF_SIE_FLAGS, stack_frame, sie_flags);OFFSET (__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys);OFFSET (__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);
arch/s390/kernel/entry.S +2 -2
@@ -200,7 +200,7 @@ SYM_FUNC_START(__sie64a) stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area stg %r5,__SF_SIE_GUEST_ASCE(%r15) # save guest asce - xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0 + xc __SF_SIE_RETURN(8,%r15),__SF_SIE_RETURN(%r15) # return code = 0 mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags lmg %r0,%r13,0(%r4) # load guest gprs 0-13 mvi __TI_sie(%r14),1
@@ -237,7 +237,7 @@ SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL) xgr %r4,%r4 xgr %r5,%r5 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers - lg %r2,__SF_SIE_REASON(%r15) # return exit reason code + lg %r2,__SF_SIE_RETURN(%r15) # return sie return code BR_EX %r14 SYM_FUNC_END(__sie64a) EXPORT_SYMBOL(__sie64a)
arch/s390/kernel/nmi.c +2 -2
@@ -487,8 +487,8 @@ void notrace s390_do_machine_check(struct pt_regs *regs) mcck_dam_code = (mci.val &MCIC_SUBCLASS_MASK );if (test_cpu_flag (CIF_MCCK_GUEST ) && (mcck_dam_code &MCCK_CODE_NO_GUEST ) != mcck_dam_code) { -/* Set exit reason code for host's later handling */ - *((long *)(regs->gprs[15 ] + __SF_SIE_REASON)) = -EINTR ; +/* Set sie return code for host's later handling */ + *((long *)(regs->gprs[15 ] + __SF_SIE_RETURN)) =SIE64_RETURN_MCCK ; }clear_cpu_flag (CIF_MCCK_GUEST );
arch/s390/kvm/kvm-s390.c +8 -7
@@ -4617,7 +4617,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)return 0 ; } -static int vcpu_post_run (struct kvm_vcpu *vcpu,int exit_reason) +static int vcpu_post_run (struct kvm_vcpu *vcpu,int sie_return) {struct mcck_volatile_info *mcck_info;struct sie_page *sie_page;
@@ -4633,13 +4633,14 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason) vcpu->run->s.regs.gprs[14 ] = vcpu->arch.sie_block->gg14; vcpu->run->s.regs.gprs[15 ] = vcpu->arch.sie_block->gg15; -if (exit_reason == -EINTR ) { +if (sie_return ==SIE64_RETURN_MCCK ) { sie_page =container_of (vcpu->arch.sie_block, struct sie_page, sie_block); mcck_info = &sie_page->mcck_info;kvm_s390_reinject_machine_check (vcpu, mcck_info);return 0 ; } +WARN_ON (sie_return !=SIE64_RETURN_NORMAL );if (vcpu->arch.sie_block->icptcode >0 ) { rc =kvm_handle_sie_intercept (vcpu);
@@ -4678,7 +4679,7 @@ int noinstr kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,#define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)static int __vcpu_run (struct kvm_vcpu *vcpu) { -int rc, exit_reason; +int rc, sie_return;struct sie_page *sie_page = (struct sie_page *)vcpu->arch.sie_block;/*
@@ -4718,9 +4719,9 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)guest_timing_enter_irqoff ();__disable_cpu_timer_accounting (vcpu); - exit_reason =kvm_s390_enter_exit_sie (vcpu->arch.sie_block, - vcpu->run->s.regs.gprs, - vcpu->arch.gmap->asce.val); + sie_return =kvm_s390_enter_exit_sie (vcpu->arch.sie_block, + vcpu->run->s.regs.gprs, + vcpu->arch.gmap->asce.val);__enable_cpu_timer_accounting (vcpu);guest_timing_exit_irqoff ();
@@ -4743,7 +4744,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu) }kvm_vcpu_srcu_read_lock (vcpu); - rc =vcpu_post_run (vcpu, exit_reason); + rc =vcpu_post_run (vcpu, sie_return);if (rc ||guestdbg_exit_pending (vcpu)) {kvm_vcpu_srcu_read_unlock (vcpu);break ;
arch/s390/kvm/vsie.c +5 -2
@@ -1123,6 +1123,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, strucstruct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;int guest_bp_isolation; +int sie_return =SIE64_RETURN_NORMAL ;int rc =0 ;handle_last_fault (vcpu, vsie_page, sg);
@@ -1163,7 +1164,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc goto xfer_to_guest_mode_check; }guest_timing_enter_irqoff (); - rc =kvm_s390_enter_exit_sie (scb_s, vcpu->run->s.regs.gprs, sg->asce.val); + sie_return =kvm_s390_enter_exit_sie (scb_s, vcpu->run->s.regs.gprs, sg->asce.val);guest_timing_exit_irqoff ();local_irq_enable (); }
@@ -1178,11 +1179,13 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struckvm_vcpu_srcu_read_lock (vcpu); -if (rc == -EINTR ) { +if (sie_return ==SIE64_RETURN_MCCK ) {kvm_s390_reinject_machine_check (vcpu, &vsie_page->mcck_info);return 0 ; } +WARN_ON (sie_return !=SIE64_RETURN_NORMAL ); +if (rc >0 ) rc =0 ;/* we could still have an icpt */ else if (current->thread.gmap_int_code)
Signature · 1 line
2.53.0
Quoted 26 lines · Christian Borntraeger
The recent
XFER_TO_GUEST_WORKchange resulted in a situation, where the vsie code would interpret a signal during work as a machine check during SIE as both use the EINTR return code.
Theexit_reasonof the sie64a function has nothing to do with thekvm_runexit_reason. Rename it and define a specific code for machine checks instead of abusing-EINTR.
renameexit_reasonintosie_returnto avoid the naming conflict and change the code flow invsie.cto have a separate variable for rc andsie_return.Fixes 2bd1337a1295e ("KVM: s390: Use generic VIRT_XFER_TO_GUEST_WORK functions")Signed-off-by Christian Borntraeger <[email protected]>---
v1->v2:
instead of a band-aid, make the machine check more directv2->v3:
avoid overloading the rc variable invsie.carch/s390/include/asm/kvm_host.h | 3 +++ arch/s390/include/asm/stacktrace.h | 2 +- arch/s390/kernel/asm-offsets.c | 2 +- arch/s390/kernel/entry.S | 4 ++-- arch/s390/kernel/nmi.c | 4 ++-- arch/s390/kvm/kvm-s390.c | 15 ++++++++------- arch/s390/kvm/vsie.c | 7 +++++-- 7 files changed, 22 insertions(+), 15 deletions(-)
...
arch/s390/kvm/vsie.c static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc · line 1127
Quoted 10 lines
arch/s390/kvm/vsie.c +1
-0@@ -1123,6 +1123,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, strucstruct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;int guest_bp_isolation; +int sie_return =SIE64_RETURN_NORMAL ;int rc =0 ;
Move that one line up to keep the reverse x-mas style?
arch/s390/kvm/vsie.c static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc · line 1128
Quoted 1 line
arch/s390/kvm/vsie.c +1
-0+WARN_ON (sie_return !=SIE64_RETURN_NORMAL );
And as written in the previous version: both should be WARN_ON_ONCE() I guess.
Anyway:
Quoted 10 lines · On Mon, 16 Mar 2026 14:09:47 +0100 Christian Borntraeger…
The recent
XFER_TO_GUEST_WORKchange resulted in a situation, where the vsie code would interpret a signal during work as a machine check during SIE as both use the EINTR return code.
Theexit_reasonof the sie64a function has nothing to do with thekvm_runexit_reason. Rename it and define a specific code for machine checks instead of abusing-EINTR.
renameexit_reasonintosie_returnto avoid the naming conflict and change the code flow invsie.cto have a separate variable for rc andsie_return.
Quoted 2 lines
Fixes 2bd1337a1295e ("KVM: s390: Use generic VIRT_XFER_TO_GUEST_WORK functions")Signed-off-by Christian Borntraeger <[email protected]>
With Heiko's comments addresssed:
Quoted 188 lines
---
v1->v2:
instead of a band-aid, make the machine check more directv2->v3:
avoid overloading the rc variable invsie.carch/s390/include/asm/kvm_host.h | 3 +++ arch/s390/include/asm/stacktrace.h | 2 +- arch/s390/kernel/asm-offsets.c | 2 +- arch/s390/kernel/entry.S | 4 ++-- arch/s390/kernel/nmi.c | 4 ++-- arch/s390/kvm/kvm-s390.c | 15 ++++++++------- arch/s390/kvm/vsie.c | 7 +++++-- 7 files changed, 22 insertions(+), 15 deletions(-)arch/s390/include/asm/kvm_host.h +3
-0@@ -710,6 +710,9 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm);void kvm_arch_crypto_set_masks (struct kvm *kvm,unsigned long *apm,unsigned long *aqm,unsigned long *adm); +#define SIE64_RETURN_NORMAL 0 +#define SIE64_RETURN_MCCK 1 +int __sie64a (phys_addr_t sie_block_phys,struct kvm_s390_sie_block *sie_block,u64 *rsa,unsigned long gasce);arch/s390/include/asm/stacktrace.h +1
-1@@ -62,7 +62,7 @@ struct stack_frame {struct {unsigned long sie_control_block;unsigned long sie_savearea; -unsigned long sie_reason; +unsigned long sie_return;unsigned long sie_flags;unsigned long sie_control_block_phys;unsigned long sie_guest_asce;arch/s390/kernel/asm-offsets.c +1
-1@@ -63,7 +63,7 @@ int main(void)OFFSET (__SF_EMPTY, stack_frame, empty[0 ]);OFFSET (__SF_SIE_CONTROL, stack_frame, sie_control_block);OFFSET (__SF_SIE_SAVEAREA, stack_frame, sie_savearea); -OFFSET (__SF_SIE_REASON, stack_frame, sie_reason); +OFFSET (__SF_SIE_RETURN, stack_frame, sie_return);OFFSET (__SF_SIE_FLAGS, stack_frame, sie_flags);OFFSET (__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys);OFFSET (__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);arch/s390/kernel/entry.S +2
-2@@ -200,7 +200,7 @@ SYM_FUNC_START(__sie64a) stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area stg %r5,__SF_SIE_GUEST_ASCE(%r15) # save guest asce - xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0 + xc __SF_SIE_RETURN(8,%r15),__SF_SIE_RETURN(%r15) # return code = 0 mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags lmg %r0,%r13,0(%r4) # load guest gprs 0-13 mvi __TI_sie(%r14),1@@ -237,7 +237,7 @@ SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL) xgr %r4,%r4 xgr %r5,%r5 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers - lg %r2,__SF_SIE_REASON(%r15) # return exit reason code + lg %r2,__SF_SIE_RETURN(%r15) # return sie return code BR_EX %r14 SYM_FUNC_END(__sie64a) EXPORT_SYMBOL(__sie64a)arch/s390/kernel/nmi.c +2
-2@@ -487,8 +487,8 @@ void notrace s390_do_machine_check(struct pt_regs *regs) mcck_dam_code = (mci.val &MCIC_SUBCLASS_MASK );if (test_cpu_flag (CIF_MCCK_GUEST ) && (mcck_dam_code &MCCK_CODE_NO_GUEST ) != mcck_dam_code) { -/* Set exit reason code for host's later handling */ - *((long *)(regs->gprs[15 ] + __SF_SIE_REASON)) = -EINTR ; +/* Set sie return code for host's later handling */ + *((long *)(regs->gprs[15 ] + __SF_SIE_RETURN)) =SIE64_RETURN_MCCK ; }clear_cpu_flag (CIF_MCCK_GUEST );arch/s390/kvm/kvm-s390.c +8
-7@@ -4617,7 +4617,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)return 0 ; } -static int vcpu_post_run (struct kvm_vcpu *vcpu,int exit_reason) +static int vcpu_post_run (struct kvm_vcpu *vcpu,int sie_return) {struct mcck_volatile_info *mcck_info;struct sie_page *sie_page;@@ -4633,13 +4633,14 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason) vcpu->run->s.regs.gprs[14 ] = vcpu->arch.sie_block->gg14; vcpu->run->s.regs.gprs[15 ] = vcpu->arch.sie_block->gg15; -if (exit_reason == -EINTR ) { +if (sie_return ==SIE64_RETURN_MCCK ) { sie_page =container_of (vcpu->arch.sie_block, struct sie_page, sie_block); mcck_info = &sie_page->mcck_info;kvm_s390_reinject_machine_check (vcpu, mcck_info);return 0 ; } +WARN_ON (sie_return !=SIE64_RETURN_NORMAL );if (vcpu->arch.sie_block->icptcode >0 ) { rc =kvm_handle_sie_intercept (vcpu);@@ -4678,7 +4679,7 @@ int noinstr kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,#define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)static int __vcpu_run (struct kvm_vcpu *vcpu) { -int rc, exit_reason; +int rc, sie_return;struct sie_page *sie_page = (struct sie_page *)vcpu->arch.sie_block;/* @@ -4718,9 +4719,9 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)guest_timing_enter_irqoff ();__disable_cpu_timer_accounting (vcpu); - exit_reason =kvm_s390_enter_exit_sie (vcpu->arch.sie_block, - vcpu->run->s.regs.gprs, - vcpu->arch.gmap->asce.val); + sie_return =kvm_s390_enter_exit_sie (vcpu->arch.sie_block, + vcpu->run->s.regs.gprs, + vcpu->arch.gmap->asce.val);__enable_cpu_timer_accounting (vcpu);guest_timing_exit_irqoff ();@@ -4743,7 +4744,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu) }kvm_vcpu_srcu_read_lock (vcpu); - rc =vcpu_post_run (vcpu, exit_reason); + rc =vcpu_post_run (vcpu, sie_return);if (rc ||guestdbg_exit_pending (vcpu)) {kvm_vcpu_srcu_read_unlock (vcpu);break ;arch/s390/kvm/vsie.c +5
-2@@ -1123,6 +1123,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, strucstruct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;int guest_bp_isolation; +int sie_return =SIE64_RETURN_NORMAL ;int rc =0 ;handle_last_fault (vcpu, vsie_page, sg);@@ -1163,7 +1164,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc goto xfer_to_guest_mode_check; }guest_timing_enter_irqoff (); - rc =kvm_s390_enter_exit_sie (scb_s, vcpu->run->s.regs.gprs, sg->asce.val); + sie_return =kvm_s390_enter_exit_sie (scb_s, vcpu->run->s.regs.gprs, sg->asce.val);guest_timing_exit_irqoff ();local_irq_enable (); }@@ -1178,11 +1179,13 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struckvm_vcpu_srcu_read_lock (vcpu); -if (rc == -EINTR ) { +if (sie_return ==SIE64_RETURN_MCCK ) {kvm_s390_reinject_machine_check (vcpu, &vsie_page->mcck_info);return 0 ; } +WARN_ON (sie_return !=SIE64_RETURN_NORMAL ); +if (rc >0 ) rc =0 ;/* we could still have an icpt */ else if (current->thread.gmap_int_code)
Janosch Frank
maintainerQuoted 94 lines · Christian Borntraeger
The recent
XFER_TO_GUEST_WORKchange resulted in a situation, where the vsie code would interpret a signal during work as a machine check during SIE as both use the EINTR return code.
Theexit_reasonof the sie64a function has nothing to do with thekvm_runexit_reason. Rename it and define a specific code for machine checks instead of abusing-EINTR.
renameexit_reasonintosie_returnto avoid the naming conflict and change the code flow invsie.cto have a separate variable for rc andsie_return.Fixes 2bd1337a1295e ("KVM: s390: Use generic VIRT_XFER_TO_GUEST_WORK functions")Signed-off-by Christian Borntraeger <[email protected]>---
v1->v2:
instead of a band-aid, make the machine check more directv2->v3:
avoid overloading the rc variable invsie.carch/s390/include/asm/kvm_host.h | 3 +++ arch/s390/include/asm/stacktrace.h | 2 +- arch/s390/kernel/asm-offsets.c | 2 +- arch/s390/kernel/entry.S | 4 ++-- arch/s390/kernel/nmi.c | 4 ++-- arch/s390/kvm/kvm-s390.c | 15 ++++++++------- arch/s390/kvm/vsie.c | 7 +++++-- 7 files changed, 22 insertions(+), 15 deletions(-)arch/s390/include/asm/kvm_host.h +3
-0@@ -710,6 +710,9 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm);void kvm_arch_crypto_set_masks (struct kvm *kvm,unsigned long *apm,unsigned long *aqm,unsigned long *adm); +#define SIE64_RETURN_NORMAL 0 +#define SIE64_RETURN_MCCK 1 +int __sie64a (phys_addr_t sie_block_phys,struct kvm_s390_sie_block *sie_block,u64 *rsa,unsigned long gasce);arch/s390/include/asm/stacktrace.h +1
-1@@ -62,7 +62,7 @@ struct stack_frame {struct {unsigned long sie_control_block;unsigned long sie_savearea; -unsigned long sie_reason; +unsigned long sie_return;unsigned long sie_flags;unsigned long sie_control_block_phys;unsigned long sie_guest_asce;arch/s390/kernel/asm-offsets.c +1
-1@@ -63,7 +63,7 @@ int main(void)OFFSET (__SF_EMPTY, stack_frame, empty[0 ]);OFFSET (__SF_SIE_CONTROL, stack_frame, sie_control_block);OFFSET (__SF_SIE_SAVEAREA, stack_frame, sie_savearea); -OFFSET (__SF_SIE_REASON, stack_frame, sie_reason); +OFFSET (__SF_SIE_RETURN, stack_frame, sie_return);OFFSET (__SF_SIE_FLAGS, stack_frame, sie_flags);OFFSET (__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys);OFFSET (__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);arch/s390/kernel/entry.S +2
-2@@ -200,7 +200,7 @@ SYM_FUNC_START(__sie64a) stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area stg %r5,__SF_SIE_GUEST_ASCE(%r15) # save guest asce - xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0 + xc __SF_SIE_RETURN(8,%r15),__SF_SIE_RETURN(%r15) # return code = 0 mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags lmg %r0,%r13,0(%r4) # load guest gprs 0-13 mvi __TI_sie(%r14),1@@ -237,7 +237,7 @@ SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL) xgr %r4,%r4 xgr %r5,%r5 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers - lg %r2,__SF_SIE_REASON(%r15) # return exit reason code + lg %r2,__SF_SIE_RETURN(%r15) # return sie return code BR_EX %r14 SYM_FUNC_END(__sie64a) EXPORT_SYMBOL(__sie64a)arch/s390/kernel/nmi.c +0
-0
arch/s390/kernel/nmi.c void notrace s390_do_machine_check(struct pt_regs *regs) · line 491
Quoted 7 lines
arch/s390/kernel/nmi.c +2
-2@@ -487,8 +487,8 @@ void notrace s390_do_machine_check(struct pt_regs *regs) mcck_dam_code = (mci.val &MCIC_SUBCLASS_MASK );if (test_cpu_flag (CIF_MCCK_GUEST ) && (mcck_dam_code &MCCK_CODE_NO_GUEST ) != mcck_dam_code) { -/* Set exit reason code for host's later handling */ - *((long *)(regs->gprs[15 ] + __SF_SIE_REASON)) = -EINTR ; +/* Set sie return code for host's later handling */ + *((long *)(regs->gprs[15 ] + __SF_SIE_RETURN)) =SIE64_RETURN_MCCK ;
We don't need to cast this to long anymore, do we?
Since sie_return is ulong, and we if we stay with positive numbers ulong would make the most sense.
Although I'd prefer a cast to stack_frame but I'm unsure if that would make it more readable if we stay with a one line change.
Rest looks good to me
Christian Borntraeger
maintainerAm 16.03.26 um 14:57 schrieb Janosch Frank:
Quoted 104 lines · Christian Borntraeger
Quoted 93 lines
The recent
XFER_TO_GUEST_WORKchange resulted in a situation, where the vsie code would interpret a signal during work as a machine check during SIE as both use the EINTR return code.
Theexit_reasonof the sie64a function has nothing to do with thekvm_runexit_reason. Rename it and define a specific code for machine checks instead of abusing-EINTR.
renameexit_reasonintosie_returnto avoid the naming conflict and change the code flow invsie.cto have a separate variable for rc andsie_return.Fixes 2bd1337a1295e ("KVM: s390: Use generic VIRT_XFER_TO_GUEST_WORK functions")Signed-off-by Christian Borntraeger <[email protected]>---
v1->v2:
instead of a band-aid, make the machine check more directv2->v3:
avoid overloading the rc variable invsie.carch/s390/include/asm/kvm_host.h | 3 +++
arch/s390/include/asm/stacktrace.h| 2 +- arch/s390/kernel/asm-offsets.c | 2 +- arch/s390/kernel/entry.S | 4 ++-- arch/s390/kernel/nmi.c | 4 ++-- arch/s390/kvm/kvm-s390.c | 15 ++++++++------- arch/s390/kvm/vsie.c | 7 +++++--7 files changed, 22 insertions(+), 15 deletions(-)arch/s390/include/asm/kvm_host.h +3
-0@@ -710,6 +710,9 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm); void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm, unsigned long *aqm, unsigned long *adm); +#define SIE64_RETURN_NORMAL 0 +#define SIE64_RETURN_MCCK 1 + int __sie64a(phys_addr_t sie_block_phys, struct kvm_s390_sie_block *sie_block, u64 *rsa, unsigned long gasce);arch/s390/include/asm/stacktrace.h +1
-1@@ -62,7 +62,7 @@ struct stack_frame { struct { unsigned long sie_control_block; unsigned long sie_savearea; - unsigned long sie_reason; + unsigned long sie_return; unsigned long sie_flags; unsigned long sie_control_block_phys; unsigned long sie_guest_asce;arch/s390/kernel/asm-offsets.c +1
-1@@ -63,7 +63,7 @@ int main(void) OFFSET(__SF_EMPTY, stack_frame, empty[0]); OFFSET(__SF_SIE_CONTROL, stack_frame, sie_control_block); OFFSET(__SF_SIE_SAVEAREA, stack_frame, sie_savearea); - OFFSET(__SF_SIE_REASON, stack_frame, sie_reason); + OFFSET(__SF_SIE_RETURN, stack_frame, sie_return); OFFSET(__SF_SIE_FLAGS, stack_frame, sie_flags); OFFSET(__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys); OFFSET(__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);arch/s390/kernel/entry.S +0
-0@@ -200,7 +200,7 @@ SYM_FUNC_START(__sie64a)stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area stg %r5,__SF_SIE_GUEST_ASCE(%r15) # save guest asce - xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0 + xc __SF_SIE_RETURN(8,%r15),__SF_SIE_RETURN(%r15) # return code = 0 mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags lmg %r0,%r13,0(%r4) # load guest gprs 0-13 mvi __TI_sie(%r14),1
arch/s390/kernel/entry.S +0
-0@@ -237,7 +237,7 @@ SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL)xgr %r4,%r4
xgr %r5,%r5
lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers - lg %r2,__SF_SIE_REASON(%r15) # return exit reason code + lg %r2,__SF_SIE_RETURN(%r15) # return sie return code BR_EX %r14
SYM_FUNC_END(__sie64a)
EXPORT_SYMBOL(__sie64a)arch/s390/kernel/nmi.c +0
-0@@ -487,8 +487,8 @@ void notrace s390_do_machine_check(struct pt_regs *regs) mcck_dam_code = (mci.val & MCIC_SUBCLASS_MASK);Quoted 6 lines
if (
test_cpu_flag(CIF_MCCK_GUEST)&&
(mcck_dam_code&MCCK_CODE_NO_GUEST) !=mcck_dam_code) { - /* Set exit reason code for host's later handling */
- *((long *)(regs->gprs[15] +__SF_SIE_REASON)) =-EINTR; + /* Set sie return code for host's later handling */
+ *((long *)(regs->gprs[15] +__SF_SIE_RETURN)) =SIE64_RETURN_MCCK;We don't need to cast this to long anymore, do we?
Sincesie_returnis ulong, and we if we stay with positive numbers ulong would make the most sense.
Quoted 1 line
Although I'd prefer a cast to
stack_framebut I'm unsure if that would make it more readable if we stay with a one line change.
something like
- *((long *)(regs->gprs[15] + __SF_SIE_RETURN)) = SIE64_RETURN_MCCK;
+ ((struct stack_frame *) regs->gprs[15])->sie_return = SIE64_RETURN_MCCK;
What do you think?
This reminds me that I should probably also make the local variable in vsie.c unsigned long instead of int.
Janosch Frank
maintainerQuoted 111 lines · Christian Borntraeger
Am 16.03.26 um 14:57 schrieb Janosch Frank:
Quoted 104 lines · Christian Borntraeger
Quoted 92 lines
The recent
XFER_TO_GUEST_WORKchange resulted in a situation, where the vsie code would interpret a signal during work as a machine check during SIE as both use the EINTR return code.
Theexit_reasonof the sie64a function has nothing to do with thekvm_runexit_reason. Rename it and define a specific code for machine checks instead of abusing-EINTR.
renameexit_reasonintosie_returnto avoid the naming conflict and change the code flow invsie.cto have a separate variable for rc andsie_return.Fixes 2bd1337a1295e ("KVM: s390: Use generic VIRT_XFER_TO_GUEST_WORK functions")Signed-off-by Christian Borntraeger <[email protected]>---
v1->v2:
instead of a band-aid, make the machine check more directv2->v3:
avoid overloading the rc variable invsie.carch/s390/include/asm/kvm_host.h | 3 +++ arch/s390/include/asm/stacktrace.h | 2 +- arch/s390/kernel/asm-offsets.c | 2 +- arch/s390/kernel/entry.S | 4 ++-- arch/s390/kernel/nmi.c | 4 ++-- arch/s390/kvm/kvm-s390.c | 15 ++++++++------- arch/s390/kvm/vsie.c | 7 +++++-- 7 files changed, 22 insertions(+), 15 deletions(-)arch/s390/include/asm/kvm_host.h +3
-0@@ -710,6 +710,9 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm); void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm, unsigned long *aqm, unsigned long *adm); +#define SIE64_RETURN_NORMAL 0 +#define SIE64_RETURN_MCCK 1 + int __sie64a(phys_addr_t sie_block_phys, struct kvm_s390_sie_block *sie_block, u64 *rsa, unsigned long gasce);arch/s390/include/asm/stacktrace.h +1
-1@@ -62,7 +62,7 @@ struct stack_frame { struct { unsigned long sie_control_block; unsigned long sie_savearea; - unsigned long sie_reason; + unsigned long sie_return; unsigned long sie_flags; unsigned long sie_control_block_phys; unsigned long sie_guest_asce;arch/s390/kernel/asm-offsets.c +1
-1@@ -63,7 +63,7 @@ int main(void) OFFSET(__SF_EMPTY, stack_frame, empty[0]); OFFSET(__SF_SIE_CONTROL, stack_frame, sie_control_block); OFFSET(__SF_SIE_SAVEAREA, stack_frame, sie_savearea); - OFFSET(__SF_SIE_REASON, stack_frame, sie_reason); + OFFSET(__SF_SIE_RETURN, stack_frame, sie_return); OFFSET(__SF_SIE_FLAGS, stack_frame, sie_flags); OFFSET(__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys); OFFSET(__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);arch/s390/kernel/entry.S +2
-2@@ -200,7 +200,7 @@ SYM_FUNC_START(__sie64a) stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area stg %r5,__SF_SIE_GUEST_ASCE(%r15) # save guest asce - xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0 + xc __SF_SIE_RETURN(8,%r15),__SF_SIE_RETURN(%r15) # return code = 0 mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags lmg %r0,%r13,0(%r4) # load guest gprs 0-13 mvi __TI_sie(%r14),1@@ -237,7 +237,7 @@ SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL) xgr %r4,%r4 xgr %r5,%r5 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers - lg %r2,__SF_SIE_REASON(%r15) # return exit reason code + lg %r2,__SF_SIE_RETURN(%r15) # return sie return code BR_EX %r14 SYM_FUNC_END(__sie64a) EXPORT_SYMBOL(__sie64a)arch/s390/kernel/nmi.c +0
-0arch/s390/kernel/nmi.c void notrace s390_do_machine_check(struct pt_regs *regs) · line 491
Quoted 7 lines
arch/s390/kernel/nmi.c +2
-2@@ -487,8 +487,8 @@ void notrace s390_do_machine_check(struct pt_regs *regs) mcck_dam_code = (mci.val & MCIC_SUBCLASS_MASK); if (test_cpu_flag(CIF_MCCK_GUEST) && (mcck_dam_code & MCCK_CODE_NO_GUEST) != mcck_dam_code) { - /* Set exit reason code for host's later handling */ - *((long *)(regs->gprs[15] + __SF_SIE_REASON)) = -EINTR; + /* Set sie return code for host's later handling */ + *((long *)(regs->gprs[15] + __SF_SIE_RETURN)) = SIE64_RETURN_MCCK;We don't need to cast this to long anymore, do we?
Sincesie_returnis ulong, and we if we stay with positive numbers ulong would make the most sense.Quoted 1 line
Although I'd prefer a cast to
stack_framebut I'm unsure if that would make it more readable if we stay with a one line change.something like
(quoted diff) +1
-1- *((long *)(regs->gprs[15] + __SF_SIE_RETURN)) = SIE64_RETURN_MCCK; + ((struct stack_frame *) regs->gprs[15])->sie_return = SIE64_RETURN_MCCK;>
Quoted 1 line
What do you think?
Yep
Quoted 4 lines
This reminds me that I should probably also make the local variable in
vsie.cunsigned long instead of int.