blob: 766ffe3ba313711fef22b21bee349d2db360fb46 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Thomas Gleixner6b39ba72008-10-16 11:32:24 +02002/*
3 * Common interrupt code for 32 and 64 bit
4 */
5#include <linux/cpu.h>
6#include <linux/interrupt.h>
7#include <linux/kernel_stat.h>
Andres Salomon4722d192010-11-12 05:45:26 +00008#include <linux/of.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +02009#include <linux/seq_file.h>
Jaswinder Singh Rajput6a02e712009-01-04 16:22:17 +053010#include <linux/smp.h>
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -080011#include <linux/ftrace.h>
Jean Delvareca4445642011-03-25 15:20:14 +010012#include <linux/delay.h>
Paul Gortmaker69c60c82011-05-26 12:22:53 -040013#include <linux/export.h>
Nicolai Stange447ae312018-07-29 12:15:33 +020014#include <linux/irq.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020015
Thomas Gleixner7c2a5732020-05-21 22:05:35 +020016#include <asm/irq_stack.h>
Ingo Molnar7b6aa332009-02-17 13:58:15 +010017#include <asm/apic.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020018#include <asm/io_apic.h>
Ingo Molnarc3d80002008-12-23 15:15:17 +010019#include <asm/irq.h>
Andi Kleen01ca79f2009-05-27 21:56:52 +020020#include <asm/mce.h>
Jaswinder Singh Rajput2c1b2842009-04-11 00:03:10 +053021#include <asm/hw_irq.h>
Yinghai Luac2a5532014-05-13 11:39:34 -040022#include <asm/desc.h>
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +020023#include <asm/traps.h>
Borislav Petkov9223d0d2021-01-07 13:29:05 +010024#include <asm/thermal.h>
Steven Rostedt (Red Hat)83ab8512013-06-21 10:29:05 -040025
26#define CREATE_TRACE_POINTS
Seiji Aguchicf910e82013-06-20 11:46:53 -040027#include <asm/trace/irq_vectors.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020028
Brian Gerstc5bde902015-05-09 11:36:50 -040029DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
30EXPORT_PER_CPU_SYMBOL(irq_stat);
31
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020032atomic_t irq_err_count;
33
Thomas Gleixner249f6d92008-10-16 12:18:50 +020034/*
35 * 'what should we do if we get a hw irq event on an illegal vector'.
36 * each architecture has to answer this themselves.
37 */
38void ack_bad_irq(unsigned int irq)
39{
Cyrill Gorcunovedea7142009-04-12 20:47:39 +040040 if (printk_ratelimit())
41 pr_err("unexpected IRQ trap at vector %02x\n", irq);
Thomas Gleixner249f6d92008-10-16 12:18:50 +020042
Thomas Gleixner249f6d92008-10-16 12:18:50 +020043 /*
44 * Currently unexpected vectors happen only on SMP and APIC.
45 * We _must_ ack these because every local APIC has only N
46 * irq slots per priority level, and a 'hanging, unacked' IRQ
47 * holds up an irq slot - in excessive cases (when multiple
48 * unexpected vectors occur) that might lock up the APIC
49 * completely.
50 * But only ack when the APIC is enabled -AK
51 */
Cyrill Gorcunov08306ce2009-04-12 20:47:41 +040052 ack_APIC_irq();
Thomas Gleixner249f6d92008-10-16 12:18:50 +020053}
54
Brian Gerst1b437c82009-01-19 00:38:57 +090055#define irq_stats(x) (&per_cpu(irq_stat, x))
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020056/*
Thomas Gleixner517e4982010-12-16 17:59:57 +010057 * /proc/interrupts printing for arch specific interrupts
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020058 */
Thomas Gleixner517e4982010-12-16 17:59:57 +010059int arch_show_interrupts(struct seq_file *p, int prec)
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020060{
61 int j;
62
Jan Beulich7a81d9a2009-03-12 12:45:15 +000063 seq_printf(p, "%*s: ", prec, "NMI");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020064 for_each_online_cpu(j)
65 seq_printf(p, "%10u ", irq_stats(j)->__nmi_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +010066 seq_puts(p, " Non-maskable interrupts\n");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020067#ifdef CONFIG_X86_LOCAL_APIC
Jan Beulich7a81d9a2009-03-12 12:45:15 +000068 seq_printf(p, "%*s: ", prec, "LOC");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020069 for_each_online_cpu(j)
70 seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs);
Rasmus Villemoes37367082014-11-28 22:03:41 +010071 seq_puts(p, " Local timer interrupts\n");
Jaswinder Singh Rajput474e56b2009-03-23 02:08:34 +053072
73 seq_printf(p, "%*s: ", prec, "SPU");
74 for_each_online_cpu(j)
75 seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +010076 seq_puts(p, " Spurious interrupts\n");
Li Hong89ccf462009-10-14 18:50:39 +080077 seq_printf(p, "%*s: ", prec, "PMI");
Ingo Molnar241771e2008-12-03 10:39:53 +010078 for_each_online_cpu(j)
79 seq_printf(p, "%10u ", irq_stats(j)->apic_perf_irqs);
Rasmus Villemoes37367082014-11-28 22:03:41 +010080 seq_puts(p, " Performance monitoring interrupts\n");
Peter Zijlstrae360adb2010-10-14 14:01:34 +080081 seq_printf(p, "%*s: ", prec, "IWI");
Peter Zijlstrab6276f32009-04-06 11:45:03 +020082 for_each_online_cpu(j)
Peter Zijlstrae360adb2010-10-14 14:01:34 +080083 seq_printf(p, "%10u ", irq_stats(j)->apic_irq_work_irqs);
Rasmus Villemoes37367082014-11-28 22:03:41 +010084 seq_puts(p, " IRQ work interrupts\n");
Fernando Luis Vázquez Cao346b46b2011-12-13 11:51:53 +090085 seq_printf(p, "%*s: ", prec, "RTR");
86 for_each_online_cpu(j)
Fernando Luis Vazquez Caob49d7d82011-12-15 11:32:24 +090087 seq_printf(p, "%10u ", irq_stats(j)->icr_read_retry_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +010088 seq_puts(p, " APIC ICR read retries\n");
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -050089 if (x86_platform_ipi_callback) {
Hidetoshi Seto59d13812009-03-25 10:50:34 +090090 seq_printf(p, "%*s: ", prec, "PLT");
Dimitri Sivanichacaabe72009-03-04 12:56:05 -060091 for_each_online_cpu(j)
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -050092 seq_printf(p, "%10u ", irq_stats(j)->x86_platform_ipis);
Rasmus Villemoes37367082014-11-28 22:03:41 +010093 seq_puts(p, " Platform interrupts\n");
Dimitri Sivanichacaabe72009-03-04 12:56:05 -060094 }
Thomas Gleixner0428e01a2017-08-28 08:47:34 +020095#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020096#ifdef CONFIG_SMP
Jan Beulich7a81d9a2009-03-12 12:45:15 +000097 seq_printf(p, "%*s: ", prec, "RES");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020098 for_each_online_cpu(j)
99 seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100100 seq_puts(p, " Rescheduling interrupts\n");
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000101 seq_printf(p, "%*s: ", prec, "CAL");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200102 for_each_online_cpu(j)
Aaron Lu82ba4fa2016-08-11 15:44:30 +0800103 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100104 seq_puts(p, " Function call interrupts\n");
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000105 seq_printf(p, "%*s: ", prec, "TLB");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200106 for_each_online_cpu(j)
107 seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100108 seq_puts(p, " TLB shootdowns\n");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200109#endif
Jan Beulich0444c9b2009-11-20 14:03:05 +0000110#ifdef CONFIG_X86_THERMAL_VECTOR
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000111 seq_printf(p, "%*s: ", prec, "TRM");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200112 for_each_online_cpu(j)
113 seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100114 seq_puts(p, " Thermal event interrupts\n");
Jan Beulich0444c9b2009-11-20 14:03:05 +0000115#endif
116#ifdef CONFIG_X86_MCE_THRESHOLD
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000117 seq_printf(p, "%*s: ", prec, "THR");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200118 for_each_online_cpu(j)
119 seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100120 seq_puts(p, " Threshold APIC interrupts\n");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200121#endif
Aravind Gopalakrishnan24fd78a2015-05-06 06:58:56 -0500122#ifdef CONFIG_X86_MCE_AMD
123 seq_printf(p, "%*s: ", prec, "DFR");
124 for_each_online_cpu(j)
125 seq_printf(p, "%10u ", irq_stats(j)->irq_deferred_error_count);
126 seq_puts(p, " Deferred Error APIC interrupts\n");
127#endif
Andi Kleenc1ebf832009-07-09 00:31:41 +0200128#ifdef CONFIG_X86_MCE
Andi Kleen01ca79f2009-05-27 21:56:52 +0200129 seq_printf(p, "%*s: ", prec, "MCE");
130 for_each_online_cpu(j)
131 seq_printf(p, "%10u ", per_cpu(mce_exception_count, j));
Rasmus Villemoes37367082014-11-28 22:03:41 +0100132 seq_puts(p, " Machine check exceptions\n");
Andi Kleenca84f692009-05-27 21:56:57 +0200133 seq_printf(p, "%*s: ", prec, "MCP");
134 for_each_online_cpu(j)
135 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
Rasmus Villemoes37367082014-11-28 22:03:41 +0100136 seq_puts(p, " Machine check polls\n");
Andi Kleen01ca79f2009-05-27 21:56:52 +0200137#endif
Zhao Yakuiecca25022019-04-30 11:45:23 +0800138#ifdef CONFIG_X86_HV_CALLBACK_VECTOR
Thomas Gleixner7854f822017-09-13 23:29:26 +0200139 if (test_bit(HYPERVISOR_CALLBACK_VECTOR, system_vectors)) {
Vitaly Kuznetsov9d87cd62015-07-07 18:26:13 +0200140 seq_printf(p, "%*s: ", prec, "HYP");
141 for_each_online_cpu(j)
142 seq_printf(p, "%10u ",
143 irq_stats(j)->irq_hv_callback_count);
144 seq_puts(p, " Hypervisor callback interrupts\n");
145 }
Thomas Gleixner929320e2014-02-23 21:40:20 +0000146#endif
Vitaly Kuznetsov51d4e5d2018-01-24 14:23:35 +0100147#if IS_ENABLED(CONFIG_HYPERV)
148 if (test_bit(HYPERV_REENLIGHTENMENT_VECTOR, system_vectors)) {
149 seq_printf(p, "%*s: ", prec, "HRE");
150 for_each_online_cpu(j)
151 seq_printf(p, "%10u ",
152 irq_stats(j)->irq_hv_reenlightenment_count);
153 seq_puts(p, " Hyper-V reenlightenment interrupts\n");
154 }
Michael Kelley248e7422018-03-04 22:17:18 -0700155 if (test_bit(HYPERV_STIMER0_VECTOR, system_vectors)) {
156 seq_printf(p, "%*s: ", prec, "HVS");
157 for_each_online_cpu(j)
158 seq_printf(p, "%10u ",
159 irq_stats(j)->hyperv_stimer0_count);
160 seq_puts(p, " Hyper-V stimer0 interrupts\n");
161 }
Vitaly Kuznetsov51d4e5d2018-01-24 14:23:35 +0100162#endif
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000163 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200164#if defined(CONFIG_X86_IO_APIC)
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000165 seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200166#endif
Feng Wu501b3262015-05-19 17:07:17 +0800167#ifdef CONFIG_HAVE_KVM
168 seq_printf(p, "%*s: ", prec, "PIN");
169 for_each_online_cpu(j)
170 seq_printf(p, "%10u ", irq_stats(j)->kvm_posted_intr_ipis);
171 seq_puts(p, " Posted-interrupt notification event\n");
172
Wincy Van210f84b2017-04-28 13:13:58 +0800173 seq_printf(p, "%*s: ", prec, "NPI");
174 for_each_online_cpu(j)
175 seq_printf(p, "%10u ",
176 irq_stats(j)->kvm_posted_intr_nested_ipis);
177 seq_puts(p, " Nested posted-interrupt event\n");
178
Feng Wu501b3262015-05-19 17:07:17 +0800179 seq_printf(p, "%*s: ", prec, "PIW");
180 for_each_online_cpu(j)
181 seq_printf(p, "%10u ",
182 irq_stats(j)->kvm_posted_intr_wakeup_ipis);
183 seq_puts(p, " Posted-interrupt wakeup event\n");
184#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200185 return 0;
186}
187
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200188/*
189 * /proc/stat helpers
190 */
191u64 arch_irq_stat_cpu(unsigned int cpu)
192{
193 u64 sum = irq_stats(cpu)->__nmi_count;
194
195#ifdef CONFIG_X86_LOCAL_APIC
196 sum += irq_stats(cpu)->apic_timer_irqs;
Jaswinder Singh Rajput474e56b2009-03-23 02:08:34 +0530197 sum += irq_stats(cpu)->irq_spurious_count;
Ingo Molnar241771e2008-12-03 10:39:53 +0100198 sum += irq_stats(cpu)->apic_perf_irqs;
Peter Zijlstrae360adb2010-10-14 14:01:34 +0800199 sum += irq_stats(cpu)->apic_irq_work_irqs;
Fernando Luis Vazquez Caob49d7d82011-12-15 11:32:24 +0900200 sum += irq_stats(cpu)->icr_read_retry_count;
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -0500201 if (x86_platform_ipi_callback)
202 sum += irq_stats(cpu)->x86_platform_ipis;
Thomas Gleixner0428e01a2017-08-28 08:47:34 +0200203#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200204#ifdef CONFIG_SMP
205 sum += irq_stats(cpu)->irq_resched_count;
206 sum += irq_stats(cpu)->irq_call_count;
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200207#endif
Jan Beulich0444c9b2009-11-20 14:03:05 +0000208#ifdef CONFIG_X86_THERMAL_VECTOR
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200209 sum += irq_stats(cpu)->irq_thermal_count;
Jan Beulich0444c9b2009-11-20 14:03:05 +0000210#endif
211#ifdef CONFIG_X86_MCE_THRESHOLD
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200212 sum += irq_stats(cpu)->irq_threshold_count;
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200213#endif
Andi Kleenc1ebf832009-07-09 00:31:41 +0200214#ifdef CONFIG_X86_MCE
Hidetoshi Seto8051dbd2009-06-02 16:53:23 +0900215 sum += per_cpu(mce_exception_count, cpu);
216 sum += per_cpu(mce_poll_count, cpu);
217#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200218 return sum;
219}
220
221u64 arch_irq_stat(void)
222{
223 u64 sum = atomic_read(&irq_err_count);
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200224 return sum;
225}
Ingo Molnarc3d80002008-12-23 15:15:17 +0100226
Thomas Gleixner7c2a5732020-05-21 22:05:35 +0200227static __always_inline void handle_irq(struct irq_desc *desc,
228 struct pt_regs *regs)
229{
230 if (IS_ENABLED(CONFIG_X86_64))
Thomas Gleixner5b51e1d2021-02-10 00:40:48 +0100231 generic_handle_irq_desc(desc);
Thomas Gleixner7c2a5732020-05-21 22:05:35 +0200232 else
233 __handle_irq(desc, regs);
234}
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800235
236/*
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200237 * common_interrupt() handles all normal device IRQ's (the special SMP
238 * cross-CPU interrupts have their own entry points).
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800239 */
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200240DEFINE_IDTENTRY_IRQ(common_interrupt)
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800241{
242 struct pt_regs *old_regs = set_irq_regs(regs);
Thomas Gleixner633260f2020-05-21 22:05:34 +0200243 struct irq_desc *desc;
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800244
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200245 /* entry code tells RCU that we're not quiescent. Check it. */
Linus Torvalds57780772015-09-01 08:40:25 -0700246 RCU_LOCKDEP_WARN(!rcu_is_watching(), "IRQ failed to wake up RCU");
Andy Lutomirski0333a202015-07-03 12:44:34 -0700247
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000248 desc = __this_cpu_read(vector_irq[vector]);
Heiner Kallweitd6f83422019-08-19 21:36:09 +0200249 if (likely(!IS_ERR_OR_NULL(desc))) {
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200250 handle_irq(desc, regs);
Heiner Kallweitd6f83422019-08-19 21:36:09 +0200251 } else {
Cyrill Gorcunov08306ce2009-04-12 20:47:41 +0400252 ack_APIC_irq();
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800253
Heiner Kallweit8725fcd2019-08-19 21:36:39 +0200254 if (desc == VECTOR_UNUSED) {
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200255 pr_emerg_ratelimited("%s: %d.%u No irq handler for vector\n",
Prarit Bhargava93450052014-01-05 11:10:52 -0500256 __func__, smp_processor_id(),
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000257 vector);
Prarit Bhargava93450052014-01-05 11:10:52 -0500258 } else {
Thomas Gleixner7276c6a2015-08-02 20:38:25 +0000259 __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
Prarit Bhargava93450052014-01-05 11:10:52 -0500260 }
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800261 }
262
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800263 set_irq_regs(old_regs);
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800264}
265
Thomas Gleixner0428e01a2017-08-28 08:47:34 +0200266#ifdef CONFIG_X86_LOCAL_APIC
267/* Function pointer for generic interrupt vector handling */
268void (*x86_platform_ipi_callback)(void) = NULL;
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600269/*
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -0500270 * Handler for X86_PLATFORM_IPI_VECTOR.
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600271 */
Thomas Gleixnerdb0338e2020-05-21 22:05:39 +0200272DEFINE_IDTENTRY_SYSVEC(sysvec_x86_platform_ipi)
Seiji Aguchieddc0e92013-06-20 11:45:17 -0400273{
274 struct pt_regs *old_regs = set_irq_regs(regs);
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600275
Thomas Gleixnerdb0338e2020-05-21 22:05:39 +0200276 ack_APIC_irq();
Thomas Gleixner8a171162017-08-28 08:47:25 +0200277 trace_x86_platform_ipi_entry(X86_PLATFORM_IPI_VECTOR);
278 inc_irq_stat(x86_platform_ipis);
279 if (x86_platform_ipi_callback)
280 x86_platform_ipi_callback();
281 trace_x86_platform_ipi_exit(X86_PLATFORM_IPI_VECTOR);
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600282 set_irq_regs(old_regs);
283}
Thomas Gleixner0428e01a2017-08-28 08:47:34 +0200284#endif
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600285
Yang Zhangd78f2662013-04-11 19:25:11 +0800286#ifdef CONFIG_HAVE_KVM
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800287static void dummy_handler(void) {}
288static void (*kvm_posted_intr_wakeup_handler)(void) = dummy_handler;
289
290void kvm_set_posted_intr_wakeup_handler(void (*handler)(void))
291{
292 if (handler)
293 kvm_posted_intr_wakeup_handler = handler;
Sean Christopherson6ff53f62021-10-08 17:11:04 -0700294 else {
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800295 kvm_posted_intr_wakeup_handler = dummy_handler;
Sean Christopherson6ff53f62021-10-08 17:11:04 -0700296 synchronize_rcu();
297 }
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800298}
299EXPORT_SYMBOL_GPL(kvm_set_posted_intr_wakeup_handler);
300
Yang Zhangd78f2662013-04-11 19:25:11 +0800301/*
302 * Handler for POSTED_INTERRUPT_VECTOR.
303 */
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200304DEFINE_IDTENTRY_SYSVEC_SIMPLE(sysvec_kvm_posted_intr_ipi)
Yang Zhangd78f2662013-04-11 19:25:11 +0800305{
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200306 ack_APIC_irq();
Yang Zhangd78f2662013-04-11 19:25:11 +0800307 inc_irq_stat(kvm_posted_intr_ipis);
Yang Zhangd78f2662013-04-11 19:25:11 +0800308}
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800309
310/*
311 * Handler for POSTED_INTERRUPT_WAKEUP_VECTOR.
312 */
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200313DEFINE_IDTENTRY_SYSVEC(sysvec_kvm_posted_intr_wakeup_ipi)
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800314{
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200315 ack_APIC_irq();
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800316 inc_irq_stat(kvm_posted_intr_wakeup_ipis);
317 kvm_posted_intr_wakeup_handler();
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800318}
Wincy Van210f84b2017-04-28 13:13:58 +0800319
320/*
321 * Handler for POSTED_INTERRUPT_NESTED_VECTOR.
322 */
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200323DEFINE_IDTENTRY_SYSVEC_SIMPLE(sysvec_kvm_posted_intr_nested_ipi)
Wincy Van210f84b2017-04-28 13:13:58 +0800324{
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200325 ack_APIC_irq();
Wincy Van210f84b2017-04-28 13:13:58 +0800326 inc_irq_stat(kvm_posted_intr_nested_ipis);
Wincy Van210f84b2017-04-28 13:13:58 +0800327}
Yang Zhangd78f2662013-04-11 19:25:11 +0800328#endif
329
Seiji Aguchicf910e82013-06-20 11:46:53 -0400330
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800331#ifdef CONFIG_HOTPLUG_CPU
332/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
333void fixup_irqs(void)
334{
Thomas Gleixnerad7a9292017-06-20 01:37:33 +0200335 unsigned int irr, vector;
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800336 struct irq_desc *desc;
Thomas Gleixnera3c08e52010-10-08 20:24:58 +0200337 struct irq_data *data;
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100338 struct irq_chip *chip;
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800339
Thomas Gleixnerad7a9292017-06-20 01:37:33 +0200340 irq_migrate_all_off_this_cpu();
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800341
Suresh Siddha5231a682009-10-26 14:24:36 -0800342 /*
Ingo Molnard9f6e122021-03-18 15:28:01 +0100343 * We can remove mdelay() and then send spurious interrupts to
Suresh Siddha5231a682009-10-26 14:24:36 -0800344 * new cpu targets for all the irqs that were handled previously by
345 * this cpu. While it works, I have seen spurious interrupt messages
346 * (nothing wrong but still...).
347 *
348 * So for now, retain mdelay(1) and check the IRR and then send those
349 * interrupts to new targets as this cpu is already offlined...
350 */
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800351 mdelay(1);
Suresh Siddha5231a682009-10-26 14:24:36 -0800352
Thomas Gleixner09cf92b2015-07-05 17:12:35 +0000353 /*
354 * We can walk the vector array of this cpu without holding
355 * vector_lock because the cpu is already marked !online, so
356 * nothing else will touch it.
357 */
Suresh Siddha5231a682009-10-26 14:24:36 -0800358 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000359 if (IS_ERR_OR_NULL(__this_cpu_read(vector_irq[vector])))
Suresh Siddha5231a682009-10-26 14:24:36 -0800360 continue;
361
362 irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
363 if (irr & (1 << (vector % 32))) {
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000364 desc = __this_cpu_read(vector_irq[vector]);
Suresh Siddha5231a682009-10-26 14:24:36 -0800365
Thomas Gleixner09cf92b2015-07-05 17:12:35 +0000366 raw_spin_lock(&desc->lock);
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100367 data = irq_desc_get_irq_data(desc);
368 chip = irq_data_get_irq_chip(data);
Prarit Bhargava93450052014-01-05 11:10:52 -0500369 if (chip->irq_retrigger) {
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100370 chip->irq_retrigger(data);
Prarit Bhargava93450052014-01-05 11:10:52 -0500371 __this_cpu_write(vector_irq[vector], VECTOR_RETRIGGERED);
372 }
Thomas Gleixner239007b2009-11-17 16:46:45 +0100373 raw_spin_unlock(&desc->lock);
Suresh Siddha5231a682009-10-26 14:24:36 -0800374 }
Prarit Bhargava93450052014-01-05 11:10:52 -0500375 if (__this_cpu_read(vector_irq[vector]) != VECTOR_RETRIGGERED)
Thomas Gleixner7276c6a2015-08-02 20:38:25 +0000376 __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
Suresh Siddha5231a682009-10-26 14:24:36 -0800377 }
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800378}
379#endif
Borislav Petkov9223d0d2021-01-07 13:29:05 +0100380
381#ifdef CONFIG_X86_THERMAL_VECTOR
382static void smp_thermal_vector(void)
383{
384 if (x86_thermal_enabled())
385 intel_thermal_interrupt();
386 else
387 pr_err("CPU%d: Unexpected LVT thermal interrupt!\n",
388 smp_processor_id());
389}
390
391DEFINE_IDTENTRY_SYSVEC(sysvec_thermal)
392{
393 trace_thermal_apic_entry(THERMAL_APIC_VECTOR);
394 inc_irq_stat(irq_thermal_count);
395 smp_thermal_vector();
396 trace_thermal_apic_exit(THERMAL_APIC_VECTOR);
397 ack_APIC_irq();
398}
399#endif