From: Victor Nogueira <victor@mojatatu.com>
To: netdev@vger.kernel.org
Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, pctammela@mojatatu.com, kernel@mojatatu.com
Subject: [PATCH net 3/5] net: sched: cls_u32: Undo tcf_bind_filter if u32_replace_hw_knode
Date: Tue, 4 Jul 2023 12:14:54 -0300 [thread overview]
Message-ID: <20230704151456.52334-4-victor@mojatatu.com> (raw)
In-Reply-To: <20230704151456.52334-1-victor@mojatatu.com>
When u32_replace_hw_knode fails, we need to undo the tcf_bind_filter
operation done at u32_set_parms.
Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.")
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Reviewed-by: Pedro Tammela <pctammela@mojatatu.com>
---
net/sched/cls_u32.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
index d15d50de7980..e193db39bee2 100644
--- a/net/sched/cls_u32.c
+++ b/net/sched/cls_u32.c
@@ -712,11 +712,13 @@ static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = {
[TCA_U32_FLAGS] = { .type = NLA_U32 },
};
+#define U32_SET_FLAGS_BOUND 0x1
+
static int u32_set_parms(struct net *net, struct tcf_proto *tp,
unsigned long base,
struct tc_u_knode *n, struct nlattr **tb,
struct nlattr *est, u32 flags, u32 fl_flags,
- struct netlink_ext_ack *extack)
+ u8 *set_flags, struct netlink_ext_ack *extack)
{
int err, ifindex = -1;
@@ -763,6 +765,7 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
if (tb[TCA_U32_CLASSID]) {
n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]);
tcf_bind_filter(tp, &n->res, base);
+ *set_flags |= U32_SET_FLAGS_BOUND;
}
if (ifindex >= 0)
@@ -853,6 +856,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
struct netlink_ext_ack *extack)
{
struct tc_u_common *tp_c = tp->data;
+ u8 set_flags = 0;
struct tc_u_hnode *ht;
struct tc_u_knode *n;
struct tc_u32_sel *s;
@@ -905,7 +909,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
err = u32_set_parms(net, tp, base, new, tb,
tca[TCA_RATE], flags, new->flags,
- extack);
+ &set_flags, extack);
if (err) {
__u32_destroy_key(new);
@@ -914,6 +918,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
err = u32_replace_hw_knode(tp, new, flags, extack);
if (err) {
+ if (set_flags & U32_SET_FLAGS_BOUND)
+ tcf_unbind_filter(tp, &new->res);
+
__u32_destroy_key(new);
return err;
}
@@ -1075,14 +1082,14 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
#endif
err = u32_set_parms(net, tp, base, n, tb, tca[TCA_RATE],
- flags, n->flags, extack);
+ flags, n->flags, &set_flags, extack);
if (err == 0) {
struct tc_u_knode __rcu **ins;
struct tc_u_knode *pins;
err = u32_replace_hw_knode(tp, n, flags, extack);
if (err)
- goto errhw;
+ goto errunbind;
if (!tc_in_hw(n->flags))
n->flags |= TCA_CLS_FLAGS_NOT_IN_HW;
@@ -1100,7 +1107,10 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
return 0;
}
-errhw:
+errunbind:
+ if (set_flags & U32_SET_FLAGS_BOUND)
+ tcf_unbind_filter(tp, &n->res);
+
#ifdef CONFIG_CLS_U32_MARK
free_percpu(n->pcpu_success);
#endif
--
2.25.1
next prev parent reply other threads:[~2023-07-04 15:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-04 15:14 [PATCH net 0/5] net: sched: Undo tcf_bind_filter in case of errors in set callbacks Victor Nogueira
2023-07-04 15:14 ` [PATCH net 1/5] net: sched: cls_bpf: Undo tcf_bind_filter in case of an error Victor Nogueira
2023-07-04 20:48 ` Simon Horman
2023-07-04 20:55 ` Jamal Hadi Salim
2023-07-04 21:19 ` Simon Horman
2023-07-04 21:42 ` Jamal Hadi Salim
2023-07-05 7:45 ` Simon Horman
2023-07-04 15:14 ` [PATCH net 2/5] net: sched: cls_matchall: Undo tcf_bind_filter in case of failure after mall_set_parms Victor Nogueira
2023-07-04 15:14 ` Victor Nogueira [this message]
2023-07-04 15:14 ` [PATCH net 4/5] net: sched: cls_u32: Undo refcount decrement in case update failed Victor Nogueira
2023-07-04 15:14 ` [PATCH net 5/5] net: sched: cls_flower: Undo tcf_bind_filter if fl_set_key fails Victor Nogueira
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=20230704151456.52334-4-victor@mojatatu.com \
--to=victor@mojatatu.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kernel@mojatatu.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pctammela@mojatatu.com \
--cc=xiyou.wangcong@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 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).