Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/i915/gem: missing folio_unlock() after redirty in
  __shmem_writeback()
- [High] drm/i915/gem: invalid dirty-tag writeback helpers in
  __shmem_writeback()
--

commit eee676ed22d7c6fdff448f68a9e29b819f5d0c1e
Author: Kiryl Shutsemau (Meta) <[email protected]>

drm/i915/gem: Skip writeback of shmem folios with extra references

This commit skips shmem writeback in __shmem_writeback() for folios that
carry references beyond the page cache and writeback_iter(), avoiding
writeback while an unmapped PMD may still have pending stores through a
stale TLB entry.

> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c 
> b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> index bf9e7480f0f54..748772c358acd 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> @@ -316,9 +316,15 @@ void __shmem_writeback(size_t size, struct address_space 
> *mapping)
>        * leaving only CPU mmapings around) and add those folios to the LRU
>        * instead of invoking writeback so they are aged and paged out
>        * as normal.
> +      *
> +      * The same goes for a folio with references beyond the page cache
> +      * and writeback_iter(). A folio that was just unmapped can still be
> +      * written through a stale TLB entry until the unmapping side flushes
> +      * the TLB and drops its reference. pageout() checks the same.
>        */
>       while ((folio = writeback_iter(mapping, &wbc, folio, &error))) {
> -             if (folio_mapped(folio))
> +             if (folio_mapped(folio) ||
> +                 folio_ref_count(folio) != 1 + folio_nr_pages(folio))
>                       folio_redirty_for_writepage(&wbc, folio);
>               else
>                       error = shmem_write_folio(folio);

[Severity: High]
Does skipping writeback here leave the folio locked?

writeback_iter() returns the folio locked via writeback_get_folio(), and
neither folio_redirty_for_writepage() nor the next writeback_iter() call
unlocks it.  Routing unmapped folios with extra references into the
folio_redirty_for_writepage() branch without calling folio_unlock() leaves
PG_locked set permanently, deadlocking later faults, reclaim or truncation
on that folio.

[Severity: High]
Can writeback_iter() and folio_redirty_for_writepage() be used on a shmem
mapping?

writeback_get_folio() looks up folios by PAGECACHE_TAG_DIRTY, but
shmem_aops uses noop_dirty_folio, which sets PG_dirty without tagging
mapping->i_pages.  As a result, writeback_iter() never finds dirty shmem
folios, and calling folio_redirty_for_writepage() on a shmem folio reaches
__folio_mark_dirty(), which triggers:

mm/page-writeback.c:__folio_mark_dirty() {
        ...
        /*
         * Shmem writeback relies on swap, and swap writeback is LRU based,
         * not using the dirty mark.
         */
        VM_WARN_ON_ONCE(folio_test_swapcache(folio) || shmem_mapping(mapping));
        ...
}

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to