Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Jul 2020 13:55:05 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r363694 - in stable/12/sys: dev/ena modules/ena
Message-ID:  <202007301355.06UDt50o031158@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Thu Jul 30 13:55:05 2020
New Revision: 363694
URL: https://svnweb.freebsd.org/changeset/base/363694

Log:
  MFC r362530: teach ena driver about RSS kernel option
  
  Networking is broken if the driver configures its (virtual) hardware to
  use a hash algorithm (or a key) different from the one that the network
  stack (software RSS) uses.  This can be seen with connections initiated
  from the host.  The PCB will be placed into the hash table based on the
  hash value calculated by the software.  The hardware-calculated hash
  value in reponse packets will be different, so the PCB won't be found.
  
  Tested with a kernel compiled with 'options RSS' on an instance with ena
  driver.

Modified:
  stable/12/sys/dev/ena/ena.c
  stable/12/sys/modules/ena/Makefile
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/dev/ena/ena.c
==============================================================================
--- stable/12/sys/dev/ena/ena.c	Thu Jul 30 13:36:24 2020	(r363693)
+++ stable/12/sys/dev/ena/ena.c	Thu Jul 30 13:55:05 2020	(r363694)
@@ -30,6 +30,8 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include "opt_rss.h"
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/bus.h>
@@ -62,6 +64,9 @@ __FBSDID("$FreeBSD$");
 #include <net/rss_config.h>
 #include <net/if_types.h>
 #include <net/if_vlan_var.h>
+#ifdef RSS
+#include <net/rss_config.h>
+#endif
 
 #include <netinet/in_rss.h>
 #include <netinet/in_systm.h>
@@ -1424,6 +1429,19 @@ ena_rx_hash_mbuf(struct ena_ring *rx_ring, struct ena_
 	if (likely(adapter->rss_support)) {
 		mbuf->m_pkthdr.flowid = ena_rx_ctx->hash;
 
+#ifdef RSS
+		/*
+		 * Hardware and software RSS are in agreement only when both are
+		 * configured to Toeplitz algorithm.  This driver configures
+		 * that algorithm only when software RSS is enabled and uses it.
+		 */
+		if (adapter->ena_dev->rss.hash_func != ENA_ADMIN_TOEPLITZ &&
+		    ena_rx_ctx->l3_proto != ENA_ETH_IO_L3_PROTO_UNKNOWN) {
+			M_HASHTYPE_SET(mbuf, M_HASHTYPE_OPAQUE_HASH);
+			return;
+		}
+#endif
+
 		if (ena_rx_ctx->frag &&
 		    (ena_rx_ctx->l3_proto != ENA_ETH_IO_L3_PROTO_UNKNOWN)) {
 			M_HASHTYPE_SET(mbuf, M_HASHTYPE_OPAQUE_HASH);
@@ -3106,6 +3124,16 @@ ena_rss_init_default(struct ena_adapter *adapter)
 		}
 	}
 
+#ifdef RSS
+	uint8_t rss_algo = rss_gethashalgo();
+	if (rss_algo == RSS_HASH_TOEPLITZ) {
+		uint8_t hash_key[RSS_KEYSIZE];
+
+		rss_getkey(hash_key);
+		rc = ena_com_fill_hash_function(ena_dev, ENA_ADMIN_TOEPLITZ,
+		    hash_key, RSS_KEYSIZE, 0xFFFFFFFF);
+	} else
+#endif
 	rc = ena_com_fill_hash_function(ena_dev, ENA_ADMIN_CRC32, NULL,
 	    ENA_HASH_KEY_SIZE, 0xFFFFFFFF);
 	if (unlikely((rc != 0) && (rc != EOPNOTSUPP))) {

Modified: stable/12/sys/modules/ena/Makefile
==============================================================================
--- stable/12/sys/modules/ena/Makefile	Thu Jul 30 13:36:24 2020	(r363693)
+++ stable/12/sys/modules/ena/Makefile	Thu Jul 30 13:55:05 2020	(r363694)
@@ -36,6 +36,7 @@
 KMOD	= if_ena
 SRCS	= ena.c ena_com.c ena_eth_com.c ena_sysctl.c
 SRCS	+= device_if.h bus_if.h pci_if.h
+SRCS	+= opt_rss.h
 CFLAGS  += -I${SRCTOP}/sys/contrib
 
 .include <bsd.kmod.mk>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007301355.06UDt50o031158>