aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
authorBjörn Töpel <bjorn.topel@intel.com>2018-10-08 13:40:16 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-10-11 04:19:01 -0400
commitcee271678d0e3177a25d0fcb2fa5e051d48e4262 (patch)
treeb63781801b81ccc68cda0d24417764e90ec138c1 /kernel/bpf
parent262f9d811c7608f1e74258ceecfe1fa213bdf912 (diff)
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: fbfc504a24f5 ("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>
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/xskmap.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/kernel/bpf/xskmap.c b/kernel/bpf/xskmap.c
index 9f8463afda9c..47147c9e184d 100644
--- a/kernel/bpf/xskmap.c
+++ b/kernel/bpf/xskmap.c
@@ -192,11 +192,8 @@ static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value,
192 sock_hold(sock->sk); 192 sock_hold(sock->sk);
193 193
194 old_xs = xchg(&m->xsk_map[i], xs); 194 old_xs = xchg(&m->xsk_map[i], xs);
195 if (old_xs) { 195 if (old_xs)
196 /* Make sure we've flushed everything. */
197 synchronize_net();
198 sock_put((struct sock *)old_xs); 196 sock_put((struct sock *)old_xs);
199 }
200 197
201 sockfd_put(sock); 198 sockfd_put(sock);
202 return 0; 199 return 0;
@@ -212,11 +209,8 @@ static int xsk_map_delete_elem(struct bpf_map *map, void *key)
212 return -EINVAL; 209 return -EINVAL;
213 210
214 old_xs = xchg(&m->xsk_map[k], NULL); 211 old_xs = xchg(&m->xsk_map[k], NULL);
215 if (old_xs) { 212 if (old_xs)
216 /* Make sure we've flushed everything. */
217 synchronize_net();
218 sock_put((struct sock *)old_xs); 213 sock_put((struct sock *)old_xs);
219 }
220 214
221 return 0; 215 return 0;
222} 216}