net/fq_impl: bulk-free packets from a flow on overmemory
Subsystems (2)
PATCH v2 1/6 net/fq_impl: bulk-free packets from a flow on overmemory
This is similar to what sch_fq_codel does. It also amortizes the worst case cost of a follow-up patch that changes the selection of the biggest flow for dropping packets
--- include/net/fq_impl.h | 55 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 11 deletions(-)
include/net/fq_impl.h +44 -11
@@ -11,17 +11,25 @@/* functions that are embedded into includer */ + +static void +__fq_adjust_removal (struct fq *fq,struct fq_flow *flow,unsigned int packets, +unsigned int bytes,unsigned int truesize) +{ +struct fq_tin *tin = flow->tin; + + tin->backlog_bytes -= bytes; + tin->backlog_packets -= packets; + flow->backlog -= bytes; + fq->backlog -= packets; + fq->memory_usage -= truesize; +} +static void fq_adjust_removal (struct fq *fq,struct fq_flow *flow,struct sk_buff *skb) { -struct fq_tin *tin = flow->tin; - - tin->backlog_bytes -= skb->len; - tin->backlog_packets--; - flow->backlog -= skb->len; - fq->backlog--; - fq->memory_usage -= skb->truesize; +__fq_adjust_removal (fq, flow,1 , skb->len, skb->truesize); }static void fq_rejigger_backlog (struct fq *fq,struct fq_flow *flow)
@@ -59,6 +67,34 @@ static struct sk_buff *fq_flow_dequeue(struct fq *fq,return skb; } +static int fq_flow_drop (struct fq *fq,struct fq_flow *flow, +fq_skb_free_t free_func) +{ +unsigned int packets =0 , bytes =0 , truesize =0 ; +struct fq_tin *tin = flow->tin; +struct sk_buff *skb; +int pending; + +lockdep_assert_held (&fq->lock); + + pending =min_t (int,32 ,skb_queue_len (&flow->queue) /2 ); +do { + skb =__skb_dequeue (&flow->queue); +if (!skb) +break ; + + packets++; + bytes += skb->len; + truesize += skb->truesize; +free_func (fq, tin, flow, skb); + }while (packets < pending); + +__fq_adjust_removal (fq, flow, packets, bytes, truesize); +fq_rejigger_backlog (fq, flow); + +return packets; +} +static struct sk_buff *fq_tin_dequeue (struct fq *fq,struct fq_tin *tin,fq_tin_dequeue_t dequeue_func)
@@ -190,12 +226,9 @@ static void fq_tin_enqueue(struct fq *fq,if (!flow)return ; - skb =fq_flow_dequeue (fq, flow); -if (!skb) +if (!fq_flow_drop (fq, flow, free_func))return ; -free_func (fq, flow->tin, flow, skb); - flow->tin->overlimit++; fq->overlimit++;if (oom) {
Signature · 1 line
2.28.0
PATCH v2 2/6 net/fq_impl: drop get_default_func, move default flow to fq_tin
Simplifies the code and prepares for a rework of scanning for flows on overmemory drop.
--- include/net/fq.h | 1 + include/net/fq_impl.h | 11 +++++------ net/mac80211/ieee80211_i.h | 1 - net/mac80211/tx.c | 22 ++++------------------ 4 files changed, 10 insertions(+), 25 deletions(-)
include/net/fq.h +1 -0
@@ -47,6 +47,7 @@ struct fq_flow {struct fq_tin {struct list_head new_flows;struct list_head old_flows; +struct fq_flow default_flow;u32 backlog_bytes;u32 backlog_packets;u32 overlimit;
include/net/fq_impl.h +5 -6
@@ -151,8 +151,7 @@ static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb)static struct fq_flow *fq_flow_classify (struct fq *fq,struct fq_tin *tin,u32 idx, -struct sk_buff *skb, -fq_flow_get_default_t get_default_func) +struct sk_buff *skb) {struct fq_flow *flow;
@@ -160,7 +159,7 @@ static struct fq_flow *fq_flow_classify(struct fq *fq, flow = &fq->flows[idx];if (flow->tin && flow->tin != tin) { - flow =get_default_func (fq, tin, idx, skb); + flow = &tin->default_flow; tin->collisions++; fq->collisions++; }
@@ -192,15 +191,14 @@ static void fq_recalc_backlog(struct fq *fq,static void fq_tin_enqueue (struct fq *fq,struct fq_tin *tin,u32 idx,struct sk_buff *skb, -fq_skb_free_t free_func, -fq_flow_get_default_t get_default_func) +fq_skb_free_t free_func) {struct fq_flow *flow;bool oom;lockdep_assert_held (&fq->lock); - flow =fq_flow_classify (fq, tin, idx, skb, get_default_func); + flow =fq_flow_classify (fq, tin, idx, skb); flow->tin = tin; flow->backlog += skb->len;
@@ -331,6 +329,7 @@ static void fq_tin_init(struct fq_tin *tin) {INIT_LIST_HEAD (&tin->new_flows);INIT_LIST_HEAD (&tin->old_flows); +fq_flow_init (&tin->default_flow); }static int fq_init (struct fq *fq,int flows_cnt)
net/mac80211/ieee80211_i.h +0 -1
@@ -848,7 +848,6 @@ enum txq_info_flags {*/ struct txq_info {struct fq_tin tin; -struct fq_flow def_flow;struct codel_vars def_cvars;struct codel_stats cstats;struct sk_buff_head frags;
net/mac80211/tx.c +4 -18
@@ -1309,7 +1309,7 @@ static struct sk_buff *codel_dequeue_func(struct codel_vars *cvars, fq = &local->fq;if (cvars == &txqi->def_cvars) - flow = &txqi->def_flow; + flow = &txqi->tin.default_flow;else flow = &fq->flows[cvars - local->cvars];
@@ -1352,7 +1352,7 @@ static struct sk_buff *fq_tin_dequeue_func(struct fq *fq, cparams = &local->cparams; } -if (flow == &txqi->def_flow) +if (flow == &tin->default_flow) cvars = &txqi->def_cvars;else cvars = &local->cvars[flow - fq->flows];
@@ -1379,17 +1379,6 @@ static void fq_skb_free_func(struct fq *fq,ieee80211_free_txskb (&local->hw, skb); } -static struct fq_flow *fq_flow_get_default_func (struct fq *fq, -struct fq_tin *tin, -int idx, -struct sk_buff *skb) -{ -struct txq_info *txqi; - - txqi = container_of(tin, struct txq_info, tin); -return &txqi->def_flow; -} -static void ieee80211_txq_enqueue (struct ieee80211_local *local,struct txq_info *txqi,struct sk_buff *skb)
@@ -1402,8 +1391,7 @@ static void ieee80211_txq_enqueue(struct ieee80211_local *local,spin_lock_bh (&fq->lock);fq_tin_enqueue (fq, tin, flow_idx, skb, - fq_skb_free_func, - fq_flow_get_default_func); + fq_skb_free_func);spin_unlock_bh (&fq->lock); }
@@ -1446,7 +1434,6 @@ void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata, struct txq_info *txqi, int tid) {fq_tin_init (&txqi->tin); -fq_flow_init (&txqi->def_flow);codel_vars_init (&txqi->def_cvars);codel_stats_init (&txqi->cstats);__skb_queue_head_init (&txqi->frags);
@@ -3283,8 +3270,7 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,*/ tin = &txqi->tin; - flow =fq_flow_classify (fq, tin, flow_idx, skb, - fq_flow_get_default_func); + flow =fq_flow_classify (fq, tin, flow_idx, skb); head =skb_peek_tail (&flow->queue);if (!head ||skb_is_gso (head)) goto out;
Signature · 1 line
2.28.0
PATCH v2 3/6 net/fq_impl: do not maintain a backlog-sorted list of flows
In reply to Felix FietkauA sorted flow list is only needed to drop packets in the biggest flow when hitting the overmemory condition.
By scanning flows only when needed, we can avoid paying the cost of maintaining the list under normal conditions
In order to avoid scanning lots of empty flows and touching too many cold cache lines, a bitmap of flows with backlog is maintained
--- include/net/fq.h | 10 ++-- include/net/fq_impl.h | 113 +++++++++++++++++++++++++----------------- net/mac80211/tx.c | 2 - 3 files changed, 71 insertions(+), 54 deletions(-)
include/net/fq.h +4 -6
@@ -19,8 +19,6 @@ struct fq_tin;* @flowchain: can be linked to fq_tin's new_flows or old_flows. Used for DRR++ * (deficit round robin) based round robin queuing similar to the one * found in net/sched/sch_fq_codel.c -* @backlogchain: can be linked to other fq_flow and fq. Used to keep track of -* fat flows and efficient head-dropping if packet limit is reached * @queue: sk_buff queue to hold packets * @backlog: number of bytes pending in the queue. The number of packets can be * found in @queue.qlen
@@ -29,7 +27,6 @@ struct fq_tin;struct fq_flow {struct fq_tin *tin;struct list_head flowchain; -struct list_head backlogchain;struct sk_buff_head queue;u32 backlog;int deficit;
@@ -47,6 +44,7 @@ struct fq_flow {struct fq_tin {struct list_head new_flows;struct list_head old_flows; +struct list_head tin_list;struct fq_flow default_flow;u32 backlog_bytes;u32 backlog_packets;
@@ -60,14 +58,14 @@ struct fq_tin {/** * struct fq - main container for fair queuing purposes * -* @backlogs: linked to fq_flows. Used to maintain fat flows for efficient -* head-dropping when @backlog reaches @limit * @limit: max number of packets that can be queued across all flows * @backlog: number of packets queued across all flows */ struct fq {struct fq_flow *flows; -struct list_head backlogs; +unsigned long *flows_bitmap; + +struct list_head tin_backlog;spinlock_t lock;u32 flows_cnt;u32 limit;
include/net/fq_impl.h +67 -46
225 lines not on this page · raw message
net/mac80211/tx.c +0 -2
@@ -3337,8 +3337,6 @@ static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,if (head->len != orig_len) { flow->backlog += head->len - orig_len; tin->backlog_bytes += head->len - orig_len; - -fq_recalc_backlog (fq, tin, flow); } out:spin_unlock_bh (&fq->lock);
Signature · 1 line
2.28.0
PATCH v2 4/6 mac80211: fix encryption key selection for 802.3 xmit
In reply to Felix FietkauWhen using WEP, the default unicast key needs to be selected, instead of the STA PTK.
--- net/mac80211/tx.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
net/mac80211/tx.c +15 -12
@@ -4235,7 +4235,6 @@ netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,struct ethhdr *ehdr = (struct ethhdr *)skb->data;struct ieee80211_key *key;struct sta_info *sta; -bool offload = true;if (unlikely (skb->len <ETH_HLEN )) {kfree_skb (skb);
@@ -4251,18 +4250,22 @@ netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,if (unlikely (IS_ERR_OR_NULL (sta) || !sta->uploaded || !test_sta_flag (sta,WLAN_STA_AUTHORIZED ) || - sdata->control_port_protocol == ehdr->h_proto)) - offload = false; -else if ((key =rcu_dereference (sta->ptk[sta->ptk_idx])) && - (!(key->flags &KEY_FLAG_UPLOADED_TO_HARDWARE ) || - key->conf.cipher ==WLAN_CIPHER_SUITE_TKIP )) - offload = false; - -if (offload) -ieee80211_8023_xmit (sdata, dev, sta, key, skb); -else -ieee80211_subif_start_xmit (skb, dev); + sdata->control_port_protocol == ehdr->h_proto)) + goto skip_offload; + + key =rcu_dereference (sta->ptk[sta->ptk_idx]); +if (!key) + key =rcu_dereference (sdata->default_unicast_key); + +if (key && (!(key->flags &KEY_FLAG_UPLOADED_TO_HARDWARE ) || + key->conf.cipher ==WLAN_CIPHER_SUITE_TKIP )) + goto skip_offload; + +ieee80211_8023_xmit (sdata, dev, sta, key, skb); + goto out; +skip_offload: +ieee80211_subif_start_xmit (skb, dev); out:rcu_read_unlock ();
Signature · 1 line
2.28.0
PATCH v2 5/6 mac80211: fix fast-rx encryption check
In reply to Felix FietkauWhen using WEP, the default unicast key needs to be selected, instead of the STA PTK.
--- net/mac80211/rx.c | 2 ++ 1 file changed, 2 insertions(+)
net/mac80211/rx.c +2 -0
@@ -4176,6 +4176,8 @@ void ieee80211_check_fast_rx(struct sta_info *sta)rcu_read_lock (); key =rcu_dereference (sta->ptk[sta->ptk_idx]); +if (!key) + key =rcu_dereference (sdata->default_unicast_key);if (key) {switch (key->conf.cipher) {case WLAN_CIPHER_SUITE_TKIP :
Signature · 1 line
2.28.0
PATCH v2 6/6 mac80211: add rx decapsulation offload support
In reply to Felix FietkauThis allows drivers to pass 802.3 frames to mac80211, with some restrictions:
- the skb must be passed with a valid sta
- fast-rx needs to be active for the sta
- monitor mode needs to be disabled
mac80211 will tell the driver when it is safe to enable rx decap offload for a particular station.
In order to implement support, a driver must:
- call ieee80211_hw_set(hw, SUPPORTS_RX_DECAP_OFFLOAD)
- implement ops->sta_set_decap_offload
- mark 802.3 frames with RX_FLAG_8023
If it doesn't want to enable offload for some vif types, it can mask out IEEE80211_OFFLOAD_DECAP_ENABLED in vif->offload_flags from within the .add_interface or .update_vif_offload driver ops
---
v2: rename ieee80211_iftype_supports_encap_offload to
ieee80211_iftype_supports_hdr_offload
include/net/mac80211.h | 16 +++ net/mac80211/debugfs.c | 1 + net/mac80211/debugfs_sta.c | 1 + net/mac80211/driver-ops.h | 16 +++ net/mac80211/iface.c | 17 ++- net/mac80211/rx.c | 243 ++++++++++++++++++++++++------------- net/mac80211/sta_info.h | 2 + net/mac80211/trace.h | 18 ++- 8 files changed, 225 insertions(+), 89 deletions(-)
include/net/mac80211.h +16 -0
@@ -1296,6 +1296,8 @@ ieee80211_tx_info_clear_status(struct ieee80211_tx_info *info)* the "0-length PSDU" field included there. The value for it is * in &struct ieee80211_rx_status. Note that if this value isn't * known the frame shouldn't be reported. +* @RX_FLAG_8023: the frame has an 802.3 header (decap offload performed by +* hardware or driver) */ enum mac80211_rx_flags {RX_FLAG_MMIC_ERROR =BIT (0 ),
@@ -1328,6 +1330,7 @@ enum mac80211_rx_flags {RX_FLAG_RADIOTAP_HE_MU =BIT (27 ),RX_FLAG_RADIOTAP_LSIG =BIT (28 ),RX_FLAG_NO_PSDU =BIT (29 ), + RX_FLAG_8023 = BIT(30), };/**
@@ -1649,11 +1652,15 @@ enum ieee80211_vif_flags {* The driver supports sending frames passed as 802.3 frames by mac80211. * It must also support sending 802.11 packets for the same interface. * @IEEE80211_OFFLOAD_ENCAP_4ADDR: support 4-address mode encapsulation offload +* @IEEE80211_OFFLOAD_DECAP_ENABLED: rx encapsulation offload is enabled +* The driver supports passing received 802.11 frames as 802.3 frames to +* mac80211. */ enum ieee80211_offload_flags {IEEE80211_OFFLOAD_ENCAP_ENABLED =BIT (0 ),IEEE80211_OFFLOAD_ENCAP_4ADDR =BIT (1 ), +IEEE80211_OFFLOAD_DECAP_ENABLED =BIT (2 ), };/**
@@ -2389,6 +2396,9 @@ struct ieee80211_txq {* @IEEE80211_HW_SUPPORTS_TX_ENCAP_OFFLOAD: Hardware supports tx encapsulation * offload * +* @IEEE80211_HW_SUPPORTS_RX_DECAP_OFFLOAD: Hardware supports rx decapsulation +* offload +* * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays */ enum ieee80211_hw_flags {
@@ -2442,6 +2452,7 @@ enum ieee80211_hw_flags {IEEE80211_HW_SUPPORTS_ONLY_HE_MULTI_BSSID ,IEEE80211_HW_AMPDU_KEYBORDER_SUPPORT ,IEEE80211_HW_SUPPORTS_TX_ENCAP_OFFLOAD , +IEEE80211_HW_SUPPORTS_RX_DECAP_OFFLOAD ,/* keep last, obviously */ NUM_IEEE80211_HW_FLAGS
@@ -3880,6 +3891,8 @@ enum ieee80211_reconfig_type {* This callback may sleep. * @sta_set_4addr: Called to notify the driver when a station starts/stops using * 4-address mode +* @sta_set_decap_offload: Called to notify the driver when a station is allowed +* to use rx decapsulation offload */ struct ieee80211_ops { void (*tx)(struct ieee80211_hw *hw,
@@ -4197,6 +4210,9 @@ struct ieee80211_ops { struct ieee80211_sta *sta, bool enabled);int (*set_sar_specs)(struct ieee80211_hw *hw,const struct cfg80211_sar_specs *sar); +void (*sta_set_decap_offload)(struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct ieee80211_sta *sta,bool enabled); };/**
net/mac80211/debugfs.c +1 -0
@@ -409,6 +409,7 @@ static const char *hw_flag_names[] = {FLAG (SUPPORTS_ONLY_HE_MULTI_BSSID ),FLAG (AMPDU_KEYBORDER_SUPPORT ),FLAG (SUPPORTS_TX_ENCAP_OFFLOAD ), +FLAG (SUPPORTS_RX_DECAP_OFFLOAD ), #undef FLAG };
net/mac80211/debugfs_sta.c +1 -0
@@ -79,6 +79,7 @@ static const char * const sta_flag_names[] = {FLAG (MPSP_RECIPIENT ),FLAG (PS_DELIVER ),FLAG (USES_ENCRYPTION ), +FLAG (DECAP_OFFLOAD ), #undef FLAG };
net/mac80211/driver-ops.h +16 -0
@@ -1413,4 +1413,20 @@ static inline void drv_sta_set_4addr(struct ieee80211_local *local, trace_drv_return_void(local); } +static inline void drv_sta_set_decap_offload (struct ieee80211_local *local, +struct ieee80211_sub_if_data *sdata, +struct ieee80211_sta *sta, +bool enabled) +{ + sdata =get_bss_sdata (sdata); +if (!check_sdata_in_driver (sdata)) +return ; + +trace_drv_sta_set_decap_offload (local, sdata, sta, enabled); +if (local->ops->sta_set_decap_offload) + local->ops->sta_set_decap_offload (&local->hw, &sdata->vif, sta, + enabled); +trace_drv_return_void (local); +} +#endif /* __MAC80211_DRIVER_OPS */
net/mac80211/iface.c +14 -3
@@ -765,7 +765,7 @@ static const struct net_device_ops ieee80211_dataif_8023_ops = { .ndo_get_stats64 = ieee80211_get_stats64, }; -static bool ieee80211_iftype_supports_encap_offload (enum nl80211_iftype iftype) +static bool ieee80211_iftype_supports_hdr_offload (enum nl80211_iftype iftype) {switch (iftype) {/* P2P GO and client are mapped to AP/STATION types */
@@ -785,7 +785,7 @@ static bool ieee80211_set_sdata_offload_flags(struct ieee80211_sub_if_data *sdat flags = sdata->vif.offload_flags;if (ieee80211_hw_check (&local->hw,SUPPORTS_TX_ENCAP_OFFLOAD ) && -ieee80211_iftype_supports_encap_offload (sdata->vif.type)) { +ieee80211_iftype_supports_hdr_offload (sdata->vif.type)) { flags |=IEEE80211_OFFLOAD_ENCAP_ENABLED ; if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG) &&
@@ -798,10 +798,21 @@ static bool ieee80211_set_sdata_offload_flags(struct ieee80211_sub_if_data *sdat flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED ; } +if (ieee80211_hw_check (&local->hw,SUPPORTS_RX_DECAP_OFFLOAD ) && +ieee80211_iftype_supports_hdr_offload (sdata->vif.type)) { + flags |=IEEE80211_OFFLOAD_DECAP_ENABLED ; + +if (local->monitors) + flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED ; + }else { + flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED ; + } +if (sdata->vif.offload_flags == flags)return false; sdata->vif.offload_flags = flags; +ieee80211_check_fast_rx_iface (sdata);return true; }
@@ -819,7 +830,7 @@ static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata) }if (!ieee80211_hw_check (&local->hw,SUPPORTS_TX_ENCAP_OFFLOAD ) || - !ieee80211_iftype_supports_encap_offload (bss->vif.type)) + !ieee80211_iftype_supports_hdr_offload (bss->vif.type))return ; enabled = bss->vif.offload_flags &IEEE80211_OFFLOAD_ENCAP_ENABLED ;
net/mac80211/rx.c +158 -85
307 lines not on this page · raw message
net/mac80211/sta_info.h +2 -0
@@ -71,6 +71,7 @@* until pending frames are delivered * @WLAN_STA_USES_ENCRYPTION: This station was configured for encryption, * so drop all packets without a key later. +* @WLAN_STA_DECAP_OFFLOAD: This station uses rx decap offload * * @NUM_WLAN_STA_FLAGS: number of defined flags */
@@ -102,6 +103,7 @@ enum ieee80211_sta_info_flags {WLAN_STA_MPSP_RECIPIENT ,WLAN_STA_PS_DELIVER ,WLAN_STA_USES_ENCRYPTION , +WLAN_STA_DECAP_OFFLOAD , NUM_WLAN_STA_FLAGS, };
net/mac80211/trace.h +17 -1
@@ -2761,7 +2761,7 @@ DEFINE_EVENT(local_sdata_addr_evt, drv_update_vif_offload,TP_ARGS (local, sdata) ); -TRACE_EVENT(drv_sta_set_4addr, +DECLARE_EVENT_CLASS(sta_flag_evt, TP_PROTO(struct ieee80211_local *local, struct ieee80211_sub_if_data *sdata, struct ieee80211_sta *sta, bool enabled),
@@ -2788,6 +2788,22 @@ TRACE_EVENT(drv_sta_set_4addr, ) ); +DEFINE_EVENT (sta_flag_evt, drv_sta_set_4addr, + TP_PROTO(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_sta *sta, bool enabled), + +TP_ARGS (local, sdata, sta, enabled) +); + +DEFINE_EVENT (sta_flag_evt, drv_sta_set_decap_offload, + TP_PROTO(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_sta *sta, bool enabled), + +TP_ARGS (local, sdata, sta, enabled) +); +#endif /* !__MAC80211_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */ #undef TRACE_INCLUDE_PATH
Signature · 1 line
2.28.0