1. 24 5月, 2014 2 次提交
    • D
      net: filter: let unattached filters use sock_fprog_kern · b1fcd35c
      Daniel Borkmann 提交于
      The sk_unattached_filter_create() API is used by BPF filters that
      are not directly attached or related to sockets, and are used in
      team, ptp, xt_bpf, cls_bpf, etc. As such all users do their own
      internal managment of obtaining filter blocks and thus already
      have them in kernel memory and set up before calling into
      sk_unattached_filter_create(). As a result, due to __user annotation
      in sock_fprog, sparse triggers false positives (incorrect type in
      assignment [different address space]) when filters are set up before
      passing them to sk_unattached_filter_create(). Therefore, let
      sk_unattached_filter_create() API use sock_fprog_kern to overcome
      this issue.
      Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      Acked-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b1fcd35c
    • A
      lib/test_bpf.c: don't use gcc union shortcut · ece80490
      Andrew Morton 提交于
      Older gcc's (mine is gcc-4.4.4) make a mess of this.
      
      lib/test_bpf.c:74: error: unknown field 'insns' specified in initializer
      lib/test_bpf.c:75: warning: missing braces around initializer
      lib/test_bpf.c:75: warning: (near initialization for 'tests[0].<anonymous>.insns[0]')
      lib/test_bpf.c:76: error: extra brace group at end of initializer
      lib/test_bpf.c:76: error: (near initialization for 'tests[0].<anonymous>')
      lib/test_bpf.c:76: warning: excess elements in union initializer
      lib/test_bpf.c:76: warning: (near initialization for 'tests[0].<anonymous>')
      lib/test_bpf.c:77: error: extra brace group at end of initializer
      
      Cc: Alexei Starovoitov <ast@plumgrid.com>
      Cc: David S. Miller <davem@davemloft.net>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Acked-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ece80490
  2. 22 5月, 2014 1 次提交
    • A
      net: filter: cleanup invocation of internal BPF · 5fe821a9
      Alexei Starovoitov 提交于
      Kernel API for classic BPF socket filters is:
      
      sk_unattached_filter_create() - validate classic BPF, convert, JIT
      SK_RUN_FILTER() - run it
      sk_unattached_filter_destroy() - destroy socket filter
      
      Cleanup internal BPF kernel API as following:
      
      sk_filter_select_runtime() - final step of internal BPF creation.
        Try to JIT internal BPF program, if JIT is not available select interpreter
      SK_RUN_FILTER() - run it
      sk_filter_free() - free internal BPF program
      
      Disallow direct calls to BPF interpreter. Execution of the BPF program should
      be done with SK_RUN_FILTER() macro.
      
      Example of internal BPF create, run, destroy:
      
        struct sk_filter *fp;
      
        fp = kzalloc(sk_filter_size(prog_len), GFP_KERNEL);
        memcpy(fp->insni, prog, prog_len * sizeof(fp->insni[0]));
        fp->len = prog_len;
      
        sk_filter_select_runtime(fp);
      
        SK_RUN_FILTER(fp, ctx);
      
        sk_filter_free(fp);
      
      Sockets, seccomp, testsuite, tracing are using different ways to populate
      sk_filter, so first steps of program creation are not common.
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Acked-by: NDaniel Borkmann <dborkman@redhat.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      5fe821a9
  3. 12 5月, 2014 2 次提交
    • A
      net: filter: additional BPF tests · 9def624a
      Alexei Starovoitov 提交于
      All tests should pass with and without JIT.
      
      Example output:
      test_bpf: #0 TAX 35 16 16 PASS
      test_bpf: #1 TXA 7 7 7 PASS
      test_bpf: #2 ADD_SUB_MUL_K 10 PASS
      test_bpf: #3 DIV_KX 33 PASS
      test_bpf: #4 AND_OR_LSH_K 10 10 PASS
      test_bpf: #5 LD_IND 8 8 8 PASS
      test_bpf: #6 LD_ABS 8 8 8 PASS
      test_bpf: #7 LD_ABS_LL 13 14 PASS
      test_bpf: #8 LD_IND_LL 12 12 12 PASS
      test_bpf: #9 LD_ABS_NET 10 12 PASS
      test_bpf: #10 LD_IND_NET 11 12 12 PASS
      ...
      
      Numbers are times in nsec per filter for given input data.
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      9def624a
    • A
      net: filter: BPF testsuite · 64a8946b
      Alexei Starovoitov 提交于
      The testsuite covers classic and internal BPF instructions.
      It is particularly useful for JIT compiler developers.
      Adds to "net" selftest target.
      
      The testsuite can be used as a set of micro-benchmarks.
      It measures execution time of each BPF program in nsec.
      
      This patch adds core framework.
      Signed-off-by: NAlexei Starovoitov <ast@plumgrid.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      64a8946b