From ca76137442edcafc089f19d189a55dc8d42ff7b8 Mon Sep 17 00:00:00 2001 From: Honglei Huang Date: Sat, 5 Sep 2026 21:31:37 +0800 Subject: [PATCH] drm/gpusvm: move dma_addr allocation before the notifier lock The dma_addr allocation was in a lazy allocation flow, it needs unlock and goto map_pages. The allocation only needs npages, so just do it before taking the lock. Drop the map_pages label and the relock flow, so the sequence becomes fault, allocate, then lock, validate, map and unlock. No functional change intended. Reviewed-by: Matthew Brost Signed-off-by: Honglei Huang Signed-off-by: Matthew Brost Link: https://patch.msgid.link/20260905133142.3628027-2-honghuan@amd.com --- drivers/gpu/drm/drm_gpusvm.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c index a93eee7ddb9e..b507de539e67 100644 --- a/drivers/gpu/drm/drm_gpusvm.c +++ b/drivers/gpu/drm/drm_gpusvm.c @@ -1516,10 +1516,18 @@ retry: if (err) goto err_free; + if (!svm_pages->dma_addr) { + svm_pages->dma_addr = + kvzalloc_objs(*svm_pages->dma_addr, npages); + if (!svm_pages->dma_addr) { + err = -ENOMEM; + goto err_free; + } + } + *state = (struct dma_iova_state){}; svm_pages->state_offset = 0; -map_pages: /* * Perform all dma mappings under the notifier lock to not * access freed pages. A notifier will either block on @@ -1540,18 +1548,6 @@ map_pages: goto retry; } - if (!svm_pages->dma_addr) { - /* Unlock and restart mapping to allocate memory. */ - drm_gpusvm_notifier_unlock(gpusvm); - svm_pages->dma_addr = - kvzalloc_objs(*svm_pages->dma_addr, npages); - if (!svm_pages->dma_addr) { - err = -ENOMEM; - goto err_free; - } - goto map_pages; - } - zdd = NULL; pagemap = NULL; num_dma_mapped = 0;