All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.1] sched/stats: fix a hard lockup on task_lock in update_sched_lat()
@ 2026-11-16 10:15 Denis V. Lunev
  2026-11-16 10:20 ` no-reply
  2026-11-16 11:04 ` Vasileios Almpanis
  0 siblings, 2 replies; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-16 10:15 UTC (permalink / raw)
  To: khorenko; +Cc: devel

From: Denis V. Lunev <den@openvz.org>

Commit ead7be4fd3ca ("ve: Switch from ->task_ve to *task_ve() helpers")
made update_sched_lat() look the ve up with get_task_ve(), which takes
task_lock. update_sched_lat() runs from __update_stats_wait_end() under
rq->__lock with interrupts off whenever kernel.sched_schedstats is on,
while task_lock is taken elsewhere with interrupts on. Any lock taken
in an interrupt and held across a wakeup then closes a cycle. wbt does
it on an I/O completion:

  CPU A: /proc reader     CPU B: NVMe irq         CPU C: scheduler
  -------------------     ---------------         ----------------
  getdents64(/proc/X/fd)
    task_lock(X)
                          nvme_irq()
                            wbt_done()
                              lock wq
                                                  __schedule()
                                                    rq_lock(C)
                                                    pick X
  nvme_irq()
    wbt_done()
      lock wq  -> spins
                              wake W, slept on C:
                                rq_lock(C) -> spins
                                                    set_next_entity(X)
                                                      update_sched_lat(X)
                                                        get_task_ve(X)
                                                          task_lock(X)
                                                            -> spins

wq is the wbt wait queue of the device and W a writer throttled on it.
W slept in iowait on C, so try_to_wake_up() locks C's rq to move the
iowait count off it before migrating W. Every other CPU completing I/O
on that device then spins on wq too, and the hard lockup detector
panics the node.

The put_ve() under rq->__lock is unsafe as well: dropping the last
reference queues the css release work, and that wakeup may need the rq
lock already held.

Read the pointer with task_ve() and take no reference, as the code did
before that commit. Whoever switches the ve of the task, the old one is
freed from css_free after an RCU grace period, and rq->__lock with
interrupts off is an RCU read-side critical section.

Fixes: ead7be4fd3ca ("ve: Switch from ->task_ve to *task_ve() helpers")

https://virtuozzo.atlassian.net/browse/VSTOR-155276

Feature: ve: ve generic structures
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
 kernel/sched/stats.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c
index 08ed7c8a9c4a..ede339b768cf 100644
--- a/kernel/sched/stats.c
+++ b/kernel/sched/stats.c
@@ -23,10 +23,8 @@ void __update_stats_wait_start(struct rq *rq, struct task_struct *p,
 static inline void update_sched_lat(struct task_struct *t, u64 delta, u64 now)
 {
 #ifdef CONFIG_VE
-	struct ve_struct *ve __free(put_ve) = get_task_ve(t);
-
 	KSTAT_LAT_PCPU_ADD(&kstat_glob.sched_lat, delta);
-	KSTAT_LAT_PCPU_ADD(&ve->sched_lat_ve, delta);
+	KSTAT_LAT_PCPU_ADD(&task_ve(t)->sched_lat_ve, delta);
 
 	t->alloc_lat[KSTAT_SCHED].totlat += delta;
 	t->alloc_lat[KSTAT_SCHED].count++;
-- 
2.55.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-16 11:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 10:15 [Devel] [PATCH hci-8.1] sched/stats: fix a hard lockup on task_lock in update_sched_lat() Denis V. Lunev
2026-11-16 10:20 ` no-reply
2026-11-16 11:04 ` Vasileios Almpanis
2026-11-16 11:19   ` Denis V. Lunev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.