Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'gro-out-of-core-files'

Eric Dumazet says:

====================
gro: get out of core files

Move GRO related content into net/core/gro.c
and include/net/gro.h.

This reduces GRO scope to where it is really needed,
and shrinks too big files (include/linux/netdevice.h
and net/core/dev.c)
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+1230 -1202
+1
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
··· 25 25 #include <linux/ip.h> 26 26 #include <linux/crash_dump.h> 27 27 #include <net/tcp.h> 28 + #include <net/gro.h> 28 29 #include <net/ipv6.h> 29 30 #include <net/ip6_checksum.h> 30 31 #include <linux/prefetch.h>
+1
drivers/net/ethernet/broadcom/bnxt/bnxt.c
··· 37 37 #include <linux/if_bridge.h> 38 38 #include <linux/rtc.h> 39 39 #include <linux/bpf.h> 40 + #include <net/gro.h> 40 41 #include <net/ip.h> 41 42 #include <net/tcp.h> 42 43 #include <net/udp.h>
+1
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
··· 17 17 #include <linux/skbuff.h> 18 18 #include <linux/sctp.h> 19 19 #include <net/gre.h> 20 + #include <net/gro.h> 20 21 #include <net/ip6_checksum.h> 21 22 #include <net/pkt_cls.h> 22 23 #include <net/tcp.h>
+1
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
··· 37 37 #include <net/ip6_checksum.h> 38 38 #include <net/page_pool.h> 39 39 #include <net/inet_ecn.h> 40 + #include <net/gro.h> 40 41 #include <net/udp.h> 41 42 #include <net/tcp.h> 42 43 #include "en.h"
+1
drivers/net/ethernet/qlogic/qede/qede_fp.c
··· 10 10 #include <linux/bpf_trace.h> 11 11 #include <net/udp_tunnel.h> 12 12 #include <linux/ip.h> 13 + #include <net/gro.h> 13 14 #include <net/ipv6.h> 14 15 #include <net/tcp.h> 15 16 #include <linux/if_ether.h>
+1
drivers/net/geneve.c
··· 17 17 #include <net/gro_cells.h> 18 18 #include <net/rtnetlink.h> 19 19 #include <net/geneve.h> 20 + #include <net/gro.h> 20 21 #include <net/protocol.h> 21 22 22 23 #define GENEVE_NETDEV_VER "0.6"
+1
drivers/net/vxlan.c
··· 17 17 #include <linux/ethtool.h> 18 18 #include <net/arp.h> 19 19 #include <net/ndisc.h> 20 + #include <net/gro.h> 20 21 #include <net/ipv6_stubs.h> 21 22 #include <net/ip.h> 22 23 #include <net/icmp.h>
+1 -350
include/linux/netdevice.h
··· 2520 2520 synchronize_net(); 2521 2521 } 2522 2522 2523 - struct napi_gro_cb { 2524 - /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */ 2525 - void *frag0; 2526 - 2527 - /* Length of frag0. */ 2528 - unsigned int frag0_len; 2529 - 2530 - /* This indicates where we are processing relative to skb->data. */ 2531 - int data_offset; 2532 - 2533 - /* This is non-zero if the packet cannot be merged with the new skb. */ 2534 - u16 flush; 2535 - 2536 - /* Save the IP ID here and check when we get to the transport layer */ 2537 - u16 flush_id; 2538 - 2539 - /* Number of segments aggregated. */ 2540 - u16 count; 2541 - 2542 - /* Start offset for remote checksum offload */ 2543 - u16 gro_remcsum_start; 2544 - 2545 - /* jiffies when first packet was created/queued */ 2546 - unsigned long age; 2547 - 2548 - /* Used in ipv6_gro_receive() and foo-over-udp */ 2549 - u16 proto; 2550 - 2551 - /* This is non-zero if the packet may be of the same flow. */ 2552 - u8 same_flow:1; 2553 - 2554 - /* Used in tunnel GRO receive */ 2555 - u8 encap_mark:1; 2556 - 2557 - /* GRO checksum is valid */ 2558 - u8 csum_valid:1; 2559 - 2560 - /* Number of checksums via CHECKSUM_UNNECESSARY */ 2561 - u8 csum_cnt:3; 2562 - 2563 - /* Free the skb? */ 2564 - u8 free:2; 2565 - #define NAPI_GRO_FREE 1 2566 - #define NAPI_GRO_FREE_STOLEN_HEAD 2 2567 - 2568 - /* Used in foo-over-udp, set in udp[46]_gro_receive */ 2569 - u8 is_ipv6:1; 2570 - 2571 - /* Used in GRE, set in fou/gue_gro_receive */ 2572 - u8 is_fou:1; 2573 - 2574 - /* Used to determine if flush_id can be ignored */ 2575 - u8 is_atomic:1; 2576 - 2577 - /* Number of gro_receive callbacks this packet already went through */ 2578 - u8 recursion_counter:4; 2579 - 2580 - /* GRO is done by frag_list pointer chaining. */ 2581 - u8 is_flist:1; 2582 - 2583 - /* used to support CHECKSUM_COMPLETE for tunneling protocols */ 2584 - __wsum csum; 2585 - 2586 - /* used in skb_gro_receive() slow path */ 2587 - struct sk_buff *last; 2588 - }; 2589 - 2590 - #define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb) 2591 - 2592 - #define GRO_RECURSION_LIMIT 15 2593 - static inline int gro_recursion_inc_test(struct sk_buff *skb) 2594 - { 2595 - return ++NAPI_GRO_CB(skb)->recursion_counter == GRO_RECURSION_LIMIT; 2596 - } 2597 - 2598 - typedef struct sk_buff *(*gro_receive_t)(struct list_head *, struct sk_buff *); 2599 - static inline struct sk_buff *call_gro_receive(gro_receive_t cb, 2600 - struct list_head *head, 2601 - struct sk_buff *skb) 2602 - { 2603 - if (unlikely(gro_recursion_inc_test(skb))) { 2604 - NAPI_GRO_CB(skb)->flush |= 1; 2605 - return NULL; 2606 - } 2607 - 2608 - return cb(head, skb); 2609 - } 2610 - 2611 - typedef struct sk_buff *(*gro_receive_sk_t)(struct sock *, struct list_head *, 2612 - struct sk_buff *); 2613 - static inline struct sk_buff *call_gro_receive_sk(gro_receive_sk_t cb, 2614 - struct sock *sk, 2615 - struct list_head *head, 2616 - struct sk_buff *skb) 2617 - { 2618 - if (unlikely(gro_recursion_inc_test(skb))) { 2619 - NAPI_GRO_CB(skb)->flush |= 1; 2620 - return NULL; 2621 - } 2622 - 2623 - return cb(sk, head, skb); 2624 - } 2625 - 2626 2523 struct packet_type { 2627 2524 __be16 type; /* This is really htons(ether_type). */ 2628 2525 bool ignore_outgoing; ··· 2902 3005 struct net_device *dev_get_by_napi_id(unsigned int napi_id); 2903 3006 int netdev_get_name(struct net *net, char *name, int ifindex); 2904 3007 int dev_restart(struct net_device *dev); 2905 - int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb); 2906 - int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb); 2907 3008 2908 - static inline unsigned int skb_gro_offset(const struct sk_buff *skb) 2909 - { 2910 - return NAPI_GRO_CB(skb)->data_offset; 2911 - } 2912 - 2913 - static inline unsigned int skb_gro_len(const struct sk_buff *skb) 2914 - { 2915 - return skb->len - NAPI_GRO_CB(skb)->data_offset; 2916 - } 2917 - 2918 - static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len) 2919 - { 2920 - NAPI_GRO_CB(skb)->data_offset += len; 2921 - } 2922 - 2923 - static inline void *skb_gro_header_fast(struct sk_buff *skb, 2924 - unsigned int offset) 2925 - { 2926 - return NAPI_GRO_CB(skb)->frag0 + offset; 2927 - } 2928 - 2929 - static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen) 2930 - { 2931 - return NAPI_GRO_CB(skb)->frag0_len < hlen; 2932 - } 2933 - 2934 - static inline void skb_gro_frag0_invalidate(struct sk_buff *skb) 2935 - { 2936 - NAPI_GRO_CB(skb)->frag0 = NULL; 2937 - NAPI_GRO_CB(skb)->frag0_len = 0; 2938 - } 2939 - 2940 - static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen, 2941 - unsigned int offset) 2942 - { 2943 - if (!pskb_may_pull(skb, hlen)) 2944 - return NULL; 2945 - 2946 - skb_gro_frag0_invalidate(skb); 2947 - return skb->data + offset; 2948 - } 2949 - 2950 - static inline void *skb_gro_network_header(struct sk_buff *skb) 2951 - { 2952 - return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) + 2953 - skb_network_offset(skb); 2954 - } 2955 - 2956 - static inline void skb_gro_postpull_rcsum(struct sk_buff *skb, 2957 - const void *start, unsigned int len) 2958 - { 2959 - if (NAPI_GRO_CB(skb)->csum_valid) 2960 - NAPI_GRO_CB(skb)->csum = csum_sub(NAPI_GRO_CB(skb)->csum, 2961 - csum_partial(start, len, 0)); 2962 - } 2963 - 2964 - /* GRO checksum functions. These are logical equivalents of the normal 2965 - * checksum functions (in skbuff.h) except that they operate on the GRO 2966 - * offsets and fields in sk_buff. 2967 - */ 2968 - 2969 - __sum16 __skb_gro_checksum_complete(struct sk_buff *skb); 2970 - 2971 - static inline bool skb_at_gro_remcsum_start(struct sk_buff *skb) 2972 - { 2973 - return (NAPI_GRO_CB(skb)->gro_remcsum_start == skb_gro_offset(skb)); 2974 - } 2975 - 2976 - static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb, 2977 - bool zero_okay, 2978 - __sum16 check) 2979 - { 2980 - return ((skb->ip_summed != CHECKSUM_PARTIAL || 2981 - skb_checksum_start_offset(skb) < 2982 - skb_gro_offset(skb)) && 2983 - !skb_at_gro_remcsum_start(skb) && 2984 - NAPI_GRO_CB(skb)->csum_cnt == 0 && 2985 - (!zero_okay || check)); 2986 - } 2987 - 2988 - static inline __sum16 __skb_gro_checksum_validate_complete(struct sk_buff *skb, 2989 - __wsum psum) 2990 - { 2991 - if (NAPI_GRO_CB(skb)->csum_valid && 2992 - !csum_fold(csum_add(psum, NAPI_GRO_CB(skb)->csum))) 2993 - return 0; 2994 - 2995 - NAPI_GRO_CB(skb)->csum = psum; 2996 - 2997 - return __skb_gro_checksum_complete(skb); 2998 - } 2999 - 3000 - static inline void skb_gro_incr_csum_unnecessary(struct sk_buff *skb) 3001 - { 3002 - if (NAPI_GRO_CB(skb)->csum_cnt > 0) { 3003 - /* Consume a checksum from CHECKSUM_UNNECESSARY */ 3004 - NAPI_GRO_CB(skb)->csum_cnt--; 3005 - } else { 3006 - /* Update skb for CHECKSUM_UNNECESSARY and csum_level when we 3007 - * verified a new top level checksum or an encapsulated one 3008 - * during GRO. This saves work if we fallback to normal path. 3009 - */ 3010 - __skb_incr_checksum_unnecessary(skb); 3011 - } 3012 - } 3013 - 3014 - #define __skb_gro_checksum_validate(skb, proto, zero_okay, check, \ 3015 - compute_pseudo) \ 3016 - ({ \ 3017 - __sum16 __ret = 0; \ 3018 - if (__skb_gro_checksum_validate_needed(skb, zero_okay, check)) \ 3019 - __ret = __skb_gro_checksum_validate_complete(skb, \ 3020 - compute_pseudo(skb, proto)); \ 3021 - if (!__ret) \ 3022 - skb_gro_incr_csum_unnecessary(skb); \ 3023 - __ret; \ 3024 - }) 3025 - 3026 - #define skb_gro_checksum_validate(skb, proto, compute_pseudo) \ 3027 - __skb_gro_checksum_validate(skb, proto, false, 0, compute_pseudo) 3028 - 3029 - #define skb_gro_checksum_validate_zero_check(skb, proto, check, \ 3030 - compute_pseudo) \ 3031 - __skb_gro_checksum_validate(skb, proto, true, check, compute_pseudo) 3032 - 3033 - #define skb_gro_checksum_simple_validate(skb) \ 3034 - __skb_gro_checksum_validate(skb, 0, false, 0, null_compute_pseudo) 3035 - 3036 - static inline bool __skb_gro_checksum_convert_check(struct sk_buff *skb) 3037 - { 3038 - return (NAPI_GRO_CB(skb)->csum_cnt == 0 && 3039 - !NAPI_GRO_CB(skb)->csum_valid); 3040 - } 3041 - 3042 - static inline void __skb_gro_checksum_convert(struct sk_buff *skb, 3043 - __wsum pseudo) 3044 - { 3045 - NAPI_GRO_CB(skb)->csum = ~pseudo; 3046 - NAPI_GRO_CB(skb)->csum_valid = 1; 3047 - } 3048 - 3049 - #define skb_gro_checksum_try_convert(skb, proto, compute_pseudo) \ 3050 - do { \ 3051 - if (__skb_gro_checksum_convert_check(skb)) \ 3052 - __skb_gro_checksum_convert(skb, \ 3053 - compute_pseudo(skb, proto)); \ 3054 - } while (0) 3055 - 3056 - struct gro_remcsum { 3057 - int offset; 3058 - __wsum delta; 3059 - }; 3060 - 3061 - static inline void skb_gro_remcsum_init(struct gro_remcsum *grc) 3062 - { 3063 - grc->offset = 0; 3064 - grc->delta = 0; 3065 - } 3066 - 3067 - static inline void *skb_gro_remcsum_process(struct sk_buff *skb, void *ptr, 3068 - unsigned int off, size_t hdrlen, 3069 - int start, int offset, 3070 - struct gro_remcsum *grc, 3071 - bool nopartial) 3072 - { 3073 - __wsum delta; 3074 - size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start); 3075 - 3076 - BUG_ON(!NAPI_GRO_CB(skb)->csum_valid); 3077 - 3078 - if (!nopartial) { 3079 - NAPI_GRO_CB(skb)->gro_remcsum_start = off + hdrlen + start; 3080 - return ptr; 3081 - } 3082 - 3083 - ptr = skb_gro_header_fast(skb, off); 3084 - if (skb_gro_header_hard(skb, off + plen)) { 3085 - ptr = skb_gro_header_slow(skb, off + plen, off); 3086 - if (!ptr) 3087 - return NULL; 3088 - } 3089 - 3090 - delta = remcsum_adjust(ptr + hdrlen, NAPI_GRO_CB(skb)->csum, 3091 - start, offset); 3092 - 3093 - /* Adjust skb->csum since we changed the packet */ 3094 - NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta); 3095 - 3096 - grc->offset = off + hdrlen + offset; 3097 - grc->delta = delta; 3098 - 3099 - return ptr; 3100 - } 3101 - 3102 - static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb, 3103 - struct gro_remcsum *grc) 3104 - { 3105 - void *ptr; 3106 - size_t plen = grc->offset + sizeof(u16); 3107 - 3108 - if (!grc->delta) 3109 - return; 3110 - 3111 - ptr = skb_gro_header_fast(skb, grc->offset); 3112 - if (skb_gro_header_hard(skb, grc->offset + sizeof(u16))) { 3113 - ptr = skb_gro_header_slow(skb, plen, grc->offset); 3114 - if (!ptr) 3115 - return; 3116 - } 3117 - 3118 - remcsum_unadjust((__sum16 *)ptr, grc->delta); 3119 - } 3120 - 3121 - #ifdef CONFIG_XFRM_OFFLOAD 3122 - static inline void skb_gro_flush_final(struct sk_buff *skb, struct sk_buff *pp, int flush) 3123 - { 3124 - if (PTR_ERR(pp) != -EINPROGRESS) 3125 - NAPI_GRO_CB(skb)->flush |= flush; 3126 - } 3127 - static inline void skb_gro_flush_final_remcsum(struct sk_buff *skb, 3128 - struct sk_buff *pp, 3129 - int flush, 3130 - struct gro_remcsum *grc) 3131 - { 3132 - if (PTR_ERR(pp) != -EINPROGRESS) { 3133 - NAPI_GRO_CB(skb)->flush |= flush; 3134 - skb_gro_remcsum_cleanup(skb, grc); 3135 - skb->remcsum_offload = 0; 3136 - } 3137 - } 3138 - #else 3139 - static inline void skb_gro_flush_final(struct sk_buff *skb, struct sk_buff *pp, int flush) 3140 - { 3141 - NAPI_GRO_CB(skb)->flush |= flush; 3142 - } 3143 - static inline void skb_gro_flush_final_remcsum(struct sk_buff *skb, 3144 - struct sk_buff *pp, 3145 - int flush, 3146 - struct gro_remcsum *grc) 3147 - { 3148 - NAPI_GRO_CB(skb)->flush |= flush; 3149 - skb_gro_remcsum_cleanup(skb, grc); 3150 - skb->remcsum_offload = 0; 3151 - } 3152 - #endif 3153 3009 3154 3010 static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev, 3155 3011 unsigned short type, ··· 3657 4007 int netif_rx_any_context(struct sk_buff *skb); 3658 4008 int netif_receive_skb(struct sk_buff *skb); 3659 4009 int netif_receive_skb_core(struct sk_buff *skb); 4010 + void netif_receive_skb_list_internal(struct list_head *head); 3660 4011 void netif_receive_skb_list(struct list_head *head); 3661 4012 gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb); 3662 4013 void napi_gro_flush(struct napi_struct *napi, bool flush_old);
+418 -2
include/net/gro.h
··· 4 4 #define _NET_IPV6_GRO_H 5 5 6 6 #include <linux/indirect_call_wrapper.h> 7 + #include <linux/ip.h> 8 + #include <linux/ipv6.h> 9 + #include <linux/skbuff.h> 10 + #include <net/udp.h> 7 11 8 - struct list_head; 9 - struct sk_buff; 12 + struct napi_gro_cb { 13 + /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */ 14 + void *frag0; 15 + 16 + /* Length of frag0. */ 17 + unsigned int frag0_len; 18 + 19 + /* This indicates where we are processing relative to skb->data. */ 20 + int data_offset; 21 + 22 + /* This is non-zero if the packet cannot be merged with the new skb. */ 23 + u16 flush; 24 + 25 + /* Save the IP ID here and check when we get to the transport layer */ 26 + u16 flush_id; 27 + 28 + /* Number of segments aggregated. */ 29 + u16 count; 30 + 31 + /* Start offset for remote checksum offload */ 32 + u16 gro_remcsum_start; 33 + 34 + /* jiffies when first packet was created/queued */ 35 + unsigned long age; 36 + 37 + /* Used in ipv6_gro_receive() and foo-over-udp */ 38 + u16 proto; 39 + 40 + /* This is non-zero if the packet may be of the same flow. */ 41 + u8 same_flow:1; 42 + 43 + /* Used in tunnel GRO receive */ 44 + u8 encap_mark:1; 45 + 46 + /* GRO checksum is valid */ 47 + u8 csum_valid:1; 48 + 49 + /* Number of checksums via CHECKSUM_UNNECESSARY */ 50 + u8 csum_cnt:3; 51 + 52 + /* Free the skb? */ 53 + u8 free:2; 54 + #define NAPI_GRO_FREE 1 55 + #define NAPI_GRO_FREE_STOLEN_HEAD 2 56 + 57 + /* Used in foo-over-udp, set in udp[46]_gro_receive */ 58 + u8 is_ipv6:1; 59 + 60 + /* Used in GRE, set in fou/gue_gro_receive */ 61 + u8 is_fou:1; 62 + 63 + /* Used to determine if flush_id can be ignored */ 64 + u8 is_atomic:1; 65 + 66 + /* Number of gro_receive callbacks this packet already went through */ 67 + u8 recursion_counter:4; 68 + 69 + /* GRO is done by frag_list pointer chaining. */ 70 + u8 is_flist:1; 71 + 72 + /* used to support CHECKSUM_COMPLETE for tunneling protocols */ 73 + __wsum csum; 74 + 75 + /* used in skb_gro_receive() slow path */ 76 + struct sk_buff *last; 77 + }; 78 + 79 + #define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb) 80 + 81 + #define GRO_RECURSION_LIMIT 15 82 + static inline int gro_recursion_inc_test(struct sk_buff *skb) 83 + { 84 + return ++NAPI_GRO_CB(skb)->recursion_counter == GRO_RECURSION_LIMIT; 85 + } 86 + 87 + typedef struct sk_buff *(*gro_receive_t)(struct list_head *, struct sk_buff *); 88 + static inline struct sk_buff *call_gro_receive(gro_receive_t cb, 89 + struct list_head *head, 90 + struct sk_buff *skb) 91 + { 92 + if (unlikely(gro_recursion_inc_test(skb))) { 93 + NAPI_GRO_CB(skb)->flush |= 1; 94 + return NULL; 95 + } 96 + 97 + return cb(head, skb); 98 + } 99 + 100 + typedef struct sk_buff *(*gro_receive_sk_t)(struct sock *, struct list_head *, 101 + struct sk_buff *); 102 + static inline struct sk_buff *call_gro_receive_sk(gro_receive_sk_t cb, 103 + struct sock *sk, 104 + struct list_head *head, 105 + struct sk_buff *skb) 106 + { 107 + if (unlikely(gro_recursion_inc_test(skb))) { 108 + NAPI_GRO_CB(skb)->flush |= 1; 109 + return NULL; 110 + } 111 + 112 + return cb(sk, head, skb); 113 + } 114 + 115 + static inline unsigned int skb_gro_offset(const struct sk_buff *skb) 116 + { 117 + return NAPI_GRO_CB(skb)->data_offset; 118 + } 119 + 120 + static inline unsigned int skb_gro_len(const struct sk_buff *skb) 121 + { 122 + return skb->len - NAPI_GRO_CB(skb)->data_offset; 123 + } 124 + 125 + static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len) 126 + { 127 + NAPI_GRO_CB(skb)->data_offset += len; 128 + } 129 + 130 + static inline void *skb_gro_header_fast(struct sk_buff *skb, 131 + unsigned int offset) 132 + { 133 + return NAPI_GRO_CB(skb)->frag0 + offset; 134 + } 135 + 136 + static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen) 137 + { 138 + return NAPI_GRO_CB(skb)->frag0_len < hlen; 139 + } 140 + 141 + static inline void skb_gro_frag0_invalidate(struct sk_buff *skb) 142 + { 143 + NAPI_GRO_CB(skb)->frag0 = NULL; 144 + NAPI_GRO_CB(skb)->frag0_len = 0; 145 + } 146 + 147 + static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen, 148 + unsigned int offset) 149 + { 150 + if (!pskb_may_pull(skb, hlen)) 151 + return NULL; 152 + 153 + skb_gro_frag0_invalidate(skb); 154 + return skb->data + offset; 155 + } 156 + 157 + static inline void *skb_gro_network_header(struct sk_buff *skb) 158 + { 159 + return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) + 160 + skb_network_offset(skb); 161 + } 162 + 163 + static inline __wsum inet_gro_compute_pseudo(struct sk_buff *skb, int proto) 164 + { 165 + const struct iphdr *iph = skb_gro_network_header(skb); 166 + 167 + return csum_tcpudp_nofold(iph->saddr, iph->daddr, 168 + skb_gro_len(skb), proto, 0); 169 + } 170 + 171 + static inline void skb_gro_postpull_rcsum(struct sk_buff *skb, 172 + const void *start, unsigned int len) 173 + { 174 + if (NAPI_GRO_CB(skb)->csum_valid) 175 + NAPI_GRO_CB(skb)->csum = csum_sub(NAPI_GRO_CB(skb)->csum, 176 + csum_partial(start, len, 0)); 177 + } 178 + 179 + /* GRO checksum functions. These are logical equivalents of the normal 180 + * checksum functions (in skbuff.h) except that they operate on the GRO 181 + * offsets and fields in sk_buff. 182 + */ 183 + 184 + __sum16 __skb_gro_checksum_complete(struct sk_buff *skb); 185 + 186 + static inline bool skb_at_gro_remcsum_start(struct sk_buff *skb) 187 + { 188 + return (NAPI_GRO_CB(skb)->gro_remcsum_start == skb_gro_offset(skb)); 189 + } 190 + 191 + static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb, 192 + bool zero_okay, 193 + __sum16 check) 194 + { 195 + return ((skb->ip_summed != CHECKSUM_PARTIAL || 196 + skb_checksum_start_offset(skb) < 197 + skb_gro_offset(skb)) && 198 + !skb_at_gro_remcsum_start(skb) && 199 + NAPI_GRO_CB(skb)->csum_cnt == 0 && 200 + (!zero_okay || check)); 201 + } 202 + 203 + static inline __sum16 __skb_gro_checksum_validate_complete(struct sk_buff *skb, 204 + __wsum psum) 205 + { 206 + if (NAPI_GRO_CB(skb)->csum_valid && 207 + !csum_fold(csum_add(psum, NAPI_GRO_CB(skb)->csum))) 208 + return 0; 209 + 210 + NAPI_GRO_CB(skb)->csum = psum; 211 + 212 + return __skb_gro_checksum_complete(skb); 213 + } 214 + 215 + static inline void skb_gro_incr_csum_unnecessary(struct sk_buff *skb) 216 + { 217 + if (NAPI_GRO_CB(skb)->csum_cnt > 0) { 218 + /* Consume a checksum from CHECKSUM_UNNECESSARY */ 219 + NAPI_GRO_CB(skb)->csum_cnt--; 220 + } else { 221 + /* Update skb for CHECKSUM_UNNECESSARY and csum_level when we 222 + * verified a new top level checksum or an encapsulated one 223 + * during GRO. This saves work if we fallback to normal path. 224 + */ 225 + __skb_incr_checksum_unnecessary(skb); 226 + } 227 + } 228 + 229 + #define __skb_gro_checksum_validate(skb, proto, zero_okay, check, \ 230 + compute_pseudo) \ 231 + ({ \ 232 + __sum16 __ret = 0; \ 233 + if (__skb_gro_checksum_validate_needed(skb, zero_okay, check)) \ 234 + __ret = __skb_gro_checksum_validate_complete(skb, \ 235 + compute_pseudo(skb, proto)); \ 236 + if (!__ret) \ 237 + skb_gro_incr_csum_unnecessary(skb); \ 238 + __ret; \ 239 + }) 240 + 241 + #define skb_gro_checksum_validate(skb, proto, compute_pseudo) \ 242 + __skb_gro_checksum_validate(skb, proto, false, 0, compute_pseudo) 243 + 244 + #define skb_gro_checksum_validate_zero_check(skb, proto, check, \ 245 + compute_pseudo) \ 246 + __skb_gro_checksum_validate(skb, proto, true, check, compute_pseudo) 247 + 248 + #define skb_gro_checksum_simple_validate(skb) \ 249 + __skb_gro_checksum_validate(skb, 0, false, 0, null_compute_pseudo) 250 + 251 + static inline bool __skb_gro_checksum_convert_check(struct sk_buff *skb) 252 + { 253 + return (NAPI_GRO_CB(skb)->csum_cnt == 0 && 254 + !NAPI_GRO_CB(skb)->csum_valid); 255 + } 256 + 257 + static inline void __skb_gro_checksum_convert(struct sk_buff *skb, 258 + __wsum pseudo) 259 + { 260 + NAPI_GRO_CB(skb)->csum = ~pseudo; 261 + NAPI_GRO_CB(skb)->csum_valid = 1; 262 + } 263 + 264 + #define skb_gro_checksum_try_convert(skb, proto, compute_pseudo) \ 265 + do { \ 266 + if (__skb_gro_checksum_convert_check(skb)) \ 267 + __skb_gro_checksum_convert(skb, \ 268 + compute_pseudo(skb, proto)); \ 269 + } while (0) 270 + 271 + struct gro_remcsum { 272 + int offset; 273 + __wsum delta; 274 + }; 275 + 276 + static inline void skb_gro_remcsum_init(struct gro_remcsum *grc) 277 + { 278 + grc->offset = 0; 279 + grc->delta = 0; 280 + } 281 + 282 + static inline void *skb_gro_remcsum_process(struct sk_buff *skb, void *ptr, 283 + unsigned int off, size_t hdrlen, 284 + int start, int offset, 285 + struct gro_remcsum *grc, 286 + bool nopartial) 287 + { 288 + __wsum delta; 289 + size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start); 290 + 291 + BUG_ON(!NAPI_GRO_CB(skb)->csum_valid); 292 + 293 + if (!nopartial) { 294 + NAPI_GRO_CB(skb)->gro_remcsum_start = off + hdrlen + start; 295 + return ptr; 296 + } 297 + 298 + ptr = skb_gro_header_fast(skb, off); 299 + if (skb_gro_header_hard(skb, off + plen)) { 300 + ptr = skb_gro_header_slow(skb, off + plen, off); 301 + if (!ptr) 302 + return NULL; 303 + } 304 + 305 + delta = remcsum_adjust(ptr + hdrlen, NAPI_GRO_CB(skb)->csum, 306 + start, offset); 307 + 308 + /* Adjust skb->csum since we changed the packet */ 309 + NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta); 310 + 311 + grc->offset = off + hdrlen + offset; 312 + grc->delta = delta; 313 + 314 + return ptr; 315 + } 316 + 317 + static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb, 318 + struct gro_remcsum *grc) 319 + { 320 + void *ptr; 321 + size_t plen = grc->offset + sizeof(u16); 322 + 323 + if (!grc->delta) 324 + return; 325 + 326 + ptr = skb_gro_header_fast(skb, grc->offset); 327 + if (skb_gro_header_hard(skb, grc->offset + sizeof(u16))) { 328 + ptr = skb_gro_header_slow(skb, plen, grc->offset); 329 + if (!ptr) 330 + return; 331 + } 332 + 333 + remcsum_unadjust((__sum16 *)ptr, grc->delta); 334 + } 335 + 336 + #ifdef CONFIG_XFRM_OFFLOAD 337 + static inline void skb_gro_flush_final(struct sk_buff *skb, struct sk_buff *pp, int flush) 338 + { 339 + if (PTR_ERR(pp) != -EINPROGRESS) 340 + NAPI_GRO_CB(skb)->flush |= flush; 341 + } 342 + static inline void skb_gro_flush_final_remcsum(struct sk_buff *skb, 343 + struct sk_buff *pp, 344 + int flush, 345 + struct gro_remcsum *grc) 346 + { 347 + if (PTR_ERR(pp) != -EINPROGRESS) { 348 + NAPI_GRO_CB(skb)->flush |= flush; 349 + skb_gro_remcsum_cleanup(skb, grc); 350 + skb->remcsum_offload = 0; 351 + } 352 + } 353 + #else 354 + static inline void skb_gro_flush_final(struct sk_buff *skb, struct sk_buff *pp, int flush) 355 + { 356 + NAPI_GRO_CB(skb)->flush |= flush; 357 + } 358 + static inline void skb_gro_flush_final_remcsum(struct sk_buff *skb, 359 + struct sk_buff *pp, 360 + int flush, 361 + struct gro_remcsum *grc) 362 + { 363 + NAPI_GRO_CB(skb)->flush |= flush; 364 + skb_gro_remcsum_cleanup(skb, grc); 365 + skb->remcsum_offload = 0; 366 + } 367 + #endif 10 368 11 369 INDIRECT_CALLABLE_DECLARE(struct sk_buff *ipv6_gro_receive(struct list_head *, 12 370 struct sk_buff *)); ··· 373 15 struct sk_buff *)); 374 16 INDIRECT_CALLABLE_DECLARE(int inet_gro_complete(struct sk_buff *, int)); 375 17 18 + INDIRECT_CALLABLE_DECLARE(struct sk_buff *udp4_gro_receive(struct list_head *, 19 + struct sk_buff *)); 20 + INDIRECT_CALLABLE_DECLARE(int udp4_gro_complete(struct sk_buff *, int)); 21 + 22 + INDIRECT_CALLABLE_DECLARE(struct sk_buff *udp6_gro_receive(struct list_head *, 23 + struct sk_buff *)); 24 + INDIRECT_CALLABLE_DECLARE(int udp6_gro_complete(struct sk_buff *, int)); 25 + 376 26 #define indirect_call_gro_receive_inet(cb, f2, f1, head, skb) \ 377 27 ({ \ 378 28 unlikely(gro_recursion_inc_test(skb)) ? \ 379 29 NAPI_GRO_CB(skb)->flush |= 1, NULL : \ 380 30 INDIRECT_CALL_INET(cb, f2, f1, head, skb); \ 381 31 }) 32 + 33 + struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb, 34 + struct udphdr *uh, struct sock *sk); 35 + int udp_gro_complete(struct sk_buff *skb, int nhoff, udp_lookup_t lookup); 36 + 37 + static inline struct udphdr *udp_gro_udphdr(struct sk_buff *skb) 38 + { 39 + struct udphdr *uh; 40 + unsigned int hlen, off; 41 + 42 + off = skb_gro_offset(skb); 43 + hlen = off + sizeof(*uh); 44 + uh = skb_gro_header_fast(skb, off); 45 + if (skb_gro_header_hard(skb, hlen)) 46 + uh = skb_gro_header_slow(skb, hlen, off); 47 + 48 + return uh; 49 + } 50 + 51 + static inline __wsum ip6_gro_compute_pseudo(struct sk_buff *skb, int proto) 52 + { 53 + const struct ipv6hdr *iph = skb_gro_network_header(skb); 54 + 55 + return ~csum_unfold(csum_ipv6_magic(&iph->saddr, &iph->daddr, 56 + skb_gro_len(skb), proto, 0)); 57 + } 58 + 59 + int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb); 60 + 61 + /* Pass the currently batched GRO_NORMAL SKBs up to the stack. */ 62 + static inline void gro_normal_list(struct napi_struct *napi) 63 + { 64 + if (!napi->rx_count) 65 + return; 66 + netif_receive_skb_list_internal(&napi->rx_list); 67 + INIT_LIST_HEAD(&napi->rx_list); 68 + napi->rx_count = 0; 69 + } 70 + 71 + /* Queue one GRO_NORMAL SKB up for list processing. If batch size exceeded, 72 + * pass the whole batch up to the stack. 73 + */ 74 + static inline void gro_normal_one(struct napi_struct *napi, struct sk_buff *skb, int segs) 75 + { 76 + list_add_tail(&skb->list, &napi->rx_list); 77 + napi->rx_count += segs; 78 + if (napi->rx_count >= gro_normal_batch) 79 + gro_normal_list(napi); 80 + } 81 + 382 82 383 83 #endif /* _NET_IPV6_GRO_H */
-8
include/net/ip.h
··· 568 568 flow->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; 569 569 } 570 570 571 - static inline __wsum inet_gro_compute_pseudo(struct sk_buff *skb, int proto) 572 - { 573 - const struct iphdr *iph = skb_gro_network_header(skb); 574 - 575 - return csum_tcpudp_nofold(iph->saddr, iph->daddr, 576 - skb_gro_len(skb), proto, 0); 577 - } 578 - 579 571 /* 580 572 * Map a multicast IP onto multicast MAC for type ethernet. 581 573 */
-8
include/net/ip6_checksum.h
··· 43 43 skb->len, proto, 0)); 44 44 } 45 45 46 - static inline __wsum ip6_gro_compute_pseudo(struct sk_buff *skb, int proto) 47 - { 48 - const struct ipv6hdr *iph = skb_gro_network_header(skb); 49 - 50 - return ~csum_unfold(csum_ipv6_magic(&iph->saddr, &iph->daddr, 51 - skb_gro_len(skb), proto, 0)); 52 - } 53 - 54 46 static __inline__ __sum16 tcp_v6_check(int len, 55 47 const struct in6_addr *saddr, 56 48 const struct in6_addr *daddr,
-24
include/net/udp.h
··· 167 167 typedef struct sock *(*udp_lookup_t)(const struct sk_buff *skb, __be16 sport, 168 168 __be16 dport); 169 169 170 - INDIRECT_CALLABLE_DECLARE(struct sk_buff *udp4_gro_receive(struct list_head *, 171 - struct sk_buff *)); 172 - INDIRECT_CALLABLE_DECLARE(int udp4_gro_complete(struct sk_buff *, int)); 173 - INDIRECT_CALLABLE_DECLARE(struct sk_buff *udp6_gro_receive(struct list_head *, 174 - struct sk_buff *)); 175 - INDIRECT_CALLABLE_DECLARE(int udp6_gro_complete(struct sk_buff *, int)); 176 170 INDIRECT_CALLABLE_DECLARE(void udp_v6_early_demux(struct sk_buff *)); 177 171 INDIRECT_CALLABLE_DECLARE(int udpv6_rcv(struct sk_buff *)); 178 172 179 - struct sk_buff *udp_gro_receive(struct list_head *head, struct sk_buff *skb, 180 - struct udphdr *uh, struct sock *sk); 181 - int udp_gro_complete(struct sk_buff *skb, int nhoff, udp_lookup_t lookup); 182 - 183 173 struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, 184 174 netdev_features_t features, bool is_ipv6); 185 - 186 - static inline struct udphdr *udp_gro_udphdr(struct sk_buff *skb) 187 - { 188 - struct udphdr *uh; 189 - unsigned int hlen, off; 190 - 191 - off = skb_gro_offset(skb); 192 - hlen = off + sizeof(*uh); 193 - uh = skb_gro_header_fast(skb, off); 194 - if (skb_gro_header_hard(skb, hlen)) 195 - uh = skb_gro_header_slow(skb, hlen, off); 196 - 197 - return uh; 198 - } 199 175 200 176 /* hash routines shared between UDPv4/6 and UDP-Litev4/6 */ 201 177 static inline int udp_lib_hash(struct sock *sk)
+1 -1
net/core/Makefile
··· 11 11 obj-y += dev.o dev_addr_lists.o dst.o netevent.o \ 12 12 neighbour.o rtnetlink.o utils.o link_watch.o filter.o \ 13 13 sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \ 14 - fib_notifier.o xdp.o flow_offload.o 14 + fib_notifier.o xdp.o flow_offload.o gro.o 15 15 16 16 obj-y += net-sysfs.o 17 17 obj-$(CONFIG_PAGE_POOL) += page_pool.o
+1 -667
net/core/dev.c
··· 153 153 154 154 #include "net-sysfs.h" 155 155 156 - #define MAX_GRO_SKBS 8 157 - 158 - /* This should be increased if a protocol with a bigger head is added. */ 159 - #define GRO_MAX_HEAD (MAX_HEADER + 128) 160 156 161 157 static DEFINE_SPINLOCK(ptype_lock); 162 - static DEFINE_SPINLOCK(offload_lock); 163 158 struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; 164 159 struct list_head ptype_all __read_mostly; /* Taps */ 165 - static struct list_head offload_base __read_mostly; 166 160 167 161 static int netif_rx_internal(struct sk_buff *skb); 168 162 static int call_netdevice_notifiers_info(unsigned long val, ··· 597 603 } 598 604 EXPORT_SYMBOL(dev_remove_pack); 599 605 600 - 601 - /** 602 - * dev_add_offload - register offload handlers 603 - * @po: protocol offload declaration 604 - * 605 - * Add protocol offload handlers to the networking stack. The passed 606 - * &proto_offload is linked into kernel lists and may not be freed until 607 - * it has been removed from the kernel lists. 608 - * 609 - * This call does not sleep therefore it can not 610 - * guarantee all CPU's that are in middle of receiving packets 611 - * will see the new offload handlers (until the next received packet). 612 - */ 613 - void dev_add_offload(struct packet_offload *po) 614 - { 615 - struct packet_offload *elem; 616 - 617 - spin_lock(&offload_lock); 618 - list_for_each_entry(elem, &offload_base, list) { 619 - if (po->priority < elem->priority) 620 - break; 621 - } 622 - list_add_rcu(&po->list, elem->list.prev); 623 - spin_unlock(&offload_lock); 624 - } 625 - EXPORT_SYMBOL(dev_add_offload); 626 - 627 - /** 628 - * __dev_remove_offload - remove offload handler 629 - * @po: packet offload declaration 630 - * 631 - * Remove a protocol offload handler that was previously added to the 632 - * kernel offload handlers by dev_add_offload(). The passed &offload_type 633 - * is removed from the kernel lists and can be freed or reused once this 634 - * function returns. 635 - * 636 - * The packet type might still be in use by receivers 637 - * and must not be freed until after all the CPU's have gone 638 - * through a quiescent state. 639 - */ 640 - static void __dev_remove_offload(struct packet_offload *po) 641 - { 642 - struct list_head *head = &offload_base; 643 - struct packet_offload *po1; 644 - 645 - spin_lock(&offload_lock); 646 - 647 - list_for_each_entry(po1, head, list) { 648 - if (po == po1) { 649 - list_del_rcu(&po->list); 650 - goto out; 651 - } 652 - } 653 - 654 - pr_warn("dev_remove_offload: %p not found\n", po); 655 - out: 656 - spin_unlock(&offload_lock); 657 - } 658 - 659 - /** 660 - * dev_remove_offload - remove packet offload handler 661 - * @po: packet offload declaration 662 - * 663 - * Remove a packet offload handler that was previously added to the kernel 664 - * offload handlers by dev_add_offload(). The passed &offload_type is 665 - * removed from the kernel lists and can be freed or reused once this 666 - * function returns. 667 - * 668 - * This call sleeps to guarantee that no CPU is looking at the packet 669 - * type after return. 670 - */ 671 - void dev_remove_offload(struct packet_offload *po) 672 - { 673 - __dev_remove_offload(po); 674 - 675 - synchronize_net(); 676 - } 677 - EXPORT_SYMBOL(dev_remove_offload); 678 606 679 607 /******************************************************************************* 680 608 * ··· 3231 3315 return __vlan_get_protocol(skb, type, depth); 3232 3316 } 3233 3317 3234 - /** 3235 - * skb_mac_gso_segment - mac layer segmentation handler. 3236 - * @skb: buffer to segment 3237 - * @features: features for the output path (see dev->features) 3238 - */ 3239 - struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb, 3240 - netdev_features_t features) 3241 - { 3242 - struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT); 3243 - struct packet_offload *ptype; 3244 - int vlan_depth = skb->mac_len; 3245 - __be16 type = skb_network_protocol(skb, &vlan_depth); 3246 - 3247 - if (unlikely(!type)) 3248 - return ERR_PTR(-EINVAL); 3249 - 3250 - __skb_pull(skb, vlan_depth); 3251 - 3252 - rcu_read_lock(); 3253 - list_for_each_entry_rcu(ptype, &offload_base, list) { 3254 - if (ptype->type == type && ptype->callbacks.gso_segment) { 3255 - segs = ptype->callbacks.gso_segment(skb, features); 3256 - break; 3257 - } 3258 - } 3259 - rcu_read_unlock(); 3260 - 3261 - __skb_push(skb, skb->data - skb_mac_header(skb)); 3262 - 3263 - return segs; 3264 - } 3265 - EXPORT_SYMBOL(skb_mac_gso_segment); 3266 - 3267 - 3268 3318 /* openvswitch calls this on rx path, so we need a different check. 3269 3319 */ 3270 3320 static inline bool skb_needs_check(struct sk_buff *skb, bool tx_path) ··· 4202 4320 int dev_weight_tx_bias __read_mostly = 1; /* bias for output_queue quota */ 4203 4321 int dev_rx_weight __read_mostly = 64; 4204 4322 int dev_tx_weight __read_mostly = 64; 4205 - /* Maximum number of GRO_NORMAL skbs to batch up for list-RX */ 4206 - int gro_normal_batch __read_mostly = 8; 4207 4323 4208 4324 /* Called with irq disabled */ 4209 4325 static inline void ____napi_schedule(struct softnet_data *sd, ··· 5544 5664 return ret; 5545 5665 } 5546 5666 5547 - static void netif_receive_skb_list_internal(struct list_head *head) 5667 + void netif_receive_skb_list_internal(struct list_head *head) 5548 5668 { 5549 5669 struct sk_buff *skb, *next; 5550 5670 struct list_head sublist; ··· 5721 5841 5722 5842 cpus_read_unlock(); 5723 5843 } 5724 - 5725 - /* Pass the currently batched GRO_NORMAL SKBs up to the stack. */ 5726 - static void gro_normal_list(struct napi_struct *napi) 5727 - { 5728 - if (!napi->rx_count) 5729 - return; 5730 - netif_receive_skb_list_internal(&napi->rx_list); 5731 - INIT_LIST_HEAD(&napi->rx_list); 5732 - napi->rx_count = 0; 5733 - } 5734 - 5735 - /* Queue one GRO_NORMAL SKB up for list processing. If batch size exceeded, 5736 - * pass the whole batch up to the stack. 5737 - */ 5738 - static void gro_normal_one(struct napi_struct *napi, struct sk_buff *skb, int segs) 5739 - { 5740 - list_add_tail(&skb->list, &napi->rx_list); 5741 - napi->rx_count += segs; 5742 - if (napi->rx_count >= gro_normal_batch) 5743 - gro_normal_list(napi); 5744 - } 5745 - 5746 - static void napi_gro_complete(struct napi_struct *napi, struct sk_buff *skb) 5747 - { 5748 - struct packet_offload *ptype; 5749 - __be16 type = skb->protocol; 5750 - struct list_head *head = &offload_base; 5751 - int err = -ENOENT; 5752 - 5753 - BUILD_BUG_ON(sizeof(struct napi_gro_cb) > sizeof(skb->cb)); 5754 - 5755 - if (NAPI_GRO_CB(skb)->count == 1) { 5756 - skb_shinfo(skb)->gso_size = 0; 5757 - goto out; 5758 - } 5759 - 5760 - rcu_read_lock(); 5761 - list_for_each_entry_rcu(ptype, head, list) { 5762 - if (ptype->type != type || !ptype->callbacks.gro_complete) 5763 - continue; 5764 - 5765 - err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete, 5766 - ipv6_gro_complete, inet_gro_complete, 5767 - skb, 0); 5768 - break; 5769 - } 5770 - rcu_read_unlock(); 5771 - 5772 - if (err) { 5773 - WARN_ON(&ptype->list == head); 5774 - kfree_skb(skb); 5775 - return; 5776 - } 5777 - 5778 - out: 5779 - gro_normal_one(napi, skb, NAPI_GRO_CB(skb)->count); 5780 - } 5781 - 5782 - static void __napi_gro_flush_chain(struct napi_struct *napi, u32 index, 5783 - bool flush_old) 5784 - { 5785 - struct list_head *head = &napi->gro_hash[index].list; 5786 - struct sk_buff *skb, *p; 5787 - 5788 - list_for_each_entry_safe_reverse(skb, p, head, list) { 5789 - if (flush_old && NAPI_GRO_CB(skb)->age == jiffies) 5790 - return; 5791 - skb_list_del_init(skb); 5792 - napi_gro_complete(napi, skb); 5793 - napi->gro_hash[index].count--; 5794 - } 5795 - 5796 - if (!napi->gro_hash[index].count) 5797 - __clear_bit(index, &napi->gro_bitmask); 5798 - } 5799 - 5800 - /* napi->gro_hash[].list contains packets ordered by age. 5801 - * youngest packets at the head of it. 5802 - * Complete skbs in reverse order to reduce latencies. 5803 - */ 5804 - void napi_gro_flush(struct napi_struct *napi, bool flush_old) 5805 - { 5806 - unsigned long bitmask = napi->gro_bitmask; 5807 - unsigned int i, base = ~0U; 5808 - 5809 - while ((i = ffs(bitmask)) != 0) { 5810 - bitmask >>= i; 5811 - base += i; 5812 - __napi_gro_flush_chain(napi, base, flush_old); 5813 - } 5814 - } 5815 - EXPORT_SYMBOL(napi_gro_flush); 5816 - 5817 - static void gro_list_prepare(const struct list_head *head, 5818 - const struct sk_buff *skb) 5819 - { 5820 - unsigned int maclen = skb->dev->hard_header_len; 5821 - u32 hash = skb_get_hash_raw(skb); 5822 - struct sk_buff *p; 5823 - 5824 - list_for_each_entry(p, head, list) { 5825 - unsigned long diffs; 5826 - 5827 - NAPI_GRO_CB(p)->flush = 0; 5828 - 5829 - if (hash != skb_get_hash_raw(p)) { 5830 - NAPI_GRO_CB(p)->same_flow = 0; 5831 - continue; 5832 - } 5833 - 5834 - diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev; 5835 - diffs |= skb_vlan_tag_present(p) ^ skb_vlan_tag_present(skb); 5836 - if (skb_vlan_tag_present(p)) 5837 - diffs |= skb_vlan_tag_get(p) ^ skb_vlan_tag_get(skb); 5838 - diffs |= skb_metadata_differs(p, skb); 5839 - if (maclen == ETH_HLEN) 5840 - diffs |= compare_ether_header(skb_mac_header(p), 5841 - skb_mac_header(skb)); 5842 - else if (!diffs) 5843 - diffs = memcmp(skb_mac_header(p), 5844 - skb_mac_header(skb), 5845 - maclen); 5846 - 5847 - /* in most common scenarions 'slow_gro' is 0 5848 - * otherwise we are already on some slower paths 5849 - * either skip all the infrequent tests altogether or 5850 - * avoid trying too hard to skip each of them individually 5851 - */ 5852 - if (!diffs && unlikely(skb->slow_gro | p->slow_gro)) { 5853 - #if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT) 5854 - struct tc_skb_ext *skb_ext; 5855 - struct tc_skb_ext *p_ext; 5856 - #endif 5857 - 5858 - diffs |= p->sk != skb->sk; 5859 - diffs |= skb_metadata_dst_cmp(p, skb); 5860 - diffs |= skb_get_nfct(p) ^ skb_get_nfct(skb); 5861 - 5862 - #if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT) 5863 - skb_ext = skb_ext_find(skb, TC_SKB_EXT); 5864 - p_ext = skb_ext_find(p, TC_SKB_EXT); 5865 - 5866 - diffs |= (!!p_ext) ^ (!!skb_ext); 5867 - if (!diffs && unlikely(skb_ext)) 5868 - diffs |= p_ext->chain ^ skb_ext->chain; 5869 - #endif 5870 - } 5871 - 5872 - NAPI_GRO_CB(p)->same_flow = !diffs; 5873 - } 5874 - } 5875 - 5876 - static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff) 5877 - { 5878 - const struct skb_shared_info *pinfo = skb_shinfo(skb); 5879 - const skb_frag_t *frag0 = &pinfo->frags[0]; 5880 - 5881 - NAPI_GRO_CB(skb)->data_offset = 0; 5882 - NAPI_GRO_CB(skb)->frag0 = NULL; 5883 - NAPI_GRO_CB(skb)->frag0_len = 0; 5884 - 5885 - if (!skb_headlen(skb) && pinfo->nr_frags && 5886 - !PageHighMem(skb_frag_page(frag0)) && 5887 - (!NET_IP_ALIGN || !((skb_frag_off(frag0) + nhoff) & 3))) { 5888 - NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0); 5889 - NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int, 5890 - skb_frag_size(frag0), 5891 - skb->end - skb->tail); 5892 - } 5893 - } 5894 - 5895 - static void gro_pull_from_frag0(struct sk_buff *skb, int grow) 5896 - { 5897 - struct skb_shared_info *pinfo = skb_shinfo(skb); 5898 - 5899 - BUG_ON(skb->end - skb->tail < grow); 5900 - 5901 - memcpy(skb_tail_pointer(skb), NAPI_GRO_CB(skb)->frag0, grow); 5902 - 5903 - skb->data_len -= grow; 5904 - skb->tail += grow; 5905 - 5906 - skb_frag_off_add(&pinfo->frags[0], grow); 5907 - skb_frag_size_sub(&pinfo->frags[0], grow); 5908 - 5909 - if (unlikely(!skb_frag_size(&pinfo->frags[0]))) { 5910 - skb_frag_unref(skb, 0); 5911 - memmove(pinfo->frags, pinfo->frags + 1, 5912 - --pinfo->nr_frags * sizeof(pinfo->frags[0])); 5913 - } 5914 - } 5915 - 5916 - static void gro_flush_oldest(struct napi_struct *napi, struct list_head *head) 5917 - { 5918 - struct sk_buff *oldest; 5919 - 5920 - oldest = list_last_entry(head, struct sk_buff, list); 5921 - 5922 - /* We are called with head length >= MAX_GRO_SKBS, so this is 5923 - * impossible. 5924 - */ 5925 - if (WARN_ON_ONCE(!oldest)) 5926 - return; 5927 - 5928 - /* Do not adjust napi->gro_hash[].count, caller is adding a new 5929 - * SKB to the chain. 5930 - */ 5931 - skb_list_del_init(oldest); 5932 - napi_gro_complete(napi, oldest); 5933 - } 5934 - 5935 - static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 5936 - { 5937 - u32 bucket = skb_get_hash_raw(skb) & (GRO_HASH_BUCKETS - 1); 5938 - struct gro_list *gro_list = &napi->gro_hash[bucket]; 5939 - struct list_head *head = &offload_base; 5940 - struct packet_offload *ptype; 5941 - __be16 type = skb->protocol; 5942 - struct sk_buff *pp = NULL; 5943 - enum gro_result ret; 5944 - int same_flow; 5945 - int grow; 5946 - 5947 - if (netif_elide_gro(skb->dev)) 5948 - goto normal; 5949 - 5950 - gro_list_prepare(&gro_list->list, skb); 5951 - 5952 - rcu_read_lock(); 5953 - list_for_each_entry_rcu(ptype, head, list) { 5954 - if (ptype->type != type || !ptype->callbacks.gro_receive) 5955 - continue; 5956 - 5957 - skb_set_network_header(skb, skb_gro_offset(skb)); 5958 - skb_reset_mac_len(skb); 5959 - NAPI_GRO_CB(skb)->same_flow = 0; 5960 - NAPI_GRO_CB(skb)->flush = skb_is_gso(skb) || skb_has_frag_list(skb); 5961 - NAPI_GRO_CB(skb)->free = 0; 5962 - NAPI_GRO_CB(skb)->encap_mark = 0; 5963 - NAPI_GRO_CB(skb)->recursion_counter = 0; 5964 - NAPI_GRO_CB(skb)->is_fou = 0; 5965 - NAPI_GRO_CB(skb)->is_atomic = 1; 5966 - NAPI_GRO_CB(skb)->gro_remcsum_start = 0; 5967 - 5968 - /* Setup for GRO checksum validation */ 5969 - switch (skb->ip_summed) { 5970 - case CHECKSUM_COMPLETE: 5971 - NAPI_GRO_CB(skb)->csum = skb->csum; 5972 - NAPI_GRO_CB(skb)->csum_valid = 1; 5973 - NAPI_GRO_CB(skb)->csum_cnt = 0; 5974 - break; 5975 - case CHECKSUM_UNNECESSARY: 5976 - NAPI_GRO_CB(skb)->csum_cnt = skb->csum_level + 1; 5977 - NAPI_GRO_CB(skb)->csum_valid = 0; 5978 - break; 5979 - default: 5980 - NAPI_GRO_CB(skb)->csum_cnt = 0; 5981 - NAPI_GRO_CB(skb)->csum_valid = 0; 5982 - } 5983 - 5984 - pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive, 5985 - ipv6_gro_receive, inet_gro_receive, 5986 - &gro_list->list, skb); 5987 - break; 5988 - } 5989 - rcu_read_unlock(); 5990 - 5991 - if (&ptype->list == head) 5992 - goto normal; 5993 - 5994 - if (PTR_ERR(pp) == -EINPROGRESS) { 5995 - ret = GRO_CONSUMED; 5996 - goto ok; 5997 - } 5998 - 5999 - same_flow = NAPI_GRO_CB(skb)->same_flow; 6000 - ret = NAPI_GRO_CB(skb)->free ? GRO_MERGED_FREE : GRO_MERGED; 6001 - 6002 - if (pp) { 6003 - skb_list_del_init(pp); 6004 - napi_gro_complete(napi, pp); 6005 - gro_list->count--; 6006 - } 6007 - 6008 - if (same_flow) 6009 - goto ok; 6010 - 6011 - if (NAPI_GRO_CB(skb)->flush) 6012 - goto normal; 6013 - 6014 - if (unlikely(gro_list->count >= MAX_GRO_SKBS)) 6015 - gro_flush_oldest(napi, &gro_list->list); 6016 - else 6017 - gro_list->count++; 6018 - 6019 - NAPI_GRO_CB(skb)->count = 1; 6020 - NAPI_GRO_CB(skb)->age = jiffies; 6021 - NAPI_GRO_CB(skb)->last = skb; 6022 - skb_shinfo(skb)->gso_size = skb_gro_len(skb); 6023 - list_add(&skb->list, &gro_list->list); 6024 - ret = GRO_HELD; 6025 - 6026 - pull: 6027 - grow = skb_gro_offset(skb) - skb_headlen(skb); 6028 - if (grow > 0) 6029 - gro_pull_from_frag0(skb, grow); 6030 - ok: 6031 - if (gro_list->count) { 6032 - if (!test_bit(bucket, &napi->gro_bitmask)) 6033 - __set_bit(bucket, &napi->gro_bitmask); 6034 - } else if (test_bit(bucket, &napi->gro_bitmask)) { 6035 - __clear_bit(bucket, &napi->gro_bitmask); 6036 - } 6037 - 6038 - return ret; 6039 - 6040 - normal: 6041 - ret = GRO_NORMAL; 6042 - goto pull; 6043 - } 6044 - 6045 - struct packet_offload *gro_find_receive_by_type(__be16 type) 6046 - { 6047 - struct list_head *offload_head = &offload_base; 6048 - struct packet_offload *ptype; 6049 - 6050 - list_for_each_entry_rcu(ptype, offload_head, list) { 6051 - if (ptype->type != type || !ptype->callbacks.gro_receive) 6052 - continue; 6053 - return ptype; 6054 - } 6055 - return NULL; 6056 - } 6057 - EXPORT_SYMBOL(gro_find_receive_by_type); 6058 - 6059 - struct packet_offload *gro_find_complete_by_type(__be16 type) 6060 - { 6061 - struct list_head *offload_head = &offload_base; 6062 - struct packet_offload *ptype; 6063 - 6064 - list_for_each_entry_rcu(ptype, offload_head, list) { 6065 - if (ptype->type != type || !ptype->callbacks.gro_complete) 6066 - continue; 6067 - return ptype; 6068 - } 6069 - return NULL; 6070 - } 6071 - EXPORT_SYMBOL(gro_find_complete_by_type); 6072 - 6073 - static gro_result_t napi_skb_finish(struct napi_struct *napi, 6074 - struct sk_buff *skb, 6075 - gro_result_t ret) 6076 - { 6077 - switch (ret) { 6078 - case GRO_NORMAL: 6079 - gro_normal_one(napi, skb, 1); 6080 - break; 6081 - 6082 - case GRO_MERGED_FREE: 6083 - if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) 6084 - napi_skb_free_stolen_head(skb); 6085 - else if (skb->fclone != SKB_FCLONE_UNAVAILABLE) 6086 - __kfree_skb(skb); 6087 - else 6088 - __kfree_skb_defer(skb); 6089 - break; 6090 - 6091 - case GRO_HELD: 6092 - case GRO_MERGED: 6093 - case GRO_CONSUMED: 6094 - break; 6095 - } 6096 - 6097 - return ret; 6098 - } 6099 - 6100 - gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 6101 - { 6102 - gro_result_t ret; 6103 - 6104 - skb_mark_napi_id(skb, napi); 6105 - trace_napi_gro_receive_entry(skb); 6106 - 6107 - skb_gro_reset_offset(skb, 0); 6108 - 6109 - ret = napi_skb_finish(napi, skb, dev_gro_receive(napi, skb)); 6110 - trace_napi_gro_receive_exit(ret); 6111 - 6112 - return ret; 6113 - } 6114 - EXPORT_SYMBOL(napi_gro_receive); 6115 - 6116 - static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb) 6117 - { 6118 - if (unlikely(skb->pfmemalloc)) { 6119 - consume_skb(skb); 6120 - return; 6121 - } 6122 - __skb_pull(skb, skb_headlen(skb)); 6123 - /* restore the reserve we had after netdev_alloc_skb_ip_align() */ 6124 - skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN - skb_headroom(skb)); 6125 - __vlan_hwaccel_clear_tag(skb); 6126 - skb->dev = napi->dev; 6127 - skb->skb_iif = 0; 6128 - 6129 - /* eth_type_trans() assumes pkt_type is PACKET_HOST */ 6130 - skb->pkt_type = PACKET_HOST; 6131 - 6132 - skb->encapsulation = 0; 6133 - skb_shinfo(skb)->gso_type = 0; 6134 - skb->truesize = SKB_TRUESIZE(skb_end_offset(skb)); 6135 - if (unlikely(skb->slow_gro)) { 6136 - skb_orphan(skb); 6137 - skb_ext_reset(skb); 6138 - nf_reset_ct(skb); 6139 - skb->slow_gro = 0; 6140 - } 6141 - 6142 - napi->skb = skb; 6143 - } 6144 - 6145 - struct sk_buff *napi_get_frags(struct napi_struct *napi) 6146 - { 6147 - struct sk_buff *skb = napi->skb; 6148 - 6149 - if (!skb) { 6150 - skb = napi_alloc_skb(napi, GRO_MAX_HEAD); 6151 - if (skb) { 6152 - napi->skb = skb; 6153 - skb_mark_napi_id(skb, napi); 6154 - } 6155 - } 6156 - return skb; 6157 - } 6158 - EXPORT_SYMBOL(napi_get_frags); 6159 - 6160 - static gro_result_t napi_frags_finish(struct napi_struct *napi, 6161 - struct sk_buff *skb, 6162 - gro_result_t ret) 6163 - { 6164 - switch (ret) { 6165 - case GRO_NORMAL: 6166 - case GRO_HELD: 6167 - __skb_push(skb, ETH_HLEN); 6168 - skb->protocol = eth_type_trans(skb, skb->dev); 6169 - if (ret == GRO_NORMAL) 6170 - gro_normal_one(napi, skb, 1); 6171 - break; 6172 - 6173 - case GRO_MERGED_FREE: 6174 - if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) 6175 - napi_skb_free_stolen_head(skb); 6176 - else 6177 - napi_reuse_skb(napi, skb); 6178 - break; 6179 - 6180 - case GRO_MERGED: 6181 - case GRO_CONSUMED: 6182 - break; 6183 - } 6184 - 6185 - return ret; 6186 - } 6187 - 6188 - /* Upper GRO stack assumes network header starts at gro_offset=0 6189 - * Drivers could call both napi_gro_frags() and napi_gro_receive() 6190 - * We copy ethernet header into skb->data to have a common layout. 6191 - */ 6192 - static struct sk_buff *napi_frags_skb(struct napi_struct *napi) 6193 - { 6194 - struct sk_buff *skb = napi->skb; 6195 - const struct ethhdr *eth; 6196 - unsigned int hlen = sizeof(*eth); 6197 - 6198 - napi->skb = NULL; 6199 - 6200 - skb_reset_mac_header(skb); 6201 - skb_gro_reset_offset(skb, hlen); 6202 - 6203 - if (unlikely(skb_gro_header_hard(skb, hlen))) { 6204 - eth = skb_gro_header_slow(skb, hlen, 0); 6205 - if (unlikely(!eth)) { 6206 - net_warn_ratelimited("%s: dropping impossible skb from %s\n", 6207 - __func__, napi->dev->name); 6208 - napi_reuse_skb(napi, skb); 6209 - return NULL; 6210 - } 6211 - } else { 6212 - eth = (const struct ethhdr *)skb->data; 6213 - gro_pull_from_frag0(skb, hlen); 6214 - NAPI_GRO_CB(skb)->frag0 += hlen; 6215 - NAPI_GRO_CB(skb)->frag0_len -= hlen; 6216 - } 6217 - __skb_pull(skb, hlen); 6218 - 6219 - /* 6220 - * This works because the only protocols we care about don't require 6221 - * special handling. 6222 - * We'll fix it up properly in napi_frags_finish() 6223 - */ 6224 - skb->protocol = eth->h_proto; 6225 - 6226 - return skb; 6227 - } 6228 - 6229 - gro_result_t napi_gro_frags(struct napi_struct *napi) 6230 - { 6231 - gro_result_t ret; 6232 - struct sk_buff *skb = napi_frags_skb(napi); 6233 - 6234 - trace_napi_gro_frags_entry(skb); 6235 - 6236 - ret = napi_frags_finish(napi, skb, dev_gro_receive(napi, skb)); 6237 - trace_napi_gro_frags_exit(ret); 6238 - 6239 - return ret; 6240 - } 6241 - EXPORT_SYMBOL(napi_gro_frags); 6242 - 6243 - /* Compute the checksum from gro_offset and return the folded value 6244 - * after adding in any pseudo checksum. 6245 - */ 6246 - __sum16 __skb_gro_checksum_complete(struct sk_buff *skb) 6247 - { 6248 - __wsum wsum; 6249 - __sum16 sum; 6250 - 6251 - wsum = skb_checksum(skb, skb_gro_offset(skb), skb_gro_len(skb), 0); 6252 - 6253 - /* NAPI_GRO_CB(skb)->csum holds pseudo checksum */ 6254 - sum = csum_fold(csum_add(NAPI_GRO_CB(skb)->csum, wsum)); 6255 - /* See comments in __skb_checksum_complete(). */ 6256 - if (likely(!sum)) { 6257 - if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE) && 6258 - !skb->csum_complete_sw) 6259 - netdev_rx_csum_fault(skb->dev, skb); 6260 - } 6261 - 6262 - NAPI_GRO_CB(skb)->csum = wsum; 6263 - NAPI_GRO_CB(skb)->csum_valid = 1; 6264 - 6265 - return sum; 6266 - } 6267 - EXPORT_SYMBOL(__skb_gro_checksum_complete); 6268 5844 6269 5845 static void net_rps_send_ipi(struct softnet_data *remsd) 6270 5846 { ··· 10975 11639 INIT_LIST_HEAD(&ptype_all); 10976 11640 for (i = 0; i < PTYPE_HASH_SIZE; i++) 10977 11641 INIT_LIST_HEAD(&ptype_base[i]); 10978 - 10979 - INIT_LIST_HEAD(&offload_base); 10980 11642 10981 11643 if (register_pernet_subsys(&netdev_net_ops)) 10982 11644 goto out;
+766
net/core/gro.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + #include <net/gro.h> 3 + #include <net/dst_metadata.h> 4 + #include <net/busy_poll.h> 5 + #include <trace/events/net.h> 6 + 7 + #define MAX_GRO_SKBS 8 8 + 9 + /* This should be increased if a protocol with a bigger head is added. */ 10 + #define GRO_MAX_HEAD (MAX_HEADER + 128) 11 + 12 + static DEFINE_SPINLOCK(offload_lock); 13 + static struct list_head offload_base __read_mostly = LIST_HEAD_INIT(offload_base); 14 + /* Maximum number of GRO_NORMAL skbs to batch up for list-RX */ 15 + int gro_normal_batch __read_mostly = 8; 16 + 17 + /** 18 + * dev_add_offload - register offload handlers 19 + * @po: protocol offload declaration 20 + * 21 + * Add protocol offload handlers to the networking stack. The passed 22 + * &proto_offload is linked into kernel lists and may not be freed until 23 + * it has been removed from the kernel lists. 24 + * 25 + * This call does not sleep therefore it can not 26 + * guarantee all CPU's that are in middle of receiving packets 27 + * will see the new offload handlers (until the next received packet). 28 + */ 29 + void dev_add_offload(struct packet_offload *po) 30 + { 31 + struct packet_offload *elem; 32 + 33 + spin_lock(&offload_lock); 34 + list_for_each_entry(elem, &offload_base, list) { 35 + if (po->priority < elem->priority) 36 + break; 37 + } 38 + list_add_rcu(&po->list, elem->list.prev); 39 + spin_unlock(&offload_lock); 40 + } 41 + EXPORT_SYMBOL(dev_add_offload); 42 + 43 + /** 44 + * __dev_remove_offload - remove offload handler 45 + * @po: packet offload declaration 46 + * 47 + * Remove a protocol offload handler that was previously added to the 48 + * kernel offload handlers by dev_add_offload(). The passed &offload_type 49 + * is removed from the kernel lists and can be freed or reused once this 50 + * function returns. 51 + * 52 + * The packet type might still be in use by receivers 53 + * and must not be freed until after all the CPU's have gone 54 + * through a quiescent state. 55 + */ 56 + static void __dev_remove_offload(struct packet_offload *po) 57 + { 58 + struct list_head *head = &offload_base; 59 + struct packet_offload *po1; 60 + 61 + spin_lock(&offload_lock); 62 + 63 + list_for_each_entry(po1, head, list) { 64 + if (po == po1) { 65 + list_del_rcu(&po->list); 66 + goto out; 67 + } 68 + } 69 + 70 + pr_warn("dev_remove_offload: %p not found\n", po); 71 + out: 72 + spin_unlock(&offload_lock); 73 + } 74 + 75 + /** 76 + * dev_remove_offload - remove packet offload handler 77 + * @po: packet offload declaration 78 + * 79 + * Remove a packet offload handler that was previously added to the kernel 80 + * offload handlers by dev_add_offload(). The passed &offload_type is 81 + * removed from the kernel lists and can be freed or reused once this 82 + * function returns. 83 + * 84 + * This call sleeps to guarantee that no CPU is looking at the packet 85 + * type after return. 86 + */ 87 + void dev_remove_offload(struct packet_offload *po) 88 + { 89 + __dev_remove_offload(po); 90 + 91 + synchronize_net(); 92 + } 93 + EXPORT_SYMBOL(dev_remove_offload); 94 + 95 + /** 96 + * skb_mac_gso_segment - mac layer segmentation handler. 97 + * @skb: buffer to segment 98 + * @features: features for the output path (see dev->features) 99 + */ 100 + struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb, 101 + netdev_features_t features) 102 + { 103 + struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT); 104 + struct packet_offload *ptype; 105 + int vlan_depth = skb->mac_len; 106 + __be16 type = skb_network_protocol(skb, &vlan_depth); 107 + 108 + if (unlikely(!type)) 109 + return ERR_PTR(-EINVAL); 110 + 111 + __skb_pull(skb, vlan_depth); 112 + 113 + rcu_read_lock(); 114 + list_for_each_entry_rcu(ptype, &offload_base, list) { 115 + if (ptype->type == type && ptype->callbacks.gso_segment) { 116 + segs = ptype->callbacks.gso_segment(skb, features); 117 + break; 118 + } 119 + } 120 + rcu_read_unlock(); 121 + 122 + __skb_push(skb, skb->data - skb_mac_header(skb)); 123 + 124 + return segs; 125 + } 126 + EXPORT_SYMBOL(skb_mac_gso_segment); 127 + 128 + int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) 129 + { 130 + struct skb_shared_info *pinfo, *skbinfo = skb_shinfo(skb); 131 + unsigned int offset = skb_gro_offset(skb); 132 + unsigned int headlen = skb_headlen(skb); 133 + unsigned int len = skb_gro_len(skb); 134 + unsigned int delta_truesize; 135 + unsigned int new_truesize; 136 + struct sk_buff *lp; 137 + 138 + if (unlikely(p->len + len >= 65536 || NAPI_GRO_CB(skb)->flush)) 139 + return -E2BIG; 140 + 141 + lp = NAPI_GRO_CB(p)->last; 142 + pinfo = skb_shinfo(lp); 143 + 144 + if (headlen <= offset) { 145 + skb_frag_t *frag; 146 + skb_frag_t *frag2; 147 + int i = skbinfo->nr_frags; 148 + int nr_frags = pinfo->nr_frags + i; 149 + 150 + if (nr_frags > MAX_SKB_FRAGS) 151 + goto merge; 152 + 153 + offset -= headlen; 154 + pinfo->nr_frags = nr_frags; 155 + skbinfo->nr_frags = 0; 156 + 157 + frag = pinfo->frags + nr_frags; 158 + frag2 = skbinfo->frags + i; 159 + do { 160 + *--frag = *--frag2; 161 + } while (--i); 162 + 163 + skb_frag_off_add(frag, offset); 164 + skb_frag_size_sub(frag, offset); 165 + 166 + /* all fragments truesize : remove (head size + sk_buff) */ 167 + new_truesize = SKB_TRUESIZE(skb_end_offset(skb)); 168 + delta_truesize = skb->truesize - new_truesize; 169 + 170 + skb->truesize = new_truesize; 171 + skb->len -= skb->data_len; 172 + skb->data_len = 0; 173 + 174 + NAPI_GRO_CB(skb)->free = NAPI_GRO_FREE; 175 + goto done; 176 + } else if (skb->head_frag) { 177 + int nr_frags = pinfo->nr_frags; 178 + skb_frag_t *frag = pinfo->frags + nr_frags; 179 + struct page *page = virt_to_head_page(skb->head); 180 + unsigned int first_size = headlen - offset; 181 + unsigned int first_offset; 182 + 183 + if (nr_frags + 1 + skbinfo->nr_frags > MAX_SKB_FRAGS) 184 + goto merge; 185 + 186 + first_offset = skb->data - 187 + (unsigned char *)page_address(page) + 188 + offset; 189 + 190 + pinfo->nr_frags = nr_frags + 1 + skbinfo->nr_frags; 191 + 192 + __skb_frag_set_page(frag, page); 193 + skb_frag_off_set(frag, first_offset); 194 + skb_frag_size_set(frag, first_size); 195 + 196 + memcpy(frag + 1, skbinfo->frags, sizeof(*frag) * skbinfo->nr_frags); 197 + /* We dont need to clear skbinfo->nr_frags here */ 198 + 199 + new_truesize = SKB_DATA_ALIGN(sizeof(struct sk_buff)); 200 + delta_truesize = skb->truesize - new_truesize; 201 + skb->truesize = new_truesize; 202 + NAPI_GRO_CB(skb)->free = NAPI_GRO_FREE_STOLEN_HEAD; 203 + goto done; 204 + } 205 + 206 + merge: 207 + /* sk owenrship - if any - completely transferred to the aggregated packet */ 208 + skb->destructor = NULL; 209 + delta_truesize = skb->truesize; 210 + if (offset > headlen) { 211 + unsigned int eat = offset - headlen; 212 + 213 + skb_frag_off_add(&skbinfo->frags[0], eat); 214 + skb_frag_size_sub(&skbinfo->frags[0], eat); 215 + skb->data_len -= eat; 216 + skb->len -= eat; 217 + offset = headlen; 218 + } 219 + 220 + __skb_pull(skb, offset); 221 + 222 + if (NAPI_GRO_CB(p)->last == p) 223 + skb_shinfo(p)->frag_list = skb; 224 + else 225 + NAPI_GRO_CB(p)->last->next = skb; 226 + NAPI_GRO_CB(p)->last = skb; 227 + __skb_header_release(skb); 228 + lp = p; 229 + 230 + done: 231 + NAPI_GRO_CB(p)->count++; 232 + p->data_len += len; 233 + p->truesize += delta_truesize; 234 + p->len += len; 235 + if (lp != p) { 236 + lp->data_len += len; 237 + lp->truesize += delta_truesize; 238 + lp->len += len; 239 + } 240 + NAPI_GRO_CB(skb)->same_flow = 1; 241 + return 0; 242 + } 243 + 244 + 245 + static void napi_gro_complete(struct napi_struct *napi, struct sk_buff *skb) 246 + { 247 + struct packet_offload *ptype; 248 + __be16 type = skb->protocol; 249 + struct list_head *head = &offload_base; 250 + int err = -ENOENT; 251 + 252 + BUILD_BUG_ON(sizeof(struct napi_gro_cb) > sizeof(skb->cb)); 253 + 254 + if (NAPI_GRO_CB(skb)->count == 1) { 255 + skb_shinfo(skb)->gso_size = 0; 256 + goto out; 257 + } 258 + 259 + rcu_read_lock(); 260 + list_for_each_entry_rcu(ptype, head, list) { 261 + if (ptype->type != type || !ptype->callbacks.gro_complete) 262 + continue; 263 + 264 + err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete, 265 + ipv6_gro_complete, inet_gro_complete, 266 + skb, 0); 267 + break; 268 + } 269 + rcu_read_unlock(); 270 + 271 + if (err) { 272 + WARN_ON(&ptype->list == head); 273 + kfree_skb(skb); 274 + return; 275 + } 276 + 277 + out: 278 + gro_normal_one(napi, skb, NAPI_GRO_CB(skb)->count); 279 + } 280 + 281 + static void __napi_gro_flush_chain(struct napi_struct *napi, u32 index, 282 + bool flush_old) 283 + { 284 + struct list_head *head = &napi->gro_hash[index].list; 285 + struct sk_buff *skb, *p; 286 + 287 + list_for_each_entry_safe_reverse(skb, p, head, list) { 288 + if (flush_old && NAPI_GRO_CB(skb)->age == jiffies) 289 + return; 290 + skb_list_del_init(skb); 291 + napi_gro_complete(napi, skb); 292 + napi->gro_hash[index].count--; 293 + } 294 + 295 + if (!napi->gro_hash[index].count) 296 + __clear_bit(index, &napi->gro_bitmask); 297 + } 298 + 299 + /* napi->gro_hash[].list contains packets ordered by age. 300 + * youngest packets at the head of it. 301 + * Complete skbs in reverse order to reduce latencies. 302 + */ 303 + void napi_gro_flush(struct napi_struct *napi, bool flush_old) 304 + { 305 + unsigned long bitmask = napi->gro_bitmask; 306 + unsigned int i, base = ~0U; 307 + 308 + while ((i = ffs(bitmask)) != 0) { 309 + bitmask >>= i; 310 + base += i; 311 + __napi_gro_flush_chain(napi, base, flush_old); 312 + } 313 + } 314 + EXPORT_SYMBOL(napi_gro_flush); 315 + 316 + static void gro_list_prepare(const struct list_head *head, 317 + const struct sk_buff *skb) 318 + { 319 + unsigned int maclen = skb->dev->hard_header_len; 320 + u32 hash = skb_get_hash_raw(skb); 321 + struct sk_buff *p; 322 + 323 + list_for_each_entry(p, head, list) { 324 + unsigned long diffs; 325 + 326 + NAPI_GRO_CB(p)->flush = 0; 327 + 328 + if (hash != skb_get_hash_raw(p)) { 329 + NAPI_GRO_CB(p)->same_flow = 0; 330 + continue; 331 + } 332 + 333 + diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev; 334 + diffs |= skb_vlan_tag_present(p) ^ skb_vlan_tag_present(skb); 335 + if (skb_vlan_tag_present(p)) 336 + diffs |= skb_vlan_tag_get(p) ^ skb_vlan_tag_get(skb); 337 + diffs |= skb_metadata_differs(p, skb); 338 + if (maclen == ETH_HLEN) 339 + diffs |= compare_ether_header(skb_mac_header(p), 340 + skb_mac_header(skb)); 341 + else if (!diffs) 342 + diffs = memcmp(skb_mac_header(p), 343 + skb_mac_header(skb), 344 + maclen); 345 + 346 + /* in most common scenarions 'slow_gro' is 0 347 + * otherwise we are already on some slower paths 348 + * either skip all the infrequent tests altogether or 349 + * avoid trying too hard to skip each of them individually 350 + */ 351 + if (!diffs && unlikely(skb->slow_gro | p->slow_gro)) { 352 + #if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT) 353 + struct tc_skb_ext *skb_ext; 354 + struct tc_skb_ext *p_ext; 355 + #endif 356 + 357 + diffs |= p->sk != skb->sk; 358 + diffs |= skb_metadata_dst_cmp(p, skb); 359 + diffs |= skb_get_nfct(p) ^ skb_get_nfct(skb); 360 + 361 + #if IS_ENABLED(CONFIG_SKB_EXTENSIONS) && IS_ENABLED(CONFIG_NET_TC_SKB_EXT) 362 + skb_ext = skb_ext_find(skb, TC_SKB_EXT); 363 + p_ext = skb_ext_find(p, TC_SKB_EXT); 364 + 365 + diffs |= (!!p_ext) ^ (!!skb_ext); 366 + if (!diffs && unlikely(skb_ext)) 367 + diffs |= p_ext->chain ^ skb_ext->chain; 368 + #endif 369 + } 370 + 371 + NAPI_GRO_CB(p)->same_flow = !diffs; 372 + } 373 + } 374 + 375 + static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff) 376 + { 377 + const struct skb_shared_info *pinfo = skb_shinfo(skb); 378 + const skb_frag_t *frag0 = &pinfo->frags[0]; 379 + 380 + NAPI_GRO_CB(skb)->data_offset = 0; 381 + NAPI_GRO_CB(skb)->frag0 = NULL; 382 + NAPI_GRO_CB(skb)->frag0_len = 0; 383 + 384 + if (!skb_headlen(skb) && pinfo->nr_frags && 385 + !PageHighMem(skb_frag_page(frag0)) && 386 + (!NET_IP_ALIGN || !((skb_frag_off(frag0) + nhoff) & 3))) { 387 + NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0); 388 + NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int, 389 + skb_frag_size(frag0), 390 + skb->end - skb->tail); 391 + } 392 + } 393 + 394 + static void gro_pull_from_frag0(struct sk_buff *skb, int grow) 395 + { 396 + struct skb_shared_info *pinfo = skb_shinfo(skb); 397 + 398 + BUG_ON(skb->end - skb->tail < grow); 399 + 400 + memcpy(skb_tail_pointer(skb), NAPI_GRO_CB(skb)->frag0, grow); 401 + 402 + skb->data_len -= grow; 403 + skb->tail += grow; 404 + 405 + skb_frag_off_add(&pinfo->frags[0], grow); 406 + skb_frag_size_sub(&pinfo->frags[0], grow); 407 + 408 + if (unlikely(!skb_frag_size(&pinfo->frags[0]))) { 409 + skb_frag_unref(skb, 0); 410 + memmove(pinfo->frags, pinfo->frags + 1, 411 + --pinfo->nr_frags * sizeof(pinfo->frags[0])); 412 + } 413 + } 414 + 415 + static void gro_flush_oldest(struct napi_struct *napi, struct list_head *head) 416 + { 417 + struct sk_buff *oldest; 418 + 419 + oldest = list_last_entry(head, struct sk_buff, list); 420 + 421 + /* We are called with head length >= MAX_GRO_SKBS, so this is 422 + * impossible. 423 + */ 424 + if (WARN_ON_ONCE(!oldest)) 425 + return; 426 + 427 + /* Do not adjust napi->gro_hash[].count, caller is adding a new 428 + * SKB to the chain. 429 + */ 430 + skb_list_del_init(oldest); 431 + napi_gro_complete(napi, oldest); 432 + } 433 + 434 + static enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 435 + { 436 + u32 bucket = skb_get_hash_raw(skb) & (GRO_HASH_BUCKETS - 1); 437 + struct gro_list *gro_list = &napi->gro_hash[bucket]; 438 + struct list_head *head = &offload_base; 439 + struct packet_offload *ptype; 440 + __be16 type = skb->protocol; 441 + struct sk_buff *pp = NULL; 442 + enum gro_result ret; 443 + int same_flow; 444 + int grow; 445 + 446 + if (netif_elide_gro(skb->dev)) 447 + goto normal; 448 + 449 + gro_list_prepare(&gro_list->list, skb); 450 + 451 + rcu_read_lock(); 452 + list_for_each_entry_rcu(ptype, head, list) { 453 + if (ptype->type != type || !ptype->callbacks.gro_receive) 454 + continue; 455 + 456 + skb_set_network_header(skb, skb_gro_offset(skb)); 457 + skb_reset_mac_len(skb); 458 + NAPI_GRO_CB(skb)->same_flow = 0; 459 + NAPI_GRO_CB(skb)->flush = skb_is_gso(skb) || skb_has_frag_list(skb); 460 + NAPI_GRO_CB(skb)->free = 0; 461 + NAPI_GRO_CB(skb)->encap_mark = 0; 462 + NAPI_GRO_CB(skb)->recursion_counter = 0; 463 + NAPI_GRO_CB(skb)->is_fou = 0; 464 + NAPI_GRO_CB(skb)->is_atomic = 1; 465 + NAPI_GRO_CB(skb)->gro_remcsum_start = 0; 466 + 467 + /* Setup for GRO checksum validation */ 468 + switch (skb->ip_summed) { 469 + case CHECKSUM_COMPLETE: 470 + NAPI_GRO_CB(skb)->csum = skb->csum; 471 + NAPI_GRO_CB(skb)->csum_valid = 1; 472 + NAPI_GRO_CB(skb)->csum_cnt = 0; 473 + break; 474 + case CHECKSUM_UNNECESSARY: 475 + NAPI_GRO_CB(skb)->csum_cnt = skb->csum_level + 1; 476 + NAPI_GRO_CB(skb)->csum_valid = 0; 477 + break; 478 + default: 479 + NAPI_GRO_CB(skb)->csum_cnt = 0; 480 + NAPI_GRO_CB(skb)->csum_valid = 0; 481 + } 482 + 483 + pp = INDIRECT_CALL_INET(ptype->callbacks.gro_receive, 484 + ipv6_gro_receive, inet_gro_receive, 485 + &gro_list->list, skb); 486 + break; 487 + } 488 + rcu_read_unlock(); 489 + 490 + if (&ptype->list == head) 491 + goto normal; 492 + 493 + if (PTR_ERR(pp) == -EINPROGRESS) { 494 + ret = GRO_CONSUMED; 495 + goto ok; 496 + } 497 + 498 + same_flow = NAPI_GRO_CB(skb)->same_flow; 499 + ret = NAPI_GRO_CB(skb)->free ? GRO_MERGED_FREE : GRO_MERGED; 500 + 501 + if (pp) { 502 + skb_list_del_init(pp); 503 + napi_gro_complete(napi, pp); 504 + gro_list->count--; 505 + } 506 + 507 + if (same_flow) 508 + goto ok; 509 + 510 + if (NAPI_GRO_CB(skb)->flush) 511 + goto normal; 512 + 513 + if (unlikely(gro_list->count >= MAX_GRO_SKBS)) 514 + gro_flush_oldest(napi, &gro_list->list); 515 + else 516 + gro_list->count++; 517 + 518 + NAPI_GRO_CB(skb)->count = 1; 519 + NAPI_GRO_CB(skb)->age = jiffies; 520 + NAPI_GRO_CB(skb)->last = skb; 521 + skb_shinfo(skb)->gso_size = skb_gro_len(skb); 522 + list_add(&skb->list, &gro_list->list); 523 + ret = GRO_HELD; 524 + 525 + pull: 526 + grow = skb_gro_offset(skb) - skb_headlen(skb); 527 + if (grow > 0) 528 + gro_pull_from_frag0(skb, grow); 529 + ok: 530 + if (gro_list->count) { 531 + if (!test_bit(bucket, &napi->gro_bitmask)) 532 + __set_bit(bucket, &napi->gro_bitmask); 533 + } else if (test_bit(bucket, &napi->gro_bitmask)) { 534 + __clear_bit(bucket, &napi->gro_bitmask); 535 + } 536 + 537 + return ret; 538 + 539 + normal: 540 + ret = GRO_NORMAL; 541 + goto pull; 542 + } 543 + 544 + struct packet_offload *gro_find_receive_by_type(__be16 type) 545 + { 546 + struct list_head *offload_head = &offload_base; 547 + struct packet_offload *ptype; 548 + 549 + list_for_each_entry_rcu(ptype, offload_head, list) { 550 + if (ptype->type != type || !ptype->callbacks.gro_receive) 551 + continue; 552 + return ptype; 553 + } 554 + return NULL; 555 + } 556 + EXPORT_SYMBOL(gro_find_receive_by_type); 557 + 558 + struct packet_offload *gro_find_complete_by_type(__be16 type) 559 + { 560 + struct list_head *offload_head = &offload_base; 561 + struct packet_offload *ptype; 562 + 563 + list_for_each_entry_rcu(ptype, offload_head, list) { 564 + if (ptype->type != type || !ptype->callbacks.gro_complete) 565 + continue; 566 + return ptype; 567 + } 568 + return NULL; 569 + } 570 + EXPORT_SYMBOL(gro_find_complete_by_type); 571 + 572 + static gro_result_t napi_skb_finish(struct napi_struct *napi, 573 + struct sk_buff *skb, 574 + gro_result_t ret) 575 + { 576 + switch (ret) { 577 + case GRO_NORMAL: 578 + gro_normal_one(napi, skb, 1); 579 + break; 580 + 581 + case GRO_MERGED_FREE: 582 + if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) 583 + napi_skb_free_stolen_head(skb); 584 + else if (skb->fclone != SKB_FCLONE_UNAVAILABLE) 585 + __kfree_skb(skb); 586 + else 587 + __kfree_skb_defer(skb); 588 + break; 589 + 590 + case GRO_HELD: 591 + case GRO_MERGED: 592 + case GRO_CONSUMED: 593 + break; 594 + } 595 + 596 + return ret; 597 + } 598 + 599 + gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) 600 + { 601 + gro_result_t ret; 602 + 603 + skb_mark_napi_id(skb, napi); 604 + trace_napi_gro_receive_entry(skb); 605 + 606 + skb_gro_reset_offset(skb, 0); 607 + 608 + ret = napi_skb_finish(napi, skb, dev_gro_receive(napi, skb)); 609 + trace_napi_gro_receive_exit(ret); 610 + 611 + return ret; 612 + } 613 + EXPORT_SYMBOL(napi_gro_receive); 614 + 615 + static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb) 616 + { 617 + if (unlikely(skb->pfmemalloc)) { 618 + consume_skb(skb); 619 + return; 620 + } 621 + __skb_pull(skb, skb_headlen(skb)); 622 + /* restore the reserve we had after netdev_alloc_skb_ip_align() */ 623 + skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN - skb_headroom(skb)); 624 + __vlan_hwaccel_clear_tag(skb); 625 + skb->dev = napi->dev; 626 + skb->skb_iif = 0; 627 + 628 + /* eth_type_trans() assumes pkt_type is PACKET_HOST */ 629 + skb->pkt_type = PACKET_HOST; 630 + 631 + skb->encapsulation = 0; 632 + skb_shinfo(skb)->gso_type = 0; 633 + skb->truesize = SKB_TRUESIZE(skb_end_offset(skb)); 634 + if (unlikely(skb->slow_gro)) { 635 + skb_orphan(skb); 636 + skb_ext_reset(skb); 637 + nf_reset_ct(skb); 638 + skb->slow_gro = 0; 639 + } 640 + 641 + napi->skb = skb; 642 + } 643 + 644 + struct sk_buff *napi_get_frags(struct napi_struct *napi) 645 + { 646 + struct sk_buff *skb = napi->skb; 647 + 648 + if (!skb) { 649 + skb = napi_alloc_skb(napi, GRO_MAX_HEAD); 650 + if (skb) { 651 + napi->skb = skb; 652 + skb_mark_napi_id(skb, napi); 653 + } 654 + } 655 + return skb; 656 + } 657 + EXPORT_SYMBOL(napi_get_frags); 658 + 659 + static gro_result_t napi_frags_finish(struct napi_struct *napi, 660 + struct sk_buff *skb, 661 + gro_result_t ret) 662 + { 663 + switch (ret) { 664 + case GRO_NORMAL: 665 + case GRO_HELD: 666 + __skb_push(skb, ETH_HLEN); 667 + skb->protocol = eth_type_trans(skb, skb->dev); 668 + if (ret == GRO_NORMAL) 669 + gro_normal_one(napi, skb, 1); 670 + break; 671 + 672 + case GRO_MERGED_FREE: 673 + if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) 674 + napi_skb_free_stolen_head(skb); 675 + else 676 + napi_reuse_skb(napi, skb); 677 + break; 678 + 679 + case GRO_MERGED: 680 + case GRO_CONSUMED: 681 + break; 682 + } 683 + 684 + return ret; 685 + } 686 + 687 + /* Upper GRO stack assumes network header starts at gro_offset=0 688 + * Drivers could call both napi_gro_frags() and napi_gro_receive() 689 + * We copy ethernet header into skb->data to have a common layout. 690 + */ 691 + static struct sk_buff *napi_frags_skb(struct napi_struct *napi) 692 + { 693 + struct sk_buff *skb = napi->skb; 694 + const struct ethhdr *eth; 695 + unsigned int hlen = sizeof(*eth); 696 + 697 + napi->skb = NULL; 698 + 699 + skb_reset_mac_header(skb); 700 + skb_gro_reset_offset(skb, hlen); 701 + 702 + if (unlikely(skb_gro_header_hard(skb, hlen))) { 703 + eth = skb_gro_header_slow(skb, hlen, 0); 704 + if (unlikely(!eth)) { 705 + net_warn_ratelimited("%s: dropping impossible skb from %s\n", 706 + __func__, napi->dev->name); 707 + napi_reuse_skb(napi, skb); 708 + return NULL; 709 + } 710 + } else { 711 + eth = (const struct ethhdr *)skb->data; 712 + gro_pull_from_frag0(skb, hlen); 713 + NAPI_GRO_CB(skb)->frag0 += hlen; 714 + NAPI_GRO_CB(skb)->frag0_len -= hlen; 715 + } 716 + __skb_pull(skb, hlen); 717 + 718 + /* 719 + * This works because the only protocols we care about don't require 720 + * special handling. 721 + * We'll fix it up properly in napi_frags_finish() 722 + */ 723 + skb->protocol = eth->h_proto; 724 + 725 + return skb; 726 + } 727 + 728 + gro_result_t napi_gro_frags(struct napi_struct *napi) 729 + { 730 + gro_result_t ret; 731 + struct sk_buff *skb = napi_frags_skb(napi); 732 + 733 + trace_napi_gro_frags_entry(skb); 734 + 735 + ret = napi_frags_finish(napi, skb, dev_gro_receive(napi, skb)); 736 + trace_napi_gro_frags_exit(ret); 737 + 738 + return ret; 739 + } 740 + EXPORT_SYMBOL(napi_gro_frags); 741 + 742 + /* Compute the checksum from gro_offset and return the folded value 743 + * after adding in any pseudo checksum. 744 + */ 745 + __sum16 __skb_gro_checksum_complete(struct sk_buff *skb) 746 + { 747 + __wsum wsum; 748 + __sum16 sum; 749 + 750 + wsum = skb_checksum(skb, skb_gro_offset(skb), skb_gro_len(skb), 0); 751 + 752 + /* NAPI_GRO_CB(skb)->csum holds pseudo checksum */ 753 + sum = csum_fold(csum_add(NAPI_GRO_CB(skb)->csum, wsum)); 754 + /* See comments in __skb_checksum_complete(). */ 755 + if (likely(!sum)) { 756 + if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE) && 757 + !skb->csum_complete_sw) 758 + netdev_rx_csum_fault(skb->dev, skb); 759 + } 760 + 761 + NAPI_GRO_CB(skb)->csum = wsum; 762 + NAPI_GRO_CB(skb)->csum_valid = 1; 763 + 764 + return sum; 765 + } 766 + EXPORT_SYMBOL(__skb_gro_checksum_complete);
-142
net/core/skbuff.c
··· 3919 3919 } 3920 3920 EXPORT_SYMBOL_GPL(skb_segment_list); 3921 3921 3922 - int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb) 3923 - { 3924 - if (unlikely(p->len + skb->len >= 65536)) 3925 - return -E2BIG; 3926 - 3927 - if (NAPI_GRO_CB(p)->last == p) 3928 - skb_shinfo(p)->frag_list = skb; 3929 - else 3930 - NAPI_GRO_CB(p)->last->next = skb; 3931 - 3932 - skb_pull(skb, skb_gro_offset(skb)); 3933 - 3934 - NAPI_GRO_CB(p)->last = skb; 3935 - NAPI_GRO_CB(p)->count++; 3936 - p->data_len += skb->len; 3937 - 3938 - /* sk owenrship - if any - completely transferred to the aggregated packet */ 3939 - skb->destructor = NULL; 3940 - p->truesize += skb->truesize; 3941 - p->len += skb->len; 3942 - 3943 - NAPI_GRO_CB(skb)->same_flow = 1; 3944 - 3945 - return 0; 3946 - } 3947 - 3948 3922 /** 3949 3923 * skb_segment - Perform protocol segmentation on skb. 3950 3924 * @head_skb: buffer to segment ··· 4270 4296 return ERR_PTR(err); 4271 4297 } 4272 4298 EXPORT_SYMBOL_GPL(skb_segment); 4273 - 4274 - int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) 4275 - { 4276 - struct skb_shared_info *pinfo, *skbinfo = skb_shinfo(skb); 4277 - unsigned int offset = skb_gro_offset(skb); 4278 - unsigned int headlen = skb_headlen(skb); 4279 - unsigned int len = skb_gro_len(skb); 4280 - unsigned int delta_truesize; 4281 - unsigned int new_truesize; 4282 - struct sk_buff *lp; 4283 - 4284 - if (unlikely(p->len + len >= 65536 || NAPI_GRO_CB(skb)->flush)) 4285 - return -E2BIG; 4286 - 4287 - lp = NAPI_GRO_CB(p)->last; 4288 - pinfo = skb_shinfo(lp); 4289 - 4290 - if (headlen <= offset) { 4291 - skb_frag_t *frag; 4292 - skb_frag_t *frag2; 4293 - int i = skbinfo->nr_frags; 4294 - int nr_frags = pinfo->nr_frags + i; 4295 - 4296 - if (nr_frags > MAX_SKB_FRAGS) 4297 - goto merge; 4298 - 4299 - offset -= headlen; 4300 - pinfo->nr_frags = nr_frags; 4301 - skbinfo->nr_frags = 0; 4302 - 4303 - frag = pinfo->frags + nr_frags; 4304 - frag2 = skbinfo->frags + i; 4305 - do { 4306 - *--frag = *--frag2; 4307 - } while (--i); 4308 - 4309 - skb_frag_off_add(frag, offset); 4310 - skb_frag_size_sub(frag, offset); 4311 - 4312 - /* all fragments truesize : remove (head size + sk_buff) */ 4313 - new_truesize = SKB_TRUESIZE(skb_end_offset(skb)); 4314 - delta_truesize = skb->truesize - new_truesize; 4315 - 4316 - skb->truesize = new_truesize; 4317 - skb->len -= skb->data_len; 4318 - skb->data_len = 0; 4319 - 4320 - NAPI_GRO_CB(skb)->free = NAPI_GRO_FREE; 4321 - goto done; 4322 - } else if (skb->head_frag) { 4323 - int nr_frags = pinfo->nr_frags; 4324 - skb_frag_t *frag = pinfo->frags + nr_frags; 4325 - struct page *page = virt_to_head_page(skb->head); 4326 - unsigned int first_size = headlen - offset; 4327 - unsigned int first_offset; 4328 - 4329 - if (nr_frags + 1 + skbinfo->nr_frags > MAX_SKB_FRAGS) 4330 - goto merge; 4331 - 4332 - first_offset = skb->data - 4333 - (unsigned char *)page_address(page) + 4334 - offset; 4335 - 4336 - pinfo->nr_frags = nr_frags + 1 + skbinfo->nr_frags; 4337 - 4338 - __skb_frag_set_page(frag, page); 4339 - skb_frag_off_set(frag, first_offset); 4340 - skb_frag_size_set(frag, first_size); 4341 - 4342 - memcpy(frag + 1, skbinfo->frags, sizeof(*frag) * skbinfo->nr_frags); 4343 - /* We dont need to clear skbinfo->nr_frags here */ 4344 - 4345 - new_truesize = SKB_DATA_ALIGN(sizeof(struct sk_buff)); 4346 - delta_truesize = skb->truesize - new_truesize; 4347 - skb->truesize = new_truesize; 4348 - NAPI_GRO_CB(skb)->free = NAPI_GRO_FREE_STOLEN_HEAD; 4349 - goto done; 4350 - } 4351 - 4352 - merge: 4353 - /* sk owenrship - if any - completely transferred to the aggregated packet */ 4354 - skb->destructor = NULL; 4355 - delta_truesize = skb->truesize; 4356 - if (offset > headlen) { 4357 - unsigned int eat = offset - headlen; 4358 - 4359 - skb_frag_off_add(&skbinfo->frags[0], eat); 4360 - skb_frag_size_sub(&skbinfo->frags[0], eat); 4361 - skb->data_len -= eat; 4362 - skb->len -= eat; 4363 - offset = headlen; 4364 - } 4365 - 4366 - __skb_pull(skb, offset); 4367 - 4368 - if (NAPI_GRO_CB(p)->last == p) 4369 - skb_shinfo(p)->frag_list = skb; 4370 - else 4371 - NAPI_GRO_CB(p)->last->next = skb; 4372 - NAPI_GRO_CB(p)->last = skb; 4373 - __skb_header_release(skb); 4374 - lp = p; 4375 - 4376 - done: 4377 - NAPI_GRO_CB(p)->count++; 4378 - p->data_len += len; 4379 - p->truesize += delta_truesize; 4380 - p->len += len; 4381 - if (lp != p) { 4382 - lp->data_len += len; 4383 - lp->truesize += delta_truesize; 4384 - lp->len += len; 4385 - } 4386 - NAPI_GRO_CB(skb)->same_flow = 1; 4387 - return 0; 4388 - } 4389 4299 4390 4300 #ifdef CONFIG_SKB_EXTENSIONS 4391 4301 #define SKB_EXT_ALIGN_VALUE 8
+1
net/ipv4/af_inet.c
··· 99 99 #include <net/route.h> 100 100 #include <net/ip_fib.h> 101 101 #include <net/inet_connection_sock.h> 102 + #include <net/gro.h> 102 103 #include <net/tcp.h> 103 104 #include <net/udp.h> 104 105 #include <net/udplite.h>
+1
net/ipv4/esp4_offload.c
··· 16 16 #include <crypto/authenc.h> 17 17 #include <linux/err.h> 18 18 #include <linux/module.h> 19 + #include <net/gro.h> 19 20 #include <net/ip.h> 20 21 #include <net/xfrm.h> 21 22 #include <net/esp.h>
+1
net/ipv4/fou.c
··· 9 9 #include <linux/types.h> 10 10 #include <linux/kernel.h> 11 11 #include <net/genetlink.h> 12 + #include <net/gro.h> 12 13 #include <net/gue.h> 13 14 #include <net/fou.h> 14 15 #include <net/ip.h>
+1
net/ipv4/gre_offload.c
··· 10 10 #include <linux/init.h> 11 11 #include <net/protocol.h> 12 12 #include <net/gre.h> 13 + #include <net/gro.h> 13 14 14 15 static struct sk_buff *gre_gso_segment(struct sk_buff *skb, 15 16 netdev_features_t features)
+1
net/ipv4/tcp_offload.c
··· 8 8 9 9 #include <linux/indirect_call_wrapper.h> 10 10 #include <linux/skbuff.h> 11 + #include <net/gro.h> 11 12 #include <net/tcp.h> 12 13 #include <net/protocol.h> 13 14
+28
net/ipv4/udp_offload.c
··· 7 7 */ 8 8 9 9 #include <linux/skbuff.h> 10 + #include <net/gro.h> 10 11 #include <net/udp.h> 11 12 #include <net/protocol.h> 12 13 #include <net/inet_common.h> ··· 424 423 out: 425 424 return segs; 426 425 } 426 + 427 + static int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb) 428 + { 429 + if (unlikely(p->len + skb->len >= 65536)) 430 + return -E2BIG; 431 + 432 + if (NAPI_GRO_CB(p)->last == p) 433 + skb_shinfo(p)->frag_list = skb; 434 + else 435 + NAPI_GRO_CB(p)->last->next = skb; 436 + 437 + skb_pull(skb, skb_gro_offset(skb)); 438 + 439 + NAPI_GRO_CB(p)->last = skb; 440 + NAPI_GRO_CB(p)->count++; 441 + p->data_len += skb->len; 442 + 443 + /* sk owenrship - if any - completely transferred to the aggregated packet */ 444 + skb->destructor = NULL; 445 + p->truesize += skb->truesize; 446 + p->len += skb->len; 447 + 448 + NAPI_GRO_CB(skb)->same_flow = 1; 449 + 450 + return 0; 451 + } 452 + 427 453 428 454 #define UDP_GRO_CNT_MAX 64 429 455 static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
+1
net/ipv6/esp6_offload.c
··· 16 16 #include <crypto/authenc.h> 17 17 #include <linux/err.h> 18 18 #include <linux/module.h> 19 + #include <net/gro.h> 19 20 #include <net/ip.h> 20 21 #include <net/xfrm.h> 21 22 #include <net/esp.h>
+1
net/ipv6/tcpv6_offload.c
··· 7 7 */ 8 8 #include <linux/indirect_call_wrapper.h> 9 9 #include <linux/skbuff.h> 10 + #include <net/gro.h> 10 11 #include <net/protocol.h> 11 12 #include <net/tcp.h> 12 13 #include <net/ip6_checksum.h>
+1
net/ipv6/udp_offload.c
··· 13 13 #include <net/udp.h> 14 14 #include <net/ip6_checksum.h> 15 15 #include "ip6_offload.h" 16 + #include <net/gro.h> 16 17 17 18 static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, 18 19 netdev_features_t features)