documentation and scripts
Subsystems (8)
Akinobu Mita
maintainerPATCH 1/7 documentation and scripts
In reply to a message not in the archiveFrom: Akinobu Mita <[email protected]>
This patch set provides some fault-injection capabilities.
- kmalloc() failures
- alloc_pages() failures
- disk IO errors
We can see what really happens if those failures happen.
In order to enable these fault-injection capabilities:
1. Enable relevant config options (CONFIG_FAILSLAB, CONFIG_PAGE_ALLOC, CONFIG_MAKE_REQUEST) and if you want to configure them via debugfs, enable CONFIG_FAULT_INJECTION_DEBUG_FS.
2. Build and boot with this kernel
3. Configure fault-injection capabilities behavior by boot option or debugfs
- Boot option
failslab=
fail_page_alloc=
fail_make_request=
- Debugfs
/debug/failslab/*
/debug/fail_page_alloc/*
/debug/fail_make_request/*
Please refer to the Documentation/fault-injection/fault-injection.txt for details.
4. See what really happens.
Documentation/fault-injection/failcmd.sh | 4 Documentation/fault-injection/failmodule.sh | 31 +++ Documentation/fault-injection/fault-injection.txt | 180 ++++++++++++++++++++++ Documentation/kernel-parameters.txt | 7 4 files changed, 222 insertions(+)
Documentation/fault-injection/failcmd.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/bash + +echo 1 > /proc/self/make-it-fail +exec $*
Documentation/fault-injection/failmodule.sh new file +31 -0
@@ -0,0 +1,31 @@ +#!/bin/bash +# +# Usage: failmodule <failname> <modulename> [stacktrace-depth] +# +# <failname>: "failslab", "fail_alloc_page", or "fail_make_request" +# +# <modulename>: module name that you want to inject faults. +# +# [stacktrace-depth]: the maximum number of stacktrace walking allowed +# + +STACKTRACE_DEPTH=5 +if [ $# -gt 2 ]; then + STACKTRACE_DEPTH=$3 +fi + +if [ ! -d /debug/$1 ]; then + echo "Fault-injection $1 does not exist" >&2 + exit 1 +fi +if [ ! -d /sys/module/$2 ]; then + echo "Module $2 does not exist" >&2 + exit 1 +fi + +# Disable any fault injection +echo 0 > /debug/$1/stacktrace-depth + +echo `cat /sys/module/$2/sections/.text` > /debug/$1/address-start +echo `cat /sys/module/$2/sections/.exit.text` > /debug/$1/address-end +echo $STACKTRACE_DEPTH > /debug/$1/stacktrace-depth
Documentation/fault-injection/fault-injection.txt new file +180 -0
180 lines not on this page · raw message
Documentation/kernel-parameters.txt +7 -0
@@ -545,6 +545,13 @@ and is between 256 and 4096 characters. eurwdt= [HW,WDT] Eurotech CPU-1220/1410 onboard watchdog. Format: <io>[,<irq>] + failslab= + fail_page_alloc= + fail_make_request=[KNL] + General fault injection mechanism. + Format: <interval>,<probability>,<space>,<times> + See also /Documentation/fault-injection/. + fd_mcs= [HW,SCSI] See header of drivers/scsi/fd_mcs.c.
--
Akinobu Mita
maintainerPATCH 2/7 fault-injection capabilities infrastructure
In reply to a message not in the archiveFrom: Akinobu Mita <[email protected]>
This patch provides base functions for implement fault-injection capabilities.
- Lightweight random simulator is taken from crasher module for SUSE kernel
- The function should_fail() is taken from failmalloc-1.0
(http://www.nongnu.org/failmalloc/)
include/linux/fault-inject.h | 69 ++++++++++++++ lib/Kconfig.debug | 12 ++ lib/Makefile | 1 lib/fault-inject.c | 207 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 289 insertions(+)
lib/Kconfig.debug +12 -0
@@ -469,3 +469,15 @@ config LKDTM Documentation on how to use the module can be found in drivers/misc/lkdtm.c + +config FAULT_INJECTION + bool + +config FAULT_INJECTION_DEBUG_FS + bool "debugfs entries for fault-injection capabilities" + depends on FAULT_INJECTION && SYSFS + select DEBUG_FS + help + This option enables to configure fault-injection capabilities via + debugfs entries. +
lib/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_AUDIT_GENERIC) += audit.o obj-$(CONFIG_STATISTICS) += statistic.o obj-$(CONFIG_SWIOTLB) += swiotlb.o +obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o lib-$(CONFIG_GENERIC_BUG) += bug.o
include/linux/fault-inject.h new file +69 -0
69 lines not on this page · raw message
lib/fault-inject.c new file +207 -0
207 lines not on this page · raw message
--
Akinobu Mita
maintainerPATCH 5/7 fault-injection capability for disk IO
In reply to a message not in the archiveFrom: Akinobu Mita <[email protected]>
This patch provides fault-injection capability for disk IO.
Boot option:
fail_make_request=<probability>,<interval>,<space>,<times>
<interval> -- specifies the interval of failures.
<probability> -- specifies how often it should fail in percent.
<space> -- specifies the size of free space where disk IO can be issued
safely in bytes.
<times> -- specifies how many times failures may happen at most.
Debugfs:
/debug/fail_make_request/interval
/debug/fail_make_request/probability
/debug/fail_make_request/specifies
/debug/fail_make_request/times
Example:
fail_make_request=10,100,0,-1 echo 1 > /sys/blocks/hda/hda1/make-it-fail
generic_make_request() on /dev/hda1 fails once per 10 times.
block/genhd.c | 31 +++++++++++++++++++++++++++++++ block/ll_rw_blk.c | 43 +++++++++++++++++++++++++++++++++++++++++++ fs/partitions/check.c | 27 +++++++++++++++++++++++++++ include/linux/genhd.h | 4 ++++ lib/Kconfig.debug | 7 +++++++ 5 files changed, 112 insertions(+)
block/ll_rw_blk.c +43 -0
@@ -28,6 +28,7 @@#include <linux/interrupt.h> #include <linux/cpu.h> #include <linux/blktrace_api.h> +#include <linux/fault-inject.h> /* * for max sense size
@@ -3050,6 +3051,45 @@ static void handle_bad_sector(struct bioset_bit (BIO_EOF , &bio->bi_flags); } +#ifdef CONFIG_FAIL_MAKE_REQUEST + +static DEFINE_FAULT_ATTR (fail_make_request); + +static int __init setup_fail_make_request (char *str) +{ +should_fail_srandom (jiffies); + +return setup_fault_attr (&fail_make_request, str); +} +__setup ("fail_make_request=" , setup_fail_make_request); + +static int should_fail_request (struct bio *bio) +{ +if ((bio->bi_bdev->bd_disk->flags &GENHD_FL_FAIL ) || + (bio->bi_bdev->bd_part && bio->bi_bdev->bd_part->make_it_fail)) +return should_fail (&fail_make_request, bio->bi_size); + +return 0 ; +} + +static int __init fail_make_request_debugfs (void ) +{ +should_fail_srandom (jiffies); + +return init_fault_attr_entries (&fail_make_request,"fail_make_request" ); +} + +late_initcall (fail_make_request_debugfs); + +#else /* CONFIG_FAIL_MAKE_REQUEST */ + +static inline int should_fail_request (struct bio *bio) +{ +return 0 ; +} + +#endif /* CONFIG_FAIL_MAKE_REQUEST */ +/** * generic_make_request: hand a buffer to its device driver for I/O * @bio: The bio describing the location in memory and on the device.
@@ -3134,6 +3174,9 @@ end_io:if (unlikely (test_bit (QUEUE_FLAG_DEAD , &q->queue_flags))) goto end_io; +if (should_fail_request (bio)) + goto end_io; +/* * If this device has partitions, remap block n * of partition p to block n+start(p) of the disk.
lib/Kconfig.debug +7 -0
@@ -487,6 +487,13 @@ config FAIL_PAGE_ALLOC help This option provides fault-injection capabilitiy for alloc_pages(). +config FAIL_MAKE_REQUEST + bool "fault-injection capabilitiy for disk IO" + depends on DEBUG_KERNEL + select FAULT_INJECTION + help + This option provides fault-injection capabilitiy to disk IO. + config FAULT_INJECTION_DEBUG_FS bool "debugfs entries for fault-injection capabilities" depends on FAULT_INJECTION && SYSFS
block/genhd.c +31 -0
@@ -417,6 +417,34 @@ static struct disk_attribute disk_attr_s .show = disk_stats_read }; +#ifdef CONFIG_FAIL_MAKE_REQUEST + +static ssize_t disk_fail_store (struct gendisk * disk, +const char *buf,size_t count) +{ +int i; + +if (count >0 &&sscanf (buf,"%d" , &i) >0 ) { +if (i ==0 ) + disk->flags &= ~GENHD_FL_FAIL ; +else + disk->flags |=GENHD_FL_FAIL ; + } + +return count; +} +static ssize_t disk_fail_read (struct gendisk * disk,char *page) +{ +return sprintf (page,"%d\n" , disk->flags &GENHD_FL_FAIL ?1 :0 ); +} +static struct disk_attribute disk_attr_fail = { + .attr = {.name ="make-it-fail" , .mode =S_IRUGO |S_IWUSR }, + .store = disk_fail_store, + .show = disk_fail_read +}; + +#endif +static struct attribute * default_attrs[] = { &disk_attr_uevent.attr, &disk_attr_dev.attr,
@@ -424,6 +452,9 @@ static struct attribute * default_attrs[ &disk_attr_removable.attr, &disk_attr_size.attr, &disk_attr_stat.attr, +#ifdef CONFIG_FAIL_MAKE_REQUEST + &disk_attr_fail.attr, +#endif NULL, };
include/linux/genhd.h +4 -0
@@ -83,6 +83,9 @@ struct hd_struct {struct kobject *holder_dir;unsigned ios[2 ], sectors[2 ];/* READs and WRITEs */ int policy, partno; +#ifdef CONFIG_FAIL_MAKE_REQUEST +int make_it_fail; +#endif };#define GENHD_FL_REMOVABLE 1
@@ -90,6 +93,7 @@ struct hd_struct {#define GENHD_FL_CD 8#define GENHD_FL_UP 16#define GENHD_FL_SUPPRESS_PARTITION_INFO 32 +#define GENHD_FL_FAIL 64struct disk_stats {unsigned long sectors[2 ];/* READs and WRITEs */
fs/partitions/check.c +27 -0
@@ -276,12 +276,39 @@ static struct part_attribute part_attr_s .show = part_stat_read }; +#ifdef CONFIG_FAIL_MAKE_REQUEST + +static ssize_t part_fail_store (struct hd_struct * p, +const char *buf,size_t count) +{ +int i; + +if (count >0 &&sscanf (buf,"%d" , &i) >0 ) + p->make_it_fail = (i ==0 ) ?0 :1 ; + +return count; +} +static ssize_t part_fail_read (struct hd_struct * p,char *page) +{ +return sprintf (page,"%d\n" , p->make_it_fail); +} +static struct part_attribute part_attr_fail = { + .attr = {.name ="make-it-fail" , .mode =S_IRUGO |S_IWUSR }, + .store = part_fail_store, + .show = part_fail_read +}; + +#endif +static struct attribute * default_attrs[] = { &part_attr_uevent.attr, &part_attr_dev.attr, &part_attr_start.attr, &part_attr_size.attr, &part_attr_stat.attr, +#ifdef CONFIG_FAIL_MAKE_REQUEST + &part_attr_fail.attr, +#endifNULL , };
--
Akinobu Mita
maintainerPATCH 6/7 process filtering for fault-injection capabilities
In reply to a message not in the archiveFrom: Akinobu Mita <[email protected]>
This patch provides process filtering feature. The process filter allows failing only permitted processes by /proc/<pid>/make-it-fail
Please see the example that demostrates how to inject slab allocation failures into module init/cleanup code
in Documentation/fault-injection/fault-injection.txt
fs/proc/base.c | 65 +++++++++++++++++++++++++++++++++++++++++++ include/linux/fault-inject.h | 2 + include/linux/sched.h | 3 + lib/fault-inject.c | 19 ++++++++++++ 4 files changed, 89 insertions(+)
fs/proc/base.c +65 -0
@@ -776,6 +776,65 @@ static struct file_operations proc_login };#endif +#ifdef CONFIG_FAULT_INJECTION +static ssize_t proc_fault_inject_read (struct file * file,char __user * buf, +size_t count,loff_t *ppos) +{ +struct task_struct *task =get_proc_task (file->f_dentry->d_inode); +char buffer[PROC_NUMBUF ]; +size_t len; +int make_it_fail; +loff_t __ppos = *ppos; + +if (!task) +return -ESRCH ; + make_it_fail = task->make_it_fail; +put_task_struct (task); + + len =snprintf (buffer,sizeof (buffer),"%i\n" , make_it_fail); +if (__ppos >= len) +return 0 ; +if (count > len-__ppos) + count = len-__ppos; +if (copy_to_user (buf, buffer + __ppos, count)) +return -EFAULT ; + *ppos = __ppos + count; +return count; +} + +static ssize_t proc_fault_inject_write (struct file * file, +const char __user * buf,size_t count,loff_t *ppos) +{ +struct task_struct *task; +char buffer[PROC_NUMBUF ], *end; +int make_it_fail; + +if (!capable (CAP_SYS_RESOURCE )) +return -EPERM ; +memset (buffer,0 ,sizeof (buffer)); +if (count >sizeof (buffer) -1 ) + count =sizeof (buffer) -1 ; +if (copy_from_user (buffer, buf, count)) +return -EFAULT ; + make_it_fail =simple_strtol (buffer, &end,0 ); +if (*end =='\n' ) + end++; + task =get_proc_task (file->f_dentry->d_inode); +if (!task) +return -ESRCH ; + task->make_it_fail = make_it_fail; +put_task_struct (task); +if (end - buffer ==0 ) +return -EIO ; +return end - buffer; +} + +static struct file_operations proc_fault_inject_operations = { + .read = proc_fault_inject_read, + .write = proc_fault_inject_write, +}; +#endif +#ifdef CONFIG_SECCOMP static ssize_t seccomp_read (struct file *file,char __user *buf,size_t count,loff_t *ppos)
@@ -1788,6 +1847,9 @@ static struct pid_entry tgid_base_stuff[#ifdef CONFIG_AUDITSYSCALL REG("loginuid", S_IWUSR|S_IRUGO, loginuid),#endif +#ifdef CONFIG_FAULT_INJECTION + REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject), +#endif }; static int proc_tgid_base_readdir(struct file * filp,
@@ -2062,6 +2124,9 @@ static struct pid_entry tid_base_stuff[]#ifdef CONFIG_AUDITSYSCALL REG("loginuid", S_IWUSR|S_IRUGO, loginuid),#endif +#ifdef CONFIG_FAULT_INJECTION + REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject), +#endif }; static int proc_tid_base_readdir(struct file * filp,
include/linux/sched.h +3 -0
@@ -1051,6 +1051,9 @@ struct task_struct {#ifdef CONFIG_TASK_DELAY_ACCT struct task_delay_info *delays;#endif +#ifdef CONFIG_FAULT_INJECTION +int make_it_fail; +#endif };static inline pid_t process_group (struct task_struct *tsk)
include/linux/fault-inject.h +2 -0
@@ -17,6 +17,7 @@ struct fault_attr {atomic_t times;atomic_t space;unsigned long verbose; +u32 task_filter;unsigned long count;
@@ -30,6 +31,7 @@ struct fault_attr {struct dentry *times_file;struct dentry *space_file;struct dentry *verbose_file; + struct dentry *task_filter_file; } entries;#endif
lib/fault-inject.c +19 -0
@@ -5,6 +5,7 @@#include <linux/types.h> #include <linux/fs.h> #include <linux/module.h> +#include <linux/interrupt.h> #include <linux/fault-inject.h> int setup_fault_attr (struct fault_attr *attr,char *str)
@@ -58,6 +59,11 @@ static void fail_dump(struct fault_attrdump_stack (); } +static int fail_task (struct fault_attr *attr,struct task_struct *task) +{ +return !in_interrupt () && task->make_it_fail; +} +/* * This code is stolen from failmalloc-1.0 * http://www.nongnu.org/failmalloc/
@@ -65,6 +71,9 @@ static void fail_dump(struct fault_attrint should_fail (struct fault_attr *attr,ssize_t size) { +if (attr->task_filter && !fail_task (attr, current)) +return 0 ; +if (atomic_read (&max_failures (attr)) ==0 )return 0 ;
@@ -155,6 +164,10 @@ void cleanup_fault_attr_entries(struct fdebugfs_remove (attr->entries.verbose_file); attr->entries.verbose_file =NULL ; } +if (attr->entries.task_filter_file) { +debugfs_remove (attr->entries.task_filter_file); + attr->entries.task_filter_file =NULL ; + }debugfs_remove (attr->entries.dir); attr->entries.dir =NULL ; }
@@ -198,6 +211,12 @@ int init_fault_attr_entries(struct fault goto fail; attr->entries.verbose_file = file; + file =debugfs_create_bool ("task-filter" , mode, dir, + &attr->task_filter); +if (!file) + goto fail; + attr->entries.task_filter_file = file; +return 0 ; fail:cleanup_fault_attr_entries (attr);
--
Akinobu Mita
maintainerPATCH 7/7 stacktrace filtering for fault-injection capabilities
In reply to a message not in the archiveFrom: Akinobu Mita <[email protected]>
This patch provides stacktrace filtering feature.
The stacktrace filter allows failing only for the caller you are interested in.
stacktrace filter is enabled by setting the value of /debugfs/*/stacktrace-depth more than 0.
and specify the range of the virtual address
by the /debugfs/*/address-start and /debugfs/*/address-end
Please see the example that demostrates how to inject slab allocation failures only for a specific module
in Documentation/fault-injection/fault-injection.txt
include/linux/fault-inject.h | 7 ++ lib/Kconfig.debug | 2 lib/fault-inject.c | 111 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+)
lib/fault-inject.c +111 -0
@@ -6,6 +6,9 @@#include <linux/fs.h> #include <linux/module.h> #include <linux/interrupt.h> +#include <linux/unwind.h> +#include <linux/stacktrace.h> +#include <linux/kallsyms.h> #include <linux/fault-inject.h> int setup_fault_attr (struct fault_attr *attr,char *str)
@@ -64,6 +67,82 @@ static int fail_task(struct fault_attr *return !in_interrupt () && task->make_it_fail; } +static int fail_any_address (struct fault_attr *attr) +{ +return (attr->address_start ==0 && attr->address_end ==ULONG_MAX ); +} + +#ifdef CONFIG_STACK_UNWIND + +static asmlinkage int fail_stacktrace_callback(struct unwind_frame_info *info, + void *arg) +{ + int depth; + struct fault_attr *attr = arg; + + for (depth = 0; depth < attr->stacktrace_depth + && unwind(info) == 0 && UNW_PC(info); depth++) { + if (arch_unw_user_mode(info)) + break; + if (attr->address_start <= UNW_PC(info) && + UNW_PC(info) < attr->address_end) + return 1; + } + return 0; +} + +static int fail_stacktrace(struct fault_attr *attr) +{ + struct unwind_frame_info info; + + return unwind_init_running(&info, fail_stacktrace_callback, attr); +} + +#elif defined(CONFIG_STACKTRACE) + +#define MAX_STACK_TRACE_DEPTH 10 + +static int fail_stacktrace(struct fault_attr *attr) +{ + struct stack_trace trace; + int depth = attr->stacktrace_depth; + unsigned long entries[MAX_STACK_TRACE_DEPTH]; + int n; + + if (depth == 0) + return 0; + + trace.nr_entries = 0; + trace.entries = entries; + trace.max_entries = (depth < MAX_STACK_TRACE_DEPTH) ? + depth : MAX_STACK_TRACE_DEPTH; + trace.skip = 1; + trace.all_contexts = 0; + + save_stack_trace(&trace, NULL); + for (n = 0; n < trace.nr_entries; n++) + if (attr->address_start <= entries[n] && + entries[n] < attr->address_end) + return 1; + return 0; +} + +#else + +static inline int fail_stacktrace(struct fault_attr *attr) +{ + static int firsttime = 1; + + if (firsttime) { + printk(KERN_WARNING + "This architecture does not implement save_stack_trace()"\n"); + firsttime = 0; + } + return 0; +} + +#endif + /* * This code is stolen from failmalloc-1.0 * http://www.nongnu.org/failmalloc/
@@ -74,6 +153,9 @@ int should_fail(struct fault_attr *attr,if (attr->task_filter && !fail_task (attr, current))return 0 ; +if (!fail_any_address (attr) && !fail_stacktrace (attr)) +return 0 ; +if (atomic_read (&max_failures (attr)) ==0 )return 0 ;
@@ -168,6 +250,18 @@ void cleanup_fault_attr_entries(struct fdebugfs_remove (attr->entries.task_filter_file); attr->entries.task_filter_file =NULL ; } +if (attr->entries.stacktrace_depth_file) { +debugfs_remove (attr->entries.stacktrace_depth_file); + attr->entries.stacktrace_depth_file =NULL ; + } +if (attr->entries.address_start_file) { +debugfs_remove (attr->entries.address_start_file); + attr->entries.address_start_file =NULL ; + } +if (attr->entries.address_end_file) { +debugfs_remove (attr->entries.address_end_file); + attr->entries.address_end_file =NULL ; + }debugfs_remove (attr->entries.dir); attr->entries.dir =NULL ; }
@@ -217,6 +311,23 @@ int init_fault_attr_entries(struct fault goto fail; attr->entries.task_filter_file = file; + file =debugfs_create_ul ("stacktrace-depth" , mode, dir, + &attr->stacktrace_depth); +if (!file) + goto fail; + attr->entries.stacktrace_depth_file = file; + + file =debugfs_create_ul ("address-start" , mode, dir, + &attr->address_start); +if (!file) + goto fail; + attr->entries.address_start_file = file; + + file =debugfs_create_ul ("address-end" , mode, dir, &attr->address_end); +if (!file) + goto fail; + attr->entries.address_end_file = file; +return 0 ; fail:cleanup_fault_attr_entries (attr);
include/linux/fault-inject.h +7 -0
@@ -18,6 +18,9 @@ struct fault_attr {atomic_t space;unsigned long verbose;u32 task_filter; +unsigned long stacktrace_depth; +unsigned long address_start; +unsigned long address_end;unsigned long count;
@@ -32,6 +35,9 @@ struct fault_attr {struct dentry *space_file;struct dentry *verbose_file;struct dentry *task_filter_file; +struct dentry *stacktrace_depth_file; +struct dentry *address_start_file; + struct dentry *address_end_file; } entries;#endif
@@ -41,6 +47,7 @@ struct fault_attr {struct fault_attr name = { \ .interval =1 , \ .times =ATOMIC_INIT (1 ), \ + .address_end =ULONG_MAX , \ }int setup_fault_attr (struct fault_attr *attr,char *str);
lib/Kconfig.debug +2 -0
@@ -472,6 +472,8 @@ config LKDTM config FAULT_INJECTION bool + select STACKTRACE + select FRAME_POINTER config FAILSLAB bool "fault-injection capabilitiy for kmalloc"
--
Akinobu Mita
maintainerPATCH 3/7 fault-injection capability for kmalloc
In reply to a message not in the archiveFrom: Akinobu Mita <[email protected]>
This patch provides fault-injection capability for kmalloc.
Boot option:
failslab=<interval>,<probability>,<space>,<times>
<interval> -- specifies the interval of failures.
<probability> -- specifies how often it should fail in percent.
<space> -- specifies the size of free space where memory can be
allocated safely in bytes.
<times> -- specifies how many times failures may happen at most.
Debugfs:
/debug/failslab/interval
/debug/failslab/probability
/debug/failslab/specifies
/debug/failslab/times
Example:
failslab=10,100,0,-1
slab allocation (kmalloc(), kmem_cache_alloc(),..) fails once per 10 times.
lib/Kconfig.debug | 7 +++++++ mm/slab.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
mm/slab.c +43 -0
@@ -107,6 +107,7 @@#include <linux/mempolicy.h> #include <linux/mutex.h> #include <linux/rtmutex.h> +#include <linux/fault-inject.h> #include <asm/uaccess.h> #include <asm/cacheflush.h>
@@ -3075,12 +3076,54 @@ static void *cache_alloc_debugcheck_afte#define cache_alloc_debugcheck_after (a,b,objp,d) (objp)#endif +#ifdef CONFIG_FAILSLAB + +static DEFINE_FAULT_ATTR (failslab); + +static int __init setup_failslab (char *str) +{ +should_fail_srandom (jiffies); + +return setup_fault_attr (&failslab, str); +} +__setup ("failslab=" , setup_failslab); + +static int should_failslab (struct kmem_cache *cachep,gfp_t flags) +{ +if ((flags & __GFP_NOFAIL) || cachep == &cache_cache) +return 0 ; + +return should_fail (&failslab,obj_size (cachep)); +} + +static int __init failslab_debugfs (void ) +{ +should_fail_srandom (jiffies); + +return init_fault_attr_entries (&failslab,"failslab" ); +} + +late_initcall (failslab_debugfs); + +#else /* CONFIG_FAILSLAB */ + +static inline int should_failslab (struct kmem_cache *cachep,gfp_t flags) +{ +return 0 ; +} + +#endif /* CONFIG_FAILSLAB */ +static inline void *____cache_alloc (struct kmem_cache *cachep,gfp_t flags) {void *objp;struct array_cache *ac;check_irq_off (); + +if (should_failslab (cachep, flags)) +return NULL ; + ac =cpu_cache_get (cachep);if (likely (ac->avail)) {STATS_INC_ALLOCHIT (cachep);
lib/Kconfig.debug +7 -0
@@ -473,6 +473,13 @@ config LKDTM config FAULT_INJECTION bool +config FAILSLAB + bool "fault-injection capabilitiy for kmalloc" + depends on DEBUG_KERNEL + select FAULT_INJECTION + help + This option provides fault-injection capabilitiy for kmalloc. + config FAULT_INJECTION_DEBUG_FS bool "debugfs entries for fault-injection capabilities" depends on FAULT_INJECTION && SYSFS
--
Akinobu Mita
maintainerPATCH 4/7 fault-injection capability for alloc_pages()
In reply to a message not in the archiveFrom: Akinobu Mita <[email protected]>
This patch provides fault-injection capability for alloc_pages()
Boot option:
fail_page_alloc=<interval>,<probability>,<space>,<times>
<interval> -- specifies the interval of failures.
<probability> -- specifies how often it should fail in percent.
<space> -- specifies the size of free space where memory can be
allocated safely in pages.
<times> -- specifies how many times failures may happen at most.
Debugfs:
/debug/fail_page_alloc/interval
/debug/fail_page_alloc/probability
/debug/fail_page_alloc/specifies
/debug/fail_page_alloc/times
Example:
fail_page_alloc=10,100,0,-1
The page allocation (alloc_pages(), ...) fails once per 10 times.
lib/Kconfig.debug | 7 +++++++ mm/page_alloc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
lib/Kconfig.debug +7 -0
@@ -480,6 +480,13 @@ config FAILSLAB help This option provides fault-injection capabilitiy for kmalloc. +config FAIL_PAGE_ALLOC + bool "fault-injection capabilitiy for alloc_pages()" + depends on DEBUG_KERNEL + select FAULT_INJECTION + help + This option provides fault-injection capabilitiy for alloc_pages(). + config FAULT_INJECTION_DEBUG_FS bool "debugfs entries for fault-injection capabilities" depends on FAULT_INJECTION && SYSFS
mm/page_alloc.c +42 -0
60 lines not on this page · raw message
--
Re: [patch 3/7] fault-injection capability for kmalloc
In reply to Akinobu MitaQuoted 3 lines · Akinobu Mita
From: Akinobu Mita <[email protected]>
This patch provides fault-injection capability for kmalloc.
The slab bits look ok to me.
Pekka
Re: [patch 2/7] fault-injection capabilities infrastructure
In reply to Akinobu MitaQuoted 6 lines · On Thu, 12 Oct 2006 16:43:07 +0900 Akinobu Mita <[email protected]> wrote:
From: Akinobu Mita <[email protected]>
This patch provides base functions for implement fault-injection capabilities.
- Lightweight random simulator is taken from crasher module for SUSE kernel
heh, another one.
Please switch over to carta_random32() for now. Later we'll probably be removing carta_random32() and adding random32(), but I can take care of that.
lib/fault-inject.c line 37
Quoted 5 lines
lib/fault-inject.c new file +5
-0+#define failure_probability (attr) (attr)->probability +#define failure_interval (attr) (attr)->interval +#define max_failures (attr) (attr)->times +#define current_space (attr) (attr)->space +#define atomic_dec_not_zero (v) atomic_add_unless((v), -1, 0)
Please remove these macros and simply open-code these operations at each callsite.
Re: [patch 5/7] fault-injection capability for disk IO
In reply to Akinobu Mitablock/ll_rw_blk.c end_io: · line 3179
Quoted 7 lines · On Thu, 12 Oct 2006 16:43:10 +0900 Akinobu Mita <[email protected]> wrote:
block/ll_rw_blk.c +3
-0@@ -3134,6 +3174,9 @@ end_io:if (unlikely (test_bit (QUEUE_FLAG_DEAD , &q->queue_flags))) goto end_io; +if (should_fail_request (bio)) + goto end_io; +
hm, so we simulate IO errors by failing at make_request() time rather than at end_that_request_last()-time, which is where IO errors would usually be reported.
If we're testing the filesystem/VFS/etc layers then that's pretty much equivalent. But perhaps there's an argument for doing both.
Jens, could you have a think about it please?
Re: [patch 7/7] stacktrace filtering for fault-injection capabilities
In reply to Akinobu MitaQuoted 6 lines · On Thu, 12 Oct 2006 16:43:12 +0900 Akinobu Mita <[email protected]> wrote:
From: Akinobu Mita <[email protected]>
This patch provides stacktrace filtering feature.
The stacktrace filter allows failing only for the caller you are interested in.
Quoted 8 lines
stacktrace filter is enabled by setting the value of /debugfs/*/stacktrace-depth more than 0.
and specify the range of the virtual address
by the /debugfs/*/address-start and /debugfs/*/address-endPlease see the example that demostrates how to inject slab allocation failures only for a specific module
inDocumentation/fault-injection/fault-injection.txt
I read the documentation but I still don't understand this feature. What does the stacktrace actually do? It gets stored somewhere and displayed later? What's it all for?
lib/Kconfig.debug config LKDTM · line 479
Quoted 12 lines
lib/Kconfig.debug +2
-0@@ -472,6 +472,8 @@ config LKDTM config FAULT_INJECTION bool + select STACKTRACE + select FRAME_POINTER config FAILSLAB bool "fault-injection capabilitiy for kmalloc"
Is the selection of FRAME_POINTER really needed? The fancy new unwinder is supposed to be able to handle frame-pointerless unwinding?
Review
Quoted 3 lines · On Thu, 12 Oct 2006 16:43:06 +0900 Akinobu Mita <[email protected]> wrote:
+- /debug/*/probability:
(quoted diff) +2
-0+ + likelihood of failure injection, in percent.
The fact that this is a percentage worries me. When I was playing around with this sort of thing several years ago I found that even one-failure-per-thousand was a very high error rate for some testcases. This interface would force a minimum failure rate of one-per-hundred, which is terribly high.
So I wonder if it'd be better to make this have units of "one millionth", or simply make this tunable "1/(probability of failure)". So setting it to 1,000,000 gives you one failure per million calls, on average.
Re: [patch 4/7] fault-injection capability for alloc_pages()
In reply to Akinobu Mitamm/page_alloc.c __alloc_pages(gfp_t gfp_mask, unsigned i · line 1101
Quoted 6 lines · On Thu, 12 Oct 2006 16:43:09 +0900 Akinobu Mita <[email protected]> wrote:
mm/page_alloc.c +2
-0@@ -1058,6 +1097,9 @@ __alloc_pages(gfp_t gfp_mask, unsigned imight_sleep_if (wait); +if (should_fail_alloc_page (gfp_mask, order)) +return NULL ;
In previous work I've done on this I've found that allowing application-initiated allocations to fail is a right pain: all of userspace gets all unreliable and applications die all the time.
I realise that it's possible to limit the failures to a particular process, but it's also possible to let the allocations fail for _all_ processes, in which case this problem will hurt.
What I found was a reasonable fix for this problem was to limit the failures to those requests which did not have __GFP_HIGHMEM set. That way, userspace allocations work, but kernel-internal allocations are subject to failures.
That might be worth adding as an additional tunable?
Re: [patch 5/7] fault-injection capability for disk IO
In reply to Andrew MortonQuoted 15 lines · Andrew Morton
block/ll_rw_blk.c end_io: · line 3179
Quoted 7 lines · On Thu, 12 Oct 2006 16:43:10 +0900 Akinobu Mita <[email protected]> wrote:
block/ll_rw_blk.c +3
-0@@ -3134,6 +3174,9 @@ end_io:if (unlikely (test_bit (QUEUE_FLAG_DEAD , &q->queue_flags))) goto end_io; +if (should_fail_request (bio)) + goto end_io; +hm, so we simulate IO errors by failing at
make_request()time rather than at end_that_request_last()-time, which is where IO errors would usually be reported.
Quoted 4 lines
If we're testing the filesystem/VFS/etc layers then that's pretty much equivalent. But perhaps there's an argument for doing both.
Jens, could you have a think about it please?
For the io submitter and above layers, it's 100% identical to doing it at end_that_request_first() time (which I suspect is what you meant). So the above tests those layers only, which is fine if that is what you want. When we have timeout timers at the block layer (moved from lower layers), we could do more fancy stuff and test lower layers of the io stack as well more easily.
Signature · 1 line
Jens Axboe
Re: [patch 6/7] process filtering for fault-injection capabilities
In reply to Akinobu MitaQuoted 3 lines · Akinobu Mita
This patch provides process filtering feature. The process filter allows failing only permitted processes by /proc/<pid>/make-it-fail
Akinobu: Toward the end of the previous round of review, we had the following exchange:
On Tue, 2006-09-19 at 17:05 +0800, Akinobu Mita wrote:
On Mon, Sep 18, 2006 at 10:54:51PM -0700, Don Mullis wrote:
> > Add functionality to the process_filter variable: A negative argument
> > injects failures for only for pid==-process_filter, thereby permitting
> > per-process failures from boot time.
> >
>
> Is it better to add new filter for this purpose?
> Because someone may want to filter by tgid instead of pid.
>
> - positive value is for task->pid
> - nevative value is for task->tgid
Your idea sounds good to me.So naturally I'm wondering why the functionality was dropped. An application I had in mind was to identify which of the boot-time calls to the slab allocator must not fail but are not yet marked __GFP_NOFAIL (some experimentation showed that for pid 1 there are lots of these).
Andrew: Would such an exercise would be worth the effort?
Akinobu Mita
maintainerQuoted 3 lines · Andrew Morton
So I wonder if it'd be better to make this have units of "one millionth", or simply make this tunable "1/(probability of failure)". So setting it to 1,000,000 gives you one failure per million calls, on average.
/debug/*/interval is available for this purpose.
The combination of below commands gives one failure per million calls.
# echo 1000000 > /debug/failslab/interval # echo 100 > /debug/failslab/probability
Akinobu Mita
maintainerRe: [patch 4/7] fault-injection capability for alloc_pages()
In reply to Andrew MortonQuoted 4 lines · Andrew Morton
What I found was a reasonable fix for this problem was to limit the failures to those requests which did not have
__GFP_HIGHMEMset. That way, userspace allocations work, but kernel-internal allocations are subject to failures.
This is what I want especally when I ran the script in fault-inject.txt. This would be quite useful.
Akinobu Mita
maintainerRe: [patch 7/7] stacktrace filtering for fault-injection capabilities
In reply to Andrew MortonQuoted 3 lines · Andrew Morton
I read the documentation but I still don't understand this feature. What does the stacktrace actually do? It gets stored somewhere and displayed later? What's it all for?
For example someone may want to inject kmalloc()/kmem_cache_alloc() failures into only e100 module. they want to inject not only direct kmalloc() call, but also indirect allocation, too.
- e100_poll --> netif_receive_skb --> packet_rcv_spkt --> skb_clone --> kmem_cache_alloc
This patch enables to detect function calls like this by stacktrace and inject failures. The script Documentaion/fault-injection/failmodule.sh
helps it.
The range of text section of loaded e100 is expected to be [/sys/module/e100/sections/.text, /sys/module/e100/sections/.exit.text)
So failmodule.sh stores these values into /debug/failslab/address-start and /debug/failslab/address-end.
Quoted 9 lines
Quoted 9 lines
lib/Kconfig.debug +2
-0@@ -472,6 +472,8 @@ config LKDTM config FAULT_INJECTION bool + select STACKTRACE + select FRAME_POINTER
Quoted 6 lines
lib/Kconfig.debug config LKDTM · line 479
Quoted 3 lines
lib/Kconfig.debug +0
-0config FAILSLAB bool "fault-injection capabilitiy for kmalloc"Is the selection of
FRAME_POINTERreally needed? The fancy new unwinder is supposed to be able to handle frame-pointerless unwinding?
As I wrote in another reply, There are two type of implementation of this stacktrace filter.
- using STACKTRACE + FRAME_POINTER
- using new unwinder (STACK_UNWIND)
The stacktrace with using new unwinder without FRAME_POINTER is much slower than STACKTRACE + FRAME_POINTER.
Akinobu Mita
maintainerRe: [patch 7/7] stacktrace filtering for fault-injection capabilities
2006/10/14, Akinobu Mita <[email protected]>:
Quoted 16 lines
Quoted 9 lines
Quoted 9 lines
lib/Kconfig.debug +2
-0@@ -472,6 +472,8 @@ config LKDTM config FAULT_INJECTION bool + select STACKTRACE + select FRAME_POINTERQuoted 6 lines
lib/Kconfig.debug config LKDTM · line 479
Quoted 3 lines
lib/Kconfig.debug +0
-0config FAILSLAB bool "fault-injection capabilitiy for kmalloc"Is the selection of
FRAME_POINTERreally needed? The fancy new unwinder is supposed to be able to handle frame-pointerless unwinding?
Quoted 9 lines
As I wrote in another reply, There are two type of implementation of this stacktrace filter.
- using STACKTRACE +
FRAME_POINTER
- using new unwinder (STACK_UNWIND)The stacktrace with using new unwinder without
FRAME_POINTERis much slower than STACKTRACE +FRAME_POINTER.
Maybe I should drop new unwinder support for now.
Re: [patch 6/7] process filtering for fault-injection capabilities
In reply to Don MullisQuoted 24 lines · On Fri, 13 Oct 2006 10:28:54 -0700 Don Mullis <[email protected]> wrote:
Quoted 3 lines · Akinobu Mita
This patch provides process filtering feature. The process filter allows failing only permitted processes by /proc/<pid>/make-it-fail
Akinobu: Toward the end of the previous round of review, we had the following exchange:
On Tue, 2006-09-19 at 17:05 +0800, Akinobu Mita wrote: On Mon, Sep 18, 2006 at 10:54:51PM -0700, Don Mullis wrote: > > Add functionality to the process_filter variable: A negative argument > > injects failures for only for pid==-process_filter, thereby permitting > > per-process failures from boot time. > > > > Is it better to add new filter for this purpose? > Because someone may want to filter by tgid instead of pid. > > - positive value is for task->pid > - nevative value is for task->tgid Your idea sounds good to me.
Quoted 8 lines
So naturally I'm wondering why the functionality was dropped. An application I had in mind was to identify which of the boot-time calls to the slab allocator must not fail but are not yet marked
__GFP_NOFAIL(some experimentation showed that for pid 1 there are lots of these).Andrew: Would such an exercise would be worth the effort?
If we're looking for unchecked boot-time allocation failures then I'd say no, there's not much point in adding code to check for these. We tend to assume that the machine has enough memory to boot the kernel and initial userspace.
That being said, some boot-time allocations are in code which could also have been compiled into a module, so we do want to be checking those, because we do care about memory-allocation failures at modprobe time. But we can check for these by building the relevant driver as a module and then testing it.
And the "if it's positive it's a pid, if it's negative it's a tgid" interface is rather unpleasant - if we're going to do this we should use separate control files, or use something like
echo "pid=1234" > /proc/process_filter echo "tgid=4321" > /proc/process_filter
Quoted 11 lines · On Sat, 14 Oct 2006 02:47:24 +0900 Akinobu Mita <[email protected]> wrote:
Quoted 3 lines · Andrew Morton
So I wonder if it'd be better to make this have units of "one millionth", or simply make this tunable "1/(probability of failure)". So setting it to 1,000,000 gives you one failure per million calls, on average.
/debug/*/interval is available for this purpose.
The combination of below commands gives one failure per million calls.# echo 1000000 > /debug/failslab/interval # echo 100 > /debug/failslab/probability
Oh. What are the units of "interval"?
(I find it's nice to put the units in the actual filename if practical - it's self-documenting)
Re: [patch 7/7] stacktrace filtering for fault-injection capabilities
In reply to Akinobu MitaQuoted 18 lines · On Sat, 14 Oct 2006 03:00:39 +0900 Akinobu Mita <[email protected]> wrote:
Quoted 3 lines · Andrew Morton
I read the documentation but I still don't understand this feature. What does the stacktrace actually do? It gets stored somewhere and displayed later? What's it all for?
For example someone may want to inject kmalloc()/kmem_cache_alloc() failures into only e100 module. they want to inject not only direct
kmalloc()call, but also indirect allocation, too.-
e100_poll-->netif_receive_skb-->packet_rcv_spkt-->skb_clone-->kmem_cache_allocThis patch enables to detect function calls like this by stacktrace and inject failures. The script
Documentaion/fault-injection/failmodule.sh
helps it.
Quoted 5 lines
The range of text section of loaded e100 is expected to be [
/sys/module/e100/sections/.text,/sys/module/e100/sections/.exit.text)So
failmodule.shstores these values into /debug/failslab/address-start and /debug/failslab/address-end.
Oh I see. So you walk up the stack and if any caller falls between those
two addresses, we enable the fault-injector. Fair enough.
Re: [patch 7/7] stacktrace filtering for fault-injection capabilities
In reply to Akinobu MitaQuoted 21 lines · On Sat, 14 Oct 2006 03:12:23 +0900 "Akinobu Mita" <[email protected]>…
2006/10/14, Akinobu Mita <[email protected]>:
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
lib/Kconfig.debug +2
-0@@ -472,6 +472,8 @@ config LKDTM config FAULT_INJECTION bool + select STACKTRACE + select FRAME_POINTERQuoted 6 lines
lib/Kconfig.debug config LKDTM · line 479
Quoted 3 lines
lib/Kconfig.debug +0
-0config FAILSLAB bool "fault-injection capabilitiy for kmalloc"Is the selection of
FRAME_POINTERreally needed? The fancy new unwinder is supposed to be able to handle frame-pointerless unwinding?As I wrote in another reply, There are two type of implementation of this stacktrace filter.
Quoted 8 lines
Quoted 6 lines
- using STACKTRACE +
FRAME_POINTER
- using new unwinder (STACK_UNWIND)The stacktrace with using new unwinder without
FRAME_POINTERis much slower than STACKTRACE +FRAME_POINTER.Maybe I should drop new unwinder support for now.
I'd say it should stay. It'll be a lot more accurate once everything is sorted out. And hopefully the new unwinder will get sped up.
Plus I don't think performance matters a lot here: if you want to test the e100 driver with fault injection, the whole test would take about three seconds. After that, you've exercised every code path in the driver. So if enabling range-based fault injection increases that to 300 seconds, it is still practical.