05 Sep, 2018

1 commit

  • commit 26f843848bae973817b3587780ce6b7b0200d3e4 upstream.

    For machines without the exrl instruction the BFP jit generates
    code that uses an "br %r1" instruction located in the lowcore page.
    Unfortunately there is a cut & paste error that puts an additional
    "larl %r1,.+14" instruction in the code that clobbers the branch
    target address in %r1. Remove the larl instruction.

    Cc: # v4.17+
    Fixes: de5cb6eb51 ("s390: use expoline thunks in the BPF JIT")
    Signed-off-by: Martin Schwidefsky
    Signed-off-by: Greg Kroah-Hartman

    Martin Schwidefsky
     

24 Aug, 2018

1 commit

  • [ Upstream commit f605ce5eb26ac934fb8106d75d46a2c875a2bf23 ]

    If we would ever fail in the bpf_jit_prog() pass that writes the
    actual insns to the image after we got header via bpf_jit_binary_alloc()
    then we also need to make sure to free it through bpf_jit_binary_free()
    again when bailing out. Given we had prior bpf_jit_prog() passes to
    initially probe for clobbered registers, program size and to fill in
    addrs arrray for jump targets, this is more of a theoretical one,
    but at least make sure this doesn't break with future changes.

    Fixes: 054623105728 ("s390/bpf: Add s390x eBPF JIT compiler backend")
    Signed-off-by: Daniel Borkmann
    Cc: Martin Schwidefsky
    Acked-by: Alexei Starovoitov
    Signed-off-by: Alexei Starovoitov
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Daniel Borkmann
     

25 May, 2018

1 commit

  • [ Upstream commit de5cb6eb514ebe241e3edeb290cb41deb380b81d ]

    The BPF JIT need safe guarding against spectre v2 in the sk_load_xxx
    assembler stubs and the indirect branches generated by the JIT itself
    need to be converted to expolines.

    Signed-off-by: Martin Schwidefsky
    Signed-off-by: Greg Kroah-Hartman

    Martin Schwidefsky
     

25 Dec, 2017

1 commit

  • [ Upstream commit 6d59b7dbf72ed20d0138e2f9b75ca3d4a9d4faca ]

    The assumption of unconditionally reloading skb pointers on
    BPF helper calls where bpf_helper_changes_pkt_data() holds
    true is wrong. There can be different contexts where the
    BPF helper would enforce a reload such as in case of XDP.
    Here, we do have a struct xdp_buff instead of struct sk_buff
    as context, thus this will access garbage.

    JITs only ever need to deal with cached skb pointer reload
    when ld_abs/ind was seen, therefore guard the reload behind
    SEEN_SKB only. Tested on s390x.

    Fixes: 9db7f2b81880 ("s390/bpf: recache skb->data/hlen for skb_vlan_push/pop")
    Signed-off-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Cc: Michael Holzheu
    Signed-off-by: Alexei Starovoitov
    Signed-off-by: Greg Kroah-Hartman

    Daniel Borkmann
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

10 Aug, 2017

1 commit


05 Aug, 2017

1 commit

  • While testing some other work that required JIT modifications, I
    run into test_bpf causing a hang when JIT enabled on s390. The
    problematic test case was the one from ddc665a4bb4b (bpf, arm64:
    fix jit branch offset related to ldimm64), and turns out that we
    do have a similar issue on s390 as well. In bpf_jit_prog() we
    update next instruction address after returning from bpf_jit_insn()
    with an insn_count. bpf_jit_insn() returns either -1 in case of
    error (e.g. unsupported insn), 1 or 2. The latter is only the
    case for ldimm64 due to spanning 2 insns, however, next address
    is only set to i + 1 not taking actual insn_count into account,
    thus fix is to use insn_count instead of 1. bpf_jit_enable in
    mode 2 provides also disasm on s390:

    Before fix:

    000003ff800349b6: a7f40003 brc 15,3ff800349bc ; target
    000003ff800349ba: 0000 unknown
    000003ff800349bc: e3b0f0700024 stg %r11,112(%r15)
    000003ff800349c2: e3e0f0880024 stg %r14,136(%r15)
    000003ff800349c8: 0db0 basr %r11,%r0
    000003ff800349ca: c0ef00000000 llilf %r14,0
    000003ff800349d0: e320b0360004 lg %r2,54(%r11)
    000003ff800349d6: e330b03e0004 lg %r3,62(%r11)
    000003ff800349dc: ec23ffeda065 clgrj %r2,%r3,10,3ff800349b6 ; jmp
    000003ff800349e2: e3e0b0460004 lg %r14,70(%r11)
    000003ff800349e8: e3e0b04e0004 lg %r14,78(%r11)
    000003ff800349ee: b904002e lgr %r2,%r14
    000003ff800349f2: e3b0f0700004 lg %r11,112(%r15)
    000003ff800349f8: e3e0f0880004 lg %r14,136(%r15)
    000003ff800349fe: 07fe bcr 15,%r14

    After fix:

    000003ff80ef3db4: a7f40003 brc 15,3ff80ef3dba
    000003ff80ef3db8: 0000 unknown
    000003ff80ef3dba: e3b0f0700024 stg %r11,112(%r15)
    000003ff80ef3dc0: e3e0f0880024 stg %r14,136(%r15)
    000003ff80ef3dc6: 0db0 basr %r11,%r0
    000003ff80ef3dc8: c0ef00000000 llilf %r14,0
    000003ff80ef3dce: e320b0360004 lg %r2,54(%r11)
    000003ff80ef3dd4: e330b03e0004 lg %r3,62(%r11)
    000003ff80ef3dda: ec230006a065 clgrj %r2,%r3,10,3ff80ef3de6 ; jmp
    000003ff80ef3de0: e3e0b0460004 lg %r14,70(%r11)
    000003ff80ef3de6: e3e0b04e0004 lg %r14,78(%r11) ; target
    000003ff80ef3dec: b904002e lgr %r2,%r14
    000003ff80ef3df0: e3b0f0700004 lg %r11,112(%r15)
    000003ff80ef3df6: e3e0f0880004 lg %r14,136(%r15)
    000003ff80ef3dfc: 07fe bcr 15,%r14

    test_bpf.ko suite runs fine after the fix.

    Fixes: 054623105728 ("s390/bpf: Add s390x eBPF JIT compiler backend")
    Signed-off-by: Daniel Borkmann
    Tested-by: Michael Holzheu
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

07 Jun, 2017

1 commit


01 Jun, 2017

1 commit


09 May, 2017

1 commit

  • set_memory_* functions have moved to set_memory.h. Switch to this
    explicitly

    Link: http://lkml.kernel.org/r/1488920133-27229-5-git-send-email-labbott@redhat.com
    Signed-off-by: Laura Abbott
    Acked-by: Heiko Carstens
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Laura Abbott
     

23 Feb, 2017

1 commit

  • Pull s390 updates from Martin Schwidefsky:

    - New entropy generation for the pseudo random number generator.

    - Early boot printk output via sclp to help debug crashes on boot. This
    needs to be enabled with a kernel parameter.

    - Add proper no-execute support with a bit in the page table entry.

    - Bug fixes and cleanups.

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: (65 commits)
    s390/syscall: fix single stepped system calls
    s390/zcrypt: make ap_bus explicitly non-modular
    s390/zcrypt: Removed unneeded debug feature directory creation.
    s390: add missing "do {} while (0)" loop constructs to multiline macros
    s390/mm: add cond_resched call to kernel page table dumper
    s390: get rid of MACHINE_HAS_PFMF and MACHINE_HAS_HPAGE
    s390/mm: make memory_block_size_bytes available for !MEMORY_HOTPLUG
    s390: replace ACCESS_ONCE with READ_ONCE
    s390: Audit and remove any remaining unnecessary uses of module.h
    s390: mm: Audit and remove any unnecessary uses of module.h
    s390: kernel: Audit and remove any unnecessary uses of module.h
    s390/kdump: Use "LINUX" ELF note name instead of "CORE"
    s390: add no-execute support
    s390: report new vector facilities
    s390: use correct input data address for setup_randomness
    s390/sclp: get rid of common response code handling
    s390/sclp: don't add new lines to each printed string
    s390/sclp: make early sclp code readable
    s390/sclp: disable early sclp code as soon as the base sclp driver is active
    s390/sclp: move early printk code to drivers
    ...

    Linus Torvalds
     

22 Feb, 2017

1 commit

  • Eric and Willem reported that they recently saw random crashes when
    JIT was in use and bisected this to 74451e66d516 ("bpf: make jited
    programs visible in traces"). Issue was that the consolidation part
    added bpf_jit_binary_unlock_ro() that would unlock previously made
    read-only memory back to read-write. However, DEBUG_SET_MODULE_RONX
    cannot be used for this to test for presence of set_memory_*()
    functions. We need to use ARCH_HAS_SET_MEMORY instead to fix this;
    also add the corresponding bpf_jit_binary_lock_ro() to filter.h.

    Fixes: 74451e66d516 ("bpf: make jited programs visible in traces")
    Reported-by: Eric Dumazet
    Reported-by: Willem de Bruijn
    Bisected-by: Eric Dumazet
    Signed-off-by: Daniel Borkmann
    Tested-by: Willem de Bruijn
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

18 Feb, 2017

2 commits

  • Long standing issue with JITed programs is that stack traces from
    function tracing check whether a given address is kernel code
    through {__,}kernel_text_address(), which checks for code in core
    kernel, modules and dynamically allocated ftrace trampolines. But
    what is still missing is BPF JITed programs (interpreted programs
    are not an issue as __bpf_prog_run() will be attributed to them),
    thus when a stack trace is triggered, the code walking the stack
    won't see any of the JITed ones. The same for address correlation
    done from user space via reading /proc/kallsyms. This is read by
    tools like perf, but the latter is also useful for permanent live
    tracing with eBPF itself in combination with stack maps when other
    eBPF types are part of the callchain. See offwaketime example on
    dumping stack from a map.

    This work tries to tackle that issue by making the addresses and
    symbols known to the kernel. The lookup from *kernel_text_address()
    is implemented through a latched RB tree that can be read under
    RCU in fast-path that is also shared for symbol/size/offset lookup
    for a specific given address in kallsyms. The slow-path iteration
    through all symbols in the seq file done via RCU list, which holds
    a tiny fraction of all exported ksyms, usually below 0.1 percent.
    Function symbols are exported as bpf_prog_, in order to aide
    debugging and attribution. This facility is currently enabled for
    root-only when bpf_jit_kallsyms is set to 1, and disabled if hardening
    is active in any mode. The rationale behind this is that still a lot
    of systems ship with world read permissions on kallsyms thus addresses
    should not get suddenly exposed for them. If that situation gets
    much better in future, we always have the option to change the
    default on this. Likewise, unprivileged programs are not allowed
    to add entries there either, but that is less of a concern as most
    such programs types relevant in this context are for root-only anyway.
    If enabled, call graphs and stack traces will then show a correct
    attribution; one example is illustrated below, where the trace is
    now visible in tooling such as perf script --kallsyms=/proc/kallsyms
    and friends.

    Before:

    7fff8166889d bpf_clone_redirect+0x80007f0020ed (/lib/modules/4.9.0-rc8+/build/vmlinux)
    f5d80 __sendmsg_nocancel+0xffff006451f1a007 (/usr/lib64/libc-2.18.so)

    After:

    7fff816688b7 bpf_clone_redirect+0x80007f002107 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fffa0575728 bpf_prog_33c45a467c9e061a+0x8000600020fb (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fffa07ef1fc cls_bpf_classify+0x8000600020dc (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff81678b68 tc_classify+0x80007f002078 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff8164d40b __netif_receive_skb_core+0x80007f0025fb (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff8164d718 __netif_receive_skb+0x80007f002018 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff8164e565 process_backlog+0x80007f002095 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff8164dc71 net_rx_action+0x80007f002231 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff81767461 __softirqentry_text_start+0x80007f0020d1 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff817658ac do_softirq_own_stack+0x80007f00201c (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff810a2c20 do_softirq+0x80007f002050 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff810a2cb5 __local_bh_enable_ip+0x80007f002085 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff8168d452 ip_finish_output2+0x80007f002152 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff8168ea3d ip_finish_output+0x80007f00217d (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff8168f2af ip_output+0x80007f00203f (/lib/modules/4.9.0-rc8+/build/vmlinux)
    [...]
    7fff81005854 do_syscall_64+0x80007f002054 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    7fff817649eb return_from_SYSCALL_64+0x80007f002000 (/lib/modules/4.9.0-rc8+/build/vmlinux)
    f5d80 __sendmsg_nocancel+0xffff01c484812007 (/usr/lib64/libc-2.18.so)

    Signed-off-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: David S. Miller

    Daniel Borkmann
     
  • Remove the dummy bpf_jit_compile() stubs for eBPF JITs and make
    that a single __weak function in the core that can be overridden
    similarly to the eBPF one. Also remove stale pr_err() mentions
    of bpf_jit_compile.

    Signed-off-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

16 Jan, 2017

1 commit

  • After we already allocated the jit.prg_buf image via
    bpf_jit_binary_alloc() and filled it out with instructions,
    jit.prg_buf cannot be NULL anymore. Thus, remove the
    unnecessary check. Tested on s390x with test_bpf module.

    Signed-off-by: Daniel Borkmann
    Cc: Michael Holzheu
    Cc: Martin Schwidefsky
    Signed-off-by: Heiko Carstens
    Signed-off-by: Martin Schwidefsky

    Daniel Borkmann
     

09 Dec, 2016

1 commit

  • This patch allows XDP prog to extend/remove the packet
    data at the head (like adding or removing header). It is
    done by adding a new XDP helper bpf_xdp_adjust_head().

    It also renames bpf_helper_changes_skb_data() to
    bpf_helper_changes_pkt_data() to better reflect
    that XDP prog does not work on skb.

    This patch adds one "xdp_adjust_head" bit to bpf_prog for the
    XDP-capable driver to check if the XDP prog requires
    bpf_xdp_adjust_head() support. The driver can then decide
    to error out during XDP_SETUP_PROG.

    Signed-off-by: Martin KaFai Lau
    Acked-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Acked-by: John Fastabend
    Signed-off-by: David S. Miller

    Martin KaFai Lau
     

19 May, 2016

2 commits

  • In case of usage of skb_vlan_push/pop, in the prologue we store
    the SKB pointer on the stack and restore it after BPF_JMP_CALL
    to skb_vlan_push/pop.

    Unfortunately currently there are two bugs in the code:

    1) The wrong stack slot (offset 170 instead of 176) is used
    2) The wrong register (W1 instead of B1) is saved

    So fix this and use correct stack slot and register.

    Fixes: 9db7f2b81880 ("s390/bpf: recache skb->data/hlen for skb_vlan_push/pop")
    Cc: stable@vger.kernel.org # 4.3+
    Signed-off-by: Michael Holzheu
    Signed-off-by: Martin Schwidefsky

    Michael Holzheu
     
  • The s390 BFP compiler currently uses relative branch instructions
    that only support jumps up to 64 KB. Examples are "j", "jnz", "cgrj",
    etc. Currently the maximum size of s390 BPF programs is set
    to 0x7ffff. If branches over 64 KB are generated the, kernel can
    crash due to incorrect code.

    So fix this an reduce the maximum size to 64 KB. Programs larger than
    that will be interpreted.

    Fixes: ce2b6ad9c185 ("s390/bpf: increase BPF_SIZE_MAX")

    Cc: stable@vger.kernel.org # 4.3+
    Signed-off-by: Michael Holzheu
    Signed-off-by: Martin Schwidefsky

    Michael Holzheu
     

17 May, 2016

2 commits

  • This patch adds recently added constant blinding helpers into the
    s390 eBPF JIT. In the bpf_int_jit_compile() path, requirements are
    to utilize bpf_jit_blind_constants()/bpf_jit_prog_release_other()
    pair for rewriting the program into a blinded one, and to map the
    BPF_REG_AX register to a CPU register. The mapping of BPF_REG_AX
    is at r12 and similarly like in x86 case performs reloading when
    ld_abs/ind is used. When blinding is not used, there's no additional
    overhead in the generated image.

    When BPF_REG_AX is used, we don't need to emit skb->data reload when
    helper function changed skb->data, as this will be reloaded later
    on anyway from stack on ld_abs/ind, where skb->data is needed. s390
    allows for this w/o much additional complexity unlike f.e. x86.

    Signed-off-by: Daniel Borkmann
    Signed-off-by: Michael Holzheu
    Signed-off-by: David S. Miller

    Daniel Borkmann
     
  • Since the blinding is strictly only called from inside eBPF JITs,
    we need to change signatures for bpf_int_jit_compile() and
    bpf_prog_select_runtime() first in order to prepare that the
    eBPF program we're dealing with can change underneath. Hence,
    for call sites, we need to return the latest prog. No functional
    change in this patch.

    Signed-off-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

19 Dec, 2015

1 commit

  • Back in the days where eBPF (or back then "internal BPF" ;->) was not
    exposed to user space, and only the classic BPF programs internally
    translated into eBPF programs, we missed the fact that for classic BPF
    A and X needed to be cleared. It was fixed back then via 83d5b7ef99c9
    ("net: filter: initialize A and X registers"), and thus classic BPF
    specifics were added to the eBPF interpreter core to work around it.

    This added some confusion for JIT developers later on that take the
    eBPF interpreter code as an example for deriving their JIT. F.e. in
    f75298f5c3fe ("s390/bpf: clear correct BPF accumulator register"), at
    least X could leak stack memory. Furthermore, since this is only needed
    for classic BPF translations and not for eBPF (verifier takes care
    that read access to regs cannot be done uninitialized), more complexity
    is added to JITs as they need to determine whether they deal with
    migrations or native eBPF where they can just omit clearing A/X in
    their prologue and thus reduce image size a bit, see f.e. cde66c2d88da
    ("s390/bpf: Only clear A and X for converted BPF programs"). In other
    cases (x86, arm64), A and X is being cleared in the prologue also for
    eBPF case, which is unnecessary.

    Lets move this into the BPF migration in bpf_convert_filter() where it
    actually belongs as long as the number of eBPF JITs are still few. It
    can thus be done generically; allowing us to remove the quirk from
    __bpf_prog_run() and to slightly reduce JIT image size in case of eBPF,
    while reducing code duplication on this matter in current(/future) eBPF
    JITs.

    Signed-off-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Reviewed-by: Michael Holzheu
    Tested-by: Michael Holzheu
    Cc: Zi Shen Lim
    Cc: Yang Shi
    Acked-by: Yang Shi
    Acked-by: Zi Shen Lim
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

03 Oct, 2015

1 commit

  • As we need to add further flags to the bpf_prog structure, lets migrate
    both bools to a bitfield representation. The size of the base structure
    (excluding insns) remains unchanged at 40 bytes.

    Add also tags for the kmemchecker, so that it doesn't throw false
    positives. Even in case gcc would generate suboptimal code, it's not
    being accessed in performance critical paths.

    Signed-off-by: Daniel Borkmann
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

12 Aug, 2015

1 commit

  • There is a build error that "'struct bpf_array' has no member
    named 'prog'" on s390. In commit 2a36f0b92eb6 ("bpf: Make the
    bpf_prog_array_map more generic"), the member 'prog' of struct
    bpf_array is replaced by 'ptrs'. So this patch fixes it.

    Fixes: 2a36f0b92eb6 ("bpf: Make the bpf_prog_array_map more generic")
    Reported-by: Wu Fengguang
    Signed-off-by: Kaixu Xia
    Signed-off-by: David S. Miller

    Kaixu Xia
     

31 Jul, 2015

1 commit

  • During recent discussions we had with Michael, we found that it would
    be useful to have an indicator that tells the JIT that an eBPF program
    had been migrated from classic instructions into eBPF instructions, as
    only in that case A and X need to be cleared in the prologue. Such eBPF
    programs do not set a particular type, but all have BPF_PROG_TYPE_UNSPEC.
    Thus, introduce a small helper for cde66c2d88da ("s390/bpf: Only clear
    A and X for converted BPF programs") and possibly others in future.

    Signed-off-by: Daniel Borkmann
    Cc: Michael Holzheu
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

30 Jul, 2015

5 commits

  • Allow eBPF programs attached to TC qdiscs call skb_vlan_push/pop
    via helper functions. These functions may change skb->data/hlen.
    This data is cached by s390 JIT to improve performance of ld_abs/ld_ind
    instructions. Therefore after a change we have to reload the data.

    In case of usage of skb_vlan_push/pop, in the prologue we store
    the SKB pointer on the stack and restore it after BPF_JMP_CALL
    to skb_vlan_push/pop.

    Signed-off-by: Michael Holzheu
    Signed-off-by: David S. Miller

    Michael Holzheu
     
  • Only classic BPF programs that have been converted to eBPF need to clear
    the A and X registers. We can check for converted programs with:

    bpf_prog->type == BPF_PROG_TYPE_UNSPEC

    So add the check and skip initialization for real eBPF programs.

    Signed-off-by: Michael Holzheu
    Signed-off-by: David S. Miller

    Michael Holzheu
     
  • Currently we have the restriction that jitted BPF programs can
    have a maximum size of one page. The reason is that we use short
    displacements for the literal pool.

    The 20 bit displacements are available since z990 and BPF requires
    z196 as minimum. Therefore we can remove this restriction and use
    everywhere 20 bit signed long displacements.

    Acked-by: Martin Schwidefsky
    Signed-off-by: Michael Holzheu
    Signed-off-by: David S. Miller

    Michael Holzheu
     
  • The EMIT6_DISP_LH macro passes the "disp" parameter to the _EMIT6_DISP_LH
    macro. The _EMIT6_DISP_LH macro uses the "disp" parameter twice:

    unsigned int __disp_h = ((u32)disp) & 0xff000;
    unsigned int __disp_l = ((u32)disp) & 0x00fff;

    The EMIT6_DISP_LH is used several times with EMIT_CONST_U64() as "disp"
    parameter. Therefore always two constants are created per usage of
    EMIT6_DISP_LH.

    Fix this and add variable "_disp" to avoid multiple expansions.

    * v2: Move "_disp" to _EMIT6_DISP_LH as suggested by Joe Perches

    Fixes: 054623105728 ("s390/bpf: Add s390x eBPF JIT compiler backend")
    Signed-off-by: Michael Holzheu
    Signed-off-by: David S. Miller

    Michael Holzheu
     
  • Currently we assumed the following BPF to eBPF register mapping:

    - BPF_REG_A -> BPF_REG_7
    - BPF_REG_X -> BPF_REG_8

    Unfortunately this mapping is wrong. The correct mapping is:

    - BPF_REG_A -> BPF_REG_0
    - BPF_REG_X -> BPF_REG_7

    So clear the correct registers and use the BPF_REG_A and BPF_REG_X
    macros instead of BPF_REG_0/7.

    Fixes: 054623105728 ("s390/bpf: Add s390x eBPF JIT compiler backend")
    Cc: stable@vger.kernel.org # 4.0+
    Signed-off-by: Michael Holzheu
    Signed-off-by: David S. Miller

    Michael Holzheu
     

21 Jul, 2015

1 commit

  • Allow eBPF programs attached to TC qdiscs call skb_vlan_push/pop via
    helper functions. These functions may change skb->data/hlen which are
    cached by some JITs to improve performance of ld_abs/ld_ind instructions.
    Therefore JITs need to recognize bpf_skb_vlan_push/pop() calls,
    re-compute header len and re-cache skb->data/hlen back into cpu registers.
    Note, skb->data/hlen are not directly accessible from the programs,
    so any changes to skb->data done either by these helpers or by other
    TC actions are safe.

    eBPF JIT supported by three architectures:
    - arm64 JIT is using bpf_load_pointer() without caching, so it's ok as-is.
    - x64 JIT re-caches skb->data/hlen unconditionally after vlan_push/pop calls
    (experiments showed that conditional re-caching is slower).
    - s390 JIT falls back to interpreter for now when bpf_skb_vlan_push() is present
    in the program (re-caching is tbd).

    These helpers allow more scalable handling of vlan from the programs.
    Instead of creating thousands of vlan netdevs on top of eth0 and attaching
    TC+ingress+bpf to all of them, the program can be attached to eth0 directly
    and manipulate vlans as necessary.

    Signed-off-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Alexei Starovoitov
     

25 Jun, 2015

1 commit

  • Currently all backward jumps crash for JITed s390x eBPF programs
    with an illegal instruction program check and kernel panic. Because
    for negative values the opcode of the jump instruction is overriden
    by the negative branch offset an illegal instruction is generated
    by the JIT:

    000003ff802da378: c01100000002 lgfi %r1,2
    000003ff802da37e: fffffff52065 unknown
    Signed-off-by: Martin Schwidefsky

    Michael Holzheu
     

10 Jun, 2015

1 commit

  • bpf_tail_call() arguments:

    - ctx......: Context pointer
    - jmp_table: One of BPF_MAP_TYPE_PROG_ARRAY maps used as the jump table
    - index....: Index in the jump table

    In this implementation s390x JIT does stack unwinding and jumps into the
    callee program prologue. Caller and callee use the same stack.

    With this patch a tail call generates the following code on s390x:

    if (index >= array->map.max_entries)
    goto out
    000003ff8001c7e4: e31030100016 llgf %r1,16(%r3)
    000003ff8001c7ea: ec41001fa065 clgrj %r4,%r1,10,3ff8001c828

    if (tail_call_cnt++ > MAX_TAIL_CALL_CNT)
    goto out;
    000003ff8001c7f0: a7080001 lhi %r0,1
    000003ff8001c7f4: eb10f25000fa laal %r1,%r0,592(%r15)
    000003ff8001c7fa: ec120017207f clij %r1,32,2,3ff8001c828

    prog = array->prog[index];
    if (prog == NULL)
    goto out;
    000003ff8001c800: eb140003000d sllg %r1,%r4,3
    000003ff8001c806: e31310800004 lg %r1,128(%r3,%r1)
    000003ff8001c80c: ec18000e007d clgij %r1,0,8,3ff8001c828

    Restore registers before calling function
    000003ff8001c812: eb68f2980004 lmg %r6,%r8,664(%r15)
    000003ff8001c818: ebbff2c00004 lmg %r11,%r15,704(%r15)

    goto *(prog->bpf_func + tail_call_start);
    000003ff8001c81e: e31100200004 lg %r1,32(%r1,%r0)
    000003ff8001c824: 47f01006 bc 15,6(%r1)

    Reviewed-by: Martin Schwidefsky
    Signed-off-by: Michael Holzheu
    Acked-by: Heiko Carstens
    Signed-off-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Michael Holzheu
     

04 Jun, 2015

2 commits

  • Currently the bpf frame pointer is set to the old r15. This is
    wrong because of packed stack. Fix this and adjust the frame pointer
    to respect packed stack. This now generates a prolog like the following:

    3ff8001c3fa: eb67f0480024 stmg %r6,%r7,72(%r15)
    3ff8001c400: ebcff0780024 stmg %r12,%r15,120(%r15)
    3ff8001c406: b904001f lgr %r1,%r15
    Acked-by: Heiko Carstens
    Signed-off-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Michael Holzheu
     
  • On s390x we have to provide 160 bytes stack space before we can call
    the next function. From the 160 bytes that we got from the previous
    function we only use 11 * 8 bytes and have 160 - 11 * 8 bytes left.
    Currently for BPF we allocate additional 160 - 11 * 8 bytes for the
    next function. This is wrong because then the next function only gets:

    (160 - 11 * 8) + (160 - 11 * 8) = 2 * 72 = 144 bytes

    Fix this and allocate enough memory for the next function.

    Fixes: 054623105728 ("s390/bpf: Add s390x eBPF JIT compiler backend")
    Signed-off-by: Michael Holzheu
    Acked-by: Heiko Carstens
    Signed-off-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Michael Holzheu
     

30 Apr, 2015

2 commits

  • When compiling the kernel for GCOV (CONFIG_GCOV_KERNEL,-fprofile-arcs),
    gcc allocates a lot of stack space because of the large switch statement
    in bpf_jit_insn().

    This leads to the following compile warning:

    arch/s390/net/bpf_jit_comp.c: In function 'bpf_jit_prog':
    arch/s390/net/bpf_jit_comp.c:1144:1: warning: frame size of
    function 'bpf_jit_prog' is 12592 bytes which is more than
    half the stack size. The dynamic check would not be reliable.
    No check emitted for this function.

    arch/s390/net/bpf_jit_comp.c:1144:1: warning: the frame size of 12504
    bytes is larger than 1024 bytes [-Wframe-larger-than=]

    And indead gcc allocates 12592 bytes of stack space:

    # objdump -d arch/s390/net/bpf_jit_comp.o
    ...
    0000000000000c60 :
    c60: eb 6f f0 48 00 24 stmg %r6,%r15,72(%r15)
    c66: b9 04 00 ef lgr %r14,%r15
    c6a: e3 f0 fe d0 fc 71 lay %r15,-12592(%r15)

    As a workaround of that problem we now define bpf_jit_insn() as
    noinline which then reduces the stack space.

    # objdump -d arch/s390/net/bpf_jit_comp.o
    ...
    0000000000000070 :
    70: eb 6f f0 48 00 24 stmg %r6,%r15,72(%r15)
    76: c0 d0 00 00 00 00 larl %r13,76
    7c: a7 f1 3f 80 tmll %r15,16256
    80: b9 04 00 ef lgr %r14,%r15
    84: e3 f0 ff a0 ff 71 lay %r15,-96(%r15)

    Signed-off-by: Michael Holzheu
    Signed-off-by: Martin Schwidefsky

    Michael Holzheu
     
  • The s390x ALU64_DIV/MOD has been implemented according to the eBPF
    interpreter specification that used do_div(). This function does a 64-bit
    by 32-bit divide. It turned out that this was wrong and now the interpreter
    uses div64_u64_rem() for full 64-bit division.

    So fix this and use full 64-bit division in the s390x eBPF backend code.

    Signed-off-by: Michael Holzheu
    Signed-off-by: Martin Schwidefsky

    Michael Holzheu
     

15 Apr, 2015

1 commit


15 Jan, 2015

3 commits