All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf@vger.kernel.org,  Alexei Starovoitov <ast@kernel.org>,
	 Andrii Nakryiko <andrii@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	 Emil Tsalapatis <emil@etsalapatis.com>,
	 Barret Rhoden <brho@google.com>,
	 Matt Bobrowski <mattbobrowski@google.com>,
	 kkd@meta.com,  kernel-team@meta.com
Subject: Re: [PATCH bpf-next v2 01/11] bpf: Introduce BPF standard streams
Date: Tue, 27 May 2025 16:47:18 -0700	[thread overview]
Message-ID: <m2cybt62gp.fsf@gmail.com> (raw)
In-Reply-To: <20250524011849.681425-2-memxor@gmail.com> (Kumar Kartikeya Dwivedi's message of "Fri, 23 May 2025 18:18:39 -0700")

Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:

Overall logic seems right to me, a few comments below.

[...]

> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 5b25d278409b..d298746f4dcc 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1538,6 +1538,41 @@ struct btf_mod_pair {
>  
>  struct bpf_kfunc_desc_tab;
>  
> +enum bpf_stream_id {
> +	BPF_STDOUT = 1,
> +	BPF_STDERR = 2,
> +};
> +
> +struct bpf_stream_elem {
> +	struct llist_node node;
> +	int total_len;
> +	int consumed_len;
> +	char str[];
> +};
> +
> +struct bpf_stream_elem_batch {
> +	struct llist_node *node;
> +};

This type is not used anymore.

> +
> +enum {
> +	BPF_STREAM_MAX_CAPACITY = (4 * 1024U * 1024U),
> +};
> +
> +struct bpf_stream {
> +	enum bpf_stream_id stream_id;

Nit: `stream_id` is never read, as streams are identified by a position
     in the bpf_prog_aux->stream.

> +	atomic_t capacity;
> +	struct llist_head log;
> +
> +	rqspinlock_t lock;
> +	struct llist_node *backlog_head;
> +	struct llist_node *backlog_tail;

Nit: maybe add comments describing what kind of data is in the llist_{head,node}? E.g.:

	atomic_t capacity;
	struct llist_head log;		 /* list of struct bpf_stream_elem in LIFO order */

	rqspinlock_t lock;		 /* backlog_{head,tail} lock */
	struct llist_node *backlog_head; /* list of struct bpf_stream_elem in FIFO order */
	struct llist_node *backlog_tail;


> +};
> +
> +struct bpf_stream_stage {
> +	struct llist_head log;
> +	int len;
> +};
> +

[...]

> diff --git a/kernel/bpf/stream.c b/kernel/bpf/stream.c
> new file mode 100644
> index 000000000000..b9e6f7a43b1b
> --- /dev/null
> +++ b/kernel/bpf/stream.c

[...]

> +int bpf_stream_stage_commit(struct bpf_stream_stage *ss, struct bpf_prog *prog,
> +			    enum bpf_stream_id stream_id)
> +{
> +	struct llist_node *list, *head, *tail;
> +	struct bpf_stream *stream;
> +	int ret;
> +
> +	stream = bpf_stream_get(stream_id, prog->aux);
> +	if (!stream)
> +		return -EINVAL;
> +
> +	ret = bpf_stream_consume_capacity(stream, ss->len);
> +	if (ret)
> +		return ret;
> +
> +	list = llist_del_all(&ss->log);
> +	head = list;
> +
> +	if (!list)
> +		return 0;
> +	while (llist_next(list)) {
> +		tail = llist_next(list);
> +		list = tail;
> +	}
> +	llist_add_batch(head, tail, &stream->log);

If `llist_next(list) == NULL` at entry `tail` is never assigned?

> +	return 0;
> +}

[...]

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index d5807d2efc92..5ab8742d2c00 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -13882,10 +13882,9 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>  			regs[BPF_REG_0].type = PTR_TO_BTF_ID;
>  			regs[BPF_REG_0].btf_id = ptr_type_id;
>  
> -			if (meta.func_id == special_kfunc_list[KF_bpf_get_kmem_cache])
> +			if (meta.func_id == special_kfunc_list[KF_bpf_get_kmem_cache]) {
>  				regs[BPF_REG_0].type |= PTR_UNTRUSTED;
> -
> -			if (is_iter_next_kfunc(&meta)) {
> +			} else if (is_iter_next_kfunc(&meta)) {

Nit: unrelated change?

>  				struct bpf_reg_state *cur_iter;
>  
>  				cur_iter = get_iter_from_state(env->cur_state, &meta);

[...]

  reply	other threads:[~2025-05-27 23:47 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-24  1:18 [PATCH bpf-next v2 00/11] BPF Standard Streams Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 01/11] bpf: Introduce BPF standard streams Kumar Kartikeya Dwivedi
2025-05-27 23:47   ` Eduard Zingerman [this message]
2025-05-27 23:55     ` Kumar Kartikeya Dwivedi
2025-05-28  0:23       ` Eduard Zingerman
2025-05-28  0:30         ` Kumar Kartikeya Dwivedi
2025-06-02 20:07   ` Alexei Starovoitov
2025-06-02 20:31     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 02/11] bpf: Add function to extract program source info Kumar Kartikeya Dwivedi
2025-06-02 20:18   ` Alexei Starovoitov
2025-06-02 20:21     ` Kumar Kartikeya Dwivedi
2025-06-02 20:25       ` Alexei Starovoitov
2025-06-02 20:31         ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 03/11] bpf: Add function to find program from stack trace Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 04/11] bpf: Hold RCU read lock in bpf_prog_ksym_find Kumar Kartikeya Dwivedi
2025-05-24  4:41   ` Kumar Kartikeya Dwivedi
2025-05-28  0:15     ` Eduard Zingerman
2025-05-28  0:27       ` Kumar Kartikeya Dwivedi
2025-05-28  0:33         ` Eduard Zingerman
2025-05-24  1:18 ` [PATCH bpf-next v2 05/11] bpf: Add dump_stack() analogue to print to BPF stderr Kumar Kartikeya Dwivedi
2025-05-28  0:45   ` Eduard Zingerman
2025-05-28  0:58     ` Kumar Kartikeya Dwivedi
2025-05-28  6:03       ` Eduard Zingerman
2025-05-24  1:18 ` [PATCH bpf-next v2 06/11] bpf: Report may_goto timeout " Kumar Kartikeya Dwivedi
2025-06-02 22:27   ` Alexei Starovoitov
2025-06-03  1:55     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 07/11] bpf: Report rqspinlock deadlocks/timeout " Kumar Kartikeya Dwivedi
2025-06-02 22:32   ` Alexei Starovoitov
2025-06-03  2:06     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 08/11] libbpf: Add bpf_stream_printk() macro Kumar Kartikeya Dwivedi
2025-05-28  6:12   ` Eduard Zingerman
2025-05-28 10:09     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 09/11] libbpf: Introduce bpf_prog_stream_read() API Kumar Kartikeya Dwivedi
2025-05-28 18:02   ` Eduard Zingerman
2025-05-29 15:36     ` Kumar Kartikeya Dwivedi
2025-06-05 20:06   ` Andrii Nakryiko
2025-05-24  1:18 ` [PATCH bpf-next v2 10/11] bpftool: Add support for dumping streams Kumar Kartikeya Dwivedi
2025-05-27 10:20   ` Quentin Monnet
2025-05-27 14:51     ` Kumar Kartikeya Dwivedi
2025-05-24  1:18 ` [PATCH bpf-next v2 11/11] selftests/bpf: Add tests for prog streams Kumar Kartikeya Dwivedi
2025-05-28 17:04   ` Eduard Zingerman
2025-05-29 14:57     ` Kumar Kartikeya Dwivedi
2025-05-29 16:28       ` Eduard Zingerman

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=m2cybt62gp.fsf@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brho@google.com \
    --cc=daniel@iogearbox.net \
    --cc=emil@etsalapatis.com \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=mattbobrowski@google.com \
    --cc=memxor@gmail.com \
    /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.