]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
genirq: Prepare for default affinity to be passed to __irq_alloc_descs()
authorDavid Woodhouse <dwmw@amazon.co.uk>
Sun, 4 Oct 2020 10:10:43 +0000 (11:10 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 7 Oct 2020 10:17:46 +0000 (11:17 +0100)
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@amazon.co.uk>
include/linux/interrupt.h
kernel/irq/irqdesc.c

index f9aee35384610b6e6f22b8a56e84bfd72dc5f301..cd0ff293486aac0cfec636d809c6e5ea970c92bf 100644 (file)
@@ -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;
index 1a7723604399c09496a77433b1685604680edc5e..4ac91b9fc618ed6b0cbca9139152dce4fefc253e 100644 (file)
@@ -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;