Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Matlack" <dmatlack@google.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v7 03/12] PCI: liveupdate: Track incoming preserved PCI devices
Date: Fri, 10 Jul 2026 21:39:28 +0000	[thread overview]
Message-ID: <20260710213928.E7CE11F0155B@smtp.kernel.org> (raw)
In-Reply-To: <20260710212616.1351130-4-dmatlack@google.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] pci_liveupdate_finish_device() incorrectly aborts if refcount != 1, completely breaking the preservation lifecycle for parent bridges and leaking their FLB references.
- [Medium] `pci_liveupdate_cleanup_device()` fails to clear `dev_ser->refcount`, leading to state contamination for subsequently hot-plugged devices.
- [Medium] Memory allocated for incoming preserved PCI devices (the KHO block set) is leaked in `pci_flb_retrieve()` if `kzalloc_obj()` fails.
--

--- Patch [3]: [PATCH v7 03/12] PCI: liveupdate: Track incoming preserved PCI devices ---
commit 4fcd6c9f661309adcb1a2b891b9c5a34af9e319f
Author: David Matlack <dmatlack@google.com>

PCI: liveupdate: Track incoming preserved PCI devices

This patch adds support to the PCI core for tracking preserved PCI devices 
across Live Update. It introduces pci_liveupdate_setup_device() to fetch 
serialized state from the Live Update Orchestrator and exposes APIs for 
drivers to notify the PCI core when preservation is finished.

> diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c
> index 03075ce06ac98..df6a02240aa47 100644
> --- a/drivers/pci/liveupdate.c
> +++ b/drivers/pci/liveupdate.c

[ ... ]

> @@ -138,13 +172,58 @@ static void pci_flb_unpreserve(struct liveupdate_flb_op_args *args)
>  
>  static int pci_flb_retrieve(struct liveupdate_flb_op_args *args)
>  {
> -	args->obj = phys_to_virt(args->data);
> +	struct pci_ser *ser = phys_to_virt(args->data);
> +	struct pci_flb_incoming *incoming;
> +	struct pci_dev_ser *dev_ser;
> +	struct kho_block_set_it it;
> +	int ret = -ENOMEM;
> +
> +	incoming = kzalloc_obj(*incoming);
> +	if (!incoming)
> +		goto err_restore_free;

[ ... ]

> +err_block_set_destroy:
> +	kho_block_set_destroy(&incoming->block_set);
> +err_free_incoming:
> +	xa_destroy(&incoming->xa);
> +	kfree(incoming);
> +err_restore_free:
> +	kho_restore_free(ser);
> +	return ret;
>  }

[Severity: Medium]
If kzalloc_obj() fails, the code jumps to err_restore_free and calls
kho_restore_free(ser).

Because the underlying memory pages backing ser->devices (the KHO block set)
have not been restored or explicitly freed, does this error path permanently
leak the memory reserved for the block set?

[ ... ]

> @@ -298,6 +377,87 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev)

[ ... ]

> +void pci_liveupdate_setup_device(struct pci_dev *dev)
> +{

[ ... ]

> +	dev_ser = xa_load(&incoming->xa, key);
> +
> +	/*
> +	 * This device was not preserved across Live Update, or it was preserved
> +	 * but has already been probed and gone through pci_liveupdate_finish(),
> +	 * e.g. due to removing and re-adding the device. Either way, it's not
> +	 * treated as incoming-preserved.
> +	 */
> +	if (!dev_ser || !dev_ser->refcount) {
> +		pci_liveupdate_flb_put_incoming();
> +		return;
> +	}

[ ... ]

>  void pci_liveupdate_cleanup_device(struct pci_dev *dev)
>  {
>  	/*
> @@ -309,7 +469,83 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev)
>  	 */
>  	if (READ_ONCE(dev->liveupdate.outgoing))
>  		pci_WARN(dev, 1, "Destroying outgoing-preserved device!\n");
> +
> +	if (READ_ONCE(dev->liveupdate.incoming)) {
> +		pci_WARN(dev, 1, "Destroying incoming-preserved device!\n");
> +		pci_liveupdate_flb_put_incoming();
> +	}
>  }

[Severity: Medium]
In pci_liveupdate_cleanup_device(), the FLB reference is dropped but 
dev_ser->refcount is left unmodified.

If a preserved device is removed or destroyed before its driver calls 
pci_liveupdate_finish() (for instance, if probe fails), and a new device
is subsequently hot-plugged at the same BDF, won't pci_liveupdate_setup_device()
see the stale dev_ser with a non-zero refcount and incorrectly associate the 
new device with the stale preserved state?

> +static void pci_liveupdate_finish_device(struct pci_ser *ser, struct pci_dev *dev)
> +{
> +	if (!dev->liveupdate.incoming) {
> +		pci_warn(dev, "Cannot finish preserving an unpreserved device\n");
> +		return;
> +	}
> +
> +	if (dev->liveupdate.incoming->refcount != 1) {
> +		pci_WARN(dev, 1, "Preserved device has a corrupted refcount!\n");
> +		return;
> +	}

[Severity: High]
Is this strict refcount != 1 check correct for PCI bridges?

Looking at the outgoing path in pci_liveupdate_preserve_device_again(), a 
bridge legitimately has its refcount incremented for each preserved downstream 
device, making it greater than 1.

When the bridge driver calls pci_liveupdate_finish() on the incoming side, 
won't this check fail, abort the finish process, and permanently leak the 
FLB reference for the bridge?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260710212616.1351130-1-dmatlack@google.com?part=3

  reply	other threads:[~2026-07-10 21:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 21:26 [PATCH v7 00/12] PCI: liveupdate: PCI core support for Live Update David Matlack
2026-07-10 21:26 ` [PATCH v7 01/12] PCI: liveupdate: Set up FLB handler for the PCI core David Matlack
2026-07-10 21:36   ` sashiko-bot
2026-07-10 21:26 ` [PATCH v7 02/12] PCI: liveupdate: Track outgoing preserved PCI devices David Matlack
2026-07-10 21:39   ` sashiko-bot
2026-07-10 22:20     ` David Matlack
2026-07-10 21:26 ` [PATCH v7 03/12] PCI: liveupdate: Track incoming " David Matlack
2026-07-10 21:39   ` sashiko-bot [this message]
2026-07-10 22:31     ` David Matlack
2026-07-10 21:26 ` [PATCH v7 04/12] PCI: liveupdate: Document driver binding responsibilities David Matlack
2026-07-10 21:28   ` sashiko-bot
2026-07-10 21:26 ` [PATCH v7 05/12] PCI: liveupdate: Keep bus numbers constant during Live Update David Matlack
2026-07-10 21:32   ` sashiko-bot
2026-07-10 21:26 ` [PATCH v7 06/12] PCI: liveupdate: Auto-preserve upstream bridges across " David Matlack
2026-07-10 21:33   ` sashiko-bot
2026-07-10 21:26 ` [PATCH v7 07/12] PCI: Refactor matching logic for pci_dev_acs_ops David Matlack
2026-07-10 21:34   ` sashiko-bot
2026-07-10 21:26 ` [PATCH v7 08/12] PCI: liveupdate: Inherit ACS flags in incoming preserved devices David Matlack
2026-07-10 21:34   ` sashiko-bot
2026-07-10 21:26 ` [PATCH v7 09/12] PCI: liveupdate: Inherit ARI Forwarding Enable on preserved bridges David Matlack
2026-07-10 21:37   ` sashiko-bot
2026-07-10 22:07     ` David Matlack
2026-07-10 21:26 ` [PATCH v7 10/12] PCI: liveupdate: Freeze preservation status during shutdown David Matlack
2026-07-10 21:35   ` sashiko-bot
2026-07-10 21:26 ` [PATCH v7 11/12] PCI: liveupdate: Do not disable bus mastering on preserved devices during kexec David Matlack
2026-07-10 21:38   ` sashiko-bot
2026-07-10 21:26 ` [PATCH v7 12/12] Documentation: PCI: Add documentation for Live Update David Matlack
2026-07-10 21:37   ` 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=20260710213928.E7CE11F0155B@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmatlack@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox