2007-05-11 13:22:32 +08:00
|
|
|
/*
|
2017-11-21 05:17:58 +08:00
|
|
|
* Copyright (C) 2017 - Cambridge Greys Ltd
|
|
|
|
* Copyright (C) 2011 - 2014 Cisco Systems Inc
|
2007-10-16 16:27:00 +08:00
|
|
|
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-17 06:20:36 +08:00
|
|
|
* Licensed under the GPL
|
|
|
|
* Derived (i.e. mostly copied) from arch/i386/kernel/irq.c:
|
|
|
|
* Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
|
|
|
|
*/
|
|
|
|
|
2012-10-08 10:27:32 +08:00
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/hardirq.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <as-layout.h>
|
|
|
|
#include <kern_util.h>
|
|
|
|
#include <os.h>
|
2017-11-21 05:17:58 +08:00
|
|
|
#include <irq_user.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
|
|
|
|
/* When epoll triggers we do not know why it did so
|
|
|
|
* we can also have different IRQs for read and write.
|
|
|
|
* This is why we keep a small irq_fd array for each fd -
|
|
|
|
* one entry per IRQ type
|
2007-05-07 05:51:27 +08:00
|
|
|
*/
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
struct irq_entry {
|
|
|
|
struct irq_entry *next;
|
|
|
|
int fd;
|
|
|
|
struct irq_fd *irq_array[MAX_IRQ_TYPE + 1];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct irq_entry *active_fds;
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(irq_lock);
|
|
|
|
|
|
|
|
static void irq_io_loop(struct irq_fd *irq, struct uml_pt_regs *regs)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* irq->active guards against reentry
|
|
|
|
* irq->pending accumulates pending requests
|
|
|
|
* if pending is raised the irq_handler is re-run
|
|
|
|
* until pending is cleared
|
|
|
|
*/
|
|
|
|
if (irq->active) {
|
|
|
|
irq->active = false;
|
|
|
|
do {
|
|
|
|
irq->pending = false;
|
|
|
|
do_IRQ(irq->irq, regs);
|
|
|
|
} while (irq->pending && (!irq->purge));
|
|
|
|
if (!irq->purge)
|
|
|
|
irq->active = true;
|
|
|
|
} else {
|
|
|
|
irq->pending = true;
|
|
|
|
}
|
|
|
|
}
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2012-08-02 06:49:17 +08:00
|
|
|
void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
|
2006-03-27 17:14:31 +08:00
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
struct irq_entry *irq_entry;
|
|
|
|
struct irq_fd *irq;
|
|
|
|
|
|
|
|
int n, i, j;
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2006-05-02 03:15:57 +08:00
|
|
|
while (1) {
|
2017-11-21 05:17:58 +08:00
|
|
|
/* This is now lockless - epoll keeps back-referencesto the irqs
|
|
|
|
* which have trigger it so there is no need to walk the irq
|
|
|
|
* list and lock it every time. We avoid locking by turning off
|
|
|
|
* IO for a specific fd by executing os_del_epoll_fd(fd) before
|
|
|
|
* we do any changes to the actual data structures
|
|
|
|
*/
|
|
|
|
n = os_waiting_for_events_epoll();
|
|
|
|
|
2006-03-27 17:14:31 +08:00
|
|
|
if (n <= 0) {
|
2007-10-16 16:27:00 +08:00
|
|
|
if (n == -EINTR)
|
|
|
|
continue;
|
2017-11-21 05:17:58 +08:00
|
|
|
else
|
|
|
|
break;
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
for (i = 0; i < n ; i++) {
|
|
|
|
/* Epoll back reference is the entry with 3 irq_fd
|
|
|
|
* leaves - one for each irq type.
|
|
|
|
*/
|
|
|
|
irq_entry = (struct irq_entry *)
|
|
|
|
os_epoll_get_data_pointer(i);
|
|
|
|
for (j = 0; j < MAX_IRQ_TYPE ; j++) {
|
|
|
|
irq = irq_entry->irq_array[j];
|
|
|
|
if (irq == NULL)
|
|
|
|
continue;
|
|
|
|
if (os_epoll_triggered(i, irq->events) > 0)
|
|
|
|
irq_io_loop(irq, regs);
|
|
|
|
if (irq->purge) {
|
|
|
|
irq_entry->irq_array[j] = NULL;
|
|
|
|
kfree(irq);
|
|
|
|
}
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 05:17:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int assign_epoll_events_to_irq(struct irq_entry *irq_entry)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int events = 0;
|
|
|
|
struct irq_fd *irq;
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
for (i = 0; i < MAX_IRQ_TYPE ; i++) {
|
|
|
|
irq = irq_entry->irq_array[i];
|
|
|
|
if (irq != NULL)
|
|
|
|
events = irq->events | events;
|
|
|
|
}
|
|
|
|
if (events > 0) {
|
|
|
|
/* os_add_epoll will call os_mod_epoll if this already exists */
|
|
|
|
return os_add_epoll_fd(events, irq_entry->fd, irq_entry);
|
|
|
|
}
|
|
|
|
/* No events - delete */
|
|
|
|
return os_del_epoll_fd(irq_entry->fd);
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
|
2006-07-10 19:45:10 +08:00
|
|
|
|
2008-07-24 12:28:47 +08:00
|
|
|
static int activate_fd(int irq, int fd, int type, void *dev_id)
|
2006-03-27 17:14:31 +08:00
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
struct irq_fd *new_fd;
|
|
|
|
struct irq_entry *irq_entry;
|
|
|
|
int i, err, events;
|
2006-03-27 17:14:31 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-02-05 14:31:04 +08:00
|
|
|
err = os_set_fd_async(fd);
|
2006-05-02 03:15:57 +08:00
|
|
|
if (err < 0)
|
2006-03-27 17:14:31 +08:00
|
|
|
goto out;
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
/* Check if we have an entry for this fd */
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2007-03-08 12:41:13 +08:00
|
|
|
err = -EBUSY;
|
2017-11-21 05:17:58 +08:00
|
|
|
for (irq_entry = active_fds;
|
|
|
|
irq_entry != NULL; irq_entry = irq_entry->next) {
|
|
|
|
if (irq_entry->fd == fd)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irq_entry == NULL) {
|
|
|
|
/* This needs to be atomic as it may be called from an
|
|
|
|
* IRQ context.
|
|
|
|
*/
|
|
|
|
irq_entry = kmalloc(sizeof(struct irq_entry), GFP_ATOMIC);
|
|
|
|
if (irq_entry == NULL) {
|
|
|
|
printk(KERN_ERR
|
|
|
|
"Failed to allocate new IRQ entry\n");
|
2006-03-27 17:14:31 +08:00
|
|
|
goto out_unlock;
|
|
|
|
}
|
2017-11-21 05:17:58 +08:00
|
|
|
irq_entry->fd = fd;
|
|
|
|
for (i = 0; i < MAX_IRQ_TYPE; i++)
|
|
|
|
irq_entry->irq_array[i] = NULL;
|
|
|
|
irq_entry->next = active_fds;
|
|
|
|
active_fds = irq_entry;
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
/* Check if we are trying to re-register an interrupt for a
|
|
|
|
* particular fd
|
|
|
|
*/
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
if (irq_entry->irq_array[type] != NULL) {
|
|
|
|
printk(KERN_ERR
|
|
|
|
"Trying to reregister IRQ %d FD %d TYPE %d ID %p\n",
|
|
|
|
irq, fd, type, dev_id
|
|
|
|
);
|
|
|
|
goto out_unlock;
|
|
|
|
} else {
|
|
|
|
/* New entry for this fd */
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
new_fd = kmalloc(sizeof(struct irq_fd), GFP_ATOMIC);
|
|
|
|
if (new_fd == NULL)
|
|
|
|
goto out_unlock;
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
events = os_event_mask(type);
|
|
|
|
|
|
|
|
*new_fd = ((struct irq_fd) {
|
|
|
|
.id = dev_id,
|
|
|
|
.irq = irq,
|
|
|
|
.type = type,
|
|
|
|
.events = events,
|
|
|
|
.active = true,
|
|
|
|
.pending = false,
|
|
|
|
.purge = false
|
|
|
|
});
|
|
|
|
/* Turn off any IO on this fd - allows us to
|
|
|
|
* avoid locking the IRQ loop
|
2006-03-27 17:14:31 +08:00
|
|
|
*/
|
2017-11-21 05:17:58 +08:00
|
|
|
os_del_epoll_fd(irq_entry->fd);
|
|
|
|
irq_entry->irq_array[type] = new_fd;
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
/* Turn back IO on with the correct (new) IO event mask */
|
|
|
|
assign_epoll_events_to_irq(irq_entry);
|
2006-07-10 19:45:10 +08:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2017-11-21 05:17:58 +08:00
|
|
|
maybe_sigio_broken(fd, (type != IRQ_NONE));
|
2006-03-27 17:14:31 +08: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 14:33:04 +08:00
|
|
|
return 0;
|
2017-11-21 05:17:58 +08:00
|
|
|
out_unlock:
|
2006-07-10 19:45:10 +08:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2017-11-21 05:17:58 +08:00
|
|
|
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 14:33:04 +08:00
|
|
|
return err;
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
/*
|
|
|
|
* Walk the IRQ list and dispose of any unused entries.
|
|
|
|
* Should be done under irq_lock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void garbage_collect_irq_entries(void)
|
2006-03-27 17:14:31 +08:00
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
int i;
|
|
|
|
bool reap;
|
|
|
|
struct irq_entry *walk;
|
|
|
|
struct irq_entry *previous = NULL;
|
|
|
|
struct irq_entry *to_free;
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
if (active_fds == NULL)
|
|
|
|
return;
|
|
|
|
walk = active_fds;
|
|
|
|
while (walk != NULL) {
|
|
|
|
reap = true;
|
|
|
|
for (i = 0; i < MAX_IRQ_TYPE ; i++) {
|
|
|
|
if (walk->irq_array[i] != NULL) {
|
|
|
|
reap = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (reap) {
|
|
|
|
if (previous == NULL)
|
|
|
|
active_fds = walk->next;
|
|
|
|
else
|
|
|
|
previous->next = walk->next;
|
|
|
|
to_free = walk;
|
|
|
|
} else {
|
|
|
|
to_free = NULL;
|
|
|
|
}
|
|
|
|
walk = walk->next;
|
|
|
|
if (to_free != NULL)
|
|
|
|
kfree(to_free);
|
|
|
|
}
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
/*
|
|
|
|
* Walk the IRQ list and get the descriptor for our FD
|
|
|
|
*/
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
static struct irq_entry *get_irq_entry_by_fd(int fd)
|
2006-03-27 17:14:31 +08:00
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
struct irq_entry *walk = active_fds;
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
while (walk != NULL) {
|
|
|
|
if (walk->fd == fd)
|
|
|
|
return walk;
|
|
|
|
walk = walk->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
/*
|
|
|
|
* Walk the IRQ list and dispose of an entry for a specific
|
|
|
|
* device, fd and number. Note - if sharing an IRQ for read
|
|
|
|
* and writefor the same FD it will be disposed in either case.
|
|
|
|
* If this behaviour is undesirable use different IRQ ids.
|
|
|
|
*/
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
#define IGNORE_IRQ 1
|
|
|
|
#define IGNORE_DEV (1<<1)
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
static void do_free_by_irq_and_dev(
|
|
|
|
struct irq_entry *irq_entry,
|
|
|
|
unsigned int irq,
|
|
|
|
void *dev,
|
|
|
|
int flags
|
|
|
|
)
|
2006-03-27 17:14:31 +08:00
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
int i;
|
|
|
|
struct irq_fd *to_free;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_IRQ_TYPE ; i++) {
|
|
|
|
if (irq_entry->irq_array[i] != NULL) {
|
|
|
|
if (
|
|
|
|
((flags & IGNORE_IRQ) ||
|
|
|
|
(irq_entry->irq_array[i]->irq == irq)) &&
|
|
|
|
((flags & IGNORE_DEV) ||
|
|
|
|
(irq_entry->irq_array[i]->id == dev))
|
|
|
|
) {
|
|
|
|
/* Turn off any IO on this fd - allows us to
|
|
|
|
* avoid locking the IRQ loop
|
|
|
|
*/
|
|
|
|
os_del_epoll_fd(irq_entry->fd);
|
|
|
|
to_free = irq_entry->irq_array[i];
|
|
|
|
irq_entry->irq_array[i] = NULL;
|
|
|
|
assign_epoll_events_to_irq(irq_entry);
|
|
|
|
if (to_free->active)
|
|
|
|
to_free->purge = true;
|
|
|
|
else
|
|
|
|
kfree(to_free);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
void free_irq_by_fd(int fd)
|
2006-03-27 17:14:31 +08:00
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
struct irq_entry *to_free;
|
|
|
|
unsigned long flags;
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
|
|
|
to_free = get_irq_entry_by_fd(fd);
|
|
|
|
if (to_free != NULL) {
|
|
|
|
do_free_by_irq_and_dev(
|
|
|
|
to_free,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
IGNORE_IRQ | IGNORE_DEV
|
|
|
|
);
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
2017-11-21 05:17:58 +08:00
|
|
|
garbage_collect_irq_entries();
|
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
2017-11-22 21:49:55 +08:00
|
|
|
EXPORT_SYMBOL(free_irq_by_fd);
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
static void free_irq_by_irq_and_dev(unsigned int irq, void *dev)
|
2006-03-27 17:14:31 +08:00
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
struct irq_entry *to_free;
|
2006-03-27 17:14:31 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2006-07-10 19:45:10 +08:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
2017-11-21 05:17:58 +08:00
|
|
|
to_free = active_fds;
|
|
|
|
while (to_free != NULL) {
|
|
|
|
do_free_by_irq_and_dev(
|
|
|
|
to_free,
|
|
|
|
irq,
|
|
|
|
dev,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
to_free = to_free->next;
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
2017-11-21 05:17:58 +08:00
|
|
|
garbage_collect_irq_entries();
|
2006-07-10 19:45:10 +08:00
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
2017-11-21 05:17:58 +08:00
|
|
|
}
|
|
|
|
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
void reactivate_fd(int fd, int irqnum)
|
|
|
|
{
|
|
|
|
/** NOP - we do auto-EOI now **/
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void deactivate_fd(int fd, int irqnum)
|
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
struct irq_entry *to_free;
|
2006-03-27 17:14:31 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
os_del_epoll_fd(fd);
|
2006-07-10 19:45:10 +08:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
2017-11-21 05:17:58 +08:00
|
|
|
to_free = get_irq_entry_by_fd(fd);
|
|
|
|
if (to_free != NULL) {
|
|
|
|
do_free_by_irq_and_dev(
|
|
|
|
to_free,
|
|
|
|
irqnum,
|
|
|
|
NULL,
|
|
|
|
IGNORE_DEV
|
|
|
|
);
|
[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 14:33:04 +08:00
|
|
|
}
|
2017-11-21 05:17:58 +08:00
|
|
|
garbage_collect_irq_entries();
|
2006-07-10 19:45:10 +08: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 14:33:04 +08:00
|
|
|
ignore_sigio_fd(fd);
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
2011-08-19 03:14:10 +08:00
|
|
|
EXPORT_SYMBOL(deactivate_fd);
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2007-05-07 05:51:27 +08: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 17:14:31 +08:00
|
|
|
int deactivate_all_fds(void)
|
|
|
|
{
|
2017-11-21 05:17:58 +08:00
|
|
|
unsigned long flags;
|
|
|
|
struct irq_entry *to_free;
|
2006-03-27 17:14:31 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
spin_lock_irqsave(&irq_lock, flags);
|
|
|
|
/* Stop IO. The IRQ loop has no lock so this is our
|
|
|
|
* only way of making sure we are safe to dispose
|
|
|
|
* of all IRQ handlers
|
|
|
|
*/
|
2006-03-27 17:14:31 +08:00
|
|
|
os_set_ioignore();
|
2017-11-21 05:17:58 +08:00
|
|
|
to_free = active_fds;
|
|
|
|
while (to_free != NULL) {
|
|
|
|
do_free_by_irq_and_dev(
|
|
|
|
to_free,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
IGNORE_IRQ | IGNORE_DEV
|
|
|
|
);
|
|
|
|
to_free = to_free->next;
|
|
|
|
}
|
|
|
|
garbage_collect_irq_entries();
|
|
|
|
spin_unlock_irqrestore(&irq_lock, flags);
|
|
|
|
os_close_epoll_fd();
|
2006-05-02 03:15:57 +08:00
|
|
|
return 0;
|
2006-03-27 17:14:31 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-10-20 07:23:03 +08:00
|
|
|
* do_IRQ handles all normal device IRQs (the special
|
2005-04-17 06:20:36 +08:00
|
|
|
* SMP cross-CPU interrupts have their own specific
|
|
|
|
* handlers).
|
|
|
|
*/
|
2007-10-16 16:26:58 +08:00
|
|
|
unsigned int do_IRQ(int irq, struct uml_pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-10-09 05:49:34 +08:00
|
|
|
struct pt_regs *old_regs = set_irq_regs((struct pt_regs *)regs);
|
|
|
|
irq_enter();
|
2010-10-27 05:22:20 +08:00
|
|
|
generic_handle_irq(irq);
|
2006-10-09 05:49:34 +08:00
|
|
|
irq_exit();
|
|
|
|
set_irq_regs(old_regs);
|
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-04-18 04:37:13 +08:00
|
|
|
void um_free_irq(unsigned int irq, void *dev)
|
|
|
|
{
|
|
|
|
free_irq_by_irq_and_dev(irq, dev);
|
|
|
|
free_irq(irq, dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(um_free_irq);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int um_request_irq(unsigned int irq, int fd, int type,
|
2006-10-09 19:19:47 +08:00
|
|
|
irq_handler_t handler,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long irqflags, const char * devname,
|
|
|
|
void *dev_id)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2007-11-15 09:00:23 +08:00
|
|
|
if (fd != -1) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err = activate_fd(irq, fd, type, dev_id);
|
2007-11-15 09:00:23 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return request_irq(irq, handler, irqflags, devname, dev_id);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-11-15 09:00:23 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
EXPORT_SYMBOL(um_request_irq);
|
|
|
|
EXPORT_SYMBOL(reactivate_fd);
|
|
|
|
|
2007-10-16 16:27:00 +08:00
|
|
|
/*
|
2011-02-07 06:45:34 +08:00
|
|
|
* irq_chip must define at least enable/disable and ack when
|
|
|
|
* the edge handler is used.
|
2007-10-16 16:27:00 +08:00
|
|
|
*/
|
2011-02-07 06:45:34 +08:00
|
|
|
static void dummy(struct irq_data *d)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
[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 08:16:19 +08:00
|
|
|
/* This is used for everything else than the timer. */
|
2009-06-17 06:33:29 +08:00
|
|
|
static struct irq_chip normal_irq_type = {
|
2010-09-24 00:40:07 +08:00
|
|
|
.name = "SIGIO",
|
2011-02-07 06:45:34 +08:00
|
|
|
.irq_disable = dummy,
|
|
|
|
.irq_enable = dummy,
|
|
|
|
.irq_ack = dummy,
|
2013-09-03 04:49:22 +08:00
|
|
|
.irq_mask = dummy,
|
|
|
|
.irq_unmask = dummy,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2009-06-17 06:33:29 +08:00
|
|
|
static struct irq_chip SIGVTALRM_irq_type = {
|
2010-09-24 00:40:07 +08:00
|
|
|
.name = "SIGVTALRM",
|
2011-02-07 06:45:34 +08:00
|
|
|
.irq_disable = dummy,
|
|
|
|
.irq_enable = dummy,
|
|
|
|
.irq_ack = dummy,
|
2013-09-03 04:49:22 +08:00
|
|
|
.irq_mask = dummy,
|
|
|
|
.irq_unmask = dummy,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void __init init_IRQ(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-03-25 01:24:42 +08:00
|
|
|
irq_set_chip_and_handler(TIMER_IRQ, &SIGVTALRM_irq_type, handle_edge_irq);
|
2010-10-27 05:22:20 +08:00
|
|
|
|
2017-11-21 05:17:58 +08:00
|
|
|
|
2011-03-25 01:24:42 +08:00
|
|
|
for (i = 1; i < NR_IRQS; i++)
|
|
|
|
irq_set_chip_and_handler(i, &normal_irq_type, handle_edge_irq);
|
2017-11-21 05:17:58 +08:00
|
|
|
/* Initialize EPOLL Loop */
|
|
|
|
os_setup_epoll();
|
2005-04-17 06:20:36 +08: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 13:22:34 +08: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 13:46:49 +08: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 13:22:34 +08: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 13:46:49 +08:00
|
|
|
mask = xchg(&pending_mask, *mask_out);
|
2007-10-16 16:27:00 +08: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 13:22:34 +08: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 13:46:49 +08: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 13:22:34 +08:00
|
|
|
do {
|
|
|
|
old |= mask;
|
|
|
|
mask = xchg(&pending_mask, old);
|
2007-10-16 16:27:00 +08: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 13:22:34 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ti = current_thread_info();
|
|
|
|
nested = (ti->real_thread != NULL);
|
2007-10-16 16:27:00 +08: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 13:22:34 +08: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 13:46:49 +08: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 13:22:34 +08: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;
|
|
|
|
}
|
|
|
|
|