blob: 181060247e3cb75789d7522b0b0be0d6483c3596 [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>
Steven Rostedt (Red Hat)83ab8512013-06-21 10:29:05 -040024
25#define CREATE_TRACE_POINTS
Seiji Aguchicf910e82013-06-20 11:46:53 -040026#include <asm/trace/irq_vectors.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020027
Brian Gerstc5bde902015-05-09 11:36:50 -040028DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
29EXPORT_PER_CPU_SYMBOL(irq_stat);
30
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020031atomic_t irq_err_count;
32
Thomas Gleixner249f6d92008-10-16 12:18:50 +020033/*
34 * 'what should we do if we get a hw irq event on an illegal vector'.
35 * each architecture has to answer this themselves.
36 */
37void ack_bad_irq(unsigned int irq)
38{
Cyrill Gorcunovedea7142009-04-12 20:47:39 +040039 if (printk_ratelimit())
40 pr_err("unexpected IRQ trap at vector %02x\n", irq);
Thomas Gleixner249f6d92008-10-16 12:18:50 +020041
Thomas Gleixner249f6d92008-10-16 12:18:50 +020042 /*
43 * Currently unexpected vectors happen only on SMP and APIC.
44 * We _must_ ack these because every local APIC has only N
45 * irq slots per priority level, and a 'hanging, unacked' IRQ
46 * holds up an irq slot - in excessive cases (when multiple
47 * unexpected vectors occur) that might lock up the APIC
48 * completely.
49 * But only ack when the APIC is enabled -AK
50 */
Cyrill Gorcunov08306ce2009-04-12 20:47:41 +040051 ack_APIC_irq();
Thomas Gleixner249f6d92008-10-16 12:18:50 +020052}
53
Brian Gerst1b437c82009-01-19 00:38:57 +090054#define irq_stats(x) (&per_cpu(irq_stat, x))
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020055/*
Thomas Gleixner517e4982010-12-16 17:59:57 +010056 * /proc/interrupts printing for arch specific interrupts
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020057 */
Thomas Gleixner517e4982010-12-16 17:59:57 +010058int arch_show_interrupts(struct seq_file *p, int prec)
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020059{
60 int j;
61
Jan Beulich7a81d9a2009-03-12 12:45:15 +000062 seq_printf(p, "%*s: ", prec, "NMI");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020063 for_each_online_cpu(j)
64 seq_printf(p, "%10u ", irq_stats(j)->__nmi_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +010065 seq_puts(p, " Non-maskable interrupts\n");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020066#ifdef CONFIG_X86_LOCAL_APIC
Jan Beulich7a81d9a2009-03-12 12:45:15 +000067 seq_printf(p, "%*s: ", prec, "LOC");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020068 for_each_online_cpu(j)
69 seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs);
Rasmus Villemoes37367082014-11-28 22:03:41 +010070 seq_puts(p, " Local timer interrupts\n");
Jaswinder Singh Rajput474e56b2009-03-23 02:08:34 +053071
72 seq_printf(p, "%*s: ", prec, "SPU");
73 for_each_online_cpu(j)
74 seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +010075 seq_puts(p, " Spurious interrupts\n");
Li Hong89ccf462009-10-14 18:50:39 +080076 seq_printf(p, "%*s: ", prec, "PMI");
Ingo Molnar241771e2008-12-03 10:39:53 +010077 for_each_online_cpu(j)
78 seq_printf(p, "%10u ", irq_stats(j)->apic_perf_irqs);
Rasmus Villemoes37367082014-11-28 22:03:41 +010079 seq_puts(p, " Performance monitoring interrupts\n");
Peter Zijlstrae360adb2010-10-14 14:01:34 +080080 seq_printf(p, "%*s: ", prec, "IWI");
Peter Zijlstrab6276f32009-04-06 11:45:03 +020081 for_each_online_cpu(j)
Peter Zijlstrae360adb2010-10-14 14:01:34 +080082 seq_printf(p, "%10u ", irq_stats(j)->apic_irq_work_irqs);
Rasmus Villemoes37367082014-11-28 22:03:41 +010083 seq_puts(p, " IRQ work interrupts\n");
Fernando Luis Vázquez Cao346b46b2011-12-13 11:51:53 +090084 seq_printf(p, "%*s: ", prec, "RTR");
85 for_each_online_cpu(j)
Fernando Luis Vazquez Caob49d7d82011-12-15 11:32:24 +090086 seq_printf(p, "%10u ", irq_stats(j)->icr_read_retry_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +010087 seq_puts(p, " APIC ICR read retries\n");
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -050088 if (x86_platform_ipi_callback) {
Hidetoshi Seto59d13812009-03-25 10:50:34 +090089 seq_printf(p, "%*s: ", prec, "PLT");
Dimitri Sivanichacaabe72009-03-04 12:56:05 -060090 for_each_online_cpu(j)
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -050091 seq_printf(p, "%10u ", irq_stats(j)->x86_platform_ipis);
Rasmus Villemoes37367082014-11-28 22:03:41 +010092 seq_puts(p, " Platform interrupts\n");
Dimitri Sivanichacaabe72009-03-04 12:56:05 -060093 }
Thomas Gleixner0428e01a2017-08-28 08:47:34 +020094#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020095#ifdef CONFIG_SMP
Jan Beulich7a81d9a2009-03-12 12:45:15 +000096 seq_printf(p, "%*s: ", prec, "RES");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020097 for_each_online_cpu(j)
98 seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +010099 seq_puts(p, " Rescheduling interrupts\n");
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000100 seq_printf(p, "%*s: ", prec, "CAL");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200101 for_each_online_cpu(j)
Aaron Lu82ba4fa2016-08-11 15:44:30 +0800102 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100103 seq_puts(p, " Function call interrupts\n");
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000104 seq_printf(p, "%*s: ", prec, "TLB");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200105 for_each_online_cpu(j)
106 seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100107 seq_puts(p, " TLB shootdowns\n");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200108#endif
Jan Beulich0444c9b2009-11-20 14:03:05 +0000109#ifdef CONFIG_X86_THERMAL_VECTOR
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000110 seq_printf(p, "%*s: ", prec, "TRM");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200111 for_each_online_cpu(j)
112 seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100113 seq_puts(p, " Thermal event interrupts\n");
Jan Beulich0444c9b2009-11-20 14:03:05 +0000114#endif
115#ifdef CONFIG_X86_MCE_THRESHOLD
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000116 seq_printf(p, "%*s: ", prec, "THR");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200117 for_each_online_cpu(j)
118 seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count);
Rasmus Villemoes37367082014-11-28 22:03:41 +0100119 seq_puts(p, " Threshold APIC interrupts\n");
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200120#endif
Aravind Gopalakrishnan24fd78a2015-05-06 06:58:56 -0500121#ifdef CONFIG_X86_MCE_AMD
122 seq_printf(p, "%*s: ", prec, "DFR");
123 for_each_online_cpu(j)
124 seq_printf(p, "%10u ", irq_stats(j)->irq_deferred_error_count);
125 seq_puts(p, " Deferred Error APIC interrupts\n");
126#endif
Andi Kleenc1ebf832009-07-09 00:31:41 +0200127#ifdef CONFIG_X86_MCE
Andi Kleen01ca79f2009-05-27 21:56:52 +0200128 seq_printf(p, "%*s: ", prec, "MCE");
129 for_each_online_cpu(j)
130 seq_printf(p, "%10u ", per_cpu(mce_exception_count, j));
Rasmus Villemoes37367082014-11-28 22:03:41 +0100131 seq_puts(p, " Machine check exceptions\n");
Andi Kleenca84f692009-05-27 21:56:57 +0200132 seq_printf(p, "%*s: ", prec, "MCP");
133 for_each_online_cpu(j)
134 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
Rasmus Villemoes37367082014-11-28 22:03:41 +0100135 seq_puts(p, " Machine check polls\n");
Andi Kleen01ca79f2009-05-27 21:56:52 +0200136#endif
Zhao Yakuiecca25022019-04-30 11:45:23 +0800137#ifdef CONFIG_X86_HV_CALLBACK_VECTOR
Thomas Gleixner7854f822017-09-13 23:29:26 +0200138 if (test_bit(HYPERVISOR_CALLBACK_VECTOR, system_vectors)) {
Vitaly Kuznetsov9d87cd62015-07-07 18:26:13 +0200139 seq_printf(p, "%*s: ", prec, "HYP");
140 for_each_online_cpu(j)
141 seq_printf(p, "%10u ",
142 irq_stats(j)->irq_hv_callback_count);
143 seq_puts(p, " Hypervisor callback interrupts\n");
144 }
Thomas Gleixner929320e2014-02-23 21:40:20 +0000145#endif
Vitaly Kuznetsov51d4e5d2018-01-24 14:23:35 +0100146#if IS_ENABLED(CONFIG_HYPERV)
147 if (test_bit(HYPERV_REENLIGHTENMENT_VECTOR, system_vectors)) {
148 seq_printf(p, "%*s: ", prec, "HRE");
149 for_each_online_cpu(j)
150 seq_printf(p, "%10u ",
151 irq_stats(j)->irq_hv_reenlightenment_count);
152 seq_puts(p, " Hyper-V reenlightenment interrupts\n");
153 }
Michael Kelley248e7422018-03-04 22:17:18 -0700154 if (test_bit(HYPERV_STIMER0_VECTOR, system_vectors)) {
155 seq_printf(p, "%*s: ", prec, "HVS");
156 for_each_online_cpu(j)
157 seq_printf(p, "%10u ",
158 irq_stats(j)->hyperv_stimer0_count);
159 seq_puts(p, " Hyper-V stimer0 interrupts\n");
160 }
Vitaly Kuznetsov51d4e5d2018-01-24 14:23:35 +0100161#endif
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000162 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200163#if defined(CONFIG_X86_IO_APIC)
Jan Beulich7a81d9a2009-03-12 12:45:15 +0000164 seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200165#endif
Feng Wu501b3262015-05-19 17:07:17 +0800166#ifdef CONFIG_HAVE_KVM
167 seq_printf(p, "%*s: ", prec, "PIN");
168 for_each_online_cpu(j)
169 seq_printf(p, "%10u ", irq_stats(j)->kvm_posted_intr_ipis);
170 seq_puts(p, " Posted-interrupt notification event\n");
171
Wincy Van210f84b2017-04-28 13:13:58 +0800172 seq_printf(p, "%*s: ", prec, "NPI");
173 for_each_online_cpu(j)
174 seq_printf(p, "%10u ",
175 irq_stats(j)->kvm_posted_intr_nested_ipis);
176 seq_puts(p, " Nested posted-interrupt event\n");
177
Feng Wu501b3262015-05-19 17:07:17 +0800178 seq_printf(p, "%*s: ", prec, "PIW");
179 for_each_online_cpu(j)
180 seq_printf(p, "%10u ",
181 irq_stats(j)->kvm_posted_intr_wakeup_ipis);
182 seq_puts(p, " Posted-interrupt wakeup event\n");
183#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200184 return 0;
185}
186
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200187/*
188 * /proc/stat helpers
189 */
190u64 arch_irq_stat_cpu(unsigned int cpu)
191{
192 u64 sum = irq_stats(cpu)->__nmi_count;
193
194#ifdef CONFIG_X86_LOCAL_APIC
195 sum += irq_stats(cpu)->apic_timer_irqs;
Jaswinder Singh Rajput474e56b2009-03-23 02:08:34 +0530196 sum += irq_stats(cpu)->irq_spurious_count;
Ingo Molnar241771e2008-12-03 10:39:53 +0100197 sum += irq_stats(cpu)->apic_perf_irqs;
Peter Zijlstrae360adb2010-10-14 14:01:34 +0800198 sum += irq_stats(cpu)->apic_irq_work_irqs;
Fernando Luis Vazquez Caob49d7d82011-12-15 11:32:24 +0900199 sum += irq_stats(cpu)->icr_read_retry_count;
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -0500200 if (x86_platform_ipi_callback)
201 sum += irq_stats(cpu)->x86_platform_ipis;
Thomas Gleixner0428e01a2017-08-28 08:47:34 +0200202#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200203#ifdef CONFIG_SMP
204 sum += irq_stats(cpu)->irq_resched_count;
205 sum += irq_stats(cpu)->irq_call_count;
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200206#endif
Jan Beulich0444c9b2009-11-20 14:03:05 +0000207#ifdef CONFIG_X86_THERMAL_VECTOR
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200208 sum += irq_stats(cpu)->irq_thermal_count;
Jan Beulich0444c9b2009-11-20 14:03:05 +0000209#endif
210#ifdef CONFIG_X86_MCE_THRESHOLD
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200211 sum += irq_stats(cpu)->irq_threshold_count;
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200212#endif
Andi Kleenc1ebf832009-07-09 00:31:41 +0200213#ifdef CONFIG_X86_MCE
Hidetoshi Seto8051dbd2009-06-02 16:53:23 +0900214 sum += per_cpu(mce_exception_count, cpu);
215 sum += per_cpu(mce_poll_count, cpu);
216#endif
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200217 return sum;
218}
219
220u64 arch_irq_stat(void)
221{
222 u64 sum = atomic_read(&irq_err_count);
Thomas Gleixner6b39ba72008-10-16 11:32:24 +0200223 return sum;
224}
Ingo Molnarc3d80002008-12-23 15:15:17 +0100225
Thomas Gleixner7c2a5732020-05-21 22:05:35 +0200226static __always_inline void handle_irq(struct irq_desc *desc,
227 struct pt_regs *regs)
228{
229 if (IS_ENABLED(CONFIG_X86_64))
230 run_on_irqstack_cond(desc->handle_irq, desc, regs);
231 else
232 __handle_irq(desc, regs);
233}
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800234
235/*
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200236 * common_interrupt() handles all normal device IRQ's (the special SMP
237 * cross-CPU interrupts have their own entry points).
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800238 */
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200239DEFINE_IDTENTRY_IRQ(common_interrupt)
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800240{
241 struct pt_regs *old_regs = set_irq_regs(regs);
Thomas Gleixner633260f2020-05-21 22:05:34 +0200242 struct irq_desc *desc;
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800243
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200244 /* entry code tells RCU that we're not quiescent. Check it. */
Linus Torvalds57780772015-09-01 08:40:25 -0700245 RCU_LOCKDEP_WARN(!rcu_is_watching(), "IRQ failed to wake up RCU");
Andy Lutomirski0333a202015-07-03 12:44:34 -0700246
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000247 desc = __this_cpu_read(vector_irq[vector]);
Heiner Kallweitd6f83422019-08-19 21:36:09 +0200248 if (likely(!IS_ERR_OR_NULL(desc))) {
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200249 handle_irq(desc, regs);
Heiner Kallweitd6f83422019-08-19 21:36:09 +0200250 } else {
Cyrill Gorcunov08306ce2009-04-12 20:47:41 +0400251 ack_APIC_irq();
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800252
Heiner Kallweit8725fcd2019-08-19 21:36:39 +0200253 if (desc == VECTOR_UNUSED) {
Thomas Gleixnerfa5e5c42020-05-21 22:05:37 +0200254 pr_emerg_ratelimited("%s: %d.%u No irq handler for vector\n",
Prarit Bhargava93450052014-01-05 11:10:52 -0500255 __func__, smp_processor_id(),
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000256 vector);
Prarit Bhargava93450052014-01-05 11:10:52 -0500257 } else {
Thomas Gleixner7276c6a2015-08-02 20:38:25 +0000258 __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
Prarit Bhargava93450052014-01-05 11:10:52 -0500259 }
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800260 }
261
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800262 set_irq_regs(old_regs);
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800263}
264
Thomas Gleixner0428e01a2017-08-28 08:47:34 +0200265#ifdef CONFIG_X86_LOCAL_APIC
266/* Function pointer for generic interrupt vector handling */
267void (*x86_platform_ipi_callback)(void) = NULL;
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600268/*
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -0500269 * Handler for X86_PLATFORM_IPI_VECTOR.
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600270 */
Thomas Gleixnerdb0338e2020-05-21 22:05:39 +0200271DEFINE_IDTENTRY_SYSVEC(sysvec_x86_platform_ipi)
Seiji Aguchieddc0e92013-06-20 11:45:17 -0400272{
273 struct pt_regs *old_regs = set_irq_regs(regs);
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600274
Thomas Gleixnerdb0338e2020-05-21 22:05:39 +0200275 ack_APIC_irq();
Thomas Gleixner8a171162017-08-28 08:47:25 +0200276 trace_x86_platform_ipi_entry(X86_PLATFORM_IPI_VECTOR);
277 inc_irq_stat(x86_platform_ipis);
278 if (x86_platform_ipi_callback)
279 x86_platform_ipi_callback();
280 trace_x86_platform_ipi_exit(X86_PLATFORM_IPI_VECTOR);
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600281 set_irq_regs(old_regs);
282}
Thomas Gleixner0428e01a2017-08-28 08:47:34 +0200283#endif
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600284
Yang Zhangd78f2662013-04-11 19:25:11 +0800285#ifdef CONFIG_HAVE_KVM
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800286static void dummy_handler(void) {}
287static void (*kvm_posted_intr_wakeup_handler)(void) = dummy_handler;
288
289void kvm_set_posted_intr_wakeup_handler(void (*handler)(void))
290{
291 if (handler)
292 kvm_posted_intr_wakeup_handler = handler;
293 else
294 kvm_posted_intr_wakeup_handler = dummy_handler;
295}
296EXPORT_SYMBOL_GPL(kvm_set_posted_intr_wakeup_handler);
297
Yang Zhangd78f2662013-04-11 19:25:11 +0800298/*
299 * Handler for POSTED_INTERRUPT_VECTOR.
300 */
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200301DEFINE_IDTENTRY_SYSVEC_SIMPLE(sysvec_kvm_posted_intr_ipi)
Yang Zhangd78f2662013-04-11 19:25:11 +0800302{
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200303 ack_APIC_irq();
Yang Zhangd78f2662013-04-11 19:25:11 +0800304 inc_irq_stat(kvm_posted_intr_ipis);
Yang Zhangd78f2662013-04-11 19:25:11 +0800305}
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800306
307/*
308 * Handler for POSTED_INTERRUPT_WAKEUP_VECTOR.
309 */
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200310DEFINE_IDTENTRY_SYSVEC(sysvec_kvm_posted_intr_wakeup_ipi)
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800311{
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200312 ack_APIC_irq();
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800313 inc_irq_stat(kvm_posted_intr_wakeup_ipis);
314 kvm_posted_intr_wakeup_handler();
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800315}
Wincy Van210f84b2017-04-28 13:13:58 +0800316
317/*
318 * Handler for POSTED_INTERRUPT_NESTED_VECTOR.
319 */
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200320DEFINE_IDTENTRY_SYSVEC_SIMPLE(sysvec_kvm_posted_intr_nested_ipi)
Wincy Van210f84b2017-04-28 13:13:58 +0800321{
Thomas Gleixner9c3b1f42020-05-21 22:05:42 +0200322 ack_APIC_irq();
Wincy Van210f84b2017-04-28 13:13:58 +0800323 inc_irq_stat(kvm_posted_intr_nested_ipis);
Wincy Van210f84b2017-04-28 13:13:58 +0800324}
Yang Zhangd78f2662013-04-11 19:25:11 +0800325#endif
326
Seiji Aguchicf910e82013-06-20 11:46:53 -0400327
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800328#ifdef CONFIG_HOTPLUG_CPU
329/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
330void fixup_irqs(void)
331{
Thomas Gleixnerad7a9292017-06-20 01:37:33 +0200332 unsigned int irr, vector;
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800333 struct irq_desc *desc;
Thomas Gleixnera3c08e52010-10-08 20:24:58 +0200334 struct irq_data *data;
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100335 struct irq_chip *chip;
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800336
Thomas Gleixnerad7a9292017-06-20 01:37:33 +0200337 irq_migrate_all_off_this_cpu();
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800338
Suresh Siddha5231a682009-10-26 14:24:36 -0800339 /*
340 * We can remove mdelay() and then send spuriuous interrupts to
341 * new cpu targets for all the irqs that were handled previously by
342 * this cpu. While it works, I have seen spurious interrupt messages
343 * (nothing wrong but still...).
344 *
345 * So for now, retain mdelay(1) and check the IRR and then send those
346 * interrupts to new targets as this cpu is already offlined...
347 */
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800348 mdelay(1);
Suresh Siddha5231a682009-10-26 14:24:36 -0800349
Thomas Gleixner09cf92b2015-07-05 17:12:35 +0000350 /*
351 * We can walk the vector array of this cpu without holding
352 * vector_lock because the cpu is already marked !online, so
353 * nothing else will touch it.
354 */
Suresh Siddha5231a682009-10-26 14:24:36 -0800355 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000356 if (IS_ERR_OR_NULL(__this_cpu_read(vector_irq[vector])))
Suresh Siddha5231a682009-10-26 14:24:36 -0800357 continue;
358
359 irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
360 if (irr & (1 << (vector % 32))) {
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000361 desc = __this_cpu_read(vector_irq[vector]);
Suresh Siddha5231a682009-10-26 14:24:36 -0800362
Thomas Gleixner09cf92b2015-07-05 17:12:35 +0000363 raw_spin_lock(&desc->lock);
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100364 data = irq_desc_get_irq_data(desc);
365 chip = irq_data_get_irq_chip(data);
Prarit Bhargava93450052014-01-05 11:10:52 -0500366 if (chip->irq_retrigger) {
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100367 chip->irq_retrigger(data);
Prarit Bhargava93450052014-01-05 11:10:52 -0500368 __this_cpu_write(vector_irq[vector], VECTOR_RETRIGGERED);
369 }
Thomas Gleixner239007b2009-11-17 16:46:45 +0100370 raw_spin_unlock(&desc->lock);
Suresh Siddha5231a682009-10-26 14:24:36 -0800371 }
Prarit Bhargava93450052014-01-05 11:10:52 -0500372 if (__this_cpu_read(vector_irq[vector]) != VECTOR_RETRIGGERED)
Thomas Gleixner7276c6a2015-08-02 20:38:25 +0000373 __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
Suresh Siddha5231a682009-10-26 14:24:36 -0800374 }
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800375}
376#endif