Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hongtao Zhang" <zhanghongtao35@huawei.com>, linux-pci@vger.kernel.org
Subject: Re: [PATCH v1] PCI: Make PCIe link wait timeout configurable via pcie_link_timeout=
Date: Sat, 21 Nov 2026 11:08:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-226970@kernel.org> (raw)
In-Reply-To: <20261121110806.1158344-1-zhanghongtao35@huawei.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] PCI/DPC: 4000 ms timeout in pci_dpc_recovered() expires
  before link wait
- [Low] PCI: unnecessary EXPORT_SYMBOL_GPL and missing __ro_after_init
  on timeout
- [Low] PCI: inaccurate kernel-parameters.txt note on blind-sleep ports
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] PCI: missing PCI_ERROR_RESPONSE check in
  pcie_wait_for_link_status() [1]
--

commit 79c6602cfac02cd18ceb2cc8a36f64252285fc19
Author: Hongtao Zhang <zhanghongtao35@huawei.com>

PCI: Make PCIe link wait timeout configurable via pcie_link_timeout=

This commit makes the PCIe link training and link state transition wait
timeout configurable at boot via the pcie_link_timeout= kernel parameter,
allowing values between 1000 ms and 10000 ms.

> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 396d196d6ea00..15d6507de968d 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -5304,6 +5304,20 @@ Kernel parameters
>  		force	Enable ASPM even on devices that claim not to support it.
>  			WARNING: Forcing ASPM on may cause system lockups.
>  
> +	pcie_link_timeout=
> +			[PCIE] Timeout in milliseconds to wait for PCIe link
> +			training and link state (up/down) transitions, e.g.
> +			during hot-plug power-on, error recovery resets and
> +			runtime resume.
> +			Some devices, or specific device/board combinations,
> +			may need more than the PCIe spec's 1 sec to train the
> +			link; use this to raise the wait, e.g.
> +			pcie_link_timeout=3000
> +			Range: [1000, 10000] ms. Values out of range are
> +			ignored with a warning and the 1000 ms default is
> +			used. Only affects failure detection latency; healthy
> +			links return as soon as training completes.

[Severity: Low]
Is it accurate that this parameter only affects failure detection latency?
In pcie_wait_for_link_delay(), ports without link_active_reporting
unconditionally sleep for pcie_link_retrain_timeout_ms + delay even when the
link is healthy.

> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 7c6f2aba81443..a5996beeaebbd 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -159,6 +159,25 @@ static bool pci_bridge_d3_disable;
>  /* Force bridge_d3 for all PCIe ports */
>  static bool pci_bridge_d3_force;
>  
> +/*
> + * Effective timeout (ms) for waiting on PCIe link training / state changes.
> + * Defaults to the spec-mandated 1 sec floor.  Devices or device/board
> + * combinations that legitimately need longer than 1 sec to train the link
> + * can raise this at boot via "pcie_link_timeout=<ms>".
> + */
> +unsigned int pcie_link_retrain_timeout_ms = PCIE_LINK_RETRAIN_TIMEOUT_MS;
> +EXPORT_SYMBOL_GPL(pcie_link_retrain_timeout_ms);

[Severity: Low]
pcie_link_retrain_timeout_ms is only declared in drivers/pci/pci.h, only
consumed by built-in code (drivers/pci/pci.c and drivers/pci/pcie/dpc.c),
and only modified during __init.  Should EXPORT_SYMBOL_GPL() be dropped and
the variable marked __ro_after_init?

[ ... ]

> @@ -4624,7 +4674,7 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev,
>  	lnksta_mask = use_lt ? PCI_EXP_LNKSTA_LT : PCI_EXP_LNKSTA_DLLLA;
>  	lnksta_match = active ? lnksta_mask : 0;
>  
> -	end_jiffies = jiffies + msecs_to_jiffies(PCIE_LINK_RETRAIN_TIMEOUT_MS);
> +	end_jiffies = jiffies + msecs_to_jiffies(pcie_link_retrain_timeout_ms);
>  	do {
>  		pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnksta);
>  		if ((lnksta & lnksta_mask) == lnksta_match)

[Severity: High]
This problem wasn't introduced by this patch, but can
pcie_wait_for_link_status() misinterpret a disconnected device [1] as
an active link because lnksta is not checked for PCI_ERROR_RESPONSE
(0xffff)?

When a config read from a removed or unresponsive device populates lnksta
with 0xffff, (lnksta & lnksta_mask) == lnksta_match immediately succeeds
when active is true (falsely reporting that link training succeeded) and
never matches when active is false (blocking for the full
pcie_link_retrain_timeout_ms timeout).

[ ... ]

> diff --git a/drivers/pci/pcie/dpc.c b/drivers/pci/pcie/dpc.c
> index 2b779bd1d861b..ef04532d9c8ab 100644
> --- a/drivers/pci/pcie/dpc.c
> +++ b/drivers/pci/pcie/dpc.c
> @@ -163,7 +163,8 @@ pci_ers_result_t dpc_reset_link(struct pci_dev *pdev)
>  	 * to allow the Port to leave DPC.
>  	 */
>  	if (!pcie_wait_for_link(pdev, false))
> -		pci_info(pdev, "Data Link Layer Link Active not cleared in 1000 msec\n");
> +		pci_info(pdev, "Data Link Layer Link Active not cleared in %u msec\n",
> +			 pcie_link_retrain_timeout_ms);

[Severity: Medium]
Can pci_dpc_recovered() time out prematurely during DPC recovery when
pcie_link_timeout= is raised?

dpc_reset_link() waits up to pcie_link_retrain_timeout_ms in
pcie_wait_for_link(pdev, false) and again in
pci_bridge_wait_for_secondary_bus() before setting PCI_DPC_RECOVERED and
waking dpc_completed_waitqueue, whereas pci_dpc_recovered() still uses a
hardcoded 4000 ms timeout:

drivers/pci/pcie/dpc.c:pci_dpc_recovered() {
	...
	wait_event_timeout(dpc_completed_waitqueue, dpc_completed(pdev),
			   msecs_to_jiffies(4000));

	return test_and_clear_bit(PCI_DPC_RECOVERED, &pdev->priv_flags);
}

When pcie_link_timeout= is set above 4000 ms (or 2000 ms on ports without
link_active_reporting) and DPC link recovery takes longer than 4000 ms,
pci_dpc_recovered() returns false to pciehp_ist() while dpc_reset_link() is
still running.  pciehp_ist() then falls through to
pciehp_handle_presence_or_link_change() and tears down the hotplug slot
mid-recovery, and dpc_reset_link() later leaves a stale PCI_DPC_RECOVERED
bit set that causes pciehp_ist() to ignore the next hotplug event.

[1] https://sashiko.dev/#/bug/linux-139f3acd-7e0a-4e79-85a1-afc0e1e4f511

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261121110806.1158344-1-zhanghongtao35@huawei.com?part=1

      reply	other threads:[~2026-11-21 11:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 11:08 [PATCH v1] PCI: Make PCIe link wait timeout configurable via pcie_link_timeout= Hongtao Zhang
2026-11-21 11:08 ` sashiko-bot [this message]

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-226970@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhanghongtao35@huawei.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