net: fix the features flag in sctp_gso_segment
Subsystems (3)
Xin Long
maintainercover 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.
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 | 5 +++-- net/sctp/offload.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
Xin Long
maintainerPATCH 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.
--- net/core/skbuff.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/core/skbuff.c +3 -2
@@ -3855,8 +3855,6 @@ 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) && (skb_headlen (list_skb) == len || sg)) {
@@ -3901,6 +3899,9 @@ 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; + 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 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: [PATCH net-next 1/2] net: move the hsize check to the else block in skb_segment
In reply to Xin LongQuoted 20 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.Signed-off-by Xin Long <[email protected]>--- net/core/skbuff.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)net/core/skbuff.c +0
-0
net/core/skbuff.c struct sk_buff *skb_segment(struct sk_buff *head_skb, · line 3860
Quoted 8 lines
net/core/skbuff.c +0
-2@@ -3855,8 +3855,6 @@ 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) && (skb_headlen (list_skb) == len || sg)) {
So looking at the function it seems like the only spot where the standard path actually reads the hsize value is right here, and it is overwritten before we exit the non-error portion of the if statement. I wonder if we couldn't save ourselves a few cycles and avoid an unnecessary assignment by replacing the "!hsize" with a check for "hsize <= 0" and just move the entire set of checks above down into the lower block.
net/core/skbuff.c struct sk_buff *skb_segment(struct sk_buff *head_skb, · line 3904
Quoted 7 lines
net/core/skbuff.c +3
-0@@ -3901,6 +3899,9 @@ 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; +
Then you could essentially just add the "if (hsize < 0)" piece here as an "else if" check and avoid the check if it isn't needed.
Quoted 6 lines
net/core/skbuff.c +0
-1nskb =__alloc_skb (hsize + doffset + headroom,GFP_ATOMIC ,skb_alloc_rx_flag (head_skb),NUMA_NO_NODE ); --2.1.0
Xin Long
maintainerRe: [PATCH net-next 1/2] net: move the hsize check to the else block in skb_segment
Quoted 39 lines · Alexander Duyck
Quoted 20 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.Signed-off-by Xin Long <[email protected]>--- net/core/skbuff.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)net/core/skbuff.c +0
-0net/core/skbuff.c struct sk_buff *skb_segment(struct sk_buff *head_skb, · line 3860
Quoted 8 lines
net/core/skbuff.c +0
-2@@ -3855,8 +3855,6 @@ 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) && (skb_headlen (list_skb) == len || sg)) {So looking at the function it seems like the only spot where the standard path actually reads the hsize value is right here, and it is overwritten before we exit the non-error portion of the if statement. I wonder if we couldn't save ourselves a few cycles and avoid an unnecessary assignment by replacing the "!hsize" with a check for "hsize <= 0" and just move the entire set of checks above down into the lower block.
Quoted 10 lines
net/core/skbuff.c struct sk_buff *skb_segment(struct sk_buff *head_skb, · line 3904
Quoted 7 lines
net/core/skbuff.c +3
-0@@ -3901,6 +3899,9 @@ 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; +Then you could essentially just add the "if (hsize < 0)" piece here as an "else if" check and avoid the check if it isn't needed.
Look correct, will post v2. Thanks!
Quoted 7 lines
Quoted 7 lines
net/core/skbuff.c +0
-1nskb =__alloc_skb (hsize + doffset + headroom,GFP_ATOMIC ,skb_alloc_rx_flag (head_skb),NUMA_NO_NODE ); --2.1.0