[patch V2 06/45] genirq/proc: Switch to lock guards

Thomas Gleixner posted 45 patches 7 months, 3 weeks ago
[patch V2 06/45] genirq/proc: Switch to lock guards
Posted by Thomas Gleixner 7 months, 3 weeks ago
Convert all lock/unlock pairs to guards and tidy up the code.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

---
 kernel/irq/proc.c |   65 +++++++++++++++++++-----------------------------------
 1 file changed, 24 insertions(+), 41 deletions(-)

--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -81,20 +81,18 @@ static int show_irq_affinity(int type, s
 static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
 {
 	struct irq_desc *desc = irq_to_desc((long)m->private);
-	unsigned long flags;
 	cpumask_var_t mask;
 
 	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
 		return -ENOMEM;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
-	if (desc->affinity_hint)
-		cpumask_copy(mask, desc->affinity_hint);
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
+	scoped_guard(raw_spinlock_irq, &desc->lock) {
+		if (desc->affinity_hint)
+			cpumask_copy(mask, desc->affinity_hint);
+	}
 
 	seq_printf(m, "%*pb\n", cpumask_pr_args(mask));
 	free_cpumask_var(mask);
-
 	return 0;
 }
 
@@ -295,23 +293,18 @@ static int irq_spurious_proc_show(struct
 
 #define MAX_NAMELEN 128
 
-static int name_unique(unsigned int irq, struct irqaction *new_action)
+static bool name_unique(unsigned int irq, struct irqaction *new_action)
 {
 	struct irq_desc *desc = irq_to_desc(irq);
 	struct irqaction *action;
-	unsigned long flags;
-	int ret = 1;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
+	guard(raw_spinlock_irq)(&desc->lock);
 	for_each_action_of_desc(desc, action) {
 		if ((action != new_action) && action->name &&
-				!strcmp(new_action->name, action->name)) {
-			ret = 0;
-			break;
-		}
+		    !strcmp(new_action->name, action->name))
+			return false;
 	}
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-	return ret;
+	return true;
 }
 
 void register_handler_proc(unsigned int irq, struct irqaction *action)
@@ -319,8 +312,7 @@ void register_handler_proc(unsigned int
 	char name [MAX_NAMELEN];
 	struct irq_desc *desc = irq_to_desc(irq);
 
-	if (!desc->dir || action->dir || !action->name ||
-					!name_unique(irq, action))
+	if (!desc->dir || action->dir || !action->name || !name_unique(irq, action))
 		return;
 
 	snprintf(name, MAX_NAMELEN, "%s", action->name);
@@ -347,17 +339,16 @@ void register_irq_proc(unsigned int irq,
 	 * added, not when the descriptor is created, so multiple
 	 * tasks might try to register at the same time.
 	 */
-	mutex_lock(&register_lock);
+	guard(mutex)(&register_lock);
 
 	if (desc->dir)
-		goto out_unlock;
-
-	sprintf(name, "%d", irq);
+		return;
 
 	/* create /proc/irq/1234 */
+	sprintf(name, "%d", irq);
 	desc->dir = proc_mkdir(name, root_irq_dir);
 	if (!desc->dir)
-		goto out_unlock;
+		return;
 
 #ifdef CONFIG_SMP
 	umode_t umode = S_IRUGO;
@@ -366,31 +357,27 @@ void register_irq_proc(unsigned int irq,
 		umode |= S_IWUSR;
 
 	/* create /proc/irq/<irq>/smp_affinity */
-	proc_create_data("smp_affinity", umode, desc->dir,
-			 &irq_affinity_proc_ops, irqp);
+	proc_create_data("smp_affinity", umode, desc->dir, &irq_affinity_proc_ops, irqp);
 
 	/* create /proc/irq/<irq>/affinity_hint */
 	proc_create_single_data("affinity_hint", 0444, desc->dir,
-			irq_affinity_hint_proc_show, irqp);
+				irq_affinity_hint_proc_show, irqp);
 
 	/* create /proc/irq/<irq>/smp_affinity_list */
 	proc_create_data("smp_affinity_list", umode, desc->dir,
 			 &irq_affinity_list_proc_ops, irqp);
 
-	proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show,
-			irqp);
+	proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show, irqp);
 # ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
 	proc_create_single_data("effective_affinity", 0444, desc->dir,
-			irq_effective_aff_proc_show, irqp);
+				irq_effective_aff_proc_show, irqp);
 	proc_create_single_data("effective_affinity_list", 0444, desc->dir,
-			irq_effective_aff_list_proc_show, irqp);
+				irq_effective_aff_list_proc_show, irqp);
 # endif
 #endif
 	proc_create_single_data("spurious", 0444, desc->dir,
-			irq_spurious_proc_show, (void *)(long)irq);
+				irq_spurious_proc_show, (void *)(long)irq);
 
-out_unlock:
-	mutex_unlock(&register_lock);
 }
 
 void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
@@ -468,7 +455,6 @@ int show_interrupts(struct seq_file *p,
 	int i = *(loff_t *) v, j;
 	struct irqaction *action;
 	struct irq_desc *desc;
-	unsigned long flags;
 
 	if (i > ACTUAL_NR_IRQS)
 		return 0;
@@ -487,13 +473,13 @@ int show_interrupts(struct seq_file *p,
 		seq_putc(p, '\n');
 	}
 
-	rcu_read_lock();
+	guard(rcu)();
 	desc = irq_to_desc(i);
 	if (!desc || irq_settings_is_hidden(desc))
-		goto outsparse;
+		return 0;
 
 	if (!desc->action || irq_desc_is_chained(desc) || !desc->kstat_irqs)
-		goto outsparse;
+		return 0;
 
 	seq_printf(p, "%*d:", prec, i);
 	for_each_online_cpu(j) {
@@ -503,7 +489,7 @@ int show_interrupts(struct seq_file *p,
 	}
 	seq_putc(p, ' ');
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
+	guard(raw_spinlock_irq)(&desc->lock);
 	if (desc->irq_data.chip) {
 		if (desc->irq_data.chip->irq_print_chip)
 			desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
@@ -532,9 +518,6 @@ int show_interrupts(struct seq_file *p,
 	}
 
 	seq_putc(p, '\n');
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-outsparse:
-	rcu_read_unlock();
 	return 0;
 }
 #endif
Re: [patch V2 06/45] genirq/proc: Switch to lock guards
Posted by Zenghui Yu 6 months, 1 week ago
Hi Thomas,

On 2025/4/29 14:54, Thomas Gleixner wrote:
> Convert all lock/unlock pairs to guards and tidy up the code.
> 
> No functional change.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> 
> ---
>  kernel/irq/proc.c |   65 +++++++++++++++++++-----------------------------------
>  1 file changed, 24 insertions(+), 41 deletions(-)
> 
> --- a/kernel/irq/proc.c
> +++ b/kernel/irq/proc.c
> @@ -81,20 +81,18 @@ static int show_irq_affinity(int type, s
>  static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
>  {
>  	struct irq_desc *desc = irq_to_desc((long)m->private);
> -	unsigned long flags;
>  	cpumask_var_t mask;
>  
>  	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
>  		return -ENOMEM;
>  
> -	raw_spin_lock_irqsave(&desc->lock, flags);
> -	if (desc->affinity_hint)
> -		cpumask_copy(mask, desc->affinity_hint);
> -	raw_spin_unlock_irqrestore(&desc->lock, flags);
> +	scoped_guard(raw_spinlock_irq, &desc->lock) {

Any reason it has been switched to a raw_spinlock_irq?

I've hit some random Oops with the backtrace looks like:

 Call trace:
  string+0x110/0x3b8 (P)
  vsnprintf+0x2f0/0xac8
  seq_printf+0x180/0x220
  show_interrupts+0x4e0/0x7e0
  seq_read_iter+0x350/0xd80
  proc_reg_read_iter+0x194/0x248
  vfs_read+0x5b0/0x940
  ksys_read+0xf0/0x1e8
  __arm64_sys_read+0x74/0xb0
  invoke_syscall+0x74/0x270
  el0_svc_common.constprop.0+0xb4/0x240
  do_el0_svc+0x48/0x68
  el0_svc+0x4c/0xe8
  el0t_64_sync_handler+0xc8/0xd0
  el0t_64_sync+0x1ac/0x1b0

I haven't dig further. But it looks to me that this patch had introduced
functional change and I'm planning to give the following diff a go on
the same box.

Thanks,
Zenghui

From cfad0937ffb724c2c51c8656c212ccefb09c8990 Mon Sep 17 00:00:00 2001
From: Zenghui Yu <yuzenghui@huawei.com>
Date: Sun, 8 Jun 2025 19:41:41 +0800
Subject: [PATCH] fixup! genirq/proc: Switch to lock guards

Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
---
 kernel/irq/proc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
index 29c2404e743b..5af8bd1f3ab4 100644
--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -86,7 +86,7 @@ static int irq_affinity_hint_proc_show(struct seq_file
*m, void *v)
 	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
 		return -ENOMEM;

-	scoped_guard(raw_spinlock_irq, &desc->lock) {
+	scoped_guard(raw_spinlock_irqsave, &desc->lock) {
 		if (desc->affinity_hint)
 			cpumask_copy(mask, desc->affinity_hint);
 	}
@@ -298,7 +298,7 @@ static bool name_unique(unsigned int irq, struct
irqaction *new_action)
 	struct irq_desc *desc = irq_to_desc(irq);
 	struct irqaction *action;

-	guard(raw_spinlock_irq)(&desc->lock);
+	guard(raw_spinlock_irqsave)(&desc->lock);
 	for_each_action_of_desc(desc, action) {
 		if ((action != new_action) && action->name &&
 		    !strcmp(new_action->name, action->name))
@@ -489,7 +489,7 @@ int show_interrupts(struct seq_file *p, void *v)
 	}
 	seq_putc(p, ' ');

-	guard(raw_spinlock_irq)(&desc->lock);
+	guard(raw_spinlock_irqsave)(&desc->lock);
 	if (desc->irq_data.chip) {
 		if (desc->irq_data.chip->irq_print_chip)
 			desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
-- 
2.33.0
Re: [patch V2 06/45] genirq/proc: Switch to lock guards
Posted by Thomas Gleixner 6 months, 1 week ago
On Sun, Jun 08 2025 at 20:45, Zenghui Yu wrote:
> On 2025/4/29 14:54, Thomas Gleixner wrote:
>> -	raw_spin_lock_irqsave(&desc->lock, flags);
>> -	if (desc->affinity_hint)
>> -		cpumask_copy(mask, desc->affinity_hint);
>> -	raw_spin_unlock_irqrestore(&desc->lock, flags);
>> +	scoped_guard(raw_spinlock_irq, &desc->lock) {
>
> Any reason it has been switched to a raw_spinlock_irq?

Yes. This code is always thread context and can never be invoked with
interrupts disabled. So there is zero reason to use irqsave().

> I've hit some random Oops with the backtrace looks like:
>
>  Call trace:
>   string+0x110/0x3b8 (P)
>   vsnprintf+0x2f0/0xac8
>   seq_printf+0x180/0x220
>   show_interrupts+0x4e0/0x7e0
>   seq_read_iter+0x350/0xd80
>   proc_reg_read_iter+0x194/0x248
>   vfs_read+0x5b0/0x940
>   ksys_read+0xf0/0x1e8
>   __arm64_sys_read+0x74/0xb0
>   invoke_syscall+0x74/0x270
>   el0_svc_common.constprop.0+0xb4/0x240
>   do_el0_svc+0x48/0x68
>   el0_svc+0x4c/0xe8
>   el0t_64_sync_handler+0xc8/0xd0
>   el0t_64_sync+0x1ac/0x1b0
>
> I haven't dig further. But it looks to me that this patch had introduced
> functional change and I'm planning to give the following diff a go on
> the same box.

That won't help at all because the actual crash is within show_interrupts()....

Thanks,

        tglx
Re: [patch V2 06/45] genirq/proc: Switch to lock guards
Posted by Zenghui Yu 6 months, 1 week ago
On 2025/6/8 20:45, Zenghui Yu wrote:
> Hi Thomas,
> 
> On 2025/4/29 14:54, Thomas Gleixner wrote:
> > Convert all lock/unlock pairs to guards and tidy up the code.
> >
> > No functional change.
> >
> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> >
> > ---
> >  kernel/irq/proc.c |   65 +++++++++++++++++++-----------------------------------
> >  1 file changed, 24 insertions(+), 41 deletions(-)
> >
> > --- a/kernel/irq/proc.c
> > +++ b/kernel/irq/proc.c
> > @@ -81,20 +81,18 @@ static int show_irq_affinity(int type, s
> >  static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
> >  {
> >  	struct irq_desc *desc = irq_to_desc((long)m->private);
> > -	unsigned long flags;
> >  	cpumask_var_t mask;
> >  
> >  	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
> >  		return -ENOMEM;
> >  
> > -	raw_spin_lock_irqsave(&desc->lock, flags);
> > -	if (desc->affinity_hint)
> > -		cpumask_copy(mask, desc->affinity_hint);
> > -	raw_spin_unlock_irqrestore(&desc->lock, flags);
> > +	scoped_guard(raw_spinlock_irq, &desc->lock) {
> 
> Any reason it has been switched to a raw_spinlock_irq?
> 
> I've hit some random Oops with the backtrace looks like:
> 
>  Call trace:
>   string+0x110/0x3b8 (P)
>   vsnprintf+0x2f0/0xac8
>   seq_printf+0x180/0x220
>   show_interrupts+0x4e0/0x7e0
>   seq_read_iter+0x350/0xd80
>   proc_reg_read_iter+0x194/0x248
>   vfs_read+0x5b0/0x940
>   ksys_read+0xf0/0x1e8
>   __arm64_sys_read+0x74/0xb0
>   invoke_syscall+0x74/0x270
>   el0_svc_common.constprop.0+0xb4/0x240
>   do_el0_svc+0x48/0x68
>   el0_svc+0x4c/0xe8
>   el0t_64_sync_handler+0xc8/0xd0
>   el0t_64_sync+0x1ac/0x1b0
> 
> I haven't dig further. But it looks to me that this patch had introduced
> functional change and I'm planning to give the following diff a go on
> the same box.
> 
> Thanks,
> Zenghui
> 
>>From cfad0937ffb724c2c51c8656c212ccefb09c8990 Mon Sep 17 00:00:00 2001
> From: Zenghui Yu <yuzenghui@huawei.com>
> Date: Sun, 8 Jun 2025 19:41:41 +0800
> Subject: [PATCH] fixup! genirq/proc: Switch to lock guards
> 
> Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
> ---
>  kernel/irq/proc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
> index 29c2404e743b..5af8bd1f3ab4 100644
> --- a/kernel/irq/proc.c
> +++ b/kernel/irq/proc.c
> @@ -86,7 +86,7 @@ static int irq_affinity_hint_proc_show(struct seq_file
> *m, void *v)
>  	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
>  		return -ENOMEM;
> 
> -	scoped_guard(raw_spinlock_irq, &desc->lock) {
> +	scoped_guard(raw_spinlock_irqsave, &desc->lock) {
>  		if (desc->affinity_hint)
>  			cpumask_copy(mask, desc->affinity_hint);
>  	}
> @@ -298,7 +298,7 @@ static bool name_unique(unsigned int irq, struct
> irqaction *new_action)
>  	struct irq_desc *desc = irq_to_desc(irq);
>  	struct irqaction *action;
> 
> -	guard(raw_spinlock_irq)(&desc->lock);
> +	guard(raw_spinlock_irqsave)(&desc->lock);
>  	for_each_action_of_desc(desc, action) {
>  		if ((action != new_action) && action->name &&
>  		    !strcmp(new_action->name, action->name))
> @@ -489,7 +489,7 @@ int show_interrupts(struct seq_file *p, void *v)
>  	}
>  	seq_putc(p, ' ');
> 
> -	guard(raw_spinlock_irq)(&desc->lock);
> +	guard(raw_spinlock_irqsave)(&desc->lock);
>  	if (desc->irq_data.chip) {
>  		if (desc->irq_data.chip->irq_print_chip)
>  			desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);

Plus,

diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index b0e0a7332993..57facdc30d55 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -964,7 +964,7 @@ __irq_do_set_handler(struct irq_desc *desc,
irq_flow_handler_t handle,
 void __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int
is_chained,
 		       const char *name)
 {
-	scoped_irqdesc_get_and_lock(irq, 0)
+	scoped_irqdesc_get_and_buslock(irq, 0)
 		__irq_do_set_handler(scoped_irqdesc, handle, is_chained, name);
 }
 EXPORT_SYMBOL_GPL(__irq_set_handler);
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index c94837382037..400856abf672 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -659,7 +659,7 @@ void __disable_irq(struct irq_desc *desc)

 static int __disable_irq_nosync(unsigned int irq)
 {
-	scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
+	scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
 		__disable_irq(scoped_irqdesc);
 		return 0;
 	}
@@ -789,7 +789,7 @@ void __enable_irq(struct irq_desc *desc)
  */
 void enable_irq(unsigned int irq)
 {
-	scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
+	scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
 		struct irq_desc *desc = scoped_irqdesc;

 		if (WARN(!desc->irq_data.chip, "enable_irq before setup/request_irq:
irq %u\n", irq))
Re: [patch V2 06/45] genirq/proc: Switch to lock guards
Posted by Thomas Gleixner 6 months, 1 week ago
On Mon, Jun 09 2025 at 15:15, Zenghui Yu wrote:
> On 2025/6/8 20:45, Zenghui Yu wrote:
>> On 2025/4/29 14:54, Thomas Gleixner wrote:
> Plus,
>
> diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
> index b0e0a7332993..57facdc30d55 100644
> --- a/kernel/irq/chip.c
> +++ b/kernel/irq/chip.c
> @@ -964,7 +964,7 @@ __irq_do_set_handler(struct irq_desc *desc,
> irq_flow_handler_t handle,
>  void __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int
> is_chained,
>  		       const char *name)
>  {
> -	scoped_irqdesc_get_and_lock(irq, 0)
> +	scoped_irqdesc_get_and_buslock(irq, 0)

What for? Which problem are you trying to solve here?

>  		__irq_do_set_handler(scoped_irqdesc, handle, is_chained, name);
>  }
>  EXPORT_SYMBOL_GPL(__irq_set_handler);
> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index c94837382037..400856abf672 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -659,7 +659,7 @@ void __disable_irq(struct irq_desc *desc)
>
>  static int __disable_irq_nosync(unsigned int irq)
>  {
> -	scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
> +	scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {

That's broken as __disable_irq_nosync() can be invoked from
non-preemtible contexts.

>  		__disable_irq(scoped_irqdesc);
>  		return 0;
>  	}
> @@ -789,7 +789,7 @@ void __enable_irq(struct irq_desc *desc)
>   */
>  void enable_irq(unsigned int irq)
>  {
> -	scoped_irqdesc_get_and_lock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {
> +	scoped_irqdesc_get_and_buslock(irq, IRQ_GET_DESC_CHECK_GLOBAL) {

Ditto.

Can you stop making random changes and instead provide the actual
information to decode the OOPS?

>  string+0x110/0x3b8 (P)
>  vsnprintf+0x2f0/0xac8
>  seq_printf+0x180/0x220
>  show_interrupts+0x4e0/0x7e0

This means the print in show_interrupts() accesses an invalid
pointer. So the obvious thing to do is:

  scripts/faddr2line vmlinux show_interrupts+0x4e0/0x7e0

and provide the information, which of the gazillions of seq_printf()'s
in that function causes the problem.

I'm pretty sure that is has absolutely nothing to do with the guard()
conversions.

Thanks,

        tglx
Re: [patch V2 06/45] genirq/proc: Switch to lock guards
Posted by Jiri Slaby 6 months, 1 week ago
On 09. 06. 25, 9:15, Zenghui Yu wrote:
>> >From cfad0937ffb724c2c51c8656c212ccefb09c8990 Mon Sep 17 00:00:00 2001
>> From: Zenghui Yu <yuzenghui@huawei.com>
>> Date: Sun, 8 Jun 2025 19:41:41 +0800
>> Subject: [PATCH] fixup! genirq/proc: Switch to lock guards
>>
>> Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
>> ---
>>   kernel/irq/proc.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
>> index 29c2404e743b..5af8bd1f3ab4 100644
>> --- a/kernel/irq/proc.c
>> +++ b/kernel/irq/proc.c
>> @@ -86,7 +86,7 @@ static int irq_affinity_hint_proc_show(struct seq_file
>> *m, void *v)
>>   	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
>>   		return -ENOMEM;
>>
>> -	scoped_guard(raw_spinlock_irq, &desc->lock) {
>> +	scoped_guard(raw_spinlock_irqsave, &desc->lock) {
>>   		if (desc->affinity_hint)
>>   			cpumask_copy(mask, desc->affinity_hint);
>>   	}
>> @@ -298,7 +298,7 @@ static bool name_unique(unsigned int irq, struct
>> irqaction *new_action)
>>   	struct irq_desc *desc = irq_to_desc(irq);
>>   	struct irqaction *action;
>>
>> -	guard(raw_spinlock_irq)(&desc->lock);
>> +	guard(raw_spinlock_irqsave)(&desc->lock);
>>   	for_each_action_of_desc(desc, action) {
>>   		if ((action != new_action) && action->name &&
>>   		    !strcmp(new_action->name, action->name))
>> @@ -489,7 +489,7 @@ int show_interrupts(struct seq_file *p, void *v)
>>   	}
>>   	seq_putc(p, ' ');
>>
>> -	guard(raw_spinlock_irq)(&desc->lock);
>> +	guard(raw_spinlock_irqsave)(&desc->lock);
>>   	if (desc->irq_data.chip) {
>>   		if (desc->irq_data.chip->irq_print_chip)
>>   			desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
> 
> Plus,

Could you send proper patches, pls?

-- 
js
suse labs
[tip: irq/core] genirq/proc: Switch to lock guards
Posted by tip-bot2 for Thomas Gleixner 7 months, 2 weeks ago
The following commit has been merged into the irq/core branch of tip:

Commit-ID:     659ff9c9d77b8ad9d9c18e264abc9a56bd19230e
Gitweb:        https://git.kernel.org/tip/659ff9c9d77b8ad9d9c18e264abc9a56bd19230e
Author:        Thomas Gleixner <tglx@linutronix.de>
AuthorDate:    Tue, 29 Apr 2025 08:54:56 +02:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 07 May 2025 09:08:11 +02:00

genirq/proc: Switch to lock guards

Convert all lock/unlock pairs to guards and tidy up the code.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/20250429065420.373998838@linutronix.de


---
 kernel/irq/proc.c | 65 ++++++++++++++++------------------------------
 1 file changed, 24 insertions(+), 41 deletions(-)

diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
index 8e29809..94eba9a 100644
--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -81,20 +81,18 @@ static int show_irq_affinity(int type, struct seq_file *m)
 static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
 {
 	struct irq_desc *desc = irq_to_desc((long)m->private);
-	unsigned long flags;
 	cpumask_var_t mask;
 
 	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
 		return -ENOMEM;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
-	if (desc->affinity_hint)
-		cpumask_copy(mask, desc->affinity_hint);
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
+	scoped_guard(raw_spinlock_irq, &desc->lock) {
+		if (desc->affinity_hint)
+			cpumask_copy(mask, desc->affinity_hint);
+	}
 
 	seq_printf(m, "%*pb\n", cpumask_pr_args(mask));
 	free_cpumask_var(mask);
-
 	return 0;
 }
 
@@ -295,23 +293,18 @@ static int irq_spurious_proc_show(struct seq_file *m, void *v)
 
 #define MAX_NAMELEN 128
 
-static int name_unique(unsigned int irq, struct irqaction *new_action)
+static bool name_unique(unsigned int irq, struct irqaction *new_action)
 {
 	struct irq_desc *desc = irq_to_desc(irq);
 	struct irqaction *action;
-	unsigned long flags;
-	int ret = 1;
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
+	guard(raw_spinlock_irq)(&desc->lock);
 	for_each_action_of_desc(desc, action) {
 		if ((action != new_action) && action->name &&
-				!strcmp(new_action->name, action->name)) {
-			ret = 0;
-			break;
-		}
+		    !strcmp(new_action->name, action->name))
+			return false;
 	}
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-	return ret;
+	return true;
 }
 
 void register_handler_proc(unsigned int irq, struct irqaction *action)
@@ -319,8 +312,7 @@ void register_handler_proc(unsigned int irq, struct irqaction *action)
 	char name [MAX_NAMELEN];
 	struct irq_desc *desc = irq_to_desc(irq);
 
-	if (!desc->dir || action->dir || !action->name ||
-					!name_unique(irq, action))
+	if (!desc->dir || action->dir || !action->name || !name_unique(irq, action))
 		return;
 
 	snprintf(name, MAX_NAMELEN, "%s", action->name);
@@ -347,17 +339,16 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
 	 * added, not when the descriptor is created, so multiple
 	 * tasks might try to register at the same time.
 	 */
-	mutex_lock(&register_lock);
+	guard(mutex)(&register_lock);
 
 	if (desc->dir)
-		goto out_unlock;
-
-	sprintf(name, "%d", irq);
+		return;
 
 	/* create /proc/irq/1234 */
+	sprintf(name, "%d", irq);
 	desc->dir = proc_mkdir(name, root_irq_dir);
 	if (!desc->dir)
-		goto out_unlock;
+		return;
 
 #ifdef CONFIG_SMP
 	umode_t umode = S_IRUGO;
@@ -366,31 +357,27 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
 		umode |= S_IWUSR;
 
 	/* create /proc/irq/<irq>/smp_affinity */
-	proc_create_data("smp_affinity", umode, desc->dir,
-			 &irq_affinity_proc_ops, irqp);
+	proc_create_data("smp_affinity", umode, desc->dir, &irq_affinity_proc_ops, irqp);
 
 	/* create /proc/irq/<irq>/affinity_hint */
 	proc_create_single_data("affinity_hint", 0444, desc->dir,
-			irq_affinity_hint_proc_show, irqp);
+				irq_affinity_hint_proc_show, irqp);
 
 	/* create /proc/irq/<irq>/smp_affinity_list */
 	proc_create_data("smp_affinity_list", umode, desc->dir,
 			 &irq_affinity_list_proc_ops, irqp);
 
-	proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show,
-			irqp);
+	proc_create_single_data("node", 0444, desc->dir, irq_node_proc_show, irqp);
 # ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
 	proc_create_single_data("effective_affinity", 0444, desc->dir,
-			irq_effective_aff_proc_show, irqp);
+				irq_effective_aff_proc_show, irqp);
 	proc_create_single_data("effective_affinity_list", 0444, desc->dir,
-			irq_effective_aff_list_proc_show, irqp);
+				irq_effective_aff_list_proc_show, irqp);
 # endif
 #endif
 	proc_create_single_data("spurious", 0444, desc->dir,
-			irq_spurious_proc_show, (void *)(long)irq);
+				irq_spurious_proc_show, (void *)(long)irq);
 
-out_unlock:
-	mutex_unlock(&register_lock);
 }
 
 void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
@@ -468,7 +455,6 @@ int show_interrupts(struct seq_file *p, void *v)
 	int i = *(loff_t *) v, j;
 	struct irqaction *action;
 	struct irq_desc *desc;
-	unsigned long flags;
 
 	if (i > ACTUAL_NR_IRQS)
 		return 0;
@@ -487,13 +473,13 @@ int show_interrupts(struct seq_file *p, void *v)
 		seq_putc(p, '\n');
 	}
 
-	rcu_read_lock();
+	guard(rcu)();
 	desc = irq_to_desc(i);
 	if (!desc || irq_settings_is_hidden(desc))
-		goto outsparse;
+		return 0;
 
 	if (!desc->action || irq_desc_is_chained(desc) || !desc->kstat_irqs)
-		goto outsparse;
+		return 0;
 
 	seq_printf(p, "%*d:", prec, i);
 	for_each_online_cpu(j) {
@@ -503,7 +489,7 @@ int show_interrupts(struct seq_file *p, void *v)
 	}
 	seq_putc(p, ' ');
 
-	raw_spin_lock_irqsave(&desc->lock, flags);
+	guard(raw_spinlock_irq)(&desc->lock);
 	if (desc->irq_data.chip) {
 		if (desc->irq_data.chip->irq_print_chip)
 			desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
@@ -532,9 +518,6 @@ int show_interrupts(struct seq_file *p, void *v)
 	}
 
 	seq_putc(p, '\n');
-	raw_spin_unlock_irqrestore(&desc->lock, flags);
-outsparse:
-	rcu_read_unlock();
 	return 0;
 }
 #endif