Skip to content

Commit 43650dc

Browse files
Jacob PanKAGA-KOKO
authored andcommitted
x86/irq: Set up per host CPU posted interrupt descriptors
To support posted MSIs, create a posted interrupt descriptor (PID) for each host CPU. Later on, when setting up interrupt affinity, the IOMMU's interrupt remapping table entry (IRTE) will point to the physical address of the matching CPU's PID. Each PID is initialized with the owner CPU's physical APICID as the destination. Originally-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-7-jacob.jun.pan@linux.intel.com
1 parent f5a3562 commit 43650dc

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

arch/x86/include/asm/hardirq.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ typedef struct {
4848

4949
DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
5050

51+
#ifdef CONFIG_X86_POSTED_MSI
52+
DECLARE_PER_CPU_ALIGNED(struct pi_desc, posted_msi_pi_desc);
53+
#endif
5154
#define __ARCH_IRQ_STAT
5255

5356
#define inc_irq_stat(member) this_cpu_inc(irq_stat.member)

arch/x86/include/asm/posted_intr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,10 @@ static inline void __pi_clear_sn(struct pi_desc *pi_desc)
9191
pi_desc->notifications &= ~BIT(POSTED_INTR_SN);
9292
}
9393

94+
#ifdef CONFIG_X86_POSTED_MSI
95+
extern void intel_posted_msi_init(void);
96+
#else
97+
static inline void intel_posted_msi_init(void) {};
98+
#endif /* X86_POSTED_MSI */
99+
94100
#endif /* _X86_POSTED_INTR_H */

arch/x86/kernel/cpu/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include <asm/traps.h>
6969
#include <asm/sev.h>
7070
#include <asm/tdx.h>
71+
#include <asm/posted_intr.h>
7172

7273
#include "cpu.h"
7374

@@ -2227,6 +2228,8 @@ void cpu_init(void)
22272228
barrier();
22282229

22292230
x2apic_setup();
2231+
2232+
intel_posted_msi_init();
22302233
}
22312234

22322235
mmgrab(&init_mm);

arch/x86/kernel/irq.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <asm/desc.h>
2323
#include <asm/traps.h>
2424
#include <asm/thermal.h>
25+
#include <asm/posted_intr.h>
26+
#include <asm/irq_remapping.h>
2527

2628
#define CREATE_TRACE_POINTS
2729
#include <asm/trace/irq_vectors.h>
@@ -334,6 +336,27 @@ DEFINE_IDTENTRY_SYSVEC_SIMPLE(sysvec_kvm_posted_intr_nested_ipi)
334336
}
335337
#endif
336338

339+
#ifdef CONFIG_X86_POSTED_MSI
340+
341+
/* Posted Interrupt Descriptors for coalesced MSIs to be posted */
342+
DEFINE_PER_CPU_ALIGNED(struct pi_desc, posted_msi_pi_desc);
343+
344+
void intel_posted_msi_init(void)
345+
{
346+
u32 destination;
347+
u32 apic_id;
348+
349+
this_cpu_write(posted_msi_pi_desc.nv, POSTED_MSI_NOTIFICATION_VECTOR);
350+
351+
/*
352+
* APIC destination ID is stored in bit 8:15 while in XAPIC mode.
353+
* VT-d spec. CH 9.11
354+
*/
355+
apic_id = this_cpu_read(x86_cpu_to_apicid);
356+
destination = x2apic_enabled() ? apic_id : apic_id << 8;
357+
this_cpu_write(posted_msi_pi_desc.ndst, destination);
358+
}
359+
#endif /* X86_POSTED_MSI */
337360

338361
#ifdef CONFIG_HOTPLUG_CPU
339362
/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */

0 commit comments

Comments
 (0)