dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: "Upadhyay, Tejas" <tejas.upadhyay@intel.com>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
	"Aravind Iddamsetty" <aravind.iddamsetty@linux.intel.com>,
	"Ghimiray, Himal Prasad" <himal.prasad.ghimiray@intel.com>,
	"Tauro, Riana" <riana.tauro@intel.com>
Subject: Re: [PATCH v6 3/3] drm/xe: Expose retired VRAM pages via drm-ras
Date: Mon, 30 Nov 2026 11:04:04 -0500	[thread overview]
Message-ID: <aw2edG25HMvI4IYx@intel.com> (raw)
In-Reply-To: <DM3PPF4C5964328CF63DEBBF5C3A834874B814F2@DM3PPF4C5964328.namprd11.prod.outlook.com>

On Sun, Nov 29, 2026 at 12:31:04PM -0500, Upadhyay, Tejas wrote:
> 
> 
> > -----Original Message-----
> > From: Vivi, Rodrigo <rodrigo.vivi@intel.com>
> > Sent: 27 November 2026 23:48
> > To: dri-devel@lists.freedesktop.org
> > Cc: intel-xe@lists.freedesktop.org; Aravind Iddamsetty
> > <aravind.iddamsetty@linux.intel.com>; Upadhyay, Tejas
> > <tejas.upadhyay@intel.com>; Ghimiray, Himal Prasad
> > <himal.prasad.ghimiray@intel.com>; Tauro, Riana <riana.tauro@intel.com>;
> > Vivi, Rodrigo <rodrigo.vivi@intel.com>
> > Subject: [PATCH v6 3/3] drm/xe: Expose retired VRAM pages via drm-ras
> > 
> > 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 snapshot of the dump is taken in one pass over the page lists of each
> > VRAM manager, under its lock.
> > 
> > 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).
> > 
> > v6 (Rodrigo+LLM):
> >  - Add the pages to the drm-ras snapshot in one pass over the page
> >    lists, instead of a walk per page, and drop the generation counter
> >    (Riana).
> >  - Do not read the pages of an unplugged device (Riana).
> >  - Return -EINVAL when firmware reports no max pages (Riana).
> >  - Do not register the node when page offlining is disabled, and do not
> >    fail probe if the registration fails (Riana).
> > 
> > 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      | 78
> > ++++++++++++++++++++++++++++
> >  drivers/gpu/drm/xe/xe_drm_ras.h      |  1 +
> >  drivers/gpu/drm/xe/xe_ras.c          |  2 +
> >  drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 58 +++++++++++++++++++++
> > drivers/gpu/drm/xe/xe_ttm_vram_mgr.h |  2 +
> >  5 files changed, 141 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_drm_ras.c
> > b/drivers/gpu/drm/xe/xe_drm_ras.c index 86c589437a9f..7490281095ae
> > 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,83 @@ static
> > int register_nodes(struct xe_device *xe)
> >  	return ret;
> >  }
> > 
> > +static int query_retired_pages(struct drm_ras_node *node, struct
> > +drm_ras_retired_pages *list) {
> > +	struct xe_device *xe = node->priv;
> > +	int idx, ret;
> > +
> > +	if (!drm_dev_enter(&xe->drm, &idx))
> > +		return -ENODEV;
> > +
> > +	ret = xe_ttm_vram_get_retired_pages(xe, list);
> > +
> > +	drm_dev_exit(idx);
> > +
> > +	return ret;
> > +}
> > +
> > +static int query_retired_pages_info(struct drm_ras_node *node,
> > +				    struct drm_ras_retired_pages_info *info) {
> > +	struct xe_device *xe = node->priv;
> > +	int idx, ret = 0;
> > +
> > +	if (!drm_dev_enter(&xe->drm, &idx))
> > +		return -ENODEV;
> > +
> > +	info->max_pages = xe_ras_get_max_pages(xe);
> > +	if (!info->max_pages)
> > +		ret = -EINVAL;
> > +
> > +	drm_dev_exit(idx);
> > +
> > +	return ret;
> > +}
> > +
> > +/**
> > + * 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 ||
> > xe_ras_get_disable_vram_page_offline(xe))
> > +		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_pages = query_retired_pages;
> > +	node->query_retired_pages_info = query_retired_pages_info;
> > +	node->priv = xe;
> > +
> > +	ret = drm_ras_node_register(node);
> > +	if (ret) {
> > +		drm_err(&xe->drm, "Failed to register DRM RAS retired pages
> > node (%pe)\n",
> > +			ERR_PTR(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
> > d14ee40d0440..39895f6a040c 100644
> > --- a/drivers/gpu/drm/xe/xe_ras.c
> > +++ b/drivers/gpu/drm/xe/xe_ras.c
> > @@ -1519,6 +1519,8 @@ int xe_ras_init(struct xe_device *xe)
> >  	get_offline_list(xe);
> >  	get_offline_queue(xe);
> > 
> > +	xe_drm_ras_register_retired_pages(xe);
> > +
> >  	/*
> >  	 * 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..7658ce9f1bd9 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>
> > @@ -625,6 +626,63 @@ u64 xe_ttm_vram_get_avail(struct
> > ttm_resource_manager *man)
> >  	return avail;
> >  }
> > 
> > +/**
> > + * xe_ttm_vram_get_retired_pages - Get a snapshot of the retired VRAM
> > +pages
> > + * @xe: xe device instance
> > + * @list: drm-ras snapshot to add the retired pages to
> > + *
> > + * Return: 0 on success, negative error code otherwise.
> > + */
> > +int xe_ttm_vram_get_retired_pages(struct xe_device *xe, struct
> > +drm_ras_retired_pages *list) {
> > +	struct xe_ttm_vram_offline_resource *pos;
> > +	struct drm_ras_retired_page page;
> > +	struct xe_tile *tile;
> > +	u8 id;
> > +	int ret;
> > +
> > +	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);
> > +
> > +		list_for_each_entry(pos, &mgr->offlined_pages, offlined_link)
> > {
> > +			page = (struct drm_ras_retired_page) {
> > +				.address = pos->addr + vr->dpa_base,
> 
> As per design doc, we were supposed to expose PFN. Are we good with this change?

Yes, this was on purpose. drm-ras is generic, and a PFN alone doesn't
tell much without knowing the page size, which can be different on
each device. So we give the address and the size of each page, and
the PFN is easy to get from them if needed.

> 
> Apart from above comment, fetching stats of offlined and queued pages info and their status seems fine, LGTM,
> Reviewed-by: Tejas Upadhyay <tejas.upadhyay@intel.com>

Thank you!
Rodrigo.

> 
> > +				.size = PAGE_SIZE,
> > +				.status =
> > DRM_RAS_RETIRED_PAGE_STATUS_RETIRED,
> > +			};
> > +
> > +			ret = drm_ras_retired_pages_add(list, &page);
> > +			if (ret)
> > +				return ret;
> > +		}
> > +
> > +		list_for_each_entry(pos, &mgr->queued_pages, queued_link)
> > {
> > +			page = (struct drm_ras_retired_page) {
> > +				.address = pos->addr + vr->dpa_base,
> > +				.size = PAGE_SIZE,
> > +				.status = pos->status ==
> > XE_PAGE_RESERVE_FAIL ?
> > +
> > DRM_RAS_RETIRED_PAGE_STATUS_FAILED :
> > +
> > DRM_RAS_RETIRED_PAGE_STATUS_PENDING,
> > +			};
> > +
> > +			ret = drm_ras_retired_pages_add(list, &page);
> > +			if (ret)
> > +				return ret;
> > +		}
> > +	}
> > +
> > +	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;
> > diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.h
> > b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.h
> > index d77f067d197b..7fdcd9836148 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_pages;
> >  struct xe_device;
> >  struct xe_tile;
> >  struct xe_vram_region;
> > @@ -33,6 +34,7 @@ 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_pages(struct xe_device *xe, struct
> > +drm_ras_retired_pages *list);
> > 
> >  static inline struct xe_ttm_vram_mgr_resource *
> > to_xe_ttm_vram_mgr_resource(struct ttm_resource *res)
> > --
> > 2.56.0
> 

  reply	other threads:[~2026-11-30 16:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 18:17 [PATCH v6 0/3] drm/xe: Expose retired VRAM pages via drm-ras Rodrigo Vivi
2026-11-27 18:17 ` [PATCH v6 1/3] drm/ras: Check the node type in node lookups Rodrigo Vivi
2026-11-27 18:24   ` sashiko-bot
2026-11-27 18:41     ` Rodrigo Vivi
2026-11-30  4:24   ` Tauro, Riana
2026-11-27 18:17 ` [PATCH v6 2/3] drm/ras: Add retired-pages node type Rodrigo Vivi
2026-11-30  5:01   ` Tauro, Riana
2026-11-30 15:34     ` Rodrigo Vivi
2026-11-30 16:27       ` Tauro, Riana
2026-11-30 16:30         ` Tauro, Riana
2026-11-30  5:09   ` Tauro, Riana
2026-11-30 13:35     ` Rodrigo Vivi
2026-11-30 18:02       ` Rodrigo Vivi
2026-11-27 18:17 ` [PATCH v6 3/3] drm/xe: Expose retired VRAM pages via drm-ras Rodrigo Vivi
2026-11-29 17:31   ` Upadhyay, Tejas
2026-11-30 16:04     ` Rodrigo Vivi [this message]
2026-11-30  5:04   ` Tauro, Riana

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=aw2edG25HMvI4IYx@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