Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fuse: fix possibly missed wake-up after abort

In current fuse_drop_waiting() implementation it's possible that
fuse_wait_aborted() will not be woken up in the unlikely case that
fuse_abort_conn() + fuse_wait_aborted() runs in between checking
fc->connected and calling atomic_dec(&fc->num_waiting).

Do the atomic_dec_and_test() unconditionally, which also provides the
necessary barrier against reordering with the fc->connected check.

The explicit smp_mb() in fuse_wait_aborted() is not actually needed, since
the spin_unlock() in fuse_abort_conn() provides the necessary RELEASE
barrier after resetting fc->connected. However, this is not a performance
sensitive path, and adding the explicit barrier makes it easier to
document.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Fixes: b8f95e5d13f5 ("fuse: umount should wait for all requests")
Cc: <stable@vger.kernel.org> #v4.19

+9 -3
+9 -3
fs/fuse/dev.c
··· 165 165 166 166 static void fuse_drop_waiting(struct fuse_conn *fc) 167 167 { 168 - if (fc->connected) { 169 - atomic_dec(&fc->num_waiting); 170 - } else if (atomic_dec_and_test(&fc->num_waiting)) { 168 + /* 169 + * lockess check of fc->connected is okay, because atomic_dec_and_test() 170 + * provides a memory barrier mached with the one in fuse_wait_aborted() 171 + * to ensure no wake-up is missed. 172 + */ 173 + if (atomic_dec_and_test(&fc->num_waiting) && 174 + !READ_ONCE(fc->connected)) { 171 175 /* wake up aborters */ 172 176 wake_up_all(&fc->blocked_waitq); 173 177 } ··· 2225 2221 2226 2222 void fuse_wait_aborted(struct fuse_conn *fc) 2227 2223 { 2224 + /* matches implicit memory barrier in fuse_drop_waiting() */ 2225 + smp_mb(); 2228 2226 wait_event(fc->blocked_waitq, atomic_read(&fc->num_waiting) == 0); 2229 2227 } 2230 2228