Skip to contentSkip to conversation

blk-iolatency: use guard(spinlock_irqsave)() in iolatency_clear_scaling()

PATCH New Tao Cui 1 participant 1 message Jul 17

Subsystems (3)
lore
Share & tools
lore

Tao Cui

author
#0 lore raw

PATCH v2 1/1 blk-iolatency: use guard(spinlock_irqsave)() in iolatency_clear_scaling()

From: Tao Cui <[email protected]>

child_lat.lock is acquired with irqsave semantics in both iolatency_check_latencies() (called from the blkcg_iolatency_done_bio() softirq path) and blkiolatency_timer_fn() (timer softirq). iolatency_clear_scaling() instead uses a plain spin_lock(), which only happens to be safe because both of its callers enter with interrupts already disabled:

* iolatency_set_limit() runs under queue_lock via blkg_conf_prep(),

    which returns with the lock held and interrupts disabled;

* iolatency_pd_offline() runs under queue_lock from blkg_destroy() and blkcg_deactivate_policy(), both of which take it with spin_lock_irq().

Take the lock with guard(spinlock_irqsave)() so the locking is self-contained and consistent with the other two sites, instead of relying on an undocumented caller precondition. No functional change.

---

Changes in v2:
- use guard(spinlock_irqsave)() (suggested by Leon Hwang)

---
 block/blk-iolatency.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-iolatency.c +1 -2
index cef02b6c5fa9..1cc33aa0b669 100644
@@ -815,12 +815,11 @@ static void iolatency_clear_scaling(struct blkcg_gq *blkg)
 			return;
 
 		lat_info = &iolat->child_lat;
-		spin_lock(&lat_info->lock);
+		guard(spinlock_irqsave)(&lat_info->lock);
 		atomic_set(&lat_info->scale_cookie, DEFAULT_SCALE_COOKIE);
 		lat_info->last_scale_event = 0;
 		lat_info->scale_grp = NULL;
 		lat_info->scale_lat = 0;
-		spin_unlock(&lat_info->lock);
 	}
 }
 
Signature · 1 line
2.43.0