Skip to content

Commit ab51197

Browse files
committed
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. Fixes: 2bd1337 ("KVM: s390: Use generic VIRT_XFER_TO_GUEST_WORK functions") Signed-off-by: Christian Borntraeger <[email protected]> Reviewed-by: Heiko Carstens <[email protected]> Reviewed-by: Claudio Imbrenda <[email protected]>
1 parent 1ca90f4 commit ab51197

7 files changed

Lines changed: 22 additions & 15 deletions

File tree

arch/s390/include/asm/kvm_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm);
710710
void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
711711
unsigned long *aqm, unsigned long *adm);
712712

713+
#define SIE64_RETURN_NORMAL 0
714+
#define SIE64_RETURN_MCCK 1
715+
713716
int __sie64a(phys_addr_t sie_block_phys, struct kvm_s390_sie_block *sie_block, u64 *rsa,
714717
unsigned long gasce);
715718

arch/s390/include/asm/stacktrace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct stack_frame {
6262
struct {
6363
unsigned long sie_control_block;
6464
unsigned long sie_savearea;
65-
unsigned long sie_reason;
65+
unsigned long sie_return;
6666
unsigned long sie_flags;
6767
unsigned long sie_control_block_phys;
6868
unsigned long sie_guest_asce;

arch/s390/kernel/asm-offsets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int main(void)
6363
OFFSET(__SF_EMPTY, stack_frame, empty[0]);
6464
OFFSET(__SF_SIE_CONTROL, stack_frame, sie_control_block);
6565
OFFSET(__SF_SIE_SAVEAREA, stack_frame, sie_savearea);
66-
OFFSET(__SF_SIE_REASON, stack_frame, sie_reason);
66+
OFFSET(__SF_SIE_RETURN, stack_frame, sie_return);
6767
OFFSET(__SF_SIE_FLAGS, stack_frame, sie_flags);
6868
OFFSET(__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys);
6969
OFFSET(__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);

arch/s390/kernel/entry.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ SYM_FUNC_START(__sie64a)
200200
stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses
201201
stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area
202202
stg %r5,__SF_SIE_GUEST_ASCE(%r15) # save guest asce
203-
xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0
203+
xc __SF_SIE_RETURN(8,%r15),__SF_SIE_RETURN(%r15) # return code = 0
204204
mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags
205205
lmg %r0,%r13,0(%r4) # load guest gprs 0-13
206206
mvi __TI_sie(%r14),1
@@ -237,7 +237,7 @@ SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL)
237237
xgr %r4,%r4
238238
xgr %r5,%r5
239239
lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
240-
lg %r2,__SF_SIE_REASON(%r15) # return exit reason code
240+
lg %r2,__SF_SIE_RETURN(%r15) # return sie return code
241241
BR_EX %r14
242242
SYM_FUNC_END(__sie64a)
243243
EXPORT_SYMBOL(__sie64a)

arch/s390/kernel/nmi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
487487
mcck_dam_code = (mci.val & MCIC_SUBCLASS_MASK);
488488
if (test_cpu_flag(CIF_MCCK_GUEST) &&
489489
(mcck_dam_code & MCCK_CODE_NO_GUEST) != mcck_dam_code) {
490-
/* Set exit reason code for host's later handling */
491-
*((long *)(regs->gprs[15] + __SF_SIE_REASON)) = -EINTR;
490+
/* Set sie return code for host's later handling */
491+
((struct stack_frame *)regs->gprs[15])->sie_return = SIE64_RETURN_MCCK;
492492
}
493493
clear_cpu_flag(CIF_MCCK_GUEST);
494494

arch/s390/kvm/kvm-s390.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4617,7 +4617,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
46174617
return 0;
46184618
}
46194619

4620-
static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)
4620+
static int vcpu_post_run(struct kvm_vcpu *vcpu, int sie_return)
46214621
{
46224622
struct mcck_volatile_info *mcck_info;
46234623
struct sie_page *sie_page;
@@ -4633,13 +4633,14 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)
46334633
vcpu->run->s.regs.gprs[14] = vcpu->arch.sie_block->gg14;
46344634
vcpu->run->s.regs.gprs[15] = vcpu->arch.sie_block->gg15;
46354635

4636-
if (exit_reason == -EINTR) {
4636+
if (sie_return == SIE64_RETURN_MCCK) {
46374637
sie_page = container_of(vcpu->arch.sie_block,
46384638
struct sie_page, sie_block);
46394639
mcck_info = &sie_page->mcck_info;
46404640
kvm_s390_reinject_machine_check(vcpu, mcck_info);
46414641
return 0;
46424642
}
4643+
WARN_ON_ONCE(sie_return != SIE64_RETURN_NORMAL);
46434644

46444645
if (vcpu->arch.sie_block->icptcode > 0) {
46454646
rc = kvm_handle_sie_intercept(vcpu);
@@ -4678,7 +4679,7 @@ int noinstr kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
46784679
#define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)
46794680
static int __vcpu_run(struct kvm_vcpu *vcpu)
46804681
{
4681-
int rc, exit_reason;
4682+
int rc, sie_return;
46824683
struct sie_page *sie_page = (struct sie_page *)vcpu->arch.sie_block;
46834684

46844685
/*
@@ -4718,9 +4719,9 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
47184719
guest_timing_enter_irqoff();
47194720
__disable_cpu_timer_accounting(vcpu);
47204721

4721-
exit_reason = kvm_s390_enter_exit_sie(vcpu->arch.sie_block,
4722-
vcpu->run->s.regs.gprs,
4723-
vcpu->arch.gmap->asce.val);
4722+
sie_return = kvm_s390_enter_exit_sie(vcpu->arch.sie_block,
4723+
vcpu->run->s.regs.gprs,
4724+
vcpu->arch.gmap->asce.val);
47244725

47254726
__enable_cpu_timer_accounting(vcpu);
47264727
guest_timing_exit_irqoff();
@@ -4743,7 +4744,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)
47434744
}
47444745
kvm_vcpu_srcu_read_lock(vcpu);
47454746

4746-
rc = vcpu_post_run(vcpu, exit_reason);
4747+
rc = vcpu_post_run(vcpu, sie_return);
47474748
if (rc || guestdbg_exit_pending(vcpu)) {
47484749
kvm_vcpu_srcu_read_unlock(vcpu);
47494750
break;

arch/s390/kvm/vsie.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc
11221122
{
11231123
struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s;
11241124
struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
1125+
unsigned long sie_return = SIE64_RETURN_NORMAL;
11251126
int guest_bp_isolation;
11261127
int rc = 0;
11271128

@@ -1163,7 +1164,7 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc
11631164
goto xfer_to_guest_mode_check;
11641165
}
11651166
guest_timing_enter_irqoff();
1166-
rc = kvm_s390_enter_exit_sie(scb_s, vcpu->run->s.regs.gprs, sg->asce.val);
1167+
sie_return = kvm_s390_enter_exit_sie(scb_s, vcpu->run->s.regs.gprs, sg->asce.val);
11671168
guest_timing_exit_irqoff();
11681169
local_irq_enable();
11691170
}
@@ -1178,11 +1179,13 @@ static int do_vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struc
11781179

11791180
kvm_vcpu_srcu_read_lock(vcpu);
11801181

1181-
if (rc == -EINTR) {
1182+
if (sie_return == SIE64_RETURN_MCCK) {
11821183
kvm_s390_reinject_machine_check(vcpu, &vsie_page->mcck_info);
11831184
return 0;
11841185
}
11851186

1187+
WARN_ON_ONCE(sie_return != SIE64_RETURN_NORMAL);
1188+
11861189
if (rc > 0)
11871190
rc = 0; /* we could still have an icpt */
11881191
else if (current->thread.gmap_int_code)

0 commit comments

Comments
 (0)