Skip to content

Commit 96336ec

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Perform reset_resource() and build fail list in sync
Resetting a resource is problematic as it prevents attempting to allocate the resource later, unless something in between restores the resource. Similarly, if fail_head does not contain all resources that were reset, those resources cannot be restored later. The entire reset/restore cycle adds complexity and leaving resources in the reset state causes issues to other code such as for checks done in pci_enable_resources(). Take a small step towards not resetting resources by delaying reset until the end of resource assignment and build failure list (fail_head) in sync with the reset to avoid leaving behind resources that cannot be restored (for the case where the caller provides fail_head in the first place to allow restore somewhere in the callchain, as is not all callers pass non-NULL fail_head). Leave the Expansion ROM check temporarily in place while building the failure list until an upcoming change that reworks optional resource handling. Ideally, whole resource reset could be removed but doing that in one step would be non-tractable due to complexity of all related code. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Tested-by: Xiaochun Lee <[email protected]>
1 parent e89df6d commit 96336ec

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

drivers/pci/setup-bus.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,14 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
252252

253253
res = add_res->res;
254254
dev = add_res->dev;
255+
idx = pci_resource_num(dev, res);
255256

256-
/* Skip resource that has been reset */
257-
if (!res->flags)
257+
/*
258+
* Skip resource that failed the earlier assignment and is
259+
* not optional as it would just fail again.
260+
*/
261+
if (!res->parent && resource_size(res) &&
262+
!pci_resource_is_optional(dev, idx))
258263
goto out;
259264

260265
/* Skip this resource if not found in head list */
@@ -267,7 +272,6 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
267272
if (!found_match) /* Just skip */
268273
continue;
269274

270-
idx = pci_resource_num(dev, res);
271275
res_name = pci_resource_name(dev, idx);
272276
add_size = add_res->add_size;
273277
align = add_res->min_align;
@@ -277,7 +281,6 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
277281
pci_dbg(dev,
278282
"%s %pR: ignoring failure in optional allocation\n",
279283
res_name, res);
280-
reset_resource(res);
281284
}
282285
} else {
283286
res->flags |= add_res->flags &
@@ -332,7 +335,6 @@ static void assign_requested_resources_sorted(struct list_head *head,
332335
0 /* don't care */,
333336
0 /* don't care */);
334337
}
335-
reset_resource(res);
336338
}
337339
}
338340
}
@@ -518,13 +520,34 @@ static void __assign_resources_sorted(struct list_head *head,
518520

519521
requested_and_reassign:
520522
/* Satisfy the must-have resource requests */
521-
assign_requested_resources_sorted(head, fail_head);
523+
assign_requested_resources_sorted(head, NULL);
522524

523525
/* Try to satisfy any additional optional resource requests */
524526
if (!list_empty(realloc_head))
525527
reassign_resources_sorted(realloc_head, head);
526528

527529
out:
530+
/* Reset any failed resource, cannot use fail_head as it can be NULL. */
531+
list_for_each_entry(dev_res, head, list) {
532+
res = dev_res->res;
533+
dev = dev_res->dev;
534+
535+
if (res->parent)
536+
continue;
537+
538+
/*
539+
* If the failed resource is a ROM BAR and it will
540+
* be enabled later, don't add it to the list.
541+
*/
542+
if (fail_head && !pci_resource_is_disabled_rom(res, idx)) {
543+
add_to_list(fail_head, dev, res,
544+
0 /* don't care */,
545+
0 /* don't care */);
546+
}
547+
548+
reset_resource(res);
549+
}
550+
528551
free_list(head);
529552
}
530553

0 commit comments

Comments
 (0)