Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mrinmay Sarkar" <mrinmay.sarkar@oss.qualcomm.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 1/2] PCI: qcom: Implement .reset_root_port() for firmware-managed controllers
Date: Fri, 27 Nov 2026 15:02:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-237665@kernel.org> (raw)
In-Reply-To: <20261127-pcie-controller-reset-v2-1-17467b64f5f5@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] PCI: qcom: unpowered MMIO access in
  qcom_pcie_fw_reset_root_port()
- [High] PCI: qcom: concurrent unpowered MMIO in
  qcom_pcie_fw_reset_root_port()
--

commit d192484df4b90b14ad3c75da5b46d87d0d0f79dc
Author: Mrinmay Sarkar <mrinmay.sarkar@oss.qualcomm.com>

PCI: qcom: Implement .reset_root_port() for firmware-managed controllers

This commit implements the .reset_root_port() callback for firmware-managed
Qualcomm PCIe controllers by force-suspending and force-resuming the
controller via runtime PM and reinitializing DWC MSI registers.

> diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
> index d903f10211c23..fe86b8fbc8950 100644
> --- a/drivers/pci/controller/dwc/pcie-qcom.c
> +++ b/drivers/pci/controller/dwc/pcie-qcom.c
> @@ -1855,6 +1855,35 @@ static int qcom_pcie_set_max_opp(struct device *dev)
>  	return ret;
>  }
>  
> +/*
> + * Reset for firmware-managed controllers: power-cycle via runtime PM and
> + * reprogram DWC MSI registers on resume.
> + */
> +static int qcom_pcie_fw_reset_root_port(struct pci_host_bridge *bridge,
> +					struct pci_dev *pdev)
> +{
> +	struct pci_config_window *cfg = bridge->sysdata;
> +	struct device *dev = bridge->dev.parent;
> +	struct dw_pcie_rp *pp = cfg->priv;
> +	int ret;
> +
> +	ret = pm_runtime_force_suspend(dev);
> +	if (ret) {
> +		dev_err(dev, "Failed to force runtime suspend for reset: %d\n", ret);
> +		return ret;
> +	}

[Severity: High]
Can pm_runtime_force_suspend(dev) allow concurrent callers to access ECAM
registers while the controller power domain is off?

When active child devices are present (dev->power.child_count > 0),
pm_runtime_need_not_resume(dev) is false, so pm_runtime_force_suspend(dev)
disables runtime PM and powers off the domain while leaving
dev->power.runtime_status and dev->power.last_status set to RPM_ACTIVE:

drivers/base/power/runtime.c:pm_runtime_force_suspend() {
    ...
	if (pm_runtime_need_not_resume(dev))
		pm_runtime_set_suspended(dev);
	else
		dev->power.needs_force_resume = true;
    ...
}

Because rpm_resume() returns 1 immediately when disable_depth > 0 and both
status fields are RPM_ACTIVE, a concurrent config-space access happens while
the controller is powered down:

CPU0                                  CPU1
qcom_pcie_fw_reset_root_port()
  pm_runtime_force_suspend(dev)
    pm_runtime_disable(dev)
    callback(dev) [powers off domain]
                                      current_link_speed_show()
                                        pci_config_pm_runtime_get()
                                          pm_runtime_get_sync()
                                            rpm_resume() -> returns 1
                                        pci_read_config_word()
                                          <-- unpowered ECAM read (SError)
  pm_runtime_force_resume(dev)

> +
> +	ret = pm_runtime_force_resume(dev);
> +	if (ret) {
> +		dev_err(dev, "Failed to force runtime resume after reset: %d\n", ret);
> +		return ret;
> +	}
> +
> +	dw_pcie_msi_init(pp);
> +
> +	return 0;
> +}

[Severity: High]
Can pm_runtime_force_resume(dev) skip resuming the controller and leave it
powered off when dw_pcie_msi_init(pp) accesses DBI registers?

pm_runtime_force_suspend() and pm_runtime_force_resume() are system sleep
helpers that assume device_prepare() has taken an extra runtime PM reference.
At runtime, dev->power.usage_count is 1 (from qcom_pcie_probe()).  If the
Root Port is runtime-suspended so dev->power.child_count is 0 (for example,
during a bus reset or recovery when no downstream devices are active),
pm_runtime_need_not_resume(dev) returns true:

drivers/base/power/runtime.c:pm_runtime_need_not_resume() {
	return atomic_read(&dev->power.usage_count) <= 1 &&
		(atomic_read(&dev->power.child_count) == 0 ||
		 dev->power.ignore_children);
}

pm_runtime_force_suspend(dev) then sets the status to RPM_SUSPENDED without
setting dev->power.needs_force_resume.  When pm_runtime_force_resume(dev)
runs next, it sees !dev->power.needs_force_resume and
pm_runtime_status_suspended(dev), skips the resume callback, and returns 0
with the power domain still off.  dw_pcie_msi_init(pp) and the subsequent
config-space restore in pcibios_reset_secondary_bus() then write to unpowered
DBI and ECAM registers, causing a synchronous external abort.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-pcie-controller-reset-v2-0-17467b64f5f5@oss.qualcomm.com?part=1

  reply	other threads:[~2026-11-27 15:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 14:40 [PATCH v2 0/2] PCI: qcom: Add support for firmware-managed PCIe controller recovery Mrinmay Sarkar
2026-11-27 14:40 ` [PATCH v2 1/2] PCI: qcom: Implement .reset_root_port() for firmware-managed controllers Mrinmay Sarkar
2026-11-27 15:02   ` sashiko-bot [this message]
2026-11-27 14:40 ` [PATCH v2 2/2] PCI: qcom: Reinitialize MSI on resume " Mrinmay Sarkar
2026-11-27 15:02 ` [PATCH v2 0/2] PCI: qcom: Add support for firmware-managed PCIe controller recovery sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-237665@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mrinmay.sarkar@oss.qualcomm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox