From: Kommula Shiva Shankar <kshankar@marvell.com>
To: <pabeni@redhat.com>, <willemb@google.com>, <jasowang@redhat.com>,
<parav@nvidia.com>, <virtio-comment@lists.linux.dev>
Cc: <ndabilpuram@marvell.com>, <jerinj@marvell.com>, <rbhansali@marvell.com>
Subject: [PATCH v5] virtio-net: Introduce a new field to indicate outer network header offset
Date: Wed, 2 Apr 2025 01:26:55 +0530 [thread overview]
Message-ID: <20250401195655.486230-1-kshankar@marvell.com> (raw)
This patch introduces a new field in the virtio_net_hdr called outer_nh_offset, along with a new net device feature, VIRTIO_NET_F_OUT_NET_HEADER.
Currently, drivers lack a dedicated field to signal the start of the network header to the device when performing checksum offload
and segmentation offload. This requires the device to read the packet in data path, which significantly affects performance.
Additionally, some hardware implementations require knowledge of the outer L3 offset (aka L2 length) for inline IPsec hardware acceleration.
To address this limitation, we propose to introduce a new field in the virtio_net_hdr called
outer_nh_offset.
The outer_nh_offset represents the start byte offset of the outer network header from the beginning of the packet.
This issue was briefly discussed on the mailing list in a different thread, which can be found here.
https://lore.kernel.org/all/DM4PR18MB4269FAAC3CFC7E57E25DFBD2DF8B2@DM4PR18MB4269.namprd18.prod.outlook.com/
v4->v5
- Added padding bytes to virtio_net_hdr to ensure 64b alignment
- Addressed pending review comments
v4:https://lore.kernel.org/virtio-comment/20250304075955.208450-1-kshankar@marvell.com/
v3 -> v4
- Removed the union of new flag with existing flags. Added as a separate field
in the virtio net header
- Renamed out_nh_offset to outer_nh_offset to maintain consistency with other fields
- Spellchecks in commit message description
v3:https://lore.kernel.org/all/20250217172509.107212-1-kshankar@marvell.com
v2 -> v3:
- Rebase to virtio-1.4
- Addressed pending review comments related to wording.
v2:https://lore.kernel.org/all/20250128142152.3662988-1-kshankar@marvell.com/
v1 -> v2:
- explicitly state that the out_nh_offset can be set only when a valid network header is present.
- updated out_nh_offset usage in the RX direction.
- minor word cleanup.
v1: https://lore.kernel.org/virtio-comment/20250114171636.3175670-1-kshankar@marvell.com/
Signed-off-by: Kommula Shiva Shankar <kshankar@marvell.com>
---
device-types/net/description.tex | 37 +++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/device-types/net/description.tex b/device-types/net/description.tex
index 1b6b54d..0bb1cef 100644
--- a/device-types/net/description.tex
+++ b/device-types/net/description.tex
@@ -136,6 +136,10 @@ \subsection{Feature bits}\label{sec:Device Types / Network Device / Feature bits
\item[VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM (68)] Device handles packets
carried by a UDP tunnel with partial csum for the outer header.
+
+\item[VIRTIO_NET_F_OUT_NET_HEADER(69)] Driver can provide the start of
+ \field{outer_nh_offset} value. Device gains advantage by not reading packet
+ to calculate outer network header offset.
\end{description}
\subsubsection{Feature bit requirements}\label{sec:Device Types / Network Device / Feature bits / Feature bit requirements}
@@ -599,6 +603,8 @@ \subsection{Device Operation}\label{sec:Device Types / Network Device / Device O
le16 padding_reserved; (Only if VIRTIO_NET_F_HASH_REPORT negotiated)
le16 outer_th_offset (Only if VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO or VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO negotiated)
le16 inner_nh_offset; (Only if VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO or VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO negotiated)
+ le16 outer_nh_offset; /* Only if VIRTIO_NET_F_OUT_NET_HEADER negotiated */
+ u8 padding_reserved_2[6]; /* Only if VIRTIO_NET_F_OUT_NET_HEADER negotiated */
};
\end{lstlisting}
@@ -633,6 +639,11 @@ \subsubsection{Packet Transmission}\label{sec:Device Types / Network Device / De
\item The driver can send a completely checksummed packet. In this case,
\field{flags} will be zero, and \field{gso_type} will be VIRTIO_NET_HDR_GSO_NONE.
+\item When VIRTIO_NET_F_OUT_NET_HEADER is negotiated, the driver MAY optionally provide
+ the \field{outer_nh_offset} value. A nonzero value of \field{outer_nh_offset} indicates
+ a valid outer network header with in the packet, and specifies the offset in bytes from
+ the beginning of the packet. Otherwise \field{outer_nh_offset} MUST not be used.
+
\item If the driver negotiated VIRTIO_NET_F_CSUM, it can skip
checksumming the packet:
\begin{itemize}
@@ -767,6 +778,11 @@ \subsubsection{Packet Transmission}\label{sec:Device Types / Network Device / De
\field{flags} to zero and SHOULD supply a fully checksummed
packet to the device.
+If the VIRTIO_NET_F_OUT_NET_HEADER feature has been negotiated,
+the driver MAY set \field{outer_nh_offset} to nonzero value to indicate
+the start of the outer network header offset, if the packet contains a
+valid network header. Otherwise, \field{outer_nh_offset} is not used.
+
If VIRTIO_NET_F_HOST_TSO4 is negotiated, the driver MAY set
\field{gso_type} to VIRTIO_NET_HDR_GSO_TCPV4 to request TCPv4
segmentation, otherwise the driver MUST NOT set
@@ -948,6 +964,11 @@ \subsubsection{Packet Transmission}\label{sec:Device Types / Network Device / De
If VIRTIO_NET_HDR_F_NEEDS_CSUM bit in \field{flags} is not set, the
device MUST NOT use the \field{csum_start} and \field{csum_offset}.
+If the VIRTIO_NET_F_OUT_NET_HEADER feature has been negotiated,
+and \field{outer_nh_offset} is nonzero, the device MAY use \field{outer_nh_offset}
+as the outer network header offset. Otherwise, device MUST NOT use
+the \field{outer_nh_offset}.
+
If one of the VIRTIO_NET_F_HOST_TSO4, TSO6, USO or UFO options have
been negotiated:
\begin{itemize}
@@ -1049,7 +1070,9 @@ \subsubsection{Setting Up Receive Buffers}\label{sec:Device Types / Network Devi
\end{note}
When calculating the size of \field{struct virtio_net_hdr}, the driver
-MUST consider all the fields inclusive up to \field{padding_reserved},
+MUST consider all the fields inclusive up to \field{padding_reserved_2},
+i.e. 32 bytes if VIRTIO_NET_F_OUT_NET_HEADER is negotiated or up to \field{inner_nh_offset}
+i.e. 24 bytes if VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO is negotiated or up to \field{padding_reserved}
i.e. 20 bytes if VIRTIO_NET_F_HASH_REPORT is negotiated, and 12 bytes if not.
If VIRTIO_NET_F_MQ is negotiated, each of receiveq1\ldots receiveqN
@@ -1102,6 +1125,9 @@ \subsubsection{Processing of Incoming Packets}\label{sec:Device Types / Network
both the outer UDP checksum and the inner transport checksum
have been validated, otherwise only one level of checksums (the outer one
in case of tunnels) has been validated.
+\item If the VIRTIO_NET_F_OUT_NET_HEADER has been negotiated, and if the packet
+ contains a valid network header, \field{outer_nh_offset} MAY be set to nonzero
+ value to indicate the outer network header offset in packet.
\end{enumerate}
Additionally, VIRTIO_NET_F_GUEST_CSUM, TSO4, TSO6, UDP, UDP_TUNNEL
@@ -1215,6 +1241,11 @@ \subsubsection{Processing of Incoming Packets}\label{sec:Device Types / Network
device MUST set the VIRTIO_NET_HDR_GSO_ECN bit in
\field{gso_type}.
+If VIRTIO_NET_F_OUT_NET_HEADER has been negotiated, the device MAY
+set the \field{outer_nh_offset} to nonzero value to indicate outer network header offset,
+if packet contains a valid network header. Otherwise, the device MUST not
+use \field{outer_nh_offset}.
+
If the VIRTIO_NET_F_GUEST_CSUM feature has been negotiated, the
device MAY set the VIRTIO_NET_HDR_F_NEEDS_CSUM bit in
\field{flags}, if so:
@@ -1302,6 +1333,10 @@ \subsubsection{Processing of Incoming Packets}\label{sec:Device Types / Network
The driver MUST ignore \field{flag} bits that it does not recognize.
+If VIRTIO_NET_F_OUT_NET_HEADER has been negotiated, and if \field{outer_nh_offset}
+is nonzero, the driver MAY use \field{outer_nh_offset} as outer network header
+offset. Otherwise, the driver MUST not use the \field{outer_nh_offset}.
+
If VIRTIO_NET_HDR_F_NEEDS_CSUM bit in \field{flags} is not set or
if VIRTIO_NET_HDR_F_RSC_INFO bit \field{flags} is set, the
driver MUST NOT use the \field{csum_start} and \field{csum_offset}.
--
2.43.0
next reply other threads:[~2025-04-01 19:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 19:56 Kommula Shiva Shankar [this message]
2025-04-20 12:44 ` [PATCH v5] virtio-net: Introduce a new field to indicate outer network header offset Parav Pandit
2025-04-21 6:23 ` Shiva Shankar Kommula
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=20250401195655.486230-1-kshankar@marvell.com \
--to=kshankar@marvell.com \
--cc=jasowang@redhat.com \
--cc=jerinj@marvell.com \
--cc=ndabilpuram@marvell.com \
--cc=pabeni@redhat.com \
--cc=parav@nvidia.com \
--cc=rbhansali@marvell.com \
--cc=virtio-comment@lists.linux.dev \
--cc=willemb@google.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