Skip to content

pagecache_read_sg_finish(): fix locking order inversion #2055

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

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

francescolavra
Copy link
Member

Throughout the page cache code, when both a cache node and the cache state need to be locked at the same time, the node must be locked first. The existing implementation of pagecache_read_sg_finish() is locking the cache state first, thereby creating a locking order inversion that can cause the kernel to deadlock in multi-vCPU instances, for example if multiple reads from the page cache are executed concurrently (the CI test failure at
https://app.circleci.com/pipelines/github/nanovms/nanos/4810/workflows/d6be64e2-18b7-4d4a-bb4c-8426ac35239c/jobs/16820 is caused by this).
Bug introduced in commit 8225e71.

Throughout the pagecache code, when both a cache node and the cache
state need to be locked at the same time, the node must be locked
first. The existing implementation of pagecache_read_sg_finish() is
locking the cache state first, thereby creating a locking order
inversion that can cause the kernel to deadlock in multi-vCPU
instances, for example if multiple reads from the page cache are
executed concurrently (the CI test failure at
https://app.circleci.com/pipelines/github/nanovms/nanos/4810/workflows/d6be64e2-18b7-4d4a-bb4c-8426ac35239c/jobs/16820
is caused by this).
Bug introduced in commit 8225e71.
@francescolavra francescolavra merged commit f65bc5c into master Aug 22, 2024
5 checks passed
@francescolavra francescolavra deleted the fix/pagecache_read_sg_finish branch August 22, 2024 14:00
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.

2 participants