From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>, Tejun Heo <tj@kernel.org>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v1 4/6] libbpf: Add bpf_prog_stream_open()
Date: Sun, 30 Aug 2026 11:35:09 +0200 [thread overview]
Message-ID: <20260830093514.4105972-5-memxor@gmail.com> (raw)
In-Reply-To: <20260830093514.4105972-1-memxor@gmail.com>
Expose the BPF_PROG_STREAM_OPEN command through a low-level libbpf wrapper.
The options structure carries stream open flags, including non-blocking
mode, while leaving room for future extensions.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
tools/lib/bpf/bpf.c | 19 +++++++++++++++++++
tools/lib/bpf/bpf.h | 24 ++++++++++++++++++++++++
tools/lib/bpf/libbpf.map | 1 +
3 files changed, 44 insertions(+)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 96819c082c77..5186f6245879 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -1464,6 +1464,25 @@ int bpf_prog_stream_read(int prog_fd, __u32 stream_id, void *buf, __u32 buf_len,
return libbpf_err_errno(err);
}
+int bpf_prog_stream_open(int prog_fd, __u32 stream_id,
+ const struct bpf_prog_stream_open_opts *opts)
+{
+ const size_t attr_sz = offsetofend(union bpf_attr, prog_stream_open);
+ union bpf_attr attr;
+ int fd;
+
+ if (!OPTS_VALID(opts, bpf_prog_stream_open_opts))
+ return libbpf_err(-EINVAL);
+
+ memset(&attr, 0, attr_sz);
+ attr.prog_stream_open.prog_fd = prog_fd;
+ attr.prog_stream_open.stream_id = stream_id;
+ attr.prog_stream_open.flags = OPTS_GET(opts, flags, 0);
+
+ fd = sys_bpf_fd(BPF_PROG_STREAM_OPEN, &attr, attr_sz);
+ return libbpf_err_errno(fd);
+}
+
int bpf_prog_assoc_struct_ops(int prog_fd, int map_fd,
struct bpf_prog_assoc_struct_ops_opts *opts)
{
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 7534a593edae..860c5644ec1e 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -758,10 +758,34 @@ struct bpf_prog_stream_read_opts {
*
* @return The number of bytes read, on success; negative error code, otherwise
* (errno is also set to the error code)
+ *
+ * For blocking reads and polling, prefer **bpf_prog_stream_open**.
*/
LIBBPF_API int bpf_prog_stream_read(int prog_fd, __u32 stream_id, void *buf, __u32 buf_len,
struct bpf_prog_stream_read_opts *opts);
+struct bpf_prog_stream_open_opts {
+ size_t sz;
+ __u32 flags;
+ size_t :0;
+};
+#define bpf_prog_stream_open_opts__last_field flags
+
+/**
+ * @brief **bpf_prog_stream_open** opens a file descriptor for a BPF stream of
+ * a given BPF program.
+ *
+ * @param prog_fd FD for the BPF program whose BPF stream is to be opened.
+ * @param stream_id ID of the BPF stream to be opened.
+ * @param opts optional options, can be NULL. BPF_F_STREAM_NONBLOCK requests a
+ * non-blocking descriptor.
+ *
+ * @return A new stream FD, on success; negative error code, otherwise (errno
+ * is also set to the error code)
+ */
+LIBBPF_API int bpf_prog_stream_open(int prog_fd, __u32 stream_id,
+ const struct bpf_prog_stream_open_opts *opts);
+
struct bpf_prog_assoc_struct_ops_opts {
size_t sz;
__u32 flags;
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 08ab2ea881fb..a89e10811a73 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -458,6 +458,7 @@ LIBBPF_1.7.0 {
LIBBPF_1.8.0 {
global:
+ bpf_prog_stream_open;
bpf_program__attach_tracing_multi;
bpf_program__clone;
btf__find_by_name_kind_own;
--
2.53.0
next prev parent reply other threads:[~2026-08-30 9:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 9:35 [PATCH bpf-next v1 0/6] File descriptor interface for BPF streams Kumar Kartikeya Dwivedi
2026-08-30 9:35 ` [PATCH bpf-next v1 1/6] bpf: Add file descriptor interface for program streams Kumar Kartikeya Dwivedi
2026-08-30 9:47 ` sashiko-bot
2026-08-30 10:47 ` bot+bpf-ci
2026-09-08 18:19 ` Emil Tsalapatis
2026-08-30 9:35 ` [PATCH bpf-next v1 2/6] bpf: Defer stream file notifications from NMI context Kumar Kartikeya Dwivedi
2026-09-08 18:25 ` Emil Tsalapatis
2026-08-30 9:35 ` [PATCH bpf-next v1 3/6] bpf: Separate stream readiness from capacity accounting Kumar Kartikeya Dwivedi
2026-08-30 9:45 ` sashiko-bot
2026-08-30 10:35 ` bot+bpf-ci
2026-09-08 18:47 ` Emil Tsalapatis
2026-08-30 9:35 ` Kumar Kartikeya Dwivedi [this message]
2026-09-08 18:48 ` [PATCH bpf-next v1 4/6] libbpf: Add bpf_prog_stream_open() Emil Tsalapatis
2026-08-30 9:35 ` [PATCH bpf-next v1 5/6] bpftool: Read program streams through file descriptors Kumar Kartikeya Dwivedi
2026-08-30 10:35 ` bot+bpf-ci
2026-09-08 19:22 ` Emil Tsalapatis
2026-08-30 9:35 ` [PATCH bpf-next v1 6/6] selftests/bpf: Test program stream " Kumar Kartikeya Dwivedi
2026-09-08 19:22 ` Emil Tsalapatis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260830093514.4105972-5-memxor@gmail.com \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.