]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - kernel/bpf/devmap.c
drm/i915/execlists: Track active elements during dequeue
[linux.git] / kernel / bpf / devmap.c
index de630f9802825503a114946b53457fd3dda94963..58bdca5d978a820eec9f7efa9ecdba95f61b0883 100644 (file)
@@ -190,10 +190,12 @@ static void dev_map_free(struct bpf_map *map)
 
        /* At this point bpf_prog->aux->refcnt == 0 and this map->refcnt == 0,
         * so the programs (can be more than one that used this map) were
-        * disconnected from events. Wait for outstanding critical sections in
-        * these programs to complete. The rcu critical section only guarantees
-        * no further reads against netdev_map. It does __not__ ensure pending
-        * flush operations (if any) are complete.
+        * disconnected from events. The following synchronize_rcu() guarantees
+        * both rcu read critical sections complete and waits for
+        * preempt-disable regions (NAPI being the relevant context here) so we
+        * are certain there will be no further reads against the netdev_map and
+        * all flush operations are complete. Flush operations can only be done
+        * from NAPI context for this reason.
         */
 
        spin_lock(&dev_map_lock);
@@ -263,7 +265,8 @@ struct bpf_dtab_netdev *__dev_map_hash_lookup_elem(struct bpf_map *map, u32 key)
        struct hlist_head *head = dev_map_index_hash(dtab, key);
        struct bpf_dtab_netdev *dev;
 
-       hlist_for_each_entry_rcu(dev, head, index_hlist)
+       hlist_for_each_entry_rcu(dev, head, index_hlist,
+                                lockdep_is_held(&dtab->index_lock))
                if (dev->idx == key)
                        return dev;
 
@@ -363,16 +366,17 @@ static int bq_xmit_all(struct xdp_dev_bulk_queue *bq, u32 flags)
  * from NET_RX_SOFTIRQ. Either way the poll routine must complete before the
  * net device can be torn down. On devmap tear down we ensure the flush list
  * is empty before completing to ensure all flush operations have completed.
+ * When drivers update the bpf program they may need to ensure any flush ops
+ * are also complete. Using synchronize_rcu or call_rcu will suffice for this
+ * because both wait for napi context to exit.
  */
 void __dev_flush(void)
 {
        struct list_head *flush_list = this_cpu_ptr(&dev_flush_list);
        struct xdp_dev_bulk_queue *bq, *tmp;
 
-       rcu_read_lock();
        list_for_each_entry_safe(bq, tmp, flush_list, flush_node)
                bq_xmit_all(bq, XDP_XMIT_FLUSH);
-       rcu_read_unlock();
 }
 
 /* rcu_read_lock (from syscall and BPF contexts) ensures that if a delete and/or
@@ -502,12 +506,11 @@ static int dev_map_delete_elem(struct bpf_map *map, void *key)
                return -EINVAL;
 
        /* Use call_rcu() here to ensure any rcu critical sections have
-        * completed, but this does not guarantee a flush has happened
-        * yet. Because driver side rcu_read_lock/unlock only protects the
-        * running XDP program. However, for pending flush operations the
-        * dev and ctx are stored in another per cpu map. And additionally,
-        * the driver tear down ensures all soft irqs are complete before
-        * removing the net device in the case of dev_put equals zero.
+        * completed as well as any flush operations because call_rcu
+        * will wait for preempt-disable region to complete, NAPI in this
+        * context.  And additionally, the driver tear down ensures all
+        * soft irqs are complete before removing the net device in the
+        * case of dev_put equals zero.
         */
        old_dev = xchg(&dtab->netdev_map[k], NULL);
        if (old_dev)