Skip to contentSkip to conversation

drm/amdgpu: use set_page_dirty_lock() when unpinning userptr pages

PATCH New Perry Yuan 1 participant 1 message Sep 2

Subsystems (2)
lore
Share & tools
lore

Perry Yuan

author
#0 lore raw

PATCH 1/1 drm/amdgpu: use set_page_dirty_lock() when unpinning userptr pages

amdgpu_ttm_tt_mark_user_pages() dirties pages obtained from get_user_pages() while holding only a page reference - no page lock, no page table lock. set_page_dirty() requires the caller to keep the folio from being truncated, otherwise the address_space can be freed between the folio_mapping() load and the ->dirty_folio() call.

Use set_page_dirty_lock(), which takes the folio lock around the update. The upstream gup helper unpin_user_pages_dirty_lock() does the same for this reason.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index 07f8854bc80c..4bc6ba074c23 100644
@@ -971,8 +971,9 @@ void amdgpu_ttm_tt_mark_user_pages(struct ttm_tt *ttm)
 		if (!page)
 			continue;
 
+		/* The caller does not hold the page lock. */
 		if (!(gtt->userflags & AMDGPU_GEM_USERPTR_READONLY))
-			set_page_dirty(page);
+			set_page_dirty_lock(page);
 
 		mark_page_accessed(page);
 	}
Signature · 1 line
2.34.1