netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kommula Shiva Shankar <kshankar@marvell.com>
To: <netdev@vger.kernel.org>, <mst@redhat.com>, <jasowang@redhat.com>,
	<pabeni@redhat.com>, <xuanzhuo@linux.alibaba.com>
Cc: <virtualization@lists.linux.dev>, <parav@nvidia.com>,
	<jerinj@marvell.com>, <ndabilpuram@marvell.com>,
	<sburla@marvell.com>, <schalla@marvell.com>
Subject: [PATCH v2 net-next  2/3] virtio_net: enable outer nw header offset support
Date: Wed, 8 Oct 2025 16:30:03 +0530	[thread overview]
Message-ID: <20251008110004.2933101-3-kshankar@marvell.com> (raw)
In-Reply-To: <20251008110004.2933101-1-kshankar@marvell.com>

If outer network header feature is set, update header offset
in ingress and egress path.

If feature is not set, reset header offset to zero.

Signed-off-by: Kommula Shiva Shankar <kshankar@marvell.com>
---
 drivers/net/virtio_net.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 7da5a37917e9..0b60cbbb3d33 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -451,6 +451,9 @@ struct virtnet_info {
 
 	bool rx_tnl_csum;
 
+	/* Outer network header support */
+	bool out_net_hdr_negotiated;
+
 	/* Is delayed refill enabled? */
 	bool refill_enabled;
 
@@ -511,6 +514,7 @@ struct virtio_net_common_hdr {
 		struct virtio_net_hdr_mrg_rxbuf	mrg_hdr;
 		struct virtio_net_hdr_v1_hash hash_v1_hdr;
 		struct virtio_net_hdr_v1_hash_tunnel tnl_hdr;
+		struct virtio_net_hdr_v1_hash_tunnel_out_net_hdr out_net_hdr;
 	};
 };
 
@@ -2576,8 +2580,8 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *
 	hdr->hdr.flags = flags;
 	if (virtio_net_handle_csum_offload(skb, &hdr->hdr, vi->rx_tnl_csum)) {
 		net_warn_ratelimited("%s: bad csum: flags: %x, gso_type: %x rx_tnl_csum %d\n",
-				     dev->name, hdr->hdr.flags,
-				     hdr->hdr.gso_type, vi->rx_tnl_csum);
+				dev->name, hdr->hdr.flags,
+				hdr->hdr.gso_type, vi->rx_tnl_csum);
 		goto frame_err;
 	}
 
@@ -2591,6 +2595,8 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *
 		goto frame_err;
 	}
 
+	virtio_net_out_net_header_to_skb(skb, &hdr->out_net_hdr, vi->out_net_hdr_negotiated,
+					 virtio_is_little_endian(vi->vdev));
 	skb_record_rx_queue(skb, vq2rxq(rq->vq));
 	skb->protocol = eth_type_trans(skb, dev);
 	pr_debug("Receiving skb proto 0x%04x len %i type %i\n",
@@ -3317,6 +3323,9 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb, bool orphan)
 	else
 		hdr = &skb_vnet_common_hdr(skb)->tnl_hdr;
 
+	virtio_net_out_net_header_from_skb(skb, &skb_vnet_common_hdr(skb)->out_net_hdr,
+					   vi->out_net_hdr_negotiated,
+					   virtio_is_little_endian(vi->vdev));
 	if (virtio_net_hdr_tnl_from_skb(skb, hdr, vi->tx_tnl,
 					virtio_is_little_endian(vi->vdev), 0))
 		return -EPROTO;
@@ -6915,8 +6924,10 @@ static int virtnet_probe(struct virtio_device *vdev)
 		dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops;
 	}
 
-	if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) ||
-	    virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO))
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_OUT_NET_HEADER))
+		vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel_out_net_hdr);
+	else if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) ||
+		 virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO))
 		vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash_tunnel);
 	else if (vi->has_rss_hash_report)
 		vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash);
@@ -6933,6 +6944,9 @@ static int virtnet_probe(struct virtio_device *vdev)
 	if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO))
 		vi->tx_tnl = true;
 
+	if (virtio_has_feature(vdev, VIRTIO_NET_F_OUT_NET_HEADER))
+		vi->out_net_hdr_negotiated = true;
+
 	if (virtio_has_feature(vdev, VIRTIO_F_ANY_LAYOUT) ||
 	    virtio_has_feature(vdev, VIRTIO_F_VERSION_1))
 		vi->any_header_sg = true;
@@ -7247,6 +7261,7 @@ static unsigned int features[] = {
 	VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM,
 	VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO,
 	VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM,
+	VIRTIO_NET_F_OUT_NET_HEADER,
 };
 
 static unsigned int features_legacy[] = {
-- 
2.48.1


  parent reply	other threads:[~2025-10-08 11:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08 11:00 [PATCH v2 net-next 0/3] virtio_net: Implement VIRTIO_NET_F_OUT_NET_HEADER from virtio spec 1.4 Kommula Shiva Shankar
2025-10-08 11:00 ` [PATCH v2 net-next 1/3] net: implement virtio helper to handle outer nw offset Kommula Shiva Shankar
2025-10-08 11:00 ` Kommula Shiva Shankar [this message]
2025-10-08 11:00 ` [PATCH v2 net-next 3/3] vhost/net: enable outer nw header offset support Kommula Shiva Shankar
2025-10-09  9:44   ` Paolo Abeni
2025-10-09 10:31   ` Michael S. Tsirkin
2025-10-08 11:26 ` [PATCH v2 net-next 0/3] virtio_net: Implement VIRTIO_NET_F_OUT_NET_HEADER from virtio spec 1.4 Parav Pandit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251008110004.2933101-3-kshankar@marvell.com \
    --to=kshankar@marvell.com \
    --cc=jasowang@redhat.com \
    --cc=jerinj@marvell.com \
    --cc=mst@redhat.com \
    --cc=ndabilpuram@marvell.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=parav@nvidia.com \
    --cc=sburla@marvell.com \
    --cc=schalla@marvell.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).