Skip to content

Commit cb6d7c7

Browse files
committed
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]
1 parent baf08ed commit cb6d7c7

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
@@ -665,7 +665,15 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,
665665

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

670678
mark_page_accessed(page);
671679
put_page(page);

0 commit comments

Comments
 (0)