1. 21 12月, 2019 1 次提交
  2. 20 12月, 2019 4 次提交
    • A
      selftests/bpf: Test BPF_F_REPLACE in cgroup_attach_multi · 06ac0186
      Andrey Ignatov 提交于
      Test replacing a cgroup-bpf program attached with BPF_F_ALLOW_MULTI and
      possible failure modes: invalid combination of flags, invalid
      replace_bpf_fd, replacing a non-attachd to specified cgroup program.
      
      Example of program replacing:
      
        # gdb -q --args ./test_progs --name=cgroup_attach_multi
        ...
        Breakpoint 1, test_cgroup_attach_multi () at cgroup_attach_multi.c:227
        (gdb)
        [1]+  Stopped                 gdb -q --args ./test_progs --name=cgroup_attach_multi
        # bpftool c s /mnt/cgroup2/cgroup-test-work-dir/cg1
        ID       AttachType      AttachFlags     Name
        2133     egress          multi
        2134     egress          multi
        # fg
        gdb -q --args ./test_progs --name=cgroup_attach_multi
        (gdb) c
        Continuing.
      
        Breakpoint 2, test_cgroup_attach_multi () at cgroup_attach_multi.c:233
        (gdb)
        [1]+  Stopped                 gdb -q --args ./test_progs --name=cgroup_attach_multi
        # bpftool c s /mnt/cgroup2/cgroup-test-work-dir/cg1
        ID       AttachType      AttachFlags     Name
        2139     egress          multi
        2134     egress          multi
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/7b9b83e8d5fb82e15b034341bd40b6fb2431eeba.1576741281.git.rdna@fb.com
      06ac0186
    • A
      selftests/bpf: Convert test_cgroup_attach to prog_tests · 257c8855
      Andrey Ignatov 提交于
      Convert test_cgroup_attach to prog_tests.
      
      This change does a lot of things but in many cases it's pretty expensive
      to separate them, so they go in one commit. Nevertheless the logic is
      ketp as is and changes made are just moving things around, simplifying
      them (w/o changing the meaning of the tests) and making prog_tests
      compatible:
      
      * split the 3 tests in the file into 3 separate files in prog_tests/;
      
      * rename the test functions to test_<file_base_name>;
      
      * remove unused includes, constants, variables and functions from every
        test;
      
      * replace `if`-s with or `if (CHECK())` where additional context should
        be logged and with `if (CHECK_FAIL())` where line number is enough;
      
      * switch from `log_err()` to logging via `CHECK()`;
      
      * replace `assert`-s with `CHECK_FAIL()` to avoid crashing the whole
        test_progs if one assertion fails;
      
      * replace cgroup_helpers with test__join_cgroup() in
        cgroup_attach_override only, other tests need more fine-grained
        control for cgroup creation/deletion so cgroup_helpers are still used
        there;
      
      * simplify cgroup_attach_autodetach by switching to easiest possible
        program since this test doesn't really need such a complicated program
        as cgroup_attach_multi does;
      
      * remove test_cgroup_attach.c itself.
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/0ff19cc64d2dc5cf404349f07131119480e10e32.1576741281.git.rdna@fb.com
      257c8855
    • A
      libbpf: Introduce bpf_prog_attach_xattr · cdbee383
      Andrey Ignatov 提交于
      Introduce a new bpf_prog_attach_xattr function that, in addition to
      program fd, target fd and attach type, accepts an extendable struct
      bpf_prog_attach_opts.
      
      bpf_prog_attach_opts relies on DECLARE_LIBBPF_OPTS macro to maintain
      backward and forward compatibility and has the following "optional"
      attach attributes:
      
      * existing attach_flags, since it's not required when attaching in NONE
        mode. Even though it's quite often used in MULTI and OVERRIDE mode it
        seems to be a good idea to reduce number of arguments to
        bpf_prog_attach_xattr;
      
      * newly introduced attribute of BPF_PROG_ATTACH command: replace_prog_fd
        that is fd of previously attached cgroup-bpf program to replace if
        BPF_F_REPLACE flag is used.
      
      The new function is named to be consistent with other xattr-functions
      (bpf_prog_test_run_xattr, bpf_create_map_xattr, bpf_load_program_xattr).
      
      The struct bpf_prog_attach_opts is supposed to be used with
      DECLARE_LIBBPF_OPTS macro.
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/bd6e0732303eb14e4b79cb128268d9e9ad6db208.1576741281.git.rdna@fb.com
      cdbee383
    • A
      bpf: Support replacing cgroup-bpf program in MULTI mode · 7dd68b32
      Andrey Ignatov 提交于
      The common use-case in production is to have multiple cgroup-bpf
      programs per attach type that cover multiple use-cases. Such programs
      are attached with BPF_F_ALLOW_MULTI and can be maintained by different
      people.
      
      Order of programs usually matters, for example imagine two egress
      programs: the first one drops packets and the second one counts packets.
      If they're swapped the result of counting program will be different.
      
      It brings operational challenges with updating cgroup-bpf program(s)
      attached with BPF_F_ALLOW_MULTI since there is no way to replace a
      program:
      
      * One way to update is to detach all programs first and then attach the
        new version(s) again in the right order. This introduces an
        interruption in the work a program is doing and may not be acceptable
        (e.g. if it's egress firewall);
      
      * Another way is attach the new version of a program first and only then
        detach the old version. This introduces the time interval when two
        versions of same program are working, what may not be acceptable if a
        program is not idempotent. It also imposes additional burden on
        program developers to make sure that two versions of their program can
        co-exist.
      
      Solve the problem by introducing a "replace" mode in BPF_PROG_ATTACH
      command for cgroup-bpf programs being attached with BPF_F_ALLOW_MULTI
      flag. This mode is enabled by newly introduced BPF_F_REPLACE attach flag
      and bpf_attr.replace_bpf_fd attribute to pass fd of the old program to
      replace
      
      That way user can replace any program among those attached with
      BPF_F_ALLOW_MULTI flag without the problems described above.
      
      Details of the new API:
      
      * If BPF_F_REPLACE is set but replace_bpf_fd doesn't have valid
        descriptor of BPF program, BPF_PROG_ATTACH will return corresponding
        error (EINVAL or EBADF).
      
      * If replace_bpf_fd has valid descriptor of BPF program but such a
        program is not attached to specified cgroup, BPF_PROG_ATTACH will
        return ENOENT.
      
      BPF_F_REPLACE is introduced to make the user intent clear, since
      replace_bpf_fd alone can't be used for this (its default value, 0, is a
      valid fd). BPF_F_REPLACE also makes it possible to extend the API in the
      future (e.g. add BPF_F_BEFORE and BPF_F_AFTER if needed).
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Acked-by: NAndrii Narkyiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/30cd850044a0057bdfcaaf154b7d2f39850ba813.1576741281.git.rdna@fb.com
      7dd68b32
  3. 19 12月, 2019 12 次提交
  4. 18 12月, 2019 6 次提交
  5. 17 12月, 2019 2 次提交
  6. 16 12月, 2019 15 次提交