Skip to content

Commit bb6f9a7

Browse files
Jarno RajahalmePravin B Shelar
authored andcommitted
openvswitch: Clarify locking.
Remove unnecessary locking from functions that are always called with appropriate locking. Signed-off-by: Jarno Rajahalme <[email protected]> Signed-off-by: Thomas Graf <[email protected]> Signed-off-by: Pravin B Shelar <[email protected]>
1 parent be52c9e commit bb6f9a7

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

net/openvswitch/datapath.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static struct hlist_head *vport_hash_bucket(const struct datapath *dp,
173173
return &dp->ports[port_no & (DP_VPORT_HASH_BUCKETS - 1)];
174174
}
175175

176+
/* Called with ovs_mutex or RCU read lock. */
176177
struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no)
177178
{
178179
struct vport *vport;
@@ -652,7 +653,7 @@ static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts)
652653
+ nla_total_size(acts->actions_len); /* OVS_FLOW_ATTR_ACTIONS */
653654
}
654655

655-
/* Called with ovs_mutex. */
656+
/* Called with ovs_mutex or RCU read lock. */
656657
static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp,
657658
struct sk_buff *skb, u32 portid,
658659
u32 seq, u32 flags, u8 cmd)
@@ -743,6 +744,7 @@ static int ovs_flow_cmd_fill_info(struct sw_flow *flow, struct datapath *dp,
743744
return err;
744745
}
745746

747+
/* Must be called with ovs_mutex. */
746748
static struct sk_buff *ovs_flow_cmd_alloc_info(struct sw_flow *flow,
747749
struct genl_info *info)
748750
{
@@ -753,6 +755,7 @@ static struct sk_buff *ovs_flow_cmd_alloc_info(struct sw_flow *flow,
753755
return genlmsg_new_unicast(len, info, GFP_KERNEL);
754756
}
755757

758+
/* Must be called with ovs_mutex. */
756759
static struct sk_buff *ovs_flow_cmd_build_info(struct sw_flow *flow,
757760
struct datapath *dp,
758761
struct genl_info *info,
@@ -1094,6 +1097,7 @@ static size_t ovs_dp_cmd_msg_size(void)
10941097
return msgsize;
10951098
}
10961099

1100+
/* Called with ovs_mutex or RCU read lock. */
10971101
static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
10981102
u32 portid, u32 seq, u32 flags, u8 cmd)
10991103
{
@@ -1109,9 +1113,7 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
11091113

11101114
ovs_header->dp_ifindex = get_dpifindex(dp);
11111115

1112-
rcu_read_lock();
11131116
err = nla_put_string(skb, OVS_DP_ATTR_NAME, ovs_dp_name(dp));
1114-
rcu_read_unlock();
11151117
if (err)
11161118
goto nla_put_failure;
11171119

@@ -1136,6 +1138,7 @@ static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
11361138
return -EMSGSIZE;
11371139
}
11381140

1141+
/* Must be called with ovs_mutex. */
11391142
static struct sk_buff *ovs_dp_cmd_build_info(struct datapath *dp,
11401143
struct genl_info *info, u8 cmd)
11411144
{
@@ -1154,7 +1157,7 @@ static struct sk_buff *ovs_dp_cmd_build_info(struct datapath *dp,
11541157
return skb;
11551158
}
11561159

1157-
/* Called with ovs_mutex. */
1160+
/* Called with rcu_read_lock or ovs_mutex. */
11581161
static struct datapath *lookup_datapath(struct net *net,
11591162
struct ovs_header *ovs_header,
11601163
struct nlattr *a[OVS_DP_ATTR_MAX + 1])
@@ -1166,10 +1169,8 @@ static struct datapath *lookup_datapath(struct net *net,
11661169
else {
11671170
struct vport *vport;
11681171

1169-
rcu_read_lock();
11701172
vport = ovs_vport_locate(net, nla_data(a[OVS_DP_ATTR_NAME]));
11711173
dp = vport && vport->port_no == OVSP_LOCAL ? vport->dp : NULL;
1172-
rcu_read_unlock();
11731174
}
11741175
return dp ? dp : ERR_PTR(-ENODEV);
11751176
}

net/openvswitch/flow.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ void ovs_flow_stats_update(struct sw_flow *flow, struct sk_buff *skb)
122122
spin_unlock(&stats->lock);
123123
}
124124

125+
/* Called with ovs_mutex. */
125126
void ovs_flow_stats_get(struct sw_flow *flow, struct ovs_flow_stats *ovs_stats,
126127
unsigned long *used, __be16 *tcp_flags)
127128
{
@@ -132,7 +133,7 @@ void ovs_flow_stats_get(struct sw_flow *flow, struct ovs_flow_stats *ovs_stats,
132133
memset(ovs_stats, 0, sizeof(*ovs_stats));
133134

134135
for_each_node(node) {
135-
struct flow_stats *stats = rcu_dereference(flow->stats[node]);
136+
struct flow_stats *stats = ovsl_dereference(flow->stats[node]);
136137

137138
if (stats) {
138139
/* Local CPU may write on non-local stats, so we must

0 commit comments

Comments
 (0)