Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tejas Upadhyay" <tejas.upadhyay@intel.com>,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH V4 1/3] drm/xe/vram: add decay-based reinstatement of soft-offlined VRAM pages
Date: Tue, 01 Dec 2026 11:51:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-243220@kernel.org> (raw)
In-Reply-To: <20261201113518.146130-6-tejas.upadhyay@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/xe/vram: race in xe_ttm_vram_mgr_fini() can re-arm
  decay_gc_work
- [Low] drm/xe: unused XE_BAD_PAGE_DECAY_SECS_DEFAULT and missing
  configfs visibility
--

commit a18ba37985069c5d01894a2deb36a31a4255b80e
Author: Tejas Upadhyay <tejas.upadhyay@intel.com>

drm/xe/vram: add decay-based reinstatement of soft-offlined VRAM pages

This commit adds a per-VRAM-manager delayed work timer and a
bad_page_decay_secs configfs attribute to reinstate soft-offlined VRAM
pages after a decay period with no further faults, while promoting
repeated faults to permanent hard retirement.

> diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> index 36d47de8b11ba..ed9fa4e2b574f 100644
> --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> @@ -229,6 +229,8 @@ static void xe_ttm_vram_buddy_free(struct xe_ttm_vram_mgr *mgr,
>   *
>   * Called with @mgr->lock held.
>   */
> +static unsigned long xe_ttm_vram_decay_gc_period(struct xe_ttm_vram_mgr *mgr);
> +
>  static void xe_ttm_vram_retry_queued_pages(struct xe_ttm_vram_mgr *mgr)
>  {
>  	struct xe_ttm_vram_offline_resource *pos, *n;
> @@ -247,6 +249,11 @@ static void xe_ttm_vram_retry_queued_pages(struct xe_ttm_vram_mgr *mgr)
>  		list_del(&pos->queued_link);
>  		++mgr->n_offlined_pages;
>  		list_add(&pos->offlined_link, &mgr->offlined_pages);
> +
> +		if (pos->mode == XE_PAGE_OFFLINE_SOFT && mgr->decay_interval_jiffies &&
> +		    !delayed_work_pending(&mgr->decay_gc_work))
> +			schedule_delayed_work(&mgr->decay_gc_work,
> +					      xe_ttm_vram_decay_gc_period(mgr));
>  	}
>  }

[ ... ]

> @@ -415,6 +470,8 @@ static void xe_ttm_vram_mgr_fini(struct drm_device *dev, void *arg)
>  	struct xe_ttm_vram_mgr *mgr = arg;
>  	struct ttm_resource_manager *man = &mgr->manager;
>  
> +	cancel_delayed_work_sync(&mgr->decay_gc_work);
> +
>  	mutex_lock(&mgr->lock);
>  	xe_ttm_vram_free_bad_pages(mgr);
>  	mutex_unlock(&mgr->lock);

[Severity: Medium]
Can xe_ttm_vram_retry_queued_pages() re-arm mgr->decay_gc_work after
cancel_delayed_work_sync() returns in xe_ttm_vram_mgr_fini()?

During drmm teardown, xe_ttm_vram_mgr_fini() runs before
ttm_resource_manager_evict_all() and before xe_device_destroy() drains
xe->bo_device.async_free and xe->ttm.wq.  If an in-flight BO or ghost
object deletion freeing a queued soft-offlined page runs in the window
before mgr->lock is taken, it schedules decay_gc_work again:

CPU0                                  CPU1 (kworker)
xe_ttm_vram_mgr_fini()
  cancel_delayed_work_sync(&mgr->decay_gc_work)
                                      xe_ttm_vram_mgr_del()
                                        mutex_lock(&mgr->lock)
                                        ...
                                        xe_ttm_vram_retry_queued_pages()
                                          schedule_delayed_work(&mgr->decay_gc_work, ...)
                                        mutex_unlock(&mgr->lock)
  mutex_lock(&mgr->lock)
  xe_ttm_vram_free_bad_pages(mgr)
  mutex_unlock(&mgr->lock)
  ...
  gpu_buddy_fini(&mgr->mm)
                                      xe_ttm_vram_decay_gc_worker()
                                        <-- use-after-free on mgr

Cancelling decay_gc_work after xe_ttm_vram_free_bad_pages() has emptied
mgr->queued_pages (or zeroing mgr->decay_interval_jiffies under
mgr->lock before cancel_delayed_work_sync()) would prevent it from being
re-armed.

> diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h b/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h
> index 4a2cd27a5b617..0a6d8f8c2aa83 100644
> --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h
> +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h
> @@ -7,8 +7,16 @@
>  #define _XE_TTM_VRAM_MGR_TYPES_H_
>  
>  #include <linux/gpu_buddy.h>
> +#include <linux/workqueue.h>
>  #include <drm/ttm/ttm_device.h>
>  
> +#define XE_BAD_PAGE_DECAY_SECS_DEFAULT	(24 * 60 * 60)

[Severity: Low]
This isn't a bug, but XE_BAD_PAGE_DECAY_SECS_DEFAULT is unused while
device_defaults in drivers/gpu/drm/xe/xe_configfs.c open-codes
24 * 60 * 60 (and configfs defaults live in xe_defaults.h).  Also,
xe_config_device_is_visible() hides attr_disable_vram_page_offline when
!dev->desc->is_dgfx || dev->desc->platform != XE_CRESCENTISLAND, but
does not gate attr_bad_page_decay_secs, and the DOC: Xe Configfs comment
in xe_configfs.c wasn't updated for the new attribute.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201113518.146130-5-tejas.upadhyay@intel.com?part=1

  reply	other threads:[~2026-12-01 11:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 11:35 [PATCH V4 0/3] drm/xe/vram: decay-based reinstatement of soft-offlined VRAM pages Tejas Upadhyay
2026-12-01 11:35 ` [PATCH V4 1/3] drm/xe/vram: add " Tejas Upadhyay
2026-12-01 11:51   ` sashiko-bot [this message]
2026-12-01 11:35 ` [PATCH V4 2/3] drm/xe/vram: don't let firmware-confirmed permanent bad pages decay back in Tejas Upadhyay
2026-12-01 11:35 ` [PATCH V4 3/3] drm/xe/vram: stop decay worker from rescheduling itself forever Tejas Upadhyay
2026-12-01 11:57 ` ✓ CI.KUnit: success for drm/xe/vram: decay-based reinstatement of soft-offlined VRAM pages (rev3) Patchwork
2026-12-01 12:34 ` ✓ 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-243220@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tejas.upadhyay@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