From: Bjorn Helgaas <helgaas@kernel.org>
To: David Matlack <dmatlack@google.com>
Cc: kexec@lists.infradead.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-pci@vger.kernel.org,
Adithya Jayachandran <ajayachandra@nvidia.com>,
Alexander Graf <graf@amazon.com>,
Alex Williamson <alex@shazbot.org>,
Bjorn Helgaas <bhelgaas@google.com>, Chris Li <chrisl@kernel.org>,
David Rientjes <rientjes@google.com>,
Jacob Pan <jacob.pan@linux.microsoft.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Jonathan Corbet <corbet@lwn.net>, Josh Hilke <jrhilke@google.com>,
Leon Romanovsky <leonro@nvidia.com>,
Lukas Wunner <lukas@wunner.de>, Mike Rapoport <rppt@kernel.org>,
Parav Pandit <parav@nvidia.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Pranjal Shrivastava <praan@google.com>,
Pratyush Yadav <pratyush@kernel.org>,
Randy Dunlap <rdunlap@infradead.org>,
Saeed Mahameed <saeedm@nvidia.com>,
Samiullah Khawaja <skhawaja@google.com>,
Shuah Khan <skhan@linuxfoundation.org>,
Vipin Sharma <vipinsh@google.com>, William Tu <witu@nvidia.com>,
Yi Liu <yi.l.liu@intel.com>
Subject: Re: [PATCH v10 05/13] PCI: liveupdate: Auto-preserve upstream bridges across Live Update
Date: Fri, 6 Nov 2026 12:40:32 -0600 [thread overview]
Message-ID: <20261106184032.GA1640926@bhelgaas> (raw)
In-Reply-To: <DMOC3XV68W0K.3FGK4UZ87838R@google.com>
On Fri, Nov 06, 2026 at 06:20:36PM +0000, David Matlack wrote:
> On Fri Nov 6, 2026 at 5:34 PM UTC, Bjorn Helgaas wrote:
> > On Tue, Oct 13, 2026 at 04:25:21PM +0000, David Matlack wrote:
> >> static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing,
> >> struct pci_dev *dev)
> >> {
> >> - struct pci_dev_ser *dev_ser;
> >> -
> >> if (dev->is_virtfn) {
> >> pci_warn(dev, "Cannot preserve Virtual Functions\n");
> >> return -EINVAL;
> >> }
> >>
> >> - if (dev->liveupdate.outgoing) {
> >> + /*
> >> + * Endpoint devices should not be preserved more than once.
> >> + * Bridges are preserved once for every downstream device that
> >> + * is preserved.
> >> + */
> >> + if (dev->liveupdate.outgoing && !dev->subordinate) {
> >> pci_warn(dev, "Device is already preserved\n");
> >> return -EBUSY;
> >> }
> >>
> >> - if (!pci_is_root_bus(dev->bus)) {
> >> - pci_warn(dev, "Cannot preserve devices behind bridges\n");
> >> + if (dev->liveupdate.outgoing && !dev->liveupdate.outgoing->refcount) {
> >> + pci_WARN(dev, 1, "Preserved device with 0 refcount!\n");
> >> return -EINVAL;
> >> }
> >>
> >> - dev_ser = pci_flb_alloc_dev_ser(outgoing);
> >> - if (IS_ERR(dev_ser))
> >> - return PTR_ERR(dev_ser);
> >> + if (!dev->liveupdate.outgoing) {
> >> + struct pci_dev_ser *dev_ser;
> >>
> >> - pci_info(dev, "Device will be preserved across next Live Update\n");
> >> - outgoing->ser->nr_devices++;
> >> - outgoing->ser->devices = kho_block_set_head_pa(&outgoing->block_set);
> >> + dev_ser = pci_flb_alloc_dev_ser(outgoing);
> >> + if (IS_ERR(dev_ser))
> >> + return PTR_ERR(dev_ser);
> >>
> >> - dev_ser->domain = pci_domain_nr(dev->bus);
> >> - dev_ser->bdf = pci_dev_id(dev);
> >> - dev_ser->refcount++;
> >> + pci_info(dev, "Device will be preserved across next Live Update\n");
> >> + outgoing->ser->nr_devices++;
> >
> > This looks a little funny because prior to this patch, nr_devices was
> > always incremented in pci_liveupdate_preserve_device() and always
> > decremented in pci_liveupdate_unpreserve_device(). Now it's only
> > incremented once (per device) in pci_liveupdate_preserve_device(), so
> > it looks unbalanced.
> >
> > My guess is this is because previously we didn't expect to preserve
> > bridges at all, and now pci_liveupdate_preserve_device() might be
> > called several times for a bridge, and it's all just fine, but it's a
> > little subtle.
>
> Right. nr_devices counts struct pci_dev_ser entries that are in use, so
> it goes up when a device's refcount goes from 0 to 1 (the entry is
> allocated) and down when it goes from 1 to 0 (the entry is released).
> For endpoints that is every preserve/unpreserve call, but a bridge is
> preserved once per preserved device below it, so most calls for a
> bridge only change its refcount.
>
> > I suppose the "(dev->liveupdate.outgoing && !dev->subordinate)" test
> > above is what allows us to just increment refcount each time a bridge
> > is preserved. And the test around pci_flb_alloc_dev_ser() is doing
> > basically the same thing. I wonder if there's a way to connect them
> > more explicitly.
>
> Agreed, both points come from the same thing being spread out. I think
> both can be fixed by splitting pci_liveupdate_preserve_device() into
> "already preserved" and "first preservation" cases, and moving the
> nr_devices accounting into helpers that allocate and release the
> struct pci_dev_ser, so it is visibly paired:
>
> if (dev_ser) {
> /*
> * Endpoints can only be preserved once. Bridges are
> * preserved once for every preserved device below them.
> */
> if (!dev->subordinate) {
> pci_warn(dev, "Device is already preserved\n");
> return -EBUSY;
> }
> ...
> } else {
> dev_ser = pci_liveupdate_alloc_dev_ser(outgoing, dev);
> if (IS_ERR(dev_ser))
> return PTR_ERR(dev_ser);
> }
>
> dev_ser->refcount++;
>
> with pci_liveupdate_unpreserve_device() calling a matching
> pci_liveupdate_free_dev_ser() when the refcount drops to 0.
I think that would be good.
next prev parent reply other threads:[~2026-11-06 18:40 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 16:25 [PATCH v10 00/13] PCI: liveupdate: PCI core support for " David Matlack
2026-10-13 16:25 ` [PATCH v10 01/13] PCI: liveupdate: Set up FLB handler for the PCI core David Matlack
2026-11-06 16:52 ` Bjorn Helgaas
2026-10-13 16:25 ` [PATCH v10 02/13] PCI: liveupdate: Track outgoing preserved PCI devices David Matlack
2026-10-13 16:25 ` [PATCH v10 03/13] PCI: liveupdate: Track incoming " David Matlack
2026-11-06 16:53 ` Bjorn Helgaas
2026-10-13 16:25 ` [PATCH v10 04/13] PCI: liveupdate: Document driver binding responsibilities David Matlack
2026-11-06 16:54 ` Bjorn Helgaas
2026-10-13 16:25 ` [PATCH v10 05/13] PCI: liveupdate: Auto-preserve upstream bridges across Live Update David Matlack
2026-11-06 17:34 ` Bjorn Helgaas
2026-11-06 18:20 ` David Matlack
2026-11-06 18:40 ` Bjorn Helgaas [this message]
2026-11-06 18:40 ` Bjorn Helgaas
2026-10-13 16:25 ` [PATCH v10 06/13] PCI: liveupdate: Preserve bus numbers during " David Matlack
2026-11-06 17:43 ` Bjorn Helgaas
2026-10-13 16:25 ` [PATCH v10 07/13] PCI: Refactor matching logic for pci_dev_acs_ops David Matlack
2026-10-13 16:25 ` [PATCH v10 08/13] PCI: Save and restore the ACS Control register and Egress Control Vector David Matlack
2026-10-13 16:25 ` [PATCH v10 09/13] PCI: liveupdate: Adopt ACS controls in incoming preserved devices David Matlack
2026-10-13 16:25 ` [PATCH v10 10/13] PCI: liveupdate: Adopt ARI Forwarding Enable on preserved bridges David Matlack
2026-10-13 16:25 ` [PATCH v10 11/13] PCI: liveupdate: Freeze preservation status during shutdown David Matlack
2026-10-13 16:25 ` [PATCH v10 12/13] PCI: liveupdate: Do not disable bus mastering on preserved devices during kexec David Matlack
2026-10-13 16:25 ` [PATCH v10 13/13] Documentation: PCI: Add documentation for Live Update David Matlack
2026-11-03 19:21 ` [PATCH v10 00/13] PCI: liveupdate: PCI core support " Pasha Tatashin
2026-11-04 13:40 ` Mike Rapoport
2026-11-04 18:00 ` Pasha Tatashin
2026-11-04 18:06 ` David Matlack
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=20261106184032.GA1640926@bhelgaas \
--to=helgaas@kernel.org \
--cc=ajayachandra@nvidia.com \
--cc=alex@shazbot.org \
--cc=bhelgaas@google.com \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=dmatlack@google.com \
--cc=graf@amazon.com \
--cc=jacob.pan@linux.microsoft.com \
--cc=jgg@nvidia.com \
--cc=jrhilke@google.com \
--cc=kexec@lists.infradead.org \
--cc=leonro@nvidia.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=parav@nvidia.com \
--cc=pasha.tatashin@soleen.com \
--cc=praan@google.com \
--cc=pratyush@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=saeedm@nvidia.com \
--cc=skhan@linuxfoundation.org \
--cc=skhawaja@google.com \
--cc=vipinsh@google.com \
--cc=witu@nvidia.com \
--cc=yi.l.liu@intel.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
all inboxes | Powered by JetHome®