OSDN Git Service

Merge branch 'fix_bpf_send_signal'
authorAlexei Starovoitov <ast@kernel.org>
Thu, 5 Mar 2020 21:59:13 +0000 (13:59 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 5 Mar 2020 22:09:22 +0000 (14:09 -0800)
commita35a76faad53429b52a8937b69fdeee5b4e5f935
tree92d864323c3302206195a100bc8cc17e4d2530da
parent52e7c083b417417bb4352ebf3a6409988b6af238
parentc4ef2f3256e3bc008f98121cad39ee5467db07a6
Merge branch 'fix_bpf_send_signal'

Yonghong Song says:

====================
Commit 8b401f9ed244 ("bpf: implement bpf_send_signal() helper")
introduced bpf_send_signal() helper and Commit 8482941f0906
("bpf: Add bpf_send_signal_thread() helper") added bpf_send_signal_thread()
helper. Both helpers try to send a signel to current process or thread.

When bpf_prog is called with scheduler rq_lock held, a deadlock
could happen since bpf_send_signal() and bpf_send_signal_thread()
will call group_send_sig_info() which may ultimately want to acquire
rq_lock() again. This happens in 5.2 and 4.16 based kernels in our
production environment with perf_sw_event.

In a different scenario, the following is also possible in the last kernel:
  cpu 1:
     do_task_stat <- holding sighand->siglock
     ...
     task_sched_runtime <- trying to grab rq_lock

  cpu 2:
     __schedule <- holding rq_lock
     ...
     do_send_sig_info <- trying to grab sighand->siglock

Commit eac9153f2b58 ("bpf/stackmap: Fix deadlock with
rq_lock in bpf_get_stack()") has a similar issue with above
rq_lock() deadlock. This patch set addressed the issue
in a similar way. Patch #1 provided kernel solution and
Patch #2 added a selftest.

Changelogs:
  v2 -> v3:
    . simplify selftest send_signal_sched_switch().
      The previous version has mmap/munmap inherited
      from Song's reproducer. They are not necessary
      in this context.
  v1 -> v2:
    . previous fix using task_work in nmi() is incorrect.
      there is no nmi() involvement here. Using task_work
      in all cases might be a solution. But decided to
      use a similar fix as in Commit eac9153f2b58.
====================

Signed-off-by: Alexei Starovoitov <ast@kernel.org>