summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWillem de Bruijn <willemb@google.com>2017-01-07 17:06:36 -0500
committerDavid S. Miller <davem@davemloft.net>2017-01-08 20:58:52 -0500
commita5135bcfba7345031df45e02cd150a45add47cf8 (patch)
tree11e201bd54742af84404e74007a9408f14b5aa0f
parente7246e122aaa99ebbb8ad7da80f35a20577bd8af (diff)
net-tc: convert tc_verd to integer bitfields
Extract the remaining two fields from tc_verd and remove the __u16 completely. TC_AT and TC_FROM are converted to equivalent two-bit integer fields tc_at and tc_from. Where possible, use existing helper skb_at_tc_ingress when reading tc_at. Introduce helper skb_reset_tc to clear fields. Not documenting tc_from and tc_at, because they will be replaced with single bit fields in follow-on patches. Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ifb.c7
-rw-r--r--drivers/staging/octeon/ethernet-tx.c5
-rw-r--r--include/linux/skbuff.h6
-rw-r--r--include/net/sch_generic.h10
-rw-r--r--include/uapi/linux/pkt_cls.h31
-rw-r--r--net/core/dev.c10
-rw-r--r--net/core/pktgen.c4
-rw-r--r--net/core/skbuff.c3
-rw-r--r--net/sched/act_ife.c7
-rw-r--r--net/sched/act_mirred.c9
-rw-r--r--net/sched/sch_netem.c2
11 files changed, 29 insertions, 65 deletions
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 442c4c4a9606..b73b6b6c066b 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -78,9 +78,9 @@ static void ifb_ri_tasklet(unsigned long _txp)
78 } 78 }
79 79
80 while ((skb = __skb_dequeue(&txp->tq)) != NULL) { 80 while ((skb = __skb_dequeue(&txp->tq)) != NULL) {
81 u32 from = G_TC_FROM(skb->tc_verd); 81 u32 from = skb->tc_from;
82 82
83 skb->tc_verd = 0; 83 skb_reset_tc(skb);
84 skb->tc_skip_classify = 1; 84 skb->tc_skip_classify = 1;
85 85
86 u64_stats_update_begin(&txp->tsync); 86 u64_stats_update_begin(&txp->tsync);
@@ -239,7 +239,6 @@ static void ifb_setup(struct net_device *dev)
239static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev) 239static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
240{ 240{
241 struct ifb_dev_private *dp = netdev_priv(dev); 241 struct ifb_dev_private *dp = netdev_priv(dev);
242 u32 from = G_TC_FROM(skb->tc_verd);
243 struct ifb_q_private *txp = dp->tx_private + skb_get_queue_mapping(skb); 242 struct ifb_q_private *txp = dp->tx_private + skb_get_queue_mapping(skb);
244 243
245 u64_stats_update_begin(&txp->rsync); 244 u64_stats_update_begin(&txp->rsync);
@@ -247,7 +246,7 @@ static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
247 txp->rx_bytes += skb->len; 246 txp->rx_bytes += skb->len;
248 u64_stats_update_end(&txp->rsync); 247 u64_stats_update_end(&txp->rsync);
249 248
250 if (!(from & (AT_INGRESS|AT_EGRESS)) || !skb->skb_iif) { 249 if (skb->tc_from == AT_STACK || !skb->skb_iif) {
251 dev_kfree_skb(skb); 250 dev_kfree_skb(skb);
252 dev->stats.rx_dropped++; 251 dev->stats.rx_dropped++;
253 return NETDEV_TX_OK; 252 return NETDEV_TX_OK;
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 6b4c20872323..0b8053205091 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -23,6 +23,7 @@
23#endif /* CONFIG_XFRM */ 23#endif /* CONFIG_XFRM */
24 24
25#include <linux/atomic.h> 25#include <linux/atomic.h>
26#include <net/sch_generic.h>
26 27
27#include <asm/octeon/octeon.h> 28#include <asm/octeon/octeon.h>
28 29
@@ -369,9 +370,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
369 370
370#ifdef CONFIG_NET_SCHED 371#ifdef CONFIG_NET_SCHED
371 skb->tc_index = 0; 372 skb->tc_index = 0;
372#ifdef CONFIG_NET_CLS_ACT 373 skb_reset_tc(skb);
373 skb->tc_verd = 0;
374#endif /* CONFIG_NET_CLS_ACT */
375#endif /* CONFIG_NET_SCHED */ 374#endif /* CONFIG_NET_SCHED */
376#endif /* REUSE_SKBUFFS_WITHOUT_FREE */ 375#endif /* REUSE_SKBUFFS_WITHOUT_FREE */
377 376
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 570f60ec6cb4..f738d09947b2 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -599,7 +599,6 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1,
599 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c 599 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
600 * @skb_iif: ifindex of device we arrived on 600 * @skb_iif: ifindex of device we arrived on
601 * @tc_index: Traffic control index 601 * @tc_index: Traffic control index
602 * @tc_verd: traffic control verdict
603 * @hash: the packet hash 602 * @hash: the packet hash
604 * @queue_mapping: Queue mapping for multiqueue devices 603 * @queue_mapping: Queue mapping for multiqueue devices
605 * @xmit_more: More SKBs are pending for this queue 604 * @xmit_more: More SKBs are pending for this queue
@@ -752,13 +751,12 @@ struct sk_buff {
752#endif 751#endif
753#ifdef CONFIG_NET_CLS_ACT 752#ifdef CONFIG_NET_CLS_ACT
754 __u8 tc_skip_classify:1; 753 __u8 tc_skip_classify:1;
754 __u8 tc_at:2;
755 __u8 tc_from:2;
755#endif 756#endif
756 757
757#ifdef CONFIG_NET_SCHED 758#ifdef CONFIG_NET_SCHED
758 __u16 tc_index; /* traffic control index */ 759 __u16 tc_index; /* traffic control index */
759#ifdef CONFIG_NET_CLS_ACT
760 __u16 tc_verd; /* traffic control verdict */
761#endif
762#endif 760#endif
763 761
764 union { 762 union {
diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
index 857356f2d74b..f80dba516964 100644
--- a/include/net/sch_generic.h
+++ b/include/net/sch_generic.h
@@ -409,10 +409,18 @@ bool tcf_destroy(struct tcf_proto *tp, bool force);
409void tcf_destroy_chain(struct tcf_proto __rcu **fl); 409void tcf_destroy_chain(struct tcf_proto __rcu **fl);
410int skb_do_redirect(struct sk_buff *); 410int skb_do_redirect(struct sk_buff *);
411 411
412static inline void skb_reset_tc(struct sk_buff *skb)
413{
414#ifdef CONFIG_NET_CLS_ACT
415 skb->tc_at = 0;
416 skb->tc_from = 0;
417#endif
418}
419
412static inline bool skb_at_tc_ingress(const struct sk_buff *skb) 420static inline bool skb_at_tc_ingress(const struct sk_buff *skb)
413{ 421{
414#ifdef CONFIG_NET_CLS_ACT 422#ifdef CONFIG_NET_CLS_ACT
415 return G_TC_AT(skb->tc_verd) & AT_INGRESS; 423 return skb->tc_at & AT_INGRESS;
416#else 424#else
417 return false; 425 return false;
418#endif 426#endif
diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
index 1eed5d7509bc..cee753a7a40c 100644
--- a/include/uapi/linux/pkt_cls.h
+++ b/include/uapi/linux/pkt_cls.h
@@ -5,40 +5,9 @@
5#include <linux/pkt_sched.h> 5#include <linux/pkt_sched.h>
6 6
7#ifdef __KERNEL__ 7#ifdef __KERNEL__
8/* I think i could have done better macros ; for now this is stolen from
9 * some arch/mips code - jhs
10*/
11#define _TC_MAKE32(x) ((x))
12
13#define _TC_MAKEMASK1(n) (_TC_MAKE32(1) << _TC_MAKE32(n))
14#define _TC_MAKEMASK(v,n) (_TC_MAKE32((_TC_MAKE32(1)<<(v))-1) << _TC_MAKE32(n))
15#define _TC_MAKEVALUE(v,n) (_TC_MAKE32(v) << _TC_MAKE32(n))
16#define _TC_GETVALUE(v,n,m) ((_TC_MAKE32(v) & _TC_MAKE32(m)) >> _TC_MAKE32(n))
17
18/* verdict bit breakdown
19 *
20bit 6,7: Where this packet was last seen
210: Above the transmit example at the socket level
221: on the Ingress
232: on the Egress
24
25 *
26 * */
27
28#define S_TC_FROM _TC_MAKE32(6)
29#define M_TC_FROM _TC_MAKEMASK(2,S_TC_FROM)
30#define G_TC_FROM(x) _TC_GETVALUE(x,S_TC_FROM,M_TC_FROM)
31#define V_TC_FROM(x) _TC_MAKEVALUE(x,S_TC_FROM)
32#define SET_TC_FROM(v,n) ((V_TC_FROM(n)) | (v & ~M_TC_FROM))
33#define AT_STACK 0x0 8#define AT_STACK 0x0
34#define AT_INGRESS 0x1 9#define AT_INGRESS 0x1
35#define AT_EGRESS 0x2 10#define AT_EGRESS 0x2
36
37#define S_TC_AT _TC_MAKE32(12)
38#define M_TC_AT _TC_MAKEMASK(2,S_TC_AT)
39#define G_TC_AT(x) _TC_GETVALUE(x,S_TC_AT,M_TC_AT)
40#define V_TC_AT(x) _TC_MAKEVALUE(x,S_TC_AT)
41#define SET_TC_AT(v,n) ((V_TC_AT(n)) | (v & ~M_TC_AT))
42#endif 11#endif
43 12
44/* Action attributes */ 13/* Action attributes */
diff --git a/net/core/dev.c b/net/core/dev.c
index e39e35d2e082..8b5d6d033473 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3153,7 +3153,7 @@ sch_handle_egress(struct sk_buff *skb, int *ret, struct net_device *dev)
3153 if (!cl) 3153 if (!cl)
3154 return skb; 3154 return skb;
3155 3155
3156 /* skb->tc_verd and qdisc_skb_cb(skb)->pkt_len were already set 3156 /* skb->tc_at and qdisc_skb_cb(skb)->pkt_len were already set
3157 * earlier by the caller. 3157 * earlier by the caller.
3158 */ 3158 */
3159 qdisc_bstats_cpu_update(cl->q, skb); 3159 qdisc_bstats_cpu_update(cl->q, skb);
@@ -3320,7 +3320,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)
3320 3320
3321 qdisc_pkt_len_init(skb); 3321 qdisc_pkt_len_init(skb);
3322#ifdef CONFIG_NET_CLS_ACT 3322#ifdef CONFIG_NET_CLS_ACT
3323 skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS); 3323 skb->tc_at = AT_EGRESS;
3324# ifdef CONFIG_NET_EGRESS 3324# ifdef CONFIG_NET_EGRESS
3325 if (static_key_false(&egress_needed)) { 3325 if (static_key_false(&egress_needed)) {
3326 skb = sch_handle_egress(skb, &rc, dev); 3326 skb = sch_handle_egress(skb, &rc, dev);
@@ -3920,7 +3920,7 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
3920 } 3920 }
3921 3921
3922 qdisc_skb_cb(skb)->pkt_len = skb->len; 3922 qdisc_skb_cb(skb)->pkt_len = skb->len;
3923 skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS); 3923 skb->tc_at = AT_INGRESS;
3924 qdisc_bstats_cpu_update(cl->q, skb); 3924 qdisc_bstats_cpu_update(cl->q, skb);
3925 3925
3926 switch (tc_classify(skb, cl, &cl_res, false)) { 3926 switch (tc_classify(skb, cl, &cl_res, false)) {
@@ -4122,9 +4122,7 @@ skip_taps:
4122 goto out; 4122 goto out;
4123 } 4123 }
4124#endif 4124#endif
4125#ifdef CONFIG_NET_CLS_ACT 4125 skb_reset_tc(skb);
4126 skb->tc_verd = 0;
4127#endif
4128skip_classify: 4126skip_classify:
4129 if (pfmemalloc && !skb_pfmemalloc_protocol(skb)) 4127 if (pfmemalloc && !skb_pfmemalloc_protocol(skb))
4130 goto drop; 4128 goto drop;
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 8e69ce472236..96947f5d41e4 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3439,9 +3439,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
3439 /* skb was 'freed' by stack, so clean few 3439 /* skb was 'freed' by stack, so clean few
3440 * bits and reuse it 3440 * bits and reuse it
3441 */ 3441 */
3442#ifdef CONFIG_NET_CLS_ACT 3442 skb_reset_tc(skb);
3443 skb->tc_verd = 0; /* reset reclass/redir ttl */
3444#endif
3445 } while (--burst > 0); 3443 } while (--burst > 0);
3446 goto out; /* Skips xmit_mode M_START_XMIT */ 3444 goto out; /* Skips xmit_mode M_START_XMIT */
3447 } else if (pkt_dev->xmit_mode == M_QUEUE_XMIT) { 3445 } else if (pkt_dev->xmit_mode == M_QUEUE_XMIT) {
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 5a03730fbc1a..adec4bf807d8 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -878,9 +878,6 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
878#endif 878#endif
879#ifdef CONFIG_NET_SCHED 879#ifdef CONFIG_NET_SCHED
880 CHECK_SKB_FIELD(tc_index); 880 CHECK_SKB_FIELD(tc_index);
881#ifdef CONFIG_NET_CLS_ACT
882 CHECK_SKB_FIELD(tc_verd);
883#endif
884#endif 881#endif
885 882
886} 883}
diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index 80b848d3f096..921fb20eaa7c 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -736,12 +736,11 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
736 u16 metalen = ife_get_sz(skb, ife); 736 u16 metalen = ife_get_sz(skb, ife);
737 int hdrm = metalen + skb->dev->hard_header_len + IFE_METAHDRLEN; 737 int hdrm = metalen + skb->dev->hard_header_len + IFE_METAHDRLEN;
738 unsigned int skboff = skb->dev->hard_header_len; 738 unsigned int skboff = skb->dev->hard_header_len;
739 u32 at = G_TC_AT(skb->tc_verd);
740 int new_len = skb->len + hdrm; 739 int new_len = skb->len + hdrm;
741 bool exceed_mtu = false; 740 bool exceed_mtu = false;
742 int err; 741 int err;
743 742
744 if (at & AT_EGRESS) { 743 if (!skb_at_tc_ingress(skb)) {
745 if (new_len > skb->dev->mtu) 744 if (new_len > skb->dev->mtu)
746 exceed_mtu = true; 745 exceed_mtu = true;
747 } 746 }
@@ -773,7 +772,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
773 return TC_ACT_SHOT; 772 return TC_ACT_SHOT;
774 } 773 }
775 774
776 if (!(at & AT_EGRESS)) 775 if (skb_at_tc_ingress(skb))
777 skb_push(skb, skb->dev->hard_header_len); 776 skb_push(skb, skb->dev->hard_header_len);
778 777
779 iethh = (struct ethhdr *)skb->data; 778 iethh = (struct ethhdr *)skb->data;
@@ -816,7 +815,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
816 ether_addr_copy(oethh->h_dest, iethh->h_dest); 815 ether_addr_copy(oethh->h_dest, iethh->h_dest);
817 oethh->h_proto = htons(ife->eth_type); 816 oethh->h_proto = htons(ife->eth_type);
818 817
819 if (!(at & AT_EGRESS)) 818 if (skb_at_tc_ingress(skb))
820 skb_pull(skb, skb->dev->hard_header_len); 819 skb_pull(skb, skb->dev->hard_header_len);
821 820
822 spin_unlock(&ife->tcf_lock); 821 spin_unlock(&ife->tcf_lock);
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 2d9fa6e0a1b4..8543279bba49 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -170,7 +170,6 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
170 int retval, err = 0; 170 int retval, err = 0;
171 int m_eaction; 171 int m_eaction;
172 int mac_len; 172 int mac_len;
173 u32 at;
174 173
175 tcf_lastuse_update(&m->tcf_tm); 174 tcf_lastuse_update(&m->tcf_tm);
176 bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb); 175 bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb);
@@ -191,7 +190,6 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
191 goto out; 190 goto out;
192 } 191 }
193 192
194 at = G_TC_AT(skb->tc_verd);
195 skb2 = skb_clone(skb, GFP_ATOMIC); 193 skb2 = skb_clone(skb, GFP_ATOMIC);
196 if (!skb2) 194 if (!skb2)
197 goto out; 195 goto out;
@@ -200,8 +198,9 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
200 * and devices expect a mac header on xmit, then mac push/pull is 198 * and devices expect a mac header on xmit, then mac push/pull is
201 * needed. 199 * needed.
202 */ 200 */
203 if (at != tcf_mirred_act_direction(m_eaction) && m_mac_header_xmit) { 201 if (skb->tc_at != tcf_mirred_act_direction(m_eaction) &&
204 if (at & AT_EGRESS) { 202 m_mac_header_xmit) {
203 if (!skb_at_tc_ingress(skb)) {
205 /* caught at egress, act ingress: pull mac */ 204 /* caught at egress, act ingress: pull mac */
206 mac_len = skb_network_header(skb) - skb_mac_header(skb); 205 mac_len = skb_network_header(skb) - skb_mac_header(skb);
207 skb_pull_rcsum(skb2, mac_len); 206 skb_pull_rcsum(skb2, mac_len);
@@ -213,7 +212,7 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
213 212
214 /* mirror is always swallowed */ 213 /* mirror is always swallowed */
215 if (tcf_mirred_is_act_redirect(m_eaction)) 214 if (tcf_mirred_is_act_redirect(m_eaction))
216 skb2->tc_verd = SET_TC_FROM(skb2->tc_verd, at); 215 skb2->tc_from = skb2->tc_at;
217 216
218 skb2->skb_iif = skb->dev->ifindex; 217 skb2->skb_iif = skb->dev->ifindex;
219 skb2->dev = dev; 218 skb2->dev = dev;
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index bcfadfdea8e0..bb5c638b6852 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -626,7 +626,7 @@ deliver:
626 * If it's at ingress let's pretend the delay is 626 * If it's at ingress let's pretend the delay is
627 * from the network (tstamp will be updated). 627 * from the network (tstamp will be updated).
628 */ 628 */
629 if (G_TC_FROM(skb->tc_verd) & AT_INGRESS) 629 if (skb->tc_from & AT_INGRESS)
630 skb->tstamp = 0; 630 skb->tstamp = 0;
631#endif 631#endif
632 632