KVM: x86: Add a VALID_MASK for the MSR exit reason flags
authorAaron Lewis <aaronlewis@google.com>
Wed, 21 Sep 2022 15:15:22 +0000 (15:15 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 9 Nov 2022 17:31:29 +0000 (12:31 -0500)
Add the mask KVM_MSR_EXIT_REASON_VALID_MASK for the MSR exit reason
flags.  This simplifies checks that validate these flags, and makes it
easier to introduce new flags in the future.

No functional change intended.

Signed-off-by: Aaron Lewis <aaronlewis@google.com>
Message-Id: <20220921151525.904162-3-aaronlewis@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c
include/uapi/linux/kvm.h

index cbec2e6..9ba8c1b 100644 (file)
@@ -6230,9 +6230,7 @@ split_irqchip_unlock:
                break;
        case KVM_CAP_X86_USER_SPACE_MSR:
                r = -EINVAL;
-               if (cap->args[0] & ~(KVM_MSR_EXIT_REASON_INVAL |
-                                    KVM_MSR_EXIT_REASON_UNKNOWN |
-                                    KVM_MSR_EXIT_REASON_FILTER))
+               if (cap->args[0] & ~KVM_MSR_EXIT_REASON_VALID_MASK)
                        break;
                kvm->arch.user_space_msr_mask = cap->args[0];
                r = 0;
index 0d5d441..7fea123 100644 (file)
@@ -485,6 +485,9 @@ struct kvm_run {
 #define KVM_MSR_EXIT_REASON_INVAL      (1 << 0)
 #define KVM_MSR_EXIT_REASON_UNKNOWN    (1 << 1)
 #define KVM_MSR_EXIT_REASON_FILTER     (1 << 2)
+#define KVM_MSR_EXIT_REASON_VALID_MASK (KVM_MSR_EXIT_REASON_INVAL   |  \
+                                        KVM_MSR_EXIT_REASON_UNKNOWN |  \
+                                        KVM_MSR_EXIT_REASON_FILTER)
                        __u32 reason; /* kernel -> user */
                        __u32 index; /* kernel -> user */
                        __u64 data; /* kernel <-> user */