: dev_queue_xmit error propagation
Subsystems (3)
cover : dev_queue_xmit error propagation
Currently the ->ndo_hard_start_xmit() callbacks are only permitted to return one of the NETDEV_TX codes. This prevents any kind of error propagation for virtual devices, like queue congestion of the underlying device in case of layered devices, or unreachability in case of tunnels.
These patches change the return conventions so hard_start_xmit() can return a NETDEV_TX code, an errno code or a NET_XMIT code. This means it can additionally to the NETDEV_TX codes simply return the value of dev_queue_xmit().
When queueing is used, errors can't be propagated back since transmission is asynchronously and all non-NETDEV codes are mapped to NETDEV_TX_OK, reflecting the fact that the skb is consumed unconditionally.
In case of virtual devices not using queueing, the NETDEV_TX codes are consumed by dev_queue_xmit(), everything else is returned to the higher layers.
The end result is that virtual network devices can propagate queue congestion state of the underlying device, or other errors, back to the socket layer. One immediately useful effect is that TCP can make use of this information as is currently done with non-virtual devices. But it also seems useful in case of tunnels, which can return more meaningful errors, or for statistics.
Comments welcome. A review of my changes in dev_hard_start_xmit() would be especially appreciated :)
include/linux/netdevice.h | 39 +++++++++++++++++++++++++++++---------- net/8021q/vlan_dev.c | 29 ++++++++++++++++++++++------- net/core/dev.c | 7 +++++-- net/sched/sch_atm.c | 4 ++-- net/sched/sch_generic.c | 10 +++++++++- net/sched/sch_sfq.c | 2 +- net/sched/sch_tbf.c | 4 ++-- net/sched/sch_teql.c | 2 +- 8 files changed, 71 insertions(+), 26 deletions(-)
Patrick McHardy (3):
net-sched: use symbolic NET_XMIT constants in qdiscs
net: allow to propagate errors through ->ndo_hard_start_xmit()
vlan: propagate transmission state
RFC 1/3 : use symbolic NET_XMIT constants in qdiscs
commit 49ffbac7a80175238e550479c44e1e897bc56911
Author: Patrick McHardy <[email protected]> Date: Tue Jun 9 17:55:06 2009 +0200
net-sched: use symbolic NET_XMIT constants in qdiscs
Convert the remaining spots using raw values to use the symbolic NET_XMIT constants.
net/sched/sch_atm.c +2 -2
@@ -431,7 +431,7 @@ static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch) } ret =qdisc_enqueue (skb, flow->q); -if (ret !=0 ) { +if (ret !=NET_XMIT_SUCCESS ) { drop:__maybe_unused if (net_xmit_drop_count (ret)) { sch->qstats.drops++;
@@ -455,7 +455,7 @@ drop: __maybe_unused*/ if (flow == &p->link) { sch->q.qlen++; -return 0 ; +return NET_XMIT_SUCCESS ; }tasklet_schedule (&p->task);return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
net/sched/sch_sfq.c +1 -1
@@ -322,7 +322,7 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch)if (++sch->q.qlen <= q->limit) { sch->bstats.bytes +=qdisc_pkt_len (skb); sch->bstats.packets++; -return 0 ; +return NET_XMIT_SUCCESS ; }sfq_drop (sch);
net/sched/sch_tbf.c +2 -2
@@ -127,7 +127,7 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc* sch)return qdisc_reshape_fail (skb, sch); ret =qdisc_enqueue (skb, q->qdisc); -if (ret !=0 ) { +if (ret !=NET_XMIT_SUCCESS ) {if (net_xmit_drop_count (ret)) sch->qstats.drops++;return ret;
@@ -136,7 +136,7 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc* sch) sch->q.qlen++; sch->bstats.bytes +=qdisc_pkt_len (skb); sch->bstats.packets++; -return 0 ; +return NET_XMIT_SUCCESS ; }static unsigned int tbf_drop (struct Qdisc * sch)
net/sched/sch_teql.c +1 -1
@@ -84,7 +84,7 @@ teql_enqueue(struct sk_buff *skb, struct Qdisc* sch)__skb_queue_tail (&q->q, skb); sch->bstats.bytes +=qdisc_pkt_len (skb); sch->bstats.packets++; -return 0 ; +return NET_XMIT_SUCCESS ; }kfree_skb (skb);
RFC 2/3 : allow to propagate errors through ->ndo_hard_start_xmit()
In reply to Patrick McHardycommit c2104095c3a1023b4f4809c90092145dff093c88
Author: Patrick McHardy <[email protected]> Date: Tue Jun 9 17:55:34 2009 +0200
net: allow to propagate errors through ->ndo_hard_start_xmit()
Currently the ->ndo_hard_start_xmit() callbacks are only permitted to return one of the NETDEV_TX codes. This prevents any kind of error propagation for virtual devices, like queue congestion of the underlying device in case of layered devices, or unreachability in case of tunnels.
This patches changes the NET_XMIT codes to avoid clashes with the NETDEV_TX codes and changes the two callers of dev_hard_start_xmit() to expect either errno codes, NET_XMIT codes or NETDEV_TX codes as return value.
In case of qdisc_restart(), all non NETDEV_TX codes are mapped to NETDEV_TX_OK since no error propagation is possible when using qdiscs. In case of dev_queue_xmit(), the error is propagated upwards.
include/linux/netdevice.h +29 -10
@@ -63,11 +63,35 @@ struct wireless_dev;#define HAVE_FREE_NETDEV /* free_netdev() */ #define HAVE_NETDEV_PRIV /* netdev_priv() */ -#define NET_XMIT_SUCCESS 0 -#define NET_XMIT_DROP 1/* skb dropped */ -#define NET_XMIT_CN 2/* congestion notification */ -#define NET_XMIT_POLICED 3/* skb is shot by police */ -#define NET_XMIT_MASK 0xFFFF/* qdisc flags in net/sch_generic.h */ +/* +* Transmit return codes: transmit return codes originate from three different +* namespaces: +* +* - qdisc return codes +* - driver transmit return codes +* - errno values +* +* Drivers are allowed to return any one of those in their hard_start_xmit() +* function. Real network devices commonly used with qdiscs should only return +* the driver transmit return codes though - when qdiscs are used, the actual +* transmission happens asynchronously, so the value is not propagated to +* higher layers. Virtual network devices transmit synchronously, in this case +* the driver transmit return codes are consumed by dev_queue_xmit(), all +* others are propagated to higher layers. +*/ + +/* qdisc ->enqueue() return codes. */ +#define NET_XMIT_SUCCESS 0x00 +#define NET_XMIT_DROP 0x10/* skb dropped */ +#define NET_XMIT_CN 0x20/* congestion notification */ +#define NET_XMIT_POLICED 0x30/* skb is shot by police */ +#define NET_XMIT_MASK 0xf0/* qdisc flags in net/sch_generic.h */ + +/* Driver transmit return codes */ +#define NETDEV_TX_OK 0x0/* driver took care of packet */ +#define NETDEV_TX_BUSY 0x1/* driver tx path was busy*/ +#define NETDEV_TX_LOCKED 0x2/* driver tx lock was already taken */ +#define NETDEV_TX_MASK 0xf/* Backlog congestion levels */ #define NET_RX_SUCCESS 0/* keep 'em coming, baby */
@@ -87,11 +111,6 @@ struct wireless_dev;#define MAX_ADDR_LEN 32/* Largest hardware address length */ -/* Driver transmit return codes */ -#define NETDEV_TX_OK 0/* driver took care of packet */ -#define NETDEV_TX_BUSY 1/* driver tx path was busy*/ -#define NETDEV_TX_LOCKED -1/* driver tx lock was already taken */ -#ifdef __KERNEL__/*
net/core/dev.c +5 -2
@@ -1731,6 +1731,8 @@ gso: nskb->next =NULL ; rc = ops->ndo_start_xmit (nskb, dev);if (unlikely (rc)) { +if (rc & ~NETDEV_TX_MASK ) +return rc; nskb->next = skb->next; skb->next = nskb;return rc;
@@ -1895,8 +1897,9 @@ gso:HARD_TX_LOCK (dev, txq, cpu);if (!netif_tx_queue_stopped (txq)) { - rc =0 ; -if (!dev_hard_start_xmit (skb, dev, txq)) { + rc =dev_hard_start_xmit (skb, dev, txq); +if (rc ==NETDEV_TX_OK || rc <0 || + rc &NET_XMIT_MASK ) {HARD_TX_UNLOCK (dev, txq); goto out; }
net/sched/sch_generic.c +9 -1
@@ -143,8 +143,16 @@ static inline int qdisc_restart(struct Qdisc *q)HARD_TX_LOCK (dev, txq,smp_processor_id ());if (!netif_tx_queue_stopped (txq) && - !netif_tx_queue_frozen (txq)) + !netif_tx_queue_frozen (txq)) { ret =dev_hard_start_xmit (skb, dev, txq); + +/* an error implies that the skb was consumed */ +if (ret <0 ) + ret =NETDEV_TX_OK ; + +/* all NET_XMIT codes map to NETDEV_TX_OK */ + ret &= ~NET_XMIT_MASK ; + }HARD_TX_UNLOCK (dev, txq);spin_lock (root_lock);
RFC 3/3 : propagate transmission state
In reply to Patrick McHardycommit b124eaaf852e982c7af9b130ee81cfc293ae30ff
Author: Patrick McHardy <[email protected]> Date: Tue Jun 9 18:01:11 2009 +0200
vlan: propagate transmission state
Propagate transmission state to upper layers and maintain error statistics.
net/8021q/vlan_dev.c +22 -7
@@ -292,6 +292,8 @@ static int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) {struct netdev_queue *txq =netdev_get_tx_queue (dev,0 );struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data); +unsigned int len; +int err;/* Handle non-VLAN frames if they are sent to us, for example by DHCP. *
@@ -317,19 +319,25 @@ static int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)vlan_dev_info (dev)->cnt_inc_headroom_on_tx++; } - txq->tx_packets++; - txq->tx_bytes += skb->len; - skb->dev =vlan_dev_info (dev)->real_dev; -dev_queue_xmit (skb); -return NETDEV_TX_OK ; + len = skb->len; + err =dev_queue_xmit (skb); +if (err ==NET_XMIT_SUCCESS ) { + txq->tx_packets++; + txq->tx_bytes += len; + }else + txq->tx_dropped++; + +return err; }static int vlan_dev_hwaccel_hard_start_xmit (struct sk_buff *skb,struct net_device *dev) {struct netdev_queue *txq =netdev_get_tx_queue (dev,0 ); +unsigned int len;u16 vlan_tci; +int err; vlan_tci =vlan_dev_info (dev)->vlan_id; vlan_tci |=vlan_dev_get_egress_qos_mask (dev, skb);
@@ -339,8 +347,15 @@ static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, txq->tx_bytes += skb->len; skb->dev =vlan_dev_info (dev)->real_dev; -dev_queue_xmit (skb); -return NETDEV_TX_OK ; + len = skb->len; + err =dev_queue_xmit (skb); +if (err ==NET_XMIT_SUCCESS ) { + txq->tx_packets++; + txq->tx_bytes += len; + }else + txq->tx_dropped++; + +return err; }static int vlan_dev_change_mtu (struct net_device *dev,int new_mtu)
Re: [RFC vlan 03/03]: propagate transmission state
Quoted 55 lines · Patrick McHardy
commit
b124eaaf852e982c7af9b130ee81cfc293ae30ffAuthor: Patrick McHardy <[email protected]> Date: Tue Jun 9 18:01:11 2009 +0200vlan: propagate transmission state
Propagate transmission state to upper layers and maintain error statistics.
Signed-off-by Patrick McHardy <[email protected]>net/8021q/vlan_dev.c +13
-5@@ -292,6 +292,8 @@ static int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) {struct netdev_queue *txq =netdev_get_tx_queue (dev,0 );struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data); +unsigned int len; +int err;/* Handle non-VLAN frames if they are sent to us, for example by DHCP. * @@ -317,19 +319,25 @@ static int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)vlan_dev_info (dev)->cnt_inc_headroom_on_tx++; } - txq->tx_packets++; - txq->tx_bytes += skb->len; - skb->dev =vlan_dev_info (dev)->real_dev; -dev_queue_xmit (skb); -return NETDEV_TX_OK ; + len = skb->len; + err =dev_queue_xmit (skb); +if (err ==NET_XMIT_SUCCESS ) { + txq->tx_packets++; + txq->tx_bytes += len; + }else + txq->tx_dropped++; + +return err; }static int vlan_dev_hwaccel_hard_start_xmit (struct sk_buff *skb,struct net_device *dev) {struct netdev_queue *txq =netdev_get_tx_queue (dev,0 ); +unsigned int len;u16 vlan_tci; +int err; vlan_tci =vlan_dev_info (dev)->vlan_id; vlan_tci |=vlan_dev_get_egress_qos_mask (dev, skb);
net/8021q/vlan_dev.c static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, · line 347
Quoted 1 line
net/8021q/vlan_dev.c +0
-0@@ -339,8 +347,15 @@ static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, txq->tx_bytes += skb->len;
It seems you forgot to delete previous txq->tx_bytes += skb->len; && txq->tx_packets++; ?
Quoted 16 lines
net/8021q/vlan_dev.c +9
-2skb->dev =vlan_dev_info (dev)->real_dev; -dev_queue_xmit (skb); -return NETDEV_TX_OK ; + len = skb->len; + err =dev_queue_xmit (skb); +if (err ==NET_XMIT_SUCCESS ) { + txq->tx_packets++; + txq->tx_bytes += len; + }else + txq->tx_dropped++; + +return err; }static int vlan_dev_change_mtu (struct net_device *dev,int new_mtu)
Re: [RFC vlan 03/03]: propagate transmission state
Quoted 9 lines · Eric Dumazet
Quoted 8 lines · Patrick McHardy
static int vlan_dev_hwaccel_hard_start_xmit(struct
sk_buff*skb,net/8021q/vlan_dev.c +2
-0struct net_device *dev) {struct netdev_queue *txq =netdev_get_tx_queue (dev,0 ); +unsigned int len;u16 vlan_tci; +int err;
Quoted 6 lines
net/8021q/vlan_dev.c static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, · line 347
Quoted 4 lines
net/8021q/vlan_dev.c +0
-0vlan_tci =vlan_dev_info (dev)->vlan_id; vlan_tci |=vlan_dev_get_egress_qos_mask (dev, skb);@@ -339,8 +347,15 @@ static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, txq->tx_bytes += skb->len;It seems you forgot to delete previous
txq->tx_bytes+=skb->len; && txq->tx_packets++; ?
Indeed, thanks, I've fixed it in my tree.
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Tue, 9 Jun 2009 18:16:59 +0200 (MEST)
Quoted 16 lines
Currently the ->ndo_hard_start_xmit() callbacks are only permitted to return one of the
NETDEV_TXcodes. This prevents any kind of error propagation for virtual devices, like queue congestion of the underlying device in case of layered devices, or unreachability in case of tunnels.These patches change the return conventions so
hard_start_xmit()can return aNETDEV_TXcode, an errno code or aNET_XMITcode. This means it can additionally to theNETDEV_TXcodes simply return the value ofdev_queue_xmit().When queueing is used, errors can't be propagated back since transmission is asynchronously and all non-NETDEV codes are mapped to
NETDEV_TX_OK, reflecting the fact that the skb is consumed unconditionally.In case of virtual devices not using queueing, the
NETDEV_TXcodes are consumed bydev_queue_xmit(), everything else is returned to the higher layers.
Quoted 8 lines
The end result is that virtual network devices can propagate queue congestion state of the underlying device, or other errors, back to the socket layer. One immediately useful effect is that TCP can make use of this information as is currently done with non-virtual devices. But it also seems useful in case of tunnels, which can return more meaningful errors, or for statistics.
Comments welcome. A review of my changes in
dev_hard_start_xmit()would be especially appreciated :)
These changes look fine to me.
That one if() conditional checking 'ret' for three different properties is stretching the brain a bit. Maybe you can encapsulate that sucker into an inline function with suitable comments. That way when someone reads the test, it just says what it is looking for, rather than being some complicated set of tests.
Once you fix that up and the problem Eric spotted in patch #3 feel free to formally submit this.
Thanks!
Quoted 13 lines · David Miller
From: Patrick McHardy <[email protected]>
Date: Tue, 9 Jun 2009 18:16:59 +0200 (MEST)Quoted 9 lines
Currently the ->ndo_hard_start_xmit() callbacks are only permitted to return one of the
NETDEV_TXcodes. This prevents any kind of error propagation for virtual devices, like queue congestion of the underlying device in case of layered devices, or unreachability in case of tunnels.These patches change the return conventions so
hard_start_xmit()can return aNETDEV_TXcode, an errno code or aNET_XMITcode. This means it can additionally to theNETDEV_TXcodes simply return the value ofdev_queue_xmit().
Quoted 8 lines
These changes look fine to me.
That one
if()conditional checking 'ret' for three different properties is stretching the brain a bit. Maybe you can encapsulate that sucker into an inline function with suitable comments. That way when someone reads the test, it just says what it is looking for, rather than being some complicated set of tests.
Yeah, I mainly failed to come up with a suitable name, but I've now moved it to an inline function called "dev_xmit_skb_consumed". Better suggestions are still welcome though :)
Quoted 2 lines
Once you fix that up and the problem Eric spotted in patch #3 feel free to formally submit this.
I still need to verify that no drivers are using the raw values for the NETDEV_TX codes since NETDEV_TX_LOCKED is using a different value with my patch. I'll probably submit them later today.
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Thu, 11 Jun 2009 18:33:26 +0200
Quoted 3 lines
I still need to verify that no drivers are using the raw values for the
NETDEV_TXcodes sinceNETDEV_TX_LOCKEDis using a different value with my patch.
Yeah, auditing 500 ->hard_start_xmit implementations is fun.
Quoted 11 lines · David Miller
From: Patrick McHardy <[email protected]>
Date: Thu, 11 Jun 2009 18:33:26 +0200Quoted 4 lines
I still need to verify that no drivers are using the raw values for the
NETDEV_TXcodes sinceNETDEV_TX_LOCKEDis using a different value with my patch.Yeah, auditing 500 ->hard_start_xmit implementations is fun.
Indeed. Found about 30 which are already returning errno codes :)
Re: [RFC net 02/03]: allow to propagate errors through ->ndo_hard_start_xmit()
In reply to Patrick McHardyQuoted 6 lines · Patrick McHardy
commit
c2104095c3a1023b4f4809c90092145dff093c88Author: Patrick McHardy <[email protected]> Date: Tue Jun 9 17:55:34 2009 +0200net: allow to propagate errors through ->ndo_hard_start_xmit()
...
net/core/dev.c gso: · line 1735
Quoted 10 lines
net/core/dev.c +2
-0@@ -1731,6 +1731,8 @@ gso: nskb->next =NULL ; rc = ops->ndo_start_xmit (nskb, dev);if (unlikely (rc)) { +if (rc & ~NETDEV_TX_MASK ) +return rc;
This is probably not enough: what about the rest of the skb (qdisc_restart() would skip requeuing)?
Jarek P.
Quoted 42 lines
net/core/dev.c +3
-2nskb->next = skb->next; skb->next = nskb;return rc;@@ -1895,8 +1897,9 @@ gso:HARD_TX_LOCK (dev, txq, cpu);if (!netif_tx_queue_stopped (txq)) { - rc =0 ; -if (!dev_hard_start_xmit (skb, dev, txq)) { + rc =dev_hard_start_xmit (skb, dev, txq); +if (rc ==NETDEV_TX_OK || rc <0 || + rc &NET_XMIT_MASK ) {HARD_TX_UNLOCK (dev, txq); goto out; }net/sched/sch_generic.c +9
-2@@ -143,8 +143,16 @@ static inline int qdisc_restart(struct Qdisc *q)HARD_TX_LOCK (dev, txq,smp_processor_id ());if (!netif_tx_queue_stopped (txq) && - !netif_tx_queue_frozen (txq)) + !netif_tx_queue_frozen (txq)) { ret =dev_hard_start_xmit (skb, dev, txq); + +/* an error implies that the skb was consumed */ +if (ret <0 ) + ret =NETDEV_TX_OK ; + +/* all NET_XMIT codes map to NETDEV_TX_OK */ + ret &= ~NET_XMIT_MASK ; + }HARD_TX_UNLOCK (dev, txq);spin_lock (root_lock); --To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC net 02/03]: allow to propagate errors through ->ndo_hard_start_xmit()
Quoted 8 lines · Jarek Poplawski
Quoted 6 lines · Patrick McHardy
commit
c2104095c3a1023b4f4809c90092145dff093c88Author: Patrick McHardy <[email protected]> Date: Tue Jun 9 17:55:34 2009 +0200net: allow to propagate errors through ->ndo_hard_start_xmit()...
Quoted 13 lines
net/core/dev.c gso: · line 1735
Quoted 10 lines
net/core/dev.c +2
-0@@ -1731,6 +1731,8 @@ gso: nskb->next =NULL ; rc = ops->ndo_start_xmit (nskb, dev);if (unlikely (rc)) { +if (rc & ~NETDEV_TX_MASK ) +return rc;This is probably not enough: what about the rest of the skb (
qdisc_restart()would skip requeuing)?
Good point, I guess we should drop the remaining parts. I'll fix that up, thanks.