All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/xe/hwmon: Unregister hwmon before the device is unplugged
@ 2026-11-20 15:27 Rodrigo Vivi
  2026-11-20 15:37 ` ✓ CI.KUnit: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Rodrigo Vivi @ 2026-11-20 15:27 UTC (permalink / raw)
  To: intel-xe; +Cc: Rodrigo Vivi, Karthik Poosa, Michael J. Ruhl

hwmon was registered with devm, so its sysfs attributes stayed
reachable after drm_dev_unplug() until devres teardown. A reader in
that window accesses an unplugged device, e.g. the PMT energy read
on BMG.

Unregister it explicitly in xe_device_remove() and in the probe error
path, before the device is unplugged. Removing the attributes waits
for in-flight reads, so none can run afterwards.

Cc: Karthik Poosa <karthik.poosa@intel.com>
Cc: Michael J. Ruhl <michael.j.ruhl@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
 drivers/gpu/drm/xe/xe_device.c |  9 ++++++---
 drivers/gpu/drm/xe/xe_hwmon.c  | 22 +++++++++++++++++++---
 drivers/gpu/drm/xe/xe_hwmon.h  |  2 ++
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index f5a581d39c96..30863c988cca 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -1096,22 +1096,24 @@ int xe_device_probe(struct xe_device *xe)
 
 	err = xe_i2c_probe(xe);
 	if (err)
-		goto err_unregister_display;
+		goto err_unregister_hwmon;
 
 	xe_vsec_init(xe);
 
 	err = xe_sriov_init_late(xe);
 	if (err)
-		goto err_unregister_display;
+		goto err_unregister_hwmon;
 
 	detect_preproduction_hw(xe);
 
 	err = devm_add_action_or_reset(xe->drm.dev, xe_device_sanitize, xe);
 	if (err)
-		goto err_unregister_display;
+		goto err_unregister_hwmon;
 
 	return 0;
 
+err_unregister_hwmon:
+	xe_hwmon_unregister(xe);
 err_unregister_display:
 	xe_display_unregister(xe);
 	drm_dev_unregister(&xe->drm);
@@ -1121,6 +1123,7 @@ int xe_device_probe(struct xe_device *xe)
 
 void xe_device_remove(struct xe_device *xe)
 {
+	xe_hwmon_unregister(xe);
 	xe_display_unregister(xe);
 
 	drm_dev_unplug(&xe->drm);
diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
index defe8aaca7c1..9cbb65891aa4 100644
--- a/drivers/gpu/drm/xe/xe_hwmon.c
+++ b/drivers/gpu/drm/xe/xe_hwmon.c
@@ -1900,9 +1900,9 @@ int xe_hwmon_register(struct xe_device *xe)
 	drm_dbg(&xe->drm, "Register xe hwmon interface\n");
 
 	/*  hwmon_dev points to device hwmon<i> */
-	hwmon->hwmon_dev = devm_hwmon_device_register_with_info(dev, "xe", hwmon,
-								&hwmon_chip_info,
-								hwmon_groups);
+	hwmon->hwmon_dev = hwmon_device_register_with_info(dev, "xe", hwmon,
+							   &hwmon_chip_info,
+							   hwmon_groups);
 	if (IS_ERR(hwmon->hwmon_dev)) {
 		ret = PTR_ERR(hwmon->hwmon_dev);
 		xe_log_err(xe, HWMON, ret, "Failed to register xe hwmon\n");
@@ -1915,4 +1915,20 @@ int xe_hwmon_register(struct xe_device *xe)
 	xe->hwmon = NULL;
 	return ret;
 }
+
+/**
+ * xe_hwmon_unregister - Remove the hwmon interface
+ * @xe: xe device
+ *
+ * Called before the device is unplugged, so that no hwmon attribute can
+ * be accessed afterwards.
+ */
+void xe_hwmon_unregister(struct xe_device *xe)
+{
+	if (!xe->hwmon)
+		return;
+
+	hwmon_device_unregister(xe->hwmon->hwmon_dev);
+	xe->hwmon = NULL;
+}
 MODULE_IMPORT_NS("INTEL_PMT_TELEMETRY");
diff --git a/drivers/gpu/drm/xe/xe_hwmon.h b/drivers/gpu/drm/xe/xe_hwmon.h
index d02c1bfe8c0a..e67e0134f02a 100644
--- a/drivers/gpu/drm/xe/xe_hwmon.h
+++ b/drivers/gpu/drm/xe/xe_hwmon.h
@@ -12,8 +12,10 @@ struct xe_device;
 
 #if IS_REACHABLE(CONFIG_HWMON)
 int xe_hwmon_register(struct xe_device *xe);
+void xe_hwmon_unregister(struct xe_device *xe);
 #else
 static inline int xe_hwmon_register(struct xe_device *xe) { return 0; };
+static inline void xe_hwmon_unregister(struct xe_device *xe) { }
 #endif
 
 #endif /* _XE_HWMON_H_ */
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-20 16:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 15:27 [PATCH] drm/xe/hwmon: Unregister hwmon before the device is unplugged Rodrigo Vivi
2026-11-20 15:37 ` ✓ CI.KUnit: success for " Patchwork
2026-11-20 15:38 ` [PATCH] " sashiko-bot
2026-11-20 16:10 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-11-20 16:25 ` [PATCH] " Ruhl, Michael J

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.