.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2007-2014 Nicira, Inc. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or |
---|
5 | | - * modify it under the terms of version 2 of the GNU General Public |
---|
6 | | - * License as published by the Free Software Foundation. |
---|
7 | | - * |
---|
8 | | - * This program is distributed in the hope that it will be useful, but |
---|
9 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
11 | | - * General Public License for more details. |
---|
12 | | - * |
---|
13 | | - * You should have received a copy of the GNU General Public License |
---|
14 | | - * along with this program; if not, write to the Free Software |
---|
15 | | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
16 | | - * 02110-1301, USA |
---|
17 | 4 | */ |
---|
18 | 5 | |
---|
19 | 6 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
.. | .. |
---|
143 | 130 | const struct dp_upcall_info *, |
---|
144 | 131 | uint32_t cutlen); |
---|
145 | 132 | |
---|
| 133 | +static void ovs_dp_masks_rebalance(struct work_struct *work); |
---|
| 134 | + |
---|
146 | 135 | /* Must be called with rcu_read_lock or ovs_mutex. */ |
---|
147 | 136 | const char *ovs_dp_name(const struct datapath *dp) |
---|
148 | 137 | { |
---|
.. | .. |
---|
192 | 181 | struct hlist_head *head; |
---|
193 | 182 | |
---|
194 | 183 | head = vport_hash_bucket(dp, port_no); |
---|
195 | | - hlist_for_each_entry_rcu(vport, head, dp_hash_node) { |
---|
| 184 | + hlist_for_each_entry_rcu(vport, head, dp_hash_node, |
---|
| 185 | + lockdep_ovsl_is_held()) { |
---|
196 | 186 | if (vport->port_no == port_no) |
---|
197 | 187 | return vport; |
---|
198 | 188 | } |
---|
.. | .. |
---|
235 | 225 | struct dp_stats_percpu *stats; |
---|
236 | 226 | u64 *stats_counter; |
---|
237 | 227 | u32 n_mask_hit; |
---|
| 228 | + u32 n_cache_hit; |
---|
| 229 | + int error; |
---|
238 | 230 | |
---|
239 | 231 | stats = this_cpu_ptr(dp->stats_percpu); |
---|
240 | 232 | |
---|
241 | 233 | /* Look up flow. */ |
---|
242 | | - flow = ovs_flow_tbl_lookup_stats(&dp->table, key, &n_mask_hit); |
---|
| 234 | + flow = ovs_flow_tbl_lookup_stats(&dp->table, key, skb_get_hash(skb), |
---|
| 235 | + &n_mask_hit, &n_cache_hit); |
---|
243 | 236 | if (unlikely(!flow)) { |
---|
244 | 237 | struct dp_upcall_info upcall; |
---|
245 | | - int error; |
---|
246 | 238 | |
---|
247 | 239 | memset(&upcall, 0, sizeof(upcall)); |
---|
248 | 240 | upcall.cmd = OVS_PACKET_CMD_MISS; |
---|
249 | 241 | upcall.portid = ovs_vport_find_upcall_portid(p, skb); |
---|
250 | 242 | upcall.mru = OVS_CB(skb)->mru; |
---|
251 | 243 | error = ovs_dp_upcall(dp, skb, key, &upcall, 0); |
---|
252 | | - if (unlikely(error)) |
---|
253 | | - kfree_skb(skb); |
---|
254 | | - else |
---|
| 244 | + switch (error) { |
---|
| 245 | + case 0: |
---|
| 246 | + case -EAGAIN: |
---|
| 247 | + case -ERESTARTSYS: |
---|
| 248 | + case -EINTR: |
---|
255 | 249 | consume_skb(skb); |
---|
| 250 | + break; |
---|
| 251 | + default: |
---|
| 252 | + kfree_skb(skb); |
---|
| 253 | + break; |
---|
| 254 | + } |
---|
256 | 255 | stats_counter = &stats->n_missed; |
---|
257 | 256 | goto out; |
---|
258 | 257 | } |
---|
259 | 258 | |
---|
260 | 259 | ovs_flow_stats_update(flow, key->tp.flags, skb); |
---|
261 | 260 | sf_acts = rcu_dereference(flow->sf_acts); |
---|
262 | | - ovs_execute_actions(dp, skb, sf_acts, key); |
---|
| 261 | + error = ovs_execute_actions(dp, skb, sf_acts, key); |
---|
| 262 | + if (unlikely(error)) |
---|
| 263 | + net_dbg_ratelimited("ovs: action execution error on datapath %s: %d\n", |
---|
| 264 | + ovs_dp_name(dp), error); |
---|
263 | 265 | |
---|
264 | 266 | stats_counter = &stats->n_hit; |
---|
265 | 267 | |
---|
.. | .. |
---|
268 | 270 | u64_stats_update_begin(&stats->syncp); |
---|
269 | 271 | (*stats_counter)++; |
---|
270 | 272 | stats->n_mask_hit += n_mask_hit; |
---|
| 273 | + stats->n_cache_hit += n_cache_hit; |
---|
271 | 274 | u64_stats_update_end(&stats->syncp); |
---|
272 | 275 | } |
---|
273 | 276 | |
---|
.. | .. |
---|
306 | 309 | static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb, |
---|
307 | 310 | const struct sw_flow_key *key, |
---|
308 | 311 | const struct dp_upcall_info *upcall_info, |
---|
309 | | - uint32_t cutlen) |
---|
| 312 | + uint32_t cutlen) |
---|
310 | 313 | { |
---|
311 | 314 | unsigned int gso_type = skb_shinfo(skb)->gso_type; |
---|
312 | 315 | struct sw_flow_key later_key; |
---|
313 | 316 | struct sk_buff *segs, *nskb; |
---|
314 | 317 | int err; |
---|
315 | 318 | |
---|
316 | | - BUILD_BUG_ON(sizeof(*OVS_CB(skb)) > SKB_SGO_CB_OFFSET); |
---|
| 319 | + BUILD_BUG_ON(sizeof(*OVS_CB(skb)) > SKB_GSO_CB_OFFSET); |
---|
317 | 320 | segs = __skb_gso_segment(skb, NETIF_F_SG, false); |
---|
318 | 321 | if (IS_ERR(segs)) |
---|
319 | 322 | return PTR_ERR(segs); |
---|
.. | .. |
---|
330 | 333 | } |
---|
331 | 334 | |
---|
332 | 335 | /* Queue all of the segments. */ |
---|
333 | | - skb = segs; |
---|
334 | | - do { |
---|
| 336 | + skb_list_walk_safe(segs, skb, nskb) { |
---|
335 | 337 | if (gso_type & SKB_GSO_UDP && skb != segs) |
---|
336 | 338 | key = &later_key; |
---|
337 | 339 | |
---|
.. | .. |
---|
339 | 341 | if (err) |
---|
340 | 342 | break; |
---|
341 | 343 | |
---|
342 | | - } while ((skb = skb->next)); |
---|
| 344 | + } |
---|
343 | 345 | |
---|
344 | 346 | /* Free all of the segments. */ |
---|
345 | | - skb = segs; |
---|
346 | | - do { |
---|
347 | | - nskb = skb->next; |
---|
| 347 | + skb_list_walk_safe(segs, skb, nskb) { |
---|
348 | 348 | if (err) |
---|
349 | 349 | kfree_skb(skb); |
---|
350 | 350 | else |
---|
351 | 351 | consume_skb(skb); |
---|
352 | | - } while ((skb = nskb)); |
---|
| 352 | + } |
---|
353 | 353 | return err; |
---|
354 | 354 | } |
---|
355 | 355 | |
---|
.. | .. |
---|
359 | 359 | size_t size = NLMSG_ALIGN(sizeof(struct ovs_header)) |
---|
360 | 360 | + nla_total_size(hdrlen) /* OVS_PACKET_ATTR_PACKET */ |
---|
361 | 361 | + nla_total_size(ovs_key_attr_size()) /* OVS_PACKET_ATTR_KEY */ |
---|
362 | | - + nla_total_size(sizeof(unsigned int)); /* OVS_PACKET_ATTR_LEN */ |
---|
| 362 | + + nla_total_size(sizeof(unsigned int)) /* OVS_PACKET_ATTR_LEN */ |
---|
| 363 | + + nla_total_size(sizeof(u64)); /* OVS_PACKET_ATTR_HASH */ |
---|
363 | 364 | |
---|
364 | 365 | /* OVS_PACKET_ATTR_USERDATA */ |
---|
365 | 366 | if (upcall_info->userdata) |
---|
.. | .. |
---|
402 | 403 | size_t len; |
---|
403 | 404 | unsigned int hlen; |
---|
404 | 405 | int err, dp_ifindex; |
---|
| 406 | + u64 hash; |
---|
405 | 407 | |
---|
406 | 408 | dp_ifindex = get_dpifindex(dp); |
---|
407 | 409 | if (!dp_ifindex) |
---|
.. | .. |
---|
448 | 450 | |
---|
449 | 451 | upcall = genlmsg_put(user_skb, 0, 0, &dp_packet_genl_family, |
---|
450 | 452 | 0, upcall_info->cmd); |
---|
| 453 | + if (!upcall) { |
---|
| 454 | + err = -EINVAL; |
---|
| 455 | + goto out; |
---|
| 456 | + } |
---|
451 | 457 | upcall->dp_ifindex = dp_ifindex; |
---|
452 | 458 | |
---|
453 | 459 | err = ovs_nla_put_key(key, key, OVS_PACKET_ATTR_KEY, false, user_skb); |
---|
454 | | - BUG_ON(err); |
---|
| 460 | + if (err) |
---|
| 461 | + goto out; |
---|
455 | 462 | |
---|
456 | 463 | if (upcall_info->userdata) |
---|
457 | 464 | __nla_put(user_skb, OVS_PACKET_ATTR_USERDATA, |
---|
.. | .. |
---|
459 | 466 | nla_data(upcall_info->userdata)); |
---|
460 | 467 | |
---|
461 | 468 | if (upcall_info->egress_tun_info) { |
---|
462 | | - nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_EGRESS_TUN_KEY); |
---|
| 469 | + nla = nla_nest_start_noflag(user_skb, |
---|
| 470 | + OVS_PACKET_ATTR_EGRESS_TUN_KEY); |
---|
| 471 | + if (!nla) { |
---|
| 472 | + err = -EMSGSIZE; |
---|
| 473 | + goto out; |
---|
| 474 | + } |
---|
463 | 475 | err = ovs_nla_put_tunnel_info(user_skb, |
---|
464 | 476 | upcall_info->egress_tun_info); |
---|
465 | | - BUG_ON(err); |
---|
| 477 | + if (err) |
---|
| 478 | + goto out; |
---|
| 479 | + |
---|
466 | 480 | nla_nest_end(user_skb, nla); |
---|
467 | 481 | } |
---|
468 | 482 | |
---|
469 | 483 | if (upcall_info->actions_len) { |
---|
470 | | - nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_ACTIONS); |
---|
| 484 | + nla = nla_nest_start_noflag(user_skb, OVS_PACKET_ATTR_ACTIONS); |
---|
| 485 | + if (!nla) { |
---|
| 486 | + err = -EMSGSIZE; |
---|
| 487 | + goto out; |
---|
| 488 | + } |
---|
471 | 489 | err = ovs_nla_put_actions(upcall_info->actions, |
---|
472 | 490 | upcall_info->actions_len, |
---|
473 | 491 | user_skb); |
---|
.. | .. |
---|
478 | 496 | } |
---|
479 | 497 | |
---|
480 | 498 | /* Add OVS_PACKET_ATTR_MRU */ |
---|
481 | | - if (upcall_info->mru) { |
---|
482 | | - if (nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU, |
---|
483 | | - upcall_info->mru)) { |
---|
484 | | - err = -ENOBUFS; |
---|
485 | | - goto out; |
---|
486 | | - } |
---|
487 | | - pad_packet(dp, user_skb); |
---|
| 499 | + if (upcall_info->mru && |
---|
| 500 | + nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU, upcall_info->mru)) { |
---|
| 501 | + err = -ENOBUFS; |
---|
| 502 | + goto out; |
---|
488 | 503 | } |
---|
489 | 504 | |
---|
490 | 505 | /* Add OVS_PACKET_ATTR_LEN when packet is truncated */ |
---|
491 | | - if (cutlen > 0) { |
---|
492 | | - if (nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN, |
---|
493 | | - skb->len)) { |
---|
494 | | - err = -ENOBUFS; |
---|
495 | | - goto out; |
---|
496 | | - } |
---|
497 | | - pad_packet(dp, user_skb); |
---|
| 506 | + if (cutlen > 0 && |
---|
| 507 | + nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN, skb->len)) { |
---|
| 508 | + err = -ENOBUFS; |
---|
| 509 | + goto out; |
---|
| 510 | + } |
---|
| 511 | + |
---|
| 512 | + /* Add OVS_PACKET_ATTR_HASH */ |
---|
| 513 | + hash = skb_get_hash_raw(skb); |
---|
| 514 | + if (skb->sw_hash) |
---|
| 515 | + hash |= OVS_PACKET_HASH_SW_BIT; |
---|
| 516 | + |
---|
| 517 | + if (skb->l4_hash) |
---|
| 518 | + hash |= OVS_PACKET_HASH_L4_BIT; |
---|
| 519 | + |
---|
| 520 | + if (nla_put(user_skb, OVS_PACKET_ATTR_HASH, sizeof (u64), &hash)) { |
---|
| 521 | + err = -ENOBUFS; |
---|
| 522 | + goto out; |
---|
498 | 523 | } |
---|
499 | 524 | |
---|
500 | 525 | /* Only reserve room for attribute header, packet data is added |
---|
.. | .. |
---|
519 | 544 | out: |
---|
520 | 545 | if (err) |
---|
521 | 546 | skb_tx_error(skb); |
---|
522 | | - kfree_skb(user_skb); |
---|
523 | | - kfree_skb(nskb); |
---|
| 547 | + consume_skb(user_skb); |
---|
| 548 | + consume_skb(nskb); |
---|
| 549 | + |
---|
524 | 550 | return err; |
---|
525 | 551 | } |
---|
526 | 552 | |
---|
.. | .. |
---|
536 | 562 | struct datapath *dp; |
---|
537 | 563 | struct vport *input_vport; |
---|
538 | 564 | u16 mru = 0; |
---|
| 565 | + u64 hash; |
---|
539 | 566 | int len; |
---|
540 | 567 | int err; |
---|
541 | 568 | bool log = !a[OVS_PACKET_ATTR_PROBE]; |
---|
.. | .. |
---|
560 | 587 | packet->ignore_df = 1; |
---|
561 | 588 | } |
---|
562 | 589 | OVS_CB(packet)->mru = mru; |
---|
| 590 | + |
---|
| 591 | + if (a[OVS_PACKET_ATTR_HASH]) { |
---|
| 592 | + hash = nla_get_u64(a[OVS_PACKET_ATTR_HASH]); |
---|
| 593 | + |
---|
| 594 | + __skb_set_hash(packet, hash & 0xFFFFFFFFULL, |
---|
| 595 | + !!(hash & OVS_PACKET_HASH_SW_BIT), |
---|
| 596 | + !!(hash & OVS_PACKET_HASH_L4_BIT)); |
---|
| 597 | + } |
---|
563 | 598 | |
---|
564 | 599 | /* Build an sw_flow for sending this packet. */ |
---|
565 | 600 | flow = ovs_flow_alloc(); |
---|
.. | .. |
---|
622 | 657 | [OVS_PACKET_ATTR_ACTIONS] = { .type = NLA_NESTED }, |
---|
623 | 658 | [OVS_PACKET_ATTR_PROBE] = { .type = NLA_FLAG }, |
---|
624 | 659 | [OVS_PACKET_ATTR_MRU] = { .type = NLA_U16 }, |
---|
| 660 | + [OVS_PACKET_ATTR_HASH] = { .type = NLA_U64 }, |
---|
625 | 661 | }; |
---|
626 | 662 | |
---|
627 | | -static const struct genl_ops dp_packet_genl_ops[] = { |
---|
| 663 | +static const struct genl_small_ops dp_packet_genl_ops[] = { |
---|
628 | 664 | { .cmd = OVS_PACKET_CMD_EXECUTE, |
---|
| 665 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
629 | 666 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
630 | | - .policy = packet_policy, |
---|
631 | 667 | .doit = ovs_packet_cmd_execute |
---|
632 | 668 | } |
---|
633 | 669 | }; |
---|
.. | .. |
---|
637 | 673 | .name = OVS_PACKET_FAMILY, |
---|
638 | 674 | .version = OVS_PACKET_VERSION, |
---|
639 | 675 | .maxattr = OVS_PACKET_ATTR_MAX, |
---|
| 676 | + .policy = packet_policy, |
---|
640 | 677 | .netnsok = true, |
---|
641 | 678 | .parallel_ops = true, |
---|
642 | | - .ops = dp_packet_genl_ops, |
---|
643 | | - .n_ops = ARRAY_SIZE(dp_packet_genl_ops), |
---|
| 679 | + .small_ops = dp_packet_genl_ops, |
---|
| 680 | + .n_small_ops = ARRAY_SIZE(dp_packet_genl_ops), |
---|
644 | 681 | .module = THIS_MODULE, |
---|
645 | 682 | }; |
---|
646 | 683 | |
---|
.. | .. |
---|
672 | 709 | stats->n_missed += local_stats.n_missed; |
---|
673 | 710 | stats->n_lost += local_stats.n_lost; |
---|
674 | 711 | mega_stats->n_mask_hit += local_stats.n_mask_hit; |
---|
| 712 | + mega_stats->n_cache_hit += local_stats.n_cache_hit; |
---|
675 | 713 | } |
---|
676 | 714 | } |
---|
677 | 715 | |
---|
.. | .. |
---|
768 | 806 | * This can only fail for dump operations because the skb is always |
---|
769 | 807 | * properly sized for single flows. |
---|
770 | 808 | */ |
---|
771 | | - start = nla_nest_start(skb, OVS_FLOW_ATTR_ACTIONS); |
---|
| 809 | + start = nla_nest_start_noflag(skb, OVS_FLOW_ATTR_ACTIONS); |
---|
772 | 810 | if (start) { |
---|
773 | 811 | const struct sw_flow_actions *sf_acts; |
---|
774 | 812 | |
---|
.. | .. |
---|
895 | 933 | struct sw_flow_mask mask; |
---|
896 | 934 | struct sk_buff *reply; |
---|
897 | 935 | struct datapath *dp; |
---|
| 936 | + struct sw_flow_key *key; |
---|
898 | 937 | struct sw_flow_actions *acts; |
---|
899 | 938 | struct sw_flow_match match; |
---|
900 | 939 | u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]); |
---|
.. | .. |
---|
922 | 961 | } |
---|
923 | 962 | |
---|
924 | 963 | /* Extract key. */ |
---|
925 | | - ovs_match_init(&match, &new_flow->key, false, &mask); |
---|
| 964 | + key = kzalloc(sizeof(*key), GFP_KERNEL); |
---|
| 965 | + if (!key) { |
---|
| 966 | + error = -ENOMEM; |
---|
| 967 | + goto err_kfree_flow; |
---|
| 968 | + } |
---|
| 969 | + |
---|
| 970 | + ovs_match_init(&match, key, false, &mask); |
---|
926 | 971 | error = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY], |
---|
927 | 972 | a[OVS_FLOW_ATTR_MASK], log); |
---|
928 | 973 | if (error) |
---|
929 | | - goto err_kfree_flow; |
---|
| 974 | + goto err_kfree_key; |
---|
| 975 | + |
---|
| 976 | + ovs_flow_mask_key(&new_flow->key, key, true, &mask); |
---|
930 | 977 | |
---|
931 | 978 | /* Extract flow identifier. */ |
---|
932 | 979 | error = ovs_nla_get_identifier(&new_flow->id, a[OVS_FLOW_ATTR_UFID], |
---|
933 | | - &new_flow->key, log); |
---|
| 980 | + key, log); |
---|
934 | 981 | if (error) |
---|
935 | | - goto err_kfree_flow; |
---|
936 | | - |
---|
937 | | - /* unmasked key is needed to match when ufid is not used. */ |
---|
938 | | - if (ovs_identifier_is_key(&new_flow->id)) |
---|
939 | | - match.key = new_flow->id.unmasked_key; |
---|
940 | | - |
---|
941 | | - ovs_flow_mask_key(&new_flow->key, &new_flow->key, true, &mask); |
---|
| 982 | + goto err_kfree_key; |
---|
942 | 983 | |
---|
943 | 984 | /* Validate actions. */ |
---|
944 | 985 | error = ovs_nla_copy_actions(net, a[OVS_FLOW_ATTR_ACTIONS], |
---|
945 | 986 | &new_flow->key, &acts, log); |
---|
946 | 987 | if (error) { |
---|
947 | 988 | OVS_NLERR(log, "Flow actions may not be safe on all matching packets."); |
---|
948 | | - goto err_kfree_flow; |
---|
| 989 | + goto err_kfree_key; |
---|
949 | 990 | } |
---|
950 | 991 | |
---|
951 | 992 | reply = ovs_flow_cmd_alloc_info(acts, &new_flow->id, info, false, |
---|
.. | .. |
---|
966 | 1007 | if (ovs_identifier_is_ufid(&new_flow->id)) |
---|
967 | 1008 | flow = ovs_flow_tbl_lookup_ufid(&dp->table, &new_flow->id); |
---|
968 | 1009 | if (!flow) |
---|
969 | | - flow = ovs_flow_tbl_lookup(&dp->table, &new_flow->key); |
---|
| 1010 | + flow = ovs_flow_tbl_lookup(&dp->table, key); |
---|
970 | 1011 | if (likely(!flow)) { |
---|
971 | 1012 | rcu_assign_pointer(new_flow->sf_acts, acts); |
---|
972 | 1013 | |
---|
.. | .. |
---|
1036 | 1077 | |
---|
1037 | 1078 | if (reply) |
---|
1038 | 1079 | ovs_notify(&dp_flow_genl_family, reply, info); |
---|
| 1080 | + |
---|
| 1081 | + kfree(key); |
---|
1039 | 1082 | return 0; |
---|
1040 | 1083 | |
---|
1041 | 1084 | err_unlock_ovs: |
---|
.. | .. |
---|
1043 | 1086 | kfree_skb(reply); |
---|
1044 | 1087 | err_kfree_acts: |
---|
1045 | 1088 | ovs_nla_free_flow_actions(acts); |
---|
| 1089 | +err_kfree_key: |
---|
| 1090 | + kfree(key); |
---|
1046 | 1091 | err_kfree_flow: |
---|
1047 | 1092 | ovs_flow_free(new_flow, false); |
---|
1048 | 1093 | error: |
---|
.. | .. |
---|
1050 | 1095 | } |
---|
1051 | 1096 | |
---|
1052 | 1097 | /* Factor out action copy to avoid "Wframe-larger-than=1024" warning. */ |
---|
1053 | | -static struct sw_flow_actions *get_flow_actions(struct net *net, |
---|
1054 | | - const struct nlattr *a, |
---|
1055 | | - const struct sw_flow_key *key, |
---|
1056 | | - const struct sw_flow_mask *mask, |
---|
1057 | | - bool log) |
---|
| 1098 | +static noinline_for_stack |
---|
| 1099 | +struct sw_flow_actions *get_flow_actions(struct net *net, |
---|
| 1100 | + const struct nlattr *a, |
---|
| 1101 | + const struct sw_flow_key *key, |
---|
| 1102 | + const struct sw_flow_mask *mask, |
---|
| 1103 | + bool log) |
---|
1058 | 1104 | { |
---|
1059 | 1105 | struct sw_flow_actions *acts; |
---|
1060 | 1106 | struct sw_flow_key masked_key; |
---|
.. | .. |
---|
1084 | 1130 | * we should not to return match object with dangling reference |
---|
1085 | 1131 | * to mask. |
---|
1086 | 1132 | * */ |
---|
1087 | | -static int ovs_nla_init_match_and_action(struct net *net, |
---|
1088 | | - struct sw_flow_match *match, |
---|
1089 | | - struct sw_flow_key *key, |
---|
1090 | | - struct nlattr **a, |
---|
1091 | | - struct sw_flow_actions **acts, |
---|
1092 | | - bool log) |
---|
| 1133 | +static noinline_for_stack int |
---|
| 1134 | +ovs_nla_init_match_and_action(struct net *net, |
---|
| 1135 | + struct sw_flow_match *match, |
---|
| 1136 | + struct sw_flow_key *key, |
---|
| 1137 | + struct nlattr **a, |
---|
| 1138 | + struct sw_flow_actions **acts, |
---|
| 1139 | + bool log) |
---|
1093 | 1140 | { |
---|
1094 | 1141 | struct sw_flow_mask mask; |
---|
1095 | 1142 | int error = 0; |
---|
.. | .. |
---|
1189 | 1236 | ovs_header->dp_ifindex, |
---|
1190 | 1237 | reply, info->snd_portid, |
---|
1191 | 1238 | info->snd_seq, 0, |
---|
1192 | | - OVS_FLOW_CMD_NEW, |
---|
| 1239 | + OVS_FLOW_CMD_SET, |
---|
1193 | 1240 | ufid_flags); |
---|
1194 | 1241 | BUG_ON(error < 0); |
---|
1195 | 1242 | } |
---|
1196 | 1243 | } else { |
---|
1197 | 1244 | /* Could not alloc without acts before locking. */ |
---|
1198 | 1245 | reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex, |
---|
1199 | | - info, OVS_FLOW_CMD_NEW, false, |
---|
| 1246 | + info, OVS_FLOW_CMD_SET, false, |
---|
1200 | 1247 | ufid_flags); |
---|
1201 | 1248 | |
---|
1202 | 1249 | if (IS_ERR(reply)) { |
---|
.. | .. |
---|
1272 | 1319 | } |
---|
1273 | 1320 | |
---|
1274 | 1321 | reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex, info, |
---|
1275 | | - OVS_FLOW_CMD_NEW, true, ufid_flags); |
---|
| 1322 | + OVS_FLOW_CMD_GET, true, ufid_flags); |
---|
1276 | 1323 | if (IS_ERR(reply)) { |
---|
1277 | 1324 | err = PTR_ERR(reply); |
---|
1278 | 1325 | goto unlock; |
---|
.. | .. |
---|
1337 | 1384 | reply = ovs_flow_cmd_alloc_info((const struct sw_flow_actions __force *) flow->sf_acts, |
---|
1338 | 1385 | &flow->id, info, false, ufid_flags); |
---|
1339 | 1386 | if (likely(reply)) { |
---|
1340 | | - if (likely(!IS_ERR(reply))) { |
---|
| 1387 | + if (!IS_ERR(reply)) { |
---|
1341 | 1388 | rcu_read_lock(); /*To keep RCU checker happy. */ |
---|
1342 | 1389 | err = ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex, |
---|
1343 | 1390 | reply, info->snd_portid, |
---|
.. | .. |
---|
1352 | 1399 | |
---|
1353 | 1400 | ovs_notify(&dp_flow_genl_family, reply, info); |
---|
1354 | 1401 | } else { |
---|
1355 | | - netlink_set_err(sock_net(skb->sk)->genl_sock, 0, 0, PTR_ERR(reply)); |
---|
| 1402 | + netlink_set_err(sock_net(skb->sk)->genl_sock, 0, 0, |
---|
| 1403 | + PTR_ERR(reply)); |
---|
1356 | 1404 | } |
---|
1357 | 1405 | } |
---|
1358 | 1406 | |
---|
.. | .. |
---|
1373 | 1421 | u32 ufid_flags; |
---|
1374 | 1422 | int err; |
---|
1375 | 1423 | |
---|
1376 | | - err = genlmsg_parse(cb->nlh, &dp_flow_genl_family, a, |
---|
1377 | | - OVS_FLOW_ATTR_MAX, flow_policy, NULL); |
---|
| 1424 | + err = genlmsg_parse_deprecated(cb->nlh, &dp_flow_genl_family, a, |
---|
| 1425 | + OVS_FLOW_ATTR_MAX, flow_policy, NULL); |
---|
1378 | 1426 | if (err) |
---|
1379 | 1427 | return err; |
---|
1380 | 1428 | ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]); |
---|
.. | .. |
---|
1400 | 1448 | if (ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex, skb, |
---|
1401 | 1449 | NETLINK_CB(cb->skb).portid, |
---|
1402 | 1450 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
---|
1403 | | - OVS_FLOW_CMD_NEW, ufid_flags) < 0) |
---|
| 1451 | + OVS_FLOW_CMD_GET, ufid_flags) < 0) |
---|
1404 | 1452 | break; |
---|
1405 | 1453 | |
---|
1406 | 1454 | cb->args[0] = bucket; |
---|
.. | .. |
---|
1420 | 1468 | [OVS_FLOW_ATTR_UFID_FLAGS] = { .type = NLA_U32 }, |
---|
1421 | 1469 | }; |
---|
1422 | 1470 | |
---|
1423 | | -static const struct genl_ops dp_flow_genl_ops[] = { |
---|
| 1471 | +static const struct genl_small_ops dp_flow_genl_ops[] = { |
---|
1424 | 1472 | { .cmd = OVS_FLOW_CMD_NEW, |
---|
| 1473 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
1425 | 1474 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
1426 | | - .policy = flow_policy, |
---|
1427 | 1475 | .doit = ovs_flow_cmd_new |
---|
1428 | 1476 | }, |
---|
1429 | 1477 | { .cmd = OVS_FLOW_CMD_DEL, |
---|
| 1478 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
1430 | 1479 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
1431 | | - .policy = flow_policy, |
---|
1432 | 1480 | .doit = ovs_flow_cmd_del |
---|
1433 | 1481 | }, |
---|
1434 | 1482 | { .cmd = OVS_FLOW_CMD_GET, |
---|
| 1483 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
1435 | 1484 | .flags = 0, /* OK for unprivileged users. */ |
---|
1436 | | - .policy = flow_policy, |
---|
1437 | 1485 | .doit = ovs_flow_cmd_get, |
---|
1438 | 1486 | .dumpit = ovs_flow_cmd_dump |
---|
1439 | 1487 | }, |
---|
1440 | 1488 | { .cmd = OVS_FLOW_CMD_SET, |
---|
| 1489 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
1441 | 1490 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
1442 | | - .policy = flow_policy, |
---|
1443 | 1491 | .doit = ovs_flow_cmd_set, |
---|
1444 | 1492 | }, |
---|
1445 | 1493 | }; |
---|
.. | .. |
---|
1449 | 1497 | .name = OVS_FLOW_FAMILY, |
---|
1450 | 1498 | .version = OVS_FLOW_VERSION, |
---|
1451 | 1499 | .maxattr = OVS_FLOW_ATTR_MAX, |
---|
| 1500 | + .policy = flow_policy, |
---|
1452 | 1501 | .netnsok = true, |
---|
1453 | 1502 | .parallel_ops = true, |
---|
1454 | | - .ops = dp_flow_genl_ops, |
---|
1455 | | - .n_ops = ARRAY_SIZE(dp_flow_genl_ops), |
---|
| 1503 | + .small_ops = dp_flow_genl_ops, |
---|
| 1504 | + .n_small_ops = ARRAY_SIZE(dp_flow_genl_ops), |
---|
1456 | 1505 | .mcgrps = &ovs_dp_flow_multicast_group, |
---|
1457 | 1506 | .n_mcgrps = 1, |
---|
1458 | 1507 | .module = THIS_MODULE, |
---|
.. | .. |
---|
1466 | 1515 | msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_stats)); |
---|
1467 | 1516 | msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_megaflow_stats)); |
---|
1468 | 1517 | msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_USER_FEATURES */ |
---|
| 1518 | + msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_MASKS_CACHE_SIZE */ |
---|
1469 | 1519 | |
---|
1470 | 1520 | return msgsize; |
---|
1471 | 1521 | } |
---|
.. | .. |
---|
1480 | 1530 | int err; |
---|
1481 | 1531 | |
---|
1482 | 1532 | ovs_header = genlmsg_put(skb, portid, seq, &dp_datapath_genl_family, |
---|
1483 | | - flags, cmd); |
---|
| 1533 | + flags, cmd); |
---|
1484 | 1534 | if (!ovs_header) |
---|
1485 | 1535 | goto error; |
---|
1486 | 1536 | |
---|
.. | .. |
---|
1501 | 1551 | goto nla_put_failure; |
---|
1502 | 1552 | |
---|
1503 | 1553 | if (nla_put_u32(skb, OVS_DP_ATTR_USER_FEATURES, dp->user_features)) |
---|
| 1554 | + goto nla_put_failure; |
---|
| 1555 | + |
---|
| 1556 | + if (nla_put_u32(skb, OVS_DP_ATTR_MASKS_CACHE_SIZE, |
---|
| 1557 | + ovs_flow_tbl_masks_cache_size(&dp->table))) |
---|
1504 | 1558 | goto nla_put_failure; |
---|
1505 | 1559 | |
---|
1506 | 1560 | genlmsg_end(skb, ovs_header); |
---|
.. | .. |
---|
1535 | 1589 | return dp ? dp : ERR_PTR(-ENODEV); |
---|
1536 | 1590 | } |
---|
1537 | 1591 | |
---|
1538 | | -static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *info) |
---|
| 1592 | +static void ovs_dp_reset_user_features(struct sk_buff *skb, |
---|
| 1593 | + struct genl_info *info) |
---|
1539 | 1594 | { |
---|
1540 | 1595 | struct datapath *dp; |
---|
1541 | 1596 | |
---|
1542 | | - dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs); |
---|
| 1597 | + dp = lookup_datapath(sock_net(skb->sk), info->userhdr, |
---|
| 1598 | + info->attrs); |
---|
1543 | 1599 | if (IS_ERR(dp)) |
---|
1544 | 1600 | return; |
---|
1545 | 1601 | |
---|
1546 | | - WARN(dp->user_features, "Dropping previously announced user features\n"); |
---|
| 1602 | + pr_warn("%s: Dropping previously announced user features\n", |
---|
| 1603 | + ovs_dp_name(dp)); |
---|
1547 | 1604 | dp->user_features = 0; |
---|
1548 | 1605 | } |
---|
1549 | 1606 | |
---|
1550 | | -static void ovs_dp_change(struct datapath *dp, struct nlattr *a[]) |
---|
| 1607 | +DEFINE_STATIC_KEY_FALSE(tc_recirc_sharing_support); |
---|
| 1608 | + |
---|
| 1609 | +static int ovs_dp_change(struct datapath *dp, struct nlattr *a[]) |
---|
1551 | 1610 | { |
---|
1552 | | - if (a[OVS_DP_ATTR_USER_FEATURES]) |
---|
1553 | | - dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]); |
---|
| 1611 | + u32 user_features = 0; |
---|
| 1612 | + |
---|
| 1613 | + if (a[OVS_DP_ATTR_USER_FEATURES]) { |
---|
| 1614 | + user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]); |
---|
| 1615 | + |
---|
| 1616 | + if (user_features & ~(OVS_DP_F_VPORT_PIDS | |
---|
| 1617 | + OVS_DP_F_UNALIGNED | |
---|
| 1618 | + OVS_DP_F_TC_RECIRC_SHARING)) |
---|
| 1619 | + return -EOPNOTSUPP; |
---|
| 1620 | + |
---|
| 1621 | +#if !IS_ENABLED(CONFIG_NET_TC_SKB_EXT) |
---|
| 1622 | + if (user_features & OVS_DP_F_TC_RECIRC_SHARING) |
---|
| 1623 | + return -EOPNOTSUPP; |
---|
| 1624 | +#endif |
---|
| 1625 | + } |
---|
| 1626 | + |
---|
| 1627 | + if (a[OVS_DP_ATTR_MASKS_CACHE_SIZE]) { |
---|
| 1628 | + int err; |
---|
| 1629 | + u32 cache_size; |
---|
| 1630 | + |
---|
| 1631 | + cache_size = nla_get_u32(a[OVS_DP_ATTR_MASKS_CACHE_SIZE]); |
---|
| 1632 | + err = ovs_flow_tbl_masks_cache_resize(&dp->table, cache_size); |
---|
| 1633 | + if (err) |
---|
| 1634 | + return err; |
---|
| 1635 | + } |
---|
| 1636 | + |
---|
| 1637 | + dp->user_features = user_features; |
---|
| 1638 | + |
---|
| 1639 | + if (dp->user_features & OVS_DP_F_TC_RECIRC_SHARING) |
---|
| 1640 | + static_branch_enable(&tc_recirc_sharing_support); |
---|
| 1641 | + else |
---|
| 1642 | + static_branch_disable(&tc_recirc_sharing_support); |
---|
| 1643 | + |
---|
| 1644 | + return 0; |
---|
| 1645 | +} |
---|
| 1646 | + |
---|
| 1647 | +static int ovs_dp_stats_init(struct datapath *dp) |
---|
| 1648 | +{ |
---|
| 1649 | + dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu); |
---|
| 1650 | + if (!dp->stats_percpu) |
---|
| 1651 | + return -ENOMEM; |
---|
| 1652 | + |
---|
| 1653 | + return 0; |
---|
| 1654 | +} |
---|
| 1655 | + |
---|
| 1656 | +static int ovs_dp_vport_init(struct datapath *dp) |
---|
| 1657 | +{ |
---|
| 1658 | + int i; |
---|
| 1659 | + |
---|
| 1660 | + dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS, |
---|
| 1661 | + sizeof(struct hlist_head), |
---|
| 1662 | + GFP_KERNEL); |
---|
| 1663 | + if (!dp->ports) |
---|
| 1664 | + return -ENOMEM; |
---|
| 1665 | + |
---|
| 1666 | + for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) |
---|
| 1667 | + INIT_HLIST_HEAD(&dp->ports[i]); |
---|
| 1668 | + |
---|
| 1669 | + return 0; |
---|
1554 | 1670 | } |
---|
1555 | 1671 | |
---|
1556 | 1672 | static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) |
---|
.. | .. |
---|
1561 | 1677 | struct datapath *dp; |
---|
1562 | 1678 | struct vport *vport; |
---|
1563 | 1679 | struct ovs_net *ovs_net; |
---|
1564 | | - int err, i; |
---|
| 1680 | + int err; |
---|
1565 | 1681 | |
---|
1566 | 1682 | err = -EINVAL; |
---|
1567 | 1683 | if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID]) |
---|
.. | .. |
---|
1574 | 1690 | err = -ENOMEM; |
---|
1575 | 1691 | dp = kzalloc(sizeof(*dp), GFP_KERNEL); |
---|
1576 | 1692 | if (dp == NULL) |
---|
1577 | | - goto err_free_reply; |
---|
| 1693 | + goto err_destroy_reply; |
---|
1578 | 1694 | |
---|
1579 | 1695 | ovs_dp_set_net(dp, sock_net(skb->sk)); |
---|
1580 | 1696 | |
---|
1581 | 1697 | /* Allocate table. */ |
---|
1582 | 1698 | err = ovs_flow_tbl_init(&dp->table); |
---|
1583 | 1699 | if (err) |
---|
1584 | | - goto err_free_dp; |
---|
| 1700 | + goto err_destroy_dp; |
---|
1585 | 1701 | |
---|
1586 | | - dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu); |
---|
1587 | | - if (!dp->stats_percpu) { |
---|
1588 | | - err = -ENOMEM; |
---|
| 1702 | + err = ovs_dp_stats_init(dp); |
---|
| 1703 | + if (err) |
---|
1589 | 1704 | goto err_destroy_table; |
---|
1590 | | - } |
---|
1591 | 1705 | |
---|
1592 | | - dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS, |
---|
1593 | | - sizeof(struct hlist_head), |
---|
1594 | | - GFP_KERNEL); |
---|
1595 | | - if (!dp->ports) { |
---|
1596 | | - err = -ENOMEM; |
---|
1597 | | - goto err_destroy_percpu; |
---|
1598 | | - } |
---|
1599 | | - |
---|
1600 | | - for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) |
---|
1601 | | - INIT_HLIST_HEAD(&dp->ports[i]); |
---|
| 1706 | + err = ovs_dp_vport_init(dp); |
---|
| 1707 | + if (err) |
---|
| 1708 | + goto err_destroy_stats; |
---|
1602 | 1709 | |
---|
1603 | 1710 | err = ovs_meters_init(dp); |
---|
1604 | 1711 | if (err) |
---|
1605 | | - goto err_destroy_ports_array; |
---|
| 1712 | + goto err_destroy_ports; |
---|
1606 | 1713 | |
---|
1607 | 1714 | /* Set up our datapath device. */ |
---|
1608 | 1715 | parms.name = nla_data(a[OVS_DP_ATTR_NAME]); |
---|
.. | .. |
---|
1612 | 1719 | parms.port_no = OVSP_LOCAL; |
---|
1613 | 1720 | parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID]; |
---|
1614 | 1721 | |
---|
1615 | | - ovs_dp_change(dp, a); |
---|
1616 | | - |
---|
1617 | 1722 | /* So far only local changes have been made, now need the lock. */ |
---|
1618 | 1723 | ovs_lock(); |
---|
| 1724 | + |
---|
| 1725 | + err = ovs_dp_change(dp, a); |
---|
| 1726 | + if (err) |
---|
| 1727 | + goto err_unlock_and_destroy_meters; |
---|
1619 | 1728 | |
---|
1620 | 1729 | vport = new_vport(&parms); |
---|
1621 | 1730 | if (IS_ERR(vport)) { |
---|
.. | .. |
---|
1632 | 1741 | ovs_dp_reset_user_features(skb, info); |
---|
1633 | 1742 | } |
---|
1634 | 1743 | |
---|
1635 | | - goto err_destroy_meters; |
---|
| 1744 | + goto err_unlock_and_destroy_meters; |
---|
1636 | 1745 | } |
---|
1637 | 1746 | |
---|
1638 | 1747 | err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, |
---|
.. | .. |
---|
1647 | 1756 | ovs_notify(&dp_datapath_genl_family, reply, info); |
---|
1648 | 1757 | return 0; |
---|
1649 | 1758 | |
---|
1650 | | -err_destroy_meters: |
---|
| 1759 | +err_unlock_and_destroy_meters: |
---|
1651 | 1760 | ovs_unlock(); |
---|
1652 | 1761 | ovs_meters_exit(dp); |
---|
1653 | | -err_destroy_ports_array: |
---|
| 1762 | +err_destroy_ports: |
---|
1654 | 1763 | kfree(dp->ports); |
---|
1655 | | -err_destroy_percpu: |
---|
| 1764 | +err_destroy_stats: |
---|
1656 | 1765 | free_percpu(dp->stats_percpu); |
---|
1657 | 1766 | err_destroy_table: |
---|
1658 | 1767 | ovs_flow_tbl_destroy(&dp->table); |
---|
1659 | | -err_free_dp: |
---|
| 1768 | +err_destroy_dp: |
---|
1660 | 1769 | kfree(dp); |
---|
1661 | | -err_free_reply: |
---|
| 1770 | +err_destroy_reply: |
---|
1662 | 1771 | kfree_skb(reply); |
---|
1663 | 1772 | err: |
---|
1664 | 1773 | return err; |
---|
.. | .. |
---|
1667 | 1776 | /* Called with ovs_mutex. */ |
---|
1668 | 1777 | static void __dp_destroy(struct datapath *dp) |
---|
1669 | 1778 | { |
---|
| 1779 | + struct flow_table *table = &dp->table; |
---|
1670 | 1780 | int i; |
---|
1671 | 1781 | |
---|
1672 | 1782 | for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) { |
---|
.. | .. |
---|
1685 | 1795 | */ |
---|
1686 | 1796 | ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL)); |
---|
1687 | 1797 | |
---|
1688 | | - /* RCU destroy the flow table */ |
---|
| 1798 | + /* Flush sw_flow in the tables. RCU cb only releases resource |
---|
| 1799 | + * such as dp, ports and tables. That may avoid some issues |
---|
| 1800 | + * such as RCU usage warning. |
---|
| 1801 | + */ |
---|
| 1802 | + table_instance_flow_flush(table, ovsl_dereference(table->ti), |
---|
| 1803 | + ovsl_dereference(table->ufid_ti)); |
---|
| 1804 | + |
---|
| 1805 | + /* RCU destroy the ports, meters and flow tables. */ |
---|
1689 | 1806 | call_rcu(&dp->rcu, destroy_dp_rcu); |
---|
1690 | 1807 | } |
---|
1691 | 1808 | |
---|
.. | .. |
---|
1738 | 1855 | if (IS_ERR(dp)) |
---|
1739 | 1856 | goto err_unlock_free; |
---|
1740 | 1857 | |
---|
1741 | | - ovs_dp_change(dp, info->attrs); |
---|
| 1858 | + err = ovs_dp_change(dp, info->attrs); |
---|
| 1859 | + if (err) |
---|
| 1860 | + goto err_unlock_free; |
---|
1742 | 1861 | |
---|
1743 | 1862 | err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, |
---|
1744 | | - info->snd_seq, 0, OVS_DP_CMD_NEW); |
---|
| 1863 | + info->snd_seq, 0, OVS_DP_CMD_SET); |
---|
1745 | 1864 | BUG_ON(err < 0); |
---|
1746 | 1865 | |
---|
1747 | 1866 | ovs_unlock(); |
---|
.. | .. |
---|
1772 | 1891 | goto err_unlock_free; |
---|
1773 | 1892 | } |
---|
1774 | 1893 | err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, |
---|
1775 | | - info->snd_seq, 0, OVS_DP_CMD_NEW); |
---|
| 1894 | + info->snd_seq, 0, OVS_DP_CMD_GET); |
---|
1776 | 1895 | BUG_ON(err < 0); |
---|
1777 | 1896 | ovs_unlock(); |
---|
1778 | 1897 | |
---|
.. | .. |
---|
1796 | 1915 | if (i >= skip && |
---|
1797 | 1916 | ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid, |
---|
1798 | 1917 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
---|
1799 | | - OVS_DP_CMD_NEW) < 0) |
---|
| 1918 | + OVS_DP_CMD_GET) < 0) |
---|
1800 | 1919 | break; |
---|
1801 | 1920 | i++; |
---|
1802 | 1921 | } |
---|
.. | .. |
---|
1811 | 1930 | [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, |
---|
1812 | 1931 | [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 }, |
---|
1813 | 1932 | [OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 }, |
---|
| 1933 | + [OVS_DP_ATTR_MASKS_CACHE_SIZE] = NLA_POLICY_RANGE(NLA_U32, 0, |
---|
| 1934 | + PCPU_MIN_UNIT_SIZE / sizeof(struct mask_cache_entry)), |
---|
1814 | 1935 | }; |
---|
1815 | 1936 | |
---|
1816 | | -static const struct genl_ops dp_datapath_genl_ops[] = { |
---|
| 1937 | +static const struct genl_small_ops dp_datapath_genl_ops[] = { |
---|
1817 | 1938 | { .cmd = OVS_DP_CMD_NEW, |
---|
| 1939 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
1818 | 1940 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
1819 | | - .policy = datapath_policy, |
---|
1820 | 1941 | .doit = ovs_dp_cmd_new |
---|
1821 | 1942 | }, |
---|
1822 | 1943 | { .cmd = OVS_DP_CMD_DEL, |
---|
| 1944 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
1823 | 1945 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
1824 | | - .policy = datapath_policy, |
---|
1825 | 1946 | .doit = ovs_dp_cmd_del |
---|
1826 | 1947 | }, |
---|
1827 | 1948 | { .cmd = OVS_DP_CMD_GET, |
---|
| 1949 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
1828 | 1950 | .flags = 0, /* OK for unprivileged users. */ |
---|
1829 | | - .policy = datapath_policy, |
---|
1830 | 1951 | .doit = ovs_dp_cmd_get, |
---|
1831 | 1952 | .dumpit = ovs_dp_cmd_dump |
---|
1832 | 1953 | }, |
---|
1833 | 1954 | { .cmd = OVS_DP_CMD_SET, |
---|
| 1955 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
1834 | 1956 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
1835 | | - .policy = datapath_policy, |
---|
1836 | 1957 | .doit = ovs_dp_cmd_set, |
---|
1837 | 1958 | }, |
---|
1838 | 1959 | }; |
---|
.. | .. |
---|
1842 | 1963 | .name = OVS_DATAPATH_FAMILY, |
---|
1843 | 1964 | .version = OVS_DATAPATH_VERSION, |
---|
1844 | 1965 | .maxattr = OVS_DP_ATTR_MAX, |
---|
| 1966 | + .policy = datapath_policy, |
---|
1845 | 1967 | .netnsok = true, |
---|
1846 | 1968 | .parallel_ops = true, |
---|
1847 | | - .ops = dp_datapath_genl_ops, |
---|
1848 | | - .n_ops = ARRAY_SIZE(dp_datapath_genl_ops), |
---|
| 1969 | + .small_ops = dp_datapath_genl_ops, |
---|
| 1970 | + .n_small_ops = ARRAY_SIZE(dp_datapath_genl_ops), |
---|
1849 | 1971 | .mcgrps = &ovs_dp_datapath_multicast_group, |
---|
1850 | 1972 | .n_mcgrps = 1, |
---|
1851 | 1973 | .module = THIS_MODULE, |
---|
.. | .. |
---|
1964 | 2086 | |
---|
1965 | 2087 | } |
---|
1966 | 2088 | |
---|
1967 | | -/* Called with ovs_mutex */ |
---|
1968 | | -static void update_headroom(struct datapath *dp) |
---|
| 2089 | +static unsigned int ovs_get_max_headroom(struct datapath *dp) |
---|
1969 | 2090 | { |
---|
1970 | | - unsigned dev_headroom, max_headroom = 0; |
---|
| 2091 | + unsigned int dev_headroom, max_headroom = 0; |
---|
1971 | 2092 | struct net_device *dev; |
---|
1972 | 2093 | struct vport *vport; |
---|
1973 | 2094 | int i; |
---|
1974 | 2095 | |
---|
1975 | 2096 | for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) { |
---|
1976 | | - hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) { |
---|
| 2097 | + hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node, |
---|
| 2098 | + lockdep_ovsl_is_held()) { |
---|
1977 | 2099 | dev = vport->dev; |
---|
1978 | 2100 | dev_headroom = netdev_get_fwd_headroom(dev); |
---|
1979 | 2101 | if (dev_headroom > max_headroom) |
---|
.. | .. |
---|
1981 | 2103 | } |
---|
1982 | 2104 | } |
---|
1983 | 2105 | |
---|
1984 | | - dp->max_headroom = max_headroom; |
---|
1985 | | - for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) |
---|
1986 | | - hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) |
---|
1987 | | - netdev_set_rx_headroom(vport->dev, max_headroom); |
---|
| 2106 | + return max_headroom; |
---|
| 2107 | +} |
---|
| 2108 | + |
---|
| 2109 | +/* Called with ovs_mutex */ |
---|
| 2110 | +static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom) |
---|
| 2111 | +{ |
---|
| 2112 | + struct vport *vport; |
---|
| 2113 | + int i; |
---|
| 2114 | + |
---|
| 2115 | + dp->max_headroom = new_headroom; |
---|
| 2116 | + for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) { |
---|
| 2117 | + hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node, |
---|
| 2118 | + lockdep_ovsl_is_held()) |
---|
| 2119 | + netdev_set_rx_headroom(vport->dev, new_headroom); |
---|
| 2120 | + } |
---|
1988 | 2121 | } |
---|
1989 | 2122 | |
---|
1990 | 2123 | static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) |
---|
.. | .. |
---|
1995 | 2128 | struct sk_buff *reply; |
---|
1996 | 2129 | struct vport *vport; |
---|
1997 | 2130 | struct datapath *dp; |
---|
| 2131 | + unsigned int new_headroom; |
---|
1998 | 2132 | u32 port_no; |
---|
1999 | 2133 | int err; |
---|
2000 | 2134 | |
---|
.. | .. |
---|
2056 | 2190 | info->snd_portid, info->snd_seq, 0, |
---|
2057 | 2191 | OVS_VPORT_CMD_NEW, GFP_KERNEL); |
---|
2058 | 2192 | |
---|
2059 | | - if (netdev_get_fwd_headroom(vport->dev) > dp->max_headroom) |
---|
2060 | | - update_headroom(dp); |
---|
| 2193 | + new_headroom = netdev_get_fwd_headroom(vport->dev); |
---|
| 2194 | + |
---|
| 2195 | + if (new_headroom > dp->max_headroom) |
---|
| 2196 | + ovs_update_headroom(dp, new_headroom); |
---|
2061 | 2197 | else |
---|
2062 | 2198 | netdev_set_rx_headroom(vport->dev, dp->max_headroom); |
---|
2063 | 2199 | |
---|
.. | .. |
---|
2113 | 2249 | |
---|
2114 | 2250 | err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), |
---|
2115 | 2251 | info->snd_portid, info->snd_seq, 0, |
---|
2116 | | - OVS_VPORT_CMD_NEW, GFP_ATOMIC); |
---|
| 2252 | + OVS_VPORT_CMD_SET, GFP_KERNEL); |
---|
2117 | 2253 | BUG_ON(err < 0); |
---|
2118 | 2254 | |
---|
2119 | 2255 | ovs_unlock(); |
---|
.. | .. |
---|
2128 | 2264 | |
---|
2129 | 2265 | static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info) |
---|
2130 | 2266 | { |
---|
2131 | | - bool must_update_headroom = false; |
---|
| 2267 | + bool update_headroom = false; |
---|
2132 | 2268 | struct nlattr **a = info->attrs; |
---|
2133 | 2269 | struct sk_buff *reply; |
---|
2134 | 2270 | struct datapath *dp; |
---|
2135 | 2271 | struct vport *vport; |
---|
| 2272 | + unsigned int new_headroom; |
---|
2136 | 2273 | int err; |
---|
2137 | 2274 | |
---|
2138 | 2275 | reply = ovs_vport_cmd_alloc_info(); |
---|
.. | .. |
---|
2158 | 2295 | /* the vport deletion may trigger dp headroom update */ |
---|
2159 | 2296 | dp = vport->dp; |
---|
2160 | 2297 | if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom) |
---|
2161 | | - must_update_headroom = true; |
---|
| 2298 | + update_headroom = true; |
---|
| 2299 | + |
---|
2162 | 2300 | netdev_reset_rx_headroom(vport->dev); |
---|
2163 | 2301 | ovs_dp_detach_port(vport); |
---|
2164 | 2302 | |
---|
2165 | | - if (must_update_headroom) |
---|
2166 | | - update_headroom(dp); |
---|
| 2303 | + if (update_headroom) { |
---|
| 2304 | + new_headroom = ovs_get_max_headroom(dp); |
---|
| 2305 | + |
---|
| 2306 | + if (new_headroom < dp->max_headroom) |
---|
| 2307 | + ovs_update_headroom(dp, new_headroom); |
---|
| 2308 | + } |
---|
2167 | 2309 | ovs_unlock(); |
---|
2168 | 2310 | |
---|
2169 | 2311 | ovs_notify(&dp_vport_genl_family, reply, info); |
---|
.. | .. |
---|
2194 | 2336 | goto exit_unlock_free; |
---|
2195 | 2337 | err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), |
---|
2196 | 2338 | info->snd_portid, info->snd_seq, 0, |
---|
2197 | | - OVS_VPORT_CMD_NEW, GFP_ATOMIC); |
---|
| 2339 | + OVS_VPORT_CMD_GET, GFP_ATOMIC); |
---|
2198 | 2340 | BUG_ON(err < 0); |
---|
2199 | 2341 | rcu_read_unlock(); |
---|
2200 | 2342 | |
---|
.. | .. |
---|
2230 | 2372 | NETLINK_CB(cb->skb).portid, |
---|
2231 | 2373 | cb->nlh->nlmsg_seq, |
---|
2232 | 2374 | NLM_F_MULTI, |
---|
2233 | | - OVS_VPORT_CMD_NEW, |
---|
| 2375 | + OVS_VPORT_CMD_GET, |
---|
2234 | 2376 | GFP_ATOMIC) < 0) |
---|
2235 | 2377 | goto out; |
---|
2236 | 2378 | |
---|
.. | .. |
---|
2247 | 2389 | return skb->len; |
---|
2248 | 2390 | } |
---|
2249 | 2391 | |
---|
| 2392 | +static void ovs_dp_masks_rebalance(struct work_struct *work) |
---|
| 2393 | +{ |
---|
| 2394 | + struct ovs_net *ovs_net = container_of(work, struct ovs_net, |
---|
| 2395 | + masks_rebalance.work); |
---|
| 2396 | + struct datapath *dp; |
---|
| 2397 | + |
---|
| 2398 | + ovs_lock(); |
---|
| 2399 | + |
---|
| 2400 | + list_for_each_entry(dp, &ovs_net->dps, list_node) |
---|
| 2401 | + ovs_flow_masks_rebalance(&dp->table); |
---|
| 2402 | + |
---|
| 2403 | + ovs_unlock(); |
---|
| 2404 | + |
---|
| 2405 | + schedule_delayed_work(&ovs_net->masks_rebalance, |
---|
| 2406 | + msecs_to_jiffies(DP_MASKS_REBALANCE_INTERVAL)); |
---|
| 2407 | +} |
---|
| 2408 | + |
---|
2250 | 2409 | static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { |
---|
2251 | 2410 | [OVS_VPORT_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, |
---|
2252 | 2411 | [OVS_VPORT_ATTR_STATS] = { .len = sizeof(struct ovs_vport_stats) }, |
---|
.. | .. |
---|
2258 | 2417 | [OVS_VPORT_ATTR_NETNSID] = { .type = NLA_S32 }, |
---|
2259 | 2418 | }; |
---|
2260 | 2419 | |
---|
2261 | | -static const struct genl_ops dp_vport_genl_ops[] = { |
---|
| 2420 | +static const struct genl_small_ops dp_vport_genl_ops[] = { |
---|
2262 | 2421 | { .cmd = OVS_VPORT_CMD_NEW, |
---|
| 2422 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
2263 | 2423 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
2264 | | - .policy = vport_policy, |
---|
2265 | 2424 | .doit = ovs_vport_cmd_new |
---|
2266 | 2425 | }, |
---|
2267 | 2426 | { .cmd = OVS_VPORT_CMD_DEL, |
---|
| 2427 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
2268 | 2428 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
2269 | | - .policy = vport_policy, |
---|
2270 | 2429 | .doit = ovs_vport_cmd_del |
---|
2271 | 2430 | }, |
---|
2272 | 2431 | { .cmd = OVS_VPORT_CMD_GET, |
---|
| 2432 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
2273 | 2433 | .flags = 0, /* OK for unprivileged users. */ |
---|
2274 | | - .policy = vport_policy, |
---|
2275 | 2434 | .doit = ovs_vport_cmd_get, |
---|
2276 | 2435 | .dumpit = ovs_vport_cmd_dump |
---|
2277 | 2436 | }, |
---|
2278 | 2437 | { .cmd = OVS_VPORT_CMD_SET, |
---|
| 2438 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
---|
2279 | 2439 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
---|
2280 | | - .policy = vport_policy, |
---|
2281 | 2440 | .doit = ovs_vport_cmd_set, |
---|
2282 | 2441 | }, |
---|
2283 | 2442 | }; |
---|
.. | .. |
---|
2287 | 2446 | .name = OVS_VPORT_FAMILY, |
---|
2288 | 2447 | .version = OVS_VPORT_VERSION, |
---|
2289 | 2448 | .maxattr = OVS_VPORT_ATTR_MAX, |
---|
| 2449 | + .policy = vport_policy, |
---|
2290 | 2450 | .netnsok = true, |
---|
2291 | 2451 | .parallel_ops = true, |
---|
2292 | | - .ops = dp_vport_genl_ops, |
---|
2293 | | - .n_ops = ARRAY_SIZE(dp_vport_genl_ops), |
---|
| 2452 | + .small_ops = dp_vport_genl_ops, |
---|
| 2453 | + .n_small_ops = ARRAY_SIZE(dp_vport_genl_ops), |
---|
2294 | 2454 | .mcgrps = &ovs_dp_vport_multicast_group, |
---|
2295 | 2455 | .n_mcgrps = 1, |
---|
2296 | 2456 | .module = THIS_MODULE, |
---|
.. | .. |
---|
2337 | 2497 | static int __net_init ovs_init_net(struct net *net) |
---|
2338 | 2498 | { |
---|
2339 | 2499 | struct ovs_net *ovs_net = net_generic(net, ovs_net_id); |
---|
| 2500 | + int err; |
---|
2340 | 2501 | |
---|
2341 | 2502 | INIT_LIST_HEAD(&ovs_net->dps); |
---|
2342 | 2503 | INIT_WORK(&ovs_net->dp_notify_work, ovs_dp_notify_wq); |
---|
2343 | | - return ovs_ct_init(net); |
---|
| 2504 | + INIT_DELAYED_WORK(&ovs_net->masks_rebalance, ovs_dp_masks_rebalance); |
---|
| 2505 | + |
---|
| 2506 | + err = ovs_ct_init(net); |
---|
| 2507 | + if (err) |
---|
| 2508 | + return err; |
---|
| 2509 | + |
---|
| 2510 | + schedule_delayed_work(&ovs_net->masks_rebalance, |
---|
| 2511 | + msecs_to_jiffies(DP_MASKS_REBALANCE_INTERVAL)); |
---|
| 2512 | + return 0; |
---|
2344 | 2513 | } |
---|
2345 | 2514 | |
---|
2346 | 2515 | static void __net_exit list_vports_from_net(struct net *net, struct net *dnet, |
---|
.. | .. |
---|
2374 | 2543 | struct net *net; |
---|
2375 | 2544 | LIST_HEAD(head); |
---|
2376 | 2545 | |
---|
2377 | | - ovs_ct_exit(dnet); |
---|
2378 | 2546 | ovs_lock(); |
---|
| 2547 | + |
---|
| 2548 | + ovs_ct_exit(dnet); |
---|
| 2549 | + |
---|
2379 | 2550 | list_for_each_entry_safe(dp, dp_next, &ovs_net->dps, list_node) |
---|
2380 | 2551 | __dp_destroy(dp); |
---|
2381 | 2552 | |
---|
.. | .. |
---|
2392 | 2563 | |
---|
2393 | 2564 | ovs_unlock(); |
---|
2394 | 2565 | |
---|
| 2566 | + cancel_delayed_work_sync(&ovs_net->masks_rebalance); |
---|
2395 | 2567 | cancel_work_sync(&ovs_net->dp_notify_work); |
---|
2396 | 2568 | } |
---|
2397 | 2569 | |
---|
.. | .. |
---|
2406 | 2578 | { |
---|
2407 | 2579 | int err; |
---|
2408 | 2580 | |
---|
2409 | | - BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > FIELD_SIZEOF(struct sk_buff, cb)); |
---|
| 2581 | + BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > |
---|
| 2582 | + sizeof_field(struct sk_buff, cb)); |
---|
2410 | 2583 | |
---|
2411 | 2584 | pr_info("Open vSwitch switching datapath\n"); |
---|
2412 | 2585 | |
---|