Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76B15C44500 for ; Thu, 22 Jan 2026 09:35:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3BD1410E96E; Thu, 22 Jan 2026 09:35:49 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="DC8WwmJD"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id DC35110E96E for ; Thu, 22 Jan 2026 09:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769074548; x=1800610548; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QBV2591VNpGzw1FCMeBzARtwxlCjoJ5+210iR4w/yYU=; b=DC8WwmJDO4RpHmNmzjh1FtCJagXAFopNox+sysMLcRMaJd73GVeaz5fi ZgZEl8JREgp5owfLF8N58ZHy8gYK947QwtiVPzmt5OoJwuP9GalTjkPry Z6LNsWmxGQc9EW160m0SBp8ncpJovFF2swgop1ipPXiP4YusIp2OaDbgx S/yfzPEm0VAYgvy35ngZVwCZZwOHAWtTS+PcYlxHiaYjCpAoncDILMAzy 06ccVRmeNwocX8+9pCD0CvL9DObSRwBntKIxzigdSJh5PE9TD2IloTE3E 88WrXOIVJ6JB+mm595UVNaKpOrshMyo+7PCf9zXWySdOzKTQs7SIhLEK+ A==; X-CSE-ConnectionGUID: 3j5h/ENLQKyh/fNMz1BWVg== X-CSE-MsgGUID: 5M2o+fDXR2u2cqM/m6Taaw== X-IronPort-AV: E=McAfee;i="6800,10657,11678"; a="80937736" X-IronPort-AV: E=Sophos;i="6.21,245,1763452800"; d="scan'208";a="80937736" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 01:35:47 -0800 X-CSE-ConnectionGUID: 9iMu6c5QQEC+UyXQWBwhWg== X-CSE-MsgGUID: pVd/BtAFTVmciKXXR0+1jA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,245,1763452800"; d="scan'208";a="207122751" Received: from rtauro-desk.iind.intel.com ([10.190.238.50]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2026 01:35:45 -0800 From: Riana Tauro To: intel-xe@lists.freedesktop.org Cc: riana.tauro@intel.com, anshuman.gupta@intel.com, rodrigo.vivi@intel.com, aravind.iddamsetty@linux.intel.com, badal.nilawar@intel.com, raag.jadav@intel.com, ravi.kishore.koppuravuri@intel.com, mallesh.koujalagi@intel.com Subject: [PATCH 2/8] drm/xe/xe_pci_error: Implement PCI error recovery callbacks Date: Thu, 22 Jan 2026 15:36:14 +0530 Message-ID: <20260122100613.3631582-12-riana.tauro@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20260122100613.3631582-10-riana.tauro@intel.com> References: <20260122100613.3631582-10-riana.tauro@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Add error_detected, mmio_enabled, slot_reset and resume recovery callbacks to handle PCIe Advanced Error Reporting (AER) errors. For fatal errors, the device is wedged and becomes inaccessible. Return PCI_ERS_RESULT_SLOT_RESET from error_detected to request a Secondary Bus Reset (SBR). For non-fatal errors, return PCI_ERS_RESULT_CAN_RECOVER from error_detected to trigger the mmio_enabled callback. In this callback, the device is queried to determine the error cause and attempt recovery based on the error type. Once the secondary bus reset(SBR) is completed the slot_reset callback cleanly removes and reprobe the device to restore functionality. Signed-off-by: Riana Tauro --- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device.h | 15 +++++ drivers/gpu/drm/xe/xe_device_types.h | 3 + drivers/gpu/drm/xe/xe_pci.c | 3 + drivers/gpu/drm/xe/xe_pci_error.c | 85 ++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_pci_error.c diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile index f6650ec3ab42..5581f2180b5c 100644 --- a/drivers/gpu/drm/xe/Makefile +++ b/drivers/gpu/drm/xe/Makefile @@ -98,6 +98,7 @@ xe-y += xe_bb.o \ xe_page_reclaim.o \ xe_pat.o \ xe_pci.o \ + xe_pci_error.o \ xe_pci_rebar.o \ xe_pcode.o \ xe_pm.o \ diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h index 58d7d8b2fea3..81480248eeff 100644 --- a/drivers/gpu/drm/xe/xe_device.h +++ b/drivers/gpu/drm/xe/xe_device.h @@ -43,6 +43,21 @@ static inline struct xe_device *ttm_to_xe_device(struct ttm_device *ttm) return container_of(ttm, struct xe_device, ttm); } +static inline bool xe_device_is_in_recovery(struct xe_device *xe) +{ + return atomic_read(&xe->in_recovery); +} + +static inline void xe_device_set_in_recovery(struct xe_device *xe) +{ + atomic_set(&xe->in_recovery, 1); +} + +static inline void xe_device_clear_in_recovery(struct xe_device *xe) +{ + atomic_set(&xe->in_recovery, 0); +} + struct xe_device *xe_device_create(struct pci_dev *pdev, const struct pci_device_id *ent); int xe_device_probe_early(struct xe_device *xe); diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index 944f909a86ad..2d140463dc5e 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -669,6 +669,9 @@ struct xe_device { bool inconsistent_reset; } wedged; + /** @in_recovery: Indicates if device is in recovery */ + atomic_t in_recovery; + /** @bo_device: Struct to control async free of BOs */ struct xe_bo_dev { /** @bo_device.async_free: Free worker */ diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c index c92cc176f669..e1ee393b7461 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -1255,6 +1255,8 @@ static const struct dev_pm_ops xe_pm_ops = { }; #endif +extern const struct pci_error_handlers xe_pci_error_handlers; + static struct pci_driver xe_pci_driver = { .name = DRIVER_NAME, .id_table = pciidlist, @@ -1262,6 +1264,7 @@ static struct pci_driver xe_pci_driver = { .remove = xe_pci_remove, .shutdown = xe_pci_shutdown, .sriov_configure = xe_pci_sriov_configure, + .err_handler = &xe_pci_error_handlers, #ifdef CONFIG_PM_SLEEP .driver.pm = &xe_pm_ops, #endif diff --git a/drivers/gpu/drm/xe/xe_pci_error.c b/drivers/gpu/drm/xe/xe_pci_error.c new file mode 100644 index 000000000000..a3cc01afa179 --- /dev/null +++ b/drivers/gpu/drm/xe/xe_pci_error.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2026 Intel Corporation + */ +#include +#include + +#include "xe_device.h" +#include "xe_gt.h" +#include "xe_pci.h" +#include "xe_uc.h" + +static void xe_pci_error_handling(struct pci_dev *pdev) +{ + struct xe_device *xe = pdev_to_xe_device(pdev); + + xe_device_set_in_recovery(xe); + xe_device_declare_wedged(xe); + + pci_disable_device(pdev); +} + +static pci_ers_result_t xe_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) +{ + dev_err(&pdev->dev, "PCI error detected, state %d\n", state); + + switch (state) { + case pci_channel_io_normal: + return PCI_ERS_RESULT_CAN_RECOVER; + case pci_channel_io_frozen: + xe_pci_error_handling(pdev); + return PCI_ERS_RESULT_NEED_RESET; + case pci_channel_io_perm_failure: + return PCI_ERS_RESULT_DISCONNECT; + } + + return PCI_ERS_RESULT_NEED_RESET; +} + +static pci_ers_result_t xe_pci_error_mmio_enabled(struct pci_dev *pdev) +{ + dev_err(&pdev->dev, "PCI mmio enabled\n"); + + return PCI_ERS_RESULT_NEED_RESET; +} + +static pci_ers_result_t xe_pci_error_slot_reset(struct pci_dev *pdev) +{ + const struct pci_device_id *ent = pci_match_id(pdev->driver->id_table, pdev); + struct xe_device *xe = pdev_to_xe_device(pdev); + + dev_err(&pdev->dev, "PCI slot reset\n"); + + pci_restore_state(pdev); + + if (pci_enable_device(pdev)) { + dev_err(&pdev->dev, + "Cannot re-enable PCI device after reset\n"); + return PCI_ERS_RESULT_DISCONNECT; + } + + /* + * Secondary Bus Reset wipes out all device memory + * requiring XE KMD to perform a device removal and reprobe. + */ + pdev->driver->remove(pdev); + xe_device_clear_in_recovery(xe); + + if (!pdev->driver->probe(pdev, ent)) + return PCI_ERS_RESULT_RECOVERED; + + return PCI_ERS_RESULT_RECOVERED; +} + +static void xe_pci_error_resume(struct pci_dev *pdev) +{ + dev_info(&pdev->dev, "PCI error resume\n"); +} + +const struct pci_error_handlers xe_pci_error_handlers = { + .error_detected = xe_pci_error_detected, + .mmio_enabled = xe_pci_error_mmio_enabled, + .slot_reset = xe_pci_error_slot_reset, + .resume = xe_pci_error_resume, +}; -- 2.47.1