Skip to contentSkip to conversation

bpf: expose cgroup preorder attachment state to userspace

PATCH Applied Hui Su 4 participants 8 messages Sep 22 – Sep 24

Subsystems (4)
lore
Share & tools
lore

Hui Su

author
#0 lore raw

v3 cover bpf: expose cgroup preorder attachment state to userspace

The BPF_F_PREORDER attach flag changes the ordering of programs in the effective cgroup program array, but BPF_PROG_QUERY did not report the per-program flag. This series exposes that state and updates bpftool to display, accept, and document this flag.

The series is split into three patches:

1. Report BPF_F_PREORDER in direct cgroup program queries.
2. Add selftests for direct and link-based program queries.
3. Add bpftool support for text, JSON, command-line, completion, and documentation handling of BPF_F_PREORDER.

Changes in v3:
- Simplify the changelogs for patches 1 and 2.
- Simplify the ATTACH_FLAGS synopsis and represent attach flags as an array in JSON output, as suggested by Quentin Monnet.
- Widen the plain-text AttachFlags column for combined flags.
- Address checkpatch line-length and alignment warnings.

Testing:
- PASS: cgroup_mprog_opts, cgroup_preorder, and bpftool cgroup plain-text/JSON smoke (x86_64 QEMU/KVM).
- PASS: bpftool build, Documentation build, bash -n, and checkpatch on generated v3 patches.

Previous versions:
v2: https://lore.kernel.org/bpf/[email protected]/
v1: https://lore.kernel.org/bpf/[email protected]/

Hui Su (3):
bpf: Report BPF_F_PREORDER in cgroup program queries selftests/bpf: Test querying BPF_F_PREORDER cgroup attachments
bpftool: Add support for BPF_F_PREORDER cgroup attach flag

 kernel/bpf/cgroup.c                           | 16 +--
 .../bpftool/Documentation/bpftool-cgroup.rst  | 25 +++--
 tools/bpf/bpftool/bash-completion/bpftool     |  4 +-
 tools/bpf/bpftool/cgroup.c                    | 99 +++++++++++++------
 .../bpf/prog_tests/cgroup_mprog_opts.c        | 71 ++++++++++++-
 5 files changed, 166 insertions(+), 49 deletions(-)

base-commit: 79dc258c9392051420a26f1504c647bd3d27c66a

Signature · 1 line
2.55.0
author
#1 lore raw

PATCH v3 1/3 bpf: Report BPF_F_PREORDER in cgroup program queries

Extend direct cgroup program queries to merge
(pl->flags & BPF_F_PREORDER) with the cgroup-wide flags when copying prog_attach_flags to user space. Only BPF_F_PREORDER is extracted from pl->flags to ensure transient positioning flags (such as BPF_F_BEFORE, BPF_F_AFTER, BPF_F_ID, or BPF_F_REPLACE) are not leaked to user space.

This can introduce new prog_attach_flags[] values with BPF_F_PREORDER set, for example 0x40 (BPF_F_PREORDER), 0x41 (BPF_F_ALLOW_OVERRIDE | BPF_F_PREORDER), or 0x42 (BPF_F_ALLOW_MULTI | BPF_F_PREORDER), depending on the cgroup-wide attachment mode.

Older bpftool versions treat such combinations as unknown flags; bpftool support is updated later in this series.

---

Notes (bpf-preorder-v3-20260922-check):
Testing:
- PASS: ./test_progs -t cgroup_mprog_opts (x86_64 QEMU/KVM).
- Result reused after a content-equivalent rebase; the patch diff is unchanged.

 kernel/bpf/cgroup.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
kernel/bpf/cgroup.c +8 -8
index 1cb5e6a6ffc1..2bbe77de89f0 100644
@@ -1515,19 +1515,19 @@ static int __cgroup_bpf_query(struct cgroup *cgrp, const union bpf_attr *attr,
 				id = prog_list_id(pl);
 				if (copy_to_user(prog_ids + i, &id, sizeof(id)))
 					return -EFAULT;
+				if (prog_attach_flags) {
+					flags = cgrp->bpf.flags[atype] |
+						(pl->flags & BPF_F_PREORDER);
+					if (copy_to_user(prog_attach_flags + i,
+							 &flags, sizeof(flags)))
+						return -EFAULT;
+				}
 				if (++i == cnt)
 					break;
 			}
 
-			if (prog_attach_flags) {
-				flags = cgrp->bpf.flags[atype];
-
-				for (i = 0; i < cnt; i++)
-					if (copy_to_user(prog_attach_flags + i,
-							 &flags, sizeof(flags)))
-						return -EFAULT;
+			if (prog_attach_flags)
 				prog_attach_flags += cnt;
-			}
 		}
 
 		prog_ids += cnt;
Signature · 1 line
2.55.0
author
#2 lore raw

PATCH v3 2/3 selftests/bpf: Test querying BPF_F_PREORDER cgroup attachments

In reply to Hui Su

Extend cgroup_mprog_opts selftests to verify that BPF_PROG_QUERY reports BPF_F_PREORDER in prog_attach_flags for both direct program and link attachments.

Verify that:
- Programs attached with BPF_F_PREORDER report BPF_F_ALLOW_MULTI | BPF_F_PREORDER (0x42) in prog_attach_flags.
- Programs attached without BPF_F_PREORDER report BPF_F_ALLOW_MULTI (0x2).
- Transient flags such as BPF_F_AFTER or BPF_F_LINK are not present in prog_attach_flags.

---

Notes (bpf-preorder-v3-20260922-check):
Testing:
- PASS: ./test_progs -t cgroup_preorder (x86_64 QEMU/KVM).
- Result reused after a content-equivalent rebase; the patch diff is unchanged.

 .../bpf/prog_tests/cgroup_mprog_opts.c        | 71 ++++++++++++++++++-
 1 file changed, 69 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/cgroup_mprog_opts.c +69 -2
index bb60704a3ef9..9ec5e4f96312 100644
@@ -273,11 +273,64 @@ static void test_link_attach_detach(int atype)
 	close(cg);
 }
 
+static int find_prog_attach_flags(const struct bpf_prog_query_opts *opts,
+				  __u32 prog_id, __u32 *flags)
+{
+	__u32 i;
+
+	for (i = 0; i < opts->count; i++) {
+		if (opts->prog_ids[i] == prog_id) {
+			*flags = opts->prog_attach_flags[i];
+			return 0;
+		}
+	}
+	return -ENOENT;
+}
+
+static void assert_preorder_query_flags(int cg, int atype,
+					__u32 id1, __u32 id2,
+					__u32 id3, __u32 id4)
+{
+	LIBBPF_OPTS(bpf_prog_query_opts, optq);
+	__u32 prog_attach_flags[10] = {};
+	__u32 prog_ids[10] = {};
+	__u32 flags;
+	int err;
+
+	optq.prog_ids = prog_ids;
+	optq.prog_attach_flags = prog_attach_flags;
+	optq.count = 10;
+	err = bpf_prog_query_opts(cg, atype, &optq);
+	if (!ASSERT_OK(err, "prog_query"))
+		return;
+
+	ASSERT_EQ(optq.count, 4, "count");
+
+	/* Match by prog_id to avoid relying on query order. */
+	err = find_prog_attach_flags(&optq, id1, &flags);
+	if (ASSERT_OK(err, "find id1"))
+		ASSERT_EQ(flags, BPF_F_ALLOW_MULTI, "flags id1");
+
+	err = find_prog_attach_flags(&optq, id2, &flags);
+	if (ASSERT_OK(err, "find id2"))
+		ASSERT_EQ(flags, BPF_F_ALLOW_MULTI | BPF_F_PREORDER,
+			  "flags id2");
+
+	err = find_prog_attach_flags(&optq, id3, &flags);
+	if (ASSERT_OK(err, "find id3"))
+		ASSERT_EQ(flags, BPF_F_ALLOW_MULTI | BPF_F_PREORDER,
+			  "flags id3");
+
+	err = find_prog_attach_flags(&optq, id4, &flags);
+	if (ASSERT_OK(err, "find id4"))
+		ASSERT_EQ(flags, BPF_F_ALLOW_MULTI, "flags id4");
+}
+
 static void test_preorder_prog_attach_detach(int atype)
 {
 	LIBBPF_OPTS(bpf_prog_attach_opts, opta);
 	LIBBPF_OPTS(bpf_prog_detach_opts, optd);
-	__u32 fd1, fd2, fd3, fd4;
+	__u32 fd1, fd2, fd3, fd4, id1, id2, id3, id4;
 	struct cgroup_mprog *skel;
 	int cg, err;
 
@@ -294,6 +347,11 @@ static void test_preorder_prog_attach_detach(int atype)
 	fd3 = bpf_program__fd(skel->progs.getsockopt_3);
 	fd4 = bpf_program__fd(skel->progs.getsockopt_4);
 
+	id1 = id_from_prog_fd(fd1);
+	id2 = id_from_prog_fd(fd2);
+	id3 = id_from_prog_fd(fd3);
+	id4 = id_from_prog_fd(fd4);
+
 	assert_mprog_count(cg, atype, 0);
 
 	LIBBPF_OPTS_RESET(opta,
@@ -357,6 +415,8 @@ static void test_preorder_prog_attach_detach(int atype)
 
 	assert_mprog_count(cg, atype, 4);
 
+	assert_preorder_query_flags(cg, atype, id1, id2, id3, id4);
+
 	err = bpf_prog_detach_opts(fd4, cg, atype, &optd);
 	ASSERT_OK(err, "prog_detach");
 	assert_mprog_count(cg, atype, 3);
@@ -386,7 +446,7 @@ static void test_preorder_link_attach_detach(int atype)
 	LIBBPF_OPTS(bpf_cgroup_opts, opta);
 	struct bpf_link *link1, *link2, *link3, *link4;
 	struct cgroup_mprog *skel;
-	__u32 fd2;
+	__u32 fd2, id1, id2, id3, id4;
 	int cg;
 
 	cg = test__join_cgroup("/preorder_link_attach_detach");
@@ -399,6 +459,11 @@ static void test_preorder_link_attach_detach(int atype)
 
 	fd2 = bpf_program__fd(skel->progs.getsockopt_2);
 
+	id1 = id_from_prog_fd(bpf_program__fd(skel->progs.getsockopt_1));
+	id2 = id_from_prog_fd(fd2);
+	id3 = id_from_prog_fd(bpf_program__fd(skel->progs.getsockopt_3));
+	id4 = id_from_prog_fd(bpf_program__fd(skel->progs.getsockopt_4));
+
 	assert_mprog_count(cg, atype, 0);
 
 	LIBBPF_OPTS_RESET(opta,
@@ -460,6 +525,8 @@ static void test_preorder_link_attach_detach(int atype)
 
 	assert_mprog_count(cg, atype, 4);
 
+	assert_preorder_query_flags(cg, atype, id1, id2, id3, id4);
+
 	bpf_link__destroy(link4);
 	assert_mprog_count(cg, atype, 3);
 
Signature · 1 line
2.55.0
author
#3 lore raw

PATCH v3 3/3 bpftool: Add support for BPF_F_PREORDER cgroup attach flag

In reply to Hui Su

Commit 4b82b181a26c ("bpf: Allow pre-ordering for bpf cgroup progs") introduced BPF_F_PREORDER to request pre-order execution across the cgroup hierarchy. Furthermore, attachments legitimately use combinations such as BPF_F_ALLOW_MULTI | BPF_F_PREORDER or BPF_F_ALLOW_OVERRIDE | BPF_F_PREORDER.

With BPF_PROG_QUERY reporting the per-program BPF_F_PREORDER attribute, bpftool's exact-match formatter falls back to "unknown(40)" when BPF_F_PREORDER is present alone, or "unknown(41)" / "unknown(42)" when combined with BPF_F_ALLOW_OVERRIDE or BPF_F_ALLOW_MULTI. Additionally, do_attach() only accepts "multi" and "override", rejecting "preorder" with "unknown option".

Before:

  $ bpftool cgroup show <cg>
  1234  cgroup_inet_ingress  unknown(42)  test_prog
  $ bpftool cgroup attach <cg> cgroup_inet_ingress id 5678 multi preorder
  Error: unknown option: preorder

After:

  $ bpftool cgroup show <cg>
  1234  cgroup_inet_ingress  multi,preorder  test_prog
  $ bpftool cgroup attach <cg> cgroup_inet_ingress id 5678 multi preorder
  (attaches successfully)

Refactor the attach flags formatter into a bitmask formatter that outputs comma-separated flag names for plain text while preserving unrecognized bits as "unknown(...)". Render attach flags as an array of flag names in JSON output. Accept "preorder" in do_attach(), update the cgroup documentation and synopsis to express valid flag combinations, and teach bash completion about them ("multi" or "override" optionally combined with "preorder").

---

Notes (bpf-preorder-v3-20260922-check):
Testing:
- PASS: make -C tools/bpf/bpftool -j12 (fresh after rebase).
- PASS: make -C tools/bpf/bpftool/Documentation -j12 (fresh after rebase).
- PASS: bash -n tools/bpf/bpftool/bash-completion/bpftool (fresh after rebase).
- PASS: bpftool cgroup plain-text and JSON runtime smoke (x86_64 QEMU/KVM); result reused after a content-equivalent rebase.
- PASS: scripts/checkpatch.pl on the generated v3 patches.

 .../bpftool/Documentation/bpftool-cgroup.rst  | 25 +++--
 tools/bpf/bpftool/bash-completion/bpftool     |  4 +-
 tools/bpf/bpftool/cgroup.c                    | 99 +++++++++++++------
 3 files changed, 89 insertions(+), 39 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-cgroup.rst +16 -9
index e8185596a759..d1b8193dc576 100644
@@ -45,7 +45,7 @@ CGROUP COMMANDS
 |     **cgroup_unix_recvmsg** | **cgroup_sysctl** |
 |     **cgroup_getsockopt** | **cgroup_setsockopt** |
 |     **cgroup_inet_sock_release** }
-| *ATTACH_FLAGS* := { **multi** | **override** }
+| *ATTACH_FLAGS* := { [ **multi** | **override** ] [ **preorder** ] }
 
 DESCRIPTION
 ===========
@@ -75,20 +75,27 @@ bpftool cgroup attach *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
     Attach program *PROG* to the cgroup *CGROUP* with attach type *ATTACH_TYPE*
     and optional *ATTACH_FLAGS*.
 
-    *ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs some
+    *ATTACH_FLAGS* can include: **override** if a sub-cgroup installs some
     bpf program, the program in this cgroup yields to sub-cgroup program;
     **multi** if a sub-cgroup installs some bpf program, that cgroup program
-    gets run in addition to the program in this cgroup.
+    gets run in addition to the program in this cgroup;
+    **preorder** requests ancestor-to-descendant execution for this program,
+    before non-preorder programs, which execute descendants-to-ancestors
+    across the cgroup hierarchy. Note that **preorder** alone does not enable
+    multi-program attachment; specify **multi** together with **preorder** to
+    attach multiple programs.
 
-    Only one program is allowed to be attached to a cgroup with no attach flags
-    or the **override** flag. Attaching another program will release old
-    program and attach the new one.
+    Only one program is allowed to be attached to a cgroup unless the
+    **multi** flag is specified. Without **multi**, attaching another program
+    replaces the existing program, provided the **override** setting matches.
 
     Multiple programs are allowed to be attached to a cgroup with **multi**.
-    They are executed in FIFO order (those that were attached first, run
-    first).
+    Programs marked with **preorder** are placed before non-preorder programs
+    in the effective program array. Within each ordering class at the same
+    cgroup level, attachment order is preserved.
 
-    Non-default *ATTACH_FLAGS* are supported by kernel version 4.14 and later.
+    **multi** and **override** are supported by kernel version 4.14 and later.
+    **preorder** was introduced upstream in Linux 6.15.
 
     *ATTACH_TYPE* can be one of:
 
tools/bpf/bpftool/bash-completion/bpftool +2 -2
index c9e8761e4ef2..9d9ced270685 100644
@@ -1064,7 +1064,6 @@ _bpftool()
                 attach|detach)
                     local BPFTOOL_CGROUP_ATTACH_TYPES="$(bpftool feature list_builtins attach_types 2>/dev/null | \
                         grep '^cgroup_')"
-                    local ATTACH_FLAGS='multi override'
                     # Check for $prev = $command first
                     if [ $prev = $command ]; then
                         _filedir
@@ -1094,7 +1093,8 @@ _bpftool()
                                 # "id|pinned|tag|name" (we already checked for
                                 # that). This should only leave the case when
                                 # we need attach flags for "attach" commamnd.
-                                _bpftool_one_of_list "$ATTACH_FLAGS"
+                                _bpftool_one_of_list 'multi override'
+                                _bpftool_once_attr 'preorder'
                             fi
                             return 0
                             ;;
tools/bpf/bpftool/cgroup.c +71 -28

163 lines not on this page · raw message

Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH bpf-next v3 3/3] bpftool: Add support for BPF_F_PREORDER cgroup attach flag

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] bpf: bpftool JSON ABI breakage for attach_flags field --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] bpf: bpftool JSON ABI breakage for attach_flags field
--

commit 7ba7f84eaca8177e2045dffce655aae4da559465
Author: Hui Su <[email protected]>

bpftool: Add support for BPF_F_PREORDER cgroup attach flag

This commit adds support for the BPF_F_PREORDER cgroup attach flag to bpftool. It updates attach operations to accept the new flag and modifies the show operations to output combinations of attach flags, rather than just a single flag.

Quoted 4 lines
tools/bpf/bpftool/cgroup.c +0 -0
index ce69d1e5468e3..fee1a260f6d1a 100644

[ ... ]

Quoted 23 lines
tools/bpf/bpftool/cgroup.c +23 -0
+static void show_attach_flags_json(__u32 flags)
+{
+	char buf[32];
+	size_t i;
+
+	jsonw_name(json_wtr, "attach_flags");
+	jsonw_start_array(json_wtr);
+
+	for (i = 0; i < ARRAY_SIZE(attach_flag_names); i++) {
+		if (!(flags & attach_flag_names[i].flag))
+			continue;
+
+		jsonw_string(json_wtr, attach_flag_names[i].name);
+		flags &= ~attach_flag_names[i].flag;
+	}
+
+	if (flags) {
+		snprintf(buf, sizeof(buf), "unknown(%x)", flags);
+		jsonw_string(json_wtr, buf);
+	}
+
+	jsonw_end_array(json_wtr);
+}

[ ... ]

tools/bpf/bpftool/cgroup.c static int show_bpf_prog(int id, enum bpf_attach_type attach_type, · line 243

Quoted 6 lines
tools/bpf/bpftool/cgroup.c +1 -1
@@ -182,7 +240,7 @@ static int show_bpf_prog(int id, enum bpf_attach_type attach_type,
 		else
 			jsonw_uint_field(json_wtr, "attach_type", attach_type);
 		if (!(query_flags & BPF_F_QUERY_EFFECTIVE))
-			jsonw_string_field(json_wtr, "attach_flags", attach_flags_str);
+			show_attach_flags_json(attach_flags);

[Severity: Medium]
Does this change break bpftool's JSON ABI by changing the attach_flags field from a string to an array?

Previously, this field was output as a single string. Changing the data type to an array could cause external scripts or applications using strict JSON parsers to crash or fail to unmarshal the output when running bpftool cgroup show -j.

Would it be safer to format the multiple flags as a single comma-separated string in the JSON output, similar to what is done for the plain-text output, to maintain backwards compatibility?

Quoted 3 lines
tools/bpf/bpftool/cgroup.c +0 -0
 		jsonw_string_field(json_wtr, "name", prog_name);
 		if (attach_btf_name)
 			jsonw_string_field(json_wtr, "attach_btf_name", attach_btf_name);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer
#5 lore raw

Re: [PATCH bpf-next v3 3/3] bpftool: Add support for BPF_F_PREORDER cgroup attach flag

2026-09-22 03:01 UTC+0000 ~ [email protected]

Quoted 47 lines

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] bpf: bpftool JSON ABI breakage for attach_flags field
--

commit 7ba7f84eaca8177e2045dffce655aae4da559465
Author: Hui Su <[email protected]>

bpftool: Add support for BPF_F_PREORDER cgroup attach flag

This commit adds support for the BPF_F_PREORDER cgroup attach flag to bpftool. It updates attach operations to accept the new flag and modifies the show operations to output combinations of attach flags, rather than just a single flag.

Quoted 4 lines
tools/bpf/bpftool/cgroup.c +0 -0
index ce69d1e5468e3..fee1a260f6d1a 100644

[ ... ]

Quoted 23 lines
tools/bpf/bpftool/cgroup.c +23 -0
+static void show_attach_flags_json(__u32 flags)
+{
+	char buf[32];
+	size_t i;
+
+	jsonw_name(json_wtr, "attach_flags");
+	jsonw_start_array(json_wtr);
+
+	for (i = 0; i < ARRAY_SIZE(attach_flag_names); i++) {
+		if (!(flags & attach_flag_names[i].flag))
+			continue;
+
+		jsonw_string(json_wtr, attach_flag_names[i].name);
+		flags &= ~attach_flag_names[i].flag;
+	}
+
+	if (flags) {
+		snprintf(buf, sizeof(buf), "unknown(%x)", flags);
+		jsonw_string(json_wtr, buf);
+	}
+
+	jsonw_end_array(json_wtr);
+}

[ ... ]

Quoted 10 lines

tools/bpf/bpftool/cgroup.c static int show_bpf_prog(int id, enum bpf_attach_type attach_type, · line 243

Quoted 6 lines
tools/bpf/bpftool/cgroup.c +1 -1
@@ -182,7 +240,7 @@ static int show_bpf_prog(int id, enum bpf_attach_type attach_type,
 		else
 			jsonw_uint_field(json_wtr, "attach_type", attach_type);
 		if (!(query_flags & BPF_F_QUERY_EFFECTIVE))
-			jsonw_string_field(json_wtr, "attach_flags", attach_flags_str);
+			show_attach_flags_json(attach_flags);

[Severity: Medium]
Does this change break bpftool's JSON ABI by changing the attach_flags field from a string to an array?

It does. I suggested it, given that appending ",preorder" to the flag may break parsing anyway, so we may just as well take this chance to use the right JSON format for these flags. I'm fine taking in that change, and documenting it in the next release notes on GitHub. Alexei may disagree, though, so let's see.

Quentin

Quoted 13 lines

Previously, this field was output as a single string. Changing the data type to an array could cause external scripts or applications using strict JSON parsers to crash or fail to unmarshal the output when running bpftool cgroup show -j.

Would it be safer to format the multiple flags as a single comma-separated string in the JSON output, similar to what is done for the plain-text output, to maintain backwards compatibility?

Quoted 3 lines
tools/bpf/bpftool/cgroup.c +0 -0
 		jsonw_string_field(json_wtr, "name", prog_name);
 		if (attach_btf_name)
 			jsonw_string_field(json_wtr, "attach_btf_name", attach_btf_name);
maintainer Acked-by on v3 3/3
#6 lore raw

Re: [PATCH bpf-next v3 3/3] bpftool: Add support for BPF_F_PREORDER cgroup attach flag

In reply to Hui Su

2026-09-22 11:54 UTC+0900 ~ Hui Su <[email protected]>

Quoted 33 lines

Commit 4b82b181a26c ("bpf: Allow pre-ordering for bpf cgroup progs") introduced BPF_F_PREORDER to request pre-order execution across the cgroup hierarchy. Furthermore, attachments legitimately use combinations such as BPF_F_ALLOW_MULTI | BPF_F_PREORDER or BPF_F_ALLOW_OVERRIDE | BPF_F_PREORDER.

With BPF_PROG_QUERY reporting the per-program BPF_F_PREORDER attribute, bpftool's exact-match formatter falls back to "unknown(40)" when BPF_F_PREORDER is present alone, or "unknown(41)" / "unknown(42)" when combined with BPF_F_ALLOW_OVERRIDE or BPF_F_ALLOW_MULTI. Additionally, do_attach() only accepts "multi" and "override", rejecting "preorder" with "unknown option".

Before:

  $ bpftool cgroup show <cg>
  1234  cgroup_inet_ingress  unknown(42)  test_prog
  $ bpftool cgroup attach <cg> cgroup_inet_ingress id 5678 multi preorder
  Error: unknown option: preorder

After:

  $ bpftool cgroup show <cg>
  1234  cgroup_inet_ingress  multi,preorder  test_prog
  $ bpftool cgroup attach <cg> cgroup_inet_ingress id 5678 multi preorder
  (attaches successfully)

Refactor the attach flags formatter into a bitmask formatter that outputs comma-separated flag names for plain text while preserving unrecognized bits as "unknown(...)". Render attach flags as an array of flag names in JSON output. Accept "preorder" in do_attach(), update the cgroup documentation and synopsis to express valid flag combinations, and teach bash completion about them ("multi" or "override" optionally combined with "preorder").

Quoted 1 line

Thank you

#7 lore raw
In reply to Hui Su
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Tue, 22 Sep 2026 11:54:39 +0900 you wrote:

The BPF_F_PREORDER attach flag changes the ordering of programs in the effective cgroup program array, but BPF_PROG_QUERY did not report the per-program flag. This series exposes that state and updates bpftool to display, accept, and document this flag.

The series is split into three patches:

[...]

Here is the summary with links:
- [bpf-next,v3,1/3] bpf: Report BPF_F_PREORDER in cgroup program queries

    https://git.kernel.org/bpf/bpf-next/c/9ed640ee09ab
  - [bpf-next,v3,2/3] selftests/bpf: Test querying BPF_F_PREORDER cgroup attachments
    https://git.kernel.org/bpf/bpf-next/c/47211d1200f0
  - [bpf-next,v3,3/3] bpftool: Add support for BPF_F_PREORDER cgroup attach flag
    https://git.kernel.org/bpf/bpf-next/c/c39bf6b6705f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html