Commit b7fe10e5 authored by Tom Herbert's avatar Tom Herbert Committed by David S. Miller

gro: Fix remcsum offload to deal with frags in GRO

The remote checksum offload GRO did not consider the case that frag0
might be in use. This patch fixes that by accessing headers using the
skb_gro functions and not saving offsets relative to skb->head.
Signed-off-by: default avatarTom Herbert <tom@herbertland.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9a873c71
...@@ -519,10 +519,10 @@ static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb, ...@@ -519,10 +519,10 @@ static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb,
u32 data, struct gro_remcsum *grc, u32 data, struct gro_remcsum *grc,
bool nopartial) bool nopartial)
{ {
size_t start, offset, plen; size_t start, offset;
if (skb->remcsum_offload) if (skb->remcsum_offload)
return NULL; return vh;
if (!NAPI_GRO_CB(skb)->csum_valid) if (!NAPI_GRO_CB(skb)->csum_valid)
return NULL; return NULL;
...@@ -532,17 +532,8 @@ static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb, ...@@ -532,17 +532,8 @@ static struct vxlanhdr *vxlan_gro_remcsum(struct sk_buff *skb,
offsetof(struct udphdr, check) : offsetof(struct udphdr, check) :
offsetof(struct tcphdr, check)); offsetof(struct tcphdr, check));
plen = hdrlen + offset + sizeof(u16); vh = skb_gro_remcsum_process(skb, (void *)vh, off, hdrlen,
start, offset, grc, nopartial);
/* Pull checksum that will be written */
if (skb_gro_header_hard(skb, off + plen)) {
vh = skb_gro_header_slow(skb, off + plen, off);
if (!vh)
return NULL;
}
skb_gro_remcsum_process(skb, (void *)vh + hdrlen,
start, offset, grc, nopartial);
skb->remcsum_offload = 1; skb->remcsum_offload = 1;
...@@ -573,7 +564,6 @@ static struct sk_buff **vxlan_gro_receive(struct sk_buff **head, ...@@ -573,7 +564,6 @@ static struct sk_buff **vxlan_gro_receive(struct sk_buff **head,
goto out; goto out;
} }
skb_gro_pull(skb, sizeof(struct vxlanhdr)); /* pull vxlan header */
skb_gro_postpull_rcsum(skb, vh, sizeof(struct vxlanhdr)); skb_gro_postpull_rcsum(skb, vh, sizeof(struct vxlanhdr));
flags = ntohl(vh->vx_flags); flags = ntohl(vh->vx_flags);
...@@ -588,6 +578,8 @@ static struct sk_buff **vxlan_gro_receive(struct sk_buff **head, ...@@ -588,6 +578,8 @@ static struct sk_buff **vxlan_gro_receive(struct sk_buff **head,
goto out; goto out;
} }
skb_gro_pull(skb, sizeof(struct vxlanhdr)); /* pull vxlan header */
flush = 0; flush = 0;
for (p = *head; p; p = p->next) { for (p = *head; p; p = p->next) {
...@@ -1110,6 +1102,9 @@ static struct vxlanhdr *vxlan_remcsum(struct sk_buff *skb, struct vxlanhdr *vh, ...@@ -1110,6 +1102,9 @@ static struct vxlanhdr *vxlan_remcsum(struct sk_buff *skb, struct vxlanhdr *vh,
{ {
size_t start, offset, plen; size_t start, offset, plen;
if (skb->remcsum_offload)
return vh;
start = (data & VXLAN_RCO_MASK) << VXLAN_RCO_SHIFT; start = (data & VXLAN_RCO_MASK) << VXLAN_RCO_SHIFT;
offset = start + ((data & VXLAN_RCO_UDP) ? offset = start + ((data & VXLAN_RCO_UDP) ?
offsetof(struct udphdr, check) : offsetof(struct udphdr, check) :
......
...@@ -2311,8 +2311,7 @@ __sum16 __skb_gro_checksum_complete(struct sk_buff *skb); ...@@ -2311,8 +2311,7 @@ __sum16 __skb_gro_checksum_complete(struct sk_buff *skb);
static inline bool skb_at_gro_remcsum_start(struct sk_buff *skb) static inline bool skb_at_gro_remcsum_start(struct sk_buff *skb)
{ {
return (NAPI_GRO_CB(skb)->gro_remcsum_start - skb_headroom(skb) == return (NAPI_GRO_CB(skb)->gro_remcsum_start == skb_gro_offset(skb));
skb_gro_offset(skb));
} }
static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb, static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb,
...@@ -2408,37 +2407,58 @@ static inline void skb_gro_remcsum_init(struct gro_remcsum *grc) ...@@ -2408,37 +2407,58 @@ static inline void skb_gro_remcsum_init(struct gro_remcsum *grc)
grc->delta = 0; grc->delta = 0;
} }
static inline void skb_gro_remcsum_process(struct sk_buff *skb, void *ptr, static inline void *skb_gro_remcsum_process(struct sk_buff *skb, void *ptr,
int start, int offset, unsigned int off, size_t hdrlen,
struct gro_remcsum *grc, int start, int offset,
bool nopartial) struct gro_remcsum *grc,
bool nopartial)
{ {
__wsum delta; __wsum delta;
size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
BUG_ON(!NAPI_GRO_CB(skb)->csum_valid); BUG_ON(!NAPI_GRO_CB(skb)->csum_valid);
if (!nopartial) { if (!nopartial) {
NAPI_GRO_CB(skb)->gro_remcsum_start = NAPI_GRO_CB(skb)->gro_remcsum_start = off + hdrlen + start;
((unsigned char *)ptr + start) - skb->head; return ptr;
return; }
ptr = skb_gro_header_fast(skb, off);
if (skb_gro_header_hard(skb, off + plen)) {
ptr = skb_gro_header_slow(skb, off + plen, off);
if (!ptr)
return NULL;
} }
delta = remcsum_adjust(ptr, NAPI_GRO_CB(skb)->csum, start, offset); delta = remcsum_adjust(ptr + hdrlen, NAPI_GRO_CB(skb)->csum,
start, offset);
/* Adjust skb->csum since we changed the packet */ /* Adjust skb->csum since we changed the packet */
NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta); NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta);
grc->offset = (ptr + offset) - (void *)skb->head; grc->offset = off + hdrlen + offset;
grc->delta = delta; grc->delta = delta;
return ptr;
} }
static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb, static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb,
struct gro_remcsum *grc) struct gro_remcsum *grc)
{ {
void *ptr;
size_t plen = grc->offset + sizeof(u16);
if (!grc->delta) if (!grc->delta)
return; return;
remcsum_unadjust((__sum16 *)(skb->head + grc->offset), grc->delta); ptr = skb_gro_header_fast(skb, grc->offset);
if (skb_gro_header_hard(skb, grc->offset + sizeof(u16))) {
ptr = skb_gro_header_slow(skb, plen, grc->offset);
if (!ptr)
return;
}
remcsum_unadjust((__sum16 *)ptr, grc->delta);
} }
static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev, static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
......
...@@ -79,7 +79,11 @@ static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr, ...@@ -79,7 +79,11 @@ static struct guehdr *gue_remcsum(struct sk_buff *skb, struct guehdr *guehdr,
__be16 *pd = data; __be16 *pd = data;
size_t start = ntohs(pd[0]); size_t start = ntohs(pd[0]);
size_t offset = ntohs(pd[1]); size_t offset = ntohs(pd[1]);
size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start); size_t plen = sizeof(struct udphdr) + hdrlen +
max_t(size_t, offset + sizeof(u16), start);
if (skb->remcsum_offload)
return guehdr;
if (!pskb_may_pull(skb, plen)) if (!pskb_may_pull(skb, plen))
return NULL; return NULL;
...@@ -221,29 +225,21 @@ static int fou_gro_complete(struct sk_buff *skb, int nhoff, ...@@ -221,29 +225,21 @@ static int fou_gro_complete(struct sk_buff *skb, int nhoff,
static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off, static struct guehdr *gue_gro_remcsum(struct sk_buff *skb, unsigned int off,
struct guehdr *guehdr, void *data, struct guehdr *guehdr, void *data,
size_t hdrlen, u8 ipproto, size_t hdrlen, struct gro_remcsum *grc,
struct gro_remcsum *grc, bool nopartial) bool nopartial)
{ {
__be16 *pd = data; __be16 *pd = data;
size_t start = ntohs(pd[0]); size_t start = ntohs(pd[0]);
size_t offset = ntohs(pd[1]); size_t offset = ntohs(pd[1]);
size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
if (skb->remcsum_offload) if (skb->remcsum_offload)
return NULL; return guehdr;
if (!NAPI_GRO_CB(skb)->csum_valid) if (!NAPI_GRO_CB(skb)->csum_valid)
return NULL; return NULL;
/* Pull checksum that will be written */ guehdr = skb_gro_remcsum_process(skb, (void *)guehdr, off, hdrlen,
if (skb_gro_header_hard(skb, off + plen)) { start, offset, grc, nopartial);
guehdr = skb_gro_header_slow(skb, off + plen, off);
if (!guehdr)
return NULL;
}
skb_gro_remcsum_process(skb, (void *)guehdr + hdrlen,
start, offset, grc, nopartial);
skb->remcsum_offload = 1; skb->remcsum_offload = 1;
...@@ -307,10 +303,10 @@ static struct sk_buff **gue_gro_receive(struct sk_buff **head, ...@@ -307,10 +303,10 @@ static struct sk_buff **gue_gro_receive(struct sk_buff **head,
if (flags & GUE_PFLAG_REMCSUM) { if (flags & GUE_PFLAG_REMCSUM) {
guehdr = gue_gro_remcsum(skb, off, guehdr, guehdr = gue_gro_remcsum(skb, off, guehdr,
data + doffset, hdrlen, data + doffset, hdrlen, &grc,
guehdr->proto_ctype, &grc,
!!(fou->flags & !!(fou->flags &
FOU_F_REMCSUM_NOPARTIAL)); FOU_F_REMCSUM_NOPARTIAL));
if (!guehdr) if (!guehdr)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment