Fix fence completion race in virtio-gpu worker#604
Open
aford173 wants to merge 1 commit intocontainers:stable-1.17.xfrom
Open
Fix fence completion race in virtio-gpu worker#604aford173 wants to merge 1 commit intocontainers:stable-1.17.xfrom
aford173 wants to merge 1 commit intocontainers:stable-1.17.xfrom
Conversation
Collaborator
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the virtio_gpu module to correctly handle out-of-order fence completions. Specifically, it updates the logic for completed_fences to ensure that the highest fence_id is always retained for each ring, preventing a lower fence_id from overwriting a higher one. The reviewer suggests a more concise implementation for this max logic using u64::max.
Comment on lines
+212
to
+214
| if completed_fence.fence_id > *entry { | ||
| *entry = completed_fence.fence_id; | ||
| } |
When fences complete out of order (e.g., an immediate-retire for fence N+1 arrives before the timeline signal for fence N), the unconditional insert() would overwrite the higher fence_id with the lower one. This causes fence N+1 to appear incomplete forever, hanging the guest. Use entry().or_insert() with a max check so only strictly higher fence_ids update the completed_fences map. Signed-off-by: Adam Ford <adam.ford@anodize.com>
b862bb1 to
b9ae63e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix an out-of-order fence completion race that causes the guest to hang intermittently during heavy GPU
rendering through vDRM/virtio-gpu.
When virglrenderer immediately retires fence N+1 (no GPU work) before the timeline thread signals fence N,
the unconditional
insert()in the fence handler overwritescompleted_fences[ring]from N+1 back to N.The worker's
process_fence()then sees N+1 > N and adds fence N+1 to the pending list, where it staysforever — the retirement callback already fired and won't fire again.
The fix uses a max check so only strictly higher fence_ids update the map.
Discovered while bringing up vDRM GPU passthrough on an MT8196 Chromebook (Mali-G725 / Panthor). The hang
was reproducible with glmark2 after ~100K-1.5M frames during multi-pass rendering scenes (desktop blur,
terrain, refract). Simple apps like glxgears ran indefinitely.
Test plan
multi-pass scenes)