Skip to contentSkip to conversation

hrtimer: fix sparse warnings on hrtimer locking

PATCH Applied Ben Dooks 2 participants 2 messages Jun 21, 2023 – Jun 22, 2023 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

PATCH 1/1 hrtimer: fix sparse warnings on hrtimer locking

Add __acquires() to the points the hertier spinlock is acquired and a __releases() to when it gets released in unlock_hrtimer_base() as sparse is warning about thses during lock imbalance checks.

Adding these removes the following sparse warnings:

kernel/time/hrtimer.c:175:33: warning: context imbalance in 'lock_hrtimer_base' - wrong count at exit kernel/time/hrtimer.c:1301:28: warning: context imbalance in 'hrtimer_start_range_ns' - unexpected unlock kernel/time/hrtimer.c:1336:28: warning: context imbalance in 'hrtimer_try_to_cancel' - unexpected unlock kernel/time/hrtimer.c:1457:9: warning: context imbalance in '__hrtimer_get_remaining' - unexpected unlock

---
 kernel/time/hrtimer.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/time/hrtimer.c +3 -0
index e8c08292defc..238262e4aba7 100644
@@ -164,6 +164,7 @@ static inline bool is_migration_base(struct hrtimer_clock_base *base)
 static
 struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer,
 					     unsigned long *flags)
+	__acquires(&timer->base->lock)
 {
 	struct hrtimer_clock_base *base;
 
@@ -280,6 +281,7 @@ static inline bool is_migration_base(struct hrtimer_clock_base *base)
 
 static inline struct hrtimer_clock_base *
 lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
+	__acquires(&timer->base->cpu_base->lock)
 {
 	struct hrtimer_clock_base *base = timer->base;
 
@@ -1013,6 +1015,7 @@ void hrtimers_resume_local(void)
  */
 static inline
 void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
+	__releases(&timer->base->cpu_base->lock)
 {
 	raw_spin_unlock_irqrestore(&timer->base->cpu_base->lock, *flags);
 }
Signature · 1 line
2.39.2
merge bot Applied
#1 lore raw

[tip: timers/core] hrtimer: Add missing sparse annotations to hrtimer locking

The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     ccaa4926c2264ca2a2fcad4b3511fe435d7d4d15
Gitweb:        https://git.kernel.org/tip/ccaa4926c2264ca2a2fcad4b3511fe435d7d4d15
Author:        Ben Dooks <[email protected]>
AuthorDate:    Wed, 21 Jun 2023 08:59:28 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Thu, 22 Jun 2023 10:32:37 +02:00

hrtimer: Add missing sparse annotations to hrtimer locking

Sparse warns about lock imbalance vs. the hrtimer_base lock due to missing sparse annotations:

kernel/time/hrtimer.c:175:33: warning: context imbalance in 'lock_hrtimer_base' - wrong count at exit kernel/time/hrtimer.c:1301:28: warning: context imbalance in 'hrtimer_start_range_ns' - unexpected unlock kernel/time/hrtimer.c:1336:28: warning: context imbalance in 'hrtimer_try_to_cancel' - unexpected unlock kernel/time/hrtimer.c:1457:9: warning: context imbalance in '__hrtimer_get_remaining' - unexpected unlock

Add the annotations to the relevant functions.

---
 kernel/time/hrtimer.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/time/hrtimer.c +3 -0
index e8c0829..238262e 100644
@@ -164,6 +164,7 @@ static inline bool is_migration_base(struct hrtimer_clock_base *base)
 static
 struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer,
 					     unsigned long *flags)
+	__acquires(&timer->base->lock)
 {
 	struct hrtimer_clock_base *base;
 
@@ -280,6 +281,7 @@ static inline bool is_migration_base(struct hrtimer_clock_base *base)
 
 static inline struct hrtimer_clock_base *
 lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
+	__acquires(&timer->base->cpu_base->lock)
 {
 	struct hrtimer_clock_base *base = timer->base;
 
@@ -1013,6 +1015,7 @@ void hrtimers_resume_local(void)
  */
 static inline
 void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
+	__releases(&timer->base->cpu_base->lock)
 {
 	raw_spin_unlock_irqrestore(&timer->base->cpu_base->lock, *flags);
 }