History

xsk: Add option to calculate TX checksum in SW

For XDP_COPY mode, add a UMEM option XDP_UMEM_TX_SW_CSUM to call skb_checksum_help in transmit path. Might be useful to debugging issues with real hardware. I also use this mode in the selftests.

Stanislav Fomichev committed 2 years ago

Commit 11614721 parent ce59f967 files · +37 −3Browse files

Unified · Split

7 files
  1. Documentation/networking/xsk-tx-metadata.rst +9 −0
  2. include/net/xsk_buff_pool.h +1 −0
  3. include/uapi/linux/if_xdp.h +7 −1
  4. net/xdp/xdp_umem.c +6 −1
  5. net/xdp/xsk.c +6 −0
  6. net/xdp/xsk_buff_pool.c +1 −0
  7. tools/include/uapi/linux/if_xdp.h +7 −1
Documentation/networking/xsk-tx-metadata.rst+9−0
@@ -50,6 +50,15 @@ packet's ``struct xdp_desc`` descriptor should set ``XDP_TX_METADATA`` · 49 unmodified lines
5050 bit in the ``options`` field. Also note that in a multi-buffer packet
5151 only the first chunk should carry the metadata.
5252
53+Software TX Checksum
54+====================
55+
56+For development and testing purposes its possible to pass
57+``XDP_UMEM_TX_SW_CSUM`` flag to ``XDP_UMEM_REG`` UMEM registration call.
58+In this case, when running in ``XDK_COPY`` mode, the TX checksum
59+is calculated on the CPU. Do not enable this option in production because
60+it will negatively affect performance.
61+
5362 Querying Device Capabilities
5463 ============================
5564
include/net/xsk_buff_pool.h+1−0
@@ -83,6 +83,7 @@ struct xsk_buff_pool { · 82 unmodified lines
8383 bool uses_need_wakeup;
8484 bool dma_need_sync;
8585 bool unaligned;
86+ bool tx_sw_csum;
8687 void *addrs;
8788 /* Mutual exclusion of the completion ring in the SKB mode. Two cases to protect:
8889 * NAPI TX thread and sendmsg error paths in the SKB destructor callback and when
include/uapi/linux/if_xdp.h+7−1
@@ -33,7 +33,13 @@ · 32 unmodified lines
3333 #define XDP_USE_SG (1 << 4)
3434
3535 /* Flags for xsk_umem_config flags */
36−#define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
36+#define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
37+
38+/* Force checksum calculation in software. Can be used for testing or
39+ * working around potential HW issues. This option causes performance
40+ * degradation and only works in XDP_COPY mode.
41+ */
42+#define XDP_UMEM_TX_SW_CSUM (1 << 1)
3743
3844 struct sockaddr_xdp {
3945 __u16 sxdp_family;
net/xdp/xdp_umem.c+6−1
@@ -148,6 +148,11 @@ static int xdp_umem_account_pages(struct xdp_umem *umem) · 147 unmodified lines
148148 return 0;
149149 }
150150
151+#define XDP_UMEM_FLAGS_VALID ( \
152+ XDP_UMEM_UNALIGNED_CHUNK_FLAG | \
153+ XDP_UMEM_TX_SW_CSUM | \
154+ 0)
155+
151156 static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
152157 {
153158 bool unaligned_chunks = mr->flags & XDP_UMEM_UNALIGNED_CHUNK_FLAG;
@@ -167,7 +172,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) · 13 unmodified lines
167172 return -EINVAL;
168173 }
169174
170− if (mr->flags & ~XDP_UMEM_UNALIGNED_CHUNK_FLAG)
175+ if (mr->flags & ~XDP_UMEM_FLAGS_VALID)
171176 return -EINVAL;
172177
173178 if (!unaligned_chunks && !is_power_of_2(chunk_size))
net/xdp/xsk.c+6−0
@@ -744,6 +744,12 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs, · 743 unmodified lines
744744 skb->csum_start = hr + meta->request.csum_start;
745745 skb->csum_offset = meta->request.csum_offset;
746746 skb->ip_summed = CHECKSUM_PARTIAL;
747+
748+ if (unlikely(xs->pool->tx_sw_csum)) {
749+ err = skb_checksum_help(skb);
750+ if (err)
751+ goto free_err;
752+ }
747753 }
748754 }
749755 }
net/xdp/xsk_buff_pool.c+1−0
@@ -86,6 +86,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs, · 85 unmodified lines
8686 pool->umem = umem;
8787 pool->addrs = umem->addrs;
8888 pool->tx_metadata_len = umem->tx_metadata_len;
89+ pool->tx_sw_csum = umem->flags & XDP_UMEM_TX_SW_CSUM;
8990 INIT_LIST_HEAD(&pool->free_list);
9091 INIT_LIST_HEAD(&pool->xskb_list);
9192 INIT_LIST_HEAD(&pool->xsk_tx_list);
tools/include/uapi/linux/if_xdp.h+7−1
@@ -33,7 +33,13 @@ · 32 unmodified lines
3333 #define XDP_USE_SG (1 << 4)
3434
3535 /* Flags for xsk_umem_config flags */
36−#define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
36+#define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
37+
38+/* Force checksum calculation in software. Can be used for testing or
39+ * working around potential HW issues. This option causes performance
40+ * degradation and only works in XDP_COPY mode.
41+ */
42+#define XDP_UMEM_TX_SW_CSUM (1 << 1)
3743
3844 struct sockaddr_xdp {
3945 __u16 sxdp_family;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t