blob: 9b68b5b00ac91cf7755c9767d8e78c1a558dacb8 [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
K. Y. Srinivasanf704a7d2014-04-01 23:51:42 -0700138#if IS_ENABLED(CONFIG_HYPERV) || defined(CONFIG_XEN)
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]);
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800246
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000247 if (!handle_irq(desc, regs)) {
Cyrill Gorcunov08306ce2009-04-12 20:47:41 +0400248 ack_APIC_irq();
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800249
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000250 if (desc != VECTOR_RETRIGGERED) {
251 pr_emerg_ratelimited("%s: %d.%d No irq handler for vector\n",
Prarit Bhargava93450052014-01-05 11:10:52 -0500252 __func__, smp_processor_id(),
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000253 vector);
Prarit Bhargava93450052014-01-05 11:10:52 -0500254 } else {
Thomas Gleixner7276c6a2015-08-02 20:38:25 +0000255 __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
Prarit Bhargava93450052014-01-05 11:10:52 -0500256 }
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800257 }
258
Thomas Gleixner6af7faf2015-05-15 15:48:25 +0200259 exiting_irq();
Jeremy Fitzhardinge7c1d7cd2009-02-06 14:09:41 -0800260
261 set_irq_regs(old_regs);
262 return 1;
263}
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 */
Daniel Bristot de Oliveirac4158ff2017-01-04 12:20:33 +0100271__visible void __irq_entry smp_x86_platform_ipi(struct pt_regs *regs)
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
Seiji Aguchieddc0e92013-06-20 11:45:17 -0400275 entering_ack_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);
Seiji Aguchieddc0e92013-06-20 11:45:17 -0400281 exiting_irq();
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;
294 else
295 kvm_posted_intr_wakeup_handler = dummy_handler;
296}
297EXPORT_SYMBOL_GPL(kvm_set_posted_intr_wakeup_handler);
298
Yang Zhangd78f2662013-04-11 19:25:11 +0800299/*
300 * Handler for POSTED_INTERRUPT_VECTOR.
301 */
Andi Kleen1d9090e2013-08-05 15:02:37 -0700302__visible void smp_kvm_posted_intr_ipi(struct pt_regs *regs)
Yang Zhangd78f2662013-04-11 19:25:11 +0800303{
304 struct pt_regs *old_regs = set_irq_regs(regs);
305
Thomas Gleixner6af7faf2015-05-15 15:48:25 +0200306 entering_ack_irq();
Yang Zhangd78f2662013-04-11 19:25:11 +0800307 inc_irq_stat(kvm_posted_intr_ipis);
Thomas Gleixner6af7faf2015-05-15 15:48:25 +0200308 exiting_irq();
Yang Zhangd78f2662013-04-11 19:25:11 +0800309 set_irq_regs(old_regs);
310}
Feng Wuf6b3c72c2015-05-19 17:07:16 +0800311
312/*
313 * Handler for POSTED_INTERRUPT_WAKEUP_VECTOR.
314 */
315__visible void smp_kvm_posted_intr_wakeup_ipi(struct pt_regs *regs)
316{
317 struct pt_regs *old_regs = set_irq_regs(regs);
318
319 entering_ack_irq();
320 inc_irq_stat(kvm_posted_intr_wakeup_ipis);
321 kvm_posted_intr_wakeup_handler();
322 exiting_irq();
323 set_irq_regs(old_regs);
324}
Wincy Van210f84b2017-04-28 13:13:58 +0800325
326/*
327 * Handler for POSTED_INTERRUPT_NESTED_VECTOR.
328 */
329__visible void smp_kvm_posted_intr_nested_ipi(struct pt_regs *regs)
330{
331 struct pt_regs *old_regs = set_irq_regs(regs);
332
333 entering_ack_irq();
334 inc_irq_stat(kvm_posted_intr_nested_ipis);
335 exiting_irq();
336 set_irq_regs(old_regs);
337}
Yang Zhangd78f2662013-04-11 19:25:11 +0800338#endif
339
Seiji Aguchicf910e82013-06-20 11:46:53 -0400340
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800341#ifdef CONFIG_HOTPLUG_CPU
342/* A cpu has been removed from cpu_online_mask. Reset irq affinities. */
343void fixup_irqs(void)
344{
Thomas Gleixnerad7a9292017-06-20 01:37:33 +0200345 unsigned int irr, vector;
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800346 struct irq_desc *desc;
Thomas Gleixnera3c08e52010-10-08 20:24:58 +0200347 struct irq_data *data;
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100348 struct irq_chip *chip;
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800349
Thomas Gleixnerad7a9292017-06-20 01:37:33 +0200350 irq_migrate_all_off_this_cpu();
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800351
Suresh Siddha5231a682009-10-26 14:24:36 -0800352 /*
353 * We can remove mdelay() and then send spuriuous interrupts to
354 * new cpu targets for all the irqs that were handled previously by
355 * this cpu. While it works, I have seen spurious interrupt messages
356 * (nothing wrong but still...).
357 *
358 * So for now, retain mdelay(1) and check the IRR and then send those
359 * interrupts to new targets as this cpu is already offlined...
360 */
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800361 mdelay(1);
Suresh Siddha5231a682009-10-26 14:24:36 -0800362
Thomas Gleixner09cf92b2015-07-05 17:12:35 +0000363 /*
364 * We can walk the vector array of this cpu without holding
365 * vector_lock because the cpu is already marked !online, so
366 * nothing else will touch it.
367 */
Suresh Siddha5231a682009-10-26 14:24:36 -0800368 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000369 if (IS_ERR_OR_NULL(__this_cpu_read(vector_irq[vector])))
Suresh Siddha5231a682009-10-26 14:24:36 -0800370 continue;
371
372 irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
373 if (irr & (1 << (vector % 32))) {
Thomas Gleixnera782a7e2015-08-02 20:38:27 +0000374 desc = __this_cpu_read(vector_irq[vector]);
Suresh Siddha5231a682009-10-26 14:24:36 -0800375
Thomas Gleixner09cf92b2015-07-05 17:12:35 +0000376 raw_spin_lock(&desc->lock);
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100377 data = irq_desc_get_irq_data(desc);
378 chip = irq_data_get_irq_chip(data);
Prarit Bhargava93450052014-01-05 11:10:52 -0500379 if (chip->irq_retrigger) {
Thomas Gleixner51c43ac2011-02-10 21:40:36 +0100380 chip->irq_retrigger(data);
Prarit Bhargava93450052014-01-05 11:10:52 -0500381 __this_cpu_write(vector_irq[vector], VECTOR_RETRIGGERED);
382 }
Thomas Gleixner239007b2009-11-17 16:46:45 +0100383 raw_spin_unlock(&desc->lock);
Suresh Siddha5231a682009-10-26 14:24:36 -0800384 }
Prarit Bhargava93450052014-01-05 11:10:52 -0500385 if (__this_cpu_read(vector_irq[vector]) != VECTOR_RETRIGGERED)
Thomas Gleixner7276c6a2015-08-02 20:38:25 +0000386 __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
Suresh Siddha5231a682009-10-26 14:24:36 -0800387 }
Suresh Siddha7a7732b2009-10-26 14:24:31 -0800388}
389#endif