* [PATCH] drm/i915/gem: Skip writeback of shmem folios with extra references
@ 2026-11-19 13:42 Kiryl Shutsemau (Meta)
2026-11-19 17:43 ` Andi Shyti
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Kiryl Shutsemau (Meta) @ 2026-11-19 13:42 UTC (permalink / raw)
To: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin
Cc: Kiryl Shutsemau (Meta), David Airlie, Simona Vetter, Andi Shyti,
David Hildenbrand, Hugh Dickins, Baolin Wang, intel-gfx,
dri-devel, linux-mm, linux-kernel, kernel-team
__shmem_writeback() writes out every dirty folio that is not mapped. A
folio stops being mapped when munmap() removes its rmap, but the TLB
flush comes later. Until then another thread can still store to it
through a stale TLB entry:
CPU0 (munmap) CPU1 (same mm) CPU2 (i915 shrinker)
zap_huge_pmd()
folio_remove_rmap_pmd()
__shmem_writeback()
clear dirty
!folio_mapped()
shmem_write_folio()
store via stale TLB
tlb_finish_mmu()
The store leaves the folio clean in the swap cache. Once reclaim frees
it, the object reads back from swap without that store.
The legacy mmap ioctl maps the shmem file directly, and i915 mounts it
with huge=within_size on some platforms, so the folio can be PMD-mapped.
The core mm keeps the rmap until after the flush for PTEs, but not for
shmem PMDs: shmem has no writeback, and pageout() refuses a folio with
an extra reference.
Do the same here. The unmapping side holds its reference until the TLB
is flushed, so a folio with references beyond the page cache and
writeback_iter() is left to reclaim, as a mapped one already is.
Fixes: 2d6692e642e7 ("drm/i915: Start writeback from the shrinker")
Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
---
Found while reviewing David's fix for the same race on file PMDs, which
leaves shmem out because shmem has no writeback:
https://patch.msgid.link/20261116-dirty_file_pmd-v2-2-571883053174@kernel.org
Build-tested only.
drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
index bf9e7480f0f5..748772c358ac 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);
base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] drm/i915/gem: Skip writeback of shmem folios with extra references 2026-11-19 13:42 [PATCH] drm/i915/gem: Skip writeback of shmem folios with extra references Kiryl Shutsemau (Meta) @ 2026-11-19 17:43 ` Andi Shyti 2026-11-20 13:17 ` Kiryl Shutsemau (Meta) 2026-11-19 19:14 ` ✓ i915.CI.BAT: success for " Patchwork 2026-11-20 13:42 ` [PATCH] " sashiko-bot 2 siblings, 1 reply; 5+ messages in thread From: Andi Shyti @ 2026-11-19 17:43 UTC (permalink / raw) To: Kiryl Shutsemau (Meta) Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter, Andi Shyti, David Hildenbrand, Hugh Dickins, Baolin Wang, intel-gfx, dri-devel, linux-mm, linux-kernel, kernel-team Hi Kiryl, On Thu, Nov 19, 2026 at 01:42:41PM +0000, Kiryl Shutsemau (Meta) wrote: > __shmem_writeback() writes out every dirty folio that is not mapped. A > folio stops being mapped when munmap() removes its rmap, but the TLB > flush comes later. Until then another thread can still store to it > through a stale TLB entry: > > CPU0 (munmap) CPU1 (same mm) CPU2 (i915 shrinker) > zap_huge_pmd() > folio_remove_rmap_pmd() > __shmem_writeback() > clear dirty > !folio_mapped() > shmem_write_folio() > store via stale TLB > tlb_finish_mmu() > > The store leaves the folio clean in the swap cache. Once reclaim frees > it, the object reads back from swap without that store. > > The legacy mmap ioctl maps the shmem file directly, and i915 mounts it > with huge=within_size on some platforms, so the folio can be PMD-mapped. > The core mm keeps the rmap until after the flush for PTEs, but not for > shmem PMDs: shmem has no writeback, and pageout() refuses a folio with > an extra reference. > > Do the same here. The unmapping side holds its reference until the TLB > is flushed, so a folio with references beyond the page cache and > writeback_iter() is left to reclaim, as a mapped one already is. > > Fixes: 2d6692e642e7 ("drm/i915: Start writeback from the shrinker") > Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org> > --- > Found while reviewing David's fix for the same race on file PMDs, which > leaves shmem out because shmem has no writeback: > https://patch.msgid.link/20261116-dirty_file_pmd-v2-2-571883053174@kernel.org > > Build-tested only. > > drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c > index bf9e7480f0f5..748772c358ac 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)) I don't think we need this fix in the current tree. The i915 writeback iterator already skips the shmem folio in the case you describe, so the new refcount check doesn't change the outcome. Thanks, Andi > folio_redirty_for_writepage(&wbc, folio); > else > error = shmem_write_folio(folio); > > base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd > -- > 2.54.0 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/i915/gem: Skip writeback of shmem folios with extra references 2026-11-19 17:43 ` Andi Shyti @ 2026-11-20 13:17 ` Kiryl Shutsemau (Meta) 0 siblings, 0 replies; 5+ messages in thread From: Kiryl Shutsemau (Meta) @ 2026-11-20 13:17 UTC (permalink / raw) To: Andi Shyti Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter, Andi Shyti, David Hildenbrand, Hugh Dickins, Baolin Wang, intel-gfx, dri-devel, linux-mm, linux-kernel, kernel-team On Thu, Nov 19, 2026 at 06:43:08PM +0100, Andi Shyti wrote: > > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c > > index bf9e7480f0f5..748772c358ac 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)) > > I don't think we need this fix in the current tree. The i915 > writeback iterator already skips the shmem folio in the case you > describe, so the new refcount check doesn't change the outcome. Oh. It took me a while to see why. __shmem_writeback() asks writeback_iter() for PAGECACHE_TAG_DIRTY folios, and shmem never sets that tag, its ->dirty_folio is noop_dirty_folio(). So the loop body never runs for any folio, and hasn't since 776a853a43c9 ("i915: Use writeback_iter()"). That makes me question the whole writeback thing. What's going on there, and what's the plan? -- Kiryl Shutsemau / Kirill A. Shutemov ^ permalink raw reply [flat|nested] 5+ messages in thread
* ✓ i915.CI.BAT: success for drm/i915/gem: Skip writeback of shmem folios with extra references 2026-11-19 13:42 [PATCH] drm/i915/gem: Skip writeback of shmem folios with extra references Kiryl Shutsemau (Meta) 2026-11-19 17:43 ` Andi Shyti @ 2026-11-19 19:14 ` Patchwork 2026-11-20 13:42 ` [PATCH] " sashiko-bot 2 siblings, 0 replies; 5+ messages in thread From: Patchwork @ 2026-11-19 19:14 UTC (permalink / raw) To: Kiryl Shutsemau (Meta); +Cc: intel-gfx [-- Attachment #1: Type: text/plain, Size: 9549 bytes --] == Series Details == Series: drm/i915/gem: Skip writeback of shmem folios with extra references URL : https://patchwork.freedesktop.org/series/179090/ State : success == Summary == CI Bug Log - changes from CI_DRM_19566 -> Patchwork_179090v1 ==================================================== Summary ------- **SUCCESS** No regressions found. External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/index.html Participating hosts (37 -> 39) ------------------------------ Additional (3): bat-rpls-4 fi-skl-6600u bat-jsl-5 Missing (1): bat-dg2-13 Known issues ------------ Here are the changes found in Patchwork_179090v1 that come from known issues: ### IGT changes ### #### Issues hit #### * igt@gem_huc_copy@huc-copy: - bat-jsl-5: NOTRUN -> [SKIP][1] ([i915#2190]) [1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@gem_huc_copy@huc-copy.html - fi-skl-6600u: NOTRUN -> [SKIP][2] ([i915#2190]) [2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/fi-skl-6600u/igt@gem_huc_copy@huc-copy.html * igt@gem_lmem_swapping@parallel-random-engines: - bat-rpls-4: NOTRUN -> [SKIP][3] ([i915#4613]) +3 other tests skip [3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@gem_lmem_swapping@parallel-random-engines.html - bat-jsl-5: NOTRUN -> [SKIP][4] ([i915#4613]) +3 other tests skip [4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@gem_lmem_swapping@parallel-random-engines.html * igt@gem_lmem_swapping@random-engines: - fi-skl-6600u: NOTRUN -> [SKIP][5] ([i915#4613]) +3 other tests skip [5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/fi-skl-6600u/igt@gem_lmem_swapping@random-engines.html * igt@gem_tiled_pread_basic@basic: - bat-rpls-4: NOTRUN -> [SKIP][6] ([i915#15656]) [6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@gem_tiled_pread_basic@basic.html * igt@i915_pm_rpm@module-reload: - bat-jsl-5: NOTRUN -> [FAIL][7] ([i915#17751]) [7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@i915_pm_rpm@module-reload.html * igt@i915_selftest@live: - bat-adls-6: [PASS][8] -> [DMESG-FAIL][9] ([i915#14808]) +1 other test dmesg-fail [8]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_19566/bat-adls-6/igt@i915_selftest@live.html [9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-adls-6/igt@i915_selftest@live.html * igt@intel_hwmon@hwmon-read: - bat-rpls-4: NOTRUN -> [SKIP][10] ([i915#7707]) +1 other test skip [10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@intel_hwmon@hwmon-read.html - bat-jsl-5: NOTRUN -> [SKIP][11] ([i915#7707]) +1 other test skip [11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@intel_hwmon@hwmon-read.html - fi-skl-6600u: NOTRUN -> [SKIP][12] ([i915#11680]) +1 other test skip [12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/fi-skl-6600u/igt@intel_hwmon@hwmon-read.html * igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy: - bat-rpls-4: NOTRUN -> [SKIP][13] ([i915#4103]) +1 other test skip [13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy.html - bat-jsl-5: NOTRUN -> [SKIP][14] ([i915#4103]) +1 other test skip [14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy.html - fi-skl-6600u: NOTRUN -> [SKIP][15] ([i915#17457]) +1 other test skip [15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/fi-skl-6600u/igt@kms_cursor_legacy@basic-busy-flip-before-cursor-legacy.html * igt@kms_dsc@dsc-basic: - bat-rpls-4: NOTRUN -> [SKIP][16] ([i915#16361]) [16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@kms_dsc@dsc-basic.html - bat-jsl-5: NOTRUN -> [SKIP][17] ([i915#16361]) [17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@kms_dsc@dsc-basic.html - fi-skl-6600u: NOTRUN -> [SKIP][18] ([i915#17458]) [18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/fi-skl-6600u/igt@kms_dsc@dsc-basic.html * igt@kms_force_connector_basic@force-load-detect: - bat-rpls-4: NOTRUN -> [SKIP][19] ([i915#17452]) [19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@kms_force_connector_basic@force-load-detect.html - bat-jsl-5: NOTRUN -> [SKIP][20] ([i915#17452]) [20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@kms_force_connector_basic@force-load-detect.html - fi-skl-6600u: NOTRUN -> [SKIP][21] ([i915#17465]) [21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/fi-skl-6600u/igt@kms_force_connector_basic@force-load-detect.html * igt@kms_pipe_crc_basic@compare-crc-sanitycheck-nv12@pipe-b-edp-1: - fi-skl-6600u: NOTRUN -> [SKIP][22] ([i915#17461]) +3 other tests skip [22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/fi-skl-6600u/igt@kms_pipe_crc_basic@compare-crc-sanitycheck-nv12@pipe-b-edp-1.html * igt@kms_pm_backlight@basic-brightness: - bat-rpls-4: NOTRUN -> [SKIP][23] ([i915#5354]) [23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@kms_pm_backlight@basic-brightness.html - bat-jsl-5: NOTRUN -> [SKIP][24] ([i915#15205]) [24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@kms_pm_backlight@basic-brightness.html * igt@kms_psr@psr-primary-page-flip: - bat-rpls-4: NOTRUN -> [SKIP][25] ([i915#1072] / [i915#9732]) +3 other tests skip [25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@kms_psr@psr-primary-page-flip.html - bat-jsl-5: NOTRUN -> [SKIP][26] ([i915#1072]) +3 other tests skip [26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@kms_psr@psr-primary-page-flip.html * igt@kms_setmode@basic-clone-single-crtc: - bat-rpls-4: NOTRUN -> [SKIP][27] ([i915#3555]) [27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@kms_setmode@basic-clone-single-crtc.html - bat-jsl-5: NOTRUN -> [SKIP][28] ([i915#3555]) [28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-jsl-5/igt@kms_setmode@basic-clone-single-crtc.html - fi-skl-6600u: NOTRUN -> [SKIP][29] ([i915#17463]) [29]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/fi-skl-6600u/igt@kms_setmode@basic-clone-single-crtc.html * igt@prime_vgem@basic-read: - bat-rpls-4: NOTRUN -> [SKIP][30] ([i915#17448] / [i915#3708]) +2 other tests skip [30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@prime_vgem@basic-read.html * igt@vgem_basic@unload: - bat-rpls-4: NOTRUN -> [DMESG-WARN][31] ([i915#13400]) [31]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/bat-rpls-4/igt@vgem_basic@unload.html [i915#1072]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/1072 [i915#11680]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11680 [i915#13400]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13400 [i915#14808]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14808 [i915#15205]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/15205 [i915#15656]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/15656 [i915#16361]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16361 [i915#17448]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17448 [i915#17452]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17452 [i915#17457]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17457 [i915#17458]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17458 [i915#17461]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17461 [i915#17463]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17463 [i915#17465]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17465 [i915#17751]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/17751 [i915#2190]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/2190 [i915#3555]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3555 [i915#3708]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/3708 [i915#4103]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4103 [i915#4613]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4613 [i915#5354]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/5354 [i915#7707]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/7707 [i915#9732]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9732 Build changes ------------- * Linux: CI_DRM_19566 -> Patchwork_179090v1 CI-20190529: 20190529 CI_DRM_19566: d05450d36ef3d0f6e4ce4b26a831003847a7e75d @ git://anongit.freedesktop.org/gfx-ci/linux IGT_9198: 9198 Patchwork_179090v1: d05450d36ef3d0f6e4ce4b26a831003847a7e75d @ git://anongit.freedesktop.org/gfx-ci/linux == Logs == For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_179090v1/index.html [-- Attachment #2: Type: text/html, Size: 11248 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/i915/gem: Skip writeback of shmem folios with extra references 2026-11-19 13:42 [PATCH] drm/i915/gem: Skip writeback of shmem folios with extra references Kiryl Shutsemau (Meta) 2026-11-19 17:43 ` Andi Shyti 2026-11-19 19:14 ` ✓ i915.CI.BAT: success for " Patchwork @ 2026-11-20 13:42 ` sashiko-bot 2 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-11-20 13:42 UTC (permalink / raw) To: Kiryl Shutsemau (Meta), Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin Cc: David Airlie, Simona Vetter, Andi Shyti, David Hildenbrand, Hugh Dickins, Baolin Wang, intel-gfx, dri-devel, linux-mm, kernel-team 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) <kas@kernel.org> 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/20261119134243.3745282-1-kas@kernel.org?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-20 13:43 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-19 13:42 [PATCH] drm/i915/gem: Skip writeback of shmem folios with extra references Kiryl Shutsemau (Meta) 2026-11-19 17:43 ` Andi Shyti 2026-11-20 13:17 ` Kiryl Shutsemau (Meta) 2026-11-19 19:14 ` ✓ i915.CI.BAT: success for " Patchwork 2026-11-20 13:42 ` [PATCH] " sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox