Skip to contentSkip to conversation

driver core: allow explicit deferred probe preference

PATCH In review Luis R. Rodriguez 8 participants 28 messages Jul 28, 2014 – Aug 11, 2014

Subsystems (7)
lore
Share & tools
lore
#1 lore raw

PATCH v2 1/4 driver core: move deferred probe add / remove helpers down a bit

In reply to Luis R. Rodriguez

From: "Luis R. Rodriguez" <[email protected]>

We need to do this if we want to use the trigger at a later point. This change has introduces no functional changes.

Cc Tetsuo Handa <[email protected]>
Cc Joseph Salisbury <[email protected]>
Cc One Thousand Gnomes <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Pierre Fersing <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Benjamin Poirier <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Nagalakshmi Nandigama <[email protected]>
Cc Praveen Krishnamoorthy <[email protected]>
Cc Sreekanth Reddy <[email protected]>
Cc Abhijit Mahajan <[email protected]>
Cc Hariprasad S <[email protected]>
Cc Santosh Rastapur <[email protected]>
---
 drivers/base/dd.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
drivers/base/dd.c +20 -20
index e4ffbcf..9947c2e 100644
@@ -109,26 +109,6 @@ static void deferred_probe_work_func(struct work_struct *work)
 }
 static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);
 
-static void driver_deferred_probe_add(struct device *dev)
-{
-	mutex_lock(&deferred_probe_mutex);
-	if (list_empty(&dev->p->deferred_probe)) {
-		dev_dbg(dev, "Added to deferred list\n");
-		list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
-	}
-	mutex_unlock(&deferred_probe_mutex);
-}
-
-void driver_deferred_probe_del(struct device *dev)
-{
-	mutex_lock(&deferred_probe_mutex);
-	if (!list_empty(&dev->p->deferred_probe)) {
-		dev_dbg(dev, "Removed from deferred list\n");
-		list_del_init(&dev->p->deferred_probe);
-	}
-	mutex_unlock(&deferred_probe_mutex);
-}
-
 static bool driver_deferred_probe_enable = false;
 /**
  * driver_deferred_probe_trigger() - Kick off re-probing deferred devices
@@ -171,6 +151,26 @@ static void driver_deferred_probe_trigger(void)
 	queue_work(deferred_wq, &deferred_probe_work);
 }
 
+static void driver_deferred_probe_add(struct device *dev)
+{
+	mutex_lock(&deferred_probe_mutex);
+	if (list_empty(&dev->p->deferred_probe)) {
+		dev_dbg(dev, "Added to deferred list\n");
+		list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
+	}
+	mutex_unlock(&deferred_probe_mutex);
+}
+
+void driver_deferred_probe_del(struct device *dev)
+{
+	mutex_lock(&deferred_probe_mutex);
+	if (!list_empty(&dev->p->deferred_probe)) {
+		dev_dbg(dev, "Removed from deferred list\n");
+		list_del_init(&dev->p->deferred_probe);
+	}
+	mutex_unlock(&deferred_probe_mutex);
+}
+
 /**
  * deferred_probe_initcall() - Enable probing of deferred devices
  *
Signature · 1 line
2.0.1
#2 lore raw

PATCH v2 2/4 driver core: enable drivers to use deferred probe from init

In reply to Luis R. Rodriguez

From: "Luis R. Rodriguez" <[email protected]>

Tetsuo bisected and found that commit 786235ee "kthread: make kthread_create() killable" modified kthread_create() to bail as soon as SIGKILL is received. This is causing some issues with some drivers and at times boot. Joseph then found that failures occur as the systemd-udevd process sends SIGKILL to modprobe if probe on a driver takes over 30 seconds. When this happens probe will fail on any driver, its why booting on some system will fail if the driver happens to be a storage related driver. Some folks have suggested fixing this by modifying kthread_create() to not leave upon SIGKILL [3], upon review Oleg rejected this change and the discussion was punted out to systemd to see if the default timeout could be increased from 30 seconds to 120. The opinion of the systemd maintainers is that the driver's behavior should be fixed [4]. Linus seems to agree [5], however more recently even networking drivers have been reported to fail on probe since just writing the firmware to a device and kicking it can take easy over 60 seconds [6]. Benjamim was able to trace the issues recently reported on cxgb4 down to the same systemd-udevd 30 second timeout [6].

This is an alternative solution which enables drivers that are known to take long to use deferred probe workqueue. This avoids the 30 second timeout and lets us annotate drivers with long init sequences.

As drivers determine a component is not yet available and needs to defer probe you'll be notified this happen upon init for each device but now with a message such as:

pci 0000:03:00.0: Driver cxgb4 requests probe deferral on init

You should see one of these per struct device probed.

[0] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1276705
[1] https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1297248
[2] http://lists.freedesktop.org/archives/systemd-devel/2014-March/018006.html
[3] http://thread.gmane.org/gmane.linux.ubuntu.devel.kernel.general/39123
[4] http://article.gmane.org/gmane.comp.sysutils.systemd.devel/17860
[5] http://article.gmane.org/gmane.linux.kernel/1671333
[6] https://bugzilla.novell.com/show_bug.cgi?id=877622

Cc Greg Kroah-Hartman <[email protected]>
Cc Tetsuo Handa <[email protected]>
Cc Joseph Salisbury <[email protected]>
Cc Kay Sievers <[email protected]>
Cc One Thousand Gnomes <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Pierre Fersing <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Benjamin Poirier <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Nagalakshmi Nandigama <[email protected]>
Cc Praveen Krishnamoorthy <[email protected]>
Cc Sreekanth Reddy <[email protected]>
Cc Abhijit Mahajan <[email protected]>
Cc Hariprasad S <[email protected]>
Cc Santosh Rastapur <[email protected]>
---
 drivers/base/dd.c      | 18 +++++++++++++++++-
 include/linux/device.h |  7 +++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
drivers/base/dd.c +17 -1
index 9947c2e..d59e4b5 100644
@@ -159,6 +159,9 @@ static void driver_deferred_probe_add(struct device *dev)
 		list_add_tail(&dev->p->deferred_probe, &deferred_probe_pending_list);
 	}
 	mutex_unlock(&deferred_probe_mutex);
+
+	if (driver_deferred_probe_enable)
+		driver_deferred_probe_trigger();
 }
 
 void driver_deferred_probe_del(struct device *dev)
@@ -374,6 +377,19 @@ void wait_for_device_probe(void)
 }
 EXPORT_SYMBOL_GPL(wait_for_device_probe);
 
+static int __driver_probe_device(struct device_driver *drv, struct device *dev)
+{
+	if (drv->delay_probe && !dev->init_delayed_probe) {
+		dev_info(dev, "Driver %s requests probe deferral on init\n",
+			 drv->name);
+		dev->init_delayed_probe = true;
+		driver_deferred_probe_add(dev);
+		return -EPROBE_DEFER;
+	}
+
+	return really_probe(dev, drv);
+}
+
 /**
  * driver_probe_device - attempt to bind device & driver together
  * @drv: driver to bind a device to
@@ -396,7 +412,7 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
 		 drv->bus->name, __func__, dev_name(dev), drv->name);
 
 	pm_runtime_barrier(dev);
-	ret = really_probe(dev, drv);
+	ret = __driver_probe_device(drv, dev);
 	pm_request_idle(dev);
 
 	return ret;
include/linux/device.h +7 -0
index af424ac..c317dfa 100644
@@ -200,6 +200,9 @@ extern struct klist *bus_get_device_klist(struct bus_type *bus);
  * @owner:	The module owner.
  * @mod_name:	Used for built-in modules.
  * @suppress_bind_attrs: Disables bind/unbind via sysfs.
+ * @delay_probe: this driver is requesting a deferred probe since
+ *	initialization. This can be desirable if its known the device probe
+ *	or initialization takes more than 30 seconds.
  * @of_match_table: The open firmware table.
  * @acpi_match_table: The ACPI match table.
  * @probe:	Called to query the existence of a specific device,
@@ -233,6 +236,7 @@ struct device_driver {
 	const char		*mod_name;	/* used for built-in modules */
 
 	bool suppress_bind_attrs;	/* disables bind/unbind via sysfs */
+	bool delay_probe;		/* requests deferred probe */
 
 	const struct of_device_id	*of_match_table;
 	const struct acpi_device_id	*acpi_match_table;
@@ -715,6 +719,8 @@ struct acpi_dev_node {
  *
  * @offline_disabled: If set, the device is permanently online.
  * @offline:	Set after successful invocation of bus type's .offline().
+ * @init_delayed_probe: lets the coore keep track if the device has already
+ * 	gone through a delayed probe upon init.
  *
  * At the lowest level, every device in a Linux system is represented by an
  * instance of struct device. The device structure contains the information
@@ -793,6 +799,7 @@ struct device {
 
 	bool			offline_disabled:1;
 	bool			offline:1;
+	bool			init_delayed_probe:1;
 };
 
 static inline struct device *kobj_to_dev(struct kobject *kobj)
Signature · 1 line
2.0.1
#26 lore raw

PATCH v2 3/4 cxgb4: ask for deferred probe

In reply to Luis R. Rodriguez

From: "Luis R. Rodriguez" <[email protected]>

cxgb4 probe can take up to over 1 minute when the firmware is is written and installed on the device. Use the new delayed probe preference so that cxgb4 gets probed on the deferred workqueue. Without this devices that require the update on firmware will fail on probe.

Cc Tetsuo Handa <[email protected]>
Cc Joseph Salisbury <[email protected]>
Cc One Thousand Gnomes <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Pierre Fersing <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Benjamin Poirier <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Nagalakshmi Nandigama <[email protected]>
Cc Praveen Krishnamoorthy <[email protected]>
Cc Sreekanth Reddy <[email protected]>
Cc Abhijit Mahajan <[email protected]>
Cc Hariprasad S <[email protected]>
Cc Santosh Rastapur <[email protected]>
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +3 -0
index 6b11fde..bb5daaf 100644
@@ -6400,6 +6400,9 @@ static void remove_one(struct pci_dev *pdev)
 }
 
 static struct pci_driver cxgb4_driver = {
+	.driver = {
+		.delay_probe = true,
+	},
 	.name     = KBUILD_MODNAME,
 	.id_table = cxgb4_pci_tbl,
 	.probe    = init_one,
Signature · 1 line
2.0.1
#27 lore raw

PATCH v2 4/4 mptsas: ask for deferred probe

In reply to Luis R. Rodriguez

From: "Luis R. Rodriguez" <[email protected]>

Its reported that mptsas can at times take over 30 seconds to recognize SCSI storage devices [0], this is done on the driver's probe path. Use the the deferred probe workqueue to allow long init sequences to complete.

[0] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1276705

Cc Tetsuo Handa <[email protected]>
Cc Joseph Salisbury <[email protected]>
Cc One Thousand Gnomes <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Pierre Fersing <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Benjamin Poirier <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Nagalakshmi Nandigama <[email protected]>
Cc Praveen Krishnamoorthy <[email protected]>
Cc Sreekanth Reddy <[email protected]>
Cc Abhijit Mahajan <[email protected]>
Cc Hariprasad S <[email protected]>
Cc Santosh Rastapur <[email protected]>
---
 drivers/message/fusion/mptsas.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/message/fusion/mptsas.c +3 -0
index 711fcb5..3859ac3 100644
@@ -5382,6 +5382,9 @@ MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
 
 
 static struct pci_driver mptsas_driver = {
+	.driver = {
+		.delay_probe = true,
+	},
 	.name		= "mptsas",
 	.id_table	= mptsas_pci_table,
 	.probe		= mptsas_probe,
Signature · 1 line
2.0.1
#0 lore raw

v2 cover driver core: allow explicit deferred probe preference

From: "Luis R. Rodriguez" <[email protected]>

This adds support to let device drivers explicitly request to be probed on the deferred workqueue. Note that another ideal solution on top of this would be if we could detect somehow if kthread_create() was SIGKILL'd for a modprobe, and also driver_deferred_probe_add() the device there proactively. This would enable us to not have to be hunting for these device drivers as a fix after a problem popped up. That would allow us to look for device drivers that need this change in a proactive way but without failing them first -- I just can't think of a way to do this yet.

Luis R. Rodriguez (4):
driver core: move deferred probe add / remove helpers down a bit driver core: enable drivers to use deferred probe from init
cxgb4: ask for deferred probe
mptsas: ask for deferred probe

 drivers/base/dd.c                               | 58 ++++++++++++++++---------
 drivers/message/fusion/mptsas.c                 |  3 ++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c |  3 ++
 include/linux/device.h                          |  7 +++
 4 files changed, 50 insertions(+), 21 deletions(-)
Signature · 1 line
2.0.1
maintainer
#3 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

In reply to Luis R. Rodriguez
Quoted 8 lines · Luis R. Rodriguez

From: "Luis R. Rodriguez" <[email protected]>

Tetsuo bisected and found that commit 786235ee "kthread: make kthread_create() killable" modified kthread_create() to bail as soon as SIGKILL is received. This is causing some issues with some drivers and at times boot. Joseph then found that failures occur as the systemd-udevd process sends SIGKILL to modprobe if probe on a driver takes over 30 seconds.

Because no driver should ever take that long for their probe function to return. Why not fix those drivers?

Quoted 5 lines

When this happens probe will fail on any driver, its why booting on some system will fail if the driver happens to be a storage related driver. Some folks
have suggested fixing this by modifying kthread_create() to not leave upon SIGKILL [3], upon review Oleg rejected this change and

Quoted 8 lines

the discussion was punted out to systemd to see if the default timeout could be increased from 30 seconds to 120. The opinion of the systemd maintainers is that the driver's behavior should be fixed [4]. Linus seems to agree [5], however more recently even networking drivers have been reported to fail on probe since just writing the firmware to a device and kicking it can take easy over 60 seconds [6]. Benjamim was able to trace the issues recently reported on cxgb4 down to the same systemd-udevd 30 second timeout [6].

Then use the async firmware interface, why is any driver taking longer than less than a second in their init function?

Quoted 5 lines

This is an alternative solution which enables drivers that are known to take long to use deferred probe workqueue. This avoids the 30 second timeout and lets us annotate drivers with long init sequences.

Quoted 7 lines

As drivers determine a component is not yet available and needs to defer probe you'll be notified this happen upon init for each device but now with a message such as:

pci 0000:03:00.0: Driver cxgb4 requests probe deferral on init

You should see one of these per struct device probed.

I'm all for abusing kernel interfaces, but please, no, don't try to use the deferred init code to cover up for broken drivers. Just fix them properly, we have the interfaces to handle it properly (i.e. async firmware loading), please use it.

And no PCI driver should ever need "deferred init" as the resources for such a device is already present in the system. Now if userspace is up and running yet is a different issue, one that deferred init is not there for at all, sorry.

So, what drivers are having problems in their init sequence, and why aren't they using async firmware loading?

thanks,

greg k-h

#4 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 2 lines · Greg KH

So, what drivers are having problems in their init sequence, and why aren't they using async firmware loading?

Fixing drivers is one thing, fixing drivers *now* because *now* drivers are failing due to a regression is another thing and that's what we have now so lets just be clear on that. The 30 second rule is a major driver requirement change and it should not be taken slightly, all of a sudden this is a new requirement but you won't know that unless you're reading these threads or hit an issue. That's an issue in itself.

The cxgb4: driver is an example where although I did propose patches to use asynch firmware loading the entire registration of the netdevice would need to be changed as well in order to get this right. In short we have to scramble now to first identify drivers that have long init sequences and then fix. There's an assumption that we can easily fix drivers, this can take time. This series, although does take advantage of a kernel interface for other uses, lets us identify these drivers on the kernel ring buffer, so we can go and address fixing them with time.

Luis

#5 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 12 lines · Luis R. Rodriguez
Quoted 2 lines · Greg KH

So, what drivers are having problems in their init sequence, and why aren't they using async firmware loading?

Fixing drivers is one thing, fixing drivers *now* because *now* drivers are failing due to a regression is another thing and that's what we have now so lets just be clear on that. The 30 second rule is a major driver requirement change and it should not be taken slightly, all of a sudden this is a new requirement but you won't know that unless you're reading these threads or hit an issue. That's an issue in itself.

Quoted 9 lines

The cxgb4: driver is an example where although I did propose patches to use asynch firmware loading the entire registration of the netdevice would need to be changed as well in order to get this right. In short we have to scramble now to first identify drivers that have long init sequences and then fix. There's an assumption that we can easily fix drivers, this can take time. This series, although does take advantage of a kernel interface for other uses, lets us identify these drivers on the kernel ring buffer, so we can go and address fixing them with time.

Another thing that came up during asynch firmware review / integration on cxgb4 was that it would not be the only thing that would need to be fixed, the driver also has a ton of ports and at least as per my review the proper fix would be to use platform regiister stuff. It is a major rewrite of the driver but an example of a driver that needs quite a bit of work to meet this new 30 second driver requirement.

Luis

maintainer
#6 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 6 lines · Luis R. Rodriguez
Quoted 4 lines · Luis R. Rodriguez
Quoted 2 lines · Greg KH

So, what drivers are having problems in their init sequence, and why aren't they using async firmware loading?

Quoted 7 lines
Quoted 7 lines

Fixing drivers is one thing, fixing drivers *now* because *now* drivers are failing due to a regression is another thing and that's what we have now so lets just be clear on that. The 30 second rule is a major driver requirement change and it should not be taken slightly, all of a sudden this is a new requirement but you won't know that unless you're reading these threads or hit an issue. That's an issue in itself.

That "regression" is something that userspace has decided to do, not anything the kernel changed, so perhaps you should just patch your modprobe and be done with it until you can fix up those drivers?

And putting a horrid hack in the driver core, just because of some really bad drivers, is not ok, that's an interface _I_ will have to support for the next few decades.

And it's going to take you a while to get something like this ever merged in anyway, odds are you can fix up the driver faster...

Quoted 10 lines
Quoted 9 lines

The cxgb4: driver is an example where although I did propose patches to use asynch firmware loading the entire registration of the netdevice would need to be changed as well in order to get this right. In short we have to scramble now to first identify drivers that have long init sequences and then fix. There's an assumption that we can easily fix drivers, this can take time. This series, although does take advantage of a kernel interface for other uses, lets us identify these drivers on the kernel ring buffer, so we can go and address fixing them with time.

Quoted 6 lines

Another thing that came up during asynch firmware review / integration on cxgb4 was that it would not be the only thing that would need to be fixed, the driver also has a ton of ports and at least as per my review the proper fix would be to use platform regiister stuff. It is a major rewrite of the driver but an example of a driver that needs quite a bit of work to meet this new 30 second driver requirement.

It shouldn't be using any platform driver stuff, it's a pci device, not a platform device.

Why not just put the initial "register the device" in a single-shot workqueue or thread or something like that so that modprobe returns instantly back with a success and all is fine?

Again, trying to hack the "deferred init" logic for PCI drivers isn't ok, I'm not going to take that into the driver core if at all possible, sorry.

greg k-h

#7 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 15 lines · Greg KH
Quoted 6 lines · Luis R. Rodriguez
Quoted 4 lines · Luis R. Rodriguez
Quoted 2 lines · Greg KH

So, what drivers are having problems in their init sequence, and why aren't they using async firmware loading?

Quoted 7 lines
Quoted 7 lines

Fixing drivers is one thing, fixing drivers *now* because *now* drivers are failing due to a regression is another thing and that's what we have now so lets just be clear on that. The 30 second rule is a major driver requirement change and it should not be taken slightly, all of a sudden this is a new requirement but you won't know that unless you're reading these threads or hit an issue. That's an issue in itself.

Quoted 2 lines

That "regression" is something that userspace has decided to do, not anything the kernel changed,

Actually commit 786235ee seems to have been the one that caused this issue, systemd would just send the SIGKILL and that change forced a bail on probe then hence Canonical's work around to modify kthread_create() to not leave upon SIGKILL:

http://thread.gmane.org/gmane.linux.ubuntu.devel.kernel.general/39123

Quoted 2 lines

so perhaps you should just patch your
modprobe and be done with it until you can fix up those drivers?

To ignore SIGKILL ?

Quoted 3 lines

And putting a horrid hack in the driver core, just because of some really bad drivers, is not ok, that's an interface _I_ will have to support for the next few decades.

I understand, hence review.

Quoted 2 lines

And it's going to take you a while to get something like this ever merged in anyway, odds are you can fix up the driver faster...

That requires quite a bit of changes and commitment and again, there are quite a bit of drivers that we can run into in the community, we've just spotted 2 so far here for now.

Quoted 17 lines
Quoted 10 lines
Quoted 9 lines

The cxgb4: driver is an example where although I did propose patches to use asynch firmware loading the entire registration of the netdevice would need to be changed as well in order to get this right. In short we have to scramble now to first identify drivers that have long init sequences and then fix. There's an assumption that we can easily fix drivers, this can take time. This series, although does take advantage of a kernel interface for other uses, lets us identify these drivers on the kernel ring buffer, so we can go and address fixing them with time.

Quoted 6 lines

Another thing that came up during asynch firmware review / integration on cxgb4 was that it would not be the only thing that would need to be fixed, the driver also has a ton of ports and at least as per my review the proper fix would be to use platform regiister stuff. It is a major rewrite of the driver but an example of a driver that needs quite a bit of work to meet this new 30 second driver requirement.

Quoted 2 lines

It shouldn't be using any platform driver stuff, it's a pci device, not a platform device.

The general PCI stuff is already used, the reason for suggesting the platform_device_register_simple() stuff is it has tons of ports and each port will register in turn a new struct netdevice, essentially one device can end up having tons of different network devices, the platform stuff would be to allow handling each netdevice candidate separately as part of the internal driver architecture, right now its some scary loop thing that in my eyes can be very error prone. drivers/net/ethernet/8390/ne.c. This discussion:

https://lkml.org/lkml/2014/6/25/815

Quoted 3 lines

Why not just put the initial "register the device" in a single-shot workqueue or thread or something like that so that modprobe returns instantly back with a success and all is fine?

That surely is possible but why not a general solution for such kludges?

Quoted 3 lines

Again, trying to hack the "deferred init" logic for PCI drivers isn't ok, I'm not going to take that into the driver core if at all possible, sorry.

No need to apologize I'm looking for the best solution here after all. One userspace kludge is surely better than a one per driver while drivers are fixed for this new driver requirement. Its just kind of odd the circle of events for a kernel issue from kernel --> systemd --> modprobe as a work around.

Luis

maintainer
#8 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 24 lines · Luis R. Rodriguez
Quoted 15 lines · Greg KH
Quoted 6 lines · Luis R. Rodriguez
Quoted 4 lines · Luis R. Rodriguez
Quoted 2 lines · Greg KH

So, what drivers are having problems in their init sequence, and why aren't they using async firmware loading?

Quoted 7 lines
Quoted 7 lines

Fixing drivers is one thing, fixing drivers *now* because *now* drivers are failing due to a regression is another thing and that's what we have now so lets just be clear on that. The 30 second rule is a major driver requirement change and it should not be taken slightly, all of a sudden this is a new requirement but you won't know that unless you're reading these threads or hit an issue. That's an issue in itself.

Quoted 2 lines

That "regression" is something that userspace has decided to do, not anything the kernel changed,

Actually commit 786235ee seems to have been the one that caused this issue, systemd would just send the SIGKILL and that change forced a bail on probe then hence Canonical's work around to modify kthread_create() to not leave upon SIGKILL:

Quoted 6 lines

http://thread.gmane.org/gmane.linux.ubuntu.devel.kernel.general/39123

Quoted 2 lines

so perhaps you should just patch your
modprobe and be done with it until you can fix up those drivers?

To ignore SIGKILL ?

Sorry, I thought this was a userspace change that caused this.

As it's a kernel change, well, maybe that patch should be reverted...

Quoted 33 lines
Quoted 3 lines

And putting a horrid hack in the driver core, just because of some really bad drivers, is not ok, that's an interface _I_ will have to support for the next few decades.

I understand, hence review.

Quoted 2 lines

And it's going to take you a while to get something like this ever merged in anyway, odds are you can fix up the driver faster...

That requires quite a bit of changes and commitment and again, there are quite a bit of drivers that we can run into in the community, we've just spotted 2 so far here for now.

Quoted 17 lines
Quoted 10 lines
Quoted 9 lines

The cxgb4: driver is an example where although I did propose patches to use asynch firmware loading the entire registration of the netdevice would need to be changed as well in order to get this right. In short we have to scramble now to first identify drivers that have long init sequences and then fix. There's an assumption that we can easily fix drivers, this can take time. This series, although does take advantage of a kernel interface for other uses, lets us identify these drivers on the kernel ring buffer, so we can go and address fixing them with time.

Quoted 6 lines

Another thing that came up during asynch firmware review / integration on cxgb4 was that it would not be the only thing that would need to be fixed, the driver also has a ton of ports and at least as per my review the proper fix would be to use platform regiister stuff. It is a major rewrite of the driver but an example of a driver that needs quite a bit of work to meet this new 30 second driver requirement.

Quoted 2 lines

It shouldn't be using any platform driver stuff, it's a pci device, not a platform device.

Quoted 8 lines

The general PCI stuff is already used, the reason for suggesting the platform_device_register_simple() stuff is it has tons of ports and each port will register in turn a new struct netdevice, essentially one device can end up having tons of different network devices, the platform stuff would be to allow handling each netdevice candidate separately as part of the internal driver architecture, right now its some scary loop thing that in my eyes can be very error prone. drivers/net/ethernet/8390/ne.c. This discussion:

No, don't use platform devices as a "catch-all" for when you don't want to write your own bus code. This looks like a device-specific bus, great, write the code to do that, it can be done in about 200 lines, with comments and whitespace.

Only use platform devices for, wait for it, platform devices. And even then, reconsider and use something else if at all possible.

Quoted 5 lines
Quoted 3 lines

Why not just put the initial "register the device" in a single-shot workqueue or thread or something like that so that modprobe returns instantly back with a success and all is fine?

That surely is possible but why not a general solution for such kludges?

Because the driver should be fixed. How hard would it be to do what I just suggested here, 20 lines added at most?

thanks,

greg k-h

#9 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 27 lines · Greg KH
Quoted 26 lines · Luis R. Rodriguez
Quoted 15 lines · Greg KH
Quoted 6 lines · Luis R. Rodriguez
Quoted 4 lines · Luis R. Rodriguez
Quoted 2 lines · Greg KH

So, what drivers are having problems in their init sequence, and why aren't they using async firmware loading?

Quoted 7 lines
Quoted 7 lines

Fixing drivers is one thing, fixing drivers *now* because *now* drivers are failing due to a regression is another thing and that's what we have now so lets just be clear on that. The 30 second rule is a major driver requirement change and it should not be taken slightly, all of a sudden this is a new requirement but you won't know that unless you're reading these threads or hit an issue. That's an issue in itself.

Quoted 2 lines

That "regression" is something that userspace has decided to do, not anything the kernel changed,

Actually commit 786235ee seems to have been the one that caused this issue, systemd would just send the SIGKILL and that change forced a bail on probe then hence Canonical's work around to modify kthread_create() to not leave upon SIGKILL:

http://thread.gmane.org/gmane.linux.ubuntu.devel.kernel.general/39123

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

so perhaps you should just patch your
modprobe and be done with it until you can fix up those drivers?

To ignore SIGKILL ?

Sorry, I thought this was a userspace change that caused this.

As it's a kernel change, well, maybe that patch should be reverted...

That's certainly viable. Oleg?

If its reverted we won't know which drivers are hitting over the new 30 second limit requirement imposed by userspace, which the culprit commit forces failure on probe now. This series at least would allow us to annotate which drivers are brake the 30 second init limit, and enable a work around alternative if we wish to not revert the commit. This series essentially should be considered an alternative solution to what was proposed initially by Joseph Salisbury, it may not be perfect but its a proposal. I welcome others.

Quoted 42 lines
Quoted 33 lines
Quoted 3 lines

And putting a horrid hack in the driver core, just because of some really bad drivers, is not ok, that's an interface _I_ will have to support for the next few decades.

I understand, hence review.

Quoted 2 lines

And it's going to take you a while to get something like this ever merged in anyway, odds are you can fix up the driver faster...

That requires quite a bit of changes and commitment and again, there are quite a bit of drivers that we can run into in the community, we've just spotted 2 so far here for now.

Quoted 17 lines
Quoted 10 lines
Quoted 9 lines

The cxgb4: driver is an example where although I did propose patches to use asynch firmware loading the entire registration of the netdevice would need to be changed as well in order to get this right. In short we have to scramble now to first identify drivers that have long init sequences and then fix. There's an assumption that we can easily fix drivers, this can take time. This series, although does take advantage of a kernel interface for other uses, lets us identify these drivers on the kernel ring buffer, so we can go and address fixing them with time.

Quoted 6 lines

Another thing that came up during asynch firmware review / integration on cxgb4 was that it would not be the only thing that would need to be fixed, the driver also has a ton of ports and at least as per my review the proper fix would be to use platform regiister stuff. It is a major rewrite of the driver but an example of a driver that needs quite a bit of work to meet this new 30 second driver requirement.

Quoted 2 lines

It shouldn't be using any platform driver stuff, it's a pci device, not a platform device.

Quoted 8 lines

The general PCI stuff is already used, the reason for suggesting the platform_device_register_simple() stuff is it has tons of ports and each port will register in turn a new struct netdevice, essentially one device can end up having tons of different network devices, the platform stuff would be to allow handling each netdevice candidate separately as part of the internal driver architecture, right now its some scary loop thing that in my eyes can be very error prone. drivers/net/ethernet/8390/ne.c. This discussion:

Quoted 7 lines

No, don't use platform devices as a "catch-all" for when you don't want to write your own bus code. This looks like a device-specific bus, great, write the code to do that, it can be done in about 200 lines, with comments and whitespace.

Only use platform devices for, wait for it, platform devices. And even then, reconsider and use something else if at all possible.

OK thanks I had asked for advice for this a while back on that old thread as I wasn't sure if that was the best.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Why not just put the initial "register the device" in a single-shot workqueue or thread or something like that so that modprobe returns instantly back with a success and all is fine?

That surely is possible but why not a general solution for such kludges?

Because the driver should be fixed. How hard would it be to do what I just suggested here, 20 lines added at most?

I appreciate the feedback, but don't look at me, I'd happy to go nutty on ripping things apart from hairy drivers, however Chelsie folks expressed concerns over major rework on the driver... so even if we did have something I expect things to take a while to bake / gain confidence from others.

This also just addresses this *one* Ethernet driver, there was that SCSI driver that created the original report -- Canonical merged Joseph's fix as a work around, there is no general solution for this yet, and again with that work around you won't find which drivers run into this issue. There may be others found later so this is why I resorted to the deferred workqueue as a solution for now and to enable us to annotate which drivers need fixing as I expect getting the fix done / everyone happy can take time.

Luis

#10 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 116 lines · Luis R. Rodriguez
Quoted 27 lines · Greg KH
Quoted 26 lines · Luis R. Rodriguez
Quoted 15 lines · Greg KH
Quoted 6 lines · Luis R. Rodriguez
Quoted 4 lines · Luis R. Rodriguez
Quoted 2 lines · Greg KH

So, what drivers are having problems in their init sequence, and why aren't they using async firmware loading?

Quoted 7 lines
Quoted 7 lines

Fixing drivers is one thing, fixing drivers *now* because *now* drivers are failing due to a regression is another thing and that's what we have now so lets just be clear on that. The 30 second rule is a major driver requirement change and it should not be taken slightly, all of a sudden this is a new requirement but you won't know that unless you're reading these threads or hit an issue. That's an issue in itself.

Quoted 2 lines

That "regression" is something that userspace has decided to do, not anything the kernel changed,

Actually commit 786235ee seems to have been the one that caused this issue, systemd would just send the SIGKILL and that change forced a bail on probe then hence Canonical's work around to modify kthread_create() to not leave upon SIGKILL:

http://thread.gmane.org/gmane.linux.ubuntu.devel.kernel.general/39123

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

so perhaps you should just patch your
modprobe and be done with it until you can fix up those drivers?

To ignore SIGKILL ?

Sorry, I thought this was a userspace change that caused this.

As it's a kernel change, well, maybe that patch should be reverted...

That's certainly viable. Oleg?

If its reverted we won't know which drivers are hitting over the new 30 second limit requirement imposed by userspace, which the culprit commit forces failure on probe now. This series at least would allow us to annotate which drivers are brake the 30 second init limit, and enable a work around alternative if we wish to not revert the commit. This series essentially should be considered an alternative solution to what was proposed initially by Joseph Salisbury, it may not be perfect but its a proposal. I welcome others.

Quoted 42 lines
Quoted 33 lines
Quoted 3 lines

And putting a horrid hack in the driver core, just because of some really bad drivers, is not ok, that's an interface _I_ will have to support for the next few decades.

I understand, hence review.

Quoted 2 lines

And it's going to take you a while to get something like this ever merged in anyway, odds are you can fix up the driver faster...

That requires quite a bit of changes and commitment and again, there are quite a bit of drivers that we can run into in the community, we've just spotted 2 so far here for now.

Quoted 17 lines
Quoted 10 lines
Quoted 9 lines

The cxgb4: driver is an example where although I did propose patches to use asynch firmware loading the entire registration of the netdevice would need to be changed as well in order to get this right. In short we have to scramble now to first identify drivers that have long init sequences and then fix. There's an assumption that we can easily fix drivers, this can take time. This series, although does take advantage of a kernel interface for other uses, lets us identify these drivers on the kernel ring buffer, so we can go and address fixing them with time.

Quoted 6 lines

Another thing that came up during asynch firmware review / integration on cxgb4 was that it would not be the only thing that would need to be fixed, the driver also has a ton of ports and at least as per my review the proper fix would be to use platform regiister stuff. It is a major rewrite of the driver but an example of a driver that needs quite a bit of work to meet this new 30 second driver requirement.

Quoted 2 lines

It shouldn't be using any platform driver stuff, it's a pci device, not a platform device.

Quoted 8 lines

The general PCI stuff is already used, the reason for suggesting the platform_device_register_simple() stuff is it has tons of ports and each port will register in turn a new struct netdevice, essentially one device can end up having tons of different network devices, the platform stuff would be to allow handling each netdevice candidate separately as part of the internal driver architecture, right now its some scary loop thing that in my eyes can be very error prone. drivers/net/ethernet/8390/ne.c. This discussion:

Quoted 7 lines

No, don't use platform devices as a "catch-all" for when you don't want to write your own bus code. This looks like a device-specific bus, great, write the code to do that, it can be done in about 200 lines, with comments and whitespace.

Only use platform devices for, wait for it, platform devices. And even then, reconsider and use something else if at all possible.

OK thanks I had asked for advice for this a while back on that old thread as I wasn't sure if that was the best.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Why not just put the initial "register the device" in a single-shot workqueue or thread or something like that so that modprobe returns instantly back with a success and all is fine?

That surely is possible but why not a general solution for such kludges?

Because the driver should be fixed. How hard would it be to do what I just suggested here, 20 lines added at most?

I appreciate the feedback, but don't look at me, I'd happy to go nutty on ripping things apart from hairy drivers, however Chelsie folks expressed concerns over major rework on the driver... so even if we did have something I expect things to take a while to bake / gain confidence from others.

Quoted 9 lines

This also just addresses this *one* Ethernet driver, there was that SCSI driver that created the original report -- Canonical merged Joseph's fix as a work around, there is no general solution for this yet, and again with that work around you won't find which drivers run into this issue. There may be others found later so this is why I resorted to the deferred workqueue as a solution for now and to enable us to annotate which drivers need fixing as I expect getting the fix done / everyone happy can take time.

Well ... from my POV there are two issues here:

The one is that systemd essentially nailed its internal worker timeout to 30 seconds. And there is no way of modifying that short of recompiling. Which should be fixed, so that at least one can modify this timeout.

The other one is that systemd killing a worker by sending SIGKILL, which will kill modprobe terminally. Which definitely needs to be fixed.

But if we have both issues resolved (eg by allowing udevd to use a longer timeout and revert the latter patch) we can identify the offending drivers _and_ get the system to boot by simply adding a kernel commandline parameter. Which is _far_ preferrable from a maintenance perspective.
Users tend to become annoyed if their system doesn't boot ...

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      zSeries & Storage
[email protected]			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
#11 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probefrom init

Quoted 9 lines · Luis R. Rodriguez
Quoted 6 lines · Greg KH
Quoted 1 line · Luis R. Rodriguez

To ignore SIGKILL ?

Sorry, I thought this was a userspace change that caused this.

As it's a kernel change, well, maybe that patch should be reverted...

That's certainly viable. Oleg?

I don't want to revert that patch.

I'm trying to reduce use of blocking operations that wait in unkillable state, for the OOM killer is optimistic enough to wait forever even if the OOM-killed process cannot be terminated due to having dependency on other threads that are waiting the OOM-killed process to terminate and release memory. Linux kernel is too optimistic about memory reclaim; memory allocation/reclaim deadlock is not detectable.

Quoted 9 lines

If its reverted we won't know which drivers are hitting over the new 30 second limit requirement imposed by userspace, which the culprit commit forces failure on probe now. This series at least would allow us to annotate which drivers are brake the 30 second init limit, and enable a work around alternative if we wish to not revert the commit. This series essentially should be considered an alternative solution to what was proposed initially by Joseph Salisbury, it may not be perfect but its a proposal. I welcome others.

(...snipped...)

Quoted 8 lines

This also just addresses this *one* Ethernet driver, there was that SCSI driver that created the original report -- Canonical merged Joseph's fix as a work around, there is no general solution for this yet, and again with that work around you won't find which drivers run into this issue. There may be others found later so this is why I resorted to the deferred workqueue as a solution for now and to enable us to annotate which drivers need fixing as I expect getting the fix done / everyone happy can take time.

If you want to know which drivers are hitting over the new 30 second limit requirement but don't want to break the boot, I think we can do "what Ubuntu chose as a work around" + "a warning message" like below.

kernel/kthread.c +21 -0
index c2390f4..43da2b1 100644
@@ -292,6 +292,26 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
 	 * new kernel thread.
 	 */
 	if (unlikely(wait_for_completion_killable(&done))) {
+		int i = 0;
+
+		/*
+		 * I got SIGKILL, but wait for 10 more seconds for completion
+		 * unless chosen by the OOM killer. This delay is there as a
+		 * workaround for boot failure caused by SIGKILL upon device
+		 * driver initialization timeout.
+		 */
+		if (!test_tsk_thread_flag(current, TIF_MEMDIE)) {
+			pr_warn("I already got SIGKILL but ignoring it up to "
+				"10 seconds, in case the caller can't survive "
+				"fail-immediately-upon-SIGKILL event. "
+				"Please make sure that the caller can survive "
+				"this event, for this delay will be removed "
+				"in the future.\n");
+			dump_stack();
+		}
+		while (i++ < 10 && !test_tsk_thread_flag(current, TIF_MEMDIE))
+			if (wait_for_completion_timeout(&done, HZ))
+				goto ready;
 		/*
 		 * If I was SIGKILLed before kthreadd (or new kernel thread)
 		 * calls complete(), leave the cleanup of this structure to
@@ -305,6 +325,7 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
 		 */
 		wait_for_completion(&done);
 	}
+ready:
 	task = create->result;
 	if (!IS_ERR(task)) {
 		static const struct sched_param param = { .sched_priority = 0 };
Quoted 11 lines · Hannes Reinecke

Well ... from my POV there are two issues here:

The one is that systemd essentially nailed its internal worker timeout to 30 seconds. And there is no way of modifying that short of recompiling. Which should be fixed, so that at least one can modify this timeout.

The other one is that systemd killing a worker by sending SIGKILL, which will kill modprobe terminally.
Which definitely needs to be fixed.

Quoted 6 lines

But if we have both issues resolved (eg by allowing udevd to use a longer timeout and revert the latter patch) we can identify the offending drivers _and_ get the system to boot by simply adding a kernel commandline parameter.
Which is _far_ preferrable from a maintenance perspective. Users tend to become annoyed if their system doesn't boot ...

The proposal which allows longer timeout was expired.
https://bugs.launchpad.net/bugs/1297248

#12 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probefrom init

Quoted 5 lines · Tetsuo Handa
Quoted 4 lines · Luis R. Rodriguez
Quoted 3 lines · Greg KH
Quoted 1 line · Luis R. Rodriguez

To ignore SIGKILL ?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Sorry, I thought this was a userspace change that caused this.

As it's a kernel change, well, maybe that patch should be reverted...

That's certainly viable. Oleg?

I don't want to revert that patch.

I agree that 786235ee should not be reverted to fix the problem of modules that receive sigkill from udev while they are initializing. In fact, while it may fix the case that was reported with mptsas, it would not fix cxgb4 because there are other code paths that check for pending signals and that abort (ex. pci_vpd_pci22_wait()).

Reverting 786235ee effectively works around the problem by making modprobe unkillable. The proper solution would be to make sure that udev does not send sigkill to modprobe in the first place, either by making the timeout longer or by making the module probe faster.

If you have other reasons for reverting 786235ee, then it's a different story.

maintainer
#16 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

In reply to Luis R. Rodriguez
Quoted 6 lines · Luis R. Rodriguez
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Why not just put the initial "register the device" in a single-shot workqueue or thread or something like that so that modprobe returns instantly back with a success and all is fine?

That surely is possible but why not a general solution for such kludges?

Quoted 8 lines
Quoted 2 lines

Because the driver should be fixed. How hard would it be to do what I just suggested here, 20 lines added at most?

I appreciate the feedback, but don't look at me, I'd happy to go nutty on ripping things apart from hairy drivers, however Chelsie folks expressed concerns over major rework on the driver... so even if we did have something I expect things to take a while to bake / gain confidence from others.

"rework"? Heh, here's a patch that adds 10 lines to the mptsas driver that should also work for any other driver as well. Why not just do this instead?

Quoted 3 lines

This also just addresses this *one* Ethernet driver, there was that SCSI driver that created the original report -- Canonical merged Joseph's fix as a work around,

What fix was that?

Quoted 2 lines

there is no general solution for this yet, and again with that work around you won't find which drivers run into this issue.

Great, fix them as they are found, that's fine. Again, don't add stuff to the driver core to paper over crappy drivers, I'm not going to take that type of change. I _only_ took the defer binding code as there was no other way for an individual driver to deal with things if it's resources were not present yet due to binding order in the system.

So, anyone care to test the patch below on a system that has this problem to let me know if it would work or not? Odds are, this should be a workqueue, to make it cleaner, but a kthread is just so easy to use...

thanks,

greg k-h

drivers/message/fusion/mptsas.c +12 -2
index 711fcb5cec87..4fd4f36a2d9e 100644
@@ -51,6 +51,7 @@
 #include <linux/jiffies.h>
 #include <linux/workqueue.h>
 #include <linux/delay.h>	/* for mdelay */
+#include <linux/kthread.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -5393,8 +5394,7 @@ static struct pci_driver mptsas_driver = {
 #endif
 };
 
-static int __init
-mptsas_init(void)
+static int mptsas_real_init(void *data)
 {
 	int error;
 
@@ -5429,9 +5429,19 @@ mptsas_init(void)
 	return error;
 }
 
+static struct task_struct *init_thread;
+
+static int __init
+mptsas_init(void)
+{
+	init_thread = kthread_run(mptsas_real_init, NULL, "mptsas_init");
+	return 0;
+}
+
 static void __exit
 mptsas_exit(void)
 {
+	kthread_stop(init_thread);
 	pci_unregister_driver(&mptsas_driver);
 	sas_release_transport(mptsas_transport_template);
 
#17 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 16 lines · Greg KH
Quoted 6 lines · Luis R. Rodriguez
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Why not just put the initial "register the device" in a single-shot workqueue or thread or something like that so that modprobe returns instantly back with a success and all is fine?

That surely is possible but why not a general solution for such kludges?

Quoted 8 lines
Quoted 2 lines

Because the driver should be fixed. How hard would it be to do what I just suggested here, 20 lines added at most?

I appreciate the feedback, but don't look at me, I'd happy to go nutty on ripping things apart from hairy drivers, however Chelsie folks expressed concerns over major rework on the driver... so even if we did have something I expect things to take a while to bake / gain confidence from others.

Quoted 3 lines

"rework"? Heh, here's a patch that adds 10 lines to the mptsas driver that should also work for any other driver as well. Why not just do this instead?

That's not a rework, that's a kludge, doing something similar for other drivers would be replicating kludges, the deferred probe use was trying to generalize a kludge with 3 lines of code. But I'm no not yet convinced its the best solution now.

Quoted 5 lines
Quoted 3 lines

This also just addresses this *one* Ethernet driver, there was that SCSI driver that created the original report -- Canonical merged Joseph's fix as a work around,

What fix was that?

https://launchpadlibrarian.net/169714201/kthread-Do-not-leave-kthread_create-immediately.patch

It was reviewed and Oleg preferred the timeout instead be reviewed on systemd devel mailing list. That didn't go anywhere but today Hannes posted a patch and that got merged. Its still not solving all issues though as it lets us override the timeout value, systems / drivers can still crash without a long timeout.

Quoted 4 lines
Quoted 2 lines

there is no general solution for this yet, and again with that work around you won't find which drivers run into this issue.

Great, fix them as they are found, that's fine.

Are we really OK in letting distributions have to deal with crashes because of this new driver 30 second timeout ? I think warning about it would be better and more friendlier, no? What gains do we have to kill the damn thing?

Quoted 5 lines

Again, don't add stuff
to the driver core to paper over crappy drivers, I'm not going to take that type of change. I _only_ took the defer binding code as there was no other way for an individual driver to deal with things if it's resources were not present yet due to binding order in the system.

Ok but its a bit unfair to force killing drivers over a new driver 30 second timeout requirement for a change that was made implicitly through a series of collateral changes.

Quoted 40 lines

So, anyone care to test the patch below on a system that has this problem to let me know if it would work or not? Odds are, this should be a workqueue, to make it cleaner, but a kthread is just so easy to use...

thanks,

greg k-h

drivers/message/fusion/mptsas.c +7 -2
index 711fcb5cec87..4fd4f36a2d9e 100644
@@ -51,6 +51,7 @@
 #include <linux/jiffies.h>
 #include <linux/workqueue.h>
 #include <linux/delay.h>	/* for mdelay */
+#include <linux/kthread.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -5393,8 +5394,7 @@ static struct pci_driver mptsas_driver = {
 #endif
 };
 
-static int __init
-mptsas_init(void)
+static int mptsas_real_init(void *data)
 {
 	int error;
 
@@ -5429,9 +5429,19 @@ mptsas_init(void)
 	return error;
 }
 
+static struct task_struct *init_thread;
+
+static int __init
+mptsas_init(void)
+{

drivers/message/fusion/mptsas.c mptsas_init(void) · line 5446

Quoted 10 lines
drivers/message/fusion/mptsas.c +5 -0
+	init_thread = kthread_run(mptsas_real_init, NULL, "mptsas_init");
+	return 0;
+}
+
 static void __exit
 mptsas_exit(void)
 {
+	kthread_stop(init_thread);
 	pci_unregister_driver(&mptsas_driver);
 	sas_release_transport(mptsas_transport_template);

So we're OK to see these kludges sprinkled over the kernel instead of genrealizing somethiing for them in the meantime?

Luis

maintainer
#18 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 17 lines · Luis R. Rodriguez
Quoted 16 lines · Greg KH
Quoted 14 lines · Luis R. Rodriguez
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Why not just put the initial "register the device" in a single-shot workqueue or thread or something like that so that modprobe returns instantly back with a success and all is fine?

That surely is possible but why not a general solution for such kludges?

Because the driver should be fixed. How hard would it be to do what I just suggested here, 20 lines added at most?

I appreciate the feedback, but don't look at me, I'd happy to go nutty on ripping things apart from hairy drivers, however Chelsie folks expressed concerns over major rework on the driver... so even if we did have something I expect things to take a while to bake / gain confidence from others.

Quoted 8 lines
Quoted 3 lines

"rework"? Heh, here's a patch that adds 10 lines to the mptsas driver that should also work for any other driver as well. Why not just do this instead?

That's not a rework, that's a kludge, doing something similar for other drivers would be replicating kludges, the deferred probe use was trying to generalize a kludge with 3 lines of code. But I'm no not yet convinced its the best solution now.

I'm not saying it's pretty, but it confied to just the broken module, and also, it's obvious what needs to be fixed if someone cares.

It sounds like no one cares about these moduls :)

Adding it to the driver core ensures that the drivers will _never_ be changed, which isn't ok with me, sorry.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

This also just addresses this *one* Ethernet driver, there was that SCSI driver that created the original report -- Canonical merged Joseph's fix as a work around,

What fix was that?

Quoted 7 lines

https://launchpadlibrarian.net/169714201/kthread-Do-not-leave-kthread_create-immediately.patch

It was reviewed and Oleg preferred the timeout instead be reviewed on systemd devel mailing list. That didn't go anywhere but today Hannes posted a patch and that got merged. Its still not solving all issues though as it lets us override the timeout value, systems / drivers can still crash without a long timeout.

Great, work it out with them, again, stay away from the driver core for this...

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

there is no general solution for this yet, and again with that work around you won't find which drivers run into this issue.

Great, fix them as they are found, that's fine.

Are we really OK in letting distributions have to deal with crashes because of this new driver 30 second timeout ?

If you don't want to, then revert the kernel change that caused it for your distro kernels.

Quoted 2 lines

I think warning about it would be better and more friendlier, no? What gains do we have to kill the damn thing?

Take it up with the owners of that code...

Quoted 9 lines
Quoted 5 lines

Again, don't add stuff
to the driver core to paper over crappy drivers, I'm not going to take that type of change. I _only_ took the defer binding code as there was no other way for an individual driver to deal with things if it's resources were not present yet due to binding order in the system.

Ok but its a bit unfair to force killing drivers over a new driver 30 second timeout requirement for a change that was made implicitly through a series of collateral changes.

I'm not disagreeing with that, but hey, life isn't fair, and things needs to get fixed all the time...

I say fix it _properly_ by fixing the drivers.

best of luck,

greg k-h

#13 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probefrom init

In reply to Benjamin Poirier
Quoted 20 lines · Benjamin Poirier
Quoted 5 lines · Tetsuo Handa
Quoted 4 lines · Luis R. Rodriguez
Quoted 3 lines · Greg KH
Quoted 1 line · Luis R. Rodriguez

To ignore SIGKILL ?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Sorry, I thought this was a userspace change that caused this.

As it's a kernel change, well, maybe that patch should be reverted...

That's certainly viable. Oleg?

I don't want to revert that patch.

I agree that 786235ee should not be reverted to fix the problem of modules that receive sigkill from udev while they are initializing. In fact, while it may fix the case that was reported with mptsas, it would not fix cxgb4 because there are other code paths that check for pending signals and that abort (ex. pci_vpd_pci22_wait()).

Quoted 4 lines

Reverting 786235ee effectively works around the problem by making modprobe unkillable. The proper solution would be to make sure that udev does not send sigkill to modprobe in the first place, either by making the timeout longer or by making the module probe faster.

Hannes sent a patch for systemd that enables a kernel command line override for the timeout, this however still means some drivers can fail and distros would have to use the longest known timeout for the supported kernel.

http://lists.freedesktop.org/archives/systemd-devel/2014-July/021601.html

Tetsuo is it possible / desirable to allow tasks to not kill unless the reason is OOM ? Its unclear if this was discussed before, sorry if it was, have just been a bit busy today to review the archive / discussions on this.

To *fatally* kill a module if it does not reach a time limit is rather harsh without properly thinking about the entire picture of possible issues and reasons for the timeout and also consequences of the kill, essentially what has happened is we are breaking ome boots on at least storage drivers that take long, and now networking on one driver at least. I think we all agree these drivers need fixing, there is no one arguing over that. but to allow a timeout to fatally kill the damn system seems rather stupid too if what we want to do is to get drivers fixed. It is both *hard to debug* (see the bug reports) and simply just irritating to users.

The original commit on systemd that introduced the timeout is commit e64fae55 but the purpose of that commit was to send to hell drivers that are not using asynch firmware loading, but this is not the only reason why some drivers would hit the timeout limit. As Benjamin notes the cxgb4 driver issue is a bit more complex than that, as I've noted I've sent some initial patches to help with asynch firmware but proper integration is a bit more complex and even if we remove firmware out of the picture (this was tried) the driver *still* takes more than 30 seconds to load and fails as Benjamin indicated. As Greg notes a bus driver stub can be written -- but this will take a bit of time folks, even if its a day or two, or a week or to just test things. In the meantime we simply have broken systems / networking as collateral to a CVE patch that in turn allowed systemd to also kill drivers on a 30 second timeout under the assumption it was all asynch firmware loading. Collateral should not be the way to introduce new driver requirements, specially if its breaking boots. All I'm saying is we should just try to warn here, and not be fatal.

Hannes' patch will allow us to override the timeout through the comand line but we're essentially still killing drivers that don't meet the new implicit rules. This doesn't seem optimal and hence the discussion.

Luis

#14 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probefrom init

Quoted 3 lines · Luis R. Rodriguez

Tetsuo is it possible / desirable to allow tasks to not kill unless the reason is OOM ? Its unclear if this was discussed before, sorry if it was, have just been a bit busy today to review the archive / discussions on this.

Are we aware that the 10 seconds timeout after SIGKILL is not the duration between the beginning of module loading and the end of kthread_create() but the duration to wait for kthreadd to create a new kernel thread?

If the kthreadd is unable to create a new kernel thread within 10 seconds, something very bad is happening. For example, memory allocation deadlock sequence shown below might be happening.

(1) process1 holds a mutex using mutex_lock().
(2) process1 calls kthread_create() and enters into killable wait state at wait_for_completion_killable().
(3) kthreadd calls kernel_thread() and enters into oom-killable busy loop due to out of memory at alloc_pages_nodemask().
(4) process2 is chosen by the OOM killer, but process2 is unable to terminate because process2 is waiting in unkillable state at mutex_lock() which was held by process1 at (1).
(5) kthreadd continues busy loop because process2 does not release memory and the OOM killer does not kill more processes.
(6) process1 continues waiting in oom-killable state because process1 is not chosen by the OOM killer.

See? The system will remain unresponding unless somebody releases memory that is enough for kthreadd to complete. We cannot teach process1 that process1 needs to give up waiting for kthreadd and call mutex_unlock() in order to allow process2 to terminate. Also, we cannot teach the OOM killer that process1 needs to be oom-killed after process2 is oom-killed.

Making the 10 seconds timeout after SIGKILL longer is safe. Changing it to no-timeout-unless-oom-killed is unsafe.

#15 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probefrom init

Quoted 26 lines · Tetsuo Handa
Quoted 3 lines · Luis R. Rodriguez

Tetsuo is it possible / desirable to allow tasks to not kill unless the reason is OOM ? Its unclear if this was discussed before, sorry if it was, have just been a bit busy today to review the archive / discussions on this.

Are we aware that the 10 seconds timeout after SIGKILL is not the duration between the beginning of module loading and the end of kthread_create() but the duration to wait for kthreadd to create a new kernel thread?

If the kthreadd is unable to create a new kernel thread within 10 seconds, something very bad is happening. For example, memory allocation deadlock sequence shown below might be happening.

(1) process1 holds a mutex using mutex_lock().
(2) process1 calls kthread_create() and enters into killable wait state at wait_for_completion_killable().
(3) kthreadd calls kernel_thread() and enters into oom-killable busy loop due to out of memory at alloc_pages_nodemask().
(4) process2 is chosen by the OOM killer, but process2 is unable to terminate because process2 is waiting in unkillable state at mutex_lock() which was held by process1 at (1).
(5) kthreadd continues busy loop because process2 does not release memory and the OOM killer does not kill more processes.
(6) process1 continues waiting in oom-killable state because process1 is not chosen by the OOM killer.

Quoted 2 lines

See? The system will remain unresponding unless somebody releases memory that is enough for kthreadd to complete.

I see but we're talking about large systems with gobs of memory so I'm pretty sure memory should not be the issue here.

Quoted 7 lines

We cannot teach process1 that
process1 needs to give up waiting for kthreadd and call mutex_unlock() in order to allow process2 to terminate. Also, we cannot teach the OOM killer that process1 needs to be oom-killed after process2 is oom-killed.

Making the 10 seconds timeout after SIGKILL longer is safe. Changing it to no-timeout-unless-oom-killed is unsafe.

To be clear we have *not* merged the 10 second workaround:

https://launchpadlibrarian.net/169714201/kthread-Do-not-leave-kthread_create-immediately.patch

and come to think of it the work aroaund is aligned with what I was thinking *without *waiting for 10 seconds, but my question was whether or not it was reasonable to have the process request to go through this excemption. So we would not do this all the time, but only for processes that would request this, in this case modprobe.

Luis

maintainer
#19 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

In reply to Luis R. Rodriguez

From: "Luis R. Rodriguez" <[email protected]>
Date: Mon, 28 Jul 2014 11:28:28 -0700

Quoted 24 lines

Tetsuo bisected and found that commit 786235ee "kthread: make kthread_create() killable" modified kthread_create() to bail as soon as SIGKILL is received. This is causing some issues with some drivers and at times boot. Joseph then found that failures occur as the systemd-udevd process sends SIGKILL to modprobe if probe on a driver takes over 30 seconds. When this happens probe will fail on any driver, its why booting on some system will fail if the driver happens to be a storage related driver. Some folks have suggested fixing this by modifying kthread_create() to not leave upon SIGKILL [3], upon review Oleg rejected this change and the discussion was punted out to systemd to see if the default timeout could be increased from 30 seconds to 120. The opinion of the systemd maintainers is that the driver's behavior should be fixed [4]. Linus seems to agree [5], however more recently even networking drivers have been reported to fail on probe since just writing the firmware to a device and kicking it can take easy over 60 seconds [6]. Benjamim was able to trace the issues recently reported on cxgb4 down to the same systemd-udevd 30 second timeout [6].

This is an alternative solution which enables drivers that are known to take long to use deferred probe workqueue. This avoids the 30 second timeout and lets us annotate drivers with long init sequences.

Quoted 7 lines

As drivers determine a component is not yet available and needs to defer probe you'll be notified this happen upon init for each device but now with a message such as:

pci 0000:03:00.0: Driver cxgb4 requests probe deferral on init

You should see one of these per struct device probed.

It seems we're still discussing this.

I think I understand all of the underlying issues, and what I'll say is that perhaps we should use what Greg KH requested but via a helper that is easy to grep for.

I don't care if it's something like "module_long_probe_init()" and "module_long_probe_exit()", but it just needs to be some properly named interface which does the whole kthread or whatever bit.

Thanks.

#20 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 37 lines · David Miller

From: "Luis R. Rodriguez" <[email protected]>
Date: Mon, 28 Jul 2014 11:28:28 -0700

Quoted 24 lines

Tetsuo bisected and found that commit 786235ee "kthread: make kthread_create() killable" modified kthread_create() to bail as soon as SIGKILL is received. This is causing some issues with some drivers and at times boot. Joseph then found that failures occur as the systemd-udevd process sends SIGKILL to modprobe if probe on a driver takes over 30 seconds. When this happens probe will fail on any driver, its why booting on some system will fail if the driver happens to be a storage related driver. Some folks have suggested fixing this by modifying kthread_create() to not leave upon SIGKILL [3], upon review Oleg rejected this change and the discussion was punted out to systemd to see if the default timeout could be increased from 30 seconds to 120. The opinion of the systemd maintainers is that the driver's behavior should be fixed [4]. Linus seems to agree [5], however more recently even networking drivers have been reported to fail on probe since just writing the firmware to a device and kicking it can take easy over 60 seconds [6]. Benjamim was able to trace the issues recently reported on cxgb4 down to the same systemd-udevd 30 second timeout [6].

This is an alternative solution which enables drivers that are known to take long to use deferred probe workqueue. This avoids the 30 second timeout and lets us annotate drivers with long init sequences.

Quoted 7 lines

As drivers determine a component is not yet available and needs to defer probe you'll be notified this happen upon init for each device but now with a message such as:

pci 0000:03:00.0: Driver cxgb4 requests probe deferral on init

You should see one of these per struct device probed.

It seems we're still discussing this.

Quoted 7 lines

I think I understand all of the underlying issues, and what I'll say is that perhaps we should use what Greg KH requested but via a helper that is easy to grep for.

I don't care if it's something like "module_long_probe_init()" and "module_long_probe_exit()", but it just needs to be some properly named interface which does the whole kthread or whatever bit.

I've tested the alternative kthread_run() proposal but unfortunately it does not help resolve the issue, the timeout is still hit and a SIGKILL still kills the driver probe. Please let me know how you'd all like us to proceed, these defer probe patches do help cure the issue though.

I should also note that these work around patches can only be done once we already know a driver fails to go over the timeout, root causing and associating driver issues to the timeout has been very difficult with a few drivers already, for this reason I've submitted a change for systemd to issue a warning instead of killing kmod usage on udev after a timeout, that would make this regression non-fatal, and let us more easily then hunt drivers that need fixing much easily [0] [1]. As noted we'd still want to have drivers easily annotated which require fixing, this orignal series would allow us to do that by hunting for delay_probe. If there alternative and preferred strategies please let me know.

[0] http://lists.freedesktop.org/archives/systemd-devel/2014-August/021812.html
[1] http://lists.freedesktop.org/archives/systemd-devel/2014-August/021821.html

Luis

maintainer
#21 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 42 lines · Luis R. Rodriguez
Quoted 41 lines · David Miller

From: "Luis R. Rodriguez" <[email protected]>
Date: Mon, 28 Jul 2014 11:28:28 -0700

Quoted 24 lines

Tetsuo bisected and found that commit 786235ee "kthread: make kthread_create() killable" modified kthread_create() to bail as soon as SIGKILL is received. This is causing some issues with some drivers and at times boot. Joseph then found that failures occur as the systemd-udevd process sends SIGKILL to modprobe if probe on a driver takes over 30 seconds. When this happens probe will fail on any driver, its why booting on some system will fail if the driver happens to be a storage related driver. Some folks have suggested fixing this by modifying kthread_create() to not leave upon SIGKILL [3], upon review Oleg rejected this change and the discussion was punted out to systemd to see if the default timeout could be increased from 30 seconds to 120. The opinion of the systemd maintainers is that the driver's behavior should be fixed [4]. Linus seems to agree [5], however more recently even networking drivers have been reported to fail on probe since just writing the firmware to a device and kicking it can take easy over 60 seconds [6]. Benjamim was able to trace the issues recently reported on cxgb4 down to the same systemd-udevd 30 second timeout [6].

This is an alternative solution which enables drivers that are known to take long to use deferred probe workqueue. This avoids the 30 second timeout and lets us annotate drivers with long init sequences.

Quoted 7 lines

As drivers determine a component is not yet available and needs to defer probe you'll be notified this happen upon init for each device but now with a message such as:

pci 0000:03:00.0: Driver cxgb4 requests probe deferral on init

You should see one of these per struct device probed.

It seems we're still discussing this.

I think I understand all of the underlying issues, and what I'll say is that perhaps we should use what Greg KH requested but via a helper that is easy to grep for.

Quoted 8 lines
Quoted 3 lines

I don't care if it's something like "module_long_probe_init()" and "module_long_probe_exit()", but it just needs to be some properly named interface which does the whole kthread or whatever bit.

I've tested the alternative kthread_run() proposal but unfortunately it does not help resolve the issue, the timeout is still hit and a SIGKILL still kills the driver probe. Please let me know how you'd all like us to proceed, these defer probe patches do help cure the issue though.

Why doesn't it work? Doesn't modprobe come right back and the init sequence still takes a while to run? What exactly fails?

thanks,

greg k-h

#22 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probefrom init

Quoted 2 lines · Greg KH

Why doesn't it work? Doesn't modprobe come right back and the init sequence still takes a while to run? What exactly fails?

I guess ...

Quoted 11 lines
(quoted diff) +6 -0
@@ -5429,9 +5429,19 @@ mptsas_init(void)
 	return error;
 }
 
+static struct task_struct *init_thread;
+
+static int __init
+mptsas_init(void)
+{
+	init_thread = kthread_run(mptsas_real_init, NULL, "mptsas_init");

Review mptsas_init(void) · line 5447

Quoted 10 lines
(quoted diff) +4 -0
+	return 0;
+}
+
 static void __exit
 mptsas_exit(void)
 {
+	kthread_stop(init_thread);
 	pci_unregister_driver(&mptsas_driver);
 	sas_release_transport(mptsas_transport_template);
 

kthread_run() can fail. sas_attach_transport() and/or pci_register_driver() in mptsas_real_init() can fail. Caller process may fail to continue if sas_attach_transport() and pci_register_driver() in mptsas_real_init() has not completed yet.

kthread_stop() must not be called when kthread_run() failed. pci_unregister_driver() and/or sas_release_transport() must not be called when mptsas_real_init() did not return 0 (or has not returned 0 yet).

#23 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

In reply to Greg KH
Quoted 47 lines · Greg KH
Quoted 46 lines · Luis R. Rodriguez
Quoted 44 lines · David Miller

From: "Luis R. Rodriguez" <[email protected]>
Date: Mon, 28 Jul 2014 11:28:28 -0700

Quoted 24 lines

Tetsuo bisected and found that commit 786235ee "kthread: make kthread_create() killable" modified kthread_create() to bail as soon as SIGKILL is received. This is causing some issues with some drivers and at times boot. Joseph then found that failures occur as the systemd-udevd process sends SIGKILL to modprobe if probe on a driver takes over 30 seconds. When this happens probe will fail on any driver, its why booting on some system will fail if the driver happens to be a storage related driver. Some folks have suggested fixing this by modifying kthread_create() to not leave upon SIGKILL [3], upon review Oleg rejected this change and the discussion was punted out to systemd to see if the default timeout could be increased from 30 seconds to 120. The opinion of the systemd maintainers is that the driver's behavior should be fixed [4]. Linus seems to agree [5], however more recently even networking drivers have been reported to fail on probe since just writing the firmware to a device and kicking it can take easy over 60 seconds [6]. Benjamim was able to trace the issues recently reported on cxgb4 down to the same systemd-udevd 30 second timeout [6].

This is an alternative solution which enables drivers that are known to take long to use deferred probe workqueue. This avoids the 30 second timeout and lets us annotate drivers with long init sequences.

Quoted 7 lines

As drivers determine a component is not yet available and needs to defer probe you'll be notified this happen upon init for each device but now with a message such as:

pci 0000:03:00.0: Driver cxgb4 requests probe deferral on init

You should see one of these per struct device probed.

It seems we're still discussing this.

I think I understand all of the underlying issues, and what I'll say is that perhaps we should use what Greg KH requested but via a helper that is easy to grep for.

I don't care if it's something like "module_long_probe_init()" and "module_long_probe_exit()", but it just needs to be some properly named interface which does the whole kthread or whatever bit.

Quoted 7 lines
Quoted 4 lines

I've tested the alternative kthread_run() proposal but unfortunately it does not help resolve the issue, the timeout is still hit and a SIGKILL still kills the driver probe. Please let me know how you'd all like us to proceed, these defer probe patches do help cure the issue though.

Why doesn't it work? Doesn't modprobe come right back and the init sequence still takes a while to run? What exactly fails?

systemd uses kmod kmod_module_probe_insert_module(), what I see is that using kthread_run() as a work around still causes probe to fail on a driver that otherwise would work fine if all you do is sprinkle ssleep(33) (seconds) on the init sequence. To see the issue you can test this on any of your network drivers that get loaded automatically, I did my testing with iwlwifi by purposely breaking it and then using the work around. It seems the probe somehow still gets killed as before, I haven't debugged this further.

For example by breaking and fixing iwlwifi this yields:

ergon:~ # journalctl -b -0 -u systemd-udevd

-- Logs begin at Mon 2014-08-04 21:55:28 EDT, end at Sun 2014-08-10 10:50:14 EDT. --

Aug 10 10:48:49 ergon systemd-udevd[257]: specified group 'input' unknown
Aug 10 10:48:55 ergon mtp-probe[493]: checking bus 3, device 2: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-7"
Aug 10 10:48:55 ergon mtp-probe[492]: checking bus 3, device 4: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-12"
Aug 10 10:49:24 ergon systemd-udevd[465]: seq 1755 '/devices/pci0000:00/0000:00:1c.1/0000:03:00.0' killed

ergon:~ # dmesg | grep iwlwifi

[   10.315538] iwlwifi Going to sleep for 33 seconds
[   43.323958] iwlwifi Done sleeping
[   43.324400] iwlwifi 0000:03:00.0: irq 50 for MSI/MSI-X
[   43.324534] iwlwifi 0000:03:00.0: Error allocating IRQ 50
[   43.326951] iwlwifi: probe of 0000:03:00.0 failed with error -4

The patch used:

drivers/net/wireless/iwlwifi/mvm/ops.c +11 -1
index 610dbcb..65e0ab2 100644
@@ -63,6 +63,7 @@
 #include <linux/module.h>
 #include <linux/vmalloc.h>
 #include <net/mac80211.h>
+#include <linux/kthread.h>
 
 #include "iwl-notif-wait.h"
 #include "iwl-trans.h"
@@ -111,7 +112,7 @@ MODULE_PARM_DESC(power_scheme,
 /*
  * module init and exit functions
  */
-static int __init iwl_mvm_init(void)
+static int iwl_mvm_init_real(void *arg)
 {
 	int ret;
 
@@ -130,12 +131,21 @@ static int __init iwl_mvm_init(void)
 
 	return ret;
 }
+
+static struct task_struct *init_thread;
+
+static int __init iwl_mvm_init(void)
+{
+	init_thread = kthread_run(iwl_mvm_init_real, NULL, "iwl_mvm_init");
+	return 0;
+}
 module_init(iwl_mvm_init);
 
 static void __exit iwl_mvm_exit(void)
 {
 	iwl_opmode_deregister("iwlmvm");
 	iwl_mvm_rate_control_unregister();
+	kthread_stop(init_thread);
 }
 module_exit(iwl_mvm_exit);
 
drivers/net/wireless/iwlwifi/pcie/drv.c +4 -0
index 98950e4..c1f2823 100644
@@ -489,6 +489,10 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	struct iwl_trans_pcie *trans_pcie;
 	int ret;
 
+	printk("iwlwifi Going to sleep for 33 seconds\n");
+	ssleep(33);
+	printk("iwlwifi Done sleeping\n");
+
 	iwl_trans = iwl_trans_pcie_alloc(pdev, ent, cfg);
 	if (IS_ERR(iwl_trans))
 		return PTR_ERR(iwl_trans);
#24 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

At Sun, 10 Aug 2014 16:58:02 +0200,

Quoted 133 lines · Luis R. Rodriguez
Quoted 47 lines · Greg KH
Quoted 46 lines · Luis R. Rodriguez
Quoted 44 lines · David Miller

From: "Luis R. Rodriguez" <[email protected]>
Date: Mon, 28 Jul 2014 11:28:28 -0700

Quoted 24 lines

Tetsuo bisected and found that commit 786235ee "kthread: make kthread_create() killable" modified kthread_create() to bail as soon as SIGKILL is received. This is causing some issues with some drivers and at times boot. Joseph then found that failures occur as the systemd-udevd process sends SIGKILL to modprobe if probe on a driver takes over 30 seconds. When this happens probe will fail on any driver, its why booting on some system will fail if the driver happens to be a storage related driver. Some folks have suggested fixing this by modifying kthread_create() to not leave upon SIGKILL [3], upon review Oleg rejected this change and the discussion was punted out to systemd to see if the default timeout could be increased from 30 seconds to 120. The opinion of the systemd maintainers is that the driver's behavior should be fixed [4]. Linus seems to agree [5], however more recently even networking drivers have been reported to fail on probe since just writing the firmware to a device and kicking it can take easy over 60 seconds [6]. Benjamim was able to trace the issues recently reported on cxgb4 down to the same systemd-udevd 30 second timeout [6].

This is an alternative solution which enables drivers that are known to take long to use deferred probe workqueue. This avoids the 30 second timeout and lets us annotate drivers with long init sequences.

Quoted 7 lines

As drivers determine a component is not yet available and needs to defer probe you'll be notified this happen upon init for each device but now with a message such as:

pci 0000:03:00.0: Driver cxgb4 requests probe deferral on init

You should see one of these per struct device probed.

It seems we're still discussing this.

I think I understand all of the underlying issues, and what I'll say is that perhaps we should use what Greg KH requested but via a helper that is easy to grep for.

I don't care if it's something like "module_long_probe_init()" and "module_long_probe_exit()", but it just needs to be some properly named interface which does the whole kthread or whatever bit.

Quoted 7 lines
Quoted 4 lines

I've tested the alternative kthread_run() proposal but unfortunately it does not help resolve the issue, the timeout is still hit and a SIGKILL still kills the driver probe. Please let me know how you'd all like us to proceed, these defer probe patches do help cure the issue though.

Why doesn't it work? Doesn't modprobe come right back and the init sequence still takes a while to run? What exactly fails?

systemd uses kmod kmod_module_probe_insert_module(), what I see is that using kthread_run() as a work around still causes probe to fail on a driver that otherwise would work fine if all you do is sprinkle ssleep(33) (seconds) on the init sequence. To see the issue you can test this on any of your network drivers that get loaded automatically, I did my testing with iwlwifi by purposely breaking it and then using the work around. It seems the probe somehow still gets killed as before, I haven't debugged this further.

For example by breaking and fixing iwlwifi this yields:

ergon:~ # journalctl -b -0 -u systemd-udevd

-- Logs begin at Mon 2014-08-04 21:55:28 EDT, end at Sun 2014-08-10 10:50:14 EDT. --

Aug 10 10:48:49 ergon systemd-udevd[257]: specified group 'input' unknown
Aug 10 10:48:55 ergon mtp-probe[493]: checking bus 3, device 2: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-7"
Aug 10 10:48:55 ergon mtp-probe[492]: checking bus 3, device 4: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-12"
Aug 10 10:49:24 ergon systemd-udevd[465]: seq 1755 '/devices/pci0000:00/0000:00:1c.1/0000:03:00.0' killed

ergon:~ # dmesg | grep iwlwifi

[   10.315538] iwlwifi Going to sleep for 33 seconds
[   43.323958] iwlwifi Done sleeping
[   43.324400] iwlwifi 0000:03:00.0: irq 50 for MSI/MSI-X
[   43.324534] iwlwifi 0000:03:00.0: Error allocating IRQ 50
[   43.326951] iwlwifi: probe of 0000:03:00.0 failed with error -4

The patch used:

drivers/net/wireless/iwlwifi/mvm/ops.c +11 -1
index 610dbcb..65e0ab2 100644
@@ -63,6 +63,7 @@
 #include <linux/module.h>
 #include <linux/vmalloc.h>
 #include <net/mac80211.h>
+#include <linux/kthread.h>
 
 #include "iwl-notif-wait.h"
 #include "iwl-trans.h"
@@ -111,7 +112,7 @@ MODULE_PARM_DESC(power_scheme,
 /*
  * module init and exit functions
  */
-static int __init iwl_mvm_init(void)
+static int iwl_mvm_init_real(void *arg)
 {
 	int ret;
 
@@ -130,12 +131,21 @@ static int __init iwl_mvm_init(void)
 
 	return ret;
 }
+
+static struct task_struct *init_thread;
+
+static int __init iwl_mvm_init(void)
+{
+	init_thread = kthread_run(iwl_mvm_init_real, NULL, "iwl_mvm_init");
+	return 0;
+}
 module_init(iwl_mvm_init);
 
 static void __exit iwl_mvm_exit(void)
 {
 	iwl_opmode_deregister("iwlmvm");
 	iwl_mvm_rate_control_unregister();
+	kthread_stop(init_thread);
 }
 module_exit(iwl_mvm_exit);
 
drivers/net/wireless/iwlwifi/pcie/drv.c +0 -0
index 98950e4..c1f2823 100644

drivers/net/wireless/iwlwifi/pcie/drv.c static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 498

Quoted 10 lines
drivers/net/wireless/iwlwifi/pcie/drv.c +4 -0
@@ -489,6 +489,10 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	struct iwl_trans_pcie *trans_pcie;
 	int ret;
 
+	printk("iwlwifi Going to sleep for 33 seconds\n");
+	ssleep(33);
+	printk("iwlwifi Done sleeping\n");
+
 	iwl_trans = iwl_trans_pcie_alloc(pdev, ent, cfg);
 	if (IS_ERR(iwl_trans))
 		return PTR_ERR(iwl_trans);

I guess that the problem is that you moved the init stuff into kthread for iwlmvm module, but the stall happens in a different module, iwlwifi. So iwlwifi is killed as expected. You had to put the kthread hack into pcie/drv.c instead.

(Actually, it's interesting how the SIGKILL error is reported back;
it failed at request_threaded_irq(). If this were the normal irq handler, it might have worked :)

Takashi

#25 lore raw

Re: [PATCH v2 2/4] driver core: enable drivers to use deferred probe from init

Quoted 136 lines · Takashi Iwai
Quoted 135 lines · Luis R. Rodriguez
Quoted 47 lines · Greg KH
Quoted 46 lines · Luis R. Rodriguez
Quoted 44 lines · David Miller

From: "Luis R. Rodriguez" <[email protected]>
Date: Mon, 28 Jul 2014 11:28:28 -0700

Quoted 24 lines

Tetsuo bisected and found that commit 786235ee "kthread: make kthread_create() killable" modified kthread_create() to bail as soon as SIGKILL is received. This is causing some issues with some drivers and at times boot. Joseph then found that failures occur as the systemd-udevd process sends SIGKILL to modprobe if probe on a driver takes over 30 seconds. When this happens probe will fail on any driver, its why booting on some system will fail if the driver happens to be a storage related driver. Some folks have suggested fixing this by modifying kthread_create() to not leave upon SIGKILL [3], upon review Oleg rejected this change and the discussion was punted out to systemd to see if the default timeout could be increased from 30 seconds to 120. The opinion of the systemd maintainers is that the driver's behavior should be fixed [4]. Linus seems to agree [5], however more recently even networking drivers have been reported to fail on probe since just writing the firmware to a device and kicking it can take easy over 60 seconds [6]. Benjamim was able to trace the issues recently reported on cxgb4 down to the same systemd-udevd 30 second timeout [6].

This is an alternative solution which enables drivers that are known to take long to use deferred probe workqueue. This avoids the 30 second timeout and lets us annotate drivers with long init sequences.

Quoted 7 lines

As drivers determine a component is not yet available and needs to defer probe you'll be notified this happen upon init for each device but now with a message such as:

pci 0000:03:00.0: Driver cxgb4 requests probe deferral on init

You should see one of these per struct device probed.

It seems we're still discussing this.

I think I understand all of the underlying issues, and what I'll say is that perhaps we should use what Greg KH requested but via a helper that is easy to grep for.

I don't care if it's something like "module_long_probe_init()" and "module_long_probe_exit()", but it just needs to be some properly named interface which does the whole kthread or whatever bit.

Quoted 7 lines
Quoted 4 lines

I've tested the alternative kthread_run() proposal but unfortunately it does not help resolve the issue, the timeout is still hit and a SIGKILL still kills the driver probe. Please let me know how you'd all like us to proceed, these defer probe patches do help cure the issue though.

Why doesn't it work? Doesn't modprobe come right back and the init sequence still takes a while to run? What exactly fails?

systemd uses kmod kmod_module_probe_insert_module(), what I see is that using kthread_run() as a work around still causes probe to fail on a driver that otherwise would work fine if all you do is sprinkle ssleep(33) (seconds) on the init sequence. To see the issue you can test this on any of your network drivers that get loaded automatically, I did my testing with iwlwifi by purposely breaking it and then using the work around. It seems the probe somehow still gets killed as before, I haven't debugged this further.

For example by breaking and fixing iwlwifi this yields:

ergon:~ # journalctl -b -0 -u systemd-udevd

-- Logs begin at Mon 2014-08-04 21:55:28 EDT, end at Sun 2014-08-10 10:50:14 EDT. --

Aug 10 10:48:49 ergon systemd-udevd[257]: specified group 'input' unknown
Aug 10 10:48:55 ergon mtp-probe[493]: checking bus 3, device 2: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-7"
Aug 10 10:48:55 ergon mtp-probe[492]: checking bus 3, device 4: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-12"
Aug 10 10:49:24 ergon systemd-udevd[465]: seq 1755 '/devices/pci0000:00/0000:00:1c.1/0000:03:00.0' killed

ergon:~ # dmesg | grep iwlwifi

[   10.315538] iwlwifi Going to sleep for 33 seconds
[   43.323958] iwlwifi Done sleeping
[   43.324400] iwlwifi 0000:03:00.0: irq 50 for MSI/MSI-X
[   43.324534] iwlwifi 0000:03:00.0: Error allocating IRQ 50
[   43.326951] iwlwifi: probe of 0000:03:00.0 failed with error -4

The patch used:

drivers/net/wireless/iwlwifi/mvm/ops.c +11 -1
index 610dbcb..65e0ab2 100644
@@ -63,6 +63,7 @@
 #include <linux/module.h>
 #include <linux/vmalloc.h>
 #include <net/mac80211.h>
+#include <linux/kthread.h>
 
 #include "iwl-notif-wait.h"
 #include "iwl-trans.h"
@@ -111,7 +112,7 @@ MODULE_PARM_DESC(power_scheme,
 /*
  * module init and exit functions
  */
-static int __init iwl_mvm_init(void)
+static int iwl_mvm_init_real(void *arg)
 {
      int ret;
 
@@ -130,12 +131,21 @@ static int __init iwl_mvm_init(void)
 
      return ret;
 }
+
+static struct task_struct *init_thread;
+
+static int __init iwl_mvm_init(void)
+{
+     init_thread = kthread_run(iwl_mvm_init_real, NULL, "iwl_mvm_init");
+     return 0;
+}
 module_init(iwl_mvm_init);
 
 static void __exit iwl_mvm_exit(void)
 {
      iwl_opmode_deregister("iwlmvm");
      iwl_mvm_rate_control_unregister();
+     kthread_stop(init_thread);
 }
 module_exit(iwl_mvm_exit);
 
drivers/net/wireless/iwlwifi/pcie/drv.c +0 -0
index 98950e4..c1f2823 100644
@@ -489,6 +489,10 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
      struct iwl_trans_pcie *trans_pcie;
      int ret;
 
Quoted 13 lines

drivers/net/wireless/iwlwifi/pcie/drv.c static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 498

Quoted 8 lines
drivers/net/wireless/iwlwifi/pcie/drv.c +4 -0
+     printk("iwlwifi Going to sleep for 33 seconds\n");
+     ssleep(33);
+     printk("iwlwifi Done sleeping\n");
+
      iwl_trans = iwl_trans_pcie_alloc(pdev, ent, cfg);
      if (IS_ERR(iwl_trans))
              return PTR_ERR(iwl_trans);

I guess that the problem is that you moved the init stuff into kthread for iwlmvm module, but the stall happens in a different module, iwlwifi. So iwlwifi is killed as expected. You had to put the kthread hack into pcie/drv.c instead.

Indeed, will work on a general solution next, thanks!

Quoted 3 lines

(Actually, it's interesting how the SIGKILL error is reported back;
it failed at request_threaded_irq(). If this were the normal irq handler, it might have worked :)

:)

Luis