From: David Woodhouse <dwmw@xxxxxxxxxxxx> Instead of plugging in irq_default_affinity at the lowest level in desc_smp_init() if the caller didn't specify an affinity for this specific IRQ in its array, allow the default affinity to be passed down from __irq_alloc_descs() instead. This is in preparation for irq domains having their own default (and indeed maximum) affinities. An alternative possibility would have been to make the caller allocate an entire array of struct irq_affinity_desc for the allocation, but that's a lot nastier than simply passing in an additional const cpumask. This commit has no visible API change outside static functions in irqdesc.c for now; the actual change will come later. Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx> --- include/linux/interrupt.h | 2 ++ kernel/irq/irqdesc.c | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index f9aee3538461..cd0ff293486a 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -364,6 +364,8 @@ unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec, #else /* CONFIG_SMP */ +#define irq_default_affinity (NULL) + static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m) { return -EINVAL; diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 1a7723604399..4ac91b9fc618 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -81,8 +81,6 @@ static int alloc_masks(struct irq_desc *desc, int node) static void desc_smp_init(struct irq_desc *desc, int node, const struct cpumask *affinity) { - if (!affinity) - affinity = irq_default_affinity; cpumask_copy(desc->irq_common_data.affinity, affinity); #ifdef CONFIG_GENERIC_PENDING_IRQ @@ -465,12 +463,16 @@ static void free_desc(unsigned int irq) static int alloc_descs(unsigned int start, unsigned int cnt, int node, const struct irq_affinity_desc *affinity, + const struct cpumask *default_affinity, struct module *owner) { struct irq_desc *desc; int i; /* Validate affinity mask(s) */ + if (!default_affinity || cpumask_empty(default_affinity)) + return -EINVAL; + if (affinity) { for (i = 0; i < cnt; i++) { if (cpumask_empty(&affinity[i].mask)) @@ -479,7 +481,7 @@ static int alloc_descs(unsigned int start, unsigned int cnt, int node, } for (i = 0; i < cnt; i++) { - const struct cpumask *mask = NULL; + const struct cpumask *mask = default_affinity; unsigned int flags = 0; if (affinity) { @@ -488,10 +490,10 @@ static int alloc_descs(unsigned int start, unsigned int cnt, int node, IRQD_MANAGED_SHUTDOWN; } mask = &affinity->mask; - node = cpu_to_node(cpumask_first(mask)); affinity++; } + node = cpu_to_node(cpumask_first(mask)); desc = alloc_desc(start + i, node, flags, mask, owner); if (!desc) goto err; @@ -538,7 +540,7 @@ int __init early_irq_init(void) nr_irqs = initcnt; for (i = 0; i < initcnt; i++) { - desc = alloc_desc(i, node, 0, NULL, NULL); + desc = alloc_desc(i, node, 0, irq_default_affinity, NULL); set_bit(i, allocated_irqs); irq_insert_desc(i, desc); } @@ -573,7 +575,8 @@ int __init early_irq_init(void) raw_spin_lock_init(&desc[i].lock); lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); mutex_init(&desc[i].request_mutex); - desc_set_defaults(i, &desc[i], node, NULL, NULL); + desc_set_defaults(i, &desc[i], node, irq_default_affinity, + NULL); } return arch_early_irq_init(); } @@ -590,12 +593,14 @@ static void free_desc(unsigned int irq) unsigned long flags; raw_spin_lock_irqsave(&desc->lock, flags); - desc_set_defaults(irq, desc, irq_desc_get_node(desc), NULL, NULL); + desc_set_defaults(irq, desc, irq_desc_get_node(desc), + irq_default_affinity, NULL); raw_spin_unlock_irqrestore(&desc->lock, flags); } static inline int alloc_descs(unsigned int start, unsigned int cnt, int node, const struct irq_affinity_desc *affinity, + const struct cpumask *default_affinity, struct module *owner) { u32 i; @@ -803,7 +808,7 @@ __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, if (ret) goto unlock; } - ret = alloc_descs(start, cnt, node, affinity, owner); + ret = alloc_descs(start, cnt, node, affinity, irq_default_affinity, owner); unlock: mutex_unlock(&sparse_irq_lock); return ret; -- 2.26.2