Commit 13e59344 authored by Ahmed Zaki's avatar Ahmed Zaki Committed by Jakub Kicinski
Browse files

net: ethtool: add support for symmetric-xor RSS hash



Symmetric RSS hash functions are beneficial in applications that monitor
both Tx and Rx packets of the same flow (IDS, software firewalls, ..etc).
Getting all traffic of the same flow on the same RX queue results in
higher CPU cache efficiency.

A NIC that supports "symmetric-xor" can achieve this RSS hash symmetry
by XORing the source and destination fields and pass the values to the
RSS hash algorithm.

The user may request RSS hash symmetry for a specific algorithm, via:

    # ethtool -X eth0 hfunc <hash_alg> symmetric-xor

or turn symmetry off (asymmetric) by:

    # ethtool -X eth0 hfunc <hash_alg>

The specific fields for each flow type should then be specified as usual
via:
    # ethtool -N|-U eth0 rx-flow-hash <flow_type> s|d|f|n

Reviewed-by: default avatarWojciech Drewek <wojciech.drewek@intel.com>
Signed-off-by: default avatarAhmed Zaki <ahmed.zaki@intel.com>
Link: https://lore.kernel.org/r/20231213003321.605376-4-ahmed.zaki@intel.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent dcd8dbf9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -908,6 +908,9 @@ attribute-sets:
      -
        name: hkey
        type: binary
      -
        name: input_xfrm
        type: u32
  -
    name: plca
    attributes:
@@ -1598,6 +1601,7 @@ operations:
            - hfunc
            - indir
            - hkey
            - input_xfrm
      dump: *rss-get-op
    -
      name: plca-get-cfg
+5 −1
Original line number Diff line number Diff line
@@ -1774,12 +1774,16 @@ Kernel response contents:
  ``ETHTOOL_A_RSS_HFUNC``              u32     RSS hash func
  ``ETHTOOL_A_RSS_INDIR``              binary  Indir table bytes
  ``ETHTOOL_A_RSS_HKEY``               binary  Hash key bytes
  ``ETHTOOL_A_RSS_INPUT_XFRM``         u32     RSS input data transformation
=====================================  ======  ==========================

ETHTOOL_A_RSS_HFUNC attribute is bitmap indicating the hash function
being used. Current supported options are toeplitz, xor or crc32.
ETHTOOL_A_RSS_INDIR attribute returns RSS indrection table where each byte
ETHTOOL_A_RSS_INDIR attribute returns RSS indirection table where each byte
indicates queue number.
ETHTOOL_A_RSS_INPUT_XFRM attribute is a bitmap indicating the type of
transformation applied to the input protocol fields before given to the RSS
hfunc. Current supported option is symmetric-xor.

PLCA_GET_CFG
============
+15 −0
Original line number Diff line number Diff line
@@ -44,6 +44,21 @@ by masking out the low order seven bits of the computed hash for the
packet (usually a Toeplitz hash), taking this number as a key into the
indirection table and reading the corresponding value.

Some NICs support symmetric RSS hashing where, if the IP (source address,
destination address) and TCP/UDP (source port, destination port) tuples
are swapped, the computed hash is the same. This is beneficial in some
applications that monitor TCP/IP flows (IDS, firewalls, ...etc) and need
both directions of the flow to land on the same Rx queue (and CPU). The
"Symmetric-XOR" is a type of RSS algorithms that achieves this hash
symmetry by XORing the input source and destination fields of the IP
and/or L4 protocols. This, however, results in reduced input entropy and
could potentially be exploited. Specifically, the algorithm XORs the input
as follows::

    # (SRC_IP ^ DST_IP, SRC_IP ^ DST_IP, SRC_PORT ^ DST_PORT, SRC_PORT ^ DST_PORT)

The result is then fed to the underlying RSS algorithm.

Some advanced NICs allow steering packets to queues based on
programmable filters. For example, webserver bound TCP port 80 packets
can be directed to their own receive queue. Such “n-tuple” filters can
+6 −0
Original line number Diff line number Diff line
@@ -615,6 +615,8 @@ struct ethtool_mm_stats {
 *	to allocate a new RSS context; on return this field will
 *	contain the ID of the newly allocated context.
 * @rss_delete: Set to non-ZERO to remove the @rss_context context.
 * @input_xfrm: Defines how the input data is transformed. Valid values are one
 *	of %RXH_XFRM_*.
 */
struct ethtool_rxfh_param {
	u8	hfunc;
@@ -624,6 +626,7 @@ struct ethtool_rxfh_param {
	u8	*key;
	u32	rss_context;
	u8	rss_delete;
	u8	input_xfrm;
};

/**
@@ -632,6 +635,8 @@ struct ethtool_rxfh_param {
 *	parameter.
 * @cap_rss_ctx_supported: indicates if the driver supports RSS
 *	contexts.
 * @cap_rss_sym_xor_supported: indicates if the driver supports symmetric-xor
 *	RSS.
 * @supported_coalesce_params: supported types of interrupt coalescing.
 * @supported_ring_params: supported ring params.
 * @get_drvinfo: Report driver/device information. Modern drivers no
@@ -811,6 +816,7 @@ struct ethtool_rxfh_param {
struct ethtool_ops {
	u32     cap_link_lanes_supported:1;
	u32     cap_rss_ctx_supported:1;
	u32	cap_rss_sym_xor_supported:1;
	u32	supported_coalesce_params;
	u32	supported_ring_params;
	void	(*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
+12 −1
Original line number Diff line number Diff line
@@ -1266,6 +1266,8 @@ struct ethtool_rxfh_indir {
 *	hardware hash key.
 * @hfunc: Defines the current RSS hash function used by HW (or to be set to).
 *	Valid values are one of the %ETH_RSS_HASH_*.
 * @input_xfrm: Defines how the input data is transformed. Valid values are one
 *	of %RXH_XFRM_*.
 * @rsvd8: Reserved for future use; see the note on reserved space.
 * @rsvd32: Reserved for future use; see the note on reserved space.
 * @rss_config: RX ring/queue index for each hash value i.e., indirection table
@@ -1285,7 +1287,8 @@ struct ethtool_rxfh {
	__u32   indir_size;
	__u32   key_size;
	__u8	hfunc;
	__u8	rsvd8[3];
	__u8	input_xfrm;
	__u8	rsvd8[2];
	__u32	rsvd32;
	__u32   rss_config[];
};
@@ -1992,6 +1995,14 @@ static inline int ethtool_validate_duplex(__u8 duplex)

#define WOL_MODE_COUNT		8

/* RSS hash function data
 * XOR the corresponding source and destination fields of each specified
 * protocol. Both copies of the XOR'ed fields are fed into the RSS and RXHASH
 * calculation. Note that this XORing reduces the input set entropy and could
 * be exploited to reduce the RSS queue spread.
 */
#define	RXH_XFRM_SYM_XOR	(1 << 0)

/* L2-L4 network traffic flow types */
#define	TCP_V4_FLOW	0x01	/* hash or spec (tcp_ip4_spec) */
#define	UDP_V4_FLOW	0x02	/* hash or spec (udp_ip4_spec) */
Loading