Skip to content

Commit 2254808

Browse files
Jacob PanKAGA-KOKO
authored andcommitted
x86/irq: Remove bitfields in posted interrupt descriptor
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 <[email protected]> Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Jacob Pan <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/all/20240404101735.402feec8@jacob-builder/T/#mf66e34a82a48f4d8e2926b5581eff59a122de53a
1 parent 4ec8fd0 commit 2254808

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

arch/x86/include/asm/posted_intr.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,9 @@ struct pi_desc {
1515
};
1616
union {
1717
struct {
18-
/* bit 256 - Outstanding Notification */
19-
u16 on : 1,
20-
/* bit 257 - Suppress Notification */
21-
sn : 1,
22-
/* bit 271:258 - Reserved */
23-
rsvd_1 : 14;
24-
/* bit 279:272 - Notification Vector */
18+
u16 notifications; /* Suppress and outstanding bits */
2519
u8 nv;
26-
/* bit 287:280 - Reserved */
2720
u8 rsvd_2;
28-
/* bit 319:288 - Notification Destination */
2921
u32 ndst;
3022
};
3123
u64 control;
@@ -88,4 +80,15 @@ static inline bool pi_test_sn(struct pi_desc *pi_desc)
8880
return test_bit(POSTED_INTR_SN, (unsigned long *)&pi_desc->control);
8981
}
9082

83+
/* Non-atomic helpers */
84+
static inline void __pi_set_sn(struct pi_desc *pi_desc)
85+
{
86+
pi_desc->notifications |= BIT(POSTED_INTR_SN);
87+
}
88+
89+
static inline void __pi_clear_sn(struct pi_desc *pi_desc)
90+
{
91+
pi_desc->notifications &= ~BIT(POSTED_INTR_SN);
92+
}
93+
9194
#endif /* _X86_POSTED_INTR_H */

arch/x86/kvm/vmx/posted_intr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
107107
* handle task migration (@cpu != vcpu->cpu).
108108
*/
109109
new.ndst = dest;
110-
new.sn = 0;
110+
__pi_clear_sn(&new);
111111

112112
/*
113113
* Restore the notification vector; in the blocking case, the
@@ -157,7 +157,7 @@ static void pi_enable_wakeup_handler(struct kvm_vcpu *vcpu)
157157
&per_cpu(wakeup_vcpus_on_cpu, vcpu->cpu));
158158
raw_spin_unlock(&per_cpu(wakeup_vcpus_on_cpu_lock, vcpu->cpu));
159159

160-
WARN(pi_desc->sn, "PI descriptor SN field set before blocking");
160+
WARN(pi_test_sn(pi_desc), "PI descriptor SN field set before blocking");
161161

162162
old.control = READ_ONCE(pi_desc->control);
163163
do {

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4845,7 +4845,7 @@ static void __vmx_vcpu_reset(struct kvm_vcpu *vcpu)
48454845
* or POSTED_INTR_WAKEUP_VECTOR.
48464846
*/
48474847
vmx->pi_desc.nv = POSTED_INTR_VECTOR;
4848-
vmx->pi_desc.sn = 1;
4848+
__pi_set_sn(&vmx->pi_desc);
48494849
}
48504850

48514851
static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)

0 commit comments

Comments
 (0)