Skip to content

Commit bebe468

Browse files
jmalinenrichardweinberger
authored andcommitted
um: Fix IRQ controller regression on console read
The conversion of UML to use epoll based IRQ controller claimed that clone_one_chan() can safely call um_free_irq() while starting to ignore the delay_free_irq parameter that explicitly noted that the IRQ cannot be freed because this is being called from chan_interrupt(). This resulted in free_irq() getting called in interrupt context ("Trying to free IRQ 6 from IRQ context!"). Fix this by restoring previously used delay_free_irq processing. Fixes: ff6a179 ("Epoll based IRQ controller") Signed-off-by: Jouni Malinen <j@w1.fi> Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 4b972a0 commit bebe468

2 files changed

Lines changed: 48 additions & 8 deletions

File tree

‎arch/um/drivers/chan_kern.c‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,55 @@ int enable_chan(struct line *line)
171171
return err;
172172
}
173173

174+
/* Items are added in IRQ context, when free_irq can't be called, and
175+
* removed in process context, when it can.
176+
* This handles interrupt sources which disappear, and which need to
177+
* be permanently disabled. This is discovered in IRQ context, but
178+
* the freeing of the IRQ must be done later.
179+
*/
180+
static DEFINE_SPINLOCK(irqs_to_free_lock);
181+
static LIST_HEAD(irqs_to_free);
182+
183+
void free_irqs(void)
184+
{
185+
struct chan *chan;
186+
LIST_HEAD(list);
187+
struct list_head *ele;
188+
unsigned long flags;
189+
190+
spin_lock_irqsave(&irqs_to_free_lock, flags);
191+
list_splice_init(&irqs_to_free, &list);
192+
spin_unlock_irqrestore(&irqs_to_free_lock, flags);
193+
194+
list_for_each(ele, &list) {
195+
chan = list_entry(ele, struct chan, free_list);
196+
197+
if (chan->input && chan->enabled)
198+
um_free_irq(chan->line->driver->read_irq, chan);
199+
if (chan->output && chan->enabled)
200+
um_free_irq(chan->line->driver->write_irq, chan);
201+
chan->enabled = 0;
202+
}
203+
}
204+
174205
static void close_one_chan(struct chan *chan, int delay_free_irq)
175206
{
207+
unsigned long flags;
208+
176209
if (!chan->opened)
177210
return;
178211

179-
/* we can safely call free now - it will be marked
180-
* as free and freed once the IRQ stopped processing
181-
*/
182-
if (chan->input && chan->enabled)
183-
um_free_irq(chan->line->driver->read_irq, chan);
184-
if (chan->output && chan->enabled)
185-
um_free_irq(chan->line->driver->write_irq, chan);
186-
chan->enabled = 0;
212+
if (delay_free_irq) {
213+
spin_lock_irqsave(&irqs_to_free_lock, flags);
214+
list_add(&chan->free_list, &irqs_to_free);
215+
spin_unlock_irqrestore(&irqs_to_free_lock, flags);
216+
} else {
217+
if (chan->input && chan->enabled)
218+
um_free_irq(chan->line->driver->read_irq, chan);
219+
if (chan->output && chan->enabled)
220+
um_free_irq(chan->line->driver->write_irq, chan);
221+
chan->enabled = 0;
222+
}
187223
if (chan->ops->close != NULL)
188224
(*chan->ops->close)(chan->fd, chan->data);
189225

‎arch/um/kernel/irq.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <irq_user.h>
2222

2323

24+
extern void free_irqs(void);
25+
2426
/* When epoll triggers we do not know why it did so
2527
* we can also have different IRQs for read and write.
2628
* This is why we keep a small irq_fd array for each fd -
@@ -100,6 +102,8 @@ void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
100102
}
101103
}
102104
}
105+
106+
free_irqs();
103107
}
104108

105109
static int assign_epoll_events_to_irq(struct irq_entry *irq_entry)

0 commit comments

Comments
 (0)