Skip to content

Commit 6575b26

Browse files
djbwweiny2
authored andcommitted
cxl/port: Fix CXL port initialization order when the subsystem is built-in
When the CXL subsystem is built-in the module init order is determined by Makefile order. That order violates expectations. The expectation is that cxl_acpi and cxl_mem can race to attach. If cxl_acpi wins the race, cxl_mem will find the enabled CXL root ports it needs. If cxl_acpi loses the race it will retrigger cxl_mem to attach via cxl_bus_rescan(). That flow only works if cxl_acpi can assume ports are enabled immediately upon cxl_acpi_probe() return. That in turn can only happen in the CONFIG_CXL_ACPI=y case if the cxl_port driver is registered before cxl_acpi_probe() runs. Fix up the order to prevent initialization failures. Ensure that cxl_port is built-in when cxl_acpi is also built-in, arrange for Makefile order to resolve the subsys_initcall() order of cxl_port and cxl_acpi, and arrange for Makefile order to resolve the device_initcall() (module_init()) order of the remaining objects. As for what contributed to this not being found earlier, the CXL regression environment, cxl_test, builds all CXL functionality as a module to allow to symbol mocking and other dynamic reload tests. As a result there is no regression coverage for the built-in case. Reported-by: Gregory Price <[email protected]> Closes: http://lore.kernel.org/[email protected] Tested-by: Gregory Price <[email protected]> Fixes: 8dd2bc0 ("cxl/mem: Add the cxl_mem driver") Cc: [email protected] Cc: Davidlohr Bueso <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Dave Jiang <[email protected]> Cc: Alison Schofield <[email protected]> Cc: Vishal Verma <[email protected]> Cc: Ira Weiny <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Tested-by: Alejandro Lucero <[email protected]> Reviewed-by: Alejandro Lucero <[email protected]> Signed-off-by: Dan Williams <[email protected]> Link: https://patch.msgid.link/172988474904.476062.7961350937442459266.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Ira Weiny <[email protected]>
1 parent 53ab867 commit 6575b26

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

drivers/cxl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ config CXL_ACPI
6060
default CXL_BUS
6161
select ACPI_TABLE_LIB
6262
select ACPI_HMAT
63+
select CXL_PORT
6364
help
6465
Enable support for host managed device memory (HDM) resources
6566
published by a platform's ACPI CXL memory layout description. See

drivers/cxl/Makefile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
3+
# Order is important here for the built-in case:
4+
# - 'core' first for fundamental init
5+
# - 'port' before platform root drivers like 'acpi' so that CXL-root ports
6+
# are immediately enabled
7+
# - 'mem' and 'pmem' before endpoint drivers so that memdevs are
8+
# immediately enabled
9+
# - 'pci' last, also mirrors the hardware enumeration hierarchy
210
obj-y += core/
3-
obj-$(CONFIG_CXL_PCI) += cxl_pci.o
4-
obj-$(CONFIG_CXL_MEM) += cxl_mem.o
11+
obj-$(CONFIG_CXL_PORT) += cxl_port.o
512
obj-$(CONFIG_CXL_ACPI) += cxl_acpi.o
613
obj-$(CONFIG_CXL_PMEM) += cxl_pmem.o
7-
obj-$(CONFIG_CXL_PORT) += cxl_port.o
14+
obj-$(CONFIG_CXL_MEM) += cxl_mem.o
15+
obj-$(CONFIG_CXL_PCI) += cxl_pci.o
816

9-
cxl_mem-y := mem.o
10-
cxl_pci-y := pci.o
17+
cxl_port-y := port.o
1118
cxl_acpi-y := acpi.o
1219
cxl_pmem-y := pmem.o security.o
13-
cxl_port-y := port.o
20+
cxl_mem-y := mem.o
21+
cxl_pci-y := pci.o

drivers/cxl/port.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,22 @@ static struct cxl_driver cxl_port_driver = {
208208
},
209209
};
210210

211-
module_cxl_driver(cxl_port_driver);
211+
static int __init cxl_port_init(void)
212+
{
213+
return cxl_driver_register(&cxl_port_driver);
214+
}
215+
/*
216+
* Be ready to immediately enable ports emitted by the platform CXL root
217+
* (e.g. cxl_acpi) when CONFIG_CXL_PORT=y.
218+
*/
219+
subsys_initcall(cxl_port_init);
220+
221+
static void __exit cxl_port_exit(void)
222+
{
223+
cxl_driver_unregister(&cxl_port_driver);
224+
}
225+
module_exit(cxl_port_exit);
226+
212227
MODULE_DESCRIPTION("CXL: Port enumeration and services");
213228
MODULE_LICENSE("GPL v2");
214229
MODULE_IMPORT_NS(CXL);

0 commit comments

Comments
 (0)