All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: sashiko-reviews@lists.linux.dev
Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	 intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	 linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 03/16] PCI: Abort BAR resize only if saving the resized BAR fails
Date: Sat, 5 Dec 2026 03:25:57 +0200 (EET)	[thread overview]
Message-ID: <1feedb58-3002-59f7-a0f6-197bfb65d41b@linux.intel.com> (raw)
In-Reply-To: <sashiko-outbox-250878@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 3652 bytes --]

On Sat, 5 Dec 2026, sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] PCI: continuing after -ENOMEM in
>   pci_do_resource_release_and_resize()
> - [Medium] PCI: pci_do_resource_release_and_resize() skips unsaved
>   unassigned BARs
> --
> 
> commit 2e0d31c7b9377b1d5689204c149a99e359a637cb
> Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> 
> PCI: Abort BAR resize only if saving the resized BAR fails
> 
> This commit changes pci_do_resource_release_and_resize() so that a
> failure to save a BAR in the saved list only aborts and rolls back when
> the failing BAR is the one being resized, leaving other BARs in place
> and continuing.
> 
> > diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> > index db16c8c2913d6..c18664b5e5a25 100644
> > --- a/drivers/pci/setup-bus.c
> > +++ b/drivers/pci/setup-bus.c
> > @@ -2407,8 +2407,11 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
> >  			continue;
> >  
> >  		ret = pci_dev_res_add_to_list(&saved, pdev, r, 0, 0);
> > -		if (ret)
> > -			goto restore;
> > +		if (ret) {
> > +			if (i == resno)
> > +				goto restore;
> > +			continue;
> > +		}
> >  		pci_release_resource(pdev, i);
> >  	}
> 
> [Severity: Medium]
> Can continuing after pci_dev_res_add_to_list() fails with -ENOMEM turn a
> clean rollback into a kernel panic?

It can, like boot can too. One day, I'll remove that panic() but it isn't 
going to be in this series. There are no shortage of more important things 
to address than this panic().

> pci_dev_res_add_to_list() only fails when kzalloc_obj() cannot allocate a
> struct pci_dev_resource.  If that happens for a sibling BAR after the
> resized BAR was already released, leaving the sibling BAR assigned keeps
> b_win->child non-NULL.
> 
> pbus_reassign_bridge_resources() then skips its own save check and calls
> into pdev_sort_resources(), which allocates the same struct pci_dev_resource
> with kzalloc_obj() for the released resized BAR and panics on failure.
> 
> Even if the allocation failure is transient, leaving the sibling BAR
> assigned pins the bridge window and can mask the -ENOMEM as -ENOSPC.
> 
> [Severity: Medium]
> What happens if the unsaved sibling BAR is currently unassigned rather than
> assigned?
> 
> Because this loop does not check resource_assigned(r), an unassigned BAR
> with non-zero flags (for example, on a PCI_PROBE_ONLY platform) still
> matches b_win via pbus_select_window().  Continuing on error leaves it
> unassigned and absent from saved.
>
> When b_win is not released (for example, when exclude_bars keeps another
> BAR in place), pdev_sort_resources() includes that unassigned BAR and can
> assign it into resno's vacated range while the enlarged resno fails with
> -ENOSPC.
> 
> Rollback only releases resources tracked in saved and their children, so
> neither b_win nor the sibling BAR is released.  pci_claim_resource() for
> resno then fails with -EBUSY, leaving the resized BAR unassigned.
> 
> Checking (i == resno || !resource_assigned(r)) before jumping to restore
> would avoid leaving an unassigned BAR untracked.

Generally, if a BAR is not assigned, pci_enable_resources() would have 
already refused to enable the device, so it's hard to see how this would 
make things significantly worse or better. Not sure what could be salvaged 
in the suggested rollback scenario as it only trades one resource failure 
to another.

And it still has the alloc fail precondition too.

-- 
 i.

  reply	other threads:[~2026-12-05  1:26 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  0:39 [PATCH v2 00/16] PCI: Resource release fixes and improvements Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 01/16] PCI: Release all resources before restoring them in BAR resize rollback Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 02/16] PCI: Set new BAR Size only after releasing the BARs for BAR resize Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 03/16] PCI: Abort BAR resize only if saving the resized BAR fails Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  1:25     ` Ilpo Järvinen [this message]
2026-12-05  0:39 ` [PATCH v2 04/16] PCI: Consistently use Header Type to detect bridge headers Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  0:39 ` [PATCH v2 05/16] resource: Check that the resource is in the tree when releasing it Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 06/16] resource, kunit: Add test for releasing a resource not in the tree Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 07/16] resource: Add release_leaf_resource() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 08/16] resource, kunit: Add test for release_leaf_resource() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 09/16] PCI: Do not release resources with children in pci_release_resource() Ilpo Järvinen
2026-12-05  1:04   ` sashiko-bot
2026-12-05  1:29     ` Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 10/16] resource: Rename next_resource() and for_each_resource() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 11/16] resource: Make resource_lock and resource tree traversal available Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 12/16] resource: Add release_resource_locked() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 13/16] PCI: Split pci_resource_post_release() out of pci_release_resource() Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 14/16] PCI: Add iterators for devices and resources in bus windows Ilpo Järvinen
2026-12-05  1:02   ` sashiko-bot
2026-12-05  1:12     ` Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 15/16] PCI: Keep the range of fixed resources when releasing them Ilpo Järvinen
2026-12-05  0:39 ` [PATCH v2 16/16] PCI: Release only PCI resources when releasing a resource tree Ilpo Järvinen
2026-12-05  1:11   ` sashiko-bot
2026-12-05  1:57     ` Ilpo Järvinen
2026-12-05  0:50 ` ✗ CI.checkpatch: warning for PCI: Resource release fixes and improvements (rev2) Patchwork
2026-12-05  0:52 ` ✓ CI.KUnit: success " Patchwork
2026-12-05  1:27 ` ✓ Xe.CI.BAT: " Patchwork
2026-12-05  2:06 ` ✓ i915.CI.BAT: " Patchwork
2026-12-05 16:24 ` ✗ i915.CI.Full: failure " Patchwork

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=1feedb58-3002-59f7-a0f6-197bfb65d41b@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --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.