Commit 4f6923fb authored by Howard McLauchlan's avatar Howard McLauchlan Committed by Linus Torvalds
Browse files

mm: make should_failslab always available for fault injection

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"""

    #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:

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").


Signed-off-by: default avatarHoward McLauchlan <>
Reviewed-by: default avatarAndrew Morton <>
Cc: Akinobu Mita <>
Cc: Christoph Lameter <>
Cc: Pekka Enberg <>
Cc: David Rientjes <>
Cc: Joonsoo Kim <>
Cc: Josef Bacik <>
Cc: Johannes Weiner <>
Cc: Alexei Starovoitov <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 14298d36
......@@ -64,10 +64,11 @@ static inline struct dentry *fault_create_debugfs_attr(const char *name,
struct kmem_cache;
int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
extern bool should_failslab(struct kmem_cache *s, gfp_t gfpflags);
extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
static inline bool should_failslab(struct kmem_cache *s, gfp_t gfpflags)
static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
return false;
......@@ -14,7 +14,7 @@ static struct {
.cache_filter = false,
bool should_failslab(struct kmem_cache *s, gfp_t gfpflags)
bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
/* No fault-injection for bootstrap cache */
if (unlikely(s == kmem_cache))
......@@ -1516,3 +1516,11 @@ EXPORT_TRACEPOINT_SYMBOL(kmalloc_node);
int should_failslab(struct kmem_cache *s, gfp_t gfpflags)
if (__should_failslab(s, gfpflags))
return -ENOMEM;
return 0;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment