mbox series

[bpf-next,0/3] bpf: Enable preemption after irq_work_raise() completes

Message ID 20230822133807.3198625-1-houtao@huaweicloud.com (mailing list archive)
Headers show
Series bpf: Enable preemption after irq_work_raise() completes | expand

Message

Hou Tao Aug. 22, 2023, 1:38 p.m. UTC
From: Hou Tao <houtao1@huawei.com>

Hi,

The patchset aims to fix the problem that bpf_mem_alloc() may return
NULL unexpectedly when multiple bpf_mem_alloc() are invoked concurrently
under process context and there is still free memory available. The
problem was found when doing stress test for qp-trie but the same
problem also exists for bpf_obj_new() as demonstrated in patch #3.

Patch #1 fixes the race between unit_alloc() and unit_alloc(). Patch
#2 fixes the race between unit_alloc() and unit_free(). And patch #3
adds a selftest for the problem. Please see individual patches for more
details. And comments are always welcome.

Hou Tao (3):
  bpf: Enable preemption after irq_work_raise() in unit_alloc()
  bpf: Enable preemption after irq_work_raise() in unit_free{_rcu}()
  selftests/bpf: Test preemption between bpf_obj_new() and
    bpf_obj_drop()

 kernel/bpf/memalloc.c                         |  12 ++
 .../bpf/prog_tests/preempted_bpf_ma_op.c      |  89 +++++++++++++++
 .../selftests/bpf/progs/preempted_bpf_ma_op.c | 106 ++++++++++++++++++
 3 files changed, 207 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/preempted_bpf_ma_op.c
 create mode 100644 tools/testing/selftests/bpf/progs/preempted_bpf_ma_op.c