#
# requires: arch=amd64 vendor=intel nested -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)

# Create two Intel nested VMs whose MSR lists contain MSR_FS_BASE (0xc0000100), which
# nested_vmx_load_msr_check() rejects.
# VM 0 has it in the VM-entry load list (list=0): VM entry fails with a VM exit whose
# reason is EXIT_REASON_MSR_LOAD_FAIL (34) with the failed-VM-entry bit set, which SYZOS
# reports as 0xe2110022.
# VM 1 has it in the VM-exit load list (list=1): L2 runs HLT, and loading L1 MSRs on the
# VM exit fails, so KVM aborts with VMX_ABORT_LOAD_HOST_MSR_FAIL, which triple-faults L1
# and exits to userspace with KVM_EXIT_SHUTDOWN (0x8).
#
r3 = syz_kvm_add_vcpu$x86(r2, &AUTO={0x0, &AUTO=[@enable_nested={AUTO, AUTO, 0x0}, @nested_create_vm={AUTO, AUTO, 0x0}, @nested_load_code={AUTO, AUTO, {0x0, "f4"}}, @nested_intel_msr_list_add={AUTO, AUTO, {0x0, 0x0, 0xc0000100, 0x0}}, @nested_vmlaunch={AUTO, AUTO, 0x0}, @nested_create_vm={AUTO, AUTO, 0x1}, @nested_load_code={AUTO, AUTO, {0x1, "f4"}}, @nested_intel_msr_list_add={AUTO, AUTO, {0x1, 0x1, 0xc0000100, 0x0}}, @nested_vmlaunch={AUTO, AUTO, 0x1}], AUTO})
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)
syz_kvm_assert_syzos_uexit$x86(r3, r5, 0xe2110022)

ioctl$KVM_RUN(r3, AUTO, 0x0)
syz_kvm_assert_syzos_kvm_exit$x86(r5, 0x8)
