pagecache_read_sg_finish(): fix locking order inversion #2055
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.