All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2 1/2] drm/xe: Track number of populated ttm_tts in the shrinker
Date: Fri, 14 Aug 2026 14:56:21 +0000	[thread overview]
Message-ID: <20260814145622.0E5771F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260814143737.49684-2-thomas.hellstrom@linux.intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Double subtraction of shrinker accounts (including the new populated_tts) during nested external pins.
--

--- Patch [1]: [PATCH v2 1/2] drm/xe: Track number of populated ttm_tts in the shrinker ---
commit 96b66a44985d6775af6634dd1b400406d1705547
Author: Thomas Hellström <thomas.hellstrom@linux.intel.com>

drm/xe: Track number of populated ttm_tts in the shrinker

This commit introduces a populated_tts counter to the xe shrinker to track
the number of shrinkable or purgeable ttm_tt objects. It modifies
xe_ttm_tt_account_add() and xe_ttm_tt_account_subtract() to increment and
decrement this new counter alongside existing page accounting. Additionally,
it updates xe_shrinker_mod_pages() to handle the new tts delta.

> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index dde309821237b..0ddc1d13d6ba6 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -450,9 +450,9 @@ static void xe_ttm_tt_account_subtract(struct xe_device *xe, struct ttm_tt *tt)
>  	struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
>  
>  	if (xe_tt->purgeable)
> -		xe_shrinker_mod_pages(xe->mem.shrinker, 0, -(long)tt->num_pages);
> +		xe_shrinker_mod_pages(xe->mem.shrinker, 0, -(long)tt->num_pages, -1);
>  	else
> -		xe_shrinker_mod_pages(xe->mem.shrinker, -(long)tt->num_pages, 0);
> +		xe_shrinker_mod_pages(xe->mem.shrinker, -(long)tt->num_pages, 0, -1);
>  }

[Severity: High]
This is a pre-existing issue, but won't the new populated_tts counter also
underflow here when external DMA-bufs are pinned multiple times?

In xe_bo_pin_external(), the BO is unconditionally subtracted from the
shrinker tracking even if it is already pinned:

	ttm_bo_pin(&bo->ttm);
	if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm))
		xe_ttm_tt_account_subtract(xe, bo->ttm.ttm);

Similarly, xe_bo_unpin_external() unconditionally adds it back without
checking if bo->ttm.pin_count actually reached 0:

	ttm_bo_unpin(&bo->ttm);
	if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm))
		xe_ttm_tt_account_add(xe, bo->ttm.ttm);

If a userspace process imports an external DMA-buf and maps/pins it multiple
times, xe_ttm_tt_account_subtract() is called for every pin, and
xe_ttm_tt_account_add() for every unpin. Since xe_ttm_tt_account_add() was
only called once upon initial population, the nested subtractions cause an
underflow.

Could this lead to the shrinker fields, including the new populated_tts,
becoming massive positive numbers when evaluated as unsigned long in
xe_shrinker_count(), potentially misleading kswapd to continuously scan
and consume 100% CPU?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260814143737.49684-1-thomas.hellstrom@linux.intel.com?part=1

  reply	other threads:[~2026-08-14 14:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 14:37 [PATCH v2 0/2] drm/xe: Adjust the bo shrinker batch size Thomas Hellström
2026-08-14 14:37 ` [PATCH v2 1/2] drm/xe: Track number of populated ttm_tts in the shrinker Thomas Hellström
2026-08-14 14:56   ` sashiko-bot [this message]
2026-08-14 14:37 ` [PATCH v2 2/2] drm/xe: Update shrinker batch size based on average BO size Thomas Hellström
2026-08-14 14:45   ` sashiko-bot
2026-08-14 15:17 ` ✓ CI.KUnit: success for drm/xe: Adjust the bo shrinker batch size (rev2) Patchwork
2026-08-14 16:14 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-08-14 18:07 ` ✓ Xe.CI.FULL: success " 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=20260814145622.0E5771F000E9@smtp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.