Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1722374imm; Wed, 16 May 2018 01:58:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoojN0EKWCERnOBI4ZgEzN7tjtGb6Hl596owhfKXsTQtBV3rU8TL5SOkWbfpen2VwbVgv0S X-Received: by 2002:a17:902:8692:: with SMTP id g18-v6mr19244plo.152.1526461117602; Wed, 16 May 2018 01:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526461117; cv=none; d=google.com; s=arc-20160816; b=HesjbawZT9TORyHfrXuqO14Pd0PZ8CEYZLdySd84JGRonAj88q7JzkAqdJeA/5/LrI MN2ZTlaVGoZZgYwfBc2uxqOlXCQ9qkQTET+6izWq1zbw/Nc4cf2go8zJg1JQXOnGCW9j aOzqjod2HwCYXYyuXt/wcXP2qX7Kw0jV38XbqBJYOQgEJTv8ZrCDEJOizixqUNd24pTJ 5Qh5DO6DPHFxY2aTsNTIOQcfh4b9UH8ZXPx+TNBL/j1ETUaSgH6wgJeH2zVo4P/Snxyl TcfX33mnGRmocKRbtKWvI2J/ntdVv3/gG4KCy4BQvZ9gcI3slAOUUQ6UYBd0Y/CG8RKI W+Dw== 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=nnA0HQD7T033dbYafd3glCyfXtCmiLKZNsJP9bctpmI=; b=dYPZg2hCSbD2Ccd3FK7Bybk4jJ8Gdb2Bh9InFB/jZtdkr5zpGDUApmtZWqRCwh6JKX dU1RDMmEcDeDTm4yZ/vibp1YVP86dnP914wIRHE44T/Ogwkyz0aArW3puui62Ctu9S1u 3I60+yO9ydtLDyIfgwaM9ezslMIs8Q4ERgkeMcLW+weLghduGsLhg86h8LY1a9WKETVE b4djlGR1fpbRKFt1Dj7v3N27hmrqFNENpAB22A8w3sZCqFJ8RyO4EFbk1iQFBHfWbHba rqMyEFoeRB3npFvrTSZ2UhmRKSnC3Vmf1AuorAV4iLr0Uzrdu+cSwsGws+kAWFKGax2o 2HlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=V+MIJjXa; 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 w13-v6si2064220plq.413.2018.05.16.01.58.23; Wed, 16 May 2018 01:58:37 -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=V+MIJjXa; 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 S1752321AbeEPI4f (ORCPT + 99 others); Wed, 16 May 2018 04:56:35 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:52582 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751844AbeEPI4b (ORCPT ); Wed, 16 May 2018 04:56:31 -0400 Received: by mail-wm0-f68.google.com with SMTP id w194-v6so17967wmf.2 for ; Wed, 16 May 2018 01:56:30 -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=nnA0HQD7T033dbYafd3glCyfXtCmiLKZNsJP9bctpmI=; b=V+MIJjXawKvE3TdJ6xDucEqdYB0HTdPftVvKjKb7uWYAxMCNp5AJ6Z+tuooYOVXD/S PDSDSw92UPZX6Pmajiqw5QXPRtGT24HsqCh672UWLje+s36VnuFZdNfSI/pyJFs6mpY2 0M9YqBT6MliOXfq8PnNbzP2JOJeYftfin/bdSqQclDUqnm1bT4AIlPpX2ps1crRFzk84 ps4hMkSyupEenQ7E60xZGqr5rONTUbpSD8gywSTKfFBXnp4ePf/4uSgftVjG4I+SzVkt +E+KKZxJiHIwq8rJhoPhXrMOCXNlQ22/QKtEUjuVDwVpLP4Ui7PE7aNAOPFcuTE8aOJr aljg== 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=nnA0HQD7T033dbYafd3glCyfXtCmiLKZNsJP9bctpmI=; b=hMPsoZBYphnlwNdEkwBNzUH9mbX+Jr5OxaUAc5dK1Uz06dCjkm2NLwZ6yoc9NBlm8F 0vFzKUbGJJsDjnDQi6jHBCFdQ/5H6lX0T5oJhe1XZY3B4toLIsucCTA4n3Vy01NFadDs rgNRyUfgE2XKc1OyNBgHKYtGwHzyAiHTEDTCQGlkgCHtKQ1GoOTUaj3fM6mnam6c7t0K MNEC0iUsRPUPZeXNQJHao1v1tmdhW1PIxnMzJ7F2+0y19Chzlht1Q+Mbh6Zp6dzwEI0P Dpc3CI4WhnMfe0wll4nI+rAZG7fRTM28GJex4Jrej0aSGAQvh9SpzlptfT4QqVc4WV1t KO0A== X-Gm-Message-State: ALKqPwd/SKMCH6i4H04ALEYBpN3WMSz6l1MM2seyeafdfyIAUZAYdt+3 WvSLQiYWce2iCrBRefqwrQEFNQ== X-Received: by 2002:a1c:c588:: with SMTP id v130-v6mr874690wmf.135.1526460989870; Wed, 16 May 2018 01:56:29 -0700 (PDT) Received: from localhost (ip-94-113-127-8.net.upcbroadband.cz. [94.113.127.8]) by smtp.gmail.com with ESMTPSA id t189-v6sm2049445wmf.22.2018.05.16.01.56.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 May 2018 01:56:29 -0700 (PDT) Date: Wed, 16 May 2018 10:56:28 +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: <20180516085628.GE1972@nanopsycho> References: <1526308035-12484-1-git-send-email-vladbu@mellanox.com> <1526308035-12484-11-git-send-email-vladbu@mellanox.com> <20180516075000.GC1972@nanopsycho> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, May 16, 2018 at 10:16:13AM CEST, vladbu@mellanox.com wrote: > >On Wed 16 May 2018 at 07:50, Jiri Pirko wrote: >> 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? > >Original idr remove function used _bh version so I used it here as well. >As I already replied to your previous question about idrinfo lock usage, >I don't see any particular reason for locking with _bh at this point. >I've contacted the author(Chris Mi) and he said that he just preserved >locking the same way as it was before he changed hash table to idr for >action lookup. > >You want me to do standalone patch that cleans up idrinfo locking? Yes please. You can send it separately, not as a part of this patchset. > >> >> >>>+ 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... > >This is what original code returned so I decided to preserve >compatibility. Okay. > >> >> >>>+ } >>>+ >>>+ 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? > >When idr replace returns non-NULL pointer, which means that somehow >concurrent insertion of action with same index has happened and we are >leaking memory. Is that possible to happen? Meaning, can I as a user cause this by doing something in a wrong/unexpected way? > >By the way I'm still not sure if having this insert unique function is >warranted or I should just add WARN to regular idr insert. What is your >opinion on this? I have to check where you use this. > >> >> >>>+ 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 >>> >