#
# requires: arch=amd64 -threaded
#
r0 = openat$kvm(0, &AUTO='/dev/kvm\x00', 0x0, 0x0)
r1 = ioctl$KVM_CREATE_VM(r0, AUTO, 0x0)
r2 = syz_kvm_setup_syzos_vm$x86(r1, &(0x7f0000c00000/0x400000)=nil)

# DR7.GD=1 causes further attempts to touch a debug register to result in a debug exception.
#
r3 = syz_kvm_add_vcpu$x86(r2, &AUTO={0x0, &AUTO=[@wr_drn={AUTO, AUTO, {0x7, 0x2000}}, @wr_drn={AUTO, AUTO, {0x0, 0x1}}], AUTO})

# 0x10001 = KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP enables software breakpoints.
#
ioctl$KVM_SET_GUEST_DEBUG_x86(r3, AUTO, &AUTO={0x10001, 0x0, {[0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}})
r4 = ioctl$KVM_GET_VCPU_MMAP_SIZE(r0, AUTO)
r5 = mmap$KVM_VCPU(&(0x7f0000009000/0x1000)=nil, r4, 0x3, 0x1, r3, 0x0)

ioctl$KVM_RUN(r3, AUTO, 0x0)

# Ensure that the exception is handled by the guest, and the program finishes normally.
#
syz_kvm_assert_syzos_kvm_exit$x86(r5, 0x6)
syz_kvm_assert_syzos_uexit$x86(r3, r5, 0xffffffffffffffff)
