]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fuse: use READ_ONCE in fuse_chan_num_background()
authorLi Wang <liwang@kylinos.cn>
Fri, 22 May 2026 08:38:05 +0000 (16:38 +0800)
committerMiklos Szeredi <mszeredi@redhat.com>
Mon, 15 Jun 2026 12:06:19 +0000 (14:06 +0200)
fuse_chan_num_background() is called without holding fch->bg_lock (for
example from fuse_writepages() to compare against fc->congestion_threshold),
while fch->num_background is updated under bg_lock in dev.c and dev_uring.c.
This is the same locked-write/lockless-read pattern already used for
max_background in fuse_chan_max_background().

Use READ_ONCE() on the read side so that:

- The compiler does not cache or coalesce loads of a value that may change
  concurrently on another CPU.
- Prevent KCSAN from reporting an unexpected race.

Signed-off-by: Li Wang <liwang@kylinos.cn>
Fixes: 670d21c6e17f ("fuse: remove reliance on bdi congestion")
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/dev.c

index 63a2898530232c1b3897df1980738ba8992075dc..d09cddd68e0350b6b5dc586b82719b223c6e54d2 100644 (file)
@@ -383,7 +383,7 @@ EXPORT_SYMBOL_GPL(fuse_dev_chan_new);
 
 unsigned int fuse_chan_num_background(struct fuse_chan *fch)
 {
-       return fch->num_background;
+       return READ_ONCE(fch->num_background);
 }
 
 unsigned int fuse_chan_max_background(struct fuse_chan *fch)