From: Martin KaFai Lau <martin.lau@linux.dev>
To: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Cc: Amery Hung <amery.hung@bytedance.com>,
bpf@vger.kernel.org, magnus.karlsson@intel.com,
sreedevi.joshi@intel.com, ast@kernel.org
Subject: Re: [External] Storing sk_buffs as kptrs in map
Date: Wed, 27 Nov 2024 12:54:41 -0800 [thread overview]
Message-ID: <d1e95498-4613-43e0-bc6b-6f6157802649@linux.dev> (raw)
In-Reply-To: <Z0dt/wZZhigcgGPI@boxer>
On 11/27/24 11:07 AM, Maciej Fijalkowski wrote:
> But kfunc does not work on PTR_TO_CTX - it takes in directly sk_buff, not
> __sk_buff. As I mention above we use bpf_cast_to_kern_ctx() and per my
> current limited understanding it overwrites the reg->type to
> PTR_TO_BTF_ID | PTR_TRUSTED.
Can you try skip calling the bpf_cast_to_kern_ctx and directly pass the "struct
__sk_buff *skb" to the "struct sk_buff *bpf_skb_acquire(struct __sk_buff *skb).
> I tried to simplify the use case that customer has, but I am a bit worried
> that it might only confuse people more :/ however, here it is:
No. not at all. I suspect the use case has some similarity to the net-timestamp
patches
(https://lore.kernel.org/bpf/20241028110535.82999-1-kerneljasonxing@gmail.com/)
which uses a skb tskey to associate/co-relate different timestamp.
Please share the patch and the test case. It will be easier for others to help.
> On TC egress hook skb is stored in a map - reason for picking it over the
> linked list or rbtree is that we want to be able to access skbs via some index,
> say a hash. This is where we bump the skb's refcount via acquire kfunc.
>
> During TC ingress hook on the same interface, the skb that was previously
> stored in map is retrieved, current skb that resides in the context of
> hook carries the timestamp via metadata. We then use the retrieved skb and
> tstamp from metadata on skb_tstamp_tx() (another kfunc) and finally
> decrement skb's refcount via release kfunc.
>
>
> Anyways, since we are able to do similar operations on task_struct
> (holding it in map via kptr), I don't see a reason why wouldn't we allow
> ourselves to do it on sk_buffs, no?
skb holds other things like dev and dst, like someone may be trying to remove
the netdevice and route...etc. Overall, yes, the skb refcnt will eventually be
decremented when the map is freed like other kptr (e.g. task) do.
next prev parent reply other threads:[~2024-11-27 20:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-26 17:05 Storing sk_buffs as kptrs in map Maciej Fijalkowski
2024-11-26 19:56 ` [External] " Amery Hung
2024-11-26 20:47 ` Martin KaFai Lau
2024-11-27 19:07 ` Maciej Fijalkowski
2024-11-27 20:54 ` Martin KaFai Lau [this message]
2024-12-03 20:46 ` Maciej Fijalkowski
2024-12-04 23:24 ` Martin KaFai Lau
2024-12-06 16:24 ` Maciej Fijalkowski
2024-12-07 0:36 ` Martin KaFai Lau
2024-12-09 13:17 ` Maciej Fijalkowski
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=d1e95498-4613-43e0-bc6b-6f6157802649@linux.dev \
--to=martin.lau@linux.dev \
--cc=amery.hung@bytedance.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=sreedevi.joshi@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox