drm/i915/userptr: Try to acquire the page lock around set_page_dirty()
Subsystems (2)
PATCH 1/1 drm/i915/userptr: Try to acquire the page lock around set_page_dirty()
From: Fei Yang <[email protected]>
This is a backport of cee7fb437edcdb2f9f8affa959e274997f5dca4d to linux-4.4.y
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).
However, following a try_to_unmap() we may want to remove the userptr and so call put_pages(). However, try_to_unmap() acquires the page lock and so we must avoid recursively locking the pages ourselves -- which means that we cannot safely acquire the lock around set_page_dirty(). Since we can't be sure of the lock, we have to risk skip dirtying the page, or else risk calling set_page_dirty() without a lock and so risk fs corruption.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203317
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=112012
References: cb6d7c7dc7ff ("drm/i915/userptr: Acquire the page lock around set_page_dirty()")
References: 505a8ec7e11a ("Revert "drm/i915/userptr: Acquire the page lock around set_page_dirty()"")
References: 6dcc693bc57f ("ext4: warn when page is dirtied without buffers")
--- drivers/gpu/drm/i915/i915_gem_userptr.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem_userptr.c +21 -1
@@ -764,8 +764,28 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj)for_each_sg_page (obj->pages->sgl, &sg_iter, obj->pages->nents,0 ) {struct page *page =sg_page_iter_page (&sg_iter); -if (obj->dirty) +if (obj->dirty &&trylock_page (page)) { +/* +* As this may not be anonymous memory (e.g. shmem) +* but exist on a real mapping, we have to lock +* the page in order to dirty it -- holding +* the page reference is not sufficient to +* prevent the inode from being truncated. +* Play safe and take the lock. +* +* However...! +* +* The mmu-notifier can be invalidated for a +* migrate_page, that is alreadying holding the lock +* on the page. Such a try_to_unmap() will result +* in us calling put_pages() and so recursively try +* to lock the page. We avoid that deadlock with +* a trylock_page() and in exchange we risk missing +* some page dirtying. +*/ set_page_dirty (page); +unlock_page (page); + }mark_page_accessed (page);page_cache_release (page);
Signature · 6 lines
2.23.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BUILD: failure for drm/i915/userptr: Try to acquire the page lock around set_page_dirty() (rev2)
== Series Details ==
== Series Details ==
Series: drm/i915/userptr: Try to acquire the page lock around set_page_dirty() (rev2)
URL : https://patchwork.freedesktop.org/series/69037/
State : failure
== Summary ==
Applying: drm/i915/userptr: Try to acquire the page lock around set_page_dirty()
error: sha1 information is lacking or useless (drivers/gpu/drm/i915/i915_gem_userptr.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch' to see the failed patch
Patch failed at 0001 drm/i915/userptr: Try to acquire the page lock around set_page_dirty() When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx