From patchwork Mon Nov 12 02:08:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 996232 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42tZ1h6zkgz9s5c for ; Mon, 12 Nov 2018 13:08:55 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 890C03C1; Mon, 12 Nov 2018 02:08:51 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id A4D4B25A for ; Mon, 12 Nov 2018 02:08:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id B71CE19B for ; Mon, 12 Nov 2018 02:08:49 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from chrism@mellanox.com) with ESMTPS (AES256-SHA encrypted); 12 Nov 2018 04:14:14 +0200 Received: from dev-r630-04.mtbc.labs.mlnx (dev-r630-04.mtbc.labs.mlnx [10.12.205.14]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id wAC28f5r002814; Mon, 12 Nov 2018 04:08:42 +0200 From: Chris Mi To: simon.horman@netronome.com Date: Mon, 12 Nov 2018 11:08:38 +0900 Message-Id: <20181112020838.17495-1-chrism@mellanox.com> X-Mailer: git-send-email 2.14.4 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: ovs-dev@openvswitch.org Subject: [ovs-dev] [ovs-dev v2] netdev-tc-offloads: Delete ufid tc mapping in the right place X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Currently, the ufid tc mapping is deleted in add_ufid_tc_mapping(). But if tc_replace_flower() failed, the old ufid tc mapping will not be deleted. If another thread adds the same tc mapping successfully, then there will be multiple mappings for the same ifindex, handle and prio. * V2: - Add a wrapper function del_filter_and_ufid_mapping() Fixes: 9116730db ("netdev-tc-offloads: Add ufid to tc/netdev map") Signed-off-by: Chris Mi Reviewed-by: Roi Dayan --- lib/netdev-tc-offloads.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 6f1fbe667..606a4f4db 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -163,8 +163,20 @@ del_ufid_tc_mapping(const ovs_u128 *ufid) ovs_mutex_unlock(&ufid_lock); } -/* Add ufid entry to ufid_tc hashmap. - * If entry exists already it will be replaced. */ +/* Wrapper function to delete filter and ufid tc mapping */ +static int +del_filter_and_ufid_mapping(int ifindex, int prio, int handle, + uint32_t block_id, const ovs_u128 *ufid) +{ + int err; + + err = tc_del_filter(ifindex, prio, handle, block_id); + del_ufid_tc_mapping(ufid); + + return err; +} + +/* Add ufid entry to ufid_tc hashmap. */ static void add_ufid_tc_mapping(const ovs_u128 *ufid, int prio, int handle, struct netdev *netdev, int ifindex) @@ -173,8 +185,6 @@ add_ufid_tc_mapping(const ovs_u128 *ufid, int prio, int handle, size_t tc_hash = hash_int(hash_int(prio, handle), ifindex); struct ufid_tc_data *new_data = xzalloc(sizeof *new_data); - del_ufid_tc_mapping(ufid); - new_data->ufid = *ufid; new_data->prio = prio; new_data->handle = handle; @@ -1302,7 +1312,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, handle = get_ufid_tc_mapping(ufid, &prio, NULL); if (handle && prio) { VLOG_DBG_RL(&rl, "updating old handle: %d prio: %d", handle, prio); - tc_del_filter(ifindex, prio, handle, block_id); + del_filter_and_ufid_mapping(ifindex, prio, handle, block_id, ufid); } if (!prio) { @@ -1413,8 +1423,7 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED, } } - error = tc_del_filter(ifindex, prio, handle, block_id); - del_ufid_tc_mapping(ufid); + error = del_filter_and_ufid_mapping(ifindex, prio, handle, block_id, ufid); netdev_close(dev);