Skip to content

Commit ba317ce

Browse files
joshhunt-akamaigregkh
authored andcommitted
udp: only do GSO if # of segs > 1
[ Upstream commit 4094871 ] Prior to this change an application sending <= 1MSS worth of data and enabling UDP GSO would fail if the system had SW GSO enabled, but the same send would succeed if HW GSO offload is enabled. In addition to this inconsistency the error in the SW GSO case does not get back to the application if sending out of a real device so the user is unaware of this failure. With this change we only perform GSO if the # of segments is > 1 even if the application has enabled segmentation. I've also updated the relevant udpgso selftests. Fixes: bec1f6f ("udp: generate gso with UDP_SEGMENT") Signed-off-by: Josh Hunt <johunt@akamai.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Alexander Duyck <alexander.h.duyck@linux.intel.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 673f813 commit ba317ce

3 files changed

Lines changed: 18 additions & 20 deletions

File tree

‎net/ipv4/udp.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
821821
int is_udplite = IS_UDPLITE(sk);
822822
int offset = skb_transport_offset(skb);
823823
int len = skb->len - offset;
824+
int datalen = len - sizeof(*uh);
824825
__wsum csum = 0;
825826

826827
/*
@@ -854,10 +855,12 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
854855
return -EIO;
855856
}
856857

857-
skb_shinfo(skb)->gso_size = cork->gso_size;
858-
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
859-
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(len - sizeof(*uh),
860-
cork->gso_size);
858+
if (datalen > cork->gso_size) {
859+
skb_shinfo(skb)->gso_size = cork->gso_size;
860+
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
861+
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
862+
cork->gso_size);
863+
}
861864
goto csum_partial;
862865
}
863866

‎net/ipv6/udp.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
11091109
__wsum csum = 0;
11101110
int offset = skb_transport_offset(skb);
11111111
int len = skb->len - offset;
1112+
int datalen = len - sizeof(*uh);
11121113

11131114
/*
11141115
* Create a UDP header
@@ -1141,10 +1142,12 @@ static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
11411142
return -EIO;
11421143
}
11431144

1144-
skb_shinfo(skb)->gso_size = cork->gso_size;
1145-
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
1146-
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(len - sizeof(*uh),
1147-
cork->gso_size);
1145+
if (datalen > cork->gso_size) {
1146+
skb_shinfo(skb)->gso_size = cork->gso_size;
1147+
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
1148+
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
1149+
cork->gso_size);
1150+
}
11481151
goto csum_partial;
11491152
}
11501153

‎tools/testing/selftests/net/udpgso.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ struct testcase testcases_v4[] = {
8989
.tfail = true,
9090
},
9191
{
92-
/* send a single MSS: will fail with GSO, because the segment
93-
* logic in udp4_ufo_fragment demands a gso skb to be > MTU
94-
*/
92+
/* send a single MSS: will fall back to no GSO */
9593
.tlen = CONST_MSS_V4,
9694
.gso_len = CONST_MSS_V4,
97-
.tfail = true,
9895
.r_num_mss = 1,
9996
},
10097
{
@@ -139,10 +136,9 @@ struct testcase testcases_v4[] = {
139136
.tfail = true,
140137
},
141138
{
142-
/* send a single 1B MSS: will fail, see single MSS above */
139+
/* send a single 1B MSS: will fall back to no GSO */
143140
.tlen = 1,
144141
.gso_len = 1,
145-
.tfail = true,
146142
.r_num_mss = 1,
147143
},
148144
{
@@ -196,12 +192,9 @@ struct testcase testcases_v6[] = {
196192
.tfail = true,
197193
},
198194
{
199-
/* send a single MSS: will fail with GSO, because the segment
200-
* logic in udp4_ufo_fragment demands a gso skb to be > MTU
201-
*/
195+
/* send a single MSS: will fall back to no GSO */
202196
.tlen = CONST_MSS_V6,
203197
.gso_len = CONST_MSS_V6,
204-
.tfail = true,
205198
.r_num_mss = 1,
206199
},
207200
{
@@ -246,10 +239,9 @@ struct testcase testcases_v6[] = {
246239
.tfail = true,
247240
},
248241
{
249-
/* send a single 1B MSS: will fail, see single MSS above */
242+
/* send a single 1B MSS: will fall back to no GSO */
250243
.tlen = 1,
251244
.gso_len = 1,
252-
.tfail = true,
253245
.r_num_mss = 1,
254246
},
255247
{

0 commit comments

Comments
 (0)