sparseirq: Enable early irq_desc allocation.
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. :-)
---
kernel/irq/handle.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
kernel/irq/handle.c +12 -5
@@ -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) {
Quoted 65 lines · Paul Mundt
Presently non-legacy IRQs have their
irq_descallocated withkzalloc_node(). This assumes that all callers ofirq_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_bootmemcheck 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]>Signed-off-by Paul Mundt <[email protected]>---
kernel/irq/handle.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)kernel/irq/handle.c +8
-4@@ -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
-1node =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
Quoted 15 lines · Yinghai Lu
can you check tip?
we change_cputo node already.also only sh have
after_bootmemnow.
arch/sh/mm/init.c:intafter_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:enumbootmem_state{ arch/x86/include/asm/page_types.h:extern enumbootmem_statebootmem_state;arch/x86/kernel/setup.c:bootmem_state=DURING_BOOTMEM;
arch/x86/mm/init.c:enumbootmem_statebootmem_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 movebootmem_stateback tolinux/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.
---
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
@@ -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" );
Quoted 22 lines · Paul Mundt
Quoted 21 lines · Yinghai Lu
can you check tip?
we change_cputo node already.also only sh have
after_bootmemnow.
arch/sh/mm/init.c:intafter_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:enumbootmem_state{ arch/x86/include/asm/page_types.h:extern enumbootmem_statebootmem_state;arch/x86/kernel/setup.c:bootmem_state=DURING_BOOTMEM;
arch/x86/mm/init.c:enumbootmem_statebootmem_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 movebootmem_stateback tolinux/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
[tip:irq/numa] sparseirq: Allow early irq_desc allocation
In reply to Paul MundtCommit-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
@@ -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" );