2007-05-11 07:22:32 +02:00
|
|
|
/*
|
2007-10-16 10:27:00 +02:00
|
|
|
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-17 00:20:36 +02:00
|
|
|
* Licensed under the GPL
|
|
|
|
* Derived (i.e. mostly copied) from arch/i386/kernel/irq.c:
|
|
|
|
* Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
|
|
|
|
*/
|
|
|
|
|
2007-10-16 10:27:00 +02:00
|
|
|
#include "linux/cpumask.h"
|
|
|
|
#include "linux/hardirq.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "linux/interrupt.h"
|
2007-10-16 10:27:00 +02:00
|
|
|
#include "linux/kernel_stat.h"
|
|
|
|
#include "linux/module.h"
|
2009-10-07 15:09:06 +02:00
|
|
|
#include "linux/sched.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "linux/seq_file.h"
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include "linux/slab.h"
|
2007-10-16 10:27:00 +02:00
|
|
|
#include "as-layout.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "kern_util.h"
|
2005-09-04 00:57:45 +02:00
|
|
|
#include "os.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic, controller-independent functions:
|
|
|
|
*/
|
|
|
|
|
|
|
|
int show_interrupts(struct seq_file *p, void *v)
|
|
|
|
{
|
|
|
|
int i = *(loff_t *) v, j;
|
|
|
|
struct irqaction * action;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
seq_printf(p, " ");
|
|
|
|
for_each_online_cpu(j)
|
|
|
|
seq_printf(p, "CPU%d ",j);
|
|
|
|
seq_putc(p, '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < NR_IRQS) {
|
2009-11-17 16:46:45 +01:00
|
|
|
raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
action = irq_desc[i].action;
|
2007-05-11 07:22:32 +02:00
|
|
|
if (!action)
|
2005-04-17 00:20:36 +02:00
|
|
|
goto skip;
|
|
|
|
seq_printf(p, "%3d: ",i);
|
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
seq_printf(p, "%10u ", kstat_irqs(i));
|
|
|
|
#else
|
|
|
|
for_each_online_cpu(j)
|
2009-01-11 09:29:15 +01:00
|
|
|
seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
|
2005-04-17 00:20:36 +02:00
|
|
|
#endif
|
[PATCH] genirq: rename desc->handler to desc->chip
This patch-queue improves the generic IRQ layer to be truly generic, by adding
various abstractions and features to it, without impacting existing
functionality.
While the queue can be best described as "fix and improve everything in the
generic IRQ layer that we could think of", and thus it consists of many
smaller features and lots of cleanups, the one feature that stands out most is
the new 'irq chip' abstraction.
The irq-chip abstraction is about describing and coding and IRQ controller
driver by mapping its raw hardware capabilities [and quirks, if needed] in a
straightforward way, without having to think about "IRQ flow"
(level/edge/etc.) type of details.
This stands in contrast with the current 'irq-type' model of genirq
architectures, which 'mixes' raw hardware capabilities with 'flow' details.
The patchset supports both types of irq controller designs at once, and
converts i386 and x86_64 to the new irq-chip design.
As a bonus side-effect of the irq-chip approach, chained interrupt controllers
(master/slave PIC constructs, etc.) are now supported by design as well.
The end result of this patchset intends to be simpler architecture-level code
and more consolidation between architectures.
We reused many bits of code and many concepts from Russell King's ARM IRQ
layer, the merging of which was one of the motivations for this patchset.
This patch:
rename desc->handler to desc->chip.
Originally i did not want to do this, because it's a big patch. But having
both "desc->handler", "desc->handle_irq" and "action->handler" caused a
large degree of confusion and made the code appear alot less clean than it
truly is.
I have also attempted a dual approach as well by introducing a
desc->chip alias - but that just wasnt robust enough and broke
frequently.
So lets get over with this quickly. The conversion was done automatically
via scripts and converts all the code in the kernel.
This renaming patch is the first one amongst the patches, so that the
remaining patches can stay flexible and can be merged and split up
without having some big monolithic patch act as a merge barrier.
[akpm@osdl.org: build fix]
[akpm@osdl.org: another build fix]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-29 11:24:36 +02:00
|
|
|
seq_printf(p, " %14s", irq_desc[i].chip->typename);
|
2005-04-17 00:20:36 +02:00
|
|
|
seq_printf(p, " %s", action->name);
|
|
|
|
|
|
|
|
for (action=action->next; action; action = action->next)
|
|
|
|
seq_printf(p, ", %s", action->name);
|
|
|
|
|
|
|
|
seq_putc(p, '\n');
|
|
|
|
skip:
|
2009-11-17 16:46:45 +01:00
|
|
|
raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
|
2007-10-16 10:27:00 +02:00
|
|
|
} else if (i == NR_IRQS)
|
2005-04-17 00:20:36 +02:00
|
|
|
seq_putc(p, '\n');
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-06 23:51:27 +02:00
|
|
|
/*
|
|
|
|
* This list is accessed under irq_lock, except in sigio_handler,
|
|
|
|
* where it is safe from being modified. IRQ handlers won't change it -
|
|
|
|
* if an IRQ source has vanished, it will be freed by free_irqs just
|
|
|
|
* before returning from sigio_handler. That will process a separate
|
|
|
|
* list of irqs to free, with its own locking, coming back here to
|
|
|
|
* remove list elements, taking the irq_lock to do so.
|
|
|
|
*/
|
2007-02-10 10:44:23 +01:00
|
|
|
static struct irq_fd *active_fds = NULL;
|
2006-03-27 11:14:31 +02:00
|
|
|
static struct irq_fd **last_irq_ptr = &active_fds;
|
|
|
|
|
|
|
|
extern void free_irqs(void);
|
|
|
|
|
2007-10-16 10:26:58 +02:00
|
|
|
void sigio_handler(int sig, struct uml_pt_regs *regs)
|
2006-03-27 11:14:31 +02:00
|
|
|
{
|
|
|
|
struct irq_fd *irq_fd;
|
|
|
|
int n;
|
|
|
|
|
2006-05-01 21:15:57 +02:00
|
|
|
if (smp_sigio_handler())
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (1) {
|
2006-03-27 11:14:31 +02:00
|
|
|
n = os_waiting_for_events(active_fds);
|
|
|
|
if (n <= 0) {
|
2007-10-16 10:27:00 +02:00
|
|
|
if (n == -EINTR)
|
|
|
|
continue;
|
2006-03-27 11:14:31 +02:00
|
|
|
else break;
|
|
|
|
}
|
|
|
|
|
2007-10-16 10:27:00 +02:00
|
|
|
for (irq_fd = active_fds; irq_fd != NULL;
|
|
|
|
irq_fd = irq_fd->next) {
|
2006-05-01 21:15:57 +02:00
|
|
|
if (irq_fd->current_events != 0) {
|
2006-03-27 11:14:31 +02:00
|
|
|
irq_fd->current_events = 0;
|
|
|
|
do_IRQ(irq_fd->irq, regs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free_irqs();
|
|
|
|
}
|
|
|
|
|
2006-07-10 13:45:10 +02:00
|
|
|
static DEFINE_SPINLOCK(irq_lock);
|
|
|
|
|
2008-07-24 06:28:47 +02:00
|
|
|
static int activate_fd(int irq, int fd, int type, void *dev_id)
|
2006-03-27 11:14:31 +02:00
|
|
|
{
|
|
|
|
struct pollfd *tmp_pfd;
|
|
|
|
struct irq_fd *new_fd, *irq_fd;
|
|
|
|
unsigned long flags;
|
2008-02-05 07:31:04 +01:00
|
|
|
int events, err, n;
|
2006-03-27 11:14:31 +02:00
|
|
|
|
2008-02-05 07:31:04 +01:00
|
|
|
err = os_set_fd_async(fd);
|
2006-05-01 21:15:57 +02:00
|
|
|
if (err < 0)
|
2006-03-27 11:14:31 +02:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
2007-02-10 10:44:23 +01:00
|
|
|
new_fd = kmalloc(sizeof(struct irq_fd), GFP_KERNEL);
|
2006-05-01 21:15:57 +02:00
|
|
|
if (new_fd == NULL)
|
2006-03-27 11:14:31 +02:00
|
|
|
goto out;
|
|
|
|
|
2006-05-01 21:15:57 +02:00
|
|
|
if (type == IRQ_READ)
|
|
|
|
events = UM_POLLIN | UM_POLLPRI;
|
2007-10-16 10:27:00 +02:00
|
|
|
else events = UM_POLLOUT;
|
2006-03-27 11:14:31 +02:00
|
|
|
*new_fd = ((struct irq_fd) { .next = NULL,
|
|
|
|
.id = dev_id,
|
|
|
|
.fd = fd,
|
|
|
|
.type = type,
|
|
|
|
.irq = irq,
|
|
|
|
.events = events,
|
|
|
|
.current_events = 0 } );
|
|
|
|
|
2007-03-08 05:41:13 +01:00
|
|
|
err = -EBUSY;
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
2006-05-01 21:15:57 +02:00
|
|
|
for (irq_fd = active_fds; irq_fd != NULL; irq_fd = irq_fd->next) {
|
|
|
|
if ((irq_fd->fd == fd) && (irq_fd->type == type)) {
|
2007-10-16 10:27:00 +02:00
|
|
|
printk(KERN_ERR "Registering fd %d twice\n", fd);
|
|
|
|
printk(KERN_ERR "Irqs : %d, %d\n", irq_fd->irq, irq);
|
|
|
|
printk(KERN_ERR "Ids : 0x%p, 0x%p\n", irq_fd->id,
|
|
|
|
dev_id);
|
2006-03-27 11:14:31 +02:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-01 21:15:57 +02:00
|
|
|
if (type == IRQ_WRITE)
|
2006-03-27 11:14:31 +02:00
|
|
|
fd = -1;
|
|
|
|
|
|
|
|
tmp_pfd = NULL;
|
|
|
|
n = 0;
|
|
|
|
|
2006-05-01 21:15:57 +02:00
|
|
|
while (1) {
|
2006-03-27 11:14:31 +02:00
|
|
|
n = os_create_pollfd(fd, events, tmp_pfd, n);
|
|
|
|
if (n == 0)
|
|
|
|
break;
|
|
|
|
|
2007-10-16 10:27:00 +02:00
|
|
|
/*
|
|
|
|
* n > 0
|
2006-03-27 11:14:31 +02:00
|
|
|
* It means we couldn't put new pollfd to current pollfds
|
|
|
|
* and tmp_fds is NULL or too small for new pollfds array.
|
|
|
|
* Needed size is equal to n as minimum.
|
|
|
|
*
|
|
|
|
* Here we have to drop the lock in order to call
|
|
|
|
* kmalloc, which might sleep.
|
|
|
|
* If something else came in and changed the pollfds array
|
|
|
|
* so we will not be able to put new pollfd struct to pollfds
|
|
|
|
* then we free the buffer tmp_fds and try again.
|
|
|
|
*/
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2006-05-01 21:15:57 +02:00
|
|
|
kfree(tmp_pfd);
|
2006-03-27 11:14:31 +02:00
|
|
|
|
2007-02-10 10:44:23 +01:00
|
|
|
tmp_pfd = kmalloc(n, GFP_KERNEL);
|
2006-03-27 11:14:31 +02:00
|
|
|
if (tmp_pfd == NULL)
|
|
|
|
goto out_kfree;
|
|
|
|
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*last_irq_ptr = new_fd;
|
|
|
|
last_irq_ptr = &new_fd->next;
|
|
|
|
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
|
2007-10-16 10:27:00 +02:00
|
|
|
/*
|
|
|
|
* This calls activate_fd, so it has to be outside the critical
|
2006-03-27 11:14:31 +02:00
|
|
|
* section.
|
|
|
|
*/
|
2006-07-10 13:45:11 +02:00
|
|
|
maybe_sigio_broken(fd, (type == IRQ_READ));
|
2006-03-27 11:14:31 +02:00
|
|
|
|
[PATCH] uml: SIGIO cleanups
- Various cleanups in the sigio code.
- Removed explicit zero-initializations of a few structures.
- Improved some error messages.
- An API change - there was an asymmetry between reactivate_fd calling
maybe_sigio_broken, which goes through all the machinery of figuring out if
a file descriptor supports SIGIO and applying the workaround to it if not,
and deactivate_fd, which just turns off the descriptor.
This is changed so that only activate_fd calls maybe_sigio_broken, when
the descriptor is first seen. reactivate_fd now calls add_sigio_fd, which
is symmetric with ignore_sigio_fd.
This removes a recursion which makes a critical section look more critical
than it really was, obsoleting a big comment to that effect. This requires
keeping track of all descriptors which are getting the SIGIO treatment, not
just the ones being polled at any given moment, so that reactivate_fd,
through add_sigio_fd, doesn't try to tell the SIGIO thread about descriptors
it doesn't care about.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-09-26 08:33:04 +02:00
|
|
|
return 0;
|
2006-03-27 11:14:31 +02:00
|
|
|
|
|
|
|
out_unlock:
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
out_kfree:
|
|
|
|
kfree(new_fd);
|
|
|
|
out:
|
[PATCH] uml: SIGIO cleanups
- Various cleanups in the sigio code.
- Removed explicit zero-initializations of a few structures.
- Improved some error messages.
- An API change - there was an asymmetry between reactivate_fd calling
maybe_sigio_broken, which goes through all the machinery of figuring out if
a file descriptor supports SIGIO and applying the workaround to it if not,
and deactivate_fd, which just turns off the descriptor.
This is changed so that only activate_fd calls maybe_sigio_broken, when
the descriptor is first seen. reactivate_fd now calls add_sigio_fd, which
is symmetric with ignore_sigio_fd.
This removes a recursion which makes a critical section look more critical
than it really was, obsoleting a big comment to that effect. This requires
keeping track of all descriptors which are getting the SIGIO treatment, not
just the ones being polled at any given moment, so that reactivate_fd,
through add_sigio_fd, doesn't try to tell the SIGIO thread about descriptors
it doesn't care about.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-09-26 08:33:04 +02:00
|
|
|
return err;
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
os_free_irq_by_cb(test, arg, active_fds, &last_irq_ptr);
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct irq_and_dev {
|
|
|
|
int irq;
|
|
|
|
void *dev;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int same_irq_and_dev(struct irq_fd *irq, void *d)
|
|
|
|
{
|
|
|
|
struct irq_and_dev *data = d;
|
|
|
|
|
2006-05-01 21:15:57 +02:00
|
|
|
return ((irq->irq == data->irq) && (irq->id == data->dev));
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
2008-07-24 06:28:47 +02:00
|
|
|
static void free_irq_by_irq_and_dev(unsigned int irq, void *dev)
|
2006-03-27 11:14:31 +02:00
|
|
|
{
|
|
|
|
struct irq_and_dev data = ((struct irq_and_dev) { .irq = irq,
|
|
|
|
.dev = dev });
|
|
|
|
|
|
|
|
free_irq_by_cb(same_irq_and_dev, &data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int same_fd(struct irq_fd *irq, void *fd)
|
|
|
|
{
|
2006-05-01 21:15:57 +02:00
|
|
|
return (irq->fd == *((int *)fd));
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void free_irq_by_fd(int fd)
|
|
|
|
{
|
|
|
|
free_irq_by_cb(same_fd, &fd);
|
|
|
|
}
|
|
|
|
|
2007-05-06 23:51:27 +02:00
|
|
|
/* Must be called with irq_lock held */
|
2006-03-27 11:14:31 +02:00
|
|
|
static struct irq_fd *find_irq_by_fd(int fd, int irqnum, int *index_out)
|
|
|
|
{
|
|
|
|
struct irq_fd *irq;
|
|
|
|
int i = 0;
|
|
|
|
int fdi;
|
|
|
|
|
2006-05-01 21:15:57 +02:00
|
|
|
for (irq = active_fds; irq != NULL; irq = irq->next) {
|
|
|
|
if ((irq->fd == fd) && (irq->irq == irqnum))
|
|
|
|
break;
|
2006-03-27 11:14:31 +02:00
|
|
|
i++;
|
|
|
|
}
|
2006-05-01 21:15:57 +02:00
|
|
|
if (irq == NULL) {
|
2007-10-16 10:27:00 +02:00
|
|
|
printk(KERN_ERR "find_irq_by_fd doesn't have descriptor %d\n",
|
|
|
|
fd);
|
2006-03-27 11:14:31 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
fdi = os_get_pollfd(i);
|
2006-05-01 21:15:57 +02:00
|
|
|
if ((fdi != -1) && (fdi != fd)) {
|
2007-10-16 10:27:00 +02:00
|
|
|
printk(KERN_ERR "find_irq_by_fd - mismatch between active_fds "
|
|
|
|
"and pollfds, fd %d vs %d, need %d\n", irq->fd,
|
2006-03-27 11:14:31 +02:00
|
|
|
fdi, fd);
|
|
|
|
irq = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
*index_out = i;
|
|
|
|
out:
|
2006-05-01 21:15:57 +02:00
|
|
|
return irq;
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void reactivate_fd(int fd, int irqnum)
|
|
|
|
{
|
|
|
|
struct irq_fd *irq;
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
irq = find_irq_by_fd(fd, irqnum, &i);
|
2006-05-01 21:15:57 +02:00
|
|
|
if (irq == NULL) {
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
os_set_pollfd(i, irq->fd);
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
|
[PATCH] uml: SIGIO cleanups
- Various cleanups in the sigio code.
- Removed explicit zero-initializations of a few structures.
- Improved some error messages.
- An API change - there was an asymmetry between reactivate_fd calling
maybe_sigio_broken, which goes through all the machinery of figuring out if
a file descriptor supports SIGIO and applying the workaround to it if not,
and deactivate_fd, which just turns off the descriptor.
This is changed so that only activate_fd calls maybe_sigio_broken, when
the descriptor is first seen. reactivate_fd now calls add_sigio_fd, which
is symmetric with ignore_sigio_fd.
This removes a recursion which makes a critical section look more critical
than it really was, obsoleting a big comment to that effect. This requires
keeping track of all descriptors which are getting the SIGIO treatment, not
just the ones being polled at any given moment, so that reactivate_fd,
through add_sigio_fd, doesn't try to tell the SIGIO thread about descriptors
it doesn't care about.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-09-26 08:33:04 +02:00
|
|
|
add_sigio_fd(fd);
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void deactivate_fd(int fd, int irqnum)
|
|
|
|
{
|
|
|
|
struct irq_fd *irq;
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
2006-03-27 11:14:31 +02:00
|
|
|
irq = find_irq_by_fd(fd, irqnum, &i);
|
2007-10-16 10:27:00 +02:00
|
|
|
if (irq == NULL) {
|
[PATCH] uml: SIGIO cleanups
- Various cleanups in the sigio code.
- Removed explicit zero-initializations of a few structures.
- Improved some error messages.
- An API change - there was an asymmetry between reactivate_fd calling
maybe_sigio_broken, which goes through all the machinery of figuring out if
a file descriptor supports SIGIO and applying the workaround to it if not,
and deactivate_fd, which just turns off the descriptor.
This is changed so that only activate_fd calls maybe_sigio_broken, when
the descriptor is first seen. reactivate_fd now calls add_sigio_fd, which
is symmetric with ignore_sigio_fd.
This removes a recursion which makes a critical section look more critical
than it really was, obsoleting a big comment to that effect. This requires
keeping track of all descriptors which are getting the SIGIO treatment, not
just the ones being polled at any given moment, so that reactivate_fd,
through add_sigio_fd, doesn't try to tell the SIGIO thread about descriptors
it doesn't care about.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-09-26 08:33:04 +02:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-27 11:14:31 +02:00
|
|
|
os_set_pollfd(i, -1);
|
2006-07-10 13:45:10 +02:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
[PATCH] uml: SIGIO cleanups
- Various cleanups in the sigio code.
- Removed explicit zero-initializations of a few structures.
- Improved some error messages.
- An API change - there was an asymmetry between reactivate_fd calling
maybe_sigio_broken, which goes through all the machinery of figuring out if
a file descriptor supports SIGIO and applying the workaround to it if not,
and deactivate_fd, which just turns off the descriptor.
This is changed so that only activate_fd calls maybe_sigio_broken, when
the descriptor is first seen. reactivate_fd now calls add_sigio_fd, which
is symmetric with ignore_sigio_fd.
This removes a recursion which makes a critical section look more critical
than it really was, obsoleting a big comment to that effect. This requires
keeping track of all descriptors which are getting the SIGIO treatment, not
just the ones being polled at any given moment, so that reactivate_fd,
through add_sigio_fd, doesn't try to tell the SIGIO thread about descriptors
it doesn't care about.
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-09-26 08:33:04 +02:00
|
|
|
|
|
|
|
ignore_sigio_fd(fd);
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
2007-05-06 23:51:27 +02:00
|
|
|
/*
|
|
|
|
* Called just before shutdown in order to provide a clean exec
|
|
|
|
* environment in case the system is rebooting. No locking because
|
|
|
|
* that would cause a pointless shutdown hang if something hadn't
|
|
|
|
* released the lock.
|
|
|
|
*/
|
2006-03-27 11:14:31 +02:00
|
|
|
int deactivate_all_fds(void)
|
|
|
|
{
|
|
|
|
struct irq_fd *irq;
|
|
|
|
int err;
|
|
|
|
|
2006-05-01 21:15:57 +02:00
|
|
|
for (irq = active_fds; irq != NULL; irq = irq->next) {
|
2006-03-27 11:14:31 +02:00
|
|
|
err = os_clear_fd_async(irq->fd);
|
2006-05-01 21:15:57 +02:00
|
|
|
if (err)
|
|
|
|
return err;
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
/* If there is a signal already queued, after unblocking ignore it */
|
|
|
|
os_set_ioignore();
|
|
|
|
|
2006-05-01 21:15:57 +02:00
|
|
|
return 0;
|
2006-03-27 11:14:31 +02:00
|
|
|
}
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2007-10-20 01:23:03 +02:00
|
|
|
* do_IRQ handles all normal device IRQs (the special
|
2005-04-17 00:20:36 +02:00
|
|
|
* SMP cross-CPU interrupts have their own specific
|
|
|
|
* handlers).
|
|
|
|
*/
|
2007-10-16 10:26:58 +02:00
|
|
|
unsigned int do_IRQ(int irq, struct uml_pt_regs *regs)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-10-08 23:49:34 +02:00
|
|
|
struct pt_regs *old_regs = set_irq_regs((struct pt_regs *)regs);
|
|
|
|
irq_enter();
|
|
|
|
__do_IRQ(irq);
|
|
|
|
irq_exit();
|
|
|
|
set_irq_regs(old_regs);
|
|
|
|
return 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int um_request_irq(unsigned int irq, int fd, int type,
|
2006-10-09 13:19:47 +02:00
|
|
|
irq_handler_t handler,
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned long irqflags, const char * devname,
|
|
|
|
void *dev_id)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2007-11-15 02:00:23 +01:00
|
|
|
if (fd != -1) {
|
2005-04-17 00:20:36 +02:00
|
|
|
err = activate_fd(irq, fd, type, dev_id);
|
2007-11-15 02:00:23 +01:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return request_irq(irq, handler, irqflags, devname, dev_id);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2007-11-15 02:00:23 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
EXPORT_SYMBOL(um_request_irq);
|
|
|
|
EXPORT_SYMBOL(reactivate_fd);
|
|
|
|
|
2007-10-16 10:27:00 +02:00
|
|
|
/*
|
2009-06-17 00:33:29 +02:00
|
|
|
* irq_chip must define (startup || enable) &&
|
2007-10-16 10:27:00 +02:00
|
|
|
* (shutdown || disable) && end
|
|
|
|
*/
|
2005-04-17 00:20:36 +02:00
|
|
|
static void dummy(unsigned int irq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
[PATCH] uml: add and use generic hw_controller_type->release
With Chris Wedgwood <cw@f00f.org>
Currently UML must explicitly call the UML-specific
free_irq_by_irq_and_dev() for each free_irq call it's done.
This is needed because ->shutdown and/or ->disable are only called when the
last "action" for that irq is removed.
Instead, for UML shared IRQs (UML IRQs are very often, if not always,
shared), for each dev_id some setup is done, which must be cleared on the
release of that fd. For instance, for each open console a new instance
(i.e. new dev_id) of the same IRQ is requested().
Exactly, a fd is stored in an array (pollfds), which is after read by a
host thread and passed to poll(). Each event registered by poll() triggers
an interrupt. So, for each free_irq() we must remove the corresponding
host fd from the table, which we do via this -release() method.
In this patch we add an appropriate hook for this, and remove all uses of
it by pointing the hook to the said procedure; this is safe to do since the
said procedure.
Also some cosmetic improvements are included.
This is heavily based on some work by Chris Wedgwood, which however didn't
get the patch merged for something I'd call a "misunderstanding" (the need
for this patch wasn't cleanly explained, thus adding the generic hook was
felt as undesirable).
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
CC: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-22 02:16:19 +02:00
|
|
|
/* This is used for everything else than the timer. */
|
2009-06-17 00:33:29 +02:00
|
|
|
static struct irq_chip normal_irq_type = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.typename = "SIGIO",
|
[PATCH] uml: add and use generic hw_controller_type->release
With Chris Wedgwood <cw@f00f.org>
Currently UML must explicitly call the UML-specific
free_irq_by_irq_and_dev() for each free_irq call it's done.
This is needed because ->shutdown and/or ->disable are only called when the
last "action" for that irq is removed.
Instead, for UML shared IRQs (UML IRQs are very often, if not always,
shared), for each dev_id some setup is done, which must be cleared on the
release of that fd. For instance, for each open console a new instance
(i.e. new dev_id) of the same IRQ is requested().
Exactly, a fd is stored in an array (pollfds), which is after read by a
host thread and passed to poll(). Each event registered by poll() triggers
an interrupt. So, for each free_irq() we must remove the corresponding
host fd from the table, which we do via this -release() method.
In this patch we add an appropriate hook for this, and remove all uses of
it by pointing the hook to the said procedure; this is safe to do since the
said procedure.
Also some cosmetic improvements are included.
This is heavily based on some work by Chris Wedgwood, which however didn't
get the patch merged for something I'd call a "misunderstanding" (the need
for this patch wasn't cleanly explained, thus adding the generic hook was
felt as undesirable).
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
CC: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-22 02:16:19 +02:00
|
|
|
.release = free_irq_by_irq_and_dev,
|
2005-04-17 00:20:36 +02:00
|
|
|
.disable = dummy,
|
|
|
|
.enable = dummy,
|
|
|
|
.ack = dummy,
|
|
|
|
.end = dummy
|
|
|
|
};
|
|
|
|
|
2009-06-17 00:33:29 +02:00
|
|
|
static struct irq_chip SIGVTALRM_irq_type = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.typename = "SIGVTALRM",
|
[PATCH] uml: add and use generic hw_controller_type->release
With Chris Wedgwood <cw@f00f.org>
Currently UML must explicitly call the UML-specific
free_irq_by_irq_and_dev() for each free_irq call it's done.
This is needed because ->shutdown and/or ->disable are only called when the
last "action" for that irq is removed.
Instead, for UML shared IRQs (UML IRQs are very often, if not always,
shared), for each dev_id some setup is done, which must be cleared on the
release of that fd. For instance, for each open console a new instance
(i.e. new dev_id) of the same IRQ is requested().
Exactly, a fd is stored in an array (pollfds), which is after read by a
host thread and passed to poll(). Each event registered by poll() triggers
an interrupt. So, for each free_irq() we must remove the corresponding
host fd from the table, which we do via this -release() method.
In this patch we add an appropriate hook for this, and remove all uses of
it by pointing the hook to the said procedure; this is safe to do since the
said procedure.
Also some cosmetic improvements are included.
This is heavily based on some work by Chris Wedgwood, which however didn't
get the patch merged for something I'd call a "misunderstanding" (the need
for this patch wasn't cleanly explained, thus adding the generic hook was
felt as undesirable).
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
CC: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-22 02:16:19 +02:00
|
|
|
.release = free_irq_by_irq_and_dev,
|
2005-04-17 00:20:36 +02:00
|
|
|
.shutdown = dummy, /* never called */
|
|
|
|
.disable = dummy,
|
|
|
|
.enable = dummy,
|
|
|
|
.ack = dummy,
|
|
|
|
.end = dummy
|
|
|
|
};
|
|
|
|
|
|
|
|
void __init init_IRQ(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
irq_desc[TIMER_IRQ].status = IRQ_DISABLED;
|
|
|
|
irq_desc[TIMER_IRQ].action = NULL;
|
|
|
|
irq_desc[TIMER_IRQ].depth = 1;
|
[PATCH] genirq: rename desc->handler to desc->chip
This patch-queue improves the generic IRQ layer to be truly generic, by adding
various abstractions and features to it, without impacting existing
functionality.
While the queue can be best described as "fix and improve everything in the
generic IRQ layer that we could think of", and thus it consists of many
smaller features and lots of cleanups, the one feature that stands out most is
the new 'irq chip' abstraction.
The irq-chip abstraction is about describing and coding and IRQ controller
driver by mapping its raw hardware capabilities [and quirks, if needed] in a
straightforward way, without having to think about "IRQ flow"
(level/edge/etc.) type of details.
This stands in contrast with the current 'irq-type' model of genirq
architectures, which 'mixes' raw hardware capabilities with 'flow' details.
The patchset supports both types of irq controller designs at once, and
converts i386 and x86_64 to the new irq-chip design.
As a bonus side-effect of the irq-chip approach, chained interrupt controllers
(master/slave PIC constructs, etc.) are now supported by design as well.
The end result of this patchset intends to be simpler architecture-level code
and more consolidation between architectures.
We reused many bits of code and many concepts from Russell King's ARM IRQ
layer, the merging of which was one of the motivations for this patchset.
This patch:
rename desc->handler to desc->chip.
Originally i did not want to do this, because it's a big patch. But having
both "desc->handler", "desc->handle_irq" and "action->handler" caused a
large degree of confusion and made the code appear alot less clean than it
truly is.
I have also attempted a dual approach as well by introducing a
desc->chip alias - but that just wasnt robust enough and broke
frequently.
So lets get over with this quickly. The conversion was done automatically
via scripts and converts all the code in the kernel.
This renaming patch is the first one amongst the patches, so that the
remaining patches can stay flexible and can be merged and split up
without having some big monolithic patch act as a merge barrier.
[akpm@osdl.org: build fix]
[akpm@osdl.org: another build fix]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-29 11:24:36 +02:00
|
|
|
irq_desc[TIMER_IRQ].chip = &SIGVTALRM_irq_type;
|
2005-04-17 00:20:36 +02:00
|
|
|
enable_irq(TIMER_IRQ);
|
2006-05-01 21:15:57 +02:00
|
|
|
for (i = 1; i < NR_IRQS; i++) {
|
2005-04-17 00:20:36 +02:00
|
|
|
irq_desc[i].status = IRQ_DISABLED;
|
|
|
|
irq_desc[i].action = NULL;
|
|
|
|
irq_desc[i].depth = 1;
|
[PATCH] genirq: rename desc->handler to desc->chip
This patch-queue improves the generic IRQ layer to be truly generic, by adding
various abstractions and features to it, without impacting existing
functionality.
While the queue can be best described as "fix and improve everything in the
generic IRQ layer that we could think of", and thus it consists of many
smaller features and lots of cleanups, the one feature that stands out most is
the new 'irq chip' abstraction.
The irq-chip abstraction is about describing and coding and IRQ controller
driver by mapping its raw hardware capabilities [and quirks, if needed] in a
straightforward way, without having to think about "IRQ flow"
(level/edge/etc.) type of details.
This stands in contrast with the current 'irq-type' model of genirq
architectures, which 'mixes' raw hardware capabilities with 'flow' details.
The patchset supports both types of irq controller designs at once, and
converts i386 and x86_64 to the new irq-chip design.
As a bonus side-effect of the irq-chip approach, chained interrupt controllers
(master/slave PIC constructs, etc.) are now supported by design as well.
The end result of this patchset intends to be simpler architecture-level code
and more consolidation between architectures.
We reused many bits of code and many concepts from Russell King's ARM IRQ
layer, the merging of which was one of the motivations for this patchset.
This patch:
rename desc->handler to desc->chip.
Originally i did not want to do this, because it's a big patch. But having
both "desc->handler", "desc->handle_irq" and "action->handler" caused a
large degree of confusion and made the code appear alot less clean than it
truly is.
I have also attempted a dual approach as well by introducing a
desc->chip alias - but that just wasnt robust enough and broke
frequently.
So lets get over with this quickly. The conversion was done automatically
via scripts and converts all the code in the kernel.
This renaming patch is the first one amongst the patches, so that the
remaining patches can stay flexible and can be merged and split up
without having some big monolithic patch act as a merge barrier.
[akpm@osdl.org: build fix]
[akpm@osdl.org: another build fix]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-29 11:24:36 +02:00
|
|
|
irq_desc[i].chip = &normal_irq_type;
|
2005-04-17 00:20:36 +02:00
|
|
|
enable_irq(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 07:22:34 +02:00
|
|
|
/*
|
|
|
|
* IRQ stack entry and exit:
|
|
|
|
*
|
|
|
|
* Unlike i386, UML doesn't receive IRQs on the normal kernel stack
|
|
|
|
* and switch over to the IRQ stack after some preparation. We use
|
|
|
|
* sigaltstack to receive signals on a separate stack from the start.
|
|
|
|
* These two functions make sure the rest of the kernel won't be too
|
|
|
|
* upset by being on a different stack. The IRQ stack has a
|
|
|
|
* thread_info structure at the bottom so that current et al continue
|
|
|
|
* to work.
|
|
|
|
*
|
|
|
|
* to_irq_stack copies the current task's thread_info to the IRQ stack
|
|
|
|
* thread_info and sets the tasks's stack to point to the IRQ stack.
|
|
|
|
*
|
|
|
|
* from_irq_stack copies the thread_info struct back (flags may have
|
|
|
|
* been modified) and resets the task's stack pointer.
|
|
|
|
*
|
|
|
|
* Tricky bits -
|
|
|
|
*
|
|
|
|
* What happens when two signals race each other? UML doesn't block
|
|
|
|
* signals with sigprocmask, SA_DEFER, or sa_mask, so a second signal
|
|
|
|
* could arrive while a previous one is still setting up the
|
|
|
|
* thread_info.
|
|
|
|
*
|
|
|
|
* There are three cases -
|
|
|
|
* The first interrupt on the stack - sets up the thread_info and
|
|
|
|
* handles the interrupt
|
|
|
|
* A nested interrupt interrupting the copying of the thread_info -
|
|
|
|
* can't handle the interrupt, as the stack is in an unknown state
|
|
|
|
* A nested interrupt not interrupting the copying of the
|
|
|
|
* thread_info - doesn't do any setup, just handles the interrupt
|
|
|
|
*
|
|
|
|
* The first job is to figure out whether we interrupted stack setup.
|
|
|
|
* This is done by xchging the signal mask with thread_info->pending.
|
|
|
|
* If the value that comes back is zero, then there is no setup in
|
|
|
|
* progress, and the interrupt can be handled. If the value is
|
|
|
|
* non-zero, then there is stack setup in progress. In order to have
|
|
|
|
* the interrupt handled, we leave our signal in the mask, and it will
|
|
|
|
* be handled by the upper handler after it has set up the stack.
|
|
|
|
*
|
|
|
|
* Next is to figure out whether we are the outer handler or a nested
|
|
|
|
* one. As part of setting up the stack, thread_info->real_thread is
|
|
|
|
* set to non-NULL (and is reset to NULL on exit). This is the
|
|
|
|
* nesting indicator. If it is non-NULL, then the stack is already
|
|
|
|
* set up and the handler can run.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned long pending_mask;
|
|
|
|
|
uml: fix irqstack crash
This patch fixes a crash caused by an interrupt coming in when an IRQ stack
is being torn down. When this happens, handle_signal will loop, setting up
the IRQ stack again because the tearing down had finished, and handling
whatever signals had come in.
However, to_irq_stack returns a mask of pending signals to be handled, plus
bit zero is set if the IRQ stack was already active, and thus shouldn't be
torn down. This causes a problem because when handle_signal goes around
the loop, sig will be zero, and to_irq_stack will duly set bit zero in the
returned mask, faking handle_signal into believing that it shouldn't tear
down the IRQ stack and return thread_info pointers back to their original
values.
This will eventually cause a crash, as the IRQ stack thread_info will
continue pointing to the original task_struct and an interrupt will look
into it after it has been freed.
The fix is to stop passing a signal number into to_irq_stack. Rather, the
pending signals mask is initialized beforehand with the bit for sig already
set. References to sig in to_irq_stack can be replaced with references to
the mask.
[akpm@linux-foundation.org: use UL]
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-09-19 07:46:49 +02:00
|
|
|
unsigned long to_irq_stack(unsigned long *mask_out)
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 07:22:34 +02:00
|
|
|
{
|
|
|
|
struct thread_info *ti;
|
|
|
|
unsigned long mask, old;
|
|
|
|
int nested;
|
|
|
|
|
uml: fix irqstack crash
This patch fixes a crash caused by an interrupt coming in when an IRQ stack
is being torn down. When this happens, handle_signal will loop, setting up
the IRQ stack again because the tearing down had finished, and handling
whatever signals had come in.
However, to_irq_stack returns a mask of pending signals to be handled, plus
bit zero is set if the IRQ stack was already active, and thus shouldn't be
torn down. This causes a problem because when handle_signal goes around
the loop, sig will be zero, and to_irq_stack will duly set bit zero in the
returned mask, faking handle_signal into believing that it shouldn't tear
down the IRQ stack and return thread_info pointers back to their original
values.
This will eventually cause a crash, as the IRQ stack thread_info will
continue pointing to the original task_struct and an interrupt will look
into it after it has been freed.
The fix is to stop passing a signal number into to_irq_stack. Rather, the
pending signals mask is initialized beforehand with the bit for sig already
set. References to sig in to_irq_stack can be replaced with references to
the mask.
[akpm@linux-foundation.org: use UL]
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-09-19 07:46:49 +02:00
|
|
|
mask = xchg(&pending_mask, *mask_out);
|
2007-10-16 10:27:00 +02:00
|
|
|
if (mask != 0) {
|
|
|
|
/*
|
|
|
|
* If any interrupts come in at this point, we want to
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 07:22:34 +02:00
|
|
|
* make sure that their bits aren't lost by our
|
|
|
|
* putting our bit in. So, this loop accumulates bits
|
|
|
|
* until xchg returns the same value that we put in.
|
|
|
|
* When that happens, there were no new interrupts,
|
|
|
|
* and pending_mask contains a bit for each interrupt
|
|
|
|
* that came in.
|
|
|
|
*/
|
uml: fix irqstack crash
This patch fixes a crash caused by an interrupt coming in when an IRQ stack
is being torn down. When this happens, handle_signal will loop, setting up
the IRQ stack again because the tearing down had finished, and handling
whatever signals had come in.
However, to_irq_stack returns a mask of pending signals to be handled, plus
bit zero is set if the IRQ stack was already active, and thus shouldn't be
torn down. This causes a problem because when handle_signal goes around
the loop, sig will be zero, and to_irq_stack will duly set bit zero in the
returned mask, faking handle_signal into believing that it shouldn't tear
down the IRQ stack and return thread_info pointers back to their original
values.
This will eventually cause a crash, as the IRQ stack thread_info will
continue pointing to the original task_struct and an interrupt will look
into it after it has been freed.
The fix is to stop passing a signal number into to_irq_stack. Rather, the
pending signals mask is initialized beforehand with the bit for sig already
set. References to sig in to_irq_stack can be replaced with references to
the mask.
[akpm@linux-foundation.org: use UL]
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-09-19 07:46:49 +02:00
|
|
|
old = *mask_out;
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 07:22:34 +02:00
|
|
|
do {
|
|
|
|
old |= mask;
|
|
|
|
mask = xchg(&pending_mask, old);
|
2007-10-16 10:27:00 +02:00
|
|
|
} while (mask != old);
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 07:22:34 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ti = current_thread_info();
|
|
|
|
nested = (ti->real_thread != NULL);
|
2007-10-16 10:27:00 +02:00
|
|
|
if (!nested) {
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 07:22:34 +02:00
|
|
|
struct task_struct *task;
|
|
|
|
struct thread_info *tti;
|
|
|
|
|
|
|
|
task = cpu_tasks[ti->cpu].task;
|
|
|
|
tti = task_thread_info(task);
|
uml: fix irqstack crash
This patch fixes a crash caused by an interrupt coming in when an IRQ stack
is being torn down. When this happens, handle_signal will loop, setting up
the IRQ stack again because the tearing down had finished, and handling
whatever signals had come in.
However, to_irq_stack returns a mask of pending signals to be handled, plus
bit zero is set if the IRQ stack was already active, and thus shouldn't be
torn down. This causes a problem because when handle_signal goes around
the loop, sig will be zero, and to_irq_stack will duly set bit zero in the
returned mask, faking handle_signal into believing that it shouldn't tear
down the IRQ stack and return thread_info pointers back to their original
values.
This will eventually cause a crash, as the IRQ stack thread_info will
continue pointing to the original task_struct and an interrupt will look
into it after it has been freed.
The fix is to stop passing a signal number into to_irq_stack. Rather, the
pending signals mask is initialized beforehand with the bit for sig already
set. References to sig in to_irq_stack can be replaced with references to
the mask.
[akpm@linux-foundation.org: use UL]
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-09-19 07:46:49 +02:00
|
|
|
|
uml: iRQ stacks
Add a separate IRQ stack. This differs from i386 in having the entire
interrupt run on a separate stack rather than starting on the normal kernel
stack and switching over once some preparation has been done. The underlying
mechanism, is of course, sigaltstack.
Another difference is that interrupts that happen in userspace are handled on
the normal kernel stack. These cause a wait wakeup instead of a signal
delivery so there is no point in trying to switch stacks for these. There's
no other stuff on the stack, so there is no extra stack consumption.
This quirk makes it possible to have the entire interrupt run on a separate
stack - process preemption (and calls to schedule()) happens on a normal
kernel stack. If we enable CONFIG_PREEMPT, this will need to be rethought.
The IRQ stack for CPU 0 is declared in the same way as the initial kernel
stack. IRQ stacks for other CPUs will be allocated dynamically.
An extra field was added to the thread_info structure. When the active
thread_info is copied to the IRQ stack, the real_thread field points back to
the original stack. This makes it easy to tell where to copy the thread_info
struct back to when the interrupt is finished. It also serves as a marker of
a nested interrupt. It is NULL for the first interrupt on the stack, and
non-NULL for any nested interrupts.
Care is taken to behave correctly if a second interrupt comes in when the
thread_info structure is being set up or taken down. I could just disable
interrupts here, but I don't feel like giving up any of the performance gained
by not flipping signals on and off.
If an interrupt comes in during these critical periods, the handler can't run
because it has no idea what shape the stack is in. So, it sets a bit for its
signal in a global mask and returns. The outer handler will deal with this
signal itself.
Atomicity is had with xchg. A nested interrupt that needs to bail out will
xchg its signal mask into pending_mask and repeat in case yet another
interrupt hit at the same time, until the mask stabilizes.
The outermost interrupt will set up the thread_info and xchg a zero into
pending_mask when it is done. At this point, nested interrupts will look at
->real_thread and see that no setup needs to be done. They can just continue
normally.
Similar care needs to be taken when exiting the outer handler. If another
interrupt comes in while it is copying the thread_info, it will drop a bit
into pending_mask. The outer handler will check this and if it is non-zero,
will loop, set up the stack again, and handle the interrupt.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-11 07:22:34 +02:00
|
|
|
*ti = *tti;
|
|
|
|
ti->real_thread = tti;
|
|
|
|
task->stack = ti;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = xchg(&pending_mask, 0);
|
|
|
|
*mask_out |= mask | nested;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long from_irq_stack(int nested)
|
|
|
|
{
|
|
|
|
struct thread_info *ti, *to;
|
|
|
|
unsigned long mask;
|
|
|
|
|
|
|
|
ti = current_thread_info();
|
|
|
|
|
|
|
|
pending_mask = 1;
|
|
|
|
|
|
|
|
to = ti->real_thread;
|
|
|
|
current->stack = to;
|
|
|
|
ti->real_thread = NULL;
|
|
|
|
*to = *ti;
|
|
|
|
|
|
|
|
mask = xchg(&pending_mask, 0);
|
|
|
|
return mask & ~1;
|
|
|
|
}
|
|
|
|
|