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.
Signed-off-by: Honglei Huang <[email protected]> --- 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 507ef6f0a60e..3496cb568836 100644 --- a/drivers/gpu/drm/drm_gpusvm.c +++ b/drivers/gpu/drm/drm_gpusvm.c @@ -1551,10 +1551,18 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm, if (err) goto err_free; + if (!svm_pages->dma_addr) { + svm_pages->dma_addr = + kvmalloc_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 @@ -1575,18 +1583,6 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm, goto retry; } - if (!svm_pages->dma_addr) { - /* Unlock and restart mapping to allocate memory. */ - drm_gpusvm_notifier_unlock(gpusvm); - svm_pages->dma_addr = - kvmalloc_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; -- 2.34.1
