datapath: Remove redundant key ref from upcall_info.
[cascardo/ovs.git] / datapath / datapath.c
index aa4c109..1185f60 100644 (file)
@@ -140,19 +140,29 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *,
 static int queue_userspace_packet(struct datapath *dp, struct sk_buff *,
                                  const struct dp_upcall_info *);
 
-/* Must be called with rcu_read_lock or ovs_mutex. */
-static struct datapath *get_dp(struct net *net, int dp_ifindex)
+/* Must be called with rcu_read_lock. */
+static struct datapath *get_dp_rcu(struct net *net, int dp_ifindex)
 {
-       struct datapath *dp = NULL;
-       struct net_device *dev;
+       struct net_device *dev = dev_get_by_index_rcu(net, dp_ifindex);
 
-       rcu_read_lock();
-       dev = dev_get_by_index_rcu(net, dp_ifindex);
        if (dev) {
                struct vport *vport = ovs_internal_dev_get_vport(dev);
                if (vport)
-                       dp = vport->dp;
+                       return vport->dp;
        }
+
+       return NULL;
+}
+
+/* The caller must hold either ovs_mutex or rcu_read_lock to keep the
+ * returned dp pointer valid. */
+static inline struct datapath *get_dp(struct net *net, int dp_ifindex)
+{
+       struct datapath *dp;
+
+       WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_ovsl_is_held());
+       rcu_read_lock();
+       dp = get_dp_rcu(net, dp_ifindex);
        rcu_read_unlock();
 
        return dp;
@@ -187,6 +197,7 @@ static void destroy_dp_rcu(struct rcu_head *rcu)
 {
        struct datapath *dp = container_of(rcu, struct datapath, rcu);
 
+       ovs_flow_tbl_destroy(&dp->table);
        free_percpu(dp->stats_percpu);
        release_net(ovs_dp_get_net(dp));
        kfree(dp->ports);
@@ -240,7 +251,8 @@ void ovs_dp_detach_port(struct vport *p)
 }
 
 void ovs_dp_process_packet_with_key(struct sk_buff *skb,
-               struct sw_flow_key *pkt_key)
+                                   struct sw_flow_key *pkt_key,
+                                   bool recirc)
 {
        const struct vport *p = OVS_CB(skb)->input_vport;
        struct datapath *dp = p->dp;
@@ -250,14 +262,15 @@ void ovs_dp_process_packet_with_key(struct sk_buff *skb,
        u32 n_mask_hit;
 
        stats = this_cpu_ptr(dp->stats_percpu);
+       OVS_CB(skb)->pkt_key = pkt_key;
 
        /* Look up flow. */
-       flow = ovs_flow_tbl_lookup_stats(&dp->table, pkt_key, &n_mask_hit);
+       flow = ovs_flow_tbl_lookup_stats(&dp->table, pkt_key, skb_get_hash(skb),
+                                        &n_mask_hit);
        if (unlikely(!flow)) {
                struct dp_upcall_info upcall;
 
                upcall.cmd = OVS_PACKET_CMD_MISS;
-               upcall.key = pkt_key;
                upcall.userdata = NULL;
                upcall.portid = ovs_vport_find_upcall_portid(p, skb);
                ovs_dp_upcall(dp, skb, &upcall);
@@ -266,11 +279,10 @@ void ovs_dp_process_packet_with_key(struct sk_buff *skb,
                goto out;
        }
 
-       OVS_CB(skb)->pkt_key = pkt_key;
        OVS_CB(skb)->flow = flow;
 
        ovs_flow_stats_update(OVS_CB(skb)->flow, pkt_key->tp.flags, skb);
-       ovs_execute_actions(dp, skb);
+       ovs_execute_actions(dp, skb, recirc);
        stats_counter = &stats->n_hit;
 
 out:
@@ -282,21 +294,19 @@ out:
 }
 
 /* Must be called with rcu_read_lock. */
-void ovs_dp_process_received_packet(struct vport *p, struct sk_buff *skb)
+void ovs_dp_process_received_packet(struct sk_buff *skb)
 {
        int error;
        struct sw_flow_key key;
 
-       OVS_CB(skb)->input_vport = p;
-
        /* Extract flow from 'skb' into 'key'. */
-       error = ovs_flow_extract(skb, p->port_no, &key);
+       error = ovs_flow_extract(skb, OVS_CB(skb)->input_vport->port_no, &key);
        if (unlikely(error)) {
                kfree_skb(skb);
                return;
        }
 
-       ovs_dp_process_packet_with_key(skb, &key);
+       ovs_dp_process_packet_with_key(skb, &key, false);
 }
 
 int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
@@ -305,6 +315,8 @@ int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
        struct dp_stats_percpu *stats;
        int err;
 
+       BUG_ON(!OVS_CB(skb)->pkt_key);
+
        if (upcall_info->portid == 0) {
                err = -ENOTCONN;
                goto err;
@@ -333,7 +345,6 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
                             const struct dp_upcall_info *upcall_info)
 {
        unsigned short gso_type = skb_shinfo(skb)->gso_type;
-       struct dp_upcall_info later_info;
        struct sw_flow_key later_key;
        struct sk_buff *segs, *nskb;
        int err;
@@ -342,25 +353,25 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
        if (IS_ERR(segs))
                return PTR_ERR(segs);
 
+       if (gso_type & SKB_GSO_UDP) {
+               /* The initial flow key extracted by ovs_flow_extract()
+                * in this case is for a first fragment, so we need to
+                * properly mark later fragments.
+                */
+               later_key = *OVS_CB(skb)->pkt_key;
+               later_key.ip.frag = OVS_FRAG_TYPE_LATER;
+       }
+
        /* Queue all of the segments. */
        skb = segs;
        do {
+               if (gso_type & SKB_GSO_UDP && skb != segs)
+                       OVS_CB(skb)->pkt_key = &later_key;
+
                err = queue_userspace_packet(dp, skb, upcall_info);
                if (err)
                        break;
 
-               if (skb == segs && gso_type & SKB_GSO_UDP) {
-                       /* The initial flow key extracted by ovs_flow_extract()
-                        * in this case is for a first fragment, so we need to
-                        * properly mark later fragments.
-                        */
-                       later_key = *upcall_info->key;
-                       later_key.ip.frag = OVS_FRAG_TYPE_LATER;
-
-                       later_info = *upcall_info;
-                       later_info.key = &later_key;
-                       upcall_info = &later_info;
-               }
        } while ((skb = skb->next));
 
        /* Free all of the segments. */
@@ -377,6 +388,10 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
 
 static size_t key_attr_size(void)
 {
+       /* Whenever adding new OVS_KEY_ FIELDS, we should consider
+        * updating this function.  */
+       BUILD_BUG_ON(OVS_KEY_ATTR_TUNNEL_INFO != 22);
+
        return    nla_total_size(4)   /* OVS_KEY_ATTR_PRIORITY */
                + nla_total_size(0)   /* OVS_KEY_ATTR_TUNNEL */
                  + nla_total_size(8)   /* OVS_TUNNEL_KEY_ATTR_ID */
@@ -386,8 +401,12 @@ static size_t key_attr_size(void)
                  + nla_total_size(1)   /* OVS_TUNNEL_KEY_ATTR_TTL */
                  + nla_total_size(0)   /* OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT */
                  + nla_total_size(0)   /* OVS_TUNNEL_KEY_ATTR_CSUM */
+                 + nla_total_size(0)   /* OVS_TUNNEL_KEY_ATTR_OAM */
+                 + nla_total_size(256) /* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS */
                + nla_total_size(4)   /* OVS_KEY_ATTR_IN_PORT */
                + nla_total_size(4)   /* OVS_KEY_ATTR_SKB_MARK */
+               + nla_total_size(4)   /* OVS_KEY_ATTR_DP_HASH */
+               + nla_total_size(4)   /* OVS_KEY_ATTR_RECIRC_ID */
                + nla_total_size(12)  /* OVS_KEY_ATTR_ETHERNET */
                + nla_total_size(2)   /* OVS_KEY_ATTR_ETHERTYPE */
                + nla_total_size(4)   /* OVS_KEY_ATTR_8021Q */
@@ -418,6 +437,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
        struct ovs_header *upcall;
        struct sk_buff *nskb = NULL;
        struct sk_buff *user_skb; /* to be queued to userspace */
+       struct sw_flow_key *pkt_key = OVS_CB(skb)->pkt_key;
        struct nlattr *nla;
        struct genl_info info = {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
@@ -478,7 +498,8 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
        upcall->dp_ifindex = dp_ifindex;
 
        nla = nla_nest_start(user_skb, OVS_PACKET_ATTR_KEY);
-       ovs_nla_put_flow(upcall_info->key, upcall_info->key, user_skb);
+       err = ovs_nla_put_flow(dp, pkt_key, pkt_key, user_skb);
+       BUG_ON(err);
        nla_nest_end(user_skb, nla);
 
        if (upcall_info->userdata)
@@ -573,7 +594,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
                goto err_flow_free;
 
        err = ovs_nla_copy_actions(a[OVS_PACKET_ATTR_ACTIONS],
-                                  &flow->key, 0, &acts);
+                                  &flow->key, &acts);
        rcu_assign_pointer(flow->sf_acts, acts);
        if (err)
                goto err_flow_free;
@@ -584,7 +605,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
        packet->mark = flow->key.phy.skb_mark;
 
        rcu_read_lock();
-       dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
+       dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex);
        err = -ENODEV;
        if (!dp)
                goto err_unlock;
@@ -599,7 +620,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
        OVS_CB(packet)->input_vport = input_vport;
 
        local_bh_disable();
-       err = ovs_execute_actions(dp, packet);
+       err = ovs_execute_actions(dp, packet, false);
        local_bh_enable();
        rcu_read_unlock();
 
@@ -662,9 +683,9 @@ static void get_dp_stats(struct datapath *dp, struct ovs_dp_stats *stats,
                percpu_stats = per_cpu_ptr(dp->stats_percpu, i);
 
                do {
-                       start = u64_stats_fetch_begin_bh(&percpu_stats->sync);
+                       start = u64_stats_fetch_begin_irq(&percpu_stats->sync);
                        local_stats = *percpu_stats;
-               } while (u64_stats_fetch_retry_bh(&percpu_stats->sync, start));
+               } while (u64_stats_fetch_retry_irq(&percpu_stats->sync, start));
 
                stats->n_hit += local_stats.n_hit;
                stats->n_missed += local_stats.n_missed;
@@ -685,58 +706,68 @@ static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts)
 }
 
 /* Called with ovs_mutex or RCU read lock. */
-static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex,
-                                 struct sk_buff *skb, u32 portid,
-                                 u32 seq, u32 flags, u8 cmd)
+static int ovs_flow_cmd_fill_match(struct datapath *dp,
+                                  const struct sw_flow *flow,
+                                  struct sk_buff *skb)
 {
-       const int skb_orig_len = skb->len;
-       struct nlattr *start;
-       struct ovs_flow_stats stats;
-       __be16 tcp_flags;
-       unsigned long used;
-       struct ovs_header *ovs_header;
        struct nlattr *nla;
        int err;
 
-       ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family, flags, cmd);
-       if (!ovs_header)
-               return -EMSGSIZE;
-
-       ovs_header->dp_ifindex = dp_ifindex;
-
        /* Fill flow key. */
        nla = nla_nest_start(skb, OVS_FLOW_ATTR_KEY);
        if (!nla)
-               goto nla_put_failure;
+               return -EMSGSIZE;
 
-       err = ovs_nla_put_flow(&flow->unmasked_key, &flow->unmasked_key, skb);
+       err = ovs_nla_put_flow(dp, &flow->unmasked_key,
+                              &flow->unmasked_key, skb);
        if (err)
-               goto error;
+               return err;
        nla_nest_end(skb, nla);
 
+       /* Fill flow mask. */
        nla = nla_nest_start(skb, OVS_FLOW_ATTR_MASK);
        if (!nla)
-               goto nla_put_failure;
+               return -EMSGSIZE;
 
-       err = ovs_nla_put_flow(&flow->key, &flow->mask->key, skb);
+       err = ovs_nla_put_flow(dp, &flow->key, &flow->mask->key, skb);
        if (err)
-               goto error;
-
+               return err;
        nla_nest_end(skb, nla);
 
+       return 0;
+}
+
+/* Called with ovs_mutex or RCU read lock. */
+static int ovs_flow_cmd_fill_stats(const struct sw_flow *flow,
+                                  struct sk_buff *skb)
+{
+       struct ovs_flow_stats stats;
+       __be16 tcp_flags;
+       unsigned long used;
+
        ovs_flow_stats_get(flow, &stats, &used, &tcp_flags);
 
        if (used &&
            nla_put_u64(skb, OVS_FLOW_ATTR_USED, ovs_flow_used_time(used)))
-               goto nla_put_failure;
+               return -EMSGSIZE;
 
        if (stats.n_packets &&
            nla_put(skb, OVS_FLOW_ATTR_STATS, sizeof(struct ovs_flow_stats), &stats))
-               goto nla_put_failure;
+               return -EMSGSIZE;
 
        if ((u8)ntohs(tcp_flags) &&
             nla_put_u8(skb, OVS_FLOW_ATTR_TCP_FLAGS, (u8)ntohs(tcp_flags)))
-               goto nla_put_failure;
+               return -EMSGSIZE;
+
+       return 0;
+}
+
+/* Called with ovs_mutex or RCU read lock. */
+static int ovs_flow_cmd_fill_actions(const struct sw_flow *flow,
+                                    struct sk_buff *skb, int skb_orig_len)
+{
+       struct nlattr *start;
+       int err;
 
        /* If OVS_FLOW_ATTR_ACTIONS doesn't fit, skip dumping the actions if
         * this is the first flow to be dumped into 'skb'.  This is unusual for
@@ -760,17 +791,46 @@ static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex,
                        nla_nest_end(skb, start);
                else {
                        if (skb_orig_len)
-                               goto error;
+                               return err;
 
                        nla_nest_cancel(skb, start);
                }
-       } else if (skb_orig_len)
-               goto nla_put_failure;
+       } else if (skb_orig_len) {
+               return -EMSGSIZE;
+       }
+
+       return 0;
+}
+
+/* Called with ovs_mutex or RCU read lock. */
+static int ovs_flow_cmd_fill_info(struct datapath *dp,
+                                 const struct sw_flow *flow, int dp_ifindex,
+                                 struct sk_buff *skb, u32 portid,
+                                 u32 seq, u32 flags, u8 cmd)
+{
+       const int skb_orig_len = skb->len;
+       struct ovs_header *ovs_header;
+       int err;
+
+       ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family, flags, cmd);
+       if (!ovs_header)
+               return -EMSGSIZE;
+       ovs_header->dp_ifindex = dp_ifindex;
+
+       err = ovs_flow_cmd_fill_match(dp, flow, skb);
+       if (err)
+               goto error;
+
+       err = ovs_flow_cmd_fill_stats(flow, skb);
+       if (err)
+               goto error;
+
+       err = ovs_flow_cmd_fill_actions(flow, skb, skb_orig_len);
+       if (err)
+               goto error;
 
        return genlmsg_end(skb, ovs_header);
 
-nla_put_failure:
-       err = -EMSGSIZE;
 error:
        genlmsg_cancel(skb, ovs_header);
        return err;
@@ -795,7 +855,8 @@ static struct sk_buff *ovs_flow_cmd_alloc_info(const struct sw_flow_actions *act
 }
 
 /* Called with ovs_mutex. */
-static struct sk_buff *ovs_flow_cmd_build_info(const struct sw_flow *flow,
+static struct sk_buff *ovs_flow_cmd_build_info(struct datapath *dp,
+                                              const struct sw_flow *flow,
                                               int dp_ifindex,
                                               struct genl_info *info, u8 cmd,
                                               bool always)
@@ -808,7 +869,7 @@ static struct sk_buff *ovs_flow_cmd_build_info(const struct sw_flow *flow,
        if (!skb || IS_ERR(skb))
                return skb;
 
-       retval = ovs_flow_cmd_fill_info(flow, dp_ifindex, skb,
+       retval = ovs_flow_cmd_fill_info(dp, flow, dp_ifindex, skb,
                                        info->snd_portid, info->snd_seq, 0,
                                        cmd);
        BUG_ON(retval < 0);
@@ -829,10 +890,14 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
 
        /* Must have key and actions. */
        error = -EINVAL;
-       if (!a[OVS_FLOW_ATTR_KEY])
+       if (!a[OVS_FLOW_ATTR_KEY]) {
+               OVS_NLERR("Flow key attribute not present in new flow.\n");
                goto error;
-       if (!a[OVS_FLOW_ATTR_ACTIONS])
+       }
+       if (!a[OVS_FLOW_ATTR_ACTIONS]) {
+               OVS_NLERR("Flow actions attribute not present in new flow.\n");
                goto error;
+       }
 
        /* Most of the time we need to allocate a new flow, do it before
         * locking. */
@@ -858,7 +923,7 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
                goto err_kfree_flow;
 
        error = ovs_nla_copy_actions(a[OVS_FLOW_ATTR_ACTIONS], &new_flow->key,
-                                    0, &acts);
+                                    &acts);
        if (error) {
                OVS_NLERR("Flow actions may not be safe on all matching packets.\n");
                goto err_kfree_acts;
@@ -889,7 +954,7 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
                }
 
                if (unlikely(reply)) {
-                       error = ovs_flow_cmd_fill_info(new_flow,
+                       error = ovs_flow_cmd_fill_info(dp, new_flow,
                                                       ovs_header->dp_ifindex,
                                                       reply, info->snd_portid,
                                                       info->snd_seq, 0,
@@ -913,15 +978,19 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
                }
                /* The unmasked key has to be the same for flow updates. */
                if (unlikely(!ovs_flow_cmp_unmasked_key(flow, &match))) {
-                       error = -EEXIST;
-                       goto err_unlock_ovs;
+                       /* Look for any overlapping flow. */
+                       flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
+                       if (!flow) {
+                               error = -ENOENT;
+                               goto err_unlock_ovs;
+                       }
                }
                /* Update actions. */
                old_acts = ovsl_dereference(flow->sf_acts);
                rcu_assign_pointer(flow->sf_acts, acts);
 
                if (unlikely(reply)) {
-                       error = ovs_flow_cmd_fill_info(flow,
+                       error = ovs_flow_cmd_fill_info(dp, flow,
                                                       ovs_header->dp_ifindex,
                                                       reply, info->snd_portid,
                                                       info->snd_seq, 0,
@@ -949,11 +1018,34 @@ error:
        return error;
 }
 
+static struct sw_flow_actions *get_flow_actions(const struct nlattr *a,
+                                               const struct sw_flow_key *key,
+                                               const struct sw_flow_mask *mask)
+{
+       struct sw_flow_actions *acts;
+       struct sw_flow_key masked_key;
+       int error;
+
+       acts = ovs_nla_alloc_flow_actions(nla_len(a));
+       if (IS_ERR(acts))
+               return acts;
+
+       ovs_flow_mask_key(&masked_key, key, mask);
+       error = ovs_nla_copy_actions(a, &masked_key, &acts);
+       if (error) {
+               OVS_NLERR("Flow actions may not be safe on all matching packets.\n");
+               kfree(acts);
+               return ERR_PTR(error);
+       }
+
+       return acts;
+}
+
 static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
 {
        struct nlattr **a = info->attrs;
        struct ovs_header *ovs_header = info->userhdr;
-       struct sw_flow_key key, masked_key;
+       struct sw_flow_key key;
        struct sw_flow *flow;
        struct sw_flow_mask mask;
        struct sk_buff *reply = NULL;
@@ -964,8 +1056,10 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
 
        /* Extract key. */
        error = -EINVAL;
-       if (!a[OVS_FLOW_ATTR_KEY])
+       if (!a[OVS_FLOW_ATTR_KEY]) {
+               OVS_NLERR("Flow key attribute not present in set flow.\n");
                goto error;
+       }
 
        ovs_match_init(&match, &key, &mask);
        error = ovs_nla_get_match(&match,
@@ -975,17 +1069,10 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
 
        /* Validate actions. */
        if (a[OVS_FLOW_ATTR_ACTIONS]) {
-               acts = ovs_nla_alloc_flow_actions(nla_len(a[OVS_FLOW_ATTR_ACTIONS]));
-               error = PTR_ERR(acts);
-               if (IS_ERR(acts))
+               acts = get_flow_actions(a[OVS_FLOW_ATTR_ACTIONS], &key, &mask);
+               if (IS_ERR(acts)) {
+                       error = PTR_ERR(acts);
                        goto error;
-
-               ovs_flow_mask_key(&masked_key, &key, &mask);
-               error = ovs_nla_copy_actions(a[OVS_FLOW_ATTR_ACTIONS],
-                                            &masked_key, 0, &acts);
-               if (error) {
-                       OVS_NLERR("Flow actions may not be safe on all matching packets.\n");
-                       goto err_kfree_acts;
                }
        }
 
@@ -1005,23 +1092,19 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
                goto err_unlock_ovs;
        }
        /* Check that the flow exists. */
-       flow = ovs_flow_tbl_lookup(&dp->table, &key);
+       flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
        if (unlikely(!flow)) {
                error = -ENOENT;
                goto err_unlock_ovs;
        }
-       /* The unmasked key has to be the same for flow updates. */
-       if (unlikely(!ovs_flow_cmp_unmasked_key(flow, &match))) {
-               error = -EEXIST;
-               goto err_unlock_ovs;
-       }
+
        /* Update actions, if present. */
        if (likely(acts)) {
                old_acts = ovsl_dereference(flow->sf_acts);
                rcu_assign_pointer(flow->sf_acts, acts);
 
                if (unlikely(reply)) {
-                       error = ovs_flow_cmd_fill_info(flow,
+                       error = ovs_flow_cmd_fill_info(dp, flow,
                                                       ovs_header->dp_ifindex,
                                                       reply, info->snd_portid,
                                                       info->snd_seq, 0,
@@ -1030,7 +1113,8 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
                }
        } else {
                /* Could not alloc without acts before locking. */
-               reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex,
+               reply = ovs_flow_cmd_build_info(dp, flow,
+                                               ovs_header->dp_ifindex,
                                                info, OVS_FLOW_CMD_NEW, false);
                if (unlikely(IS_ERR(reply))) {
                        error = PTR_ERR(reply);
@@ -1086,13 +1170,13 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info)
                goto unlock;
        }
 
-       flow = ovs_flow_tbl_lookup(&dp->table, &key);
-       if (!flow || !ovs_flow_cmp_unmasked_key(flow, &match)) {
+       flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
+       if (!flow) {
                err = -ENOENT;
                goto unlock;
        }
 
-       reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex, info,
+       reply = ovs_flow_cmd_build_info(dp, flow, ovs_header->dp_ifindex, info,
                                        OVS_FLOW_CMD_NEW, true);
        if (IS_ERR(reply)) {
                err = PTR_ERR(reply);
@@ -1134,8 +1218,8 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
                err = ovs_flow_tbl_flush(&dp->table);
                goto unlock;
        }
-       flow = ovs_flow_tbl_lookup(&dp->table, &key);
-       if (unlikely(!flow || !ovs_flow_cmp_unmasked_key(flow, &match))) {
+       flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
+       if (unlikely(!flow)) {
                err = -ENOENT;
                goto unlock;
        }
@@ -1149,7 +1233,7 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
        if (likely(reply)) {
                if (likely(!IS_ERR(reply))) {
                        rcu_read_lock(); /* Keep RCU checker happy. */
-                       err = ovs_flow_cmd_fill_info(flow,
+                       err = ovs_flow_cmd_fill_info(dp, flow,
                                                     ovs_header->dp_ifindex,
                                                     reply, info->snd_portid,
                                                     info->snd_seq, 0,
@@ -1178,7 +1262,7 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
        struct datapath *dp;
 
        rcu_read_lock();
-       dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
+       dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex);
        if (!dp) {
                rcu_read_unlock();
                return -ENODEV;
@@ -1195,7 +1279,7 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
                if (!flow)
                        break;
 
-               if (ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex, skb,
+               if (ovs_flow_cmd_fill_info(dp, flow, ovs_header->dp_ifindex, skb,
                                           NETLINK_CB(cb->skb).portid,
                                           cb->nlh->nlmsg_seq, NLM_F_MULTI,
                                           OVS_FLOW_CMD_NEW) < 0)
@@ -1447,7 +1531,7 @@ err_destroy_ports_array:
 err_destroy_percpu:
        free_percpu(dp->stats_percpu);
 err_destroy_table:
-       ovs_flow_tbl_destroy(&dp->table, false);
+       ovs_flow_tbl_destroy(&dp->table);
 err_free_dp:
        release_net(ovs_dp_get_net(dp));
        kfree(dp);
@@ -1479,8 +1563,6 @@ static void __dp_destroy(struct datapath *dp)
        ovs_dp_detach_port(ovs_vport_ovsl(dp, OVSP_LOCAL));
 
        /* RCU destroy the flow table */
-       ovs_flow_tbl_destroy(&dp->table, true);
-
        call_rcu(&dp->rcu, destroy_dp_rcu);
 }
 
@@ -1947,7 +2029,7 @@ static int ovs_vport_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
        int i, j = 0;
 
        rcu_read_lock();
-       dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex);
+       dp = get_dp_rcu(sock_net(skb->sk), ovs_header->dp_ifindex);
        if (!dp) {
                rcu_read_unlock();
                return -ENODEV;