aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 20:25:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 20:25:34 -0400
commit27c1ee3f929555b71fa39ec0d81a7e7185de1b16 (patch)
tree42e40bdfe4efac660d650658019391536ce67a42 /lib
parent37cd9600a9e20359b0283983c9e3a55d84347168 (diff)
parent086ff4b3a7fb9cdf41e6a5d0ccd99b86d84633a1 (diff)
Merge branch 'akpm' (Andrew's patch-bomb)
Merge Andrew's first set of patches: "Non-MM patches: - lots of misc bits - tree-wide have_clk() cleanups - quite a lot of printk tweaks. I draw your attention to "printk: convert the format for KERN_<LEVEL> to a 2 byte pattern" which looks a bit scary. But afaict it's solid. - backlight updates - lib/ feature work (notably the addition and use of memweight()) - checkpatch updates - rtc updates - nilfs updates - fatfs updates (partial, still waiting for acks) - kdump, proc, fork, IPC, sysctl, taskstats, pps, etc - new fault-injection feature work" * Merge emailed patches from Andrew Morton <akpm@linux-foundation.org>: (128 commits) drivers/misc/lkdtm.c: fix missing allocation failure check lib/scatterlist: do not re-write gfp_flags in __sg_alloc_table() fault-injection: add tool to run command with failslab or fail_page_alloc fault-injection: add selftests for cpu and memory hotplug powerpc: pSeries reconfig notifier error injection module memory: memory notifier error injection module PM: PM notifier error injection module cpu: rewrite cpu-notifier-error-inject module fault-injection: notifier error injection c/r: fcntl: add F_GETOWNER_UIDS option resource: make sure requested range is included in the root range include/linux/aio.h: cpp->C conversions fs: cachefiles: add support for large files in filesystem caching pps: return PTR_ERR on error in device_create taskstats: check nla_reserve() return sysctl: suppress kmemleak messages ipc: use Kconfig options for __ARCH_WANT_[COMPAT_]IPC_PARSE_VERSION ipc: compat: use signed size_t types for msgsnd and msgrcv ipc: allow compat IPC version field parsing if !ARCH_WANT_OLD_COMPAT_IPC ipc: add COMPAT_SHMLBA support ...
Diffstat (limited to 'lib')
-rw-r--r--lib/Kconfig3
-rw-r--r--lib/Kconfig.debug91
-rw-r--r--lib/Makefile7
-rw-r--r--lib/atomic64_test.c5
-rw-r--r--lib/cpu-notifier-error-inject.c63
-rw-r--r--lib/crc32.c2
-rw-r--r--lib/memory-notifier-error-inject.c48
-rw-r--r--lib/memweight.c38
-rw-r--r--lib/notifier-error-inject.c112
-rw-r--r--lib/notifier-error-inject.h24
-rw-r--r--lib/pSeries-reconfig-notifier-error-inject.c51
-rw-r--r--lib/pm-notifier-error-inject.c49
-rw-r--r--lib/scatterlist.c8
-rw-r--r--lib/spinlock_debug.c2
-rw-r--r--lib/vsprintf.c83
15 files changed, 528 insertions, 58 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index bfdbb1ff0aa3..bb94c1ba616a 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -340,6 +340,9 @@ config NLATTR
340config GENERIC_ATOMIC64 340config GENERIC_ATOMIC64
341 bool 341 bool
342 342
343config ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
344 def_bool y if GENERIC_ATOMIC64
345
343config LRU_CACHE 346config LRU_CACHE
344 tristate 347 tristate
345 348
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 4a186508bf8b..2403a63b5da5 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1084,18 +1084,105 @@ config LKDTM
1084 Documentation on how to use the module can be found in 1084 Documentation on how to use the module can be found in
1085 Documentation/fault-injection/provoke-crashes.txt 1085 Documentation/fault-injection/provoke-crashes.txt
1086 1086
1087config NOTIFIER_ERROR_INJECTION
1088 tristate "Notifier error injection"
1089 depends on DEBUG_KERNEL
1090 select DEBUG_FS
1091 help
1092 This option provides the ability to inject artifical errors to
1093 specified notifier chain callbacks. It is useful to test the error
1094 handling of notifier call chain failures.
1095
1096 Say N if unsure.
1097
1087config CPU_NOTIFIER_ERROR_INJECT 1098config CPU_NOTIFIER_ERROR_INJECT
1088 tristate "CPU notifier error injection module" 1099 tristate "CPU notifier error injection module"
1089 depends on HOTPLUG_CPU && DEBUG_KERNEL 1100 depends on HOTPLUG_CPU && NOTIFIER_ERROR_INJECTION
1090 help 1101 help
1091 This option provides a kernel module that can be used to test 1102 This option provides a kernel module that can be used to test
1092 the error handling of the cpu notifiers 1103 the error handling of the cpu notifiers by injecting artifical
1104 errors to CPU notifier chain callbacks. It is controlled through
1105 debugfs interface under /sys/kernel/debug/notifier-error-inject/cpu
1106
1107 If the notifier call chain should be failed with some events
1108 notified, write the error code to "actions/<notifier event>/error".
1109
1110 Example: Inject CPU offline error (-1 == -EPERM)
1111
1112 # cd /sys/kernel/debug/notifier-error-inject/cpu
1113 # echo -1 > actions/CPU_DOWN_PREPARE/error
1114 # echo 0 > /sys/devices/system/cpu/cpu1/online
1115 bash: echo: write error: Operation not permitted
1093 1116
1094 To compile this code as a module, choose M here: the module will 1117 To compile this code as a module, choose M here: the module will
1095 be called cpu-notifier-error-inject. 1118 be called cpu-notifier-error-inject.
1096 1119
1097 If unsure, say N. 1120 If unsure, say N.
1098 1121
1122config PM_NOTIFIER_ERROR_INJECT
1123 tristate "PM notifier error injection module"
1124 depends on PM && NOTIFIER_ERROR_INJECTION
1125 default m if PM_DEBUG
1126 help
1127 This option provides the ability to inject artifical errors to
1128 PM notifier chain callbacks. It is controlled through debugfs
1129 interface /sys/kernel/debug/notifier-error-inject/pm
1130
1131 If the notifier call chain should be failed with some events
1132 notified, write the error code to "actions/<notifier event>/error".
1133
1134 Example: Inject PM suspend error (-12 = -ENOMEM)
1135
1136 # cd /sys/kernel/debug/notifier-error-inject/pm/
1137 # echo -12 > actions/PM_SUSPEND_PREPARE/error
1138 # echo mem > /sys/power/state
1139 bash: echo: write error: Cannot allocate memory
1140
1141 To compile this code as a module, choose M here: the module will
1142 be called pm-notifier-error-inject.
1143
1144 If unsure, say N.
1145
1146config MEMORY_NOTIFIER_ERROR_INJECT
1147 tristate "Memory hotplug notifier error injection module"
1148 depends on MEMORY_HOTPLUG_SPARSE && NOTIFIER_ERROR_INJECTION
1149 help
1150 This option provides the ability to inject artifical errors to
1151 memory hotplug notifier chain callbacks. It is controlled through
1152 debugfs interface under /sys/kernel/debug/notifier-error-inject/memory
1153
1154 If the notifier call chain should be failed with some events
1155 notified, write the error code to "actions/<notifier event>/error".
1156
1157 Example: Inject memory hotplug offline error (-12 == -ENOMEM)
1158
1159 # cd /sys/kernel/debug/notifier-error-inject/memory
1160 # echo -12 > actions/MEM_GOING_OFFLINE/error
1161 # echo offline > /sys/devices/system/memory/memoryXXX/state
1162 bash: echo: write error: Cannot allocate memory
1163
1164 To compile this code as a module, choose M here: the module will
1165 be called pSeries-reconfig-notifier-error-inject.
1166
1167 If unsure, say N.
1168
1169config PSERIES_RECONFIG_NOTIFIER_ERROR_INJECT
1170 tristate "pSeries reconfig notifier error injection module"
1171 depends on PPC_PSERIES && NOTIFIER_ERROR_INJECTION
1172 help
1173 This option provides the ability to inject artifical errors to
1174 pSeries reconfig notifier chain callbacks. It is controlled
1175 through debugfs interface under
1176 /sys/kernel/debug/notifier-error-inject/pSeries-reconfig/
1177
1178 If the notifier call chain should be failed with some events
1179 notified, write the error code to "actions/<notifier event>/error".
1180
1181 To compile this code as a module, choose M here: the module will
1182 be called memory-notifier-error-inject.
1183
1184 If unsure, say N.
1185
1099config FAULT_INJECTION 1186config FAULT_INJECTION
1100 bool "Fault-injection framework" 1187 bool "Fault-injection framework"
1101 depends on DEBUG_KERNEL 1188 depends on DEBUG_KERNEL
diff --git a/lib/Makefile b/lib/Makefile
index 2f2be5a8734c..9cb4104f47d9 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -22,7 +22,7 @@ lib-y += kobject.o klist.o
22obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 22obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
23 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ 23 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \
24 string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \ 24 string_helpers.o gcd.o lcm.o list_sort.o uuid.o flex_array.o \
25 bsearch.o find_last_bit.o find_next_bit.o llist.o 25 bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o
26obj-y += kstrtox.o 26obj-y += kstrtox.o
27obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o 27obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
28 28
@@ -90,7 +90,12 @@ obj-$(CONFIG_AUDIT_GENERIC) += audit.o
90obj-$(CONFIG_SWIOTLB) += swiotlb.o 90obj-$(CONFIG_SWIOTLB) += swiotlb.o
91obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o 91obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
92obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o 92obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
93obj-$(CONFIG_NOTIFIER_ERROR_INJECTION) += notifier-error-inject.o
93obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o 94obj-$(CONFIG_CPU_NOTIFIER_ERROR_INJECT) += cpu-notifier-error-inject.o
95obj-$(CONFIG_PM_NOTIFIER_ERROR_INJECT) += pm-notifier-error-inject.o
96obj-$(CONFIG_MEMORY_NOTIFIER_ERROR_INJECT) += memory-notifier-error-inject.o
97obj-$(CONFIG_PSERIES_RECONFIG_NOTIFIER_ERROR_INJECT) += \
98 pSeries-reconfig-notifier-error-inject.o
94 99
95lib-$(CONFIG_GENERIC_BUG) += bug.o 100lib-$(CONFIG_GENERIC_BUG) += bug.o
96 101
diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c
index cb99b91c3a1d..00bca223d1e1 100644
--- a/lib/atomic64_test.c
+++ b/lib/atomic64_test.c
@@ -114,8 +114,7 @@ static __init int test_atomic64(void)
114 r += one; 114 r += one;
115 BUG_ON(v.counter != r); 115 BUG_ON(v.counter != r);
116 116
117#if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \ 117#ifdef CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
118 defined(CONFIG_S390) || defined(_ASM_GENERIC_ATOMIC64_H) || defined(CONFIG_ARM)
119 INIT(onestwos); 118 INIT(onestwos);
120 BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1)); 119 BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1));
121 r -= one; 120 r -= one;
@@ -129,7 +128,7 @@ static __init int test_atomic64(void)
129 BUG_ON(atomic64_dec_if_positive(&v) != (-one - one)); 128 BUG_ON(atomic64_dec_if_positive(&v) != (-one - one));
130 BUG_ON(v.counter != r); 129 BUG_ON(v.counter != r);
131#else 130#else
132#warning Please implement atomic64_dec_if_positive for your architecture, and add it to the IF above 131#warning Please implement atomic64_dec_if_positive for your architecture and select the above Kconfig symbol
133#endif 132#endif
134 133
135 INIT(onestwos); 134 INIT(onestwos);
diff --git a/lib/cpu-notifier-error-inject.c b/lib/cpu-notifier-error-inject.c
index 4dc20321b0d5..707ca24f7b18 100644
--- a/lib/cpu-notifier-error-inject.c
+++ b/lib/cpu-notifier-error-inject.c
@@ -1,58 +1,45 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/cpu.h>
3#include <linux/module.h> 2#include <linux/module.h>
4#include <linux/notifier.h> 3#include <linux/cpu.h>
5 4
6static int priority; 5#include "notifier-error-inject.h"
7static int cpu_up_prepare_error;
8static int cpu_down_prepare_error;
9 6
7static int priority;
10module_param(priority, int, 0); 8module_param(priority, int, 0);
11MODULE_PARM_DESC(priority, "specify cpu notifier priority"); 9MODULE_PARM_DESC(priority, "specify cpu notifier priority");
12 10
13module_param(cpu_up_prepare_error, int, 0644); 11static struct notifier_err_inject cpu_notifier_err_inject = {
14MODULE_PARM_DESC(cpu_up_prepare_error, 12 .actions = {
15 "specify error code to inject CPU_UP_PREPARE action"); 13 { NOTIFIER_ERR_INJECT_ACTION(CPU_UP_PREPARE) },
16 14 { NOTIFIER_ERR_INJECT_ACTION(CPU_UP_PREPARE_FROZEN) },
17module_param(cpu_down_prepare_error, int, 0644); 15 { NOTIFIER_ERR_INJECT_ACTION(CPU_DOWN_PREPARE) },
18MODULE_PARM_DESC(cpu_down_prepare_error, 16 { NOTIFIER_ERR_INJECT_ACTION(CPU_DOWN_PREPARE_FROZEN) },
19 "specify error code to inject CPU_DOWN_PREPARE action"); 17 {}
20
21static int err_inject_cpu_callback(struct notifier_block *nfb,
22 unsigned long action, void *hcpu)
23{
24 int err = 0;
25
26 switch (action) {
27 case CPU_UP_PREPARE:
28 case CPU_UP_PREPARE_FROZEN:
29 err = cpu_up_prepare_error;
30 break;
31 case CPU_DOWN_PREPARE:
32 case CPU_DOWN_PREPARE_FROZEN:
33 err = cpu_down_prepare_error;
34 break;
35 } 18 }
36 if (err)
37 printk(KERN_INFO "Injecting error (%d) at cpu notifier\n", err);
38
39 return notifier_from_errno(err);
40}
41
42static struct notifier_block err_inject_cpu_notifier = {
43 .notifier_call = err_inject_cpu_callback,
44}; 19};
45 20
21static struct dentry *dir;
22
46static int err_inject_init(void) 23static int err_inject_init(void)
47{ 24{
48 err_inject_cpu_notifier.priority = priority; 25 int err;
26
27 dir = notifier_err_inject_init("cpu", notifier_err_inject_dir,
28 &cpu_notifier_err_inject, priority);
29 if (IS_ERR(dir))
30 return PTR_ERR(dir);
31
32 err = register_hotcpu_notifier(&cpu_notifier_err_inject.nb);
33 if (err)
34 debugfs_remove_recursive(dir);
49 35
50 return register_hotcpu_notifier(&err_inject_cpu_notifier); 36 return err;
51} 37}
52 38
53static void err_inject_exit(void) 39static void err_inject_exit(void)
54{ 40{
55 unregister_hotcpu_notifier(&err_inject_cpu_notifier); 41 unregister_hotcpu_notifier(&cpu_notifier_err_inject.nb);
42 debugfs_remove_recursive(dir);
56} 43}
57 44
58module_init(err_inject_init); 45module_init(err_inject_init);
diff --git a/lib/crc32.c b/lib/crc32.c
index b0d278fb1d91..61774b8db4de 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -74,7 +74,9 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
74 size_t i; 74 size_t i;
75# endif 75# endif
76 const u32 *t0=tab[0], *t1=tab[1], *t2=tab[2], *t3=tab[3]; 76 const u32 *t0=tab[0], *t1=tab[1], *t2=tab[2], *t3=tab[3];
77# if CRC_LE_BITS != 32
77 const u32 *t4 = tab[4], *t5 = tab[5], *t6 = tab[6], *t7 = tab[7]; 78 const u32 *t4 = tab[4], *t5 = tab[5], *t6 = tab[6], *t7 = tab[7];
79# endif
78 u32 q; 80 u32 q;
79 81
80 /* Align it */ 82 /* Align it */
diff --git a/lib/memory-notifier-error-inject.c b/lib/memory-notifier-error-inject.c
new file mode 100644
index 000000000000..e6239bf0b0df
--- /dev/null
+++ b/lib/memory-notifier-error-inject.c
@@ -0,0 +1,48 @@
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/memory.h>
4
5#include "notifier-error-inject.h"
6
7static int priority;
8module_param(priority, int, 0);
9MODULE_PARM_DESC(priority, "specify memory notifier priority");
10
11static struct notifier_err_inject memory_notifier_err_inject = {
12 .actions = {
13 { NOTIFIER_ERR_INJECT_ACTION(MEM_GOING_ONLINE) },
14 { NOTIFIER_ERR_INJECT_ACTION(MEM_GOING_OFFLINE) },
15 {}
16 }
17};
18
19static struct dentry *dir;
20
21static int err_inject_init(void)
22{
23 int err;
24
25 dir = notifier_err_inject_init("memory", notifier_err_inject_dir,
26 &memory_notifier_err_inject, priority);
27 if (IS_ERR(dir))
28 return PTR_ERR(dir);
29
30 err = register_memory_notifier(&memory_notifier_err_inject.nb);
31 if (err)
32 debugfs_remove_recursive(dir);
33
34 return err;
35}
36
37static void err_inject_exit(void)
38{
39 unregister_memory_notifier(&memory_notifier_err_inject.nb);
40 debugfs_remove_recursive(dir);
41}
42
43module_init(err_inject_init);
44module_exit(err_inject_exit);
45
46MODULE_DESCRIPTION("memory notifier error injection module");
47MODULE_LICENSE("GPL");
48MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
diff --git a/lib/memweight.c b/lib/memweight.c
new file mode 100644
index 000000000000..e35fc8771893
--- /dev/null
+++ b/lib/memweight.c
@@ -0,0 +1,38 @@
1#include <linux/export.h>
2#include <linux/bug.h>
3#include <linux/bitmap.h>
4
5/**
6 * memweight - count the total number of bits set in memory area
7 * @ptr: pointer to the start of the area
8 * @bytes: the size of the area
9 */
10size_t memweight(const void *ptr, size_t bytes)
11{
12 size_t ret = 0;
13 size_t longs;
14 const unsigned char *bitmap = ptr;
15
16 for (; bytes > 0 && ((unsigned long)bitmap) % sizeof(long);
17 bytes--, bitmap++)
18 ret += hweight8(*bitmap);
19
20 longs = bytes / sizeof(long);
21 if (longs) {
22 BUG_ON(longs >= INT_MAX / BITS_PER_LONG);
23 ret += bitmap_weight((unsigned long *)bitmap,
24 longs * BITS_PER_LONG);
25 bytes -= longs * sizeof(long);
26 bitmap += longs * sizeof(long);
27 }
28 /*
29 * The reason that this last loop is distinct from the preceding
30 * bitmap_weight() call is to compute 1-bits in the last region smaller
31 * than sizeof(long) properly on big-endian systems.
32 */
33 for (; bytes > 0; bytes--, bitmap++)
34 ret += hweight8(*bitmap);
35
36 return ret;
37}
38EXPORT_SYMBOL(memweight);
diff --git a/lib/notifier-error-inject.c b/lib/notifier-error-inject.c
new file mode 100644
index 000000000000..44b92cb6224f
--- /dev/null
+++ b/lib/notifier-error-inject.c
@@ -0,0 +1,112 @@
1#include <linux/module.h>
2
3#include "notifier-error-inject.h"
4
5static int debugfs_errno_set(void *data, u64 val)
6{
7 *(int *)data = clamp_t(int, val, -MAX_ERRNO, 0);
8 return 0;
9}
10
11static int debugfs_errno_get(void *data, u64 *val)
12{
13 *val = *(int *)data;
14 return 0;
15}
16
17DEFINE_SIMPLE_ATTRIBUTE(fops_errno, debugfs_errno_get, debugfs_errno_set,
18 "%lld\n");
19
20static struct dentry *debugfs_create_errno(const char *name, mode_t mode,
21 struct dentry *parent, int *value)
22{
23 return debugfs_create_file(name, mode, parent, value, &fops_errno);
24}
25
26static int notifier_err_inject_callback(struct notifier_block *nb,
27 unsigned long val, void *p)
28{
29 int err = 0;
30 struct notifier_err_inject *err_inject =
31 container_of(nb, struct notifier_err_inject, nb);
32 struct notifier_err_inject_action *action;
33
34 for (action = err_inject->actions; action->name; action++) {
35 if (action->val == val) {
36 err = action->error;
37 break;
38 }
39 }
40 if (err)
41 pr_info("Injecting error (%d) to %s\n", err, action->name);
42
43 return notifier_from_errno(err);
44}
45
46struct dentry *notifier_err_inject_dir;
47EXPORT_SYMBOL_GPL(notifier_err_inject_dir);
48
49struct dentry *notifier_err_inject_init(const char *name, struct dentry *parent,
50 struct notifier_err_inject *err_inject, int priority)
51{
52 struct notifier_err_inject_action *action;
53 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
54 struct dentry *dir;
55 struct dentry *actions_dir;
56
57 err_inject->nb.notifier_call = notifier_err_inject_callback;
58 err_inject->nb.priority = priority;
59
60 dir = debugfs_create_dir(name, parent);
61 if (!dir)
62 return ERR_PTR(-ENOMEM);
63
64 actions_dir = debugfs_create_dir("actions", dir);
65 if (!actions_dir)
66 goto fail;
67
68 for (action = err_inject->actions; action->name; action++) {
69 struct dentry *action_dir;
70
71 action_dir = debugfs_create_dir(action->name, actions_dir);
72 if (!action_dir)
73 goto fail;
74
75 /*
76 * Create debugfs r/w file containing action->error. If
77 * notifier call chain is called with action->val, it will
78 * fail with the error code
79 */
80 if (!debugfs_create_errno("error", mode, action_dir,
81 &action->error))
82 goto fail;
83 }
84 return dir;
85fail:
86 debugfs_remove_recursive(dir);
87 return ERR_PTR(-ENOMEM);
88}
89EXPORT_SYMBOL_GPL(notifier_err_inject_init);
90
91static int __init err_inject_init(void)
92{
93 notifier_err_inject_dir =
94 debugfs_create_dir("notifier-error-inject", NULL);
95
96 if (!notifier_err_inject_dir)
97 return -ENOMEM;
98
99 return 0;
100}
101
102static void __exit err_inject_exit(void)
103{
104 debugfs_remove_recursive(notifier_err_inject_dir);
105}
106
107module_init(err_inject_init);
108module_exit(err_inject_exit);
109
110MODULE_DESCRIPTION("Notifier error injection module");
111MODULE_LICENSE("GPL");
112MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
diff --git a/lib/notifier-error-inject.h b/lib/notifier-error-inject.h
new file mode 100644
index 000000000000..99b3b6fc470b
--- /dev/null
+++ b/lib/notifier-error-inject.h
@@ -0,0 +1,24 @@
1#include <linux/atomic.h>
2#include <linux/debugfs.h>
3#include <linux/notifier.h>
4
5struct notifier_err_inject_action {
6 unsigned long val;
7 int error;
8 const char *name;
9};
10
11#define NOTIFIER_ERR_INJECT_ACTION(action) \
12 .name = #action, .val = (action),
13
14struct notifier_err_inject {
15 struct notifier_block nb;
16 struct notifier_err_inject_action actions[];
17 /* The last slot must be terminated with zero sentinel */
18};
19
20extern struct dentry *notifier_err_inject_dir;
21
22extern struct dentry *notifier_err_inject_init(const char *name,
23 struct dentry *parent, struct notifier_err_inject *err_inject,
24 int priority);
diff --git a/lib/pSeries-reconfig-notifier-error-inject.c b/lib/pSeries-reconfig-notifier-error-inject.c
new file mode 100644
index 000000000000..7f7c98dcd5c4
--- /dev/null
+++ b/lib/pSeries-reconfig-notifier-error-inject.c
@@ -0,0 +1,51 @@
1#include <linux/kernel.h>
2#include <linux/module.h>
3
4#include <asm/pSeries_reconfig.h>
5
6#include "notifier-error-inject.h"
7
8static int priority;
9module_param(priority, int, 0);
10MODULE_PARM_DESC(priority, "specify pSeries reconfig notifier priority");
11
12static struct notifier_err_inject reconfig_err_inject = {
13 .actions = {
14 { NOTIFIER_ERR_INJECT_ACTION(PSERIES_RECONFIG_ADD) },
15 { NOTIFIER_ERR_INJECT_ACTION(PSERIES_RECONFIG_REMOVE) },
16 { NOTIFIER_ERR_INJECT_ACTION(PSERIES_DRCONF_MEM_ADD) },
17 { NOTIFIER_ERR_INJECT_ACTION(PSERIES_DRCONF_MEM_REMOVE) },
18 {}
19 }
20};
21
22static struct dentry *dir;
23
24static int err_inject_init(void)
25{
26 int err;
27
28 dir = notifier_err_inject_init("pSeries-reconfig",
29 notifier_err_inject_dir, &reconfig_err_inject, priority);
30 if (IS_ERR(dir))
31 return PTR_ERR(dir);
32
33 err = pSeries_reconfig_notifier_register(&reconfig_err_inject.nb);
34 if (err)
35 debugfs_remove_recursive(dir);
36
37 return err;
38}
39
40static void err_inject_exit(void)
41{
42 pSeries_reconfig_notifier_unregister(&reconfig_err_inject.nb);
43 debugfs_remove_recursive(dir);
44}
45
46module_init(err_inject_init);
47module_exit(err_inject_exit);
48
49MODULE_DESCRIPTION("pSeries reconfig notifier error injection module");
50MODULE_LICENSE("GPL");
51MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
diff --git a/lib/pm-notifier-error-inject.c b/lib/pm-notifier-error-inject.c
new file mode 100644
index 000000000000..c094b2dedc23
--- /dev/null
+++ b/lib/pm-notifier-error-inject.c
@@ -0,0 +1,49 @@
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/suspend.h>
4
5#include "notifier-error-inject.h"
6
7static int priority;
8module_param(priority, int, 0);
9MODULE_PARM_DESC(priority, "specify PM notifier priority");
10
11static struct notifier_err_inject pm_notifier_err_inject = {
12 .actions = {
13 { NOTIFIER_ERR_INJECT_ACTION(PM_HIBERNATION_PREPARE) },
14 { NOTIFIER_ERR_INJECT_ACTION(PM_SUSPEND_PREPARE) },
15 { NOTIFIER_ERR_INJECT_ACTION(PM_RESTORE_PREPARE) },
16 {}
17 }
18};
19
20static struct dentry *dir;
21
22static int err_inject_init(void)
23{
24 int err;
25
26 dir = notifier_err_inject_init("pm", notifier_err_inject_dir,
27 &pm_notifier_err_inject, priority);
28 if (IS_ERR(dir))
29 return PTR_ERR(dir);
30
31 err = register_pm_notifier(&pm_notifier_err_inject.nb);
32 if (err)
33 debugfs_remove_recursive(dir);
34
35 return err;
36}
37
38static void err_inject_exit(void)
39{
40 unregister_pm_notifier(&pm_notifier_err_inject.nb);
41 debugfs_remove_recursive(dir);
42}
43
44module_init(err_inject_init);
45module_exit(err_inject_exit);
46
47MODULE_DESCRIPTION("PM notifier error injection module");
48MODULE_LICENSE("GPL");
49MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index e719adf695bf..fadae774a20c 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -279,14 +279,6 @@ int __sg_alloc_table(struct sg_table *table, unsigned int nents,
279 if (!left) 279 if (!left)
280 sg_mark_end(&sg[sg_size - 1]); 280 sg_mark_end(&sg[sg_size - 1]);
281 281
282 /*
283 * only really needed for mempool backed sg allocations (like
284 * SCSI), a possible improvement here would be to pass the
285 * table pointer into the allocator and let that clear these
286 * flags
287 */
288 gfp_mask &= ~__GFP_WAIT;
289 gfp_mask |= __GFP_HIGH;
290 prv = sg; 282 prv = sg;
291 } while (left); 283 } while (left);
292 284
diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c
index e91fbc23fff1..eb10578ae055 100644
--- a/lib/spinlock_debug.c
+++ b/lib/spinlock_debug.c
@@ -58,7 +58,7 @@ static void spin_dump(raw_spinlock_t *lock, const char *msg)
58 printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n", 58 printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n",
59 msg, raw_smp_processor_id(), 59 msg, raw_smp_processor_id(),
60 current->comm, task_pid_nr(current)); 60 current->comm, task_pid_nr(current));
61 printk(KERN_EMERG " lock: %ps, .magic: %08x, .owner: %s/%d, " 61 printk(KERN_EMERG " lock: %pS, .magic: %08x, .owner: %s/%d, "
62 ".owner_cpu: %d\n", 62 ".owner_cpu: %d\n",
63 lock, lock->magic, 63 lock, lock->magic,
64 owner ? owner->comm : "<none>", 64 owner ? owner->comm : "<none>",
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c3f36d415bdf..0e337541f005 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -655,6 +655,50 @@ char *resource_string(char *buf, char *end, struct resource *res,
655} 655}
656 656
657static noinline_for_stack 657static noinline_for_stack
658char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
659 const char *fmt)
660{
661 int i, len = 1; /* if we pass '%ph[CDN]', field witdh remains
662 negative value, fallback to the default */
663 char separator;
664
665 if (spec.field_width == 0)
666 /* nothing to print */
667 return buf;
668
669 if (ZERO_OR_NULL_PTR(addr))
670 /* NULL pointer */
671 return string(buf, end, NULL, spec);
672
673 switch (fmt[1]) {
674 case 'C':
675 separator = ':';
676 break;
677 case 'D':
678 separator = '-';
679 break;
680 case 'N':
681 separator = 0;
682 break;
683 default:
684 separator = ' ';
685 break;
686 }
687
688 if (spec.field_width > 0)
689 len = min_t(int, spec.field_width, 64);
690
691 for (i = 0; i < len && buf < end - 1; i++) {
692 buf = hex_byte_pack(buf, addr[i]);
693
694 if (buf < end && separator && i != len - 1)
695 *buf++ = separator;
696 }
697
698 return buf;
699}
700
701static noinline_for_stack
658char *mac_address_string(char *buf, char *end, u8 *addr, 702char *mac_address_string(char *buf, char *end, u8 *addr,
659 struct printf_spec spec, const char *fmt) 703 struct printf_spec spec, const char *fmt)
660{ 704{
@@ -662,15 +706,28 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
662 char *p = mac_addr; 706 char *p = mac_addr;
663 int i; 707 int i;
664 char separator; 708 char separator;
709 bool reversed = false;
665 710
666 if (fmt[1] == 'F') { /* FDDI canonical format */ 711 switch (fmt[1]) {
712 case 'F':
667 separator = '-'; 713 separator = '-';
668 } else { 714 break;
715
716 case 'R':
717 reversed = true;
718 /* fall through */
719
720 default:
669 separator = ':'; 721 separator = ':';
722 break;
670 } 723 }
671 724
672 for (i = 0; i < 6; i++) { 725 for (i = 0; i < 6; i++) {
673 p = hex_byte_pack(p, addr[i]); 726 if (reversed)
727 p = hex_byte_pack(p, addr[5 - i]);
728 else
729 p = hex_byte_pack(p, addr[i]);
730
674 if (fmt[0] == 'M' && i != 5) 731 if (fmt[0] == 'M' && i != 5)
675 *p++ = separator; 732 *p++ = separator;
676 } 733 }
@@ -933,6 +990,7 @@ int kptr_restrict __read_mostly;
933 * - 'm' For a 6-byte MAC address, it prints the hex address without colons 990 * - 'm' For a 6-byte MAC address, it prints the hex address without colons
934 * - 'MF' For a 6-byte MAC FDDI address, it prints the address 991 * - 'MF' For a 6-byte MAC FDDI address, it prints the address
935 * with a dash-separated hex notation 992 * with a dash-separated hex notation
993 * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth)
936 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way 994 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
937 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) 995 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
938 * IPv6 uses colon separated network-order 16 bit hex with leading 0's 996 * IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -960,6 +1018,13 @@ int kptr_restrict __read_mostly;
960 * correctness of the format string and va_list arguments. 1018 * correctness of the format string and va_list arguments.
961 * - 'K' For a kernel pointer that should be hidden from unprivileged users 1019 * - 'K' For a kernel pointer that should be hidden from unprivileged users
962 * - 'NF' For a netdev_features_t 1020 * - 'NF' For a netdev_features_t
1021 * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with
1022 * a certain separator (' ' by default):
1023 * C colon
1024 * D dash
1025 * N no separator
1026 * The maximum supported length is 64 bytes of the input. Consider
1027 * to use print_hex_dump() for the larger input.
963 * 1028 *
964 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 1029 * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
965 * function pointers are really function descriptors, which contain a 1030 * function pointers are really function descriptors, which contain a
@@ -993,9 +1058,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
993 case 'R': 1058 case 'R':
994 case 'r': 1059 case 'r':
995 return resource_string(buf, end, ptr, spec, fmt); 1060 return resource_string(buf, end, ptr, spec, fmt);
1061 case 'h':
1062 return hex_string(buf, end, ptr, spec, fmt);
996 case 'M': /* Colon separated: 00:01:02:03:04:05 */ 1063 case 'M': /* Colon separated: 00:01:02:03:04:05 */
997 case 'm': /* Contiguous: 000102030405 */ 1064 case 'm': /* Contiguous: 000102030405 */
998 /* [mM]F (FDDI, bit reversed) */ 1065 /* [mM]F (FDDI) */
1066 /* [mM]R (Reverse order; Bluetooth) */
999 return mac_address_string(buf, end, ptr, spec, fmt); 1067 return mac_address_string(buf, end, ptr, spec, fmt);
1000 case 'I': /* Formatted IP supported 1068 case 'I': /* Formatted IP supported
1001 * 4: 1.2.3.4 1069 * 4: 1.2.3.4
@@ -1030,7 +1098,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1030 * %pK cannot be used in IRQ context because its test 1098 * %pK cannot be used in IRQ context because its test
1031 * for CAP_SYSLOG would be meaningless. 1099 * for CAP_SYSLOG would be meaningless.
1032 */ 1100 */
1033 if (in_irq() || in_serving_softirq() || in_nmi()) { 1101 if (kptr_restrict && (in_irq() || in_serving_softirq() ||
1102 in_nmi())) {
1034 if (spec.field_width == -1) 1103 if (spec.field_width == -1)
1035 spec.field_width = default_width; 1104 spec.field_width = default_width;
1036 return string(buf, end, "pK-error", spec); 1105 return string(buf, end, "pK-error", spec);
@@ -1280,8 +1349,12 @@ qualifier:
1280 * %pI6c print an IPv6 address as specified by RFC 5952 1349 * %pI6c print an IPv6 address as specified by RFC 5952
1281 * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper 1350 * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper
1282 * case. 1351 * case.
1352 * %*ph[CDN] a variable-length hex string with a separator (supports up to 64
1353 * bytes of the input)
1283 * %n is ignored 1354 * %n is ignored
1284 * 1355 *
1356 * ** Please update Documentation/printk-formats.txt when making changes **
1357 *
1285 * The return value is the number of characters which would 1358 * The return value is the number of characters which would
1286 * be generated for the given input, excluding the trailing 1359 * be generated for the given input, excluding the trailing
1287 * '\0', as per ISO C99. If you want to have the exact 1360 * '\0', as per ISO C99. If you want to have the exact