[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200921112218.GB2139@willie-the-truck>
Date: Mon, 21 Sep 2020 12:22:19 +0100
From: Will Deacon <will@...nel.org>
To: peterz@...radead.org
Cc: David Howells <dhowells@...hat.com>,
Kees Cook <keescook@...omium.org>,
Xiaoming Ni <nixiaoming@...wei.com>,
David Windsor <dwindsor@...il.com>,
Hans Liljestrand <ishkamiel@...il.com>,
Elena Reshetova <elena.reshetova@...el.com>,
Paul Moore <paul@...l-moore.com>, edumazet@...gle.com,
paulmck@...nel.org, shakeelb@...gle.com,
James Morris <jamorris@...ux.microsoft.com>,
alex.huangjianhui@...wei.com, dylix.dailei@...wei.com,
chenzefeng2@...wei.com, linux-kernel@...r.kernel.org
Subject: Re: [RFC][PATCH] locking/refcount: Provide __refcount API to obtain
the old value
On Wed, Jul 29, 2020 at 01:11:20PM +0200, peterz@...radead.org wrote:
> On Tue, Jul 28, 2020 at 11:56:38AM +0100, David Howells wrote:
> > Peter Zijlstra <peterz@...radead.org> wrote:
> >
> > > > Please do not _undo_ the changes; just add the API you need.
> > >
> > > add_return and sub_return are horrible interface for refcount, which is
> > > the problem.
> > >
> > > If you meant: refcount_dec(), but want the old value for tracing, you
> > > want a different ordering than if you wanted to do
> > > refcount_dec_and_test(); dec_return can't know this.
> > >
> > > David, would something like a __refcount_*() API work where there is a
> > > 3rd argument (int *), which, if !NULL, will be assigned the old value?
> >
> > That would be fine, though the number needs to be something I can interpret
> > easily when looking through the traces. It would also be okay if there was an
> > interpretation function that I could use in the trace point when setting the
> > variable.
>
> I'm not entirely sure what you mean with interpret, provided you don't
> trigger a refcount fail, the number will be just what you expect and
> would get from refcount_read(). If you do trigger a fail, you'll get a
> negative value.
>
> How's the below? I didn't provide __refcount versions for the external
> functions, I suppose that can be done too, but wondered if you really
> needed those.
It looks like this didn't go anywhere, but I'm supportive of the general
idea if it's useful to somebody. The only part I find a bit grotty is that
we end up introducing a bunch of redundancy in some of the new functions,
e.g.:
> @@ -219,9 +235,14 @@ static inline void refcount_add(int i, r
> *
> * Return: true if the increment was successful, false otherwise
> */
> +static inline __must_check bool __refcount_inc_not_zero(refcount_t *r, int *oldp)
> +{
> + return __refcount_add_not_zero(1, r, oldp);
> +}
Where returning both a bool to indicate whether the old value was zero
and also the old value itself is a bit OTT.
Will
Powered by blists - more mailing lists