Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: "Tauro, Riana" <riana.tauro@intel.com>
Cc: <dri-devel@lists.freedesktop.org>,
	<intel-xe@lists.freedesktop.org>,
	Aravind Iddamsetty <aravind.iddamsetty@linux.intel.com>,
	Tejas Upadhyay <tejas.upadhyay@intel.com>,
	Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Subject: Re: [PATCH v5 2/2] drm/xe: Expose retired VRAM pages via drm-ras
Date: Fri, 27 Nov 2026 13:07:59 -0500	[thread overview]
Message-ID: <awnG_8nDRqha_b0g@intel.com> (raw)
In-Reply-To: <7800e7ac-fbba-4724-8170-a31043f9c62b@intel.com>

On Fri, Nov 27, 2026 at 12:48:39PM +0530, Tauro, Riana wrote:
> 
> On 26-11-2026 00:32, Rodrigo Vivi wrote:
> > From: Aravind Iddamsetty <aravind.iddamsetty@linux.intel.com>
> > 
> > Retired VRAM pages are only visible through the vram_bad_pages debugfs
> > file today. Register a drm-ras retired-pages node so userspace gets
> > them, and the maximum number of pages that can be retired, through a
> > stable interface.
> > 
> > The page lists are walked under the VRAM manager lock, and a generation
> > counter on each manager lets drm-ras flag dumps that raced with a page
> > being added, retired or failing its reservation.
> > 
> > v3 (Rodrigo+LLM):
> >   - Use the drm-ras retired-pages node type, which replaces the nested
> >     retired-resources layout (Jakub).
> >   - Walk the lists under mgr->lock instead of RCU, which they are not
> >     protected by, and stop reading the buddy blocks (Sashiko).
> >   - Add a generation counter for interrupted dumps.
> >   - Keep the vram_bad_pages debugfs file for now.
> >   - Remove deprecated Assisted-by tag.
> > 
> > v4 (Rodrigo+LLM):
> >   - Register the node at the end of xe_ras_init(), once the retired page
> >     lists are fetched. That point is only reached with a system
> >     controller, which replaces the XE_CRESCENTISLAND check and keeps the
> >     node off VFs (local Sashiko).
> >   - Report the list generation also when no page is left (local Sashiko).
> > 
> > Cc: Tejas Upadhyay <tejas.upadhyay@intel.com>
> > Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> > Cc: Riana Tauro <riana.tauro@intel.com>
> > Signed-off-by: Aravind Iddamsetty <aravind.iddamsetty@linux.intel.com>
> > Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > ---
> >   drivers/gpu/drm/xe/xe_drm_ras.c            | 56 +++++++++++++++++
> >   drivers/gpu/drm/xe/xe_drm_ras.h            |  1 +
> >   drivers/gpu/drm/xe/xe_ras.c                |  4 ++
> >   drivers/gpu/drm/xe/xe_ttm_vram_mgr.c       | 72 +++++++++++++++++++++-
> >   drivers/gpu/drm/xe/xe_ttm_vram_mgr.h       |  3 +
> >   drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h |  5 ++
> >   6 files changed, 140 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_drm_ras.c b/drivers/gpu/drm/xe/xe_drm_ras.c
> > index 86c589437a9f..5382b60bb328 100644
> > --- a/drivers/gpu/drm/xe/xe_drm_ras.c
> > +++ b/drivers/gpu/drm/xe/xe_drm_ras.c
> > @@ -13,6 +13,7 @@
> >   #include "xe_device_types.h"
> >   #include "xe_drm_ras.h"
> >   #include "xe_ras.h"
> > +#include "xe_ttm_vram_mgr.h"
> >   #include "xe_wedge.h"
> >   static const char * const error_components[] = DRM_XE_RAS_ERROR_COMPONENT_NAMES;
> > @@ -272,6 +273,61 @@ static int register_nodes(struct xe_device *xe)
> >   	return ret;
> >   }
> > +static int query_retired_page(struct drm_ras_node *node, u64 cursor,
> > +			      struct drm_ras_retired_page *page)
> > +{
> > +	return xe_ttm_vram_get_retired_page(node->priv, cursor, page);
> > +}
> 
> This patch [PATCH v4 0/2] Protect drm_ras against unplugged or wedged device
> - Raag Jadav
> <https://lore.kernel.org/intel-xe/20261119102344.2053821-1-raag.jadav@intel.com/>adds
> protection against a dev unplug for error counter nodes due to a issue we
> saw while unbind.
> The same needs to be added here.

upcoming v6 adds the unplug protection. I left the wedged check out on
purpose: the counters skip a wedged device because they talk to the
firmware, while the retired pages are driver memory, and still
useful to read after a wedge.

> 
> > +
> > +static int query_retired_pages_info(struct drm_ras_node *node, u64 *max_pages)
> > +{
> > +	*max_pages = xe_ras_get_max_pages(node->priv);
> 
> There could be an issue with firmware reporting incorrect max pages.
> Can we return -EINVAL for max_pages if its 0.
> 
> 
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * xe_drm_ras_register_retired_pages() - Register the retired VRAM pages node
> > + * @xe: xe device instance
> > + *
> > + * Called once the retired page lists are populated.
> > + *
> > + * Return: 0 on success, negative error code otherwise.
> > + */
> > +int xe_drm_ras_register_retired_pages(struct xe_device *xe)
> > +{
> > +	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
> > +	struct drm_ras_node *node;
> > +	int ret;
> > +
> > +	if (!xe->info.has_drm_ras)
> > +		return 0;
> > +
> > +	node = drmm_kzalloc(&xe->drm, sizeof(*node), GFP_KERNEL);
> > +	if (!node)
> > +		return -ENOMEM;
> > +
> > +	node->device_name = kasprintf(GFP_KERNEL, "%04x:%02x:%02x.%d",
> > +				      pci_domain_nr(pdev->bus), pdev->bus->number,
> > +				      PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
> > +	if (!node->device_name)
> > +		return -ENOMEM;
> > +
> > +	node->node_name = "vram-retired-pages";
> > +	node->type = DRM_RAS_NODE_TYPE_RETIRED_PAGES;
> > +	node->query_retired_page = query_retired_page;
> > +	node->query_retired_pages_info = query_retired_pages_info;
> > +	node->priv = xe;
> > +
> > +	ret = drm_ras_node_register(node);
> > +	if (ret) {
> > +		cleanup_node_param(node);
> > +		return ret;
> > +	}
> > +
> > +	return drmm_add_action_or_reset(&xe->drm, cleanup_node, node);
> > +}
> > +
> >   /**
> >    * xe_drm_ras_event() - Report drm-ras error event to userspace
> >    * @xe: xe device structure
> > diff --git a/drivers/gpu/drm/xe/xe_drm_ras.h b/drivers/gpu/drm/xe/xe_drm_ras.h
> > index 723229b2cffb..a6fc2255986d 100644
> > --- a/drivers/gpu/drm/xe/xe_drm_ras.h
> > +++ b/drivers/gpu/drm/xe/xe_drm_ras.h
> > @@ -13,6 +13,7 @@ struct xe_device;
> >   	for (i = 0; i < DRM_XE_RAS_ERR_SEV_MAX; i++)
> >   int xe_drm_ras_init(struct xe_device *xe);
> > +int xe_drm_ras_register_retired_pages(struct xe_device *xe);
> >   void xe_drm_ras_event(struct xe_device *xe, u32 component, u32 severity, u32 value);
> >   #endif
> > diff --git a/drivers/gpu/drm/xe/xe_ras.c b/drivers/gpu/drm/xe/xe_ras.c
> > index 9b04be3405ca..8e5e2df2c9f7 100644
> > --- a/drivers/gpu/drm/xe/xe_ras.c
> > +++ b/drivers/gpu/drm/xe/xe_ras.c
> > @@ -1508,6 +1508,10 @@ int xe_ras_init(struct xe_device *xe)
> >   	get_offline_list(xe);
> >   	get_offline_queue(xe);
> > +	ret = xe_drm_ras_register_retired_pages(xe);
> > +	if (ret)
> > +		return ret;
> 
> Could we move this into xe_drm_ras_init() and add the sysctrl check there
> too? That way all the initialization stays in one init function.

The node needs the retired page lists, which are only fetched later
in xe_ras_init(), by get_offline_list() and get_offline_queue().
Registering it in xe_drm_ras_init() would expose an incomplete list
in the meantime, so I kept it right after the lists are fetched,
which is also only reached with a system controller.

> 
> We should also add a check to skip registering this node when page
> offlining is disabled.
> 
> Do we really need to fail probe if drm_ras node fails to register?
> 
> Thanks
> Riana
> 
> 
> > +
> >   	/*
> >   	 * During probe, process and log any errors detected by firmware while the driver was not
> >   	 * loaded. Critical errors such as Punit and CSC are reported through Pcode init failure,
> > diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> > index 36d47de8b11b..4a7b9ea36211 100644
> > --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> > +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> > @@ -10,6 +10,7 @@
> >   #include <drm/drm_managed.h>
> >   #include <drm/drm_drv.h>
> >   #include <drm/drm_buddy.h>
> > +#include <drm/drm_ras.h>
> >   #include <uapi/drm/xe_drm.h>
> >   #include <drm/ttm/ttm_placement.h>
> > @@ -240,13 +241,17 @@ static void xe_ttm_vram_retry_queued_pages(struct xe_ttm_vram_mgr *mgr)
> >   					    PAGE_SIZE, PAGE_SIZE, &pos->blocks,
> >   					    GPU_BUDDY_RANGE_ALLOCATION, NULL,
> >   					    &pos->used_visible_size)) {
> > -			pos->status = XE_PAGE_RESERVE_FAIL;
> > +			if (pos->status != XE_PAGE_RESERVE_FAIL) {
> > +				pos->status = XE_PAGE_RESERVE_FAIL;
> > +				mgr->retired_gen++;
> > +			}
> >   			continue;
> >   		}
> >   		--mgr->n_queued_pages;
> >   		list_del(&pos->queued_link);
> >   		++mgr->n_offlined_pages;
> >   		list_add(&pos->offlined_link, &mgr->offlined_pages);
> > +		mgr->retired_gen++;
> >   	}
> >   }
> > @@ -625,6 +630,68 @@ u64 xe_ttm_vram_get_avail(struct ttm_resource_manager *man)
> >   	return avail;
> >   }
> > +static void retired_page_update(struct drm_ras_retired_page *page, bool *found,
> > +				u64 cursor, u64 addr, enum drm_ras_retired_page_status status)
> > +{
> > +	if (addr < cursor || (*found && addr >= page->address))
> > +		return;
> > +
> > +	page->address = addr;
> > +	page->status = status;
> > +	*found = true;
> > +}
> > +
> > +/**
> > + * xe_ttm_vram_get_retired_page - Get the next retired VRAM page
> > + * @xe: xe device instance
> > + * @cursor: lowest device address to consider
> > + * @page: filled with the retired page that has the lowest address >= @cursor
> > + *
> > + * Return: 0 on success, -ENOENT if no retired page is at or above @cursor.
> > + */
> > +int xe_ttm_vram_get_retired_page(struct xe_device *xe, u64 cursor,
> > +				 struct drm_ras_retired_page *page)
> > +{
> > +	struct xe_ttm_vram_offline_resource *pos;
> > +	struct xe_tile *tile;
> > +	bool found = false;
> > +	u32 gen = 0;
> > +	u8 id;
> > +
> > +	for_each_tile(tile, xe, id) {
> > +		struct xe_vram_region *vr = tile->mem.vram;
> > +		struct ttm_resource_manager *man;
> > +		struct xe_ttm_vram_mgr *mgr;
> > +
> > +		man = ttm_manager_type(&xe->ttm, XE_PL_VRAM0 + id);
> > +		if (!man || !vr)
> > +			continue;
> > +		mgr = to_xe_ttm_vram_mgr(man);
> > +
> > +		guard(mutex)(&mgr->lock);
> > +
> > +		gen += mgr->retired_gen;
> > +
> > +		list_for_each_entry(pos, &mgr->offlined_pages, offlined_link)
> > +			retired_page_update(page, &found, cursor, pos->addr + vr->dpa_base,
> > +					    DRM_RAS_RETIRED_PAGE_STATUS_RETIRED);
> > +
> > +		list_for_each_entry(pos, &mgr->queued_pages, queued_link)
> > +			retired_page_update(page, &found, cursor, pos->addr + vr->dpa_base,
> > +					    pos->status == XE_PAGE_RESERVE_FAIL ?
> > +					    DRM_RAS_RETIRED_PAGE_STATUS_FAILED :
> > +					    DRM_RAS_RETIRED_PAGE_STATUS_PENDING);
> > +	}
> > +
> > +	page->generation = gen;
> > +	if (!found)
> > +		return -ENOENT;
> > +
> > +	page->size = PAGE_SIZE;
> > +
> > +	return 0;
> > +}
> > +
> >   static int xe_ttm_vram_purge_page(struct xe_device *xe, struct xe_bo *bo)
> >   {
> >   	u32 q_flag = DRM_XE_EXEC_QUEUE_BAN_REASON_PAGE_OFFLINE;
> > @@ -825,6 +892,7 @@ static int xe_ttm_vram_reserve_page_at_addr(struct xe_device *xe, u64 addr,
> >   			/* Queue free(to-be-purged) pages */
> >   			++vram_mgr->n_queued_pages;
> >   			list_add(&nentry->queued_link, &vram_mgr->queued_pages);
> > +			vram_mgr->retired_gen++;
> >   		} else {
> >   			/* Immediately offline unoccupied pages */
> >   			/* Queue free(to-be-reserved) pages */
> > @@ -839,10 +907,12 @@ static int xe_ttm_vram_reserve_page_at_addr(struct xe_device *xe, u64 addr,
> >   					addr, ret);
> >   				++vram_mgr->n_queued_pages;
> >   				list_add(&nentry->queued_link, &vram_mgr->queued_pages);
> > +				vram_mgr->retired_gen++;
> >   				return 0;
> >   			}
> >   			++vram_mgr->n_offlined_pages;
> >   			list_add(&nentry->offlined_link, &vram_mgr->offlined_pages);
> > +			vram_mgr->retired_gen++;
> >   			return ret;
> >   		}
> >   	}
> > diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.h b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.h
> > index d77f067d197b..91147385718c 100644
> > --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.h
> > +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.h
> > @@ -9,6 +9,7 @@
> >   #include "xe_ttm_vram_mgr_types.h"
> >   enum dma_data_direction;
> > +struct drm_ras_retired_page;
> >   struct xe_device;
> >   struct xe_tile;
> >   struct xe_vram_region;
> > @@ -33,6 +34,8 @@ void xe_ttm_vram_get_used(struct ttm_resource_manager *man,
> >   			  u64 *used, u64 *used_visible);
> >   int xe_ttm_vram_handle_addr_fault(struct xe_device *xe, u64 addr);
> >   int xe_ttm_vram_inject_fault(struct xe_device *xe);
> > +int xe_ttm_vram_get_retired_page(struct xe_device *xe, u64 cursor,
> > +				 struct drm_ras_retired_page *page);
> >   static inline struct xe_ttm_vram_mgr_resource *
> >   to_xe_ttm_vram_mgr_resource(struct ttm_resource *res)
> > 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 4a2cd27a5b61..6a49ee8b09ef 100644
> > --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h
> > +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h
> > @@ -27,6 +27,11 @@ struct xe_ttm_vram_mgr {
> >   	struct list_head queued_pages;
> >   	/** @n_queued_pages: Number of queued pages */
> >   	u16 n_queued_pages;
> > +	/**
> > +	 * @retired_gen: Changed whenever @offlined_pages or @queued_pages
> > +	 * change. Protected by @lock.
> > +	 */
> > +	u32 retired_gen;
> >   	/** @visible_size: Probed size of the CPU visible portion */
> >   	u64 visible_size;
> >   	/** @visible_avail: CPU visible portion still unallocated */

  reply	other threads:[~2026-11-27 18:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 19:02 [PATCH v5 0/2] drm/xe: Expose retired VRAM pages via drm-ras Rodrigo Vivi
2026-11-25 19:02 ` [PATCH v5 1/2] drm/ras: Add retired-pages node type Rodrigo Vivi
2026-11-25 23:46   ` Zack McKevitt
2026-11-27  7:16   ` Tauro, Riana
2026-11-27 18:03     ` Rodrigo Vivi
2026-11-25 19:02 ` [PATCH v5 2/2] drm/xe: Expose retired VRAM pages via drm-ras Rodrigo Vivi
2026-11-27  7:18   ` Tauro, Riana
2026-11-27 18:07     ` Rodrigo Vivi [this message]
2026-11-25 20:19 ` ✗ CI.checkpatch: warning for drm/xe: Expose retired VRAM pages via drm-ras (rev5) Patchwork
2026-11-25 20:22 ` ✓ CI.KUnit: success " Patchwork
2026-11-25 21:02 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-26  5:35 ` ✗ Xe.CI.FULL: failure " 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=awnG_8nDRqha_b0g@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=aravind.iddamsetty@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=riana.tauro@intel.com \
    --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