mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Guenter Roeck" <linux@roeck-us.net>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Igor Mammedov" <imammedo@redhat.com>,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>,
	"Michał Winiarski" <michal.winiarski@intel.com>
Subject: [PATCH 1/1] PCI: Restore assigned resources fully after release
Date: Thu,  3 Apr 2025 12:31:37 +0300	[thread overview]
Message-ID: <20250403093137.1481-1-ilpo.jarvinen@linux.intel.com> (raw)

PCI resource fitting code in __assign_resources_sorted() runs in
multiple steps. A resource that was successfully assigned may have to
be released before the next step attempts assignment again. The
assign+release cycle is destructive to a start-aligned struct resource
(bridge window or IOV resource) because the start field is overwritten
with the real address when the resource got assigned.

Properly restore the resource after releasing it. The start, end, and
flags fields must be stored into the related struct pci_dev_resource in
order to be able to restore the resource to its original state.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Fixes: 96336ec70264 ("PCI: Perform reset_resource() and build fail list in sync")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/pci/setup-bus.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 54d6f4fa3ce1..e994c546422c 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -187,6 +187,9 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
 			panic("%s: kzalloc() failed!\n", __func__);
 		tmp->res = r;
 		tmp->dev = dev;
+		tmp->start = r->start;
+		tmp->end = r->end;
+		tmp->flags = r->flags;
 
 		/* Fallback is smallest one or list is empty */
 		n = head;
@@ -545,6 +548,7 @@ static void __assign_resources_sorted(struct list_head *head,
 		pci_dbg(dev, "%s %pR: releasing\n", res_name, res);
 
 		release_resource(res);
+		restore_dev_resource(dev_res);
 	}
 	/* Restore start/end/flags from saved list */
 	list_for_each_entry(save_res, &save_head, list)

base-commit: 7d06015d936c861160803e020f68f413b5c3cd9d
-- 
2.39.5


             reply	other threads:[~2025-04-03  9:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03  9:31 Ilpo Järvinen [this message]
2025-04-03 12:16 ` Guenter Roeck
2025-04-14 13:29 ` Ondřej Jirman
2025-04-17 14:49 ` Nicolas Frattaroli
2025-04-17 16:39 ` Bjorn Helgaas
2025-04-18 14:41   ` 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=20250403093137.1481-1-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=imammedo@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=michal.winiarski@intel.com \
    --cc=mika.westerberg@linux.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®