Skip to contentSkip to conversation

fuse: use READ_ONCE in fuse_chan_num_background()

PATCH Applied Li Wang 2 participants 2 messages May 22 – Jun 10

Subsystems (2)
lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 fuse: use READ_ONCE in fuse_chan_num_background()

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.

---
 fs/fuse/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev.c +1 -1
index 6254307c07e6..69fcfdfed409 100644
@@ -401,7 +401,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)
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Li Wang

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().

Quoted 7 lines

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.

Applied, thanks.

Miklos