From 76cb841cb886eef6b3bee341a2266c76578724ad Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 May 2024 03:02:30 +0200 Subject: Adding upstream version 4.19.249. Signed-off-by: Daniel Baumann --- mm/failslab.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 mm/failslab.c (limited to 'mm/failslab.c') diff --git a/mm/failslab.c b/mm/failslab.c new file mode 100644 index 000000000..b135ebb88 --- /dev/null +++ b/mm/failslab.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include "slab.h" + +static struct { + struct fault_attr attr; + bool ignore_gfp_reclaim; + bool cache_filter; +} failslab = { + .attr = FAULT_ATTR_INITIALIZER, + .ignore_gfp_reclaim = true, + .cache_filter = false, +}; + +bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags) +{ + /* No fault-injection for bootstrap cache */ + if (unlikely(s == kmem_cache)) + return false; + + if (gfpflags & __GFP_NOFAIL) + return false; + + if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM)) + return false; + + if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB)) + return false; + + return should_fail(&failslab.attr, s->object_size); +} + +static int __init setup_failslab(char *str) +{ + return setup_fault_attr(&failslab.attr, str); +} +__setup("failslab=", setup_failslab); + +#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS +static int __init failslab_debugfs_init(void) +{ + struct dentry *dir; + umode_t mode = S_IFREG | 0600; + + dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr); + if (IS_ERR(dir)) + return PTR_ERR(dir); + + if (!debugfs_create_bool("ignore-gfp-wait", mode, dir, + &failslab.ignore_gfp_reclaim)) + goto fail; + if (!debugfs_create_bool("cache-filter", mode, dir, + &failslab.cache_filter)) + goto fail; + + return 0; +fail: + debugfs_remove_recursive(dir); + + return -ENOMEM; +} + +late_initcall(failslab_debugfs_init); + +#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ -- cgit v1.2.3