1e456a18aSEric Dumazet // SPDX-License-Identifier: GPL-2.0-or-later
2e456a18aSEric Dumazet #include <net/gro.h>
3587652bbSEric Dumazet #include <net/dst_metadata.h>
4587652bbSEric Dumazet #include <net/busy_poll.h>
5587652bbSEric Dumazet #include <trace/events/net.h>
6587652bbSEric Dumazet
7587652bbSEric Dumazet #define MAX_GRO_SKBS 8
8587652bbSEric Dumazet
9587652bbSEric Dumazet /* This should be increased if a protocol with a bigger head is added. */
10587652bbSEric Dumazet #define GRO_MAX_HEAD (MAX_HEADER + 128)
11587652bbSEric Dumazet
12587652bbSEric Dumazet static DEFINE_SPINLOCK(offload_lock);
13d457a0e3SEric Dumazet struct list_head offload_base __read_mostly = LIST_HEAD_INIT(offload_base);
14587652bbSEric Dumazet /* Maximum number of GRO_NORMAL skbs to batch up for list-RX */
15587652bbSEric Dumazet int gro_normal_batch __read_mostly = 8;
16587652bbSEric Dumazet
17587652bbSEric Dumazet /**
18587652bbSEric Dumazet * dev_add_offload - register offload handlers
19587652bbSEric Dumazet * @po: protocol offload declaration
20587652bbSEric Dumazet *
21587652bbSEric Dumazet * Add protocol offload handlers to the networking stack. The passed
22587652bbSEric Dumazet * &proto_offload is linked into kernel lists and may not be freed until
23587652bbSEric Dumazet * it has been removed from the kernel lists.
24587652bbSEric Dumazet *
25587652bbSEric Dumazet * This call does not sleep therefore it can not
26587652bbSEric Dumazet * guarantee all CPU's that are in middle of receiving packets
27587652bbSEric Dumazet * will see the new offload handlers (until the next received packet).
28587652bbSEric Dumazet */
dev_add_offload(struct packet_offload * po)29587652bbSEric Dumazet void dev_add_offload(struct packet_offload *po)
30587652bbSEric Dumazet {
31587652bbSEric Dumazet struct packet_offload *elem;
32587652bbSEric Dumazet
33587652bbSEric Dumazet spin_lock(&offload_lock);
34587652bbSEric Dumazet list_for_each_entry(elem, &offload_base, list) {
35587652bbSEric Dumazet if (po->priority < elem->priority)
36587652bbSEric Dumazet break;
37587652bbSEric Dumazet }
38587652bbSEric Dumazet list_add_rcu(&po->list, elem->list.prev);
39587652bbSEric Dumazet spin_unlock(&offload_lock);
40587652bbSEric Dumazet }
41587652bbSEric Dumazet EXPORT_SYMBOL(dev_add_offload);
42587652bbSEric Dumazet
43587652bbSEric Dumazet /**
44587652bbSEric Dumazet * __dev_remove_offload - remove offload handler
45587652bbSEric Dumazet * @po: packet offload declaration
46587652bbSEric Dumazet *
47587652bbSEric Dumazet * Remove a protocol offload handler that was previously added to the
48587652bbSEric Dumazet * kernel offload handlers by dev_add_offload(). The passed &offload_type
49587652bbSEric Dumazet * is removed from the kernel lists and can be freed or reused once this
50587652bbSEric Dumazet * function returns.
51587652bbSEric Dumazet *
52587652bbSEric Dumazet * The packet type might still be in use by receivers
53587652bbSEric Dumazet * and must not be freed until after all the CPU's have gone
54587652bbSEric Dumazet * through a quiescent state.
55587652bbSEric Dumazet */
__dev_remove_offload(struct packet_offload * po)56587652bbSEric Dumazet static void __dev_remove_offload(struct packet_offload *po)
57587652bbSEric Dumazet {
58587652bbSEric Dumazet struct list_head *head = &offload_base;
59587652bbSEric Dumazet struct packet_offload *po1;
60587652bbSEric Dumazet
61587652bbSEric Dumazet spin_lock(&offload_lock);
62587652bbSEric Dumazet
63587652bbSEric Dumazet list_for_each_entry(po1, head, list) {
64587652bbSEric Dumazet if (po == po1) {
65587652bbSEric Dumazet list_del_rcu(&po->list);
66587652bbSEric Dumazet goto out;
67587652bbSEric Dumazet }
68587652bbSEric Dumazet }
69587652bbSEric Dumazet
70587652bbSEric Dumazet pr_warn("dev_remove_offload: %p not found\n", po);
71587652bbSEric Dumazet out:
72587652bbSEric Dumazet spin_unlock(&offload_lock);
73587652bbSEric Dumazet }
74587652bbSEric Dumazet
75587652bbSEric Dumazet /**
76587652bbSEric Dumazet * dev_remove_offload - remove packet offload handler
77587652bbSEric Dumazet * @po: packet offload declaration
78587652bbSEric Dumazet *
79587652bbSEric Dumazet * Remove a packet offload handler that was previously added to the kernel
80587652bbSEric Dumazet * offload handlers by dev_add_offload(). The passed &offload_type is
81587652bbSEric Dumazet * removed from the kernel lists and can be freed or reused once this
82587652bbSEric Dumazet * function returns.
83587652bbSEric Dumazet *
84587652bbSEric Dumazet * This call sleeps to guarantee that no CPU is looking at the packet
85587652bbSEric Dumazet * type after return.
86587652bbSEric Dumazet */
dev_remove_offload(struct packet_offload * po)87587652bbSEric Dumazet void dev_remove_offload(struct packet_offload *po)
88587652bbSEric Dumazet {
89587652bbSEric Dumazet __dev_remove_offload(po);
90587652bbSEric Dumazet
91587652bbSEric Dumazet synchronize_net();
92587652bbSEric Dumazet }
93587652bbSEric Dumazet EXPORT_SYMBOL(dev_remove_offload);
94587652bbSEric Dumazet
95e456a18aSEric Dumazet
skb_gro_receive(struct sk_buff * p,struct sk_buff * skb)96e456a18aSEric Dumazet int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
97e456a18aSEric Dumazet {
98e456a18aSEric Dumazet struct skb_shared_info *pinfo, *skbinfo = skb_shinfo(skb);
99e456a18aSEric Dumazet unsigned int offset = skb_gro_offset(skb);
100e456a18aSEric Dumazet unsigned int headlen = skb_headlen(skb);
101e456a18aSEric Dumazet unsigned int len = skb_gro_len(skb);
102e456a18aSEric Dumazet unsigned int delta_truesize;
103e456a18aSEric Dumazet unsigned int new_truesize;
104e456a18aSEric Dumazet struct sk_buff *lp;
1055eddb249SCoco Li int segs;
106e456a18aSEric Dumazet
1077d2c89b3SAlexander Duyck /* Do not splice page pool based packets w/ non-page pool
1087d2c89b3SAlexander Duyck * packets. This can result in reference count issues as page
1097d2c89b3SAlexander Duyck * pool pages will not decrement the reference count and will
1107d2c89b3SAlexander Duyck * instead be immediately returned to the pool or have frag
1117d2c89b3SAlexander Duyck * count decremented.
1127d2c89b3SAlexander Duyck */
1137d2c89b3SAlexander Duyck if (p->pp_recycle != skb->pp_recycle)
1147d2c89b3SAlexander Duyck return -ETOOMANYREFS;
1157d2c89b3SAlexander Duyck
116dae9b99bSDaniel Borkmann if (unlikely(p->len + len >= netif_get_gro_max_size(p->dev, p) ||
117dae9b99bSDaniel Borkmann NAPI_GRO_CB(skb)->flush))
118e456a18aSEric Dumazet return -E2BIG;
119e456a18aSEric Dumazet
1200fe79f28SAlexander Duyck if (unlikely(p->len + len >= GRO_LEGACY_MAX_SIZE)) {
121b1a78b9bSXin Long if (NAPI_GRO_CB(skb)->proto != IPPROTO_TCP ||
122b1a78b9bSXin Long (p->protocol == htons(ETH_P_IPV6) &&
123b1a78b9bSXin Long skb_headroom(p) < sizeof(struct hop_jumbo_hdr)) ||
1240fe79f28SAlexander Duyck p->encapsulation)
1250fe79f28SAlexander Duyck return -E2BIG;
1260fe79f28SAlexander Duyck }
1270fe79f28SAlexander Duyck
1285eddb249SCoco Li segs = NAPI_GRO_CB(skb)->count;
129e456a18aSEric Dumazet lp = NAPI_GRO_CB(p)->last;
130e456a18aSEric Dumazet pinfo = skb_shinfo(lp);
131e456a18aSEric Dumazet
132e456a18aSEric Dumazet if (headlen <= offset) {
133e456a18aSEric Dumazet skb_frag_t *frag;
134e456a18aSEric Dumazet skb_frag_t *frag2;
135e456a18aSEric Dumazet int i = skbinfo->nr_frags;
136e456a18aSEric Dumazet int nr_frags = pinfo->nr_frags + i;
137e456a18aSEric Dumazet
138e456a18aSEric Dumazet if (nr_frags > MAX_SKB_FRAGS)
139e456a18aSEric Dumazet goto merge;
140e456a18aSEric Dumazet
141e456a18aSEric Dumazet offset -= headlen;
142e456a18aSEric Dumazet pinfo->nr_frags = nr_frags;
143e456a18aSEric Dumazet skbinfo->nr_frags = 0;
144e456a18aSEric Dumazet
145e456a18aSEric Dumazet frag = pinfo->frags + nr_frags;
146e456a18aSEric Dumazet frag2 = skbinfo->frags + i;
147e456a18aSEric Dumazet do {
148e456a18aSEric Dumazet *--frag = *--frag2;
149e456a18aSEric Dumazet } while (--i);
150e456a18aSEric Dumazet
151e456a18aSEric Dumazet skb_frag_off_add(frag, offset);
152e456a18aSEric Dumazet skb_frag_size_sub(frag, offset);
153e456a18aSEric Dumazet
154e456a18aSEric Dumazet /* all fragments truesize : remove (head size + sk_buff) */
155e456a18aSEric Dumazet new_truesize = SKB_TRUESIZE(skb_end_offset(skb));
156e456a18aSEric Dumazet delta_truesize = skb->truesize - new_truesize;
157e456a18aSEric Dumazet
158e456a18aSEric Dumazet skb->truesize = new_truesize;
159e456a18aSEric Dumazet skb->len -= skb->data_len;
160e456a18aSEric Dumazet skb->data_len = 0;
161e456a18aSEric Dumazet
162e456a18aSEric Dumazet NAPI_GRO_CB(skb)->free = NAPI_GRO_FREE;
163e456a18aSEric Dumazet goto done;
164e456a18aSEric Dumazet } else if (skb->head_frag) {
165e456a18aSEric Dumazet int nr_frags = pinfo->nr_frags;
166e456a18aSEric Dumazet skb_frag_t *frag = pinfo->frags + nr_frags;
167e456a18aSEric Dumazet struct page *page = virt_to_head_page(skb->head);
168e456a18aSEric Dumazet unsigned int first_size = headlen - offset;
169e456a18aSEric Dumazet unsigned int first_offset;
170e456a18aSEric Dumazet
171e456a18aSEric Dumazet if (nr_frags + 1 + skbinfo->nr_frags > MAX_SKB_FRAGS)
172e456a18aSEric Dumazet goto merge;
173e456a18aSEric Dumazet
174e456a18aSEric Dumazet first_offset = skb->data -
175e456a18aSEric Dumazet (unsigned char *)page_address(page) +
176e456a18aSEric Dumazet offset;
177e456a18aSEric Dumazet
178e456a18aSEric Dumazet pinfo->nr_frags = nr_frags + 1 + skbinfo->nr_frags;
179e456a18aSEric Dumazet
180b51f4113SYunsheng Lin skb_frag_fill_page_desc(frag, page, first_offset, first_size);
181e456a18aSEric Dumazet
182e456a18aSEric Dumazet memcpy(frag + 1, skbinfo->frags, sizeof(*frag) * skbinfo->nr_frags);
183e456a18aSEric Dumazet /* We dont need to clear skbinfo->nr_frags here */
184e456a18aSEric Dumazet
185e456a18aSEric Dumazet new_truesize = SKB_DATA_ALIGN(sizeof(struct sk_buff));
186e456a18aSEric Dumazet delta_truesize = skb->truesize - new_truesize;
187e456a18aSEric Dumazet skb->truesize = new_truesize;
188e456a18aSEric Dumazet NAPI_GRO_CB(skb)->free = NAPI_GRO_FREE_STOLEN_HEAD;
189e456a18aSEric Dumazet goto done;
190e456a18aSEric Dumazet }
191e456a18aSEric Dumazet
192e456a18aSEric Dumazet merge:
193fc126c1dSAntoine Tenart /* sk ownership - if any - completely transferred to the aggregated packet */
194e456a18aSEric Dumazet skb->destructor = NULL;
195fc126c1dSAntoine Tenart skb->sk = NULL;
196e456a18aSEric Dumazet delta_truesize = skb->truesize;
197e456a18aSEric Dumazet if (offset > headlen) {
198e456a18aSEric Dumazet unsigned int eat = offset - headlen;
199e456a18aSEric Dumazet
200e456a18aSEric Dumazet skb_frag_off_add(&skbinfo->frags[0], eat);
201e456a18aSEric Dumazet skb_frag_size_sub(&skbinfo->frags[0], eat);
202e456a18aSEric Dumazet skb->data_len -= eat;
203e456a18aSEric Dumazet skb->len -= eat;
204e456a18aSEric Dumazet offset = headlen;
205e456a18aSEric Dumazet }
206e456a18aSEric Dumazet
207e456a18aSEric Dumazet __skb_pull(skb, offset);
208e456a18aSEric Dumazet
209e456a18aSEric Dumazet if (NAPI_GRO_CB(p)->last == p)
210e456a18aSEric Dumazet skb_shinfo(p)->frag_list = skb;
211e456a18aSEric Dumazet else
212e456a18aSEric Dumazet NAPI_GRO_CB(p)->last->next = skb;
213e456a18aSEric Dumazet NAPI_GRO_CB(p)->last = skb;
214e456a18aSEric Dumazet __skb_header_release(skb);
215e456a18aSEric Dumazet lp = p;
216e456a18aSEric Dumazet
217e456a18aSEric Dumazet done:
2185eddb249SCoco Li NAPI_GRO_CB(p)->count += segs;
219e456a18aSEric Dumazet p->data_len += len;
220e456a18aSEric Dumazet p->truesize += delta_truesize;
221e456a18aSEric Dumazet p->len += len;
222e456a18aSEric Dumazet if (lp != p) {
223e456a18aSEric Dumazet lp->data_len += len;
224e456a18aSEric Dumazet lp->truesize += delta_truesize;
225e456a18aSEric Dumazet lp->len += len;
226e456a18aSEric Dumazet }
227e456a18aSEric Dumazet NAPI_GRO_CB(skb)->same_flow = 1;
228e456a18aSEric Dumazet return 0;
229e456a18aSEric Dumazet }
230587652bbSEric Dumazet
231587652bbSEric Dumazet
napi_gro_complete(struct napi_struct * napi,struct sk_buff * skb)232587652bbSEric Dumazet static void napi_gro_complete(struct napi_struct *napi, struct sk_buff *skb)
233587652bbSEric Dumazet {
234587652bbSEric Dumazet struct packet_offload *ptype;
235587652bbSEric Dumazet __be16 type = skb->protocol;
236587652bbSEric Dumazet struct list_head *head = &offload_base;
237587652bbSEric Dumazet int err = -ENOENT;
238587652bbSEric Dumazet
239587652bbSEric Dumazet BUILD_BUG_ON(sizeof(struct napi_gro_cb) > sizeof(skb->cb));
240587652bbSEric Dumazet
241587652bbSEric Dumazet if (NAPI_GRO_CB(skb)->count == 1) {
242587652bbSEric Dumazet skb_shinfo(skb)->gso_size = 0;
243587652bbSEric Dumazet goto out;
244587652bbSEric Dumazet }
245587652bbSEric Dumazet
246587652bbSEric Dumazet rcu_read_lock();
247587652bbSEric Dumazet list_for_each_entry_rcu(ptype, head, list) {
248587652bbSEric Dumazet if (ptype->type != type || !ptype->callbacks.gro_complete)
249587652bbSEric Dumazet continue;
250587652bbSEric Dumazet
251587652bbSEric Dumazet err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete,
252587652bbSEric Dumazet ipv6_gro_complete, inet_gro_complete,
253587652bbSEric Dumazet skb, 0);
254587652bbSEric Dumazet break;
255587652bbSEric Dumazet }
256587652bbSEric Dumazet rcu_read_unlock();
257587652bbSEric Dumazet
258587652bbSEric Dumazet if (err) {
259587652bbSEric Dumazet WARN_ON(&ptype->list == head);
260587652bbSEric Dumazet kfree_skb(skb);
261587652bbSEric Dumazet return;
262587652bbSEric Dumazet }
263587652bbSEric Dumazet
264587652bbSEric Dumazet out:
265587652bbSEric Dumazet gro_normal_one(napi, skb, NAPI_GRO_CB(skb)->count);
266587652bbSEric Dumazet }
267587652bbSEric Dumazet
__napi_gro_flush_chain(struct napi_struct * napi,u32 index,bool flush_old)268587652bbSEric Dumazet static void __napi_gro_flush_chain(struct napi_struct *napi, u32 index,
269587652bbSEric Dumazet bool flush_old)
270587652bbSEric Dumazet {
271587652bbSEric Dumazet struct list_head *head = &napi->gro_hash[index].list;
272587652bbSEric Dumazet struct sk_buff *skb, *p;
273587652bbSEric Dumazet
274587652bbSEric Dumazet list_for_each_entry_safe_reverse(skb, p, head, list) {
275587652bbSEric Dumazet if (flush_old && NAPI_GRO_CB(skb)->age == jiffies)
276587652bbSEric Dumazet return;
277587652bbSEric Dumazet skb_list_del_init(skb);
278587652bbSEric Dumazet napi_gro_complete(napi, skb);
279587652bbSEric Dumazet napi->gro_hash[index].count--;
280587652bbSEric Dumazet }
281587652bbSEric Dumazet
282587652bbSEric Dumazet if (!napi->gro_hash[index].count)
283587652bbSEric Dumazet __clear_bit(index, &napi->gro_bitmask);
284587652bbSEric Dumazet }
285587652bbSEric Dumazet
286587652bbSEric Dumazet /* napi->gro_hash[].list contains packets ordered by age.
287587652bbSEric Dumazet * youngest packets at the head of it.
288587652bbSEric Dumazet * Complete skbs in reverse order to reduce latencies.
289587652bbSEric Dumazet */
napi_gro_flush(struct napi_struct * napi,bool flush_old)290587652bbSEric Dumazet void napi_gro_flush(struct napi_struct *napi, bool flush_old)
291587652bbSEric Dumazet {
292587652bbSEric Dumazet unsigned long bitmask = napi->gro_bitmask;
293587652bbSEric Dumazet unsigned int i, base = ~0U;
294587652bbSEric Dumazet
295587652bbSEric Dumazet while ((i = ffs(bitmask)) != 0) {
296587652bbSEric Dumazet bitmask >>= i;
297587652bbSEric Dumazet base += i;
298587652bbSEric Dumazet __napi_gro_flush_chain(napi, base, flush_old);
299587652bbSEric Dumazet }
300587652bbSEric Dumazet }
301587652bbSEric Dumazet EXPORT_SYMBOL(napi_gro_flush);
302587652bbSEric Dumazet
gro_list_prepare_tc_ext(const struct sk_buff * skb,const struct sk_buff * p,unsigned long diffs)3032dc6af8bSJakub Kicinski static unsigned long gro_list_prepare_tc_ext(const struct sk_buff *skb,
3042dc6af8bSJakub Kicinski const struct sk_buff *p,
3052dc6af8bSJakub Kicinski unsigned long diffs)
3062dc6af8bSJakub Kicinski {
3072dc6af8bSJakub Kicinski #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
3082dc6af8bSJakub Kicinski struct tc_skb_ext *skb_ext;
3092dc6af8bSJakub Kicinski struct tc_skb_ext *p_ext;
3102dc6af8bSJakub Kicinski
3112dc6af8bSJakub Kicinski skb_ext = skb_ext_find(skb, TC_SKB_EXT);
3122dc6af8bSJakub Kicinski p_ext = skb_ext_find(p, TC_SKB_EXT);
3132dc6af8bSJakub Kicinski
3142dc6af8bSJakub Kicinski diffs |= (!!p_ext) ^ (!!skb_ext);
3152dc6af8bSJakub Kicinski if (!diffs && unlikely(skb_ext))
3162dc6af8bSJakub Kicinski diffs |= p_ext->chain ^ skb_ext->chain;
3172dc6af8bSJakub Kicinski #endif
3182dc6af8bSJakub Kicinski return diffs;
3192dc6af8bSJakub Kicinski }
3202dc6af8bSJakub Kicinski
gro_list_prepare(const struct list_head * head,const struct sk_buff * skb)321587652bbSEric Dumazet static void gro_list_prepare(const struct list_head *head,
322587652bbSEric Dumazet const struct sk_buff *skb)
323587652bbSEric Dumazet {
324587652bbSEric Dumazet unsigned int maclen = skb->dev->hard_header_len;
325587652bbSEric Dumazet u32 hash = skb_get_hash_raw(skb);
326587652bbSEric Dumazet struct sk_buff *p;
327587652bbSEric Dumazet
328587652bbSEric Dumazet list_for_each_entry(p, head, list) {
329587652bbSEric Dumazet unsigned long diffs;
330587652bbSEric Dumazet
331587652bbSEric Dumazet NAPI_GRO_CB(p)->flush = 0;
332587652bbSEric Dumazet
333587652bbSEric Dumazet if (hash != skb_get_hash_raw(p)) {
334587652bbSEric Dumazet NAPI_GRO_CB(p)->same_flow = 0;
335587652bbSEric Dumazet continue;
336587652bbSEric Dumazet }
337587652bbSEric Dumazet
338587652bbSEric Dumazet diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev;
339be3ed486SEric Dumazet diffs |= p->vlan_all ^ skb->vlan_all;
340587652bbSEric Dumazet diffs |= skb_metadata_differs(p, skb);
341587652bbSEric Dumazet if (maclen == ETH_HLEN)
342587652bbSEric Dumazet diffs |= compare_ether_header(skb_mac_header(p),
343587652bbSEric Dumazet skb_mac_header(skb));
344587652bbSEric Dumazet else if (!diffs)
345587652bbSEric Dumazet diffs = memcmp(skb_mac_header(p),
346587652bbSEric Dumazet skb_mac_header(skb),
347587652bbSEric Dumazet maclen);
348587652bbSEric Dumazet
349587652bbSEric Dumazet /* in most common scenarions 'slow_gro' is 0
350587652bbSEric Dumazet * otherwise we are already on some slower paths
351587652bbSEric Dumazet * either skip all the infrequent tests altogether or
352587652bbSEric Dumazet * avoid trying too hard to skip each of them individually
353587652bbSEric Dumazet */
354587652bbSEric Dumazet if (!diffs && unlikely(skb->slow_gro | p->slow_gro)) {
355587652bbSEric Dumazet diffs |= p->sk != skb->sk;
356587652bbSEric Dumazet diffs |= skb_metadata_dst_cmp(p, skb);
357587652bbSEric Dumazet diffs |= skb_get_nfct(p) ^ skb_get_nfct(skb);
358587652bbSEric Dumazet
3592dc6af8bSJakub Kicinski diffs |= gro_list_prepare_tc_ext(skb, p, diffs);
360587652bbSEric Dumazet }
361587652bbSEric Dumazet
362587652bbSEric Dumazet NAPI_GRO_CB(p)->same_flow = !diffs;
363587652bbSEric Dumazet }
364587652bbSEric Dumazet }
365587652bbSEric Dumazet
skb_gro_reset_offset(struct sk_buff * skb,u32 nhoff)366587652bbSEric Dumazet static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff)
367587652bbSEric Dumazet {
368587652bbSEric Dumazet const struct skb_shared_info *pinfo = skb_shinfo(skb);
369587652bbSEric Dumazet const skb_frag_t *frag0 = &pinfo->frags[0];
370587652bbSEric Dumazet
371af276a5aSRichard Gobert NAPI_GRO_CB(skb)->network_offset = 0;
372587652bbSEric Dumazet NAPI_GRO_CB(skb)->data_offset = 0;
373587652bbSEric Dumazet NAPI_GRO_CB(skb)->frag0 = NULL;
374587652bbSEric Dumazet NAPI_GRO_CB(skb)->frag0_len = 0;
375587652bbSEric Dumazet
376587652bbSEric Dumazet if (!skb_headlen(skb) && pinfo->nr_frags &&
377587652bbSEric Dumazet !PageHighMem(skb_frag_page(frag0)) &&
378587652bbSEric Dumazet (!NET_IP_ALIGN || !((skb_frag_off(frag0) + nhoff) & 3))) {
379587652bbSEric Dumazet NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0);
380587652bbSEric Dumazet NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int,
381587652bbSEric Dumazet skb_frag_size(frag0),
382587652bbSEric Dumazet skb->end - skb->tail);
383587652bbSEric Dumazet }
384587652bbSEric Dumazet }
385587652bbSEric Dumazet
gro_pull_from_frag0(struct sk_buff * skb,int grow)386587652bbSEric Dumazet static void gro_pull_from_frag0(struct sk_buff *skb, int grow)
387587652bbSEric Dumazet {
388587652bbSEric Dumazet struct skb_shared_info *pinfo = skb_shinfo(skb);
389587652bbSEric Dumazet
390587652bbSEric Dumazet BUG_ON(skb->end - skb->tail < grow);
391587652bbSEric Dumazet
392587652bbSEric Dumazet memcpy(skb_tail_pointer(skb), NAPI_GRO_CB(skb)->frag0, grow);
393587652bbSEric Dumazet
394587652bbSEric Dumazet skb->data_len -= grow;
395587652bbSEric Dumazet skb->tail += grow;
396587652bbSEric Dumazet
397587652bbSEric Dumazet skb_frag_off_add(&pinfo->frags[0], grow);
398587652bbSEric Dumazet skb_frag_size_sub(&pinfo->frags[0], grow);
399587652bbSEric Dumazet
400587652bbSEric Dumazet if (unlikely(!skb_frag_size(&pinfo->frags[0]))) {
401587652bbSEric Dumazet skb_frag_unref(skb, 0);
402587652bbSEric Dumazet memmove(pinfo->frags, pinfo->frags + 1,
403587652bbSEric Dumazet --pinfo->nr_frags * sizeof(pinfo->frags[0]));
404587652bbSEric Dumazet }
405587652bbSEric Dumazet }
406587652bbSEric Dumazet
gro_try_pull_from_frag0(struct sk_buff * skb)4077b355b76SRichard Gobert static void gro_try_pull_from_frag0(struct sk_buff *skb)
4087b355b76SRichard Gobert {
4097b355b76SRichard Gobert int grow = skb_gro_offset(skb) - skb_headlen(skb);
4107b355b76SRichard Gobert
4117b355b76SRichard Gobert if (grow > 0)
4127b355b76SRichard Gobert gro_pull_from_frag0(skb, grow);
4137b355b76SRichard Gobert }
4147b355b76SRichard Gobert
gro_flush_oldest(struct napi_struct * napi,struct list_head * head)415587652bbSEric Dumazet static void gro_flush_oldest(struct napi_struct *napi, struct list_head *head)
416587652bbSEric Dumazet {
417587652bbSEric Dumazet struct sk_buff *oldest;
418587652bbSEric Dumazet
419587652bbSEric Dumazet oldest = list_last_entry(head, struct sk_buff, list);
420587652bbSEric Dumazet
421587652bbSEric Dumazet /* We are called with head length >= MAX_GRO_SKBS, so this is
422587652bbSEric Dumazet * impossible.
423587652bbSEric Dumazet */
424587652bbSEric Dumazet if (WARN_ON_ONCE(!oldest))
425587652bbSEric Dumazet return;
426587652bbSEric Dumazet
427587652bbSEric Dumazet /* Do not adjust napi->gro_hash[].count, caller is adding a new
428587652bbSEric Dumazet * SKB to the chain.
429587652bbSEric Dumazet */
430587652bbSEric Dumazet skb_list_del_init(oldest);
431587652bbSEric Dumazet napi_gro_complete(napi, oldest);
432587652bbSEric Dumazet }
433587652bbSEric Dumazet
dev_gro_receive(struct napi_struct * napi,struct sk_buff * skb)434587652bbSEric Dumazet static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
435587652bbSEric Dumazet {
436587652bbSEric Dumazet u32 bucket = skb_get_hash_raw(skb) & (GRO_HASH_BUCKETS - 1);
437587652bbSEric Dumazet struct gro_list *gro_list = &napi->gro_hash[bucket];
438587652bbSEric Dumazet struct list_head *head = &offload_base;
439587652bbSEric Dumazet struct packet_offload *ptype;
440587652bbSEric Dumazet __be16 type = skb->protocol;
441587652bbSEric Dumazet struct sk_buff *pp = NULL;
442587652bbSEric Dumazet enum gro_result ret;
443587652bbSEric Dumazet int same_flow;
444587652bbSEric Dumazet
445587652bbSEric Dumazet if (netif_elide_gro(skb->dev))
446587652bbSEric Dumazet goto normal;
447587652bbSEric Dumazet
448587652bbSEric Dumazet gro_list_prepare(&gro_list->list, skb);
449587652bbSEric Dumazet
450587652bbSEric Dumazet rcu_read_lock();
451587652bbSEric Dumazet list_for_each_entry_rcu(ptype, head, list) {
452e081ecf0SRichard Gobert if (ptype->type == type && ptype->callbacks.gro_receive)
453e081ecf0SRichard Gobert goto found_ptype;
454e081ecf0SRichard Gobert }
455e081ecf0SRichard Gobert rcu_read_unlock();
456e081ecf0SRichard Gobert goto normal;
457587652bbSEric Dumazet
458e081ecf0SRichard Gobert found_ptype:
459587652bbSEric Dumazet skb_set_network_header(skb, skb_gro_offset(skb));
460587652bbSEric Dumazet skb_reset_mac_len(skb);
461de5a1f3cSPaolo Abeni BUILD_BUG_ON(sizeof_field(struct napi_gro_cb, zeroed) != sizeof(u32));
462de5a1f3cSPaolo Abeni BUILD_BUG_ON(!IS_ALIGNED(offsetof(struct napi_gro_cb, zeroed),
463de5a1f3cSPaolo Abeni sizeof(u32))); /* Avoid slow unaligned acc */
464de5a1f3cSPaolo Abeni *(u32 *)&NAPI_GRO_CB(skb)->zeroed = 0;
4655eddb249SCoco Li NAPI_GRO_CB(skb)->flush = skb_has_frag_list(skb);
466587652bbSEric Dumazet NAPI_GRO_CB(skb)->is_atomic = 1;
4675eddb249SCoco Li NAPI_GRO_CB(skb)->count = 1;
4685eddb249SCoco Li if (unlikely(skb_is_gso(skb))) {
4695eddb249SCoco Li NAPI_GRO_CB(skb)->count = skb_shinfo(skb)->gso_segs;
4707871f54eSEric Dumazet /* Only support TCP and non DODGY users. */
4717871f54eSEric Dumazet if (!skb_is_gso_tcp(skb) ||
4727871f54eSEric Dumazet (skb_shinfo(skb)->gso_type & SKB_GSO_DODGY))
4735eddb249SCoco Li NAPI_GRO_CB(skb)->flush = 1;
4745eddb249SCoco Li }
475587652bbSEric Dumazet
476587652bbSEric Dumazet /* Setup for GRO checksum validation */
477587652bbSEric Dumazet switch (skb->ip_summed) {
478587652bbSEric Dumazet case CHECKSUM_COMPLETE:
479587652bbSEric Dumazet NAPI_GRO_CB(skb)->csum = skb->csum;
480587652bbSEric Dumazet NAPI_GRO_CB(skb)->csum_valid = 1;
481587652bbSEric Dumazet break;
482587652bbSEric Dumazet case CHECKSUM_UNNECESSARY:
483587652bbSEric Dumazet NAPI_GRO_CB(skb)->csum_cnt = skb->csum_level + 1;
484587652bbSEric Dumazet break;
485587652bbSEric Dumazet }
486587652bbSEric Dumazet
487587652bbSEric Dumazet pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive,
488587652bbSEric Dumazet ipv6_gro_receive, inet_gro_receive,
489587652bbSEric Dumazet &gro_list->list, skb);
490587652bbSEric Dumazet
491e081ecf0SRichard Gobert rcu_read_unlock();
492587652bbSEric Dumazet
493587652bbSEric Dumazet if (PTR_ERR(pp) == -EINPROGRESS) {
494587652bbSEric Dumazet ret = GRO_CONSUMED;
495587652bbSEric Dumazet goto ok;
496587652bbSEric Dumazet }
497587652bbSEric Dumazet
498587652bbSEric Dumazet same_flow = NAPI_GRO_CB(skb)->same_flow;
499587652bbSEric Dumazet ret = NAPI_GRO_CB(skb)->free ? GRO_MERGED_FREE : GRO_MERGED;
500587652bbSEric Dumazet
501587652bbSEric Dumazet if (pp) {
502587652bbSEric Dumazet skb_list_del_init(pp);
503587652bbSEric Dumazet napi_gro_complete(napi, pp);
504587652bbSEric Dumazet gro_list->count--;
505587652bbSEric Dumazet }
506587652bbSEric Dumazet
507587652bbSEric Dumazet if (same_flow)
508587652bbSEric Dumazet goto ok;
509587652bbSEric Dumazet
510587652bbSEric Dumazet if (NAPI_GRO_CB(skb)->flush)
511587652bbSEric Dumazet goto normal;
512587652bbSEric Dumazet
513587652bbSEric Dumazet if (unlikely(gro_list->count >= MAX_GRO_SKBS))
514587652bbSEric Dumazet gro_flush_oldest(napi, &gro_list->list);
515587652bbSEric Dumazet else
516587652bbSEric Dumazet gro_list->count++;
517587652bbSEric Dumazet
5187b355b76SRichard Gobert /* Must be called before setting NAPI_GRO_CB(skb)->{age|last} */
5197b355b76SRichard Gobert gro_try_pull_from_frag0(skb);
520587652bbSEric Dumazet NAPI_GRO_CB(skb)->age = jiffies;
521587652bbSEric Dumazet NAPI_GRO_CB(skb)->last = skb;
5225eddb249SCoco Li if (!skb_is_gso(skb))
523587652bbSEric Dumazet skb_shinfo(skb)->gso_size = skb_gro_len(skb);
524587652bbSEric Dumazet list_add(&skb->list, &gro_list->list);
525587652bbSEric Dumazet ret = GRO_HELD;
526587652bbSEric Dumazet ok:
527587652bbSEric Dumazet if (gro_list->count) {
528587652bbSEric Dumazet if (!test_bit(bucket, &napi->gro_bitmask))
529587652bbSEric Dumazet __set_bit(bucket, &napi->gro_bitmask);
530587652bbSEric Dumazet } else if (test_bit(bucket, &napi->gro_bitmask)) {
531587652bbSEric Dumazet __clear_bit(bucket, &napi->gro_bitmask);
532587652bbSEric Dumazet }
533587652bbSEric Dumazet
534587652bbSEric Dumazet return ret;
535587652bbSEric Dumazet
536587652bbSEric Dumazet normal:
537587652bbSEric Dumazet ret = GRO_NORMAL;
5387b355b76SRichard Gobert gro_try_pull_from_frag0(skb);
5397b355b76SRichard Gobert goto ok;
540587652bbSEric Dumazet }
541587652bbSEric Dumazet
gro_find_receive_by_type(__be16 type)542587652bbSEric Dumazet struct packet_offload *gro_find_receive_by_type(__be16 type)
543587652bbSEric Dumazet {
544587652bbSEric Dumazet struct list_head *offload_head = &offload_base;
545587652bbSEric Dumazet struct packet_offload *ptype;
546587652bbSEric Dumazet
547587652bbSEric Dumazet list_for_each_entry_rcu(ptype, offload_head, list) {
548587652bbSEric Dumazet if (ptype->type != type || !ptype->callbacks.gro_receive)
549587652bbSEric Dumazet continue;
550587652bbSEric Dumazet return ptype;
551587652bbSEric Dumazet }
552587652bbSEric Dumazet return NULL;
553587652bbSEric Dumazet }
554587652bbSEric Dumazet EXPORT_SYMBOL(gro_find_receive_by_type);
555587652bbSEric Dumazet
gro_find_complete_by_type(__be16 type)556587652bbSEric Dumazet struct packet_offload *gro_find_complete_by_type(__be16 type)
557587652bbSEric Dumazet {
558587652bbSEric Dumazet struct list_head *offload_head = &offload_base;
559587652bbSEric Dumazet struct packet_offload *ptype;
560587652bbSEric Dumazet
561587652bbSEric Dumazet list_for_each_entry_rcu(ptype, offload_head, list) {
562587652bbSEric Dumazet if (ptype->type != type || !ptype->callbacks.gro_complete)
563587652bbSEric Dumazet continue;
564587652bbSEric Dumazet return ptype;
565587652bbSEric Dumazet }
566587652bbSEric Dumazet return NULL;
567587652bbSEric Dumazet }
568587652bbSEric Dumazet EXPORT_SYMBOL(gro_find_complete_by_type);
569587652bbSEric Dumazet
napi_skb_finish(struct napi_struct * napi,struct sk_buff * skb,gro_result_t ret)570587652bbSEric Dumazet static gro_result_t napi_skb_finish(struct napi_struct *napi,
571587652bbSEric Dumazet struct sk_buff *skb,
572587652bbSEric Dumazet gro_result_t ret)
573587652bbSEric Dumazet {
574587652bbSEric Dumazet switch (ret) {
575587652bbSEric Dumazet case GRO_NORMAL:
576587652bbSEric Dumazet gro_normal_one(napi, skb, 1);
577587652bbSEric Dumazet break;
578587652bbSEric Dumazet
579587652bbSEric Dumazet case GRO_MERGED_FREE:
580587652bbSEric Dumazet if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
581587652bbSEric Dumazet napi_skb_free_stolen_head(skb);
582587652bbSEric Dumazet else if (skb->fclone != SKB_FCLONE_UNAVAILABLE)
583587652bbSEric Dumazet __kfree_skb(skb);
584587652bbSEric Dumazet else
5858fa66e4aSJakub Kicinski __napi_kfree_skb(skb, SKB_CONSUMED);
586587652bbSEric Dumazet break;
587587652bbSEric Dumazet
588587652bbSEric Dumazet case GRO_HELD:
589587652bbSEric Dumazet case GRO_MERGED:
590587652bbSEric Dumazet case GRO_CONSUMED:
591587652bbSEric Dumazet break;
592587652bbSEric Dumazet }
593587652bbSEric Dumazet
594587652bbSEric Dumazet return ret;
595587652bbSEric Dumazet }
596587652bbSEric Dumazet
napi_gro_receive(struct napi_struct * napi,struct sk_buff * skb)597587652bbSEric Dumazet gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
598587652bbSEric Dumazet {
599587652bbSEric Dumazet gro_result_t ret;
600587652bbSEric Dumazet
601587652bbSEric Dumazet skb_mark_napi_id(skb, napi);
602587652bbSEric Dumazet trace_napi_gro_receive_entry(skb);
603587652bbSEric Dumazet
604587652bbSEric Dumazet skb_gro_reset_offset(skb, 0);
605587652bbSEric Dumazet
606587652bbSEric Dumazet ret = napi_skb_finish(napi, skb, dev_gro_receive(napi, skb));
607587652bbSEric Dumazet trace_napi_gro_receive_exit(ret);
608587652bbSEric Dumazet
609587652bbSEric Dumazet return ret;
610587652bbSEric Dumazet }
611587652bbSEric Dumazet EXPORT_SYMBOL(napi_gro_receive);
612587652bbSEric Dumazet
napi_reuse_skb(struct napi_struct * napi,struct sk_buff * skb)613587652bbSEric Dumazet static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
614587652bbSEric Dumazet {
615587652bbSEric Dumazet if (unlikely(skb->pfmemalloc)) {
616587652bbSEric Dumazet consume_skb(skb);
617587652bbSEric Dumazet return;
618587652bbSEric Dumazet }
619587652bbSEric Dumazet __skb_pull(skb, skb_headlen(skb));
620587652bbSEric Dumazet /* restore the reserve we had after netdev_alloc_skb_ip_align() */
621587652bbSEric Dumazet skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN - skb_headroom(skb));
622587652bbSEric Dumazet __vlan_hwaccel_clear_tag(skb);
623587652bbSEric Dumazet skb->dev = napi->dev;
624587652bbSEric Dumazet skb->skb_iif = 0;
625587652bbSEric Dumazet
626587652bbSEric Dumazet /* eth_type_trans() assumes pkt_type is PACKET_HOST */
627587652bbSEric Dumazet skb->pkt_type = PACKET_HOST;
628587652bbSEric Dumazet
629587652bbSEric Dumazet skb->encapsulation = 0;
630*28e5a2d1SMohammad Heib skb->ip_summed = CHECKSUM_NONE;
631587652bbSEric Dumazet skb_shinfo(skb)->gso_type = 0;
6325eddb249SCoco Li skb_shinfo(skb)->gso_size = 0;
633587652bbSEric Dumazet if (unlikely(skb->slow_gro)) {
634587652bbSEric Dumazet skb_orphan(skb);
635587652bbSEric Dumazet skb_ext_reset(skb);
636587652bbSEric Dumazet nf_reset_ct(skb);
637587652bbSEric Dumazet skb->slow_gro = 0;
638587652bbSEric Dumazet }
639587652bbSEric Dumazet
640587652bbSEric Dumazet napi->skb = skb;
641587652bbSEric Dumazet }
642587652bbSEric Dumazet
napi_get_frags(struct napi_struct * napi)643587652bbSEric Dumazet struct sk_buff *napi_get_frags(struct napi_struct *napi)
644587652bbSEric Dumazet {
645587652bbSEric Dumazet struct sk_buff *skb = napi->skb;
646587652bbSEric Dumazet
647587652bbSEric Dumazet if (!skb) {
648587652bbSEric Dumazet skb = napi_alloc_skb(napi, GRO_MAX_HEAD);
649587652bbSEric Dumazet if (skb) {
650587652bbSEric Dumazet napi->skb = skb;
651587652bbSEric Dumazet skb_mark_napi_id(skb, napi);
652587652bbSEric Dumazet }
653587652bbSEric Dumazet }
654587652bbSEric Dumazet return skb;
655587652bbSEric Dumazet }
656587652bbSEric Dumazet EXPORT_SYMBOL(napi_get_frags);
657587652bbSEric Dumazet
napi_frags_finish(struct napi_struct * napi,struct sk_buff * skb,gro_result_t ret)658587652bbSEric Dumazet static gro_result_t napi_frags_finish(struct napi_struct *napi,
659587652bbSEric Dumazet struct sk_buff *skb,
660587652bbSEric Dumazet gro_result_t ret)
661587652bbSEric Dumazet {
662587652bbSEric Dumazet switch (ret) {
663587652bbSEric Dumazet case GRO_NORMAL:
664587652bbSEric Dumazet case GRO_HELD:
665587652bbSEric Dumazet __skb_push(skb, ETH_HLEN);
666587652bbSEric Dumazet skb->protocol = eth_type_trans(skb, skb->dev);
667587652bbSEric Dumazet if (ret == GRO_NORMAL)
668587652bbSEric Dumazet gro_normal_one(napi, skb, 1);
669587652bbSEric Dumazet break;
670587652bbSEric Dumazet
671587652bbSEric Dumazet case GRO_MERGED_FREE:
672587652bbSEric Dumazet if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD)
673587652bbSEric Dumazet napi_skb_free_stolen_head(skb);
674587652bbSEric Dumazet else
675587652bbSEric Dumazet napi_reuse_skb(napi, skb);
676587652bbSEric Dumazet break;
677587652bbSEric Dumazet
678587652bbSEric Dumazet case GRO_MERGED:
679587652bbSEric Dumazet case GRO_CONSUMED:
680587652bbSEric Dumazet break;
681587652bbSEric Dumazet }
682587652bbSEric Dumazet
683587652bbSEric Dumazet return ret;
684587652bbSEric Dumazet }
685587652bbSEric Dumazet
686587652bbSEric Dumazet /* Upper GRO stack assumes network header starts at gro_offset=0
687587652bbSEric Dumazet * Drivers could call both napi_gro_frags() and napi_gro_receive()
688587652bbSEric Dumazet * We copy ethernet header into skb->data to have a common layout.
689587652bbSEric Dumazet */
napi_frags_skb(struct napi_struct * napi)690587652bbSEric Dumazet static struct sk_buff *napi_frags_skb(struct napi_struct *napi)
691587652bbSEric Dumazet {
692587652bbSEric Dumazet struct sk_buff *skb = napi->skb;
693587652bbSEric Dumazet const struct ethhdr *eth;
694587652bbSEric Dumazet unsigned int hlen = sizeof(*eth);
695587652bbSEric Dumazet
696587652bbSEric Dumazet napi->skb = NULL;
697587652bbSEric Dumazet
698587652bbSEric Dumazet skb_reset_mac_header(skb);
699587652bbSEric Dumazet skb_gro_reset_offset(skb, hlen);
700587652bbSEric Dumazet
701587652bbSEric Dumazet if (unlikely(skb_gro_header_hard(skb, hlen))) {
702587652bbSEric Dumazet eth = skb_gro_header_slow(skb, hlen, 0);
703587652bbSEric Dumazet if (unlikely(!eth)) {
704587652bbSEric Dumazet net_warn_ratelimited("%s: dropping impossible skb from %s\n",
705587652bbSEric Dumazet __func__, napi->dev->name);
706587652bbSEric Dumazet napi_reuse_skb(napi, skb);
707587652bbSEric Dumazet return NULL;
708587652bbSEric Dumazet }
709587652bbSEric Dumazet } else {
710587652bbSEric Dumazet eth = (const struct ethhdr *)skb->data;
711587652bbSEric Dumazet gro_pull_from_frag0(skb, hlen);
712587652bbSEric Dumazet NAPI_GRO_CB(skb)->frag0 += hlen;
713587652bbSEric Dumazet NAPI_GRO_CB(skb)->frag0_len -= hlen;
714587652bbSEric Dumazet }
715587652bbSEric Dumazet __skb_pull(skb, hlen);
716587652bbSEric Dumazet
717587652bbSEric Dumazet /*
718587652bbSEric Dumazet * This works because the only protocols we care about don't require
719587652bbSEric Dumazet * special handling.
720587652bbSEric Dumazet * We'll fix it up properly in napi_frags_finish()
721587652bbSEric Dumazet */
722587652bbSEric Dumazet skb->protocol = eth->h_proto;
723587652bbSEric Dumazet
724587652bbSEric Dumazet return skb;
725587652bbSEric Dumazet }
726587652bbSEric Dumazet
napi_gro_frags(struct napi_struct * napi)727587652bbSEric Dumazet gro_result_t napi_gro_frags(struct napi_struct *napi)
728587652bbSEric Dumazet {
729587652bbSEric Dumazet gro_result_t ret;
730587652bbSEric Dumazet struct sk_buff *skb = napi_frags_skb(napi);
731587652bbSEric Dumazet
732587652bbSEric Dumazet trace_napi_gro_frags_entry(skb);
733587652bbSEric Dumazet
734587652bbSEric Dumazet ret = napi_frags_finish(napi, skb, dev_gro_receive(napi, skb));
735587652bbSEric Dumazet trace_napi_gro_frags_exit(ret);
736587652bbSEric Dumazet
737587652bbSEric Dumazet return ret;
738587652bbSEric Dumazet }
739587652bbSEric Dumazet EXPORT_SYMBOL(napi_gro_frags);
740587652bbSEric Dumazet
741587652bbSEric Dumazet /* Compute the checksum from gro_offset and return the folded value
742587652bbSEric Dumazet * after adding in any pseudo checksum.
743587652bbSEric Dumazet */
__skb_gro_checksum_complete(struct sk_buff * skb)744587652bbSEric Dumazet __sum16 __skb_gro_checksum_complete(struct sk_buff *skb)
745587652bbSEric Dumazet {
746587652bbSEric Dumazet __wsum wsum;
747587652bbSEric Dumazet __sum16 sum;
748587652bbSEric Dumazet
749587652bbSEric Dumazet wsum = skb_checksum(skb, skb_gro_offset(skb), skb_gro_len(skb), 0);
750587652bbSEric Dumazet
751587652bbSEric Dumazet /* NAPI_GRO_CB(skb)->csum holds pseudo checksum */
752587652bbSEric Dumazet sum = csum_fold(csum_add(NAPI_GRO_CB(skb)->csum, wsum));
753587652bbSEric Dumazet /* See comments in __skb_checksum_complete(). */
754587652bbSEric Dumazet if (likely(!sum)) {
755587652bbSEric Dumazet if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE) &&
756587652bbSEric Dumazet !skb->csum_complete_sw)
757587652bbSEric Dumazet netdev_rx_csum_fault(skb->dev, skb);
758587652bbSEric Dumazet }
759587652bbSEric Dumazet
760587652bbSEric Dumazet NAPI_GRO_CB(skb)->csum = wsum;
761587652bbSEric Dumazet NAPI_GRO_CB(skb)->csum_valid = 1;
762587652bbSEric Dumazet
763587652bbSEric Dumazet return sum;
764587652bbSEric Dumazet }
765587652bbSEric Dumazet EXPORT_SYMBOL(__skb_gro_checksum_complete);
766