All of lore.kernel.org
 help / color / mirror / Atom feed
From: <alucerop@amd.com>
To: <linux-cxl@vger.kernel.org>, <dave.jiang@intel.com>,
	<dave@stgolabs.net>, <jic23@kernel.org>,
	<alison.schofield@intel.com>, <vishal.l.verma@intel.com>
Cc: Alejandro Lucero <alucerop@amd.com>
Subject: [RFC 1/3] cxl: add tracepoints to the unwinding code path
Date: Wed, 18 Nov 2026 19:14:29 +0000	[thread overview]
Message-ID: <20261118191431.21781-2-alucerop@amd.com> (raw)
In-Reply-To: <20261118191431.21781-1-alucerop@amd.com>

From: Alejandro Lucero <alucerop@amd.com>

Once all CXL objects/devices are created for a Type2/3 device, the way
those same objects are removed depends on the triggering point with
several possibilities:

 - Type2 driver removed.
 - Through the sysfs unbind files linked to the cxl drivers.

Add tracepoints to the different functions invoked when the unwinding
happens which will help to visualize the process and debug potential
problems. As those functions can trigger further unwinding, add start
and done tracepoints for easily seeing the unwinding action graph.

Signed-off-by: Alejandro Lucero <alucerop@amd.com>
---
 drivers/cxl/core/memdev.c            | 10 +++
 drivers/cxl/core/port.c              | 16 +++++
 drivers/cxl/core/region.c            | 14 +++++
 drivers/cxl/cxl_memdev_tracepoints.h | 58 ++++++++++++++++++
 drivers/cxl/cxl_port_tracepoints.h   | 91 ++++++++++++++++++++++++++++
 drivers/cxl/cxl_region_tracepoints.h | 78 ++++++++++++++++++++++++
 6 files changed, 267 insertions(+)
 create mode 100644 drivers/cxl/cxl_memdev_tracepoints.h
 create mode 100644 drivers/cxl/cxl_port_tracepoints.h
 create mode 100644 drivers/cxl/cxl_region_tracepoints.h

diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index 787988e92965..7333fe7594bd 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -11,6 +11,9 @@
 #include "trace.h"
 #include "core.h"
 
+#define CREATE_TRACE_POINTS
+#include "cxl_memdev_tracepoints.h"
+
 static DECLARE_RWSEM(cxl_memdev_rwsem);
 
 /*
@@ -27,9 +30,11 @@ static void cxl_memdev_release(struct device *dev)
 	struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
 	struct device *parent = dev->parent;
 
+	trace_cxl_memdev_release(cxlmd, "start");
 	ida_free(&cxl_memdev_ida, cxlmd->id);
 	kfree(cxlmd);
 	put_device(parent);
+	trace_cxl_memdev_release(cxlmd, "done");
 }
 
 static char *cxl_memdev_devnode(const struct device *dev, umode_t *mode, kuid_t *uid,
@@ -752,9 +757,11 @@ static void cxl_memdev_unregister(void *_cxlmd)
 	struct cxl_memdev *cxlmd = _cxlmd;
 	struct device *dev = &cxlmd->dev;
 
+	trace_cxl_memdev_unregister(cxlmd, "start");
 	cdev_device_del(&cxlmd->cdev, dev);
 	cxl_memdev_shutdown(dev);
 	put_device(dev);
+	trace_cxl_memdev_unregister(cxlmd, "done");
 }
 
 static void detach_memdev(struct work_struct *work)
@@ -763,6 +770,7 @@ static void detach_memdev(struct work_struct *work)
 
 	cxlmd = container_of(work, typeof(*cxlmd), detach_work);
 
+	trace_cxl_memdev_detach(cxlmd, "start");
 	/*
 	 * When the creator of @cxlmd sets ->attach it indicates CXL operation
 	 * is required. In that case, @cxlmd detach escalates to parent device
@@ -772,7 +780,9 @@ static void detach_memdev(struct work_struct *work)
 		device_release_driver(cxlmd->dev.parent);
 	else
 		device_release_driver(&cxlmd->dev);
+
 	put_device(&cxlmd->dev);
+	trace_cxl_memdev_detach(cxlmd, "done");
 }
 
 static struct lock_class_key cxl_memdev_key;
diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index f3705ea44db7..9ccb0d185904 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -17,6 +17,9 @@
 #include <cxl.h>
 #include "core.h"
 
+#define CREATE_TRACE_POINTS
+#include "cxl_port_tracepoints.h"
+
 /**
  * DOC: cxl core
  *
@@ -34,6 +37,7 @@
 static DEFINE_IDA(cxl_port_ida);
 static DEFINE_XARRAY(cxl_root_buses);
 
+
 /*
  * The terminal device in PCI is NULL and @platform_bus
  * for platform devices (for cxl_test)
@@ -540,8 +544,10 @@ EXPORT_SYMBOL_NS_GPL(to_cxl_switch_decoder, "CXL");
 
 static void cxl_ep_release(struct cxl_ep *ep)
 {
+	trace_cxl_ep_release(ep->ep, "start");
 	put_device(ep->ep);
 	kfree(ep);
+	trace_cxl_ep_release(ep->ep, "done");
 }
 
 static void cxl_ep_remove(struct cxl_port *port, struct cxl_ep *ep)
@@ -558,6 +564,7 @@ static void cxl_port_release(struct device *dev)
 	unsigned long index;
 	struct cxl_ep *ep;
 
+	trace_cxl_port_release(dev, "start");
 	xa_for_each(&port->endpoints, index, ep)
 		cxl_ep_remove(port, ep);
 	xa_destroy(&port->endpoints);
@@ -571,6 +578,7 @@ static void cxl_port_release(struct device *dev)
 		put_device(dev->parent);
 		kfree(port);
 	}
+	trace_cxl_port_release(dev, "done");
 }
 
 static ssize_t decoders_committed_show(struct device *dev,
@@ -1478,6 +1486,8 @@ static void delete_endpoint(void *data)
 	struct cxl_port *endpoint = cxlmd->endpoint;
 	struct device *host = port_to_host(endpoint);
 
+	trace_cxl_delete_endpoint(&endpoint->dev, "start");
+
 	scoped_guard(device, host) {
 		if (host->driver && !endpoint->dead) {
 			devm_release_action(host, cxl_unlink_parent_dport, endpoint);
@@ -1488,6 +1498,7 @@ static void delete_endpoint(void *data)
 	}
 	put_device(&endpoint->dev);
 	put_device(host);
+	trace_cxl_delete_endpoint(&endpoint->dev, "done");
 }
 
 int cxl_endpoint_autoremove(struct cxl_memdev *cxlmd, struct cxl_port *endpoint)
@@ -1553,6 +1564,7 @@ static void cxl_detach_ep(void *data)
 {
 	struct cxl_memdev *cxlmd = data;
 
+	trace_cxl_detach_ep(&cxlmd->dev, "start");
 	for (int i = cxlmd->depth - 1; i >= 1; i--) {
 		struct cxl_port *port, *parent_port;
 		struct detach_ctx ctx = {
@@ -1595,6 +1607,7 @@ static void cxl_detach_ep(void *data)
 		}
 		device_unlock(&parent_port->dev);
 	}
+	trace_cxl_detach_ep(&cxlmd->dev, "done");
 }
 
 static resource_size_t find_component_registers(struct device *dev)
@@ -2283,6 +2296,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_decoder_add, "CXL");
 
 static void cxld_unregister(void *dev)
 {
+	trace_cxld_unregister(dev, "start");
 	if (is_endpoint_decoder(dev))
 		cxl_decoder_detach(NULL, to_cxl_endpoint_decoder(dev), -1,
 				   DETACH_INVALIDATE);
@@ -2290,6 +2304,7 @@ static void cxld_unregister(void *dev)
 		kill_regions(to_cxl_root_decoder(dev));
 
 	device_unregister(dev);
+	trace_cxld_unregister(dev, "done");
 }
 
 int cxl_decoder_autoremove(struct device *host, struct cxl_decoder *cxld)
@@ -2397,6 +2412,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_bus_drain, "CXL");
 
 bool schedule_cxl_memdev_detach(struct cxl_memdev *cxlmd)
 {
+	trace_schedule_cxl_memdev_detach(cxlmd);
 	return queue_work(cxl_bus_wq, &cxlmd->detach_work);
 }
 EXPORT_SYMBOL_NS_GPL(schedule_cxl_memdev_detach, "CXL");
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index a048bd5c06cb..efbd53a37405 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -18,6 +18,9 @@
 #include "core.h"
 #include "mce.h"
 
+#define CREATE_TRACE_POINTS
+#include "cxl_region_tracepoints.h"
+
 /**
  * DOC: cxl core region
  *
@@ -2275,6 +2278,7 @@ __cxl_decoder_detach(struct cxl_region *cxlr,
 	lockdep_assert_held_write(&cxl_rwsem.region);
 
 	if (!cxled) {
+		trace_cxl_decoder_detach(&cxlr->dev, "start");
 		p = &cxlr->params;
 
 		if (pos >= p->interleave_ways) {
@@ -2292,6 +2296,7 @@ __cxl_decoder_detach(struct cxl_region *cxlr,
 			cxl_cancel_auto_attach(cxled);
 			return NULL;
 		}
+		trace_cxl_decoder_detach(&cxlr->dev, "start");
 		p = &cxlr->params;
 	}
 
@@ -2329,6 +2334,7 @@ __cxl_decoder_detach(struct cxl_region *cxlr,
 	};
 
 	get_device(&cxlr->dev);
+	trace_cxl_decoder_detach(&cxlr->dev, "done");
 	return cxlr;
 }
 
@@ -2360,6 +2366,7 @@ int cxl_decoder_detach(struct cxl_region *cxlr,
 	}
 
 	if (detach) {
+		trace_cxl_decoder_detach_release_driver(&detach->dev);
 		device_release_driver(&detach->dev);
 		put_device(&detach->dev);
 	}
@@ -2521,6 +2528,7 @@ static void cxl_region_release(struct device *dev)
 	struct cxl_root_decoder *cxlrd = cxlr->cxlrd;
 	int id = atomic_read(&cxlrd->region_id);
 
+	trace_cxl_region_release(dev, "start");
 	/*
 	 * Try to reuse the recently idled id rather than the cached
 	 * next id to prevent the region id space from increasing
@@ -2536,6 +2544,7 @@ static void cxl_region_release(struct device *dev)
 out:
 	put_device(dev->parent);
 	kfree(cxlr);
+	trace_cxl_region_release(dev, "done");
 }
 
 const struct device_type cxl_region_type = {
@@ -2565,6 +2574,7 @@ static void unregister_region(struct cxl_region *cxlr)
 	struct cxl_region_params *p = &cxlr->params;
 	int i;
 
+	trace_cxl_unregister_region(&cxlr->dev, "start");
 	xa_erase(&cxlrd->regions, cxlr->id);
 	device_del(&cxlr->dev);
 
@@ -2580,6 +2590,7 @@ static void unregister_region(struct cxl_region *cxlr)
 
 	cxl_region_iomem_release(cxlr);
 	put_device(&cxlr->dev);
+	trace_cxl_unregister_region(&cxlr->dev, "done");
 }
 
 static void endpoint_unregister_region(void *_cxlr)
@@ -2587,10 +2598,12 @@ static void endpoint_unregister_region(void *_cxlr)
 	struct cxl_region *cxlr = _cxlr;
 	struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
 
+	trace_cxl_endpoint_unregister_region(&cxlr->dev, "start");
 	guard(mutex)(&cxlrd->regions_lock);
 	if (xa_load(&cxlrd->regions, cxlr->id))
 		unregister_region(cxlr);
 	put_device(&cxlr->dev);
+	trace_cxl_endpoint_unregister_region(&cxlr->dev, "done");
 }
 
 static struct lock_class_key cxl_region_key;
@@ -4163,6 +4176,7 @@ int cxl_memdev_attach_region(struct cxl_memdev *cxlmd)
 
 	/* Only teardown regions that pass validation, ignore the rest */
 	get_device(&cxlr->dev);
+
 	rc = devm_add_action_or_reset(&endpoint->dev,
 				      endpoint_unregister_region, cxlr);
 	if (rc)
diff --git a/drivers/cxl/cxl_memdev_tracepoints.h b/drivers/cxl/cxl_memdev_tracepoints.h
new file mode 100644
index 000000000000..6e8206cf178a
--- /dev/null
+++ b/drivers/cxl/cxl_memdev_tracepoints.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/****************************************************************************
+ * Tracepoints for CXL subsystem
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, incorporated herein by reference.
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cxl_unwinding
+
+#include <linux/tracepoint.h>
+#include "cxlmem.h"
+
+TRACE_EVENT(cxl_memdev_release,
+	    TP_PROTO(struct cxl_memdev *cxlmd, char *action),
+	    TP_ARGS(cxlmd, action),
+	    TP_STRUCT__entry(__string(devname, cxlmd->dev.kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxl_memdev_unregister,
+	    TP_PROTO(struct cxl_memdev *cxlmd, char *action),
+	    TP_ARGS(cxlmd, action),
+	    TP_STRUCT__entry(__string(devname, cxlmd->dev.kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxl_memdev_detach,
+	    TP_PROTO(struct cxl_memdev *cxlmd, char *action),
+	    TP_ARGS(cxlmd, action),
+	    TP_STRUCT__entry(__string(devname, cxlmd->dev.kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE cxl_memdev_tracepoints
+
+#include <trace/define_trace.h>
diff --git a/drivers/cxl/cxl_port_tracepoints.h b/drivers/cxl/cxl_port_tracepoints.h
new file mode 100644
index 000000000000..faefa418d968
--- /dev/null
+++ b/drivers/cxl/cxl_port_tracepoints.h
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/****************************************************************************
+ * Tracepoints for CXL subsystem
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, incorporated herein by reference.
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cxl_unwinding
+
+#include <linux/tracepoint.h>
+#include "cxlmem.h"
+
+TRACE_EVENT(schedule_cxl_memdev_detach,
+	    TP_PROTO(struct cxl_memdev *cxlmd),
+	    TP_ARGS(cxlmd),
+	    TP_STRUCT__entry(__string(devname, cxlmd->dev.kobj.name)),
+	    TP_fast_assign(__assign_str(devname);
+	    ),
+	    TP_printk("%s", __get_str(devname))
+);
+
+TRACE_EVENT(cxl_detach_ep,
+	    TP_PROTO(struct device *ep, char *action),
+	    TP_ARGS(ep, action),
+	    TP_STRUCT__entry(__string(devname, ep->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxl_ep_release,
+	    TP_PROTO(struct device *ep, char *action),
+	    TP_ARGS(ep, action),
+	    TP_STRUCT__entry(__string(devname, ep->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxl_port_release,
+	    TP_PROTO(struct device *dev, char *action),
+	    TP_ARGS(dev, action),
+	    TP_STRUCT__entry(__string(devname, dev->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxl_delete_endpoint,
+	    TP_PROTO(struct device *dev, char *action),
+	    TP_ARGS(dev, action),
+	    TP_STRUCT__entry(__string(devname, dev->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxld_unregister,
+	    TP_PROTO(struct device *dev, char *action),
+	    TP_ARGS(dev, action),
+	    TP_STRUCT__entry(__string(devname, dev->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE cxl_port_tracepoints
+
+#include <trace/define_trace.h>
diff --git a/drivers/cxl/cxl_region_tracepoints.h b/drivers/cxl/cxl_region_tracepoints.h
new file mode 100644
index 000000000000..977eb45b6aad
--- /dev/null
+++ b/drivers/cxl/cxl_region_tracepoints.h
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/****************************************************************************
+ * Tracepoints for CXL subsystem
+ * Copyright 2026 Advanced Micro Devices, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, incorporated herein by reference.
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cxl_unwinding
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(cxl_decoder_detach,
+	    TP_PROTO(struct device *dev, char *action),
+	    TP_ARGS(dev, action),
+	    TP_STRUCT__entry(__string(devname, dev->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxl_decoder_detach_release_driver,
+	    TP_PROTO(struct device *ep),
+	    TP_ARGS(ep),
+	    TP_STRUCT__entry(__string(devname, ep->kobj.name)),
+	    TP_fast_assign(__assign_str(devname);
+	    ),
+	    TP_printk("%s", __get_str(devname))
+);
+
+TRACE_EVENT(cxl_region_release,
+	    TP_PROTO(struct device *dev, char *action),
+	    TP_ARGS(dev, action),
+	    TP_STRUCT__entry(__string(devname, dev->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxl_unregister_region,
+	    TP_PROTO(struct device *dev, char *action),
+	    TP_ARGS(dev, action),
+	    TP_STRUCT__entry(__string(devname, dev->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+TRACE_EVENT(cxl_endpoint_unregister_region,
+	    TP_PROTO(struct device *dev, char *action),
+	    TP_ARGS(dev, action),
+	    TP_STRUCT__entry(__string(devname, dev->kobj.name)
+			     __string(action, action)
+	    ),
+	    TP_fast_assign(__assign_str(devname);
+			   __assign_str(action);
+	    ),
+	    TP_printk("%s, %s", __get_str(devname), __get_str(action))
+);
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE cxl_region_tracepoints
+
+#include <trace/define_trace.h>
-- 
2.34.1


  reply	other threads:[~2026-11-18 17:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 19:14 [RFC 0/3] Type2 unwinding ordering change alucerop
2026-11-18 19:14 ` alucerop [this message]
2026-11-18 18:00   ` [RFC 1/3] cxl: add tracepoints to the unwinding code path sashiko-bot
2026-11-18 19:14 ` [RFC 2/3] cxl: make explicit removal of endpoint and decoder for Type2 alucerop
2026-11-18 18:09   ` sashiko-bot
2026-11-18 19:14 ` [RFC 3/3] Documentation/cxl: add document about Type2 binding and unbinding alucerop
2026-11-18 18:04   ` sashiko-bot
2026-11-18 23:39 ` [RFC 0/3] Type2 unwinding ordering change Dave Jiang
2026-11-19  8:13   ` Lucero Palau, Alejandro
2026-11-19 10:00   ` Lucero Palau, Alejandro
2026-11-20 15:17     ` Lucero Palau, Alejandro

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=20261118191431.21781-2-alucerop@amd.com \
    --to=alucerop@amd.com \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=jic23@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=vishal.l.verma@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.