Introduce a background worker in cxl_acpi to delay SOFT RESERVE handling until the cxl_mem driver has probed at least one device. This coordination ensures that DAX registration or fallback handling for soft-reserved regions is not triggered prematurely.
The worker waits on cxl_wait_queue, which is signaled via cxl_mem_active_inc() during cxl_mem_probe(). Once at least one memory device probe is confirmed, the worker invokes wait_for_device_probe() to allow the rest of the CXL device hierarchy to complete initialization. Additionally, it also handles initialization order issues where cxl_acpi_probe() may complete before other drivers such as cxl_port or cxl_mem have loaded, especially when cxl_acpi and cxl_port are built-in and cxl_mem is a loadable module. In such cases, using only wait_for_device_probe() is insufficient, as it may return before all relevant probes are registered. While region creation happens in cxl_port_probe(), waiting on cxl_mem_active() would be sufficient as cxl_mem_probe() can only succeed after the port hierarchy is in place. Furthermore, since cxl_mem depends on cxl_pci, this also guarantees that cxl_pci has loaded by the time the wait completes. As cxl_mem_active() infrastructure already exists for tracking probe activity, cxl_acpi can use it without introducing new coordination mechanisms. Co-developed-by: Nathan Fontenot <nathan.fonte...@amd.com> Signed-off-by: Nathan Fontenot <nathan.fonte...@amd.com> Co-developed-by: Terry Bowman <terry.bow...@amd.com> Signed-off-by: Terry Bowman <terry.bow...@amd.com> Signed-off-by: Smita Koralahalli <smita.koralahallichannabasa...@amd.com> --- drivers/cxl/acpi.c | 18 ++++++++++++++++++ drivers/cxl/core/probe_state.c | 5 +++++ drivers/cxl/cxl.h | 2 ++ 3 files changed, 25 insertions(+) diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c index ca06d5acdf8f..3a27289e669b 100644 --- a/drivers/cxl/acpi.c +++ b/drivers/cxl/acpi.c @@ -823,6 +823,20 @@ static int pair_cxl_resource(struct device *dev, void *data) return 0; } +static void cxl_softreserv_mem_work_fn(struct work_struct *work) +{ + if (!wait_event_timeout(cxl_wait_queue, cxl_mem_active(), 30 * HZ)) + pr_debug("Timeout waiting for cxl_mem probing"); + + wait_for_device_probe(); +} +static DECLARE_WORK(cxl_sr_work, cxl_softreserv_mem_work_fn); + +static void cxl_softreserv_mem_update(void) +{ + schedule_work(&cxl_sr_work); +} + static int cxl_acpi_probe(struct platform_device *pdev) { int rc = 0; @@ -903,6 +917,9 @@ static int cxl_acpi_probe(struct platform_device *pdev) cxl_bus_rescan(); out: + /* Update SOFT RESERVE resources that intersect with CXL regions */ + cxl_softreserv_mem_update(); + return rc; } @@ -934,6 +951,7 @@ static int __init cxl_acpi_init(void) static void __exit cxl_acpi_exit(void) { + cancel_work_sync(&cxl_sr_work); platform_driver_unregister(&cxl_acpi_driver); cxl_bus_drain(); } diff --git a/drivers/cxl/core/probe_state.c b/drivers/cxl/core/probe_state.c index 5ba4b4de0e33..3089b2698b32 100644 --- a/drivers/cxl/core/probe_state.c +++ b/drivers/cxl/core/probe_state.c @@ -2,9 +2,12 @@ /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ #include <linux/atomic.h> #include <linux/export.h> +#include <linux/wait.h> #include "cxlmem.h" static atomic_t mem_active; +DECLARE_WAIT_QUEUE_HEAD(cxl_wait_queue); +EXPORT_SYMBOL_NS_GPL(cxl_wait_queue, "CXL"); bool cxl_mem_active(void) { @@ -13,10 +16,12 @@ bool cxl_mem_active(void) return false; } +EXPORT_SYMBOL_NS_GPL(cxl_mem_active, "CXL"); void cxl_mem_active_inc(void) { atomic_inc(&mem_active); + wake_up(&cxl_wait_queue); } EXPORT_SYMBOL_NS_GPL(cxl_mem_active_inc, "CXL"); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 3f1695c96abc..3117136f0208 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -903,6 +903,8 @@ void cxl_coordinates_combine(struct access_coordinate *out, bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port); +extern wait_queue_head_t cxl_wait_queue; + /* * Unit test builds overrides this to __weak, find the 'strong' version * of these symbols in tools/testing/cxl/. -- 2.17.1