drm/vc4: Protect madv read in vc4_gem_object_mmap() with madv_lock

[ Upstream commit 338c56050d ]

The mmap callback reads bo->madv without holding madv_lock, racing with
concurrent DRM_IOCTL_VC4_GEM_MADVISE calls that modify the field under
the same lock. Add the missing locking to prevent the data race.

Fixes: b9f19259b8 ("drm/vc4: Add the DRM_IOCTL_VC4_GEM_MADVISE ioctl")
Reviewed-by: Melissa Wen <mwen@igalia.com>
Link: https://patch.msgid.link/20260330-vc4-misc-fixes-v1-4-92defc940a29@igalia.com
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Maíra Canal
2026-03-30 14:51:46 -03:00
committed by Greg Kroah-Hartman
parent c197def383
commit d868edbc1e
+3
View File
@@ -719,12 +719,15 @@ int vc4_mmap(struct file *filp, struct vm_area_struct *vma)
return -EINVAL;
}
mutex_lock(&bo->madv_lock);
if (bo->madv != VC4_MADV_WILLNEED) {
DRM_DEBUG("mmaping of %s BO not allowed\n",
bo->madv == VC4_MADV_DONTNEED ?
"purgeable" : "purged");
mutex_unlock(&bo->madv_lock);
return -EINVAL;
}
mutex_unlock(&bo->madv_lock);
/*
* Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the