Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull kvm fixes from Paolo Bonzini:
"ARM64:

- Address a rather annoying bug w.r.t. guest timer offsetting. The
synchronization of timer offsets between vCPUs was broken, leading
to inconsistent timer reads within the VM.

x86:

- New tests for the slow path of the EVTCHNOP_send Xen hypercall

- Add missing nVMX consistency checks for CR0 and CR4

- Fix bug that broke AMD GATag on 512 vCPU machines

Selftests:

- Skip hugetlb tests if huge pages are not available

- Sync KVM exit reasons"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
KVM: selftests: Sync KVM exit reasons in selftests
KVM: selftests: Add macro to generate KVM exit reason strings
KVM: selftests: Print expected and actual exit reason in KVM exit reason assert
KVM: selftests: Make vCPU exit reason test assertion common
KVM: selftests: Add EVTCHNOP_send slow path test to xen_shinfo_test
KVM: selftests: Use enum for test numbers in xen_shinfo_test
KVM: selftests: Add helpers to make Xen-style VMCALL/VMMCALL hypercalls
KVM: selftests: Move the guts of kvm_hypercall() to a separate macro
KVM: SVM: WARN if GATag generation drops VM or vCPU ID information
KVM: SVM: Modify AVIC GATag to support max number of 512 vCPUs
KVM: SVM: Fix a benign off-by-one bug in AVIC physical table mask
selftests: KVM: skip hugetlb tests if huge pages are not available
KVM: VMX: Use tabs instead of spaces for indentation
KVM: VMX: Fix indentation coding style issue
KVM: nVMX: remove unnecessary #ifdef
KVM: nVMX: add missing consistency checks for CR0 and CR4
KVM: arm64: timers: Convert per-vcpu virtual offset to a global value

+354 -511
+3
arch/arm64/include/asm/kvm_host.h
··· 193 193 /* Interrupt controller */ 194 194 struct vgic_dist vgic; 195 195 196 + /* Timers */ 197 + struct arch_timer_vm_data timer_data; 198 + 196 199 /* Mandated version of PSCI */ 197 200 u32 psci_version; 198 201
+10 -35
arch/arm64/kvm/arch_timer.c
··· 84 84 85 85 static u64 timer_get_offset(struct arch_timer_context *ctxt) 86 86 { 87 - struct kvm_vcpu *vcpu = ctxt->vcpu; 87 + if (ctxt->offset.vm_offset) 88 + return *ctxt->offset.vm_offset; 88 89 89 - switch(arch_timer_ctx_index(ctxt)) { 90 - case TIMER_VTIMER: 91 - return __vcpu_sys_reg(vcpu, CNTVOFF_EL2); 92 - default: 93 - return 0; 94 - } 90 + return 0; 95 91 } 96 92 97 93 static void timer_set_ctl(struct arch_timer_context *ctxt, u32 ctl) ··· 124 128 125 129 static void timer_set_offset(struct arch_timer_context *ctxt, u64 offset) 126 130 { 127 - struct kvm_vcpu *vcpu = ctxt->vcpu; 128 - 129 - switch(arch_timer_ctx_index(ctxt)) { 130 - case TIMER_VTIMER: 131 - __vcpu_sys_reg(vcpu, CNTVOFF_EL2) = offset; 132 - break; 133 - default: 131 + if (!ctxt->offset.vm_offset) { 134 132 WARN(offset, "timer %ld\n", arch_timer_ctx_index(ctxt)); 133 + return; 135 134 } 135 + 136 + WRITE_ONCE(*ctxt->offset.vm_offset, offset); 136 137 } 137 138 138 139 u64 kvm_phys_timer_read(void) ··· 758 765 return 0; 759 766 } 760 767 761 - /* Make the updates of cntvoff for all vtimer contexts atomic */ 762 - static void update_vtimer_cntvoff(struct kvm_vcpu *vcpu, u64 cntvoff) 763 - { 764 - unsigned long i; 765 - struct kvm *kvm = vcpu->kvm; 766 - struct kvm_vcpu *tmp; 767 - 768 - mutex_lock(&kvm->lock); 769 - kvm_for_each_vcpu(i, tmp, kvm) 770 - timer_set_offset(vcpu_vtimer(tmp), cntvoff); 771 - 772 - /* 773 - * When called from the vcpu create path, the CPU being created is not 774 - * included in the loop above, so we just set it here as well. 775 - */ 776 - timer_set_offset(vcpu_vtimer(vcpu), cntvoff); 777 - mutex_unlock(&kvm->lock); 778 - } 779 - 780 768 void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) 781 769 { 782 770 struct arch_timer_cpu *timer = vcpu_timer(vcpu); ··· 765 791 struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); 766 792 767 793 vtimer->vcpu = vcpu; 794 + vtimer->offset.vm_offset = &vcpu->kvm->arch.timer_data.voffset; 768 795 ptimer->vcpu = vcpu; 769 796 770 797 /* Synchronize cntvoff across all vtimers of a VM. */ 771 - update_vtimer_cntvoff(vcpu, kvm_phys_timer_read()); 798 + timer_set_offset(vtimer, kvm_phys_timer_read()); 772 799 timer_set_offset(ptimer, 0); 773 800 774 801 hrtimer_init(&timer->bg_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); ··· 815 840 break; 816 841 case KVM_REG_ARM_TIMER_CNT: 817 842 timer = vcpu_vtimer(vcpu); 818 - update_vtimer_cntvoff(vcpu, kvm_phys_timer_read() - value); 843 + timer_set_offset(timer, kvm_phys_timer_read() - value); 819 844 break; 820 845 case KVM_REG_ARM_TIMER_CVAL: 821 846 timer = vcpu_vtimer(vcpu);
+1 -1
arch/arm64/kvm/hypercalls.c
··· 44 44 feature = smccc_get_arg1(vcpu); 45 45 switch (feature) { 46 46 case KVM_PTP_VIRT_COUNTER: 47 - cycles = systime_snapshot.cycles - vcpu_read_sys_reg(vcpu, CNTVOFF_EL2); 47 + cycles = systime_snapshot.cycles - vcpu->kvm->arch.timer_data.voffset; 48 48 break; 49 49 case KVM_PTP_PHYS_COUNTER: 50 50 cycles = systime_snapshot.cycles;
+7 -5
arch/x86/include/asm/svm.h
··· 261 261 AVIC_IPI_FAILURE_INVALID_BACKING_PAGE, 262 262 }; 263 263 264 - #define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(9, 0) 264 + #define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(8, 0) 265 265 266 266 /* 267 - * For AVIC, the max index allowed for physical APIC ID 268 - * table is 0xff (255). 267 + * For AVIC, the max index allowed for physical APIC ID table is 0xfe (254), as 268 + * 0xff is a broadcast to all CPUs, i.e. can't be targeted individually. 269 269 */ 270 270 #define AVIC_MAX_PHYSICAL_ID 0XFEULL 271 271 272 272 /* 273 - * For x2AVIC, the max index allowed for physical APIC ID 274 - * table is 0x1ff (511). 273 + * For x2AVIC, the max index allowed for physical APIC ID table is 0x1ff (511). 275 274 */ 276 275 #define X2AVIC_MAX_PHYSICAL_ID 0x1FFUL 276 + 277 + static_assert((AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == AVIC_MAX_PHYSICAL_ID); 278 + static_assert((X2AVIC_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AVIC_MAX_PHYSICAL_ID); 277 279 278 280 #define AVIC_HPA_MASK ~((0xFFFULL << 52) | 0xFFF) 279 281 #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL
+28 -9
arch/x86/kvm/svm/avic.c
··· 27 27 #include "irq.h" 28 28 #include "svm.h" 29 29 30 - /* AVIC GATAG is encoded using VM and VCPU IDs */ 31 - #define AVIC_VCPU_ID_BITS 8 32 - #define AVIC_VCPU_ID_MASK ((1 << AVIC_VCPU_ID_BITS) - 1) 30 + /* 31 + * Encode the arbitrary VM ID and the vCPU's default APIC ID, i.e the vCPU ID, 32 + * into the GATag so that KVM can retrieve the correct vCPU from a GALog entry 33 + * if an interrupt can't be delivered, e.g. because the vCPU isn't running. 34 + * 35 + * For the vCPU ID, use however many bits are currently allowed for the max 36 + * guest physical APIC ID (limited by the size of the physical ID table), and 37 + * use whatever bits remain to assign arbitrary AVIC IDs to VMs. Note, the 38 + * size of the GATag is defined by hardware (32 bits), but is an opaque value 39 + * as far as hardware is concerned. 40 + */ 41 + #define AVIC_VCPU_ID_MASK AVIC_PHYSICAL_MAX_INDEX_MASK 33 42 34 - #define AVIC_VM_ID_BITS 24 35 - #define AVIC_VM_ID_NR (1 << AVIC_VM_ID_BITS) 36 - #define AVIC_VM_ID_MASK ((1 << AVIC_VM_ID_BITS) - 1) 43 + #define AVIC_VM_ID_SHIFT HWEIGHT32(AVIC_PHYSICAL_MAX_INDEX_MASK) 44 + #define AVIC_VM_ID_MASK (GENMASK(31, AVIC_VM_ID_SHIFT) >> AVIC_VM_ID_SHIFT) 37 45 38 - #define AVIC_GATAG(x, y) (((x & AVIC_VM_ID_MASK) << AVIC_VCPU_ID_BITS) | \ 39 - (y & AVIC_VCPU_ID_MASK)) 40 - #define AVIC_GATAG_TO_VMID(x) ((x >> AVIC_VCPU_ID_BITS) & AVIC_VM_ID_MASK) 46 + #define AVIC_GATAG_TO_VMID(x) ((x >> AVIC_VM_ID_SHIFT) & AVIC_VM_ID_MASK) 41 47 #define AVIC_GATAG_TO_VCPUID(x) (x & AVIC_VCPU_ID_MASK) 48 + 49 + #define __AVIC_GATAG(vm_id, vcpu_id) ((((vm_id) & AVIC_VM_ID_MASK) << AVIC_VM_ID_SHIFT) | \ 50 + ((vcpu_id) & AVIC_VCPU_ID_MASK)) 51 + #define AVIC_GATAG(vm_id, vcpu_id) \ 52 + ({ \ 53 + u32 ga_tag = __AVIC_GATAG(vm_id, vcpu_id); \ 54 + \ 55 + WARN_ON_ONCE(AVIC_GATAG_TO_VCPUID(ga_tag) != (vcpu_id)); \ 56 + WARN_ON_ONCE(AVIC_GATAG_TO_VMID(ga_tag) != (vm_id)); \ 57 + ga_tag; \ 58 + }) 59 + 60 + static_assert(__AVIC_GATAG(AVIC_VM_ID_MASK, AVIC_VCPU_ID_MASK) == -1u); 42 61 43 62 static bool force_avic; 44 63 module_param_unsafe(force_avic, bool, 0444);
+9 -9
arch/x86/kvm/vmx/nested.c
··· 2903 2903 static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu, 2904 2904 struct vmcs12 *vmcs12) 2905 2905 { 2906 - bool ia32e; 2906 + bool ia32e = !!(vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE); 2907 2907 2908 2908 if (CC(!nested_host_cr0_valid(vcpu, vmcs12->host_cr0)) || 2909 2909 CC(!nested_host_cr4_valid(vcpu, vmcs12->host_cr4)) || ··· 2922 2922 CC(!kvm_valid_perf_global_ctrl(vcpu_to_pmu(vcpu), 2923 2923 vmcs12->host_ia32_perf_global_ctrl))) 2924 2924 return -EINVAL; 2925 - 2926 - #ifdef CONFIG_X86_64 2927 - ia32e = !!(vmcs12->vm_exit_controls & VM_EXIT_HOST_ADDR_SPACE_SIZE); 2928 - #else 2929 - ia32e = false; 2930 - #endif 2931 2925 2932 2926 if (ia32e) { 2933 2927 if (CC(!(vmcs12->host_cr4 & X86_CR4_PAE))) ··· 3016 3022 struct vmcs12 *vmcs12, 3017 3023 enum vm_entry_failure_code *entry_failure_code) 3018 3024 { 3019 - bool ia32e; 3025 + bool ia32e = !!(vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE); 3020 3026 3021 3027 *entry_failure_code = ENTRY_FAIL_DEFAULT; 3022 3028 ··· 3042 3048 vmcs12->guest_ia32_perf_global_ctrl))) 3043 3049 return -EINVAL; 3044 3050 3051 + if (CC((vmcs12->guest_cr0 & (X86_CR0_PG | X86_CR0_PE)) == X86_CR0_PG)) 3052 + return -EINVAL; 3053 + 3054 + if (CC(ia32e && !(vmcs12->guest_cr4 & X86_CR4_PAE)) || 3055 + CC(ia32e && !(vmcs12->guest_cr0 & X86_CR0_PG))) 3056 + return -EINVAL; 3057 + 3045 3058 /* 3046 3059 * If the load IA32_EFER VM-entry control is 1, the following checks 3047 3060 * are performed on the field for the IA32_EFER MSR: ··· 3060 3059 */ 3061 3060 if (to_vmx(vcpu)->nested.nested_run_pending && 3062 3061 (vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_EFER)) { 3063 - ia32e = (vmcs12->vm_entry_controls & VM_ENTRY_IA32E_MODE) != 0; 3064 3062 if (CC(!kvm_valid_efer(vcpu, vmcs12->guest_ia32_efer)) || 3065 3063 CC(ia32e != !!(vmcs12->guest_ia32_efer & EFER_LMA)) || 3066 3064 CC(((vmcs12->guest_cr0 & X86_CR0_PG) &&
+2 -2
arch/x86/kvm/vmx/vmenter.S
··· 262 262 * eIBRS has its own protection against poisoned RSB, so it doesn't 263 263 * need the RSB filling sequence. But it does need to be enabled, and a 264 264 * single call to retire, before the first unbalanced RET. 265 - */ 265 + */ 266 266 267 267 FILL_RETURN_BUFFER %_ASM_CX, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT,\ 268 268 X86_FEATURE_RSB_VMEXIT_LITE ··· 311 311 * vmread_error_trampoline - Trampoline from inline asm to vmread_error() 312 312 * @field: VMCS field encoding that failed 313 313 * @fault: %true if the VMREAD faulted, %false if it failed 314 - 314 + * 315 315 * Save and restore volatile registers across a call to vmread_error(). Note, 316 316 * all parameters are passed on the stack. 317 317 */
+6 -6
arch/x86/kvm/vmx/vmx.c
··· 874 874 */ 875 875 if (is_guest_mode(vcpu)) 876 876 eb |= get_vmcs12(vcpu)->exception_bitmap; 877 - else { 877 + else { 878 878 int mask = 0, match = 0; 879 879 880 880 if (enable_ept && (eb & (1u << PF_VECTOR))) { ··· 1282 1282 } 1283 1283 } 1284 1284 1285 - if (vmx->nested.need_vmcs12_to_shadow_sync) 1285 + if (vmx->nested.need_vmcs12_to_shadow_sync) 1286 1286 nested_sync_vmcs12_to_shadow(vcpu); 1287 1287 1288 1288 if (vmx->guest_state_loaded) ··· 5049 5049 if (to_vmx(vcpu)->nested.nested_run_pending) 5050 5050 return -EBUSY; 5051 5051 5052 - /* 5053 - * An IRQ must not be injected into L2 if it's supposed to VM-Exit, 5054 - * e.g. if the IRQ arrived asynchronously after checking nested events. 5055 - */ 5052 + /* 5053 + * An IRQ must not be injected into L2 if it's supposed to VM-Exit, 5054 + * e.g. if the IRQ arrived asynchronously after checking nested events. 5055 + */ 5056 5056 if (for_injection && is_guest_mode(vcpu) && nested_exit_on_intr(vcpu)) 5057 5057 return -EBUSY; 5058 5058
+15
include/kvm/arm_arch_timer.h
··· 23 23 TIMER_REG_CTL, 24 24 }; 25 25 26 + struct arch_timer_offset { 27 + /* 28 + * If set, pointer to one of the offsets in the kvm's offset 29 + * structure. If NULL, assume a zero offset. 30 + */ 31 + u64 *vm_offset; 32 + }; 33 + 34 + struct arch_timer_vm_data { 35 + /* Offset applied to the virtual timer/counter */ 36 + u64 voffset; 37 + }; 38 + 26 39 struct arch_timer_context { 27 40 struct kvm_vcpu *vcpu; 28 41 ··· 45 32 /* Emulated Timer (may be unused) */ 46 33 struct hrtimer hrtimer; 47 34 35 + /* Offset for this counter/timer */ 36 + struct arch_timer_offset offset; 48 37 /* 49 38 * We have multiple paths which can save/restore the timer state onto 50 39 * the hardware, so we need some way of keeping track of where the
+1 -3
tools/testing/selftests/kvm/aarch64/psci_test.c
··· 180 180 181 181 enter_guest(source); 182 182 183 - TEST_ASSERT(run->exit_reason == KVM_EXIT_SYSTEM_EVENT, 184 - "Unhandled exit reason: %u (%s)", 185 - run->exit_reason, exit_reason_str(run->exit_reason)); 183 + TEST_ASSERT_KVM_EXIT_REASON(source, KVM_EXIT_SYSTEM_EVENT); 186 184 TEST_ASSERT(run->system_event.type == KVM_SYSTEM_EVENT_SUSPEND, 187 185 "Unhandled system event: %u (expected: %u)", 188 186 run->system_event.type, KVM_SYSTEM_EVENT_SUSPEND);
+9
tools/testing/selftests/kvm/include/test_util.h
··· 63 63 #a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \ 64 64 } while (0) 65 65 66 + #define TEST_ASSERT_KVM_EXIT_REASON(vcpu, expected) do { \ 67 + __u32 exit_reason = (vcpu)->run->exit_reason; \ 68 + \ 69 + TEST_ASSERT(exit_reason == (expected), \ 70 + "Wanted KVM exit reason: %u (%s), got: %u (%s)", \ 71 + (expected), exit_reason_str((expected)), \ 72 + exit_reason, exit_reason_str(exit_reason)); \ 73 + } while (0) 74 + 66 75 #define TEST_FAIL(fmt, ...) do { \ 67 76 TEST_ASSERT(false, fmt, ##__VA_ARGS__); \ 68 77 __builtin_unreachable(); \
+2
tools/testing/selftests/kvm/include/x86_64/processor.h
··· 1063 1063 1064 1064 uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, 1065 1065 uint64_t a3); 1066 + uint64_t __xen_hypercall(uint64_t nr, uint64_t a0, void *a1); 1067 + void xen_hypercall(uint64_t nr, uint64_t a0, void *a1); 1066 1068 1067 1069 void __vm_xsave_require_permission(int bit, const char *name); 1068 1070
+41 -26
tools/testing/selftests/kvm/lib/kvm_util.c
··· 1815 1815 vcpu_dump(stream, vcpu, indent + 2); 1816 1816 } 1817 1817 1818 + #define KVM_EXIT_STRING(x) {KVM_EXIT_##x, #x} 1819 + 1818 1820 /* Known KVM exit reasons */ 1819 1821 static struct exit_reason { 1820 1822 unsigned int reason; 1821 1823 const char *name; 1822 1824 } exit_reasons_known[] = { 1823 - {KVM_EXIT_UNKNOWN, "UNKNOWN"}, 1824 - {KVM_EXIT_EXCEPTION, "EXCEPTION"}, 1825 - {KVM_EXIT_IO, "IO"}, 1826 - {KVM_EXIT_HYPERCALL, "HYPERCALL"}, 1827 - {KVM_EXIT_DEBUG, "DEBUG"}, 1828 - {KVM_EXIT_HLT, "HLT"}, 1829 - {KVM_EXIT_MMIO, "MMIO"}, 1830 - {KVM_EXIT_IRQ_WINDOW_OPEN, "IRQ_WINDOW_OPEN"}, 1831 - {KVM_EXIT_SHUTDOWN, "SHUTDOWN"}, 1832 - {KVM_EXIT_FAIL_ENTRY, "FAIL_ENTRY"}, 1833 - {KVM_EXIT_INTR, "INTR"}, 1834 - {KVM_EXIT_SET_TPR, "SET_TPR"}, 1835 - {KVM_EXIT_TPR_ACCESS, "TPR_ACCESS"}, 1836 - {KVM_EXIT_S390_SIEIC, "S390_SIEIC"}, 1837 - {KVM_EXIT_S390_RESET, "S390_RESET"}, 1838 - {KVM_EXIT_DCR, "DCR"}, 1839 - {KVM_EXIT_NMI, "NMI"}, 1840 - {KVM_EXIT_INTERNAL_ERROR, "INTERNAL_ERROR"}, 1841 - {KVM_EXIT_OSI, "OSI"}, 1842 - {KVM_EXIT_PAPR_HCALL, "PAPR_HCALL"}, 1843 - {KVM_EXIT_DIRTY_RING_FULL, "DIRTY_RING_FULL"}, 1844 - {KVM_EXIT_X86_RDMSR, "RDMSR"}, 1845 - {KVM_EXIT_X86_WRMSR, "WRMSR"}, 1846 - {KVM_EXIT_XEN, "XEN"}, 1847 - {KVM_EXIT_HYPERV, "HYPERV"}, 1825 + KVM_EXIT_STRING(UNKNOWN), 1826 + KVM_EXIT_STRING(EXCEPTION), 1827 + KVM_EXIT_STRING(IO), 1828 + KVM_EXIT_STRING(HYPERCALL), 1829 + KVM_EXIT_STRING(DEBUG), 1830 + KVM_EXIT_STRING(HLT), 1831 + KVM_EXIT_STRING(MMIO), 1832 + KVM_EXIT_STRING(IRQ_WINDOW_OPEN), 1833 + KVM_EXIT_STRING(SHUTDOWN), 1834 + KVM_EXIT_STRING(FAIL_ENTRY), 1835 + KVM_EXIT_STRING(INTR), 1836 + KVM_EXIT_STRING(SET_TPR), 1837 + KVM_EXIT_STRING(TPR_ACCESS), 1838 + KVM_EXIT_STRING(S390_SIEIC), 1839 + KVM_EXIT_STRING(S390_RESET), 1840 + KVM_EXIT_STRING(DCR), 1841 + KVM_EXIT_STRING(NMI), 1842 + KVM_EXIT_STRING(INTERNAL_ERROR), 1843 + KVM_EXIT_STRING(OSI), 1844 + KVM_EXIT_STRING(PAPR_HCALL), 1845 + KVM_EXIT_STRING(S390_UCONTROL), 1846 + KVM_EXIT_STRING(WATCHDOG), 1847 + KVM_EXIT_STRING(S390_TSCH), 1848 + KVM_EXIT_STRING(EPR), 1849 + KVM_EXIT_STRING(SYSTEM_EVENT), 1850 + KVM_EXIT_STRING(S390_STSI), 1851 + KVM_EXIT_STRING(IOAPIC_EOI), 1852 + KVM_EXIT_STRING(HYPERV), 1853 + KVM_EXIT_STRING(ARM_NISV), 1854 + KVM_EXIT_STRING(X86_RDMSR), 1855 + KVM_EXIT_STRING(X86_WRMSR), 1856 + KVM_EXIT_STRING(DIRTY_RING_FULL), 1857 + KVM_EXIT_STRING(AP_RESET_HOLD), 1858 + KVM_EXIT_STRING(X86_BUS_LOCK), 1859 + KVM_EXIT_STRING(XEN), 1860 + KVM_EXIT_STRING(RISCV_SBI), 1861 + KVM_EXIT_STRING(RISCV_CSR), 1862 + KVM_EXIT_STRING(NOTIFY), 1848 1863 #ifdef KVM_EXIT_MEMORY_NOT_PRESENT 1849 - {KVM_EXIT_MEMORY_NOT_PRESENT, "MEMORY_NOT_PRESENT"}, 1864 + KVM_EXIT_STRING(MEMORY_NOT_PRESENT), 1850 1865 #endif 1851 1866 }; 1852 1867
+1 -2
tools/testing/selftests/kvm/lib/s390x/diag318_test_handler.c
··· 35 35 vcpu_run(vcpu); 36 36 run = vcpu->run; 37 37 38 - TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, 39 - "DIAGNOSE 0x0318 instruction was not intercepted"); 38 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC); 40 39 TEST_ASSERT(run->s390_sieic.icptcode == ICPT_INSTRUCTION, 41 40 "Unexpected intercept code: 0x%x", run->s390_sieic.icptcode); 42 41 TEST_ASSERT((run->s390_sieic.ipa & 0xff00) == IPA0_DIAG,
+16 -9
tools/testing/selftests/kvm/lib/test_util.c
··· 165 165 size_t get_def_hugetlb_pagesz(void) 166 166 { 167 167 char buf[64]; 168 - const char *tag = "Hugepagesize:"; 168 + const char *hugepagesize = "Hugepagesize:"; 169 + const char *hugepages_total = "HugePages_Total:"; 169 170 FILE *f; 170 171 171 172 f = fopen("/proc/meminfo", "r"); 172 173 TEST_ASSERT(f != NULL, "Error in opening /proc/meminfo"); 173 174 174 175 while (fgets(buf, sizeof(buf), f) != NULL) { 175 - if (strstr(buf, tag) == buf) { 176 + if (strstr(buf, hugepages_total) == buf) { 177 + unsigned long long total = strtoull(buf + strlen(hugepages_total), NULL, 10); 178 + if (!total) { 179 + fprintf(stderr, "HUGETLB is not enabled in /proc/sys/vm/nr_hugepages\n"); 180 + exit(KSFT_SKIP); 181 + } 182 + } 183 + if (strstr(buf, hugepagesize) == buf) { 176 184 fclose(f); 177 - return strtoull(buf + strlen(tag), NULL, 10) << 10; 185 + return strtoull(buf + strlen(hugepagesize), NULL, 10) << 10; 178 186 } 179 187 } 180 188 181 - if (feof(f)) 182 - TEST_FAIL("HUGETLB is not configured in host kernel"); 183 - else 184 - TEST_FAIL("Error in reading /proc/meminfo"); 189 + if (feof(f)) { 190 + fprintf(stderr, "HUGETLB is not configured in host kernel"); 191 + exit(KSFT_SKIP); 192 + } 185 193 186 - fclose(f); 187 - return 0; 194 + TEST_FAIL("Error in reading /proc/meminfo"); 188 195 } 189 196 190 197 #define ANON_FLAGS (MAP_PRIVATE | MAP_ANONYMOUS)
+26 -11
tools/testing/selftests/kvm/lib/x86_64/processor.c
··· 1139 1139 return NULL; 1140 1140 } 1141 1141 1142 + #define X86_HYPERCALL(inputs...) \ 1143 + ({ \ 1144 + uint64_t r; \ 1145 + \ 1146 + asm volatile("test %[use_vmmcall], %[use_vmmcall]\n\t" \ 1147 + "jnz 1f\n\t" \ 1148 + "vmcall\n\t" \ 1149 + "jmp 2f\n\t" \ 1150 + "1: vmmcall\n\t" \ 1151 + "2:" \ 1152 + : "=a"(r) \ 1153 + : [use_vmmcall] "r" (host_cpu_is_amd), inputs); \ 1154 + \ 1155 + r; \ 1156 + }) 1157 + 1142 1158 uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, 1143 1159 uint64_t a3) 1144 1160 { 1145 - uint64_t r; 1161 + return X86_HYPERCALL("a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3)); 1162 + } 1146 1163 1147 - asm volatile("test %[use_vmmcall], %[use_vmmcall]\n\t" 1148 - "jnz 1f\n\t" 1149 - "vmcall\n\t" 1150 - "jmp 2f\n\t" 1151 - "1: vmmcall\n\t" 1152 - "2:" 1153 - : "=a"(r) 1154 - : "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3), 1155 - [use_vmmcall] "r" (host_cpu_is_amd)); 1156 - return r; 1164 + uint64_t __xen_hypercall(uint64_t nr, uint64_t a0, void *a1) 1165 + { 1166 + return X86_HYPERCALL("a"(nr), "D"(a0), "S"(a1)); 1167 + } 1168 + 1169 + void xen_hypercall(uint64_t nr, uint64_t a0, void *a1) 1170 + { 1171 + GUEST_ASSERT(!__xen_hypercall(nr, a0, a1)); 1157 1172 } 1158 1173 1159 1174 const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void)
+3 -12
tools/testing/selftests/kvm/s390x/sync_regs_test.c
··· 126 126 run->kvm_valid_regs = TEST_SYNC_FIELDS; 127 127 rv = _vcpu_run(vcpu); 128 128 TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); 129 - TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, 130 - "Unexpected exit reason: %u (%s)\n", 131 - run->exit_reason, 132 - exit_reason_str(run->exit_reason)); 129 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC); 133 130 TEST_ASSERT(run->s390_sieic.icptcode == 4 && 134 131 (run->s390_sieic.ipa >> 8) == 0x83 && 135 132 (run->s390_sieic.ipb >> 16) == 0x501, ··· 162 165 163 166 rv = _vcpu_run(vcpu); 164 167 TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); 165 - TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, 166 - "Unexpected exit reason: %u (%s)\n", 167 - run->exit_reason, 168 - exit_reason_str(run->exit_reason)); 168 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC); 169 169 TEST_ASSERT(run->s.regs.gprs[11] == 0xBAD1DEA + 1, 170 170 "r11 sync regs value incorrect 0x%llx.", 171 171 run->s.regs.gprs[11]); ··· 194 200 run->s.regs.diag318 = 0x4B1D; 195 201 rv = _vcpu_run(vcpu); 196 202 TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv); 197 - TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC, 198 - "Unexpected exit reason: %u (%s)\n", 199 - run->exit_reason, 200 - exit_reason_str(run->exit_reason)); 203 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC); 201 204 TEST_ASSERT(run->s.regs.gprs[11] != 0xDEADBEEF, 202 205 "r11 sync regs value incorrect 0x%llx.", 203 206 run->s.regs.gprs[11]);
+1 -5
tools/testing/selftests/kvm/set_memory_region_test.c
··· 308 308 static void test_zero_memory_regions(void) 309 309 { 310 310 struct kvm_vcpu *vcpu; 311 - struct kvm_run *run; 312 311 struct kvm_vm *vm; 313 312 314 313 pr_info("Testing KVM_RUN with zero added memory regions\n"); ··· 317 318 318 319 vm_ioctl(vm, KVM_SET_NR_MMU_PAGES, (void *)64ul); 319 320 vcpu_run(vcpu); 320 - 321 - run = vcpu->run; 322 - TEST_ASSERT(run->exit_reason == KVM_EXIT_INTERNAL_ERROR, 323 - "Unexpected exit_reason = %u\n", run->exit_reason); 321 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR); 324 322 325 323 kvm_vm_free(vm); 326 324 }
+1 -7
tools/testing/selftests/kvm/x86_64/amx_test.c
··· 241 241 struct kvm_regs regs1, regs2; 242 242 struct kvm_vcpu *vcpu; 243 243 struct kvm_vm *vm; 244 - struct kvm_run *run; 245 244 struct kvm_x86_state *state; 246 245 int xsave_restore_size; 247 246 vm_vaddr_t amx_cfg, tiledata, xsavedata; ··· 267 268 "KVM should enumerate max XSAVE size when XSAVE is supported"); 268 269 xsave_restore_size = kvm_cpu_property(X86_PROPERTY_XSTATE_MAX_SIZE); 269 270 270 - run = vcpu->run; 271 271 vcpu_regs_get(vcpu, &regs1); 272 272 273 273 /* Register #NM handler */ ··· 289 291 290 292 for (stage = 1; ; stage++) { 291 293 vcpu_run(vcpu); 292 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 293 - "Stage %d: unexpected exit reason: %u (%s),\n", 294 - stage, run->exit_reason, 295 - exit_reason_str(run->exit_reason)); 294 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 296 295 297 296 switch (get_ucall(vcpu, &uc)) { 298 297 case UCALL_ABORT: ··· 345 350 /* Restore state in a new VM. */ 346 351 vcpu = vm_recreate_with_one_vcpu(vm); 347 352 vcpu_load_state(vcpu, state); 348 - run = vcpu->run; 349 353 kvm_x86_state_cleanup(state); 350 354 351 355 memset(&regs2, 0, sizeof(regs2));
+1 -7
tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c
··· 50 50 int main(int argc, char *argv[]) 51 51 { 52 52 struct kvm_vcpu *vcpu; 53 - struct kvm_run *run; 54 53 struct kvm_vm *vm; 55 54 struct kvm_sregs sregs; 56 55 struct ucall uc; ··· 57 58 TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVE)); 58 59 59 60 vm = vm_create_with_one_vcpu(&vcpu, guest_code); 60 - run = vcpu->run; 61 61 62 62 while (1) { 63 63 vcpu_run(vcpu); 64 - 65 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 66 - "Unexpected exit reason: %u (%s),\n", 67 - run->exit_reason, 68 - exit_reason_str(run->exit_reason)); 64 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 69 65 70 66 switch (get_ucall(vcpu, &uc)) { 71 67 case UCALL_SYNC:
+1 -1
tools/testing/selftests/kvm/x86_64/debug_regs.c
··· 204 204 vcpu_guest_debug_set(vcpu, &debug); 205 205 206 206 vcpu_run(vcpu); 207 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, "KVM_EXIT_IO"); 207 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 208 208 cmd = get_ucall(vcpu, &uc); 209 209 TEST_ASSERT(cmd == UCALL_DONE, "UCALL_DONE"); 210 210
+1 -4
tools/testing/selftests/kvm/x86_64/flds_emulation.h
··· 24 24 uint8_t *insn_bytes; 25 25 uint64_t flags; 26 26 27 - TEST_ASSERT(run->exit_reason == KVM_EXIT_INTERNAL_ERROR, 28 - "Unexpected exit reason: %u (%s)", 29 - run->exit_reason, 30 - exit_reason_str(run->exit_reason)); 27 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR); 31 28 32 29 TEST_ASSERT(run->emulation_failure.suberror == KVM_INTERNAL_ERROR_EMULATION, 33 30 "Unexpected suberror: %u",
+1 -6
tools/testing/selftests/kvm/x86_64/hyperv_clock.c
··· 207 207 { 208 208 struct kvm_vcpu *vcpu; 209 209 struct kvm_vm *vm; 210 - struct kvm_run *run; 211 210 struct ucall uc; 212 211 vm_vaddr_t tsc_page_gva; 213 212 int stage; 214 213 215 214 vm = vm_create_with_one_vcpu(&vcpu, guest_main); 216 - run = vcpu->run; 217 215 218 216 vcpu_set_hv_cpuid(vcpu); 219 217 ··· 225 227 226 228 for (stage = 1;; stage++) { 227 229 vcpu_run(vcpu); 228 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 229 - "Stage %d: unexpected exit reason: %u (%s),\n", 230 - stage, run->exit_reason, 231 - exit_reason_str(run->exit_reason)); 230 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 232 231 233 232 switch (get_ucall(vcpu, &uc)) { 234 233 case UCALL_ABORT:
+1 -7
tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c
··· 237 237 238 238 struct kvm_vcpu *vcpu; 239 239 struct kvm_vm *vm; 240 - struct kvm_run *run; 241 240 struct ucall uc; 242 241 int stage; 243 242 ··· 265 266 pr_info("Running L1 which uses EVMCS to run L2\n"); 266 267 267 268 for (stage = 1;; stage++) { 268 - run = vcpu->run; 269 - 270 269 vcpu_run(vcpu); 271 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 272 - "Stage %d: unexpected exit reason: %u (%s),\n", 273 - stage, run->exit_reason, 274 - exit_reason_str(run->exit_reason)); 270 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 275 271 276 272 switch (get_ucall(vcpu, &uc)) { 277 273 case UCALL_ABORT:
+2 -12
tools/testing/selftests/kvm/x86_64/hyperv_features.c
··· 122 122 { 123 123 struct kvm_cpuid2 *prev_cpuid = NULL; 124 124 struct kvm_vcpu *vcpu; 125 - struct kvm_run *run; 126 125 struct kvm_vm *vm; 127 126 struct ucall uc; 128 127 int stage = 0; ··· 149 150 150 151 vm_init_descriptor_tables(vm); 151 152 vcpu_init_descriptor_tables(vcpu); 152 - 153 - run = vcpu->run; 154 153 155 154 /* TODO: Make this entire test easier to maintain. */ 156 155 if (stage >= 21) ··· 491 494 msr->idx, msr->write ? "write" : "read"); 492 495 493 496 vcpu_run(vcpu); 494 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 495 - "unexpected exit reason: %u (%s)", 496 - run->exit_reason, exit_reason_str(run->exit_reason)); 497 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 497 498 498 499 switch (get_ucall(vcpu, &uc)) { 499 500 case UCALL_ABORT: ··· 513 518 { 514 519 struct kvm_cpuid2 *prev_cpuid = NULL; 515 520 struct kvm_vcpu *vcpu; 516 - struct kvm_run *run; 517 521 struct kvm_vm *vm; 518 522 struct ucall uc; 519 523 int stage = 0; ··· 543 549 } else { 544 550 vcpu_init_cpuid(vcpu, prev_cpuid); 545 551 } 546 - 547 - run = vcpu->run; 548 552 549 553 switch (stage) { 550 554 case 0: ··· 661 669 pr_debug("Stage %d: testing hcall: 0x%lx\n", stage, hcall->control); 662 670 663 671 vcpu_run(vcpu); 664 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 665 - "unexpected exit reason: %u (%s)", 666 - run->exit_reason, exit_reason_str(run->exit_reason)); 672 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 667 673 668 674 switch (get_ucall(vcpu, &uc)) { 669 675 case UCALL_ABORT:
+1 -5
tools/testing/selftests/kvm/x86_64/hyperv_ipi.c
··· 243 243 { 244 244 struct kvm_vm *vm; 245 245 struct kvm_vcpu *vcpu[3]; 246 - unsigned int exit_reason; 247 246 vm_vaddr_t hcall_page; 248 247 pthread_t threads[2]; 249 248 int stage = 1, r; ··· 282 283 while (true) { 283 284 vcpu_run(vcpu[0]); 284 285 285 - exit_reason = vcpu[0]->run->exit_reason; 286 - TEST_ASSERT(exit_reason == KVM_EXIT_IO, 287 - "unexpected exit reason: %u (%s)", 288 - exit_reason, exit_reason_str(exit_reason)); 286 + TEST_ASSERT_KVM_EXIT_REASON(vcpu[0], KVM_EXIT_IO); 289 287 290 288 switch (get_ucall(vcpu[0], &uc)) { 291 289 case UCALL_SYNC:
+1 -6
tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c
··· 156 156 vm_vaddr_t hcall_page; 157 157 struct kvm_vcpu *vcpu; 158 158 struct kvm_vm *vm; 159 - struct kvm_run *run; 160 159 struct ucall uc; 161 160 int stage; 162 161 ··· 164 165 /* Create VM */ 165 166 vm = vm_create_with_one_vcpu(&vcpu, guest_code); 166 167 vcpu_set_hv_cpuid(vcpu); 167 - run = vcpu->run; 168 168 vcpu_alloc_svm(vm, &nested_gva); 169 169 vcpu_alloc_hyperv_test_pages(vm, &hv_pages_gva); 170 170 ··· 175 177 176 178 for (stage = 1;; stage++) { 177 179 vcpu_run(vcpu); 178 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 179 - "Stage %d: unexpected exit reason: %u (%s),\n", 180 - stage, run->exit_reason, 181 - exit_reason_str(run->exit_reason)); 180 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 182 181 183 182 switch (get_ucall(vcpu, &uc)) { 184 183 case UCALL_ABORT:
+2 -12
tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c
··· 542 542 struct ucall uc; 543 543 int old; 544 544 int r; 545 - unsigned int exit_reason; 546 545 547 546 r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); 548 547 TEST_ASSERT(!r, "pthread_setcanceltype failed on vcpu_id=%u with errno=%d", 549 548 vcpu->id, r); 550 549 551 550 vcpu_run(vcpu); 552 - exit_reason = vcpu->run->exit_reason; 553 - 554 - TEST_ASSERT(exit_reason == KVM_EXIT_IO, 555 - "vCPU %u exited with unexpected exit reason %u-%s, expected KVM_EXIT_IO", 556 - vcpu->id, exit_reason, exit_reason_str(exit_reason)); 551 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 557 552 558 553 switch (get_ucall(vcpu, &uc)) { 559 554 case UCALL_ABORT: ··· 582 587 { 583 588 struct kvm_vm *vm; 584 589 struct kvm_vcpu *vcpu[3]; 585 - unsigned int exit_reason; 586 590 pthread_t threads[2]; 587 591 vm_vaddr_t test_data_page, gva; 588 592 vm_paddr_t gpa; ··· 651 657 652 658 while (true) { 653 659 vcpu_run(vcpu[0]); 654 - exit_reason = vcpu[0]->run->exit_reason; 655 - 656 - TEST_ASSERT(exit_reason == KVM_EXIT_IO, 657 - "unexpected exit reason: %u (%s)", 658 - exit_reason, exit_reason_str(exit_reason)); 660 + TEST_ASSERT_KVM_EXIT_REASON(vcpu[0], KVM_EXIT_IO); 659 661 660 662 switch (get_ucall(vcpu[0], &uc)) { 661 663 case UCALL_SYNC:
+1 -4
tools/testing/selftests/kvm/x86_64/kvm_clock_test.c
··· 105 105 static void enter_guest(struct kvm_vcpu *vcpu) 106 106 { 107 107 struct kvm_clock_data start, end; 108 - struct kvm_run *run = vcpu->run; 109 108 struct kvm_vm *vm = vcpu->vm; 110 109 struct ucall uc; 111 110 int i; ··· 117 118 vcpu_run(vcpu); 118 119 vm_ioctl(vm, KVM_GET_CLOCK, &end); 119 120 120 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 121 - "unexpected exit reason: %u (%s)", 122 - run->exit_reason, exit_reason_str(run->exit_reason)); 121 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 123 122 124 123 switch (get_ucall(vcpu, &uc)) { 125 124 case UCALL_SYNC:
+1 -4
tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
··· 111 111 112 112 static void enter_guest(struct kvm_vcpu *vcpu) 113 113 { 114 - struct kvm_run *run = vcpu->run; 115 114 struct ucall uc; 116 115 117 116 while (true) { 118 117 vcpu_run(vcpu); 119 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 120 - "unexpected exit reason: %u (%s)", 121 - run->exit_reason, exit_reason_str(run->exit_reason)); 118 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 122 119 123 120 switch (get_ucall(vcpu, &uc)) { 124 121 case UCALL_PR_MSR:
+1 -8
tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c
··· 64 64 { 65 65 uint64_t disabled_quirks; 66 66 struct kvm_vcpu *vcpu; 67 - struct kvm_run *run; 68 67 struct kvm_vm *vm; 69 68 struct ucall uc; 70 69 int testcase; ··· 73 74 vm = vm_create_with_one_vcpu(&vcpu, guest_code); 74 75 vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_MWAIT); 75 76 76 - run = vcpu->run; 77 - 78 77 vm_init_descriptor_tables(vm); 79 78 vcpu_init_descriptor_tables(vcpu); 80 79 81 80 while (1) { 82 81 vcpu_run(vcpu); 83 - 84 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 85 - "Unexpected exit reason: %u (%s),\n", 86 - run->exit_reason, 87 - exit_reason_str(run->exit_reason)); 82 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 88 83 89 84 switch (get_ucall(vcpu, &uc)) { 90 85 case UCALL_SYNC:
+1 -4
tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c
··· 166 166 167 167 static void assert_ucall_vector(struct kvm_vcpu *vcpu, int vector) 168 168 { 169 - struct kvm_run *run = vcpu->run; 170 169 struct ucall uc; 171 170 172 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 173 - "Unexpected exit reason: %u (%s),\n", 174 - run->exit_reason, exit_reason_str(run->exit_reason)); 171 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 175 172 176 173 switch (get_ucall(vcpu, &uc)) { 177 174 case UCALL_SYNC:
+3 -11
tools/testing/selftests/kvm/x86_64/platform_info_test.c
··· 36 36 37 37 static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu) 38 38 { 39 - struct kvm_run *run = vcpu->run; 40 39 struct ucall uc; 41 40 42 41 vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true); 43 42 vcpu_run(vcpu); 44 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 45 - "Exit_reason other than KVM_EXIT_IO: %u (%s),\n", 46 - run->exit_reason, 47 - exit_reason_str(run->exit_reason)); 43 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 44 + 48 45 get_ucall(vcpu, &uc); 49 46 TEST_ASSERT(uc.cmd == UCALL_SYNC, 50 47 "Received ucall other than UCALL_SYNC: %lu\n", uc.cmd); ··· 53 56 54 57 static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu) 55 58 { 56 - struct kvm_run *run = vcpu->run; 57 - 58 59 vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false); 59 60 vcpu_run(vcpu); 60 - TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN, 61 - "Exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n", 62 - run->exit_reason, 63 - exit_reason_str(run->exit_reason)); 61 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN); 64 62 } 65 63 66 64 int main(int argc, char *argv[])
+1 -5
tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c
··· 151 151 */ 152 152 static uint64_t run_vcpu_to_sync(struct kvm_vcpu *vcpu) 153 153 { 154 - struct kvm_run *run = vcpu->run; 155 154 struct ucall uc; 156 155 157 156 vcpu_run(vcpu); 158 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 159 - "Exit_reason other than KVM_EXIT_IO: %u (%s)\n", 160 - run->exit_reason, 161 - exit_reason_str(run->exit_reason)); 157 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 162 158 get_ucall(vcpu, &uc); 163 159 TEST_ASSERT(uc.cmd == UCALL_SYNC, 164 160 "Received ucall other than UCALL_SYNC: %lu", uc.cmd);
+1 -8
tools/testing/selftests/kvm/x86_64/smm_test.c
··· 133 133 struct kvm_vcpu *vcpu; 134 134 struct kvm_regs regs; 135 135 struct kvm_vm *vm; 136 - struct kvm_run *run; 137 136 struct kvm_x86_state *state; 138 137 int stage, stage_reported; 139 138 ··· 140 141 141 142 /* Create VM */ 142 143 vm = vm_create_with_one_vcpu(&vcpu, guest_code); 143 - 144 - run = vcpu->run; 145 144 146 145 vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, SMRAM_GPA, 147 146 SMRAM_MEMSLOT, SMRAM_PAGES, 0); ··· 166 169 167 170 for (stage = 1;; stage++) { 168 171 vcpu_run(vcpu); 169 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 170 - "Stage %d: unexpected exit reason: %u (%s),\n", 171 - stage, run->exit_reason, 172 - exit_reason_str(run->exit_reason)); 172 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 173 173 174 174 memset(&regs, 0, sizeof(regs)); 175 175 vcpu_regs_get(vcpu, &regs); ··· 202 208 203 209 vcpu = vm_recreate_with_one_vcpu(vm); 204 210 vcpu_load_state(vcpu, state); 205 - run = vcpu->run; 206 211 kvm_x86_state_cleanup(state); 207 212 } 208 213
+1 -7
tools/testing/selftests/kvm/x86_64/state_test.c
··· 158 158 struct kvm_regs regs1, regs2; 159 159 struct kvm_vcpu *vcpu; 160 160 struct kvm_vm *vm; 161 - struct kvm_run *run; 162 161 struct kvm_x86_state *state; 163 162 struct ucall uc; 164 163 int stage; 165 164 166 165 /* Create VM */ 167 166 vm = vm_create_with_one_vcpu(&vcpu, guest_code); 168 - run = vcpu->run; 169 167 170 168 vcpu_regs_get(vcpu, &regs1); 171 169 ··· 181 183 182 184 for (stage = 1;; stage++) { 183 185 vcpu_run(vcpu); 184 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 185 - "Stage %d: unexpected exit reason: %u (%s),\n", 186 - stage, run->exit_reason, 187 - exit_reason_str(run->exit_reason)); 186 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 188 187 189 188 switch (get_ucall(vcpu, &uc)) { 190 189 case UCALL_ABORT: ··· 209 214 /* Restore state in a new VM. */ 210 215 vcpu = vm_recreate_with_one_vcpu(vm); 211 216 vcpu_load_state(vcpu, state); 212 - run = vcpu->run; 213 217 kvm_x86_state_cleanup(state); 214 218 215 219 memset(&regs2, 0, sizeof(regs2));
+1 -7
tools/testing/selftests/kvm/x86_64/svm_int_ctl_test.c
··· 85 85 int main(int argc, char *argv[]) 86 86 { 87 87 struct kvm_vcpu *vcpu; 88 - struct kvm_run *run; 89 88 vm_vaddr_t svm_gva; 90 89 struct kvm_vm *vm; 91 90 struct ucall uc; ··· 102 103 vcpu_alloc_svm(vm, &svm_gva); 103 104 vcpu_args_set(vcpu, 1, svm_gva); 104 105 105 - run = vcpu->run; 106 - 107 106 vcpu_run(vcpu); 108 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 109 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 110 - run->exit_reason, 111 - exit_reason_str(run->exit_reason)); 107 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 112 108 113 109 switch (get_ucall(vcpu, &uc)) { 114 110 case UCALL_ABORT:
+1 -6
tools/testing/selftests/kvm/x86_64/svm_nested_shutdown_test.c
··· 42 42 int main(int argc, char *argv[]) 43 43 { 44 44 struct kvm_vcpu *vcpu; 45 - struct kvm_run *run; 46 45 vm_vaddr_t svm_gva; 47 46 struct kvm_vm *vm; 48 47 ··· 54 55 vcpu_alloc_svm(vm, &svm_gva); 55 56 56 57 vcpu_args_set(vcpu, 2, svm_gva, vm->idt); 57 - run = vcpu->run; 58 58 59 59 vcpu_run(vcpu); 60 - TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN, 61 - "Got exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n", 62 - run->exit_reason, 63 - exit_reason_str(run->exit_reason)); 60 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN); 64 61 65 62 kvm_vm_free(vm); 66 63 }
+1 -5
tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c
··· 176 176 memset(&debug, 0, sizeof(debug)); 177 177 vcpu_guest_debug_set(vcpu, &debug); 178 178 179 - struct kvm_run *run = vcpu->run; 180 179 struct ucall uc; 181 180 182 181 alarm(2); 183 182 vcpu_run(vcpu); 184 183 alarm(0); 185 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 186 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 187 - run->exit_reason, 188 - exit_reason_str(run->exit_reason)); 184 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 189 185 190 186 switch (get_ucall(vcpu, &uc)) { 191 187 case UCALL_ABORT:
+1 -5
tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c
··· 47 47 vcpu_args_set(vcpu, 1, svm_gva); 48 48 49 49 for (;;) { 50 - volatile struct kvm_run *run = vcpu->run; 51 50 struct ucall uc; 52 51 53 52 vcpu_run(vcpu); 54 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 55 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 56 - run->exit_reason, 57 - exit_reason_str(run->exit_reason)); 53 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 58 54 59 55 switch (get_ucall(vcpu, &uc)) { 60 56 case UCALL_ABORT:
+5 -20
tools/testing/selftests/kvm/x86_64/sync_regs_test.c
··· 132 132 /* TODO: BUILD TIME CHECK: TEST_ASSERT(KVM_SYNC_X86_NUM_FIELDS != 3); */ 133 133 run->kvm_valid_regs = TEST_SYNC_FIELDS; 134 134 rv = _vcpu_run(vcpu); 135 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 136 - "Unexpected exit reason: %u (%s),\n", 137 - run->exit_reason, 138 - exit_reason_str(run->exit_reason)); 135 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 139 136 140 137 vcpu_regs_get(vcpu, &regs); 141 138 compare_regs(&regs, &run->s.regs.regs); ··· 151 154 run->kvm_valid_regs = TEST_SYNC_FIELDS; 152 155 run->kvm_dirty_regs = KVM_SYNC_X86_REGS | KVM_SYNC_X86_SREGS; 153 156 rv = _vcpu_run(vcpu); 154 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 155 - "Unexpected exit reason: %u (%s),\n", 156 - run->exit_reason, 157 - exit_reason_str(run->exit_reason)); 157 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 158 158 TEST_ASSERT(run->s.regs.regs.rbx == 0xBAD1DEA + 1, 159 159 "rbx sync regs value incorrect 0x%llx.", 160 160 run->s.regs.regs.rbx); ··· 175 181 run->kvm_dirty_regs = 0; 176 182 run->s.regs.regs.rbx = 0xDEADBEEF; 177 183 rv = _vcpu_run(vcpu); 178 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 179 - "Unexpected exit reason: %u (%s),\n", 180 - run->exit_reason, 181 - exit_reason_str(run->exit_reason)); 184 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 182 185 TEST_ASSERT(run->s.regs.regs.rbx != 0xDEADBEEF, 183 186 "rbx sync regs value incorrect 0x%llx.", 184 187 run->s.regs.regs.rbx); ··· 190 199 regs.rbx = 0xBAC0; 191 200 vcpu_regs_set(vcpu, &regs); 192 201 rv = _vcpu_run(vcpu); 193 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 194 - "Unexpected exit reason: %u (%s),\n", 195 - run->exit_reason, 196 - exit_reason_str(run->exit_reason)); 202 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 197 203 TEST_ASSERT(run->s.regs.regs.rbx == 0xAAAA, 198 204 "rbx sync regs value incorrect 0x%llx.", 199 205 run->s.regs.regs.rbx); ··· 207 219 run->kvm_dirty_regs = TEST_SYNC_FIELDS; 208 220 run->s.regs.regs.rbx = 0xBBBB; 209 221 rv = _vcpu_run(vcpu); 210 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 211 - "Unexpected exit reason: %u (%s),\n", 212 - run->exit_reason, 213 - exit_reason_str(run->exit_reason)); 222 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 214 223 TEST_ASSERT(run->s.regs.regs.rbx == 0xBBBB, 215 224 "rbx sync regs value incorrect 0x%llx.", 216 225 run->s.regs.regs.rbx);
+2 -7
tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c
··· 89 89 run = vcpu->run; 90 90 vcpu_run(vcpu); 91 91 92 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 93 - "Expected KVM_EXIT_IO, got: %u (%s)\n", 94 - run->exit_reason, exit_reason_str(run->exit_reason)); 92 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 95 93 TEST_ASSERT(run->io.port == ARBITRARY_IO_PORT, 96 94 "Expected IN from port %d from L2, got port %d", 97 95 ARBITRARY_IO_PORT, run->io.port); ··· 109 111 110 112 111 113 if (has_svm) { 112 - TEST_ASSERT(run->exit_reason == KVM_EXIT_SHUTDOWN, 113 - "Got exit_reason other than KVM_EXIT_SHUTDOWN: %u (%s)\n", 114 - run->exit_reason, 115 - exit_reason_str(run->exit_reason)); 114 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN); 116 115 } else { 117 116 switch (get_ucall(vcpu, &uc)) { 118 117 case UCALL_DONE:
+1 -5
tools/testing/selftests/kvm/x86_64/tsc_scaling_sync.c
··· 64 64 pthread_spin_unlock(&create_lock); 65 65 66 66 for (;;) { 67 - volatile struct kvm_run *run = vcpu->run; 68 67 struct ucall uc; 69 68 70 69 vcpu_run(vcpu); 71 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 72 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 73 - run->exit_reason, 74 - exit_reason_str(run->exit_reason)); 70 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 75 71 76 72 switch (get_ucall(vcpu, &uc)) { 77 73 case UCALL_DONE:
+4 -18
tools/testing/selftests/kvm/x86_64/ucna_injection_test.c
··· 137 137 138 138 static void run_vcpu_expect_gp(struct kvm_vcpu *vcpu) 139 139 { 140 - unsigned int exit_reason; 141 140 struct ucall uc; 142 141 143 142 vcpu_run(vcpu); 144 143 145 - exit_reason = vcpu->run->exit_reason; 146 - TEST_ASSERT(exit_reason == KVM_EXIT_IO, 147 - "exited with unexpected exit reason %u-%s, expected KVM_EXIT_IO", 148 - exit_reason, exit_reason_str(exit_reason)); 144 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 149 145 TEST_ASSERT(get_ucall(vcpu, &uc) == UCALL_SYNC, 150 146 "Expect UCALL_SYNC\n"); 151 147 TEST_ASSERT(uc.args[1] == SYNC_GP, "#GP is expected."); ··· 178 182 struct ucall uc; 179 183 int old; 180 184 int r; 181 - unsigned int exit_reason; 182 185 183 186 r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); 184 187 TEST_ASSERT(r == 0, ··· 186 191 187 192 vcpu_run(params->vcpu); 188 193 189 - exit_reason = params->vcpu->run->exit_reason; 190 - TEST_ASSERT(exit_reason == KVM_EXIT_IO, 191 - "unexpected exit reason %u-%s, expected KVM_EXIT_IO", 192 - exit_reason, exit_reason_str(exit_reason)); 194 + TEST_ASSERT_KVM_EXIT_REASON(params->vcpu, KVM_EXIT_IO); 193 195 TEST_ASSERT(get_ucall(params->vcpu, &uc) == UCALL_SYNC, 194 196 "Expect UCALL_SYNC\n"); 195 197 TEST_ASSERT(uc.args[1] == SYNC_FIRST_UCNA, "Injecting first UCNA."); ··· 196 204 inject_ucna(params->vcpu, FIRST_UCNA_ADDR); 197 205 vcpu_run(params->vcpu); 198 206 199 - exit_reason = params->vcpu->run->exit_reason; 200 - TEST_ASSERT(exit_reason == KVM_EXIT_IO, 201 - "unexpected exit reason %u-%s, expected KVM_EXIT_IO", 202 - exit_reason, exit_reason_str(exit_reason)); 207 + TEST_ASSERT_KVM_EXIT_REASON(params->vcpu, KVM_EXIT_IO); 203 208 TEST_ASSERT(get_ucall(params->vcpu, &uc) == UCALL_SYNC, 204 209 "Expect UCALL_SYNC\n"); 205 210 TEST_ASSERT(uc.args[1] == SYNC_SECOND_UCNA, "Injecting second UCNA."); ··· 206 217 inject_ucna(params->vcpu, SECOND_UCNA_ADDR); 207 218 vcpu_run(params->vcpu); 208 219 209 - exit_reason = params->vcpu->run->exit_reason; 210 - TEST_ASSERT(exit_reason == KVM_EXIT_IO, 211 - "unexpected exit reason %u-%s, expected KVM_EXIT_IO", 212 - exit_reason, exit_reason_str(exit_reason)); 220 + TEST_ASSERT_KVM_EXIT_REASON(params->vcpu, KVM_EXIT_IO); 213 221 if (get_ucall(params->vcpu, &uc) == UCALL_ABORT) { 214 222 TEST_ASSERT(false, "vCPU assertion failure: %s.\n", 215 223 (const char *)uc.args[0]);
+1 -5
tools/testing/selftests/kvm/x86_64/userspace_io_test.c
··· 63 63 64 64 while (1) { 65 65 vcpu_run(vcpu); 66 - 67 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 68 - "Unexpected exit reason: %u (%s),\n", 69 - run->exit_reason, 70 - exit_reason_str(run->exit_reason)); 66 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 71 67 72 68 if (get_ucall(vcpu, &uc)) 73 69 break;
+4 -18
tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c
··· 410 410 411 411 check_for_guest_assert(vcpu); 412 412 413 - TEST_ASSERT(run->exit_reason == KVM_EXIT_X86_RDMSR, 414 - "Unexpected exit reason: %u (%s),\n", 415 - run->exit_reason, 416 - exit_reason_str(run->exit_reason)); 413 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_X86_RDMSR); 417 414 TEST_ASSERT(run->msr.index == msr_index, 418 415 "Unexpected msr (0x%04x), expected 0x%04x", 419 416 run->msr.index, msr_index); ··· 442 445 443 446 check_for_guest_assert(vcpu); 444 447 445 - TEST_ASSERT(run->exit_reason == KVM_EXIT_X86_WRMSR, 446 - "Unexpected exit reason: %u (%s),\n", 447 - run->exit_reason, 448 - exit_reason_str(run->exit_reason)); 448 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_X86_WRMSR); 449 449 TEST_ASSERT(run->msr.index == msr_index, 450 450 "Unexpected msr (0x%04x), expected 0x%04x", 451 451 run->msr.index, msr_index); ··· 466 472 467 473 static void process_ucall_done(struct kvm_vcpu *vcpu) 468 474 { 469 - struct kvm_run *run = vcpu->run; 470 475 struct ucall uc; 471 476 472 477 check_for_guest_assert(vcpu); 473 478 474 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 475 - "Unexpected exit reason: %u (%s)", 476 - run->exit_reason, 477 - exit_reason_str(run->exit_reason)); 479 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 478 480 479 481 TEST_ASSERT(get_ucall(vcpu, &uc) == UCALL_DONE, 480 482 "Unexpected ucall command: %lu, expected UCALL_DONE (%d)", ··· 479 489 480 490 static uint64_t process_ucall(struct kvm_vcpu *vcpu) 481 491 { 482 - struct kvm_run *run = vcpu->run; 483 492 struct ucall uc = {}; 484 493 485 494 check_for_guest_assert(vcpu); 486 495 487 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 488 - "Unexpected exit reason: %u (%s)", 489 - run->exit_reason, 490 - exit_reason_str(run->exit_reason)); 496 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 491 497 492 498 switch (get_ucall(vcpu, &uc)) { 493 499 case UCALL_SYNC:
+2 -9
tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c
··· 96 96 97 97 vcpu_run(vcpu); 98 98 if (apic_access_addr == high_gpa) { 99 - TEST_ASSERT(run->exit_reason == 100 - KVM_EXIT_INTERNAL_ERROR, 101 - "Got exit reason other than KVM_EXIT_INTERNAL_ERROR: %u (%s)\n", 102 - run->exit_reason, 103 - exit_reason_str(run->exit_reason)); 99 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR); 104 100 TEST_ASSERT(run->internal.suberror == 105 101 KVM_INTERNAL_ERROR_EMULATION, 106 102 "Got internal suberror other than KVM_INTERNAL_ERROR_EMULATION: %u\n", 107 103 run->internal.suberror); 108 104 break; 109 105 } 110 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 111 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 112 - run->exit_reason, 113 - exit_reason_str(run->exit_reason)); 106 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 114 107 115 108 switch (get_ucall(vcpu, &uc)) { 116 109 case UCALL_ABORT:
+1 -4
tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c
··· 64 64 struct ucall uc; 65 65 66 66 vcpu_run(vcpu); 67 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 68 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 69 - run->exit_reason, 70 - exit_reason_str(run->exit_reason)); 67 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 71 68 72 69 if (run->io.port == PORT_L0_EXIT) 73 70 break;
+1 -6
tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c
··· 73 73 74 74 struct kvm_vcpu *vcpu; 75 75 struct kvm_vm *vm; 76 - struct kvm_run *run; 77 76 struct ucall uc; 78 77 bool done = false; 79 78 ··· 83 84 vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); 84 85 vmx = vcpu_alloc_vmx(vm, &vmx_pages_gva); 85 86 vcpu_args_set(vcpu, 1, vmx_pages_gva); 86 - run = vcpu->run; 87 87 88 88 /* Add an extra memory slot for testing dirty logging */ 89 89 vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, ··· 115 117 while (!done) { 116 118 memset(host_test_mem, 0xaa, TEST_MEM_PAGES * 4096); 117 119 vcpu_run(vcpu); 118 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 119 - "Unexpected exit reason: %u (%s),\n", 120 - run->exit_reason, 121 - exit_reason_str(run->exit_reason)); 120 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 122 121 123 122 switch (get_ucall(vcpu, &uc)) { 124 123 case UCALL_ABORT:
+1 -3
tools/testing/selftests/kvm/x86_64/vmx_exception_with_invalid_guest_state.c
··· 26 26 27 27 vcpu_run(vcpu); 28 28 29 - TEST_ASSERT(run->exit_reason == KVM_EXIT_INTERNAL_ERROR, 30 - "Expected KVM_EXIT_INTERNAL_ERROR, got %d (%s)\n", 31 - run->exit_reason, exit_reason_str(run->exit_reason)); 29 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR); 32 30 TEST_ASSERT(run->emulation_failure.suberror == KVM_INTERNAL_ERROR_EMULATION, 33 31 "Expected emulation failure, got %d\n", 34 32 run->emulation_failure.suberror);
+1 -3
tools/testing/selftests/kvm/x86_64/vmx_invalid_nested_guest_state.c
··· 74 74 * The first exit to L0 userspace should be an I/O access from L2. 75 75 * Running L1 should launch L2 without triggering an exit to userspace. 76 76 */ 77 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 78 - "Expected KVM_EXIT_IO, got: %u (%s)\n", 79 - run->exit_reason, exit_reason_str(run->exit_reason)); 77 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 80 78 81 79 TEST_ASSERT(run->io.port == ARBITRARY_IO_PORT, 82 80 "Expected IN from port %d from L2, got port %d",
+1 -5
tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
··· 183 183 vcpu_ioctl(vcpu, KVM_SET_TSC_KHZ, (void *) (tsc_khz / l1_scale_factor)); 184 184 185 185 for (;;) { 186 - volatile struct kvm_run *run = vcpu->run; 187 186 struct ucall uc; 188 187 189 188 vcpu_run(vcpu); 190 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 191 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 192 - run->exit_reason, 193 - exit_reason_str(run->exit_reason)); 189 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 194 190 195 191 switch (get_ucall(vcpu, &uc)) { 196 192 case UCALL_ABORT:
+1 -7
tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c
··· 157 157 158 158 struct kvm_regs regs1, regs2; 159 159 struct kvm_vm *vm; 160 - struct kvm_run *run; 161 160 struct kvm_vcpu *vcpu; 162 161 struct kvm_x86_state *state; 163 162 struct ucall uc; ··· 172 173 173 174 /* Create VM */ 174 175 vm = vm_create_with_one_vcpu(&vcpu, guest_code); 175 - run = vcpu->run; 176 176 177 177 vcpu_regs_get(vcpu, &regs1); 178 178 ··· 180 182 181 183 for (stage = 1;; stage++) { 182 184 vcpu_run(vcpu); 183 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 184 - "Stage %d: unexpected exit reason: %u (%s),\n", 185 - stage, run->exit_reason, 186 - exit_reason_str(run->exit_reason)); 185 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 187 186 188 187 switch (get_ucall(vcpu, &uc)) { 189 188 case UCALL_ABORT: ··· 232 237 /* Restore state in a new VM. */ 233 238 vcpu = vm_recreate_with_one_vcpu(vm); 234 239 vcpu_load_state(vcpu, state); 235 - run = vcpu->run; 236 240 kvm_x86_state_cleanup(state); 237 241 238 242 memset(&regs2, 0, sizeof(regs2));
+1 -5
tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c
··· 131 131 vcpu_args_set(vcpu, 1, vmx_pages_gva); 132 132 133 133 for (;;) { 134 - volatile struct kvm_run *run = vcpu->run; 135 134 struct ucall uc; 136 135 137 136 vcpu_run(vcpu); 138 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 139 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 140 - run->exit_reason, 141 - exit_reason_str(run->exit_reason)); 137 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 142 138 143 139 switch (get_ucall(vcpu, &uc)) { 144 140 case UCALL_ABORT:
+1 -5
tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c
··· 198 198 struct ucall uc; 199 199 int old; 200 200 int r; 201 - unsigned int exit_reason; 202 201 203 202 r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); 204 203 TEST_ASSERT(r == 0, ··· 206 207 207 208 fprintf(stderr, "vCPU thread running vCPU %u\n", vcpu->id); 208 209 vcpu_run(vcpu); 209 - exit_reason = vcpu->run->exit_reason; 210 210 211 - TEST_ASSERT(exit_reason == KVM_EXIT_IO, 212 - "vCPU %u exited with unexpected exit reason %u-%s, expected KVM_EXIT_IO", 213 - vcpu->id, exit_reason, exit_reason_str(exit_reason)); 211 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 214 212 215 213 if (get_ucall(vcpu, &uc) == UCALL_ABORT) { 216 214 TEST_ASSERT(false,
+119 -111
tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
··· 26 26 #define DUMMY_REGION_GPA (SHINFO_REGION_GPA + (3 * PAGE_SIZE)) 27 27 #define DUMMY_REGION_SLOT 11 28 28 29 + #define DUMMY_REGION_GPA_2 (SHINFO_REGION_GPA + (4 * PAGE_SIZE)) 30 + #define DUMMY_REGION_SLOT_2 12 31 + 29 32 #define SHINFO_ADDR (SHINFO_REGION_GPA) 30 33 #define VCPU_INFO_ADDR (SHINFO_REGION_GPA + 0x40) 31 34 #define PVTIME_ADDR (SHINFO_REGION_GPA + PAGE_SIZE) ··· 43 40 #define EVTCHN_TEST1 15 44 41 #define EVTCHN_TEST2 66 45 42 #define EVTCHN_TIMER 13 43 + 44 + enum { 45 + TEST_INJECT_VECTOR = 0, 46 + TEST_RUNSTATE_runnable, 47 + TEST_RUNSTATE_blocked, 48 + TEST_RUNSTATE_offline, 49 + TEST_RUNSTATE_ADJUST, 50 + TEST_RUNSTATE_DATA, 51 + TEST_STEAL_TIME, 52 + TEST_EVTCHN_MASKED, 53 + TEST_EVTCHN_UNMASKED, 54 + TEST_EVTCHN_SLOWPATH, 55 + TEST_EVTCHN_SEND_IOCTL, 56 + TEST_EVTCHN_HCALL, 57 + TEST_EVTCHN_HCALL_SLOWPATH, 58 + TEST_EVTCHN_HCALL_EVENTFD, 59 + TEST_TIMER_SETUP, 60 + TEST_TIMER_WAIT, 61 + TEST_TIMER_RESTORE, 62 + TEST_POLL_READY, 63 + TEST_POLL_TIMEOUT, 64 + TEST_POLL_MASKED, 65 + TEST_POLL_WAKE, 66 + TEST_TIMER_PAST, 67 + TEST_LOCKING_SEND_RACE, 68 + TEST_LOCKING_POLL_RACE, 69 + TEST_LOCKING_POLL_TIMEOUT, 70 + TEST_DONE, 71 + 72 + TEST_GUEST_SAW_IRQ, 73 + }; 46 74 47 75 #define XEN_HYPERCALL_MSR 0x40000000 48 76 ··· 178 144 vi->evtchn_pending_sel = 0; 179 145 guest_saw_irq = true; 180 146 181 - GUEST_SYNC(0x20); 147 + GUEST_SYNC(TEST_GUEST_SAW_IRQ); 182 148 } 183 149 184 150 static void guest_wait_for_irq(void) ··· 199 165 ); 200 166 201 167 /* Trigger an interrupt injection */ 202 - GUEST_SYNC(0); 168 + GUEST_SYNC(TEST_INJECT_VECTOR); 203 169 204 170 guest_wait_for_irq(); 205 171 206 172 /* Test having the host set runstates manually */ 207 - GUEST_SYNC(RUNSTATE_runnable); 173 + GUEST_SYNC(TEST_RUNSTATE_runnable); 208 174 GUEST_ASSERT(rs->time[RUNSTATE_runnable] != 0); 209 175 GUEST_ASSERT(rs->state == 0); 210 176 211 - GUEST_SYNC(RUNSTATE_blocked); 177 + GUEST_SYNC(TEST_RUNSTATE_blocked); 212 178 GUEST_ASSERT(rs->time[RUNSTATE_blocked] != 0); 213 179 GUEST_ASSERT(rs->state == 0); 214 180 215 - GUEST_SYNC(RUNSTATE_offline); 181 + GUEST_SYNC(TEST_RUNSTATE_offline); 216 182 GUEST_ASSERT(rs->time[RUNSTATE_offline] != 0); 217 183 GUEST_ASSERT(rs->state == 0); 218 184 219 185 /* Test runstate time adjust */ 220 - GUEST_SYNC(4); 186 + GUEST_SYNC(TEST_RUNSTATE_ADJUST); 221 187 GUEST_ASSERT(rs->time[RUNSTATE_blocked] == 0x5a); 222 188 GUEST_ASSERT(rs->time[RUNSTATE_offline] == 0x6b6b); 223 189 224 190 /* Test runstate time set */ 225 - GUEST_SYNC(5); 191 + GUEST_SYNC(TEST_RUNSTATE_DATA); 226 192 GUEST_ASSERT(rs->state_entry_time >= 0x8000); 227 193 GUEST_ASSERT(rs->time[RUNSTATE_runnable] == 0); 228 194 GUEST_ASSERT(rs->time[RUNSTATE_blocked] == 0x6b6b); 229 195 GUEST_ASSERT(rs->time[RUNSTATE_offline] == 0x5a); 230 196 231 197 /* sched_yield() should result in some 'runnable' time */ 232 - GUEST_SYNC(6); 198 + GUEST_SYNC(TEST_STEAL_TIME); 233 199 GUEST_ASSERT(rs->time[RUNSTATE_runnable] >= MIN_STEAL_TIME); 234 200 235 201 /* Attempt to deliver a *masked* interrupt */ 236 - GUEST_SYNC(7); 202 + GUEST_SYNC(TEST_EVTCHN_MASKED); 237 203 238 204 /* Wait until we see the bit set */ 239 205 struct shared_info *si = (void *)SHINFO_VADDR; ··· 241 207 __asm__ __volatile__ ("rep nop" : : : "memory"); 242 208 243 209 /* Now deliver an *unmasked* interrupt */ 244 - GUEST_SYNC(8); 210 + GUEST_SYNC(TEST_EVTCHN_UNMASKED); 245 211 246 212 guest_wait_for_irq(); 247 213 248 214 /* Change memslots and deliver an interrupt */ 249 - GUEST_SYNC(9); 215 + GUEST_SYNC(TEST_EVTCHN_SLOWPATH); 250 216 251 217 guest_wait_for_irq(); 252 218 253 219 /* Deliver event channel with KVM_XEN_HVM_EVTCHN_SEND */ 254 - GUEST_SYNC(10); 220 + GUEST_SYNC(TEST_EVTCHN_SEND_IOCTL); 255 221 256 222 guest_wait_for_irq(); 257 223 258 - GUEST_SYNC(11); 224 + GUEST_SYNC(TEST_EVTCHN_HCALL); 259 225 260 226 /* Our turn. Deliver event channel (to ourselves) with 261 227 * EVTCHNOP_send hypercall. */ 262 - unsigned long rax; 263 228 struct evtchn_send s = { .port = 127 }; 264 - __asm__ __volatile__ ("vmcall" : 265 - "=a" (rax) : 266 - "a" (__HYPERVISOR_event_channel_op), 267 - "D" (EVTCHNOP_send), 268 - "S" (&s)); 269 - 270 - GUEST_ASSERT(rax == 0); 229 + xen_hypercall(__HYPERVISOR_event_channel_op, EVTCHNOP_send, &s); 271 230 272 231 guest_wait_for_irq(); 273 232 274 - GUEST_SYNC(12); 233 + GUEST_SYNC(TEST_EVTCHN_HCALL_SLOWPATH); 234 + 235 + /* 236 + * Same again, but this time the host has messed with memslots so it 237 + * should take the slow path in kvm_xen_set_evtchn(). 238 + */ 239 + xen_hypercall(__HYPERVISOR_event_channel_op, EVTCHNOP_send, &s); 240 + 241 + guest_wait_for_irq(); 242 + 243 + GUEST_SYNC(TEST_EVTCHN_HCALL_EVENTFD); 275 244 276 245 /* Deliver "outbound" event channel to an eventfd which 277 246 * happens to be one of our own irqfds. */ 278 247 s.port = 197; 279 - __asm__ __volatile__ ("vmcall" : 280 - "=a" (rax) : 281 - "a" (__HYPERVISOR_event_channel_op), 282 - "D" (EVTCHNOP_send), 283 - "S" (&s)); 284 - 285 - GUEST_ASSERT(rax == 0); 248 + xen_hypercall(__HYPERVISOR_event_channel_op, EVTCHNOP_send, &s); 286 249 287 250 guest_wait_for_irq(); 288 251 289 - GUEST_SYNC(13); 252 + GUEST_SYNC(TEST_TIMER_SETUP); 290 253 291 254 /* Set a timer 100ms in the future. */ 292 - __asm__ __volatile__ ("vmcall" : 293 - "=a" (rax) : 294 - "a" (__HYPERVISOR_set_timer_op), 295 - "D" (rs->state_entry_time + 100000000)); 296 - GUEST_ASSERT(rax == 0); 255 + xen_hypercall(__HYPERVISOR_set_timer_op, 256 + rs->state_entry_time + 100000000, NULL); 297 257 298 - GUEST_SYNC(14); 258 + GUEST_SYNC(TEST_TIMER_WAIT); 299 259 300 260 /* Now wait for the timer */ 301 261 guest_wait_for_irq(); 302 262 303 - GUEST_SYNC(15); 263 + GUEST_SYNC(TEST_TIMER_RESTORE); 304 264 305 265 /* The host has 'restored' the timer. Just wait for it. */ 306 266 guest_wait_for_irq(); 307 267 308 - GUEST_SYNC(16); 268 + GUEST_SYNC(TEST_POLL_READY); 309 269 310 270 /* Poll for an event channel port which is already set */ 311 271 u32 ports[1] = { EVTCHN_TIMER }; ··· 309 281 .timeout = 0, 310 282 }; 311 283 312 - __asm__ __volatile__ ("vmcall" : 313 - "=a" (rax) : 314 - "a" (__HYPERVISOR_sched_op), 315 - "D" (SCHEDOP_poll), 316 - "S" (&p)); 284 + xen_hypercall(__HYPERVISOR_sched_op, SCHEDOP_poll, &p); 317 285 318 - GUEST_ASSERT(rax == 0); 319 - 320 - GUEST_SYNC(17); 286 + GUEST_SYNC(TEST_POLL_TIMEOUT); 321 287 322 288 /* Poll for an unset port and wait for the timeout. */ 323 289 p.timeout = 100000000; 324 - __asm__ __volatile__ ("vmcall" : 325 - "=a" (rax) : 326 - "a" (__HYPERVISOR_sched_op), 327 - "D" (SCHEDOP_poll), 328 - "S" (&p)); 290 + xen_hypercall(__HYPERVISOR_sched_op, SCHEDOP_poll, &p); 329 291 330 - GUEST_ASSERT(rax == 0); 331 - 332 - GUEST_SYNC(18); 292 + GUEST_SYNC(TEST_POLL_MASKED); 333 293 334 294 /* A timer will wake the masked port we're waiting on, while we poll */ 335 295 p.timeout = 0; 336 - __asm__ __volatile__ ("vmcall" : 337 - "=a" (rax) : 338 - "a" (__HYPERVISOR_sched_op), 339 - "D" (SCHEDOP_poll), 340 - "S" (&p)); 296 + xen_hypercall(__HYPERVISOR_sched_op, SCHEDOP_poll, &p); 341 297 342 - GUEST_ASSERT(rax == 0); 343 - 344 - GUEST_SYNC(19); 298 + GUEST_SYNC(TEST_POLL_WAKE); 345 299 346 300 /* A timer wake an *unmasked* port which should wake us with an 347 301 * actual interrupt, while we're polling on a different port. */ 348 302 ports[0]++; 349 303 p.timeout = 0; 350 - __asm__ __volatile__ ("vmcall" : 351 - "=a" (rax) : 352 - "a" (__HYPERVISOR_sched_op), 353 - "D" (SCHEDOP_poll), 354 - "S" (&p)); 355 - 356 - GUEST_ASSERT(rax == 0); 304 + xen_hypercall(__HYPERVISOR_sched_op, SCHEDOP_poll, &p); 357 305 358 306 guest_wait_for_irq(); 359 307 360 - GUEST_SYNC(20); 308 + GUEST_SYNC(TEST_TIMER_PAST); 361 309 362 310 /* Timer should have fired already */ 363 311 guest_wait_for_irq(); 364 312 365 - GUEST_SYNC(21); 313 + GUEST_SYNC(TEST_LOCKING_SEND_RACE); 366 314 /* Racing host ioctls */ 367 315 368 316 guest_wait_for_irq(); 369 317 370 - GUEST_SYNC(22); 318 + GUEST_SYNC(TEST_LOCKING_POLL_RACE); 371 319 /* Racing vmcall against host ioctl */ 372 320 373 321 ports[0] = 0; ··· 364 360 * timer IRQ is dropped due to an invalid event channel. 365 361 */ 366 362 for (i = 0; i < 100 && !guest_saw_irq; i++) 367 - asm volatile("vmcall" 368 - : "=a" (rax) 369 - : "a" (__HYPERVISOR_sched_op), 370 - "D" (SCHEDOP_poll), 371 - "S" (&p) 372 - : "memory"); 363 + __xen_hypercall(__HYPERVISOR_sched_op, SCHEDOP_poll, &p); 373 364 374 365 /* 375 366 * Re-send the timer IRQ if it was (likely) dropped due to the timer 376 367 * expiring while the event channel was invalid. 377 368 */ 378 369 if (!guest_saw_irq) { 379 - GUEST_SYNC(23); 370 + GUEST_SYNC(TEST_LOCKING_POLL_TIMEOUT); 380 371 goto wait_for_timer; 381 372 } 382 373 guest_saw_irq = false; 383 374 384 - GUEST_SYNC(24); 375 + GUEST_SYNC(TEST_DONE); 385 376 } 386 377 387 378 static int cmp_timespec(struct timespec *a, struct timespec *b) ··· 622 623 bool evtchn_irq_expected = false; 623 624 624 625 for (;;) { 625 - volatile struct kvm_run *run = vcpu->run; 626 626 struct ucall uc; 627 627 628 628 vcpu_run(vcpu); 629 - 630 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 631 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 632 - run->exit_reason, 633 - exit_reason_str(run->exit_reason)); 629 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 634 630 635 631 switch (get_ucall(vcpu, &uc)) { 636 632 case UCALL_ABORT: ··· 641 647 "runstate times don't add up"); 642 648 643 649 switch (uc.args[1]) { 644 - case 0: 650 + case TEST_INJECT_VECTOR: 645 651 if (verbose) 646 652 printf("Delivering evtchn upcall\n"); 647 653 evtchn_irq_expected = true; 648 654 vinfo->evtchn_upcall_pending = 1; 649 655 break; 650 656 651 - case RUNSTATE_runnable...RUNSTATE_offline: 657 + case TEST_RUNSTATE_runnable...TEST_RUNSTATE_offline: 652 658 TEST_ASSERT(!evtchn_irq_expected, "Event channel IRQ not seen"); 653 659 if (!do_runstate_tests) 654 660 goto done; 655 661 if (verbose) 656 662 printf("Testing runstate %s\n", runstate_names[uc.args[1]]); 657 663 rst.type = KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_CURRENT; 658 - rst.u.runstate.state = uc.args[1]; 664 + rst.u.runstate.state = uc.args[1] + RUNSTATE_runnable - 665 + TEST_RUNSTATE_runnable; 659 666 vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &rst); 660 667 break; 661 668 662 - case 4: 669 + case TEST_RUNSTATE_ADJUST: 663 670 if (verbose) 664 671 printf("Testing RUNSTATE_ADJUST\n"); 665 672 rst.type = KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST; ··· 675 680 vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &rst); 676 681 break; 677 682 678 - case 5: 683 + case TEST_RUNSTATE_DATA: 679 684 if (verbose) 680 685 printf("Testing RUNSTATE_DATA\n"); 681 686 rst.type = KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA; ··· 687 692 vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &rst); 688 693 break; 689 694 690 - case 6: 695 + case TEST_STEAL_TIME: 691 696 if (verbose) 692 697 printf("Testing steal time\n"); 693 698 /* Yield until scheduler delay exceeds target */ ··· 697 702 } while (get_run_delay() < rundelay); 698 703 break; 699 704 700 - case 7: 705 + case TEST_EVTCHN_MASKED: 701 706 if (!do_eventfd_tests) 702 707 goto done; 703 708 if (verbose) ··· 707 712 alarm(1); 708 713 break; 709 714 710 - case 8: 715 + case TEST_EVTCHN_UNMASKED: 711 716 if (verbose) 712 717 printf("Testing unmasked event channel\n"); 713 718 /* Unmask that, but deliver the other one */ ··· 718 723 alarm(1); 719 724 break; 720 725 721 - case 9: 726 + case TEST_EVTCHN_SLOWPATH: 722 727 TEST_ASSERT(!evtchn_irq_expected, 723 728 "Expected event channel IRQ but it didn't happen"); 724 729 shinfo->evtchn_pending[1] = 0; ··· 731 736 alarm(1); 732 737 break; 733 738 734 - case 10: 739 + case TEST_EVTCHN_SEND_IOCTL: 735 740 TEST_ASSERT(!evtchn_irq_expected, 736 741 "Expected event channel IRQ but it didn't happen"); 737 742 if (!do_evtchn_tests) ··· 751 756 alarm(1); 752 757 break; 753 758 754 - case 11: 759 + case TEST_EVTCHN_HCALL: 755 760 TEST_ASSERT(!evtchn_irq_expected, 756 761 "Expected event channel IRQ but it didn't happen"); 757 762 shinfo->evtchn_pending[1] = 0; ··· 762 767 alarm(1); 763 768 break; 764 769 765 - case 12: 770 + case TEST_EVTCHN_HCALL_SLOWPATH: 771 + TEST_ASSERT(!evtchn_irq_expected, 772 + "Expected event channel IRQ but it didn't happen"); 773 + shinfo->evtchn_pending[0] = 0; 774 + 775 + if (verbose) 776 + printf("Testing guest EVTCHNOP_send direct to evtchn after memslot change\n"); 777 + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 778 + DUMMY_REGION_GPA_2, DUMMY_REGION_SLOT_2, 1, 0); 779 + evtchn_irq_expected = true; 780 + alarm(1); 781 + break; 782 + 783 + case TEST_EVTCHN_HCALL_EVENTFD: 766 784 TEST_ASSERT(!evtchn_irq_expected, 767 785 "Expected event channel IRQ but it didn't happen"); 768 786 shinfo->evtchn_pending[0] = 0; ··· 786 778 alarm(1); 787 779 break; 788 780 789 - case 13: 781 + case TEST_TIMER_SETUP: 790 782 TEST_ASSERT(!evtchn_irq_expected, 791 783 "Expected event channel IRQ but it didn't happen"); 792 784 shinfo->evtchn_pending[1] = 0; ··· 795 787 printf("Testing guest oneshot timer\n"); 796 788 break; 797 789 798 - case 14: 790 + case TEST_TIMER_WAIT: 799 791 memset(&tmr, 0, sizeof(tmr)); 800 792 tmr.type = KVM_XEN_VCPU_ATTR_TYPE_TIMER; 801 793 vcpu_ioctl(vcpu, KVM_XEN_VCPU_GET_ATTR, &tmr); ··· 809 801 alarm(1); 810 802 break; 811 803 812 - case 15: 804 + case TEST_TIMER_RESTORE: 813 805 TEST_ASSERT(!evtchn_irq_expected, 814 806 "Expected event channel IRQ but it didn't happen"); 815 807 shinfo->evtchn_pending[0] = 0; ··· 823 815 alarm(1); 824 816 break; 825 817 826 - case 16: 818 + case TEST_POLL_READY: 827 819 TEST_ASSERT(!evtchn_irq_expected, 828 820 "Expected event channel IRQ but it didn't happen"); 829 821 ··· 833 825 alarm(1); 834 826 break; 835 827 836 - case 17: 828 + case TEST_POLL_TIMEOUT: 837 829 if (verbose) 838 830 printf("Testing SCHEDOP_poll timeout\n"); 839 831 shinfo->evtchn_pending[0] = 0; 840 832 alarm(1); 841 833 break; 842 834 843 - case 18: 835 + case TEST_POLL_MASKED: 844 836 if (verbose) 845 837 printf("Testing SCHEDOP_poll wake on masked event\n"); 846 838 ··· 849 841 alarm(1); 850 842 break; 851 843 852 - case 19: 844 + case TEST_POLL_WAKE: 853 845 shinfo->evtchn_pending[0] = shinfo->evtchn_mask[0] = 0; 854 846 if (verbose) 855 847 printf("Testing SCHEDOP_poll wake on unmasked event\n"); ··· 866 858 alarm(1); 867 859 break; 868 860 869 - case 20: 861 + case TEST_TIMER_PAST: 870 862 TEST_ASSERT(!evtchn_irq_expected, 871 863 "Expected event channel IRQ but it didn't happen"); 872 864 /* Read timer and check it is no longer pending */ ··· 883 875 alarm(1); 884 876 break; 885 877 886 - case 21: 878 + case TEST_LOCKING_SEND_RACE: 887 879 TEST_ASSERT(!evtchn_irq_expected, 888 880 "Expected event channel IRQ but it didn't happen"); 889 881 alarm(0); ··· 905 897 __vm_ioctl(vm, KVM_XEN_HVM_EVTCHN_SEND, &uxe); 906 898 break; 907 899 908 - case 22: 900 + case TEST_LOCKING_POLL_RACE: 909 901 TEST_ASSERT(!evtchn_irq_expected, 910 902 "Expected event channel IRQ but it didn't happen"); 911 903 ··· 920 912 vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &tmr); 921 913 break; 922 914 923 - case 23: 915 + case TEST_LOCKING_POLL_TIMEOUT: 924 916 /* 925 917 * Optional and possibly repeated sync point. 926 918 * Injecting the timer IRQ may fail if the ··· 942 934 SHINFO_RACE_TIMEOUT * 1000000000ULL; 943 935 vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &tmr); 944 936 break; 945 - case 24: 937 + case TEST_DONE: 946 938 TEST_ASSERT(!evtchn_irq_expected, 947 939 "Expected event channel IRQ but it didn't happen"); 948 940 ··· 953 945 TEST_ASSERT(ret == 0, "pthread_join() failed: %s", strerror(ret)); 954 946 goto done; 955 947 956 - case 0x20: 948 + case TEST_GUEST_SAW_IRQ: 957 949 TEST_ASSERT(evtchn_irq_expected, "Unexpected event channel IRQ"); 958 950 evtchn_irq_expected = false; 959 951 break;
+1 -4
tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c
··· 122 122 continue; 123 123 } 124 124 125 - TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, 126 - "Got exit_reason other than KVM_EXIT_IO: %u (%s)\n", 127 - run->exit_reason, 128 - exit_reason_str(run->exit_reason)); 125 + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); 129 126 130 127 switch (get_ucall(vcpu, &uc)) { 131 128 case UCALL_ABORT: