Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Himal Prasad Ghimiray" <himal.prasad.ghimiray@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH] drm/xe: Exclude imported dma-buf BOs from the TT budget
Date: Fri, 27 Nov 2026 03:54:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-236565@kernel.org> (raw)
In-Reply-To: <20261127035202.2792551-2-himal.prasad.ghimiray@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe: useless eviction of uncharged imported dma-buf BOs
  from XE_PL_TT
--

commit 5f653edd2f2a196f3a1339336b2ead9630d79884
Author: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>

drm/xe: Exclude imported dma-buf BOs from the TT budget

This commit tracks system memory usage excluding imported dma-buf BOs in
mem.sys_mgr_charged, enforcing the TT budget and reporting memory region
usage against this counter.

> diff --git a/drivers/gpu/drm/xe/xe_ttm_sys_mgr.c b/drivers/gpu/drm/xe/xe_ttm_sys_mgr.c
> index 9d77ba605aecf..24e2c690d9926 100644
> --- a/drivers/gpu/drm/xe/xe_ttm_sys_mgr.c
> +++ b/drivers/gpu/drm/xe/xe_ttm_sys_mgr.c
> @@ -16,9 +16,15 @@
>  
>  struct xe_ttm_sys_node {
>  	struct ttm_buffer_object *tbo;
> +	bool charged;
>  	struct ttm_range_mgr_node base;
>  };
>  
> +static atomic64_t *to_charged_usage(struct ttm_resource_manager *man)
> +{
> +	return &container_of(man, struct xe_device, mem.sys_mgr)->mem.sys_mgr_charged;
> +}
> +
>  static inline struct xe_ttm_sys_node *
>  to_xe_ttm_sys_node(struct ttm_resource *res)
>  {
> @@ -40,10 +46,21 @@ static int xe_ttm_sys_mgr_new(struct ttm_resource_manager *man,
>  	node->tbo = tbo;
>  	ttm_resource_init(tbo, place, &node->base.base);
>  
> -	if (!(place->flags & TTM_PL_FLAG_TEMPORARY) &&
> -	    ttm_resource_manager_usage(man) > (man->size << PAGE_SHIFT)) {
> -		r = -ENOSPC;
> -		goto err_fini;
> +	/*
> +	 * Imported dma-bufs are backed by the exporter (possibly peer VRAM),
> +	 * so don't charge them against the local system memory budget.
> +	 */
> +	if (tbo->type != ttm_bo_type_sg) {
> +		u64 size = node->base.base.size;
> +		u64 usage = atomic64_add_return(size, to_charged_usage(man));
> +
> +		if (!(place->flags & TTM_PL_FLAG_TEMPORARY) &&
> +		    usage > (man->size << PAGE_SHIFT)) {
> +			atomic64_sub(size, to_charged_usage(man));
> +			r = -ENOSPC;
> +			goto err_fini;
> +		}
> +		node->charged = true;
>  	}
>  
>  	node->base.mm_nodes[0].start = 0;
> @@ -65,6 +82,8 @@ static void xe_ttm_sys_mgr_del(struct ttm_resource_manager *man,
>  {
>  	struct xe_ttm_sys_node *node = to_xe_ttm_sys_node(res);
>  
> +	if (node->charged)
> +		atomic64_sub(res->size, to_charged_usage(man));
>  	ttm_resource_fini(man, res);
>  	kfree(node);
>  }

[Severity: Medium]
When a normal XE_PL_TT allocation exceeds the budget and returns -ENOSPC,
can TTM's eviction walk still evict unpinned ttm_bo_type_sg BOs from
XE_PL_TT without freeing any charged budget?

ttm_resource_init() places unpinned ttm_bo_type_sg resources onto
sys_mgr's LRU list, and neither xe_bo_eviction_valuable() nor
xe_ttm_sys_mgr_func.intersects rejects them.  During ttm_bo_evict_alloc(),
TTM will evict those imported dma-buf BOs to XE_PL_SYSTEM and invalidate
their VMA bindings via xe_bo_move_notify(), even though
xe_ttm_sys_mgr_del() skips atomic64_sub() when node->charged is false, so
the retried allocation still fails with -ENOSPC and the walk continues
evicting remaining imported BOs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127035202.2792551-2-himal.prasad.ghimiray@intel.com?part=1

  reply	other threads:[~2026-11-27  3:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  3:52 [PATCH] drm/xe: Exclude imported dma-buf BOs from the TT budget Himal Prasad Ghimiray
2026-11-27  3:54 ` sashiko-bot [this message]
2026-11-27  3:56 ` ✓ CI.KUnit: success for drm/xe: Exclude imported dma-buf BOs from the TT budget (rev3) Patchwork
2026-11-27  4:39 ` ✓ Xe.CI.BAT: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-11-04 18:17 [PATCH] drm/xe: Exclude imported dma-buf BOs from the TT budget Himal Prasad Ghimiray
2026-11-04 18:28 ` sashiko-bot

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-236565@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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