Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: page_alloc: split out FAIL_PAGE_ALLOC

... to a single file to reduce a bit of page_alloc.c.

Link: https://lkml.kernel.org/r/20230516063821.121844-8-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Len Brown <len.brown@intel.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kefeng Wang and committed by
Andrew Morton
0866e82e e9f2b529

+76 -74
+9
include/linux/fault-inject.h
··· 93 93 94 94 bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order); 95 95 96 + #ifdef CONFIG_FAIL_PAGE_ALLOC 97 + bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order); 98 + #else 99 + static inline bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) 100 + { 101 + return false; 102 + } 103 + #endif /* CONFIG_FAIL_PAGE_ALLOC */ 104 + 96 105 int should_failslab(struct kmem_cache *s, gfp_t gfpflags); 97 106 #ifdef CONFIG_FAILSLAB 98 107 extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
+1
mm/Makefile
··· 89 89 obj-$(CONFIG_KFENCE) += kfence/ 90 90 obj-$(CONFIG_KMSAN) += kmsan/ 91 91 obj-$(CONFIG_FAILSLAB) += failslab.o 92 + obj-$(CONFIG_FAIL_PAGE_ALLOC) += fail_page_alloc.o 92 93 obj-$(CONFIG_MEMTEST) += memtest.o 93 94 obj-$(CONFIG_MIGRATION) += migrate.o 94 95 obj-$(CONFIG_NUMA) += memory-tiers.o
+66
mm/fail_page_alloc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/fault-inject.h> 3 + #include <linux/mm.h> 4 + 5 + static struct { 6 + struct fault_attr attr; 7 + 8 + bool ignore_gfp_highmem; 9 + bool ignore_gfp_reclaim; 10 + u32 min_order; 11 + } fail_page_alloc = { 12 + .attr = FAULT_ATTR_INITIALIZER, 13 + .ignore_gfp_reclaim = true, 14 + .ignore_gfp_highmem = true, 15 + .min_order = 1, 16 + }; 17 + 18 + static int __init setup_fail_page_alloc(char *str) 19 + { 20 + return setup_fault_attr(&fail_page_alloc.attr, str); 21 + } 22 + __setup("fail_page_alloc=", setup_fail_page_alloc); 23 + 24 + bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) 25 + { 26 + int flags = 0; 27 + 28 + if (order < fail_page_alloc.min_order) 29 + return false; 30 + if (gfp_mask & __GFP_NOFAIL) 31 + return false; 32 + if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM)) 33 + return false; 34 + if (fail_page_alloc.ignore_gfp_reclaim && 35 + (gfp_mask & __GFP_DIRECT_RECLAIM)) 36 + return false; 37 + 38 + /* See comment in __should_failslab() */ 39 + if (gfp_mask & __GFP_NOWARN) 40 + flags |= FAULT_NOWARN; 41 + 42 + return should_fail_ex(&fail_page_alloc.attr, 1 << order, flags); 43 + } 44 + 45 + #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS 46 + 47 + static int __init fail_page_alloc_debugfs(void) 48 + { 49 + umode_t mode = S_IFREG | 0600; 50 + struct dentry *dir; 51 + 52 + dir = fault_create_debugfs_attr("fail_page_alloc", NULL, 53 + &fail_page_alloc.attr); 54 + 55 + debugfs_create_bool("ignore-gfp-wait", mode, dir, 56 + &fail_page_alloc.ignore_gfp_reclaim); 57 + debugfs_create_bool("ignore-gfp-highmem", mode, dir, 58 + &fail_page_alloc.ignore_gfp_highmem); 59 + debugfs_create_u32("min-order", mode, dir, &fail_page_alloc.min_order); 60 + 61 + return 0; 62 + } 63 + 64 + late_initcall(fail_page_alloc_debugfs); 65 + 66 + #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
-74
mm/page_alloc.c
··· 2994 2994 return page; 2995 2995 } 2996 2996 2997 - #ifdef CONFIG_FAIL_PAGE_ALLOC 2998 - 2999 - static struct { 3000 - struct fault_attr attr; 3001 - 3002 - bool ignore_gfp_highmem; 3003 - bool ignore_gfp_reclaim; 3004 - u32 min_order; 3005 - } fail_page_alloc = { 3006 - .attr = FAULT_ATTR_INITIALIZER, 3007 - .ignore_gfp_reclaim = true, 3008 - .ignore_gfp_highmem = true, 3009 - .min_order = 1, 3010 - }; 3011 - 3012 - static int __init setup_fail_page_alloc(char *str) 3013 - { 3014 - return setup_fault_attr(&fail_page_alloc.attr, str); 3015 - } 3016 - __setup("fail_page_alloc=", setup_fail_page_alloc); 3017 - 3018 - static bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) 3019 - { 3020 - int flags = 0; 3021 - 3022 - if (order < fail_page_alloc.min_order) 3023 - return false; 3024 - if (gfp_mask & __GFP_NOFAIL) 3025 - return false; 3026 - if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM)) 3027 - return false; 3028 - if (fail_page_alloc.ignore_gfp_reclaim && 3029 - (gfp_mask & __GFP_DIRECT_RECLAIM)) 3030 - return false; 3031 - 3032 - /* See comment in __should_failslab() */ 3033 - if (gfp_mask & __GFP_NOWARN) 3034 - flags |= FAULT_NOWARN; 3035 - 3036 - return should_fail_ex(&fail_page_alloc.attr, 1 << order, flags); 3037 - } 3038 - 3039 - #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS 3040 - 3041 - static int __init fail_page_alloc_debugfs(void) 3042 - { 3043 - umode_t mode = S_IFREG | 0600; 3044 - struct dentry *dir; 3045 - 3046 - dir = fault_create_debugfs_attr("fail_page_alloc", NULL, 3047 - &fail_page_alloc.attr); 3048 - 3049 - debugfs_create_bool("ignore-gfp-wait", mode, dir, 3050 - &fail_page_alloc.ignore_gfp_reclaim); 3051 - debugfs_create_bool("ignore-gfp-highmem", mode, dir, 3052 - &fail_page_alloc.ignore_gfp_highmem); 3053 - debugfs_create_u32("min-order", mode, dir, &fail_page_alloc.min_order); 3054 - 3055 - return 0; 3056 - } 3057 - 3058 - late_initcall(fail_page_alloc_debugfs); 3059 - 3060 - #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ 3061 - 3062 - #else /* CONFIG_FAIL_PAGE_ALLOC */ 3063 - 3064 - static inline bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) 3065 - { 3066 - return false; 3067 - } 3068 - 3069 - #endif /* CONFIG_FAIL_PAGE_ALLOC */ 3070 - 3071 2997 noinline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) 3072 2998 { 3073 2999 return __should_fail_alloc_page(gfp_mask, order);