Skip to content

Commit 0a505fe

Browse files
committed
kvm: selftests: ensure vcpu file is released
The selftests were not munmap-ing the kvm_run area from the vcpu file descriptor. The result was that kvm_vcpu_release was not called and a reference was left in the parent "struct kvm". Ultimately this was visible in the upcoming state save/restore test as an error when KVM attempted to create a duplicate debugfs entry. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 87ccb7d commit 0a505fe

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tools/testing/selftests/kvm/lib/kvm_util.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ struct vcpu *vcpu_find(struct kvm_vm *vm,
238238
static void vm_vcpu_rm(struct kvm_vm *vm, uint32_t vcpuid)
239239
{
240240
struct vcpu *vcpu = vcpu_find(vm, vcpuid);
241+
int ret;
241242

242-
int ret = close(vcpu->fd);
243+
ret = munmap(vcpu->state, sizeof(*vcpu->state));
244+
TEST_ASSERT(ret == 0, "munmap of VCPU fd failed, rc: %i "
245+
"errno: %i", ret, errno);
246+
close(vcpu->fd);
243247
TEST_ASSERT(ret == 0, "Close of VCPU fd failed, rc: %i "
244248
"errno: %i", ret, errno);
245249

@@ -295,6 +299,10 @@ void kvm_vm_free(struct kvm_vm *vmp)
295299
TEST_ASSERT(ret == 0, "Close of vm fd failed,\n"
296300
" vmp->fd: %i rc: %i errno: %i", vmp->fd, ret, errno);
297301

302+
close(vmp->kvm_fd);
303+
TEST_ASSERT(ret == 0, "Close of /dev/kvm fd failed,\n"
304+
" vmp->kvm_fd: %i rc: %i errno: %i", vmp->kvm_fd, ret, errno);
305+
298306
/* Free the structure describing the VM. */
299307
free(vmp);
300308
}

0 commit comments

Comments
 (0)