Skip to contentSkip to conversation

firmware: arm_scmi: Ensure automatic module loading

PATCH In review Bjorn Andersson 8 participants 18 messages Jun 18 – Aug 24

Subsystems (15)
lore
Share & tools
lore
#0 lore raw

v2 cover firmware: arm_scmi: Ensure automatic module loading

SCMI drivers such as the Arm SCMI CPUfreq driver are allowed to built as modules, but they are then not automatically loaded. Rework the SCMI device table alias support to make modpost consume the information from MODULE_DEVICE_TABLE(scmi, ...) and allow drivers to be loaded based on this information, if known. Also add a protocol-based alias to also trigger driver loading when only the SCMI protocol id is known.

---
Changes in v2:
- Use request_module_nowait()
- Drop #include <linux/mod_devicetable.h> from scmi_protocol.h
- Link to v1: https://patch.msgid.link/[email protected]

To: Sudeep Holla <[email protected]>
To: Cristian Marussi <[email protected]>
To: Michael Turquette <[email protected]>
To: Nicolas Schier <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: Brian Masney <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: Frank Li <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: Jyoti Bhayana <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: David Lechner <[email protected]>
Cc: Nuno Sá <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
Cc: Ulf Hansson <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Philipp Zabel <[email protected]>
Cc: Alexandre Belloni <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Bjorn Andersson (2):
module: add SCMI device table alias support
firmware: arm_scmi: request modules for discovered protocols

 drivers/clk/clk-scmi.c                         |  1 +
 drivers/cpufreq/scmi-cpufreq.c                 |  1 +
 drivers/firmware/arm_scmi/bus.c                | 20 ++++++++++----------
 drivers/firmware/arm_scmi/driver.c             |  3 +++
 drivers/firmware/arm_scmi/scmi_power_control.c |  1 +
 drivers/firmware/imx/sm-cpu.c                  |  1 +
 drivers/firmware/imx/sm-lmm.c                  |  1 +
 drivers/firmware/imx/sm-misc.c                 |  1 +
 drivers/hwmon/scmi-hwmon.c                     |  1 +
 drivers/iio/common/scmi_sensors/scmi_iio.c     |  1 +
 drivers/input/keyboard/imx-sm-bbm-key.c        |  1 +
 drivers/pmdomain/arm/scmi_perf_domain.c        |  1 +
 drivers/pmdomain/arm/scmi_pm_domain.c          |  1 +
 drivers/powercap/arm_scmi_powercap.c           |  1 +
 drivers/regulator/scmi-regulator.c             |  1 +
 drivers/reset/reset-scmi.c                     |  1 +
 drivers/rtc/rtc-imx-sm-bbm.c                   |  1 +
 include/linux/mod_devicetable.h                | 12 ++++++++++++
 include/linux/scmi_protocol.h                  |  5 +----
 scripts/mod/devicetable-offsets.c              |  4 ++++
 scripts/mod/file2alias.c                       | 13 +++++++++++++
 21 files changed, 58 insertions(+), 14 deletions(-)

---
base-commit: 8d6dbbbe3ba62de0a63e962ee004afb848c8e3ac
change-id: 20260616-scmi-modalias-0f32421bd452

Best regards,

Signature · 1 line
Bjorn Andersson <[email protected]>
#1 lore raw

PATCH v2 1/2 module: add SCMI device table alias support

SCMI client drivers already describe their bus match data with MODULE_DEVICE_TABLE(scmi, ...), but modpost does not know how to consume SCMI device tables. As a result, SCMI modules do not get generated module aliases from their id tables.

Move struct scmi_device_id to mod_devicetable.h so it has a fixed layout visible to modpost, add the corresponding generated offsets and teach file2alias to emit scmi:<protocol>:<name> aliases.

Use the same stable alias format for SCMI device uevents and sysfs modaliases. The previous string included the instance-specific device name, which is not useful for matching modules.

Assisted-by Codex:GPT-5.5
---
 drivers/clk/clk-scmi.c                         |  1 +
 drivers/cpufreq/scmi-cpufreq.c                 |  1 +
 drivers/firmware/arm_scmi/bus.c                | 20 ++++++++++----------
 drivers/firmware/arm_scmi/driver.c             |  1 +
 drivers/firmware/arm_scmi/scmi_power_control.c |  1 +
 drivers/firmware/imx/sm-cpu.c                  |  1 +
 drivers/firmware/imx/sm-lmm.c                  |  1 +
 drivers/firmware/imx/sm-misc.c                 |  1 +
 drivers/hwmon/scmi-hwmon.c                     |  1 +
 drivers/iio/common/scmi_sensors/scmi_iio.c     |  1 +
 drivers/input/keyboard/imx-sm-bbm-key.c        |  1 +
 drivers/pmdomain/arm/scmi_perf_domain.c        |  1 +
 drivers/pmdomain/arm/scmi_pm_domain.c          |  1 +
 drivers/powercap/arm_scmi_powercap.c           |  1 +
 drivers/regulator/scmi-regulator.c             |  1 +
 drivers/reset/reset-scmi.c                     |  1 +
 drivers/rtc/rtc-imx-sm-bbm.c                   |  1 +
 include/linux/mod_devicetable.h                | 11 +++++++++++
 include/linux/scmi_protocol.h                  |  5 +----
 scripts/mod/devicetable-offsets.c              |  4 ++++
 scripts/mod/file2alias.c                       | 11 +++++++++++
 21 files changed, 53 insertions(+), 14 deletions(-)
drivers/clk/clk-scmi.c +1 -0
index 7c562559ad8b..b9e29e124302 100644
@@ -11,6 +11,7 @@
 #include <linux/err.h>
 #include <linux/of.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/scmi_protocol.h>
 
 #define NOT_ATOMIC	false
drivers/cpufreq/scmi-cpufreq.c +1 -0
index 4edb4f7a8aa9..affa005bf8b1 100644
@@ -15,6 +15,7 @@
 #include <linux/energy_model.h>
 #include <linux/export.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/pm_opp.h>
 #include <linux/pm_qos.h>
drivers/firmware/arm_scmi/bus.c +10 -10
index 793be9eabaed..70781146fa61 100644
@@ -10,14 +10,16 @@
 #include <linux/atomic.h>
 #include <linux/types.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/device.h>
 
 #include "common.h"
 
-#define SCMI_UEVENT_MODALIAS_FMT	"%s:%02x:%s"
+#define SCMI_UEVENT_MODALIAS_FMT	SCMI_MODULE_PREFIX "%02x:%s"
 
 BLOCKING_NOTIFIER_HEAD(scmi_requested_devices_nh);
 EXPORT_SYMBOL_GPL(scmi_requested_devices_nh);
@@ -141,7 +143,7 @@ static int scmi_protocol_table_register(const struct scmi_device_id *id_table)
 	int ret = 0;
 	const struct scmi_device_id *entry;
 
-	for (entry = id_table; entry->name && ret == 0; entry++)
+	for (entry = id_table; entry->name[0] && ret == 0; entry++)
 		ret = scmi_protocol_device_request(entry);
 
 	return ret;
@@ -197,18 +199,18 @@ scmi_protocol_table_unregister(const struct scmi_device_id *id_table)
 {
 	const struct scmi_device_id *entry;
 
-	for (entry = id_table; entry->name; entry++)
+	for (entry = id_table; entry->name[0]; entry++)
 		scmi_protocol_device_unrequest(entry);
 }
 
 static int scmi_dev_match_by_id_table(struct scmi_device *scmi_dev,
 				      const struct scmi_device_id *id_table)
 {
-	if (!id_table || !id_table->name)
+	if (!id_table || !id_table->name[0])
 		return 0;
 
 	/* Always skip transport devices from matching */
-	for (; id_table->protocol_id && id_table->name; id_table++)
+	for (; id_table->protocol_id && id_table->name[0]; id_table++)
 		if (id_table->protocol_id == scmi_dev->protocol_id &&
 		    strncmp(scmi_dev->name, "__scmi_transport_device", 23) &&
 		    !strcmp(id_table->name, scmi_dev->name))
@@ -245,7 +247,7 @@ static struct scmi_device *scmi_child_dev_find(struct device *parent,
 	struct device *dev;
 
 	id_table[0].protocol_id = prot_id;
-	id_table[0].name = name;
+	strscpy(id_table[0].name, name, sizeof(id_table[0].name));
 
 	dev = device_find_child(parent, &id_table, scmi_match_by_id_table);
 	if (!dev)
@@ -282,8 +284,7 @@ static int scmi_device_uevent(const struct device *dev, struct kobj_uevent_env *
 	const struct scmi_device *scmi_dev = to_scmi_dev(dev);
 
 	return add_uevent_var(env, "MODALIAS=" SCMI_UEVENT_MODALIAS_FMT,
-			      dev_name(&scmi_dev->dev), scmi_dev->protocol_id,
-			      scmi_dev->name);
+			      scmi_dev->protocol_id, scmi_dev->name);
 }
 
 static ssize_t modalias_show(struct device *dev,
@@ -292,8 +293,7 @@ static ssize_t modalias_show(struct device *dev,
 	struct scmi_device *scmi_dev = to_scmi_dev(dev);
 
 	return sysfs_emit(buf, SCMI_UEVENT_MODALIAS_FMT,
-			  dev_name(&scmi_dev->dev), scmi_dev->protocol_id,
-			  scmi_dev->name);
+			  scmi_dev->protocol_id, scmi_dev->name);
 }
 static DEVICE_ATTR_RO(modalias);
 
drivers/firmware/arm_scmi/driver.c +1 -0
index 3e0d975ec94c..0fd6a947499e 100644
@@ -30,6 +30,7 @@
 #include <linux/hashtable.h>
 #include <linux/list.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/processor.h>
drivers/firmware/arm_scmi/scmi_power_control.c +1 -0
index 955736336061..1900bb77383e 100644
@@ -45,6 +45,7 @@
 
 #include <linux/math.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
 #include <linux/pm.h>
 #include <linux/printk.h>
drivers/firmware/imx/sm-cpu.c +1 -0
index 091b014f739f..53a8d1cee5ea 100644
@@ -5,6 +5,7 @@
 
 #include <linux/firmware/imx/sm.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/scmi_protocol.h>
drivers/firmware/imx/sm-lmm.c +1 -0
index 6807bf563c03..f4dc198187a8 100644
@@ -5,6 +5,7 @@
 
 #include <linux/firmware/imx/sm.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/scmi_protocol.h>
drivers/firmware/imx/sm-misc.c +1 -0
index ac9af824c2d4..5e39e79a9d8a 100644
@@ -7,6 +7,7 @@
 #include <linux/device/devres.h>
 #include <linux/firmware/imx/sm.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/scmi_protocol.h>
drivers/hwmon/scmi-hwmon.c +1 -0
index eec223d174c0..57b91e931c5d 100644
@@ -8,6 +8,7 @@
 
 #include <linux/hwmon.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/scmi_protocol.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
drivers/iio/common/scmi_sensors/scmi_iio.c +1 -0
index 442b40ef27cf..3babc4261965 100644
@@ -15,6 +15,7 @@
 #include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
 #include <linux/scmi_protocol.h>
 #include <linux/time.h>
drivers/input/keyboard/imx-sm-bbm-key.c +1 -0
index 96486bd23d60..36e349136ee7 100644
@@ -6,6 +6,7 @@
 #include <linux/input.h>
 #include <linux/jiffies.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/rtc.h>
drivers/pmdomain/arm/scmi_perf_domain.c +1 -0
index 3693423459c9..741375ad325b 100644
@@ -8,6 +8,7 @@
 #include <linux/err.h>
 #include <linux/device.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_opp.h>
 #include <linux/scmi_protocol.h>
drivers/pmdomain/arm/scmi_pm_domain.c +1 -0
index 3d73aef21d2f..0948d05c9e3c 100644
@@ -8,6 +8,7 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/pm_domain.h>
 #include <linux/scmi_protocol.h>
 
drivers/powercap/arm_scmi_powercap.c +1 -0
index ab66e9a3b1e2..332e4e26f1e5 100644
@@ -10,6 +10,7 @@
 #include <linux/limits.h>
 #include <linux/list.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/powercap.h>
 #include <linux/scmi_protocol.h>
 #include <linux/slab.h>
drivers/regulator/scmi-regulator.c +1 -0
index c005e65ba0ec..f55f228cb133 100644
@@ -25,6 +25,7 @@
 
 #include <linux/linear_range.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
drivers/reset/reset-scmi.c +1 -0
index 4335811e0cfa..a6739df1d3c2 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/device.h>
 #include <linux/reset-controller.h>
drivers/rtc/rtc-imx-sm-bbm.c +1 -0
index daa472be7c80..c8643718cef1 100644
@@ -5,6 +5,7 @@
 
 #include <linux/jiffies.h>
 #include <linux/module.h>
+#include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
 #include <linux/rtc.h>
 #include <linux/scmi_protocol.h>
include/linux/mod_devicetable.h +11 -0
index 3b0c9a251a2e..769382f2eadd 100644
@@ -473,6 +473,17 @@ struct rpmsg_device_id {
 	kernel_ulong_t driver_data;
 };
 
+/* scmi */
+
+#define SCMI_NAME_SIZE		32
+#define SCMI_MODULE_PREFIX	"scmi:"
+
+struct scmi_device_id {
+	__u8 protocol_id;
+	char name[SCMI_NAME_SIZE];
+	kernel_ulong_t driver_data;
+};
+
 /* i2c */
 
 #define I2C_NAME_SIZE	20
include/linux/scmi_protocol.h +1 -4
index 5ab73b1ab9aa..61f5ecfe0133 100644
@@ -951,10 +951,7 @@ struct scmi_device {
 
 #define to_scmi_dev(d) container_of_const(d, struct scmi_device, dev)
 
-struct scmi_device_id {
-	u8 protocol_id;
-	const char *name;
-};
+struct scmi_device_id;
 
 struct scmi_driver {
 	const char *name;
scripts/mod/devicetable-offsets.c +4 -0
index b4178c42d08f..da5bd712c8da 100644
@@ -144,6 +144,10 @@ int main(void)
 	DEVID(rpmsg_device_id);
 	DEVID_FIELD(rpmsg_device_id, name);
 
+	DEVID(scmi_device_id);
+	DEVID_FIELD(scmi_device_id, protocol_id);
+	DEVID_FIELD(scmi_device_id, name);
+
 	DEVID(i2c_device_id);
 	DEVID_FIELD(i2c_device_id, name);
 
scripts/mod/file2alias.c +11 -0
index 8d36c74dec2d..a5283f4c8e6f 100644
@@ -852,6 +852,16 @@ static void do_rpmsg_entry(struct module *mod, void *symval)
 	module_alias_printf(mod, false, RPMSG_DEVICE_MODALIAS_FMT, *name);
 }
 
+/* Looks like: scmi:NN:S */
+static void do_scmi_entry(struct module *mod, void *symval)
+{
+	DEF_FIELD(symval, scmi_device_id, protocol_id);
+	DEF_FIELD_ADDR(symval, scmi_device_id, name);
+
+	module_alias_printf(mod, false, SCMI_MODULE_PREFIX "%02x:%s",
+			    protocol_id, *name);
+}
+
 /* Looks like: i2c:S */
 static void do_i2c_entry(struct module *mod, void *symval)
 {
@@ -1491,6 +1501,7 @@ static const struct devtable devtable[] = {
 	{"virtio", SIZE_virtio_device_id, do_virtio_entry},
 	{"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
 	{"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
+	{"scmi", SIZE_scmi_device_id, do_scmi_entry},
 	{"i2c", SIZE_i2c_device_id, do_i2c_entry},
 	{"i3c", SIZE_i3c_device_id, do_i3c_entry},
 	{"slim", SIZE_slim_device_id, do_slim_entry},
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2 1/2] module: add SCMI device table alias support

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Dropping scmi_requested_devices_mtx during list iteration in scmi_protocol_device_unrequest leads to Use-After-Free and double-free.
- [Critical] scmi_child_dev_find returning an unreferenced pointer causes a Use-After-Free if the device is concurrently unregistered.
- [High] If device_register fails in __scmi_device_create for the SCMI_PROTOCOL_SYSTEM protocol, the atomic flag scmi_syspower_registered is not reset, permanently preventing future registrations. --

commit 90162c8443181b14c6b5151402b556abe1a600f4
Author: Bjorn Andersson <[email protected]>

module: add SCMI device table alias support

SCMI client drivers already describe their bus match data with MODULE_DEVICE_TABLE(scmi, ...), but modpost does not know how to consume SCMI device tables. As a result, SCMI modules do not get generated module aliases from their id tables.

drivers/firmware/arm_scmi/bus.c

Quoted 4 lines
drivers/firmware/arm_scmi/bus.c +0 -0
index 793be9eabaedd..70781146fa613 100644

[Severity: High]
This isn't a bug introduced by this patch, but does the error path in __scmi_device_create() leak the atomic state for scmi_syspower_registered?

When device_register() fails for the SCMI_PROTOCOL_SYSTEM protocol, the code jumps to the put_dev error path:

put_dev:

	put_device(&scmi_dev->dev);
	ida_free(&scmi_bus_id, id);
	return NULL;

This path cleans up memory and the IDA, but it doesn't seem to reset the global scmi_syspower_registered atomic flag back to 0. Does this permanently block subsequent attempts to register the system power protocol until reboot?

[ ... ]

drivers/firmware/arm_scmi/bus.c scmi_protocol_table_unregister(const struct scmi_device_id *id_table) · line 203

Quoted 7 lines
drivers/firmware/arm_scmi/bus.c +1 -1
@@ -197,18 +199,18 @@ scmi_protocol_table_unregister(const struct scmi_device_id *id_table)
 {
 	const struct scmi_device_id *entry;
 
-	for (entry = id_table; entry->name; entry++)
+	for (entry = id_table; entry->name[0]; entry++)
 		scmi_protocol_device_unrequest(entry);

[Severity: Critical]
This is a pre-existing issue, but can the lock dropping in scmi_protocol_device_unrequest() lead to a use-after-free or double-free?

scmi_protocol_device_unrequest() drops the scmi_requested_devices_mtx lock during list iteration:

	mutex_lock(&scmi_requested_devices_mtx);
	phead = idr_find(&scmi_requested_devices, id_table->protocol_id);
	if (phead) {
		...
			if (!strcmp(victim->id_table->name, id_table->name)) {
				list_del(&victim->node);
				mutex_unlock(&scmi_requested_devices_mtx);
				...
				kfree(victim);
				mutex_lock(&scmi_requested_devices_mtx);
				break;
			}
		}

		if (list_empty(phead)) {
			idr_remove(&scmi_requested_devices,
				   id_table->protocol_id);
			kfree(phead);
		}
	}

If another thread concurrently removes an entry from the same phead list, sees the list is empty, and frees phead, wouldn't the original thread evaluate if (list_empty(phead)) with a freed pointer when it reacquires the lock and breaks the loop?

[ ... ]

drivers/firmware/arm_scmi/bus.c static struct scmi_device *scmi_child_dev_find(struct device *parent, · line 252

Quoted 8 lines
drivers/firmware/arm_scmi/bus.c +1 -1
@@ -245,7 +247,7 @@ static struct scmi_device *scmi_child_dev_find(struct device *parent,
 	struct device *dev;
 
 	id_table[0].protocol_id = prot_id;
-	id_table[0].name = name;
+	strscpy(id_table[0].name, name, sizeof(id_table[0].name));
 
 	dev = device_find_child(parent, &id_table, scmi_match_by_id_table);

[Severity: Critical]
This is a pre-existing issue, but does returning an unreferenced pointer here cause a use-after-free if the device is concurrently unregistered?

Right after the device_find_child() call above, the reference is dropped:

	if (!dev)
		return NULL;

	/* Drop the refcnt bumped implicitly by device_find_child */
	put_device(dev);

	return to_scmi_dev(dev);

device_find_child() increments the reference count of the device, but put_device() immediately drops it. The caller will receive a raw pointer without holding any locks or active references. Could the memory be freed out from under the caller before they use it?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] module: add SCMI device table alias support

In reply to Bjorn Andersson
Quoted 10 lines · Bjorn Andersson

SCMI client drivers already describe their bus match data with MODULE_DEVICE_TABLE(scmi, ...), but modpost does not know how to consume SCMI device tables. As a result, SCMI modules do not get generated module aliases from their id tables.

Move struct scmi_device_id to mod_devicetable.h so it has a fixed layout visible to modpost, add the corresponding generated offsets and teach file2alias to emit scmi:<protocol>:<name> aliases.

Quoted 8 lines

Use the same stable alias format for SCMI device uevents and sysfs modaliases. The previous string included the instance-specific device name, which is not useful for matching modules.

Assisted-by Codex:GPT-5.5

---

#4 lore raw

Re: [PATCH v2 1/2] module: add SCMI device table alias support

In reply to Bjorn Andersson

Hello,

Quoted 9 lines · Bjorn Andersson
include/linux/mod_devicetable.h +1 -0
index 3b0c9a251a2e..769382f2eadd 100644
@@ -473,6 +473,17 @@ struct rpmsg_device_id {
 	kernel_ulong_t driver_data;
 };
 
+/* scmi */

include/linux/mod_devicetable.h struct rpmsg_device_id { · line 486

Quoted 10 lines
include/linux/mod_devicetable.h +10 -0
+
+#define SCMI_NAME_SIZE		32
+#define SCMI_MODULE_PREFIX	"scmi:"
+
+struct scmi_device_id {
+	__u8 protocol_id;
+	char name[SCMI_NAME_SIZE];
+	kernel_ulong_t driver_data;
+};
+

Note this won't apply since commit ad428f5811bd ("mod_devicetable.h:
Split into per subsystem headers"). Please create a header below include/device-id for scmi similar to what was done in ad428f5811bd. (And don't add an #include for it to mod_devicetable.h, but to the modpost program only.)

Also please only add a driver_data member if you need it. And if you do, consider using

	union {
		kernel_ulong_t driver_data;
		const void *driver_data_ptr;
	};

instead of a plain kernel_ulong_t driver_data member. I'm working (less than part-time) on changing the existing device-id members accordingly.

See e.g.
https://lore.kernel.org/all/[email protected]
for an extended rationale.

Best regards
Uwe

#5 lore raw

PATCH v2 2/2 firmware: arm_scmi: request modules for discovered protocols

In reply to Bjorn Andersson

SCMI client devices are created from SCMI driver id tables. If such a driver is modular, the core does not know the driver's client name until the module has already loaded, so normal device uevent based autoloading cannot break the dependency cycle.

Emit a protocol-level alias for each SCMI device id table entry and request that alias when the SCMI core discovers an implemented protocol. This loads modules that have registered interest in the protocol; their normal SCMI driver registration then requests the concrete client device and the SCMI bus matches it by protocol and name.

This allows e.g. ARM_SCMI_CPUFREQ=m to autoload on systems that expose only the SCMI Performance protocol node, where the cpufreq client name is Linux-internal and not available from firmware before loading the module.

Assisted-by Codex:GPT-5.5
---
 drivers/firmware/arm_scmi/driver.c | 2 ++
 include/linux/mod_devicetable.h    | 1 +
 scripts/mod/file2alias.c           | 4 +++-
 3 files changed, 6 insertions(+), 1 deletion(-)
drivers/firmware/arm_scmi/driver.c +2 -0
index 0fd6a947499e..7d33fab94e28 100644
@@ -48,6 +48,7 @@
 #include <trace/events/scmi.h>
 
 #define SCMI_VENDOR_MODULE_ALIAS_FMT	"scmi-protocol-0x%02x-%s"
+#define SCMI_MODULE_ALIAS_FMT		SCMI_PROTOCOL_MODULE_PREFIX "0x%02x"
 
 static DEFINE_IDA(scmi_id);
 
@@ -3363,6 +3364,7 @@ static int scmi_probe(struct platform_device *pdev)
 		}
 
 		of_node_get(child);
+		request_module_nowait(SCMI_MODULE_ALIAS_FMT, prot_id);
 		scmi_create_protocol_devices(child, info, prot_id, NULL);
 	}
 
include/linux/mod_devicetable.h +1 -0
index 769382f2eadd..2cc7e78e35a3 100644
@@ -477,6 +477,7 @@ struct rpmsg_device_id {
 
 #define SCMI_NAME_SIZE		32
 #define SCMI_MODULE_PREFIX	"scmi:"
+#define SCMI_PROTOCOL_MODULE_PREFIX	"scmi-protocol-"
 
 struct scmi_device_id {
 	__u8 protocol_id;
scripts/mod/file2alias.c +3 -1
index a5283f4c8e6f..40a37b6bf1ad 100644
@@ -852,7 +852,7 @@ static void do_rpmsg_entry(struct module *mod, void *symval)
 	module_alias_printf(mod, false, RPMSG_DEVICE_MODALIAS_FMT, *name);
 }
 
-/* Looks like: scmi:NN:S */
+/* Looks like: scmi:NN:S and scmi-protocol-0xNN */
 static void do_scmi_entry(struct module *mod, void *symval)
 {
 	DEF_FIELD(symval, scmi_device_id, protocol_id);
@@ -860,6 +860,8 @@ static void do_scmi_entry(struct module *mod, void *symval)
 
 	module_alias_printf(mod, false, SCMI_MODULE_PREFIX "%02x:%s",
 			    protocol_id, *name);
+	module_alias_printf(mod, false, SCMI_PROTOCOL_MODULE_PREFIX "0x%02x",
+			    protocol_id);
 }
 
 /* Looks like: i2c:S */
Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH v2 2/2] firmware: arm_scmi: request modules for discovered protocols

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-After-Free in scmi_protocol_device_unrequest during concurrent driver unregistration.
- [High] IDA and SystemPower protocol state leak when the SCMI platform device is unbound. --

commit 55b65f66dfc5c3002d324389dda6dc66790201cc
Author: Bjorn Andersson <[email protected]>

firmware: arm_scmi: request modules for discovered protocols

This commit enables autoloading for scmi driver modules by emitting a protocol-level alias for scmi device ID table entries. It requests the alias when discovering implemented protocols so that driver modules can be loaded before the concrete client name is available.

drivers/firmware/arm_scmi/driver.c

Quoted 4 lines
drivers/firmware/arm_scmi/driver.c +0 -0
index 0fd6a947499e7..7d33fab94e281 100644

[ ... ]

[Severity: High]
This is a pre-existing issue, but can concurrent driver unregistration lead to a use-after-free in drivers/firmware/arm_scmi/bus.c?

Looking at scmi_protocol_device_unrequest(), it drops the scmi_requested_devices_mtx lock to call blocking_notifier_call_chain().

If two threads execute concurrent module unloads for different scmi drivers on the same protocol:

Thread 1 completes the notifier, re-acquires the lock, and frees phead:

    if (list_empty(phead)) {
        idr_remove(&scmi_requested_devices, id_table->protocol_id);
        kfree(phead);
    }

Would Thread 2 then evaluate list_empty(phead) using the just-freed phead pointer when it finishes its own notifier and re-acquires the lock?

[Severity: High]
This isn't a bug introduced by this patch, but does the scmi platform device unbinding leak the scmi_bus_id ida and system power protocol state?

When scmi_remove() calls scmi_destroy_protocol_devices() with a NULL name, it eventually reaches scmi_child_dev_find() in drivers/firmware/arm_scmi/bus.c:

    strscpy(id_table[0].name, name, sizeof(id_table[0].name));

Since strscpy() does not accept a NULL source pointer, doesn't this trigger a warning and leave the target name empty?

If this empty name causes scmi_dev_match_by_id_table() to fail, the device won't be found and the manual cleanup in __scmi_device_destroy() is bypassed.

The device core will then automatically unregister the child devices using:

    static void scmi_device_release(struct device *dev)
    {
        struct scmi_device *scmi_dev = to_scmi_dev(dev);

        kfree_const(scmi_dev->name);
        kfree(scmi_dev);
    }

Since this release callback skips explicit ida and state cleanup, does this permanently prevent the system power protocol device from being recreated if the driver is rebound?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw
In reply to Bjorn Andersson

Hi,

Quoted 8 lines · Bjorn Andersson

SCMI drivers such as the Arm SCMI CPUfreq driver are allowed to built as modules, but they are then not automatically loaded. Rework the SCMI device table alias support to make modpost consume the information from MODULE_DEVICE_TABLE(scmi, ...) and allow drivers to be loaded based on this information, if known. Also add a protocol-based alias to also trigger driver loading when only the SCMI protocol id is known.

So I just gave this a test spin and unfortunately it does not work.

The problem with Fedora's kernel-config / setup is that the request_module() from patch 2/2 runs from the initramfs, but the scmi_cpufreq module is only available in the rootfs.

It does work if I explictly add the scmi_cpufreq module to the initramfs, then it does get autoloaded.

We really need some place to put a uevent sysfs attr which then gets replayed when udev is restarted from the rootfs and then re-reads all the uevent files as part of its coldplug enumeration.

I wonder if it is ok for a single uevent file to have multiple MODALIAS= lines in there.

Regards,

Hans

Quoted 79 lines

---
Changes in v2:
- Use request_module_nowait()
- Drop #include <linux/mod_devicetable.h> from scmi_protocol.h
- Link to v1: https://patch.msgid.link/[email protected]

To: Sudeep Holla <[email protected]>
To: Cristian Marussi <[email protected]>
To: Michael Turquette <[email protected]>
To: Nicolas Schier <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: Brian Masney <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: Frank Li <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: Jyoti Bhayana <[email protected]>
Cc: Jonathan Cameron <[email protected]>
Cc: David Lechner <[email protected]>
Cc: Nuno Sá <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
Cc: Ulf Hansson <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Philipp Zabel <[email protected]>
Cc: Alexandre Belloni <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Bjorn Andersson (2):
module: add SCMI device table alias support
firmware: arm_scmi: request modules for discovered protocols

 drivers/clk/clk-scmi.c                         |  1 +
 drivers/cpufreq/scmi-cpufreq.c                 |  1 +
 drivers/firmware/arm_scmi/bus.c                | 20 ++++++++++----------
 drivers/firmware/arm_scmi/driver.c             |  3 +++
 drivers/firmware/arm_scmi/scmi_power_control.c |  1 +
 drivers/firmware/imx/sm-cpu.c                  |  1 +
 drivers/firmware/imx/sm-lmm.c                  |  1 +
 drivers/firmware/imx/sm-misc.c                 |  1 +
 drivers/hwmon/scmi-hwmon.c                     |  1 +
 drivers/iio/common/scmi_sensors/scmi_iio.c     |  1 +
 drivers/input/keyboard/imx-sm-bbm-key.c        |  1 +
 drivers/pmdomain/arm/scmi_perf_domain.c        |  1 +
 drivers/pmdomain/arm/scmi_pm_domain.c          |  1 +
 drivers/powercap/arm_scmi_powercap.c           |  1 +
 drivers/regulator/scmi-regulator.c             |  1 +
 drivers/reset/reset-scmi.c                     |  1 +
 drivers/rtc/rtc-imx-sm-bbm.c                   |  1 +
 include/linux/mod_devicetable.h                | 12 ++++++++++++
 include/linux/scmi_protocol.h                  |  5 +----
 scripts/mod/devicetable-offsets.c              |  4 ++++
 scripts/mod/file2alias.c                       | 13 +++++++++++++
 21 files changed, 58 insertions(+), 14 deletions(-)

---
base-commit: 8d6dbbbe3ba62de0a63e962ee004afb848c8e3ac
change-id: 20260616-scmi-modalias-0f32421bd452

Best regards,

Signature · 1 line
Bjorn Andersson <[email protected]>
maintainer
#8 lore raw
Quoted 18 lines · Hans de Goede

Hi,

Quoted 8 lines · Bjorn Andersson

SCMI drivers such as the Arm SCMI CPUfreq driver are allowed to built as modules, but they are then not automatically loaded. Rework the SCMI device table alias support to make modpost consume the information from MODULE_DEVICE_TABLE(scmi, ...) and allow drivers to be loaded based on this information, if known. Also add a protocol-based alias to also trigger driver loading when only the SCMI protocol id is known.

So I just gave this a test spin and unfortunately it does not work.

The problem with Fedora's kernel-config / setup is that the request_module() from patch 2/2 runs from the initramfs, but the scmi_cpufreq module is only available in the rootfs.

Quoted 8 lines

It does work if I explictly add the scmi_cpufreq module to the initramfs, then it does get autoloaded.

We really need some place to put a uevent sysfs attr which then gets replayed when udev is restarted from the rootfs and then re-reads all the uevent files as part of its coldplug enumeration.

I don't have much knowledge on uevent to provide any suggestions/help. But isn't this a generic requirement ? I mean you could have modules install on the rootfs and not all of them are packed in initramfs ? Just wondering if that works for other modules, we can examine how do they work and what are we missing ?

Signature · 2 lines
Regards,
Sudeep
#9 lore raw

Hi,

Quoted 28 lines · Sudeep Holla
Quoted 18 lines · Hans de Goede

Hi,

Quoted 8 lines · Bjorn Andersson

SCMI drivers such as the Arm SCMI CPUfreq driver are allowed to built as modules, but they are then not automatically loaded. Rework the SCMI device table alias support to make modpost consume the information from MODULE_DEVICE_TABLE(scmi, ...) and allow drivers to be loaded based on this information, if known. Also add a protocol-based alias to also trigger driver loading when only the SCMI protocol id is known.

So I just gave this a test spin and unfortunately it does not work.

The problem with Fedora's kernel-config / setup is that the request_module() from patch 2/2 runs from the initramfs, but the scmi_cpufreq module is only available in the rootfs.

Quoted 8 lines

It does work if I explictly add the scmi_cpufreq module to the initramfs, then it does get autoloaded.

We really need some place to put a uevent sysfs attr which then gets replayed when udev is restarted from the rootfs and then re-reads all the uevent files as part of its coldplug enumeration.

Quoted 5 lines

I don't have much knowledge on uevent to provide any suggestions/help. But isn't this a generic requirement ? I mean you could have modules install on the rootfs and not all of them are packed in initramfs ? Just wondering if that works for other modules, we can examine how do they work and what are we missing ?

scmi is special because the actual devices under /sys/bus/scmi/devices only get created when the module with the driver is loaded because of some funtion/id mapping requiring info from the driver.

Patch 2/2 tries to work around this by loading all scmi drivers matching the scmi protocol which is known at bus enumeration time, but this only works if the actual scmi driver is in the initramfs because this done through directly calling modprobe() from the kernel which does not get "replayed" when switching to the real rootfs.

And no /sys/bus/scmi/devices/xxx device means no /sys/bus/scmi/devices/xxx/modalias nor /sys/bus/scmi/devices/xxx/uevent which udev uses for coldplug (hotplug event replay) when switching to the real root.

The cleanest way to fix this from a how things are supposed to work according to the generic kernel device-model design is to get rid of the creation of the devices being delayed. Which may mean moving some static mapping tables from the driver into the scmi core. I'm not familiar enough with the scmi bus code to be sure.

Regards,

Hans

Quoted 1 line
#10 lore raw

Hi Hans,

Quoted 37 lines · Hans de Goede
Quoted 26 lines · Sudeep Holla
Quoted 16 lines · Hans de Goede
Quoted 8 lines · Bjorn Andersson

SCMI drivers such as the Arm SCMI CPUfreq driver are allowed to built as modules, but they are then not automatically loaded. Rework the SCMI device table alias support to make modpost consume the information from MODULE_DEVICE_TABLE(scmi, ...) and allow drivers to be loaded based on this information, if known. Also add a protocol-based alias to also trigger driver loading when only the SCMI protocol id is known.

So I just gave this a test spin and unfortunately it does not work.

The problem with Fedora's kernel-config / setup is that the request_module() from patch 2/2 runs from the initramfs, but the scmi_cpufreq module is only available in the rootfs.

Quoted 8 lines

It does work if I explictly add the scmi_cpufreq module to the initramfs, then it does get autoloaded.

We really need some place to put a uevent sysfs attr which then gets replayed when udev is restarted from the rootfs and then re-reads all the uevent files as part of its coldplug enumeration.

Quoted 5 lines

I don't have much knowledge on uevent to provide any suggestions/help. But isn't this a generic requirement ? I mean you could have modules install on the rootfs and not all of them are packed in initramfs ? Just wondering if that works for other modules, we can examine how do they work and what are we missing ?

scmi is special because the actual devices under /sys/bus/scmi/devices only get created when the module with the driver is loaded because of some funtion/id mapping requiring info from the driver.

Quoted 5 lines

Patch 2/2 tries to work around this by loading all scmi drivers matching the scmi protocol which is known at bus enumeration time, but this only works if the actual scmi driver is in the initramfs because this done through directly calling modprobe() from the kernel which does not get "replayed" when switching to the real rootfs.

Should the SCMI drivers be added to the dracut module here?

https://github.com/dracut-ng/dracut/blob/main/modules.d/70kernel-modules/module-setup.sh#L73

A few years ago we had to add the interconnect drivers to the list for Fedora.

Brian

#11 lore raw

Hi Brian,

Quoted 46 lines · Brian Masney

Hi Hans,

Quoted 37 lines · Hans de Goede
Quoted 26 lines · Sudeep Holla
Quoted 16 lines · Hans de Goede
Quoted 8 lines · Bjorn Andersson

SCMI drivers such as the Arm SCMI CPUfreq driver are allowed to built as modules, but they are then not automatically loaded. Rework the SCMI device table alias support to make modpost consume the information from MODULE_DEVICE_TABLE(scmi, ...) and allow drivers to be loaded based on this information, if known. Also add a protocol-based alias to also trigger driver loading when only the SCMI protocol id is known.

So I just gave this a test spin and unfortunately it does not work.

The problem with Fedora's kernel-config / setup is that the request_module() from patch 2/2 runs from the initramfs, but the scmi_cpufreq module is only available in the rootfs.

Quoted 8 lines

It does work if I explictly add the scmi_cpufreq module to the initramfs, then it does get autoloaded.

We really need some place to put a uevent sysfs attr which then gets replayed when udev is restarted from the rootfs and then re-reads all the uevent files as part of its coldplug enumeration.

Quoted 5 lines

I don't have much knowledge on uevent to provide any suggestions/help. But isn't this a generic requirement ? I mean you could have modules install on the rootfs and not all of them are packed in initramfs ? Just wondering if that works for other modules, we can examine how do they work and what are we missing ?

scmi is special because the actual devices under /sys/bus/scmi/devices only get created when the module with the driver is loaded because of some funtion/id mapping requiring info from the driver.

Quoted 5 lines

Patch 2/2 tries to work around this by loading all scmi drivers matching the scmi protocol which is known at bus enumeration time, but this only works if the actual scmi driver is in the initramfs because this done through directly calling modprobe() from the kernel which does not get "replayed" when switching to the real rootfs.

Quoted 6 lines

Should the SCMI drivers be added to the dracut module here?

https://github.com/dracut-ng/dracut/blob/main/modules.d/70kernel-modules/module-setup.sh#L73

A few years ago we had to add the interconnect drivers to the list for Fedora.

That would be one solution. I first want to understand the problem better though. The scmi bus not creating the devices until the kmod with the driver has loaded is weird. I wonder if we can just move a small part of the drivers (some mapping table) into the bus code and then just have this work as it does on regular busses. I hope to be able to make some time to look into this soonish.

Regards,

Hans

maintainer
#12 lore raw
Quoted 51 lines · Hans de Goede

Hi Brian,

Quoted 48 lines · Brian Masney

Hi Hans,

Quoted 37 lines · Hans de Goede
Quoted 26 lines · Sudeep Holla
Quoted 16 lines · Hans de Goede
Quoted 8 lines · Bjorn Andersson

SCMI drivers such as the Arm SCMI CPUfreq driver are allowed to built as modules, but they are then not automatically loaded. Rework the SCMI device table alias support to make modpost consume the information from MODULE_DEVICE_TABLE(scmi, ...) and allow drivers to be loaded based on this information, if known. Also add a protocol-based alias to also trigger driver loading when only the SCMI protocol id is known.

So I just gave this a test spin and unfortunately it does not work.

The problem with Fedora's kernel-config / setup is that the request_module() from patch 2/2 runs from the initramfs, but the scmi_cpufreq module is only available in the rootfs.

Quoted 8 lines

It does work if I explictly add the scmi_cpufreq module to the initramfs, then it does get autoloaded.

We really need some place to put a uevent sysfs attr which then gets replayed when udev is restarted from the rootfs and then re-reads all the uevent files as part of its coldplug enumeration.

Quoted 5 lines

I don't have much knowledge on uevent to provide any suggestions/help. But isn't this a generic requirement ? I mean you could have modules install on the rootfs and not all of them are packed in initramfs ? Just wondering if that works for other modules, we can examine how do they work and what are we missing ?

scmi is special because the actual devices under /sys/bus/scmi/devices only get created when the module with the driver is loaded because of some funtion/id mapping requiring info from the driver.

Quoted 5 lines

Patch 2/2 tries to work around this by loading all scmi drivers matching the scmi protocol which is known at bus enumeration time, but this only works if the actual scmi driver is in the initramfs because this done through directly calling modprobe() from the kernel which does not get "replayed" when switching to the real rootfs.

Should the SCMI drivers be added to the dracut module here?

Quoted 8 lines
Quoted 4 lines

https://github.com/dracut-ng/dracut/blob/main/modules.d/70kernel-modules/module-setup.sh#L73

A few years ago we had to add the interconnect drivers to the list for Fedora.

That would be one solution. I first want to understand the problem better though. The scmi bus not creating the devices until the kmod with the driver has loaded is weird.

I need to recall why we moved from static list of devices to dynamic. One reason I can think right now is the vendor protocols and their drivers But in general it was an attempt to help multiple drivers bind to different scmi_devices that have same protocol ID. E.g. the performance protocol can be used by cpufreq and devfreq/performance genpd drivers.

Quoted 5 lines

I wonder if we can just move a small part of the drivers (some mapping table) into the bus code and then just have this work as it does on regular busses. I hope to be able to make some time to look into this soonish.

I started with that few years ago and we then moved to this dynamic device creation. But I agree if it is deviation from the norms(which I wasn't aware of at the time), we can remove it.

Signature · 2 lines
Regards,
Sudeep
#13 lore raw

Hi,

Quoted 61 lines · Sudeep Holla
Quoted 51 lines · Hans de Goede

Hi Brian,

Quoted 48 lines · Brian Masney

Hi Hans,

Quoted 37 lines · Hans de Goede
Quoted 26 lines · Sudeep Holla
Quoted 16 lines · Hans de Goede
Quoted 8 lines · Bjorn Andersson

SCMI drivers such as the Arm SCMI CPUfreq driver are allowed to built as modules, but they are then not automatically loaded. Rework the SCMI device table alias support to make modpost consume the information from MODULE_DEVICE_TABLE(scmi, ...) and allow drivers to be loaded based on this information, if known. Also add a protocol-based alias to also trigger driver loading when only the SCMI protocol id is known.

So I just gave this a test spin and unfortunately it does not work.

The problem with Fedora's kernel-config / setup is that the request_module() from patch 2/2 runs from the initramfs, but the scmi_cpufreq module is only available in the rootfs.

Quoted 8 lines

It does work if I explictly add the scmi_cpufreq module to the initramfs, then it does get autoloaded.

We really need some place to put a uevent sysfs attr which then gets replayed when udev is restarted from the rootfs and then re-reads all the uevent files as part of its coldplug enumeration.

Quoted 5 lines

I don't have much knowledge on uevent to provide any suggestions/help. But isn't this a generic requirement ? I mean you could have modules install on the rootfs and not all of them are packed in initramfs ? Just wondering if that works for other modules, we can examine how do they work and what are we missing ?

scmi is special because the actual devices under /sys/bus/scmi/devices only get created when the module with the driver is loaded because of some funtion/id mapping requiring info from the driver.

Quoted 5 lines

Patch 2/2 tries to work around this by loading all scmi drivers matching the scmi protocol which is known at bus enumeration time, but this only works if the actual scmi driver is in the initramfs because this done through directly calling modprobe() from the kernel which does not get "replayed" when switching to the real rootfs.

Should the SCMI drivers be added to the dracut module here?

Quoted 8 lines
Quoted 4 lines

https://github.com/dracut-ng/dracut/blob/main/modules.d/70kernel-modules/module-setup.sh#L73

A few years ago we had to add the interconnect drivers to the list for Fedora.

That would be one solution. I first want to understand the problem better though. The scmi bus not creating the devices until the kmod with the driver has loaded is weird.

Quoted 5 lines

I need to recall why we moved from static list of devices to dynamic. One reason I can think right now is the vendor protocols and their drivers But in general it was an attempt to help multiple drivers bind to different scmi_devices that have same protocol ID. E.g. the performance protocol can be used by cpufreq and devfreq/performance genpd drivers.

Note it is ok to have multiple drivers bind to the same modalias, depending on the reason why there are multiple drivers either one should detect that it is not compatible and exit probe() with -ENODEV or there should be some other mechanism to make sure only one driver loads.

E.g. duplicate USB device-ids happen (they shouldn't but they do) and then the drivers typically figure out if they are talking to the device which they were written for, or the other device with the same USB-ids and then one of the 2 drivers exits with -ENODEV.

Quoted 9 lines
Quoted 5 lines

I wonder if we can just move a small part of the drivers (some mapping table) into the bus code and then just have this work as it does on regular busses. I hope to be able to make some time to look into this soonish.

I started with that few years ago and we then moved to this dynamic device creation. But I agree if it is deviation from the norms(which I wasn't aware of at the time), we can remove it.

Looking at the issue this is causing for automatic module loading if we can get back to the bus enumeration code always creating a device without waiting for the driver kmod to load then that would be good IMHO.

Regards,

Hans

maintainer
#14 lore raw
Quoted 3 lines · Hans de Goede

Hi,

On 9-Jul-26 16:21, Sudeep Holla wrote:

[...]

Quoted 13 lines
Quoted 6 lines

I need to recall why we moved from static list of devices to dynamic. One reason I can think right now is the vendor protocols and their drivers But in general it was an attempt to help multiple drivers bind to different scmi_devices that have same protocol ID. E.g. the performance protocol can be used by cpufreq and devfreq/performance genpd drivers.

Note it is ok to have multiple drivers bind to the same modalias, depending on the reason why there are multiple drivers either one should detect that it is not compatible and exit probe() with -ENODEV or there should be some other mechanism to make sure only one driver loads.

Quoted 5 lines

E.g. duplicate USB device-ids happen (they shouldn't but they do) and then the drivers typically figure out if they are talking to the device which they were written for, or the other device with the same USB-ids and then one of the 2 drivers exits with -ENODEV.

Understood. Sorry I tried to explain with examples assuming you may not be aware of the details, but now reading your response, you have better examples.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

I wonder if we can just move a small part of the drivers (some mapping table) into the bus code and then just have this work as it does on regular busses. I hope to be able to make some time to look into this soonish.

Quoted 8 lines
Quoted 3 lines

I started with that few years ago and we then moved to this dynamic device creation. But I agree if it is deviation from the norms(which I wasn't aware of at the time), we can remove it.

Looking at the issue this is causing for automatic module loading if we can get back to the bus enumeration code always creating a device without waiting for the driver kmod to load then that would be good IMHO.

Sure if it fixes the issue for you. Cristian can point out anything I might have missed to consider as he is the one who reworked it and made it dynamic device creation which at the time sounded nice option to solve the issue. We weren't aware that it could cause such issues 🙁.

Signature · 2 lines
Regards,
Sudeep
#15 lore raw

Hi,

Quoted 43 lines · Sudeep Holla
Quoted 3 lines · Hans de Goede

Hi,

On 9-Jul-26 16:21, Sudeep Holla wrote:

[...]

Quoted 13 lines
Quoted 6 lines

I need to recall why we moved from static list of devices to dynamic. One reason I can think right now is the vendor protocols and their drivers But in general it was an attempt to help multiple drivers bind to different scmi_devices that have same protocol ID. E.g. the performance protocol can be used by cpufreq and devfreq/performance genpd drivers.

Note it is ok to have multiple drivers bind to the same modalias, depending on the reason why there are multiple drivers either one should detect that it is not compatible and exit probe() with -ENODEV or there should be some other mechanism to make sure only one driver loads.

Quoted 5 lines

E.g. duplicate USB device-ids happen (they shouldn't but they do) and then the drivers typically figure out if they are talking to the device which they were written for, or the other device with the same USB-ids and then one of the 2 drivers exits with -ENODEV.

Understood. Sorry I tried to explain with examples assuming you may not be aware of the details, but now reading your response, you have better examples.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

I wonder if we can just move a small part of the drivers (some mapping table) into the bus code and then just have this work as it does on regular busses. I hope to be able to make some time to look into this soonish.

Quoted 8 lines
Quoted 3 lines

I started with that few years ago and we then moved to this dynamic device creation. But I agree if it is deviation from the norms(which I wasn't aware of at the time), we can remove it.

Looking at the issue this is causing for automatic module loading if we can get back to the bus enumeration code always creating a device without waiting for the driver kmod to load then that would be good IMHO.

Quoted 4 lines

Sure if it fixes the issue for you. Cristian can point out anything I might have missed to consider as he is the one who reworked it and made it dynamic device creation which at the time sounded nice option to solve the issue. We weren't aware that it could cause such issues 🙁.

Note that before patch 1/2 of this series we did not have working module-autoloading for SCMI modules at all. With that said yes it would be nice to get this working.

Can you provide a patch for this to try ?

Regards,

Hans

maintainer
#16 lore raw
Quoted 51 lines · Hans de Goede

Hi,

Quoted 43 lines · Sudeep Holla
Quoted 3 lines · Hans de Goede

Hi,

On 9-Jul-26 16:21, Sudeep Holla wrote:

[...]

Quoted 13 lines
Quoted 6 lines

I need to recall why we moved from static list of devices to dynamic. One reason I can think right now is the vendor protocols and their drivers But in general it was an attempt to help multiple drivers bind to different scmi_devices that have same protocol ID. E.g. the performance protocol can be used by cpufreq and devfreq/performance genpd drivers.

Note it is ok to have multiple drivers bind to the same modalias, depending on the reason why there are multiple drivers either one should detect that it is not compatible and exit probe() with -ENODEV or there should be some other mechanism to make sure only one driver loads.

Quoted 5 lines

E.g. duplicate USB device-ids happen (they shouldn't but they do) and then the drivers typically figure out if they are talking to the device which they were written for, or the other device with the same USB-ids and then one of the 2 drivers exits with -ENODEV.

Understood. Sorry I tried to explain with examples assuming you may not be aware of the details, but now reading your response, you have better examples.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

I wonder if we can just move a small part of the drivers (some mapping table) into the bus code and then just have this work as it does on regular busses. I hope to be able to make some time to look into this soonish.

Quoted 8 lines
Quoted 3 lines

I started with that few years ago and we then moved to this dynamic device creation. But I agree if it is deviation from the norms(which I wasn't aware of at the time), we can remove it.

Looking at the issue this is causing for automatic module loading if we can get back to the bus enumeration code always creating a device without waiting for the driver kmod to load then that would be good IMHO.

Quoted 4 lines

Sure if it fixes the issue for you. Cristian can point out anything I might have missed to consider as he is the one who reworked it and made it dynamic device creation which at the time sounded nice option to solve the issue. We weren't aware that it could cause such issues 🙁.

Quoted 6 lines

Note that before patch 1/2 of this series we did not have working module-autoloading for SCMI modules at all. With that said yes it would be nice to get this working.

Can you provide a patch for this to try ?

Not sure what exactly are you asking, but I don't have anything w.r.t the discussion handy to share. The codebase has moved a lot to revert just the dynamic creation addition patch unfortunately.

Signature · 2 lines
Regards,
Sudeep
#17 lore raw
In reply to Sudeep Holla
Quoted 43 lines · Sudeep Holla
Quoted 3 lines · Hans de Goede

Hi,

On 9-Jul-26 16:21, Sudeep Holla wrote:

[...]

Quoted 13 lines
Quoted 6 lines

I need to recall why we moved from static list of devices to dynamic. One reason I can think right now is the vendor protocols and their drivers But in general it was an attempt to help multiple drivers bind to different scmi_devices that have same protocol ID. E.g. the performance protocol can be used by cpufreq and devfreq/performance genpd drivers.

Note it is ok to have multiple drivers bind to the same modalias, depending on the reason why there are multiple drivers either one should detect that it is not compatible and exit probe() with -ENODEV or there should be some other mechanism to make sure only one driver loads.

Quoted 5 lines

E.g. duplicate USB device-ids happen (they shouldn't but they do) and then the drivers typically figure out if they are talking to the device which they were written for, or the other device with the same USB-ids and then one of the 2 drivers exits with -ENODEV.

Understood. Sorry I tried to explain with examples assuming you may not be aware of the details, but now reading your response, you have better examples.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

I wonder if we can just move a small part of the drivers (some mapping table) into the bus code and then just have this work as it does on regular busses. I hope to be able to make some time to look into this soonish.

Quoted 8 lines
Quoted 3 lines

I started with that few years ago and we then moved to this dynamic device creation. But I agree if it is deviation from the norms(which I wasn't aware of at the time), we can remove it.

Looking at the issue this is causing for automatic module loading if we can get back to the bus enumeration code always creating a device without waiting for the driver kmod to load then that would be good IMHO.

Quoted 5 lines

Sure if it fixes the issue for you. Cristian can point out anything I might have missed to consider as he is the one who reworked it and made it dynamic device creation which at the time sounded nice option to solve the issue. We weren't aware that it could cause such issues 🙁.

The reason for the awkward mechanism of dynamic device creation AFAICR was an explicit request by Qualcomm (via its Linaro landing team at that time) for the generic vendor module suppport that I was adding to be fully self-contained: so that you can write your own protocol and add the DT node and that's it, without the need to patch some centrally maintained table in the core SCMI stack to add your new vendor protocol.

Not saying that it was necesarily a good idea to allow that, but that was the origin of this....as far as I can remember....together with the fact that the internal interfaces were reworked to be absolutely the same for standard protocols and vendor protocols...

I thought that the current situation was that auto-loading was working for vendor protocols (this autoload issue appeared at first for vendors protocols one year ago) then I had made this hacky attempt to make it work for standard protocols by forcibly emitting a uevent for all known standard protos:

https://lore.kernel.org/arm-scmi/[email protected]/

...but that was clearly not the proper way..and all the rework was dropped...

Thanks,
Cristian