From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vlad Buslov Subject: [PATCH net-next v2 04/10] net: sched: add helper function to take reference to Qdisc Date: Mon, 17 Sep 2018 10:17:34 +0300 Message-ID: <1537168660-24032-5-git-send-email-vladbu@mellanox.com> References: <1537168660-24032-1-git-send-email-vladbu@mellanox.com> Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, stephen@networkplumber.org, ktkhai@virtuozzo.com, nicolas.dichtel@6wind.com, gregkh@linuxfoundation.org, mark.rutland@arm.com, leon@kernel.org, paulmck@linux.vnet.ibm.com, fw@strlen.de, dsahern@gmail.com, christian@brauner.io, lucien.xin@gmail.com, jakub.kicinski@netronome.com, jbenc@redhat.com, Vlad Buslov To: netdev@vger.kernel.org Return-path: Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:39853 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727440AbeIQMpT (ORCPT ); Mon, 17 Sep 2018 08:45:19 -0400 In-Reply-To: <1537168660-24032-1-git-send-email-vladbu@mellanox.com> Sender: netdev-owner@vger.kernel.org List-ID: Implement function to take reference to Qdisc that relies on rcu read lock instead of rtnl mutex. Function only takes reference to Qdisc if reference counter isn't zero. Intended to be used by unlocked cls API. Signed-off-by: Vlad Buslov Acked-by: Jiri Pirko --- include/net/sch_generic.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index 8a0d1523d11b..9a295e690efe 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -115,6 +115,19 @@ static inline void qdisc_refcount_inc(struct Qdisc *qdisc) refcount_inc(&qdisc->refcnt); } +/* Intended to be used by unlocked users, when concurrent qdisc release is + * possible. + */ + +static inline struct Qdisc *qdisc_refcount_inc_nz(struct Qdisc *qdisc) +{ + if (qdisc->flags & TCQ_F_BUILTIN) + return qdisc; + if (refcount_inc_not_zero(&qdisc->refcnt)) + return qdisc; + return NULL; +} + static inline bool qdisc_is_running(struct Qdisc *qdisc) { if (qdisc->flags & TCQ_F_NOLOCK) -- 2.7.5