Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yazen Ghannam" <yazen.ghannam@amd.com>, linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 5/6] PCI/FLIT: Signal Flit Error Counter events with ERR_COR
Date: Fri, 04 Dec 2026 18:46:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-250456@kernel.org> (raw)
In-Reply-To: <20261204181556.1418843-6-yazen.ghannam@amd.com>

Thank you for your contribution! Sashiko AI review found 10 potential
issues to consider:
- [Medium] PCI/AER: aer_root_reset() clears root status without
  re-arming Flit counters
- [Medium] PCI/AER: find_device_iter() overflow permanently silences
  Flit counters
- [Medium] PCI/FLIT: pci_flit_init() enables ERR_COR before device is on
  bus->devices
- [Medium] PCI/FLIT: flit_err_cor_usable() ignores pcie_ports_disabled
  on non-ACPI
- [Medium] PCI/FLIT: pci_flit_rearm() accesses D3cold devices and resets
  idle counters
- [Medium] PCI/FLIT: Root Port runtime resume discards Flit ERR_COR
  without re-arming
- [Medium] PCI/AER: aer_enable_rootport() rearms Flit counters before
  aer_enable_irq()
- [Medium] PCI/FLIT: pci_restore_flit_state() races with flit_service()
  counter pause
- [Medium] PCI/FLIT: flit_cntr_enable() leaves ERR_COR_EN set in IRQ
  fallback mode
- [Low] PCI/AER: is_error_source() gates Flit ERR_COR check on
  PCI_EXP_AER_FLAGS
--

commit 9ac7a72e2e543419624dd388eb814ff690ac98e9
Author: Yazen Ghannam <yazen.ghannam@amd.com>

PCI/FLIT: Signal Flit Error Counter events with ERR_COR

This commit uses ERR_COR signaling instead of the PCIe Capability
interrupt for Flit Error Counter events when Capability Version 2h
supports it.  It hooks into AER to identify and service those events and
re-arms ERR_COR counters when AER enables a Root Port or RCEC.

> diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
> index 1973b6eba6b38..376ee74981087 100644
> --- a/drivers/pci/pcie/aer.c
> +++ b/drivers/pci/pcie/aer.c
> @@ -1210,6 +1210,11 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
>  	if (!(reg16 & PCI_EXP_AER_FLAGS))
>  		return false;
>  
> +	/* A Flit Error Counter event sets no AER status bit */
> +	if (e_info->severity == AER_CORRECTABLE &&
> +	    pci_flit_err_cor_pending(dev))
> +		return true;
> +

[Severity: Low]
Should the pci_flit_err_cor_pending() check come before the
PCI_EXP_AER_FLAGS check?

Flit Error Counter ERR_COR generation is gated by
PCI_FLIT_ERR_CNTR_CTRL_ERR_COR_EN rather than PCI_EXP_DEVCTL, and
flit_err_cor_usable() only checks the Root Port's aer_cap.  If
PCI_EXP_AER_FLAGS is clear on the device -- for example after an OOM in
pci_aer_init() skips pci_enable_pcie_error_reporting() -- a multi-error
search skips the device and leaves its Flit Error Counter permanently
silent.

[ ... ]

> @@ -1594,6 +1599,8 @@ static inline void aer_process_err_devices(struct aer_err_info *e_info)
>  
>  	/* Report all before handling them, to not lose records by reset etc. */
>  	for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) {
> +		if (e_info->severity == AER_CORRECTABLE)
> +			pci_flit_handle_err_cor(e_info->dev[i]);
>  		if (aer_get_device_error_info(e_info, i))
>  			aer_print_error(e_info, i);
>  	}

[Severity: Medium]
Can an AER multi-error overflow permanently silence Flit Error Counters on
devices beyond the fifth match?

find_device_iter() stops walking the bus once add_error_device() hits
AER_MAX_MULTI_ERR_DEVICES (5), so aer_process_err_devices() never calls
pci_flit_handle_err_cor() for any remaining device with a pending Flit
ERR_COR.  Because a Flit counter stays silent until its err_cor_gen bit is
cleared, an overflowed device stops reporting Flit errors until another
multi-error burst visits it first or the Root Port re-arms it.

[ ... ]

> @@ -1805,6 +1818,15 @@ static void aer_enable_rootport(struct aer_rpc *rpc)
>  	pci_read_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS, &reg32);
>  	pci_write_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS, reg32);
>  
> +	/* Re-arm Flit Error Counters whose ERR_COR was never serviced */
> +	if (IS_ENABLED(CONFIG_PCIE_FLIT)) {
> +		pci_flit_rearm(pdev);
> +		if (pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_EC)
> +			pcie_walk_rcec(pdev, flit_rearm_iter, NULL);
> +		else if (pdev->subordinate)
> +			pci_walk_bus(pdev->subordinate, flit_rearm_iter, NULL);
> +	}
> +
>  	aer_enable_irq(pdev);
>  }

[Severity: Medium]
Can re-arming Flit Error Counters before aer_enable_irq() drop a new
ERR_COR?

While the walk drains logs on downstream devices, an earlier re-armed
device can reach its trigger and emit an ERR_COR while
PCI_ERR_ROOT_CMD_COR_EN is still clear.  On Root Ports or RCECs that do
not retroactively fire an MSI/MSI-X when PCI_ERR_ROOT_CMD_COR_EN is set
with PCI_ERR_ROOT_COR_RCV already latched, that event is never serviced
and the counter stays silent.  Moving the re-arm walk after
aer_enable_irq() avoids this window since flit_service() already
serializes with aer_isr() via service_lock.

[Severity: Medium]
Does aer_root_reset() also need to re-arm Flit Error Counters when it
clears PCI_ERR_ROOT_STATUS?

aer_root_reset() masks AER interrupts on root, runs FLR or a secondary bus
reset, clears PCI_ERR_ROOT_STATUS, and re-enables interrupts:

drivers/pci/pcie/aer.c:aer_root_reset() {
	...
	if (host->native_aer && aer) {
		/* Clear Root Error Status */
		pci_read_config_dword(root, aer + PCI_ERR_ROOT_STATUS, &reg32);
		pci_write_config_dword(root, aer + PCI_ERR_ROOT_STATUS, reg32);

		aer_enable_irq(root);
	}
	...
}

Any Flit ERR_COR sent by root or an un-reset sibling port during that
reset window is discarded when PCI_ERR_ROOT_STATUS is cleared, leaving
that counter permanently silent.

> diff --git a/drivers/pci/pcie/flit.c b/drivers/pci/pcie/flit.c
> index 97395b6942389..83a6b50221ef1 100644
> --- a/drivers/pci/pcie/flit.c
> +++ b/drivers/pci/pcie/flit.c

[ ... ]

> @@ -143,6 +151,48 @@ static void flit_select_cntr(struct pci_dev *pdev)
>  	info->cntr = &flit_ext_cntr;
>  }
>  
> +/*
> + * The Root Port or RCEC needs AER to log the ERR_COR, and system firmware must
> + * not claim it through SIG_SFW Enable or RC ECS Handling. The device itself
> + * needs no AER Capability.
> + */
> +static bool flit_err_cor_usable(struct pci_dev *pdev)
> +{
> +	struct flit_info *info = pdev->flit_info;
> +	struct pci_dev *root;
> +	u32 root_cmd, sfw;
> +	u16 ctrl;
> +
> +	if (!(info->cntr_cap & PCI_FLIT_ERR_CNTR_CAP_ERR_COR))
> +		return false;
> +
> +	if (!pci_aer_available())
> +		return false;

[Severity: Medium]
Should flit_err_cor_usable() also check pcie_ports_disabled?

On non-ACPI platforms booted with pcie_ports=compat (or PowerNV, which
sets pcie_ports_disabled unconditionally), pci_init_host_bridge() leaves
native_flit set while pcie_portdrv_init() skips registering aerdriver.
Because pci_aer_available() does not check pcie_ports_disabled,
pci_flit_init() enables ERR_COR signaling with no AER driver bound to
service the messages.

[ ... ]

> @@ -210,6 +271,12 @@ void pci_flit_init(struct pci_dev *pdev)
>  	pci_dbg(pdev, "Flit Logging Extended Capability present, using the %s\n",
>  		flit_ext(info) ? "Extended Flit Error Counter" :
>  				 "Flit Error Counter");
> +
> +	/* ERR_COR needs no port service, so start here, after pci_aer_init() */
> +	if (info->err_cor) {
> +		pci_dbg(pdev, "Flit Error Counter events signaled with ERR_COR\n");
> +		flit_cntr_enable(pdev);
> +	}
>  }

[Severity: Medium]
Can enabling the ERR_COR counter here lose the first event on hotplug or
rescan?

pci_device_add() calls pci_init_capabilities() (and then several other
initializers, including DOE mailbox exchanges and
platform_pci_configure_wake()) before adding dev to bus->devices.  If the
counter fires an ERR_COR beneath an already-probed Root Port before dev is
on bus->devices, aer_irq() clears Root Error Status, find_source_device()
cannot locate dev, and the counter stays permanently silent.

[ ... ]

> @@ -344,6 +424,10 @@ static void flit_cntr_enable(struct pci_dev *pdev)
>  
>  	/* A 0->1 transition of Counter Enable clears stale event status */
>  	__flit_cntr_ctrl_update(pdev, cntr->en, 0);
> +
> +	if (info->err_cor)
> +		__flit_err_cor_enable(pdev);
> +
>  	__flit_cntr_ctrl_update(pdev, cntr->trigger | ctrl,
>  				field_prep(cntr->trigger, info->trigger) |
>  				info->enable);

[Severity: Medium]
When falling back to IRQ mode on a Capability Version 2h port, does
flit_cntr_enable() leave PCI_FLIT_ERR_CNTR_CTRL_ERR_COR_EN set?

If ERR_COR_EN was already set in hardware (for example across kexec into a
kernel booted with pci=noaer), neither flit_select_cntr() nor
flit_cntr_enable() clears it or its saved copy in FLIT_SAVE_CNTR_CTRL.
Each trigger then emits both a PCIe interrupt and an unhandled ERR_COR
message.

[ ... ]

> @@ -448,9 +532,71 @@ static irqreturn_t flit_isr(int irq, void *context)
>  	return IRQ_WAKE_THREAD;
>  }
>  
> +/*
> + * flit_isr() and flit_ist() in one, for ERR_COR. The AER thread and the
> + * rearm walk can both get here, and must not drain one log at once.
> + */
> +static void flit_service(struct pci_dev *pdev)
> +{
> +	struct flit_info *info = pdev->flit_info;
> +
> +	mutex_lock(&info->service_lock);
> +	flit_cntr_pause(pdev);
> +	flit_cntr_write(pdev, info->cntr->sta, info->event);
> +	flit_drain_log(pdev);
> +	flit_cntr_resume(pdev);
> +	mutex_unlock(&info->service_lock);
> +}

[Severity: Medium]
Can pci_restore_flit_state() race with flit_service() and re-enable the
counter while it is paused?

flit_service() runs without device_lock() and drops info->lock right after
flit_cntr_pause().  A concurrent pci_restore_flit_state() (from
pci_reset_function(), DPC slot reset, or runtime resume) takes only
info->lock and writes the saved control register with cntr->en set:

CPU0                              CPU1
flit_service()
  flit_cntr_pause()
    /* cntr->en: 1 -> 0 */
                                  pci_restore_flit_state()
                                    /* writes saved cntr->en = 1 */
  /* new event latches sta */
  flit_cntr_write(sta, event)     <-- clears new event before AER runs
  flit_drain_log()
  flit_cntr_resume()              <-- no 0 -> 1 transition to re-arm

If errors reach the trigger before flit_cntr_write(), the RW1C write
clears the new event status and flit_cntr_resume() misses the 0->1
transition needed to re-arm the counter.  Tracking the paused state under
info->lock and masking cntr->en in pci_restore_flit_state() while paused
would prevent this.

> +
>  bool pci_flit_uses_irq(struct pci_dev *pdev)
>  {
> -	return !!pdev->flit_info;
> +	return pdev->flit_info && !pdev->flit_info->err_cor;
> +}

[Severity: Medium]
Does Root Port runtime resume discard latched Flit ERR_COR events without
re-arming the counters?

Returning false here keeps flitdriver (and its runtime_resume callback)
from binding in ERR_COR mode, while aerdriver has no runtime_resume
callback.  When a Root Port runtime-resumes from D3hot,
pci_restore_state() calls pci_aer_clear_status() to clear
PCI_ERR_ROOT_STATUS, and pci_restore_flit_state() writes Counter Enable
with no 0->1 transition, leaving any counter whose ERR_COR was latched
during D3hot permanently silent.

[ ... ]

> +/**
> + * pci_flit_rearm - service a counter whose ERR_COR may have been discarded
> + * @pdev: PCI device reporting to a Root Port or RCEC AER is enabling
> + *
> + * An ERR_COR that AER cleared while enabling the Root Port or RCEC would
> + * leave the counter silent for good.
> + */
> +void pci_flit_rearm(struct pci_dev *pdev)
> +{
> +	struct flit_info *info = pdev->flit_info;
> +
> +	if (info && info->err_cor)
> +		flit_service(pdev);
>  }

[Severity: Medium]
Can pci_flit_rearm() access D3cold subordinate devices during system
resume?

Because pcie_portdrv_probe() sets DPM_FLAG_SMART_SUSPEND, runtime-
suspended subordinate ports can stay in D3cold when the parent Root Port
runs aer_resume() -> aer_enable_rootport().  Calling flit_service()
without checking runtime PM or PCI_D3cold state issues config
read-modify-writes to D3cold devices right before aer_enable_irq(),
causing spurious Unsupported Request errors and risking corrupting the
control register if racing with runtime resume.

Also, because pci_flit_rearm() does not check pci_flit_err_cor_pending(),
it pauses and resumes healthy idle D0 counters (dropping accumulated
counts) and drains logs under pci_bus_sem on every Root Port probe and
resume.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204181556.1418843-1-yazen.ghannam@amd.com?part=5

  reply	other threads:[~2026-12-04 18:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:15 [PATCH v3 0/6] PCIe Flit Logging Ext Capability Support Yazen Ghannam
2026-12-04 18:15 ` [PATCH v3 1/6] PCI/portdrv: Group PCI Exp Cap services into a single mask Yazen Ghannam
2026-12-04 18:15 ` [PATCH v3 2/6] PCI: Add pci_clear_and_set_config_word() Yazen Ghannam
2026-12-04 18:35   ` sashiko-bot
2026-12-04 18:15 ` [PATCH v3 3/6] PCI/FLIT: Add support for Flit Logging Extended Capability Yazen Ghannam
2026-12-04 18:42   ` sashiko-bot
2026-12-04 18:15 ` [PATCH v3 4/6] PCI/FLIT: Add support for the Extended Flit Error Counter Yazen Ghannam
2026-12-04 18:40   ` sashiko-bot
2026-12-04 18:15 ` [PATCH v3 5/6] PCI/FLIT: Signal Flit Error Counter events with ERR_COR Yazen Ghannam
2026-12-04 18:46   ` sashiko-bot [this message]
2026-12-04 18:15 ` [PATCH v3 6/6] PCI/FLIT: Manage Flit Logging on Endpoint Upstream Ports Yazen Ghannam
2026-12-04 18:53   ` sashiko-bot
2026-12-04 18:53 ` [PATCH v3 0/6] PCIe Flit Logging Ext Capability Support 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-250456@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yazen.ghannam@amd.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