drm/panthor: Fix the user MMIO offset logic for emulators
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 6 Jun 2025 08:09:32 +0000 (10:09 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Fri, 6 Jun 2025 09:36:08 +0000 (11:36 +0200)
commit94ac529a9932654c0b8cbff29745c8417978a7d0
tree44aa1a90d4efbb5ca9d10398cc002e332d701e1a
parent95cbab48782bf62e4093837dc15ac6133902c12f
drm/panthor: Fix the user MMIO offset logic for emulators

Currently, we pick the MMIO offset based on the size of the pgoff_t
type seen by the process that manipulates the FD, such that a 32-bit
process can always map the user MMIO ranges. But this approach doesn't
work well for emulators like FEX, where the emulator is a 64-bit binary
which might be executing 32-bit code. In that case, the kernel thinks
it's the 64-bit process and assumes DRM_PANTHOR_USER_MMIO_OFFSET_64BIT
is in use, but the UMD library expects DRM_PANTHOR_USER_MMIO_OFFSET_32BIT,
because it can't mmap() anything above the pgoff_t size.

In order to solve that, we need a way to explicitly set the user MMIO
offset from the UMD, such that the kernel doesn't have to guess it
from the TIF_32BIT flag set on user thread. We keep the old behavior
if DRM_PANTHOR_SET_USER_MMIO_OFFSET is never called.

Changes in v2:
- Drop the lock/immutable fields and allow SET_USER_MMIO_OFFSET
  requests to race with mmap() requests
- Don't do the is_user_mmio_offset test twice in panthor_mmap()
- Improve the uAPI docs

Changes in v3:
- Bump to version 1.5 instead of 1.4 after rebasing
- Add R-bs
- Fix/rephrase comment as suggested by Liviu

Reviewed-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Link: https://lore.kernel.org/r/20250606080932.4140010-3-boris.brezillon@collabora.com
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
drivers/gpu/drm/panthor/panthor_device.h
drivers/gpu/drm/panthor/panthor_drv.c
include/uapi/drm/panthor_drm.h