]> git.openfabrics.org - ~shefty/rdma-win.git/commit
librdmacm: fix race in ucma_init()
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 26 Aug 2009 16:45:53 +0000 (16:45 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 26 Aug 2009 16:45:53 +0000 (16:45 +0000)
commit5f9d8bddeb4f1c4954d10598476ec0cb7556e643
treef841c964aef0f7e5606e2ffdfe8a6daec0297f8f
parent40e337e3cc66529f38a0d47976eeed4023665b34
librdmacm: fix race in ucma_init()

There's a potential race with ucma_init() and calls that check whether
the library is ready for use.  For example, in rdma_create_id, this
check is performed:

hr = cma_dev_cnt ? 0 : ucma_init();
if (hr) {
return hr;
}

Since the check for cma_dev_cnt is outside of any synchronization, if it
is non-zeroy, then the code will assume that initialization is complete.
However, ucma_init() can set cma_dev_cnt to non-zeroy before it has finished
executing.  The full impact of this race is unknown, but it can't be good.
In the worst case, the application may crash.

Fix this by ensuring that all initialization is complete before cma_dev_cnt
is incremented.  Note that ucma_init() provides synchronization to protect
against duplicate threads handling init.  The cma_dev_cnt check is used to
avoid synchronization on multiple calls into the library after initialization.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1@2383 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86
trunk/ulp/librdmacm/src/cma.cpp