forked from luck/tmp_suning_uos_patched
4f6923fbb3
should_failslab() is a convenient function to hook into for directed error injection into kmalloc(). However, it is only available if a config flag is set. The following BCC script, for example, fails kmalloc() calls after a btrfs umount: from bcc import BPF prog = r""" BPF_HASH(flag); #include <linux/mm.h> int kprobe__btrfs_close_devices(void *ctx) { u64 key = 1; flag.update(&key, &key); return 0; } int kprobe__should_failslab(struct pt_regs *ctx) { u64 key = 1; u64 *res; res = flag.lookup(&key); if (res != 0) { bpf_override_return(ctx, -ENOMEM); } return 0; } """ b = BPF(text=prog) while 1: b.kprobe_poll() This patch refactors the should_failslab implementation so that the function is always available for error injection, independent of flags. This change would be similar in nature to commit f5490d3ec921 ("block: Add should_fail_bio() for bpf error injection"). Link: http://lkml.kernel.org/r/20180222020320.6944-1-hmclauchlan@fb.com Signed-off-by: Howard McLauchlan <hmclauchlan@fb.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Akinobu Mita <akinobu.mita@gmail.com> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Josef Bacik <jbacik@fb.com> Cc: Johannes Weiner <jweiner@fb.com> Cc: Alexei Starovoitov <ast@fb.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
78 lines
1.9 KiB
C
78 lines
1.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_FAULT_INJECT_H
|
|
#define _LINUX_FAULT_INJECT_H
|
|
|
|
#ifdef CONFIG_FAULT_INJECTION
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/debugfs.h>
|
|
#include <linux/ratelimit.h>
|
|
#include <linux/atomic.h>
|
|
|
|
/*
|
|
* For explanation of the elements of this struct, see
|
|
* Documentation/fault-injection/fault-injection.txt
|
|
*/
|
|
struct fault_attr {
|
|
unsigned long probability;
|
|
unsigned long interval;
|
|
atomic_t times;
|
|
atomic_t space;
|
|
unsigned long verbose;
|
|
bool task_filter;
|
|
unsigned long stacktrace_depth;
|
|
unsigned long require_start;
|
|
unsigned long require_end;
|
|
unsigned long reject_start;
|
|
unsigned long reject_end;
|
|
|
|
unsigned long count;
|
|
struct ratelimit_state ratelimit_state;
|
|
struct dentry *dname;
|
|
};
|
|
|
|
#define FAULT_ATTR_INITIALIZER { \
|
|
.interval = 1, \
|
|
.times = ATOMIC_INIT(1), \
|
|
.require_end = ULONG_MAX, \
|
|
.stacktrace_depth = 32, \
|
|
.ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
|
|
.verbose = 2, \
|
|
.dname = NULL, \
|
|
}
|
|
|
|
#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
|
|
int setup_fault_attr(struct fault_attr *attr, char *str);
|
|
bool should_fail(struct fault_attr *attr, ssize_t size);
|
|
|
|
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
|
|
|
|
struct dentry *fault_create_debugfs_attr(const char *name,
|
|
struct dentry *parent, struct fault_attr *attr);
|
|
|
|
#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
|
|
|
|
static inline struct dentry *fault_create_debugfs_attr(const char *name,
|
|
struct dentry *parent, struct fault_attr *attr)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
|
|
|
|
#endif /* CONFIG_FAULT_INJECTION */
|
|
|
|
struct kmem_cache;
|
|
|
|
int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
|
|
#ifdef CONFIG_FAILSLAB
|
|
extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
|
|
#else
|
|
static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
|
|
{
|
|
return false;
|
|
}
|
|
#endif /* CONFIG_FAILSLAB */
|
|
|
|
#endif /* _LINUX_FAULT_INJECT_H */
|