[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241016175426.0000411e@Huawei.com>
Date: Wed, 16 Oct 2024 17:54:26 +0100
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Terry Bowman <terry.bowman@....com>
CC: <ming4.li@...el.com>, <linux-cxl@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <linux-pci@...r.kernel.org>,
<dave@...olabs.net>, <dave.jiang@...el.com>, <alison.schofield@...el.com>,
<vishal.l.verma@...el.com>, <dan.j.williams@...el.com>,
<bhelgaas@...gle.com>, <mahesh@...ux.ibm.com>, <oohall@...il.com>,
<Benjamin.Cheatham@....com>, <rrichter@....com>, <nathan.fontenot@....com>,
<smita.koralahallichannabasappa@....com>
Subject: Re: [PATCH 07/15] cxl/aer/pci: Add CXL PCIe port uncorrectable
error recovery in AER service driver
On Tue, 8 Oct 2024 17:16:49 -0500
Terry Bowman <terry.bowman@....com> wrote:
> The current pcie_do_recovery() handles device recovery as result of
> uncorrectable errors (UCE). But, CXL port devices require unique
> recovery handling.
>
> Create a cxl_do_recovery() function parallel to pcie_do_recovery(). Add CXL
> specific handling to the new recovery function.
>
> The CXL port UCE recovery must invoke the AER service driver's CXL port
> UCE callback. This is different than the standard pcie_do_recovery()
> recovery that calls the pci_driver::err_handler UCE handler instead.
>
> Treat all CXL PCIe port UCE errors as fatal and call kernel panic to
> "recover" the error. A panic is called instead of attempting recovery
> to avoid potential system corruption.
>
> The uncorrectable support added here will be used to complete CXL PCIe
> port error handling in the future.
>
> Signed-off-by: Terry Bowman <terry.bowman@....com>
Hi Terry,
I'm a little bothered by the subtle difference in the bus walks
in here vs the existing cases. If we need them, comments needed
to explain why.
If we are going to have separate handling, see if you can share
a lot more of the code by factoring out common functions for
the pci and cxl handling with callbacks to handle the differences.
I've managed to get my head around this code a few times in the past
(I think!) and really don't fancy having two subtle variants to
consider next time we get a bug :( The RC_EC additions hurt my head.
Jonathan
> static int handles_cxl_error_iter(struct pci_dev *dev, void *data)
> diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c
> index 31090770fffc..de12f2eb19ef 100644
> --- a/drivers/pci/pcie/err.c
> +++ b/drivers/pci/pcie/err.c
> @@ -86,6 +86,63 @@ static int report_error_detected(struct pci_dev *dev,
> return 0;
> }
>
> +static int cxl_report_error_detected(struct pci_dev *dev,
> + pci_channel_state_t state,
> + enum pci_ers_result *result)
> +{
> + struct cxl_port_err_hndlrs *cxl_port_hndlrs;
> + struct pci_driver *pdrv;
> + pci_ers_result_t vote;
> +
> + device_lock(&dev->dev);
> + cxl_port_hndlrs = find_cxl_port_hndlrs();
Can we refactor to have a common function under this and report_error_detected()?
> + pdrv = dev->driver;
> + if (pci_dev_is_disconnected(dev)) {
> + vote = PCI_ERS_RESULT_DISCONNECT;
> + } else if (!pci_dev_set_io_state(dev, state)) {
> + pci_info(dev, "can't recover (state transition %u -> %u invalid)\n",
> + dev->error_state, state);
> + vote = PCI_ERS_RESULT_NONE;
> + } else if (!cxl_port_hndlrs || !cxl_port_hndlrs->error_detected) {
> + if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
> + vote = PCI_ERS_RESULT_NO_AER_DRIVER;
> + pci_info(dev, "can't recover (no error_detected callback)\n");
> + } else {
> + vote = PCI_ERS_RESULT_NONE;
> + }
> + } else {
> + vote = cxl_port_hndlrs->error_detected(dev, state);
> + }
> + pci_uevent_ers(dev, vote);
> + *result = merge_result(*result, vote);
> + device_unlock(&dev->dev);
> + return 0;
> +}
> static int pci_pm_runtime_get_sync(struct pci_dev *pdev, void *data)
> {
> pm_runtime_get_sync(&pdev->dev);
> @@ -188,6 +245,28 @@ static void pci_walk_bridge(struct pci_dev *bridge,
> cb(bridge, userdata);
> }
>
> +/**
> + * cxl_walk_bridge - walk bridges potentially AER affected
> + * @bridge: bridge which may be a Port, an RCEC, or an RCiEP
> + * @cb: callback to be called for each device found
> + * @userdata: arbitrary pointer to be passed to callback
> + *
> + * If the device provided is a bridge, walk the subordinate bus, including
> + * the device itself and any bridged devices on buses under this bus. Call
> + * the provided callback on each device found.
> + *
> + * If the device provided has no subordinate bus, e.g., an RCEC or RCiEP,
> + * call the callback on the device itself.
only call the callback on the device itself.
(as you call it as stated above either way).
> + */
> +static void cxl_walk_bridge(struct pci_dev *bridge,
> + int (*cb)(struct pci_dev *, void *),
> + void *userdata)
> +{
> + cb(bridge, userdata);
> + if (bridge->subordinate)
> + pci_walk_bus(bridge->subordinate, cb, userdata);
The difference between this and pci_walk_bridge() is subtle and
I'd like to avoid having both if we can.
> +}
> +
> pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
> pci_channel_state_t state,
> pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev))
> @@ -276,3 +355,74 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
>
> return status;
> }
> +
> +pci_ers_result_t cxl_do_recovery(struct pci_dev *bridge,
> + pci_channel_state_t state,
> + pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev))
> +{
> + struct pci_host_bridge *host = pci_find_host_bridge(bridge->bus);
> + pci_ers_result_t status = PCI_ERS_RESULT_CAN_RECOVER;
> + int type = pci_pcie_type(bridge);
> +
> + if ((type != PCI_EXP_TYPE_ROOT_PORT) &&
> + (type != PCI_EXP_TYPE_RC_EC) &&
> + (type != PCI_EXP_TYPE_DOWNSTREAM) &&
> + (type != PCI_EXP_TYPE_UPSTREAM)) {
> + pci_dbg(bridge, "Unsupported device type (%x)\n", type);
> + return status;
> + }
> +
Would similar trick to in pcie_do_recovery work here for the upstream
and downstream ports use pci_upstream_bridge() and for the others pass the dev into
pci_walk_bridge()?
> + cxl_walk_bridge(bridge, pci_pm_runtime_get_sync, NULL);
> +
> + pci_dbg(bridge, "broadcast error_detected message\n");
> + if (state == pci_channel_io_frozen) {
> + cxl_walk_bridge(bridge, cxl_report_frozen_detected, &status);
> + if (reset_subordinates(bridge) != PCI_ERS_RESULT_RECOVERED) {
> + pci_warn(bridge, "subordinate device reset failed\n");
> + goto failed;
> + }
> + } else {
> + cxl_walk_bridge(bridge, cxl_report_normal_detected, &status);
> + }
> +
> + if (status == PCI_ERS_RESULT_PANIC)
> + panic("CXL cachemem error. Invoking panic");
> +
> + if (status == PCI_ERS_RESULT_CAN_RECOVER) {
> + status = PCI_ERS_RESULT_RECOVERED;
> + pci_dbg(bridge, "broadcast mmio_enabled message\n");
> + cxl_walk_bridge(bridge, report_mmio_enabled, &status);
> + }
> +
> + if (status == PCI_ERS_RESULT_NEED_RESET) {
> + status = PCI_ERS_RESULT_RECOVERED;
> + pci_dbg(bridge, "broadcast slot_reset message\n");
> + report_slot_reset(bridge, &status);
> + pci_walk_bridge(bridge, report_slot_reset, &status);
> + }
> +
> + if (status != PCI_ERS_RESULT_RECOVERED)
> + goto failed;
> +
> + pci_dbg(bridge, "broadcast resume message\n");
> + cxl_walk_bridge(bridge, report_resume, &status);
> +
> + if (host->native_aer || pcie_ports_native) {
> + pcie_clear_device_status(bridge);
> + pci_aer_clear_nonfatal_status(bridge);
> + }
> +
> + cxl_walk_bridge(bridge, pci_pm_runtime_put, NULL);
> +
> + pci_info(bridge, "device recovery successful\n");
> + return status;
> +
> +failed:
> + cxl_walk_bridge(bridge, pci_pm_runtime_put, NULL);
> +
> + pci_uevent_ers(bridge, PCI_ERS_RESULT_DISCONNECT);
> +
> + pci_info(bridge, "device recovery failed\n");
> +
> + return status;
> +}
Powered by blists - more mailing lists