From: Joanne Koong <joannelkoong@gmail.com>
To: bpf@vger.kernel.org
Cc: martin.lau@kernel.org, andrii@kernel.org, memxor@gmail.com,
ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org,
kernel-team@fb.com, Joanne Koong <joannelkoong@gmail.com>
Subject: [PATCH v10 bpf-next 1/9] bpf: Support "sk_buff" and "xdp_buff" as valid kfunc arg types
Date: Thu, 16 Feb 2023 14:55:16 -0800 [thread overview]
Message-ID: <20230216225524.1192789-2-joannelkoong@gmail.com> (raw)
In-Reply-To: <20230216225524.1192789-1-joannelkoong@gmail.com>
The bpf mirror of the in-kernel sk_buff and xdp_buff data structures are
__sk_buff and xdp_md. Currently, when we pass in the program ctx to a
kfunc where the program ctx is a skb or xdp buffer, we reject the
program if the in-kernel definition is sk_buff/xdp_buff instead of
__sk_buff/xdp_md.
This change allows "sk_buff <--> __sk_buff" and "xdp_buff <--> xdp_md"
to be recognized as valid matches. The user program may pass in their
program ctx as a __sk_buff or xdp_md, and the in-kernel definition
of the kfunc may define this arg as a sk_buff or xdp_buff.
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
kernel/bpf/btf.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 6582735ef1fc..ae321c358699 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -5675,6 +5675,10 @@ btf_get_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *btf,
bpf_log(log, "Please fix kernel include/linux/bpf_types.h\n");
return NULL;
}
+ if (strcmp(ctx_tname, "__sk_buff") == 0 && strcmp(tname, "sk_buff") == 0)
+ return ctx_type;
+ if (strcmp(ctx_tname, "xdp_md") == 0 && strcmp(tname, "xdp_buff") == 0)
+ return ctx_type;
/* only compare that prog's ctx type name is the same as
* kernel expects. No need to compare field by field.
* It's ok for bpf prog to do:
--
2.30.2
next prev parent reply other threads:[~2023-02-16 22:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 22:55 [PATCH v10 bpf-next 0/9] Add skb + xdp dynptrs Joanne Koong
2023-02-16 22:55 ` Joanne Koong [this message]
2023-02-16 22:55 ` [PATCH v10 bpf-next 2/9] bpf: Refactor process_dynptr_func Joanne Koong
2023-02-16 22:55 ` [PATCH v10 bpf-next 3/9] bpf: Allow initializing dynptrs in kfuncs Joanne Koong
2023-02-16 22:55 ` [PATCH v10 bpf-next 4/9] bpf: Define no-ops for externally called bpf dynptr functions Joanne Koong
2023-02-16 22:55 ` [PATCH v10 bpf-next 5/9] bpf: Refactor verifier dynptr into get_dynptr_arg_reg Joanne Koong
2023-02-16 22:55 ` [PATCH v10 bpf-next 6/9] bpf: Add skb dynptrs Joanne Koong
2023-02-18 0:55 ` Andrii Nakryiko
2023-02-16 22:55 ` [PATCH v10 bpf-next 7/9] bpf: Add xdp dynptrs Joanne Koong
2023-02-16 22:55 ` [PATCH v10 bpf-next 8/9] bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr Joanne Koong
2023-02-17 23:00 ` Joanne Koong
2023-02-20 0:26 ` Alexei Starovoitov
2023-02-16 22:55 ` [PATCH v10 bpf-next 9/9] selftests/bpf: tests for using dynptrs to parse skb and xdp buffers Joanne Koong
2023-02-17 13:05 ` Toke Høiland-Jørgensen
2023-02-17 18:14 ` Joanne Koong
2023-02-18 1:03 ` [PATCH v10 bpf-next 0/9] Add skb + xdp dynptrs Andrii Nakryiko
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=20230216225524.1192789-2-joannelkoong@gmail.com \
--to=joannelkoong@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=netdev@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).