Commit 8ae682b3 authored by Zheng Yejian's avatar Zheng Yejian Committed by Jialin Zhang
Browse files

livepatch/core: Fix hungtask against cpu hotplug on x86

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6NVPT



--------------------------------

Concurrently enable/disable livepatch and online/offline cpu cause
deadlock:
  __klp_{enable,disable}_patch()      _cpu_{up,down}()
  --------                            --------
  mutex_lock(&text_mutex);
                                      cpus_write_lock();
  cpus_read_lock();
                                      mutex_lock(&text_mutex);

__klp_{enable,disable}_patch() hold text_mutex then wait cpu_hotplug_lock,
while _cpu_{up,down}() hold cpu_hotplug_lock but wait text_mutex,
finally result in the deadlock.

Cpu hotplug locking is a "percpu" rw semaphore, however write lock and read
lock on it are globally mutual exclusive, that is cpus_write_lock() on one
cpu can block all cpus_read_lock() on other cpus, vice versa.

Similar lock issue was solved in commit 2d1e38f5 ("kprobes: Cure
hotplug lock ordering issues") which change lock order to be:
  kprobe_mutex -> cpus_rwsem -> jump_label_mutex -> text_mutex

Therefore take cpus_read_lock() before text_mutex to avoid deadlock.

Fixes: f5a67467 ("livepatch/x86: support livepatch without ftrace")
Signed-off-by: default avatarZheng Yejian <zhengyejian1@huawei.com>
Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parent bc58faea
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment