From patchwork Tue Jan 31 13:03:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongdong Liu X-Patchwork-Id: 122757 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 511A241B8F; Tue, 31 Jan 2023 14:05:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8F18F42F92; Tue, 31 Jan 2023 14:03:49 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 84C6F42D41; Tue, 31 Jan 2023 14:03:44 +0100 (CET) Received: from kwepemi500017.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4P5lbp2TmjzfZ8r; Tue, 31 Jan 2023 21:03:34 +0800 (CST) Received: from localhost.localdomain (10.28.79.22) by kwepemi500017.china.huawei.com (7.221.188.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 21:03:42 +0800 From: Dongdong Liu To: , , , CC: , , , Subject: [PATCH V3 10/10] net/hns3: fix incorrect check for duplicate RSS rule Date: Tue, 31 Jan 2023 21:03:00 +0800 Message-ID: <20230131130300.24713-11-liudongdong3@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20230131130300.24713-1-liudongdong3@huawei.com> References: <20230129105140.29921-1-liudongdong3@huawei.com> <20230131130300.24713-1-liudongdong3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500017.china.huawei.com (7.221.188.110) X-CFilter-Loop: Reflected 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 From: Huisong Li Currently, the interface for verifying duplicate RSS rules has some problems: 1) If the value of 'func' in configuring RSS rule is default value, this rule is mistakenly considered as a duplicate rule. 2) If key length is zero or 'key' is NULL in configuring RSS rule this rule is also mistakenly considered as a duplicate rule. 3) If 'key' or 'queue' in struct rte_flow_action_rss being NULL is used to memcpy, which may cause segment fault. Fixes: c37ca66f2b27 ("net/hns3: support RSS") Cc: stable@dpdk.org Signed-off-by: Huisong Li Signed-off-by: Dongdong Liu --- drivers/net/hns3/hns3_flow.c | 63 +++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/drivers/net/hns3/hns3_flow.c b/drivers/net/hns3/hns3_flow.c index a30b19cfdb..e80ec0f053 100644 --- a/drivers/net/hns3/hns3_flow.c +++ b/drivers/net/hns3/hns3_flow.c @@ -1272,28 +1272,59 @@ hns3_filterlist_flush(struct rte_eth_dev *dev) } } +static bool +hns3_flow_rule_key_same(const struct rte_flow_action_rss *comp, + const struct rte_flow_action_rss *with) +{ + if (comp->key_len != with->key_len) + return false; + + if (with->key_len == 0) + return true; + + if (comp->key == NULL && with->key == NULL) + return true; + + if (!(comp->key != NULL && with->key != NULL)) + return false; + + return !memcmp(comp->key, with->key, with->key_len); +} + +static bool +hns3_flow_rule_queues_same(const struct rte_flow_action_rss *comp, + const struct rte_flow_action_rss *with) +{ + if (comp->queue_num != with->queue_num) + return false; + + if (with->queue_num == 0) + return true; + + if (comp->queue == NULL && with->queue == NULL) + return true; + + if (!(comp->queue != NULL && with->queue != NULL)) + return false; + + return !memcmp(comp->queue, with->queue, with->queue_num); +} + static bool hns3_action_rss_same(const struct rte_flow_action_rss *comp, const struct rte_flow_action_rss *with) { - bool rss_key_is_same; - bool func_is_same; + bool same_level; + bool same_types; + bool same_func; - func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ? - (comp->func == with->func) : true; + same_level = (comp->level == with->level); + same_types = (comp->types == with->types); + same_func = (comp->func == with->func); - if (with->key_len == 0 || with->key == NULL) - rss_key_is_same = 1; - else - rss_key_is_same = comp->key_len == with->key_len && - !memcmp(comp->key, with->key, with->key_len); - - return (func_is_same && rss_key_is_same && - comp->types == with->types && - comp->level == with->level && - comp->queue_num == with->queue_num && - !memcmp(comp->queue, with->queue, - sizeof(*with->queue) * with->queue_num)); + return same_level && same_types && same_func && + hns3_flow_rule_key_same(comp, with) && + hns3_flow_rule_queues_same(comp, with); } static bool