All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: hangej <hangej@amazon.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v3] pci_crash: capture PCI config space at panic time
Date: Tue, 14 Jul 2026 18:11:41 +0000	[thread overview]
Message-ID: <20260714181141.F2DD21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714175305.2783480-1-hangej@amazon.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Calling `pci_dev_put()` from an RCU softirq callback can sleep in atomic context.
- [High] Accessing `bus->ops->read` on a removed device causes a Use-After-Free if the host controller driver was unloaded.
- [Medium] Skipped captures export un-flushed zeroed buffers, allowing the crash parser to read stale crash data from RAM.
--

--- Patch [1]: [PATCH v3] pci_crash: capture PCI config space at panic time ---
commit 93c2fd5e7de948b1f47b018b3d8a6d93723570c6
Author: Johannes Hange <hangej@amazon.com>

pci_crash: capture PCI config space at panic time

This commit adds CONFIG_PCI_CRASH to capture PCI configuration space during
a panic before kexec. It uses a pre-allocated buffer exported via
VMCOREINFO and relies on RCU snapshots and lockless accesses to safely
record device state.

> diff --git a/drivers/pci/access.c b/drivers/pci/access.c
> --- a/drivers/pci/access.c
> +++ b/drivers/pci/access.c
> @@ -131,7 +131,7 @@ int pci_bus_read_config_dword_trylock(struct pci_bus *bus, unsigned int devfn,
>  	if (!pci_trylock_config(flags)) {
>  		PCI_SET_ERROR_RESPONSE(value);
>  		return PCIBIOS_SET_FAILED;
>  	}
>  	res = bus->ops->read(bus, devfn, pos, 4, &data);

[Severity: High]
If a host controller driver is unloaded right before a panic, could this
dereference freed module memory?

Because the bus notifier uses a 200ms debounce delay, the crash snapshot
might hold a stale pci_dev reference. The reference keeps the pci_dev
struct alive, but if the controller module was unloaded, bus->ops->read
points to freed memory. Clean removals do not set error_state, so the
pci_crash_endpoint_reachable() check might not filter the device out.

[ ... ]

> diff --git a/kernel/pci_crash.c b/kernel/pci_crash.c
> --- a/kernel/pci_crash.c
> +++ b/kernel/pci_crash.c
> @@ -142,6 +142,6 @@ static void pci_crash_snapshot_free_rcu(struct rcu_head *head)
>  	if (READ_ONCE(pci_crash_captured_snap) == s)
>  		return;
>  
>  	for (i = 0; i < s->num_devs; i++)
>  		if (s->devs && s->devs[i])
>  			pci_dev_put(s->devs[i]);

[Severity: High]
Can this call to pci_dev_put() sleep in atomic context?

This runs in an RCU softirq callback. If a device was hot-removed,
this snapshot might hold the final reference to the device. Dropping
the last reference triggers device_release() -> pci_release_dev() ->
devres_release_all(), which may take sleeping locks or allocate memory
with GFP_KERNEL.

[ ... ]

> @@ -864,14 +864,14 @@ void pci_crash_save(void)
>  	WRITE_ONCE(pci_crash_captured_snap, s);
>  
>  	pci_crash_buffer = s->buffer;
>  	pci_crash_buffer_size = s->buffer_size;
>  	pci_crash_pagemap_phys = s->pagemap_phys;
>  
>  	cflags = READ_ONCE(capture_flags);
>  	if (!(cflags & PCI_CRASH_CAPTURE_ALWAYS)) {
>  		if (!(cflags & PCI_CRASH_CAPTURE_AER)) {
>  			goto out;
>  		}
>  		if (!pci_crash_aer_error_present(s)) {
>  			pr_info("no PCI errors detected, skipping capture\n");
>  			goto out;
>  		}
>  	}

[Severity: Medium]
If the capture is skipped and jumps to the out label, could the crash
parser read stale data from RAM?

The export variables are set before the AER check. If no AER errors are
found, the code jumps out without flushing the dcache. Since the buffer
and pagemap were written in process context during rebuild, they might
only reside in the CPU cache.

The crash kernel will read physical RAM, which might contain an older,
valid PCIC magic signature from a previous boot or panic, leading to
stale records being parsed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260714175305.2783480-1-hangej@amazon.com?part=1

      reply	other threads:[~2026-07-14 18:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 22:30 [PATCH v2] pci_crash: capture PCI config space at panic time hangej
2026-05-21 23:03 ` sashiko-bot
2026-07-14 17:53 ` [PATCH v3] " hangej
2026-07-14 18:11   ` 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=20260714181141.F2DD21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hangej@amazon.com \
    --cc=linux-pci@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.