Skip to contentSkip to conversation

lockdep: Fix redundant_hardirqs_on incremented with irqs enabled

PATCH New Frederic Weisbecker 1 participant 2 messages Apr 15, 2010

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 lockdep: Fix redundant_hardirqs_on incremented with irqs enabled

When a path restore the flags while irqs are already enabled, we update the per cpu var redundant_hardirqs_on in a racy fashion and debug_atomic_inc() warns about this situation.

In this particular case, loosing a few hits in a stat is not a big deal, so increment it without protection.

v2: Don't bother with disabling irq, we can miss one count in
rare situations

Cc Peter Zijlstra <[email protected]>
Cc David Miller <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
---
 kernel/lockdep.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
kernel/lockdep.c +6 -1
index 78325f8..1b58a1b 100644
@@ -2298,7 +2298,12 @@ void trace_hardirqs_on_caller(unsigned long ip)
 		return;
 
 	if (unlikely(curr->hardirqs_enabled)) {
-		debug_atomic_inc(redundant_hardirqs_on);
+		/*
+		 * Neither irq nor preemption are disabled here
+		 * so this is racy by nature but loosing one hit
+		 * in a stat is not a big deal.
+		 */
+		this_cpu_inc(lockdep_stats.redundant_hardirqs_on);
 		return;
 	}
 	/* we'll do an OFF -> ON transition: */
Signature · 1 line
1.6.2.3
#1 lore raw

PATCH 2/2 lockdep: Simplify debug atomic ops

Simplify debug_atomic_inc/dec by using this_cpu_inc/dec() instead of doing it through an indirect get_cpu_var() and a manual incrementation.

---
 kernel/lockdep_internals.h |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
kernel/lockdep_internals.h +2 -8
index 8d7d4b6..2b17476 100644
@@ -140,19 +140,13 @@ struct lockdep_stats {
 DECLARE_PER_CPU(struct lockdep_stats, lockdep_stats);
 
 #define debug_atomic_inc(ptr)			{		\
-	struct lockdep_stats *__cpu_lockdep_stats;		\
-								\
 	WARN_ON_ONCE(!irqs_disabled());				\
-	__cpu_lockdep_stats = &__get_cpu_var(lockdep_stats);	\
-	__cpu_lockdep_stats->ptr++;				\
+	this_cpu_inc(lockdep_stats.ptr);			\
 }
 
 #define debug_atomic_dec(ptr)			{		\
-	struct lockdep_stats *__cpu_lockdep_stats;		\
-								\
 	WARN_ON_ONCE(!irqs_disabled());				\
-	__cpu_lockdep_stats = &__get_cpu_var(lockdep_stats);	\
-	__cpu_lockdep_stats->ptr--;				\
+	this_cpu_inc(lockdep_stats.ptr);			\
 }
 
 #define debug_atomic_read(ptr)		({				\
Signature · 1 line
1.6.2.3