public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Ming Lei <tom.leiming@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"linux-usb" <linux-usb@vger.kernel.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	Oliver Neukum <oneukum@suse.de>, Dave Jones <davej@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Matthew Garrett <mjg@redhat.com>,
	Jack Stone <jwjstone@fastmail.fm>,
	Larry Finger <Larry.Finger@lwfinger.net>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Ming Lei <ming.lei@canonical.com>
Subject: Re: [RFC] firmware load: defer request_firmware during early boot and resume
Date: Sat, 21 Jul 2012 11:56:04 +0200	[thread overview]
Message-ID: <201207211156.04335.rjw@sisk.pl> (raw)
In-Reply-To: <CACVXFVM0bWOzzPyL7ja2c4Uj56eEjA+-Qm744FBKxWP9j3MOrA@mail.gmail.com>

On Saturday, July 21, 2012, Ming Lei wrote:
> CC guys who discussed the problem in the below link in Jan. :
> 
>       http://marc.info/?t=132528956000002&r=10&w=2
> 
> On Fri, Jul 20, 2012 at 8:33 PM, Ming Lei <tom.leiming@gmail.com> wrote:
> > The RFC patch is just for discussing if the idea of deferring
> > request_firmware is doable for addressing the issue of
> > request_firmware in resume path, which is caused by driver
> > unbind/rebind during resume.
> >
> > At least usb bus is involved in such things, one driver may be
> > unbound and rebound in resume path at several situations, and
> > request_firmware is often called inside probe().
> >
> > Also the idea should be helpful for other hotplug buses too,
> > at least there was the similar problem report on pcmcia bus.
> 
> Looks it works well in my two test cases: one is to call request_firmware
> in early boot(initcall), another one is to call request_firmware in probe()
> of resume path(caused by unbind & rebind).  And without the patch, both
> two request_firmware return failure and can't complete the loading.

And that's precisely why you're not supposed to use request_firmware() in
those two situations.

My opinion is that, at least for the suspend/hibernate case, the firmware
data should be loaded into memory before suspend (e.g. using a PM notifier)
and released only after the corresponding resume (or suspend failure), so
that it's present in memory during the entire suspend-resume cycle.

The early bood situation may be handled through deferred probing.

Thanks,
Rafael


> V1:
>         only defer handling the requests called from probe()
> 
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index 6cd2c6c..fb02eff 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -123,7 +123,7 @@ static bool driver_deferred_probe_enable = false;
>   * list and schedules the deferred probe workqueue to process them.  It
>   * should be called anytime a driver is successfully bound to a device.
>   */
> -static void driver_deferred_probe_trigger(void)
> +void driver_deferred_probe_trigger(void)
>  {
>  	if (!driver_deferred_probe_enable)
>  		return;
> @@ -144,6 +144,7 @@ static void driver_deferred_probe_trigger(void)
>  	 */
>  	queue_work(deferred_wq, &deferred_probe_work);
>  }
> +EXPORT_SYMBOL_GPL(driver_deferred_probe_trigger);
> 
>  /**
>   * deferred_probe_initcall() - Enable probing of deferred devices
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index 5401814..1b13536 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -21,6 +21,7 @@
>  #include <linux/firmware.h>
>  #include <linux/slab.h>
>  #include <linux/sched.h>
> +#include "base.h"
> 
>  #define to_dev(obj) container_of(obj, struct device, kobj)
> 
> @@ -593,6 +594,11 @@ request_firmware(const struct firmware
> **firmware_p, const char *name,
>  	if (IS_ERR_OR_NULL(fw_priv))
>  		return PTR_RET(fw_priv);
> 
> +	/* only defer handling the requests called from probe() */
> +	if (!klist_node_attached(&device->p->knode_driver) &&
> +			system_state != SYSTEM_RUNNING)
> +		return -EPROBE_DEFER;
> +
>  	ret = usermodehelper_read_trylock();
>  	if (WARN_ON(ret)) {
>  		dev_err(device, "firmware: %s will not be loaded\n", name);
> diff --git a/include/linux/device.h b/include/linux/device.h
> index d0e4d99..a63d3171 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -244,7 +244,7 @@ extern struct device_driver *driver_find(const char *name,
>  					 struct bus_type *bus);
>  extern int driver_probe_done(void);
>  extern void wait_for_device_probe(void);
> -
> +extern void driver_deferred_probe_trigger(void);
> 
>  /* sysfs interface for exporting driver attributes */
> 
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index e07f5e0..c8d74c6 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -378,6 +378,7 @@ extern enum system_states {
>  	SYSTEM_POWER_OFF,
>  	SYSTEM_RESTART,
>  	SYSTEM_SUSPEND_DISK,
> +	SYSTEM_SUSPEND,
>  } system_state;
> 
>  #define TAINT_PROPRIETARY_MODULE	0
> diff --git a/init/main.c b/init/main.c
> index e60679d..02fc1c2 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -809,6 +809,9 @@ static noinline int init_post(void)
>  	current->signal->flags |= SIGNAL_UNKILLABLE;
>  	flush_delayed_fput();
> 
> +	/* defer handling request_firmware in probe of initcall path */
> +	driver_deferred_probe_trigger();
> +
>  	if (ramdisk_execute_command) {
>  		run_init_process(ramdisk_execute_command);
>  		printk(KERN_WARNING "Failed to execute %s\n",
> diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
> index 1da39ea..61c723f 100644
> --- a/kernel/power/suspend.c
> +++ b/kernel/power/suspend.c
> @@ -224,6 +224,9 @@ int suspend_devices_and_enter(suspend_state_t state)
>  		goto Recover_platform;
>  	}
>  	suspend_test_finish("suspend devices");
> +
> +	system_state = SYSTEM_SUSPEND;
> +
>  	if (suspend_test(TEST_DEVICES))
>  		goto Recover_platform;
> 
> @@ -301,6 +304,12 @@ static int enter_state(suspend_state_t state)
>   Finish:
>  	pr_debug("PM: Finishing wakeup.\n");
>  	suspend_finish();
> +
> +	system_state = SYSTEM_RUNNING;
> +
> +	/* defer handling request_firmware in probe of resume path */
> +	driver_deferred_probe_trigger();
> +
>   Unlock:
>  	mutex_unlock(&pm_mutex);
>  	return error;
> 
> 
> 
> Thanks,
> 


  reply	other threads:[~2012-07-21  9:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-20 12:33 [RFC] firmware load: defer request_firmware during early boot and resume Ming Lei
2012-07-20 12:52 ` Borislav Petkov
2012-07-20 12:57   ` Ming Lei
2012-07-20 13:03     ` Borislav Petkov
2012-07-20 13:09       ` Ming Lei
2012-07-20 13:13         ` Borislav Petkov
2012-07-20 13:54 ` Oliver Neukum
2012-07-20 15:53   ` Ming Lei
2012-07-21  4:13 ` Ming Lei
2012-07-21  9:56   ` Rafael J. Wysocki [this message]
2012-07-21 13:25     ` Ming Lei
2012-07-21 17:35       ` Rafael J. Wysocki
2012-07-21 17:31 ` Linus Torvalds
2012-07-21 17:53   ` Rafael J. Wysocki
2012-07-21 19:55   ` Ming Lei
2012-07-21 20:38     ` Linus Torvalds
2012-07-21 20:46       ` david
2012-07-21 23:24       ` Ming Lei
2012-07-22 12:58       ` Borislav Petkov
2012-07-22 19:46         ` Linus Torvalds
2012-07-23  8:12           ` Borislav Petkov
2012-07-21 21:01     ` Francois Romieu
2012-07-21 17:49 ` Rafael J. Wysocki
2012-07-21 20:09   ` Ming Lei
2012-07-21 21:33     ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201207211156.04335.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=Larry.Finger@lwfinger.net \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=davej@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jwjstone@fastmail.fm \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ming.lei@canonical.com \
    --cc=mjg@redhat.com \
    --cc=oneukum@suse.de \
    --cc=stern@rowland.harvard.edu \
    --cc=tom.leiming@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox