-
Notifications
You must be signed in to change notification settings - Fork 131
bpf, sockmap: Fix concurrency issues between memory charge and uncharge #8911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Upstream branch: 43745d1 |
e4e98c9
to
8b8229f
Compare
Upstream branch: b69d441 |
49cd791
to
97c6b89
Compare
8b8229f
to
4b2ad00
Compare
Upstream branch: 32c563d |
97c6b89
to
e23f379
Compare
4b2ad00
to
13a3aab
Compare
Upstream branch: 0f2d39f |
e23f379
to
e6d6ef6
Compare
13a3aab
to
f1ad525
Compare
Upstream branch: cf15cdc |
e6d6ef6
to
0d4927a
Compare
f1ad525
to
d99abbe
Compare
Upstream branch: cb4a119 |
0d4927a
to
45e9d07
Compare
d99abbe
to
3deadef
Compare
Upstream branch: 5a8cb23 |
45e9d07
to
837f569
Compare
3deadef
to
71504b4
Compare
Upstream branch: c8ce7db |
837f569
to
63857e0
Compare
71504b4
to
4861ed7
Compare
Upstream branch: 7220eab |
63857e0
to
8937650
Compare
4861ed7
to
833154b
Compare
Upstream branch: d0445d7 |
e58e284
to
d00eb24
Compare
6ffb2d9
to
d48a548
Compare
Upstream branch: d0445d7 |
d00eb24
to
8c1c077
Compare
d48a548
to
c5ed444
Compare
Upstream branch: 4dd372d |
8c1c077
to
284ae43
Compare
c5ed444
to
30a6f23
Compare
Upstream branch: 9325d53 |
284ae43
to
b843728
Compare
30a6f23
to
abba24e
Compare
Upstream branch: 9325d53 |
b843728
to
fc68b05
Compare
abba24e
to
b62c574
Compare
Upstream branch: 1cb0f56 |
fc68b05
to
09a9d30
Compare
b62c574
to
7b56de2
Compare
Upstream branch: b615ce5 |
09a9d30
to
4357db2
Compare
7b56de2
to
49174bd
Compare
Upstream branch: b615ce5 |
4357db2
to
cd7222c
Compare
49174bd
to
f3a4188
Compare
Upstream branch: 25b6d5d |
Triggering WARN_ON_ONCE(sk->sk_forward_alloc) by running the following command, followed by pressing Ctrl-C after 2 seconds: ./bench sockmap -c 2 -p 1 -a --rx-verdict-ingress ''' ------------[ cut here ]------------ WARNING: CPU: 2 PID: 40 at net/ipv4/af_inet.c inet_sock_destruct Call Trace: <TASK> __sk_destruct+0x46/0x222 sk_psock_destroy+0x22f/0x242 process_one_work+0x504/0x8a8 ? process_one_work+0x39d/0x8a8 ? __pfx_process_one_work+0x10/0x10 ? worker_thread+0x44/0x2ae ? __list_add_valid_or_report+0x83/0xea ? srso_return_thunk+0x5/0x5f ? __list_add+0x45/0x52 process_scheduled_works+0x73/0x82 worker_thread+0x1ce/0x2ae ''' Reason: When we are in the backlog process, we allocate sk_msg and then perform the charge process. Meanwhile, in the user process context, the recvmsg() operation performs the uncharge process, leading to concurrency issues between them. The charge process (2 functions): 1. sk_rmem_schedule(size) -> sk_forward_alloc increases by PAGE_SIZE multiples 2. sk_mem_charge(size) -> sk_forward_alloc -= size The uncharge process (sk_mem_uncharge()): 3. sk_forward_alloc += size 4. check if sk_forward_alloc > PAGE_SIZE 5. reclaim -> sk_forward_alloc decreases, possibly becoming 0 Because the sk performing charge and uncharge is not locked (mainly because the backlog process does not lock the socket), therefore, steps 1 to 5 will execute concurrently as follows: cpu0 cpu1 1 3 4 --> sk_forward_alloc >= PAGE_SIZE 5 --> reclaim sk_forward_alloc 2 --> sk_forward_alloc may become negative Solution: 1. Add locking to the kfree_sk_msg() process, which is only called in the user process context. 2. Integrate the charge process into sk_psock_create_ingress_msg() in the backlog process and add locking. 3. Reuse the existing psock->ingress_lock. Fixes: 799aa7f ("skmsg: Avoid lock_sock() in sk_psock_backlog()") Signed-off-by: Jiayuan Chen <[email protected]>
cd7222c
to
31d14c9
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=960768 irrelevant now for [Munch({'archived': False, 'project': 399, 'delegate': 121173})] search patterns |
Pull request for series with
subject: bpf, sockmap: Fix concurrency issues between memory charge and uncharge
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=960768