]>
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 | ||
4f6923fb | 17 | bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags) |
773ff60e | 18 | { |
ea4452de QZ |
19 | int flags = 0; |
20 | ||
fab9963a JDB |
21 | /* No fault-injection for bootstrap cache */ |
22 | if (unlikely(s == kmem_cache)) | |
23 | return false; | |
24 | ||
773ff60e AM |
25 | if (gfpflags & __GFP_NOFAIL) |
26 | return false; | |
27 | ||
a9659476 NB |
28 | if (failslab.ignore_gfp_reclaim && |
29 | (gfpflags & __GFP_DIRECT_RECLAIM)) | |
773ff60e AM |
30 | return false; |
31 | ||
fab9963a | 32 | if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB)) |
4c13dd3b DM |
33 | return false; |
34 | ||
ea4452de QZ |
35 | /* |
36 | * In some cases, it expects to specify __GFP_NOWARN | |
37 | * to avoid printing any information(not just a warning), | |
38 | * thus avoiding deadlocks. See commit 6b9dbedbe349 for | |
39 | * details. | |
40 | */ | |
3f913fc5 | 41 | if (gfpflags & __GFP_NOWARN) |
ea4452de | 42 | flags |= FAULT_NOWARN; |
3f913fc5 | 43 | |
ea4452de | 44 | return should_fail_ex(&failslab.attr, s->object_size, flags); |
773ff60e AM |
45 | } |
46 | ||
47 | static int __init setup_failslab(char *str) | |
48 | { | |
49 | return setup_fault_attr(&failslab.attr, str); | |
50 | } | |
51 | __setup("failslab=", setup_failslab); | |
52 | ||
53 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS | |
773ff60e AM |
54 | static int __init failslab_debugfs_init(void) |
55 | { | |
dd48c085 | 56 | struct dentry *dir; |
0825a6f9 | 57 | umode_t mode = S_IFREG | 0600; |
773ff60e | 58 | |
dd48c085 AM |
59 | dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr); |
60 | if (IS_ERR(dir)) | |
61 | return PTR_ERR(dir); | |
773ff60e | 62 | |
d9f7979c GKH |
63 | debugfs_create_bool("ignore-gfp-wait", mode, dir, |
64 | &failslab.ignore_gfp_reclaim); | |
65 | debugfs_create_bool("cache-filter", mode, dir, | |
66 | &failslab.cache_filter); | |
4c13dd3b | 67 | |
810f09b8 | 68 | return 0; |
773ff60e AM |
69 | } |
70 | ||
71 | late_initcall(failslab_debugfs_init); | |
72 | ||
73 | #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ |