linux-stable/include
Roman Gushchin 4bfc0bb2c6 bpf: decouple the lifetime of cgroup_bpf from cgroup itself
Currently the lifetime of bpf programs attached to a cgroup is bound
to the lifetime of the cgroup itself. It means that if a user
forgets (or intentionally avoids) to detach a bpf program before
removing the cgroup, it will stay attached up to the release of the
cgroup. Since the cgroup can stay in the dying state (the state
between being rmdir()'ed and being released) for a very long time, it
leads to a waste of memory. Also, it blocks a possibility to implement
the memcg-based memory accounting for bpf objects, because a circular
reference dependency will occur. Charged memory pages are pinning the
corresponding memory cgroup, and if the memory cgroup is pinning
the attached bpf program, nothing will be ever released.

A dying cgroup can not contain any processes, so the only chance for
an attached bpf program to be executed is a live socket associated
with the cgroup. So in order to release all bpf data early, let's
count associated sockets using a new percpu refcounter. On cgroup
removal the counter is transitioned to the atomic mode, and as soon
as it reaches 0, all bpf programs are detached.

Because cgroup_bpf_release() can block, it can't be called from
the percpu ref counter callback directly, so instead an asynchronous
work is scheduled.

The reference counter is not socket specific, and can be used for any
other types of programs, which can be executed from a cgroup-bpf hook
outside of the process context, had such a need arise in the future.

Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: jolsa@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-05-28 09:30:02 -07:00
..
acpi More ACPI updates for 5.2-rc1 2019-05-15 08:58:49 -07:00
asm-generic Merge branch 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-05-19 10:23:24 -07:00
clocksource
crypto crypto: hash - fix incorrect HASH_MAX_DESCSIZE 2019-05-17 13:36:54 +08:00
drm drm pull request for 5.2 2019-05-08 21:35:19 -07:00
dt-bindings dt-bindings: phy: dp83867: Add documentation for disabling clock output 2019-05-22 17:40:17 -07:00
keys
kvm
linux bpf: decouple the lifetime of cgroup_bpf from cgroup itself 2019-05-28 09:30:02 -07:00
math-emu
media media updates for v5.2-rc1 2019-05-16 11:57:16 -07:00
memory
misc ocxl: Provide global MMIO accessors for external drivers 2019-05-03 02:55:02 +10:00
net net: Set strict_start_type for routes and rules 2019-05-22 17:50:24 -07:00
pcmcia
ras
rdma RDMA: Add EFA related definitions 2019-05-06 13:47:50 -03:00
scsi
soc Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-05-19 11:11:20 -07:00
sound sound fixes for 5.2-rc1 2019-05-17 13:57:54 -07:00
target
trace neighbor: Add tracepoint to __neigh_create 2019-05-22 17:50:24 -07:00
uapi bpf: introduce new bpf prog load flags "BPF_F_TEST_RND_HI32" 2019-05-24 18:58:37 -07:00
video treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 13 2019-05-21 11:28:45 +02:00
xen