Skip to content

Take the FUSE file slot before the session lock - #509

Merged
jserv merged 1 commit into
sysprog21:mainfrom
Max042004:fuse-slot-before-session-lock
Nov 16, 2026
Merged

jserv merged 1 commit into
sysprog21:mainfrom
Max042004:fuse-slot-before-session-lock

Conversation

@Max042004

@Max042004 Max042004 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

fuse_open_path held session->lock across the path walk and then took fuse_lock to allocate the file slot, while fuse_path_lookup takes fuse_lock and then session->lock. The session lock is held across daemon round trips, so a lookup waiting on it while holding fuse_lock and an open waiting on fuse_lock while holding it deadlock each other.

The slot is now allocated under the fuse_lock the open already holds after it the session.


Summary by cubic

Fixes a deadlock in the FUSE open path by reserving the file slot before taking the session lock.

fuse_open_path held session->lock across the path walk and then took fuse_lock for the slot, while fuse_path_lookup takes fuse_lock then session->lock. An open waiting on fuse_lock while holding the session lock and a lookup waiting on the session lock while holding fuse_lock deadlocked. The slot is now reserved under the fuse_lock the open already holds for the mount lookup, before the session lock is taken, and every early return hands it back.

Nothing reaches the daemon for an open that cannot get a slot, so a full table reports ENFILE instead of the earlier ENOMEM for a name that resolves, and ENFILE instead of ENOENT for a missing name. An O_TRUNC open cannot truncate a file it then fails to open. Each open holds a slot for the whole walk, so a burst of concurrent opens can fill the table and turn away an open that would have succeeded.

  • Adds test-fuse-open-lock and the ELFUSE_FUSE_OPEN_LOCK_DELAY_US hook to hold an open inside the session lock while a stat starts, which deadlocked on every run before this change.

Written for commit c442ee8. Summary will update on new commits.

View guided diff

cubic-dev-ai[bot]

This comment was marked as resolved.

Comment thread src/syscall/fuse.c Resolved
@jserv
jserv requested a review from xalestar November 11, 2026 20:16

@jserv jserv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase onto latest main branch which resolves regressions.

Comment thread src/syscall/fuse.c Resolved
Comment thread src/syscall/fuse.c Resolved
@Max042004
Max042004 force-pushed the fuse-slot-before-session-lock branch 2 times, most recently from 97110b4 to 994f570 Compare November 12, 2026 04:25

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

View guided diff | Re-trigger cubic

Comment thread src/syscall/fuse.c Resolved
@Max042004
Max042004 force-pushed the fuse-slot-before-session-lock branch from 994f570 to de8b57d Compare November 12, 2026 11:26
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Benchmark changes outside ±20%

Compared elfuse-aarch64 with the default branch's baseline. Lower is better.

Improvements

Metric Baseline Current Change
applications.git_status_ms 113.327 29.498 -74.0%
applications.make_ms 5850.39 1389.95 -76.2%
applications.python_startup_ms 117.826 25.848 -78.1%
applications.zstd_ms 112.975 34.501 -69.5%
lmbench.lat_proc.exec 112392 22196.4 -80.3%
lmbench.lat_proc.fork 116097 4808.02 -95.9%
lmbench.lat_syscall.read 1.72295 0.92145 -46.5%
lmbench.lat_syscall.write 1.7114 1.0171 -40.6%

Workflow run · commit c442ee8a2c12

Comment thread src/syscall/fuse.c Resolved
Comment thread tests/test-fuse-open-lock.c Resolved
@Max042004
Max042004 force-pushed the fuse-slot-before-session-lock branch from de8b57d to 12ca88e Compare November 12, 2026 16:18
@Max042004 Max042004 changed the title Take the FUSE file slot before the session lock Take the FUSE file slot after the session lock Nov 12, 2026
@Max042004
Max042004 force-pushed the fuse-slot-before-session-lock branch from 12ca88e to 585add9 Compare November 12, 2026 16:24
cubic-dev-ai[bot]

This comment was marked as resolved.

@Max042004
Max042004 force-pushed the fuse-slot-before-session-lock branch from 585add9 to 9e02c9c Compare November 13, 2026 02:17
Comment thread src/syscall/fuse.c Resolved
Comment thread src/syscall/fuse.c Resolved
@Max042004
Max042004 force-pushed the fuse-slot-before-session-lock branch from 9e02c9c to ee82b6e Compare November 13, 2026 04:26
@Max042004 Max042004 changed the title Take the FUSE file slot after the session lock Take the FUSE file slot before the session lock Nov 13, 2026
fuse_open_path held session->lock across the path walk and then took
fuse_lock to allocate the file slot, while fuse_path_lookup takes
fuse_lock and then session->lock. An open holding the session lock and
waiting on fuse_lock, and a lookup holding fuse_lock and waiting on the
session lock, deadlock each other.

The slot is now reserved under the fuse_lock the open already holds for
the mount lookup, before it takes session->lock, and every early return
hands it back. Nothing reaches the daemon for an open that cannot get a
slot. That matters because FUSE_OPEN carries the open flags, O_TRUNC
included, so a slot check after it could fail an open whose truncation
had already happened. Linux likewise allocates the struct file in
path_openat before the walk.

Two effects follow. Each open holds a slot for the whole walk,
so a burst of concurrent opens can fill the table and
turn away an open that would have succeeded. And a full table fails the
open before the walk, so a missing name reports ENFILE rather than
ENOENT, as Linux does when alloc_empty_file fails. The table does not
grow with RLIMIT_NOFILE, so the failure is ENFILE rather
than the earlier ENOMEM.

test-fuse-open-lock fails each early return of the open more times than
the table has slots, then fills the table and checks that every open
reports ENFILE without a FUSE_OPEN reaching the daemon, and that every
successful FUSE_OPEN is released. It also holds an open inside the
session lock with a new ELFUSE_FUSE_OPEN_LOCK_DELAY_US hook while a
stat starts, and fails unless the stat waited on the open. Before this
change that case deadlocked on every run.
@Max042004
Max042004 force-pushed the fuse-slot-before-session-lock branch from ee82b6e to c442ee8 Compare November 14, 2026 12:39
@jserv
jserv merged commit e9d6647 into sysprog21:main Nov 16, 2026
17 checks passed
@jserv

jserv commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Thank @Max042004 for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants