Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/vfscore: Reorder locks in *at syscalls #951

Closed
wants to merge 1 commit into from

Conversation

andreittr
Copy link
Contributor

Description of changes

*at syscalls are implemented in Unikraft in two stages: (1) build the full target path relative to the supplied dirfd, and (2) delegate to the regular syscall. Previously these syscalls held the lock on the dirfd vnode throughout steps (1) and (2); however, the sub-syscalls often need to acquire the same lock (along with perhaps others), causing double-lock asserts to trigger.
This commit changes this logic to only hold the vnode lock during step (1) and release it immediately before (2). While this relaxes the previous atomicity guarantees somewhat, holding the vnode lock on dirfd only prevented concurrent changes to first-generation descendents, and unorthogonal and arguably unexpected behavior. The useful purpose of holding the dirfd lock is to ensure we build a full path that was (at one point in time) valid, with the sub-syscalls implementing their own atomicity guarantees as per usual.

Prerequisite checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Base target

  • Architecture(s): all
  • Platform(s): all
  • Application(s): all

Additional configuration

Test with using any of the openat, mkdirat, fstatat, faccessat syscalls; staging fails with a lock assertion, fixed code should behave as expected.

*at syscalls are implemented in Unikraft in two stages: (1) build the
full target path relative to the supplied dirfd, and (2) delegate to the
regular syscall. Previously these syscalls held the lock on the dirfd
vnode throughout steps (1) and (2); however, the sub-syscalls often need
to acquire the same lock (along with perhaps others), causing
double-lock asserts to trigger.
This commit changes this logic to only hold the vnode lock during step
(1) and release it immediately before (2). While this relaxes the
previous atomicity guarantees somewhat, holding the vnode lock on dirfd
only prevented concurrent changes to first-generation descendents, and
unorthogonal and arguably unexpected behavior. The useful purpose of
holding the dirfd lock is to ensure we build a full path that was (at
one point in time) valid, with the sub-syscalls implementing their own
atomicity guarantees as per usual.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
@andreittr andreittr requested a review from a team as a code owner June 21, 2023 07:38
@unikraft-bot unikraft-bot added area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ lib/vfscore VFS Core Interface labels Jun 21, 2023
@unikraft-bot
Copy link
Member

Checkpatch passed

Beep boop! I ran Unikraft's checkpatch.pl support script on your pull request and it all looks good!

SHA commit checkpatch
0398314 lib/vfscore: Reorder locks in *at syscalls

@razvand razvand requested review from razvanvirtan and mariasfiraiala and removed request for a team and dragosargint July 24, 2023 20:40
@razvand razvand assigned razvand and unassigned nderjung Jul 24, 2023
@razvand razvand added this to the v0.14.0 (Prometheus) milestone Jul 24, 2023
Copy link
Contributor

@mariasfiraiala mariasfiraiala left a comment

Choose a reason for hiding this comment

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

This looks alright, thank you @andreittr!

Reviewed-by: Maria Sfiraiala maria.sfiraiala@gmail.com

Copy link
Contributor

@razvand razvand left a comment

Choose a reason for hiding this comment

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

Approved-by: Razvan Deaconescu razvand@unikraft.io

@unikraft-bot unikraft-bot added the ci/merged Merged by CI label Aug 7, 2023
@andreittr andreittr deleted the ttr/atlocks branch August 7, 2023 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lib Internal Unikraft Microlibrary ci/merged Merged by CI lang/c Issues or PRs to do with C/C++ lib/vfscore VFS Core Interface
Projects
Status: Done!
Development

Successfully merging this pull request may close these issues.

None yet

5 participants