From: Lukas Wunner <lukas@wunner.de>
To: sashiko-reviews@lists.linux.dev
Cc: linux-pci@vger.kernel.org,
Matthew W Carlis <mattc@purestorage.com>,
Bjorn Helgaas <helgaas@kernel.org>
Subject: Re: [PATCH 6/6] PCI/AER: Support Advisory Non-Fatal Errors
Date: Mon, 27 Jul 2026 15:55:19 +0200 [thread overview]
Message-ID: <amdjR8LqIY0YmiG4@wunner.de> (raw)
In-Reply-To: <20260724162755.DDA801F000E9@smtp.kernel.org>
On Fri, Jul 24, 2026 at 04:27:55PM +0000, sashiko-bot@kernel.org wrote:
> > +++ b/drivers/pci/pcie/aer.c
> > @@ -410,6 +424,15 @@ void pci_aer_init(struct pci_dev *dev)
> > n = pcie_cap_has_rtctl(dev) ? 5 : 4;
> > pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_ERR, sizeof(u32) * n);
> >
> > + /*
> > + * Advisory Non-Fatal Errors are masked by default (PCIe r7.0, sec
> > + * 7.8.4.6).
> > + */
> > + if (dev->devcap & PCI_EXP_DEVCAP_RBER)
> > + pci_clear_and_set_config_dword(dev,
> > + dev->aer_cap + PCI_ERR_COR_MASK,
> > + PCI_ERR_COR_ADV_NFAT, 0);
>
> [Severity: High]
> Does this code modify the AER Correctable Error Mask register unconditionally
> without checking pcie_aer_is_native(dev)?
Yes, that's a valid point.
> > @@ -916,8 +997,20 @@ void aer_print_error(struct aer_err_info *info, int i)
> >
> > __aer_print_error(dev, info);
> >
> > - if (info->tlp_header_valid)
> > + if (info->tlp_header_valid && info->severity != AER_CORRECTABLE)
> > pcie_print_tlp_log(dev, &info->tlp, level, dev_fmt(" "));
> > +
> > +anfe:
> > + /* Recursive invocation for Advisory Non-Fatal Errors */
> > + if (info->anfe_status && info->severity == AER_CORRECTABLE) {
> > + info->severity = AER_NONFATAL;
> > + info->status = info->anfe_status;
> > + info->mask = 0;
> > +
> > + aer_print_error(info, i);
>
> [Severity: Medium]
> Will this recursive call operate with the stale info->level and
> info->ratelimit_print[i] state?
That's intentional. I want the (Advisory) Uncorrectable Errors to be
reported with the same loglevel and ratelimiting as the accompanying
Correctable Error.
However while native AER handling does this the way I want it to,
I missed that Firmware First does not. It uses the loglevel and
ratelimiting of (non-Advisory) Uncorrectable Errors. So that's
something I'll have to fix.
> [Severity: High]
> This is a pre-existing issue, but can this cause a PCI device reference leak
> if the hardware error status changes between loops?
[...]
> If the hardware or firmware clears the error status after the first loop but
> before the second loop reads it, aer_get_device_error_info() returns 0. The
> second loop will skip the handler, and the pci_dev reference is permanently
> leaked.
Hallucination. If hardware or firmware clears error bits behind our back,
it would be broken.
> [Severity: High]
> This is a pre-existing issue, but does this create a TOCTOU race window for
> newly arriving hardware errors?
>
> drivers/pci/pcie/aer.c:aer_process_err_devices() {
> ...
> for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) {
> if (aer_get_device_error_info(e_info, i))
> aer_print_error(e_info, i);
> }
> for (i = 0; i < e_info->error_dev_num && e_info->dev[i]; i++) {
> if (aer_get_device_error_info(e_info, i))
> handle_error_source(e_info->dev[i], e_info);
> }
> ...
> }
It's a valid point and already on my todo list, but not something
I want to fix as part of this series. The duplicate invocation of
aer_get_device_error_info() is not only susceptible to a TOCTOU race,
but also very inefficient.
> [Severity: Medium]
> This is a pre-existing issue, but does this code cause a memory leak of the
> dynamically allocated aer_capability_regs when the recovery queue overflows?
>
> drivers/pci/pcie/aer.c:aer_recover_queue() {
> ...
> else
> pr_err("buffer overflow in recovery for %04x:%02x:%02x.%x\n",
> domain, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
> ...
> }
>
> In the GHES subsystem, memory for struct aer_capability_regs is allocated from
> ghes_estatus_pool and passed as a pointer to aer_recover_queue(). If the
> bounded aer_recover_ring kfifo is full, it prints an overflow error and returns
> without freeing the memory.
>
> The aer_regs pointer is abandoned and the memory is permanently leaked, as it
> is only freed on the success path inside aer_recover_work_func().
It's a valid point, I've added that to my todo list.
> [Severity: High]
> This is a pre-existing issue, but can this lead to data corruption when
> decoding concurrent Machine Check Exceptions due to an unprotected global
> buffer?
>
> drivers/acpi/acpi_extlog.c:extlog_print() {
> ...
> memcpy(elog_buf, (void *)estatus, ELOG_ENTRY_LEN);
> /* clear record status to enable BIOS to update it again */
> estatus->block_status = 0;
>
> tmp = (struct acpi_hest_generic_status *)elog_buf;
> ...
> }
>
> The ACPI extended log driver allocates a single global buffer elog_buf. The MCE
> decoder callback unconditionally copies the new MCE event payload into this
> global buffer without any locks.
>
> Since Machine Check Exceptions can trigger concurrently across different CPUs,
> concurrent executions of the MCE handlers will simultaneously overwrite
> elog_buf, corrupting the data structures being parsed.
I'm not familiar with MCE handling, I'll have to ask internally whether
that's a valid finding.
Thanks,
Lukas
next prev parent reply other threads:[~2026-07-27 13:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 15:24 [PATCH 0/6] PCI/AER: Support Advisory Non-Fatal Errors Lukas Wunner
2026-07-24 15:24 ` [PATCH 1/6] PCI/AER: Fix mapping of errors to agent & layer Lukas Wunner
2026-07-24 16:12 ` sashiko-bot
2026-07-24 15:24 ` [PATCH 2/6] PCI/AER: Log agent & layer for each individual error Lukas Wunner
2026-07-24 16:19 ` sashiko-bot
2026-07-24 15:24 ` [PATCH 3/6] PCI/AER: Deduplicate logging of Error Source Identification Lukas Wunner
2026-07-24 16:10 ` sashiko-bot
2026-07-24 15:24 ` [PATCH 4/6] PCI/AER: Emit TLP Log only for unmasked errors Lukas Wunner
2026-07-24 16:21 ` sashiko-bot
2026-07-24 15:24 ` [PATCH 5/6] PCI/AER: Move retrieval of FEP and TLP Log into helper Lukas Wunner
2026-07-24 16:12 ` sashiko-bot
2026-07-24 15:24 ` [PATCH 6/6] PCI/AER: Support Advisory Non-Fatal Errors Lukas Wunner
2026-07-24 16:27 ` sashiko-bot
2026-07-27 13:55 ` Lukas Wunner [this message]
2026-07-24 22:39 ` [PATCH 0/6] " Bjorn Helgaas
2026-07-27 14:12 ` Lukas Wunner
2026-07-27 15:51 ` Bjorn Helgaas
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=amdjR8LqIY0YmiG4@wunner.de \
--to=lukas@wunner.de \
--cc=helgaas@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mattc@purestorage.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