Skip to content

Commit 2c6370e

Browse files
Ben Fradellajwrdegoede
authored andcommitted
platform/x86: p2sb: Don't init until unassigned resources have been assigned
The P2SB could get an invalid BAR from the BIOS, and that won't be fixed up until pcibios_assign_resources(), which is an fs_initcall(). - Move p2sb_fs_init() to an fs_initcall_sync(). This is still early enough to avoid a race with any dependent drivers. - Add a check for IORESOURCE_UNSET in p2sb_valid_resource() to catch unset BARs going forward. - Return error values from p2sb_fs_init() so that the 'initcall_debug' cmdline arg provides useful data. Signed-off-by: Ben Fradella <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Tested-by: Klara Modin <[email protected]> Reviewed-by: Shin'ichiro Kawasaki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Hans de Goede <[email protected]>
1 parent 7c4cd2a commit 2c6370e

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

drivers/platform/x86/p2sb.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ static void p2sb_get_devfn(unsigned int *devfn)
5555
*devfn = fn;
5656
}
5757

58-
static bool p2sb_valid_resource(struct resource *res)
58+
static bool p2sb_valid_resource(const struct resource *res)
5959
{
60-
if (res->flags)
61-
return true;
62-
63-
return false;
60+
return res->flags & ~IORESOURCE_UNSET;
6461
}
6562

6663
/* Copy resource from the first BAR of the device in question */
@@ -213,16 +210,20 @@ EXPORT_SYMBOL_GPL(p2sb_bar);
213210

214211
static int __init p2sb_fs_init(void)
215212
{
216-
p2sb_cache_resources();
217-
return 0;
213+
return p2sb_cache_resources();
218214
}
219215

220216
/*
221-
* pci_rescan_remove_lock to avoid access to unhidden P2SB devices can
222-
* not be locked in sysfs pci bus rescan path because of deadlock. To
223-
* avoid the deadlock, access to P2SB devices with the lock at an early
224-
* step in kernel initialization and cache required resources. This
225-
* should happen after subsys_initcall which initializes PCI subsystem
226-
* and before device_initcall which requires P2SB resources.
217+
* pci_rescan_remove_lock() can not be locked in sysfs PCI bus rescan path
218+
* because of deadlock. To avoid the deadlock, access P2SB devices with the lock
219+
* at an early step in kernel initialization and cache required resources.
220+
*
221+
* We want to run as early as possible. If the P2SB was assigned a bad BAR,
222+
* we'll need to wait on pcibios_assign_resources() to fix it. So, our list of
223+
* initcall dependencies looks something like this:
224+
*
225+
* ...
226+
* subsys_initcall (pci_subsys_init)
227+
* fs_initcall (pcibios_assign_resources)
227228
*/
228-
fs_initcall(p2sb_fs_init);
229+
fs_initcall_sync(p2sb_fs_init);

0 commit comments

Comments
 (0)