From nobody Thu Oct 2 11:52:31 2025 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAC21244681; Wed, 17 Sep 2025 06:34:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758090847; cv=none; b=Y0/sHS6k/3NAaaPWVOfmDM9T3/XFKeM/HKcsaGCowmc5sF3YC9SANdINU5yMr/W5p0G0VVB2wp6agabsN2uo8QrNPDUFddN6GqC0sBk4bEZo6S2syFHklCA3XtkSIGN/P9Dr9ErXeq8quYOjNr6rUamUEna4dr77T/oAIjjLJEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758090847; c=relaxed/simple; bh=LBCqY7zUR//93PTgwEx4kk207wNigO+Bez3AEF3pSfQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MXFaEIlENl4Dpw9iHGBmlXwH4tpET3z9m9hVD/nAuLIOj3W/sl/zGWOLmUNBrK4/PEVZZ4XslKYdoRhpeurJy4dpPQb9DyK5cadL4esijTXdh5owEyRhi8isSgG0KiAtvJeYiCHYO3QsS0kmNn2gFAfSgAeCY7bwK668hF5tQlk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=hLv3DHom; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="hLv3DHom" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1758090835; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=QXJAUGDYWc0L7efEoBkhFUMBAgY1wDEDmp5dyuIIeqY=; b=hLv3DHom0fySdMnb7nx16X1/hnN1w32zsLl6BjCZBJYOnqBL6Y6RtL68yu8nyIVGy+BRfCOjyllnEK4+n4o1hhpcDvxuW8+KA19Zl/0iyIwx8y6zinpHTEm1pXMjHwczTR5A1TI4nz7aIOWoSM8Cl6iCmIwvH5gZKhyPvhrvRHQ= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WoBL8K6_1758090834 cluster:ay36) by smtp.aliyun-inc.com; Wed, 17 Sep 2025 14:33:54 +0800 From: Shuai Xue To: bhelgaas@google.com, mahesh@linux.ibm.com, mani@kernel.org, Jonathan.Cameron@huawei.com, sathyanarayanan.kuppuswamy@linux.intel.com Cc: oohall@gmail.com, xueshuai@linux.alibaba.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 1/3] PCI/DPC: Clarify naming for error port in DPC Handling Date: Wed, 17 Sep 2025 14:33:50 +0800 Message-Id: <20250917063352.19429-2-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250917063352.19429-1-xueshuai@linux.alibaba.com> References: <20250917063352.19429-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" dpc_handler() is registered for error port which recevie DPC interrupt and acpi_dpc_port_get() locate the port that experienced the containment event. Rename edev and pdev to err_port for clear so that later patch will avoid misused err_port in pcie_do_recovery(). No functional changes intended. Signed-off-by: Shuai Xue Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/pci/pcie/dpc.c | 10 +++++----- drivers/pci/pcie/edr.c | 34 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c index fc18349614d7..bff29726c6a5 100644 --- a/drivers/pci/pcie/dpc.c +++ b/drivers/pci/pcie/dpc.c @@ -361,21 +361,21 @@ static bool dpc_is_surprise_removal(struct pci_dev *p= dev) =20 static irqreturn_t dpc_handler(int irq, void *context) { - struct pci_dev *pdev =3D context; + struct pci_dev *err_port =3D context; =20 /* * According to PCIe r6.0 sec 6.7.6, errors are an expected side effect * of async removal and should be ignored by software. */ - if (dpc_is_surprise_removal(pdev)) { - dpc_handle_surprise_removal(pdev); + if (dpc_is_surprise_removal(err_port)) { + dpc_handle_surprise_removal(err_port); return IRQ_HANDLED; } =20 - dpc_process_error(pdev); + dpc_process_error(err_port); =20 /* We configure DPC so it only triggers on ERR_FATAL */ - pcie_do_recovery(pdev, pci_channel_io_frozen, dpc_reset_link); + pcie_do_recovery(err_port, pci_channel_io_frozen, dpc_reset_link); =20 return IRQ_HANDLED; } diff --git a/drivers/pci/pcie/edr.c b/drivers/pci/pcie/edr.c index e86298dbbcff..521fca2f40cb 100644 --- a/drivers/pci/pcie/edr.c +++ b/drivers/pci/pcie/edr.c @@ -150,7 +150,7 @@ static int acpi_send_edr_status(struct pci_dev *pdev, s= truct pci_dev *edev, =20 static void edr_handle_event(acpi_handle handle, u32 event, void *data) { - struct pci_dev *pdev =3D data, *edev; + struct pci_dev *pdev =3D data, *err_port; pci_ers_result_t estate =3D PCI_ERS_RESULT_DISCONNECT; u16 status; =20 @@ -169,36 +169,36 @@ static void edr_handle_event(acpi_handle handle, u32 = event, void *data) * may be that port or a parent of it (PCI Firmware r3.3, sec * 4.6.13). */ - edev =3D acpi_dpc_port_get(pdev); - if (!edev) { + err_port =3D acpi_dpc_port_get(pdev); + if (!err_port) { pci_err(pdev, "Firmware failed to locate DPC port\n"); return; } =20 - pci_dbg(pdev, "Reported EDR dev: %s\n", pci_name(edev)); + pci_dbg(pdev, "Reported EDR dev: %s\n", pci_name(err_port)); =20 /* If port does not support DPC, just send the OST */ - if (!edev->dpc_cap) { - pci_err(edev, FW_BUG "This device doesn't support DPC\n"); + if (!err_port->dpc_cap) { + pci_err(err_port, FW_BUG "This device doesn't support DPC\n"); goto send_ost; } =20 /* Check if there is a valid DPC trigger */ - pci_read_config_word(edev, edev->dpc_cap + PCI_EXP_DPC_STATUS, &status); + pci_read_config_word(err_port, err_port->dpc_cap + PCI_EXP_DPC_STATUS, &s= tatus); if (!(status & PCI_EXP_DPC_STATUS_TRIGGER)) { - pci_err(edev, "Invalid DPC trigger %#010x\n", status); + pci_err(err_port, "Invalid DPC trigger %#010x\n", status); goto send_ost; } =20 - dpc_process_error(edev); - pci_aer_raw_clear_status(edev); + dpc_process_error(err_port); + pci_aer_raw_clear_status(err_port); =20 /* * Irrespective of whether the DPC event is triggered by ERR_FATAL * or ERR_NONFATAL, since the link is already down, use the FATAL * error recovery path for both cases. */ - estate =3D pcie_do_recovery(edev, pci_channel_io_frozen, dpc_reset_link); + estate =3D pcie_do_recovery(err_port, pci_channel_io_frozen, dpc_reset_li= nk); =20 send_ost: =20 @@ -207,15 +207,15 @@ static void edr_handle_event(acpi_handle handle, u32 = event, void *data) * to firmware. If not successful, send _OST(0xF, BDF << 16 | 0x81). */ if (estate =3D=3D PCI_ERS_RESULT_RECOVERED) { - pci_dbg(edev, "DPC port successfully recovered\n"); - pcie_clear_device_status(edev); - acpi_send_edr_status(pdev, edev, EDR_OST_SUCCESS); + pci_dbg(err_port, "DPC port successfully recovered\n"); + pcie_clear_device_status(err_port); + acpi_send_edr_status(pdev, err_port, EDR_OST_SUCCESS); } else { - pci_dbg(edev, "DPC port recovery failed\n"); - acpi_send_edr_status(pdev, edev, EDR_OST_FAILED); + pci_dbg(err_port, "DPC port recovery failed\n"); + acpi_send_edr_status(pdev, err_port, EDR_OST_FAILED); } =20 - pci_dev_put(edev); + pci_dev_put(err_port); } =20 void pci_acpi_add_edr_notifier(struct pci_dev *pdev) --=20 2.39.3 From nobody Thu Oct 2 11:52:31 2025 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AEF910F1; Wed, 17 Sep 2025 06:34:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758090845; cv=none; b=pfDSLwDAA6JVirx6hSz//y+lHjjEpHqgT6Dqtnqp85aiBBEmOUyYhicXD/KCZMJChNHFaNiJ1ud3BPfJ4r1KORzZNyG+jI61a7XUUsw16Y0T07/4pzHB+sBes48Y/s80nXaPtrIymyMk3Fs8Rd32Z4qYkjqyC7afeve95/pz/WI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758090845; c=relaxed/simple; bh=sT0F+Hc66dK4r2beABOLLbf0r0XrWJYnUthBMb1L3sw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OubRH/2w98iD7ZLDINauarZ8zEDsLNE1vvBNweC3nO/qW85zeS5ThFCwpycGD0xV7p2paWfHcx3repcPjpTvfrs/9Icr5lSg9p+3XG7PX3sdSY14Hxpep5tsyLs9PKAWE42O3vMw75FFlAt7uk31aCN+95zrYjD2bMb6b6KPyIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=O3FmQx7P; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="O3FmQx7P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1758090836; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=l7cInLt2viFP86GcrWWMRNS3v9Fhvd3HCaJy6F6UZxk=; b=O3FmQx7PXpdQlcBNNOnsdbPY5u6UtAc6jnmuIVw14FwKU/LER1rFKNoIIqpiLMYyUGq+mrMtHLJPpzXU/eMgpP1VkcwysDN8cB/qcgxUisREO3YlzsjoB9ou+gBuVhWsKi3riSIohoQiwqyV/xtjDpLf1tHNrnX4nqHooYn03K4= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WoBL8KM_1758090835 cluster:ay36) by smtp.aliyun-inc.com; Wed, 17 Sep 2025 14:33:55 +0800 From: Shuai Xue To: bhelgaas@google.com, mahesh@linux.ibm.com, mani@kernel.org, Jonathan.Cameron@huawei.com, sathyanarayanan.kuppuswamy@linux.intel.com Cc: oohall@gmail.com, xueshuai@linux.alibaba.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 2/3] PCI/DPC: Run recovery on device that detected the error Date: Wed, 17 Sep 2025 14:33:51 +0800 Message-Id: <20250917063352.19429-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250917063352.19429-1-xueshuai@linux.alibaba.com> References: <20250917063352.19429-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current implementation of pcie_do_recovery() assumes that the recovery process is executed for the device that detected the error. However, the DPC driver currently passes the error port that experienced the DPC event to pcie_do_recovery(). Use the SOURCE ID register to correctly identify the device that detected the error. When passing the error device, the pcie_do_recovery() will find the upstream bridge and walk bridges potentially AER affected. And subsequent commits will be able to accurately access AER status of the error device. Should not observe any functional changes. Signed-off-by: Shuai Xue Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/pci/pci.h | 2 +- drivers/pci/pcie/dpc.c | 25 +++++++++++++++++++++---- drivers/pci/pcie/edr.c | 7 ++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 34f65d69662e..de2f07cefa72 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -654,7 +654,7 @@ struct rcec_ea { void pci_save_dpc_state(struct pci_dev *dev); void pci_restore_dpc_state(struct pci_dev *dev); void pci_dpc_init(struct pci_dev *pdev); -void dpc_process_error(struct pci_dev *pdev); +struct pci_dev *dpc_process_error(struct pci_dev *pdev); pci_ers_result_t dpc_reset_link(struct pci_dev *pdev); bool pci_dpc_recovered(struct pci_dev *pdev); unsigned int dpc_tlp_log_len(struct pci_dev *dev); diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c index bff29726c6a5..f6069f621683 100644 --- a/drivers/pci/pcie/dpc.c +++ b/drivers/pci/pcie/dpc.c @@ -260,10 +260,20 @@ static int dpc_get_aer_uncorrect_severity(struct pci_= dev *dev, return 1; } =20 -void dpc_process_error(struct pci_dev *pdev) +/** + * dpc_process_error - handle the DPC error status + * @pdev: the port that experienced the containment event + * + * Return: the device that detected the error. + * + * NOTE: The device reference count is increased, the caller must decrement + * the reference count by calling pci_dev_put(). + */ +struct pci_dev *dpc_process_error(struct pci_dev *pdev) { u16 cap =3D pdev->dpc_cap, status, source, reason, ext_reason; struct aer_err_info info =3D {}; + struct pci_dev *err_dev; =20 pci_read_config_word(pdev, cap + PCI_EXP_DPC_STATUS, &status); =20 @@ -279,6 +289,7 @@ void dpc_process_error(struct pci_dev *pdev) pci_aer_clear_nonfatal_status(pdev); pci_aer_clear_fatal_status(pdev); } + err_dev =3D pci_dev_get(pdev); break; case PCI_EXP_DPC_STATUS_TRIGGER_RSN_NFE: case PCI_EXP_DPC_STATUS_TRIGGER_RSN_FE: @@ -290,6 +301,8 @@ void dpc_process_error(struct pci_dev *pdev) "ERR_FATAL" : "ERR_NONFATAL", pci_domain_nr(pdev->bus), PCI_BUS_NUM(source), PCI_SLOT(source), PCI_FUNC(source)); + err_dev =3D pci_get_domain_bus_and_slot(pci_domain_nr(pdev->bus), + PCI_BUS_NUM(source), source & 0xff); break; case PCI_EXP_DPC_STATUS_TRIGGER_RSN_IN_EXT: ext_reason =3D status & PCI_EXP_DPC_STATUS_TRIGGER_RSN_EXT; @@ -304,8 +317,11 @@ void dpc_process_error(struct pci_dev *pdev) if (ext_reason =3D=3D PCI_EXP_DPC_STATUS_TRIGGER_RSN_RP_PIO && pdev->dpc_rp_extensions) dpc_process_rp_pio_error(pdev); + err_dev =3D pci_dev_get(pdev); break; } + + return err_dev; } =20 static void pci_clear_surpdn_errors(struct pci_dev *pdev) @@ -361,7 +377,7 @@ static bool dpc_is_surprise_removal(struct pci_dev *pde= v) =20 static irqreturn_t dpc_handler(int irq, void *context) { - struct pci_dev *err_port =3D context; + struct pci_dev *err_port =3D context, *err_dev; =20 /* * According to PCIe r6.0 sec 6.7.6, errors are an expected side effect @@ -372,10 +388,11 @@ static irqreturn_t dpc_handler(int irq, void *context) return IRQ_HANDLED; } =20 - dpc_process_error(err_port); + err_dev =3D dpc_process_error(err_port); =20 /* We configure DPC so it only triggers on ERR_FATAL */ - pcie_do_recovery(err_port, pci_channel_io_frozen, dpc_reset_link); + pcie_do_recovery(err_dev, pci_channel_io_frozen, dpc_reset_link); + pci_dev_put(err_dev); =20 return IRQ_HANDLED; } diff --git a/drivers/pci/pcie/edr.c b/drivers/pci/pcie/edr.c index 521fca2f40cb..3f971bb04433 100644 --- a/drivers/pci/pcie/edr.c +++ b/drivers/pci/pcie/edr.c @@ -150,7 +150,7 @@ static int acpi_send_edr_status(struct pci_dev *pdev, s= truct pci_dev *edev, =20 static void edr_handle_event(acpi_handle handle, u32 event, void *data) { - struct pci_dev *pdev =3D data, *err_port; + struct pci_dev *pdev =3D data, *err_port, *err_dev; pci_ers_result_t estate =3D PCI_ERS_RESULT_DISCONNECT; u16 status; =20 @@ -190,7 +190,7 @@ static void edr_handle_event(acpi_handle handle, u32 ev= ent, void *data) goto send_ost; } =20 - dpc_process_error(err_port); + err_dev =3D dpc_process_error(err_port); pci_aer_raw_clear_status(err_port); =20 /* @@ -198,7 +198,7 @@ static void edr_handle_event(acpi_handle handle, u32 ev= ent, void *data) * or ERR_NONFATAL, since the link is already down, use the FATAL * error recovery path for both cases. */ - estate =3D pcie_do_recovery(err_port, pci_channel_io_frozen, dpc_reset_li= nk); + estate =3D pcie_do_recovery(err_dev, pci_channel_io_frozen, dpc_reset_lin= k); =20 send_ost: =20 @@ -215,6 +215,7 @@ static void edr_handle_event(acpi_handle handle, u32 ev= ent, void *data) acpi_send_edr_status(pdev, err_port, EDR_OST_FAILED); } =20 + pci_dev_put(err_dev); pci_dev_put(err_port); } =20 --=20 2.39.3 From nobody Thu Oct 2 11:52:31 2025 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBA642773FE; Wed, 17 Sep 2025 06:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758090847; cv=none; b=cn4D63MeVJrMWiE+AoW8pPgP7Np+pNUA3pz/foimh5nOgOVG/MFCi1b7Y2LOKmyHlAgScZpP69ErlJYMZ9iRaV92dZYtO//5Z0ufPDzPllLZPEHQV5hzpIS+fhfhARrKhUZGe9jv5yHqQKA+cDEi/Ekwt4D01h/F3jkdRcFgzbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758090847; c=relaxed/simple; bh=XXIkW+I/HACkFSg+vyalgKlv0SyRuXkZlq8vs4C89eQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TiDpfn6jDBMcc7J7WefzhVW/C2Vt1uefqWiUB8fw3qq80PLcH/r8KwkSUW6FuWSZP+/FfhXZpbIGX21R4y+lc6fgwKV3nsxdXmwxNPelHOFN7TjBOIh+9o9JhbeSgaH3EYx91EwXwipsW7nXeze9567+X433EJ1iQiR9kWemvsU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=wXFckUrH; arc=none smtp.client-ip=115.124.30.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="wXFckUrH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1758090837; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Emk4LUrexpA6A1Qi+VgIagLLTTIpl1Z6BSUpE7Nvp4M=; b=wXFckUrHhE1QmJmfvSU8rfXL2oWvOl+e/QrkoPFPXqP9EpdPhie3pcBBaVoAfY5UHbVVmJ8ZXIWDWfX3uHQ9hHe365wiEYhe5XElWaRd4AdaaUbEpMeMS+6Xn3HYlb2F2KeYMy2KVBgVACbCr3XgIkt/myrWzeBUQWuXepvzBZg= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WoBL8KZ_1758090836 cluster:ay36) by smtp.aliyun-inc.com; Wed, 17 Sep 2025 14:33:56 +0800 From: Shuai Xue To: bhelgaas@google.com, mahesh@linux.ibm.com, mani@kernel.org, Jonathan.Cameron@huawei.com, sathyanarayanan.kuppuswamy@linux.intel.com Cc: oohall@gmail.com, xueshuai@linux.alibaba.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 3/3] PCI/AER: Report fatal errors of RCiEP and EP if link recoverd Date: Wed, 17 Sep 2025 14:33:52 +0800 Message-Id: <20250917063352.19429-4-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250917063352.19429-1-xueshuai@linux.alibaba.com> References: <20250917063352.19429-1-xueshuai@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The AER driver has historically avoided reading the configuration space of an endpoint or RCiEP that reported a fatal error, considering the link to that device unreliable. Consequently, when a fatal error occurs, the AER and DPC drivers do not report specific error types, resulting in logs like: pcieport 0015:00:00.0: EDR: EDR event received pcieport 0015:00:00.0: EDR: Reported EDR dev: 0015:00:00.0 pcieport 0015:00:00.0: DPC: containment event, status:0x200d, ERR_FATAL re= ceived from 0015:01:00.0 pcieport 0015:00:00.0: AER: broadcast error_detected message pcieport 0015:00:00.0: AER: broadcast mmio_enabled message pcieport 0015:00:00.0: AER: broadcast resume message pcieport 0015:00:00.0: pciehp: Slot(21): Link Down/Up ignored pcieport 0015:00:00.0: AER: device recovery successful pcieport 0015:00:00.0: EDR: DPC port successfully recovered pcieport 0015:00:00.0: EDR: Status for 0015:00:00.0: 0x80 AER status registers are sticky and Write-1-to-clear. If the link recovered after hot reset, we can still safely access AER status and TLP header of the error device. In such case, report fatal errors which helps to figure out t= he error root case. After this patch, the logs like: pcieport 0015:00:00.0: EDR: EDR event received pcieport 0015:00:00.0: EDR: Reported EDR dev: 0015:00:00.0 pcieport 0015:00:00.0: DPC: containment event, status:0x200d, ERR_FATAL re= ceived from 0015:01:00.0 pcieport 0015:00:00.0: AER: broadcast error_detected message vfio-pci 0015:01:00.0: PCIe Bus Error: severity=3DUncorrectable (Fatal), t= ype=3DTransaction Layer, (Receiver ID) pcieport 0015:00:00.0: pciehp: Slot(21): Link Down/Up ignored vfio-pci 0015:01:00.0: device [144d:a80a] error status/mask=3D00001000/0= 0400000 vfio-pci 0015:01:00.0: [12] TLP (First) vfio-pci 0015:01:00.0: AER: TLP Header: 0x4a004010 0x00000040 0x01000000= 0xffffffff pcieport 0015:00:00.0: AER: broadcast mmio_enabled message pcieport 0015:00:00.0: AER: broadcast resume message pcieport 0015:00:00.0: AER: device recovery successful pcieport 0015:00:00.0: EDR: DPC port successfully recovered pcieport 0015:00:00.0: EDR: Status for 0015:00:00.0: 0x80 Signed-off-by: Shuai Xue --- drivers/pci/pci.h | 3 ++- drivers/pci/pcie/aer.c | 11 +++++++---- drivers/pci/pcie/dpc.c | 2 +- drivers/pci/pcie/err.c | 11 +++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index de2f07cefa72..b8d364545e7d 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -629,7 +629,8 @@ struct aer_err_info { struct pcie_tlp_log tlp; /* TLP Header */ }; =20 -int aer_get_device_error_info(struct aer_err_info *info, int i); +int aer_get_device_error_info(struct aer_err_info *info, int i, + bool link_healthy); void aer_print_error(struct aer_err_info *info, int i); =20 int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2, diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index e286c197d716..157ad7fb44a0 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -1351,12 +1351,14 @@ EXPORT_SYMBOL_GPL(aer_recover_queue); * aer_get_device_error_info - read error status from dev and store it to = info * @info: pointer to structure to store the error record * @i: index into info->dev[] + * @link_healthy: link is healthy or not * * Return: 1 on success, 0 on error. * * Note that @info is reused among all error devices. Clear fields properl= y. */ -int aer_get_device_error_info(struct aer_err_info *info, int i) +int aer_get_device_error_info(struct aer_err_info *info, int i, + bool link_healthy) { struct pci_dev *dev; int type, aer; @@ -1387,7 +1389,8 @@ int aer_get_device_error_info(struct aer_err_info *in= fo, int i) } else if (type =3D=3D PCI_EXP_TYPE_ROOT_PORT || type =3D=3D PCI_EXP_TYPE_RC_EC || type =3D=3D PCI_EXP_TYPE_DOWNSTREAM || - info->severity =3D=3D AER_NONFATAL) { + info->severity =3D=3D AER_NONFATAL || + (info->severity =3D=3D AER_FATAL && link_healthy)) { =20 /* Link is still healthy for IO reads */ pci_read_config_dword(dev, aer + PCI_ERR_UNCOR_STATUS, @@ -1420,11 +1423,11 @@ static inline void aer_process_err_devices(struct a= er_err_info *e_info) =20 /* Report all before handling them, to not lose records by reset etc. */ for (i =3D 0; i < e_info->error_dev_num && e_info->dev[i]; i++) { - if (aer_get_device_error_info(e_info, i)) + if (aer_get_device_error_info(e_info, i, false)) aer_print_error(e_info, i); } for (i =3D 0; i < e_info->error_dev_num && e_info->dev[i]; i++) { - if (aer_get_device_error_info(e_info, i)) + if (aer_get_device_error_info(e_info, i, false)) handle_error_source(e_info->dev[i], e_info); } } diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c index f6069f621683..21c4e8371279 100644 --- a/drivers/pci/pcie/dpc.c +++ b/drivers/pci/pcie/dpc.c @@ -284,7 +284,7 @@ struct pci_dev *dpc_process_error(struct pci_dev *pdev) pci_warn(pdev, "containment event, status:%#06x: unmasked uncorrectable = error detected\n", status); if (dpc_get_aer_uncorrect_severity(pdev, &info) && - aer_get_device_error_info(&info, 0)) { + aer_get_device_error_info(&info, 0, false)) { aer_print_error(&info, 0); pci_aer_clear_nonfatal_status(pdev); pci_aer_clear_fatal_status(pdev); diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c index de6381c690f5..744d77ee7271 100644 --- a/drivers/pci/pcie/err.c +++ b/drivers/pci/pcie/err.c @@ -196,6 +196,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, struct pci_dev *bridge; pci_ers_result_t status =3D PCI_ERS_RESULT_CAN_RECOVER; struct pci_host_bridge *host =3D pci_find_host_bridge(dev->bus); + struct aer_err_info info; =20 /* * If the error was detected by a Root Port, Downstream Port, RCEC, @@ -223,6 +224,15 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, pci_warn(bridge, "subordinate device reset failed\n"); goto failed; } + + info.dev[0] =3D dev; + info.level =3D KERN_ERR; + info.severity =3D AER_FATAL; + /* Link recovered, report fatal errors of RCiEP or EP */ + if ((type =3D=3D PCI_EXP_TYPE_ENDPOINT || + type =3D=3D PCI_EXP_TYPE_RC_END) && + aer_get_device_error_info(&info, 0, true)) + aer_print_error(&info, 0); } else { pci_walk_bridge(bridge, report_normal_detected, &status); } @@ -259,6 +269,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, if (host->native_aer || pcie_ports_native) { pcie_clear_device_status(dev); pci_aer_clear_nonfatal_status(dev); + pci_aer_clear_fatal_status(dev); } =20 pci_walk_bridge(bridge, pci_pm_runtime_put, NULL); --=20 2.39.3