net: fix the features flag in sctp_gso_segment
Subsystems (3)
Xin Long
maintainerv3 cover net: fix the features flag in sctp_gso_segment
Patch 1/2 is to improve the code in skb_segment(), and it is needed by Patch 2/2.
v1->v2:
- see Patch 1/2.v2->v3:
- change Patch 2/2 to the right patch.
Xin Long (2):
net: move the hsize check to the else block in skb_segment
sctp: remove the NETIF_F_SG flag before calling skb_segment
net/core/skbuff.c | 11 ++++++----- net/sctp/offload.c | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
2.1.0
Xin Long
maintainerPATCH v3 1/2 net: move the hsize check to the else block in skb_segment
After commit 89319d3801d1 ("net: Add frag_list support to skb_segment"), it goes to process frag_list when !hsize in skb_segment(). However, when using skb frag_list, sg normally should not be set. In this case, hsize will be set with len right before !hsize check, then it won't go to frag_list processing code.
So the right thing to do is move the hsize check to the else block, so that it won't affect the !hsize check for frag_list processing.
v1->v2:
- change to do "hsize <= 0" check instead of "!hsize", and also move "hsize < 0" into else block, to save some cycles, as Alex suggested.
--- net/core/skbuff.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/core/skbuff.c +6 -5
@@ -3894,12 +3894,8 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, } hsize =skb_headlen (head_skb) - offset; -if (hsize <0 ) - hsize =0 ; -if (hsize > len || !sg) - hsize = len; -if (!hsize && i >= nfrags &&skb_headlen (list_skb) && +if (hsize <=0 && i >= nfrags &&skb_headlen (list_skb) && (skb_headlen (list_skb) == len || sg)) {BUG_ON (skb_headlen (list_skb) > len);
@@ -3942,6 +3938,11 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,skb_release_head_state (nskb);__skb_push (nskb, doffset); }else { +if (hsize > len || !sg) + hsize = len; +else if (hsize <0 ) + hsize =0 ; + nskb =__alloc_skb (hsize + doffset + headroom,GFP_ATOMIC ,skb_alloc_rx_flag (head_skb),NUMA_NO_NODE );
Signature · 1 line
2.1.0
Xin Long
maintainerPATCH v3 2/2 sctp: remove the NETIF_F_SG flag before calling skb_segment
It makes more sense to clear NETIF_F_SG instead of set it when calling skb_segment() in sctp_gso_segment(), since SCTP GSO is using head_skb's fraglist, of which all frags are linear skbs.
This will make SCTP GSO code more understandable.
--- net/sctp/offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/offload.c +1 -1
@@ -68,7 +68,7 @@ static struct sk_buff *sctp_gso_segment(struct sk_buff *skb, goto out; } - segs =skb_segment (skb, features |NETIF_F_HW_CSUM |NETIF_F_SG ); + segs =skb_segment (skb, (features |NETIF_F_HW_CSUM ) & ~NETIF_F_SG );if (IS_ERR (segs)) goto out;
Signature · 1 line
2.1.0
Re: [PATCHv3 net-next 1/2] net: move the hsize check to the else block in skb_segment
In reply to Xin LongQuoted 7 lines · Xin Long
After commit
89319d3801d1("net: Addfrag_listsupport toskb_segment"), it goes to processfrag_listwhen !hsize inskb_segment(). However, when using skbfrag_list, sg normally should not be set. In this case, hsize will be set with len right before !hsize check, then it won't go tofrag_listprocessing code.
Quoted 8 lines
So the right thing to do is move the hsize check to the else block, so that it won't affect the !hsize check for
frag_listprocessing.
v1->v2:
- change to do "hsize <= 0" check instead of "!hsize", and also move "hsize < 0" into else block, to save some cycles, as Alex suggested.Signed-off-by Xin Long <[email protected]>
Looks good to me.
Quoted 37 lines
--- net/core/skbuff.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)net/core/skbuff.c +6
-6@@ -3894,12 +3894,8 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb, } hsize =skb_headlen (head_skb) - offset; -if (hsize <0 ) - hsize =0 ; -if (hsize > len || !sg) - hsize = len; -if (!hsize && i >= nfrags &&skb_headlen (list_skb) && +if (hsize <=0 && i >= nfrags &&skb_headlen (list_skb) && (skb_headlen (list_skb) == len || sg)) {BUG_ON (skb_headlen (list_skb) > len);@@ -3942,6 +3938,11 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,skb_release_head_state (nskb);__skb_push (nskb, doffset); }else { +if (hsize > len || !sg) + hsize = len; +else if (hsize <0 ) + hsize =0 ; + nskb =__alloc_skb (hsize + doffset + headroom,GFP_ATOMIC ,skb_alloc_rx_flag (head_skb),NUMA_NO_NODE ); --2.1.0
Re: [PATCHv3 net-next 1/2] net: move the hsize check to the else block in skb_segment
Quoted 15 lines · On Fri, 15 Jan 2021 17:39:02 -0800 Alexander Duyck wrote:
Quoted 14 lines · Xin Long
After commit
89319d3801d1("net: Addfrag_listsupport toskb_segment"), it goes to processfrag_listwhen !hsize inskb_segment(). However, when using skbfrag_list, sg normally should not be set. In this case, hsize will be set with len right before !hsize check, then it won't go tofrag_listprocessing code.So the right thing to do is move the hsize check to the else block, so that it won't affect the !hsize check for
frag_listprocessing.
v1->v2:
- change to do "hsize <= 0" check instead of "!hsize", and also move "hsize < 0" into else block, to save some cycles, as Alex suggested.
Quoted 5 lines
Quoted 1 line
Signed-off-by Xin Long <[email protected]>Looks good to me.
Reviewed-by Alexander Duyck <[email protected]>
Applied, thanks!