summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-10-24 21:46:58 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-31 04:48:22 +0300
commitee526b88caaa4b4182144bf2576af2c3b1e9c759 (patch)
treed25c1a6b69d86c8a7ed518334dbcc13a842b37e4 /lib
parent2bce6368c46b835a133f7f4946eea9c4513828dd (diff)
downloadlinux-ee526b88caaa4b4182144bf2576af2c3b1e9c759.tar.xz
closures: Fix race in closure_sync()
As pointed out by Linus, closure_sync() was racy; we could skip blocking immediately after a get() and a put(), but then that would skip any barrier corresponding to the other thread's put() barrier. To fix this, always do the full __closure_sync() sequence whenever any get() has happened and the closure might have been used by other threads. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'lib')
-rw-r--r--lib/closure.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/closure.c b/lib/closure.c
index 501dfa277b59..f86c9eeafb35 100644
--- a/lib/closure.c
+++ b/lib/closure.c
@@ -23,6 +23,8 @@ static inline void closure_put_after_sub(struct closure *cl, int flags)
if (!r) {
smp_acquire__after_ctrl_dep();
+ cl->closure_get_happened = false;
+
if (cl->fn && !(flags & CLOSURE_DESTRUCTOR)) {
atomic_set(&cl->remaining,
CLOSURE_REMAINING_INITIALIZER);
@@ -92,6 +94,7 @@ bool closure_wait(struct closure_waitlist *waitlist, struct closure *cl)
if (atomic_read(&cl->remaining) & CLOSURE_WAITING)
return false;
+ cl->closure_get_happened = true;
closure_set_waiting(cl, _RET_IP_);
atomic_add(CLOSURE_WAITING + 1, &cl->remaining);
llist_add(&cl->list, &waitlist->list);