Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	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, 05 Dec 2026 01:04:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-250878@kernel.org> (raw)
In-Reply-To: <20261205003957.3304-4-ilpo.jarvinen@linux.intel.com>

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?

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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205003957.3304-1-ilpo.jarvinen@linux.intel.com?part=3

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

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com>
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 [this message]
2026-12-05  1:25     ` Ilpo Järvinen
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 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 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

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=sashiko-outbox-250878@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox