linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload
@ 2024-10-18  9:14 Muyang Tian
  2024-10-18  9:15 ` [PATCH bpf-next v2 1/3] xdp: Add Rx checksum hint Muyang Tian
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Muyang Tian @ 2024-10-18  9:14 UTC (permalink / raw)
  To: bpf
  Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Donald Hunter, Björn Töpel, Magnus Karlsson,
	Maciej Fijalkowski, Jonathan Lemon, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, netdev,
	linux-kernel, linux-doc, yanan, xiesongyang, wuchangye, liuxin350,
	zhangmingyi5, liwei883, tianmuyang

This series introduce XDP metadata functionality, including Rx checksum/GSO hint
and Tx GSO offload. This is aimed to transfer control fields when processing jumbo
frames between VMs.

v1:
https://lore.kernel.org/all/20241017135430.51655-1-tianmuyang@huawei.com/

Changes since v1:
- add reference to previous work[1] in patch 1/3

[1] https://lore.kernel.org/bpf/20230811161509.19722-13-larysa.zaremba@intel.com/

Muyang Tian (3):
  xdp: Add Rx checksum hint
  xdp: Add Rx GSO hint
  xsk: Add Tx GSO type and size offload support

 Documentation/netlink/specs/netdev.yaml      | 12 +++++
 Documentation/networking/xdp-rx-metadata.rst |  6 +++
 include/net/xdp.h                            | 50 ++++++++++++++++++++
 include/net/xdp_sock.h                       |  8 ++++
 include/net/xdp_sock_drv.h                   |  1 +
 include/uapi/linux/if_xdp.h                  | 11 +++++
 include/uapi/linux/netdev.h                  |  8 ++++
 net/core/xdp.c                               | 41 ++++++++++++++++
 net/xdp/xsk.c                                |  5 ++
 tools/include/uapi/linux/if_xdp.h            | 11 +++++
 tools/include/uapi/linux/netdev.h            |  8 ++++
 11 files changed, 161 insertions(+)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH bpf-next v2 1/3] xdp: Add Rx checksum hint
  2024-10-18  9:14 [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Muyang Tian
@ 2024-10-18  9:15 ` Muyang Tian
  2024-10-18  9:15 ` [PATCH bpf-next v2 2/3] xdp: Add Rx GSO hint Muyang Tian
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Muyang Tian @ 2024-10-18  9:15 UTC (permalink / raw)
  To: bpf
  Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Donald Hunter, Björn Töpel, Magnus Karlsson,
	Maciej Fijalkowski, Jonathan Lemon, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, netdev,
	linux-kernel, linux-doc, yanan, xiesongyang, wuchangye, liuxin350,
	zhangmingyi5, liwei883, tianmuyang

This is an implementation of functionality that allows drivers
to expose checksum information to XDP, as generally based on 
previous work[1], with xdp_csum_status modified.
This information includes:
- Checksum info, a union of
  - complete checksum, if checksum is complete
  - skb-style checksum start and offset, if checksum is partial
- Checksum status, an enum which is the same as skb checksums in
  skbuff.h, identical to sk_buff.ip_summed

LINK:[1] https://lore.kernel.org/bpf/20230927075124.23941-13-larysa.zaremba@intel.com

Signed-off-by: Muyang Tian <tianmuyang@huawei.com>
Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
 Documentation/netlink/specs/netdev.yaml      |  4 +++
 Documentation/networking/xdp-rx-metadata.rst |  3 ++
 include/net/xdp.h                            | 38 ++++++++++++++++++++
 include/uapi/linux/netdev.h                  |  3 ++
 net/core/xdp.c                               | 23 ++++++++++++
 tools/include/uapi/linux/netdev.h            |  3 ++
 6 files changed, 74 insertions(+)

diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
index 08412c279297..e6045b447fc1 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -58,6 +58,10 @@ definitions:
         name: vlan-tag
         doc:
           Device is capable of exposing receive packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag().
+      -
+        name: csum
+        doc:
+          Device is capable of exposing receive packet checksum via bpf_xdp_metadata_rx_csum().
   -
     type: flags
     name: xsk-flags
diff --git a/Documentation/networking/xdp-rx-metadata.rst b/Documentation/networking/xdp-rx-metadata.rst
index a6e0ece18be5..6cf273b33ee6 100644
--- a/Documentation/networking/xdp-rx-metadata.rst
+++ b/Documentation/networking/xdp-rx-metadata.rst
@@ -28,6 +28,9 @@ metadata is supported, this set will grow:
 .. kernel-doc:: net/core/xdp.c
    :identifiers: bpf_xdp_metadata_rx_vlan_tag
 
+.. kernel-doc:: net/core/xdp.c
+   :identifiers: bpf_xdp_metadata_rx_csum
+
 An XDP program can use these kfuncs to read the metadata into stack
 variables for its own consumption. Or, to pass the metadata on to other
 consumers, an XDP program can store it into the metadata area carried
diff --git a/include/net/xdp.h b/include/net/xdp.h
index e6770dd40c91..7886658975c4 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -408,6 +408,10 @@ void xdp_attachment_setup(struct xdp_attachment_info *info,
 			   NETDEV_XDP_RX_METADATA_VLAN_TAG, \
 			   bpf_xdp_metadata_rx_vlan_tag, \
 			   xmo_rx_vlan_tag) \
+	XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_CSUM, \
+			   NETDEV_XDP_RX_METADATA_CSUM, \
+			   bpf_xdp_metadata_rx_csum, \
+			   xmo_rx_csum) \
 
 enum xdp_rx_metadata {
 #define XDP_METADATA_KFUNC(name, _, __, ___) name,
@@ -465,12 +469,46 @@ enum xdp_rss_hash_type {
 	XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
 };
 
+enum xdp_csum_status {
+	/* The following enums are the same as skb checksums in skbuff.h, refer to
+	 * DOC: skb checksums for more details.
+	 */
+
+	XDP_CHECKSUM_NONE = 0,
+	XDP_CHECKSUM_UNNECESSARY = 1,
+	/* Checksum, calculated over the entire packet is provided, as ``csum`` in
+	 * ``xdp_csum_info``.
+	 */
+	XDP_CHECKSUM_COMPLETE = 2,
+	/* Refer to ``csum_start`` and ``csum_offset`` in ``xdp_csum_info`` for more information. */
+	XDP_CHECKSUM_PARTIAL = 3,
+};
+
+union xdp_csum_info {
+	/* Checksum, calculated over the whole packet.
+	 * Available, if ``status & XDP_CHECKSUM_COMPLETE``.
+	 */
+	__wsum csum;
+	/* Checksum referred to by ``csum_start + csum_offset`` is considered
+	 * valid, but was never calculated, TX device has to do this,
+	 * starting from csum_start packet byte.
+	 * Any preceding checksums are also considered valid.
+	 * Available, if ``status == XDP_CHECKSUM_PARTIAL``.
+	 */
+	struct {
+		u16 csum_start;
+		u16 csum_offset;
+	};
+};
+
 struct xdp_metadata_ops {
 	int	(*xmo_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp);
 	int	(*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash,
 			       enum xdp_rss_hash_type *rss_type);
 	int	(*xmo_rx_vlan_tag)(const struct xdp_md *ctx, __be16 *vlan_proto,
 				   u16 *vlan_tci);
+	int (*xmo_rx_csum)(const struct xdp_md *ctx, enum xdp_csum_status *csum_status,
+				   union xdp_csum_info *csum_info);
 };
 
 #ifdef CONFIG_NET
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index 7c308f04e7a0..a969b25529a3 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -46,11 +46,14 @@ enum netdev_xdp_act {
  *   hash via bpf_xdp_metadata_rx_hash().
  * @NETDEV_XDP_RX_METADATA_VLAN_TAG: Device is capable of exposing receive
  *   packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag().
+ * @NETDEV_XDP_RX_METADATA_CSUM: Device is capable of exposing receive packet
+ *   checksum via bpf_xdp_metadata_rx_csum().
  */
 enum netdev_xdp_rx_metadata {
 	NETDEV_XDP_RX_METADATA_TIMESTAMP = 1,
 	NETDEV_XDP_RX_METADATA_HASH = 2,
 	NETDEV_XDP_RX_METADATA_VLAN_TAG = 4,
+	NETDEV_XDP_RX_METADATA_CSUM = 8,
 };
 
 /**
diff --git a/net/core/xdp.c b/net/core/xdp.c
index bcc5551c6424..583e00d3580a 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -766,6 +766,29 @@ __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
 	return -EOPNOTSUPP;
 }
 
+/**
+ * bpf_xdp_metadata_rx_csum - Read XDP frame checksum status and info.
+ * @ctx: XDP context pointer.
+ * @csum_status: Destination pointer for checksum status.
+ * @csum_info: Destination pointer for complete checksum or partial checksum offset.
+ *
+ * Status (@csum_status) is an enum that informs what checksum processing was
+ * performed, same as sk_buff.ip_summed. Additional results of such processing,
+ * such as complete checksum or partial checksum offsets, are passed as
+ * info (@csum_info).
+ *
+ * Return:
+ * * Returns 0 on success or ``-errno`` on error.
+ * * ``-EOPNOTSUPP`` : means device driver doesn't implement kfunc
+ * * ``-ENODATA``    : means checksum status is unknown for this frame
+ */
+__bpf_kfunc int bpf_xdp_metadata_rx_csum(const struct xdp_md *ctx,
+					 enum xdp_csum_status *csum_status,
+					 union xdp_csum_info *csum_info)
+{
+	return -EOPNOTSUPP;
+}
+
 __bpf_kfunc_end_defs();
 
 BTF_KFUNCS_START(xdp_metadata_kfunc_ids)
diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h
index 7c308f04e7a0..a969b25529a3 100644
--- a/tools/include/uapi/linux/netdev.h
+++ b/tools/include/uapi/linux/netdev.h
@@ -46,11 +46,14 @@ enum netdev_xdp_act {
  *   hash via bpf_xdp_metadata_rx_hash().
  * @NETDEV_XDP_RX_METADATA_VLAN_TAG: Device is capable of exposing receive
  *   packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag().
+ * @NETDEV_XDP_RX_METADATA_CSUM: Device is capable of exposing receive packet
+ *   checksum via bpf_xdp_metadata_rx_csum().
  */
 enum netdev_xdp_rx_metadata {
 	NETDEV_XDP_RX_METADATA_TIMESTAMP = 1,
 	NETDEV_XDP_RX_METADATA_HASH = 2,
 	NETDEV_XDP_RX_METADATA_VLAN_TAG = 4,
+	NETDEV_XDP_RX_METADATA_CSUM = 8,
 };
 
 /**
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH bpf-next v2 2/3] xdp: Add Rx GSO hint
  2024-10-18  9:14 [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Muyang Tian
  2024-10-18  9:15 ` [PATCH bpf-next v2 1/3] xdp: Add Rx checksum hint Muyang Tian
@ 2024-10-18  9:15 ` Muyang Tian
  2024-10-18  9:15 ` [PATCH bpf-next v2 3/3] xsk: Add Tx GSO type and size offload support Muyang Tian
  2024-10-18 16:39 ` [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Stanislav Fomichev
  3 siblings, 0 replies; 7+ messages in thread
From: Muyang Tian @ 2024-10-18  9:15 UTC (permalink / raw)
  To: bpf
  Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Donald Hunter, Björn Töpel, Magnus Karlsson,
	Maciej Fijalkowski, Jonathan Lemon, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, netdev,
	linux-kernel, linux-doc, yanan, xiesongyang, wuchangye, liuxin350,
	zhangmingyi5, liwei883, tianmuyang

This is an implementation of functionality that allows drivers to
expose GSO information to XDP.
This information includes:
  - GSO info, including GSO type and size in skb_shared_info

Signed-off-by: Muyang Tian <tianmuyang@huawei.com>
---
 Documentation/netlink/specs/netdev.yaml      |  4 ++++
 Documentation/networking/xdp-rx-metadata.rst |  3 +++
 include/net/xdp.h                            | 12 ++++++++++++
 include/uapi/linux/netdev.h                  |  3 +++
 net/core/xdp.c                               | 18 ++++++++++++++++++
 tools/include/uapi/linux/netdev.h            |  3 +++
 6 files changed, 43 insertions(+)

diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
index e6045b447fc1..5beee7c8e7cf 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -62,6 +62,10 @@ definitions:
         name: csum
         doc:
           Device is capable of exposing receive packet checksum via bpf_xdp_metadata_rx_csum().
+      -
+        name: gso
+        doc:
+          Device is capable of exposing receive packet GSO via bpf_xdp_metadata_rx_gso().
   -
     type: flags
     name: xsk-flags
diff --git a/Documentation/networking/xdp-rx-metadata.rst b/Documentation/networking/xdp-rx-metadata.rst
index 6cf273b33ee6..618b9ba606e5 100644
--- a/Documentation/networking/xdp-rx-metadata.rst
+++ b/Documentation/networking/xdp-rx-metadata.rst
@@ -31,6 +31,9 @@ metadata is supported, this set will grow:
 .. kernel-doc:: net/core/xdp.c
    :identifiers: bpf_xdp_metadata_rx_csum
 
+.. kernel-doc:: net/core/xdp.c
+   :identifiers: bpf_xdp_metadata_rx_gso
+
 An XDP program can use these kfuncs to read the metadata into stack
 variables for its own consumption. Or, to pass the metadata on to other
 consumers, an XDP program can store it into the metadata area carried
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 7886658975c4..2e08f54106d3 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -412,6 +412,10 @@ void xdp_attachment_setup(struct xdp_attachment_info *info,
 			   NETDEV_XDP_RX_METADATA_CSUM, \
 			   bpf_xdp_metadata_rx_csum, \
 			   xmo_rx_csum) \
+	XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_GSO, \
+			   NETDEV_XDP_RX_METADATA_GSO, \
+			   bpf_xdp_metadata_rx_gso, \
+			   xmo_rx_gso) \
 
 enum xdp_rx_metadata {
 #define XDP_METADATA_KFUNC(name, _, __, ___) name,
@@ -501,6 +505,13 @@ union xdp_csum_info {
 	};
 };
 
+struct xdp_gso_info {
+	/* GSO info in skb_shared_info */
+
+	unsigned int	gso_type;
+	unsigned short	gso_size;
+};
+
 struct xdp_metadata_ops {
 	int	(*xmo_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp);
 	int	(*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash,
@@ -509,6 +520,7 @@ struct xdp_metadata_ops {
 				   u16 *vlan_tci);
 	int (*xmo_rx_csum)(const struct xdp_md *ctx, enum xdp_csum_status *csum_status,
 				   union xdp_csum_info *csum_info);
+	int	(*xmo_rx_gso)(const struct xdp_md *ctx, struct xdp_gso_info *gso_info);
 };
 
 #ifdef CONFIG_NET
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index a969b25529a3..1e711d6a4c6b 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -48,12 +48,15 @@ enum netdev_xdp_act {
  *   packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag().
  * @NETDEV_XDP_RX_METADATA_CSUM: Device is capable of exposing receive packet
  *   checksum via bpf_xdp_metadata_rx_csum().
+ * @NETDEV_XDP_RX_METADATA_GSO: Device is capable of exposing receive packet
+ *   GSO via bpf_xdp_metadata_rx_gso().
  */
 enum netdev_xdp_rx_metadata {
 	NETDEV_XDP_RX_METADATA_TIMESTAMP = 1,
 	NETDEV_XDP_RX_METADATA_HASH = 2,
 	NETDEV_XDP_RX_METADATA_VLAN_TAG = 4,
 	NETDEV_XDP_RX_METADATA_CSUM = 8,
+	NETDEV_XDP_RX_METADATA_GSO = 16,
 };
 
 /**
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 583e00d3580a..983440e2b3bf 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -789,6 +789,24 @@ __bpf_kfunc int bpf_xdp_metadata_rx_csum(const struct xdp_md *ctx,
 	return -EOPNOTSUPP;
 }
 
+/**
+ * bpf_xdp_metadata_rx_gso - Read XDP frame GSO info.
+ * @ctx: XDP context pointer.
+ * @gso_info: Destination pointer for GSO info.
+ *
+ * Info (@gso_info) includes GSO type and size from skb_shared_info.
+ *
+ * Return:
+ * * Returns 0 on success or ``-errno`` on error.
+ * * ``-EOPNOTSUPP`` : means device driver doesn't implement kfunc
+ * * ``-ENODATA``    : means no GSO info available for this frame
+ */
+__bpf_kfunc int bpf_xdp_metadata_rx_gso(const struct xdp_md *ctx,
+					 struct xdp_gso_info *gso_info)
+{
+	return -EOPNOTSUPP;
+}
+
 __bpf_kfunc_end_defs();
 
 BTF_KFUNCS_START(xdp_metadata_kfunc_ids)
diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h
index a969b25529a3..1e711d6a4c6b 100644
--- a/tools/include/uapi/linux/netdev.h
+++ b/tools/include/uapi/linux/netdev.h
@@ -48,12 +48,15 @@ enum netdev_xdp_act {
  *   packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag().
  * @NETDEV_XDP_RX_METADATA_CSUM: Device is capable of exposing receive packet
  *   checksum via bpf_xdp_metadata_rx_csum().
+ * @NETDEV_XDP_RX_METADATA_GSO: Device is capable of exposing receive packet
+ *   GSO via bpf_xdp_metadata_rx_gso().
  */
 enum netdev_xdp_rx_metadata {
 	NETDEV_XDP_RX_METADATA_TIMESTAMP = 1,
 	NETDEV_XDP_RX_METADATA_HASH = 2,
 	NETDEV_XDP_RX_METADATA_VLAN_TAG = 4,
 	NETDEV_XDP_RX_METADATA_CSUM = 8,
+	NETDEV_XDP_RX_METADATA_GSO = 16,
 };
 
 /**
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH bpf-next v2 3/3] xsk: Add Tx GSO type and size offload support
  2024-10-18  9:14 [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Muyang Tian
  2024-10-18  9:15 ` [PATCH bpf-next v2 1/3] xdp: Add Rx checksum hint Muyang Tian
  2024-10-18  9:15 ` [PATCH bpf-next v2 2/3] xdp: Add Rx GSO hint Muyang Tian
@ 2024-10-18  9:15 ` Muyang Tian
  2024-10-18 16:39 ` [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Stanislav Fomichev
  3 siblings, 0 replies; 7+ messages in thread
From: Muyang Tian @ 2024-10-18  9:15 UTC (permalink / raw)
  To: bpf
  Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Donald Hunter, Björn Töpel, Magnus Karlsson,
	Maciej Fijalkowski, Jonathan Lemon, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, netdev,
	linux-kernel, linux-doc, yanan, xiesongyang, wuchangye, liuxin350,
	zhangmingyi5, liwei883, tianmuyang

This change extends the xsk_tx_metadata struct with
GSO type and size fields.
A new offload XDP_TX_METADATA_GSO is defined, which
offloads gso_type and gso_size in skb_shared_info to XDP.

Signed-off-by: Muyang Tian <tianmuyang@huawei.com>
---
 Documentation/netlink/specs/netdev.yaml |  4 ++++
 include/net/xdp_sock.h                  |  8 ++++++++
 include/net/xdp_sock_drv.h              |  1 +
 include/uapi/linux/if_xdp.h             | 11 +++++++++++
 include/uapi/linux/netdev.h             |  2 ++
 net/xdp/xsk.c                           |  5 +++++
 tools/include/uapi/linux/if_xdp.h       | 11 +++++++++++
 tools/include/uapi/linux/netdev.h       |  2 ++
 8 files changed, 44 insertions(+)

diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
index 5beee7c8e7cf..f4aa04eba54c 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -78,6 +78,10 @@ definitions:
         name: tx-checksum
         doc:
           L3 checksum HW offload is supported by the driver.
+      -
+        name: tx-gso
+        doc:
+          GSO type and size is supported by the driver.
   -
     name: queue-type
     type: enum
diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
index bfe625b55d55..e5acb27c3e07 100644
--- a/include/net/xdp_sock.h
+++ b/include/net/xdp_sock.h
@@ -110,11 +110,14 @@ struct xdp_sock {
  *     indicates position where checksumming should start.
  *     csum_offset indicates position where checksum should be stored.
  *
+ * void (*tmo_request_gso)(u32 gso_type, u16 gso_size, void *priv)
+ *     Called when AF_XDP frame requested GSO info.
  */
 struct xsk_tx_metadata_ops {
 	void	(*tmo_request_timestamp)(void *priv);
 	u64	(*tmo_fill_timestamp)(void *priv);
 	void	(*tmo_request_checksum)(u16 csum_start, u16 csum_offset, void *priv);
+	void	(*tmo_request_gso)(u32 gso_type, u16 gso_size, void *priv);
 };
 
 #ifdef CONFIG_XDP_SOCKETS
@@ -170,6 +173,11 @@ static inline void xsk_tx_metadata_request(const struct xsk_tx_metadata *meta,
 		if (meta->flags & XDP_TXMD_FLAGS_CHECKSUM)
 			ops->tmo_request_checksum(meta->request.csum_start,
 						  meta->request.csum_offset, priv);
+
+	if (ops->tmo_request_gso)
+		if (meta->flags & XDP_TXMD_FLAGS_GSO)
+			ops->tmo_request_gso(meta->request.gso_type,
+						  meta->request.gso_size, priv);
 }
 
 /**
diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
index 0a5dca2b2b3f..b192dab2b835 100644
--- a/include/net/xdp_sock_drv.h
+++ b/include/net/xdp_sock_drv.h
@@ -198,6 +198,7 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr)
 #define XDP_TXMD_FLAGS_VALID ( \
 		XDP_TXMD_FLAGS_TIMESTAMP | \
 		XDP_TXMD_FLAGS_CHECKSUM | \
+		XDP_TXMD_FLAGS_GSO | \
 	0)
 
 static inline bool xsk_buff_valid_tx_metadata(struct xsk_tx_metadata *meta)
diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h
index 42ec5ddaab8d..c3ea368bf613 100644
--- a/include/uapi/linux/if_xdp.h
+++ b/include/uapi/linux/if_xdp.h
@@ -127,6 +127,11 @@ struct xdp_options {
  */
 #define XDP_TXMD_FLAGS_CHECKSUM			(1 << 1)
 
+/* Request transmit GSO info. GSO type and size are communicated via
+ * csum_start and csum_offset fields of struct xsk_tx_metadata.
+ */
+#define XDP_TXMD_FLAGS_GSO				(1 << 2)
+
 /* AF_XDP offloads request. 'request' union member is consumed by the driver
  * when the packet is being transmitted. 'completion' union member is
  * filled by the driver when the transmit completion arrives.
@@ -142,6 +147,12 @@ struct xsk_tx_metadata {
 			__u16 csum_start;
 			/* Offset from csum_start where checksum should be stored. */
 			__u16 csum_offset;
+
+			/* XDP_TXMD_FLAGS_GSO */
+			/* Identical to skb_shared_info.gso_type*/
+			__u32 gso_type;
+			/* Identical to skb_shared_info.gso_size*/
+			__u16 gso_size;
 		} request;
 
 		struct {
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index 1e711d6a4c6b..bd175afb3c6b 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -65,10 +65,12 @@ enum netdev_xdp_rx_metadata {
  *   by the driver.
  * @NETDEV_XSK_FLAGS_TX_CHECKSUM: L3 checksum HW offload is supported by the
  *   driver.
+ * @NETDEV_XSK_FLAGS_TX_GSO: GSO type and size is supported by the driver.
  */
 enum netdev_xsk_flags {
 	NETDEV_XSK_FLAGS_TX_TIMESTAMP = 1,
 	NETDEV_XSK_FLAGS_TX_CHECKSUM = 2,
+	NETDEV_XSK_FLAGS_TX_GSO = 4,
 };
 
 enum netdev_queue_type {
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 1140b2a120ca..5a19edfce16c 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -745,6 +745,11 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
 						goto free_err;
 				}
 			}
+
+			if (meta->flags & XDP_TXMD_FLAGS_GSO) {
+				skb_shinfo(skb)->gso_type = meta->request.gso_type;
+				skb_shinfo(skb)->gso_size = meta->request.gso_size;
+			}
 		}
 	}
 
diff --git a/tools/include/uapi/linux/if_xdp.h b/tools/include/uapi/linux/if_xdp.h
index 2f082b01ff22..5714d0be8c53 100644
--- a/tools/include/uapi/linux/if_xdp.h
+++ b/tools/include/uapi/linux/if_xdp.h
@@ -127,6 +127,11 @@ struct xdp_options {
  */
 #define XDP_TXMD_FLAGS_CHECKSUM			(1 << 1)
 
+/* Request transmit GSO info. GSO type and size are communicated via
+ * csum_start and csum_offset fields of struct xsk_tx_metadata.
+ */
+#define XDP_TXMD_FLAGS_GSO				(1 << 2)
+
 /* AF_XDP offloads request. 'request' union member is consumed by the driver
  * when the packet is being transmitted. 'completion' union member is
  * filled by the driver when the transmit completion arrives.
@@ -142,6 +147,12 @@ struct xsk_tx_metadata {
 			__u16 csum_start;
 			/* Offset from csum_start where checksum should be stored. */
 			__u16 csum_offset;
+
+			/* XDP_TXMD_FLAGS_GSO */
+			/* Identical to skb_shared_info.gso_type*/
+			__u32 gso_type;
+			/* Identical to skb_shared_info.gso_size*/
+			__u16 gso_size;
 		} request;
 
 		struct {
diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h
index 1e711d6a4c6b..bd175afb3c6b 100644
--- a/tools/include/uapi/linux/netdev.h
+++ b/tools/include/uapi/linux/netdev.h
@@ -65,10 +65,12 @@ enum netdev_xdp_rx_metadata {
  *   by the driver.
  * @NETDEV_XSK_FLAGS_TX_CHECKSUM: L3 checksum HW offload is supported by the
  *   driver.
+ * @NETDEV_XSK_FLAGS_TX_GSO: GSO type and size is supported by the driver.
  */
 enum netdev_xsk_flags {
 	NETDEV_XSK_FLAGS_TX_TIMESTAMP = 1,
 	NETDEV_XSK_FLAGS_TX_CHECKSUM = 2,
+	NETDEV_XSK_FLAGS_TX_GSO = 4,
 };
 
 enum netdev_queue_type {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload
  2024-10-18  9:14 [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Muyang Tian
                   ` (2 preceding siblings ...)
  2024-10-18  9:15 ` [PATCH bpf-next v2 3/3] xsk: Add Tx GSO type and size offload support Muyang Tian
@ 2024-10-18 16:39 ` Stanislav Fomichev
  2024-10-20 20:51   ` Willem de Bruijn
  3 siblings, 1 reply; 7+ messages in thread
From: Stanislav Fomichev @ 2024-10-18 16:39 UTC (permalink / raw)
  To: Muyang Tian
  Cc: bpf, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Donald Hunter, Björn Töpel, Magnus Karlsson,
	Maciej Fijalkowski, Jonathan Lemon, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, netdev,
	linux-kernel, linux-doc, yanan, xiesongyang, wuchangye, liuxin350,
	zhangmingyi5, liwei883, willemb

On 10/18, Muyang Tian wrote:
> This series introduce XDP metadata functionality, including Rx checksum/GSO hint
> and Tx GSO offload. This is aimed to transfer control fields when processing jumbo
> frames between VMs.

Ideally, the series should also have the implementation of these hints
for a couple of devices and appropriate selftest updates to exercise
them.

For GSO, CC Willem going forward (I don't think I understand why
we want to have gso_type in the TX hint; something like header_len
seems like a better fit).

Please also don't post v3 yet and allow at least a week for the initial
reviewers to catch up..

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload
  2024-10-18 16:39 ` [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Stanislav Fomichev
@ 2024-10-20 20:51   ` Willem de Bruijn
  2024-10-21 12:04     ` Magnus Karlsson
  0 siblings, 1 reply; 7+ messages in thread
From: Willem de Bruijn @ 2024-10-20 20:51 UTC (permalink / raw)
  To: Stanislav Fomichev, Muyang Tian
  Cc: bpf, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Donald Hunter, Björn Töpel, Magnus Karlsson,
	Maciej Fijalkowski, Jonathan Lemon, Alexei Starovoitov,
	Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend, netdev,
	linux-kernel, linux-doc, yanan, xiesongyang, wuchangye, liuxin350,
	zhangmingyi5, liwei883, willemb

Stanislav Fomichev wrote:
> On 10/18, Muyang Tian wrote:
> > This series introduce XDP metadata functionality, including Rx checksum/GSO hint
> > and Tx GSO offload. This is aimed to transfer control fields when processing jumbo
> > frames between VMs.
> 
> Ideally, the series should also have the implementation of these hints
> for a couple of devices and appropriate selftest updates to exercise
> them.

+1

> For GSO, CC Willem going forward (I don't think I understand why
> we want to have gso_type in the TX hint; something like header_len
> seems like a better fit).

GSO on Tx makes sense. To be able to program hardware USO, say.

GSO on Rx is less obvious. Is this for HW-GRO? In general, some usage
context will be helpful.

Two implementation questions:

- why define an XDP specific type for checksum types, but reuse the
  netdev type for gso_type?
- why u32 gso_type, when it is a u8 in skb_shared_info?

> Please also don't post v3 yet and allow at least a week for the initial
> reviewers to catch up..



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload
  2024-10-20 20:51   ` Willem de Bruijn
@ 2024-10-21 12:04     ` Magnus Karlsson
  0 siblings, 0 replies; 7+ messages in thread
From: Magnus Karlsson @ 2024-10-21 12:04 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: Stanislav Fomichev, Muyang Tian, bpf, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Donald Hunter,
	Björn Töpel, Magnus Karlsson, Maciej Fijalkowski,
	Jonathan Lemon, Alexei Starovoitov, Daniel Borkmann,
	Jesper Dangaard Brouer, John Fastabend, netdev, linux-kernel,
	linux-doc, yanan, xiesongyang, wuchangye, liuxin350, zhangmingyi5,
	liwei883, willemb

On Sun, 20 Oct 2024 at 22:51, Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> Stanislav Fomichev wrote:
> > On 10/18, Muyang Tian wrote:
> > > This series introduce XDP metadata functionality, including Rx checksum/GSO hint
> > > and Tx GSO offload. This is aimed to transfer control fields when processing jumbo
> > > frames between VMs.
> >
> > Ideally, the series should also have the implementation of these hints
> > for a couple of devices and appropriate selftest updates to exercise
> > them.
>
> +1

Larysa had one implementation for ice [0]. Ask her if she can update
and contribute that one. Then add one yourself and there are two
implementations which would hopefully make the case.

[0] https://lore.kernel.org/bpf/20230811161509.19722-1-larysa.zaremba@intel.com/

> > For GSO, CC Willem going forward (I don't think I understand why
> > we want to have gso_type in the TX hint; something like header_len
> > seems like a better fit).
>
> GSO on Tx makes sense. To be able to program hardware USO, say.
>
> GSO on Rx is less obvious. Is this for HW-GRO? In general, some usage
> context will be helpful.
>
> Two implementation questions:
>
> - why define an XDP specific type for checksum types, but reuse the
>   netdev type for gso_type?
> - why u32 gso_type, when it is a u8 in skb_shared_info?
>
> > Please also don't post v3 yet and allow at least a week for the initial
> > reviewers to catch up..
>
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-10-21 12:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-18  9:14 [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Muyang Tian
2024-10-18  9:15 ` [PATCH bpf-next v2 1/3] xdp: Add Rx checksum hint Muyang Tian
2024-10-18  9:15 ` [PATCH bpf-next v2 2/3] xdp: Add Rx GSO hint Muyang Tian
2024-10-18  9:15 ` [PATCH bpf-next v2 3/3] xsk: Add Tx GSO type and size offload support Muyang Tian
2024-10-18 16:39 ` [PATCH bpf-next v2 0/3] XDP metadata: Rx checksum/GSO hint; Tx GSO offload Stanislav Fomichev
2024-10-20 20:51   ` Willem de Bruijn
2024-10-21 12:04     ` Magnus Karlsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).