Skip to content

Commit

Permalink
northd.c: Lock to protect against possible od->group corruption.
Browse files Browse the repository at this point in the history
When parallel build is used, od->group can be updated by threads outside
of the function do_ovn_lflow_add_pd (for lb related flow building). So
use the function ovn_dp_group_add_with_reference() to update it in
function do_ovn_lflow_add() when it is not a newly created flow.

Signed-off-by: Han Zhou <hzhou@ovn.org>
Acked-by: Numan Siddique <numans@ovn.org>
  • Loading branch information
hzhou8 committed Oct 5, 2021
1 parent f5e2120 commit a1945b2
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions northd/northd.c
Expand Up @@ -4320,6 +4320,26 @@ ovn_lflow_init(struct ovn_lflow *lflow, struct ovn_datapath *od,
}
}

static bool
ovn_dp_group_add_with_reference(struct ovn_lflow *lflow_ref,
struct ovn_datapath *od)
OVS_NO_THREAD_SAFETY_ANALYSIS
{
if (!use_logical_dp_groups || !lflow_ref) {
return false;
}

if (use_parallel_build) {
ovs_mutex_lock(&lflow_ref->odg_lock);
hmapx_add(&lflow_ref->od_group, od);
ovs_mutex_unlock(&lflow_ref->odg_lock);
} else {
hmapx_add(&lflow_ref->od_group, od);
}

return true;
}

/* Adds a row with the specified contents to the Logical_Flow table.
* Version to use with dp_groups + parallel - when locking is required.
*
Expand Down Expand Up @@ -4372,7 +4392,7 @@ do_ovn_lflow_add(struct hmap *lflow_map, struct ovn_datapath *od,
old_lflow = ovn_lflow_find(lflow_map, NULL, stage, priority, match,
actions, ctrl_meter, hash);
if (old_lflow) {
hmapx_add(&old_lflow->od_group, od);
ovn_dp_group_add_with_reference(old_lflow, od);
return old_lflow;
}
}
Expand Down Expand Up @@ -4487,26 +4507,6 @@ ovn_lflow_add_at(struct hmap *lflow_map, struct ovn_datapath *od,
io_port, ctrl_meter, stage_hint, where, hash);
}

static bool
ovn_dp_group_add_with_reference(struct ovn_lflow *lflow_ref,
struct ovn_datapath *od)
OVS_NO_THREAD_SAFETY_ANALYSIS
{
if (!use_logical_dp_groups || !lflow_ref) {
return false;
}

if (use_parallel_build) {
ovs_mutex_lock(&lflow_ref->odg_lock);
hmapx_add(&lflow_ref->od_group, od);
ovs_mutex_unlock(&lflow_ref->odg_lock);
} else {
hmapx_add(&lflow_ref->od_group, od);
}

return true;
}

/* Adds a row with the specified contents to the Logical_Flow table. */
#define ovn_lflow_add_with_hint__(LFLOW_MAP, OD, STAGE, PRIORITY, MATCH, \
ACTIONS, IN_OUT_PORT, CTRL_METER, \
Expand Down

0 comments on commit a1945b2

Please sign in to comment.