Skip to content

Commit 407369e

Browse files
committed
KVM: pVMX: Implement vcpu_free operation
Enable the pKVM VMX host to release a vCPU using the vcpu_free PV interface. The physical addresses and sizes of the allocated memory pages when creating a vCPU are returned via pkvm_memcache. They are freed along with VMX specific resources such as VMCS page and MSR bitmap. Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
1 parent 25c9c7b commit 407369e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

arch/x86/kvm/vmx/pkvm_host.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,25 @@ static int pkvm_vcpu_create(struct kvm_vcpu *vcpu)
162162
return ret;
163163
}
164164

165+
static void pkvm_vcpu_free(struct kvm_vcpu *vcpu)
166+
{
167+
int vm_handle = vcpu->kvm->arch.pkvm.handle;
168+
int vcpu_handle = vcpu->arch.pkvm.handle;
169+
struct vcpu_vmx *vmx = to_vmx(vcpu);
170+
union pkvm_hc_data out;
171+
int ret;
172+
173+
ret = pkvm_hypercall_out(vcpu_free, &out, vm_handle, vcpu_handle);
174+
if (ret) {
175+
pr_err("failed to free VM%d vcpu%d: %d\n", vm_handle, vcpu_handle, ret);
176+
return;
177+
}
178+
179+
kvm_free_pkvm_memcache(&out.vcpu_free.memcache);
180+
181+
pkvm_free_loaded_vmcs(vmx->loaded_vmcs);
182+
}
183+
165184
struct kvm_x86_ops pkvm_host_vt_x86_ops __initdata = {
166185
.name = KBUILD_MODNAME,
167186

@@ -177,4 +196,5 @@ struct kvm_x86_ops pkvm_host_vt_x86_ops __initdata = {
177196

178197
.vcpu_precreate = vmx_vcpu_precreate,
179198
.vcpu_create = pkvm_vcpu_create,
199+
.vcpu_free = pkvm_vcpu_free,
180200
};

0 commit comments

Comments
 (0)