Skip to content

Commit

Permalink
datapath: Convert dp rcu read operation to locked operations
Browse files Browse the repository at this point in the history
dp read operations depends on ovs_dp_cmd_fill_info(). This API
needs to looup vport to find dp name, but vport lookup can
fail. Therefore to keep vport reference alive we need to
take ovs lock.

Found by code inspection.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
  • Loading branch information
Pravin B Shelar committed Nov 4, 2014
1 parent 3ca3ce0 commit d637497
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions datapath/datapath.c
Expand Up @@ -1332,7 +1332,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)
{
Expand Down Expand Up @@ -1618,7 +1618,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);
Expand All @@ -1627,12 +1627,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;
}
Expand All @@ -1644,16 +1644,16 @@ 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,
OVS_DP_CMD_NEW) < 0)
break;
i++;
}
rcu_read_unlock();
ovs_unlock();

cb->args[0] = i;

Expand Down

0 comments on commit d637497

Please sign in to comment.