1. 24 Jan, 2017 37 commits
  2. 23 Jan, 2017 3 commits
    • David S. Miller's avatar
      Merge branch 'bpf-lpm' · 2acc76cb
      David S. Miller authored
      Daniel Mack says:
      
      ====================
      bpf: add longest prefix match map
      
      This patch set adds a longest prefix match algorithm that can be used
      to match IP addresses to a stored set of ranges. It is exposed as a
      bpf map type.
      
      Internally, data is stored in an unbalanced tree of nodes that has a
      maximum height of n, where n is the prefixlen the trie was created
      with.
      
      Note that this has nothing to do with fib or fib6 and is in no way meant
      to replace or share code with it. It's rather a much simpler
      implementation that is specifically written with bpf maps in mind.
      
      Patch 1/2 adds the implementation, 2/2 an extensive test suite and 3/3
      has benchmarking code for the new trie type.
      
      Feedback is much appreciated.
      
      Changelog:
      
      v3 -> v4:
      	* David added a 3rd patch that augments map_perf_test for
      	  LPM trie benchmarks
      	* Limit allocation of maps of this new type to CAP_SYS_ADMIN
      	  for now, as requested by Alexei
      	* Add a stub .map_delete_elem so the core does not stumble
      	  over a NULL pointer when the syscall is invoked
      	* Tests for non-power-of-2 prefix lengths were added
      	* More comment style fixes
      
      v2 -> v3:
      	* Store both the key match data and the caller provided
      	  value in the same byte array attached to a node. This
      	  avoids double allocations
      	* Bring back node->flags to distinguish between 'real'
      	  and intermediate nodes
      	* Fix comment style and some typos
      
      v1 -> v2:
      	* Turn spin lock into raw spinlock
      	* Lock with irqsave options during trie_update_elem()
      	* Return -ENOMEM properly from trie_alloc()
      	* Force attr->flags == BPF_F_NO_PREALLOC during creation
      	* Set trie->map.pages after creation to account for map memory
      	* Allow arbitrary value sizes
      	* Removed node->flags and denode intermediate nodes through
      	  node->value == NULL instead
      
      rfc -> v1:
      	* Add __rcu pointer annotations to make sparse happy
      	* Fold _lpm_trie_find_target_node() into its only caller
      	* Fix some minor documentation issues
      ====================
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2acc76cb
    • David Herrmann's avatar
      samples/bpf: add lpm-trie benchmark · b8a943e2
      David Herrmann authored
      Extend the map_perf_test_{user,kern}.c infrastructure to stress test
      lpm-trie lookups. We hook into the kprobe on sys_gettid() and measure
      the latency depending on trie size and lookup count.
      
      On my Intel Haswell i7-6400U, a single gettid() syscall with an empty
      bpf program takes roughly 6.5us on my system. Lookups in empty tries
      take ~1.8us on first try, ~0.9us on retries. Lookups in tries with 8192
      entries take ~7.1us (on the first _and_ any subsequent try).
      Signed-off-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
      Reviewed-by: default avatarDaniel Mack <daniel@zonque.org>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      b8a943e2
    • David Herrmann's avatar
      bpf: Add tests for the lpm trie map · 4d3381f5
      David Herrmann authored
      The first part of this program runs randomized tests against the
      lpm-bpf-map. It implements a "Trivial Longest Prefix Match" (tlpm)
      based on simple, linear, single linked lists. The implementation
      should be pretty straightforward.
      
      Based on tlpm, this inserts randomized data into bpf-lpm-maps and
      verifies the trie-based bpf-map implementation behaves the same way
      as tlpm.
      
      The second part uses 'real world' IPv4 and IPv6 addresses and tests
      the trie with those.
      Signed-off-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: default avatarDaniel Mack <daniel@zonque.org>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      4d3381f5