]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/irq: Remove bitfields in posted interrupt descriptor
authorJacob Pan <jacob.jun.pan@linux.intel.com>
Tue, 23 Apr 2024 17:41:05 +0000 (10:41 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 29 Apr 2024 22:54:42 +0000 (00:54 +0200)
Mixture of bitfields and types is weird and really not intuitive, remove
bitfields and use typed data exclusively. Bitfields often result in
inferior machine code.

Suggested-by: Sean Christopherson <seanjc@google.com>
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240423174114.526704-4-jacob.jun.pan@linux.intel.com
Link: https://lore.kernel.org/all/20240404101735.402feec8@jacob-builder/T/#mf66e34a82a48f4d8e2926b5581eff59a122de53a
arch/x86/include/asm/posted_intr.h
arch/x86/kvm/vmx/posted_intr.c
arch/x86/kvm/vmx/vmx.c

index acf237b2882ebaffa9c9ea032faf1e8bbd9700ba..20e31891de15f7bd55c69ec4cdd4320aee71648c 100644 (file)
@@ -15,17 +15,9 @@ struct pi_desc {
        };
        union {
                struct {
-                               /* bit 256 - Outstanding Notification */
-                       u16     on      : 1,
-                               /* bit 257 - Suppress Notification */
-                               sn      : 1,
-                               /* bit 271:258 - Reserved */
-                               rsvd_1  : 14;
-                               /* bit 279:272 - Notification Vector */
+                       u16     notifications; /* Suppress and outstanding bits */
                        u8      nv;
-                               /* bit 287:280 - Reserved */
                        u8      rsvd_2;
-                               /* bit 319:288 - Notification Destination */
                        u32     ndst;
                };
                u64 control;
@@ -88,4 +80,15 @@ static inline bool pi_test_sn(struct pi_desc *pi_desc)
        return test_bit(POSTED_INTR_SN, (unsigned long *)&pi_desc->control);
 }
 
+/* Non-atomic helpers */
+static inline void __pi_set_sn(struct pi_desc *pi_desc)
+{
+       pi_desc->notifications |= BIT(POSTED_INTR_SN);
+}
+
+static inline void __pi_clear_sn(struct pi_desc *pi_desc)
+{
+       pi_desc->notifications &= ~BIT(POSTED_INTR_SN);
+}
+
 #endif /* _X86_POSTED_INTR_H */
index af662312fd07788ced21ec86a630280199de8e98..ec08fa3caf43ce465b562e756cf88eeba04c95b7 100644 (file)
@@ -107,7 +107,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
                 * handle task migration (@cpu != vcpu->cpu).
                 */
                new.ndst = dest;
-               new.sn = 0;
+               __pi_clear_sn(&new);
 
                /*
                 * Restore the notification vector; in the blocking case, the
@@ -157,7 +157,7 @@ static void pi_enable_wakeup_handler(struct kvm_vcpu *vcpu)
                      &per_cpu(wakeup_vcpus_on_cpu, vcpu->cpu));
        raw_spin_unlock(&per_cpu(wakeup_vcpus_on_cpu_lock, vcpu->cpu));
 
-       WARN(pi_desc->sn, "PI descriptor SN field set before blocking");
+       WARN(pi_test_sn(pi_desc), "PI descriptor SN field set before blocking");
 
        old.control = READ_ONCE(pi_desc->control);
        do {
index 273d26492e41d6af939165baa7072aa361bf2498..becefaf95cabd1c5372c1cd4cf84913402d1db81 100644 (file)
@@ -4845,7 +4845,7 @@ static void __vmx_vcpu_reset(struct kvm_vcpu *vcpu)
         * or POSTED_INTR_WAKEUP_VECTOR.
         */
        vmx->pi_desc.nv = POSTED_INTR_VECTOR;
-       vmx->pi_desc.sn = 1;
+       __pi_set_sn(&vmx->pi_desc);
 }
 
 static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)