Linux Audio

Check our new training course

Loading...
v3.1
 
 1#include <linux/fault-inject.h>
 
 
 2#include <linux/slab.h>
 
 
 3
 4static struct {
 5	struct fault_attr attr;
 6	u32 ignore_gfp_wait;
 7	int cache_filter;
 8} failslab = {
 9	.attr = FAULT_ATTR_INITIALIZER,
10	.ignore_gfp_wait = 1,
11	.cache_filter = 0,
12};
13
14bool should_failslab(size_t size, gfp_t gfpflags, unsigned long cache_flags)
15{
16	if (gfpflags & __GFP_NOFAIL)
17		return false;
 
 
 
18
19        if (failslab.ignore_gfp_wait && (gfpflags & __GFP_WAIT))
20		return false;
21
22	if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB))
23		return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
24
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
35static int __init failslab_debugfs_init(void)
36{
37	struct dentry *dir;
38	mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
39
40	dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
41	if (IS_ERR(dir))
42		return PTR_ERR(dir);
43
44	if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
45				&failslab.ignore_gfp_wait))
46		goto fail;
47	if (!debugfs_create_bool("cache-filter", mode, dir,
48				&failslab.cache_filter))
49		goto fail;
50
51	return 0;
52fail:
53	debugfs_remove_recursive(dir);
54
55	return -ENOMEM;
56}
57
58late_initcall(failslab_debugfs_init);
59
60#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
v6.13.7
 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>
 6#include <linux/mm.h>
 7#include "slab.h"
 8
 9static struct {
10	struct fault_attr attr;
11	bool ignore_gfp_reclaim;
12	bool cache_filter;
13} failslab = {
14	.attr = FAULT_ATTR_INITIALIZER,
15	.ignore_gfp_reclaim = true,
16	.cache_filter = false,
17};
18
19int should_failslab(struct kmem_cache *s, gfp_t gfpflags)
20{
21	int flags = 0;
22
23	/* No fault-injection for bootstrap cache */
24	if (unlikely(s == kmem_cache))
25		return 0;
26
27	if (gfpflags & __GFP_NOFAIL)
28		return 0;
29
30	if (failslab.ignore_gfp_reclaim &&
31			(gfpflags & __GFP_DIRECT_RECLAIM))
32		return 0;
33
34	if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB))
35		return 0;
36
37	/*
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
41	 * details.
42	 */
43	if (gfpflags & __GFP_NOWARN)
44		flags |= FAULT_NOWARN;
45
46	return should_fail_ex(&failslab.attr, s->object_size, flags) ? -ENOMEM : 0;
47}
48ALLOW_ERROR_INJECTION(should_failslab, ERRNO);
49
50static int __init setup_failslab(char *str)
51{
52	return setup_fault_attr(&failslab.attr, str);
53}
54__setup("failslab=", setup_failslab);
55
56#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
57static int __init failslab_debugfs_init(void)
58{
59	struct dentry *dir;
60	umode_t mode = S_IFREG | 0600;
61
62	dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
63	if (IS_ERR(dir))
64		return PTR_ERR(dir);
65
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);
 
 
70
71	return 0;
 
 
 
 
72}
73
74late_initcall(failslab_debugfs_init);
75
76#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */