]> Git Repo - linux.git/commit - mm/slab_common.c
mm: make should_failslab always available for fault injection
authorHoward McLauchlan <[email protected]>
Thu, 5 Apr 2018 23:23:57 +0000 (16:23 -0700)
committerLinus Torvalds <[email protected]>
Fri, 6 Apr 2018 04:36:26 +0000 (21:36 -0700)
commit4f6923fbb352d126659cabe34806cff75c7b5ea0
treef88b75ada9b91b9f78344f7c719ba38b0e1c439d
parent14298d3663e44705d3f9106343ac8298a5fdff99
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"""
    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/[email protected]
Signed-off-by: Howard McLauchlan <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Akinobu Mita <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Josef Bacik <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/fault-inject.h
mm/failslab.c
mm/slab_common.c
This page took 0.052227 seconds and 4 git commands to generate.