linux-stable/include
Howard McLauchlan 4f6923fbb3 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/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>
2018-04-05 21:36:26 -07:00
..
acpi Merge branches 'acpi-battery', 'acpi-doc' and 'acpi-pmic' 2018-04-02 10:58:13 +02:00
asm-generic arm64 updates for 4.17 2018-04-04 16:01:43 -07:00
clocksource
crypto crypto: api - Remove unused crypto_type lookup function 2018-03-31 01:32:57 +08:00
drm Linux 4.16-rc7 2018-03-28 14:30:41 +10:00
dt-bindings media updates for v4.17-rc1 2018-04-03 17:16:59 -07:00
keys
kvm
linux mm: make should_failslab always available for fault injection 2018-04-05 21:36:26 -07:00
math-emu
media media updates for v4.17-rc1 2018-04-03 17:16:59 -07:00
memory
misc
net slab: make usercopy region 32-bit 2018-04-05 21:36:24 -07:00
pcmcia
ras
rdma Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-04-01 19:49:34 -04:00
scsi SCSI fixes on 20180327 2018-03-27 14:11:46 -10:00
soc
sound Linux 4.16-rc7 2018-03-28 14:30:41 +10:00
target
trace mm/migrate: rename migration reason MR_CMA to MR_CONTIG_RANGE 2018-04-05 21:36:24 -07:00
uapi Char/Misc patches for 4.17-rc1 2018-04-04 20:07:20 -07:00
video
xen