KVM: s390: vsie: Avoid injecting machine check on signal
Christian Borntraeger
maintainerPATCH v2 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.
---v1->v2:
instead of a band-aid, make the machine check more direct
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 | 4 +++- 7 files changed, 20 insertions(+), 14 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 +3 -1
@@ -1178,11 +1178,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 (rc ==SIE64_RETURN_MCCK ) {kvm_s390_reinject_machine_check (vcpu, &vsie_page->mcck_info);return 0 ; } +WARN_ON (rc !=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
Christian Borntraeger
maintainerAm 16.03.26 um 13:25 schrieb Christian Borntraeger:
Quoted 14 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.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 direct
Quoted 8 lines
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 | 4 +++- 7 files changed, 20 insertions(+), 14 deletions(-)
I guess we should still add something like
arch/s390/kvm/vsie.c +3 -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_OK ;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,7 +1179,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struckvm_vcpu_srcu_read_lock (vcpu); -if (rc ==SIE64_RETURN_MCCK ) { +if (sie_return ==SIE64_RETURN_MCCK ) {kvm_s390_reinject_machine_check (vcpu, &vsie_page->mcck_info);return 0 ; }
Heiko Carstens
maintainerQuoted 22 lines · Christian Borntraeger
Am 16.03.26 um 13:25 schrieb Christian Borntraeger:
I guess we should still add something likearch/s390/kvm/vsie.c +2
-1@@ -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_OK ;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 (); }
arch/s390/kvm/vsie.c static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc · line 1182
Quoted 5 lines
arch/s390/kvm/vsie.c +1
-1@@ -1178,7 +1179,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struckvm_vcpu_srcu_read_lock (vcpu); -if (rc ==SIE64_RETURN_MCCK ) { +if (sie_return ==SIE64_RETURN_MCCK ) {kvm_s390_reinject_machine_check (vcpu, &vsie_page->mcck_info);return 0 ;
Yes, this looks better and makes the code more understandable.
Heiko Carstens
maintainerarch/s390/kvm/kvm-s390.c static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason) · line 4643
Quoted 2 lines · Christian Borntraeger
arch/s390/kvm/kvm-s390.c +1
-0} +WARN_ON (sie_return !=SIE64_RETURN_NORMAL );
WARN_ON_ONCE() instead?
arch/s390/kvm/vsie.c static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc · line 1187
Quoted 2 lines
arch/s390/kvm/vsie.c +2
-0+WARN_ON (rc !=SIE64_RETURN_NORMAL ); +
Same here. Besides that looks good to me.