From patchwork Sat Jul 23 08:50:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 1001822 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6N8rESU027168 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Sat, 23 Jul 2011 08:53:34 GMT Received: from daredevil.linux-foundation.org (localhost [127.0.0.1]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p6N8oZAn019677; Sat, 23 Jul 2011 01:50:35 -0700 Received: from mail-pz0-f49.google.com (mail-pz0-f49.google.com [209.85.210.49]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p6N8nW8Y019377 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL) for ; Sat, 23 Jul 2011 01:49:36 -0700 Received: by mail-pz0-f49.google.com with SMTP id 33so4311780pzk.8 for ; Sat, 23 Jul 2011 01:49:36 -0700 (PDT) Received: by 10.68.65.225 with SMTP id a1mr3440694pbt.529.1311410976124; Sat, 23 Jul 2011 01:49:36 -0700 (PDT) Received: from localhost.localdomain (p1095-adsao03yokonib2-acca.kanagawa.ocn.ne.jp [219.165.64.95]) by mx.google.com with ESMTPS id z6sm2538819pbc.62.2011.07.23.01.49.33 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 23 Jul 2011 01:49:35 -0700 (PDT) From: Akinobu Mita To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Date: Sat, 23 Jul 2011 17:50:57 +0900 Message-Id: <1311411060-30124-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1311411060-30124-1-git-send-email-akinobu.mita@gmail.com> References: <1311411060-30124-1-git-send-email-akinobu.mita@gmail.com> Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-4.232 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SPF_PASS, OSDL_HEADER_SUBJECT_BRACKETED X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.21 Cc: linux-pm@lists.linux-foundation.org, Akinobu Mita Subject: [linux-pm] [PATCH v3 3/6] PM: PM notifier error injection module X-BeenThere: linux-pm@lists.linux-foundation.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux power management List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 23 Jul 2011 08:53:34 +0000 (UTC) This provides the ability to inject artifical errors to PM notifier chain callbacks. It is controlled through debugfs interface under /sys/kernel/debug/pm-notifier-error-inject/ Each of the files in the directory represents an event which can be failed and contains the error code. If the notifier call chain should be failed with some events notified, write the error code to the files. Example: Inject PM suspend error (-12 = -ENOMEM) # cd /sys/kernel/debug/pm-notifier-error-inject # echo -12 > PM_SUSPEND_PREPARE # echo mem > /sys/power/state bash: echo: write error: Cannot allocate memory Signed-off-by: Akinobu Mita Cc: Pavel Machek Cc: "Rafael J. Wysocki" Cc: linux-pm@lists.linux-foundation.org --- * v3 - rewrite to be kernel modules instead of initializing at late_initcall()s - notifier priority can be specified as a module parameter lib/Kconfig.debug | 21 ++++++++++++++++++ lib/Makefile | 1 + lib/pm-notifier-error-inject.c | 46 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 0 deletions(-) create mode 100644 lib/pm-notifier-error-inject.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 55d56bb..69ecd50 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1058,6 +1058,27 @@ config CPU_NOTIFIER_ERROR_INJECT If unsure, say N. +config PM_NOTIFIER_ERROR_INJECT + tristate "PM notifier error injection module" + depends on PM && NOTIFIER_ERROR_INJECTION + default m if PM_DEBUG + help + This option provides the ability to inject artifical errors to + PM notifier chain callbacks. It is controlled through debugfs + interface. + + Example: Inject PM suspend error (-12 = -ENOMEM) + + # cd /sys/kernel/debug/pm-notifier-error-inject + # echo -12 > PM_SUSPEND_PREPARE + # echo mem > /sys/power/state + bash: echo: write error: Cannot allocate memory + + To compile this code as a module, choose M here: the module will + be called pm-notifier-error-inject. + + If unsure, say N. + config FAULT_INJECTION bool "Fault-injection framework" depends on DEBUG_KERNEL diff --git a/lib/Makefile b/lib/Makefile index 892f4e2..4dca6c0 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -90,6 +90,7 @@ obj-$(CONFIG_SWIOTLB) += swiotlb.o obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o +obj-$(CONFIG_PM_NOTIFIER_ERROR_INJECT) += pm-notifier-error-inject.o lib-$(CONFIG_GENERIC_BUG) += bug.o diff --git a/lib/pm-notifier-error-inject.c b/lib/pm-notifier-error-inject.c new file mode 100644 index 0000000..821b3db --- /dev/null +++ b/lib/pm-notifier-error-inject.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +static int priority; +module_param(priority, int, 0); +MODULE_PARM_DESC(priority, "specify PM notifier priority"); + +static struct err_inject_notifier_block err_inject_pm_notifier = { + .actions = { + { ERR_INJECT_NOTIFIER_ACTION(PM_HIBERNATION_PREPARE) }, + { ERR_INJECT_NOTIFIER_ACTION(PM_SUSPEND_PREPARE) }, + { ERR_INJECT_NOTIFIER_ACTION(PM_RESTORE_PREPARE) }, + {} + } +}; + +static int err_inject_init(void) +{ + int err; + + err = err_inject_notifier_block_init(&err_inject_pm_notifier, + "pm-notifier-error-inject", priority); + if (err) + return err; + + err = register_pm_notifier(&err_inject_pm_notifier.nb); + if (err) + err_inject_notifier_block_cleanup(&err_inject_pm_notifier); + + return err; +} + +static void err_inject_exit(void) +{ + unregister_pm_notifier(&err_inject_pm_notifier.nb); + err_inject_notifier_block_cleanup(&err_inject_pm_notifier); +} + +module_init(err_inject_init); +module_exit(err_inject_exit); + +MODULE_DESCRIPTION("PM notifier error injection module"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Akinobu Mita ");