Skip to content

Commit 65f1f57

Browse files
sean-jcbonzini
authored andcommitted
KVM: selftests: Verify stats fd can be dup()'d and read
Expand the binary stats test to verify that a stats fd can be dup()'d and read, to (very) roughly simulate userspace passing around the file. Adding the dup() test is primarily an intermediate step towards verifying that userspace can read VM/vCPU stats before _and_ after userspace closes its copy of the VM fd; the dup() test itself is only mildly interesting. Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20230711230131.648752-7-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 47d1be8 commit 65f1f57

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tools/testing/selftests/kvm/kvm_binary_stats_test.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,23 @@ int main(int argc, char *argv[])
232232
}
233233

234234
/*
235-
* Check stats read for every VM and vCPU, with a variety of testcases.
235+
* Check stats read for every VM and vCPU, with a variety of flavors.
236236
* Note, stats_test() closes the passed in stats fd.
237237
*/
238238
for (i = 0; i < max_vm; ++i) {
239+
/*
240+
* Verify that creating multiple userspace references to a
241+
* single stats file works and doesn't cause explosions.
242+
*/
239243
vm_stats_fds = vm_get_stats_fd(vms[i]);
244+
stats_test(dup(vm_stats_fds));
240245

241246
/* Verify userspace can instantiate multiple stats files. */
242247
stats_test(vm_get_stats_fd(vms[i]));
243248

244249
for (j = 0; j < max_vcpu; ++j) {
245250
vcpu_stats_fds[j] = vcpu_get_stats_fd(vcpus[i * max_vcpu + j]);
251+
stats_test(dup(vcpu_stats_fds[j]));
246252
stats_test(vcpu_get_stats_fd(vcpus[i * max_vcpu + j]));
247253
}
248254

0 commit comments

Comments
 (0)