]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
773ff60e | 2 | #include <linux/fault-inject.h> |
4c13dd3b | 3 | #include <linux/slab.h> |
fab9963a JDB |
4 | #include <linux/mm.h> |
5 | #include "slab.h" | |
773ff60e AM |
6 | |
7 | static struct { | |
8 | struct fault_attr attr; | |
71baba4b | 9 | bool ignore_gfp_reclaim; |
621a5f7a | 10 | bool cache_filter; |
773ff60e AM |
11 | } failslab = { |
12 | .attr = FAULT_ATTR_INITIALIZER, | |
71baba4b | 13 | .ignore_gfp_reclaim = true, |
621a5f7a | 14 | .cache_filter = false, |
773ff60e AM |
15 | }; |
16 | ||
fab9963a | 17 | bool should_failslab(struct kmem_cache *s, gfp_t gfpflags) |
773ff60e | 18 | { |
fab9963a JDB |
19 | /* No fault-injection for bootstrap cache */ |
20 | if (unlikely(s == kmem_cache)) | |
21 | return false; | |
22 | ||
773ff60e AM |
23 | if (gfpflags & __GFP_NOFAIL) |
24 | return false; | |
25 | ||
71baba4b | 26 | if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM)) |
773ff60e AM |
27 | return false; |
28 | ||
fab9963a | 29 | if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB)) |
4c13dd3b DM |
30 | return false; |
31 | ||
fab9963a | 32 | return should_fail(&failslab.attr, s->object_size); |
773ff60e AM |
33 | } |
34 | ||
35 | static int __init setup_failslab(char *str) | |
36 | { | |
37 | return setup_fault_attr(&failslab.attr, str); | |
38 | } | |
39 | __setup("failslab=", setup_failslab); | |
40 | ||
41 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS | |
773ff60e AM |
42 | static int __init failslab_debugfs_init(void) |
43 | { | |
dd48c085 | 44 | struct dentry *dir; |
f4ae40a6 | 45 | umode_t mode = S_IFREG | S_IRUSR | S_IWUSR; |
773ff60e | 46 | |
dd48c085 AM |
47 | dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr); |
48 | if (IS_ERR(dir)) | |
49 | return PTR_ERR(dir); | |
773ff60e | 50 | |
dd48c085 | 51 | if (!debugfs_create_bool("ignore-gfp-wait", mode, dir, |
71baba4b | 52 | &failslab.ignore_gfp_reclaim)) |
810f09b8 | 53 | goto fail; |
dd48c085 | 54 | if (!debugfs_create_bool("cache-filter", mode, dir, |
810f09b8 AM |
55 | &failslab.cache_filter)) |
56 | goto fail; | |
4c13dd3b | 57 | |
810f09b8 AM |
58 | return 0; |
59 | fail: | |
dd48c085 | 60 | debugfs_remove_recursive(dir); |
773ff60e | 61 | |
810f09b8 | 62 | return -ENOMEM; |
773ff60e AM |
63 | } |
64 | ||
65 | late_initcall(failslab_debugfs_init); | |
66 | ||
67 | #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ |