FAILED: patch "[PATCH] drm/virtio: use uninterruptible resv lock for plane updates" failed to apply to 5.10-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x a48bbcc7ac739e93562d6148c6fa504c2e9f22f8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072938-nearby-drab-19c2@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From a48bbcc7ac739e93562d6148c6fa504c2e9f22f8 Mon Sep 17 00:00:00 2001
From: Deepanshu Kartikey <[email protected]>
Date: Tue, 19 May 2026 13:52:47 +0530
Subject: [PATCH] drm/virtio: use uninterruptible resv lock for plane updates
virtio_gpu_cursor_plane_update() and virtio_gpu_resource_flush() lock the framebuffer BO's dma_resv via virtio_gpu_array_lock_resv() and ignore its return value. The function can fail with -EINTR from dma_resv_lock_interruptible() (signal during lock wait) or with -ENOMEM from dma_resv_reserve_fences() (fence slot allocation), leaving the resv lock not held. The queue path then walks the object array and calls dma_resv_add_fence(), which requires the lock held; with lockdep enabled this trips dma_resv_assert_held():
WARNING: drivers/dma-buf/dma-resv.c:296 at dma_resv_add_fence+0x71e/0x840 Call Trace: virtio_gpu_array_add_fence virtio_gpu_queue_ctrl_sgs virtio_gpu_queue_fenced_ctrl_buffer virtio_gpu_cursor_plane_update drm_atomic_helper_commit_planes drm_atomic_helper_commit_tail commit_tail drm_atomic_helper_commit drm_atomic_commit drm_atomic_helper_update_plane __setplane_atomic drm_mode_cursor_universal drm_mode_cursor_common drm_mode_cursor_ioctl drm_ioctl __x64_sys_ioctl
Beyond the WARN, mutating the dma_resv fence list without the lock races with concurrent readers/writers and can corrupt the list.
Both call sites run inside the .atomic_update plane callback, which DRM atomic helpers do not allow to fail (by the time it runs, the commit has been signed off to userspace and there is no clean rollback path). Moving the lock acquisition to .prepare_fb was rejected because the broader lock scope deadlocks against other BO locking paths in the same atomic commit.
Introduce virtio_gpu_lock_one_resv_uninterruptible() that uses dma_resv_lock() instead of dma_resv_lock_interruptible(). This eliminates the -EINTR failure mode -- the realistic syzbot trigger -- without extending the lock hold across the commit. The helper locks a single BO and rejects nents > 1 with -EINVAL; both fix sites lock exactly one BO.
Use it from virtio_gpu_cursor_plane_update() and virtio_gpu_resource_flush(); check the return value to handle the remaining -ENOMEM case from dma_resv_reserve_fences() by freeing the objs and skipping the plane update for that frame. The framebuffer BOs touched here are not shared with other contexts and lock contention is expected to be brief, so the loss of signal-interruptibility is acceptable.
Other callers of virtio_gpu_array_lock_resv() (the ioctl paths) continue to use the interruptible variant.
The bug was reported by syzbot, triggered via fault injection (fail_nth) on the DRM_IOCTL_MODE_CURSOR path, which forces the -ENOMEM branch in dma_resv_reserve_fences().
drivers/gpu/drm/virtio/virtgpu_drv.h +1 -0
@@ -320,6 +320,7 @@ virtio_gpu_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nentsvoid virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs,struct drm_gem_object *obj);int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs); +int virtio_gpu_lock_one_resv_uninterruptible (struct virtio_gpu_object_array *objs);void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs);void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs,struct dma_fence *fence);
drivers/gpu/drm/virtio/virtgpu_gem.c +17 -0
@@ -238,6 +238,23 @@ int virtio_gpu_array_lock_resv(struct virtio_gpu_object_array *objs)return ret; } +int virtio_gpu_lock_one_resv_uninterruptible (struct virtio_gpu_object_array *objs) +{ +int ret; + +if (objs->nents !=1 ) +return -EINVAL ; + +dma_resv_lock (objs->objs[0 ]->resv,NULL ); + + ret =dma_resv_reserve_fences (objs->objs[0 ]->resv,1 ); +if (ret) { +virtio_gpu_array_unlock_resv (objs); +return ret; + } +return 0 ; +} +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs) {if (objs->nents ==1 ) {
drivers/gpu/drm/virtio/virtgpu_plane.c +8 -2
@@ -215,7 +215,10 @@ static void virtio_gpu_resource_flush(struct drm_plane *plane,if (!objs)return ;virtio_gpu_array_add_obj (objs, vgfb->base.obj[0 ]); -virtio_gpu_array_lock_resv (objs); +if (virtio_gpu_lock_one_resv_uninterruptible (objs)) { +virtio_gpu_array_put_free (objs); +return ; + }virtio_gpu_cmd_resource_flush (vgdev, bo->hw_res_handle, x, y, width, height, objs, vgplane_st->fence);
@@ -459,7 +462,10 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,if (!objs)return ;virtio_gpu_array_add_obj (objs, vgfb->base.obj[0 ]); -virtio_gpu_array_lock_resv (objs); +if (virtio_gpu_lock_one_resv_uninterruptible (objs)) { +virtio_gpu_array_put_free (objs); +return ; + } virtio_gpu_cmd_transfer_to_host_2d (vgdev, 0, plane->state->crtc_w,
Sasha Levin
maintainerPATCH 1/2 dma-buf/drivers: make reserving a shared slot mandatory v4
From: Christian König <[email protected]>
[ Upstream commit c8d4c18bfbc4ab467188dbe45cc8155759f49d9e ]
Audit all the users of dma_resv_add_excl_fence() and make sure they reserve a shared slot also when only trying to add an exclusive fence.
This is the next step towards handling the exclusive fence like a shared one.
v2: fix missed case in amdgpu
v3: and two more radeon, rename function
v4: add one more case to TTM, fix i915 after rebase
Stable-dep-of: a48bbcc7ac73 ("drm/virtio: use uninterruptible resv lock for plane updates")
--- drivers/dma-buf/dma-resv.c | 8 ++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/i915/i915_vma.c | 2 +- drivers/gpu/drm/lima/lima_gem.c | 2 +- drivers/gpu/drm/msm/msm_gem_submit.c | 2 +- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- drivers/gpu/drm/qxl/qxl_release.c | 2 +- drivers/gpu/drm/radeon/radeon_vm.c | 2 +- drivers/gpu/drm/ttm/ttm_bo.c | 4 ++-- drivers/gpu/drm/ttm/ttm_execbuf_util.c | 4 ++-- drivers/gpu/drm/vc4/vc4_gem.c | 2 +- drivers/gpu/drm/vgem/vgem_fence.c | 2 +- include/linux/dma-resv.h | 2 +- 15 files changed, 21 insertions(+), 21 deletions(-)
drivers/dma-buf/dma-resv.c +4 -4
@@ -173,7 +173,7 @@ void dma_resv_fini(struct dma_resv *obj)EXPORT_SYMBOL (dma_resv_fini);/** -* dma_resv_reserve_shared - Reserve space to add shared fences to +* dma_resv_reserve_fences - Reserve space to add shared fences to * a dma_resv. * @obj: reservation object * @num_fences: number of fences we want to add
@@ -184,7 +184,7 @@ EXPORT_SYMBOL(dma_resv_fini);* RETURNS * Zero for success, or -errno */ -int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences) +int dma_resv_reserve_fences (struct dma_resv *obj,unsigned int num_fences) {struct dma_resv_list *old, *new;unsigned int i, j, k, max;
@@ -250,7 +250,7 @@ int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences)return 0 ; } -EXPORT_SYMBOL (dma_resv_reserve_shared); +EXPORT_SYMBOL (dma_resv_reserve_fences);/** * dma_resv_add_shared_fence - Add a fence to a shared slot
@@ -258,7 +258,7 @@ EXPORT_SYMBOL(dma_resv_reserve_shared);* @fence: the shared fence to add * * Add a fence to a shared slot, obj->lock must be held, and -* dma_resv_reserve_shared() has been called. +* dma_resv_reserve_fences() has been called. */ void dma_resv_add_shared_fence (struct dma_resv *obj,struct dma_fence *fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -2
@@ -950,7 +950,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, AMDGPU_FENCE_OWNER_KFD, false);if (ret) goto wait_pd_fail; - ret =dma_resv_reserve_shared (vm->root.base.bo->tbo.base.resv,1 ); + ret =dma_resv_reserve_fences (vm->root.base.bo->tbo.base.resv,1 );if (ret) goto reserve_shared_fail; amdgpu_bo_fence(vm->root.base.bo,
@@ -2205,7 +2205,7 @@ int amdgpu_amdkfd_add_gws_to_process(void *info, void *gws, struct kgd_mem **mem* Add process eviction fence to bo so they can * evict each other. */ - ret =dma_resv_reserve_shared (gws_bo->tbo.base.resv,1 ); + ret =dma_resv_reserve_fences (gws_bo->tbo.base.resv,1 );if (ret) goto reserve_shared_fail;amdgpu_bo_fence (gws_bo, &process_info->eviction_fence->base, true);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -2904,7 +2904,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (r) goto error_free_root; - r =dma_resv_reserve_shared (root->tbo.base.resv,1 ); + r =dma_resv_reserve_fences (root->tbo.base.resv,1 );if (r) goto error_unreserve;
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
@@ -180,7 +180,7 @@ static int submit_fence_sync(struct etnaviv_gem_submit *submit)struct dma_resv *robj = bo->obj->base.resv;if (!(bo->flags &ETNA_SUBMIT_BO_WRITE )) { - ret =dma_resv_reserve_shared (robj,1 ); + ret =dma_resv_reserve_fences (robj,1 );if (ret)return ret; }
drivers/gpu/drm/i915/i915_vma.c +1 -1
@@ -1241,7 +1241,7 @@ int i915_vma_move_to_active(struct i915_vma *vma, obj->write_domain =I915_GEM_DOMAIN_RENDER ; obj->read_domains =0 ; }else { - err =dma_resv_reserve_shared (vma->resv,1 ); + err =dma_resv_reserve_fences (vma->resv,1 );if (unlikely (err))return err;
drivers/gpu/drm/lima/lima_gem.c +1 -1
@@ -263,7 +263,7 @@ static int lima_gem_sync_bo(struct lima_sched_task *task, struct lima_bo *bo,int err =0 ;if (!write) { - err =dma_resv_reserve_shared (lima_bo_resv (bo),1 ); + err =dma_resv_reserve_fences (lima_bo_resv (bo),1 );if (err)return err; }
drivers/gpu/drm/msm/msm_gem_submit.c +1 -1
@@ -230,7 +230,7 @@ static int submit_fence_sync(struct msm_gem_submit *submit, bool no_implicit)* strange place to call it. OTOH this is a * convenient can-fail point to hook it in. */ - ret =dma_resv_reserve_shared (msm_obj->base.resv, + ret =dma_resv_reserve_fences (msm_obj->base.resv,1 );if (ret)return ret;
drivers/gpu/drm/nouveau/nouveau_fence.c +1 -1
@@ -349,7 +349,7 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool eint ret =0 , i;if (!exclusive) { - ret =dma_resv_reserve_shared (resv,1 ); + ret =dma_resv_reserve_fences (resv,1 );if (ret)return ret;
drivers/gpu/drm/qxl/qxl_release.c +1 -1
@@ -239,7 +239,7 @@ static int qxl_release_validate_bo(struct qxl_bo *bo)return ret; } - ret =dma_resv_reserve_shared (bo->tbo.base.resv,1 ); + ret =dma_resv_reserve_fences (bo->tbo.base.resv,1 );if (ret)return ret;
drivers/gpu/drm/radeon/radeon_vm.c +1 -1
@@ -831,7 +831,7 @@ static int radeon_vm_update_ptes(struct radeon_device *rdev,int r;radeon_sync_resv (rdev, &ib->sync, pt->tbo.base.resv, true); - r =dma_resv_reserve_shared (pt->tbo.base.resv,1 ); + r =dma_resv_reserve_fences (pt->tbo.base.resv,1 );if (r)return r;
drivers/gpu/drm/ttm/ttm_bo.c +2 -2
@@ -830,7 +830,7 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo,dma_resv_add_shared_fence (bo->base.resv, fence); - ret =dma_resv_reserve_shared (bo->base.resv,1 ); + ret =dma_resv_reserve_fences (bo->base.resv,1 );if (unlikely (ret)) {dma_fence_put (fence);return ret;
@@ -950,7 +950,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,bool type_found = false;int i, ret; - ret =dma_resv_reserve_shared (bo->base.resv,1 ); + ret =dma_resv_reserve_fences (bo->base.resv,1 );if (unlikely (ret))return ret;
drivers/gpu/drm/ttm/ttm_execbuf_util.c +2 -2
@@ -106,7 +106,7 @@ int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,if (!entry->num_shared)continue ; - ret =dma_resv_reserve_shared (bo->base.resv, + ret =dma_resv_reserve_fences (bo->base.resv, entry->num_shared);if (!ret)continue ;
@@ -123,7 +123,7 @@ int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket, }if (!ret && entry->num_shared) - ret =dma_resv_reserve_shared (bo->base.resv, + ret =dma_resv_reserve_fences (bo->base.resv, entry->num_shared);if (unlikely (ret !=0 )) {
drivers/gpu/drm/vc4/vc4_gem.c +1 -1
@@ -644,7 +644,7 @@ vc4_lock_bo_reservations(struct drm_device *dev,for (i =0 ; i < exec->bo_count; i++) { bo = &exec->bo[i]->base; - ret =dma_resv_reserve_shared (bo->resv,1 ); + ret =dma_resv_reserve_fences (bo->resv,1 );if (ret) {vc4_unlock_bo_reservations (dev, exec, acquire_ctx);return ret;
drivers/gpu/drm/vgem/vgem_fence.c +1 -1
@@ -162,7 +162,7 @@ int vgem_fence_attach_ioctl(struct drm_device *dev,dma_resv_lock (resv,NULL );if (arg->flags &VGEM_FENCE_WRITE )dma_resv_add_excl_fence (resv, fence); -else if ((ret =dma_resv_reserve_shared (resv,1 )) ==0 ) +else if ((ret =dma_resv_reserve_fences (resv,1 )) ==0 )dma_resv_add_shared_fence (resv, fence);dma_resv_unlock (resv);
include/linux/dma-resv.h +1 -1
@@ -273,7 +273,7 @@ dma_resv_get_excl_rcu(struct dma_resv *obj)void dma_resv_init (struct dma_resv *obj);void dma_resv_fini (struct dma_resv *obj); -int dma_resv_reserve_shared (struct dma_resv *obj,unsigned int num_fences); +int dma_resv_reserve_fences (struct dma_resv *obj,unsigned int num_fences);void dma_resv_add_shared_fence (struct dma_resv *obj,struct dma_fence *fence);void dma_resv_add_excl_fence (struct dma_resv *obj,struct dma_fence *fence);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 drm/virtio: use uninterruptible resv lock for plane updates
From: Deepanshu Kartikey <[email protected]>
[ Upstream commit a48bbcc7ac739e93562d6148c6fa504c2e9f22f8 ]
virtio_gpu_cursor_plane_update() and virtio_gpu_resource_flush() lock the framebuffer BO's dma_resv via virtio_gpu_array_lock_resv() and ignore its return value. The function can fail with -EINTR from dma_resv_lock_interruptible() (signal during lock wait) or with -ENOMEM from dma_resv_reserve_fences() (fence slot allocation), leaving the resv lock not held. The queue path then walks the object array and calls dma_resv_add_fence(), which requires the lock held; with lockdep enabled this trips dma_resv_assert_held():
WARNING: drivers/dma-buf/dma-resv.c:296 at dma_resv_add_fence+0x71e/0x840 Call Trace: virtio_gpu_array_add_fence virtio_gpu_queue_ctrl_sgs virtio_gpu_queue_fenced_ctrl_buffer virtio_gpu_cursor_plane_update drm_atomic_helper_commit_planes drm_atomic_helper_commit_tail commit_tail drm_atomic_helper_commit drm_atomic_commit drm_atomic_helper_update_plane __setplane_atomic drm_mode_cursor_universal drm_mode_cursor_common drm_mode_cursor_ioctl drm_ioctl __x64_sys_ioctl
Beyond the WARN, mutating the dma_resv fence list without the lock races with concurrent readers/writers and can corrupt the list.
Both call sites run inside the .atomic_update plane callback, which DRM atomic helpers do not allow to fail (by the time it runs, the commit has been signed off to userspace and there is no clean rollback path). Moving the lock acquisition to .prepare_fb was rejected because the broader lock scope deadlocks against other BO locking paths in the same atomic commit.
Introduce virtio_gpu_lock_one_resv_uninterruptible() that uses dma_resv_lock() instead of dma_resv_lock_interruptible(). This eliminates the -EINTR failure mode -- the realistic syzbot trigger -- without extending the lock hold across the commit. The helper locks a single BO and rejects nents > 1 with -EINVAL; both fix sites lock exactly one BO.
Use it from virtio_gpu_cursor_plane_update() and virtio_gpu_resource_flush(); check the return value to handle the remaining -ENOMEM case from dma_resv_reserve_fences() by freeing the objs and skipping the plane update for that frame. The framebuffer BOs touched here are not shared with other contexts and lock contention is expected to be brief, so the loss of signal-interruptibility is acceptable.
Other callers of virtio_gpu_array_lock_resv() (the ioctl paths) continue to use the interruptible variant.
The bug was reported by syzbot, triggered via fault injection (fail_nth) on the DRM_IOCTL_MODE_CURSOR path, which forces the -ENOMEM branch in dma_resv_reserve_fences().
--- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_gem.c | 17 +++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_plane.c | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +1 -0
@@ -259,6 +259,7 @@ virtio_gpu_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nentsvoid virtio_gpu_array_add_obj (struct virtio_gpu_object_array *objs,struct drm_gem_object *obj);int virtio_gpu_array_lock_resv (struct virtio_gpu_object_array *objs); +int virtio_gpu_lock_one_resv_uninterruptible (struct virtio_gpu_object_array *objs);void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs);void virtio_gpu_array_add_fence (struct virtio_gpu_object_array *objs,struct dma_fence *fence);
drivers/gpu/drm/virtio/virtgpu_gem.c +17 -0
@@ -217,6 +217,23 @@ int virtio_gpu_array_lock_resv(struct virtio_gpu_object_array *objs)return ret; } +int virtio_gpu_lock_one_resv_uninterruptible (struct virtio_gpu_object_array *objs) +{ +int ret; + +if (objs->nents !=1 ) +return -EINVAL ; + +dma_resv_lock (objs->objs[0 ]->resv,NULL ); + + ret =dma_resv_reserve_fences (objs->objs[0 ]->resv,1 ); +if (ret) { +virtio_gpu_array_unlock_resv (objs); +return ret; + } +return 0 ; +} +void virtio_gpu_array_unlock_resv (struct virtio_gpu_object_array *objs) {if (objs->nents ==1 ) {
drivers/gpu/drm/virtio/virtgpu_plane.c +4 -1
@@ -260,7 +260,10 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,if (!objs)return ;virtio_gpu_array_add_obj (objs, vgfb->base.obj[0 ]); -virtio_gpu_array_lock_resv (objs); +if (virtio_gpu_lock_one_resv_uninterruptible (objs)) { +virtio_gpu_array_put_free (objs); +return ; + } virtio_gpu_cmd_transfer_to_host_2d (vgdev, 0, plane->state->crtc_w,
Signature · 1 line
2.53.0