History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net

Pull networking fixes from David Miller: 1) Limit xt_hashlimit hash table size to avoid OOM or hung tasks, from Cong Wang. 2) Fix deadlock in xsk by publishing global consumer pointers when NAPI is finished, from Magnus Karlsson. 3) Set table field properly to RT_TABLE_COMPAT when necessary, from Jethro Beekman. 4) NLA_STRING attributes are not necessary NULL terminated, deal wiht that in IFLA_ALT_IFNAME. From Eric Dumazet. 5) Fix checksum handling in atlantic driver, from Dmitry Bezrukov. 6) Handle mtu==0 devices properly in wireguard, from Jason A. Donenfeld. 7) Fix several lockdep warnings in bonding, from Taehee Yoo. 8) Fix cls_flower port blocking, from Jason Baron. 9) Sanitize internal map names in libbpf, from Toke Høiland-Jørgensen. 10) Fix RDMA race in qede driver, from Michal Kalderon. 11) Fix several false lockdep warnings by adding conditions to list_for_each_entry_rcu(), from Madhuparna Bhowmik. 12) Fix sleep in atomic in mlx5 driver, from Huy Nguyen. 13) Fix potential deadlock in bpf_map_do_batch(), from Yonghong Song. 14) Hey, variables declared in switch statement before any case statements are not initialized. I learn something every day. Get rids of this stuff in several parts of the networking, from Kees Cook. * git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net: (99 commits) bnxt_en: Issue PCIe FLR in kdump kernel to cleanup pending DMAs. bnxt_en: Improve device shutdown method. net: netlink: cap max groups which will be considered in netlink_bind() net: thunderx: workaround BGX TX Underflow issue ionic: fix fw_status read net: disable BRIDGE_NETFILTER by default net: macb: Properly handle phylink on at91rm9200 s390/qeth: fix off-by-one in RX copybreak check s390/qeth: don't warn for napi with 0 budget s390/qeth: vnicc Fix EOPNOTSUPP precedence openvswitch: Distribute switch variables for initialization net: ip6_gre: Distribute switch variables for initialization net: core: Distribute switch variables for initialization udp: rehash on disconnect net/tls: Fix to avoid gettig invalid tls record bpf: Fix a potential deadlock with bpf_map_do_batch bpf: Do not grab the bucket spinlock by default on htab batch ops ice: Wait for VF to be reset/ready before configuration ice: Don't tell the OS that link is going down ice: Don't reject odd values of usecs set by user ...

Linus Torvalds committed 6 years ago

Commit 3dc55db2 parents b0dd1eb 36a44bc104 files · +1132 −506Browse files

Showing the changes to kernel (3 of 104 files). Show all

Unified · Split

3 files
  1. kernel/bpf/btf.c +3 −3
  2. kernel/bpf/hashtab.c +53 −5
  3. kernel/bpf/offload.c +1 −1
kernel/bpf/btf.c+3−3
@@ -4142,9 +4142,9 @@ int btf_distill_func_proto(struct bpf_verifier_log *log, · 4141 unmodified lines
41424142 * EFAULT - verifier bug
41434143 * 0 - 99% match. The last 1% is validated by the verifier.
41444144 */
4145−int btf_check_func_type_match(struct bpf_verifier_log *log,
4146− struct btf *btf1, const struct btf_type *t1,
4147− struct btf *btf2, const struct btf_type *t2)
4145+static int btf_check_func_type_match(struct bpf_verifier_log *log,
4146+ struct btf *btf1, const struct btf_type *t1,
4147+ struct btf *btf2, const struct btf_type *t2)
41484148 {
41494149 const struct btf_param *args1, *args2;
41504150 const char *fn1, *fn2, *s1, *s2;
kernel/bpf/hashtab.c+53−5
@@ -56,6 +56,7 @@ struct htab_elem { · 55 unmodified lines
5656 union {
5757 struct bpf_htab *htab;
5858 struct pcpu_freelist_node fnode;
59+ struct htab_elem *batch_flink;
5960 };
6061 };
6162 };
@@ -126,6 +127,17 @@ free_elems: · 64 unmodified lines
126127 bpf_map_area_free(htab->elems);
127128 }
128129
130+/* The LRU list has a lock (lru_lock). Each htab bucket has a lock
131+ * (bucket_lock). If both locks need to be acquired together, the lock
132+ * order is always lru_lock -> bucket_lock and this only happens in
133+ * bpf_lru_list.c logic. For example, certain code path of
134+ * bpf_lru_pop_free(), which is called by function prealloc_lru_pop(),
135+ * will acquire lru_lock first followed by acquiring bucket_lock.
136+ *
137+ * In hashtab.c, to avoid deadlock, lock acquisition of
138+ * bucket_lock followed by lru_lock is not allowed. In such cases,
139+ * bucket_lock needs to be released first before acquiring lru_lock.
140+ */
129141 static struct htab_elem *prealloc_lru_pop(struct bpf_htab *htab, void *key,
130142 u32 hash)
131143 {
@@ -1256,10 +1268,12 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, · 1124 unmodified lines
12561268 void __user *ukeys = u64_to_user_ptr(attr->batch.keys);
12571269 void *ubatch = u64_to_user_ptr(attr->batch.in_batch);
12581270 u32 batch, max_count, size, bucket_size;
1271+ struct htab_elem *node_to_free = NULL;
12591272 u64 elem_map_flags, map_flags;
12601273 struct hlist_nulls_head *head;
12611274 struct hlist_nulls_node *n;
1262− unsigned long flags;
1275+ unsigned long flags = 0;
1276+ bool locked = false;
12631277 struct htab_elem *l;
12641278 struct bucket *b;
12651279 int ret = 0;
@@ -1319,15 +1333,25 @@ again_nocopy: · 53 unmodified lines
13191333 dst_val = values;
13201334 b = &htab->buckets[batch];
13211335 head = &b->head;
1322− raw_spin_lock_irqsave(&b->lock, flags);
1336+ /* do not grab the lock unless need it (bucket_cnt > 0). */
1337+ if (locked)
1338+ raw_spin_lock_irqsave(&b->lock, flags);
13231339
13241340 bucket_cnt = 0;
13251341 hlist_nulls_for_each_entry_rcu(l, n, head, hash_node)
13261342 bucket_cnt++;
13271343
1344+ if (bucket_cnt && !locked) {
1345+ locked = true;
1346+ goto again_nocopy;
1347+ }
1348+
13281349 if (bucket_cnt > (max_count - total)) {
13291350 if (total == 0)
13301351 ret = -ENOSPC;
1352+ /* Note that since bucket_cnt > 0 here, it is implicit
1353+ * that the locked was grabbed, so release it.
1354+ */
13311355 raw_spin_unlock_irqrestore(&b->lock, flags);
13321356 rcu_read_unlock();
13331357 this_cpu_dec(bpf_prog_active);
@@ -1337,6 +1361,9 @@ again_nocopy: · 3 unmodified lines
13371361
13381362 if (bucket_cnt > bucket_size) {
13391363 bucket_size = bucket_cnt;
1364+ /* Note that since bucket_cnt > 0 here, it is implicit
1365+ * that the locked was grabbed, so release it.
1366+ */
13401367 raw_spin_unlock_irqrestore(&b->lock, flags);
13411368 rcu_read_unlock();
13421369 this_cpu_dec(bpf_prog_active);
@@ -1346,6 +1373,10 @@ again_nocopy: · 3 unmodified lines
13461373 goto alloc;
13471374 }
13481375
1376+ /* Next block is only safe to run if you have grabbed the lock */
1377+ if (!locked)
1378+ goto next_batch;
1379+
13491380 hlist_nulls_for_each_entry_safe(l, n, head, hash_node) {
13501381 memcpy(dst_key, l->key, key_size);
13511382
@@ -1370,16 +1401,33 @@ again_nocopy: · 18 unmodified lines
13701401 }
13711402 if (do_delete) {
13721403 hlist_nulls_del_rcu(&l->hash_node);
1373− if (is_lru_map)
1374− bpf_lru_push_free(&htab->lru, &l->lru_node);
1375− else
1404+
1405+ /* bpf_lru_push_free() will acquire lru_lock, which
1406+ * may cause deadlock. See comments in function
1407+ * prealloc_lru_pop(). Let us do bpf_lru_push_free()
1408+ * after releasing the bucket lock.
1409+ */
1410+ if (is_lru_map) {
1411+ l->batch_flink = node_to_free;
1412+ node_to_free = l;
1413+ } else {
13761414 free_htab_elem(htab, l);
1415+ }
13771416 }
13781417 dst_key += key_size;
13791418 dst_val += value_size;
13801419 }
13811420
13821421 raw_spin_unlock_irqrestore(&b->lock, flags);
1422+ locked = false;
1423+
1424+ while (node_to_free) {
1425+ l = node_to_free;
1426+ node_to_free = node_to_free->batch_flink;
1427+ bpf_lru_push_free(&htab->lru, &l->lru_node);
1428+ }
1429+
1430+next_batch:
13831431 /* If we are not copying data, we can go to next bucket and avoid
13841432 * unlocking the rcu.
13851433 */
kernel/bpf/offload.c+1−1
@@ -321,7 +321,7 @@ int bpf_prog_offload_info_fill(struct bpf_prog_info *info, · 320 unmodified lines
321321
322322 ulen = info->jited_prog_len;
323323 info->jited_prog_len = aux->offload->jited_len;
324− if (info->jited_prog_len & ulen) {
324+ if (info->jited_prog_len && ulen) {
325325 uinsns = u64_to_user_ptr(info->jited_prog_insns);
326326 ulen = min_t(u32, info->jited_prog_len, ulen);
327327 if (copy_to_user(uinsns, aux->offload->jited_image, ulen)) {

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