]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
bpf: Use this_cpu_{inc|dec|inc_return} for bpf_task_storage_busy
authorHou Tao <houtao1@huawei.com>
Thu, 1 Sep 2022 06:19:35 +0000 (14:19 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Thu, 24 Nov 2022 13:24:15 +0000 (14:24 +0100)
commit8ac3f41743e4cf6c673d5e1d98b565ec1d1e585c
treec5aa0af4ac1aef84003ee93ab822f91180d3df8e
parentd2e27fc77d702d2203a963bd3c0c606c5665edc4
bpf: Use this_cpu_{inc|dec|inc_return} for bpf_task_storage_busy

BugLink: https://bugs.launchpad.net/bugs/1996825
[ Upstream commit 197827a05e13808c60f52632e9887eede63f1c16 ]

Now migrate_disable() does not disable preemption and under some
architectures (e.g. arm64) __this_cpu_{inc|dec|inc_return} are neither
preemption-safe nor IRQ-safe, so for fully preemptible kernel concurrent
lookups or updates on the same task local storage and on the same CPU
may make bpf_task_storage_busy be imbalanced, and
bpf_task_storage_trylock() on the specific cpu will always fail.

Fixing it by using this_cpu_{inc|dec|inc_return} when manipulating
bpf_task_storage_busy.

Fixes: bc235cdb423a ("bpf: Prevent deadlock from recursive bpf_task_storage_[get|delete]")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/r/20220901061938.3789460-2-houtao@huaweicloud.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
kernel/bpf/bpf_local_storage.c
kernel/bpf/bpf_task_storage.c