[patch] rt: fix ipi kfree(), introduce IPI_SOFTIRQ

Ingo Molnar
2009-02-12T08:19:42Z

* Ingo Molnar <mingo@elte.hu> wrote:

> hm, that's a complex one - we do kfree() from IPI context, [...]

The patch below might do the trick - it offloads this to a softirq.
Not tested yet.

Ingo

------------------>
Subject: rt: fix ipi kfree(), introduce IPI_SOFTIRQ
From: Ingo Molnar <mingo@elte.hu>
Date: Thu Feb 12 09:06:11 CET 2009

in 2.6.28 generic_smp_call_function_interrupt() grew a kfree(),
which is a rather complex, sleepable method under -rt. But the
IPI code runs as a hardirq - which cannot run such code.

So defer this work to a softirq context instead. It still stays
on the same CPU so the percpu IPI assumptions are upheld.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/interrupt.h | 1 +
include/linux/smp.h | 3 +++
init/main.c | 1 +
kernel/smp.c | 15 +++++++++++++--
4 files changed, 18 insertions(+), 2 deletions(-)

Index: tip/include/linux/interrupt.h
===================================================================
--- tip.orig/include/linux/interrupt.h
+++ tip/include/linux/interrupt.h
@@ -257,6 +257,7 @@ enum
SCHED_SOFTIRQ,
HRTIMER_SOFTIRQ,
RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
+ IPI_SOFTIRQ,
/* Entries after this are ignored in split softirq mode */
MAX_SOFTIRQ,

Index: tip/include/linux/smp.h
===================================================================
--- tip.orig/include/linux/smp.h
+++ tip/include/linux/smp.h
@@ -104,6 +104,9 @@ void ipi_call_lock(void);
void ipi_call_unlock(void);
void ipi_call_lock_irq(void);
void ipi_call_unlock_irq(void);
+void ipi_init(void);
+#else
+static inline void ipi_init(void) { }
#endif

/*
Index: tip/init/main.c
===================================================================
--- tip.orig/init/main.c
+++ tip/init/main.c
@@ -606,6 +606,7 @@ asmlinkage void __init start_kernel(void
/* init some links before init_ISA_irqs() */
early_irq_init();
init_IRQ();
+ ipi_init();
pidhash_init();
init_timers();
hrtimers_init();
Index: tip/kernel/smp.c
===================================================================
--- tip.orig/kernel/smp.c
+++ tip/kernel/smp.c
@@ -4,12 +4,13 @@
* (C) Jens Axboe <jens.axboe@oracle.com> 2008
*
*/
+#include <linux/smp.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/percpu.h>
-#include <linux/rcupdate.h>
#include <linux/rculist.h>
-#include <linux/smp.h>
+#include <linux/rcupdate.h>
+#include <linux/interrupt.h>

static DEFINE_PER_CPU(struct call_single_queue, call_single_queue);
static LIST_HEAD(call_function_queue);
@@ -152,6 +153,11 @@ void generic_smp_call_function_interrupt
*/
void generic_smp_call_function_single_interrupt(void)
{
+ raise_softirq_irqoff(IPI_SOFTIRQ);
+}
+
+static void run_generic_smp_call_function_single(struct softirq_action *h)
+{
struct call_single_queue *q = &__get_cpu_var(call_single_queue);
LIST_HEAD(list);

@@ -430,3 +436,8 @@ void ipi_call_unlock_irq(void)
{
spin_unlock_irq(&call_function_lock);
}
+
+void __init ipi_init(void)
+{
+ open_softirq(IPI_SOFTIRQ, run_generic_smp_call_function_single);
+}