Re: [PATCH 05/13] genirq: Prepare for default affinity to be passed to __irq_alloc_descs()

2020-10-06 Thread David Woodhouse



On 6 October 2020 22:01:18 BST, Thomas Gleixner  wrote:
>On Mon, Oct 05 2020 at 16:28, David Woodhouse wrote:
>>  
>>  #else /* CONFIG_SMP */
>>  
>> +#define irq_default_affinity (NULL)
>
>...
>
>>  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;
>
>How is that supposed to work on UP?

Hm, good point.

>Aside of that I really hate to have yet another argument just
>because.

Yeah, I was trying to avoid having to allocate a whole array of 
irq_affinity_desc just to fill them all in with the same default.

But perhaps I need to treat the "affinity_max" like we do cpu_online_mask, and 
allow affinity to be set even to offline/unreachable CPUs at this point. Then 
we can be more relaxed about the default affinities.

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [PATCH 05/13] genirq: Prepare for default affinity to be passed to __irq_alloc_descs()

2020-10-06 Thread Thomas Gleixner
On Mon, Oct 05 2020 at 16:28, David Woodhouse wrote:
>  
>  #else /* CONFIG_SMP */
>  
> +#define irq_default_affinity (NULL)

...

>  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;

How is that supposed to work on UP?

Aside of that I really hate to have yet another argument just
because.

Thanks,

tglx
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH 05/13] genirq: Prepare for default affinity to be passed to __irq_alloc_descs()

2020-10-05 Thread David Woodhouse
From: David Woodhouse 

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 
---
 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([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 = >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([i].lock);
lockdep_set_class([i].lock, _desc_lock_class);
mutex_init([i].request_mutex);
-   desc_set_defaults(i, [i], node, NULL, NULL);
+   desc_set_defaults(i, [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(>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(>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,