datapath: fix coding style.
[cascardo/ovs.git] / datapath / datapath.c
index 3e5ff72..3607170 100644 (file)
@@ -79,12 +79,14 @@ struct genl_multicast_group ovs_dp_vport_multicast_group = {
 };
 
 /* Check if need to build a reply message.
- * OVS userspace sets the NLM_F_ECHO flag if it needs the reply. */
-static bool ovs_must_notify(struct genl_info *info,
-                           const struct genl_multicast_group *grp)
+ * OVS userspace sets the NLM_F_ECHO flag if it needs the reply.
+ */
+static bool ovs_must_notify(struct genl_family *family, struct genl_info *info,
+                           unsigned int group)
 {
        return info->nlhdr->nlmsg_flags & NLM_F_ECHO ||
-               netlink_has_listeners(genl_info_net(info)->genl_sock, GROUP_ID(grp));
+              genl_has_listeners(family, genl_info_net(info)->genl_sock,
+                                 group);
 }
 
 static void ovs_notify(struct genl_family *family, struct genl_multicast_group *grp,
@@ -134,8 +136,10 @@ int lockdep_ovsl_is_held(void)
 #endif
 
 static int queue_gso_packets(struct datapath *dp, struct sk_buff *,
+                            const struct sw_flow_key *,
                             const struct dp_upcall_info *);
 static int queue_userspace_packet(struct datapath *dp, struct sk_buff *,
+                                 const struct sw_flow_key *,
                                  const struct dp_upcall_info *);
 
 /* Must be called with rcu_read_lock. */
@@ -153,7 +157,8 @@ static struct datapath *get_dp_rcu(struct net *net, int dp_ifindex)
 }
 
 /* The caller must hold either ovs_mutex or rcu_read_lock to keep the
- * returned dp pointer valid. */
+ * returned dp pointer valid.
+ */
 static inline struct datapath *get_dp(struct net *net, int dp_ifindex)
 {
        struct datapath *dp;
@@ -173,7 +178,7 @@ const char *ovs_dp_name(const struct datapath *dp)
        return vport->ops->get_name(vport);
 }
 
-static int get_dpifindex(struct datapath *dp)
+static int get_dpifindex(const struct datapath *dp)
 {
        struct vport *local;
        int ifindex;
@@ -249,10 +254,9 @@ void ovs_dp_detach_port(struct vport *p)
 }
 
 /* Must be called with rcu_read_lock. */
-void ovs_dp_process_packet(struct sk_buff *skb)
+void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key)
 {
        const struct vport *p = OVS_CB(skb)->input_vport;
-       struct sw_flow_key *pkt_key = OVS_CB(skb)->pkt_key;
        struct datapath *dp = p->dp;
        struct sw_flow *flow;
        struct sw_flow_actions *sf_acts;
@@ -263,7 +267,7 @@ void ovs_dp_process_packet(struct sk_buff *skb)
        stats = this_cpu_ptr(dp->stats_percpu);
 
        /* Look up flow. */
-       flow = ovs_flow_tbl_lookup_stats(&dp->table, pkt_key, skb_get_hash(skb),
+       flow = ovs_flow_tbl_lookup_stats(&dp->table, key, skb_get_hash(skb),
                                         &n_mask_hit);
        if (unlikely(!flow)) {
                struct dp_upcall_info upcall;
@@ -273,21 +277,19 @@ void ovs_dp_process_packet(struct sk_buff *skb)
                upcall.userdata = NULL;
                upcall.portid = ovs_vport_find_upcall_portid(p, skb);
                upcall.egress_tun_info = NULL;
-
-               error = ovs_dp_upcall(dp, skb, &upcall);
+               error = ovs_dp_upcall(dp, skb, key, &upcall);
                if (unlikely(error))
                        kfree_skb(skb);
                else
                        consume_skb(skb);
-
                stats_counter = &stats->n_missed;
                goto out;
        }
 
-       ovs_flow_stats_update(flow, pkt_key->tp.flags, skb);
-
+       ovs_flow_stats_update(flow, key->tp.flags, skb);
        sf_acts = rcu_dereference(flow->sf_acts);
-       ovs_execute_actions(dp, skb, sf_acts);
+       ovs_execute_actions(dp, skb, sf_acts, key);
+
        stats_counter = &stats->n_hit;
 
 out:
@@ -299,22 +301,21 @@ out:
 }
 
 int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb,
+                 const struct sw_flow_key *key,
                  const struct dp_upcall_info *upcall_info)
 {
        struct dp_stats_percpu *stats;
        int err;
 
-       BUG_ON(!OVS_CB(skb)->pkt_key);
-
        if (upcall_info->portid == 0) {
                err = -ENOTCONN;
                goto err;
        }
 
        if (!skb_is_gso(skb))
-               err = queue_userspace_packet(dp, skb, upcall_info);
+               err = queue_userspace_packet(dp, skb, key, upcall_info);
        else
-               err = queue_gso_packets(dp, skb, upcall_info);
+               err = queue_gso_packets(dp, skb, key, upcall_info);
        if (err)
                goto err;
 
@@ -331,33 +332,40 @@ err:
 }
 
 static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,
+                            const struct sw_flow_key *key,
                             const struct dp_upcall_info *upcall_info)
 {
        unsigned short gso_type = skb_shinfo(skb)->gso_type;
        struct sw_flow_key later_key;
        struct sk_buff *segs, *nskb;
+       struct ovs_skb_cb ovs_cb;
        int err;
 
+       ovs_cb = *OVS_CB(skb);
        segs = __skb_gso_segment(skb, NETIF_F_SG, false);
+       *OVS_CB(skb) = ovs_cb;
        if (IS_ERR(segs))
                return PTR_ERR(segs);
+       if (segs == NULL)
+               return -EINVAL;
 
        if (gso_type & SKB_GSO_UDP) {
                /* The initial flow key extracted by ovs_flow_key_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 = *key;
                later_key.ip.frag = OVS_FRAG_TYPE_LATER;
        }
 
        /* Queue all of the segments. */
        skb = segs;
        do {
+               *OVS_CB(skb) = ovs_cb;
                if (gso_type & SKB_GSO_UDP && skb != segs)
-                       OVS_CB(skb)->pkt_key = &later_key;
+                       key = &later_key;
 
-               err = queue_userspace_packet(dp, skb, upcall_info);
+               err = queue_userspace_packet(dp, skb, key, upcall_info);
                if (err)
                        break;
 
@@ -394,15 +402,15 @@ static size_t upcall_msg_size(const struct dp_upcall_info *upcall_info,
 }
 
 static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
+                                 const struct sw_flow_key *key,
                                  const struct dp_upcall_info *upcall_info)
 {
        struct ovs_header *upcall;
        struct sk_buff *nskb = NULL;
        struct sk_buff *user_skb = NULL; /* 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)
+#ifdef HAVE_GENLMSG_NEW_UNICAST
                .dst_sk = ovs_dp_get_net(dp)->genl_sock,
 #endif
                .snd_portid = upcall_info->portid,
@@ -460,7 +468,7 @@ 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);
-       err = ovs_nla_put_flow(pkt_key, pkt_key, user_skb);
+       err = ovs_nla_put_flow(key, key, user_skb);
        BUG_ON(err);
        nla_nest_end(user_skb, nla);
 
@@ -478,7 +486,8 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
        }
 
        /* Only reserve room for attribute header, packet data is added
-        * in skb_zerocopy() */
+        * in skb_zerocopy()
+        */
        if (!(nla = nla_reserve(user_skb, OVS_PACKET_ATTR_PACKET, 0))) {
                err = -ENOBUFS;
                goto out;
@@ -504,7 +513,6 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
 out:
        if (err)
                skb_tx_error(skb);
-
        kfree_skb(user_skb);
        kfree_skb(nskb);
        return err;
@@ -523,6 +531,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
        struct vport *input_vport;
        int len;
        int err;
+       bool log = !a[OVS_FLOW_ATTR_PROBE];
 
        err = -EINVAL;
        if (!a[OVS_PACKET_ATTR_PACKET] || !a[OVS_PACKET_ATTR_KEY] ||
@@ -543,7 +552,8 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
 
        /* Normally, setting the skb 'protocol' field would be handled by a
         * call to eth_type_trans(), but it assumes there's a sending
-        * device, which we may not have. */
+        * device, which we may not have.
+        */
        if (ntohs(eth->h_proto) >= ETH_P_802_3_MIN)
                packet->protocol = eth->h_proto;
        else
@@ -556,17 +566,16 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
                goto err_kfree_skb;
 
        err = ovs_flow_key_extract_userspace(a[OVS_PACKET_ATTR_KEY], packet,
-                                            &flow->key);
+                                            &flow->key, log);
        if (err)
                goto err_flow_free;
 
        err = ovs_nla_copy_actions(a[OVS_PACKET_ATTR_ACTIONS],
-                                  &flow->key, &acts);
+                                  &flow->key, &acts, log);
        if (err)
                goto err_flow_free;
 
        rcu_assign_pointer(flow->sf_acts, acts);
-       OVS_CB(packet)->pkt_key = &flow->key;
        OVS_CB(packet)->egress_tun_info = NULL;
        packet->priority = flow->key.phy.priority;
        packet->mark = flow->key.phy.skb_mark;
@@ -588,7 +597,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
        sf_acts = rcu_dereference(flow->sf_acts);
 
        local_bh_disable();
-       err = ovs_execute_actions(dp, packet, sf_acts);
+       err = ovs_execute_actions(dp, packet, sf_acts, &flow->key);
        local_bh_enable();
        rcu_read_unlock();
 
@@ -631,7 +640,7 @@ static struct genl_family dp_packet_genl_family = {
        .n_ops = ARRAY_SIZE(dp_packet_genl_ops),
 };
 
-static void get_dp_stats(struct datapath *dp, struct ovs_dp_stats *stats,
+static void get_dp_stats(const struct datapath *dp, struct ovs_dp_stats *stats,
                         struct ovs_dp_megaflow_stats *mega_stats)
 {
        int i;
@@ -685,10 +694,10 @@ static int ovs_flow_cmd_fill_match(const struct sw_flow *flow,
        if (!nla)
                return -EMSGSIZE;
 
-       err = ovs_nla_put_flow(&flow->unmasked_key,
-                              &flow->unmasked_key, skb);
+       err = ovs_nla_put_flow(&flow->unmasked_key, &flow->unmasked_key, skb);
        if (err)
                return err;
+
        nla_nest_end(skb, nla);
 
        /* Fill flow mask. */
@@ -699,8 +708,8 @@ static int ovs_flow_cmd_fill_match(const struct sw_flow *flow,
        err = ovs_nla_put_flow(&flow->key, &flow->mask->key, skb);
        if (err)
                return err;
-       nla_nest_end(skb, nla);
 
+       nla_nest_end(skb, nla);
        return 0;
 }
 
@@ -778,9 +787,11 @@ static int ovs_flow_cmd_fill_info(const struct sw_flow *flow, int dp_ifindex,
        struct ovs_header *ovs_header;
        int err;
 
-       ovs_header = genlmsg_put(skb, portid, seq, &dp_flow_genl_family, flags, cmd);
+       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(flow, skb);
@@ -809,11 +820,11 @@ static struct sk_buff *ovs_flow_cmd_alloc_info(const struct sw_flow_actions *act
 {
        struct sk_buff *skb;
 
-       if (!always && !ovs_must_notify(info, &ovs_dp_flow_multicast_group))
+       if (!always && !ovs_must_notify(&dp_flow_genl_family, info,
+                                       GROUP_ID(&ovs_dp_flow_multicast_group)))
                return NULL;
 
        skb = genlmsg_new_unicast(ovs_flow_cmd_msg_size(acts), info, GFP_KERNEL);
-
        if (!skb)
                return ERR_PTR(-ENOMEM);
 
@@ -821,8 +832,7 @@ 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(struct datapath *dp,
-                                              const struct sw_flow *flow,
+static struct sk_buff *ovs_flow_cmd_build_info(const struct sw_flow *flow,
                                               int dp_ifindex,
                                               struct genl_info *info, u8 cmd,
                                               bool always)
@@ -853,20 +863,22 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
        struct sw_flow_actions *acts;
        struct sw_flow_match match;
        int error;
+       bool log = !a[OVS_FLOW_ATTR_PROBE];
 
        /* Must have key and actions. */
        error = -EINVAL;
        if (!a[OVS_FLOW_ATTR_KEY]) {
-               OVS_NLERR("Flow key attribute not present in new flow.\n");
+               OVS_NLERR(log, "Flow key attr not present in new flow.");
                goto error;
        }
        if (!a[OVS_FLOW_ATTR_ACTIONS]) {
-               OVS_NLERR("Flow actions attribute not present in new flow.\n");
+               OVS_NLERR(log, "Flow actions attr not present in new flow.");
                goto error;
        }
 
        /* Most of the time we need to allocate a new flow, do it before
-        * locking. */
+        * locking.
+        */
        new_flow = ovs_flow_alloc();
        if (IS_ERR(new_flow)) {
                error = PTR_ERR(new_flow);
@@ -875,8 +887,8 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
 
        /* Extract key. */
        ovs_match_init(&match, &new_flow->unmasked_key, &mask);
-       error = ovs_nla_get_match(&match,
-                                 a[OVS_FLOW_ATTR_KEY], a[OVS_FLOW_ATTR_MASK]);
+       error = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY],
+                                 a[OVS_FLOW_ATTR_MASK], log);
        if (error)
                goto err_kfree_flow;
 
@@ -884,10 +896,10 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
 
        /* Validate actions. */
        error = ovs_nla_copy_actions(a[OVS_FLOW_ATTR_ACTIONS], &new_flow->key,
-                                    &acts);
+                                    &acts, log);
        if (error) {
-               OVS_NLERR("Flow actions may not be safe on all matching packets.\n");
-               goto err_kfree_acts;
+               OVS_NLERR(log, "Flow actions may not be safe on all matching packets.");
+               goto err_kfree_flow;
        }
 
        reply = ovs_flow_cmd_alloc_info(acts, info, false);
@@ -982,16 +994,18 @@ error:
 /* Factor out action copy to avoid "Wframe-larger-than=1024" warning. */
 static struct sw_flow_actions *get_flow_actions(const struct nlattr *a,
                                                const struct sw_flow_key *key,
-                                               const struct sw_flow_mask *mask)
+                                               const struct sw_flow_mask *mask,
+                                               bool log)
 {
        struct sw_flow_actions *acts;
        struct sw_flow_key masked_key;
        int error;
 
        ovs_flow_mask_key(&masked_key, key, mask);
-       error = ovs_nla_copy_actions(a, &masked_key, &acts);
+       error = ovs_nla_copy_actions(a, &masked_key, &acts, log);
        if (error) {
-               OVS_NLERR("Actions may not be safe on all matching packets.\n");
+               OVS_NLERR(log,
+                         "Actions may not be safe on all matching packets");
                return ERR_PTR(error);
        }
 
@@ -1010,23 +1024,25 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
        struct sw_flow_actions *old_acts = NULL, *acts = NULL;
        struct sw_flow_match match;
        int error;
+       bool log = !a[OVS_FLOW_ATTR_PROBE];
 
        /* Extract key. */
        error = -EINVAL;
        if (!a[OVS_FLOW_ATTR_KEY]) {
-               OVS_NLERR("Flow key attribute not present in set flow.\n");
+               OVS_NLERR(log, "Flow key attribute not present in set flow.");
                goto error;
        }
 
        ovs_match_init(&match, &key, &mask);
-       error = ovs_nla_get_match(&match,
-                                 a[OVS_FLOW_ATTR_KEY], a[OVS_FLOW_ATTR_MASK]);
+       error = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY],
+                                 a[OVS_FLOW_ATTR_MASK], log);
        if (error)
                goto error;
 
        /* Validate actions. */
        if (a[OVS_FLOW_ATTR_ACTIONS]) {
-               acts = get_flow_actions(a[OVS_FLOW_ATTR_ACTIONS], &key, &mask);
+               acts = get_flow_actions(a[OVS_FLOW_ATTR_ACTIONS], &key, &mask,
+                                       log);
                if (IS_ERR(acts)) {
                        error = PTR_ERR(acts);
                        goto error;
@@ -1068,8 +1084,7 @@ 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(dp, flow,
-                                               ovs_header->dp_ifindex,
+               reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex,
                                                info, OVS_FLOW_CMD_NEW, false);
                if (unlikely(IS_ERR(reply))) {
                        error = PTR_ERR(reply);
@@ -1086,6 +1101,7 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
                ovs_notify(&dp_flow_genl_family, &ovs_dp_flow_multicast_group, reply, info);
        if (old_acts)
                ovs_nla_free_flow_actions(old_acts);
+
        return 0;
 
 err_unlock_ovs:
@@ -1107,14 +1123,16 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info)
        struct datapath *dp;
        struct sw_flow_match match;
        int err;
+       bool log = !a[OVS_FLOW_ATTR_PROBE];
 
        if (!a[OVS_FLOW_ATTR_KEY]) {
-               OVS_NLERR("Flow get message rejected, Key attribute missing.\n");
+               OVS_NLERR(log,
+                         "Flow get message rejected, Key attribute missing.");
                return -EINVAL;
        }
 
        ovs_match_init(&match, &key, NULL);
-       err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL);
+       err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL, log);
        if (err)
                return err;
 
@@ -1131,7 +1149,7 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info)
                goto unlock;
        }
 
-       reply = ovs_flow_cmd_build_info(dp, flow, ovs_header->dp_ifindex, info,
+       reply = ovs_flow_cmd_build_info(flow, ovs_header->dp_ifindex, info,
                                        OVS_FLOW_CMD_NEW, true);
        if (IS_ERR(reply)) {
                err = PTR_ERR(reply);
@@ -1155,10 +1173,12 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
        struct datapath *dp;
        struct sw_flow_match match;
        int err;
+       bool log = !a[OVS_FLOW_ATTR_PROBE];
 
        if (likely(a[OVS_FLOW_ATTR_KEY])) {
                ovs_match_init(&match, &key, NULL);
-               err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL);
+               err = ovs_nla_get_match(&match, a[OVS_FLOW_ATTR_KEY], NULL,
+                                       log);
                if (unlikely(err))
                        return err;
        }
@@ -1169,10 +1189,12 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
                err = -ENODEV;
                goto unlock;
        }
+
        if (unlikely(!a[OVS_FLOW_ATTR_KEY])) {
                err = ovs_flow_tbl_flush(&dp->table);
                goto unlock;
        }
+
        flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
        if (unlikely(!flow)) {
                err = -ENOENT;
@@ -1182,14 +1204,13 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
        ovs_flow_tbl_remove(&dp->table, flow);
        ovs_unlock();
 
-       reply = ovs_flow_cmd_alloc_info((const struct sw_flow_actions __force *)flow->sf_acts,
+       reply = ovs_flow_cmd_alloc_info(rcu_dereference_raw(flow->sf_acts),
                                        info, false);
 
        if (likely(reply)) {
                if (likely(!IS_ERR(reply))) {
-                       rcu_read_lock(); /* Keep RCU checker happy. */
-                       err = ovs_flow_cmd_fill_info(flow,
-                                                    ovs_header->dp_ifindex,
+                       rcu_read_lock();        /*To keep RCU checker happy. */
+                       err = ovs_flow_cmd_fill_info(flow, ovs_header->dp_ifindex,
                                                     reply, info->snd_portid,
                                                     info->snd_seq, 0,
                                                     OVS_FLOW_CMD_DEL);
@@ -1249,8 +1270,10 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
 
 static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = {
        [OVS_FLOW_ATTR_KEY] = { .type = NLA_NESTED },
+       [OVS_FLOW_ATTR_MASK] = { .type = NLA_NESTED },
        [OVS_FLOW_ATTR_ACTIONS] = { .type = NLA_NESTED },
        [OVS_FLOW_ATTR_CLEAR] = { .type = NLA_FLAG },
+       [OVS_FLOW_ATTR_PROBE] = { .type = NLA_FLAG },
 };
 
 static struct genl_ops dp_flow_genl_ops[] = {
@@ -1303,7 +1326,7 @@ static size_t ovs_dp_cmd_msg_size(void)
        return msgsize;
 }
 
-/* Called with ovs_mutex or RCU read lock. */
+/* Called with ovs_mutex. */
 static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
                                u32 portid, u32 seq, u32 flags, u8 cmd)
 {
@@ -1351,7 +1374,7 @@ static struct sk_buff *ovs_dp_cmd_alloc_info(struct genl_info *info)
 
 /* Called with rcu_read_lock or ovs_mutex. */
 static struct datapath *lookup_datapath(struct net *net,
-                                       struct ovs_header *ovs_header,
+                                       const struct ovs_header *ovs_header,
                                        struct nlattr *a[OVS_DP_ATTR_MAX + 1])
 {
        struct datapath *dp;
@@ -1379,7 +1402,7 @@ static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *in
        dp->user_features = 0;
 }
 
-static void ovs_dp_change(struct datapath *dp, struct nlattr **a)
+static void ovs_dp_change(struct datapath *dp, struct nlattr *a[])
 {
        if (a[OVS_DP_ATTR_USER_FEATURES])
                dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]);
@@ -1468,7 +1491,6 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
 
        ovs_net = net_generic(ovs_dp_get_net(dp), ovs_net_id);
        list_add_tail_rcu(&dp->list_node, &ovs_net->dps);
-
        ovs_unlock();
 
        ovs_notify(&dp_datapath_genl_family, &ovs_dp_datapath_multicast_group, reply, info);
@@ -1536,8 +1558,8 @@ static int ovs_dp_cmd_del(struct sk_buff *skb, struct genl_info *info)
        BUG_ON(err < 0);
 
        __dp_destroy(dp);
-
        ovs_unlock();
+
        ovs_notify(&dp_datapath_genl_family, &ovs_dp_datapath_multicast_group, reply, info);
        return 0;
 
@@ -1568,8 +1590,8 @@ static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info)
        err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
                                   info->snd_seq, 0, OVS_DP_CMD_NEW);
        BUG_ON(err < 0);
-
        ovs_unlock();
+
        ovs_notify(&dp_datapath_genl_family, &ovs_dp_datapath_multicast_group, reply, info);
        return 0;
 
@@ -1589,7 +1611,7 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info)
        if (!reply)
                return -ENOMEM;
 
-       rcu_read_lock();
+       ovs_lock();
        dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
        if (IS_ERR(dp)) {
                err = PTR_ERR(dp);
@@ -1598,12 +1620,12 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info)
        err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
                                   info->snd_seq, 0, OVS_DP_CMD_NEW);
        BUG_ON(err < 0);
-       rcu_read_unlock();
+       ovs_unlock();
 
        return genlmsg_reply(reply, info);
 
 err_unlock_free:
-       rcu_read_unlock();
+       ovs_unlock();
        kfree_skb(reply);
        return err;
 }
@@ -1615,8 +1637,8 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
        int skip = cb->args[0];
        int i = 0;
 
-       rcu_read_lock();
-       list_for_each_entry_rcu(dp, &ovs_net->dps, list_node) {
+       ovs_lock();
+       list_for_each_entry(dp, &ovs_net->dps, list_node) {
                if (i >= skip &&
                    ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid,
                                         cb->nlh->nlmsg_seq, NLM_F_MULTI,
@@ -1624,7 +1646,7 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
                        break;
                i++;
        }
-       rcu_read_unlock();
+       ovs_unlock();
 
        cb->args[0] = i;
 
@@ -1740,7 +1762,7 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, u32 portid,
 
 /* Called with ovs_mutex or RCU read lock. */
 static struct vport *lookup_vport(struct net *net,
-                                 struct ovs_header *ovs_header,
+                                 const struct ovs_header *ovs_header,
                                  struct nlattr *a[OVS_VPORT_ATTR_MAX + 1])
 {
        struct datapath *dp;
@@ -1875,8 +1897,9 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
        }
 
        if (a[OVS_VPORT_ATTR_UPCALL_PID]) {
-               err = ovs_vport_set_upcall_portids(vport,
-                                                  a[OVS_VPORT_ATTR_UPCALL_PID]);
+               struct nlattr *ids = a[OVS_VPORT_ATTR_UPCALL_PID];
+
+               err = ovs_vport_set_upcall_portids(vport, ids);
                if (err)
                        goto exit_unlock_free;
        }