1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/fault-inject.h>
3 #include <linux/error-injection.h>
4 #include <linux/debugfs.h>
5 #include <linux/slab.h>
10 struct fault_attr attr
;
11 bool ignore_gfp_reclaim
;
14 .attr
= FAULT_ATTR_INITIALIZER
,
15 .ignore_gfp_reclaim
= true,
16 .cache_filter
= false,
19 int should_failslab(struct kmem_cache
*s
, gfp_t gfpflags
)
23 /* No fault-injection for bootstrap cache */
24 if (unlikely(s
== kmem_cache
))
27 if (gfpflags
& __GFP_NOFAIL
)
30 if (failslab
.ignore_gfp_reclaim
&&
31 (gfpflags
& __GFP_DIRECT_RECLAIM
))
34 if (failslab
.cache_filter
&& !(s
->flags
& SLAB_FAILSLAB
))
38 * In some cases, it expects to specify __GFP_NOWARN
39 * to avoid printing any information(not just a warning),
40 * thus avoiding deadlocks. See commit 6b9dbedbe349 for
43 if (gfpflags
& __GFP_NOWARN
)
44 flags
|= FAULT_NOWARN
;
46 return should_fail_ex(&failslab
.attr
, s
->object_size
, flags
) ? -ENOMEM
: 0;
48 ALLOW_ERROR_INJECTION(should_failslab
, ERRNO
);
50 static int __init
setup_failslab(char *str
)
52 return setup_fault_attr(&failslab
.attr
, str
);
54 __setup("failslab=", setup_failslab
);
56 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
57 static int __init
failslab_debugfs_init(void)
60 umode_t mode
= S_IFREG
| 0600;
62 dir
= fault_create_debugfs_attr("failslab", NULL
, &failslab
.attr
);
66 debugfs_create_bool("ignore-gfp-wait", mode
, dir
,
67 &failslab
.ignore_gfp_reclaim
);
68 debugfs_create_bool("cache-filter", mode
, dir
,
69 &failslab
.cache_filter
);
74 late_initcall(failslab_debugfs_init
);
76 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */