1. 26 Oct, 2022 18 commits
  2. 25 Oct, 2022 19 commits
  3. 22 Oct, 2022 3 commits
    • Dave Marchevsky's avatar
      selftests/bpf: Add write to hashmap to array_map iter test · 8f4bc15b
      Dave Marchevsky authored
      Modify iter prog in existing bpf_iter_bpf_array_map.c, which currently
      dumps arraymap key/val, to also do a write of (val, key) into a
      newly-added hashmap. Confirm that the write succeeds as expected by
      modifying the userspace runner program.
      
      Before a change added in an earlier commit - considering PTR_TO_BUF reg
      a valid input to helpers which expect MAP_{KEY,VAL} - the verifier
      would've rejected this prog change due to type mismatch. Since using
      current iter's key/val to access a separate map is a reasonable usecase,
      let's add support for it.
      
      Note that the test prog cannot directly write (val, key) into hashmap
      via bpf_map_update_elem when both come from iter context because key is
      marked MEM_RDONLY. This is due to bpf_map_update_elem - and other basic
      map helpers - taking ARG_PTR_TO_MAP_{KEY,VALUE} w/o MEM_RDONLY type
      flag. bpf_map_{lookup,update,delete}_elem don't modify their
      input key/val so it should be possible to tag their args READONLY, but
      due to the ubiquitous use of these helpers and verifier checks for
      type == MAP_VALUE, such a change is nontrivial and seems better to
      address in a followup series.
      
      Also fixup some 'goto's in test runner's map checking loop.
      Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20221020160721.4030492-4-davemarchevsky@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      8f4bc15b
    • Dave Marchevsky's avatar
      selftests/bpf: Add test verifying bpf_ringbuf_reserve retval use in map ops · 51ee71d3
      Dave Marchevsky authored
      Add a test_ringbuf_map_key test prog, borrowing heavily from extant
      test_ringbuf.c. The program tries to use the result of
      bpf_ringbuf_reserve as map_key, which was not possible before previouis
      commits in this series. The test runner added to prog_tests/ringbuf.c
      verifies that the program loads and does basic sanity checks to confirm
      that it runs as expected.
      
      Also, refactor test_ringbuf such that runners for existing test_ringbuf
      and newly-added test_ringbuf_map_key are subtests of 'ringbuf' top-level
      test.
      Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20221020160721.4030492-3-davemarchevsky@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      51ee71d3
    • Dave Marchevsky's avatar
      bpf: Consider all mem_types compatible for map_{key,value} args · d1673304
      Dave Marchevsky authored
      After the previous patch, which added PTR_TO_MEM | MEM_ALLOC type
      map_key_value_types, the only difference between map_key_value_types and
      mem_types sets is PTR_TO_BUF and PTR_TO_MEM, which are in the latter set
      but not the former.
      
      Helpers which expect ARG_PTR_TO_MAP_KEY or ARG_PTR_TO_MAP_VALUE
      already effectively expect a valid blob of arbitrary memory that isn't
      necessarily explicitly associated with a map. When validating a
      PTR_TO_MAP_{KEY,VALUE} arg, the verifier expects meta->map_ptr to have
      already been set, either by an earlier ARG_CONST_MAP_PTR arg, or custom
      logic like that in process_timer_func or process_kptr_func.
      
      So let's get rid of map_key_value_types and just use mem_types for those
      args.
      
      This has the effect of adding PTR_TO_BUF and PTR_TO_MEM to the set of
      compatible types for ARG_PTR_TO_MAP_KEY and ARG_PTR_TO_MAP_VALUE.
      
      PTR_TO_BUF is used by various bpf_iter implementations to represent a
      chunk of valid r/w memory in ctx args for iter prog.
      
      PTR_TO_MEM is used by networking, tracing, and ringbuf helpers to
      represent a chunk of valid memory. The PTR_TO_MEM | MEM_ALLOC
      type added in previous commit is specific to ringbuf helpers.
      Presence or absence of MEM_ALLOC doesn't change the validity of using
      PTR_TO_MEM as a map_{key,val} input.
      Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20221020160721.4030492-2-davemarchevsky@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      d1673304