6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Niklas Schnelle commit 0261aef4b15efcee2860ab857e5cb05e9bfa47b0 upstream. When pdev is non-NULL, zpci_report_status() accesses the device's driver. To get a consistent state matching the recovery, the device lock needs to be held. Do so by expanding the existing device lock critical section. The lock only needs to be held when the pdev is non-NULL, so extract the pdev-specific reporting into a helper function which also adds a lockdep assertion to detect calls without the device lock held. Cc: stable@vger.kernel.org Fixes: 4ec6054e7321 ("s390/pci: Report PCI error recovery results via SCLP") Signed-off-by: Niklas Schnelle Reviewed-by: Benjamin Block Reviewed-by: Farhan Ali Signed-off-by: Heiko Carstens Signed-off-by: Greg Kroah-Hartman --- arch/s390/pci/pci_event.c | 2 +- arch/s390/pci/pci_report.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) --- a/arch/s390/pci/pci_event.c +++ b/arch/s390/pci/pci_event.c @@ -257,8 +257,8 @@ static pci_ers_result_t zpci_event_attem driver->err_handler->resume(pdev); pci_uevent_ers(pdev, PCI_ERS_RESULT_RECOVERED); out_unlock: - device_unlock(&pdev->dev); zpci_report_status(zdev, pdev, "recovery", status_str); + device_unlock(&pdev->dev); return ers_res; } --- a/arch/s390/pci/pci_report.c +++ b/arch/s390/pci/pci_report.c @@ -88,6 +88,19 @@ static struct debug_view debug_log_view NULL }; +static ssize_t zpci_report_pdev(struct pci_dev *pdev, char *buf, size_t size) +{ + struct pci_driver *driver; + const char *start = buf; + char *end = buf + size; + + device_lock_assert(&pdev->dev); + buf += scnprintf(buf, end - buf, "state: %s\n", zpci_state_str(pdev->error_state)); + driver = to_pci_driver(pdev->dev.driver); + buf += scnprintf(buf, end - buf, "driver: %s\n", (driver) ? driver->name : "n/a"); + return buf - start; +} + /** * zpci_report_status - Report the status of operations on a PCI device * @zdev: The zPCI device for which to report status @@ -109,7 +122,6 @@ int zpci_report_status(struct zpci_dev * const char *operation, const char *status) { struct zpci_report_error *report; - struct pci_driver *driver = NULL; char *buf, *end; int ret; @@ -123,16 +135,13 @@ int zpci_report_status(struct zpci_dev * report = (void *)get_zeroed_page(GFP_KERNEL); if (!report) return -ENOMEM; - if (pdev) - driver = to_pci_driver(pdev->dev.driver); buf = report->data.log_data; end = report->data.log_data + ZPCI_REPORT_DATA_SIZE; buf += scnprintf(buf, end - buf, "report: %s\n", operation); buf += scnprintf(buf, end - buf, "status: %s\n", status); - buf += scnprintf(buf, end - buf, "state: %s\n", - (pdev) ? zpci_state_str(pdev->error_state) : "n/a"); - buf += scnprintf(buf, end - buf, "driver: %s\n", (driver) ? driver->name : "n/a"); + if (pdev) + buf += zpci_report_pdev(pdev, buf, end - buf); ret = debug_dump(pci_debug_msg_id, &debug_log_view, buf, end - buf, true); if (ret < 0) pr_err("Reading PCI debug messages failed with code %d\n", ret);