]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests: kvm: check dynamic bits against KVM_X86_XCOMP_GUEST_SUPP
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 26 Jan 2022 12:51:00 +0000 (07:51 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 28 Jan 2022 12:38:25 +0000 (07:38 -0500)
Provide coverage for the new API.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/arch/x86/include/uapi/asm/kvm.h
tools/include/uapi/linux/kvm.h
tools/testing/selftests/kvm/lib/x86_64/processor.c

index 2da3316bb55959dad6b400e70b06628c4de0201b..bf6e96011dfed4e2e8582e511c08b5b6cbd723b6 100644 (file)
@@ -452,6 +452,9 @@ struct kvm_sync_regs {
 
 #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE        0x00000001
 
+/* attributes for system fd (group 0) */
+#define KVM_X86_XCOMP_GUEST_SUPP       0
+
 struct kvm_vmx_nested_state_data {
        __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
        __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
index 9563d294f181974a1032ae5588f754af1b9c6f53..b46bcdb0cab1a3695f552434d34aff3f70b4c700 100644 (file)
@@ -1133,6 +1133,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM 206
 #define KVM_CAP_VM_GPA_BITS 207
 #define KVM_CAP_XSAVE2 208
+#define KVM_CAP_SYS_ATTRIBUTES 209
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
index c1d1c195a8380ad8a22094e529c209bc1936c4b9..9f000dfb55949d04f547caa4ef4d13b44bd60d4c 100644 (file)
@@ -667,8 +667,23 @@ static bool is_xfd_supported(void)
 
 void vm_xsave_req_perm(int bit)
 {
+       int kvm_fd;
        u64 bitmask;
        long rc;
+       struct kvm_device_attr attr = {
+               .group = 0,
+               .attr = KVM_X86_XCOMP_GUEST_SUPP,
+               .addr = (unsigned long) &bitmask
+       };
+
+       kvm_fd = open_kvm_dev_path_or_exit();
+       rc = ioctl(kvm_fd, KVM_GET_DEVICE_ATTR, &attr);
+       close(kvm_fd);
+       if (rc == -1 && (errno == ENXIO || errno == EINVAL))
+               exit(KSFT_SKIP);
+       TEST_ASSERT(rc == 0, "KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP) error: %ld", rc);
+       if (!(bitmask & (1ULL << bit)))
+               exit(KSFT_SKIP);
 
        if (!is_xfd_supported())
                exit(KSFT_SKIP);