Skip to content

Commit 15e2396

Browse files
Tom Herbertdavem330
authored andcommitted
net: Infrastructure for CHECKSUM_PARTIAL with remote checsum offload
This patch adds infrastructure so that remote checksum offload can set CHECKSUM_PARTIAL instead of calling csum_partial and writing the modfied checksum field. Add skb_remcsum_adjust_partial function to set an skb for using CHECKSUM_PARTIAL with remote checksum offload. Changed skb_remcsum_process and skb_gro_remcsum_process to take a boolean argument to indicate if checksum partial can be set or the checksum needs to be modified using the normal algorithm. Signed-off-by: Tom Herbert <therbert@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent baa32ff commit 15e2396

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

drivers/net/vxlan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb,
580580
}
581581

582582
skb_gro_remcsum_process(skb, (void *)vh + hdrlen,
583-
start, offset, grc);
583+
start, offset, grc, true);
584584

585585
skb->remcsum_offload = 1;
586586

@@ -1171,7 +1171,7 @@ static struct vxlanhdr *vxlan_remcsum(struct sk_buff *skb, struct vxlanhdr *vh,
11711171

11721172
vh = (struct vxlanhdr *)(udp_hdr(skb) + 1);
11731173

1174-
skb_remcsum_process(skb, (void *)vh + hdrlen, start, offset);
1174+
skb_remcsum_process(skb, (void *)vh + hdrlen, start, offset, true);
11751175

11761176
return vh;
11771177
}

include/linux/netdevice.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,9 @@ struct napi_gro_cb {
19231923
/* Number of segments aggregated. */
19241924
u16 count;
19251925

1926+
/* Start offset for remote checksum offload */
1927+
u16 gro_remcsum_start;
1928+
19261929
/* jiffies when first packet was created/queued */
19271930
unsigned long age;
19281931

@@ -2244,13 +2247,20 @@ static inline void skb_gro_postpull_rcsum(struct sk_buff *skb,
22442247

22452248
__sum16 __skb_gro_checksum_complete(struct sk_buff *skb);
22462249

2250+
static inline bool skb_at_gro_remcsum_start(struct sk_buff *skb)
2251+
{
2252+
return (NAPI_GRO_CB(skb)->gro_remcsum_start - skb_headroom(skb) ==
2253+
skb_gro_offset(skb));
2254+
}
2255+
22472256
static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb,
22482257
bool zero_okay,
22492258
__sum16 check)
22502259
{
22512260
return ((skb->ip_summed != CHECKSUM_PARTIAL ||
22522261
skb_checksum_start_offset(skb) <
22532262
skb_gro_offset(skb)) &&
2263+
!skb_at_gro_remcsum_start(skb) &&
22542264
NAPI_GRO_CB(skb)->csum_cnt == 0 &&
22552265
(!zero_okay || check));
22562266
}
@@ -2337,12 +2347,19 @@ static inline void skb_gro_remcsum_init(struct gro_remcsum *grc)
23372347

23382348
static inline void skb_gro_remcsum_process(struct sk_buff *skb, void *ptr,
23392349
int start, int offset,
2340-
struct gro_remcsum *grc)
2350+
struct gro_remcsum *grc,
2351+
bool nopartial)
23412352
{
23422353
__wsum delta;
23432354

23442355
BUG_ON(!NAPI_GRO_CB(skb)->csum_valid);
23452356

2357+
if (!nopartial) {
2358+
NAPI_GRO_CB(skb)->gro_remcsum_start =
2359+
((unsigned char *)ptr + start) - skb->head;
2360+
return;
2361+
}
2362+
23462363
delta = remcsum_adjust(ptr, NAPI_GRO_CB(skb)->csum, start, offset);
23472364

23482365
/* Adjust skb->csum since we changed the packet */

include/linux/skbuff.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3104,16 +3104,29 @@ do { \
31043104
compute_pseudo(skb, proto)); \
31053105
} while (0)
31063106

3107+
static inline void skb_remcsum_adjust_partial(struct sk_buff *skb, void *ptr,
3108+
u16 start, u16 offset)
3109+
{
3110+
skb->ip_summed = CHECKSUM_PARTIAL;
3111+
skb->csum_start = ((unsigned char *)ptr + start) - skb->head;
3112+
skb->csum_offset = offset - start;
3113+
}
3114+
31073115
/* Update skbuf and packet to reflect the remote checksum offload operation.
31083116
* When called, ptr indicates the starting point for skb->csum when
31093117
* ip_summed is CHECKSUM_COMPLETE. If we need create checksum complete
31103118
* here, skb_postpull_rcsum is done so skb->csum start is ptr.
31113119
*/
31123120
static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr,
3113-
int start, int offset)
3121+
int start, int offset, bool nopartial)
31143122
{
31153123
__wsum delta;
31163124

3125+
if (!nopartial) {
3126+
skb_remcsum_adjust_partial(skb, ptr, start, offset);
3127+
return;
3128+
}
3129+
31173130
if (unlikely(skb->ip_summed != CHECKSUM_COMPLETE)) {
31183131
__skb_checksum_complete(skb);
31193132
skb_postpull_rcsum(skb, skb->data, ptr - (void *)skb->data);

net/core/dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4024,6 +4024,7 @@ static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff
40244024
NAPI_GRO_CB(skb)->flush = 0;
40254025
NAPI_GRO_CB(skb)->free = 0;
40264026
NAPI_GRO_CB(skb)->udp_mark = 0;
4027+
NAPI_GRO_CB(skb)->gro_remcsum_start = 0;
40274028

40284029
/* Setup for GRO checksum validation */
40294030
switch (skb->ip_summed) {

net/ipv4/fou.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr,
7575
return NULL;
7676
guehdr = (struct guehdr *)&udp_hdr(skb)[1];
7777

78-
skb_remcsum_process(skb, (void *)guehdr + hdrlen, start, offset);
78+
skb_remcsum_process(skb, (void *)guehdr + hdrlen, start, offset, true);
7979

8080
return guehdr;
8181
}
@@ -230,7 +230,7 @@ static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off,
230230
}
231231

232232
skb_gro_remcsum_process(skb, (void *)guehdr + hdrlen,
233-
start, offset, grc);
233+
start, offset, grc, true);
234234

235235
skb->remcsum_offload = 1;
236236

0 commit comments

Comments
 (0)