Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4436976imm; Mon, 14 May 2018 07:33:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpDQtk7MZGJB7zaYd2DqLwpl/q2Bp5wmxChCG2q/AMt6MGvCgZvhTeCRrYZgwwkjM/7RIj/ X-Received: by 2002:a65:640e:: with SMTP id a14-v6mr8984903pgv.406.1526308433509; Mon, 14 May 2018 07:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526308433; cv=none; d=google.com; s=arc-20160816; b=AuiOGF1UORXFn3ntbqHT0oAy+5ZBwvcniIrM0MyOtEzaehs5Iw7XQ+LbOWTdhWz0gV /TEXu6YuHSzrI/JtDsq8p5JJlBHeqOArmmPTpugRbSj2ntoThbbf69oo0ui06yJ44KDa D6sJnWVU4m7Fzk1WxSgWaUfqT6JsxUBCWXcYFy/hDTNLDJvUTCYJewTfDff88sE3VuO4 ziBZz6mZfXg3ltTVwupSmO9digKIz8eNoaPs8k2iWSdUL8vYlhMfn+wdI8DdE520DCS4 i4ZLx1nJ7Wau/JUzpcIUrtTAttWZ1/DJmyhgvHY8L1ArFXQgA+4vB1HD9yM/2LQvIGmO v5uw== 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=AfwmKGk+mWx5YiQ30N8RQgZAHwFKBiUXSWZNpNpRKk0=; b=duwzOJ8n6Gs3X2EuV/B/7bdW8BDPq/Q11WaNoQuhk8dEBg36v/9Rib+tSulUKiuBsy TawR/4nDRdns++WhxJEsLEJToLvCyCdu7+NEWmw8/s4GOdAxd9AdpbQnSpjC8+O1oBGv W03c5M7KN5IKLmIBCfhwErMLm625aiCtM589L5dhjZfFuL7Xnoy6B33+gX8io4/Dy3zT uy6O2FlRrof5BPBq7cVBpol2hVXhrIUK3pL1xmoE6nnTI6OHrz4SzculjO5r0KiOqp+6 c3UTSUQ0HyElzZYMF2qmCzcKQctrdJYYW3WBRnyuf0yEIE2y7g1npN3+qAeiFOPWGKs0 y0dg== 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 w27-v6si7695638pgc.645.2018.05.14.07.33.39; Mon, 14 May 2018 07:33:53 -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 S932601AbeENOaA (ORCPT + 99 others); Mon, 14 May 2018 10:30:00 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:35106 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753973AbeENO1l (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:23 +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 w4EERXLZ002750; Mon, 14 May 2018 17:27:35 +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 07/14] net: sched: use reference counting action init Date: Mon, 14 May 2018 17:27:08 +0300 Message-Id: <1526308035-12484-8-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 Change action API to assume that action init function always takes reference to action, even when overwriting existing action. This is necessary because action API continues to use action pointer after init function is done. At this point action becomes accessible for concurrent modifications so user must always hold reference to it. Implement helper put list function to atomically release list of actions after action API init code is done using them. Signed-off-by: Vlad Buslov --- net/sched/act_api.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/net/sched/act_api.c b/net/sched/act_api.c index d324a4c..3f02cd1 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -592,6 +592,18 @@ static int tcf_action_put(struct tc_action *p) return __tcf_action_put(p, false); } +static void tcf_action_put_lst(struct list_head *actions) +{ + struct tc_action *a, *tmp; + + list_for_each_entry_safe(a, tmp, actions, list) { + const struct tc_action_ops *ops = a->ops; + + if (tcf_action_put(a)) + module_put(ops->owner); + } +} + int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int bind, int ref) { @@ -799,17 +811,6 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, return ERR_PTR(err); } -static void cleanup_a(struct list_head *actions, int ovr) -{ - struct tc_action *a; - - if (!ovr) - return; - - list_for_each_entry(a, actions, list) - refcount_dec(&a->tcfa_refcnt); -} - int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, struct nlattr *est, char *name, int ovr, int bind, struct list_head *actions, size_t *attr_size, bool unlocked, @@ -834,17 +835,10 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, } act->order = i; sz += tcf_action_fill_size(act); - if (ovr) - refcount_inc(&act->tcfa_refcnt); list_add_tail(&act->list, actions); } *attr_size = tcf_action_full_attrs_size(sz); - - /* Remove the temp refcnt which was necessary to protect against - * destroying an existing action which was being replaced - */ - cleanup_a(actions, ovr); return 0; err: @@ -1196,8 +1190,7 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, return ret; } err: - if (event != RTM_GETACTION) - tcf_action_destroy(&actions, 0); + tcf_action_put_lst(&actions); return ret; } @@ -1239,8 +1232,11 @@ static int tcf_action_add(struct net *net, struct nlattr *nla, &attr_size, false, extack); if (ret) return ret; + ret = tcf_add_notify(net, n, &actions, portid, attr_size, extack); + if (ovr) + tcf_action_put_lst(&actions); - return tcf_add_notify(net, n, &actions, portid, attr_size, extack); + return ret; } static u32 tcaa_root_flags_allowed = TCA_FLAG_LARGE_DUMP_ON; -- 2.7.5