1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/fault-inject.h> 2 #include <linux/fault-inject.h> 3 #include <linux/error-injection.h> << 4 #include <linux/mm.h> 3 #include <linux/mm.h> 5 4 6 static struct { 5 static struct { 7 struct fault_attr attr; 6 struct fault_attr attr; 8 7 9 bool ignore_gfp_highmem; 8 bool ignore_gfp_highmem; 10 bool ignore_gfp_reclaim; 9 bool ignore_gfp_reclaim; 11 u32 min_order; 10 u32 min_order; 12 } fail_page_alloc = { 11 } fail_page_alloc = { 13 .attr = FAULT_ATTR_INITIALIZER, 12 .attr = FAULT_ATTR_INITIALIZER, 14 .ignore_gfp_reclaim = true, 13 .ignore_gfp_reclaim = true, 15 .ignore_gfp_highmem = true, 14 .ignore_gfp_highmem = true, 16 .min_order = 1, 15 .min_order = 1, 17 }; 16 }; 18 17 19 static int __init setup_fail_page_alloc(char * 18 static int __init setup_fail_page_alloc(char *str) 20 { 19 { 21 return setup_fault_attr(&fail_page_all 20 return setup_fault_attr(&fail_page_alloc.attr, str); 22 } 21 } 23 __setup("fail_page_alloc=", setup_fail_page_al 22 __setup("fail_page_alloc=", setup_fail_page_alloc); 24 23 25 bool should_fail_alloc_page(gfp_t gfp_mask, un !! 24 bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) 26 { 25 { 27 int flags = 0; 26 int flags = 0; 28 27 29 if (order < fail_page_alloc.min_order) 28 if (order < fail_page_alloc.min_order) 30 return false; 29 return false; 31 if (gfp_mask & __GFP_NOFAIL) 30 if (gfp_mask & __GFP_NOFAIL) 32 return false; 31 return false; 33 if (fail_page_alloc.ignore_gfp_highmem 32 if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM)) 34 return false; 33 return false; 35 if (fail_page_alloc.ignore_gfp_reclaim 34 if (fail_page_alloc.ignore_gfp_reclaim && 36 (gfp_mask & __GFP_DIRE 35 (gfp_mask & __GFP_DIRECT_RECLAIM)) 37 return false; 36 return false; 38 37 39 /* See comment in __should_failslab() 38 /* See comment in __should_failslab() */ 40 if (gfp_mask & __GFP_NOWARN) 39 if (gfp_mask & __GFP_NOWARN) 41 flags |= FAULT_NOWARN; 40 flags |= FAULT_NOWARN; 42 41 43 return should_fail_ex(&fail_page_alloc 42 return should_fail_ex(&fail_page_alloc.attr, 1 << order, flags); 44 } 43 } 45 ALLOW_ERROR_INJECTION(should_fail_alloc_page, << 46 44 47 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS 45 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS 48 46 49 static int __init fail_page_alloc_debugfs(void 47 static int __init fail_page_alloc_debugfs(void) 50 { 48 { 51 umode_t mode = S_IFREG | 0600; 49 umode_t mode = S_IFREG | 0600; 52 struct dentry *dir; 50 struct dentry *dir; 53 51 54 dir = fault_create_debugfs_attr("fail_ 52 dir = fault_create_debugfs_attr("fail_page_alloc", NULL, 55 &fail_ 53 &fail_page_alloc.attr); 56 54 57 debugfs_create_bool("ignore-gfp-wait", 55 debugfs_create_bool("ignore-gfp-wait", mode, dir, 58 &fail_page_alloc.i 56 &fail_page_alloc.ignore_gfp_reclaim); 59 debugfs_create_bool("ignore-gfp-highme 57 debugfs_create_bool("ignore-gfp-highmem", mode, dir, 60 &fail_page_alloc.i 58 &fail_page_alloc.ignore_gfp_highmem); 61 debugfs_create_u32("min-order", mode, 59 debugfs_create_u32("min-order", mode, dir, &fail_page_alloc.min_order); 62 60 63 return 0; 61 return 0; 64 } 62 } 65 63 66 late_initcall(fail_page_alloc_debugfs); 64 late_initcall(fail_page_alloc_debugfs); 67 65 68 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ 66 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ 69 67
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.