From 7ee55d3a5ff4e8c821e39183e1f0e5d0fb778e26 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 3 Mar 2026 17:31:16 +0100 Subject: [PATCH] pan/kmod: Allow mmap() on foreign buffers If the BO comes from a different subsystem (args.extra_flags & DRM_PANTHOR_BO_IS_IMPORTED), we should normally add extra DMA_BUF_IOCTL_SYNC calls around CPU accesses to ensure the CPU mapping consistency, but this is something we never worried about (we've always assumed exporters were exposing uncached mappings with NOP {begin,end}_cpu_access() implementations), and it worked fine until now. The long term plan is to hook up DMA_BUF_IOCTL_SYNC, but this requires more work, and we need a quick fix that can be backported easily, hence this revert+FIXME. Fixes: b5e47ba89414 ("pan/kmod: Add new helpers to sync BO CPU mappings") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14963 Closes: https://gitlab.freedesktop.org/panfrost/mesa/-/issues/282 Closes: https://gitlab.freedesktop.org/wayland/weston/-/issues/1101 Signed-off-by: Boris Brezillon Reviewed-by: Yiwei Zhang Acked-by: Lars-Ivar Hesselberg Simonsen Acked-by: Erik Faye-Lund Reviewed-by: Daniel Stone (cherry picked from commit 30f1d5bab94af1c187a5e533df1c64dced501625) Part-of: --- .pick_status.json | 2 +- src/panfrost/lib/kmod/panfrost_kmod.c | 13 +++++++++---- src/panfrost/lib/kmod/panthor_kmod.c | 13 +++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 62417940e14..792cd6d0919 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3484,7 +3484,7 @@ "description": "pan/kmod: Allow mmap() on foreign buffers", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "b5e47ba8941467a4e2f53907a6645a0703852e62", "notes": null diff --git a/src/panfrost/lib/kmod/panfrost_kmod.c b/src/panfrost/lib/kmod/panfrost_kmod.c index e834b18e14d..b00c5f2853a 100644 --- a/src/panfrost/lib/kmod/panfrost_kmod.c +++ b/src/panfrost/lib/kmod/panfrost_kmod.c @@ -350,11 +350,16 @@ panfrost_kmod_bo_import(struct pan_kmod_dev *dev, uint32_t handle, uint64_t size goto err_free_bo; } - /* If the BO comes from a different subsystem, we don't allow - * mmap() to avoid the CPU-sync churn. + /* FIXME: If the BO comes from a different subsystem + * (args.extra_flags & DRM_PANTHOR_BO_IS_IMPORTED), we should normally + * add extra DMA_BUF_IOCTL_SYNC calls around CPU accesses to ensure the + * CPU mapping consistency, but this is something we never worried about + * (we've always assumed exporters were exposing uncached mappings with + * NOP {begin,end}_cpu_access() implementations), and it worked fine until + * now. + * The long term plan is to hook up DMA_BUF_IOCTL_SYNC, but this requires + * more work. */ - if (args.extra_flags & DRM_PANFROST_BO_IS_IMPORTED) - flags |= PAN_KMOD_BO_FLAG_NO_MMAP; } pan_kmod_bo_init(&panfrost_bo->base, dev, NULL, size, diff --git a/src/panfrost/lib/kmod/panthor_kmod.c b/src/panfrost/lib/kmod/panthor_kmod.c index 37013dea836..c958de188eb 100644 --- a/src/panfrost/lib/kmod/panthor_kmod.c +++ b/src/panfrost/lib/kmod/panthor_kmod.c @@ -445,11 +445,16 @@ panthor_kmod_bo_import(struct pan_kmod_dev *dev, uint32_t handle, uint64_t size, goto err_free_bo; } - /* If the BO comes from a different subsystem, we don't allow - * mmap() to avoid the CPU-sync churn. + /* FIXME: If the BO comes from a different subsystem + * (args.extra_flags & DRM_PANTHOR_BO_IS_IMPORTED), we should normally + * add extra DMA_BUF_IOCTL_SYNC calls around CPU accesses to ensure the + * CPU mapping consistency, but this is something we never worried about + * (we've always assumed exporters were exposing uncached mappings with + * NOP {begin,end}_cpu_access() implementations), and it worked fine until + * now. + * The long term plan is to hook up DMA_BUF_IOCTL_SYNC, but this requires + * more work. */ - if (args.extra_flags & DRM_PANTHOR_BO_IS_IMPORTED) - flags |= PAN_KMOD_BO_FLAG_NO_MMAP; } /* Create a unsignalled syncobj on import. Will serve as a