]> git.proxmox.com Git - mirror_lxcfs.git/commit
cpuview: fix ABBA deadlock in find_proc_stat_node
authorAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Mon, 16 Jan 2023 11:34:52 +0000 (12:34 +0100)
committerAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Mon, 16 Jan 2023 11:44:50 +0000 (12:44 +0100)
commit1e8d209fa2abc151b0e858caef4d396156d38366
tree8356103839745f35615b4869bac6a0ff63e1070f
parent0f7fe141ba747142c3961903e9549f3b64036c0e
cpuview: fix ABBA deadlock in find_proc_stat_node

Thanks to detailed report from Nikhil it was discovered
that on some workloads reads from lxcfs getting stuck.

After analysis of kernel crashdump it was found, that many
"mtail" processes waiting on read() from /proc/stat file.

First suspect was my last commit that fixes use-after-free,
but unfortunately it also adds ABBA deadlock.

Thread 1                                                   Thread 2

find_proc_stat_node():
rwlock_read                                               rwlock_read
mutex_lock(some_node) [taken]                      mutex_lock(some_node) [wait T1]
rwlock_unlock
rwlock_wrlock (prune_proc_stat_history call) [wait T2]

BOOM. That's deadlock.

Fix is simple, let's just move prune_proc_stat_history call
before taking mutex on cg_proc_stat node.

Fixes: 54db3e71b ("cpuview: fix possible use-after-free in find_proc_stat_node")
Issue #471

Reported-by: Nikhil Kshirsagar <nikhil.kshirsagar@canonical.com>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
src/proc_cpuview.c