From: Kumar Kartikeya Dwivedi <memxor@gmail•com>
To: bpf@vger•kernel.org
Cc: "Kumar Kartikeya Dwivedi" <memxor@gmail•com>,
"Toke Høiland-Jørgensen" <toke@redhat•com>,
"Alexei Starovoitov" <ast@kernel•org>,
"Daniel Borkmann" <daniel@iogearbox•net>,
"Andrii Nakryiko" <andrii@kernel•org>,
"Jamal Hadi Salim" <jhs@mojatatu•com>,
"Vlad Buslov" <vladbu@nvidia•com>,
"Cong Wang" <xiyou.wangcong@gmail•com>,
"Jesper Dangaard Brouer" <brouer@redhat•com>,
netdev@vger•kernel.org
Subject: [PATCH bpf-next v2 1/7] net: sched: refactor cls_bpf creation code
Date: Fri, 4 Jun 2021 12:01:10 +0530 [thread overview]
Message-ID: <20210604063116.234316-2-memxor@gmail.com> (raw)
In-Reply-To: <20210604063116.234316-1-memxor@gmail.com>
Move parts of the code that are independent and need to be reused into
their own helpers. These will be needed for adding a bpf_link creation
path in a subsequent patch.
Reviewed-by: Toke Høiland-Jørgensen <toke@redhat•com>.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail•com>
---
net/sched/cls_bpf.c | 84 ++++++++++++++++++++++++++++-----------------
1 file changed, 53 insertions(+), 31 deletions(-)
diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
index 6e3e63db0e01..360b97ab8646 100644
--- a/net/sched/cls_bpf.c
+++ b/net/sched/cls_bpf.c
@@ -455,6 +455,57 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp,
return 0;
}
+static int __cls_bpf_alloc_idr(struct cls_bpf_head *head, u32 handle,
+ struct cls_bpf_prog *prog,
+ struct cls_bpf_prog *oldprog)
+{
+ int ret = 0;
+
+ if (oldprog) {
+ if (handle && oldprog->handle != handle)
+ return -EINVAL;
+ }
+
+ if (handle == 0) {
+ handle = 1;
+ ret = idr_alloc_u32(&head->handle_idr, prog, &handle, INT_MAX,
+ GFP_KERNEL);
+ } else if (!oldprog) {
+ ret = idr_alloc_u32(&head->handle_idr, prog, &handle, handle,
+ GFP_KERNEL);
+ }
+
+ prog->handle = handle;
+ return ret;
+}
+
+static int __cls_bpf_change(struct cls_bpf_head *head, struct tcf_proto *tp,
+ struct cls_bpf_prog *prog,
+ struct cls_bpf_prog *oldprog,
+ struct netlink_ext_ack *extack)
+{
+ int ret;
+
+ ret = cls_bpf_offload(tp, prog, oldprog, extack);
+ if (ret)
+ return ret;
+
+ if (!tc_in_hw(prog->gen_flags))
+ prog->gen_flags |= TCA_CLS_FLAGS_NOT_IN_HW;
+
+ if (oldprog) {
+ idr_replace(&head->handle_idr, prog, prog->handle);
+ list_replace_rcu(&oldprog->link, &prog->link);
+ tcf_unbind_filter(tp, &oldprog->res);
+ tcf_exts_get_net(&oldprog->exts);
+ tcf_queue_work(&oldprog->rwork, cls_bpf_delete_prog_work);
+ } else {
+ list_add_rcu(&prog->link, &head->plist);
+ }
+
+ return 0;
+}
+
static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca,
@@ -483,48 +534,19 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
if (ret < 0)
goto errout;
- if (oldprog) {
- if (handle && oldprog->handle != handle) {
- ret = -EINVAL;
- goto errout;
- }
- }
-
- if (handle == 0) {
- handle = 1;
- ret = idr_alloc_u32(&head->handle_idr, prog, &handle,
- INT_MAX, GFP_KERNEL);
- } else if (!oldprog) {
- ret = idr_alloc_u32(&head->handle_idr, prog, &handle,
- handle, GFP_KERNEL);
- }
-
+ ret = __cls_bpf_alloc_idr(head, handle, prog, oldprog);
if (ret)
goto errout;
- prog->handle = handle;
ret = cls_bpf_set_parms(net, tp, prog, base, tb, tca[TCA_RATE], ovr,
extack);
if (ret < 0)
goto errout_idr;
- ret = cls_bpf_offload(tp, prog, oldprog, extack);
+ ret = __cls_bpf_change(head, tp, prog, oldprog, extack);
if (ret)
goto errout_parms;
- if (!tc_in_hw(prog->gen_flags))
- prog->gen_flags |= TCA_CLS_FLAGS_NOT_IN_HW;
-
- if (oldprog) {
- idr_replace(&head->handle_idr, prog, handle);
- list_replace_rcu(&oldprog->link, &prog->link);
- tcf_unbind_filter(tp, &oldprog->res);
- tcf_exts_get_net(&oldprog->exts);
- tcf_queue_work(&oldprog->rwork, cls_bpf_delete_prog_work);
- } else {
- list_add_rcu(&prog->link, &head->plist);
- }
-
*arg = prog;
return 0;
--
2.31.1
next prev parent reply other threads:[~2021-06-04 6:33 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-04 6:31 [PATCH bpf-next v2 0/7] Add bpf_link based TC-BPF API Kumar Kartikeya Dwivedi
2021-06-04 6:31 ` Kumar Kartikeya Dwivedi [this message]
2021-06-04 6:31 ` [PATCH bpf-next v2 2/7] bpf: export bpf_link functions for modules Kumar Kartikeya Dwivedi
2021-06-04 6:31 ` [PATCH bpf-next v2 3/7] net: sched: add bpf_link API for bpf classifier Kumar Kartikeya Dwivedi
2021-06-05 3:08 ` Yonghong Song
2021-06-05 4:52 ` Kumar Kartikeya Dwivedi
2021-06-07 23:23 ` Andrii Nakryiko
2021-06-04 6:31 ` [PATCH bpf-next v2 4/7] net: sched: add lightweight update path for cls_bpf Kumar Kartikeya Dwivedi
2021-06-04 17:54 ` Alexei Starovoitov
2021-06-05 4:42 ` Kumar Kartikeya Dwivedi
2021-06-07 23:32 ` Andrii Nakryiko
2021-06-10 14:14 ` Kumar Kartikeya Dwivedi
2021-06-04 6:31 ` [PATCH bpf-next v2 5/7] tools: bpf.h: sync with kernel sources Kumar Kartikeya Dwivedi
2021-06-04 6:31 ` [PATCH bpf-next v2 6/7] libbpf: add bpf_link based TC-BPF management API Kumar Kartikeya Dwivedi
2021-06-04 18:01 ` Alexei Starovoitov
2021-06-05 4:51 ` Kumar Kartikeya Dwivedi
2021-06-07 23:37 ` Andrii Nakryiko
2021-06-05 17:09 ` Yonghong Song
2021-06-07 23:41 ` Andrii Nakryiko
2021-06-04 6:31 ` [PATCH bpf-next v2 7/7] libbpf: add selftest for " Kumar Kartikeya Dwivedi
2021-06-05 17:26 ` Yonghong Song
2021-06-07 23:57 ` Andrii Nakryiko
2022-06-10 0:24 ` [PATCH bpf-next v2 0/7] Add bpf_link based TC-BPF API Joanne Koong
2022-06-10 12:58 ` Kumar Kartikeya Dwivedi
2022-06-10 17:23 ` Joanne Koong
2022-06-10 19:07 ` Joanne Koong
2022-06-10 19:34 ` Kumar Kartikeya Dwivedi
2022-06-10 20:04 ` Daniel Borkmann
2022-06-10 22:01 ` Joanne Koong
2022-06-10 20:16 ` Toke Høiland-Jørgensen
2022-06-10 20:35 ` Daniel Borkmann
2022-06-10 20:41 ` Toke Høiland-Jørgensen
2022-06-10 21:52 ` Alexei Starovoitov
2022-06-10 22:02 ` Daniel Borkmann
2022-06-11 10:54 ` Toke Høiland-Jørgensen
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=20210604063116.234316-2-memxor@gmail.com \
--to=memxor@gmail$(echo .)com \
--cc=andrii@kernel$(echo .)org \
--cc=ast@kernel$(echo .)org \
--cc=bpf@vger$(echo .)kernel.org \
--cc=brouer@redhat$(echo .)com \
--cc=daniel@iogearbox$(echo .)net \
--cc=jhs@mojatatu$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=toke@redhat$(echo .)com \
--cc=vladbu@nvidia$(echo .)com \
--cc=xiyou.wangcong@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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