All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] drm/amdkfd: honor read-only intent for userptr and SVM ranges
@ 2026-11-17  4:20 Junhua Shen
  2026-11-17  4:20 ` [PATCH v1 1/2] drm/amdgpu: map KFD userptr read-only when the BO is not writable Junhua Shen
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Junhua Shen @ 2026-11-17  4:20 UTC (permalink / raw)
  To: Philip Yang, Felix Kuehling, Alex Deucher, Christian König,
	amd-gfx
  Cc: Chris Freehill, Kent Russell, Maneesh Gupta, Denny Iriawan,
	David Yat Sin, Huang Rui, Jenny Liu, Zhu Lingshan, Honglei Huang,
	Yiru Ma, Junhua Shen

KFD records whether an allocation or SVM range is writable
(KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE for userptr, KFD_IOCTL_SVM_FLAG_GPU_RO
for SVM) and already honors it when building the GPUVM page table. The
userptr registration and the SVM mapping path, however, do not pass that
intent down to the HMM fault, so hmm_range_fault() is asked for write
access even for a read-only buffer.

For a read-only buffer backed by a writable private mapping
(PROT_READ|PROT_WRITE, MAP_PRIVATE) that the GPU only reads, e.g. a
host-to-device copy source, faulting for write breaks COW: every page is
copied into anonymous memory, which doubles the footprint and, because
the copy changes the CPU page tables, fires an MMU-notifier invalidation
that evicts the GPU user-mode queues.

To keep the GPU mapping consistent with the requested permission, this
series makes the HMM fault honor the same read-only intent:

 - Patch 1 (userptr): register the userptr read-only when the allocation
   did not request KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE.
 - Patch 2 (SVM): also honor KFD_IOCTL_SVM_FLAG_GPU_RO instead of deriving
   read-only solely from the VMA write permission.

This does not change what the GPU can access: the page table already maps
a read-only allocation without write permission, so a GPU write to it
already faults, with or without this series. The series only aligns the
HMM fault with that page table and drops the needless write fault and COW.
A buffer the GPU may write must still be allocated writable; there is no
in-place upgrade, so making a buffer writable means freeing and
re-allocating it.

The user-space side that marks such buffers read-only is tracked here:
Link: https://github.com/ROCm/rocm-systems/pull/15545

Junhua Shen (2):
  drm/amdgpu: map KFD userptr read-only when the BO is not writable
  drm/amdkfd: honor KFD_IOCTL_SVM_FLAG_GPU_RO for read-only SVM ranges

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +++-
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c             | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)


base-commit: 067c5c24cef23d913b67eaaf71ae67e7169a6620
-- 
2.53.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-17 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  4:20 [PATCH v1 0/2] drm/amdkfd: honor read-only intent for userptr and SVM ranges Junhua Shen
2026-11-17  4:20 ` [PATCH v1 1/2] drm/amdgpu: map KFD userptr read-only when the BO is not writable Junhua Shen
2026-11-17  4:30   ` sashiko-bot
2026-11-17  4:20 ` [PATCH v1 2/2] drm/amdkfd: honor KFD_IOCTL_SVM_FLAG_GPU_RO for read-only SVM ranges Junhua Shen
2026-11-17  4:42   ` sashiko-bot
2026-11-17 17:21 ` [PATCH v1 0/2] drm/amdkfd: honor read-only intent for userptr and " Philip Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.