From patchwork Wed Nov 14 01:36:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 997457 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 42vnC50xLXz9s7h for ; Wed, 14 Nov 2018 12:36:16 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8BA008D7; Wed, 14 Nov 2018 01:36:12 +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 5CF18869 for ; Wed, 14 Nov 2018 01:36:11 +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 6AA788B for ; Wed, 14 Nov 2018 01:36:10 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from chrism@mellanox.com) with ESMTPS (AES256-SHA encrypted); 14 Nov 2018 03:41:41 +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 wAE1a6BK026225; Wed, 14 Nov 2018 03:36:07 +0200 From: Chris Mi To: simon.horman@netronome.com Date: Tue, 13 Nov 2018 20:36:04 -0500 Message-Id: <1542159364-91647-1-git-send-email-chrism@mellanox.com> X-Mailer: git-send-email 1.8.3.1 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] [branch-2.8/2.9 backport] 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. 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 1ca7d45..ea5ad59 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -161,8 +161,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, + const ovs_u128 *ufid) +{ + int err; + + err = tc_del_filter(ifindex, prio, handle); + 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) @@ -171,8 +183,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; @@ -1033,7 +1043,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); + del_filter_and_ufid_mapping(ifindex, prio, handle, ufid); } if (!prio) { @@ -1138,8 +1148,7 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED, } } - error = tc_del_filter(ifindex, prio, handle); - del_ufid_tc_mapping(ufid); + error = del_filter_and_ufid_mapping(ifindex, prio, handle, ufid); netdev_close(dev);