1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Hyper-V specific functions.
4  *
5  * Copyright (C) 2021, Red Hat Inc.
6  */
7 #include <stdint.h>
8 #include "processor.h"
9 #include "hyperv.h"
10 
vcpu_alloc_hyperv_test_pages(struct kvm_vm * vm,vm_vaddr_t * p_hv_pages_gva)11 struct hyperv_test_pages *vcpu_alloc_hyperv_test_pages(struct kvm_vm *vm,
12 						       vm_vaddr_t *p_hv_pages_gva)
13 {
14 	vm_vaddr_t hv_pages_gva = vm_vaddr_alloc_page(vm);
15 	struct hyperv_test_pages *hv = addr_gva2hva(vm, hv_pages_gva);
16 
17 	/* Setup of a region of guest memory for the VP Assist page. */
18 	hv->vp_assist = (void *)vm_vaddr_alloc_page(vm);
19 	hv->vp_assist_hva = addr_gva2hva(vm, (uintptr_t)hv->vp_assist);
20 	hv->vp_assist_gpa = addr_gva2gpa(vm, (uintptr_t)hv->vp_assist);
21 
22 	/* Setup of a region of guest memory for the partition assist page. */
23 	hv->partition_assist = (void *)vm_vaddr_alloc_page(vm);
24 	hv->partition_assist_hva = addr_gva2hva(vm, (uintptr_t)hv->partition_assist);
25 	hv->partition_assist_gpa = addr_gva2gpa(vm, (uintptr_t)hv->partition_assist);
26 
27 	/* Setup of a region of guest memory for the enlightened VMCS. */
28 	hv->enlightened_vmcs = (void *)vm_vaddr_alloc_page(vm);
29 	hv->enlightened_vmcs_hva = addr_gva2hva(vm, (uintptr_t)hv->enlightened_vmcs);
30 	hv->enlightened_vmcs_gpa = addr_gva2gpa(vm, (uintptr_t)hv->enlightened_vmcs);
31 
32 	*p_hv_pages_gva = hv_pages_gva;
33 	return hv;
34 }
35 
enable_vp_assist(uint64_t vp_assist_pa,void * vp_assist)36 int enable_vp_assist(uint64_t vp_assist_pa, void *vp_assist)
37 {
38 	uint64_t val = (vp_assist_pa & HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK) |
39 		HV_X64_MSR_VP_ASSIST_PAGE_ENABLE;
40 
41 	wrmsr(HV_X64_MSR_VP_ASSIST_PAGE, val);
42 
43 	current_vp_assist = vp_assist;
44 
45 	return 0;
46 }
47