datapath: Use per_cpu_ptr instead of percpu_ptr.
[openvswitch] / datapath / datapath.c
index 837f567caf929a945511199c9af467c0295a3fb0..1d007b04b083f5a6ee9ad1032d3733ef7ac5e66d 100644 (file)
@@ -512,11 +512,12 @@ out:
        return err;
 }
 
-/* Must be called with rcu_read_lock and with bottom-halves disabled. */
+/* Must be called with rcu_read_lock. */
 void dp_process_received_packet(struct dp_port *p, struct sk_buff *skb)
 {
        struct datapath *dp = p->dp;
        struct dp_stats_percpu *stats;
+       int stats_counter_off;
        struct odp_flow_key key;
        struct tbl_node *flow_node;
 
@@ -525,14 +526,11 @@ void dp_process_received_packet(struct dp_port *p, struct sk_buff *skb)
 
        OVS_CB(skb)->dp_port = p;
 
-       /* BHs are off so we don't have to use get_cpu()/put_cpu() here. */
-       stats = percpu_ptr(dp->stats_percpu, smp_processor_id());
-
        if (flow_extract(skb, p ? p->port_no : ODPP_NONE, &key)) {
                if (dp->drop_frags) {
                        kfree_skb(skb);
-                       stats->n_frags++;
-                       return;
+                       stats_counter_off = offsetof(struct dp_stats_percpu, n_frags);
+                       goto out;
                }
        }
 
@@ -543,11 +541,17 @@ void dp_process_received_packet(struct dp_port *p, struct sk_buff *skb)
                flow_used(flow, skb);
                execute_actions(dp, skb, &key, acts->actions, acts->n_actions,
                                GFP_ATOMIC);
-               stats->n_hit++;
+               stats_counter_off = offsetof(struct dp_stats_percpu, n_hit);
        } else {
-               stats->n_missed++;
+               stats_counter_off = offsetof(struct dp_stats_percpu, n_missed);
                dp_output_control(dp, skb, _ODPL_MISS_NR, OVS_CB(skb)->tun_id);
        }
+
+out:
+       local_bh_disable();
+       stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
+       (*(u64 *)((u8 *)stats + stats_counter_off))++;
+       local_bh_enable();
 }
 
 #if defined(CONFIG_XEN) && defined(HAVE_PROTO_DATA_VALID)
@@ -830,9 +834,10 @@ dp_output_control(struct datapath *dp, struct sk_buff *skb, int queue_no,
 err_kfree_skb:
        kfree_skb(skb);
 err:
-       stats = percpu_ptr(dp->stats_percpu, get_cpu());
+       local_bh_disable();
+       stats = per_cpu_ptr(dp->stats_percpu, smp_processor_id());
        stats->n_lost++;
-       put_cpu();
+       local_bh_enable();
 
        return err;
 }
@@ -1015,7 +1020,6 @@ static int do_put_flow(struct datapath *dp, struct odp_flow_put *uf,
        } else {
                /* We found a matching flow. */
                struct sw_flow_actions *old_acts, *new_acts;
-               unsigned long int flags;
 
                flow = flow_cast(flow_node);
 
@@ -1040,11 +1044,11 @@ static int do_put_flow(struct datapath *dp, struct odp_flow_put *uf,
                }
 
                /* Fetch stats, then clear them if necessary. */
-               spin_lock_irqsave(&flow->lock, flags);
+               spin_lock_bh(&flow->lock);
                get_stats(flow, stats);
                if (uf->flags & ODPPF_ZERO_STATS)
                        clear_stats(flow);
-               spin_unlock_irqrestore(&flow->lock, flags);
+               spin_unlock_bh(&flow->lock);
        }
 
        return 0;
@@ -1084,15 +1088,14 @@ static int do_answer_query(struct sw_flow *flow, u32 query_flags,
 {
        struct sw_flow_actions *sf_acts;
        struct odp_flow_stats stats;
-       unsigned long int flags;
        u32 n_actions;
 
-       spin_lock_irqsave(&flow->lock, flags);
+       spin_lock_bh(&flow->lock);
        get_stats(flow, &stats);
-       if (query_flags & ODPFF_ZERO_TCP_FLAGS) {
+       if (query_flags & ODPFF_ZERO_TCP_FLAGS)
                flow->tcp_flags = 0;
-       }
-       spin_unlock_irqrestore(&flow->lock, flags);
+
+       spin_unlock_bh(&flow->lock);
 
        if (copy_to_user(ustats, &stats, sizeof(struct odp_flow_stats)) ||
            get_user(n_actions, n_actionsp))
@@ -1302,8 +1305,12 @@ static int do_execute(struct datapath *dp, const struct odp_execute *execute)
                skb->protocol = htons(ETH_P_802_2);
 
        flow_extract(skb, execute->in_port, &key);
+
+       rcu_read_lock();
        err = execute_actions(dp, skb, &key, actions->actions,
                              actions->n_actions, GFP_KERNEL);
+       rcu_read_unlock();
+
        kfree(actions);
        return err;
 
@@ -1340,7 +1347,7 @@ static int get_dp_stats(struct datapath *dp, struct odp_stats __user *statsp)
        stats.n_frags = stats.n_hit = stats.n_missed = stats.n_lost = 0;
        for_each_possible_cpu(i) {
                const struct dp_stats_percpu *s;
-               s = percpu_ptr(dp->stats_percpu, i);
+               s = per_cpu_ptr(dp->stats_percpu, i);
                stats.n_frags += s->n_frags;
                stats.n_hit += s->n_hit;
                stats.n_missed += s->n_missed;