> 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 <[email protected]>
>
> 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);

LGTM but what about sched_show_task? It looks like it has the same
issue. Lets fix it too while we are at it? We could protect it with
RCU critical section.

-- 
Vasileios Almpanis <[email protected]>
_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to