Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4436848imm; Mon, 14 May 2018 07:33:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqP7+Ym/rfUy32l30Vo/H2/36BvPFCF/rHMV3CPBEwqNqpANZbMTdrXk4AsP5mvHvZX4BoO X-Received: by 2002:a17:902:7b97:: with SMTP id w23-v6mr10343114pll.116.1526308426974; Mon, 14 May 2018 07:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526308426; cv=none; d=google.com; s=arc-20160816; b=M2fdvw1FZsDA/HxdjreOh+XRalYXoGBNTxAiuUpdgubfpdYwrEvLKwpLJ8cWnZEgB3 sataMOFIX8yA0o71LmcPRabPMXP1AkvkVcpLq9+hKLL+U1ljt9apXV5jBTCjsV9NRH4K zCnI81PSLvKpdCbGwTAGVd2M6JbMcjdjlpGUgh5y7XxsjTzIyttcebCJ3Na9NAr7iuaI 0341NToYe2wlGEE06HDXvKdT4UDKdUBVXfLp1lwAo+WvXTVrjoLg+ZPoChTNKDCZtIZy /6+M/veIYZQ09zjC2tXxChYNIbnfqwWeQtQrhvX5o/9T9QCHAZQSZrLiMKV5ZObkPW/3 bnFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=GbxS+IHo4ZEoZk2R3hSuPGNvOMW75rCm6Mp9w2KxwZE=; b=qEz3MC0HveYTIQCIdnix5bObZPI/ymCNgn1UbFMqGG1nKGWeaM1XA/Bh/Bx6O31t3c FEPRehb5unebonQtPY9XFM9SRckBYOrcKm8g6SuxzVACagVSlyA7GsuVX2A9bEApYEvF DlQih+L386EYdwMWRFuDq3EgYlOUNQryjV8OvS7a+tRrQuEH+PqZtdGI95DhD8FuCS4I lzjrE0tChSUoVm2MkeHOwIoWqNxWjzehaFXFjtIV8L7mP3hTbyxOwQ1cWMF1k4PoWgpk bsv+zZ6/N3VUjiVE2DjKCCq1CiUs+Er5/ldKXXCVkCpF9U+oqcpgKh59YNgm8i4ghUUw 99EA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i190-v6si7752981pge.408.2018.05.14.07.33.32; Mon, 14 May 2018 07:33:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932675AbeENOcR (ORCPT + 99 others); Mon, 14 May 2018 10:32:17 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:35073 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753963AbeENO1l (ORCPT ); Mon, 14 May 2018 10:27:41 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from vladbu@mellanox.com) with ESMTPS (AES256-SHA encrypted); 14 May 2018 17:29:22 +0300 Received: from reg-r-vrt-018-180.mtr.labs.mlnx (reg-r-vrt-018-180.mtr.labs.mlnx [10.213.18.180]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w4EERXLX002750; Mon, 14 May 2018 17:27:34 +0300 From: Vlad Buslov To: netdev@vger.kernel.org Cc: davem@davemloft.net, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, pablo@netfilter.org, kadlec@blackhole.kfki.hu, fw@strlen.de, ast@kernel.org, daniel@iogearbox.net, edumazet@google.com, vladbu@mellanox.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, kliteyn@mellanox.com Subject: [PATCH 05/14] net: sched: always take reference to action Date: Mon, 14 May 2018 17:27:06 +0300 Message-Id: <1526308035-12484-6-git-send-email-vladbu@mellanox.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1526308035-12484-1-git-send-email-vladbu@mellanox.com> References: <1526308035-12484-1-git-send-email-vladbu@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Without rtnl lock protection it is no longer safe to use pointer to tc action without holding reference to it. (it can be destroyed concurrently) Remove unsafe action idr lookup function. Instead of it, implement safe tcf idr check function that atomically looks up action in idr and increments its reference and bind counters. Implement both action search and check using new safe function. Signed-off-by: Vlad Buslov --- net/sched/act_api.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 1331beb..9459cce 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -284,44 +284,38 @@ int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb, } EXPORT_SYMBOL(tcf_generic_walker); -static struct tc_action *tcf_idr_lookup(u32 index, struct tcf_idrinfo *idrinfo) +bool __tcf_idr_check(struct tc_action_net *tn, u32 index, struct tc_action **a, + int bind) { - struct tc_action *p = NULL; + struct tcf_idrinfo *idrinfo = tn->idrinfo; + struct tc_action *p; spin_lock_bh(&idrinfo->lock); p = idr_find(&idrinfo->action_idr, index); + if (p) { + refcount_inc(&p->tcfa_refcnt); + if (bind) + atomic_inc(&p->tcfa_bindcnt); + } spin_unlock_bh(&idrinfo->lock); - return p; + if (p) { + *a = p; + return true; + } + return false; } int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index) { - struct tcf_idrinfo *idrinfo = tn->idrinfo; - struct tc_action *p = tcf_idr_lookup(index, idrinfo); - - if (p) { - *a = p; - return 1; - } - return 0; + return __tcf_idr_check(tn, index, a, 0); } EXPORT_SYMBOL(tcf_idr_search); bool tcf_idr_check(struct tc_action_net *tn, u32 index, struct tc_action **a, int bind) { - struct tcf_idrinfo *idrinfo = tn->idrinfo; - struct tc_action *p = tcf_idr_lookup(index, idrinfo); - - if (index && p) { - if (bind) - atomic_inc(&p->tcfa_bindcnt); - refcount_inc(&p->tcfa_refcnt); - *a = p; - return true; - } - return false; + return __tcf_idr_check(tn, index, a, bind); } EXPORT_SYMBOL(tcf_idr_check); -- 2.7.5