blob: 21efee32e2b12e9a92658402793fb103bb4d501e [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
Ingo Molnar7b6aa332009-02-17 13:58:15 +010016#include <asm/apic.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020017#include <asm/io_apic.h>
Ingo Molnarc3d80002008-12-23 15:15:17 +010018#include <asm/irq.h>
Andi Kleen01ca79f2009-05-27 21:56:52 +020019#include <asm/mce.h>
Jaswinder Singh Rajput2c1b2842009-04-11 00:03:10 +053020#include <asm/hw_irq.h>
Yinghai Luac2a5532014-05-13 11:39:34 -040021#include <asm/desc.h>
Steven Rostedt (Red Hat)83ab8512013-06-21 10:29:05 -040022
23#define CREATE_TRACE_POINTS
Seiji Aguchicf910e82013-06-20 11:46:53 -040024#include <asm/trace/irq_vectors.h>
Thomas Gleixner6b39ba72008-10-16 11:32:24 +020025
Brian Gerstc5bde902015-05-09 11:36:50 -040026DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
27EXPORT_PER_CPU_SYMBOL(irq_stat);
28
29DEFINE_PER_CPU(struct pt_regs *, irq_regs);
30EXPORT_PER_CPU_SYMBOL(irq_regs);
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
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800227
228/*
229 * do_IRQ handles all normal device IRQ's (the special
230 * SMP cross-CPU interrupts have their own specific
231 * handlers).
232 */
Andi Kleen1d9090e2013-08-05 15:02:37 -0700233__visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800234{
235 struct pt_regs *old_regs = set_irq_regs(regs);
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000236 struct irq_desc * desc;
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800237 /* high bit used in ret_from_ code */
238 unsigned vector = ~regs->orig_ax;
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800239
Thomas Gleixner6af7faf2015-05-15 15:48:25 +0200240 entering_irq();
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800241
Andy Lutomirski0333a202015-07-03 12:44:34 -0700242 /* entering_irq() tells RCU that we're not quiescent. Check it. */
Linus Torvalds57780772015-09-01 08:40:25 -0700243 RCU_LOCKDEP_WARN(!rcu_is_watching(), "IRQ failed to wake up RCU");
Andy Lutomirski0333a202015-07-03 12:44:34 -0700244
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000245 desc = __this_cpu_read(vector_irq[vector]);
Heiner Kallweitd6f83422019-08-19 21:36:09 +0200246 if (likely(!IS_ERR_OR_NULL(desc))) {
247 if (IS_ENABLED(CONFIG_X86_32))
248 handle_irq(desc, regs);
249 else
250 generic_handle_irq_desc(desc);
251 } 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 Gleixnera782a7e2015-08-02 20:38:27 +0000255 pr_emerg_ratelimited("%s: %d.%d 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
Thomas Gleixner6af7faf2015-05-15 15:48:25 +0200263 exiting_irq();
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800264
265 set_irq_regs(old_regs);
266 return 1;
267}
268
Thomas Gleixner0428e01a2017-08-28 08:47:34 +0200269#ifdef CONFIG_X86_LOCAL_APIC
270/* Function pointer for generic interrupt vector handling */
271void (*x86_platform_ipi_callback)(void) = NULL;
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600272/*
Dimitri Sivanich4a4de9c2009-10-14 09:22:57 -0500273 * Handler for X86_PLATFORM_IPI_VECTOR.
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600274 */
Daniel Bristot de Oliveirac4158ff2017-01-04 12:20:33 +0100275__visible void __irq_entry smp_x86_platform_ipi(struct pt_regs *regs)
Seiji Aguchieddc0e92013-06-20 11:45:17 -0400276{
277 struct pt_regs *old_regs = set_irq_regs(regs);
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600278
Seiji Aguchieddc0e92013-06-20 11:45:17 -0400279 entering_ack_irq();
Thomas Gleixner8a171162017-08-28 08:47:25 +0200280 trace_x86_platform_ipi_entry(X86_PLATFORM_IPI_VECTOR);
281 inc_irq_stat(x86_platform_ipis);
282 if (x86_platform_ipi_callback)
283 x86_platform_ipi_callback();
284 trace_x86_platform_ipi_exit(X86_PLATFORM_IPI_VECTOR);
Seiji Aguchieddc0e92013-06-20 11:45:17 -0400285 exiting_irq();
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600286 set_irq_regs(old_regs);
287}
Thomas Gleixner0428e01a2017-08-28 08:47:34 +0200288#endif
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600289
Yang Zhangd78f2662013-04-11 19:25:11 +0800290#ifdef CONFIG_HAVE_KVM
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800291static void dummy_handler(void) {}
292static void (*kvm_posted_intr_wakeup_handler)(void) = dummy_handler;
293
294void kvm_set_posted_intr_wakeup_handler(void (*handler)(void))
295{
296 if (handler)
297 kvm_posted_intr_wakeup_handler = handler;
298 else
299 kvm_posted_intr_wakeup_handler = dummy_handler;
300}
301EXPORT_SYMBOL_GPL(kvm_set_posted_intr_wakeup_handler);
302
Yang Zhangd78f2662013-04-11 19:25:11 +0800303/*
304 * Handler for POSTED_INTERRUPT_VECTOR.
305 */
Andi Kleen1d9090e2013-08-05 15:02:37 -0700306__visible void smp_kvm_posted_intr_ipi(struct pt_regs *regs)
Yang Zhangd78f2662013-04-11 19:25:11 +0800307{
308 struct pt_regs *old_regs = set_irq_regs(regs);
309
Thomas Gleixner6af7faf2015-05-15 15:48:25 +0200310 entering_ack_irq();
Yang Zhangd78f2662013-04-11 19:25:11 +0800311 inc_irq_stat(kvm_posted_intr_ipis);
Thomas Gleixner6af7faf2015-05-15 15:48:25 +0200312 exiting_irq();
Yang Zhangd78f2662013-04-11 19:25:11 +0800313 set_irq_regs(old_regs);
314}
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800315
316/*
317 * Handler for POSTED_INTERRUPT_WAKEUP_VECTOR.
318 */
319__visible void smp_kvm_posted_intr_wakeup_ipi(struct pt_regs *regs)
320{
321 struct pt_regs *old_regs = set_irq_regs(regs);
322
323 entering_ack_irq();
324 inc_irq_stat(kvm_posted_intr_wakeup_ipis);
325 kvm_posted_intr_wakeup_handler();
326 exiting_irq();
327 set_irq_regs(old_regs);
328}
Wincy Van210f84b2017-04-28 13:13:58 +0800329
330/*
331 * Handler for POSTED_INTERRUPT_NESTED_VECTOR.
332 */
333__visible void smp_kvm_posted_intr_nested_ipi(struct pt_regs *regs)
334{
335 struct pt_regs *old_regs = set_irq_regs(regs);
336
337 entering_ack_irq();
338 inc_irq_stat(kvm_posted_intr_nested_ipis);
339 exiting_irq();
340 set_irq_regs(old_regs);
341}
Yang Zhangd78f2662013-04-11 19:25:11 +0800342#endif
343
Seiji Aguchicf910e82013-06-20 11:46:53 -0400344
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800345#ifdef CONFIG_HOTPLUG_CPU
346/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
347void fixup_irqs(void)
348{
Thomas Gleixnerad7a9292017-06-20 01:37:33 +0200349 unsigned int irr, vector;
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800350 struct irq_desc *desc;
Thomas Gleixnera3c08e52010-10-08 20:24:58 +0200351 struct irq_data *data;
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100352 struct irq_chip *chip;
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800353
Thomas Gleixnerad7a9292017-06-20 01:37:33 +0200354 irq_migrate_all_off_this_cpu();
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800355
Suresh Siddha5231a682009-10-26 14:24:36 -0800356 /*
357 * We can remove mdelay() and then send spuriuous interrupts to
358 * new cpu targets for all the irqs that were handled previously by
359 * this cpu. While it works, I have seen spurious interrupt messages
360 * (nothing wrong but still...).
361 *
362 * So for now, retain mdelay(1) and check the IRR and then send those
363 * interrupts to new targets as this cpu is already offlined...
364 */
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800365 mdelay(1);
Suresh Siddha5231a682009-10-26 14:24:36 -0800366
Thomas Gleixner09cf92b2015-07-05 17:12:35 +0000367 /*
368 * We can walk the vector array of this cpu without holding
369 * vector_lock because the cpu is already marked !online, so
370 * nothing else will touch it.
371 */
Suresh Siddha5231a682009-10-26 14:24:36 -0800372 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000373 if (IS_ERR_OR_NULL(__this_cpu_read(vector_irq[vector])))
Suresh Siddha5231a682009-10-26 14:24:36 -0800374 continue;
375
376 irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
377 if (irr & (1 << (vector % 32))) {
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000378 desc = __this_cpu_read(vector_irq[vector]);
Suresh Siddha5231a682009-10-26 14:24:36 -0800379
Thomas Gleixner09cf92b2015-07-05 17:12:35 +0000380 raw_spin_lock(&desc->lock);
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100381 data = irq_desc_get_irq_data(desc);
382 chip = irq_data_get_irq_chip(data);
Prarit Bhargava93450052014-01-05 11:10:52 -0500383 if (chip->irq_retrigger) {
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100384 chip->irq_retrigger(data);
Prarit Bhargava93450052014-01-05 11:10:52 -0500385 __this_cpu_write(vector_irq[vector], VECTOR_RETRIGGERED);
386 }
Thomas Gleixner239007b2009-11-17 16:46:45 +0100387 raw_spin_unlock(&desc->lock);
Suresh Siddha5231a682009-10-26 14:24:36 -0800388 }
Prarit Bhargava93450052014-01-05 11:10:52 -0500389 if (__this_cpu_read(vector_irq[vector]) != VECTOR_RETRIGGERED)
Thomas Gleixner7276c6a2015-08-02 20:38:25 +0000390 __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
Suresh Siddha5231a682009-10-26 14:24:36 -0800391 }
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800392}
393#endif