Skip to content

Commit cee2716

Browse files
Björn Töpelborkmann
authored andcommitted
xsk: do not call synchronize_net() under RCU read lock
The XSKMAP update and delete functions called synchronize_net(), which can sleep. It is not allowed to sleep during an RCU read section. Instead we need to make sure that the sock sk_destruct (xsk_destruct) function is asynchronously called after an RCU grace period. Setting the SOCK_RCU_FREE flag for XDP sockets takes care of this. Fixes: fbfc504 ("bpf: introduce new bpf AF_XDP map type BPF_MAP_TYPE_XSKMAP") Reported-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: Björn Töpel <bjorn.topel@intel.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 262f9d8 commit cee2716

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

‎kernel/bpf/xskmap.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,8 @@ static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value,
192192
sock_hold(sock->sk);
193193

194194
old_xs = xchg(&m->xsk_map[i], xs);
195-
if (old_xs) {
196-
/* Make sure we've flushed everything. */
197-
synchronize_net();
195+
if (old_xs)
198196
sock_put((struct sock *)old_xs);
199-
}
200197

201198
sockfd_put(sock);
202199
return 0;
@@ -212,11 +209,8 @@ static int xsk_map_delete_elem(struct bpf_map *map, void *key)
212209
return -EINVAL;
213210

214211
old_xs = xchg(&m->xsk_map[k], NULL);
215-
if (old_xs) {
216-
/* Make sure we've flushed everything. */
217-
synchronize_net();
212+
if (old_xs)
218213
sock_put((struct sock *)old_xs);
219-
}
220214

221215
return 0;
222216
}

‎net/xdp/xsk.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,8 @@ static int xsk_create(struct net *net, struct socket *sock, int protocol,
744744
sk->sk_destruct = xsk_destruct;
745745
sk_refcnt_debug_inc(sk);
746746

747+
sock_set_flag(sk, SOCK_RCU_FREE);
748+
747749
xs = xdp_sk(sk);
748750
mutex_init(&xs->mutex);
749751
spin_lock_init(&xs->tx_completion_lock);

0 commit comments

Comments
 (0)