datapath: Move table destroy to dp-rcu callback.
[sliver-openvswitch.git] / datapath / datapath.c
index 6dfe69d..fcaafd1 100644 (file)
@@ -135,7 +135,6 @@ int lockdep_ovsl_is_held(void)
 }
 #endif
 
-static struct vport *new_vport(const struct vport_parms *);
 static int queue_gso_packets(struct datapath *dp, struct sk_buff *,
                             const struct dp_upcall_info *);
 static int queue_userspace_packet(struct datapath *dp, struct sk_buff *,
@@ -188,6 +187,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,33 +240,25 @@ void ovs_dp_detach_port(struct vport *p)
        ovs_vport_del(p);
 }
 
-/* Must be called with rcu_read_lock. */
-void ovs_dp_process_received_packet(struct vport *p, struct sk_buff *skb)
+void ovs_dp_process_packet_with_key(struct sk_buff *skb,
+               struct sw_flow_key *pkt_key)
 {
+       const struct vport *p = OVS_CB(skb)->input_vport;
        struct datapath *dp = p->dp;
        struct sw_flow *flow;
        struct dp_stats_percpu *stats;
-       struct sw_flow_key key;
        u64 *stats_counter;
        u32 n_mask_hit;
-       int error;
 
        stats = this_cpu_ptr(dp->stats_percpu);
 
-       /* Extract flow from 'skb' into 'key'. */
-       error = ovs_flow_extract(skb, p->port_no, &key);
-       if (unlikely(error)) {
-               kfree_skb(skb);
-               return;
-       }
-
        /* Look up flow. */
-       flow = ovs_flow_tbl_lookup_stats(&dp->table, &key, &n_mask_hit);
+       flow = ovs_flow_tbl_lookup_stats(&dp->table, pkt_key, &n_mask_hit);
        if (unlikely(!flow)) {
                struct dp_upcall_info upcall;
 
                upcall.cmd = OVS_PACKET_CMD_MISS;
-               upcall.key = &key;
+               upcall.key = pkt_key;
                upcall.userdata = NULL;
                upcall.portid = ovs_vport_find_upcall_portid(p, skb);
                ovs_dp_upcall(dp, skb, &upcall);
@@ -275,10 +267,10 @@ void ovs_dp_process_received_packet(struct vport *p, struct sk_buff *skb)
                goto out;
        }
 
+       OVS_CB(skb)->pkt_key = pkt_key;
        OVS_CB(skb)->flow = flow;
-       OVS_CB(skb)->pkt_key = &key;
 
-       ovs_flow_stats_update(OVS_CB(skb)->flow, key.tp.flags, skb);
+       ovs_flow_stats_update(OVS_CB(skb)->flow, pkt_key->tp.flags, skb);
        ovs_execute_actions(dp, skb);
        stats_counter = &stats->n_hit;
 
@@ -290,6 +282,24 @@ out:
        u64_stats_update_end(&stats->sync);
 }
 
+/* Must be called with rcu_read_lock. */
+void ovs_dp_process_received_packet(struct vport *p, 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);
+       if (unlikely(error)) {
+               kfree_skb(skb);
+               return;
+       }
+
+       ovs_dp_process_packet_with_key(skb, &key);
+}
+
 int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
                  const struct dp_upcall_info *upcall_info)
 {
@@ -516,6 +526,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
        struct sw_flow *flow;
        struct datapath *dp;
        struct ethhdr *eth;
+       struct vport *input_vport;
        int len;
        int err;
 
@@ -579,6 +590,15 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
        if (!dp)
                goto err_unlock;
 
+       input_vport = ovs_vport_rcu(dp, flow->key.phy.in_port);
+       if (!input_vport)
+               input_vport = ovs_vport_rcu(dp, OVSP_LOCAL);
+
+       if (!input_vport)
+               goto err_unlock;
+
+       OVS_CB(packet)->input_vport = input_vport;
+
        local_bh_disable();
        err = ovs_execute_actions(dp, packet);
        local_bh_enable();
@@ -1428,7 +1448,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);
@@ -1460,8 +1480,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);
 }