Repository navigation
Conversation
DdiMedia_StatusCheck removes entries from a VP context's status table
with GetStatusReport and marks the surface each entry names as
completed, until it reaches the surface being synced. vaEndPicture adds
an entry to the same table in Render. Neither holds a lock, but an
application may call vaSyncSurface from any thread on surfaces that a
shared VP context rendered.
When one thread has removed another thread's entry but not yet marked
its surface, the other thread's StatusCheck doesn't find its entry, its
surface is still pending, and vaSyncSurface returns
VA_STATUS_ERROR_OPERATION_FAILED although the job has finished. Calling
vaSyncSurface again succeeds. The table's head and tail are also
updated by several threads without synchronization.
- Add StatusMutex to DDI_VP_CONTEXT, destroyed with the context.
StatusCheck holds it while it removes entries and marks their
surfaces, and EndPicture holds it around Render, which adds the job's
entry.
- Stop at the VPREP_NOTAVAILABLE placeholder that GetStatusReport
returns for an empty table, instead of treating it as an entry for
VA surface 0.
- Skip an entry whose surface was destroyed after its job was
submitted, instead of failing the caller's vaSyncSurface.
- Make the same changes to DdiVpFunctions::StatusCheck and EndPicture
in media_softlet.
Verified on Jasper Lake (media_driver path) with threads sharing one VP
context, submitting jobs under an application lock and calling
vaSyncSurface outside it, while surfaces are created and destroyed.
With 8 threads, 778 of 120000 vaSyncSurface calls failed before the
change; after it, 0 of 544000 failed with 2 to 64 threads. Throughput
without surface churn is unchanged (2952 vs 2960 jobs/s).
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.
There's a memory safety issue in the VPHAL_STATUS_TABLE which causes
vaSyncSurfaceto sometimes returnVA_STATUS_ERROR_OPERATION_FAILED(0x1) for a job that has finished successfully. Basically we have an application with several threads that share one VA display and one vpp context. Each thread scales into its own target surface. The application serializes every call that names the shared context (vaCreateBuffer,vaBeginPicture,vaRenderPicture,vaEndPicture) with a mutex. It then releases the mutex and callsvaSyncSurfaceon its own target, so threads can wait for the GPU in parallel.When this fails:
vaQuerySurfaceStatusreportsVASurfaceReadyfor the target.vaSyncSurfaceon the same surface again succeeds, usually at once, sometimes after 1-10 ms.While another thread is creating and destroying surfaces, as a video decoder does when it's reset, every run fails on about 0.5-0.8% of
vaSyncSurfacecalls. It fails with as few as two threads. It doesn't fail with one thread, with a VPP context per thread, or when the test application holds a mutex acrossvaSyncSurface.The cause is in
DdiMedia_StatusCheck. For a VPP surface, it removes entries from the VPP context's status table, and marks the surface each entry names as completed, without holding any lock:SurfaceMutexto look up A's surface, and has to wait for it, because another thread iscreating or destroying a surface.
vaSyncSurfacefinds its own entry gone and its surface still marked pending. It returnsVA_STATUS_ERROR_OPERATION_FAILED.In a run of the program on an instrumented build of the driver, all 269 failing calls came from that return.
Reproduction
There's a (claude generated) minimal reproduction here: https://gist.github.com/jwalton/9ea6fcd2cfa0a8d66c0a8187b6f84046
The program has:
Each worker thread scales an 854x480 NV12 source into its own 764x430 NV12 target, 5,000 times. It submits with the
mutex held, then releases the mutex and calls
vaSyncSurface. Each worker alternates between two sources: onefilled with luma 50, one with luma 200. When
vaSyncSurfacefails, the worker checks three things:vaQuerySurfaceStatusreports for the target;vaSyncSurfacesucceeds if called again: at once, then after 1, 10 and 100 ms.Options:
-cgives each worker thread its own VPP context.-lholds the mutex acrossvaSyncSurfacetoo.-sturns off the thread that creates and destroys surfaces.Build and run:
Output:
Expected:
vaSyncSurfacereturnsVA_STATUS_SUCCESSfor every job, since every job finished and producedthe right output.