From af14c37bf19068ed5a41af99438e4119b93ba7d7 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 28 Oct 2025 10:49:51 +0100 Subject: [PATCH] pan/kmod: Enforce PAN_KMOD_BO_FLAG_NO_MMAP Fail early in pan_kmod_bo_mmap() if PAN_KMOD_BO_FLAG_NO_MMAP is set. This saves us a user -> kernel round-trip, but most importantly, it allows us to enforce NO_MMAP at the userspace level on BOs that the kernel would otherwise accept to mmap() (mapping of imported BOs requires extra DMA_BUF_IOCTL_SYNC calls we don't have). Signed-off-by: Boris Brezillon Reviewed-by: Christoph Pillmayer Part-of: --- src/panfrost/lib/kmod/pan_kmod.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/panfrost/lib/kmod/pan_kmod.h b/src/panfrost/lib/kmod/pan_kmod.h index da016078e59..145d4123916 100644 --- a/src/panfrost/lib/kmod/pan_kmod.h +++ b/src/panfrost/lib/kmod/pan_kmod.h @@ -648,6 +648,10 @@ pan_kmod_bo_mmap(struct pan_kmod_bo *bo, off_t bo_offset, size_t size, int prot, { off_t mmap_offset; + /* Don't bother trying an mmap() if it's not allowed. */ + if (bo->flags & PAN_KMOD_BO_FLAG_NO_MMAP) + return MAP_FAILED; + if ((uint64_t)bo_offset + (uint64_t)size > bo->size) return MAP_FAILED;