Skip to content

Commit ba853a4

Browse files
iii-ifrankjaa
authored andcommitted
KVM: s390: interrupt: Fix single-stepping kernel-emulated instructions
Single-stepping a kernel-emulated instruction that generates an interrupt causes GDB to land on the instruction following it instead of the respective interrupt handler. The reason is that kvm_handle_sie_intercept(), after injecting the interrupt, also processes the PER event and arranges a KVM_SINGLESTEP exit. The interrupt is not yet delivered, however, so the userspace sees the next instruction. Fix by avoiding the KVM_SINGLESTEP exit when there is a pending interrupt. The next __vcpu_run() loop iteration will arrange a KVM_SINGLESTEP exit after delivering the interrupt. Reviewed-by: David Hildenbrand <[email protected]> Reviewed-by: Claudio Imbrenda <[email protected]> Signed-off-by: Ilya Leoshkevich <[email protected]> Message-ID: <[email protected]> Signed-off-by: Claudio Imbrenda <[email protected]> Signed-off-by: Janosch Frank <[email protected]>
1 parent 74a439e commit ba853a4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

arch/s390/kvm/intercept.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,19 @@ static int handle_pv_notification(struct kvm_vcpu *vcpu)
583583
return handle_instruction(vcpu);
584584
}
585585

586+
static bool should_handle_per_ifetch(const struct kvm_vcpu *vcpu, int rc)
587+
{
588+
/* Process PER, also if the instruction is processed in user space. */
589+
if (!(vcpu->arch.sie_block->icptstatus & 0x02))
590+
return false;
591+
if (rc != 0 && rc != -EOPNOTSUPP)
592+
return false;
593+
if (guestdbg_sstep_enabled(vcpu) && vcpu->arch.local_int.pending_irqs)
594+
/* __vcpu_run() will exit after delivering the interrupt. */
595+
return false;
596+
return true;
597+
}
598+
586599
int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
587600
{
588601
int rc, per_rc = 0;
@@ -645,9 +658,7 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
645658
return -EOPNOTSUPP;
646659
}
647660

648-
/* process PER, also if the instruction is processed in user space */
649-
if (vcpu->arch.sie_block->icptstatus & 0x02 &&
650-
(!rc || rc == -EOPNOTSUPP))
661+
if (should_handle_per_ifetch(vcpu, rc))
651662
per_rc = kvm_s390_handle_per_ifetch_icpt(vcpu);
652663
return per_rc ? per_rc : rc;
653664
}

0 commit comments

Comments
 (0)