From nobody Sat Feb 7 08:53:19 2026 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (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 E89FB295DBD; Sat, 24 Jan 2026 07:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240796; cv=none; b=jwCNdMY8yMrV9mc10TlOgdteY9w6hyXTeh94BhwvWyn4LBNK2ZN1jZSk4L0DovoKkZY50wMzRjZshrO+M4EQImN+ZkvJ/ounrvfJWCS9f/MKSTCdEbDKCcL/LInJkpfWMy3hrB022a/hEIo+6rGzIsk7SeEhUkY8xQWEpEPl4dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240796; c=relaxed/simple; bh=DHHusRbl1IM4WN4WL9LdbN3k4S50p6qeMvx+0XHW0V8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gRGvN7zxztWP6AwXZgNNbvdq5Aj1JpnQbqgnZc5MKCbKUQl5/PW2PWy8LdZlKQZ4R8rVwK2hFw6iuqdo21spNI7EYyHyZaUzjporBR6lPOie2K7Xvv5CNQzyn0NDwjWLNqqg4lMQQCsERWyr0FyyDuxv43puxE645pl85LaOJfM= 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=Alaj+Rcu; arc=none smtp.client-ip=115.124.30.111 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="Alaj+Rcu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1769240785; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Z4gdvlXokQQkApksODv/C5pE+VqLfxiQb8yzNUh4ogA=; b=Alaj+RcuD7WFDhtwyDLdP7cSly0cK2cDfC+8I3B2mOsJ1E3KRO4wqEFMcahIsew4IePn/Ig+iYePL0elkFMPBgO6LCkv0XxU/I+Tf2zqKg03P01eTTQK5bwdDSnoPBg6kJK/hKbkOUSp6jo30qSc14mqDdcETuNISZMYmRscJt0= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WxiIIAG_1769240784 cluster:ay36) by smtp.aliyun-inc.com; Sat, 24 Jan 2026 15:46:25 +0800 From: Shuai Xue To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, bhelgaas@google.com, kbusch@kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com Cc: mahesh@linux.ibm.com, oohall@gmail.com, xueshuai@linux.alibaba.com, Jonathan.Cameron@huawei.com, terry.bowman@amd.com, tianruidong@linux.alibaba.com, lukas@wunner.de Subject: [PATCH v7 1/5] PCI/DPC: Clarify naming for error port in DPC Handling Date: Sat, 24 Jan 2026 15:45:53 +0800 Message-Id: <20260124074557.73961-2-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260124074557.73961-1-xueshuai@linux.alibaba.com> References: <20260124074557.73961-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. Reviewed-by: Kuppuswamy Sathyanarayanan Signed-off-by: Shuai Xue Reviewed-by: Jonathan Cameron --- 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 Sat Feb 7 08:53:19 2026 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 C5B151C01; Sat, 24 Jan 2026 07:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240792; cv=none; b=ZNBpa5YJ7AdxlQ+7JkWtkx4aYFWkEh+SW+uJmZ7cHTTzctQygNWRXYdauofuSOcmZhA5XO7WOi6j/FxdiM2uSXZgbPAoOTQ8Y7JKnL4IkPTpQAzT/6C24BlIsDz8CVR+0UWwLckZ/4z+uTZbX3RFrVssRndlRC7kdC1RxuMaQO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240792; c=relaxed/simple; bh=RgE9a2Wwt1gIeZtjLdK3dH8CQ0YGAe86n6qWlq1YJS4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z3qGsx49NHXpgSvkNXMx4kMAHwaesH7eTc0HSDbPKOdy3MK12jqeFEu9iNuMEOkfXHDm0WUVf/BC78YRj8rgTgy7OfqbHn28O8mV91hyRV/ugK1J4CXc5V+nghnPSmMRutD+8xzPkoW76X+4B/0NpdXJ9IHJWsU3Z7PpLdyZdp0= 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=x7859l9F; arc=none smtp.client-ip=115.124.30.110 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="x7859l9F" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1769240786; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=gdJzXK+D/+LAbE0E0SHsIWq9BjPFdGgwrb0qI4bTG8Y=; b=x7859l9FF17Y5zfJ3cKID4MNtRqRyuUO4v2XrYteCFthFDbF5o3HxGJjd+zwfV/6NjmWfZCr1Vx82wAJya+vnaHRMraigmKVLu6jGsFZ4fbRLkVa8inm2imqb7TIxO+THfQ7D4ZNr61cbHhuLKAQLQ80gHHiNO7Ngpq0a/1EYco= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WxiIIAV_1769240785 cluster:ay36) by smtp.aliyun-inc.com; Sat, 24 Jan 2026 15:46:26 +0800 From: Shuai Xue To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, bhelgaas@google.com, kbusch@kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com Cc: mahesh@linux.ibm.com, oohall@gmail.com, xueshuai@linux.alibaba.com, Jonathan.Cameron@huawei.com, terry.bowman@amd.com, tianruidong@linux.alibaba.com, lukas@wunner.de Subject: [PATCH v7 2/5] PCI/DPC: Run recovery on device that detected the error Date: Sat, 24 Jan 2026 15:45:54 +0800 Message-Id: <20260124074557.73961-3-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260124074557.73961-1-xueshuai@linux.alibaba.com> References: <20260124074557.73961-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. Reviewed-by: Kuppuswamy Sathyanarayanan Signed-off-by: Shuai Xue --- 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 0e67014aa001..58640e656897 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -771,7 +771,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..b6e9d652297e 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,8 @@ 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); + pci_dev_put(err_dev); =20 send_ost: =20 --=20 2.39.3 From nobody Sat Feb 7 08:53:19 2026 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 302C5171C9; Sat, 24 Jan 2026 07:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240793; cv=none; b=f7qrkJndjvr91QiF27aYi3uxv6PAVvjphKv9z9y3eNlEWejnrOHsSNkE2qZroLE+AGVW82517nrV9gL/B6JJ27C+DRXh6q4MJmlCUEzz09d/JupagB3NX4XP6cT0kS+aWyPyVXfN7GCvIaCmR64/MXzgQIuy9sDqo9wrDjZrRqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240793; c=relaxed/simple; bh=QJ8vCKcz1McGYRsdrAKJFHAVKZvVbELR6t+Nv0ULOPo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xs9zRwxbIQLyqAuN5+miCyKZxO7ekHwoylwzdmjkzgTd5uxdAk1k7EaHv33dRLU2HHSMqscMlarPVCVWiO/Fs6/HGn0kkh1P8aw0bGUBpGjnL8C5yoWcz8yHgeG4v4lbpAm2BLDRrRdCN9DEGHqIjwpN/gXt36OGkkAwnzdRPWM= 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=Wy7bTqRD; arc=none smtp.client-ip=115.124.30.110 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="Wy7bTqRD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1769240787; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Lai+WgHyyBBA7L8Dsr49RmuA+H1xMDngo1aaMmEEBco=; b=Wy7bTqRDrcToZxm8nw8Z4XGqnuo97StG1UNGeT/LLdVb3LpyQ9cEucLkHVnZK7dUVm2NPjBs8RqqtSwWidtmD6/IDrTaLsZ6MkVnK+UtALCA/9cx6FdmSqs+s2BBB/neVINtXtReRaI1qFr7CPMs1KdSU7OkgGZUbk4VHx6vB5A= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WxiIIB1_1769240786 cluster:ay36) by smtp.aliyun-inc.com; Sat, 24 Jan 2026 15:46:26 +0800 From: Shuai Xue To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, bhelgaas@google.com, kbusch@kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com Cc: mahesh@linux.ibm.com, oohall@gmail.com, xueshuai@linux.alibaba.com, Jonathan.Cameron@huawei.com, terry.bowman@amd.com, tianruidong@linux.alibaba.com, lukas@wunner.de Subject: [PATCH v7 3/5] PCI/AER: Report fatal errors of RCiEP and EP if link recoverd Date: Sat, 24 Jan 2026 15:45:55 +0800 Message-Id: <20260124074557.73961-4-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260124074557.73961-1-xueshuai@linux.alibaba.com> References: <20260124074557.73961-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 r= eceived 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 r= eceived from 0015:01:00.0 pcieport 0015:00:00.0: AER: broadcast error_detected message + vfio-pci 0015:01:00.0: AER: Errors reported prior to reset + vfio-pci 0015:01:00.0: PCIe Bus Error: severity=3DUncorrectable (Fatal), = type=3DTransaction Layer, (Receiver ID) + vfio-pci 0015:01:00.0: device [144d:a80a] error status/mask=3D00001000/= 00400000 + vfio-pci 0015:01:00.0: [12] TLP (First) + vfio-pci 0015:01:00.0: AER: TLP Header: 0x4a004010 0x00000040 0x0100000= 0 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: 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 Signed-off-by: Shuai Xue Reviewed-by: Jonathan Cameron Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/pci/pci.h | 4 +++- drivers/pci/pcie/aer.c | 32 ++++++++++++++++++++++++++++---- drivers/pci/pcie/dpc.c | 2 +- drivers/pci/pcie/err.c | 5 +++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 58640e656897..bd020ba0cef0 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -746,8 +746,10 @@ 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); +void aer_report_frozen_error(struct pci_dev *dev); =20 int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2, unsigned int tlp_len, bool flit, diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index e0bcaa896803..4c0a2bbe9197 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -1384,12 +1384,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; @@ -1420,7 +1422,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, @@ -1447,17 +1450,38 @@ int aer_get_device_error_info(struct aer_err_info *= info, int i) return 1; } =20 +void aer_report_frozen_error(struct pci_dev *dev) +{ + struct aer_err_info info; + int type =3D pci_pcie_type(dev); + + if (type !=3D PCI_EXP_TYPE_ENDPOINT && type !=3D PCI_EXP_TYPE_RC_END) + return; + + info.error_dev_num =3D 0; + info.severity =3D AER_FATAL; + info.level =3D KERN_ERR; + add_error_device(&info, dev); + + if (aer_get_device_error_info(&info, 0, true)) { + pci_err(dev, "Errors reported prior to reset\n"); + aer_print_error(&info, 0); + } + + pci_dev_put(dev); /* pairs with pci_dev_get() in add_error_device() */ +} + static inline void aer_process_err_devices(struct aer_err_info *e_info) { int i; =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 bebe4bc111d7..0780ea09478b 100644 --- a/drivers/pci/pcie/err.c +++ b/drivers/pci/pcie/err.c @@ -253,6 +253,11 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, pci_warn(bridge, "subordinate device reset failed\n"); goto failed; } + + /* Link recovered, report fatal errors of RCiEP or EP */ + if (state =3D=3D pci_channel_io_frozen) + aer_report_frozen_error(dev); + } =20 if (status =3D=3D PCI_ERS_RESULT_NEED_RESET) { --=20 2.39.3 From nobody Sat Feb 7 08:53:19 2026 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (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 32FBD1C01; Sat, 24 Jan 2026 07:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240798; cv=none; b=LjLqf01cBZ61ja/Tk3mh0zbDkF61SbTAB947pODrs8QFB1lCigjN5rql8DN2wxtng2fLipxdR0ZdbHv738nCI7riiQVsJibUoxbEdiI+sUtWO/B7DsFBaY5P4h8k4FCMuFbNsQYITwmCrM76lAs1miKtxeUvDrTtcS0PvdSH6V8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240798; c=relaxed/simple; bh=DNLTpq5pOf+Zd30it71XQ2eM3DCg4fdegZhQZZ6+eQ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uTEk2trZqSm7y6o1xC5Cn4KJuX2AthZ4oA1qMZ2KhaN22pe4NcYYScmYwB9SYNZk2RhcHjT508wsNPVoZHHjCmM8sfOEVBIAILNnFF5RxL93YPxxlghM+gEYb5ClnaG/mwjJR1WDx5dBHpWUGHjWQ2op6KTl8ZM0KmIto/X5Jog= 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=QqohUQ1B; arc=none smtp.client-ip=115.124.30.124 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="QqohUQ1B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1769240788; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=aFxdKk3TVTGbZ741QSPtHZ39lb0EWDC9svYSkf2cf1o=; b=QqohUQ1B/eASue0I3tHfV07sqdGNN0hTkOEt4K7H10JF0oRPk4zUm0+X6SmuBZ1DaLsAN3ifwUVxtMyf3O97y4UO/mG36IgruWHskd3vj18MtkPLaaWMnZ7w1rO2F7YD45gn3nbtEOzEThnEkWpiE+Do98m2M2mf+5DNgeJy7pY= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WxiIIBY_1769240787 cluster:ay36) by smtp.aliyun-inc.com; Sat, 24 Jan 2026 15:46:27 +0800 From: Shuai Xue To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, bhelgaas@google.com, kbusch@kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com Cc: mahesh@linux.ibm.com, oohall@gmail.com, xueshuai@linux.alibaba.com, Jonathan.Cameron@huawei.com, terry.bowman@amd.com, tianruidong@linux.alibaba.com, lukas@wunner.de Subject: [PATCH v7 4/5] PCI/AER: Clear both AER fatal and non-fatal status Date: Sat, 24 Jan 2026 15:45:56 +0800 Message-Id: <20260124074557.73961-5-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260124074557.73961-1-xueshuai@linux.alibaba.com> References: <20260124074557.73961-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 DPC driver clears AER fatal status for the port that reported the error, but not for the downstream device that deteced the error. The current recovery code only clears non-fatal AER status, leaving fatal status bits set in the error device. Use pci_aer_raw_clear_status() to clear both fatal and non-fatal error status in the error device, ensuring all AER status bits are properly cleared after recovery. Fixes: aa344bc8b727 ("PCI/ERR: Clear AER status only when we control AER") Cc: stable@vger.kernel.org Signed-off-by: Shuai Xue Reviewed-by: Jonathan Cameron Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/pci/pcie/err.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c index 0780ea09478b..5e463efc3d05 100644 --- a/drivers/pci/pcie/err.c +++ b/drivers/pci/pcie/err.c @@ -285,7 +285,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_raw_clear_status(dev); } =20 pci_walk_bridge(bridge, pci_pm_runtime_put, NULL); --=20 2.39.3 From nobody Sat Feb 7 08:53:19 2026 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (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 860812BEFF6; Sat, 24 Jan 2026 07:46:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240807; cv=none; b=FgeHfNAUN+YunduunwAnWkssViq0rYyDY5l9DImasB1Tf4tPhlHYvVIdeE9hEOJMDU3oS4ZeRAwsMkuLWfsqPuSzkT4xzSNZFmoOSybF0OsrkTl29TL/EkYrQv7oqGyvxWNHy5I7Y6kelC+GHUlVXNyk5yuH+Jkvp3TrKhuqUXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769240807; c=relaxed/simple; bh=DVWMHTNJQE5K0BQW2nIXCCu88zLHRBYPXSf6sOrFFy4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ot5mYLmRLlsWtAzRRbjGlRLY1AGfDeYcxz9Naub5NilxuG9n+vXSagbHiVY8EOKVx0UdibAtR6teD7BYwdL0ZlSbpzNb4FYAwL5OBwXPReE8i6o4H7f2xk5FDlEAwqZupC9pbxG3D0ZsHBmzUefUW4zAEl8v94M32E2TsbxkYJc= 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=t7EV4mG+; arc=none smtp.client-ip=115.124.30.111 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="t7EV4mG+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1769240789; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=sBSDEixm4+8FCCTYQu1UeCBdF+LTdyt08Svk7uwlzxo=; b=t7EV4mG+yoarR/t0bXg0k/9wDAMAJfjbQMZjC8ekDzUVmXakmw0E9Q+NPPUZkXdCETEcQzmdaJW8PjKVDLriz1Eeyeh8sEzp7U7mFAfwuPfs3dm+5nv0u4qanZuszEdNuBoZvsDXMTXkcWv8rKc9rVHeNmbpUgQhSKYLIgIhlkA= Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0WxiIIC1_1769240788 cluster:ay36) by smtp.aliyun-inc.com; Sat, 24 Jan 2026 15:46:28 +0800 From: Shuai Xue To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, bhelgaas@google.com, kbusch@kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com Cc: mahesh@linux.ibm.com, oohall@gmail.com, xueshuai@linux.alibaba.com, Jonathan.Cameron@huawei.com, terry.bowman@amd.com, tianruidong@linux.alibaba.com, lukas@wunner.de Subject: [PATCH v7 5/5] PCI/AER: Only clear error bits in pcie_clear_device_status() Date: Sat, 24 Jan 2026 15:45:57 +0800 Message-Id: <20260124074557.73961-6-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260124074557.73961-1-xueshuai@linux.alibaba.com> References: <20260124074557.73961-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" Currently, pcie_clear_device_status() clears the entire PCIe Device Status register (PCI_EXP_DEVSTA), which includes both error status bits and other status bits such as AUX Power Detected (AUXPD) and Transactions Pending (TRPND). Clearing non-error status bits can interfere with other drivers or subsystems that may rely on these bits. To fix it, only clear the error bits (0xf) while preserving other status bits. Fixes: ec752f5d54d7 ("PCI/AER: Clear device status bits during ERR_FATAL an= d ERR_NONFATAL") Cc: stable@vger.kernel.org Suggested-by: Lukas Wunner Signed-off-by: Shuai Xue Reviewed-by: Kuppuswamy Sathyanarayanan --- drivers/pci/pci.c | 2 +- include/uapi/linux/pci_regs.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 13dbb405dc31..0b947f90c333 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2246,7 +2246,7 @@ void pcie_clear_device_status(struct pci_dev *dev) u16 sta; =20 pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &sta); - pcie_capability_write_word(dev, PCI_EXP_DEVSTA, sta); + pcie_capability_write_word(dev, PCI_EXP_DEVSTA, sta & PCI_EXP_DEVSTA_ERR); } #endif =20 diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h index 3add74ae2594..f4b68203bc4e 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h @@ -534,6 +534,7 @@ #define PCI_EXP_DEVSTA_NFED 0x0002 /* Non-Fatal Error Detected */ #define PCI_EXP_DEVSTA_FED 0x0004 /* Fatal Error Detected */ #define PCI_EXP_DEVSTA_URD 0x0008 /* Unsupported Request Detected */ +#define PCI_EXP_DEVSTA_ERR 0xf /* Error bits */ #define PCI_EXP_DEVSTA_AUXPD 0x0010 /* AUX Power Detected */ #define PCI_EXP_DEVSTA_TRPND 0x0020 /* Transactions Pending */ #define PCI_CAP_EXP_RC_ENDPOINT_SIZEOF_V1 12 /* v1 endpoints without link = end here */ --=20 2.39.3