Merge tag 'v3.10.68' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / mm / failslab.c
CommitLineData
773ff60e 1#include <linux/fault-inject.h>
4c13dd3b 2#include <linux/slab.h>
773ff60e
AM
3
4static struct {
5 struct fault_attr attr;
6 u32 ignore_gfp_wait;
4c13dd3b 7 int cache_filter;
773ff60e
AM
8} failslab = {
9 .attr = FAULT_ATTR_INITIALIZER,
10 .ignore_gfp_wait = 1,
4c13dd3b 11 .cache_filter = 0,
773ff60e
AM
12};
13
4c13dd3b 14bool should_failslab(size_t size, gfp_t gfpflags, unsigned long cache_flags)
773ff60e
AM
15{
16 if (gfpflags & __GFP_NOFAIL)
17 return false;
18
19 if (failslab.ignore_gfp_wait && (gfpflags & __GFP_WAIT))
20 return false;
21
4c13dd3b
DM
22 if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB))
23 return false;
24
773ff60e
AM
25 return should_fail(&failslab.attr, size);
26}
27
28static int __init setup_failslab(char *str)
29{
30 return setup_fault_attr(&failslab.attr, str);
31}
32__setup("failslab=", setup_failslab);
33
34#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
773ff60e
AM
35static int __init failslab_debugfs_init(void)
36{
dd48c085 37 struct dentry *dir;
f4ae40a6 38 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
773ff60e 39
dd48c085
AM
40 dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
41 if (IS_ERR(dir))
42 return PTR_ERR(dir);
773ff60e 43
dd48c085 44 if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
810f09b8
AM
45 &failslab.ignore_gfp_wait))
46 goto fail;
dd48c085 47 if (!debugfs_create_bool("cache-filter", mode, dir,
810f09b8
AM
48 &failslab.cache_filter))
49 goto fail;
4c13dd3b 50
810f09b8
AM
51 return 0;
52fail:
dd48c085 53 debugfs_remove_recursive(dir);
773ff60e 54
810f09b8 55 return -ENOMEM;
773ff60e
AM
56}
57
58late_initcall(failslab_debugfs_init);
59
60#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */