Skip to content

Commit 61dfc52

Browse files
committed
net: gro: skb_gro_header helper function
JIRA: https://issues.redhat.com/browse/RHEL-36610 Conflicts: - modified due to already applied commit b0b672c ("vxlan: fix GRO with VXLAN-GPE") - hunk for fou is applied into fou_core.c instead of fou.c due to existing backport of 08d3232 ("net: fou: rename the source for linking") commit 35ffb66 Author: Richard Gobert <richardbgobert@gmail.com> Date: Tue Aug 23 09:10:49 2022 +0200 net: gro: skb_gro_header helper function Introduce a simple helper function to replace a common pattern. When accessing the GRO header, we fetch the pointer from frag0, then test its validity and fetch it from the skb when necessary. This leads to the pattern skb_gro_header_fast -> skb_gro_header_hard -> skb_gro_header_slow recurring many times throughout GRO code. This patch replaces these patterns with a single inlined function call, improving code readability. Signed-off-by: Richard Gobert <richardbgobert@gmail.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20220823071034.GA56142@debian Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent 3d0fe3b commit 61dfc52

File tree

10 files changed

+45
-69
lines changed

10 files changed

+45
-69
lines changed

drivers/net/geneve.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,9 @@ static struct sk_buff *geneve_gro_receive(struct sock *sk,
499499

500500
off_gnv = skb_gro_offset(skb);
501501
hlen = off_gnv + sizeof(*gh);
502-
gh = skb_gro_header_fast(skb, off_gnv);
503-
if (skb_gro_header_hard(skb, hlen)) {
504-
gh = skb_gro_header_slow(skb, hlen, off_gnv);
505-
if (unlikely(!gh))
506-
goto out;
507-
}
502+
gh = skb_gro_header(skb, hlen, off_gnv);
503+
if (unlikely(!gh))
504+
goto out;
508505

509506
if (gh->ver != GENEVE_VER || gh->oam)
510507
goto out;

drivers/net/vxlan/vxlan_core.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,9 @@ static struct vxlanhdr *vxlan_gro_prepare_receive(struct sock *sk,
737737

738738
off_vx = skb_gro_offset(skb);
739739
hlen = off_vx + sizeof(*vh);
740-
vh = skb_gro_header_fast(skb, off_vx);
741-
if (skb_gro_header_hard(skb, hlen)) {
742-
vh = skb_gro_header_slow(skb, hlen, off_vx);
743-
if (unlikely(!vh))
744-
return NULL;
745-
}
740+
vh = skb_gro_header(skb, hlen, off_vx);
741+
if (unlikely(!vh))
742+
return NULL;
746743

747744
skb_gro_postpull_rcsum(skb, vh, sizeof(struct vxlanhdr));
748745

include/net/gro.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
155155
return skb->data + offset;
156156
}
157157

158+
static inline void *skb_gro_header(struct sk_buff *skb,
159+
unsigned int hlen, unsigned int offset)
160+
{
161+
void *ptr;
162+
163+
ptr = skb_gro_header_fast(skb, offset);
164+
if (skb_gro_header_hard(skb, hlen))
165+
ptr = skb_gro_header_slow(skb, hlen, offset);
166+
return ptr;
167+
}
168+
158169
static inline void *skb_gro_network_header(struct sk_buff *skb)
159170
{
160171
return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
@@ -296,12 +307,9 @@ static inline void *skb_gro_remcsum_process(struct sk_buff *skb, void *ptr,
296307
return ptr;
297308
}
298309

299-
ptr = skb_gro_header_fast(skb, off);
300-
if (skb_gro_header_hard(skb, off + plen)) {
301-
ptr = skb_gro_header_slow(skb, off + plen, off);
302-
if (!ptr)
303-
return NULL;
304-
}
310+
ptr = skb_gro_header(skb, off + plen, off);
311+
if (!ptr)
312+
return NULL;
305313

306314
delta = remcsum_adjust(ptr + hdrlen, NAPI_GRO_CB(skb)->csum,
307315
start, offset);
@@ -324,12 +332,9 @@ static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb,
324332
if (!grc->delta)
325333
return;
326334

327-
ptr = skb_gro_header_fast(skb, grc->offset);
328-
if (skb_gro_header_hard(skb, grc->offset + sizeof(u16))) {
329-
ptr = skb_gro_header_slow(skb, plen, grc->offset);
330-
if (!ptr)
331-
return;
332-
}
335+
ptr = skb_gro_header(skb, plen, grc->offset);
336+
if (!ptr)
337+
return;
333338

334339
remcsum_unadjust((__sum16 *)ptr, grc->delta);
335340
}
@@ -400,9 +405,7 @@ static inline struct udphdr *udp_gro_udphdr(struct sk_buff *skb)
400405

401406
off = skb_gro_offset(skb);
402407
hlen = off + sizeof(*uh);
403-
uh = skb_gro_header_fast(skb, off);
404-
if (skb_gro_header_hard(skb, hlen))
405-
uh = skb_gro_header_slow(skb, hlen, off);
408+
uh = skb_gro_header(skb, hlen, off);
406409

407410
return uh;
408411
}

net/8021q/vlan_core.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,9 @@ static struct sk_buff *vlan_gro_receive(struct list_head *head,
474474

475475
off_vlan = skb_gro_offset(skb);
476476
hlen = off_vlan + sizeof(*vhdr);
477-
vhdr = skb_gro_header_fast(skb, off_vlan);
478-
if (skb_gro_header_hard(skb, hlen)) {
479-
vhdr = skb_gro_header_slow(skb, hlen, off_vlan);
480-
if (unlikely(!vhdr))
481-
goto out;
482-
}
477+
vhdr = skb_gro_header(skb, hlen, off_vlan);
478+
if (unlikely(!vhdr))
479+
goto out;
483480

484481
type = vhdr->h_vlan_encapsulated_proto;
485482

net/ethernet/eth.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,9 @@ struct sk_buff *eth_gro_receive(struct list_head *head, struct sk_buff *skb)
418418

419419
off_eth = skb_gro_offset(skb);
420420
hlen = off_eth + sizeof(*eh);
421-
eh = skb_gro_header_fast(skb, off_eth);
422-
if (skb_gro_header_hard(skb, hlen)) {
423-
eh = skb_gro_header_slow(skb, hlen, off_eth);
424-
if (unlikely(!eh))
425-
goto out;
426-
}
421+
eh = skb_gro_header(skb, hlen, off_eth);
422+
if (unlikely(!eh))
423+
goto out;
427424

428425
flush = 0;
429426

net/ipv4/af_inet.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,12 +1487,9 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb)
14871487

14881488
off = skb_gro_offset(skb);
14891489
hlen = off + sizeof(*iph);
1490-
iph = skb_gro_header_fast(skb, off);
1491-
if (skb_gro_header_hard(skb, hlen)) {
1492-
iph = skb_gro_header_slow(skb, hlen, off);
1493-
if (unlikely(!iph))
1494-
goto out;
1495-
}
1490+
iph = skb_gro_header(skb, hlen, off);
1491+
if (unlikely(!iph))
1492+
goto out;
14961493

14971494
proto = iph->protocol;
14981495

net/ipv4/fou_core.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,9 @@ static struct sk_buff *gue_gro_receive(struct sock *sk,
332332
off = skb_gro_offset(skb);
333333
len = off + sizeof(*guehdr);
334334

335-
guehdr = skb_gro_header_fast(skb, off);
336-
if (skb_gro_header_hard(skb, len)) {
337-
guehdr = skb_gro_header_slow(skb, len, off);
338-
if (unlikely(!guehdr))
339-
goto out;
340-
}
335+
guehdr = skb_gro_header(skb, len, off);
336+
if (unlikely(!guehdr))
337+
goto out;
341338

342339
switch (guehdr->version) {
343340
case 0:

net/ipv4/gre_offload.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,9 @@ static struct sk_buff *gre_gro_receive(struct list_head *head,
138138

139139
off = skb_gro_offset(skb);
140140
hlen = off + sizeof(*greh);
141-
greh = skb_gro_header_fast(skb, off);
142-
if (skb_gro_header_hard(skb, hlen)) {
143-
greh = skb_gro_header_slow(skb, hlen, off);
144-
if (unlikely(!greh))
145-
goto out;
146-
}
141+
greh = skb_gro_header(skb, hlen, off);
142+
if (unlikely(!greh))
143+
goto out;
147144

148145
/* Only support version 0 and K (key), C (csum) flags. Note that
149146
* although the support for the S (seq#) flag can be added easily

net/ipv4/tcp_offload.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,9 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb)
195195

196196
off = skb_gro_offset(skb);
197197
hlen = off + sizeof(*th);
198-
th = skb_gro_header_fast(skb, off);
199-
if (skb_gro_header_hard(skb, hlen)) {
200-
th = skb_gro_header_slow(skb, hlen, off);
201-
if (unlikely(!th))
202-
goto out;
203-
}
198+
th = skb_gro_header(skb, hlen, off);
199+
if (unlikely(!th))
200+
goto out;
204201

205202
thlen = th->doff * 4;
206203
if (thlen < sizeof(*th))

net/ipv6/ip6_offload.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,9 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head,
201201

202202
off = skb_gro_offset(skb);
203203
hlen = off + sizeof(*iph);
204-
iph = skb_gro_header_fast(skb, off);
205-
if (skb_gro_header_hard(skb, hlen)) {
206-
iph = skb_gro_header_slow(skb, hlen, off);
207-
if (unlikely(!iph))
208-
goto out;
209-
}
204+
iph = skb_gro_header_slow(skb, hlen, off);
205+
if (unlikely(!iph))
206+
goto out;
210207

211208
skb_set_network_header(skb, off);
212209
skb_gro_pull(skb, sizeof(*iph));

0 commit comments

Comments
 (0)