Skip to content

Commit aa56a29

Browse files
icklejnikula
authored andcommitted
drm/i915/userptr: Acquire the page lock around set_page_dirty()
set_page_dirty says: For pages with a mapping this should be done under the page lock for the benefit of asynchronous memory errors who prefer a consistent dirty state. This rule can be broken in some special cases, but should be better not to. Under those rules, it is only safe for us to use the plain set_page_dirty calls for shmemfs/anonymous memory. Userptr may be used with real mappings and so needs to use the locked version (set_page_dirty_lock). Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203317 Fixes: 5cc9ed4 ("drm/i915: Introduce mapping of user pages into video memory (userptr) ioctl") References: 6dcc693 ("ext4: warn when page is dirtied without buffers") Signed-off-by: Chris Wilson <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Cc: [email protected] Reviewed-by: Tvrtko Ursulin <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit cb6d7c7) Signed-off-by: Jani Nikula <[email protected]>
1 parent 5f4c82c commit aa56a29

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/gpu/drm/i915/gem/i915_gem_userptr.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,15 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,
664664

665665
for_each_sgt_page(page, sgt_iter, pages) {
666666
if (obj->mm.dirty)
667-
set_page_dirty(page);
667+
/*
668+
* As this may not be anonymous memory (e.g. shmem)
669+
* but exist on a real mapping, we have to lock
670+
* the page in order to dirty it -- holding
671+
* the page reference is not sufficient to
672+
* prevent the inode from being truncated.
673+
* Play safe and take the lock.
674+
*/
675+
set_page_dirty_lock(page);
668676

669677
mark_page_accessed(page);
670678
put_page(page);

0 commit comments

Comments
 (0)