aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@kernel.org>2018-01-12 12:55:33 -0500
committerAlexei Starovoitov <ast@kernel.org>2018-01-12 20:33:38 -0500
commit663faf9f7beeaca4ad0176bb96c776eed9dad0c5 (patch)
tree6784344ffd1b031664899d9272aa0005f4584420
parent540adea3809f61115d2a1ea4ed6e627613452ba1 (diff)
error-injection: Add injectable error types
Add injectable error types for each error-injectable function. One motivation of error injection test is to find software flaws, mistakes or mis-handlings of expectable errors. If we find such flaws by the test, that is a program bug, so we need to fix it. But if the tester miss input the error (e.g. just return success code without processing anything), it causes unexpected behavior even if the caller is correctly programmed to handle any errors. That is not what we want to test by error injection. To clarify what type of errors the caller must expect for each injectable function, this introduces injectable error types: - EI_ETYPE_NULL : means the function will return NULL if it fails. No ERR_PTR, just a NULL. - EI_ETYPE_ERRNO : means the function will return -ERRNO if it fails. - EI_ETYPE_ERRNO_NULL : means the function will return -ERRNO (ERR_PTR) or NULL. ALLOW_ERROR_INJECTION() macro is expanded to get one of NULL, ERRNO, ERRNO_NULL to record the error type for each function. e.g. ALLOW_ERROR_INJECTION(open_ctree, ERRNO) This error types are shown in debugfs as below. ==== / # cat /sys/kernel/debug/error_injection/list open_ctree [btrfs] ERRNO io_ctl_init [btrfs] ERRNO ==== Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Reviewed-by: Josef Bacik <jbacik@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r--fs/btrfs/disk-io.c2
-rw-r--r--fs/btrfs/free-space-cache.c2
-rw-r--r--include/asm-generic/error-injection.h23
-rw-r--r--include/asm-generic/vmlinux.lds.h2
-rw-r--r--include/linux/error-injection.h6
-rw-r--r--include/linux/module.h3
-rw-r--r--lib/error-inject.c43
7 files changed, 66 insertions, 15 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 9798e21ebe9d..83e2349e1362 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3124,7 +3124,7 @@ recovery_tree_root:
3124 goto fail_block_groups; 3124 goto fail_block_groups;
3125 goto retry_root_backup; 3125 goto retry_root_backup;
3126} 3126}
3127ALLOW_ERROR_INJECTION(open_ctree); 3127ALLOW_ERROR_INJECTION(open_ctree, ERRNO);
3128 3128
3129static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate) 3129static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
3130{ 3130{
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index ef847699031a..586bb06472bb 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -333,7 +333,7 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,
333 333
334 return 0; 334 return 0;
335} 335}
336ALLOW_ERROR_INJECTION(io_ctl_init); 336ALLOW_ERROR_INJECTION(io_ctl_init, ERRNO);
337 337
338static void io_ctl_free(struct btrfs_io_ctl *io_ctl) 338static void io_ctl_free(struct btrfs_io_ctl *io_ctl)
339{ 339{
diff --git a/include/asm-generic/error-injection.h b/include/asm-generic/error-injection.h
index 08352c9d9f97..296c65442f00 100644
--- a/include/asm-generic/error-injection.h
+++ b/include/asm-generic/error-injection.h
@@ -3,17 +3,32 @@
3#define _ASM_GENERIC_ERROR_INJECTION_H 3#define _ASM_GENERIC_ERROR_INJECTION_H
4 4
5#if defined(__KERNEL__) && !defined(__ASSEMBLY__) 5#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
6enum {
7 EI_ETYPE_NONE, /* Dummy value for undefined case */
8 EI_ETYPE_NULL, /* Return NULL if failure */
9 EI_ETYPE_ERRNO, /* Return -ERRNO if failure */
10 EI_ETYPE_ERRNO_NULL, /* Return -ERRNO or NULL if failure */
11};
12
13struct error_injection_entry {
14 unsigned long addr;
15 int etype;
16};
17
6#ifdef CONFIG_FUNCTION_ERROR_INJECTION 18#ifdef CONFIG_FUNCTION_ERROR_INJECTION
7/* 19/*
8 * Whitelist ganerating macro. Specify functions which can be 20 * Whitelist ganerating macro. Specify functions which can be
9 * error-injectable using this macro. 21 * error-injectable using this macro.
10 */ 22 */
11#define ALLOW_ERROR_INJECTION(fname) \ 23#define ALLOW_ERROR_INJECTION(fname, _etype) \
12static unsigned long __used \ 24static struct error_injection_entry __used \
13 __attribute__((__section__("_error_injection_whitelist"))) \ 25 __attribute__((__section__("_error_injection_whitelist"))) \
14 _eil_addr_##fname = (unsigned long)fname; 26 _eil_addr_##fname = { \
27 .addr = (unsigned long)fname, \
28 .etype = EI_ETYPE_##_etype, \
29 };
15#else 30#else
16#define ALLOW_ERROR_INJECTION(fname) 31#define ALLOW_ERROR_INJECTION(fname, _etype)
17#endif 32#endif
18#endif 33#endif
19 34
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index f2068cca5206..ebe544e048cd 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -137,7 +137,7 @@
137#endif 137#endif
138 138
139#ifdef CONFIG_FUNCTION_ERROR_INJECTION 139#ifdef CONFIG_FUNCTION_ERROR_INJECTION
140#define ERROR_INJECT_WHITELIST() . = ALIGN(8); \ 140#define ERROR_INJECT_WHITELIST() STRUCT_ALIGN(); \
141 VMLINUX_SYMBOL(__start_error_injection_whitelist) = .;\ 141 VMLINUX_SYMBOL(__start_error_injection_whitelist) = .;\
142 KEEP(*(_error_injection_whitelist)) \ 142 KEEP(*(_error_injection_whitelist)) \
143 VMLINUX_SYMBOL(__stop_error_injection_whitelist) = .; 143 VMLINUX_SYMBOL(__stop_error_injection_whitelist) = .;
diff --git a/include/linux/error-injection.h b/include/linux/error-injection.h
index 130a67c50dac..280c61ecbf20 100644
--- a/include/linux/error-injection.h
+++ b/include/linux/error-injection.h
@@ -7,6 +7,7 @@
7#include <asm/error-injection.h> 7#include <asm/error-injection.h>
8 8
9extern bool within_error_injection_list(unsigned long addr); 9extern bool within_error_injection_list(unsigned long addr);
10extern int get_injectable_error_type(unsigned long addr);
10 11
11#else /* !CONFIG_FUNCTION_ERROR_INJECTION */ 12#else /* !CONFIG_FUNCTION_ERROR_INJECTION */
12 13
@@ -16,6 +17,11 @@ static inline bool within_error_injection_list(unsigned long addr)
16 return false; 17 return false;
17} 18}
18 19
20static inline int get_injectable_error_type(unsigned long addr)
21{
22 return EI_ETYPE_NONE;
23}
24
19#endif 25#endif
20 26
21#endif /* _LINUX_ERROR_INJECTION_H */ 27#endif /* _LINUX_ERROR_INJECTION_H */
diff --git a/include/linux/module.h b/include/linux/module.h
index 792e51d83bda..9642d3116718 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -19,6 +19,7 @@
19#include <linux/jump_label.h> 19#include <linux/jump_label.h>
20#include <linux/export.h> 20#include <linux/export.h>
21#include <linux/rbtree_latch.h> 21#include <linux/rbtree_latch.h>
22#include <linux/error-injection.h>
22 23
23#include <linux/percpu.h> 24#include <linux/percpu.h>
24#include <asm/module.h> 25#include <asm/module.h>
@@ -477,8 +478,8 @@ struct module {
477#endif 478#endif
478 479
479#ifdef CONFIG_FUNCTION_ERROR_INJECTION 480#ifdef CONFIG_FUNCTION_ERROR_INJECTION
481 struct error_injection_entry *ei_funcs;
480 unsigned int num_ei_funcs; 482 unsigned int num_ei_funcs;
481 unsigned long *ei_funcs;
482#endif 483#endif
483} ____cacheline_aligned __randomize_layout; 484} ____cacheline_aligned __randomize_layout;
484#ifndef MODULE_ARCH_INIT 485#ifndef MODULE_ARCH_INIT
diff --git a/lib/error-inject.c b/lib/error-inject.c
index bccadcf3c981..c0d4600f4896 100644
--- a/lib/error-inject.c
+++ b/lib/error-inject.c
@@ -16,6 +16,7 @@ struct ei_entry {
16 struct list_head list; 16 struct list_head list;
17 unsigned long start_addr; 17 unsigned long start_addr;
18 unsigned long end_addr; 18 unsigned long end_addr;
19 int etype;
19 void *priv; 20 void *priv;
20}; 21};
21 22
@@ -35,6 +36,17 @@ bool within_error_injection_list(unsigned long addr)
35 return ret; 36 return ret;
36} 37}
37 38
39int get_injectable_error_type(unsigned long addr)
40{
41 struct ei_entry *ent;
42
43 list_for_each_entry(ent, &error_injection_list, list) {
44 if (addr >= ent->start_addr && addr < ent->end_addr)
45 return ent->etype;
46 }
47 return EI_ETYPE_NONE;
48}
49
38/* 50/*
39 * Lookup and populate the error_injection_list. 51 * Lookup and populate the error_injection_list.
40 * 52 *
@@ -42,16 +54,17 @@ bool within_error_injection_list(unsigned long addr)
42 * bpf_error_injection, so we need to populate the list of the symbols that have 54 * bpf_error_injection, so we need to populate the list of the symbols that have
43 * been marked as safe for overriding. 55 * been marked as safe for overriding.
44 */ 56 */
45static void populate_error_injection_list(unsigned long *start, 57static void populate_error_injection_list(struct error_injection_entry *start,
46 unsigned long *end, void *priv) 58 struct error_injection_entry *end,
59 void *priv)
47{ 60{
48 unsigned long *iter; 61 struct error_injection_entry *iter;
49 struct ei_entry *ent; 62 struct ei_entry *ent;
50 unsigned long entry, offset = 0, size = 0; 63 unsigned long entry, offset = 0, size = 0;
51 64
52 mutex_lock(&ei_mutex); 65 mutex_lock(&ei_mutex);
53 for (iter = start; iter < end; iter++) { 66 for (iter = start; iter < end; iter++) {
54 entry = arch_deref_entry_point((void *)*iter); 67 entry = arch_deref_entry_point((void *)iter->addr);
55 68
56 if (!kernel_text_address(entry) || 69 if (!kernel_text_address(entry) ||
57 !kallsyms_lookup_size_offset(entry, &size, &offset)) { 70 !kallsyms_lookup_size_offset(entry, &size, &offset)) {
@@ -65,6 +78,7 @@ static void populate_error_injection_list(unsigned long *start,
65 break; 78 break;
66 ent->start_addr = entry; 79 ent->start_addr = entry;
67 ent->end_addr = entry + size; 80 ent->end_addr = entry + size;
81 ent->etype = iter->etype;
68 ent->priv = priv; 82 ent->priv = priv;
69 INIT_LIST_HEAD(&ent->list); 83 INIT_LIST_HEAD(&ent->list);
70 list_add_tail(&ent->list, &error_injection_list); 84 list_add_tail(&ent->list, &error_injection_list);
@@ -73,8 +87,8 @@ static void populate_error_injection_list(unsigned long *start,
73} 87}
74 88
75/* Markers of the _error_inject_whitelist section */ 89/* Markers of the _error_inject_whitelist section */
76extern unsigned long __start_error_injection_whitelist[]; 90extern struct error_injection_entry __start_error_injection_whitelist[];
77extern unsigned long __stop_error_injection_whitelist[]; 91extern struct error_injection_entry __stop_error_injection_whitelist[];
78 92
79static void __init populate_kernel_ei_list(void) 93static void __init populate_kernel_ei_list(void)
80{ 94{
@@ -157,11 +171,26 @@ static void *ei_seq_next(struct seq_file *m, void *v, loff_t *pos)
157 return seq_list_next(v, &error_injection_list, pos); 171 return seq_list_next(v, &error_injection_list, pos);
158} 172}
159 173
174static const char *error_type_string(int etype)
175{
176 switch (etype) {
177 case EI_ETYPE_NULL:
178 return "NULL";
179 case EI_ETYPE_ERRNO:
180 return "ERRNO";
181 case EI_ETYPE_ERRNO_NULL:
182 return "ERRNO_NULL";
183 default:
184 return "(unknown)";
185 }
186}
187
160static int ei_seq_show(struct seq_file *m, void *v) 188static int ei_seq_show(struct seq_file *m, void *v)
161{ 189{
162 struct ei_entry *ent = list_entry(v, struct ei_entry, list); 190 struct ei_entry *ent = list_entry(v, struct ei_entry, list);
163 191
164 seq_printf(m, "%pf\n", (void *)ent->start_addr); 192 seq_printf(m, "%pf\t%s\n", (void *)ent->start_addr,
193 error_type_string(ent->etype));
165 return 0; 194 return 0;
166} 195}
167 196