1. 22 12月, 2014 1 次提交
  2. 06 12月, 2014 4 次提交
    • A
      samples: bpf: large eBPF program in C · fbe33108
      Alexei Starovoitov 提交于
      sockex2_kern.c is purposefully large eBPF program in C.
      llvm compiles ~200 lines of C code into ~300 eBPF instructions.
      
      It's similar to __skb_flow_dissect() to demonstrate that complex packet parsing
      can be done by eBPF.
      Then it uses (struct flow_keys)->dst IP address (or hash of ipv6 dst) to keep
      stats of number of packets per IP.
      User space loads eBPF program, attaches it to loopback interface and prints
      dest_ip->#packets stats every second.
      
      Usage:
      $sudo samples/bpf/sockex2
      ip 127.0.0.1 count 19
      ip 127.0.0.1 count 178115
      ip 127.0.0.1 count 369437
      ip 127.0.0.1 count 559841
      ip 127.0.0.1 count 750539
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      fbe33108
    • A
      samples: bpf: trivial eBPF program in C · a8085782
      Alexei Starovoitov 提交于
      this example does the same task as previous socket example
      in assembler, but this one does it in C.
      
      eBPF program in kernel does:
          /* assume that packet is IPv4, load one byte of IP->proto */
          int index = load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol));
          long *value;
      
          value = bpf_map_lookup_elem(&my_map, &index);
          if (value)
              __sync_fetch_and_add(value, 1);
      
      Corresponding user space reads map[tcp], map[udp], map[icmp]
      and prints protocol stats every second
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a8085782
    • A
      samples: bpf: elf_bpf file loader · 249b812d
      Alexei Starovoitov 提交于
      simple .o parser and loader using BPF syscall.
      .o is a standard ELF generated by LLVM backend
      
      It parses elf file compiled by llvm .c->.o
      - parses 'maps' section and creates maps via BPF syscall
      - parses 'license' section and passes it to syscall
      - parses elf relocations for BPF maps and adjusts BPF_LD_IMM64 insns
        by storing map_fd into insn->imm and marking such insns as BPF_PSEUDO_MAP_FD
      - loads eBPF programs via BPF syscall
      
      One ELF file can contain multiple BPF programs.
      
      int load_bpf_file(char *path);
      populates prog_fd[] and map_fd[] with FDs received from bpf syscall
      
      bpf_helpers.h - helper functions available to eBPF programs written in C
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      249b812d
    • A
      samples: bpf: example of stateful socket filtering · 03f4723e
      Alexei Starovoitov 提交于
      this socket filter example does:
      - creates arraymap in kernel with key 4 bytes and value 8 bytes
      
      - loads eBPF program which assumes that packet is IPv4 and loads one byte of
        IP->proto from the packet and uses it as a key in a map
      
        r0 = skb->data[ETH_HLEN + offsetof(struct iphdr, protocol)];
        *(u32*)(fp - 4) = r0;
        value = bpf_map_lookup_elem(map_fd, fp - 4);
        if (value)
             (*(u64*)value) += 1;
      
      - attaches this program to raw socket
      
      - every second user space reads map[IPPROTO_TCP], map[IPPROTO_UDP], map[IPPROTO_ICMP]
        to see how many packets of given protocol were seen on loopback interface
      
      Usage:
      $sudo samples/bpf/sock_example
      TCP 0 UDP 0 ICMP 0 packets
      TCP 187600 UDP 0 ICMP 4 packets
      TCP 376504 UDP 0 ICMP 8 packets
      TCP 563116 UDP 0 ICMP 12 packets
      TCP 753144 UDP 0 ICMP 16 packets
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      03f4723e
  3. 19 11月, 2014 2 次提交
  4. 31 10月, 2014 1 次提交
  5. 22 10月, 2014 1 次提交
  6. 02 10月, 2014 1 次提交
  7. 27 9月, 2014 1 次提交
    • A
      bpf: mini eBPF library, test stubs and verifier testsuite · 3c731eba
      Alexei Starovoitov 提交于
      1.
      the library includes a trivial set of BPF syscall wrappers:
      int bpf_create_map(int key_size, int value_size, int max_entries);
      int bpf_update_elem(int fd, void *key, void *value);
      int bpf_lookup_elem(int fd, void *key, void *value);
      int bpf_delete_elem(int fd, void *key);
      int bpf_get_next_key(int fd, void *key, void *next_key);
      int bpf_prog_load(enum bpf_prog_type prog_type,
      		  const struct sock_filter_int *insns, int insn_len,
      		  const char *license);
      bpf_prog_load() stores verifier log into global bpf_log_buf[] array
      
      and BPF_*() macros to build instructions
      
      2.
      test stubs configure eBPF infra with 'unspec' map and program types.
      These are fake types used by user space testsuite only.
      
      3.
      verifier tests valid and invalid programs and expects predefined
      error log messages from kernel.
      40 tests so far.
      
      $ sudo ./test_verifier
       #0 add+sub+mul OK
       #1 unreachable OK
       #2 unreachable2 OK
       #3 out of range jump OK
       #4 out of range jump2 OK
       #5 test1 ld_imm64 OK
       ...
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      3c731eba
  8. 26 9月, 2014 1 次提交
  9. 01 7月, 2014 1 次提交
  10. 21 6月, 2014 1 次提交
    • S
      tracing: Add __field_struct macro for TRACE_EVENT() · 4d4c9cc8
      Steven Rostedt 提交于
      Currently the __field() macro in TRACE_EVENT is only good for primitive
      values, such as integers and pointers, but it fails on complex data types
      such as structures or unions. This is because the __field() macro
      determines if the variable is signed or not with the test of:
      
        (((type)(-1)) < (type)1)
      
      Unfortunately, that fails when type is a structure.
      
      Since trace events should support structures as fields a new macro
      is created for such a case called __field_struct() which acts exactly
      the same as __field() does but it does not do the signed type check
      and just uses a constant false for that answer.
      
      Cc: Tony Luck <tony.luck@gmail.com>
      Signed-off-by: NSteven Rostedt <rostedt@goodmis.org>
      4d4c9cc8
  11. 14 5月, 2014 1 次提交
  12. 04 4月, 2014 1 次提交
  13. 04 12月, 2013 1 次提交
  14. 15 11月, 2013 1 次提交
    • S
      kfifo API type safety · 498d319b
      Stefani Seibold 提交于
      This patch enhances the type safety for the kfifo API.  It is now safe
      to put const data into a non const FIFO and the API will now generate a
      compiler warning when reading from the fifo where the destination
      address is pointing to a const variable.
      
      As a side effect the kfifo_put() does now expect the value of an element
      instead a pointer to the element.  This was suggested Russell King.  It
      make the handling of the kfifo_put easier since there is no need to
      create a helper variable for getting the address of a pointer or to pass
      integers of different sizes.
      
      IMHO the API break is okay, since there are currently only six users of
      kfifo_put().
      
      The code is also cleaner by kicking out the "if (0)" expressions.
      
      [akpm@linux-foundation.org: coding-style fixes]
      Signed-off-by: NStefani Seibold <stefani@seibold.net>
      Cc: Russell King <rmk@arm.linux.org.uk>
      Cc: Hauke Mehrtens <hauke@hauke-m.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      498d319b
  15. 04 9月, 2013 1 次提交
    • D
      HID: uhid: improve uhid example client · f5e4e7fd
      David Herrmann 提交于
      This extends the uhid example client. It properly documents the built-in
      report-descriptor an adds explicit report-numbers.
      
      Furthermore, LED output reports are added to utilize the new UHID output
      reports of the kernel. Support for 3 basic LEDs is added and a small
      report-parser to print debug messages if output reports were received.
      
      To test this, simply write the EV_LED+LED_CAPSL+1 event to the evdev
      device-node of the uhid-device and the kernel will forward it to your uhid
      client.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      f5e4e7fd
  16. 30 8月, 2013 1 次提交
  17. 20 8月, 2013 1 次提交
  18. 28 3月, 2013 1 次提交
  19. 05 2月, 2013 1 次提交
    • A
      samples/seccomp: be less stupid about cross compiling · 275aaa68
      Arnd Bergmann 提交于
      The seccomp filters are currently built for the build host, not for the
      machine that they are going to run on, but they are also built for with
      the -m32 flag if the kernel is built for a 32 bit machine, both of which
      seems rather odd.
      
      It broke allyesconfig on my machine, which is x86-64, but building for
      32 bit ARM, with this error message:
      
        In file included from /usr/include/stdio.h:28:0,
                         from samples/seccomp/bpf-fancy.c:15:
        /usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
      
      because there are no 32 bit libc headers installed on this machine.  We
      should really be building all the samples for the target machine rather
      than the build host, but since the infrastructure for that appears to be
      missing right now, let's be a little bit smarter and not pass the '-m32'
      flag to the HOSTCC when cross- compiling.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Acked-by: NKees Cook <keescook@chromium.org>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: James Morris <james.l.morris@oracle.com>
      Acked-by: NWill Drewry <wad@chromium.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      275aaa68
  20. 26 1月, 2013 1 次提交
  21. 04 1月, 2013 1 次提交
    • G
      misc: remove __dev* attributes. · 6ae14171
      Greg Kroah-Hartman 提交于
      CONFIG_HOTPLUG is going away as an option.  As a result, the __dev*
      markings need to be removed.
      
      This change removes the last of the __dev* markings from the kernel from
      a variety of different, tiny, places.
      
      Based on patches originally written by Bill Pemberton, but redone by me
      in order to handle some of the coding style issues better, by hand.
      
      Cc: Bill Pemberton <wfp5p@virginia.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6ae14171
  22. 12 9月, 2012 1 次提交
  23. 03 8月, 2012 1 次提交
  24. 28 6月, 2012 1 次提交
  25. 18 6月, 2012 1 次提交
    • D
      HID: uhid: add example program · 5148fa52
      David Herrmann 提交于
      This adds an example user-space program that emulates a 3 button mouse
      with wheel. It detects keyboard presses and moves the mouse accordingly.
      
      It register a fake HID device to feed the raw HID reports into the kernel.
      In this example, you could use uinput to get the same result, but this
      shows how to get the same behavior with uhid so you don't need HID parsers
      in user-space.
      Signed-off-by: NDavid Herrmann <dh.herrmann@googlemail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      5148fa52
  26. 19 4月, 2012 1 次提交
  27. 14 4月, 2012 1 次提交
    • W
      Documentation: prctl/seccomp_filter · 8ac270d1
      Will Drewry 提交于
      Documents how system call filtering using Berkeley Packet
      Filter programs works and how it may be used.
      Includes an example for x86 and a semi-generic
      example using a macro-based code generator.
      Acked-by: NEric Paris <eparis@redhat.com>
      Signed-off-by: NWill Drewry <wad@chromium.org>
      Acked-by: NKees Cook <keescook@chromium.org>
      
      v18: - added acked by
           - update no new privs numbers
      v17: - remove @compat note and add Pitfalls section for arch checking
             (keescook@chromium.org)
      v16: -
      v15: -
      v14: - rebase/nochanges
      v13: - rebase on to 88ebdda6
      v12: - comment on the ptrace_event use
           - update arch support comment
           - note the behavior of SECCOMP_RET_DATA when there are multiple filters
             (keescook@chromium.org)
           - lots of samples/ clean up incl 64-bit bpf-direct support
             (markus@chromium.org)
           - rebase to linux-next
      v11: - overhaul return value language, updates (keescook@chromium.org)
           - comment on do_exit(SIGSYS)
      v10: - update for SIGSYS
           - update for new seccomp_data layout
           - update for ptrace option use
      v9: - updated bpf-direct.c for SIGILL
      v8: - add PR_SET_NO_NEW_PRIVS to the samples.
      v7: - updated for all the new stuff in v7: TRAP, TRACE
          - only talk about PR_SET_SECCOMP now
          - fixed bad JLE32 check (coreyb@linux.vnet.ibm.com)
          - adds dropper.c: a simple system call disabler
      v6: - tweak the language to note the requirement of
            PR_SET_NO_NEW_PRIVS being called prior to use. (luto@mit.edu)
      v5: - update sample to use system call arguments
          - adds a "fancy" example using a macro-based generator
          - cleaned up bpf in the sample
          - update docs to mention arguments
          - fix prctl value (eparis@redhat.com)
          - language cleanup (rdunlap@xenotime.net)
      v4: - update for no_new_privs use
          - minor tweaks
      v3: - call out BPF <-> Berkeley Packet Filter (rdunlap@xenotime.net)
          - document use of tentative always-unprivileged
          - guard sample compilation for i386 and x86_64
      v2: - move code to samples (corbet@lwn.net)
      Signed-off-by: NJames Morris <james.l.morris@oracle.com>
      8ac270d1
  28. 09 2月, 2012 1 次提交
    • O
      samples/rpmsg: add an rpmsg driver sample · 779b96d2
      Ohad Ben-Cohen 提交于
      Add an rpmsg driver sample, which demonstrates how to communicate with
      an AMP-configured remote processor over the rpmsg bus.
      
      Note how once probed, the driver can immediately start sending messages
      using the rpmsg_send() API, without having to worry about creating endpoints
      or allocating rpmsg addresses: all that work is done by the rpmsg bus,
      and the required information is already embedded in the rpmsg channel
      that the driver is probed with.
      
      In this sample, the driver simply sends a "Hello World!" message to the remote
      processor repeatedly.
      
      Designed with Brian Swetland <swetland@google.com>.
      Signed-off-by: NOhad Ben-Cohen <ohad@wizery.com>
      Cc: Brian Swetland <swetland@google.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Grant Likely <grant.likely@secretlab.ca>
      Cc: Tony Lindgren <tony@atomide.com>
      Cc: Russell King <linux@arm.linux.org.uk>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Greg KH <greg@kroah.com>
      Cc: Stephen Boyd <sboyd@codeaurora.org>
      779b96d2
  29. 01 11月, 2011 1 次提交
  30. 01 7月, 2011 2 次提交
    • A
      perf: Add context field to perf_event · 4dc0da86
      Avi Kivity 提交于
      The perf_event overflow handler does not receive any caller-derived
      argument, so many callers need to resort to looking up the perf_event
      in their local data structure.  This is ugly and doesn't scale if a
      single callback services many perf_events.
      
      Fix by adding a context parameter to perf_event_create_kernel_counter()
      (and derived hardware breakpoints APIs) and storing it in the perf_event.
      The field can be accessed from the callback as event->overflow_handler_context.
      All callers are updated.
      Signed-off-by: NAvi Kivity <avi@redhat.com>
      Signed-off-by: NPeter Zijlstra <a.p.zijlstra@chello.nl>
      Link: http://lkml.kernel.org/r/1309362157-6596-2-git-send-email-avi@redhat.comSigned-off-by: NIngo Molnar <mingo@elte.hu>
      4dc0da86
    • P
      perf: Remove the nmi parameter from the swevent and overflow interface · a8b0ca17
      Peter Zijlstra 提交于
      The nmi parameter indicated if we could do wakeups from the current
      context, if not, we would set some state and self-IPI and let the
      resulting interrupt do the wakeup.
      
      For the various event classes:
      
        - hardware: nmi=0; PMI is in fact an NMI or we run irq_work_run from
          the PMI-tail (ARM etc.)
        - tracepoint: nmi=0; since tracepoint could be from NMI context.
        - software: nmi=[0,1]; some, like the schedule thing cannot
          perform wakeups, and hence need 0.
      
      As one can see, there is very little nmi=1 usage, and the down-side of
      not using it is that on some platforms some software events can have a
      jiffy delay in wakeup (when arch_irq_work_raise isn't implemented).
      
      The up-side however is that we can remove the nmi parameter and save a
      bunch of conditionals in fast paths.
      Signed-off-by: NPeter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Michael Cree <mcree@orcon.net.nz>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Deng-Cheng Zhu <dengcheng.zhu@gmail.com>
      Cc: Anton Blanchard <anton@samba.org>
      Cc: Eric B Munson <emunson@mgebm.net>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Paul Mundt <lethal@linux-sh.org>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Jason Wessel <jason.wessel@windriver.com>
      Cc: Don Zickus <dzickus@redhat.com>
      Link: http://lkml.kernel.org/n/tip-agjev8eu666tvknpb3iaj0fg@git.kernel.orgSigned-off-by: NIngo Molnar <mingo@elte.hu>
      a8b0ca17
  31. 21 4月, 2011 1 次提交
    • R
      HID: hid-example: fix some build issues · d431b2e3
      Randy Dunlap 提交于
      samples/hid-example.o needs some Kconfig and Makefile additions in order
      to build.  It should use <linux/*.h> headers from the build tree, so use
      HEADERS_CHECK to require that those header files be present.
      
      Change the kconfig symbol from tristate to bool since userspace cannot be
      built as loadable modules.
      
      However, I don't understand why the userspace header files are not present
      as reported in Andrew's build log, since it builds OK on x86_64 without
      any of these changes.
      Signed-off-by: NRandy Dunlap <randy.dunlap@oracle.com>
      Cc: Alan Ott <alan@signal11.us>
      Cc: Jiri Kosina <jkosina@suse.cz>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      d431b2e3
  32. 09 4月, 2011 1 次提交
  33. 31 3月, 2011 1 次提交
  34. 22 3月, 2011 1 次提交
  35. 30 10月, 2010 1 次提交