From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2D0604407F; Tue, 21 May 2024 04:49:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7FC38406A2; Tue, 21 May 2024 04:49:35 +0200 (CEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 86E964067D for ; Tue, 21 May 2024 04:49:30 +0200 (CEST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1f2ecea41deso88063855ad.1 for ; Mon, 20 May 2024 19:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1716259770; x=1716864570; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OU7guZVDu6aosJdXQlVaUaaoZmgdURl1pOYy82R+ePg=; b=RUrHtMWyvFXjIn8AYRhjza7tS/1QRSP+fJxOTykXhqPCN1458gL1T4pcaxiD9TS7sx Y9lTpgNXDma35T2s9vmWtfo4ZqstDUtqJNlYFL6FSJg7VgtGomOVWA1uddPmdbAfZEOQ uQSK6HTF6ISNaktX4JrjUs3HF6tkK26QXNj3SVFUcwijxHu+ldTAv6L0uwPPdQ1UC8WT ElBXy2wDrGOOMVf4JbSJs2E4ck3CcLn3G4mr8bXmn4QCzYPg+1/MY/ARHZzabeJ9qUax 6HyGwqou9gWTDSEivYlP9DjxtYjGU7A0L/4gHm+fgAtAluwotu0hwPUJo01ScqU6brWd Vt1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716259770; x=1716864570; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OU7guZVDu6aosJdXQlVaUaaoZmgdURl1pOYy82R+ePg=; b=ldtwdbPIRskypYx7fRFXKq/ZItFVZrfNKCGi93kvvieXKGxDo2VbR1UrfDxtp56sSd Jakp9i8k1z7kjoMH8VEwNoFQqdc7iK0ycR87wAIE5NiF7GRLYlUPoth73vT94E5gGpe+ h1Y7RgnhalNrr4pNHGX7W5wT7JPgvxepbJkR9h9DR6DUn6ze4nkGGtlV5wRDksiRL/sI lADbanCU5+5nEyarM4a14A2cMpZ0svJG4Ylanl4zOiOzrtMqVwMg1erFCm+BlxOyvlFf DmcVnJoW9glA4lYF7U8G4c00OQUpYPDbW4+Pmu0D1URp3y7icXa262EvBgwzWt/yBxYQ /NpA== X-Gm-Message-State: AOJu0Yy6KfzHFzmJqCw7grRxpzyIZHOijJkrzDBDQiRzcJ6/rlII8RCr SXXhtxbV4JNyWhyrarzo7yHIG/LArKpl8C//HeSYyx0qDzcsZmIm4N7CnUjNr7dIwxrxSLVx5Kt g X-Google-Smtp-Source: AGHT+IHM3/27FdtMVXGztwgNExl1Sr0vTwdYegZR7/OsBPI3k8nRztnBiXiAG2JZFvBJTq9D2tm/nA== X-Received: by 2002:a17:902:db11:b0:1f3:565:5660 with SMTP id d9443c01a7336-1f305655810mr45898715ad.69.1716259769611; Mon, 20 May 2024 19:49:29 -0700 (PDT) Received: from hermes.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0b9d4828sm209742315ad.20.2024.05.20.19.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 19:49:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v13 04/11] net/tap: validate and setup parameters for BPF RSS Date: Mon, 20 May 2024 19:47:23 -0700 Message-ID: <20240521024923.150983-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240521024923.150983-1-stephen@networkplumber.org> References: <20240130034925.44869-1-stephen@networkplumber.org> <20240521024923.150983-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The flow RSS support via BPF was not using the key, or hash type parameters. Which is good because they were never properly setup. Fix the setup and validate the flow parameters, the BPF side gets fixed later. Signed-off-by: Stephen Hemminger --- drivers/net/tap/tap_flow.c | 75 +++++++++++++++++++++++++++++++++++--- drivers/net/tap/tap_rss.h | 5 +-- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c index 8fccd599f0..dd4e69b876 100644 --- a/drivers/net/tap/tap_flow.c +++ b/drivers/net/tap/tap_flow.c @@ -11,9 +11,11 @@ #include #include +#include #include #include #include + #include #include #include @@ -2061,6 +2063,21 @@ static int bpf_rss_key(enum bpf_rss_key_e cmd, __u32 *key_idx) return err; } + +/* Default RSS hash key also used by mlx devices */ +static const uint8_t rss_hash_default_key[] = { + 0x2c, 0xc6, 0x81, 0xd1, + 0x5b, 0xdb, 0xf4, 0xf7, + 0xfc, 0xa2, 0x83, 0x19, + 0xdb, 0x1a, 0x3e, 0x94, + 0x6b, 0x9e, 0x38, 0xd9, + 0x2c, 0x9c, 0x03, 0xd1, + 0xad, 0x99, 0x44, 0xa7, + 0xd9, 0x56, 0x3d, 0x59, + 0x06, 0x3c, 0x25, 0xf3, + 0xfc, 0x1f, 0xdc, 0x2a, +}; + /** * Add RSS hash calculations and queue selection * @@ -2079,11 +2096,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, const struct rte_flow_action_rss *rss, struct rte_flow_error *error) { - /* 4096 is the maximum number of instructions for a BPF program */ + struct rss_key rss_entry = { }; + const uint8_t *key_in; + uint32_t hash_type = 0; unsigned int i; int err; - struct rss_key rss_entry = { .hash_fields = 0, - .key_size = 0 }; /* Check supported RSS features */ if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT) @@ -2095,6 +2112,51 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "a nonzero RSS encapsulation level is not supported"); + if (rss->queue_num == 0 || rss->queue_num >= TAP_MAX_QUEUES) + return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "invalid number of queues"); + + /* + * Follow the semantics of RSS key (see rte_ethdev.h) + * There are two valid cases: + * 1. key_length of zero, and key must be NULL; + * this uses the default driver key. + * + * 2. key_length is the TAP_RSS_HASH_KEY_SIZE (40 bytes) + * and the key must not be NULL. + * + * Anything else is an error. + */ + if (rss->key_len == 0) { + if (rss->key != NULL) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + &rss->key_len, "RSS hash key length 0"); + key_in = rss_hash_default_key; + } else { + if (rss->key_len != TAP_RSS_HASH_KEY_SIZE) + return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "RSS hash invalid key length"); + if (rss->key == NULL) + return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "RSS hash key is NULL"); + key_in = rss->key; + } + + if (rss->types & TAP_RSS_HF_MASK) + return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "RSS hash type not supported"); + + if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV4_TCP)) + hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3_L4); + else if (rss->types & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4)) + hash_type |= RTE_BIT32(HASH_FIELD_IPV4_L3); + + if (rss->types & (RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_NONFRAG_IPV6_TCP)) + hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3_L4); + else if (rss->types & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_IPV6_EX)) + hash_type |= RTE_BIT32(HASH_FIELD_IPV6_L3); + /* Get a new map key for a new RSS rule */ err = bpf_rss_key(KEY_CMD_GET, &flow->key_idx); if (err < 0) { @@ -2109,8 +2171,11 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, rss_entry.nb_queues = rss->queue_num; for (i = 0; i < rss->queue_num; i++) rss_entry.queues[i] = rss->queue[i]; - rss_entry.hash_fields = - (1 << HASH_FIELD_IPV4_L3_L4) | (1 << HASH_FIELD_IPV6_L3_L4); + + rss_entry.hash_fields = hash_type; + rte_convert_rss_key((const uint32_t *)key_in, (uint32_t *)rss_entry.key, + TAP_RSS_HASH_KEY_SIZE); + /* Add this RSS entry to map */ err = tap_flow_bpf_update_rss_elem(pmd->map_fd, diff --git a/drivers/net/tap/tap_rss.h b/drivers/net/tap/tap_rss.h index 8766ffc244..6009be7031 100644 --- a/drivers/net/tap/tap_rss.h +++ b/drivers/net/tap/tap_rss.h @@ -24,11 +24,10 @@ enum hash_field { }; struct rss_key { - __u8 key[128]; __u32 hash_fields; - __u32 key_size; - __u32 queues[TAP_MAX_QUEUES]; + __u8 key[TAP_RSS_HASH_KEY_SIZE]; __u32 nb_queues; + __u32 queues[TAP_MAX_QUEUES]; } __attribute__((packed)); #endif /* _TAP_RSS_H_ */ -- 2.43.0