History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Daniel Borkmann says: ==================== pull-request: bpf-next 2021-06-28 The following pull-request contains BPF updates for your *net-next* tree. We've added 37 non-merge commits during the last 12 day(s) which contain a total of 56 files changed, 394 insertions(+), 380 deletions(-). The main changes are: 1) XDP driver RCU cleanups, from Toke Høiland-Jørgensen and Paul E. McKenney. 2) Fix bpf_skb_change_proto() IPv4/v6 GSO handling, from Maciej Żenczykowski. 3) Fix false positive kmemleak report for BPF ringbuf alloc, from Rustam Kovhaev. 4) Fix x86 JIT's extable offset calculation for PROBE_LDX NULL, from Ravi Bangoria. 5) Enable libbpf fallback probing with tracing under RHEL7, from Jonathan Edwards. 6) Clean up x86 JIT to remove unused cnt tracking from EMIT macro, from Jiri Olsa. 7) Netlink cleanups for libbpf to please Coverity, from Kumar Kartikeya Dwivedi. 8) Allow to retrieve ancestor cgroup id in tracing programs, from Namhyung Kim. 9) Fix lirc BPF program query to use user-provided prog_cnt, from Sean Young. 10) Add initial libbpf doc including generated kdoc for its API, from Grant Seltzer. 11) Make xdp_rxq_info_unreg_mem_model() more robust, from Jakub Kicinski. 12) Fix up bpfilter startup log-level to info level, from Gary Lin. ====================

David S. Miller committed 5 years ago

Commit e1289cf2 parents 1fd07f3 a78cae256 files · +394 −380Browse files

Showing the changes to kernel (7 of 56 files). Show all

Unified · Split

7 files
  1. kernel/bpf/cpumap.c +9 −4
  2. kernel/bpf/devmap.c +21 −28
  3. kernel/bpf/hashtab.c +14 −7
  4. kernel/bpf/helpers.c +3 −3
  5. kernel/bpf/lpm_trie.c +4 −2
  6. kernel/bpf/ringbuf.c +2 −0
  7. kernel/trace/bpf_trace.c +2 −0
kernel/bpf/cpumap.c+9−4
@@ -74,7 +74,7 @@ struct bpf_cpu_map_entry { · 73 unmodified lines
7474 struct bpf_cpu_map {
7575 struct bpf_map map;
7676 /* Below members specific for map type */
77− struct bpf_cpu_map_entry **cpu_map;
77+ struct bpf_cpu_map_entry __rcu **cpu_map;
7878 };
7979
8080 static DEFINE_PER_CPU(struct list_head, cpu_map_flush_list);
@@ -469,7 +469,7 @@ static void __cpu_map_entry_replace(struct bpf_cpu_map *cmap, · 388 unmodified lines
469469 {
470470 struct bpf_cpu_map_entry *old_rcpu;
471471
472− old_rcpu = xchg(&cmap->cpu_map[key_cpu], rcpu);
472+ old_rcpu = unrcu_pointer(xchg(&cmap->cpu_map[key_cpu], RCU_INITIALIZER(rcpu)));
473473 if (old_rcpu) {
474474 call_rcu(&old_rcpu->rcu, __cpu_map_entry_free);
475475 INIT_WORK(&old_rcpu->kthread_stop_wq, cpu_map_kthread_stop);
@@ -551,7 +551,7 @@ static void cpu_map_free(struct bpf_map *map) · 75 unmodified lines
551551 for (i = 0; i < cmap->map.max_entries; i++) {
552552 struct bpf_cpu_map_entry *rcpu;
553553
554− rcpu = READ_ONCE(cmap->cpu_map[i]);
554+ rcpu = rcu_dereference_raw(cmap->cpu_map[i]);
555555 if (!rcpu)
556556 continue;
557557
@@ -562,6 +562,10 @@ static void cpu_map_free(struct bpf_map *map) · 4 unmodified lines
562562 kfree(cmap);
563563 }
564564
565+/* Elements are kept alive by RCU; either by rcu_read_lock() (from syscall) or
566+ * by local_bh_disable() (from XDP calls inside NAPI). The
567+ * rcu_read_lock_bh_held() below makes lockdep accept both.
568+ */
565569 static void *__cpu_map_lookup_elem(struct bpf_map *map, u32 key)
566570 {
567571 struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);
@@ -570,7 +574,8 @@ static void *__cpu_map_lookup_elem(struct bpf_map *map, u32 key) · 2 unmodified lines
570574 if (key >= map->max_entries)
571575 return NULL;
572576
573− rcpu = READ_ONCE(cmap->cpu_map[key]);
577+ rcpu = rcu_dereference_check(cmap->cpu_map[key],
578+ rcu_read_lock_bh_held());
574579 return rcpu;
575580 }
576581
kernel/bpf/devmap.c+21−28
@@ -73,7 +73,7 @@ struct bpf_dtab_netdev { · 72 unmodified lines
7373
7474 struct bpf_dtab {
7575 struct bpf_map map;
76− struct bpf_dtab_netdev **netdev_map; /* DEVMAP type only */
76+ struct bpf_dtab_netdev __rcu **netdev_map; /* DEVMAP type only */
7777 struct list_head list;
7878
7979 /* these are only used for DEVMAP_HASH type maps */
@@ -226,7 +226,7 @@ static void dev_map_free(struct bpf_map *map) · 146 unmodified lines
226226 for (i = 0; i < dtab->map.max_entries; i++) {
227227 struct bpf_dtab_netdev *dev;
228228
229− dev = dtab->netdev_map[i];
229+ dev = rcu_dereference_raw(dtab->netdev_map[i]);
230230 if (!dev)
231231 continue;
232232
@@ -259,6 +259,10 @@ static int dev_map_get_next_key(struct bpf_map *map, void *key, void *next_key) · 26 unmodified lines
259259 return 0;
260260 }
261261
262+/* Elements are kept alive by RCU; either by rcu_read_lock() (from syscall) or
263+ * by local_bh_disable() (from XDP calls inside NAPI). The
264+ * rcu_read_lock_bh_held() below makes lockdep accept both.
265+ */
262266 static void *__dev_map_hash_lookup_elem(struct bpf_map *map, u32 key)
263267 {
264268 struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);
@@ -410,15 +414,9 @@ out: · 145 unmodified lines
410414 trace_xdp_devmap_xmit(bq->dev_rx, dev, sent, cnt - sent, err);
411415 }
412416
413−/* __dev_flush is called from xdp_do_flush() which _must_ be signaled
414− * from the driver before returning from its napi->poll() routine. The poll()
415− * routine is called either from busy_poll context or net_rx_action signaled
416− * from NET_RX_SOFTIRQ. Either way the poll routine must complete before the
417− * net device can be torn down. On devmap tear down we ensure the flush list
418− * is empty before completing to ensure all flush operations have completed.
419− * When drivers update the bpf program they may need to ensure any flush ops
420− * are also complete. Using synchronize_rcu or call_rcu will suffice for this
421− * because both wait for napi context to exit.
417+/* __dev_flush is called from xdp_do_flush() which _must_ be signalled from the
418+ * driver before returning from its napi->poll() routine. See the comment above
419+ * xdp_do_flush() in filter.c.
422420 */
423421 void __dev_flush(void)
424422 {
@@ -433,9 +431,9 @@ void __dev_flush(void) · 8 unmodified lines
433431 }
434432 }
435433
436−/* rcu_read_lock (from syscall and BPF contexts) ensures that if a delete and/or
437− * update happens in parallel here a dev_put won't happen until after reading
438− * the ifindex.
434+/* Elements are kept alive by RCU; either by rcu_read_lock() (from syscall) or
435+ * by local_bh_disable() (from XDP calls inside NAPI). The
436+ * rcu_read_lock_bh_held() below makes lockdep accept both.
439437 */
440438 static void *__dev_map_lookup_elem(struct bpf_map *map, u32 key)
441439 {
@@ -445,12 +443,14 @@ static void *__dev_map_lookup_elem(struct bpf_map *map, u32 key) · 3 unmodified lines
445443 if (key >= map->max_entries)
446444 return NULL;
447445
448− obj = READ_ONCE(dtab->netdev_map[key]);
446+ obj = rcu_dereference_check(dtab->netdev_map[key],
447+ rcu_read_lock_bh_held());
449448 return obj;
450449 }
451450
452−/* Runs under RCU-read-side, plus in softirq under NAPI protection.
453− * Thus, safe percpu variable access.
451+/* Runs in NAPI, i.e., softirq under local_bh_disable(). Thus, safe percpu
452+ * variable access, and map elements stick around. See comment above
453+ * xdp_do_flush() in filter.c.
454454 */
455455 static void bq_enqueue(struct net_device *dev, struct xdp_frame *xdpf,
456456 struct net_device *dev_rx, struct bpf_prog *xdp_prog)
@@ -735,14 +735,7 @@ static int dev_map_delete_elem(struct bpf_map *map, void *key) · 278 unmodified lines
735735 if (k >= map->max_entries)
736736 return -EINVAL;
737737
738− /* Use call_rcu() here to ensure any rcu critical sections have
739− * completed as well as any flush operations because call_rcu
740− * will wait for preempt-disable region to complete, NAPI in this
741− * context. And additionally, the driver tear down ensures all
742− * soft irqs are complete before removing the net device in the
743− * case of dev_put equals zero.
744− */
745− old_dev = xchg(&dtab->netdev_map[k], NULL);
738+ old_dev = unrcu_pointer(xchg(&dtab->netdev_map[k], NULL));
746739 if (old_dev)
747740 call_rcu(&old_dev->rcu, __dev_map_entry_free);
748741 return 0;
@@ -851,7 +844,7 @@ static int __dev_map_update_elem(struct net *net, struct bpf_map *map, · 102 unmodified lines
851844 * Remembering the driver side flush operation will happen before the
852845 * net device is removed.
853846 */
854− old_dev = xchg(&dtab->netdev_map[i], dev);
847+ old_dev = unrcu_pointer(xchg(&dtab->netdev_map[i], RCU_INITIALIZER(dev)));
855848 if (old_dev)
856849 call_rcu(&old_dev->rcu, __dev_map_entry_free);
857850
@@ -1031,10 +1024,10 @@ static int dev_map_notification(struct notifier_block *notifier, · 173 unmodified lines
10311024 for (i = 0; i < dtab->map.max_entries; i++) {
10321025 struct bpf_dtab_netdev *dev, *odev;
10331026
1034− dev = READ_ONCE(dtab->netdev_map[i]);
1027+ dev = rcu_dereference(dtab->netdev_map[i]);
10351028 if (!dev || netdev != dev->dev)
10361029 continue;
1037− odev = cmpxchg(&dtab->netdev_map[i], dev, NULL);
1030+ odev = unrcu_pointer(cmpxchg(&dtab->netdev_map[i], RCU_INITIALIZER(dev), NULL));
10381031 if (dev == odev)
10391032 call_rcu(&dev->rcu,
10401033 __dev_map_entry_free);
kernel/bpf/hashtab.c+14−7
@@ -596,7 +596,8 @@ static void *__htab_map_lookup_elem(struct bpf_map *map, void *key) · 595 unmodified lines
596596 struct htab_elem *l;
597597 u32 hash, key_size;
598598
599− WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
599+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
600+ !rcu_read_lock_bh_held());
600601
601602 key_size = map->key_size;
602603
@@ -989,7 +990,8 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value, · 386 unmodified lines
989990 /* unknown flags */
990991 return -EINVAL;
991992
992− WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
993+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
994+ !rcu_read_lock_bh_held());
993995
994996 key_size = map->key_size;
995997
@@ -1082,7 +1084,8 @@ static int htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value, · 86 unmodified lines
10821084 /* unknown flags */
10831085 return -EINVAL;
10841086
1085− WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
1087+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
1088+ !rcu_read_lock_bh_held());
10861089
10871090 key_size = map->key_size;
10881091
@@ -1148,7 +1151,8 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key, · 59 unmodified lines
11481151 /* unknown flags */
11491152 return -EINVAL;
11501153
1151− WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
1154+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
1155+ !rcu_read_lock_bh_held());
11521156
11531157 key_size = map->key_size;
11541158
@@ -1202,7 +1206,8 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key, · 47 unmodified lines
12021206 /* unknown flags */
12031207 return -EINVAL;
12041208
1205− WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
1209+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
1210+ !rcu_read_lock_bh_held());
12061211
12071212 key_size = map->key_size;
12081213
@@ -1276,7 +1281,8 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key) · 67 unmodified lines
12761281 u32 hash, key_size;
12771282 int ret;
12781283
1279− WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
1284+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
1285+ !rcu_read_lock_bh_held());
12801286
12811287 key_size = map->key_size;
12821288
@@ -1311,7 +1317,8 @@ static int htab_lru_map_delete_elem(struct bpf_map *map, void *key) · 28 unmodified lines
13111317 u32 hash, key_size;
13121318 int ret;
13131319
1314− WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
1320+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
1321+ !rcu_read_lock_bh_held());
13151322
13161323 key_size = map->key_size;
13171324
kernel/bpf/helpers.c+3−3
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929 */
3030 BPF_CALL_2(bpf_map_lookup_elem, struct bpf_map *, map, void *, key)
3131 {
32− WARN_ON_ONCE(!rcu_read_lock_held());
32+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_bh_held());
3333 return (unsigned long) map->ops->map_lookup_elem(map, key);
3434 }
3535
@@ -45,7 +45,7 @@ const struct bpf_func_proto bpf_map_lookup_elem_proto = { · 9 unmodified lines
4545 BPF_CALL_4(bpf_map_update_elem, struct bpf_map *, map, void *, key,
4646 void *, value, u64, flags)
4747 {
48− WARN_ON_ONCE(!rcu_read_lock_held());
48+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_bh_held());
4949 return map->ops->map_update_elem(map, key, value, flags);
5050 }
5151
@@ -62,7 +62,7 @@ const struct bpf_func_proto bpf_map_update_elem_proto = { · 10 unmodified lines
6262
6363 BPF_CALL_2(bpf_map_delete_elem, struct bpf_map *, map, void *, key)
6464 {
65− WARN_ON_ONCE(!rcu_read_lock_held());
65+ WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_bh_held());
6666 return map->ops->map_delete_elem(map, key);
6767 }
6868
kernel/bpf/lpm_trie.c+4−2
@@ -232,7 +232,8 @@ static void *trie_lookup_elem(struct bpf_map *map, void *_key) · 231 unmodified lines
232232
233233 /* Start walking the trie from the root node ... */
234234
235− for (node = rcu_dereference(trie->root); node;) {
235+ for (node = rcu_dereference_check(trie->root, rcu_read_lock_bh_held());
236+ node;) {
236237 unsigned int next_bit;
237238 size_t matchlen;
238239
@@ -264,7 +265,8 @@ static void *trie_lookup_elem(struct bpf_map *map, void *_key) · 25 unmodified lines
264265 * traverse down.
265266 */
266267 next_bit = extract_bit(key->data, node->prefixlen);
267− node = rcu_dereference(node->child[next_bit]);
268+ node = rcu_dereference_check(node->child[next_bit],
269+ rcu_read_lock_bh_held());
268270 }
269271
270272 if (!found)
kernel/bpf/ringbuf.c+2−0
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #include <linux/vmalloc.h>
99 #include <linux/wait.h>
1010 #include <linux/poll.h>
11+#include <linux/kmemleak.h>
1112 #include <uapi/linux/btf.h>
1213
1314 #define RINGBUF_CREATE_FLAG_MASK (BPF_F_NUMA_NODE)
@@ -105,6 +106,7 @@ static struct bpf_ringbuf *bpf_ringbuf_area_alloc(size_t data_sz, int numa_node) · 91 unmodified lines
105106 rb = vmap(pages, nr_meta_pages + 2 * nr_data_pages,
106107 VM_ALLOC | VM_USERMAP, PAGE_KERNEL);
107108 if (rb) {
109+ kmemleak_not_leak(pages);
108110 rb->pages = pages;
109111 rb->nr_pages = nr_pages;
110112 return rb;
kernel/trace/bpf_trace.c+2−0
@@ -1017,6 +1017,8 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) · 1016 unmodified lines
10171017 #ifdef CONFIG_CGROUPS
10181018 case BPF_FUNC_get_current_cgroup_id:
10191019 return &bpf_get_current_cgroup_id_proto;
1020+ case BPF_FUNC_get_current_ancestor_cgroup_id:
1021+ return &bpf_get_current_ancestor_cgroup_id_proto;
10201022 #endif
10211023 case BPF_FUNC_send_signal:
10221024 return &bpf_send_signal_proto;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t