Skip to content

Commit 86723c8

Browse files
tmakitaborkmann
authored andcommitted
bpf, devmap: Add missing RCU read lock on flush
.ndo_xdp_xmit() assumes it is called under RCU. For example virtio_net uses RCU to detect it has setup the resources for tx. The assumption accidentally broke when introducing bulk queue in devmap. Fixes: 5d053f9 ("bpf: devmap prepare xdp frames for bulking") Reported-by: David Ahern <[email protected]> Signed-off-by: Toshiaki Makita <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent edabf4d commit 86723c8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/bpf/devmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ void __dev_map_flush(struct bpf_map *map)
282282
unsigned long *bitmap = this_cpu_ptr(dtab->flush_needed);
283283
u32 bit;
284284

285+
rcu_read_lock();
285286
for_each_set_bit(bit, bitmap, map->max_entries) {
286287
struct bpf_dtab_netdev *dev = READ_ONCE(dtab->netdev_map[bit]);
287288
struct xdp_bulk_queue *bq;
@@ -297,6 +298,7 @@ void __dev_map_flush(struct bpf_map *map)
297298

298299
__clear_bit(bit, bitmap);
299300
}
301+
rcu_read_unlock();
300302
}
301303

302304
/* rcu_read_lock (from syscall and BPF contexts) ensures that if a delete and/or
@@ -389,13 +391,15 @@ static void dev_map_flush_old(struct bpf_dtab_netdev *dev)
389391

390392
int cpu;
391393

394+
rcu_read_lock();
392395
for_each_online_cpu(cpu) {
393396
bitmap = per_cpu_ptr(dev->dtab->flush_needed, cpu);
394397
__clear_bit(dev->bit, bitmap);
395398

396399
bq = per_cpu_ptr(dev->bulkq, cpu);
397400
bq_xmit_all(dev, bq, XDP_XMIT_FLUSH, false);
398401
}
402+
rcu_read_unlock();
399403
}
400404
}
401405

0 commit comments

Comments
 (0)