]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpf, devmap: Add missing RCU read lock on flush
authorToshiaki Makita <toshiaki.makita1@gmail.com>
Fri, 14 Jun 2019 08:20:15 +0000 (17:20 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 14 Jun 2019 22:58:51 +0000 (00:58 +0200)
.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: 5d053f9da431 ("bpf: devmap prepare xdp frames for bulking")
Reported-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
kernel/bpf/devmap.c

index a126d95d12de62f992ad3ce7df0fbb8d2f7408c2..1defea4b27553c6c5733b0a2ce531cac671b5fad 100644 (file)
@@ -282,6 +282,7 @@ void __dev_map_flush(struct bpf_map *map)
        unsigned long *bitmap = this_cpu_ptr(dtab->flush_needed);
        u32 bit;
 
+       rcu_read_lock();
        for_each_set_bit(bit, bitmap, map->max_entries) {
                struct bpf_dtab_netdev *dev = READ_ONCE(dtab->netdev_map[bit]);
                struct xdp_bulk_queue *bq;
@@ -297,6 +298,7 @@ void __dev_map_flush(struct bpf_map *map)
 
                __clear_bit(bit, bitmap);
        }
+       rcu_read_unlock();
 }
 
 /* rcu_read_lock (from syscall and BPF contexts) ensures that if a delete and/or
@@ -389,6 +391,7 @@ static void dev_map_flush_old(struct bpf_dtab_netdev *dev)
 
                int cpu;
 
+               rcu_read_lock();
                for_each_online_cpu(cpu) {
                        bitmap = per_cpu_ptr(dev->dtab->flush_needed, cpu);
                        __clear_bit(dev->bit, bitmap);
@@ -396,6 +399,7 @@ static void dev_map_flush_old(struct bpf_dtab_netdev *dev)
                        bq = per_cpu_ptr(dev->bulkq, cpu);
                        bq_xmit_all(dev, bq, XDP_XMIT_FLUSH, false);
                }
+               rcu_read_unlock();
        }
 }