Skip to content

Commit d6870bb

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 da0f508 commit d6870bb

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
@@ -833,6 +833,7 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
833833
int is_udplite = IS_UDPLITE(sk);
834834
int offset = skb_transport_offset(skb);
835835
int len = skb->len - offset;
836+
int datalen = len - sizeof(*uh);
836837
__wsum csum = 0;
837838

838839
/*
@@ -866,10 +867,12 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
866867
return -EIO;
867868
}
868869

869-
skb_shinfo(skb)->gso_size = cork->gso_size;
870-
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
871-
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(len - sizeof(*uh),
872-
cork->gso_size);
870+
if (datalen > cork->gso_size) {
871+
skb_shinfo(skb)->gso_size = cork->gso_size;
872+
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
873+
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
874+
cork->gso_size);
875+
}
873876
goto csum_partial;
874877
}
875878

‎net/ipv6/udp.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
11221122
__wsum csum = 0;
11231123
int offset = skb_transport_offset(skb);
11241124
int len = skb->len - offset;
1125+
int datalen = len - sizeof(*uh);
11251126

11261127
/*
11271128
* Create a UDP header
@@ -1154,10 +1155,12 @@ static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
11541155
return -EIO;
11551156
}
11561157

1157-
skb_shinfo(skb)->gso_size = cork->gso_size;
1158-
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
1159-
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(len - sizeof(*uh),
1160-
cork->gso_size);
1158+
if (datalen > cork->gso_size) {
1159+
skb_shinfo(skb)->gso_size = cork->gso_size;
1160+
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
1161+
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
1162+
cork->gso_size);
1163+
}
11611164
goto csum_partial;
11621165
}
11631166

‎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)