Skip to content

Commit 2476b5a

Browse files
vittyvkbonzini
authored andcommitted
KVM: selftests: Test access to XMM fast hypercalls
Check that #UD is raised if bit 16 is clear in HYPERV_CPUID_FEATURES.EDX and an 'XMM fast' hypercall is issued. Signed-off-by: Vitaly Kuznetsov <[email protected]> Reviewed-by: Siddharth Chandrasekaran <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4e62aa9 commit 2476b5a

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

tools/testing/selftests/kvm/include/x86_64/hyperv.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
#define HV_X64_GUEST_DEBUGGING_AVAILABLE BIT(1)
118118
#define HV_X64_PERF_MONITOR_AVAILABLE BIT(2)
119119
#define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE BIT(3)
120-
#define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE BIT(4)
120+
#define HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE BIT(4)
121121
#define HV_X64_GUEST_IDLE_STATE_AVAILABLE BIT(5)
122122
#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8)
123123
#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10)
@@ -182,4 +182,7 @@
182182
#define HV_STATUS_INVALID_CONNECTION_ID 18
183183
#define HV_STATUS_INSUFFICIENT_BUFFERS 19
184184

185+
/* hypercall options */
186+
#define HV_HYPERCALL_FAST_BIT BIT(16)
187+
185188
#endif /* !SELFTEST_KVM_HYPERV_H */

tools/testing/selftests/kvm/x86_64/hyperv_features.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static void do_wrmsr(u32 idx, u64 val)
4747
}
4848

4949
static int nr_gp;
50+
static int nr_ud;
5051

5152
static inline u64 hypercall(u64 control, vm_vaddr_t input_address,
5253
vm_vaddr_t output_address)
@@ -80,6 +81,12 @@ static void guest_gp_handler(struct ex_regs *regs)
8081
regs->rip = (uint64_t)&wrmsr_end;
8182
}
8283

84+
static void guest_ud_handler(struct ex_regs *regs)
85+
{
86+
nr_ud++;
87+
regs->rip += 3;
88+
}
89+
8390
struct msr_data {
8491
uint32_t idx;
8592
bool available;
@@ -90,6 +97,7 @@ struct msr_data {
9097
struct hcall_data {
9198
uint64_t control;
9299
uint64_t expect;
100+
bool ud_expected;
93101
};
94102

95103
static void guest_msr(struct msr_data *msr)
@@ -117,13 +125,26 @@ static void guest_msr(struct msr_data *msr)
117125
static void guest_hcall(vm_vaddr_t pgs_gpa, struct hcall_data *hcall)
118126
{
119127
int i = 0;
128+
u64 res, input, output;
120129

121130
wrmsr(HV_X64_MSR_GUEST_OS_ID, LINUX_OS_ID);
122131
wrmsr(HV_X64_MSR_HYPERCALL, pgs_gpa);
123132

124133
while (hcall->control) {
125-
GUEST_ASSERT(hypercall(hcall->control, pgs_gpa,
126-
pgs_gpa + 4096) == hcall->expect);
134+
nr_ud = 0;
135+
if (!(hcall->control & HV_HYPERCALL_FAST_BIT)) {
136+
input = pgs_gpa;
137+
output = pgs_gpa + 4096;
138+
} else {
139+
input = output = 0;
140+
}
141+
142+
res = hypercall(hcall->control, input, output);
143+
if (hcall->ud_expected)
144+
GUEST_ASSERT(nr_ud == 1);
145+
else
146+
GUEST_ASSERT(res == hcall->expect);
147+
127148
GUEST_SYNC(i++);
128149
}
129150

@@ -552,8 +573,18 @@ static void guest_test_hcalls_access(struct kvm_vm *vm, struct hcall_data *hcall
552573
recomm.ebx = 0xfff;
553574
hcall->expect = HV_STATUS_SUCCESS;
554575
break;
555-
556576
case 17:
577+
/* XMM fast hypercall */
578+
hcall->control = HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE | HV_HYPERCALL_FAST_BIT;
579+
hcall->ud_expected = true;
580+
break;
581+
case 18:
582+
feat.edx |= HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE;
583+
hcall->ud_expected = false;
584+
hcall->expect = HV_STATUS_SUCCESS;
585+
break;
586+
587+
case 19:
557588
/* END */
558589
hcall->control = 0;
559590
break;
@@ -625,6 +656,10 @@ int main(void)
625656
/* Test hypercalls */
626657
vm = vm_create_default(VCPU_ID, 0, guest_hcall);
627658

659+
vm_init_descriptor_tables(vm);
660+
vcpu_init_descriptor_tables(vm, VCPU_ID);
661+
vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler);
662+
628663
/* Hypercall input/output */
629664
hcall_page = vm_vaddr_alloc_pages(vm, 2);
630665
memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize());

0 commit comments

Comments
 (0)