Skip to content

Commit 4a46b24

Browse files
Alex WangPravin B Shelar
authored andcommitted
openvswitch: Use exact lookup for flow_get and flow_del.
Due to the race condition in userspace, there is chance that two overlapping megaflows could be installed in datapath. And this causes userspace unable to delete the less inclusive megaflow flow even after it timeout, since the flow_del logic will stop at the first match of masked flow. This commit fixes the bug by making the kernel flow_del and flow_get logic check all masks in that case. Introduced by 03f0d91 (openvswitch: Mega flow implementation). Signed-off-by: Alex Wang <alexw@nicira.com> Acked-by: Andy Zhou <azhou@nicira.com> Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
1 parent ad55200 commit 4a46b24

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

‎net/openvswitch/datapath.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,11 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
889889
}
890890
/* The unmasked key has to be the same for flow updates. */
891891
if (unlikely(!ovs_flow_cmp_unmasked_key(flow, &match))) {
892-
error = -EEXIST;
893-
goto err_unlock_ovs;
892+
flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
893+
if (!flow) {
894+
error = -ENOENT;
895+
goto err_unlock_ovs;
896+
}
894897
}
895898
/* Update actions. */
896899
old_acts = ovsl_dereference(flow->sf_acts);
@@ -981,16 +984,12 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
981984
goto err_unlock_ovs;
982985
}
983986
/* Check that the flow exists. */
984-
flow = ovs_flow_tbl_lookup(&dp->table, &key);
987+
flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
985988
if (unlikely(!flow)) {
986989
error = -ENOENT;
987990
goto err_unlock_ovs;
988991
}
989-
/* The unmasked key has to be the same for flow updates. */
990-
if (unlikely(!ovs_flow_cmp_unmasked_key(flow, &match))) {
991-
error = -EEXIST;
992-
goto err_unlock_ovs;
993-
}
992+
994993
/* Update actions, if present. */
995994
if (likely(acts)) {
996995
old_acts = ovsl_dereference(flow->sf_acts);
@@ -1063,8 +1062,8 @@ static int ovs_flow_cmd_get(struct sk_buff *skb, struct genl_info *info)
10631062
goto unlock;
10641063
}
10651064

1066-
flow = ovs_flow_tbl_lookup(&dp->table, &key);
1067-
if (!flow || !ovs_flow_cmp_unmasked_key(flow, &match)) {
1065+
flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
1066+
if (!flow) {
10681067
err = -ENOENT;
10691068
goto unlock;
10701069
}
@@ -1113,8 +1112,8 @@ static int ovs_flow_cmd_del(struct sk_buff *skb, struct genl_info *info)
11131112
goto unlock;
11141113
}
11151114

1116-
flow = ovs_flow_tbl_lookup(&dp->table, &key);
1117-
if (unlikely(!flow || !ovs_flow_cmp_unmasked_key(flow, &match))) {
1115+
flow = ovs_flow_tbl_lookup_exact(&dp->table, &match);
1116+
if (unlikely(!flow)) {
11181117
err = -ENOENT;
11191118
goto unlock;
11201119
}

‎net/openvswitch/flow_table.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,22 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl,
456456
return ovs_flow_tbl_lookup_stats(tbl, key, &n_mask_hit);
457457
}
458458

459+
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
460+
struct sw_flow_match *match)
461+
{
462+
struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
463+
struct sw_flow_mask *mask;
464+
struct sw_flow *flow;
465+
466+
/* Always called under ovs-mutex. */
467+
list_for_each_entry(mask, &tbl->mask_list, list) {
468+
flow = masked_flow_lookup(ti, match->key, mask);
469+
if (flow && ovs_flow_cmp_unmasked_key(flow, match)) /* Found */
470+
return flow;
471+
}
472+
return NULL;
473+
}
474+
459475
int ovs_flow_tbl_num_masks(const struct flow_table *table)
460476
{
461477
struct sw_flow_mask *mask;

‎net/openvswitch/flow_table.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
7676
u32 *n_mask_hit);
7777
struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
7878
const struct sw_flow_key *);
79-
79+
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
80+
struct sw_flow_match *match);
8081
bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
8182
struct sw_flow_match *match);
8283

0 commit comments

Comments
 (0)