Skip to contentSkip to conversation

introducing RSS into virtio-net

RFC Superseded Sameeh Jubran 3 participants 10 messages Jan 25, 2018 – Mar 20, 2018

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover introducing RSS into virtio-net

From: Sameeh Jubran <[email protected]>

Hi all,

Most modern high end network devices today support configurable hash functions, the following commit introduces RSS - Receive Side Scaling - [1] into virtio net device. RSS is a technology developed by Microsoft that boosts network device performance by efficiently distributing the traffic among the CPUs in a multiprocessor system.

This feature is supported in most of the modern network cards as well as most modern OSes including Linux and Windows. It is worth mentioning that both DPDK and Hyper-v support RSS too.

Currently in NetKVM - the Windows driver for virtio-net - RSS is supported in the driver (software implementation) this adds extra overhead to the driver that's reflected in unneeded IPIs and TLB flushes, adding this support to the backend should enhance the performance and help avoid these overheads.

For all the reasons I mentioned above I think it is time for virtio-net to support this feature, please share your thoughts.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-receive-side-scaling2

Thanks,
Sameeh

Sameeh Jubran (1):
content: net: Add VIRTIO_NET_F_CTRL_RSS feature

 content.tex | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
Signature · 6 lines
2.13.6


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#1 lore raw

RFC 1/1 content: net: Add VIRTIO_NET_F_CTRL_RSS feature

From: Sameeh Jubran <[email protected]>

Most modern high end network devices today support configurable hash functions, this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance by efficiently distributing the traffic among the CPUs in a multiprocessor system.

This feature is supported in most of the modern network cards as well as most modern OSes including Linux and Windows. It is worth mentioning that both DPDK and Hyper-v support RSS too.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-receive-side-scaling2

---
 content.tex | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
content.tex +133 -0
index c840588..5969b28 100644
@@ -3115,6 +3115,9 @@ features.
 
 \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address through control
     channel.
+
+\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable RSS hash
+    functions.
 \end{description}
 
 \subsubsection{Feature bit requirements}\label{sec:Device Types / Network Device / Feature bits / Feature bit requirements}
@@ -3138,6 +3141,8 @@ Some networking feature bits require other networking feature bits
 \item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires VIRTIO_NET_F_CTRL_VQ.
 \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ.
 \item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires VIRTIO_NET_F_CTRL_VQ.
+
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ.
 \end{description}
 
 \subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types / Network Device / Feature bits / Legacy Interface: Feature bits}
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
         u8 flags;
 #define VIRTIO_NET_HDR_GSO_NONE        0
 #define VIRTIO_NET_HDR_GSO_TCPV4       1
+#define VIRTIO_NET_HDR_GSO_RSS         2
 #define VIRTIO_NET_HDR_GSO_UDP         3
 #define VIRTIO_NET_HDR_GSO_TCPV6       4
 #define VIRTIO_NET_HDR_GSO_ECN      0x80
@@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
         le16 csum_start;
         le16 csum_offset;
         le16 num_buffers;
+// Only if RSS hash offload has been negotiated
+        le64 rss_hash_value;
 };
 \end{lstlisting}
 
@@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command.
 The device MUST NOT queue packets on receive queues greater than
 \field{virtqueue_pairs} once it has placed the VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring.
 
+\paragraph{RSS hash offload}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+\begin{lstlisting}
+#define RSS_HASH_FUNCTION_NONE      1
+#define RSS_HASH_FUNCTION_TOEPLITZ  2
+#define RSS_HASH_FUNCTION_SYMMETRIC 3
+
+// Hash function fields
+#define RSS_HASH_FIELDS_IPV4          0x00000100
+#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
+#define RSS_HASH_FIELDS_IPV6          0x00000400
+#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
+#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
+#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
+
+struct virtio_net_ctrl_rss_hash{
+le32 hash_function;
+}
+
+struct virtio_net_rss {
+le32 hash_function;
+le32 hash_function_flags;
+le32 hash_key_length;
+le32 indirection_table_length;
+	struct {
+		le32 hash_key[hash_key_length];
+		le32 indirection_table[indirection_table_length];
+	}
+};
+
+#define VIRTIO_NET_F_CTRL_RSS     24
+
+#define VIRTIO_NET_CTRL_RSS                           6
+#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS   0
+#define VIRTIO_NET_CTRL_RSS_DISABLE                   1
+#define VIRTIO_NET_CTRL_RSS_SET                       2
+\end{lstlisting}
+
+If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can send control
+commands for the RSS configuration.
+
+The class VIRTIO_NET_CTRL_RSS has three commands:
+
+\begin{enumerate}
+\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the hash functions
+	supported by the device to the driver.
+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing is no
+	longer required.
+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The command is
+	used by the driver for setting RSS hash function, hash key and
+	indirection table in the device.
+\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the hash
+functions it supports and return the structure to the driver. Zero or more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the \field{hash_function}
+field.
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop calculating and
+attaching hashes for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS
+in the \field{gso_type} field, however the \field{hash_function} field is kept
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings provided as
+follows, once the configuration process is completed the device SHOULD apply
+the hash function to each of the incoming packets and distribute the packets
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.
+
+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the control
+	queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each packet
+	recieved the device MUST calculate the hashing for the packet and
+	store it in the virtio-net header in rss_hash_value and the hash
+	fields used in the calculation in rss_hash_type.
+\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field.
+
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used and fill
+	it in the \field{hash_function} field along with the approperiate flags
+	in the \field{hash_function_flags} field. These flags inidicate to the
+	device which packet fields MUST be used in the calculation process of
+	the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+	in the \field{hash_key} field, the length of the key should be stored
+	in the \field{hash_key_length} field.
+\item Lastly the driver should fill the indirection table array in the
+	\field{indirection_table} field while setting the array length in
+	\field{indirection_table_length}. This structure is used by the device
+	for determining in which RX virt queue the packet should be placed.
+\end{itemize}
+Once the configuration phase is over successfully, the packets SHOULD have the
+\field{rss_hash_value} field with the hash value that was calculated by the
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can send an
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has
+RSS_HASH_FUNCTION_NONE the \field{hash_function} field.
+
+The driver MUST check the \field{ack} field value provided by the device, in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and
+retry another hash function or else give up.
+
 \subparagraph{Legacy Interface: Automatic receive steering in multiqueue mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy Interface: Automatic receive steering in multiqueue mode}
 When using the legacy interface, transitional devices and drivers
 MUST format \field{virtqueue_pairs}
Signature · 6 lines
2.13.6


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
#2 lore raw

[virtio-dev] Re: [RFC virtio-net 1/1] content: net: Add VIRTIO_NET_F_CTRL_RSS feature

Please ignore the typos, I mistakenly sent the patch without the fixes. I'll resend the fixes along with v2.

Quoted 238 lines · Sameeh Jubran

From: Sameeh Jubran <[email protected]>

Most modern high end network devices today support configurable hash functions,
this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance
by efficiently distributing the traffic among the CPUs in a multiprocessor system.

This feature is supported in most of the modern network cards as well as most
modern OSes including Linux and Windows. It is worth mentioning that both DPDK
and Hyper-v support RSS too.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/
network/ndis-receive-side-scaling2

---
 content.tex | 133 ++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
content.tex +3 -0
index c840588..5969b28 100644
@@ -3115,6 +3115,9 @@ features.
 
 \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address through control
     channel.
+
+\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable RSS hash
+    functions.
 \end{description}
 
 \subsubsection{Feature bit requirements}\label{sec:Device Types / Network

Device / Feature bits / Feature bit requirements}

content.tex +0 -0
@@ -3138,6 +3141,8 @@ Some networking feature bits require other

networking feature bits
\item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires VIRTIO_NET_F_CTRL_VQ. \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ. \item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires VIRTIO_NET_F_CTRL_VQ.
+
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ.
\end{description}

\subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types /
Network Device / Feature bits / Legacy Interface: Feature bits}

content.tex +3 -0
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
         u8 flags;
 #define VIRTIO_NET_HDR_GSO_NONE        0
 #define VIRTIO_NET_HDR_GSO_TCPV4       1
+#define VIRTIO_NET_HDR_GSO_RSS         2
 #define VIRTIO_NET_HDR_GSO_UDP         3
 #define VIRTIO_NET_HDR_GSO_TCPV6       4
 #define VIRTIO_NET_HDR_GSO_ECN      0x80
@@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
         le16 csum_start;
         le16 csum_offset;
         le16 num_buffers;
+// Only if RSS hash offload has been negotiated
+        le64 rss_hash_value;
 };
 \end{lstlisting}
 
@@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command.
 The device MUST NOT queue packets on receive queues greater than
 \field{virtqueue_pairs} once it has placed the

VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring.

+\paragraph{RSS hash offload}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +44 -0
+
+\begin{lstlisting}
+#define RSS_HASH_FUNCTION_NONE      1
+#define RSS_HASH_FUNCTION_TOEPLITZ  2
+#define RSS_HASH_FUNCTION_SYMMETRIC 3
+
+// Hash function fields
+#define RSS_HASH_FIELDS_IPV4          0x00000100
+#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
+#define RSS_HASH_FIELDS_IPV6          0x00000400
+#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
+#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
+#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
+
+struct virtio_net_ctrl_rss_hash{
+le32 hash_function;
+}
+
+struct virtio_net_rss {
+le32 hash_function;
+le32 hash_function_flags;
+le32 hash_key_length;
+le32 indirection_table_length;
+       struct {
+               le32 hash_key[hash_key_length];
+               le32 indirection_table[indirection_table_length];
+       }
+};
+
+#define VIRTIO_NET_F_CTRL_RSS     24
+
+#define VIRTIO_NET_CTRL_RSS                           6
+#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS   0
+#define VIRTIO_NET_CTRL_RSS_DISABLE                   1
+#define VIRTIO_NET_CTRL_RSS_SET                       2
+\end{lstlisting}
+
+If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can send control
+commands for the RSS configuration.
+
+The class VIRTIO_NET_CTRL_RSS has three commands:
+
+\begin{enumerate}
+\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the hash

functions
+ supported by the device to the driver.
+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing is no
+ longer required.
+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The command is

content.tex +8 -0
+       used by the driver for setting RSS hash function, hash key and
+       indirection table in the device.
+\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types / Network

Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +4 -0
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the hash
+functions it supports and return the structure to the driver. Zero or more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the

\field{hash_function}

content.tex +3 -0
+field.
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop calculating

and
+attaching hashes for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS
+in the \field{gso_type} field, however the \field{hash_function} field is kept

content.tex +6 -0
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings

provided as
+follows, once the configuration process is completed the device SHOULD apply
+the hash function to each of the incoming packets and distribute the packets

content.tex +6 -0
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.
+
+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the

control

content.tex +14 -0
+       queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each packet
+       recieved the device MUST calculate the hashing for the packet and
+       store it in the virtio-net header in rss_hash_value and the hash
+       fields used in the calculation in rss_hash_type.
+\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field.
+
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types / Network

Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +2 -0
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver

SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure

content.tex +4 -0
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used and

fill
+ it in the \field{hash_function} field along with the approperiate
flags
+ in the \field{hash_function_flags} field. These flags inidicate to
the
+ device which packet fields MUST be used in the calculation process
of
+ the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+ in the \field{hash_key} field, the length of the key should be
stored

content.tex +4 -0
+       in the \field{hash_key_length} field.
+\item Lastly the driver should fill the indirection table array in the
+       \field{indirection_table} field while setting the array length in
+       \field{indirection_table_length}. This structure is used by the

device

content.tex +3 -0
+       for determining in which RX virt queue the packet should be placed.
+\end{itemize}
+Once the configuration phase is over successfully, the packets SHOULD

have the
+\field{rss_hash_value} field with the hash value that was calculated by the

content.tex +3 -0
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can

send an

content.tex +4 -0
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has
+RSS_HASH_FUNCTION_NONE the \field{hash_function} field.
+
+The driver MUST check the \field{ack} field value provided by the device,

in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and

content.tex +2 -0
+retry another hash function or else give up.
+
 \subparagraph{Legacy Interface: Automatic receive steering in multiqueue

mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy
Interface: Automatic receive steering in multiqueue mode}
When using the legacy interface, transitional devices and drivers MUST format \field{virtqueue_pairs}
--
2.13.6

Signature · 4 lines
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*
#3 lore raw

[virtio-dev] Re: [RFC virtio-net 1/1] content: net: Add VIRTIO_NET_F_CTRL_RSS feature

ping

Quoted 254 lines · Sameeh Jubran

Please ignore the typos, I mistakenly sent the patch without the fixes. I'll resend the fixes along with v2.

Quoted 232 lines · Sameeh Jubran

From: Sameeh Jubran <[email protected]>

Most modern high end network devices today support configurable hash functions,
this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance
by efficiently distributing the traffic among the CPUs in a multiprocessor system.

This feature is supported in most of the modern network cards as well as most
modern OSes including Linux and Windows. It is worth mentioning that both DPDK
and Hyper-v support RSS too.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/ne
twork/ndis-receive-side-scaling2

---
 content.tex | 133 ++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
content.tex +3 -0
index c840588..5969b28 100644
@@ -3115,6 +3115,9 @@ features.
 
 \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address through control
     channel.
+
+\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable RSS hash
+    functions.
 \end{description}
 
 \subsubsection{Feature bit requirements}\label{sec:Device Types /

Network Device / Feature bits / Feature bit requirements}

content.tex +0 -0
@@ -3138,6 +3141,8 @@ Some networking feature bits require other

networking feature bits
\item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires VIRTIO_NET_F_CTRL_VQ. \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ. \item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires VIRTIO_NET_F_CTRL_VQ.
+
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ.
\end{description}

\subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types /
Network Device / Feature bits / Legacy Interface: Feature bits}

content.tex +3 -0
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
         u8 flags;
 #define VIRTIO_NET_HDR_GSO_NONE        0
 #define VIRTIO_NET_HDR_GSO_TCPV4       1
+#define VIRTIO_NET_HDR_GSO_RSS         2
 #define VIRTIO_NET_HDR_GSO_UDP         3
 #define VIRTIO_NET_HDR_GSO_TCPV6       4
 #define VIRTIO_NET_HDR_GSO_ECN      0x80
@@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
         le16 csum_start;
         le16 csum_offset;
         le16 num_buffers;
+// Only if RSS hash offload has been negotiated
+        le64 rss_hash_value;
 };
 \end{lstlisting}
 
@@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command.
 The device MUST NOT queue packets on receive queues greater than
 \field{virtqueue_pairs} once it has placed the

VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring.

+\paragraph{RSS hash offload}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +44 -0
+
+\begin{lstlisting}
+#define RSS_HASH_FUNCTION_NONE      1
+#define RSS_HASH_FUNCTION_TOEPLITZ  2
+#define RSS_HASH_FUNCTION_SYMMETRIC 3
+
+// Hash function fields
+#define RSS_HASH_FIELDS_IPV4          0x00000100
+#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
+#define RSS_HASH_FIELDS_IPV6          0x00000400
+#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
+#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
+#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
+
+struct virtio_net_ctrl_rss_hash{
+le32 hash_function;
+}
+
+struct virtio_net_rss {
+le32 hash_function;
+le32 hash_function_flags;
+le32 hash_key_length;
+le32 indirection_table_length;
+       struct {
+               le32 hash_key[hash_key_length];
+               le32 indirection_table[indirection_table_length];
+       }
+};
+
+#define VIRTIO_NET_F_CTRL_RSS     24
+
+#define VIRTIO_NET_CTRL_RSS                           6
+#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS   0
+#define VIRTIO_NET_CTRL_RSS_DISABLE                   1
+#define VIRTIO_NET_CTRL_RSS_SET                       2
+\end{lstlisting}
+
+If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can send control
+commands for the RSS configuration.
+
+The class VIRTIO_NET_CTRL_RSS has three commands:
+
+\begin{enumerate}
+\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the hash

functions
+ supported by the device to the driver.
+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing is no
+ longer required.
+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The command is

content.tex +8 -0
+       used by the driver for setting RSS hash function, hash key and
+       indirection table in the device.
+\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types /

Network Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +3 -0
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the hash
+functions it supports and return the structure to the driver. Zero or

more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the \field{hash_function}

content.tex +3 -0
+field.
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop

calculating and
+attaching hashes for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS
+in the \field{gso_type} field, however the \field{hash_function} field is kept

content.tex +6 -0
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings

provided as
+follows, once the configuration process is completed the device SHOULD apply
+the hash function to each of the incoming packets and distribute the packets

content.tex +6 -0
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.
+
+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the

control

content.tex +5 -0
+       queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each

packet

content.tex +9 -0
+       recieved the device MUST calculate the hashing for the packet and
+       store it in the virtio-net header in rss_hash_value and the hash
+       fields used in the calculation in rss_hash_type.
+\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field.
+
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types /

Network Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +2 -0
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver

SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure

content.tex +4 -0
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used and

fill
+ it in the \field{hash_function} field along with the approperiate
flags
+ in the \field{hash_function_flags} field. These flags inidicate
to the
+ device which packet fields MUST be used in the calculation
process of
+ the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+ in the \field{hash_key} field, the length of the key should be
stored

content.tex +4 -0
+       in the \field{hash_key_length} field.
+\item Lastly the driver should fill the indirection table array in the
+       \field{indirection_table} field while setting the array length in
+       \field{indirection_table_length}. This structure is used by the

device
+ for determining in which RX virt queue the packet should be
placed.
+\end{itemize}
+Once the configuration phase is over successfully, the packets SHOULD have the
+\field{rss_hash_value} field with the hash value that was calculated by the

content.tex +3 -0
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can

send an

content.tex +4 -0
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has
+RSS_HASH_FUNCTION_NONE the \field{hash_function} field.
+
+The driver MUST check the \field{ack} field value provided by the

device, in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and

content.tex +2 -0
+retry another hash function or else give up.
+
 \subparagraph{Legacy Interface: Automatic receive steering in multiqueue
Quoted 9 lines

mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy
Interface: Automatic receive steering in multiqueue mode}
When using the legacy interface, transitional devices and drivers MUST format \field{virtqueue_pairs}
--
2.13.6

--
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*

Signature · 4 lines
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*
#4 lore raw

Re: [virtio-dev] [RFC virtio-net 1/1] content: net: Add VIRTIO_NET_F_CTRL_RSS feature

In reply to Sameeh Jubran
Quoted 35 lines · Sameeh Jubran

From: Sameeh Jubran <[email protected]>

Most modern high end network devices today support configurable hash functions, this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance by efficiently distributing the traffic among the CPUs in a multiprocessor system.

This feature is supported in most of the modern network cards as well as most modern OSes including Linux and Windows. It is worth mentioning that both DPDK and Hyper-v support RSS too.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-receive-side-scaling2

---
  content.tex | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 133 insertions(+)
content.tex +3 -0
index c840588..5969b28 100644
@@ -3115,6 +3115,9 @@ features.
 
  \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address through control
      channel.
+
+\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable RSS hash
+    functions.
  \end{description}
 
  \subsubsection{Feature bit requirements}\label{sec:Device Types / Network Device / Feature bits / Feature bit requirements}

content.tex Some networking feature bits require other networking feature bits · line 3146

Quoted 6 lines
content.tex +2 -0
@@ -3138,6 +3141,8 @@ Some networking feature bits require other networking feature bits
  \item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires VIRTIO_NET_F_CTRL_VQ.
  \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ.
  \item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires VIRTIO_NET_F_CTRL_VQ.
+
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ.
  \end{description}

Is this a requirement of RSSv2? Looks like at least RSS can work without multiqueue in V1.

content.tex struct virtio_net_hdr { · line 3316

Quoted 7 lines
content.tex +1 -0
  \subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types / Network Device / Feature bits / Legacy Interface: Feature bits}
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
          u8 flags;
  #define VIRTIO_NET_HDR_GSO_NONE        0
  #define VIRTIO_NET_HDR_GSO_TCPV4       1
+#define VIRTIO_NET_HDR_GSO_RSS         2

What's the reason of introducing a new GSO type here? RSS should be independent for a specific offloading type I think.

content.tex struct virtio_net_hdr { · line 3327

Quoted 9 lines
content.tex +2 -0
  #define VIRTIO_NET_HDR_GSO_UDP         3
  #define VIRTIO_NET_HDR_GSO_TCPV6       4
  #define VIRTIO_NET_HDR_GSO_ECN      0x80
@@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
          le16 csum_start;
          le16 csum_offset;
          le16 num_buffers;
+// Only if RSS hash offload has been negotiated
+        le64 rss_hash_value;

Not a native English speaker, but "rss_hash" should be sufficient.

Quoted 43 lines
content.tex +36 -0
  };
  \end{lstlisting}
 
@@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command.
  The device MUST NOT queue packets on receive queues greater than
  \field{virtqueue_pairs} once it has placed the VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring.
 
+\paragraph{RSS hash offload}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+\begin{lstlisting}
+#define RSS_HASH_FUNCTION_NONE      1
+#define RSS_HASH_FUNCTION_TOEPLITZ  2
+#define RSS_HASH_FUNCTION_SYMMETRIC 3
+
+// Hash function fields
+#define RSS_HASH_FIELDS_IPV4          0x00000100
+#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
+#define RSS_HASH_FIELDS_IPV6          0x00000400
+#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
+#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
+#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
+
+struct virtio_net_ctrl_rss_hash{
+le32 hash_function;
+}
+
+struct virtio_net_rss {
+le32 hash_function;
+le32 hash_function_flags;
+le32 hash_key_length;
+le32 indirection_table_length;
+	struct {
+		le32 hash_key[hash_key_length];
+		le32 indirection_table[indirection_table_length];
+	}
+};
+
+#define VIRTIO_NET_F_CTRL_RSS     24
+
+#define VIRTIO_NET_CTRL_RSS                           6
+#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS   0
+#define VIRTIO_NET_CTRL_RSS_DISABLE                   1
+#define VIRTIO_NET_CTRL_RSS_SET                       2

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4063

Quoted 10 lines
content.tex +10 -0
+\end{lstlisting}
+
+If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can send control
+commands for the RSS configuration.
+
+The class VIRTIO_NET_CTRL_RSS has three commands:
+
+\begin{enumerate}
+\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the hash functions
+	supported by the device to the driver.

Can we just reuse virtio_net_rss in this case, it contains all the informations (e.g hash key or whatever others)?

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4065

Quoted 2 lines
content.tex +2 -0
+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing is no
+	longer required.

So this implies that if MQ is supported, we will go to use automatic steering mode? I was thinking maybe it's better to introduce a generic command to switch between steering mode.

Quoted 7 lines
content.tex +7 -0
+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The command is
+	used by the driver for setting RSS hash function, hash key and
+	indirection table in the device.
+\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command.

Quoted 10 lines
content.tex +10 -0
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the hash
+functions it supports and return the structure to the driver. Zero or more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the \field{hash_function}
+field.
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop calculating and
+attaching hashes

For simplicity, what if just compute the hash in this case? Consider a driver may want to use this hash (e.g Linux driver).

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4093

Quoted 12 lines

for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS

content.tex +11 -0
+in the \field{gso_type} field, however the \field{hash_function} field is kept
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings provided as
+follows, once the configuration process is completed the device SHOULD apply
+the hash function to each of the incoming packets and distribute the packets
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.

We support changing #queues dynamically, so need to clarify the behavior when e.g the destination queues were disabled.

Quoted 26 lines
content.tex +26 -0
+
+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the control
+	queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each packet
+	recieved the device MUST calculate the hashing for the packet and
+	store it in the virtio-net header in rss_hash_value and the hash
+	fields used in the calculation in rss_hash_type.
+\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field.
+
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used and fill
+	it in the \field{hash_function} field along with the approperiate flags

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4129

Quoted 10 lines
content.tex +10 -0
+	in the \field{hash_function_flags} field. These flags inidicate to the
+	device which packet fields MUST be used in the calculation process of
+	the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+	in the \field{hash_key} field, the length of the key should be stored
+	in the \field{hash_key_length} field.
+\item Lastly the driver should fill the indirection table array in the
+	\field{indirection_table} field while setting the array length in
+	\field{indirection_table_length}. This structure is used by the device
+	for determining in which RX virt queue the packet should be placed.

Is the indirection table expected to be changed frequently? If yes, a single entry modification will cause a update of the whole table.

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4137

Quoted 8 lines

+\end{itemize}

content.tex +7 -0
+Once the configuration phase is over successfully, the packets SHOULD have the
+\field{rss_hash_value} field with the hash value that was calculated by the
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can send an
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has
+RSS_HASH_FUNCTION_NONE the \field{hash_function} field.

So this function looks equivalent to VIRTIO_NET_CTRL_RSS_DISABLE?

Thanks

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4145

Quoted 8 lines
content.tex +5 -0
+
+The driver MUST check the \field{ack} field value provided by the device, in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and
+retry another hash function or else give up.
+
  \subparagraph{Legacy Interface: Automatic receive steering in multiqueue mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy Interface: Automatic receive steering in multiqueue mode}
  When using the legacy interface, transitional devices and drivers
  MUST format \field{virtqueue_pairs}

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#5 lore raw

Re: [virtio-dev] [RFC virtio-net 1/1] content: net: Add VIRTIO_NET_F_CTRL_RSS feature

Quoted 48 lines · Jason Wang
Quoted 44 lines · Sameeh Jubran

From: Sameeh Jubran <[email protected]>

Most modern high end network devices today support configurable hash functions,
this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance
by efficiently distributing the traffic among the CPUs in a multiprocessor system.

This feature is supported in most of the modern network cards as well as most
modern OSes including Linux and Windows. It is worth mentioning that both DPDK
and Hyper-v support RSS too.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/ne
twork/ndis-receive-side-scaling2

---
  content.tex | 133 ++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
  1 file changed, 133 insertions(+)
content.tex +3 -0
index c840588..5969b28 100644
@@ -3115,6 +3115,9 @@ features.
    \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address through control
      channel.
+
+\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable RSS hash
+    functions.
  \end{description}
    \subsubsection{Feature bit requirements}\label{sec:Device Types /
 Network Device / Feature bits / Feature bit requirements}
@@ -3138,6 +3141,8 @@ Some networking feature bits require other

networking feature bits
\item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires VIRTIO_NET_F_CTRL_VQ. \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ.

Quoted 8 lines
Quoted 5 lines

\item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires VIRTIO_NET_F_CTRL_VQ.
+
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ.
\end{description}

Is this a requirement of RSSv2? Looks like at least RSS can work without multiqueue in V1.

You are right this is not a requirement and should be dropped. More on RSS with single hardware queue:
https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-with-a-single-hardware-receive-queue
<https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-with-a-single-hardware-receive-queue>

Quoted 13 lines

\subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types

content.tex struct virtio_net_hdr { · line 3317

Quoted 7 lines

/ Network Device / Feature bits / Legacy Interface: Feature bits}

content.tex +1 -0
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
          u8 flags;
  #define VIRTIO_NET_HDR_GSO_NONE        0
  #define VIRTIO_NET_HDR_GSO_TCPV4       1
+#define VIRTIO_NET_HDR_GSO_RSS         2
 

What's the reason of introducing a new GSO type here? RSS should be independent for a specific offloading type I think.

This was the straight forward option as there is no need to extend the virtio header but it can be moved to a specific offload.

Quoted 14 lines

#define VIRTIO_NET_HDR_GSO_UDP 3

content.tex struct virtio_net_hdr { · line 3328

Quoted 9 lines
content.tex +2 -0
  #define VIRTIO_NET_HDR_GSO_TCPV6       4
  #define VIRTIO_NET_HDR_GSO_ECN      0x80
@@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
          le16 csum_start;
          le16 csum_offset;
          le16 num_buffers;
+// Only if RSS hash offload has been negotiated
+        le64 rss_hash_value;
 

Not a native English speaker, but "rss_hash" should be sufficient.

will do

Quoted 52 lines

};

Quoted 49 lines
content.tex +0 -0
  \end{lstlisting}
  @@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command.

The device MUST NOT queue packets on receive queues greater than \field{virtqueue_pairs} once it has placed the
VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring.
+\paragraph{RSS hash offload}\label{sec:Device Types / Network Device /
Device Operation / Control Virtqueue / RSS hash offload}

content.tex +42 -0
+
+\begin{lstlisting}
+#define RSS_HASH_FUNCTION_NONE      1
+#define RSS_HASH_FUNCTION_TOEPLITZ  2
+#define RSS_HASH_FUNCTION_SYMMETRIC 3
+
+// Hash function fields
+#define RSS_HASH_FIELDS_IPV4          0x00000100
+#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
+#define RSS_HASH_FIELDS_IPV6          0x00000400
+#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
+#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
+#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
+
+struct virtio_net_ctrl_rss_hash{
+le32 hash_function;
+}
+
+struct virtio_net_rss {
+le32 hash_function;
+le32 hash_function_flags;
+le32 hash_key_length;
+le32 indirection_table_length;
+       struct {
+               le32 hash_key[hash_key_length];
+               le32 indirection_table[indirection_table_length];
+       }
+};
+
+#define VIRTIO_NET_F_CTRL_RSS     24
+
+#define VIRTIO_NET_CTRL_RSS                           6
+#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS   0
+#define VIRTIO_NET_CTRL_RSS_DISABLE                   1
+#define VIRTIO_NET_CTRL_RSS_SET                       2
+\end{lstlisting}
+
+If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can send control
+commands for the RSS configuration.
+
+The class VIRTIO_NET_CTRL_RSS has three commands:
+
Quoted 8 lines
Quoted 5 lines

+\begin{enumerate}
+\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the hash functions
+ supported by the device to the driver.

Can we just reuse virtio_net_rss in this case, it contains all the informations (e.g hash key or whatever others)?

Sure this can work

Quoted 10 lines

+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing

Quoted 3 lines

is no
+ longer required.

So this implies that if MQ is supported, we will go to use automatic steering mode? I was thinking maybe it's better to introduce a generic command to switch between steering mode.

So you are suggesting that we should have an additional generic command
that changes between steering modes and RSS is one of those modes?

Quoted 20 lines

+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The

Quoted 17 lines

command is

content.tex +8 -0
+       used by the driver for setting RSS hash function, hash key and
+       indirection table in the device.
+\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types /

Network Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +3 -0
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the hash
+functions it supports and return the structure to the driver. Zero or

more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the \field{hash_function}
+field.

Quoted 8 lines
Quoted 5 lines
content.tex +2 -0
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop

calculating and
+attaching hashes

For simplicity, what if just compute the hash in this case? Consider a driver may want to use this hash (e.g Linux driver).

I get the use case but maybe introduce a new command for computing hashes only? I think the disable should be preserved for disabling only.

Quoted 14 lines

for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS

Quoted 11 lines

+in the \field{gso_type} field, however the \field{hash_function} field is kept

content.tex +6 -0
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings

provided as
+follows, once the configuration process is completed the device SHOULD apply

Quoted 8 lines

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4093

Quoted 5 lines

+the hash function to each of the incoming packets and distribute the packets

content.tex +2 -0
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.

We support changing #queues dynamically, so need to clarify the behavior when e.g the destination queues were disabled.

I will go into these details in the next version.

Quoted 47 lines

+

Quoted 44 lines

+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the control

content.tex +5 -0
+       queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each

packet

content.tex +9 -0
+       recieved the device MUST calculate the hashing for the packet and
+       store it in the virtio-net header in rss_hash_value and the hash
+       fields used in the calculation in rss_hash_type.
+\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field.
+
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types /

Network Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +2 -0
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver

SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure

content.tex +4 -0
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used and

fill
+ it in the \field{hash_function} field along with the approperiate
flags
+ in the \field{hash_function_flags} field. These flags inidicate
to the
+ device which packet fields MUST be used in the calculation
process of
+ the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+ in the \field{hash_key} field, the length of the key should be
stored

content.tex +3 -0
+       in the \field{hash_key_length} field.
+\item Lastly the driver should fill the indirection table array in the
+       \field{indirection_table} field while setting the array length in
Quoted 8 lines
Quoted 5 lines

+ \field{indirection_table_length}. This structure is used by the
device
+ for determining in which RX virt queue the packet should be
placed.

Is the indirection table expected to be changed frequently? If yes, a single entry modification will cause a update of the whole table.

No, it should not be changing frequently

Quoted 17 lines

+\end{itemize}

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4137

Quoted 11 lines

+Once the configuration phase is over successfully, the packets SHOULD have the
+\field{rss_hash_value} field with the hash value that was calculated by the

content.tex +3 -0
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can

send an

content.tex +2 -0
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has
+RSS_HASH_FUNCTION_NONE the \field{hash_function} field.

So this function looks equivalent to VIRTIO_NET_CTRL_RSS_DISABLE?

Yes, do you think we should discard one of the two?

Quoted 20 lines

Thanks

+

Quoted 13 lines

+The driver MUST check the \field{ack} field value provided by the device, in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and

content.tex +2 -0
+retry another hash function or else give up.
+
  \subparagraph{Legacy Interface: Automatic receive steering in

multiqueue mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy Interface: Automatic receive steering in multiqueue mode}
When using the legacy interface, transitional devices and drivers MUST format \field{virtqueue_pairs}

Signature · 4 lines
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*
#6 lore raw

Re: [virtio-dev] [RFC virtio-net 1/1] content: net: Add VIRTIO_NET_F_CTRL_RSS feature

Quoted 65 lines · Sameeh Jubran

On Thu, Mar 15, 2018 at 4:19 AM, Jason Wang <[email protected] <mailto:[email protected]>> wrote:

On 2018年01月26日 00:27, Sameeh Jubran wrote:

From: Sameeh Jubran <[email protected]
<mailto:[email protected]>>

Most modern high end network devices today support configurable hash functions,
this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance
by efficiently distributing the traffic among the CPUs in a multiprocessor
system.

This feature is supported in most of the modern network cards as well as most
modern OSes including Linux and Windows. It is worth mentioning that both DPDK
and Hyper-v support RSS too.

[1]
https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-receive-side-scaling2
<https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-receive-side-scaling2>

<mailto:[email protected]>>
---
  content.tex | 133
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 133 insertions(+)

diff --git a/content.tex b/content.tex
index c840588..5969b28 100644
--- a/content.tex
+++ b/content.tex
@@ -3115,6 +3115,9 @@ features. \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address through control
      channel.
+
+\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable RSS hash
+    functions.
  \end{description}
    \subsubsection{Feature bit requirements}\label{sec:Device Types / Network Device / Feature bits / Feature bit requirements} @@ -3138,6 +3141,8 @@ Some networking feature bits require other networking feature bits \item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires VIRTIO_NET_F_CTRL_VQ.
  \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ. \item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires VIRTIO_NET_F_CTRL_VQ. +
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ. \end{description}

Quoted 5 lines

Is this a requirement of RSSv2? Looks like at least RSS can work without multiqueue in V1.

You are right this is not a requirement and should be dropped. More on RSS with single hardware queue:
 https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-with-a-single-hardware-receive-queue <https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-with-a-single-hardware-receive-queue>

Do we still expect efficiency (distribution of traffic among CPUs) in case of single queue by having RSS (in host software)?

Quoted 20 lines

    \subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types / Network Device / Feature bits / Legacy Interface: Feature bits}
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
          u8 flags;
  #define VIRTIO_NET_HDR_GSO_NONE        0
  #define VIRTIO_NET_HDR_GSO_TCPV4       1
+#define VIRTIO_NET_HDR_GSO_RSS         2

What's the reason of introducing a new GSO type here? RSS should be independent for a specific offloading type I think.

This was the straight forward option as there is no need to extend the virtio header but it can be moved to a specific offload.

Quoted 10 lines
          #define VIRTIO_NET_HDR_GSO_UDP         3
          #define VIRTIO_NET_HDR_GSO_TCPV6       4
          #define VIRTIO_NET_HDR_GSO_ECN      0x80
        @@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
                  le16 csum_start;
                  le16 csum_offset;
                  le16 num_buffers;
        +// Only if RSS hash offload has been negotiated
        +        le64 rss_hash_value;

I asked Sameeh privately and asking here again.   Is compatibility maintained if we introduce a new field to virtio_net_hdr?

Quoted 8 lines

Not a native English speaker, but "rss_hash" should be sufficient.

will do

Quoted 15 lines

  };
  \end{lstlisting}
  @@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. The device MUST NOT queue packets on receive queues greater than \field{virtqueue_pairs} once it has placed the VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring. +\paragraph{RSS hash offload}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+\begin{lstlisting}
+#define RSS_HASH_FUNCTION_NONE      1
+#define RSS_HASH_FUNCTION_TOEPLITZ  2
+#define RSS_HASH_FUNCTION_SYMMETRIC 3

Should above be bit field?  I mean first two are fine, should ..SYMMETRIC should be 4 (0x4)    Otherwise description "Zero or more flags of the RSS_HASH_FUNCTION flags MUST be used to fill the field hash_function" below wouldn't be correct.

Quoted 15 lines
        +
        +// Hash function fields
        +#define RSS_HASH_FIELDS_IPV4          0x00000100
        +#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
        +#define RSS_HASH_FIELDS_IPV6          0x00000400
        +#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
        +#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
        +#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
        +
        +struct virtio_net_ctrl_rss_hash{
        +le32 hash_function;
        +}
        +
        +struct virtio_net_rss {
        +le32 hash_function;
Quoted 9 lines
        +le32 hash_function_flags;
        +le32 hash_key_length;
        +le32 indirection_table_length;
        +       struct {
        +               le32 hash_key[hash_key_length];
        +               le32 indirection_table[indirection_table_length];
        +       }
        +};

I'm new here, hence my question: Is array size typically described like above in virtio spec?  And with #define constant in implementation?

Thanks,
Vijay

Quoted 216 lines

+
+#define VIRTIO_NET_F_CTRL_RSS     24
+
+#define VIRTIO_NET_CTRL_RSS    6
+#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS  0 +#define VIRTIO_NET_CTRL_RSS_DISABLE    1
+#define VIRTIO_NET_CTRL_RSS_SET    2 +\end{lstlisting}
+
+If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can send control
+commands for the RSS configuration.
+
+The class VIRTIO_NET_CTRL_RSS has three commands:
+
+\begin{enumerate}
+\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the hash functions
+       supported by the device to the driver.

Can we just reuse virtio_net_rss in this case, it contains all the informations (e.g hash key or whatever others)?

Sure this can work

+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing is no
+       longer required.

So this implies that if MQ is supported, we will go to use automatic steering mode? I was thinking maybe it's better to introduce a generic command to switch between steering mode.

 So you are suggesting that we should have an additional generic command that changes between steering modes and RSS is one of those modes?

+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The command is
+       used by the driver for setting RSS hash function, hash key and
+       indirection table in the device. +\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the hash
+functions it supports and return the structure to the driver. Zero or more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the \field{hash_function}
+field.
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop calculating and
+attaching hashes

For simplicity, what if just compute the hash in this case? Consider a driver may want to use this hash (e.g Linux driver).

I get the use case but maybe introduce a new command for computing hashes only? I think the disable should be preserved for disabling only.

for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS +in the \field{gso_type} field, however the \field{hash_function} field is kept
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings provided as
+follows, once the configuration process is completed the device SHOULD apply
+the hash function to each of the incoming packets and distribute the packets
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.

We support changing #queues dynamically, so need to clarify the behavior when e.g the destination queues were disabled.

I will go into these details in the next version.

+
+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the control
+       queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each packet
+       recieved the device MUST calculate the hashing for the packet and
+       store it in the virtio-net header in rss_hash_value and the hash
+       fields used in the calculation in rss_hash_type. +\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field. +
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used and fill
+       it in the \field{hash_function} field along with the approperiate flags
+       in the \field{hash_function_flags} field. These flags inidicate to the
+       device which packet fields MUST be used in the calculation process of
+       the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+       in the \field{hash_key} field, the length of the key should be stored
+       in the \field{hash_key_length} field. +\item Lastly the driver should fill the indirection table array in the
+       \field{indirection_table} field while setting the array length in
+       \field{indirection_table_length}. This structure is used by the device
+       for determining in which RX virt queue the packet should be placed.

Is the indirection table expected to be changed frequently? If yes, a single entry modification will cause a update of the whole table.

No, it should not be changing frequently

+\end{itemize}
+Once the configuration phase is over successfully, the packets SHOULD have the
+\field{rss_hash_value} field with the hash value that was calculated by the
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can send an
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has +RSS_HASH_FUNCTION_NONE the \field{hash_function} field.

So this function looks equivalent to VIRTIO_NET_CTRL_RSS_DISABLE?

Yes, do you think we should discard one of the two?

Thanks

+
+The driver MUST check the \field{ack} field value provided by the device, in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and
+retry another hash function or else give up.
+
  \subparagraph{Legacy Interface: Automatic receive steering in multiqueue mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy Interface: Automatic receive steering in multiqueue mode}
  When using the legacy interface, transitional devices and drivers
  MUST format \field{virtqueue_pairs}

Signature · 4 lines
Respectfully,
*/Sameeh Jubran/*
/Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>/
/Software Engineer @ Daynix <http://www.daynix.com>./
#8 lore raw

Re: [virtio-dev] [RFC virtio-net 1/1] content: net: Add VIRTIO_NET_F_CTRL_RSS feature

In reply to Sameeh Jubran
Quoted 83 lines · Sameeh Jubran

On Thu, Mar 15, 2018 at 4:19 AM, Jason Wang <[email protected] <mailto:[email protected]>> wrote:

On 2018年01月26日 00:27, Sameeh Jubran wrote:

From: Sameeh Jubran <[email protected]
<mailto:[email protected]>>

Most modern high end network devices today support configurable hash functions,
this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance
by efficiently distributing the traffic among the CPUs in a multiprocessor
system.

This feature is supported in most of the modern network cards as well as most
modern OSes including Linux and Windows. It is worth mentioning that both DPDK
and Hyper-v support RSS too.

[1]
https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-receive-side-scaling2
<https://docs.microsoft.com/en-us/windows-hardware/drivers/network/ndis-receive-side-scaling2>

<mailto:[email protected]>>
---
  content.tex | 133
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 133 insertions(+)

diff --git a/content.tex b/content.tex
index c840588..5969b28 100644
--- a/content.tex
+++ b/content.tex
@@ -3115,6 +3115,9 @@ features. \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address through control
      channel.
+
+\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable RSS hash
+    functions.
  \end{description}
    \subsubsection{Feature bit requirements}\label{sec:Device Types / Network Device / Feature bits / Feature bit requirements} @@ -3138,6 +3141,8 @@ Some networking feature bits require other networking feature bits \item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires VIRTIO_NET_F_CTRL_VQ.
  \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ. \item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires VIRTIO_NET_F_CTRL_VQ. +
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ. \end{description}

Is this a requirement of RSSv2? Looks like at least RSS can work without multiqueue in V1.

You are right this is not a requirement and should be dropped. More on RSS with single hardware queue:
 https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-with-a-single-hardware-receive-queue <https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-with-a-single-hardware-receive-queue>

    \subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types / Network Device / Feature bits / Legacy Interface: Feature bits}
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
          u8 flags;
  #define VIRTIO_NET_HDR_GSO_NONE        0
  #define VIRTIO_NET_HDR_GSO_TCPV4       1
+#define VIRTIO_NET_HDR_GSO_RSS         2

Quoted 4 lines

What's the reason of introducing a new GSO type here? RSS should be independent for a specific offloading type I think.

This was the straight forward option as there is no need to extend the virtio header but it can be moved to a specific offload.

If I understand correctly, RSS is not tied to GSO, so you mean VIRTIO_NET_HDR_RSS here?

Quoted 89 lines

          #define VIRTIO_NET_HDR_GSO_UDP         3
          #define VIRTIO_NET_HDR_GSO_TCPV6       4
          #define VIRTIO_NET_HDR_GSO_ECN      0x80
        @@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
                  le16 csum_start;
                  le16 csum_offset;
                  le16 num_buffers;
        +// Only if RSS hash offload has been negotiated
        +        le64 rss_hash_value;


    Not a native English speaker, but "rss_hash" should be sufficient.

will do

          };
          \end{lstlisting}
          @@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command.
          The device MUST NOT queue packets on receive queues greater than
          \field{virtqueue_pairs} once it has placed the
        VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring.
          +\paragraph{RSS hash offload}\label{sec:Device Types /
        Network Device / Device Operation / Control Virtqueue / RSS
        hash offload}
        +
        +\begin{lstlisting}
        +#define RSS_HASH_FUNCTION_NONE      1
        +#define RSS_HASH_FUNCTION_TOEPLITZ  2
        +#define RSS_HASH_FUNCTION_SYMMETRIC 3
        +
        +// Hash function fields
        +#define RSS_HASH_FIELDS_IPV4          0x00000100
        +#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
        +#define RSS_HASH_FIELDS_IPV6          0x00000400
        +#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
        +#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
        +#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
        +
        +struct virtio_net_ctrl_rss_hash{
        +le32 hash_function;
        +}
        +
        +struct virtio_net_rss {
        +le32 hash_function;
        +le32 hash_function_flags;
        +le32 hash_key_length;
        +le32 indirection_table_length;
        +       struct {
        +               le32 hash_key[hash_key_length];
        +               le32 indirection_table[indirection_table_length];
        +       }
        +};
        +
        +#define VIRTIO_NET_F_CTRL_RSS     24
        +
        +#define VIRTIO_NET_CTRL_RSS    6
        +#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS  0
        +#define VIRTIO_NET_CTRL_RSS_DISABLE    1
        +#define VIRTIO_NET_CTRL_RSS_SET    2
        +\end{lstlisting}
        +
        +If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can
        send control
        +commands for the RSS configuration.
        +
        +The class VIRTIO_NET_CTRL_RSS has three commands:
        +
        +\begin{enumerate}
        +\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the
        hash functions
        +       supported by the device to the driver.


    Can we just reuse virtio_net_rss in this case, it contains all the
    informations (e.g hash key or whatever others)?

Sure this can work

+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing is no
+       longer required.

Quoted 5 lines

So this implies that if MQ is supported, we will go to use automatic steering mode? I was thinking maybe it's better to introduce a generic command to switch between steering mode.

 So you are suggesting that we should have an additional generic command that changes between steering modes and RSS is one of those modes?

Yes.

Quoted 30 lines

+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The command is
+       used by the driver for setting RSS hash function, hash key and
+       indirection table in the device. +\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the hash
+functions it supports and return the structure to the driver. Zero or more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the \field{hash_function}
+field.
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop calculating and
+attaching hashes

Quoted 4 lines

For simplicity, what if just compute the hash in this case? Consider a driver may want to use this hash (e.g Linux driver).

I get the use case but maybe introduce a new command for computing hashes only?

Then it looks unnecessary. (Btw, the above should be "VIRTIO_NET_CTRL_RSS_DISABLE").

Quoted 110 lines

I think the disable should be preserved for disabling only.

for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS +in the \field{gso_type} field, however the \field{hash_function} field is kept
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings provided as
+follows, once the configuration process is completed the device SHOULD apply
+the hash function to each of the incoming packets and distribute the packets
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.

We support changing #queues dynamically, so need to clarify the behavior when e.g the destination queues were disabled.

I will go into these details in the next version.

+
+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the control
+       queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each packet
+       recieved the device MUST calculate the hashing for the packet and
+       store it in the virtio-net header in rss_hash_value and the hash
+       fields used in the calculation in rss_hash_type. +\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field. +
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used and fill
+       it in the \field{hash_function} field along with the approperiate flags
+       in the \field{hash_function_flags} field. These flags inidicate to the
+       device which packet fields MUST be used in the calculation process of
+       the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+       in the \field{hash_key} field, the length of the key should be stored
+       in the \field{hash_key_length} field. +\item Lastly the driver should fill the indirection table array in the
+       \field{indirection_table} field while setting the array length in
+       \field{indirection_table_length}. This structure is used by the device
+       for determining in which RX virt queue the packet should be placed.

Is the indirection table expected to be changed frequently? If yes, a single entry modification will cause a update of the whole table.

No, it should not be changing frequently

+\end{itemize}
+Once the configuration phase is over successfully, the packets SHOULD have the
+\field{rss_hash_value} field with the hash value that was calculated by the
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can send an
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has +RSS_HASH_FUNCTION_NONE the \field{hash_function} field.

Quoted 3 lines

So this function looks equivalent to VIRTIO_NET_CTRL_RSS_DISABLE?

Yes, do you think we should discard one of the two?

Yes.

Thanks

Quoted 4 lines

Thanks

Quoted 25 lines

+
+The driver MUST check the \field{ack} field value provided by the device, in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and
+retry another hash function or else give up.
+
  \subparagraph{Legacy Interface: Automatic receive steering in multiqueue mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy Interface: Automatic receive steering in multiqueue mode}
  When using the legacy interface, transitional devices and drivers
  MUST format \field{virtqueue_pairs}

Signature · 4 lines
Respectfully,
*/Sameeh Jubran/*
/Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>/
/Software Engineer @ Daynix <http://www.daynix.com>./

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

#7 lore raw

Re: [virtio-dev] [RFC virtio-net 1/1] content: net: Add VIRTIO_NET_F_CTRL_RSS feature

In reply to Vijayabhaskar Balakrishna
Quoted 65 lines · Vijayabhaskar Balakrishna

On 3/19/2018 6:33 AM, Sameeh Jubran wrote:

Quoted 50 lines · Jason Wang
Quoted 46 lines · Sameeh Jubran

From: Sameeh Jubran <[email protected]>

Most modern high end network devices today support configurable hash functions,
this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance
by efficiently distributing the traffic among the CPUs in a multiprocessor
system.

This feature is supported in most of the modern network cards as well as most
modern OSes including Linux and Windows. It is worth mentioning that both DPDK
and Hyper-v support RSS too.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/ne
twork/ndis-receive-side-scaling2

---
  content.tex | 133 ++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++
  1 file changed, 133 insertions(+)
content.tex +0 -0
index c840588..5969b28 100644
@@ -3115,6 +3115,9 @@ features.
    \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address through

control
channel.

content.tex +3 -0
+
+\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable RSS hash
+    functions.
  \end{description}
    \subsubsection{Feature bit requirements}\label{sec:Device Types /

Network Device / Feature bits / Feature bit requirements}

content.tex +0 -0
@@ -3138,6 +3141,8 @@ Some networking feature bits require other

networking feature bits
\item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires VIRTIO_NET_F_CTRL_VQ. \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ.

Quoted 8 lines
Quoted 5 lines

\item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires VIRTIO_NET_F_CTRL_VQ.
+
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ.
\end{description}

Is this a requirement of RSSv2? Looks like at least RSS can work without multiqueue in V1.

Quoted 9 lines

You are right this is not a requirement and should be dropped. More on RSS with single hardware queue:
https://docs.microsoft.com/en-us/windows-hardware/drivers/
network/rss-with-a-single-hardware-receive-queue
<https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-with-a-single-hardware-receive-queue>

Do we still expect efficiency (distribution of traffic among CPUs) in case of single queue by having RSS (in host software)?

This depends on the configuration settings for the hash function and
indirection table.

Quoted 31 lines
Quoted 4 lines

\subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types

Quoted 10 lines

content.tex struct virtio_net_hdr { · line 3317

Quoted 7 lines

/ Network Device / Feature bits / Legacy Interface: Feature bits}

content.tex +1 -0
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
          u8 flags;
  #define VIRTIO_NET_HDR_GSO_NONE        0
  #define VIRTIO_NET_HDR_GSO_TCPV4       1
+#define VIRTIO_NET_HDR_GSO_RSS         2
 

What's the reason of introducing a new GSO type here? RSS should be independent for a specific offloading type I think.

This was the straight forward option as there is no need to extend the virtio header but it can be moved to a specific offload.

Quoted 13 lines

#define VIRTIO_NET_HDR_GSO_UDP 3

content.tex struct virtio_net_hdr { · line 3328

Quoted 9 lines
content.tex +2 -0
  #define VIRTIO_NET_HDR_GSO_TCPV6       4
  #define VIRTIO_NET_HDR_GSO_ECN      0x80
@@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
          le16 csum_start;
          le16 csum_offset;
          le16 num_buffers;
+// Only if RSS hash offload has been negotiated
+        le64 rss_hash_value;
 

I asked Sameeh privately and asking here again. Is compatibility

Quoted 2 lines

maintained if we introduce a new field to virtio_net_hdr?

I believe so, only if the RSS feature has been acked then this header is used which should preserve compatibility

Quoted 22 lines
Quoted 2 lines

Not a native English speaker, but "rss_hash" should be sufficient.

will do

Quoted 17 lines

};

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4023

Quoted 13 lines
content.tex +0 -0
  \end{lstlisting}
  @@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command.

The device MUST NOT queue packets on receive queues greater than \field{virtqueue_pairs} once it has placed the
VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring.
+\paragraph{RSS hash offload}\label{sec:Device Types / Network Device
/ Device Operation / Control Virtqueue / RSS hash offload}

content.tex +5 -0
+
+\begin{lstlisting}
+#define RSS_HASH_FUNCTION_NONE      1
+#define RSS_HASH_FUNCTION_TOEPLITZ  2
+#define RSS_HASH_FUNCTION_SYMMETRIC 3

Should above be bit field? I mean first two are fine, should ..SYMMETRIC

Quoted 4 lines

should be 4 (0x4) Otherwise description "Zero or more flags of the
RSS_HASH_FUNCTION flags MUST be used to fill the field hash_function" below wouldn't be correct.

Each function is a distinct function, there is no sense for setting two or more functions in the field. Indeed the description is not accurate and I'll be addressing this in v2, thanks for catching this :)

Quoted 27 lines

+

Quoted 16 lines
Quoted 16 lines
content.tex +16 -0
+// Hash function fields
+#define RSS_HASH_FIELDS_IPV4          0x00000100
+#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
+#define RSS_HASH_FIELDS_IPV6          0x00000400
+#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
+#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
+#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
+
+struct virtio_net_ctrl_rss_hash{
+le32 hash_function;
+}
+
+struct virtio_net_rss {
+le32 hash_function;
+le32 hash_function_flags;
+le32 hash_key_length;
Quoted 8 lines

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4046

Quoted 7 lines
content.tex +6 -0
+le32 indirection_table_length;
+       struct {
+               le32 hash_key[hash_key_length];
+               le32 indirection_table[indirection_table_length];
+       }
+};

I'm new here, hence my question: Is array size typically described like

Quoted 2 lines

above in virtio spec? And with #define constant in implementation?

Yes, take a look here for example:
https://github.com/oasis-tcs/virtio-spec/blob/master/content.tex#L4778
<https://github.com/oasis-tcs/virtio-spec/blob/master/content.tex#L4778>
https://github.com/oasis-tcs/virtio-spec/blob/master/content.tex#L2716

Quoted 209 lines

Thanks,
Vijay

+

Quoted 13 lines
Quoted 13 lines
content.tex +13 -0
+#define VIRTIO_NET_F_CTRL_RSS     24
+
+#define VIRTIO_NET_CTRL_RSS                           6
+#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS   0
+#define VIRTIO_NET_CTRL_RSS_DISABLE                   1
+#define VIRTIO_NET_CTRL_RSS_SET                       2
+\end{lstlisting}
+
+If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can send control
+commands for the RSS configuration.
+
+The class VIRTIO_NET_CTRL_RSS has three commands:
+
Quoted 8 lines
Quoted 5 lines

+\begin{enumerate}
+\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the hash functions
+ supported by the device to the driver.

Can we just reuse virtio_net_rss in this case, it contains all the informations (e.g hash key or whatever others)?

Sure this can work

Quoted 10 lines

+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing

Quoted 3 lines

is no
+ longer required.

So this implies that if MQ is supported, we will go to use automatic steering mode? I was thinking maybe it's better to introduce a generic command to switch between steering mode.

So you are suggesting that we should have an additional generic command
that changes between steering modes and RSS is one of those modes?

Quoted 21 lines

+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The

Quoted 18 lines

command is

content.tex +8 -0
+       used by the driver for setting RSS hash function, hash key and
+       indirection table in the device.
+\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types /

Network Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +2 -0
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the

hash
+functions it supports and return the structure to the driver. Zero or more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the \field{hash_function}
+field.

Quoted 8 lines
Quoted 5 lines
content.tex +2 -0
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop

calculating and
+attaching hashes

For simplicity, what if just compute the hash in this case? Consider a driver may want to use this hash (e.g Linux driver).

I get the use case but maybe introduce a new command for computing hashes only? I think the disable should be preserved for disabling only.

Quoted 15 lines

for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS

Quoted 12 lines

+in the \field{gso_type} field, however the \field{hash_function} field is kept

content.tex +6 -0
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings

provided as
+follows, once the configuration process is completed the device SHOULD apply
+the hash function to each of the incoming packets and distribute the

Quoted 8 lines
Quoted 5 lines

packets
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.

We support changing #queues dynamically, so need to clarify the behavior when e.g the destination queues were disabled.

I will go into these details in the next version.

Quoted 47 lines

+

Quoted 44 lines

+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the control

content.tex +5 -0
+       queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each

packet

content.tex +9 -0
+       recieved the device MUST calculate the hashing for the packet and
+       store it in the virtio-net header in rss_hash_value and the hash
+       fields used in the calculation in rss_hash_type.
+\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field.
+
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types /

Network Device / Device Operation / Control Virtqueue / RSS hash offload}

content.tex +2 -0
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver

SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure

content.tex +4 -0
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used

and fill
+ it in the \field{hash_function} field along with the
approperiate flags
+ in the \field{hash_function_flags} field. These flags inidicate
to the
+ device which packet fields MUST be used in the calculation
process of
+ the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+ in the \field{hash_key} field, the length of the key should be
stored

content.tex +3 -0
+       in the \field{hash_key_length} field.
+\item Lastly the driver should fill the indirection table array in the
+       \field{indirection_table} field while setting the array length in
Quoted 8 lines
Quoted 5 lines

+ \field{indirection_table_length}. This structure is used by the
device
+ for determining in which RX virt queue the packet should be
placed.

Is the indirection table expected to be changed frequently? If yes, a single entry modification will cause a update of the whole table.

No, it should not be changing frequently

Quoted 16 lines

+\end{itemize}

content.tex VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command. · line 4137

Quoted 11 lines

+Once the configuration phase is over successfully, the packets SHOULD have the
+\field{rss_hash_value} field with the hash value that was calculated by the

content.tex +3 -0
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can

send an

content.tex +2 -0
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has
+RSS_HASH_FUNCTION_NONE the \field{hash_function} field.

So this function looks equivalent to VIRTIO_NET_CTRL_RSS_DISABLE?

Yes, do you think we should discard one of the two?

Quoted 5 lines

Thanks

+

Quoted 15 lines
Quoted 7 lines

+The driver MUST check the \field{ack} field value provided by the device, in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and

content.tex +2 -0
+retry another hash function or else give up.
+
  \subparagraph{Legacy Interface: Automatic receive steering in
Quoted 6 lines

multiqueue mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy Interface: Automatic receive steering in multiqueue mode}
When using the legacy interface, transitional devices and drivers MUST format \field{virtqueue_pairs}

--
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*

Signature · 4 lines
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*
#9 lore raw

Re: [virtio-dev] [RFC virtio-net 1/1] content: net: Add VIRTIO_NET_F_CTRL_RSS feature

In reply to Jason Wang
Quoted 99 lines · Jason Wang
Quoted 95 lines · Sameeh Jubran

On Thu, Mar 15, 2018 at 4:19 AM, Jason Wang <[email protected] <mailto:
[email protected]>> wrote:

On 2018年01月26日 00:27, Sameeh Jubran wrote:

From: Sameeh Jubran <[email protected]
<mailto:[email protected]>>

Most modern high end network devices today support configurable hash functions,
this commit introduces RSS - Receive Side Scaling - [1] to virtio net device.

The RSS is a technology from Microsoft that boosts network device performance
by efficiently distributing the traffic among the CPUs in a multiprocessor
system.

This feature is supported in most of the modern network cards as well as most
modern OSes including Linux and Windows. It is worth mentioning that both DPDK
and Hyper-v support RSS too.

[1]
https://docs.microsoft.com/en-us/windows-hardware/drivers/ne
twork/ndis-receive-side-scaling2
<https://docs.microsoft.com/en-us/windows-hardware/drivers/
network/ndis-receive-side-scaling2>

        Signed-off-by: Sameeh Jubran <[email protected]
        <mailto:[email protected]>>

        ---
          content.tex | 133
        ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          1 file changed, 133 insertions(+)

        diff --git a/content.tex b/content.tex
        index c840588..5969b28 100644
        --- a/content.tex
        +++ b/content.tex
        @@ -3115,6 +3115,9 @@ features.
            \item[VIRTIO_NET_F_CTRL_MAC_ADDR(23)] Set MAC address
        through control
              channel.
        +
        +\item[VIRTIO_NET_F_CTRL_RSS(24)] Device supports configurable
        RSS hash
        +    functions.
          \end{description}
            \subsubsection{Feature bit requirements}\label{sec:Device
        Types / Network Device / Feature bits / Feature bit requirements}
        @@ -3138,6 +3141,8 @@ Some networking feature bits require
        other networking feature bits
          \item[VIRTIO_NET_F_GUEST_ANNOUNCE] Requires
        VIRTIO_NET_F_CTRL_VQ.
          \item[VIRTIO_NET_F_MQ] Requires VIRTIO_NET_F_CTRL_VQ.
          \item[VIRTIO_NET_F_CTRL_MAC_ADDR] Requires

VIRTIO_NET_F_CTRL_VQ.
+
+\item[VIRTIO_NET_F_CTRL_RSS] Requires VIRTIO_NET_F_MQ.
\end{description}

Is this a requirement of RSSv2? Looks like at least RSS can work without multiqueue in V1.

You are right this is not a requirement and should be dropped. More on RSS with single hardware queue:
https://docs.microsoft.com/en-us/windows-hardware/drivers/
network/rss-with-a-single-hardware-receive-queue <
https://docs.microsoft.com/en-us/windows-hardware/drivers/
network/rss-with-a-single-hardware-receive-queue>

\subsubsection{Legacy Interface: Feature
bits}\label{sec:Device Types / Network Device / Feature bits / Legacy Interface: Feature bits}
@@ -3308,6 +3313,7 @@ struct virtio_net_hdr {
u8 flags;
#define VIRTIO_NET_HDR_GSO_NONE 0
#define VIRTIO_NET_HDR_GSO_TCPV4 1
+#define VIRTIO_NET_HDR_GSO_RSS 2

What's the reason of introducing a new GSO type here? RSS should be independent for a specific offloading type I think.

Quoted 6 lines
Quoted 3 lines

This was the straight forward option as there is no need to extend the virtio header but it can be moved to a specific offload.

If I understand correctly, RSS is not tied to GSO, so you mean VIRTIO_NET_HDR_RSS here?

Yup

Quoted 136 lines
Quoted 92 lines



          #define VIRTIO_NET_HDR_GSO_UDP         3
          #define VIRTIO_NET_HDR_GSO_TCPV6       4
          #define VIRTIO_NET_HDR_GSO_ECN      0x80
        @@ -3317,6 +3323,8 @@ struct virtio_net_hdr {
                  le16 csum_start;
                  le16 csum_offset;
                  le16 num_buffers;
        +// Only if RSS hash offload has been negotiated
        +        le64 rss_hash_value;


    Not a native English speaker, but "rss_hash" should be sufficient.

will do

          };
          \end{lstlisting}
          @@ -4007,6 +4015,131 @@ VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
command.
          The device MUST NOT queue packets on receive queues greater than
          \field{virtqueue_pairs} once it has placed the
        VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command in the used ring.
          +\paragraph{RSS hash offload}\label{sec:Device Types /
        Network Device / Device Operation / Control Virtqueue / RSS
        hash offload}
        +
        +\begin{lstlisting}
        +#define RSS_HASH_FUNCTION_NONE      1
        +#define RSS_HASH_FUNCTION_TOEPLITZ  2
        +#define RSS_HASH_FUNCTION_SYMMETRIC 3
        +
        +// Hash function fields
        +#define RSS_HASH_FIELDS_IPV4          0x00000100
        +#define RSS_HASH_FIELDS_TCP_IPV4      0x00000200
        +#define RSS_HASH_FIELDS_IPV6          0x00000400
        +#define RSS_HASH_FIELDS_IPV6_EX       0x00000800
        +#define RSS_HASH_FIELDS_TCP_IPV6      0x00001000
        +#define RSS_HASH_FIELDS_TCP_IPV6_EX   0x00002000
        +
        +struct virtio_net_ctrl_rss_hash{
        +le32 hash_function;
        +}
        +
        +struct virtio_net_rss {
        +le32 hash_function;
        +le32 hash_function_flags;
        +le32 hash_key_length;
        +le32 indirection_table_length;
        +       struct {
        +               le32 hash_key[hash_key_length];
        +               le32 indirection_table[indirection_table_length];
        +       }
        +};
        +
        +#define VIRTIO_NET_F_CTRL_RSS     24
        +
        +#define VIRTIO_NET_CTRL_RSS    6
        +#define VIRTIO_NET_CTRL_RSS_GET_SUPPORTED_FUNCTIONS  0
        +#define VIRTIO_NET_CTRL_RSS_DISABLE    1
        +#define VIRTIO_NET_CTRL_RSS_SET    2
        +\end{lstlisting}
        +
        +If the VIRTIO_NET_F_CTRL_RSS is negotiated the driver can
        send control
        +commands for the RSS configuration.
        +
        +The class VIRTIO_NET_CTRL_RSS has three commands:
        +
        +\begin{enumerate}
        +\item VIRTIO_NET_CTRL_RSS_GET_SUPPLIED_FUNCTIONS returns the
        hash functions
        +       supported by the device to the driver.


    Can we just reuse virtio_net_rss in this case, it contains all the
    informations (e.g hash key or whatever others)?

Sure this can work

+\item VIRTIO_NET_CTRL_RSS_DISABLE Instructs the device that RSS hashing is no
+ longer required.

Quoted 7 lines

So this implies that if MQ is supported, we will go to use automatic steering mode? I was thinking maybe it's better to introduce a generic command to switch between steering mode.

So you are suggesting that we should have an additional generic command
that changes between steering modes and RSS is one of those modes?

Yes.

Quoted 32 lines

+\item VIRTIO_NET_CTRL_RSS_SET applies the new RSS configuration. The command is
+ used by the driver for setting RSS hash function, hash
key and
+ indirection table in the device.
+\end{enumerate}
+
+If this feaure has been negotiated, the virtio header has an additional
+field{rss_hash_value} field attached to it.
+
+\devicenormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+The device MUST fill the virtio_net_ctrl_rss_hash structure with the hash
+functions it supports and return the structure to the driver. Zero or more
+flags of the RSS_HASH_FUNCTION flags MUST be used to fill the \field{hash_function}
+field.
+
+Upon recieving VIRTIO_NET_CTRL_DISABLE the device SHOULD stop calculating and
+attaching hashes

For simplicity, what if just compute the hash in this case? Consider a driver may want to use this hash (e.g Linux driver).

Quoted 6 lines
Quoted 3 lines

I get the use case but maybe introduce a new command for computing hashes only?

Then it looks unnecessary. (Btw, the above should be "VIRTIO_NET_CTRL_RSS_DISABLE").

We can have it as a sub command of the RSS command where the command calculates hashes only
or else make the device calculate hashes only when setting the hash function and key but not setting the indirection table (indirection_table_length = 0)
True, thanks.

Quoted 157 lines

I think the disable should be preserved for disabling only.

Quoted 109 lines

for the packets as well as stop setting the VIRTIO_NET_HDR_GSO_RSS +in the \field{gso_type} field, however the \field{hash_function} field is kept
+as a part of the header.
+
+The device MUST drop all previous RSS configuration upon receiving
+VIRTIO_NET_CTRL_RSS_SET command.
+
+The device MUST set the RSS configuration according to the settings provided as
+follows, once the configuration process is completed the device SHOULD apply
+the hash function to each of the incoming packets and distribute the packets
+through the virqueues using the calculated hash and the indirection table
+that were earlier provided by the driver.

We support changing #queues dynamically, so need to clarify the behavior when e.g the destination queues were disabled.

I will go into these details in the next version.

+
+Setting RSS configuration
+\begin{enumerate}
+\item The driver fills all of the fields and passes them through the control
+ queue to the device.
+
+\item The device sets the RSS configuration as provided by the driver.
+
+\item If the device successfully applied the configuration, on each packet
+ recieved the device MUST calculate the hashing for the
packet and
+ store it in the virtio-net header in rss_hash_value
and the hash
+ fields used in the calculation in rss_hash_type.
+\end{enumerate}
+
+In case of any unexpected values/ unsupported hash function the driver
+MUST return VIRTIO_NET_ERR in the \field{ack} field. +
+\drivernormative{\subparagraph}{RSS hash offload}{Device Types / Network Device / Device Operation / Control Virtqueue / RSS hash offload}
+
+If the driver negotiates the feature VIRTIO_NET_F_CTRL_RSS the driver SHOULD
+send VIRTIO_NET_CTRL_RSS_SET command to the device along with the RSS structure
+filled. The RSS structure fields should be filled as follows:
+
+\begin{itemize}
+\item The driver SHOULD choose the hash function that SHOULD be used and fill
+ it in the \field{hash_function} field along with the
approperiate flags
+ in the \field{hash_function_flags} field. These flags
inidicate to the
+ device which packet fields MUST be used in the
calculation process of
+ the hash.
+\item Once the hash function has been chosen a suitable hash key should be set
+ in the \field{hash_key} field, the length of the key
should be stored
+ in the \field{hash_key_length} field.
+\item Lastly the driver should fill the indirection table array in the
+ \field{indirection_table} field while setting the
array length in
+ \field{indirection_table_length}. This structure is
used by the device
+ for determining in which RX virt queue the packet
should be placed.

Is the indirection table expected to be changed frequently? If yes, a single entry modification will cause a update of the whole table.

No, it should not be changing frequently

+\end{itemize}
+Once the configuration phase is over successfully, the packets SHOULD have the
+\field{rss_hash_value} field with the hash value that was calculated by the
+device.
+
+Whenever the driver wants to discard the current RSS settings, it can send an
+VIRTIO_NET_CTRL_RSS_SET command along with rss structure that has +RSS_HASH_FUNCTION_NONE the \field{hash_function} field.

Quoted 4 lines

So this function looks equivalent to VIRTIO_NET_CTRL_RSS_DISABLE?

Yes, do you think we should discard one of the two?

Yes.

Thanks

Quoted 29 lines

Thanks

+
+The driver MUST check the \field{ack} field value provided by the device, in
+case the value is not VIRTIO_NET_OK then the driver MUST hanlde faliure and
+retry another hash function or else give up.
+
\subparagraph{Legacy Interface: Automatic receive steering
in multiqueue mode}\label{sec:Device Types / Network Device / Device Operation / Control Virtqueue / Automatic receive steering in multiqueue mode / Legacy Interface: Automatic receive steering in multiqueue mode}
When using the legacy interface, transitional devices and
drivers
MUST format \field{virtqueue_pairs}

--
Respectfully,
*/Sameeh Jubran/*
/Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>/
/Software Engineer @ Daynix <http://www.daynix.com>./

Signature · 4 lines
Respectfully,
*Sameeh Jubran*
*Linkedin <https://il.linkedin.com/pub/sameeh-jubran/87/747/a8a>*
*Software Engineer @ Daynix <http://www.daynix.com>.*