All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	alexei.starovoitov@gmail.com, martin.lau@kernel.org,
	sinquersw@gmail.com, davemarchevsky@fb.com,
	Amery Hung <amery.hung@bytedance.com>
Subject: Re: [PATCH v1 bpf-next 0/4] Support bpf_kptr_xchg into local kptr
Date: Wed, 31 Jul 2024 17:11:10 -0700	[thread overview]
Message-ID: <945a08e5-08fe-4906-a7df-ff4886ec99c0@linux.dev> (raw)
In-Reply-To: <20240728030115.3970543-1-amery.hung@bytedance.com>

On 7/27/24 8:01 PM, Amery Hung wrote:
> This series allows stashing kptr into local kptr. Currently, kptrs are
> only allowed to be stashed into map value with bpf_kptr_xchg(). A
> motivating use case of this series is to enable adding referenced kptr to
> bpf_rbtree or bpf_list by using allocated object as graph node and the
> storage of referenced kptr. For example, a bpf qdisc [0] enqueuing a
> referenced kptr to a struct sk_buff* to a bpf_list serving as a fifo:
> 
>      struct skb_node {
>              struct sk_buff __kptr *skb;
>              struct bpf_list_node node;
>      };
> 
>      private(A) struct bpf_spin_lock fifo_lock;
>      private(A) struct bpf_list_head fifo __contains(skb_node, node);
> 
>      /* In Qdisc_ops.enqueue */
>      struct skb_node *skbn;
> 
>      skbn = bpf_obj_new(typeof(*skbn));
>      if (!skbn)
>          goto drop;
> 
>      /* skb is a referenced kptr to struct sk_buff acquired earilier
>       * but not shown in this code snippet.
>       */
>      skb = bpf_kptr_xchg(&skbn->skb, skb);
>      if (skb)
>          /* should not happen; do something below releasing skb to
>           * satisfy the verifier */
>      	...
>      
>      bpf_spin_lock(&fifo_lock);
>      bpf_list_push_back(&fifo, &skbn->node);
>      bpf_spin_unlock(&fifo_lock);
> 
> The implementation first searches for BPF_KPTR when generating program
> BTF. Then, we teach the verifier that the detination argument of
> bpf_kptr_xchg() can be local kptr, and use the btf_record in program BTF
> to check against the source argument.
> 
> This series is mostly developed by Dave, who kindly helped and sent me
> the patchset. The selftests in bpf qdisc (WIP) relies on this series to
> work.

The set lgtm. With the doc fix in the bpf_kptr_xchg, you can carry my Ack.

Acked-by: Martin KaFai Lau <martin.lau@kernel.org>


      parent reply	other threads:[~2024-08-01  0:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-28  3:01 [PATCH v1 bpf-next 0/4] Support bpf_kptr_xchg into local kptr Amery Hung
2024-07-28  3:01 ` [PATCH v1 bpf-next 1/4] bpf: Search for kptrs in prog BTF structs Amery Hung
2024-07-28  3:01 ` [PATCH v1 bpf-next 2/4] bpf: Rename ARG_PTR_TO_KPTR -> ARG_KPTR_XCHG_DEST Amery Hung
2024-07-28  3:01 ` [PATCH v1 bpf-next 3/4] bpf: Support bpf_kptr_xchg into local kptr Amery Hung
2024-07-31 23:38   ` Martin KaFai Lau
2024-08-01  4:07     ` Amery Hung
2024-07-28  3:01 ` [PATCH v1 bpf-next 4/4] selftests/bpf: Test bpf_kptr_xchg stashing " Amery Hung
2024-08-01  0:11 ` Martin KaFai Lau [this message]

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=945a08e5-08fe-4906-a7df-ff4886ec99c0@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=alexei.starovoitov@gmail.com \
    --cc=amery.hung@bytedance.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=sinquersw@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.