| .. | .. |
|---|
| 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 | |
|---|
| .. | .. |
|---|
| 1050 | 1088 | } |
|---|
| 1051 | 1089 | |
|---|
| 1052 | 1090 | /* 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) |
|---|
| 1091 | +static noinline_for_stack |
|---|
| 1092 | +struct sw_flow_actions *get_flow_actions(struct net *net, |
|---|
| 1093 | + const struct nlattr *a, |
|---|
| 1094 | + const struct sw_flow_key *key, |
|---|
| 1095 | + const struct sw_flow_mask *mask, |
|---|
| 1096 | + bool log) |
|---|
| 1058 | 1097 | { |
|---|
| 1059 | 1098 | struct sw_flow_actions *acts; |
|---|
| 1060 | 1099 | struct sw_flow_key masked_key; |
|---|
| .. | .. |
|---|
| 1084 | 1123 | * we should not to return match object with dangling reference |
|---|
| 1085 | 1124 | * to mask. |
|---|
| 1086 | 1125 | * */ |
|---|
| 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) |
|---|
| 1126 | +static noinline_for_stack int |
|---|
| 1127 | +ovs_nla_init_match_and_action(struct net *net, |
|---|
| 1128 | + struct sw_flow_match *match, |
|---|
| 1129 | + struct sw_flow_key *key, |
|---|
| 1130 | + struct nlattr **a, |
|---|
| 1131 | + struct sw_flow_actions **acts, |
|---|
| 1132 | + bool log) |
|---|
| 1093 | 1133 | { |
|---|
| 1094 | 1134 | struct sw_flow_mask mask; |
|---|
| 1095 | 1135 | int error = 0; |
|---|
| .. | .. |
|---|
| 1189 | 1229 | ovs_header->dp_ifindex, |
|---|
| 1190 | 1230 | reply, info->snd_portid, |
|---|
| 1191 | 1231 | info->snd_seq, 0, |
|---|
| 1192 | | - OVS_FLOW_CMD_NEW, |
|---|
| 1232 | + OVS_FLOW_CMD_SET, |
|---|
| 1193 | 1233 | ufid_flags); |
|---|
| 1194 | 1234 | BUG_ON(error < 0); |
|---|
| 1195 | 1235 | } |
|---|
| 1196 | 1236 | } else { |
|---|
| 1197 | 1237 | /* Could not alloc without acts before locking. */ |
|---|
| 1198 | 1238 | reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex, |
|---|
| 1199 | | - info, OVS_FLOW_CMD_NEW, false, |
|---|
| 1239 | + info, OVS_FLOW_CMD_SET, false, |
|---|
| 1200 | 1240 | ufid_flags); |
|---|
| 1201 | 1241 | |
|---|
| 1202 | 1242 | if (IS_ERR(reply)) { |
|---|
| .. | .. |
|---|
| 1272 | 1312 | } |
|---|
| 1273 | 1313 | |
|---|
| 1274 | 1314 | reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex, info, |
|---|
| 1275 | | - OVS_FLOW_CMD_NEW, true, ufid_flags); |
|---|
| 1315 | + OVS_FLOW_CMD_GET, true, ufid_flags); |
|---|
| 1276 | 1316 | if (IS_ERR(reply)) { |
|---|
| 1277 | 1317 | err = PTR_ERR(reply); |
|---|
| 1278 | 1318 | goto unlock; |
|---|
| .. | .. |
|---|
| 1337 | 1377 | reply = ovs_flow_cmd_alloc_info((const struct sw_flow_actions __force *) flow->sf_acts, |
|---|
| 1338 | 1378 | &flow->id, info, false, ufid_flags); |
|---|
| 1339 | 1379 | if (likely(reply)) { |
|---|
| 1340 | | - if (likely(!IS_ERR(reply))) { |
|---|
| 1380 | + if (!IS_ERR(reply)) { |
|---|
| 1341 | 1381 | rcu_read_lock(); /*To keep RCU checker happy. */ |
|---|
| 1342 | 1382 | err = ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex, |
|---|
| 1343 | 1383 | reply, info->snd_portid, |
|---|
| .. | .. |
|---|
| 1352 | 1392 | |
|---|
| 1353 | 1393 | ovs_notify(&dp_flow_genl_family, reply, info); |
|---|
| 1354 | 1394 | } else { |
|---|
| 1355 | | - netlink_set_err(sock_net(skb->sk)->genl_sock, 0, 0, PTR_ERR(reply)); |
|---|
| 1395 | + netlink_set_err(sock_net(skb->sk)->genl_sock, 0, 0, |
|---|
| 1396 | + PTR_ERR(reply)); |
|---|
| 1356 | 1397 | } |
|---|
| 1357 | 1398 | } |
|---|
| 1358 | 1399 | |
|---|
| .. | .. |
|---|
| 1373 | 1414 | u32 ufid_flags; |
|---|
| 1374 | 1415 | int err; |
|---|
| 1375 | 1416 | |
|---|
| 1376 | | - err = genlmsg_parse(cb->nlh, &dp_flow_genl_family, a, |
|---|
| 1377 | | - OVS_FLOW_ATTR_MAX, flow_policy, NULL); |
|---|
| 1417 | + err = genlmsg_parse_deprecated(cb->nlh, &dp_flow_genl_family, a, |
|---|
| 1418 | + OVS_FLOW_ATTR_MAX, flow_policy, NULL); |
|---|
| 1378 | 1419 | if (err) |
|---|
| 1379 | 1420 | return err; |
|---|
| 1380 | 1421 | ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]); |
|---|
| .. | .. |
|---|
| 1400 | 1441 | if (ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex, skb, |
|---|
| 1401 | 1442 | NETLINK_CB(cb->skb).portid, |
|---|
| 1402 | 1443 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
|---|
| 1403 | | - OVS_FLOW_CMD_NEW, ufid_flags) < 0) |
|---|
| 1444 | + OVS_FLOW_CMD_GET, ufid_flags) < 0) |
|---|
| 1404 | 1445 | break; |
|---|
| 1405 | 1446 | |
|---|
| 1406 | 1447 | cb->args[0] = bucket; |
|---|
| .. | .. |
|---|
| 1420 | 1461 | [OVS_FLOW_ATTR_UFID_FLAGS] = { .type = NLA_U32 }, |
|---|
| 1421 | 1462 | }; |
|---|
| 1422 | 1463 | |
|---|
| 1423 | | -static const struct genl_ops dp_flow_genl_ops[] = { |
|---|
| 1464 | +static const struct genl_small_ops dp_flow_genl_ops[] = { |
|---|
| 1424 | 1465 | { .cmd = OVS_FLOW_CMD_NEW, |
|---|
| 1466 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1425 | 1467 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 1426 | | - .policy = flow_policy, |
|---|
| 1427 | 1468 | .doit = ovs_flow_cmd_new |
|---|
| 1428 | 1469 | }, |
|---|
| 1429 | 1470 | { .cmd = OVS_FLOW_CMD_DEL, |
|---|
| 1471 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1430 | 1472 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 1431 | | - .policy = flow_policy, |
|---|
| 1432 | 1473 | .doit = ovs_flow_cmd_del |
|---|
| 1433 | 1474 | }, |
|---|
| 1434 | 1475 | { .cmd = OVS_FLOW_CMD_GET, |
|---|
| 1476 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1435 | 1477 | .flags = 0, /* OK for unprivileged users. */ |
|---|
| 1436 | | - .policy = flow_policy, |
|---|
| 1437 | 1478 | .doit = ovs_flow_cmd_get, |
|---|
| 1438 | 1479 | .dumpit = ovs_flow_cmd_dump |
|---|
| 1439 | 1480 | }, |
|---|
| 1440 | 1481 | { .cmd = OVS_FLOW_CMD_SET, |
|---|
| 1482 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1441 | 1483 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 1442 | | - .policy = flow_policy, |
|---|
| 1443 | 1484 | .doit = ovs_flow_cmd_set, |
|---|
| 1444 | 1485 | }, |
|---|
| 1445 | 1486 | }; |
|---|
| .. | .. |
|---|
| 1449 | 1490 | .name = OVS_FLOW_FAMILY, |
|---|
| 1450 | 1491 | .version = OVS_FLOW_VERSION, |
|---|
| 1451 | 1492 | .maxattr = OVS_FLOW_ATTR_MAX, |
|---|
| 1493 | + .policy = flow_policy, |
|---|
| 1452 | 1494 | .netnsok = true, |
|---|
| 1453 | 1495 | .parallel_ops = true, |
|---|
| 1454 | | - .ops = dp_flow_genl_ops, |
|---|
| 1455 | | - .n_ops = ARRAY_SIZE(dp_flow_genl_ops), |
|---|
| 1496 | + .small_ops = dp_flow_genl_ops, |
|---|
| 1497 | + .n_small_ops = ARRAY_SIZE(dp_flow_genl_ops), |
|---|
| 1456 | 1498 | .mcgrps = &ovs_dp_flow_multicast_group, |
|---|
| 1457 | 1499 | .n_mcgrps = 1, |
|---|
| 1458 | 1500 | .module = THIS_MODULE, |
|---|
| .. | .. |
|---|
| 1466 | 1508 | msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_stats)); |
|---|
| 1467 | 1509 | msgsize += nla_total_size_64bit(sizeof(struct ovs_dp_megaflow_stats)); |
|---|
| 1468 | 1510 | msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_USER_FEATURES */ |
|---|
| 1511 | + msgsize += nla_total_size(sizeof(u32)); /* OVS_DP_ATTR_MASKS_CACHE_SIZE */ |
|---|
| 1469 | 1512 | |
|---|
| 1470 | 1513 | return msgsize; |
|---|
| 1471 | 1514 | } |
|---|
| .. | .. |
|---|
| 1480 | 1523 | int err; |
|---|
| 1481 | 1524 | |
|---|
| 1482 | 1525 | ovs_header = genlmsg_put(skb, portid, seq, &dp_datapath_genl_family, |
|---|
| 1483 | | - flags, cmd); |
|---|
| 1526 | + flags, cmd); |
|---|
| 1484 | 1527 | if (!ovs_header) |
|---|
| 1485 | 1528 | goto error; |
|---|
| 1486 | 1529 | |
|---|
| .. | .. |
|---|
| 1501 | 1544 | goto nla_put_failure; |
|---|
| 1502 | 1545 | |
|---|
| 1503 | 1546 | if (nla_put_u32(skb, OVS_DP_ATTR_USER_FEATURES, dp->user_features)) |
|---|
| 1547 | + goto nla_put_failure; |
|---|
| 1548 | + |
|---|
| 1549 | + if (nla_put_u32(skb, OVS_DP_ATTR_MASKS_CACHE_SIZE, |
|---|
| 1550 | + ovs_flow_tbl_masks_cache_size(&dp->table))) |
|---|
| 1504 | 1551 | goto nla_put_failure; |
|---|
| 1505 | 1552 | |
|---|
| 1506 | 1553 | genlmsg_end(skb, ovs_header); |
|---|
| .. | .. |
|---|
| 1535 | 1582 | return dp ? dp : ERR_PTR(-ENODEV); |
|---|
| 1536 | 1583 | } |
|---|
| 1537 | 1584 | |
|---|
| 1538 | | -static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *info) |
|---|
| 1585 | +static void ovs_dp_reset_user_features(struct sk_buff *skb, |
|---|
| 1586 | + struct genl_info *info) |
|---|
| 1539 | 1587 | { |
|---|
| 1540 | 1588 | struct datapath *dp; |
|---|
| 1541 | 1589 | |
|---|
| 1542 | | - dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs); |
|---|
| 1590 | + dp = lookup_datapath(sock_net(skb->sk), info->userhdr, |
|---|
| 1591 | + info->attrs); |
|---|
| 1543 | 1592 | if (IS_ERR(dp)) |
|---|
| 1544 | 1593 | return; |
|---|
| 1545 | 1594 | |
|---|
| 1546 | | - WARN(dp->user_features, "Dropping previously announced user features\n"); |
|---|
| 1595 | + pr_warn("%s: Dropping previously announced user features\n", |
|---|
| 1596 | + ovs_dp_name(dp)); |
|---|
| 1547 | 1597 | dp->user_features = 0; |
|---|
| 1548 | 1598 | } |
|---|
| 1549 | 1599 | |
|---|
| 1550 | | -static void ovs_dp_change(struct datapath *dp, struct nlattr *a[]) |
|---|
| 1600 | +DEFINE_STATIC_KEY_FALSE(tc_recirc_sharing_support); |
|---|
| 1601 | + |
|---|
| 1602 | +static int ovs_dp_change(struct datapath *dp, struct nlattr *a[]) |
|---|
| 1551 | 1603 | { |
|---|
| 1552 | | - if (a[OVS_DP_ATTR_USER_FEATURES]) |
|---|
| 1553 | | - dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]); |
|---|
| 1604 | + u32 user_features = 0; |
|---|
| 1605 | + |
|---|
| 1606 | + if (a[OVS_DP_ATTR_USER_FEATURES]) { |
|---|
| 1607 | + user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]); |
|---|
| 1608 | + |
|---|
| 1609 | + if (user_features & ~(OVS_DP_F_VPORT_PIDS | |
|---|
| 1610 | + OVS_DP_F_UNALIGNED | |
|---|
| 1611 | + OVS_DP_F_TC_RECIRC_SHARING)) |
|---|
| 1612 | + return -EOPNOTSUPP; |
|---|
| 1613 | + |
|---|
| 1614 | +#if !IS_ENABLED(CONFIG_NET_TC_SKB_EXT) |
|---|
| 1615 | + if (user_features & OVS_DP_F_TC_RECIRC_SHARING) |
|---|
| 1616 | + return -EOPNOTSUPP; |
|---|
| 1617 | +#endif |
|---|
| 1618 | + } |
|---|
| 1619 | + |
|---|
| 1620 | + if (a[OVS_DP_ATTR_MASKS_CACHE_SIZE]) { |
|---|
| 1621 | + int err; |
|---|
| 1622 | + u32 cache_size; |
|---|
| 1623 | + |
|---|
| 1624 | + cache_size = nla_get_u32(a[OVS_DP_ATTR_MASKS_CACHE_SIZE]); |
|---|
| 1625 | + err = ovs_flow_tbl_masks_cache_resize(&dp->table, cache_size); |
|---|
| 1626 | + if (err) |
|---|
| 1627 | + return err; |
|---|
| 1628 | + } |
|---|
| 1629 | + |
|---|
| 1630 | + dp->user_features = user_features; |
|---|
| 1631 | + |
|---|
| 1632 | + if (dp->user_features & OVS_DP_F_TC_RECIRC_SHARING) |
|---|
| 1633 | + static_branch_enable(&tc_recirc_sharing_support); |
|---|
| 1634 | + else |
|---|
| 1635 | + static_branch_disable(&tc_recirc_sharing_support); |
|---|
| 1636 | + |
|---|
| 1637 | + return 0; |
|---|
| 1638 | +} |
|---|
| 1639 | + |
|---|
| 1640 | +static int ovs_dp_stats_init(struct datapath *dp) |
|---|
| 1641 | +{ |
|---|
| 1642 | + dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu); |
|---|
| 1643 | + if (!dp->stats_percpu) |
|---|
| 1644 | + return -ENOMEM; |
|---|
| 1645 | + |
|---|
| 1646 | + return 0; |
|---|
| 1647 | +} |
|---|
| 1648 | + |
|---|
| 1649 | +static int ovs_dp_vport_init(struct datapath *dp) |
|---|
| 1650 | +{ |
|---|
| 1651 | + int i; |
|---|
| 1652 | + |
|---|
| 1653 | + dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS, |
|---|
| 1654 | + sizeof(struct hlist_head), |
|---|
| 1655 | + GFP_KERNEL); |
|---|
| 1656 | + if (!dp->ports) |
|---|
| 1657 | + return -ENOMEM; |
|---|
| 1658 | + |
|---|
| 1659 | + for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) |
|---|
| 1660 | + INIT_HLIST_HEAD(&dp->ports[i]); |
|---|
| 1661 | + |
|---|
| 1662 | + return 0; |
|---|
| 1554 | 1663 | } |
|---|
| 1555 | 1664 | |
|---|
| 1556 | 1665 | static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) |
|---|
| .. | .. |
|---|
| 1561 | 1670 | struct datapath *dp; |
|---|
| 1562 | 1671 | struct vport *vport; |
|---|
| 1563 | 1672 | struct ovs_net *ovs_net; |
|---|
| 1564 | | - int err, i; |
|---|
| 1673 | + int err; |
|---|
| 1565 | 1674 | |
|---|
| 1566 | 1675 | err = -EINVAL; |
|---|
| 1567 | 1676 | if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID]) |
|---|
| .. | .. |
|---|
| 1574 | 1683 | err = -ENOMEM; |
|---|
| 1575 | 1684 | dp = kzalloc(sizeof(*dp), GFP_KERNEL); |
|---|
| 1576 | 1685 | if (dp == NULL) |
|---|
| 1577 | | - goto err_free_reply; |
|---|
| 1686 | + goto err_destroy_reply; |
|---|
| 1578 | 1687 | |
|---|
| 1579 | 1688 | ovs_dp_set_net(dp, sock_net(skb->sk)); |
|---|
| 1580 | 1689 | |
|---|
| 1581 | 1690 | /* Allocate table. */ |
|---|
| 1582 | 1691 | err = ovs_flow_tbl_init(&dp->table); |
|---|
| 1583 | 1692 | if (err) |
|---|
| 1584 | | - goto err_free_dp; |
|---|
| 1693 | + goto err_destroy_dp; |
|---|
| 1585 | 1694 | |
|---|
| 1586 | | - dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu); |
|---|
| 1587 | | - if (!dp->stats_percpu) { |
|---|
| 1588 | | - err = -ENOMEM; |
|---|
| 1695 | + err = ovs_dp_stats_init(dp); |
|---|
| 1696 | + if (err) |
|---|
| 1589 | 1697 | goto err_destroy_table; |
|---|
| 1590 | | - } |
|---|
| 1591 | 1698 | |
|---|
| 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]); |
|---|
| 1699 | + err = ovs_dp_vport_init(dp); |
|---|
| 1700 | + if (err) |
|---|
| 1701 | + goto err_destroy_stats; |
|---|
| 1602 | 1702 | |
|---|
| 1603 | 1703 | err = ovs_meters_init(dp); |
|---|
| 1604 | 1704 | if (err) |
|---|
| 1605 | | - goto err_destroy_ports_array; |
|---|
| 1705 | + goto err_destroy_ports; |
|---|
| 1606 | 1706 | |
|---|
| 1607 | 1707 | /* Set up our datapath device. */ |
|---|
| 1608 | 1708 | parms.name = nla_data(a[OVS_DP_ATTR_NAME]); |
|---|
| .. | .. |
|---|
| 1612 | 1712 | parms.port_no = OVSP_LOCAL; |
|---|
| 1613 | 1713 | parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID]; |
|---|
| 1614 | 1714 | |
|---|
| 1615 | | - ovs_dp_change(dp, a); |
|---|
| 1616 | | - |
|---|
| 1617 | 1715 | /* So far only local changes have been made, now need the lock. */ |
|---|
| 1618 | 1716 | ovs_lock(); |
|---|
| 1717 | + |
|---|
| 1718 | + err = ovs_dp_change(dp, a); |
|---|
| 1719 | + if (err) |
|---|
| 1720 | + goto err_unlock_and_destroy_meters; |
|---|
| 1619 | 1721 | |
|---|
| 1620 | 1722 | vport = new_vport(&parms); |
|---|
| 1621 | 1723 | if (IS_ERR(vport)) { |
|---|
| .. | .. |
|---|
| 1632 | 1734 | ovs_dp_reset_user_features(skb, info); |
|---|
| 1633 | 1735 | } |
|---|
| 1634 | 1736 | |
|---|
| 1635 | | - goto err_destroy_meters; |
|---|
| 1737 | + goto err_unlock_and_destroy_meters; |
|---|
| 1636 | 1738 | } |
|---|
| 1637 | 1739 | |
|---|
| 1638 | 1740 | err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, |
|---|
| .. | .. |
|---|
| 1647 | 1749 | ovs_notify(&dp_datapath_genl_family, reply, info); |
|---|
| 1648 | 1750 | return 0; |
|---|
| 1649 | 1751 | |
|---|
| 1650 | | -err_destroy_meters: |
|---|
| 1752 | +err_unlock_and_destroy_meters: |
|---|
| 1651 | 1753 | ovs_unlock(); |
|---|
| 1652 | 1754 | ovs_meters_exit(dp); |
|---|
| 1653 | | -err_destroy_ports_array: |
|---|
| 1755 | +err_destroy_ports: |
|---|
| 1654 | 1756 | kfree(dp->ports); |
|---|
| 1655 | | -err_destroy_percpu: |
|---|
| 1757 | +err_destroy_stats: |
|---|
| 1656 | 1758 | free_percpu(dp->stats_percpu); |
|---|
| 1657 | 1759 | err_destroy_table: |
|---|
| 1658 | 1760 | ovs_flow_tbl_destroy(&dp->table); |
|---|
| 1659 | | -err_free_dp: |
|---|
| 1761 | +err_destroy_dp: |
|---|
| 1660 | 1762 | kfree(dp); |
|---|
| 1661 | | -err_free_reply: |
|---|
| 1763 | +err_destroy_reply: |
|---|
| 1662 | 1764 | kfree_skb(reply); |
|---|
| 1663 | 1765 | err: |
|---|
| 1664 | 1766 | return err; |
|---|
| .. | .. |
|---|
| 1667 | 1769 | /* Called with ovs_mutex. */ |
|---|
| 1668 | 1770 | static void __dp_destroy(struct datapath *dp) |
|---|
| 1669 | 1771 | { |
|---|
| 1772 | + struct flow_table *table = &dp->table; |
|---|
| 1670 | 1773 | int i; |
|---|
| 1671 | 1774 | |
|---|
| 1672 | 1775 | for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) { |
|---|
| .. | .. |
|---|
| 1685 | 1788 | */ |
|---|
| 1686 | 1789 | ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL)); |
|---|
| 1687 | 1790 | |
|---|
| 1688 | | - /* RCU destroy the flow table */ |
|---|
| 1791 | + /* Flush sw_flow in the tables. RCU cb only releases resource |
|---|
| 1792 | + * such as dp, ports and tables. That may avoid some issues |
|---|
| 1793 | + * such as RCU usage warning. |
|---|
| 1794 | + */ |
|---|
| 1795 | + table_instance_flow_flush(table, ovsl_dereference(table->ti), |
|---|
| 1796 | + ovsl_dereference(table->ufid_ti)); |
|---|
| 1797 | + |
|---|
| 1798 | + /* RCU destroy the ports, meters and flow tables. */ |
|---|
| 1689 | 1799 | call_rcu(&dp->rcu, destroy_dp_rcu); |
|---|
| 1690 | 1800 | } |
|---|
| 1691 | 1801 | |
|---|
| .. | .. |
|---|
| 1738 | 1848 | if (IS_ERR(dp)) |
|---|
| 1739 | 1849 | goto err_unlock_free; |
|---|
| 1740 | 1850 | |
|---|
| 1741 | | - ovs_dp_change(dp, info->attrs); |
|---|
| 1851 | + err = ovs_dp_change(dp, info->attrs); |
|---|
| 1852 | + if (err) |
|---|
| 1853 | + goto err_unlock_free; |
|---|
| 1742 | 1854 | |
|---|
| 1743 | 1855 | err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, |
|---|
| 1744 | | - info->snd_seq, 0, OVS_DP_CMD_NEW); |
|---|
| 1856 | + info->snd_seq, 0, OVS_DP_CMD_SET); |
|---|
| 1745 | 1857 | BUG_ON(err < 0); |
|---|
| 1746 | 1858 | |
|---|
| 1747 | 1859 | ovs_unlock(); |
|---|
| .. | .. |
|---|
| 1772 | 1884 | goto err_unlock_free; |
|---|
| 1773 | 1885 | } |
|---|
| 1774 | 1886 | err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, |
|---|
| 1775 | | - info->snd_seq, 0, OVS_DP_CMD_NEW); |
|---|
| 1887 | + info->snd_seq, 0, OVS_DP_CMD_GET); |
|---|
| 1776 | 1888 | BUG_ON(err < 0); |
|---|
| 1777 | 1889 | ovs_unlock(); |
|---|
| 1778 | 1890 | |
|---|
| .. | .. |
|---|
| 1796 | 1908 | if (i >= skip && |
|---|
| 1797 | 1909 | ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid, |
|---|
| 1798 | 1910 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
|---|
| 1799 | | - OVS_DP_CMD_NEW) < 0) |
|---|
| 1911 | + OVS_DP_CMD_GET) < 0) |
|---|
| 1800 | 1912 | break; |
|---|
| 1801 | 1913 | i++; |
|---|
| 1802 | 1914 | } |
|---|
| .. | .. |
|---|
| 1811 | 1923 | [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, |
|---|
| 1812 | 1924 | [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 }, |
|---|
| 1813 | 1925 | [OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 }, |
|---|
| 1926 | + [OVS_DP_ATTR_MASKS_CACHE_SIZE] = NLA_POLICY_RANGE(NLA_U32, 0, |
|---|
| 1927 | + PCPU_MIN_UNIT_SIZE / sizeof(struct mask_cache_entry)), |
|---|
| 1814 | 1928 | }; |
|---|
| 1815 | 1929 | |
|---|
| 1816 | | -static const struct genl_ops dp_datapath_genl_ops[] = { |
|---|
| 1930 | +static const struct genl_small_ops dp_datapath_genl_ops[] = { |
|---|
| 1817 | 1931 | { .cmd = OVS_DP_CMD_NEW, |
|---|
| 1932 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1818 | 1933 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 1819 | | - .policy = datapath_policy, |
|---|
| 1820 | 1934 | .doit = ovs_dp_cmd_new |
|---|
| 1821 | 1935 | }, |
|---|
| 1822 | 1936 | { .cmd = OVS_DP_CMD_DEL, |
|---|
| 1937 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1823 | 1938 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 1824 | | - .policy = datapath_policy, |
|---|
| 1825 | 1939 | .doit = ovs_dp_cmd_del |
|---|
| 1826 | 1940 | }, |
|---|
| 1827 | 1941 | { .cmd = OVS_DP_CMD_GET, |
|---|
| 1942 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1828 | 1943 | .flags = 0, /* OK for unprivileged users. */ |
|---|
| 1829 | | - .policy = datapath_policy, |
|---|
| 1830 | 1944 | .doit = ovs_dp_cmd_get, |
|---|
| 1831 | 1945 | .dumpit = ovs_dp_cmd_dump |
|---|
| 1832 | 1946 | }, |
|---|
| 1833 | 1947 | { .cmd = OVS_DP_CMD_SET, |
|---|
| 1948 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 1834 | 1949 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 1835 | | - .policy = datapath_policy, |
|---|
| 1836 | 1950 | .doit = ovs_dp_cmd_set, |
|---|
| 1837 | 1951 | }, |
|---|
| 1838 | 1952 | }; |
|---|
| .. | .. |
|---|
| 1842 | 1956 | .name = OVS_DATAPATH_FAMILY, |
|---|
| 1843 | 1957 | .version = OVS_DATAPATH_VERSION, |
|---|
| 1844 | 1958 | .maxattr = OVS_DP_ATTR_MAX, |
|---|
| 1959 | + .policy = datapath_policy, |
|---|
| 1845 | 1960 | .netnsok = true, |
|---|
| 1846 | 1961 | .parallel_ops = true, |
|---|
| 1847 | | - .ops = dp_datapath_genl_ops, |
|---|
| 1848 | | - .n_ops = ARRAY_SIZE(dp_datapath_genl_ops), |
|---|
| 1962 | + .small_ops = dp_datapath_genl_ops, |
|---|
| 1963 | + .n_small_ops = ARRAY_SIZE(dp_datapath_genl_ops), |
|---|
| 1849 | 1964 | .mcgrps = &ovs_dp_datapath_multicast_group, |
|---|
| 1850 | 1965 | .n_mcgrps = 1, |
|---|
| 1851 | 1966 | .module = THIS_MODULE, |
|---|
| .. | .. |
|---|
| 1964 | 2079 | |
|---|
| 1965 | 2080 | } |
|---|
| 1966 | 2081 | |
|---|
| 1967 | | -/* Called with ovs_mutex */ |
|---|
| 1968 | | -static void update_headroom(struct datapath *dp) |
|---|
| 2082 | +static unsigned int ovs_get_max_headroom(struct datapath *dp) |
|---|
| 1969 | 2083 | { |
|---|
| 1970 | | - unsigned dev_headroom, max_headroom = 0; |
|---|
| 2084 | + unsigned int dev_headroom, max_headroom = 0; |
|---|
| 1971 | 2085 | struct net_device *dev; |
|---|
| 1972 | 2086 | struct vport *vport; |
|---|
| 1973 | 2087 | int i; |
|---|
| 1974 | 2088 | |
|---|
| 1975 | 2089 | for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) { |
|---|
| 1976 | | - hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node) { |
|---|
| 2090 | + hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node, |
|---|
| 2091 | + lockdep_ovsl_is_held()) { |
|---|
| 1977 | 2092 | dev = vport->dev; |
|---|
| 1978 | 2093 | dev_headroom = netdev_get_fwd_headroom(dev); |
|---|
| 1979 | 2094 | if (dev_headroom > max_headroom) |
|---|
| .. | .. |
|---|
| 1981 | 2096 | } |
|---|
| 1982 | 2097 | } |
|---|
| 1983 | 2098 | |
|---|
| 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); |
|---|
| 2099 | + return max_headroom; |
|---|
| 2100 | +} |
|---|
| 2101 | + |
|---|
| 2102 | +/* Called with ovs_mutex */ |
|---|
| 2103 | +static void ovs_update_headroom(struct datapath *dp, unsigned int new_headroom) |
|---|
| 2104 | +{ |
|---|
| 2105 | + struct vport *vport; |
|---|
| 2106 | + int i; |
|---|
| 2107 | + |
|---|
| 2108 | + dp->max_headroom = new_headroom; |
|---|
| 2109 | + for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) { |
|---|
| 2110 | + hlist_for_each_entry_rcu(vport, &dp->ports[i], dp_hash_node, |
|---|
| 2111 | + lockdep_ovsl_is_held()) |
|---|
| 2112 | + netdev_set_rx_headroom(vport->dev, new_headroom); |
|---|
| 2113 | + } |
|---|
| 1988 | 2114 | } |
|---|
| 1989 | 2115 | |
|---|
| 1990 | 2116 | static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) |
|---|
| .. | .. |
|---|
| 1995 | 2121 | struct sk_buff *reply; |
|---|
| 1996 | 2122 | struct vport *vport; |
|---|
| 1997 | 2123 | struct datapath *dp; |
|---|
| 2124 | + unsigned int new_headroom; |
|---|
| 1998 | 2125 | u32 port_no; |
|---|
| 1999 | 2126 | int err; |
|---|
| 2000 | 2127 | |
|---|
| .. | .. |
|---|
| 2056 | 2183 | info->snd_portid, info->snd_seq, 0, |
|---|
| 2057 | 2184 | OVS_VPORT_CMD_NEW, GFP_KERNEL); |
|---|
| 2058 | 2185 | |
|---|
| 2059 | | - if (netdev_get_fwd_headroom(vport->dev) > dp->max_headroom) |
|---|
| 2060 | | - update_headroom(dp); |
|---|
| 2186 | + new_headroom = netdev_get_fwd_headroom(vport->dev); |
|---|
| 2187 | + |
|---|
| 2188 | + if (new_headroom > dp->max_headroom) |
|---|
| 2189 | + ovs_update_headroom(dp, new_headroom); |
|---|
| 2061 | 2190 | else |
|---|
| 2062 | 2191 | netdev_set_rx_headroom(vport->dev, dp->max_headroom); |
|---|
| 2063 | 2192 | |
|---|
| .. | .. |
|---|
| 2113 | 2242 | |
|---|
| 2114 | 2243 | err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), |
|---|
| 2115 | 2244 | info->snd_portid, info->snd_seq, 0, |
|---|
| 2116 | | - OVS_VPORT_CMD_NEW, GFP_ATOMIC); |
|---|
| 2245 | + OVS_VPORT_CMD_SET, GFP_KERNEL); |
|---|
| 2117 | 2246 | BUG_ON(err < 0); |
|---|
| 2118 | 2247 | |
|---|
| 2119 | 2248 | ovs_unlock(); |
|---|
| .. | .. |
|---|
| 2128 | 2257 | |
|---|
| 2129 | 2258 | static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info) |
|---|
| 2130 | 2259 | { |
|---|
| 2131 | | - bool must_update_headroom = false; |
|---|
| 2260 | + bool update_headroom = false; |
|---|
| 2132 | 2261 | struct nlattr **a = info->attrs; |
|---|
| 2133 | 2262 | struct sk_buff *reply; |
|---|
| 2134 | 2263 | struct datapath *dp; |
|---|
| 2135 | 2264 | struct vport *vport; |
|---|
| 2265 | + unsigned int new_headroom; |
|---|
| 2136 | 2266 | int err; |
|---|
| 2137 | 2267 | |
|---|
| 2138 | 2268 | reply = ovs_vport_cmd_alloc_info(); |
|---|
| .. | .. |
|---|
| 2158 | 2288 | /* the vport deletion may trigger dp headroom update */ |
|---|
| 2159 | 2289 | dp = vport->dp; |
|---|
| 2160 | 2290 | if (netdev_get_fwd_headroom(vport->dev) == dp->max_headroom) |
|---|
| 2161 | | - must_update_headroom = true; |
|---|
| 2291 | + update_headroom = true; |
|---|
| 2292 | + |
|---|
| 2162 | 2293 | netdev_reset_rx_headroom(vport->dev); |
|---|
| 2163 | 2294 | ovs_dp_detach_port(vport); |
|---|
| 2164 | 2295 | |
|---|
| 2165 | | - if (must_update_headroom) |
|---|
| 2166 | | - update_headroom(dp); |
|---|
| 2296 | + if (update_headroom) { |
|---|
| 2297 | + new_headroom = ovs_get_max_headroom(dp); |
|---|
| 2298 | + |
|---|
| 2299 | + if (new_headroom < dp->max_headroom) |
|---|
| 2300 | + ovs_update_headroom(dp, new_headroom); |
|---|
| 2301 | + } |
|---|
| 2167 | 2302 | ovs_unlock(); |
|---|
| 2168 | 2303 | |
|---|
| 2169 | 2304 | ovs_notify(&dp_vport_genl_family, reply, info); |
|---|
| .. | .. |
|---|
| 2194 | 2329 | goto exit_unlock_free; |
|---|
| 2195 | 2330 | err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), |
|---|
| 2196 | 2331 | info->snd_portid, info->snd_seq, 0, |
|---|
| 2197 | | - OVS_VPORT_CMD_NEW, GFP_ATOMIC); |
|---|
| 2332 | + OVS_VPORT_CMD_GET, GFP_ATOMIC); |
|---|
| 2198 | 2333 | BUG_ON(err < 0); |
|---|
| 2199 | 2334 | rcu_read_unlock(); |
|---|
| 2200 | 2335 | |
|---|
| .. | .. |
|---|
| 2230 | 2365 | NETLINK_CB(cb->skb).portid, |
|---|
| 2231 | 2366 | cb->nlh->nlmsg_seq, |
|---|
| 2232 | 2367 | NLM_F_MULTI, |
|---|
| 2233 | | - OVS_VPORT_CMD_NEW, |
|---|
| 2368 | + OVS_VPORT_CMD_GET, |
|---|
| 2234 | 2369 | GFP_ATOMIC) < 0) |
|---|
| 2235 | 2370 | goto out; |
|---|
| 2236 | 2371 | |
|---|
| .. | .. |
|---|
| 2247 | 2382 | return skb->len; |
|---|
| 2248 | 2383 | } |
|---|
| 2249 | 2384 | |
|---|
| 2385 | +static void ovs_dp_masks_rebalance(struct work_struct *work) |
|---|
| 2386 | +{ |
|---|
| 2387 | + struct ovs_net *ovs_net = container_of(work, struct ovs_net, |
|---|
| 2388 | + masks_rebalance.work); |
|---|
| 2389 | + struct datapath *dp; |
|---|
| 2390 | + |
|---|
| 2391 | + ovs_lock(); |
|---|
| 2392 | + |
|---|
| 2393 | + list_for_each_entry(dp, &ovs_net->dps, list_node) |
|---|
| 2394 | + ovs_flow_masks_rebalance(&dp->table); |
|---|
| 2395 | + |
|---|
| 2396 | + ovs_unlock(); |
|---|
| 2397 | + |
|---|
| 2398 | + schedule_delayed_work(&ovs_net->masks_rebalance, |
|---|
| 2399 | + msecs_to_jiffies(DP_MASKS_REBALANCE_INTERVAL)); |
|---|
| 2400 | +} |
|---|
| 2401 | + |
|---|
| 2250 | 2402 | static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { |
|---|
| 2251 | 2403 | [OVS_VPORT_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, |
|---|
| 2252 | 2404 | [OVS_VPORT_ATTR_STATS] = { .len = sizeof(struct ovs_vport_stats) }, |
|---|
| .. | .. |
|---|
| 2258 | 2410 | [OVS_VPORT_ATTR_NETNSID] = { .type = NLA_S32 }, |
|---|
| 2259 | 2411 | }; |
|---|
| 2260 | 2412 | |
|---|
| 2261 | | -static const struct genl_ops dp_vport_genl_ops[] = { |
|---|
| 2413 | +static const struct genl_small_ops dp_vport_genl_ops[] = { |
|---|
| 2262 | 2414 | { .cmd = OVS_VPORT_CMD_NEW, |
|---|
| 2415 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 2263 | 2416 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 2264 | | - .policy = vport_policy, |
|---|
| 2265 | 2417 | .doit = ovs_vport_cmd_new |
|---|
| 2266 | 2418 | }, |
|---|
| 2267 | 2419 | { .cmd = OVS_VPORT_CMD_DEL, |
|---|
| 2420 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 2268 | 2421 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 2269 | | - .policy = vport_policy, |
|---|
| 2270 | 2422 | .doit = ovs_vport_cmd_del |
|---|
| 2271 | 2423 | }, |
|---|
| 2272 | 2424 | { .cmd = OVS_VPORT_CMD_GET, |
|---|
| 2425 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 2273 | 2426 | .flags = 0, /* OK for unprivileged users. */ |
|---|
| 2274 | | - .policy = vport_policy, |
|---|
| 2275 | 2427 | .doit = ovs_vport_cmd_get, |
|---|
| 2276 | 2428 | .dumpit = ovs_vport_cmd_dump |
|---|
| 2277 | 2429 | }, |
|---|
| 2278 | 2430 | { .cmd = OVS_VPORT_CMD_SET, |
|---|
| 2431 | + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
|---|
| 2279 | 2432 | .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
|---|
| 2280 | | - .policy = vport_policy, |
|---|
| 2281 | 2433 | .doit = ovs_vport_cmd_set, |
|---|
| 2282 | 2434 | }, |
|---|
| 2283 | 2435 | }; |
|---|
| .. | .. |
|---|
| 2287 | 2439 | .name = OVS_VPORT_FAMILY, |
|---|
| 2288 | 2440 | .version = OVS_VPORT_VERSION, |
|---|
| 2289 | 2441 | .maxattr = OVS_VPORT_ATTR_MAX, |
|---|
| 2442 | + .policy = vport_policy, |
|---|
| 2290 | 2443 | .netnsok = true, |
|---|
| 2291 | 2444 | .parallel_ops = true, |
|---|
| 2292 | | - .ops = dp_vport_genl_ops, |
|---|
| 2293 | | - .n_ops = ARRAY_SIZE(dp_vport_genl_ops), |
|---|
| 2445 | + .small_ops = dp_vport_genl_ops, |
|---|
| 2446 | + .n_small_ops = ARRAY_SIZE(dp_vport_genl_ops), |
|---|
| 2294 | 2447 | .mcgrps = &ovs_dp_vport_multicast_group, |
|---|
| 2295 | 2448 | .n_mcgrps = 1, |
|---|
| 2296 | 2449 | .module = THIS_MODULE, |
|---|
| .. | .. |
|---|
| 2337 | 2490 | static int __net_init ovs_init_net(struct net *net) |
|---|
| 2338 | 2491 | { |
|---|
| 2339 | 2492 | struct ovs_net *ovs_net = net_generic(net, ovs_net_id); |
|---|
| 2493 | + int err; |
|---|
| 2340 | 2494 | |
|---|
| 2341 | 2495 | INIT_LIST_HEAD(&ovs_net->dps); |
|---|
| 2342 | 2496 | INIT_WORK(&ovs_net->dp_notify_work, ovs_dp_notify_wq); |
|---|
| 2343 | | - return ovs_ct_init(net); |
|---|
| 2497 | + INIT_DELAYED_WORK(&ovs_net->masks_rebalance, ovs_dp_masks_rebalance); |
|---|
| 2498 | + |
|---|
| 2499 | + err = ovs_ct_init(net); |
|---|
| 2500 | + if (err) |
|---|
| 2501 | + return err; |
|---|
| 2502 | + |
|---|
| 2503 | + schedule_delayed_work(&ovs_net->masks_rebalance, |
|---|
| 2504 | + msecs_to_jiffies(DP_MASKS_REBALANCE_INTERVAL)); |
|---|
| 2505 | + return 0; |
|---|
| 2344 | 2506 | } |
|---|
| 2345 | 2507 | |
|---|
| 2346 | 2508 | static void __net_exit list_vports_from_net(struct net *net, struct net *dnet, |
|---|
| .. | .. |
|---|
| 2374 | 2536 | struct net *net; |
|---|
| 2375 | 2537 | LIST_HEAD(head); |
|---|
| 2376 | 2538 | |
|---|
| 2377 | | - ovs_ct_exit(dnet); |
|---|
| 2378 | 2539 | ovs_lock(); |
|---|
| 2540 | + |
|---|
| 2541 | + ovs_ct_exit(dnet); |
|---|
| 2542 | + |
|---|
| 2379 | 2543 | list_for_each_entry_safe(dp, dp_next, &ovs_net->dps, list_node) |
|---|
| 2380 | 2544 | __dp_destroy(dp); |
|---|
| 2381 | 2545 | |
|---|
| .. | .. |
|---|
| 2392 | 2556 | |
|---|
| 2393 | 2557 | ovs_unlock(); |
|---|
| 2394 | 2558 | |
|---|
| 2559 | + cancel_delayed_work_sync(&ovs_net->masks_rebalance); |
|---|
| 2395 | 2560 | cancel_work_sync(&ovs_net->dp_notify_work); |
|---|
| 2396 | 2561 | } |
|---|
| 2397 | 2562 | |
|---|
| .. | .. |
|---|
| 2406 | 2571 | { |
|---|
| 2407 | 2572 | int err; |
|---|
| 2408 | 2573 | |
|---|
| 2409 | | - BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > FIELD_SIZEOF(struct sk_buff, cb)); |
|---|
| 2574 | + BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > |
|---|
| 2575 | + sizeof_field(struct sk_buff, cb)); |
|---|
| 2410 | 2576 | |
|---|
| 2411 | 2577 | pr_info("Open vSwitch switching datapath\n"); |
|---|
| 2412 | 2578 | |
|---|