mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Manikanta Maddireddy <mmaddireddy@nvidia.com>
Cc: lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org,
	bhelgaas@google.com, linux-pci@vger.kernel.org, robh@kernel.org,
	thierry.reding@kernel.org, jonathanh@nvidia.com,
	kishon@kernel.org, Frank.Li@kernel.org, vidyas@nvidia.com,
	cassel@kernel.org, den@valinux.co.jp, marco.crivellari@suse.com,
	andriy.shevchenko@linux.intel.com, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 03/10] PCI: tegra194: Fix Endpoint PERST# IRQ suspend race
Date: Wed, 21 Oct 2026 10:19:53 -0500	[thread overview]
Message-ID: <atjYGe1IKvAU-UF5@SMW015318> (raw)
In-Reply-To: <20261021061349.1265704-4-mmaddireddy@nvidia.com>

On Wed, Oct 21, 2026 at 11:43:42AM +0530, Manikanta Maddireddy wrote:
> Endpoint system suspend is allowed only while the endpoint is disabled.
> Checking ep_state before disabling the PERST# IRQ leaves a window in which
> PERST# deassertion starts the threaded handler after the check. The
> handler can enable the controller, clocks and PHYs before disable_irq()
> returns, but suspend still succeeds based on the earlier disabled state.
> The system then proceeds into suspend with an active endpoint that should
> have caused the suspend callback to reject the transition.
>
> Disable the PERST# IRQ before checking ep_state. disable_irq() waits for
> an already-running threaded handler to finish, so the state check sees
> its completed transition and no new handler can enable the endpoint.
> Re-enable the IRQ immediately if the endpoint is enabled and reject
> suspend. Otherwise, keep it disabled until the normal resume callback.
> This also balances the IRQ disable when another device aborts suspend
> and PM rolls back through .resume without calling .resume_early.
>
> This preserves the existing policy that PERST# is not serviced while the
> endpoint is suspended. It serializes the software state check with the
> IRQ thread; it does not make PERST# a wakeup source or guarantee delivery
> of transitions during suspension.
>
> Wrap the PM ops pointer with pm_sleep_ptr() so the callbacks are used
> only when system sleep is enabled.
>
> Fixes: c76f8eae7d46 ("PCI: tegra194: Allow system suspend when the Endpoint link is not up")
> Link: https://lore.kernel.org/r/20260324190755.1094879-10-mmaddireddy@nvidia.com
> Signed-off-by: Manikanta Maddireddy <mmaddireddy@nvidia.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> Changes V1 -> V2:
> - Expand the commit message to explain the active-endpoint suspend race,
>   IRQ-thread synchronization and suspend rollback handling.
> - Clarify that PERST# is not serviced while the endpoint is suspended.
> - Add a comment explaining why the IRQ thread is drained before checking
>   endpoint state.
>
>  drivers/pci/controller/dwc/pcie-tegra194.c | 34 ++++++++++++++--------
>  1 file changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
> index 89dbef83dd9e..0f895c766a71 100644
> --- a/drivers/pci/controller/dwc/pcie-tegra194.c
> +++ b/drivers/pci/controller/dwc/pcie-tegra194.c
> @@ -2374,19 +2374,30 @@ static int tegra_pcie_dw_suspend(struct device *dev)
>  {
>  	struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
>
> -	if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
> -		if (pcie->ep_state == EP_STATE_ENABLED) {
> -			dev_err(dev, "Tegra PCIe is in EP mode, suspend not allowed\n");
> -			return -EPERM;
> -		}
> -
> -		disable_irq(pcie->pex_rst_irq);
> +	if (pcie->of_data->mode != DW_PCIE_EP_TYPE)
>  		return 0;
> +
> +	/* Drain the PERST# thread before checking whether the endpoint is idle. */
> +	disable_irq(pcie->pex_rst_irq);
> +	if (pcie->ep_state == EP_STATE_ENABLED) {
> +		enable_irq(pcie->pex_rst_irq);
> +		dev_err(dev, "Tegra PCIe is in EP mode, suspend not allowed\n");
> +		return -EPERM;
>  	}
>
>  	return 0;
>  }
>
> +static int tegra_pcie_dw_resume(struct device *dev)
> +{
> +	struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
> +
> +	if (pcie->of_data->mode == DW_PCIE_EP_TYPE)
> +		enable_irq(pcie->pex_rst_irq);
> +
> +	return 0;
> +}
> +
>  static int tegra_pcie_dw_suspend_late(struct device *dev)
>  {
>  	struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
> @@ -2462,10 +2473,8 @@ static int tegra_pcie_dw_resume_early(struct device *dev)
>  	struct tegra_pcie_dw *pcie = dev_get_drvdata(dev);
>  	u32 val;
>
> -	if (pcie->of_data->mode == DW_PCIE_EP_TYPE) {
> -		enable_irq(pcie->pex_rst_irq);
> +	if (pcie->of_data->mode == DW_PCIE_EP_TYPE)
>  		return 0;
> -	}
>
>  	if (!pcie->link_state)
>  		return 0;
> @@ -2569,10 +2578,11 @@ static const struct of_device_id tegra_pcie_dw_of_match[] = {
>
>  static const struct dev_pm_ops tegra_pcie_dw_pm_ops = {
>  	.suspend = tegra_pcie_dw_suspend,
> +	.resume = tegra_pcie_dw_resume,
>  	.suspend_late = tegra_pcie_dw_suspend_late,
> +	.resume_early = tegra_pcie_dw_resume_early,
>  	.suspend_noirq = tegra_pcie_dw_suspend_noirq,
>  	.resume_noirq = tegra_pcie_dw_resume_noirq,
> -	.resume_early = tegra_pcie_dw_resume_early,
>  };
>
>  static struct platform_driver tegra_pcie_dw_driver = {
> @@ -2581,7 +2591,7 @@ static struct platform_driver tegra_pcie_dw_driver = {
>  	.shutdown = tegra_pcie_dw_shutdown,
>  	.driver = {
>  		.name	= "tegra194-pcie",
> -		.pm = &tegra_pcie_dw_pm_ops,
> +		.pm = pm_sleep_ptr(&tegra_pcie_dw_pm_ops),
>  		.of_match_table = tegra_pcie_dw_of_match,
>  	},
>  };
> --
> 2.34.1
>

  reply	other threads:[~2026-10-21 15:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  6:13 [PATCH v2 00/10] PCI: tegra194: Fix EP and Root Port corner cases Manikanta Maddireddy
2026-10-21  6:13 ` [PATCH v2 01/10] PCI: tegra194: Propagate REFCLK select GPIO errors Manikanta Maddireddy
2026-10-21 15:14   ` Frank Li
2026-10-21  6:13 ` [PATCH v2 02/10] PCI: tegra194: Check core reset deassertion Manikanta Maddireddy
2026-10-21 15:16   ` Frank Li
2026-10-21  6:13 ` [PATCH v2 03/10] PCI: tegra194: Fix Endpoint PERST# IRQ suspend race Manikanta Maddireddy
2026-10-21 15:19   ` Frank Li [this message]
2026-10-21  6:13 ` [PATCH v2 04/10] PCI: tegra194: Do not skip no-link Root Port remove cleanup Manikanta Maddireddy
2026-10-21 15:22   ` Frank Li
2026-10-21  6:13 ` [PATCH v2 05/10] PCI: tegra194: Check for 16 GT/s capability before programming Manikanta Maddireddy
2026-10-21 15:24   ` Frank Li
2026-10-21  6:13 ` [PATCH v2 06/10] PCI: tegra194: Check for L1SS " Manikanta Maddireddy
2026-10-21 15:28   ` Frank Li
2026-10-21  6:13 ` [PATCH v2 07/10] PCI: tegra194: Always disable Tegra234 Endpoint L1.2 Manikanta Maddireddy
2026-10-21 15:32   ` Frank Li
2026-10-21  6:13 ` [PATCH v2 08/10] PCI: tegra194: Guard Endpoint PLL-off error path Manikanta Maddireddy
2026-10-21 15:36   ` Frank Li
2026-10-21  6:13 ` [PATCH v2 09/10] PCI: tegra194: Balance core monitor clock on failures Manikanta Maddireddy
2026-10-21 15:43   ` Frank Li
2026-10-21  6:13 ` [PATCH v2 10/10] PCI: tegra194: Reject zero MSI interrupt number Manikanta Maddireddy
2026-10-21 15:44   ` Frank Li

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=atjYGe1IKvAU-UF5@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=cassel@kernel.org \
    --cc=den@valinux.co.jp \
    --cc=jonathanh@nvidia.com \
    --cc=kishon@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=marco.crivellari@suse.com \
    --cc=mmaddireddy@nvidia.com \
    --cc=robh@kernel.org \
    --cc=thierry.reding@kernel.org \
    --cc=vidyas@nvidia.com \
    /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

all inboxes | Powered by JetHome®