From: sashiko-bot@kernel.org
To: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v3 1/3] drm/xe: Track number of populated ttm_tts in the shrinker
Date: Thu, 08 Oct 2026 12:44:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-164170@kernel.org> (raw)
In-Reply-To: <20261008123024.38522-2-thomas.hellstrom@linux.intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/xe: shrinker accounting underflow on madvise of pinned BOs
--
commit 0b5d1dd0e073a31ff71e38b6052b00140aecc46a
Author: Thomas Hellström <thomas.hellstrom@linux.intel.com>
drm/xe: Track number of populated ttm_tts in the shrinker
This commit adds a populated_tts counter to struct xe_shrinker to track
the number of ttm_tts that are populated and on the LRU. It also extends
xe_shrinker_mod_pages() to atomically update both page and object accounting.
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
[ ... ]
> @@ -975,11 +975,11 @@ static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo,
> if (!xe_tt->purgeable && new_state == XE_MADV_PURGEABLE_DONTNEED) {
> xe_tt->purgeable = true;
> /* Transfer pages from shrinkable to purgeable count */
> - xe_shrinker_mod_pages(xe->mem.shrinker, -tt_pages, tt_pages);
> + xe_shrinker_mod_pages(xe->mem.shrinker, -tt_pages, tt_pages, 0);
> } else if (xe_tt->purgeable && new_state == XE_MADV_PURGEABLE_WILLNEED) {
> xe_tt->purgeable = false;
> /* Transfer pages from purgeable to shrinkable count */
> - xe_shrinker_mod_pages(xe->mem.shrinker, tt_pages, -tt_pages);
> + xe_shrinker_mod_pages(xe->mem.shrinker, tt_pages, -tt_pages, 0);
[Severity: High]
Does this logic cause an underflow in the shrinker page accounting when a
buffer object is pinned?
When a BO is pinned (e.g., used as a scanout framebuffer which calls
xe_bo_pin()), its pages are explicitly excluded from shrinker tracking.
However, if userspace subsequently calls the DRM_XE_VM_MADVISE ioctl on
the VMA to transition its state to DONTNEED or WILLNEED,
xe_bo_willneed_put_locked() invokes xe_bo_set_purgeable_shrinker().
Because xe_bo_set_purgeable_shrinker() unconditionally transfers pages
between the shrinkable and purgeable buckets without checking if the BO
is pinned (bo->ttm.pin_count > 0), this can lead to an integer underflow
on shrinkable_pages or purgeable_pages.
When evaluated by xe_shrinker_count(), a negative signed value casts to a
large positive unsigned long, creating excessive reclaim pressure.
Furthermore, when the BO is eventually unpinned, its pages will be added
back to the shrinker accounting based on its new state, resulting in a
permanent double-counting of pages that triggers an xe_assert() during
xe_shrinker_fini().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261008123024.38522-1-thomas.hellstrom@linux.intel.com?part=1
next prev parent reply other threads:[~2026-10-08 12:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 12:30 [PATCH v3 0/3] drm/xe: Adjust the bo shrinker batch size Thomas Hellström
2026-10-08 12:30 ` [PATCH v3 1/3] drm/xe: Track number of populated ttm_tts in the shrinker Thomas Hellström
2026-10-08 12:44 ` sashiko-bot [this message]
2026-10-08 12:30 ` [PATCH v3 2/3] drm/xe: Split the bo shrinker into purgeable and non-purgeable shrinkers Thomas Hellström
2026-10-08 12:46 ` sashiko-bot
2026-10-08 12:30 ` [PATCH v3 3/3] drm/xe: Update non-purgeable shrinker batch size based on average BO size Thomas Hellström
2026-10-08 13:17 ` ✓ CI.KUnit: success for drm/xe: Adjust the bo shrinker batch size (rev3) Patchwork
2026-10-08 14:00 ` ✓ Xe.CI.BAT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-164170@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=thomas.hellstrom@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox