Skip to content

Commit

Permalink
btl/ugni: fix race condition in completing frags
Browse files Browse the repository at this point in the history
The descriptor flags field in a fragment were being ready after the
fragment may have been freed. This commit reads the flags before
calling the user callback.

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
  • Loading branch information
hjelmn committed Jul 3, 2018
1 parent 87d41da commit d8916a4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions opal/mca/btl/ugni/btl_ugni_frag.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ static inline int mca_btl_ugni_frag_return (mca_btl_ugni_base_frag_t *frag)

static inline bool mca_btl_ugni_frag_del_ref (mca_btl_ugni_base_frag_t *frag, int rc) {
mca_btl_ugni_module_t *ugni_module = mca_btl_ugni_ep_btl (frag->endpoint);
/* save the descriptor flags since the callback is allowed to free the frag */
int des_flags = frag->base.des_flags;
int32_t ref_cnt;

opal_atomic_mb ();
Expand All @@ -238,11 +240,11 @@ static inline bool mca_btl_ugni_frag_del_ref (mca_btl_ugni_base_frag_t *frag, in
}

/* call callback if specified */
if (frag->base.des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK) {
if (des_flags & MCA_BTL_DES_SEND_ALWAYS_CALLBACK) {
frag->base.des_cbfunc(&ugni_module->super, frag->endpoint, &frag->base, rc);
}

if (frag->base.des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP) {
if (des_flags & MCA_BTL_DES_FLAGS_BTL_OWNERSHIP) {
mca_btl_ugni_frag_return (frag);
}

Expand Down

0 comments on commit d8916a4

Please sign in to comment.