skb_list_walk_safe refactoring for net/*'s skb_gso_segment usage
Subsystems (10)
cover skb_list_walk_safe refactoring for net/*'s skb_gso_segment usage
This patchset adjusts all return values of skb_gso_segment in net/* to use the new skb_list_walk_safe helper.
First we fix a minor bug in the helper macro that didn't come up in the last patchset's uses. Then we adjust several cases throughout net/. The xfrm changes were a bit hairy, but doable. Reading and thinking about the code in mac80211 indicates a memory leak, which the commit addresses. All the other cases were pretty trivial.
Jason A. Donenfeld (8):
net: skbuff: disambiguate argument and member for skb_list_walk_safe
helper
net: udp: use skb_list_walk_safe helper for gso segments
net: xfrm: use skb_list_walk_safe helper for gso segments
net: openvswitch: use skb_list_walk_safe helper for gso segments
net: sched: use skb_list_walk_safe helper for gso segments
net: ipv4: use skb_list_walk_safe helper for gso segments
net: netfilter: use skb_list_walk_safe helper for gso segments
net: mac80211: use skb_list_walk_safe helper for gso segments
include/linux/skbuff.h | 6 +++--- net/ipv4/ip_output.c | 8 +++----- net/ipv4/udp.c | 3 +-- net/ipv6/udp.c | 3 +-- net/mac80211/tx.c | 13 +++++-------- net/netfilter/nfnetlink_queue.c | 8 +++----- net/openvswitch/datapath.c | 11 ++++------- net/sched/sch_cake.c | 4 +--- net/sched/sch_tbf.c | 4 +--- net/xfrm/xfrm_device.c | 15 ++++----------- net/xfrm/xfrm_output.c | 9 +++------ 11 files changed, 29 insertions(+), 55 deletions(-)
Signature · 1 line
2.24.1
PATCH 1/8 net: skbuff: disambiguate argument and member for skb_list_walk_safe helper
This worked before, because we made all callers name their next pointer "next". But in trying to be more "drop-in" ready, the silliness here is revealed. This commit fixes the problem by making the macro argument and the member use different names.
--- include/linux/skbuff.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/skbuff.h +3 -3
@@ -1479,9 +1479,9 @@ static inline void skb_mark_not_on_list(struct sk_buff *skb) }/* Iterate through singly-linked GSO fragments of an skb. */ -#define skb_list_walk_safe (first, skb, next) \ - for ((skb) = (first), (next) = (skb) ? (skb)->next : NULL; (skb); \ - (skb) = (next), (next) = (skb) ? (skb)->next : NULL) +#define skb_list_walk_safe (first, skb, next_skb) \ + for ((skb) = (first), (next_skb) = (skb) ? (skb)->next : NULL; (skb); \ + (skb) = (next_skb), (next_skb) = (skb) ? (skb)->next : NULL)static inline void skb_list_del_init (struct sk_buff *skb) {
Signature · 1 line
2.24.1
PATCH 2/8 net: udp: use skb_list_walk_safe helper for gso segments
In reply to Jason A. DonenfeldThis is a straight-forward conversion case for the new function, iterating over the return value from udp_rcv_segment, which actually is a wrapper around skb_gso_segment.
--- net/ipv4/udp.c | 3 +-- net/ipv6/udp.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
net/ipv4/udp.c +1 -2
@@ -2104,8 +2104,7 @@ static int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)BUILD_BUG_ON (sizeof (struct udp_skb_cb ) >SKB_SGO_CB_OFFSET );__skb_push (skb, -skb_mac_offset (skb)); segs =udp_rcv_segment (sk, skb, true); -for (skb = segs; skb; skb = next) { - next = skb->next; + skb_list_walk_safe(segs, skb, next) {__skb_pull (skb,skb_transport_offset (skb)); ret =udp_queue_rcv_one_skb (sk, skb);if (ret >0 )
net/ipv6/udp.c +1 -2
@@ -690,8 +690,7 @@ static int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)__skb_push (skb, -skb_mac_offset (skb)); segs =udp_rcv_segment (sk, skb, false); -for (skb = segs; skb; skb = next) { - next = skb->next; + skb_list_walk_safe(segs, skb, next) {__skb_pull (skb,skb_transport_offset (skb)); ret =udpv6_queue_rcv_one_skb (sk, skb);
Signature · 1 line
2.24.1
PATCH 3/8 net: xfrm: use skb_list_walk_safe helper for gso segments
In reply to Jason A. DonenfeldThis is converts xfrm segment iteration to use the new function, keeping the flow of the existing code as intact as possible. One case is very straight-forward, whereas the other case has some more subtle code that likes to peak at ->next and relink skbs. By keeping the variables the same as before, we can upgrade this code with minimal surgery required.
--- net/xfrm/xfrm_device.c | 15 ++++----------- net/xfrm/xfrm_output.c | 9 +++------ 2 files changed, 7 insertions(+), 17 deletions(-)
net/xfrm/xfrm_device.c +4 -11
@@ -78,7 +78,7 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featurint err;unsigned long flags;struct xfrm_state *x; -struct sk_buff *skb2; +struct sk_buff *skb2, *nskb;struct softnet_data *sd;netdev_features_t esp_features = features;struct xfrm_offload *xo =xfrm_offload (skb);
@@ -148,11 +148,7 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featurreturn skb; } - skb2 = skb; - - do { - struct sk_buff *nskb = skb2->next; - + skb_list_walk_safe(skb, skb2, nskb) { esp_features |= skb->dev->gso_partial_features;skb_mark_not_on_list (skb2);
@@ -176,14 +172,11 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featurif (!skb)return NULL ; - goto skip_push; +continue ; }skb_push (skb2, skb2->data -skb_mac_header (skb2)); - -skip_push: - skb2 = nskb; - }while (skb2); + }return skb; }
net/xfrm/xfrm_output.c +3 -6
@@ -533,7 +533,7 @@ static int xfrm_output2(struct net *net, struct sock *sk, struct sk_buff *skb)static int xfrm_output_gso (struct net *net,struct sock *sk,struct sk_buff *skb) { -struct sk_buff *segs; +struct sk_buff *segs, *nskb;BUILD_BUG_ON (sizeof (*IPCB (skb)) >SKB_SGO_CB_OFFSET );BUILD_BUG_ON (sizeof (*IP6CB (skb)) >SKB_SGO_CB_OFFSET );
@@ -544,8 +544,7 @@ static int xfrm_output_gso(struct net *net, struct sock *sk, struct sk_buff *skbif (segs ==NULL )return -EINVAL ; - do { - struct sk_buff *nskb = segs->next; + skb_list_walk_safe(segs, segs, nskb) {int err;skb_mark_not_on_list (segs);
@@ -555,9 +554,7 @@ static int xfrm_output_gso(struct net *net, struct sock *sk, struct sk_buff *skbkfree_skb_list (nskb);return err; } - - segs = nskb; - }while (segs); + }return 0 ; }
Signature · 1 line
2.24.1
PATCH 4/8 net: openvswitch: use skb_list_walk_safe helper for gso segments
In reply to Jason A. DonenfeldThis is a straight-forward conversion case for the new function, keeping the flow of the existing code as intact as possible.
--- net/openvswitch/datapath.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
net/openvswitch/datapath.c +4 -7
@@ -321,8 +321,7 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb, }/* Queue all of the segments. */ - skb = segs; - do { + skb_list_walk_safe(segs, skb, nskb) {if (gso_type &SKB_GSO_UDP && skb != segs) key = &later_key;
@@ -330,17 +329,15 @@ static int queue_gso_packets(struct datapath *dp, struct sk_buff *skb,if (err)break ; - }while ((skb = skb->next)); + }/* Free all of the segments. */ - skb = segs; -do { - nskb = skb->next; + skb_list_walk_safe(segs, skb, nskb) {if (err)kfree_skb (skb);else consume_skb (skb); - }while ((skb = nskb)); + }return err; }
Signature · 1 line
2.24.1
PATCH 5/8 net: sched: use skb_list_walk_safe helper for gso segments
In reply to Jason A. DonenfeldThis is a straight-forward conversion case for the new function, keeping the flow of the existing code as intact as possible.
--- net/sched/sch_cake.c | 4 +--- net/sched/sch_tbf.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
net/sched/sch_cake.c +1 -3
@@ -1682,8 +1682,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch,if (IS_ERR_OR_NULL (segs))return qdisc_drop (skb, sch, to_free); -while (segs) { - nskb = segs->next; + skb_list_walk_safe(segs, segs, nskb) {skb_mark_not_on_list (segs);qdisc_skb_cb (segs)->pkt_len = segs->len;cobalt_set_enqueue_time (segs, now);
@@ -1696,7 +1695,6 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch, slen += segs->len; q->buffer_used += segs->truesize; b->packets++; - segs = nskb; }/* stats */
net/sched/sch_tbf.c +1 -3
@@ -155,8 +155,7 @@ static int tbf_segment(struct sk_buff *skb, struct Qdisc *sch,return qdisc_drop (skb, sch, to_free); nb =0 ; -while (segs) { - nskb = segs->next; + skb_list_walk_safe(segs, segs, nskb) {skb_mark_not_on_list (segs);qdisc_skb_cb (segs)->pkt_len = segs->len; len += segs->len;
@@ -167,7 +166,6 @@ static int tbf_segment(struct sk_buff *skb, struct Qdisc *sch, }else { nb++; } - segs = nskb; } sch->q.qlen += nb;if (nb >1 )
Signature · 1 line
2.24.1
PATCH 6/8 net: ipv4: use skb_list_walk_safe helper for gso segments
In reply to Jason A. DonenfeldThis is a straight-forward conversion case for the new function, keeping the flow of the existing code as intact as possible.
--- net/ipv4/ip_output.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/ipv4/ip_output.c +3 -5
@@ -240,8 +240,8 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *sstatic int ip_finish_output_gso (struct net *net,struct sock *sk,struct sk_buff *skb,unsigned int mtu) { +struct sk_buff *segs, *nskb;netdev_features_t features; -struct sk_buff *segs;int ret =0 ;/* common case: seglen is <= mtu
@@ -272,8 +272,7 @@ static int ip_finish_output_gso(struct net *net, struct sock *sk,consume_skb (skb); - do { - struct sk_buff *nskb = segs->next; + skb_list_walk_safe(segs, segs, nskb) {int err;skb_mark_not_on_list (segs);
@@ -281,8 +280,7 @@ static int ip_finish_output_gso(struct net *net, struct sock *sk,if (err && ret ==0 ) ret = err; - segs = nskb; - }while (segs); + }return ret; }
Signature · 1 line
2.24.1
PATCH 7/8 net: netfilter: use skb_list_walk_safe helper for gso segments
In reply to Jason A. DonenfeldThis is a straight-forward conversion case for the new function, keeping the flow of the existing code as intact as possible.
--- net/netfilter/nfnetlink_queue.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/netfilter/nfnetlink_queue.c +3 -5
@@ -778,7 +778,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum) {unsigned int queued;struct nfqnl_instance *queue; -struct sk_buff *skb, *segs; +struct sk_buff *skb, *segs, *nskb;int err = -ENOBUFS ;struct net *net = entry->state.net;struct nfnl_queue_net *q =nfnl_queue_pernet (net);
@@ -815,8 +815,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum) goto out_err; queued =0 ; err =0 ; - do { - struct sk_buff *nskb = segs->next; + skb_list_walk_safe(segs, segs, nskb) {if (err ==0 ) err =__nfqnl_enqueue_packet_gso (net, queue, segs, entry);
@@ -824,8 +823,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum) queued++; elsekfree_skb (segs ); - segs = nskb; - }while (segs); + }if (queued) {if (err)/* some segments are already queued */
Signature · 1 line
2.24.1
PATCH 8/8 net: mac80211: use skb_list_walk_safe helper for gso segments
In reply to Jason A. DonenfeldThis is a conversion case for the new function, keeping the flow of the existing code as intact as possible. We also switch over to using skb_mark_not_on_list instead of a null write to skb->next.
Finally, this code appeared to have a memory leak in the case where header building fails before the last gso segment. In that case, the remaining segments are not freed. So this commit also adds the proper kfree_skb_list call for the remainder of the skbs.
--- net/mac80211/tx.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
net/mac80211/tx.c +5 -8
@@ -3949,18 +3949,15 @@ void __ieee80211_subif_start_xmit(struct sk_buff *skb, } } - next = skb; -while (next) { - skb = next; - next = skb->next; - - skb->prev =NULL ; - skb->next =NULL ; + skb_list_walk_safe(skb, skb, next) { +skb_mark_not_on_list (skb); skb =ieee80211_build_hdr (sdata, skb, info_flags, sta, ctrl_flags); -if (IS_ERR (skb)) +if (IS_ERR (skb)) { +kfree_skb_list (next); goto out; + }ieee80211_tx_stats (dev, skb->len);
Signature · 1 line
2.24.1
David Miller
maintainerFrom: "Jason A. Donenfeld" <[email protected]>
Date: Mon, 13 Jan 2020 18:42:25 -0500
Quoted 8 lines
This patchset adjusts all return values of
skb_gso_segmentinnet/*to use the newskb_list_walk_safehelper.First we fix a minor bug in the helper macro that didn't come up in the last patchset's uses. Then we adjust several cases throughout
net/. The xfrm changes were a bit hairy, but doable. Reading and thinking about the code in mac80211 indicates a memory leak, which the commit addresses. All the other cases were pretty trivial.
Series applied, thanks Jason.