From patchwork Thu Oct 5 21:46:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ahmed Zaki X-Patchwork-Id: 13410826 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E7064121B for ; Thu, 5 Oct 2023 21:46:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bItEGZu2" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D965AD8 for ; Thu, 5 Oct 2023 14:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696542384; x=1728078384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=32akxHSYhb17D+XQtNXel6BwEp9EweKFmYRPZqxIveM=; b=bItEGZu2iO5X/9znw5OhlhH9zlASH4LL/+qbh11DxSqOLcup7DXFDNFF vpXWDmvq72PzzDOf0fu18nPJziWhppl28WSRQ01scKCIPQbn3H3msOPnp 4PVcZLSHr/07KIuffYWuNpV0gYMNuLKxlXmplNUu3/CF/ZQ9oymFiPOf3 /txBJgi4DIt6ctHLPBrLb9EJ9Y2vKGYpOEHrGQa7WsuXTYrVbop+++4rt lRUXr23aDdEIr/LHfWnN1uVwwuIcNBBtUNwguaYG1LiU8kGajBcTV04KO rNqi4lPoPVI8s6xdhRrUz4uSxVwREkBw1mFUBb+8+3uCJyatfybackXcU g==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="373977684" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="373977684" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 14:46:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="822271031" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="822271031" Received: from tsicinsk-mobl.ger.corp.intel.com (HELO azaki-desk1.intel.com) ([10.249.35.190]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 14:46:22 -0700 From: Ahmed Zaki To: netdev@vger.kernel.org Cc: intel-wired-lan@lists.osuosl.org, Ahmed Zaki , Wojciech Drewek Subject: [PATCH net-next 1/6] net: ethtool: allow symmetric RSS hash for any flow type Date: Thu, 5 Oct 2023 15:46:02 -0600 Message-Id: <20231005214607.3178614-2-ahmed.zaki@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005214607.3178614-1-ahmed.zaki@intel.com> References: <20231005214607.3178614-1-ahmed.zaki@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org 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. Only fields that has counterparts in the other direction can be accepted; IP src/dst and L4 src/dst ports. The user may request RSS hash symmetry for a specific flow type, via: # ethtool -N|-U eth0 rx-flow-hash s|d|f|n symmetric or turn symmetry off (asymmetric) by: # ethtool -N|-U eth0 rx-flow-hash s|d|f|n Reviewed-by: Wojciech Drewek Signed-off-by: Ahmed Zaki --- Documentation/networking/scaling.rst | 6 ++++++ include/uapi/linux/ethtool.h | 1 + net/ethtool/ioctl.c | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/Documentation/networking/scaling.rst b/Documentation/networking/scaling.rst index 92c9fb46d6a2..64f3d7566407 100644 --- a/Documentation/networking/scaling.rst +++ b/Documentation/networking/scaling.rst @@ -44,6 +44,12 @@ 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). + 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 diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index f7fba0dc87e5..bf67c8094ae0 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -2025,6 +2025,7 @@ static inline int ethtool_validate_duplex(__u8 duplex) #define RXH_IP_DST (1 << 5) #define RXH_L4_B_0_1 (1 << 6) /* src port in case of TCP/UDP/SCTP */ #define RXH_L4_B_2_3 (1 << 7) /* dst port in case of TCP/UDP/SCTP */ +#define RXH_SYMMETRIC (1 << 30) #define RXH_DISCARD (1 << 31) #define RX_CLS_FLOW_DISC 0xffffffffffffffffULL diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 0b0ce4f81c01..44742653a4bd 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -980,6 +980,17 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, if (rc) return rc; + /* If a symmetric hash is requested, then: + * 1 - no other fields besides IP src/dst and/or L4 src/dst + * 2 - If src is set, dst must also be set + */ + if ((info.data & RXH_SYMMETRIC) && + ((info.data & ~(RXH_SYMMETRIC | RXH_IP_SRC | RXH_IP_DST | + RXH_L4_B_0_1 | RXH_L4_B_2_3)) || + (!!(info.data & RXH_IP_SRC) ^ !!(info.data & RXH_IP_DST)) || + (!!(info.data & RXH_L4_B_0_1) ^ !!(info.data & RXH_L4_B_2_3)))) + return -EINVAL; + rc = dev->ethtool_ops->set_rxnfc(dev, &info); if (rc) return rc;