Skip to contentSkip to conversation

sparseirq: Enable early irq_desc allocation.

PATCH In review Paul Mundt 3 participants 5 messages May 21, 2009 – May 23, 2009 IRQ

lore
Share & tools
lore

Paul Mundt

author
#0 lore raw

PATCH 1/1 sparseirq: Enable early irq_desc allocation.

Presently non-legacy IRQs have their irq_desc allocated with kzalloc_node(). This assumes that all callers of irq_to_desc_cpu_alloc() will be sufficiently late in the boot process that kmalloc is available.

While porting sparseirq support to sh this blew up immediately, as at the time that we register the CPU's interrupt vector map only bootmem is available.

This adds in a simple after_bootmem check to see where the allocation needs to come from, which is likewise provided by all of the platforms that support sparse irq today. :-)

Cc Yinghai Lu <[email protected]>
Cc Ingo Molnar <[email protected]>

---

 kernel/irq/handle.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
kernel/irq/handle.c +12 -5
index d82142b..5fb3a5c 100644
@@ -19,7 +19,7 @@
 #include <linux/hash.h>
 #include <trace/irq.h>
 #include <linux/bootmem.h>
-
+#include <linux/mm.h>
 #include "internals.h"
 
 /*
@@ -81,13 +81,17 @@ static struct irq_desc irq_desc_init = {
 	.lock       = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
 };
 
-void init_kstat_irqs(struct irq_desc *desc, int cpu, int nr)
+void __ref init_kstat_irqs(struct irq_desc *desc, int cpu, int nr)
 {
 	int node;
 	void *ptr;
 
 	node = cpu_to_node(cpu);
-	ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
+	if (after_bootmem)
+		ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
+	else
+		ptr = alloc_bootmem_node(NODE_DATA(node),
+				nr * sizeof(*desc->kstat_irqs));
 
 	/*
 	 * don't overwite if can not get new one
@@ -187,7 +191,7 @@ struct irq_desc *irq_to_desc(unsigned int irq)
 	return NULL;
 }
 
-struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
+struct irq_desc * __ref irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
 {
 	struct irq_desc *desc;
 	unsigned long flags;
@@ -211,7 +215,10 @@ struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
 		goto out_unlock;
 
 	node = cpu_to_node(cpu);
-	desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
+	if (after_bootmem)
+		desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
+	else
+		desc = alloc_bootmem_node(NODE_DATA(node), sizeof(*desc));
 	printk(KERN_DEBUG "  alloc irq_desc for %d on cpu %d node %d\n",
 		 irq, cpu, node);
 	if (!desc) {
#1 lore raw
Quoted 65 lines · Paul Mundt

Presently non-legacy IRQs have their irq_desc allocated with kzalloc_node(). This assumes that all callers of irq_to_desc_cpu_alloc() will be sufficiently late in the boot process that kmalloc is available.

While porting sparseirq support to sh this blew up immediately, as at the time that we register the CPU's interrupt vector map only bootmem is available.

This adds in a simple after_bootmem check to see where the allocation needs to come from, which is likewise provided by all of the platforms that support sparse irq today. :-)

Cc Yinghai Lu <[email protected]>
Cc Ingo Molnar <[email protected]>

---

 kernel/irq/handle.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
kernel/irq/handle.c +8 -4
index d82142b..5fb3a5c 100644
@@ -19,7 +19,7 @@
 #include <linux/hash.h>
 #include <trace/irq.h>
 #include <linux/bootmem.h>
-
+#include <linux/mm.h>
 #include "internals.h"
 
 /*
@@ -81,13 +81,17 @@ static struct irq_desc irq_desc_init = {
 	.lock       = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
 };
 
-void init_kstat_irqs(struct irq_desc *desc, int cpu, int nr)
+void __ref init_kstat_irqs(struct irq_desc *desc, int cpu, int nr)
 {
 	int node;
 	void *ptr;
 
 	node = cpu_to_node(cpu);
-	ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
+	if (after_bootmem)
+		ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
+	else
+		ptr = alloc_bootmem_node(NODE_DATA(node),
+				nr * sizeof(*desc->kstat_irqs));
 
 	/*
 	 * don't overwite if can not get new one
@@ -187,7 +191,7 @@ struct irq_desc *irq_to_desc(unsigned int irq)
 	return NULL;
 }
 
-struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
+struct irq_desc * __ref irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
 {
 	struct irq_desc *desc;
 	unsigned long flags;
@@ -211,7 +215,10 @@ struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu)
 		goto out_unlock;

kernel/irq/handle.c struct irq_desc *irq_to_desc_alloc_cpu(unsigned int irq, int cpu) · line 224

Quoted 10 lines
kernel/irq/handle.c +4 -1
 
 	node = cpu_to_node(cpu);
-	desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
+	if (after_bootmem)
+		desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
+	else
+		desc = alloc_bootmem_node(NODE_DATA(node), sizeof(*desc));
 	printk(KERN_DEBUG "  alloc irq_desc for %d on cpu %d node %d\n",
 		 irq, cpu, node);
 	if (!desc) {

can you check tip?
we change _cpu to node already.

also only sh have after_bootmem now.
arch/sh/mm/init.c:int after_bootmem = 0;

arch/sh/mm/init.c:      after_bootmem = 1;
arch/sh/mm/ioremap_64.c:        extern int after_bootmem;
arch/sh/mm/ioremap_64.c:        if (after_bootmem) {

include/linux/mm.h:extern int after_bootmem;

for x86 we have bootmem_state ... arch/x86/include/asm/page_types.h:enum bootmem_state { arch/x86/include/asm/page_types.h:extern enum bootmem_state bootmem_state;
arch/x86/kernel/setup.c: bootmem_state = DURING_BOOTMEM;
arch/x86/mm/init.c:enum bootmem_state bootmem_state = BEFORE_BOOTMEM;

arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM && !start) {
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM &&
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)

Andrew,
do we need to move bootmem_state back to linux/mm.h?

YH

YH

author
#2 lore raw
Quoted 15 lines · Yinghai Lu

can you check tip?
we change _cpu to node already.

also only sh have after_bootmem now.
arch/sh/mm/init.c:int after_bootmem = 0;

arch/sh/mm/init.c:      after_bootmem = 1;
arch/sh/mm/ioremap_64.c:        extern int after_bootmem;
arch/sh/mm/ioremap_64.c:        if (after_bootmem) {

include/linux/mm.h:extern int after_bootmem;

for x86 we have bootmem_state ... arch/x86/include/asm/page_types.h:enum bootmem_state { arch/x86/include/asm/page_types.h:extern enum bootmem_state bootmem_state;
arch/x86/kernel/setup.c: bootmem_state = DURING_BOOTMEM;
arch/x86/mm/init.c:enum bootmem_state bootmem_state = BEFORE_BOOTMEM;

Quoted 8 lines
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM && !start) {
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM &&
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)

Andrew,
do we need to move bootmem_state back to linux/mm.h?

No need, I just switched to slab_is_available() in the respin. Here is v2, against -tip:

--

sparseirq: Enable early irq_desc allocation, v2.

Presently non-legacy IRQs have their irq_desc allocated with kzalloc_node(). This assumes that all callers of irq_to_desc_node_alloc() will be sufficiently late in the boot process that kmalloc is available.

While porting sparseirq support to sh this blew up immediately, as at the time that we register the CPU's interrupt vector map only bootmem is available. Check slab_is_available() to work out which path to use.

Cc Yinghai Lu <[email protected]>
Cc Ingo Molnar <[email protected]>

---

V2 updated for -tip, and switched to slab_is_available().

 kernel/irq/handle.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
kernel/irq/handle.c +14 -5
index 33ff8f5..b5a47d6 100644
@@ -18,8 +18,8 @@
 #include <linux/rculist.h>
 #include <linux/hash.h>
 #include <linux/bootmem.h>
+#include <linux/slab.h>
 #include <trace/events/irq.h>
-
 #include "internals.h"
 
 /*
@@ -81,11 +81,16 @@ static struct irq_desc irq_desc_init = {
 	.lock       = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
 };
 
-void init_kstat_irqs(struct irq_desc *desc, int node, int nr)
+void __ref init_kstat_irqs(struct irq_desc *desc, int node, int nr)
 {
 	void *ptr;
 
-	ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
+	if (slab_is_available())
+		ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs),
+				   GFP_ATOMIC, node);
+	else
+		ptr = alloc_bootmem_node(NODE_DATA(node),
+				nr * sizeof(*desc->kstat_irqs));
 
 	/*
 	 * don't overwite if can not get new one
@@ -186,7 +191,7 @@ struct irq_desc *irq_to_desc(unsigned int irq)
 	return NULL;
 }
 
-struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node)
+struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node)
 {
 	struct irq_desc *desc;
 	unsigned long flags;
@@ -208,7 +213,11 @@ struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node)
 	if (desc)
 		goto out_unlock;
 
-	desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
+	if (slab_is_available())
+		desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
+	else
+		desc = alloc_bootmem_node(NODE_DATA(node), sizeof(*desc));
+
 	printk(KERN_DEBUG "  alloc irq_desc for %d on node %d\n", irq, node);
 	if (!desc) {
 		printk(KERN_ERR "can not alloc irq_desc\n");
#3 lore raw
Quoted 22 lines · Paul Mundt
Quoted 21 lines · Yinghai Lu

can you check tip?
we change _cpu to node already.

also only sh have after_bootmem now.
arch/sh/mm/init.c:int after_bootmem = 0;

arch/sh/mm/init.c:      after_bootmem = 1;
arch/sh/mm/ioremap_64.c:        extern int after_bootmem;
arch/sh/mm/ioremap_64.c:        if (after_bootmem) {

include/linux/mm.h:extern int after_bootmem;

for x86 we have bootmem_state ... arch/x86/include/asm/page_types.h:enum bootmem_state { arch/x86/include/asm/page_types.h:extern enum bootmem_state bootmem_state;
arch/x86/kernel/setup.c: bootmem_state = DURING_BOOTMEM;
arch/x86/mm/init.c:enum bootmem_state bootmem_state = BEFORE_BOOTMEM;

arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM && !start) {
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM &&
arch/x86/mm/init.c:     if (bootmem_state == BEFORE_BOOTMEM)
Quoted 5 lines
Quoted 2 lines

Andrew,
do we need to move bootmem_state back to linux/mm.h?

No need, I just switched to slab_is_available() in the respin. Here is v2, against -tip:

thanks.

I'm a bit unhappy about allocators here (and this is not your fault). There's not two but _three_ states for allocation: bootmem, pagealloc, kmalloc. There is a (short) stage during bootup where kmalloc is not enabled yet and bootmem is already deactivated. If we ever use slab_is_available() in such a state it will blow up.

Fixing all this allocator bootstrapping mess we have in Linux is a lot larger project though.

Ingo

#4 lore raw

[tip:irq/numa] sparseirq: Allow early irq_desc allocation

In reply to Paul Mundt
Commit-ID:  948cd52906baf1f92aeea2f9b5c515db1b2e592a
Gitweb:     http://git.kernel.org/tip/948cd52906baf1f92aeea2f9b5c515db1b2e592a
Author:     Paul Mundt <[email protected]>
AuthorDate: Fri, 22 May 2009 10:40:09 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sat, 23 May 2009 14:55:24 +0200

sparseirq: Allow early irq_desc allocation

Presently non-legacy IRQs have their irq_desc allocated with kzalloc_node(). This assumes that all callers of irq_to_desc_node_alloc() will be sufficiently late in the boot process that kmalloc is available.

While porting sparseirq support to sh this blew up immediately, as at the time that we register the CPU's interrupt vector map only bootmem is available. Check slab_is_available() to work out which path to use.

[ Impact: fix SH early boot crash with sparseirq enabled ]

LKML-Reference: <[email protected]>

---
 kernel/irq/handle.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
kernel/irq/handle.c +14 -4
index a3c671e..18041a2 100644
@@ -11,6 +11,7 @@
  */
 
 #include <linux/irq.h>
+#include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/random.h>
 #include <linux/interrupt.h>
@@ -81,11 +82,16 @@ static struct irq_desc irq_desc_init = {
 	.lock       = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
 };
 
-void init_kstat_irqs(struct irq_desc *desc, int node, int nr)
+void __ref init_kstat_irqs(struct irq_desc *desc, int node, int nr)
 {
 	void *ptr;
 
-	ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), GFP_ATOMIC, node);
+	if (slab_is_available())
+		ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs),
+				   GFP_ATOMIC, node);
+	else
+		ptr = alloc_bootmem_node(NODE_DATA(node),
+				nr * sizeof(*desc->kstat_irqs));
 
 	/*
 	 * don't overwite if can not get new one
@@ -186,7 +192,7 @@ struct irq_desc *irq_to_desc(unsigned int irq)
 	return NULL;
 }
 
-struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node)
+struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node)
 {
 	struct irq_desc *desc;
 	unsigned long flags;
@@ -208,7 +214,11 @@ struct irq_desc *irq_to_desc_alloc_node(unsigned int irq, int node)
 	if (desc)
 		goto out_unlock;
 
-	desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
+	if (slab_is_available())
+		desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
+	else
+		desc = alloc_bootmem_node(NODE_DATA(node), sizeof(*desc));
+
 	printk(KERN_DEBUG "  alloc irq_desc for %d on node %d\n", irq, node);
 	if (!desc) {
 		printk(KERN_ERR "can not alloc irq_desc\n");