Skip to contentSkip to conversation

sched: act: ife: UAPI checks and performance tweaks

PATCH In review Alexander Aring 3 participants 8 messages Oct 11, 2017 – Oct 13, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover sched: act: ife: UAPI checks and performance tweaks

Hi,

this patch series contains at first a patch which adds a check for IFE_ENCODE and IFE_DECODE when a ife act gets created or updated and adding handling of these cases only inside the act callback only.

The second patch use per-cpu counters and move the spinlock around so that the spinlock is less being held in act callback.

The last patch use rcu for update parameters and also move the spinlock for the same purpose as in patch 2.

Notes:
- There is still a spinlock around for protecting the metalist and a rw-lock for another list. Should be migrated to a rcu list, ife possible.

- I use still dereference in dump callback, so I think what I didn't got was what happened when rcu_assign_pointer will do when rcu read lock is held. I suppose the pointer will be updated, then we don't have any issue here.

Alexander Aring (3):
sched: act: ife: move encode/decode check to init
sched: act: ife: migrate to use per-cpu counters
sched: act: ife: update parameters via rcu handling

 include/net/tc_act/tc_ife.h |  10 +++-
 net/sched/act_ife.c         | 135 +++++++++++++++++++++++++-------------------
 2 files changed, 86 insertions(+), 59 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 sched: act: ife: move encode/decode check to init

This patch adds the check of the two possible ife handlings encode and decode to the init callback. The decode value is for usability aspect and used in userspace code only. The current code offers encode else decode only. This patch avoids any other option than this.

---
 net/sched/act_ife.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
net/sched/act_ife.c +8 -11
index 8ccd35825b6b..efac8a32c30a 100644
@@ -450,6 +450,13 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
 
 	parm = nla_data(tb[TCA_IFE_PARMS]);
 
+	/* IFE_DECODE is 0 and indicates the opposite of IFE_ENCODE because
+	 * they cannot run as the same time. Check on all other values which
+	 * are not supported right now.
+	 */
+	if (parm->flags & ~IFE_ENCODE)
+		return -EINVAL;
+
 	exists = tcf_idr_check(tn, parm->index, a, bind);
 	if (exists && bind)
 		return 0;
@@ -772,17 +779,7 @@ static int tcf_ife_act(struct sk_buff *skb, const struct tc_action *a,
 	if (ife->flags & IFE_ENCODE)
 		return tcf_ife_encode(skb, a, res);
 
-	if (!(ife->flags & IFE_ENCODE))
-		return tcf_ife_decode(skb, a, res);
-
-	pr_info_ratelimited("unknown failure(policy neither de/encode\n");
-	spin_lock(&ife->tcf_lock);
-	bstats_update(&ife->tcf_bstats, skb);
-	tcf_lastuse_update(&ife->tcf_tm);
-	ife->tcf_qstats.drops++;
-	spin_unlock(&ife->tcf_lock);
-
-	return TC_ACT_SHOT;
+	return tcf_ife_decode(skb, a, res);
 }
 
 static int tcf_ife_walker(struct net *net, struct sk_buff *skb,
Signature · 1 line
2.11.0
maintainer Acked-by on v1 1/3
#2 lore raw

Re: [PATCH net-next 1/3] sched: act: ife: move encode/decode check to init

Quoted 6 lines · Alexander Aring

This patch adds the check of the two possible ife handlings encode and decode to the init callback. The decode value is for usability aspect and used in userspace code only. The current code offers encode else decode only. This patch avoids any other option than this.

cheers,
jamal

#3 lore raw

PATCH 2/3 sched: act: ife: migrate to use per-cpu counters

In reply to Alexander Aring

This patch migrates the current counter handling which is protected by a spinlock to a per-cpu counter handling. This reduce the time where the spinlock is being held.

---
 net/sched/act_ife.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)
net/sched/act_ife.c +11 -18
index efac8a32c30a..f0d86b182387 100644
@@ -463,7 +463,7 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
 
 	if (!exists) {
 		ret = tcf_idr_create(tn, parm->index, est, a, &act_ife_ops,
-				     bind, false);
+				     bind, true);
 		if (ret)
 			return ret;
 		ret = ACT_P_CREATED;
@@ -624,19 +624,15 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
 	u8 *tlv_data;
 	u16 metalen;
 
-	spin_lock(&ife->tcf_lock);
-	bstats_update(&ife->tcf_bstats, skb);
+	bstats_cpu_update(this_cpu_ptr(ife->common.cpu_bstats), skb);
 	tcf_lastuse_update(&ife->tcf_tm);
-	spin_unlock(&ife->tcf_lock);
 
 	if (skb_at_tc_ingress(skb))
 		skb_push(skb, skb->dev->hard_header_len);
 
 	tlv_data = ife_decode(skb, &metalen);
 	if (unlikely(!tlv_data)) {
-		spin_lock(&ife->tcf_lock);
-		ife->tcf_qstats.drops++;
-		spin_unlock(&ife->tcf_lock);
+		qstats_drop_inc(this_cpu_ptr(ife->common.cpu_qstats));
 		return TC_ACT_SHOT;
 	}
 
@@ -654,14 +650,12 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,
 			 */
 			pr_info_ratelimited("Unknown metaid %d dlen %d\n",
 					    mtype, dlen);
-			ife->tcf_qstats.overlimits++;
+			qstats_overlimit_inc(this_cpu_ptr(ife->common.cpu_qstats));
 		}
 	}
 
 	if (WARN_ON(tlv_data != ifehdr_end)) {
-		spin_lock(&ife->tcf_lock);
-		ife->tcf_qstats.drops++;
-		spin_unlock(&ife->tcf_lock);
+		qstats_drop_inc(this_cpu_ptr(ife->common.cpu_qstats));
 		return TC_ACT_SHOT;
 	}
 
@@ -713,23 +707,20 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
 			exceed_mtu = true;
 	}
 
-	spin_lock(&ife->tcf_lock);
-	bstats_update(&ife->tcf_bstats, skb);
+	bstats_cpu_update(this_cpu_ptr(ife->common.cpu_bstats), skb);
 	tcf_lastuse_update(&ife->tcf_tm);
 
 	if (!metalen) {		/* no metadata to send */
 		/* abuse overlimits to count when we allow packet
 		 * with no metadata
 		 */
-		ife->tcf_qstats.overlimits++;
-		spin_unlock(&ife->tcf_lock);
+		qstats_overlimit_inc(this_cpu_ptr(ife->common.cpu_qstats));
 		return action;
 	}
 	/* could be stupid policy setup or mtu config
 	 * so lets be conservative.. */
 	if ((action == TC_ACT_SHOT) || exceed_mtu) {
-		ife->tcf_qstats.drops++;
-		spin_unlock(&ife->tcf_lock);
+		qstats_drop_inc(this_cpu_ptr(ife->common.cpu_qstats));
 		return TC_ACT_SHOT;
 	}
 
@@ -738,6 +729,8 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
 
 	ife_meta = ife_encode(skb, metalen);
 
+	spin_lock(&ife->tcf_lock);
+
 	/* XXX: we dont have a clever way of telling encode to
 	 * not repeat some of the computations that are done by
 	 * ops->presence_check...
@@ -749,8 +742,8 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
 		}
 		if (err < 0) {
 			/* too corrupt to keep around if overwritten */
-			ife->tcf_qstats.drops++;
 			spin_unlock(&ife->tcf_lock);
+			qstats_drop_inc(this_cpu_ptr(ife->common.cpu_qstats));
 			return TC_ACT_SHOT;
 		}
 		skboff += err;
Signature · 1 line
2.11.0
#5 lore raw

PATCH 3/3 sched: act: ife: update parameters via rcu handling

In reply to Alexander Aring

This patch changes the parameter updating via RCU and not protected by a spinlock anymore. This reduce the time that the spinlock is being held.

---
 include/net/tc_act/tc_ife.h | 10 ++++--
 net/sched/act_ife.c         | 87 ++++++++++++++++++++++++++++++---------------
 2 files changed, 67 insertions(+), 30 deletions(-)
include/net/tc_act/tc_ife.h +8 -2
index 30ba459ddd34..16a84f6d43e2 100644
@@ -6,12 +6,18 @@
 #include <linux/rtnetlink.h>
 #include <linux/module.h>
 
-struct tcf_ife_info {
-	struct tc_action common;
+struct tcf_ife_params {
 	u8 eth_dst[ETH_ALEN];
 	u8 eth_src[ETH_ALEN];
 	u16 eth_type;
 	u16 flags;
+
+	struct rcu_head rcu;
+};
+
+struct tcf_ife_info {
+	struct tc_action common;
+	struct tcf_ife_params __rcu *params;
 	/* list of metaids allowed */
 	struct list_head metalist;
 };
net/sched/act_ife.c +59 -28

205 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#7 lore raw
In reply to Alexander Aring

From: Alexander Aring <[email protected]>
Date: Wed, 11 Oct 2017 17:16:05 -0400

Quoted 15 lines

this patch series contains at first a patch which adds a check for IFE_ENCODE and IFE_DECODE when a ife act gets created or updated and adding handling of these cases only inside the act callback only.

The second patch use per-cpu counters and move the spinlock around so that the spinlock is less being held in act callback.

The last patch use rcu for update parameters and also move the spinlock for the same purpose as in patch 2.

Notes:
- There is still a spinlock around for protecting the metalist and a rw-lock for another list. Should be migrated to a rcu list, ife possible.

Quoted 4 lines

- I use still dereference in dump callback, so I think what I didn't got was what happened when rcu_assign_pointer will do when rcu read lock is held. I suppose the pointer will be updated, then we don't have any issue here.

Series applied.