2018-03-15 05:15:19 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2006-06-29 17:24:50 +08:00
|
|
|
* Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
|
|
|
|
* Copyright (C) 2005-2006, Thomas Gleixner, Russell King
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2018-03-15 05:15:16 +08:00
|
|
|
* This file contains the core interrupt handling code. Detailed
|
|
|
|
* information is available in Documentation/core-api/genericirq.rst
|
2006-06-29 17:24:50 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/random.h>
|
2010-09-22 23:09:43 +08:00
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
2010-09-22 23:09:43 +08:00
|
|
|
|
2009-04-15 07:39:12 +08:00
|
|
|
#include <trace/events/irq.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "internals.h"
|
|
|
|
|
2018-03-08 07:57:27 +08:00
|
|
|
#ifdef CONFIG_GENERIC_IRQ_MULTI_HANDLER
|
|
|
|
void (*handle_arch_irq)(struct pt_regs *) __ro_after_init;
|
|
|
|
#endif
|
|
|
|
|
2006-06-29 17:24:51 +08:00
|
|
|
/**
|
|
|
|
* handle_bad_irq - handle spurious and unhandled irqs
|
2006-09-01 12:27:44 +08:00
|
|
|
* @desc: description of the interrupt
|
|
|
|
*
|
|
|
|
* Handles spurious and unhandled IRQ's. It also prints a debugmessage.
|
2006-06-29 17:24:51 +08:00
|
|
|
*/
|
2015-09-14 16:42:37 +08:00
|
|
|
void handle_bad_irq(struct irq_desc *desc)
|
2006-06-29 17:24:51 +08:00
|
|
|
{
|
2015-09-14 16:42:37 +08:00
|
|
|
unsigned int irq = irq_desc_get_irq(desc);
|
|
|
|
|
2006-06-29 17:24:58 +08:00
|
|
|
print_irq_desc(irq, desc);
|
2015-06-04 12:13:25 +08:00
|
|
|
kstat_incr_irqs_this_cpu(desc);
|
2006-06-29 17:24:51 +08:00
|
|
|
ack_bad_irq(irq);
|
|
|
|
}
|
2015-10-07 04:24:50 +08:00
|
|
|
EXPORT_SYMBOL_GPL(handle_bad_irq);
|
2006-06-29 17:24:51 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Special, empty irq handler:
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
irqreturn_t no_action(int cpl, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
2014-03-22 16:20:31 +08:00
|
|
|
EXPORT_SYMBOL_GPL(no_action);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-24 18:46:22 +08:00
|
|
|
static void warn_no_thread(unsigned int irq, struct irqaction *action)
|
|
|
|
{
|
|
|
|
if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
|
|
|
|
return;
|
|
|
|
|
|
|
|
printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
|
|
|
|
"but no thread function available.", irq, action->name);
|
|
|
|
}
|
|
|
|
|
2014-02-15 08:55:19 +08:00
|
|
|
void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action)
|
2011-02-24 07:52:13 +08:00
|
|
|
{
|
|
|
|
/*
|
2012-03-22 00:22:13 +08:00
|
|
|
* In case the thread crashed and was killed we just pretend that
|
|
|
|
* we handled the interrupt. The hardirq handler has disabled the
|
|
|
|
* device interrupt, so no irq storm is lurking.
|
|
|
|
*/
|
|
|
|
if (action->thread->flags & PF_EXITING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wake up the handler thread for this action. If the
|
2011-02-24 07:52:13 +08:00
|
|
|
* RUNTHREAD bit is already set, nothing to do.
|
|
|
|
*/
|
2012-03-22 00:22:13 +08:00
|
|
|
if (test_and_set_bit(IRQTF_RUNTHREAD, &action->thread_flags))
|
2011-02-24 07:52:13 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's safe to OR the mask lockless here. We have only two
|
|
|
|
* places which write to threads_oneshot: This code and the
|
|
|
|
* irq thread.
|
|
|
|
*
|
|
|
|
* This code is the hard irq context and can never run on two
|
|
|
|
* cpus in parallel. If it ever does we have more serious
|
|
|
|
* problems than this bitmask.
|
|
|
|
*
|
|
|
|
* The irq threads of this irq which clear their "running" bit
|
|
|
|
* in threads_oneshot are serialized via desc->lock against
|
|
|
|
* each other and they are serialized against this code by
|
|
|
|
* IRQS_INPROGRESS.
|
|
|
|
*
|
|
|
|
* Hard irq handler:
|
|
|
|
*
|
|
|
|
* spin_lock(desc->lock);
|
|
|
|
* desc->state |= IRQS_INPROGRESS;
|
|
|
|
* spin_unlock(desc->lock);
|
|
|
|
* set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
|
|
|
|
* desc->threads_oneshot |= mask;
|
|
|
|
* spin_lock(desc->lock);
|
|
|
|
* desc->state &= ~IRQS_INPROGRESS;
|
|
|
|
* spin_unlock(desc->lock);
|
|
|
|
*
|
|
|
|
* irq thread:
|
|
|
|
*
|
|
|
|
* again:
|
|
|
|
* spin_lock(desc->lock);
|
|
|
|
* if (desc->state & IRQS_INPROGRESS) {
|
|
|
|
* spin_unlock(desc->lock);
|
|
|
|
* while(desc->state & IRQS_INPROGRESS)
|
|
|
|
* cpu_relax();
|
|
|
|
* goto again;
|
|
|
|
* }
|
|
|
|
* if (!test_bit(IRQTF_RUNTHREAD, &action->thread_flags))
|
|
|
|
* desc->threads_oneshot &= ~mask;
|
|
|
|
* spin_unlock(desc->lock);
|
|
|
|
*
|
|
|
|
* So either the thread waits for us to clear IRQS_INPROGRESS
|
|
|
|
* or we are waiting in the flow handler for desc->lock to be
|
|
|
|
* released before we reach this point. The thread also checks
|
|
|
|
* IRQTF_RUNTHREAD under desc->lock. If set it leaves
|
|
|
|
* threads_oneshot untouched and runs the thread another time.
|
|
|
|
*/
|
|
|
|
desc->threads_oneshot |= action->thread_mask;
|
2011-12-03 00:24:12 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We increment the threads_active counter in case we wake up
|
|
|
|
* the irq thread. The irq thread decrements the counter when
|
|
|
|
* it returns from the handler or in the exit path and wakes
|
|
|
|
* up waiters which are stuck in synchronize_irq() when the
|
|
|
|
* active count becomes zero. synchronize_irq() is serialized
|
|
|
|
* against this code (hard irq handler) via IRQS_INPROGRESS
|
|
|
|
* like the finalize_oneshot() code. See comment above.
|
|
|
|
*/
|
|
|
|
atomic_inc(&desc->threads_active);
|
|
|
|
|
2011-02-24 07:52:13 +08:00
|
|
|
wake_up_process(action->thread);
|
|
|
|
}
|
|
|
|
|
2016-06-18 06:00:20 +08:00
|
|
|
irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-02-22 19:50:12 +08:00
|
|
|
irqreturn_t retval = IRQ_NONE;
|
2016-06-18 06:00:20 +08:00
|
|
|
unsigned int irq = desc->irq_data.irq;
|
2016-01-14 17:54:13 +08:00
|
|
|
struct irqaction *action;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-06-23 22:11:07 +08:00
|
|
|
record_irq_time(desc);
|
|
|
|
|
2016-01-14 17:54:13 +08:00
|
|
|
for_each_action_of_desc(desc, action) {
|
2011-02-22 19:50:12 +08:00
|
|
|
irqreturn_t res;
|
|
|
|
|
lockdep: Introduce wait-type checks
Extend lockdep to validate lock wait-type context.
The current wait-types are:
LD_WAIT_FREE, /* wait free, rcu etc.. */
LD_WAIT_SPIN, /* spin loops, raw_spinlock_t etc.. */
LD_WAIT_CONFIG, /* CONFIG_PREEMPT_LOCK, spinlock_t etc.. */
LD_WAIT_SLEEP, /* sleeping locks, mutex_t etc.. */
Where lockdep validates that the current lock (the one being acquired)
fits in the current wait-context (as generated by the held stack).
This ensures that there is no attempt to acquire mutexes while holding
spinlocks, to acquire spinlocks while holding raw_spinlocks and so on. In
other words, its a more fancy might_sleep().
Obviously RCU made the entire ordeal more complex than a simple single
value test because RCU can be acquired in (pretty much) any context and
while it presents a context to nested locks it is not the same as it
got acquired in.
Therefore its necessary to split the wait_type into two values, one
representing the acquire (outer) and one representing the nested context
(inner). For most 'normal' locks these two are the same.
[ To make static initialization easier we have the rule that:
.outer == INV means .outer == .inner; because INV == 0. ]
It further means that its required to find the minimal .inner of the held
stack to compare against the outer of the new lock; because while 'normal'
RCU presents a CONFIG type to nested locks, if it is taken while already
holding a SPIN type it obviously doesn't relax the rules.
Below is an example output generated by the trivial test code:
raw_spin_lock(&foo);
spin_lock(&bar);
spin_unlock(&bar);
raw_spin_unlock(&foo);
[ BUG: Invalid wait context ]
-----------------------------
swapper/0/1 is trying to lock:
ffffc90000013f20 (&bar){....}-{3:3}, at: kernel_init+0xdb/0x187
other info that might help us debug this:
1 lock held by swapper/0/1:
#0: ffffc90000013ee0 (&foo){+.+.}-{2:2}, at: kernel_init+0xd1/0x187
The way to read it is to look at the new -{n,m} part in the lock
description; -{3:3} for the attempted lock, and try and match that up to
the held locks, which in this case is the one: -{2,2}.
This tells that the acquiring lock requires a more relaxed environment than
presented by the lock stack.
Currently only the normal locks and RCU are converted, the rest of the
lockdep users defaults to .inner = INV which is ignored. More conversions
can be done when desired.
The check for spinlock_t nesting is not enabled by default. It's a separate
config option for now as there are known problems which are currently
addressed. The config option allows to identify these problems and to
verify that the solutions found are indeed solving them.
The config switch will be removed and the checks will permanently enabled
once the vast majority of issues has been addressed.
[ bigeasy: Move LD_WAIT_FREE,… out of CONFIG_LOCKDEP to avoid compile
failure with CONFIG_DEBUG_SPINLOCK + !CONFIG_LOCKDEP]
[ tglx: Add the config option ]
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200321113242.427089655@linutronix.de
2020-03-21 19:26:01 +08:00
|
|
|
/*
|
|
|
|
* If this IRQ would be threaded under force_irqthreads, mark it so.
|
|
|
|
*/
|
|
|
|
if (irq_settings_can_thread(desc) &&
|
|
|
|
!(action->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)))
|
2020-03-31 10:14:28 +08:00
|
|
|
lockdep_hardirq_threaded();
|
lockdep: Introduce wait-type checks
Extend lockdep to validate lock wait-type context.
The current wait-types are:
LD_WAIT_FREE, /* wait free, rcu etc.. */
LD_WAIT_SPIN, /* spin loops, raw_spinlock_t etc.. */
LD_WAIT_CONFIG, /* CONFIG_PREEMPT_LOCK, spinlock_t etc.. */
LD_WAIT_SLEEP, /* sleeping locks, mutex_t etc.. */
Where lockdep validates that the current lock (the one being acquired)
fits in the current wait-context (as generated by the held stack).
This ensures that there is no attempt to acquire mutexes while holding
spinlocks, to acquire spinlocks while holding raw_spinlocks and so on. In
other words, its a more fancy might_sleep().
Obviously RCU made the entire ordeal more complex than a simple single
value test because RCU can be acquired in (pretty much) any context and
while it presents a context to nested locks it is not the same as it
got acquired in.
Therefore its necessary to split the wait_type into two values, one
representing the acquire (outer) and one representing the nested context
(inner). For most 'normal' locks these two are the same.
[ To make static initialization easier we have the rule that:
.outer == INV means .outer == .inner; because INV == 0. ]
It further means that its required to find the minimal .inner of the held
stack to compare against the outer of the new lock; because while 'normal'
RCU presents a CONFIG type to nested locks, if it is taken while already
holding a SPIN type it obviously doesn't relax the rules.
Below is an example output generated by the trivial test code:
raw_spin_lock(&foo);
spin_lock(&bar);
spin_unlock(&bar);
raw_spin_unlock(&foo);
[ BUG: Invalid wait context ]
-----------------------------
swapper/0/1 is trying to lock:
ffffc90000013f20 (&bar){....}-{3:3}, at: kernel_init+0xdb/0x187
other info that might help us debug this:
1 lock held by swapper/0/1:
#0: ffffc90000013ee0 (&foo){+.+.}-{2:2}, at: kernel_init+0xd1/0x187
The way to read it is to look at the new -{n,m} part in the lock
description; -{3:3} for the attempted lock, and try and match that up to
the held locks, which in this case is the one: -{2,2}.
This tells that the acquiring lock requires a more relaxed environment than
presented by the lock stack.
Currently only the normal locks and RCU are converted, the rest of the
lockdep users defaults to .inner = INV which is ignored. More conversions
can be done when desired.
The check for spinlock_t nesting is not enabled by default. It's a separate
config option for now as there are known problems which are currently
addressed. The config option allows to identify these problems and to
verify that the solutions found are indeed solving them.
The config switch will be removed and the checks will permanently enabled
once the vast majority of issues has been addressed.
[ bigeasy: Move LD_WAIT_FREE,… out of CONFIG_LOCKDEP to avoid compile
failure with CONFIG_DEBUG_SPINLOCK + !CONFIG_LOCKDEP]
[ tglx: Add the config option ]
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200321113242.427089655@linutronix.de
2020-03-21 19:26:01 +08:00
|
|
|
|
2009-02-26 23:11:05 +08:00
|
|
|
trace_irq_handler_entry(irq, action);
|
2011-02-22 19:50:12 +08:00
|
|
|
res = action->handler(irq, action->dev_id);
|
|
|
|
trace_irq_handler_exit(irq, action, res);
|
2009-03-24 01:28:15 +08:00
|
|
|
|
2019-03-26 03:32:28 +08:00
|
|
|
if (WARN_ONCE(!irqs_disabled(),"irq %u handler %pS enabled interrupts\n",
|
2011-02-26 00:17:18 +08:00
|
|
|
irq, action->handler))
|
2011-02-03 06:58:19 +08:00
|
|
|
local_irq_disable();
|
|
|
|
|
2011-02-22 19:50:12 +08:00
|
|
|
switch (res) {
|
2009-03-24 01:28:15 +08:00
|
|
|
case IRQ_WAKE_THREAD:
|
2009-03-24 18:46:22 +08:00
|
|
|
/*
|
|
|
|
* Catch drivers which return WAKE_THREAD but
|
|
|
|
* did not set up a thread function
|
|
|
|
*/
|
|
|
|
if (unlikely(!action->thread_fn)) {
|
|
|
|
warn_no_thread(irq, action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-15 08:55:19 +08:00
|
|
|
__irq_wake_thread(desc, action);
|
2009-03-24 01:28:15 +08:00
|
|
|
|
2019-01-15 04:36:33 +08:00
|
|
|
/* Fall through - to add to randomness */
|
2009-03-24 01:28:15 +08:00
|
|
|
case IRQ_HANDLED:
|
2016-06-18 06:00:20 +08:00
|
|
|
*flags |= action->flags;
|
2009-03-24 01:28:15 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-22 19:50:12 +08:00
|
|
|
retval |= res;
|
2016-01-13 21:07:25 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-06-18 06:00:20 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
irqreturn_t handle_irq_event_percpu(struct irq_desc *desc)
|
|
|
|
{
|
|
|
|
irqreturn_t retval;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
retval = __handle_irq_event_percpu(desc, &flags);
|
|
|
|
|
|
|
|
add_interrupt_randomness(desc->irq_data.irq, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-02-07 08:08:49 +08:00
|
|
|
if (!noirqdebug)
|
2015-06-04 12:13:28 +08:00
|
|
|
note_interrupt(desc, retval);
|
2011-02-07 08:40:27 +08:00
|
|
|
return retval;
|
2011-02-07 08:08:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
irqreturn_t handle_irq_event(struct irq_desc *desc)
|
|
|
|
{
|
|
|
|
irqreturn_t ret;
|
|
|
|
|
2011-02-08 19:17:57 +08:00
|
|
|
desc->istate &= ~IRQS_PENDING;
|
2011-03-28 20:10:52 +08:00
|
|
|
irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
|
2011-02-07 08:08:49 +08:00
|
|
|
raw_spin_unlock(&desc->lock);
|
|
|
|
|
2015-09-02 10:24:55 +08:00
|
|
|
ret = handle_irq_event_percpu(desc);
|
2011-02-07 08:08:49 +08:00
|
|
|
|
|
|
|
raw_spin_lock(&desc->lock);
|
2011-03-28 20:10:52 +08:00
|
|
|
irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
|
2011-02-07 08:08:49 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2018-03-08 07:57:27 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_GENERIC_IRQ_MULTI_HANDLER
|
|
|
|
int __init set_handle_irq(void (*handle_irq)(struct pt_regs *))
|
|
|
|
{
|
|
|
|
if (handle_arch_irq)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
handle_arch_irq = handle_irq;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|