Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1659715imm; Wed, 16 May 2018 00:51:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo28tLWZdCUqcmRb8zWzUw1YdVOpHU0J98PH3JlCDDZ6iajsoF81OyTvT96Bnd+a4EjCVoJ X-Received: by 2002:a62:9f15:: with SMTP id g21-v6mr18378949pfe.207.1526457094279; Wed, 16 May 2018 00:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526457094; cv=none; d=google.com; s=arc-20160816; b=X/XfJWNo91kPMPq68DJDqdK0WjNLw3c1PCz+NlJiLveWI6M1FqCuykjNVkw+2F+jTi y5EQ/n2naP8VqW96BFMgWr7oSEHqwQuK9yEAC95/6j2FJbTgZK71OcYH7jSg9gswzIZj /fDMxu64IO7TVu/PJc+pfduBu9t966qMMvDsp+2bnRUu5AOs4XLZkJtluFlepN3HI1QK xxlkxHtDvaBjEYSxgg720TE9DYgN04ug02XqiGPW8YRvsTsrymQSLhJ+FcjLjLL074P8 ypuJx4tbz5Kym4ffhqNYZ2BYdO7Tga0P+qHBcC2175at2KooxwpFMnVlAif55tULmxHC RRyg== 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=bA+E7RmXN1VJROZfyZcNOtO4zZxOOyntaSbLPM9GIuU=; b=R8s5x0cj5gMBzn/uPvAIzNnqrrO9LoLMUyyb1dmO7znHd7oOXNYVzRs48bJ23ZX4pS IjD3Ss25zIz9m+rrsq2TEHfSy71QKtvqS4G5PfkOG5QQtTt5fX1tbzMMAT4lkyLMu2jG //UppbCNCsmhBqoSfxoPVpUsAVuSUCSabv7PJbcplg8Q2lVoFaed3Sy90CajlPz44gfe lkzBHABbG91OWEATQZEE9hcuKJzEuNPj8o6QhYWUtd0nRVzp0Q271qqi2TOW6ie1w3KX ISS2ZUR9zkf5Iry2q1gM2ddaog9KHavYbdB3DOcQvTtS63kAPikfl9bg22TAPm7CXAgv 5bGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=dMbqKxbs; 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 p5-v6si1880254plk.537.2018.05.16.00.51.19; Wed, 16 May 2018 00:51:34 -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=dMbqKxbs; 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 S1752749AbeEPHuG (ORCPT + 99 others); Wed, 16 May 2018 03:50:06 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:38322 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752730AbeEPHuD (ORCPT ); Wed, 16 May 2018 03:50:03 -0400 Received: by mail-wr0-f196.google.com with SMTP id 94-v6so2704822wrf.5 for ; Wed, 16 May 2018 00:50:02 -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=bA+E7RmXN1VJROZfyZcNOtO4zZxOOyntaSbLPM9GIuU=; b=dMbqKxbs5qfWmDJON7CgcH8mPqSzz3OUcKq4LJ+Uc47a5XU1CLxPeVNqKmev+YH2HT 8ANM7bquEHY2XtSfn2MAwFTMj7L69IJXzDbdSvkgYpSMHxJO2POeHBVs/1LWyiyEcBLb lG6UuDXAtpz2tfPuzYedgBKxrIttAfXqf5hLahpTPXBoD0Ew2Nuph8FFDNMYAtqpzGA+ 6wjQxC8fr2JhOXa5BC5J/V/DPXj1OBrc091G+H7YjKPs7A07ebVuuDuTHsguobAnIWZX h7OjqFFeWsIb3/kqIlt7UInsdSWu/3GsJZufU0+NTZyGupyXzvHrR8tsS6YzTPDqBF2P jcsQ== 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=bA+E7RmXN1VJROZfyZcNOtO4zZxOOyntaSbLPM9GIuU=; b=AxFtQXfKeH53ktqQ8m6kG+hDE1QZ4p5/ngPC5oES9KcsqpDfsRlA7iNL0Hp1c6JpI0 SL+tTQPeVU2dCErgHT5OZ+Q5OontxoAwFMB/LPWGIvlPIrTN2LfAjx0bSlzybBxm3YKX qwNyqPt3we+kFZiIp/SJs7HYdbVcEjmhaHR6jvgBBJ3L251sqwql0vFw3OTHMKv8Vpkk Pw+LBZBXnsAf1jRnglSbHAm0G6yaHvQCUCMC7or7ckOa0RFbjnmfp/S2zE3bDeIlgaL4 rFPRQ192fTYNUFj1dCzcoU92H+DLnoHnZZXd92AdmGQ4qnmDSEyibNpzjevTBX+z2Wgt 28kg== X-Gm-Message-State: ALKqPwfUN5HLWZtE4gUvT+0pwzq7kC7O9NnOxStkHl2kxJVswGGUobh0 9TrYOlgq4emn4c+k7NLNg3p4Bg== X-Received: by 2002:adf:a690:: with SMTP id t16-v6mr13303201wrc.1.1526457001643; Wed, 16 May 2018 00:50:01 -0700 (PDT) Received: from localhost (ip-94-113-127-8.net.upcbroadband.cz. [94.113.127.8]) by smtp.gmail.com with ESMTPSA id m69-v6sm4418828wmd.47.2018.05.16.00.50.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 May 2018 00:50:01 -0700 (PDT) Date: Wed, 16 May 2018 09:50:00 +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 10/14] net: sched: extend act API for lockless actions Message-ID: <20180516075000.GC1972@nanopsycho> References: <1526308035-12484-1-git-send-email-vladbu@mellanox.com> <1526308035-12484-11-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-11-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:11PM CEST, vladbu@mellanox.com wrote: >Implement new action API function to atomically delete action with >specified index and to atomically insert unique action. These functions are >required to implement init and delete functions for specific actions that >do not rely on rtnl lock. > >Signed-off-by: Vlad Buslov >--- > include/net/act_api.h | 2 ++ > net/sched/act_api.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 47 insertions(+) > >diff --git a/include/net/act_api.h b/include/net/act_api.h >index a8c8570..bce0cf1 100644 >--- a/include/net/act_api.h >+++ b/include/net/act_api.h >@@ -153,7 +153,9 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, > struct tc_action **a, const struct tc_action_ops *ops, > int bind, bool cpustats); > void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a); >+void tcf_idr_insert_unique(struct tc_action_net *tn, struct tc_action *a); > >+int tcf_idr_find_delete(struct tc_action_net *tn, u32 index); > int __tcf_idr_release(struct tc_action *a, bool bind, bool strict); > > static inline int tcf_idr_release(struct tc_action *a, bool bind) >diff --git a/net/sched/act_api.c b/net/sched/act_api.c >index 2772276e..a5193dc 100644 >--- a/net/sched/act_api.c >+++ b/net/sched/act_api.c >@@ -330,6 +330,41 @@ bool tcf_idr_check(struct tc_action_net *tn, u32 index, struct tc_action **a, > } > EXPORT_SYMBOL(tcf_idr_check); > >+int tcf_idr_find_delete(struct tc_action_net *tn, u32 index) >+{ >+ struct tcf_idrinfo *idrinfo = tn->idrinfo; >+ struct tc_action *p; >+ int ret = 0; >+ >+ spin_lock_bh(&idrinfo->lock); Why "_bh" is needed here? >+ p = idr_find(&idrinfo->action_idr, index); >+ if (!p) { >+ spin_unlock(&idrinfo->lock); >+ return -ENOENT; >+ } >+ >+ if (!atomic_read(&p->tcfa_bindcnt)) { >+ if (refcount_dec_and_test(&p->tcfa_refcnt)) { >+ struct module *owner = p->ops->owner; >+ >+ WARN_ON(p != idr_remove(&idrinfo->action_idr, >+ p->tcfa_index)); >+ spin_unlock_bh(&idrinfo->lock); >+ >+ tcf_action_cleanup(p); >+ module_put(owner); >+ return 0; >+ } >+ ret = 0; >+ } else { >+ ret = -EPERM; I wonder if "-EPERM" is the best error code for this... >+ } >+ >+ spin_unlock_bh(&idrinfo->lock); >+ return ret; >+} >+EXPORT_SYMBOL(tcf_idr_find_delete); >+ > int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, > struct tc_action **a, const struct tc_action_ops *ops, > int bind, bool cpustats) >@@ -407,6 +442,16 @@ void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a) > } > EXPORT_SYMBOL(tcf_idr_insert); > >+void tcf_idr_insert_unique(struct tc_action_net *tn, struct tc_action *a) >+{ >+ struct tcf_idrinfo *idrinfo = tn->idrinfo; >+ >+ spin_lock_bh(&idrinfo->lock); >+ WARN_ON(idr_replace(&idrinfo->action_idr, a, a->tcfa_index)); Under which condition this WARN_ON is hit? >+ spin_unlock_bh(&idrinfo->lock); >+} >+EXPORT_SYMBOL(tcf_idr_insert_unique); >+ > void tcf_idrinfo_destroy(const struct tc_action_ops *ops, > struct tcf_idrinfo *idrinfo) > { >-- >2.7.5 >