netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] net: revert "net_sched: move tp->root allocation into fw_init()"
@ 2015-09-23  0:01 Cong Wang
  2015-09-23 18:43 ` Jamal Hadi Salim
  2015-09-24 21:34 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2015-09-23  0:01 UTC (permalink / raw)
  To: netdev; +Cc: Akshat Kakkar, Cong Wang, Jamal Hadi Salim

fw filter uses tp->root==NULL to check if it is the old method,
so it doesn't need allocation at all in this case. This patch
reverts the offending commit and adds some comments for old
method to make it obvious.

Fixes: 33f8b9ecdb15 ("net_sched: move tp->root allocation into fw_init()")
Reported-by: Akshat Kakkar <akshat.1984@gmail.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/sched/cls_fw.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index 715e01e..f23a3b6 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -33,7 +33,6 @@
 
 struct fw_head {
 	u32			mask;
-	bool			mask_set;
 	struct fw_filter __rcu	*ht[HTSIZE];
 	struct rcu_head		rcu;
 };
@@ -84,7 +83,7 @@ static int fw_classify(struct sk_buff *skb, const struct tcf_proto *tp,
 			}
 		}
 	} else {
-		/* old method */
+		/* Old method: classify the packet using its skb mark. */
 		if (id && (TC_H_MAJ(id) == 0 ||
 			   !(TC_H_MAJ(id ^ tp->q->handle)))) {
 			res->classid = id;
@@ -114,14 +113,9 @@ static unsigned long fw_get(struct tcf_proto *tp, u32 handle)
 
 static int fw_init(struct tcf_proto *tp)
 {
-	struct fw_head *head;
-
-	head = kzalloc(sizeof(struct fw_head), GFP_KERNEL);
-	if (head == NULL)
-		return -ENOBUFS;
-
-	head->mask_set = false;
-	rcu_assign_pointer(tp->root, head);
+	/* We don't allocate fw_head here, because in the old method
+	 * we don't need it at all.
+	 */
 	return 0;
 }
 
@@ -252,7 +246,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 	int err;
 
 	if (!opt)
-		return handle ? -EINVAL : 0;
+		return handle ? -EINVAL : 0; /* Succeed if it is old method. */
 
 	err = nla_parse_nested(tb, TCA_FW_MAX, opt, fw_policy);
 	if (err < 0)
@@ -302,11 +296,17 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 	if (!handle)
 		return -EINVAL;
 
-	if (!head->mask_set) {
-		head->mask = 0xFFFFFFFF;
+	if (!head) {
+		u32 mask = 0xFFFFFFFF;
 		if (tb[TCA_FW_MASK])
-			head->mask = nla_get_u32(tb[TCA_FW_MASK]);
-		head->mask_set = true;
+			mask = nla_get_u32(tb[TCA_FW_MASK]);
+
+		head = kzalloc(sizeof(*head), GFP_KERNEL);
+		if (!head)
+			return -ENOBUFS;
+		head->mask = mask;
+
+		rcu_assign_pointer(tp->root, head);
 	}
 
 	f = kzalloc(sizeof(struct fw_filter), GFP_KERNEL);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch net] net: revert "net_sched: move tp->root allocation into fw_init()"
  2015-09-23  0:01 [Patch net] net: revert "net_sched: move tp->root allocation into fw_init()" Cong Wang
@ 2015-09-23 18:43 ` Jamal Hadi Salim
  2015-09-24 21:34 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Jamal Hadi Salim @ 2015-09-23 18:43 UTC (permalink / raw)
  To: Cong Wang, netdev; +Cc: Akshat Kakkar

On 09/22/15 20:01, Cong Wang wrote:
> fw filter uses tp->root==NULL to check if it is the old method,
> so it doesn't need allocation at all in this case. This patch
> reverts the offending commit and adds some comments for old
> method to make it obvious.
>
> Fixes: 33f8b9ecdb15 ("net_sched: move tp->root allocation into fw_init()")
> Reported-by: Akshat Kakkar <akshat.1984@gmail.com>
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch net] net: revert "net_sched: move tp->root allocation into fw_init()"
  2015-09-23  0:01 [Patch net] net: revert "net_sched: move tp->root allocation into fw_init()" Cong Wang
  2015-09-23 18:43 ` Jamal Hadi Salim
@ 2015-09-24 21:34 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-09-24 21:34 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, akshat.1984, jhs

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Tue, 22 Sep 2015 17:01:11 -0700

> fw filter uses tp->root==NULL to check if it is the old method,
> so it doesn't need allocation at all in this case. This patch
> reverts the offending commit and adds some comments for old
> method to make it obvious.
> 
> Fixes: 33f8b9ecdb15 ("net_sched: move tp->root allocation into fw_init()")
> Reported-by: Akshat Kakkar <akshat.1984@gmail.com>
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-24 21:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-23  0:01 [Patch net] net: revert "net_sched: move tp->root allocation into fw_init()" Cong Wang
2015-09-23 18:43 ` Jamal Hadi Salim
2015-09-24 21:34 ` David Miller

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).