Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 1 | #include <linux/fault-inject.h> |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 2 | #include <linux/slab.h> |
Jesper Dangaard Brouer | fab9963 | 2016-03-15 14:53:38 -0700 | [diff] [blame] | 3 | #include <linux/mm.h> |
| 4 | #include "slab.h" |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 5 | |
| 6 | static struct { |
| 7 | struct fault_attr attr; |
Mel Gorman | 71baba4 | 2015-11-06 16:28:28 -0800 | [diff] [blame] | 8 | bool ignore_gfp_reclaim; |
Viresh Kumar | 621a5f7 | 2015-09-26 15:04:07 -0700 | [diff] [blame] | 9 | bool cache_filter; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 10 | } failslab = { |
| 11 | .attr = FAULT_ATTR_INITIALIZER, |
Mel Gorman | 71baba4 | 2015-11-06 16:28:28 -0800 | [diff] [blame] | 12 | .ignore_gfp_reclaim = true, |
Viresh Kumar | 621a5f7 | 2015-09-26 15:04:07 -0700 | [diff] [blame] | 13 | .cache_filter = false, |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 14 | }; |
| 15 | |
Jesper Dangaard Brouer | fab9963 | 2016-03-15 14:53:38 -0700 | [diff] [blame] | 16 | bool should_failslab(struct kmem_cache *s, gfp_t gfpflags) |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 17 | { |
Jesper Dangaard Brouer | fab9963 | 2016-03-15 14:53:38 -0700 | [diff] [blame] | 18 | /* No fault-injection for bootstrap cache */ |
| 19 | if (unlikely(s == kmem_cache)) |
| 20 | return false; |
| 21 | |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 22 | if (gfpflags & __GFP_NOFAIL) |
| 23 | return false; |
| 24 | |
Mel Gorman | 71baba4 | 2015-11-06 16:28:28 -0800 | [diff] [blame] | 25 | if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM)) |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 26 | return false; |
| 27 | |
Jesper Dangaard Brouer | fab9963 | 2016-03-15 14:53:38 -0700 | [diff] [blame] | 28 | if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB)) |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 29 | return false; |
| 30 | |
Jesper Dangaard Brouer | fab9963 | 2016-03-15 14:53:38 -0700 | [diff] [blame] | 31 | return should_fail(&failslab.attr, s->object_size); |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static int __init setup_failslab(char *str) |
| 35 | { |
| 36 | return setup_fault_attr(&failslab.attr, str); |
| 37 | } |
| 38 | __setup("failslab=", setup_failslab); |
| 39 | |
| 40 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 41 | static int __init failslab_debugfs_init(void) |
| 42 | { |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 43 | struct dentry *dir; |
Al Viro | f4ae40a6 | 2011-07-24 04:33:43 -0400 | [diff] [blame] | 44 | umode_t mode = S_IFREG | S_IRUSR | S_IWUSR; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 45 | |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 46 | dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr); |
| 47 | if (IS_ERR(dir)) |
| 48 | return PTR_ERR(dir); |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 49 | |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 50 | if (!debugfs_create_bool("ignore-gfp-wait", mode, dir, |
Mel Gorman | 71baba4 | 2015-11-06 16:28:28 -0800 | [diff] [blame] | 51 | &failslab.ignore_gfp_reclaim)) |
Akinobu Mita | 810f09b | 2011-07-26 16:09:02 -0700 | [diff] [blame] | 52 | goto fail; |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 53 | if (!debugfs_create_bool("cache-filter", mode, dir, |
Akinobu Mita | 810f09b | 2011-07-26 16:09:02 -0700 | [diff] [blame] | 54 | &failslab.cache_filter)) |
| 55 | goto fail; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 56 | |
Akinobu Mita | 810f09b | 2011-07-26 16:09:02 -0700 | [diff] [blame] | 57 | return 0; |
| 58 | fail: |
Akinobu Mita | dd48c08 | 2011-08-03 16:21:01 -0700 | [diff] [blame] | 59 | debugfs_remove_recursive(dir); |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 60 | |
Akinobu Mita | 810f09b | 2011-07-26 16:09:02 -0700 | [diff] [blame] | 61 | return -ENOMEM; |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | late_initcall(failslab_debugfs_init); |
| 65 | |
| 66 | #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ |