Skip to contentSkip to conversation

net: core: set and refine qdisc pkt len before tc_classify

PATCH In review Daniel Borkmann 4 participants 9 messages May 13, 2015

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

PATCH v2 1/1 net: core: set and refine qdisc pkt len before tc_classify

From: Florian Westphal <[email protected]>

Commit d2788d34885d4ce5ba ("net: sched: further simplify handle_ing") removed the call to qdisc_enqueue_root(). However, after this removal we no longer set qdisc pkt length, which this patch fixes. We make use of qdisc_pkt_len_init() from 1def9238d4aa ("net_sched: more precise pkt_len computation"), which was suggested as the current approach so far does not take into account when GRO builds up GSO packets.

Fixes d2788d34885d ("net: sched: further simplify handle_ing")

---
v1->v2:
- use qdisc_pkt_len_init() as suggested, thanks!

 net/core/dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/core/dev.c +5 -3
index 15e51a9..6e19521 100644
@@ -2787,8 +2787,8 @@ static void qdisc_pkt_len_init(struct sk_buff *skb)
 
 	qdisc_skb_cb(skb)->pkt_len = skb->len;
 
-	/* To get more precise estimation of bytes sent on wire,
-	 * we add to pkt_len the headers size of all segments
+	/* To get more precise estimation of bytes sent/received on
+	 * wire, we add to pkt_len the headers size of all segments.
 	 */
 	if (shinfo->gso_size)  {
 		unsigned int hdr_len;
@@ -3541,9 +3541,11 @@ static inline struct sk_buff *handle_ing(struct sk_buff *skb,
 		*pt_prev = NULL;
 	}
 
-	qdisc_bstats_update_cpu(cl->q, skb);
+	qdisc_pkt_len_init(skb);
 	skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS);
 
+	qdisc_bstats_update_cpu(cl->q, skb);
+
 	switch (tc_classify(skb, cl, &cl_res)) {
 	case TC_ACT_OK:
 	case TC_ACT_RECLASSIFY:
Signature · 1 line
1.9.3
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Daniel Borkmann

From: Florian Westphal <[email protected]>

Commit d2788d34885d4ce5ba ("net: sched: further simplify handle_ing") removed the call to qdisc_enqueue_root(). However, after this removal we no longer set qdisc pkt length, which this patch fixes. We make use of qdisc_pkt_len_init() from 1def9238d4aa ("net_sched: more precise pkt_len computation"), which was suggested as the current approach so far does not take into account when GRO builds up GSO packets.

Quoted 5 lines
Fixes d2788d34885d ("net: sched: further simplify handle_ing")

---

Looks good as quick fix for now. Long term I still want to try to reuse stats from underlying netdev ;)
For TX we don't have this option and have to do qdisc_pkt_len_init(), but for RX we should be able to do something smarter.

#2 lore raw
In reply to Daniel Borkmann
Quoted 38 lines · Daniel Borkmann

From: Florian Westphal <[email protected]>

Commit d2788d34885d4ce5ba ("net: sched: further simplify handle_ing") removed the call to qdisc_enqueue_root(). However, after this removal we no longer set qdisc pkt length, which this patch fixes. We make use of qdisc_pkt_len_init() from 1def9238d4aa ("net_sched: more precise pkt_len computation"), which was suggested as the current approach so far does not take into account when GRO builds up GSO packets.

Fixes d2788d34885d ("net: sched: further simplify handle_ing")

---
v1->v2:
- use qdisc_pkt_len_init() as suggested, thanks!

 net/core/dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/core/dev.c +2 -2
index 15e51a9..6e19521 100644
@@ -2787,8 +2787,8 @@ static void qdisc_pkt_len_init(struct sk_buff *skb)
 
 	qdisc_skb_cb(skb)->pkt_len = skb->len;
 
-	/* To get more precise estimation of bytes sent on wire,
-	 * we add to pkt_len the headers size of all segments
+	/* To get more precise estimation of bytes sent/received on
+	 * wire, we add to pkt_len the headers size of all segments.
 	 */
 	if (shinfo->gso_size)  {
 		unsigned int hdr_len;
@@ -3541,9 +3541,11 @@ static inline struct sk_buff *handle_ing(struct sk_buff *skb,
 		*pt_prev = NULL;
 	}

net/core/dev.c static inline struct sk_buff *handle_ing(struct sk_buff *skb, · line 3551

Quoted 10 lines
net/core/dev.c +3 -1
 
-	qdisc_bstats_update_cpu(cl->q, skb);
+	qdisc_pkt_len_init(skb);
 	skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS);
 
+	qdisc_bstats_update_cpu(cl->q, skb);
+
 	switch (tc_classify(skb, cl, &cl_res)) {
 	case TC_ACT_OK:
 	case TC_ACT_RECLASSIFY:

Is qdisc_pkt_len_init() still inlined, now it has 2 callers ?

People using policers on ingress are very often disabling GRO for various historical reasons.

Since handle_ing() is very uncommon, I would prefer not slowing down tx just so that GRO ~5% error in ingress is fixed.

I noticed you did not CC me, don't be afraid to include me next time one of my commit is referred in a changelog ;)

#3 lore raw
Quoted 21 lines · Eric Dumazet
Quoted 21 lines

Commit d2788d34885d4ce5ba ("net: sched: further simplify handle_ing") removed the call to qdisc_enqueue_root(). However, after this removal we no longer set qdisc pkt length, which this patch fixes. We make use of qdisc_pkt_len_init() from 1def9238d4aa ("net_sched: more precise pkt_len computation"), which was suggested as the current approach so far does not take into account when GRO builds up GSO packets.

Fixes d2788d34885d ("net: sched: further simplify handle_ing")

---
v1->v2:
- use qdisc_pkt_len_init() as suggested, thanks!

net/core/dev.c +1 -1
@@ -3541,9 +3541,11 @@ static inline struct sk_buff *handle_ing(struct sk_buff *skb,
 		*pt_prev = NULL;
 	}
 
-	qdisc_bstats_update_cpu(cl->q, skb);
+	qdisc_pkt_len_init(skb);

[..]

Quoted 2 lines

Is qdisc_pkt_len_init() still inlined, now it has 2 callers ?

gcc 4.8.4, OPTIMIZE_FOR_SIZE=n: nope, callq.

Quoted 2 lines

People using policers on ingress are very often disabling GRO for various historical reasons.

right, ingress policing is rather poor with GRO (or you need to set mtu 64000 on the tc police cmd line).

Quoted 2 lines

Since handle_ing() is very uncommon, I would prefer not slowing down tx just so that GRO ~5% error in ingress is fixed.

Hmm, so whats you suggestion? Just use

qdisc_skb_cb(skb)->pkt_len = skb->len;

like in v1 of the patch set?
resurrect qdisc_enqueue_root?
set always_inline (i'd prefer not, its not very small)?

Any other idea?

Thanks!

#4 lore raw
Quoted 39 lines · Florian Westphal
Quoted 21 lines · Eric Dumazet
Quoted 21 lines

Commit d2788d34885d4ce5ba ("net: sched: further simplify handle_ing") removed the call to qdisc_enqueue_root(). However, after this removal we no longer set qdisc pkt length, which this patch fixes. We make use of qdisc_pkt_len_init() from 1def9238d4aa ("net_sched: more precise pkt_len computation"), which was suggested as the current approach so far does not take into account when GRO builds up GSO packets.

Fixes d2788d34885d ("net: sched: further simplify handle_ing")

---
v1->v2:
- use qdisc_pkt_len_init() as suggested, thanks!

net/core/dev.c +1 -1
@@ -3541,9 +3541,11 @@ static inline struct sk_buff *handle_ing(struct sk_buff *skb,
 		*pt_prev = NULL;
 	}
 
-	qdisc_bstats_update_cpu(cl->q, skb);
+	qdisc_pkt_len_init(skb);

[..]

Quoted 2 lines

Is qdisc_pkt_len_init() still inlined, now it has 2 callers ?

gcc 4.8.4, OPTIMIZE_FOR_SIZE=n: nope, callq.

Quoted 2 lines

People using policers on ingress are very often disabling GRO for various historical reasons.

right, ingress policing is rather poor with GRO (or you need to set mtu 64000 on the tc police cmd line).

Quoted 2 lines

Since handle_ing() is very uncommon, I would prefer not slowing down tx just so that GRO ~5% error in ingress is fixed.

Hmm, so whats you suggestion? Just use

Quoted 7 lines

qdisc_skb_cb(skb)->pkt_len = skb->len;

like in v1 of the patch set?
resurrect qdisc_enqueue_root?
set always_inline (i'd prefer not, its not very small)?

Any other idea?

One possibility would be to set it in GRO engine.

But then we would have to set qdisc_skb_cb(skb)->pkt_len = skb->len for non GRO packets.

Also note the DODGY thing might be not needed for ingress, and I am not sure we can currently deliver UDP aggregated packets.

Hmm....

#5 lore raw
Quoted 8 lines · Eric Dumazet

One possibility would be to set it in GRO engine.

But then we would have to set qdisc_skb_cb(skb)->pkt_len = skb->len for non GRO packets.

Also note the DODGY thing might be not needed for ingress, and I am not sure we can currently deliver UDP aggregated packets.

yeah, current qdisc_pkt_len_init() is certainly TX oriented. I'm not sure we can use tcp_hdrlen(skb) on RX which is called as part of qdisc_pkt_len_init().
I think it's probably better to take Florian's V1 with:
qdisc_skb_cb(skb)->pkt_len = skb->len;
to fix immediate breakage of act police and then proceed further? Like doing qdisc_skb_cb(skb)->pkt_len = skb->len inside GRO engine is probably not possible, since cb is used by napi_gro_cb ?

#6 lore raw
Quoted 7 lines · Alexei Starovoitov
Quoted 6 lines · Eric Dumazet

One possibility would be to set it in GRO engine.

But then we would have to set qdisc_skb_cb(skb)->pkt_len = skb->len for non GRO packets.

Quoted 6 lines
Quoted 2 lines

Also note the DODGY thing might be not needed for ingress, and I am not sure we can currently deliver UDP aggregated packets.

yeah, current qdisc_pkt_len_init() is certainly TX oriented. I'm not sure we can use tcp_hdrlen(skb) on RX which is called as part of qdisc_pkt_len_init().

We can, because GRO leave transport header set at the right place.

Quoted 3 lines

I think it's probably better to take Florian's V1 with:
qdisc_skb_cb(skb)->pkt_len = skb->len;
to fix immediate breakage of act police and then proceed further?

Yes.

Quoted 2 lines

Like doing qdisc_skb_cb(skb)->pkt_len = skb->len inside GRO engine is probably not possible, since cb is used by napi_gro_cb ?

Everything is possible ;)

At the time tcp_gro_complete() is called, we certainly can overwrite NAPI_GRO_CB(skb)->frag0, with good documentation and BUILD_BUG_ON() safet nets.

#7 lore raw
In reply to Eric Dumazet

On 05/13/2015 11:20 PM, Eric Dumazet wrote:
...

Quoted 4 lines

Is qdisc_pkt_len_init() still inlined, now it has 2 callers ?

People using policers on ingress are very often disabling GRO for various historical reasons.

Yes, tested policer and for getting it working on my side, GRO needs to be off.

Quoted 2 lines

Since handle_ing() is very uncommon, I would prefer not slowing down tx just so that GRO ~5% error in ingress is fixed.

I see a callq dc0 <qdisc_pkt_len_init> now. Ok, in that case Florian's original version is fine:

http://patchwork.ozlabs.org/patch/471346/

Quoted 2 lines

I noticed you did not CC me, don't be afraid to include me next time one of my commit is referred in a changelog ;)

Hmm, I did Cc you. ;)

To: [email protected]
Cc: [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected]

Thanks,
Daniel

#8 lore raw
In reply to Eric Dumazet
Quoted 3 lines · Eric Dumazet

I noticed you did not CC me, don't be afraid to include me next time one of my commit is referred in a changelog ;)

Sorry, I was wrong on this ;)