Skip to content

Commit 6aa8f1a

Browse files
author
Kent Overstreet
committed
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
1 parent 8e51e41 commit 6aa8f1a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎drivers/md/bcache/closure.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,18 @@ static inline void closure_put_after_sub(struct closure *cl, int flags)
6666
} else {
6767
struct closure *parent = cl->parent;
6868
struct closure_waitlist *wait = closure_waitlist(cl);
69+
closure_fn *destructor = cl->fn;
6970

7071
closure_debug_destroy(cl);
7172

73+
smp_mb();
7274
atomic_set(&cl->remaining, -1);
7375

7476
if (wait)
7577
closure_wake_up(wait);
7678

77-
if (cl->fn)
78-
cl->fn(cl);
79+
if (destructor)
80+
destructor(cl);
7981

8082
if (parent)
8183
closure_put(parent);

0 commit comments

Comments
 (0)