Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4643681imm; Mon, 14 May 2018 10:26:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq08uiIHsa1iaUhqhWy747izVUDNO5/n3GohBHqo/ORub8BikfB0fVHXlsajgCGZO/WO6qe X-Received: by 2002:a17:902:ba93:: with SMTP id k19-v6mr10504943pls.379.1526318781698; Mon, 14 May 2018 10:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526318781; cv=none; d=google.com; s=arc-20160816; b=NSA6ViaY+BCC5DrzGmmml5LD95Ffx7o+zN5dJN2OoFmKR7NTBmsTsTnWBe0uM2YDvg CQFm1HT0tPauyXkvQM84QhIxFmB88/RPx6bNfHlQ5NlzE4hkwih9SNULpl+Ck0sNSn6E VBGJD3YI7faABWHiLY+Bgh4DCeEYmaVz4eFn4+h+s78n95e0bcOXFF8XhD/NcM4f4bd1 YKbEacGLBenjFLxdnb5NsiLWJ1hx2XSEpYu7BMkGK+DEky4YBRYRypWOb3911fHpkFou AVhhpbdqXFXWwcauWKLZaDIjXyv2n76YztKqRXKUgehBOxe8ruKyUfaz/5dhPEJUROPD ZfAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=n48e5ebLqp2vn4P42HatLkXDtC8GrJewoTX9ME1m9oQ=; b=KNBqVayiKkj3gkp25wzuOCachB7aoTqD7s8O8kogCNpaYAboO9ci6Vr+PdIY/+JHxk P+RF83Dk8mHmhEtJfLQLg2/anmmpu/zgCwjJ585JJiJthf145D7LpSkFlerO1Ek9d6A7 8qqlLY9gEiBtutHxxFwjPIrgYMLoCpQzA4kUf1/XeIB+HBETVzrPGJ397nam0KXNBQIE oDvXPdXOS5p/mhf1aZ30WjnDPLNVtPRqRq+HT1RzOKi0XRJs88NGGwWC9E1OrstPWSev gb9bcjEC0+qXqeM4SOd9v4gDkMMl8Ut4wjDdtXZTgfGkfT3bggPpzFNKNKZ2e1SEO7T6 SGrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=PML+BOp0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o185-v6si1197880pga.274.2018.05.14.10.26.07; Mon, 14 May 2018 10:26:21 -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; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=PML+BOp0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932900AbeENQXG (ORCPT + 99 others); Mon, 14 May 2018 12:23:06 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33654 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932883AbeENQXE (ORCPT ); Mon, 14 May 2018 12:23:04 -0400 Received: by mail-wr0-f195.google.com with SMTP id o4-v6so13009762wrm.0 for ; Mon, 14 May 2018 09:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=n48e5ebLqp2vn4P42HatLkXDtC8GrJewoTX9ME1m9oQ=; b=PML+BOp0gKzPNf108oW9SPbHZe1A/TXE9nGviqStRhQD+xlDuDoJT111OIKtZnBIlS WDs4ZDoTJCNuEdF3dwLSaRiQnVLFfuQA/uUhAYFVbZx60augPe2bMlx6YI65zX5RUuad sBKBxLt5xEGGBD7kSiwoBbCwy4P/Rfr16diJxPUWd0EoNOiaFMnFjTLwaIYvIegUP3eo X/UjTmnoz+xxmnkgiZO9FHjx0cjkyYWZrYUS/Rp2BwZ5CeL3wYv59CZ8A63wX2Hx/Qsx iXy7k9b/QYhXYTAsaYacUBYjRSKGNqfr099r1umG7+kRp1oVoVEq4jMsV82BoA+Cv5+O uX5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=n48e5ebLqp2vn4P42HatLkXDtC8GrJewoTX9ME1m9oQ=; b=Bg7wP0xmzcKjYyRoAQu3qNB1MIHUGFqdEzyCZwKTPnqTs4hq1GuNwJN29jUq3MRL7W 6Wx2pUCF7jQtEUURJRm90sWiWBSTT6M94rtkf07DSXWqSJSZkWd6oXOvjy8udIDNmMeI NkZWshrf9FhmLLSf7hw9md0lJnaNyJLt0v7Koov1Esnin0ZXi3wdg5GerlkWnqSkEaza jPDqQrkr8DOH1yh8ado/oNGaSNw3GE6Vh0Dp4pJFBaKuLuExm2kYvWwntazff2tVc6za hWr4ulUlrI+RMAxLJGKdG9mtSq61TStcqVUdOwiP6iHDqjDFTYlHDdE+K8usCZC7Yvoa 8Iww== X-Gm-Message-State: ALKqPwdzgbzU7u5/zVZUxMnaAYDMpTSaqKuRr1OIM2e5quvu2DKIMZlE BPtE3wS4EKY3kHFOrInlYPbTSA== X-Received: by 2002:adf:b0c1:: with SMTP id j1-v6mr7173279wra.3.1526314983071; Mon, 14 May 2018 09:23:03 -0700 (PDT) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id e7-v6sm12475947wrn.88.2018.05.14.09.23.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 09:23:02 -0700 (PDT) Date: Mon, 14 May 2018 18:23:01 +0200 From: Jiri Pirko To: Vlad Buslov Cc: netdev@vger.kernel.org, davem@davemloft.net, jhs@mojatatu.com, xiyou.wangcong@gmail.com, pablo@netfilter.org, kadlec@blackhole.kfki.hu, fw@strlen.de, ast@kernel.org, daniel@iogearbox.net, edumazet@google.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, kliteyn@mellanox.com Subject: Re: [PATCH 05/14] net: sched: always take reference to action Message-ID: <20180514162301.GC2134@nanopsycho.orion> References: <1526308035-12484-1-git-send-email-vladbu@mellanox.com> <1526308035-12484-6-git-send-email-vladbu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1526308035-12484-6-git-send-email-vladbu@mellanox.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Mon, May 14, 2018 at 04:27:06PM CEST, vladbu@mellanox.com wrote: >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); Why "_bh" variant is necessary here? > 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); [...]