From patchwork Sun Nov 11 12:34:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 1725301 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id C3DBADF288 for ; Sun, 11 Nov 2012 12:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753114Ab2KKMgH (ORCPT ); Sun, 11 Nov 2012 07:36:07 -0500 Received: from mail-da0-f46.google.com ([209.85.210.46]:37302 "EHLO mail-da0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753052Ab2KKMgG (ORCPT ); Sun, 11 Nov 2012 07:36:06 -0500 Received: by mail-da0-f46.google.com with SMTP id n41so2338863dak.19 for ; Sun, 11 Nov 2012 04:36:05 -0800 (PST) Received: by 10.68.227.162 with SMTP id sb2mr50038840pbc.4.1352637365661; Sun, 11 Nov 2012 04:36:05 -0800 (PST) Received: from localhost ([183.37.194.51]) by mx.google.com with ESMTPS id wf8sm2464443pbc.65.2012.11.11.04.35.57 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 11 Nov 2012 04:36:04 -0800 (PST) From: Ming Lei To: linux-kernel@vger.kernel.org Cc: Alan Stern , Oliver Neukum , Minchan Kim , Greg Kroah-Hartman , "Rafael J. Wysocki" , Jens Axboe , "David S. Miller" , Andrew Morton , netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-pm@vger.kernel.org, linux-mm@kvack.org, Ming Lei Subject: [PATCH v5 5/6] PM / Runtime: force memory allocation with no I/O during Runtime PM callbcack Date: Sun, 11 Nov 2012 20:34:37 +0800 Message-Id: <1352637278-19968-6-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1352637278-19968-1-git-send-email-ming.lei@canonical.com> References: <1352637278-19968-1-git-send-email-ming.lei@canonical.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 Cc: Oliver Neukum Cc: Rafael J. Wysocki Signed-off-by: Ming Lei --- 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); + } if (retval) { __update_runtime_status(dev, RPM_SUSPENDED); pm_runtime_cancel_pending(dev);