From: Stefano Brivio <sbrivio@redhat.com>
To: Vlad Buslov <vladbu@mellanox.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"jhs@mojatatu.com" <jhs@mojatatu.com>,
"xiyou.wangcong@gmail.com" <xiyou.wangcong@gmail.com>,
"jiri@resnulli.us" <jiri@resnulli.us>,
"davem@davemloft.net" <davem@davemloft.net>,
"ast@kernel.org" <ast@kernel.org>,
"daniel@iogearbox.net" <daniel@iogearbox.net>
Subject: Re: [PATCH net-next 16/17] net: sched: conditionally take rtnl lock on rules update path
Date: Tue, 13 Nov 2018 16:53:07 +0100 [thread overview]
Message-ID: <20181113165307.45987362@redhat.com> (raw)
In-Reply-To: <vbfefbpjd3r.fsf@reg-r-vrt-018-180.mtr.labs.mlnx>
On Tue, 13 Nov 2018 13:58:05 +0000
Vlad Buslov <vladbu@mellanox.com> wrote:
> On Tue 13 Nov 2018 at 13:40, Stefano Brivio <sbrivio@redhat.com> wrote:
> > On Tue, 13 Nov 2018 13:25:52 +0000
> > Vlad Buslov <vladbu@mellanox.com> wrote:
> >
> >> On Tue 13 Nov 2018 at 09:40, Stefano Brivio <sbrivio@redhat.com> wrote:
> >> > Hi Vlad,
> >> >
> >> > On Mon, 12 Nov 2018 09:55:45 +0200
> >> > Vlad Buslov <vladbu@mellanox.com> wrote:
> >> >
> >> >> @@ -179,9 +179,25 @@ static void tcf_proto_destroy_work(struct work_struct *work)
> >> >> rtnl_unlock();
> >> >> }
> >> >>
> >> >> +/* Helper function to lock rtnl mutex when specified condition is true and mutex
> >> >> + * hasn't been locked yet. Will set rtnl_held to 'true' before taking rtnl lock.
> >> >> + * Note that this function does nothing if rtnl is already held. This is
> >> >> + * intended to be used by cls API rules update API when multiple conditions
> >> >> + * could require rtnl lock and its state needs to be tracked to prevent trying
> >> >> + * to obtain lock multiple times.
> >> >> + */
> >> >> +
> >> >> +static void tcf_require_rtnl(bool cond, bool *rtnl_held)
> >> >> +{
> >> >> + if (!*rtnl_held && cond) {
> >> >> + *rtnl_held = true;
> >> >> + rtnl_lock();
> >> >> + }
> >> >> +}
> >> >
> >> > I guess calls to this function are supposed to be serialised. If that's
> >> > the case (which is my tentative understanding so far), I would indicate
> >> > that in the comment.
> >> >
> >> > If that's not the case, you would be introducing a race I guess.
> >> >
> >> > Same applies to tcf_block_release() from 17/17.
> >>
> >> Hi Stefano,
> >>
> >> Thank you for reviewing my code!
> >>
> >> I did not intend for this function to be serialized. First argument to
> >> tcf_require_rtnl() is passed by value, and second argument is always a
> >> pointer to local stack-allocated value of the caller.
> >
> > Yes, sorry, I haven't been terribly clear, that's what I meant by
> > serialised: it won't be called concurrently with the same *rtnl_held.
> >
> > Perhaps the risk that somebody uses it that way is close to zero, so
> > I'm not even too sure this is worth a comment, but if you can come up
> > with a concise way of saying this, that would be nice.
>
> I considered my comment that function "Will set rtnl_held to 'true'
> before taking rtnl lock" as a red flag for caller to not pass pointer to
> a variable that can be accessed concurrently. I guess I can add
> additional sentence to explicitly warn potential users. Or I can just
> move rtnl_held assignment in both functions to be performed while
> holding rtnl mutex. I implemented it the way I did as an overzealous
> optimization, but realistically price of an assignment is negligible in
> this case.
But to make that effective, you would need to protect the read too, and
that makes your optimisation not really overzealous I think.
I'd rather go with an additional comment, if that doesn't become
unreadable.
--
Stefano
next prev parent reply other threads:[~2018-11-14 1:51 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-12 7:55 [PATCH net-next 00/17] Refactor classifier API to work with chain/classifiers without rtnl lock Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 01/17] net: sched: refactor mini_qdisc_pair_swap() to use workqueue Vlad Buslov
2018-11-12 17:28 ` David Miller
2018-11-13 13:13 ` Vlad Buslov
2018-11-13 16:08 ` David Miller
2018-11-12 7:55 ` [PATCH net-next 02/17] net: sched: protect block state with spinlock Vlad Buslov
2018-11-12 17:28 ` David Miller
2018-11-13 10:07 ` Stefano Brivio
2018-11-13 13:28 ` Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 03/17] net: sched: refactor tc_ctl_chain() to use block->lock Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 04/17] net: sched: protect block->chain0 with block->lock Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 05/17] net: sched: traverse chains in block with tcf_get_next_chain() Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 06/17] net: sched: protect chain template accesses with block lock Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 07/17] net: sched: lock the chain when accessing filter_chain list Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 08/17] net: sched: introduce reference counting for tcf proto Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 09/17] net: sched: traverse classifiers in chain with tcf_get_next_proto() Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 10/17] net: sched: refactor tp insert/delete for concurrent execution Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 11/17] net: sched: prevent insertion of new classifiers during chain flush Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 12/17] net: sched: track rtnl lock status when validating extensions Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 13/17] net: sched: extend proto ops with 'put' callback Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 14/17] net: sched: extend proto ops to support unlocked classifiers Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 15/17] net: sched: add flags to Qdisc class ops struct Vlad Buslov
2018-11-12 7:55 ` [PATCH net-next 16/17] net: sched: conditionally take rtnl lock on rules update path Vlad Buslov
2018-11-13 9:40 ` Stefano Brivio
2018-11-13 13:25 ` Vlad Buslov
2018-11-13 13:40 ` Stefano Brivio
2018-11-13 13:58 ` Vlad Buslov
2018-11-13 15:53 ` Stefano Brivio [this message]
2018-11-13 16:57 ` Stefano Brivio
2018-11-12 7:55 ` [PATCH net-next 17/17] net: sched: unlock rules update API Vlad Buslov
2018-11-12 17:30 ` David Miller
2018-11-13 13:46 ` Vlad Buslov
2018-11-14 6:44 ` Jiri Pirko
2018-11-14 16:45 ` Vlad Buslov
2018-11-15 10:20 ` Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181113165307.45987362@redhat.com \
--to=sbrivio@redhat.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=vladbu@mellanox.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).