diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-07-11 03:04:21 +0200 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2013-07-12 09:22:33 +0200 |
commit | 6aa8f1a6ca41c49721d2de4e048d3da8d06411f9 (patch) | |
tree | 2d7be747ae6dea479779fd8f993ef74744c27e6a /drivers/md | |
parent | bcache: Use standard utility code (diff) | |
download | linux-6aa8f1a6ca41c49721d2de4e048d3da8d06411f9.tar.xz linux-6aa8f1a6ca41c49721d2de4e048d3da8d06411f9.zip |
bcache: Fix a dumb race
In the far-too-complicated closure code - closures can have destructors,
for probably dubious reasons; they get run after the closure is no
longer waiting on anything but before dropping the parent ref, intended
just for freeing whatever memory the closure is embedded in.
Trouble is, when remaining goes to 0 and we've got nothing more to run -
we also have to unlock the closure, setting remaining to -1. If there's
a destructor, that unlock isn't doing anything - nobody could be trying
to lock it if we're about to free it - but if the unlock _is needed...
that check for a destructor was racy. Argh.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v3.10
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/bcache/closure.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/md/bcache/closure.c b/drivers/md/bcache/closure.c index bd05a9a8c7cf..9aba2017f0d1 100644 --- a/drivers/md/bcache/closure.c +++ b/drivers/md/bcache/closure.c @@ -66,16 +66,18 @@ static inline void closure_put_after_sub(struct closure *cl, int flags) } else { struct closure *parent = cl->parent; struct closure_waitlist *wait = closure_waitlist(cl); + closure_fn *destructor = cl->fn; closure_debug_destroy(cl); + smp_mb(); atomic_set(&cl->remaining, -1); if (wait) closure_wake_up(wait); - if (cl->fn) - cl->fn(cl); + if (destructor) + destructor(cl); if (parent) closure_put(parent); |