public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/4] Use this_cpu_xxx for preemption-safety
@ 2022-09-01  6:19 Hou Tao
  2022-09-01  6:19 ` [PATCH bpf-next v2 1/4] bpf: Use this_cpu_{inc|dec|inc_return} for bpf_task_storage_busy Hou Tao
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Hou Tao @ 2022-09-01  6:19 UTC (permalink / raw)
  To: bpf
  Cc: Song Liu, Sebastian Andrzej Siewior, Hao Sun, Hao Luo,
	Andrii Nakryiko, Yonghong Song, Alexei Starovoitov,
	Daniel Borkmann, Martin KaFai Lau, KP Singh, David S . Miller,
	Jakub Kicinski, Stanislav Fomichev, Jiri Olsa, John Fastabend,
	Lorenz Bauer, houtao1

From: Hou Tao <houtao1@huawei.com>

Hi,

The patchset aims to make the update of per-cpu prog->active and per-cpu
bpf_task_storage_busy being preemption-safe. The problem is on same
architectures (e.g. arm64), __this_cpu_{inc|dec|inc_return} are neither
preemption-safe nor IRQ-safe, so under fully preemptible kernel the
concurrent updates on these per-cpu variables may be interleaved and the
final values of these variables may be not zero.

Patch 1 & 2 use the preemption-safe per-cpu helpers to manipulate
prog->active and bpf_task_storage_busy. Patch 3 & 4 add a test case in
map_tests to show the concurrent updates on the per-cpu
bpf_task_storage_busy by using __this_cpu_{inc|dec} are not atomic.

Comments are always welcome.

Regards,
Tao

Change Log:
v2:
* Patch 1: update commit message to indicate the problem is only
  possible for fully preemptible kernel
* Patch 2: a new patch which fixes the problem for prog->active
* Patch 3 & 4: move it to test_maps and make it depend on CONFIG_PREEMPT
 
v1: https://lore.kernel.org/bpf/20220829142752.330094-1-houtao@huaweicloud.com/

Hou Tao (4):
  bpf: Use this_cpu_{inc|dec|inc_return} for bpf_task_storage_busy
  bpf: Use this_cpu_{inc_return|dec} for prog->active
  selftests/bpf: Move sys_pidfd_open() into task_local_storage_helpers.h
  selftests/bpf: Test concurrent updates on bpf_task_storage_busy

 kernel/bpf/bpf_local_storage.c                |   4 +-
 kernel/bpf/bpf_task_storage.c                 |   8 +-
 kernel/bpf/trampoline.c                       |   8 +-
 .../bpf/map_tests/task_storage_map.c          | 122 ++++++++++++++++++
 .../selftests/bpf/prog_tests/test_bprm_opts.c |  10 +-
 .../bpf/prog_tests/test_local_storage.c       |  10 +-
 .../bpf/progs/read_bpf_task_storage_busy.c    |  39 ++++++
 .../bpf/task_local_storage_helpers.h          |  18 +++
 8 files changed, 191 insertions(+), 28 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/map_tests/task_storage_map.c
 create mode 100644 tools/testing/selftests/bpf/progs/read_bpf_task_storage_busy.c
 create mode 100644 tools/testing/selftests/bpf/task_local_storage_helpers.h

-- 
2.29.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-09-02  3:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-01  6:19 [PATCH bpf-next v2 0/4] Use this_cpu_xxx for preemption-safety Hou Tao
2022-09-01  6:19 ` [PATCH bpf-next v2 1/4] bpf: Use this_cpu_{inc|dec|inc_return} for bpf_task_storage_busy Hou Tao
2022-09-01  6:19 ` [PATCH bpf-next v2 2/4] bpf: Use this_cpu_{inc_return|dec} for prog->active Hou Tao
2022-09-01  6:19 ` [PATCH bpf-next v2 3/4] selftests/bpf: Move sys_pidfd_open() into task_local_storage_helpers.h Hou Tao
2022-09-01  6:19 ` [PATCH bpf-next v2 4/4] selftests/bpf: Test concurrent updates on bpf_task_storage_busy Hou Tao
2022-09-01 19:37   ` Martin KaFai Lau
2022-09-02  3:16     ` Hou Tao
2022-09-01 19:30 ` [PATCH bpf-next v2 0/4] Use this_cpu_xxx for preemption-safety patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox