Skip to contentSkip to conversation

Fix context imbalance warning

PATCH In review Jules Irenge 2 participants 3 messages Apr 15, 2020 CPU hotplug

lore
Share & tools
lore
#0 lore raw

cover Fix context imbalance warning

Hi,

This patch adds an annotations to clear_tasks_mm_cpumask(),
the function registers a warning of context imbalance when built with Sparse tool. The adds fix the warning.

I also tested it and I think it is working fine.

I will appreciate any comment if possible.

Jules Irenge (1):
cpu: Add annotation inside clear_tasks_mm_cpumask()

 kernel/cpu.c | 1 +
 1 file changed, 1 insertion(+)
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/1 cpu: Add annotation inside clear_tasks_mm_cpumask()

Sparse reports a warning

warning: context imbalance in clear_tasks_mm_cpumask() - different lock contexts for basic block

The root cause is the missing annotation inside clear_tasks_mm_cpumask()

Add the missing __acquire(&t->alloc_lock) annotation.

---
 kernel/cpu.c | 1 +
 1 file changed, 1 insertion(+)
kernel/cpu.c +1 -0
index 9c706af713fb..d8c452a8dd09 100644
@@ -834,6 +834,7 @@ void clear_tasks_mm_cpumask(int cpu)
 		t = find_lock_task_mm(p);
 		if (!t)
 			continue;
+		__acquire(&t->alloc_lock);
 		cpumask_clear_cpu(cpu, mm_cpumask(t->mm));
 		task_unlock(t);
 	}
Signature · 1 line
2.24.1
maintainer
#2 lore raw

Re: [PATCH 1/1] cpu: Add annotation inside clear_tasks_mm_cpumask()

Quoted 3 lines · Jules Irenge

Sparse reports a warning

warning: context imbalance in clear_tasks_mm_cpumask() - different lock contexts for basic block

Does this sparse crap actually ever catch a real problem, or does it only result in horrible code like this?

Quoted 3 lines

The root cause is the missing annotation inside clear_tasks_mm_cpumask()

Add the missing __acquire(&t->alloc_lock) annotation.

That's just wrong; the actual cause is find_lock_task_mm() not being annotated, and the reason for that is because __cond_lock() is a horrible piece of crap.

Barring any evidence that these annotations actually help anybody, can't we just remove it all instead of making an ever bigger mess of things?

Quoted 20 lines
---
 kernel/cpu.c | 1 +
 1 file changed, 1 insertion(+)
kernel/cpu.c +1 -0
index 9c706af713fb..d8c452a8dd09 100644
@@ -834,6 +834,7 @@ void clear_tasks_mm_cpumask(int cpu)
 		t = find_lock_task_mm(p);
 		if (!t)
 			continue;
+		__acquire(&t->alloc_lock);
 		cpumask_clear_cpu(cpu, mm_cpumask(t->mm));
 		task_unlock(t);
 	}
Signature · 1 line
2.24.1