[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1354069667.BsTEhItmLz@vostro.rjw.lan>
Date: Tue, 27 Nov 2012 22:24:27 +0100
From: "Rafael J. Wysocki" <rjw@...k.pl>
To: linux-pm@...r.kernel.org
Cc: Ming Lei <ming.lei@...onical.com>, linux-kernel@...r.kernel.org,
Alan Stern <stern@...land.harvard.edu>,
Oliver Neukum <oneukum@...e.de>,
Minchan Kim <minchan@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jens Axboe <axboe@...nel.dk>,
"David S. Miller" <davem@...emloft.net>,
Andrew Morton <akpm@...ux-foundation.org>,
netdev@...r.kernel.org, linux-usb@...r.kernel.org,
linux-mm@...ck.org
Subject: Re: [PATCH v6 5/6] PM / Runtime: force memory allocation with no I/O during Runtime PM callbcack
On Saturday, November 24, 2012 08:59:17 PM Ming Lei wrote:
> This patch applies the introduced memalloc_noio_save() and
> memalloc_noio_restore() to force memory allocation with no I/O
> during runtime_resume/runtime_suspend callback on device with
> the flag of 'memalloc_noio' set.
>
> Cc: Alan Stern <stern@...land.harvard.edu>
> Cc: Oliver Neukum <oneukum@...e.de>
> Cc: Rafael J. Wysocki <rjw@...k.pl>
> Signed-off-by: Ming Lei <ming.lei@...onical.com>
> ---
> v5:
> - use inline memalloc_noio_save()
> v4:
> - runtime_suspend need this too because rpm_resume may wait for
> completion of concurrent runtime_suspend, so deadlock still may
> be triggered in runtime_suspend path.
> ---
> drivers/base/power/runtime.c | 32 ++++++++++++++++++++++++++++++--
> 1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 3e198a0..96d99ea 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -371,6 +371,7 @@ static int rpm_suspend(struct device *dev, int rpmflags)
> int (*callback)(struct device *);
> struct device *parent = NULL;
> int retval;
> + unsigned int noio_flag;
>
> trace_rpm_suspend(dev, rpmflags);
>
> @@ -480,7 +481,20 @@ static int rpm_suspend(struct device *dev, int rpmflags)
> if (!callback && dev->driver && dev->driver->pm)
> callback = dev->driver->pm->runtime_suspend;
>
> - retval = rpm_callback(callback, dev);
> + /*
> + * Deadlock might be caused if memory allocation with GFP_KERNEL
> + * happens inside runtime_suspend callback of one block device's
> + * ancestor or the block device itself. Network device might be
> + * thought as part of iSCSI block device, so network device and
> + * its ancestor should be marked as memalloc_noio.
> + */
> + if (dev->power.memalloc_noio) {
> + noio_flag = memalloc_noio_save();
> + retval = rpm_callback(callback, dev);
> + memalloc_noio_restore(noio_flag);
> + } else {
> + retval = rpm_callback(callback, dev);
> + }
> if (retval)
> goto fail;
>
> @@ -563,6 +577,7 @@ static int rpm_resume(struct device *dev, int rpmflags)
> int (*callback)(struct device *);
> struct device *parent = NULL;
> int retval = 0;
> + unsigned int noio_flag;
>
> trace_rpm_resume(dev, rpmflags);
>
> @@ -712,7 +727,20 @@ static int rpm_resume(struct device *dev, int rpmflags)
> if (!callback && dev->driver && dev->driver->pm)
> callback = dev->driver->pm->runtime_resume;
>
> - retval = rpm_callback(callback, dev);
> + /*
> + * Deadlock might be caused if memory allocation with GFP_KERNEL
> + * happens inside runtime_resume callback of one block device's
> + * ancestor or the block device itself. Network device might be
> + * thought as part of iSCSI block device, so network device and
> + * its ancestor should be marked as memalloc_noio.
> + */
> + if (dev->power.memalloc_noio) {
> + noio_flag = memalloc_noio_save();
> + retval = rpm_callback(callback, dev);
> + memalloc_noio_restore(noio_flag);
> + } else {
> + retval = rpm_callback(callback, dev);
> + }
Please don't duplicate code this way.
You can move that whole thing to rpm_callback(). Yes, you'll probably need to
check dev->power.memalloc_noio twice in there, but that's OK.
> if (retval) {
> __update_runtime_status(dev, RPM_SUSPENDED);
> pm_runtime_cancel_pending(dev);
>
Thanks,
Rafael
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists