-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
drm: vc4: Block swiotlb bounce buffers being imported as dmabuf #5734
Conversation
The dmabuf import already checks that the backing buffer is contiguous and rejects it if it isn't. vc4 also requires that the buffer is in the bottom 1GB of RAM, and this is all correctly defined via dma-ranges. However the kernel silently uses swiotlb to bounce dma buffers around if they are in the wrong region. This relies on dma sync functions to be called in order to copy the data to/from the bounce buffer. DRM is based on all memory allocations being coherent with the GPU so that any updates to a framebuffer will be acted on without the need for any additional update. This is fairly fundamentally incompatible with needing to call dma_sync_ to handle the bounce buffer copies, and therefore we have to detect and reject mappings that use bounce buffers. Signed-off-by: Dave Stevenson <[email protected]>
b12ad0b
to
123b042
Compare
Fixes #5727 |
This is going to reject buffers that end up in swiotlb pages. How does this rejection manifest itself? Does it not cause another problem? A very brief skim of some documentation on dmabufs (https://docs.kernel.org/driver-api/dma-buf.html) made me think that the DMA synchronisation is done at the request of the application, using the DMA_BUF_IOCTL_SYNC ioctl. |
This rejection will cause the userspace Yes the DMABUF API covers syncing to the main dmabuf allocation, but that doesn't cover syncing to the bounce buffer which only happens when the DMA consumer (ie HVS) says it wants to sync. DRM totally ignores doing that, therefore the bounce buffer never gets copied into. This is effectively the same issue that the firmware used to have to handle with the transposer and |
I'd like to discuss this more - in person is easier - but I'll merge the PR as at least an improvement. |
…OGUE_GAIN See: raspberrypi/linux#5711 kernel: DRM fixes See: raspberrypi/linux#5716 kernel: drm: vc4: Free the dlist alloc immediately if it never hit the hw See: raspberrypi/linux#5733 kernel: Include I2C bus details in ft5x06 and goodix touch driver names See: raspberrypi/linux#5703 kernel: drm: vc4: Block swiotlb bounce buffers being imported as dmabuf See: raspberrypi/linux#5734
…OGUE_GAIN See: raspberrypi/linux#5711 kernel: DRM fixes See: raspberrypi/linux#5716 kernel: drm: vc4: Free the dlist alloc immediately if it never hit the hw See: raspberrypi/linux#5733 kernel: Include I2C bus details in ft5x06 and goodix touch driver names See: raspberrypi/linux#5703 kernel: drm: vc4: Block swiotlb bounce buffers being imported as dmabuf See: raspberrypi/linux#5734
The dmabuf import already checks that the backing buffer is contiguous and rejects it if it isn't. vc4 also requires that the buffer is in the bottom 1GB of RAM, and this is all correctly defined via dma-ranges.
However the kernel silently uses swiotlb to bounce dma buffers around if they are in the wrong region. This relies on dma sync functions to be called in order to copy the data to/from the bounce buffer.
DRM is based on all memory allocations being coherent with the GPU so that any updates to a framebuffer will be acted on without the need for any additional update. This is fairly fundamentally incompatible with needing to call dma_sync_ to handle the bounce buffer copies, and therefore we have to detect and reject mappings that use bounce buffers.