From patchwork Tue Aug 25 05:06:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1350814 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=DkV0cHwY; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BbH8D07T8z9sR4 for ; Tue, 25 Aug 2020 15:08:43 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 5B7312274B; Tue, 25 Aug 2020 05:08:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id okOQyfoYEAEb; Tue, 25 Aug 2020 05:08:31 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 4A5A02271C; Tue, 25 Aug 2020 05:08:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2EBA8C0895; Tue, 25 Aug 2020 05:08:31 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id B6E08C0051 for ; Tue, 25 Aug 2020 05:08:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id A54A187FDA for ; Tue, 25 Aug 2020 05:08:29 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Gt+cYyUPSBmr for ; Tue, 25 Aug 2020 05:08:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by whitealder.osuosl.org (Postfix) with ESMTPS id CC00687FC2 for ; Tue, 25 Aug 2020 05:08:27 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id d139so4880322qke.11 for ; Mon, 24 Aug 2020 22:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QwU96szKOCY7q37dXYLFd1q36qldJ6vyX8D1sJRJQZQ=; b=DkV0cHwYaNgmxHoqv2UfaWQ6aisJqtELikwP+r2cSOXsXFvq734xqc6d084CbWT9mB NpEc8oxQPu6fimrowchvAFJ+N7MWVlJtTEA7NDGdwa+szxel5iz0VlzJvdeJ8E9EPEWo KSMX12uMyweiogCaLug2JcXogIuoyNFpj8q0VSpMda2nXYhMUzqRICUIxjg6YgG9UKAZ kRFSt1q557YAbwZBOWTyGlTgIpmbYHnpHzCYUcFeYzfVmMM3t8TK3daFi8wM0t8ukyjS gaA7IN4hT5Ocz9mjt3y8ZlhNg1Z1AFqZMqnChgas6BpRPWNjwBh/LlMSQYcRWVNfAcXH SxwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QwU96szKOCY7q37dXYLFd1q36qldJ6vyX8D1sJRJQZQ=; b=il1umjM1irn09pA3KCJJjYeGLorHSSYmOmT6sQ3ha1FAiN9L6VXZwN3kSoRGcc5W7K zcIVwb0ExN+o4YK2f8BMCwwui4A2q2LQohXEFGvC3Gaya7eSO+SR+fPL7zocLynrNXCy mV7YPWWfmsU4pujMSiV3MV1MNj4LG7OZzSpluNT1lsjmhFFw3bH4JSDwKduQ4pRGauZc nwGUK+KpQqyqSJ0SsXAqEBLdfebAAM8oDSQYVQ7Q03uLAWGtVkE8InL7ckBETjOxQNQ1 Zj2oLriH/d9Qg3Y582sfKcrk2HpYlOarS0kUrWQ+4UIoNYggDD/zLijDWCrXYfLkuWzs bt/w== X-Gm-Message-State: AOAM531O20Sux77fgsH0crdWZgrA584Qkqg8VpVaEN9x8EFMPZ2NB9M2 McVBiwH+u3lNEtPzYDEDbIo= X-Google-Smtp-Source: ABdhPJyDnereKHbpXG7XXTguDOnGRTi2FAzMFs6NRiZiXYNzVTahuDwi9X7hwj4UqSR6vT2ng8W71w== X-Received: by 2002:a05:620a:4ed:: with SMTP id b13mr7940838qkh.493.1598332106938; Mon, 24 Aug 2020 22:08:26 -0700 (PDT) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id 16sm7261723qkv.34.2020.08.24.22.08.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Aug 2020 22:08:26 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: davem@davemloft.net, pshelar@ovn.org, xiyou.wangcong@gmail.com Date: Tue, 25 Aug 2020 13:06:35 +0800 Message-Id: <20200825050636.14153-3-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200825050636.14153-1-xiangxia.m.yue@gmail.com> References: <20200825050636.14153-1-xiangxia.m.yue@gmail.com> Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next v3 2/3] net: openvswitch: refactor flow free function X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tonghao Zhang Decrease table->count and ufid_count unconditionally, because we only don't use count or ufid_count to count when flushing the flows. To simplify the codes, we remove the "count" argument of table_instance_flow_free. To avoid a bug when deleting flows in the future, add WARN_ON in flush flows function. Cc: Pravin B Shelar Signed-off-by: Tonghao Zhang Acked-by: Pravin B Shelar --- v3: use WARN_ON instead of BUG_ON v2: add more details why refactor this function. --- net/openvswitch/flow_table.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c index 4b7ab62d0e1a..98dad1c5f9d9 100644 --- a/net/openvswitch/flow_table.c +++ b/net/openvswitch/flow_table.c @@ -459,18 +459,14 @@ static void flow_tbl_destroy_rcu_cb(struct rcu_head *rcu) static void table_instance_flow_free(struct flow_table *table, struct table_instance *ti, struct table_instance *ufid_ti, - struct sw_flow *flow, - bool count) + struct sw_flow *flow) { hlist_del_rcu(&flow->flow_table.node[ti->node_ver]); - if (count) - table->count--; + table->count--; if (ovs_identifier_is_ufid(&flow->id)) { hlist_del_rcu(&flow->ufid_table.node[ufid_ti->node_ver]); - - if (count) - table->ufid_count--; + table->ufid_count--; } flow_mask_remove(table, flow->mask); @@ -495,10 +491,16 @@ void table_instance_flow_flush(struct flow_table *table, flow_table.node[ti->node_ver]) { table_instance_flow_free(table, ti, ufid_ti, - flow, false); + flow); ovs_flow_free(flow, true); } } + + if (WARN_ON(table->count != 0 || + table->ufid_count != 0)) { + table->count = 0; + table->ufid_count = 0; + } } static void table_instance_destroy(struct table_instance *ti, @@ -635,8 +637,6 @@ int ovs_flow_tbl_flush(struct flow_table *flow_table) rcu_assign_pointer(flow_table->ti, new_ti); rcu_assign_pointer(flow_table->ufid_ti, new_ufid_ti); flow_table->last_rehash = jiffies; - flow_table->count = 0; - flow_table->ufid_count = 0; table_instance_flow_flush(flow_table, old_ti, old_ufid_ti); table_instance_destroy(old_ti, old_ufid_ti); @@ -954,7 +954,7 @@ void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow) struct table_instance *ufid_ti = ovsl_dereference(table->ufid_ti); BUG_ON(table->count == 0); - table_instance_flow_free(table, ti, ufid_ti, flow, true); + table_instance_flow_free(table, ti, ufid_ti, flow); } static struct sw_flow_mask *mask_alloc(void)