Skip to contentSkip to conversation

driver core: introduce PROBE_FORCE_ASYNCHRONOUS

PATCH In review Dmitry Torokhov 2 participants 8 messages Jul 27 – Jul 30

Subsystems (2)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

PATCH 1/1 driver core: introduce PROBE_FORCE_ASYNCHRONOUS

Add PROBE_FORCE_ASYNCHRONOUS probe type enum and update driver_allows_async_probing() to allow asynchronous probing for drivers marked with this type.

While PROBE_PREFER_ASYNCHRONOUS exists, it represents a temporary opt-in preference. Subsystems that require asynchronous probing (such as slow legacy buses) need a dedicated probe type to guarantee asynchronous execution.

Assisted-by Antigravity:gemini-3.5-flash

---

I am planning to rework serio and gameport subsystems to rely on asynchronous probing instead of rolling their own implementations.

 drivers/base/dd.c             | 1 +
 include/linux/device/driver.h | 1 +
 2 files changed, 2 insertions(+)
drivers/base/dd.c +1 -0
index 60c005223844..34df7b4416ac 100644
@@ -936,6 +936,7 @@ __setup("driver_async_probe=", save_async_options);
 static bool driver_allows_async_probing(const struct device_driver *drv)
 {
 	switch (drv->probe_type) {
+	case PROBE_FORCE_ASYNCHRONOUS:
 	case PROBE_PREFER_ASYNCHRONOUS:
 		return true;
 
include/linux/device/driver.h +1 -0
index 768a1334c0a1..4b3901a35e85 100644
@@ -48,6 +48,7 @@ enum probe_type {
 	PROBE_DEFAULT_STRATEGY,
 	PROBE_PREFER_ASYNCHRONOUS,
 	PROBE_FORCE_SYNCHRONOUS,
+	PROBE_FORCE_ASYNCHRONOUS,
 };
 
 /**
Signature · 5 lines
2.55.0.229.g6434b31f56-goog


-- 
Dmitry
#1 lore raw
Quoted 9 lines · Dmitry Torokhov

Add PROBE_FORCE_ASYNCHRONOUS probe type enum and update driver_allows_async_probing() to allow asynchronous probing for drivers marked with this type.

While PROBE_PREFER_ASYNCHRONOUS exists, it represents a temporary opt-in preference. Subsystems that require asynchronous probing (such as slow legacy buses) need a dedicated probe type to guarantee asynchronous execution.

Quoted 6 lines
Assisted-by Antigravity:gemini-3.5-flash

---

I am planning to rework serio and gameport subsystems to rely on asynchronous probing instead of rolling their own implementations.

What do you mean? Why doesn't the PROBE_PREFER_ASYNCHRONOUS work for you for those subsystems?

thanks,

greg k-h

author maintainer
#2 lore raw
Quoted 14 lines · Greg Kroah-Hartman
Quoted 13 lines · Dmitry Torokhov

Add PROBE_FORCE_ASYNCHRONOUS probe type enum and update driver_allows_async_probing() to allow asynchronous probing for drivers marked with this type.

While PROBE_PREFER_ASYNCHRONOUS exists, it represents a temporary opt-in preference. Subsystems that require asynchronous probing (such as slow legacy buses) need a dedicated probe type to guarantee asynchronous execution.

Assisted-by Antigravity:gemini-3.5-flash

---

Quoted 5 lines
Quoted 2 lines

I am planning to rework serio and gameport subsystems to rely on asynchronous probing instead of rolling their own implementations.

What do you mean? Why doesn't the PROBE_PREFER_ASYNCHRONOUS work for you for those subsystems?

It shows the intent. It is not "preference" anymore, it is a "must". If we ever introduce switch to make probing synchronous for some reason it should not affect drivers that must be probed asynchronously.

Thanks.

Signature · 1 line
Dmitry
#3 lore raw
Quoted 18 lines · Dmitry Torokhov
Quoted 17 lines · Greg Kroah-Hartman
Quoted 15 lines · Dmitry Torokhov

Add PROBE_FORCE_ASYNCHRONOUS probe type enum and update driver_allows_async_probing() to allow asynchronous probing for drivers marked with this type.

While PROBE_PREFER_ASYNCHRONOUS exists, it represents a temporary opt-in preference. Subsystems that require asynchronous probing (such as slow legacy buses) need a dedicated probe type to guarantee asynchronous execution.

Assisted-by Antigravity:gemini-3.5-flash

---

I am planning to rework serio and gameport subsystems to rely on asynchronous probing instead of rolling their own implementations.

Quoted 6 lines
Quoted 2 lines

What do you mean? Why doesn't the PROBE_PREFER_ASYNCHRONOUS work for you for those subsystems?

It shows the intent. It is not "preference" anymore, it is a "must". If we ever introduce switch to make probing synchronous for some reason it should not affect drivers that must be probed asynchronously.

I'm sorry, but I don't understand. And as there's no users for this, we really can't take it until we see those users at the same time :)

thanks,

greg k-h

author maintainer
#4 lore raw
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Dmitry Torokhov
Quoted 17 lines · Greg Kroah-Hartman
Quoted 15 lines · Dmitry Torokhov

Add PROBE_FORCE_ASYNCHRONOUS probe type enum and update driver_allows_async_probing() to allow asynchronous probing for drivers marked with this type.

While PROBE_PREFER_ASYNCHRONOUS exists, it represents a temporary opt-in preference. Subsystems that require asynchronous probing (such as slow legacy buses) need a dedicated probe type to guarantee asynchronous execution.

Assisted-by Antigravity:gemini-3.5-flash

---

I am planning to rework serio and gameport subsystems to rely on asynchronous probing instead of rolling their own implementations.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

What do you mean? Why doesn't the PROBE_PREFER_ASYNCHRONOUS work for you for those subsystems?

It shows the intent. It is not "preference" anymore, it is a "must". If we ever introduce switch to make probing synchronous for some reason it should not affect drivers that must be probed asynchronously.

I'm sorry, but I don't understand.

PROBE_PREFER_ASYNCHRONOUS says that the driver prefers to be probe asynchronously but it can also be probed synchronously if needed.

PROBE_FORCE_ASYNCHRONOUS indicates that the driver *must* be probed asynchronously, or the kernel will break.

Currently there is no difference in behavior, but it documents the intent.

Quoted 2 lines

And as there's no users for this, we
really can't take it until we see those users at the same time :)

I am planning to use it in serio and gameport bus implementations that currently roll their own asynchronous registration which is quite ugly. Because we have nested serio ports probing *must* be done asynchronously or it will deadlock.

I would like to merge the new constant early so that I do not have dependency when I am ready to merge input changes.

Below is how it will look like (just a small part of a WIP series).

Thanks.

Signature · 20 lines
Dmitry


Input: serio - use PROBE_FORCE_ASYNCHRONOUS and make port registration synchronous

From: Dmitry Torokhov <[email protected]>

Mark serio drivers as using PROBE_FORCE_ASYNCHRONOUS instead of
PROBE_PREFER_ASYNCHRONOUS during registration.

At the same time, rework __serio_register_port() to run synchronously
under serio_mutex instead of queuing a SERIO_REGISTER_PORT event to
kseriod. This ensures port registration happens synchronously while
driver probing is handled asynchronously by the driver core.

Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Dmitry Torokhov <[email protected]>
---
 drivers/input/serio/serio.c |   46 +++++--------------------------------------
 1 file changed, 5 insertions(+), 41 deletions(-)
drivers/input/serio/serio.c +5 -41
index dd53c2b7a39d..f47d90f0507b 100644
@@ -124,7 +124,6 @@ enum serio_event_type {
 	SERIO_RESCAN_PORT,
 	SERIO_RECONNECT_PORT,
 	SERIO_RECONNECT_SUBTREE,
-	SERIO_REGISTER_PORT,
 };
 
 struct serio_event {
@@ -190,11 +189,6 @@ static void serio_handle_event(struct work_struct *work)
 	while ((event = serio_get_event())) {
 
 		switch (event->type) {
-
-		case SERIO_REGISTER_PORT:
-			serio_add_port(event->object);
-			break;
-
 		case SERIO_RECONNECT_PORT:
 			serio_reconnect_port(event->object);
 			break;
@@ -279,30 +273,6 @@ static void serio_remove_pending_events(void *object)
 	}
 }
 
-/*
- * Locate child serio port (if any) that has not been fully registered yet.
- *
- * Children are registered by driver's connect() handler so there can't be a
- * grandchild pending registration together with a child.
- */
-static struct serio *serio_get_pending_child(struct serio *parent)
-{
-	struct serio_event *event;
-	struct serio *serio;
-
-	guard(spinlock_irqsave)(&serio_event_lock);
-
-	list_for_each_entry(event, &serio_event_list, node) {
-		if (event->type == SERIO_REGISTER_PORT) {
-			serio = event->object;
-			if (serio->parent == parent)
-				return serio;
-		}
-	}
-
-	return NULL;
-}
-
 /*
  * Serio port operations
  */
@@ -516,13 +486,6 @@ static void serio_add_port(struct serio *serio)
  */
 static void serio_destroy_port(struct serio *serio)
 {
-	struct serio *child;
-
-	while ((child = serio_get_pending_child(serio)) != NULL) {
-		serio_remove_pending_events(child);
-		put_device(&child->dev);
-	}
-
 	if (serio->stop)
 		serio->stop(serio);
 
@@ -653,13 +616,14 @@ void serio_reconnect(struct serio *serio)
 EXPORT_SYMBOL(serio_reconnect);
 
 /*
- * Submits register request to kseriod for subsequent execution.
- * Note that port registration is always asynchronous.
+ * Synchronously registers serio port.
  */
 int __serio_register_port(struct serio *serio, struct module *owner)
 {
 	serio_init_port(serio);
-	serio_queue_event(serio, owner, SERIO_REGISTER_PORT);
+
+	guard(mutex)(&serio_mutex);
+	serio_add_port(serio);
 
 	return 0;
 }
@@ -778,7 +742,7 @@ int __serio_register_driver(struct serio_driver *drv, struct module *owner, cons
 	 * Mark all serio drivers as using asynchronous probe because serio
 	 * devices are slow and their probing takes long time.
 	 */
-	drv->driver.probe_type = PROBE_PREFER_ASYNCHRONOUS;
+	drv->driver.probe_type = PROBE_FORCE_ASYNCHRONOUS;
 
 	error = driver_register(&drv->driver);
 	if (error) {
#5 lore raw
Quoted 46 lines · Dmitry Torokhov
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Dmitry Torokhov
Quoted 17 lines · Greg Kroah-Hartman
Quoted 15 lines · Dmitry Torokhov

Add PROBE_FORCE_ASYNCHRONOUS probe type enum and update driver_allows_async_probing() to allow asynchronous probing for drivers marked with this type.

While PROBE_PREFER_ASYNCHRONOUS exists, it represents a temporary opt-in preference. Subsystems that require asynchronous probing (such as slow legacy buses) need a dedicated probe type to guarantee asynchronous execution.

Assisted-by Antigravity:gemini-3.5-flash

---

I am planning to rework serio and gameport subsystems to rely on asynchronous probing instead of rolling their own implementations.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

What do you mean? Why doesn't the PROBE_PREFER_ASYNCHRONOUS work for you for those subsystems?

It shows the intent. It is not "preference" anymore, it is a "must". If we ever introduce switch to make probing synchronous for some reason it should not affect drivers that must be probed asynchronously.

I'm sorry, but I don't understand.

PROBE_PREFER_ASYNCHRONOUS says that the driver prefers to be probe asynchronously but it can also be probed synchronously if needed.

PROBE_FORCE_ASYNCHRONOUS indicates that the driver *must* be probed asynchronously, or the kernel will break.

Currently there is no difference in behavior, but it documents the intent.

Quoted 2 lines

And as there's no users for this, we
really can't take it until we see those users at the same time :)

I am planning to use it in serio and gameport bus implementations that currently roll their own asynchronous registration which is quite ugly. Because we have nested serio ports probing *must* be done asynchronously or it will deadlock.

Quoted 4 lines

I would like to merge the new constant early so that I do not have dependency when I am ready to merge input changes.

Below is how it will look like (just a small part of a WIP series).

Ok, this makes sense, but you need to also add documentation for this new value to the comment block right above where you defined it :)

Wait, in looking at the tree, I don't see how this differs from "prefer". I don't see how "prefer" can be overloaded to NOT do async probing. Am I just missing the logic somewhere?

thanks,

greg k-h

author maintainer
#6 lore raw
Quoted 52 lines · Greg Kroah-Hartman
Quoted 46 lines · Dmitry Torokhov
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Dmitry Torokhov
Quoted 17 lines · Greg Kroah-Hartman
Quoted 15 lines · Dmitry Torokhov

Add PROBE_FORCE_ASYNCHRONOUS probe type enum and update driver_allows_async_probing() to allow asynchronous probing for drivers marked with this type.

While PROBE_PREFER_ASYNCHRONOUS exists, it represents a temporary opt-in preference. Subsystems that require asynchronous probing (such as slow legacy buses) need a dedicated probe type to guarantee asynchronous execution.

Assisted-by Antigravity:gemini-3.5-flash

---

I am planning to rework serio and gameport subsystems to rely on asynchronous probing instead of rolling their own implementations.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

What do you mean? Why doesn't the PROBE_PREFER_ASYNCHRONOUS work for you for those subsystems?

It shows the intent. It is not "preference" anymore, it is a "must". If we ever introduce switch to make probing synchronous for some reason it should not affect drivers that must be probed asynchronously.

I'm sorry, but I don't understand.

PROBE_PREFER_ASYNCHRONOUS says that the driver prefers to be probe asynchronously but it can also be probed synchronously if needed.

PROBE_FORCE_ASYNCHRONOUS indicates that the driver *must* be probed asynchronously, or the kernel will break.

Currently there is no difference in behavior, but it documents the intent.

Quoted 2 lines

And as there's no users for this, we
really can't take it until we see those users at the same time :)

I am planning to use it in serio and gameport bus implementations that currently roll their own asynchronous registration which is quite ugly. Because we have nested serio ports probing *must* be done asynchronously or it will deadlock.

Quoted 4 lines

I would like to merge the new constant early so that I do not have dependency when I am ready to merge input changes.

Below is how it will look like (just a small part of a WIP series).

Quoted 7 lines

Ok, this makes sense, but you need to also add documentation for this new value to the comment block right above where you defined it :)

Wait, in looking at the tree, I don't see how this differs from "prefer". I don't see how "prefer" can be overloaded to NOT do async probing. Am I just missing the logic somewhere?

As I mentioned, the current behavior for "prefer" and "force" is the same. It is more about documenting expectations/requirements than behavior of the current implementation.

Thanks.

Signature · 1 line
Dmitry
#7 lore raw
Quoted 57 lines · Dmitry Torokhov
Quoted 56 lines · Greg Kroah-Hartman
Quoted 46 lines · Dmitry Torokhov
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Dmitry Torokhov
Quoted 17 lines · Greg Kroah-Hartman
Quoted 15 lines · Dmitry Torokhov

Add PROBE_FORCE_ASYNCHRONOUS probe type enum and update driver_allows_async_probing() to allow asynchronous probing for drivers marked with this type.

While PROBE_PREFER_ASYNCHRONOUS exists, it represents a temporary opt-in preference. Subsystems that require asynchronous probing (such as slow legacy buses) need a dedicated probe type to guarantee asynchronous execution.

Assisted-by Antigravity:gemini-3.5-flash

---

I am planning to rework serio and gameport subsystems to rely on asynchronous probing instead of rolling their own implementations.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

What do you mean? Why doesn't the PROBE_PREFER_ASYNCHRONOUS work for you for those subsystems?

It shows the intent. It is not "preference" anymore, it is a "must". If we ever introduce switch to make probing synchronous for some reason it should not affect drivers that must be probed asynchronously.

I'm sorry, but I don't understand.

PROBE_PREFER_ASYNCHRONOUS says that the driver prefers to be probe asynchronously but it can also be probed synchronously if needed.

PROBE_FORCE_ASYNCHRONOUS indicates that the driver *must* be probed asynchronously, or the kernel will break.

Currently there is no difference in behavior, but it documents the intent.

Quoted 2 lines

And as there's no users for this, we
really can't take it until we see those users at the same time :)

I am planning to use it in serio and gameport bus implementations that currently roll their own asynchronous registration which is quite ugly. Because we have nested serio ports probing *must* be done asynchronously or it will deadlock.

Quoted 4 lines

I would like to merge the new constant early so that I do not have dependency when I am ready to merge input changes.

Below is how it will look like (just a small part of a WIP series).

Ok, this makes sense, but you need to also add documentation for this new value to the comment block right above where you defined it :)

Quoted 7 lines
Quoted 3 lines

Wait, in looking at the tree, I don't see how this differs from "prefer". I don't see how "prefer" can be overloaded to NOT do async probing. Am I just missing the logic somewhere?

As I mentioned, the current behavior for "prefer" and "force" is the same. It is more about documenting expectations/requirements than behavior of the current implementation.

But you aren't changing anything here at all, just adding a new enum that does the same thing as the existing one. So I'm really confused...