1 // SPDX-License-Identifier: GPL-2.0-only
3 * Test Hyper-V extended hypercall, HV_EXT_CALL_QUERY_CAPABILITIES (0x8001),
4 * exit to userspace and receive result in guest.
6 * Negative tests are present in hyperv_features.c
8 * Copyright 2022 Google LLC
9 * Author: Vipin Sharma <vipinsh@google.com>
12 #include "processor.h"
15 /* Any value is fine */
16 #define EXT_CAPABILITIES 0xbull
18 static void guest_code(vm_paddr_t in_pg_gpa
, vm_paddr_t out_pg_gpa
,
19 vm_vaddr_t out_pg_gva
)
23 wrmsr(HV_X64_MSR_GUEST_OS_ID
, HYPERV_LINUX_OS_ID
);
24 wrmsr(HV_X64_MSR_HYPERCALL
, in_pg_gpa
);
26 output_gva
= (uint64_t *)out_pg_gva
;
28 hyperv_hypercall(HV_EXT_CALL_QUERY_CAPABILITIES
, in_pg_gpa
, out_pg_gpa
);
30 /* TLFS states output will be a uint64_t value */
31 GUEST_ASSERT_EQ(*output_gva
, EXT_CAPABILITIES
);
38 vm_vaddr_t hcall_out_page
;
39 vm_vaddr_t hcall_in_page
;
40 struct kvm_vcpu
*vcpu
;
46 TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_CPUID
));
48 /* Verify if extended hypercalls are supported */
49 if (!kvm_cpuid_has(kvm_get_supported_hv_cpuid(),
50 HV_ENABLE_EXTENDED_HYPERCALLS
)) {
51 print_skip("Extended calls not supported by the kernel");
55 vm
= vm_create_with_one_vcpu(&vcpu
, guest_code
);
57 vcpu_set_hv_cpuid(vcpu
);
60 hcall_in_page
= vm_vaddr_alloc_pages(vm
, 1);
61 memset(addr_gva2hva(vm
, hcall_in_page
), 0x0, vm
->page_size
);
63 /* Hypercall output */
64 hcall_out_page
= vm_vaddr_alloc_pages(vm
, 1);
65 memset(addr_gva2hva(vm
, hcall_out_page
), 0x0, vm
->page_size
);
67 vcpu_args_set(vcpu
, 3, addr_gva2gpa(vm
, hcall_in_page
),
68 addr_gva2gpa(vm
, hcall_out_page
), hcall_out_page
);
72 TEST_ASSERT(run
->exit_reason
== KVM_EXIT_HYPERV
,
73 "Unexpected exit reason: %u (%s)",
74 run
->exit_reason
, exit_reason_str(run
->exit_reason
));
76 outval
= addr_gpa2hva(vm
, run
->hyperv
.u
.hcall
.params
[1]);
77 *outval
= EXT_CAPABILITIES
;
78 run
->hyperv
.u
.hcall
.result
= HV_STATUS_SUCCESS
;
82 TEST_ASSERT(run
->exit_reason
== KVM_EXIT_IO
,
83 "Unexpected exit reason: %u (%s)",
84 run
->exit_reason
, exit_reason_str(run
->exit_reason
));
86 switch (get_ucall(vcpu
, &uc
)) {
88 REPORT_GUEST_ASSERT(uc
);
93 TEST_FAIL("Unhandled ucall: %ld", uc
.cmd
);