segmentation-offloads.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. Segmentation Offloads in the Linux Networking Stack
  2. Introduction
  3. ============
  4. This document describes a set of techniques in the Linux networking stack
  5. to take advantage of segmentation offload capabilities of various NICs.
  6. The following technologies are described:
  7. * TCP Segmentation Offload - TSO
  8. * UDP Fragmentation Offload - UFO
  9. * IPIP, SIT, GRE, and UDP Tunnel Offloads
  10. * Generic Segmentation Offload - GSO
  11. * Generic Receive Offload - GRO
  12. * Partial Generic Segmentation Offload - GSO_PARTIAL
  13. * SCTP accelleration with GSO - GSO_BY_FRAGS
  14. TCP Segmentation Offload
  15. ========================
  16. TCP segmentation allows a device to segment a single frame into multiple
  17. frames with a data payload size specified in skb_shinfo()->gso_size.
  18. When TCP segmentation requested the bit for either SKB_GSO_TCPV4 or
  19. SKB_GSO_TCPV6 should be set in skb_shinfo()->gso_type and
  20. skb_shinfo()->gso_size should be set to a non-zero value.
  21. TCP segmentation is dependent on support for the use of partial checksum
  22. offload. For this reason TSO is normally disabled if the Tx checksum
  23. offload for a given device is disabled.
  24. In order to support TCP segmentation offload it is necessary to populate
  25. the network and transport header offsets of the skbuff so that the device
  26. drivers will be able determine the offsets of the IP or IPv6 header and the
  27. TCP header. In addition as CHECKSUM_PARTIAL is required csum_start should
  28. also point to the TCP header of the packet.
  29. For IPv4 segmentation we support one of two types in terms of the IP ID.
  30. The default behavior is to increment the IP ID with every segment. If the
  31. GSO type SKB_GSO_TCP_FIXEDID is specified then we will not increment the IP
  32. ID and all segments will use the same IP ID. If a device has
  33. NETIF_F_TSO_MANGLEID set then the IP ID can be ignored when performing TSO
  34. and we will either increment the IP ID for all frames, or leave it at a
  35. static value based on driver preference.
  36. UDP Fragmentation Offload
  37. =========================
  38. UDP fragmentation offload allows a device to fragment an oversized UDP
  39. datagram into multiple IPv4 fragments. Many of the requirements for UDP
  40. fragmentation offload are the same as TSO. However the IPv4 ID for
  41. fragments should not increment as a single IPv4 datagram is fragmented.
  42. UFO is deprecated: modern kernels will no longer generate UFO skbs, but can
  43. still receive them from tuntap and similar devices. Offload of UDP-based
  44. tunnel protocols is still supported.
  45. IPIP, SIT, GRE, UDP Tunnel, and Remote Checksum Offloads
  46. ========================================================
  47. In addition to the offloads described above it is possible for a frame to
  48. contain additional headers such as an outer tunnel. In order to account
  49. for such instances an additional set of segmentation offload types were
  50. introduced including SKB_GSO_IPXIP4, SKB_GSO_IPXIP6, SKB_GSO_GRE, and
  51. SKB_GSO_UDP_TUNNEL. These extra segmentation types are used to identify
  52. cases where there are more than just 1 set of headers. For example in the
  53. case of IPIP and SIT we should have the network and transport headers moved
  54. from the standard list of headers to "inner" header offsets.
  55. Currently only two levels of headers are supported. The convention is to
  56. refer to the tunnel headers as the outer headers, while the encapsulated
  57. data is normally referred to as the inner headers. Below is the list of
  58. calls to access the given headers:
  59. IPIP/SIT Tunnel:
  60. Outer Inner
  61. MAC skb_mac_header
  62. Network skb_network_header skb_inner_network_header
  63. Transport skb_transport_header
  64. UDP/GRE Tunnel:
  65. Outer Inner
  66. MAC skb_mac_header skb_inner_mac_header
  67. Network skb_network_header skb_inner_network_header
  68. Transport skb_transport_header skb_inner_transport_header
  69. In addition to the above tunnel types there are also SKB_GSO_GRE_CSUM and
  70. SKB_GSO_UDP_TUNNEL_CSUM. These two additional tunnel types reflect the
  71. fact that the outer header also requests to have a non-zero checksum
  72. included in the outer header.
  73. Finally there is SKB_GSO_TUNNEL_REMCSUM which indicates that a given tunnel
  74. header has requested a remote checksum offload. In this case the inner
  75. headers will be left with a partial checksum and only the outer header
  76. checksum will be computed.
  77. Generic Segmentation Offload
  78. ============================
  79. Generic segmentation offload is a pure software offload that is meant to
  80. deal with cases where device drivers cannot perform the offloads described
  81. above. What occurs in GSO is that a given skbuff will have its data broken
  82. out over multiple skbuffs that have been resized to match the MSS provided
  83. via skb_shinfo()->gso_size.
  84. Before enabling any hardware segmentation offload a corresponding software
  85. offload is required in GSO. Otherwise it becomes possible for a frame to
  86. be re-routed between devices and end up being unable to be transmitted.
  87. Generic Receive Offload
  88. =======================
  89. Generic receive offload is the complement to GSO. Ideally any frame
  90. assembled by GRO should be segmented to create an identical sequence of
  91. frames using GSO, and any sequence of frames segmented by GSO should be
  92. able to be reassembled back to the original by GRO. The only exception to
  93. this is IPv4 ID in the case that the DF bit is set for a given IP header.
  94. If the value of the IPv4 ID is not sequentially incrementing it will be
  95. altered so that it is when a frame assembled via GRO is segmented via GSO.
  96. Partial Generic Segmentation Offload
  97. ====================================
  98. Partial generic segmentation offload is a hybrid between TSO and GSO. What
  99. it effectively does is take advantage of certain traits of TCP and tunnels
  100. so that instead of having to rewrite the packet headers for each segment
  101. only the inner-most transport header and possibly the outer-most network
  102. header need to be updated. This allows devices that do not support tunnel
  103. offloads or tunnel offloads with checksum to still make use of segmentation.
  104. With the partial offload what occurs is that all headers excluding the
  105. inner transport header are updated such that they will contain the correct
  106. values for if the header was simply duplicated. The one exception to this
  107. is the outer IPv4 ID field. It is up to the device drivers to guarantee
  108. that the IPv4 ID field is incremented in the case that a given header does
  109. not have the DF bit set.
  110. SCTP accelleration with GSO
  111. ===========================
  112. SCTP - despite the lack of hardware support - can still take advantage of
  113. GSO to pass one large packet through the network stack, rather than
  114. multiple small packets.
  115. This requires a different approach to other offloads, as SCTP packets
  116. cannot be just segmented to (P)MTU. Rather, the chunks must be contained in
  117. IP segments, padding respected. So unlike regular GSO, SCTP can't just
  118. generate a big skb, set gso_size to the fragmentation point and deliver it
  119. to IP layer.
  120. Instead, the SCTP protocol layer builds an skb with the segments correctly
  121. padded and stored as chained skbs, and skb_segment() splits based on those.
  122. To signal this, gso_size is set to the special value GSO_BY_FRAGS.
  123. Therefore, any code in the core networking stack must be aware of the
  124. possibility that gso_size will be GSO_BY_FRAGS and handle that case
  125. appropriately.
  126. There are some helpers to make this easier:
  127. - skb_is_gso(skb) && skb_is_gso_sctp(skb) is the best way to see if
  128. an skb is an SCTP GSO skb.
  129. - For size checks, the skb_gso_validate_*_len family of helpers correctly
  130. considers GSO_BY_FRAGS.
  131. - For manipulating packets, skb_increase_gso_size and skb_decrease_gso_size
  132. will check for GSO_BY_FRAGS and WARN if asked to manipulate these skbs.
  133. This also affects drivers with the NETIF_F_FRAGLIST & NETIF_F_GSO_SCTP bits
  134. set. Note also that NETIF_F_GSO_SCTP is included in NETIF_F_GSO_SOFTWARE.