pf_packet fix
Subsystems (13)
cover pf_packet fix
Addressed all feedback from Dave and reworked the original patch from [1]. Set is intended for 3.14.
Thanks !
[1] http://patchwork.ozlabs.org/patch/320136/
Daniel Borkmann (3):
netdevice: add queue selection fallback handler for ndo_select_queue
netdevice: move netdev_cap_txqueue for shared usage to header
packet: check for ndo_select_queue during queue selection
drivers/net/bonding/bond_main.c | 2 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 4 ++-- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h | 2 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 6 ++--- drivers/net/ethernet/lantiq_etop.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_tx.c | 4 ++-- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 2 +- drivers/net/ethernet/tile/tilegx.c | 2 +- drivers/net/team/team.c | 2 +- drivers/net/tun.c | 2 +- drivers/net/wireless/mwifiex/main.c | 2 +- drivers/staging/bcm/Bcmnet.c | 2 +- drivers/staging/netlogic/xlr_net.c | 2 +- drivers/staging/rtl8188eu/os_dep/os_intfs.c | 2 +- include/linux/netdevice.h | 29 ++++++++++++++++++++++--- net/core/flow_dissector.c | 20 ++++------------- net/mac80211/iface.c | 6 +++-- net/packet/af_packet.c | 24 +++++++++++++++++--- 18 files changed, 73 insertions(+), 42 deletions(-)
Signature · 1 line
1.7.11.7
PATCH 1/3 netdevice: add queue selection fallback handler for ndo_select_queue
Add a new argument for ndo_select_queue() callback that passes a fallback handler. This gets invoked through netdev_pick_tx(); fallback handler is currently __netdev_pick_tx() as most drivers invoke this function within their customized implementation in case for skbs that don't need any special handling. This fallback handler can then be replaced on other call-sites with different queue selection methods (e.g. in packet sockets, pktgen etc).
This also has the nice side-effect that __netdev_pick_tx() is then only invoked from netdev_pick_tx() and export of that function to modules can be undone.
--- drivers/net/bonding/bond_main.c | 2 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 4 ++-- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h | 2 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 6 +++--- drivers/net/ethernet/lantiq_etop.c | 2 +- drivers/net/ethernet/mellanox/mlx4/en_tx.c | 4 ++-- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 2 +- drivers/net/ethernet/tile/tilegx.c | 2 +- drivers/net/team/team.c | 2 +- drivers/net/tun.c | 2 +- drivers/net/wireless/mwifiex/main.c | 2 +- drivers/staging/bcm/Bcmnet.c | 2 +- drivers/staging/netlogic/xlr_net.c | 2 +- drivers/staging/rtl8188eu/os_dep/os_intfs.c | 2 +- include/linux/netdevice.h | 9 ++++++--- net/core/flow_dissector.c | 7 +++---- net/mac80211/iface.c | 6 ++++-- 17 files changed, 31 insertions(+), 27 deletions(-)
drivers/net/bonding/bond_main.c +1 -1
@@ -3707,7 +3707,7 @@ static inline int bond_slave_override(struct bonding *bond,static u16 bond_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {/* * This helper function exists to help dev_pick_tx get the correct
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +2 -2
@@ -1873,7 +1873,7 @@ void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw) }u16 bnx2x_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {struct bnx2x *bp =netdev_priv (dev);
@@ -1895,7 +1895,7 @@ u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb, }/* select a non-FCoE queue */ -return __netdev_pick_tx (dev, skb) %BNX2X_NUM_ETH_QUEUES (bp); +return fallback (dev, skb) %BNX2X_NUM_ETH_QUEUES (bp); }void bnx2x_set_num_queues (struct bnx2x *bp)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h +1 -1
@@ -496,7 +496,7 @@ int bnx2x_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos);/* select_queue callback */ u16 bnx2x_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv); +void *accel_priv,select_queue_fallback_t fallback); static inline void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -3
@@ -6881,7 +6881,7 @@ static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) }static u16 ixgbe_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;#ifdef IXGBE_FCOE
@@ -6907,7 +6907,7 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,if (adapter->flags &IXGBE_FLAG_FCOE_ENABLED )break ;default : -return __netdev_pick_tx (dev, skb); +return fallback (dev, skb); } f = &adapter->ring_feature[RING_F_FCOE ];
@@ -6920,7 +6920,7 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,return txq + f->offset;#else -return __netdev_pick_tx (dev, skb); +return fallback (dev, skb);#endif }
drivers/net/ethernet/lantiq_etop.c +1 -1
@@ -619,7 +619,7 @@ ltq_etop_set_multicast_list(struct net_device *dev)static u16 ltq_etop_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {/* we are currently only using the first queue */ return 0 ;
drivers/net/ethernet/mellanox/mlx4/en_tx.c +2 -2
@@ -629,7 +629,7 @@ static void build_inline_wqe(struct mlx4_en_tx_desc *tx_desc, struct sk_buff *sk }u16 mlx4_en_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {struct mlx4_en_priv *priv =netdev_priv (dev);u16 rings_p_up = priv->num_tx_rings_p_up;
@@ -641,7 +641,7 @@ u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,if (vlan_tx_tag_present (skb)) up =vlan_tx_tag_get (skb) >>VLAN_PRIO_SHIFT ; -return __netdev_pick_tx (dev, skb) % rings_p_up + up * rings_p_up; +return fallback (dev, skb) % rings_p_up + up * rings_p_up; }static void mlx4_bf_copy (void __iomem *dst,unsigned long *src,unsigned bytecnt)
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +1 -1
@@ -723,7 +723,7 @@ int mlx4_en_arm_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq);void mlx4_en_tx_irq (struct mlx4_cq *mcq);u16 mlx4_en_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv); +void *accel_priv,select_queue_fallback_t fallback);netdev_tx_t mlx4_en_xmit (struct sk_buff *skb,struct net_device *dev); int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
drivers/net/ethernet/tile/tilegx.c +1 -1
@@ -2071,7 +2071,7 @@ static int tile_net_tx(struct sk_buff *skb, struct net_device *dev)/* Return subqueue id on this core (one per core). */ static u16 tile_net_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {return smp_processor_id (); }
drivers/net/team/team.c +1 -1
@@ -1648,7 +1648,7 @@ static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev) }static u16 team_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {/* * This helper function exists to help dev_pick_tx get the correct
drivers/net/tun.c +1 -1
@@ -366,7 +366,7 @@ static inline void tun_flow_save_rps_rxhash(struct tun_flow_entry *e, u32 hash)* hope the rxq no. may help here. */ static u16 tun_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {struct tun_struct *tun =netdev_priv (dev);struct tun_flow_entry *e;
drivers/net/wireless/mwifiex/main.c +1 -1
@@ -748,7 +748,7 @@ static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)static u16 mwifiex_netdev_select_wmm_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) { skb->priority =cfg80211_classify8021d (skb,NULL );return mwifiex_1d_to_wmm_queue[skb->priority];
drivers/staging/bcm/Bcmnet.c +1 -1
@@ -40,7 +40,7 @@ static INT bcm_close(struct net_device *dev) }static u16 bcm_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {return ClassifyPacket (netdev_priv (dev), skb); }
drivers/staging/netlogic/xlr_net.c +1 -1
@@ -307,7 +307,7 @@ static netdev_tx_t xlr_net_start_xmit(struct sk_buff *skb, }static u16 xlr_net_select_queue (struct net_device *ndev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {return (u16 )smp_processor_id (); }
drivers/staging/rtl8188eu/os_dep/os_intfs.c +1 -1
@@ -653,7 +653,7 @@ static unsigned int rtw_classify8021d(struct sk_buff *skb) }static u16 rtw_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv,select_queue_fallback_t fallback) {struct adapter *padapter =rtw_netdev_priv (dev);struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
include/linux/netdevice.h +6 -3
@@ -752,6 +752,9 @@ struct netdev_phys_port_id {unsigned char id_len; }; +typedef u16 (*select_queue_fallback_t )(struct net_device *dev, +struct sk_buff *skb); +/* * This structure defines the management hooks for network devices. * The following hooks can be defined; unless noted otherwise, they are
@@ -783,7 +786,7 @@ struct netdev_phys_port_id {* Required can not be NULL. * * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb, -* void *accel_priv); +* void *accel_priv, select_queue_fallback_t fallback); * Called to decide which queue to when device supports multiple * transmit queues. *
@@ -1005,7 +1008,8 @@ struct net_device_ops { struct net_device *dev);u16 (*ndo_select_queue)(struct net_device *dev,struct sk_buff *skb, -void *accel_priv); +void *accel_priv, +select_queue_fallback_t fallback);void (*ndo_change_rx_flags)(struct net_device *dev,int flags);void (*ndo_set_rx_mode)(struct net_device *dev);
@@ -1551,7 +1555,6 @@ static inline void netdev_for_each_tx_queue(struct net_device *dev,struct netdev_queue *netdev_pick_tx (struct net_device *dev,struct sk_buff *skb,void *accel_priv); -u16 __netdev_pick_tx (struct net_device *dev,struct sk_buff *skb);/* * Net namespace inlines
net/core/flow_dissector.c +3 -4
@@ -372,7 +372,7 @@ static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb)#endif } -u16 __netdev_pick_tx (struct net_device *dev,struct sk_buff *skb) +static u16 __netdev_pick_tx (struct net_device *dev,struct sk_buff *skb) {struct sock *sk = skb->sk;int queue_index =sk_tx_queue_get (sk);
@@ -392,7 +392,6 @@ u16 __netdev_pick_tx(struct net_device *dev, struct sk_buff *skb)return queue_index; } -EXPORT_SYMBOL (__netdev_pick_tx); struct netdev_queue *netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
@@ -403,8 +402,8 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev,if (dev->real_num_tx_queues !=1 ) {const struct net_device_ops *ops = dev->netdev_ops;if (ops->ndo_select_queue) - queue_index = ops->ndo_select_queue (dev, skb, - accel_priv); + queue_index = ops->ndo_select_queue (dev, skb, accel_priv, + __netdev_pick_tx);else queue_index =__netdev_pick_tx (dev, skb);
net/mac80211/iface.c +4 -2
@@ -1057,7 +1057,8 @@ static void ieee80211_uninit(struct net_device *dev)static u16 ieee80211_netdev_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv, +select_queue_fallback_t fallback) {return ieee80211_select_queue (IEEE80211_DEV_TO_SUB_IF (dev), skb); }
@@ -1075,7 +1076,8 @@ static const struct net_device_ops ieee80211_dataif_ops = {static u16 ieee80211_monitor_select_queue (struct net_device *dev,struct sk_buff *skb, -void *accel_priv) +void *accel_priv, +select_queue_fallback_t fallback) {struct ieee80211_sub_if_data *sdata =IEEE80211_DEV_TO_SUB_IF (dev);struct ieee80211_local *local = sdata->local;
Signature · 1 line
1.7.11.7
PATCH 2/3 netdevice: move netdev_cap_txqueue for shared usage to header
In reply to Daniel BorkmannIn order to allow users to invoke netdev_cap_txqueue, it needs to be moved into netdevice.h header file. While at it, also add kernel doc header to document the API.
--- include/linux/netdevice.h | 20 ++++++++++++++++++++ net/core/flow_dissector.c | 13 +------------ 2 files changed, 21 insertions(+), 12 deletions(-)
include/linux/netdevice.h +20 -0
@@ -2279,6 +2279,26 @@ static inline void netdev_reset_queue(struct net_device *dev_queue) }/** +* netdev_cap_txqueue - check if selected tx queue exceeds device queues +* @dev: network device +* @queue_index: given tx queue index +* +* Returns 0 if given tx queue index >= number of device tx queues, +* otherwise returns the originally passed tx queue index. +*/ +static inline u16 netdev_cap_txqueue (struct net_device *dev,u16 queue_index) +{ +if (unlikely (queue_index >= dev->real_num_tx_queues)) { +net_warn_ratelimited ("%s selects TX queue %d, but real number of TX queues is %d\n" , + dev->name, queue_index, + dev->real_num_tx_queues); +return 0 ; + } + +return queue_index; +} + +/** * netif_running - test if up * @dev: network device *
net/core/flow_dissector.c +1 -12
@@ -323,17 +323,6 @@ u32 __skb_get_poff(const struct sk_buff *skb)return poff; } -static inline u16 dev_cap_txqueue (struct net_device *dev,u16 queue_index) -{ -if (unlikely (queue_index >= dev->real_num_tx_queues)) { -net_warn_ratelimited ("%s selects TX queue %d, but real number of TX queues is %d\n" , - dev->name, queue_index, - dev->real_num_tx_queues); -return 0 ; - } -return queue_index; -} -static inline int get_xps_queue (struct net_device *dev,struct sk_buff *skb) {#ifdef CONFIG_XPS
@@ -408,7 +397,7 @@ struct netdev_queue *netdev_pick_tx(struct net_device *dev, queue_index =__netdev_pick_tx (dev, skb);if (!accel_priv) - queue_index =dev_cap_txqueue (dev, queue_index); + queue_index =netdev_cap_txqueue (dev, queue_index); }skb_set_queue_mapping (skb, queue_index);
Signature · 1 line
1.7.11.7
PATCH 3/3 packet: check for ndo_select_queue during queue selection
In reply to Daniel BorkmannMathias reported that on an AMD Geode LX embedded board (ALiX) with ath9k driver PACKET_QDISC_BYPASS, introduced in commit d346a3fae3ff ("packet: introduce PACKET_QDISC_BYPASS socket option"), triggers a WARN_ON() coming from the driver itself via 066dae93bdf ("ath9k: rework tx queue selection and fix queue stopping/waking").
The reason why this happened is that ndo_select_queue() call is not invoked from direct xmit path i.e. for ieee80211 subsystem that sets queue and TID (similar to 802.1d tag) which is being put into the frame through 802.11e (WMM, QoS). If that is not set, pending frame counter for e.g. ath9k can get messed up.
So the WARN_ON() in ath9k is absolutely legitimate. Generally, the hw queue selection in ieee80211 depends on the type of traffic, and priorities are set according to ieee80211_ac_numbers mapping; working in a similar way as DiffServ only on a lower layer, so that the AP can favour frames that have "real-time" requirements like voice or video data frames.
Therefore, check for presence of ndo_select_queue() in netdev ops and, if available, invoke it with a fallback handler to __packet_pick_tx_queue(), so that driver such as bnx2x, ixgbe, or mlx4 can still select a hw queue for transmission in relation to the current CPU while e.g. ieee80211 subsystem can make their own choices.
--- net/packet/af_packet.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
net/packet/af_packet.c +21 -3
@@ -308,11 +308,27 @@ static bool packet_use_direct_xmit(const struct packet_sock *po)return po->xmit == packet_direct_xmit; } -static u16 packet_pick_tx_queue (struct net_device *dev) +static u16 __packet_pick_tx_queue (struct net_device *dev,struct sk_buff *skb) {return (u16 )raw_smp_processor_id () % dev->real_num_tx_queues; } +static void packet_pick_tx_queue (struct net_device *dev,struct sk_buff *skb) +{ +const struct net_device_ops *ops = dev->netdev_ops; +u16 queue_index; + +if (ops->ndo_select_queue) { + queue_index = ops->ndo_select_queue (dev, skb,NULL , + __packet_pick_tx_queue); + queue_index =netdev_cap_txqueue (dev, queue_index); + }else { + queue_index =__packet_pick_tx_queue (dev, skb); + } + +skb_set_queue_mapping (skb, queue_index); +} +/* register_prot_hook must be invoked with the po->bind_lock held, * or from a context in which asynchronous accesses to the packet * socket is not possible (packet_create()).
@@ -2285,7 +2301,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) } } -skb_set_queue_mapping (skb,packet_pick_tx_queue (dev)); +packet_pick_tx_queue (dev, skb); + skb->destructor = tpacket_destruct_skb;__packet_set_status (po, ph,TP_STATUS_SENDING );packet_inc_pending (&po->tx_ring);
@@ -2499,7 +2516,8 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) skb->dev = dev; skb->priority = sk->sk_priority; skb->mark = sk->sk_mark; -skb_set_queue_mapping (skb,packet_pick_tx_queue (dev)); + +packet_pick_tx_queue (dev, skb);if (po->has_vnet_hdr) {if (vnet_hdr.flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) {
Signature · 1 line
1.7.11.7
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Sun, 16 Feb 2014 15:55:19 +0100
Quoted 2 lines
Addressed all feedback from Dave and reworked the original patch from [1]. Set is intended for 3.14.
Looks great, series applied, thanks Daniel.
Quoted 8 lines · David Miller
From: Daniel Borkmann <[email protected]>
Date: Sun, 16 Feb 2014 15:55:19 +0100Quoted 2 lines
Addressed all feedback from Dave and reworked the original patch from [1]. Set is intended for 3.14.
Looks great, series applied, thanks Daniel.
Initial feedback (linux-3.14-rc3 + your patches):
The WARNING from within 80211 is gone.
A more extensive evaluation is still pending.
Thanks,
Mathias