From owner-svn-src-stable@freebsd.org Thu Feb 27 15:08:44 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B3E552441E6; Thu, 27 Feb 2020 15:08:44 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48Swzc29N3z4dxj; Thu, 27 Feb 2020 15:08:44 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 11EFD1A8FA; Thu, 27 Feb 2020 15:08:44 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01RF8hYt072619; Thu, 27 Feb 2020 15:08:43 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01RF8hYN072616; Thu, 27 Feb 2020 15:08:43 GMT (envelope-from avg@FreeBSD.org) Message-Id: <202002271508.01RF8hYN072616@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Thu, 27 Feb 2020 15:08:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r358386 - in stable/12/sys: dev/vmware/vmxnet3 modules/vmware/vmxnet3 X-SVN-Group: stable-12 X-SVN-Commit-Author: avg X-SVN-Commit-Paths: in stable/12/sys: dev/vmware/vmxnet3 modules/vmware/vmxnet3 X-SVN-Commit-Revision: 358386 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Feb 2020 15:08:44 -0000 Author: avg Date: Thu Feb 27 15:08:43 2020 New Revision: 358386 URL: https://svnweb.freebsd.org/changeset/base/358386 Log: MFC r357042: vmxnet3: add support for RSS kernel option We observe at least one problem: if a UDP socket is connect(2)-ed, then a received packet that matches the connection cannot be matched to the corresponding PCB because of an incorrect flow ID. That was oberved for DNS requests from the libc resolver. We got this problem because FreeBSD r343291 enabled code that can set rsstype of received packets to values other than M_HASHTYPE_OPAQUE_HASH. Earlier that code was under 'ifdef notyet'. The essence of this change is to use the system-wide RSS key instead of some historic hardcoded key when the software RSS is enabled and it is configured to use Toeplitz algorithm (the default). In all other cases, the driver reports the opaque hash type for received packets while still using Toeplitz algorithm with the internal key. PR: 242890 Sponsored by: Panzura Modified: stable/12/sys/dev/vmware/vmxnet3/if_vmx.c stable/12/sys/dev/vmware/vmxnet3/if_vmxvar.h stable/12/sys/modules/vmware/vmxnet3/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/vmware/vmxnet3/if_vmx.c ============================================================================== --- stable/12/sys/dev/vmware/vmxnet3/if_vmx.c Thu Feb 27 14:52:55 2020 (r358385) +++ stable/12/sys/dev/vmware/vmxnet3/if_vmx.c Thu Feb 27 15:08:43 2020 (r358386) @@ -23,6 +23,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_rss.h" + #include #include #include @@ -46,6 +48,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef RSS +#include +#endif #include #include @@ -1140,8 +1145,11 @@ vmxnet3_reinit_rss_shared_data(struct vmxnet3_softc *s struct vmxnet3_driver_shared *ds; if_softc_ctx_t scctx; struct vmxnet3_rss_shared *rss; +#ifdef RSS + uint8_t rss_algo; +#endif int i; - + ds = sc->vmx_ds; scctx = sc->vmx_scctx; rss = sc->vmx_rss; @@ -1152,10 +1160,29 @@ vmxnet3_reinit_rss_shared_data(struct vmxnet3_softc *s rss->hash_func = UPT1_RSS_HASH_FUNC_TOEPLITZ; rss->hash_key_size = UPT1_RSS_MAX_KEY_SIZE; rss->ind_table_size = UPT1_RSS_MAX_IND_TABLE_SIZE; - memcpy(rss->hash_key, rss_key, UPT1_RSS_MAX_KEY_SIZE); - - for (i = 0; i < UPT1_RSS_MAX_IND_TABLE_SIZE; i++) - rss->ind_table[i] = i % scctx->isc_nrxqsets; +#ifdef RSS + /* + * If the software RSS is configured to anything else other than + * Toeplitz, then just do Toeplitz in "hardware" for the sake of + * the packet distribution, but report the hash as opaque to + * disengage from the software RSS. + */ + rss_algo = rss_gethashalgo(); + if (rss_algo == RSS_HASH_TOEPLITZ) { + rss_getkey(rss->hash_key); + for (i = 0; i < UPT1_RSS_MAX_IND_TABLE_SIZE; i++) { + rss->ind_table[i] = rss_get_indirection_to_bucket(i) % + scctx->isc_nrxqsets; + } + sc->vmx_flags |= VMXNET3_FLAG_SOFT_RSS; + } else +#endif + { + memcpy(rss->hash_key, rss_key, UPT1_RSS_MAX_KEY_SIZE); + for (i = 0; i < UPT1_RSS_MAX_IND_TABLE_SIZE; i++) + rss->ind_table[i] = i % scctx->isc_nrxqsets; + sc->vmx_flags &= ~VMXNET3_FLAG_SOFT_RSS; + } } static void @@ -1499,29 +1526,50 @@ vmxnet3_isc_rxd_pkt_get(void *vsc, if_rxd_info_t ri) KASSERT(rxcd->sop, ("%s: expected sop", __func__)); /* - * RSS and flow ID + * RSS and flow ID. + * Types other than M_HASHTYPE_NONE and M_HASHTYPE_OPAQUE_HASH should + * be used only if the software RSS is enabled and it uses the same + * algorithm and the hash key as the "hardware". If the software RSS + * is not enabled, then it's simply pointless to use those types. + * If it's enabled but with different parameters, then hash values will + * not match. */ ri->iri_flowid = rxcd->rss_hash; - switch (rxcd->rss_type) { - case VMXNET3_RCD_RSS_TYPE_NONE: - ri->iri_flowid = ri->iri_qsidx; - ri->iri_rsstype = M_HASHTYPE_NONE; - break; - case VMXNET3_RCD_RSS_TYPE_IPV4: - ri->iri_rsstype = M_HASHTYPE_RSS_IPV4; - break; - case VMXNET3_RCD_RSS_TYPE_TCPIPV4: - ri->iri_rsstype = M_HASHTYPE_RSS_TCP_IPV4; - break; - case VMXNET3_RCD_RSS_TYPE_IPV6: - ri->iri_rsstype = M_HASHTYPE_RSS_IPV6; - break; - case VMXNET3_RCD_RSS_TYPE_TCPIPV6: - ri->iri_rsstype = M_HASHTYPE_RSS_TCP_IPV6; - break; - default: - ri->iri_rsstype = M_HASHTYPE_OPAQUE_HASH; - break; +#ifdef RSS + if ((sc->vmx_flags & VMXNET3_FLAG_SOFT_RSS) != 0) { + switch (rxcd->rss_type) { + case VMXNET3_RCD_RSS_TYPE_NONE: + ri->iri_flowid = ri->iri_qsidx; + ri->iri_rsstype = M_HASHTYPE_NONE; + break; + case VMXNET3_RCD_RSS_TYPE_IPV4: + ri->iri_rsstype = M_HASHTYPE_RSS_IPV4; + break; + case VMXNET3_RCD_RSS_TYPE_TCPIPV4: + ri->iri_rsstype = M_HASHTYPE_RSS_TCP_IPV4; + break; + case VMXNET3_RCD_RSS_TYPE_IPV6: + ri->iri_rsstype = M_HASHTYPE_RSS_IPV6; + break; + case VMXNET3_RCD_RSS_TYPE_TCPIPV6: + ri->iri_rsstype = M_HASHTYPE_RSS_TCP_IPV6; + break; + default: + ri->iri_rsstype = M_HASHTYPE_OPAQUE_HASH; + break; + } + } else +#endif + { + switch (rxcd->rss_type) { + case VMXNET3_RCD_RSS_TYPE_NONE: + ri->iri_flowid = ri->iri_qsidx; + ri->iri_rsstype = M_HASHTYPE_NONE; + break; + default: + ri->iri_rsstype = M_HASHTYPE_OPAQUE_HASH; + break; + } } /* VLAN */ Modified: stable/12/sys/dev/vmware/vmxnet3/if_vmxvar.h ============================================================================== --- stable/12/sys/dev/vmware/vmxnet3/if_vmxvar.h Thu Feb 27 14:52:55 2020 (r358385) +++ stable/12/sys/dev/vmware/vmxnet3/if_vmxvar.h Thu Feb 27 15:08:43 2020 (r358386) @@ -113,6 +113,8 @@ struct vmxnet3_softc { struct vmxnet3_driver_shared *vmx_ds; uint32_t vmx_flags; #define VMXNET3_FLAG_RSS 0x0002 +#define VMXNET3_FLAG_SOFT_RSS 0x0004 /* Software RSS is enabled with + compatible algorithm. */ struct vmxnet3_rxqueue *vmx_rxq; struct vmxnet3_txqueue *vmx_txq; Modified: stable/12/sys/modules/vmware/vmxnet3/Makefile ============================================================================== --- stable/12/sys/modules/vmware/vmxnet3/Makefile Thu Feb 27 14:52:55 2020 (r358385) +++ stable/12/sys/modules/vmware/vmxnet3/Makefile Thu Feb 27 15:08:43 2020 (r358386) @@ -28,6 +28,6 @@ KMOD= if_vmx SRCS= if_vmx.c SRCS+= bus_if.h device_if.h pci_if.h ifdi_if.h -SRCS+= opt_inet.h opt_inet6.h +SRCS+= opt_inet.h opt_inet6.h opt_rss.h .include