1. 17 Oct, 2019 9 commits
  2. 16 Oct, 2019 2 commits
    • Song Liu's avatar
      bpf/stackmap: Fix deadlock with rq_lock in bpf_get_stack() · eac9153f
      Song Liu authored
      bpf stackmap with build-id lookup (BPF_F_STACK_BUILD_ID) can trigger A-A
      deadlock on rq_lock():
      
      rcu: INFO: rcu_sched detected stalls on CPUs/tasks:
      [...]
      Call Trace:
       try_to_wake_up+0x1ad/0x590
       wake_up_q+0x54/0x80
       rwsem_wake+0x8a/0xb0
       bpf_get_stack+0x13c/0x150
       bpf_prog_fbdaf42eded9fe46_on_event+0x5e3/0x1000
       bpf_overflow_handler+0x60/0x100
       __perf_event_overflow+0x4f/0xf0
       perf_swevent_overflow+0x99/0xc0
       ___perf_sw_event+0xe7/0x120
       __schedule+0x47d/0x620
       schedule+0x29/0x90
       futex_wait_queue_me+0xb9/0x110
       futex_wait+0x139/0x230
       do_futex+0x2ac/0xa50
       __x64_sys_futex+0x13c/0x180
       do_syscall_64+0x42/0x100
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      This can be reproduced by:
      1. Start a multi-thread program that does parallel mmap() and malloc();
      2. taskset the program to 2 CPUs;
      3. Attach bpf program to trace_sched_switch and gather stackmap with
         build-id, e.g. with trace.py from bcc tools:
         trace.py -U -p <pid> -s <some-bin,some-lib> t:sched:sched_switch
      
      A sample reproducer is attached at the end.
      
      This could also trigger deadlock with other locks that are nested with
      rq_lock.
      
      Fix this by checking whether irqs are disabled. Since rq_lock and all
      other nested locks are irq safe, it is safe to do up_read() when irqs are
      not disable. If the irqs are disabled, postpone up_read() in irq_work.
      
      Fixes: 615755a7 ("bpf: extend stackmap to save binary_build_id+offset instead of address")
      Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20191014171223.357174-1-songliubraving@fb.com
      
      Reproducer:
      ============================ 8< ============================
      
      char *filename;
      
      void *worker(void *p)
      {
              void *ptr;
              int fd;
              char *pptr;
      
              fd = open(filename, O_RDONLY);
              if (fd < 0)
                      return NULL;
              while (1) {
                      struct timespec ts = {0, 1000 + rand() % 2000};
      
                      ptr = mmap(NULL, 4096 * 64, PROT_READ, MAP_PRIVATE, fd, 0);
                      usleep(1);
                      if (ptr == MAP_FAILED) {
                              printf("failed to mmap\n");
                              break;
                      }
                      munmap(ptr, 4096 * 64);
                      usleep(1);
                      pptr = malloc(1);
                      usleep(1);
                      pptr[0] = 1;
                      usleep(1);
                      free(pptr);
                      usleep(1);
                      nanosleep(&ts, NULL);
              }
              close(fd);
              return NULL;
      }
      
      int main(int argc, char *argv[])
      {
              void *ptr;
              int i;
              pthread_t threads[THREAD_COUNT];
      
              if (argc < 2)
                      return 0;
      
              filename = argv[1];
      
              for (i = 0; i < THREAD_COUNT; i++) {
                      if (pthread_create(threads + i, NULL, worker, NULL)) {
                              fprintf(stderr, "Error creating thread\n");
                              return 0;
                      }
              }
      
              for (i = 0; i < THREAD_COUNT; i++)
                      pthread_join(threads[i], NULL);
              return 0;
      }
      ============================ 8< ============================
      eac9153f
    • Jakub Sitnicki's avatar
      scripts/bpf: Emit an #error directive known types list needs updating · 456a513b
      Jakub Sitnicki authored
      Make the compiler report a clear error when bpf_helpers_doc.py needs
      updating rather than rely on the fact that Clang fails to compile
      English:
      
      ../../../lib/bpf/bpf_helper_defs.h:2707:1: error: unknown type name 'Unrecognized'
      Unrecognized type 'struct bpf_inet_lookup', please add it to known types!
      Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20191016085811.11700-1-jakub@cloudflare.com
      456a513b
  3. 15 Oct, 2019 14 commits
  4. 14 Oct, 2019 6 commits
    • David S. Miller's avatar
      Merge branch 'PTP-driver-refactoring-for-SJA1105-DSA' · 85a83a8f
      David S. Miller authored
      Vladimir Oltean says:
      
      ====================
      PTP driver refactoring for SJA1105 DSA
      
      This series creates a better separation between the driver core and the
      PTP portion. Therefore, users who are not interested in PTP can get a
      simpler and smaller driver by compiling it out.
      
      This is in preparation for further patches: SPI transfer timestamping,
      synchronizing the hardware clock (as opposed to keeping it
      free-running), PPS input/output, etc.
      ====================
      Acked-by: default avatarRichard Cochran <richardcochran@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      85a83a8f
    • Vladimir Oltean's avatar
      net: dsa: sja1105: Change the PTP command access pattern · 66427778
      Vladimir Oltean authored
      The PTP command register contains enable bits for:
      - Putting the 64-bit PTPCLKVAL register in add/subtract or write mode
      - Taking timestamps off of the corrected vs free-running clock
      - Starting/stopping the TTEthernet scheduling
      - Starting/stopping PPS output
      - Resetting the switch
      
      When a command needs to be issued (e.g. "change the PTPCLKVAL from write
      mode to add/subtract mode"), one cannot simply write to the command
      register setting the PTPCLKADD bit to 1, because that would zeroize the
      other settings. One also cannot do a read-modify-write (that would be
      too easy for this hardware) because not all bits of the command register
      are readable over SPI.
      
      So this leaves us with the only option of keeping the value of the PTP
      command register in the driver, and operating on that.
      
      Actually there are 2 types of PTP operations now:
      - Operations that modify the cached PTP command. These operate on
        ptp_data->cmd as a pointer.
      - Operations that apply all previously cached PTP settings, but don't
        otherwise cache what they did themselves. The sja1105_ptp_reset
        function is such an example. It copies the ptp_data->cmd on stack
        before modifying and writing it to SPI.
      
      This practically means that struct sja1105_ptp_cmd is no longer an
      implementation detail, since it needs to be stored in full into struct
      sja1105_ptp_data, and hence in struct sja1105_private. So the (*ptp_cmd)
      function prototype can change and take struct sja1105_ptp_cmd as second
      argument now.
      Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      66427778
    • Vladimir Oltean's avatar
      net: dsa: sja1105: Move PTP data to its own private structure · a9d6ed7a
      Vladimir Oltean authored
      This is a non-functional change with 2 goals (both for the case when
      CONFIG_NET_DSA_SJA1105_PTP is not enabled):
      
      - Reduce the size of the sja1105_private structure.
      - Make the PTP code more self-contained.
      
      Leaving priv->ptp_data.lock to be initialized in sja1105_main.c is not a
      leftover: it will be used in a future patch "net: dsa: sja1105: Restore
      PTP time after switch reset".
      Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      a9d6ed7a
    • Vladimir Oltean's avatar
      net: dsa: sja1105: Make all public PTP functions take dsa_switch as argument · 61c77126
      Vladimir Oltean authored
      The new rule (as already started for sja1105_tas.h) is for functions of
      optional driver components (ones which may be disabled via Kconfig - PTP
      and TAS) to take struct dsa_switch *ds instead of struct sja1105_private
      *priv as first argument.
      
      This is so that forward-declarations of struct sja1105_private can be
      avoided.
      
      So make sja1105_ptp.h the second user of this rule.
      Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      61c77126
    • Vladimir Oltean's avatar
      net: dsa: sja1105: Get rid of global declaration of struct ptp_clock_info · 5b3ae43a
      Vladimir Oltean authored
      We need priv->ptp_caps to hold a structure and not just a pointer,
      because we use container_of in the various PTP callbacks.
      
      Therefore, the sja1105_ptp_caps structure declared in the global memory
      of the driver serves no further purpose after copying it into
      priv->ptp_caps.
      
      So just populate priv->ptp_caps with the needed operations and remove
      sja1105_ptp_caps.
      Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      5b3ae43a
    • David S. Miller's avatar
      Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next · a98d62c3
      David S. Miller authored
      Alexei Starovoitov says:
      
      ====================
      pull-request: bpf-next 2019-10-14
      
      The following pull-request contains BPF updates for your *net-next* tree.
      
      12 days of development and
      85 files changed, 1889 insertions(+), 1020 deletions(-)
      
      The main changes are:
      
      1) auto-generation of bpf_helper_defs.h, from Andrii.
      
      2) split of bpf_helpers.h into bpf_{helpers, helper_defs, endian, tracing}.h
         and move into libbpf, from Andrii.
      
      3) Track contents of read-only maps as scalars in the verifier, from Andrii.
      
      4) small x86 JIT optimization, from Daniel.
      
      5) cross compilation support, from Ivan.
      
      6) bpf flow_dissector enhancements, from Jakub and Stanislav.
      ====================
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      a98d62c3
  5. 13 Oct, 2019 3 commits
  6. 12 Oct, 2019 6 commits
    • Alexei Starovoitov's avatar
      Merge branch 'selftests-bpf-Makefile-cleanup' · b8fc345d
      Alexei Starovoitov authored
      Andrii Nakryiko says:
      
      ====================
      Patch #1 enforces libbpf build to have bpf_helper_defs.h ready before test BPF
      programs are built.
      Patch #2 drops obsolete BTF/pahole detection logic from Makefile.
      
      v1->v2:
      - drop CPU and PROBE (Martin).
      ====================
      Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      b8fc345d
    • Andrii Nakryiko's avatar
      selftests/bpf: Remove obsolete pahole/BTF support detection · 598dc04f
      Andrii Nakryiko authored
      Given lots of selftests won't work without recent enough Clang/LLVM that
      fully supports BTF, there is no point in maintaining outdated BTF
      support detection and fall-back to pahole logic. Just assume we have
      everything we need.
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20191011220146.3798961-3-andriin@fb.com
      598dc04f
    • Andrii Nakryiko's avatar
      selftests/bpf: Enforce libbpf build before BPF programs are built · 3fbe31ae
      Andrii Nakryiko authored
      Given BPF programs rely on libbpf's bpf_helper_defs.h, which is
      auto-generated during libbpf build, libbpf build has to happen before
      we attempt progs/*.c build. Enforce it as order-only dependency.
      
      Fixes: 24f25763 ("libbpf: auto-generate list of BPF helper definitions")
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20191011220146.3798961-2-andriin@fb.com
      3fbe31ae
    • Alexei Starovoitov's avatar
      Merge branch 'samples-cross-compile' · c2383d39
      Alexei Starovoitov authored
      Ivan Khoronzhuk says:
      
      ====================
      This series contains mainly fixes/improvements for cross-compilation
      but not only, tested for arm, arm64, and intended for any arch.
      Also verified on native build (not cross compilation) for x86_64
      and arm, arm64.
      
      Initial RFC link:
      https://lkml.org/lkml/2019/8/29/1665
      
      Prev. version:
      https://lkml.org/lkml/2019/10/9/1045
      
      Besides the patches given here, the RFC also contains couple patches
      related to llvm clang
        arm: include: asm: swab: mask rev16 instruction for clang
        arm: include: asm: unified: mask .syntax unified for clang
      They are necessarily to verify arm 32 build.
      
      Also, couple more fixes were added but are not merged in bpf-next yet,
      they can be needed for verification/configuration steps, if not in
      your tree the fixes can be taken here:
      https://www.spinics.net/lists/netdev/msg601716.html
      https://www.spinics.net/lists/netdev/msg601714.html
      https://www.spinics.net/lists/linux-kbuild/msg23468.html
      
      Now, to build samples, SAMPLE_BPF should be enabled in config.
      
      The change touches not only cross-compilation and can have impact on
      other archs and build environments, so might be good idea to verify
      it in order to add appropriate changes, some warn options could be
      tuned also.
      
      All is tested on x86-64 with clang installed (has to be built containing
      targets for arm, arm64..., see llc --version, usually it's present already)
      
      Instructions to test native on x86_64
      =================================================
      Native build on x86_64 is done in usual way and shouldn't have difference
      except HOSTCC is now printed as CC wile building the samples.
      
      Instructions to test cross compilation on arm64
      =================================================
      gcc version 8.3.0
      (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))
      
      I've used sdk for TI am65x got here:
      http://downloads.ti.com/processor-sdk-linux/esd/AM65X/latest/exports/\
      ti-processor-sdk-linux-am65xx-evm-06.00.00.07-Linux-x86-Install.bin
      
      make ARCH=arm64 -C tools/ clean
      make ARCH=arm64 -C samples/bpf clean
      make ARCH=arm64 clean
      make ARCH=arm64 defconfig
      
      make ARCH=arm64 headers_install
      
      make ARCH=arm64 INSTALL_HDR_PATH=/../sdk/\
      ti-processor-sdk-linux-am65xx-evm-06.00.00.07/linux-devkit/sysroots/\
      aarch64-linux/usr headers_install
      
      make samples/bpf/ ARCH=arm64 CROSS_COMPILE="aarch64-linux-gnu-"\
      SYSROOT="/../sdk/ti-processor-sdk-linux-am65xx-evm-06.00.00.07/\
      linux-devkit/sysroots/aarch64-linux"
      
      Instructions to test cross compilation on arm
      =================================================
      arm-linux-gnueabihf-gcc (Linaro GCC 7.2-2017.11) 7.2.1 20171011
      or
      arm-linux-gnueabihf-gcc
      (GNU Toolchain for the A-profile Architecture 8.3-2019.03 \
      (arm-rel-8.36)) 8.3.0
      
      http://downloads.ti.com/processor-sdk-linux/esd/AM57X/05_03_00_07/exports/\
      ti-processor-sdk-linux-am57xx-evm-05.03.00.07-Linux-x86-Install.bin
      
      make ARCH=arm -C tools/ clean
      make ARCH=arm -C samples/bpf clean
      make ARCH=arm clean
      make ARCH=arm omap2plus_defconfig
      
      make ARCH=arm headers_install
      
      make ARCH=arm INSTALL_HDR_PATH=/../sdk/\
      ti-processor-sdk-linux-am57xx-evm-05.03.00.07/linux-devkit/sysroots/\
      armv7ahf-neon-linux-gnueabi/usr headers_install
      
      make samples/bpf/ ARCH=arm CROSS_COMPILE="arm-linux-gnueabihf-"\
      SYSROOT="/../sdk/ti-processor-sdk-linux-am57xx-evm-05.03\
      .00.07/linux-devkit/sysroots/armv7ahf-neon-linux-gnueabi"
      
      Based on bpf-next/master
      
      v5..v4:
      - any changes, only missed SOBs are added
      
      v4..v3:
      - renamed CLANG_EXTRA_CFLAGS on BPF_EXTRA_CFLAGS
      - used filter for ARCH_ARM_SELECTOR
      - omit "-fomit-frame-pointer" and use same flags for native and "cross"
      - used sample/bpf prefixes
      - use C instead of C++ compiler for test_libbpf target
      
      v3..v2:
      - renamed makefile.progs to makeifle.target, as more appropriate
      - left only __LINUX_ARM_ARCH__ for D options for arm
      - for host build - left options from KBUILD_HOST for compatibility reasons
      - split patch adding c/cxx/ld flags to libbpf by modules
      - moved readme change to separate patch
      - added patch setting options for cross-compile
      - fixed issue with option error for syscall_nrs.S,
        avoiding overlap for ccflags-y.
      
      v2..v1:
      - restructured patches order
      - split "samples: bpf: Makefile: base progs build on Makefile.progs"
        to make change more readable. It added couple nice extra patches.
      - removed redundant patch:
        "samples: bpf: Makefile: remove target for native build"
      - added fix:
        "samples: bpf: makefile: fix cookie_uid_helper_example obj build"
      - limited -D option filter only for arm
      - improved comments
      - added couple instructions to verify cross compilation for arm and
        arm64 arches based on TI am57xx and am65xx sdks.
      - corrected include a little order
      ====================
      Tested-by: default avatarIlias Apalodimas <ilias.apalodimas@linaro.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      c2383d39
    • Ivan Khoronzhuk's avatar
      samples/bpf: Add preparation steps and sysroot info to readme · 1600c9c2
      Ivan Khoronzhuk authored
      Add couple preparation steps: clean and configuration. Also add newly
      added sysroot support info to cross-compile section.
      Signed-off-by: default avatarIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20191011002808.28206-16-ivan.khoronzhuk@linaro.org
      1600c9c2
    • Ivan Khoronzhuk's avatar
      samples/bpf: Add sysroot support · b2327c10
      Ivan Khoronzhuk authored
      Basically it only enables that was added by previous couple fixes.
      Sysroot contains correct libs installed and its headers. Useful when
      working with NFC or virtual machine.
      
      Usage example:
      
      clean (on demand)
          make ARCH=arm -C samples/bpf clean
          make ARCH=arm -C tools clean
          make ARCH=arm clean
      
      configure and install headers:
      
          make ARCH=arm defconfig
          make ARCH=arm headers_install
      
      build samples/bpf:
          make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- samples/bpf/ \
          SYSROOT="path/to/sysroot"
      Signed-off-by: default avatarIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20191011002808.28206-15-ivan.khoronzhuk@linaro.org
      b2327c10