mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 08:38:45 +02:00 
			
		
		
		
	 6ce2082fd3
			
		
	
	
		6ce2082fd3
		
	
	
	
	
		
			
			The fault-inject.h users across the kernel need to add a lot of #ifdef
CONFIG_FAULT_INJECTION to cater for shortcomings in the header.  Make
fault-inject.h self-contained for CONFIG_FAULT_INJECTION=n, and add stubs
for DECLARE_FAULT_ATTR(), setup_fault_attr(), should_fail_ex(), and
should_fail() to allow removal of conditional compilation.
[akpm@linux-foundation.org: repair fallout from no longer including debugfs.h into fault-inject.h]
[akpm@linux-foundation.org: fix drivers/misc/xilinx_tmr_inject.c]
[akpm@linux-foundation.org: Add debugfs.h inclusion to more files, per Stephen]
Link: https://lkml.kernel.org/r/20240813121237.2382534-1-jani.nikula@intel.com
Fixes: 6ff1cb355e ("[PATCH] fault-injection capabilities infrastructure")
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
		
	
			
		
			
				
	
	
		
			69 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| // SPDX-License-Identifier: GPL-2.0
 | |
| #include <linux/fault-inject.h>
 | |
| #include <linux/debugfs.h>
 | |
| #include <linux/error-injection.h>
 | |
| #include <linux/mm.h>
 | |
| 
 | |
| static struct {
 | |
| 	struct fault_attr attr;
 | |
| 
 | |
| 	bool ignore_gfp_highmem;
 | |
| 	bool ignore_gfp_reclaim;
 | |
| 	u32 min_order;
 | |
| } fail_page_alloc = {
 | |
| 	.attr = FAULT_ATTR_INITIALIZER,
 | |
| 	.ignore_gfp_reclaim = true,
 | |
| 	.ignore_gfp_highmem = true,
 | |
| 	.min_order = 1,
 | |
| };
 | |
| 
 | |
| static int __init setup_fail_page_alloc(char *str)
 | |
| {
 | |
| 	return setup_fault_attr(&fail_page_alloc.attr, str);
 | |
| }
 | |
| __setup("fail_page_alloc=", setup_fail_page_alloc);
 | |
| 
 | |
| bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
 | |
| {
 | |
| 	int flags = 0;
 | |
| 
 | |
| 	if (order < fail_page_alloc.min_order)
 | |
| 		return false;
 | |
| 	if (gfp_mask & __GFP_NOFAIL)
 | |
| 		return false;
 | |
| 	if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM))
 | |
| 		return false;
 | |
| 	if (fail_page_alloc.ignore_gfp_reclaim &&
 | |
| 			(gfp_mask & __GFP_DIRECT_RECLAIM))
 | |
| 		return false;
 | |
| 
 | |
| 	/* See comment in __should_failslab() */
 | |
| 	if (gfp_mask & __GFP_NOWARN)
 | |
| 		flags |= FAULT_NOWARN;
 | |
| 
 | |
| 	return should_fail_ex(&fail_page_alloc.attr, 1 << order, flags);
 | |
| }
 | |
| ALLOW_ERROR_INJECTION(should_fail_alloc_page, TRUE);
 | |
| 
 | |
| #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
 | |
| 
 | |
| static int __init fail_page_alloc_debugfs(void)
 | |
| {
 | |
| 	umode_t mode = S_IFREG | 0600;
 | |
| 	struct dentry *dir;
 | |
| 
 | |
| 	dir = fault_create_debugfs_attr("fail_page_alloc", NULL,
 | |
| 					&fail_page_alloc.attr);
 | |
| 
 | |
| 	debugfs_create_bool("ignore-gfp-wait", mode, dir,
 | |
| 			    &fail_page_alloc.ignore_gfp_reclaim);
 | |
| 	debugfs_create_bool("ignore-gfp-highmem", mode, dir,
 | |
| 			    &fail_page_alloc.ignore_gfp_highmem);
 | |
| 	debugfs_create_u32("min-order", mode, dir, &fail_page_alloc.min_order);
 | |
| 
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| late_initcall(fail_page_alloc_debugfs);
 | |
| 
 | |
| #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
 |