lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 18 Dec 2019 11:49:55 -0600
From:   Dennis Zhou <dennis@...nel.org>
To:     Tejun Heo <tj@...nel.org>
Cc:     Jens Axboe <axboe@...nel.dk>,
        Pavel Begunkov <asml.silence@...il.com>,
        io-uring@...r.kernel.org, linux-kernel@...r.kernel.org,
        Dennis Zhou <dennis@...nel.org>,
        Christoph Lameter <cl@...ux.com>
Subject: Re: [PATCH 1/2] pcpu_ref: add percpu_ref_tryget_many()

On Wed, Dec 18, 2019 at 08:26:42AM -0800, Tejun Heo wrote:
> (cc'ing Dennis and Christoph and quoting whole body)
> 
> Pavel, can you please cc percpu maintainers on related changes?
> 
> The patch looks fine to me.  Please feel free to add my acked-by.
> 
> On Tue, Dec 17, 2019 at 04:42:59PM -0700, Jens Axboe wrote:
> > CC Tejun on this one. Looks fine to me, and matches the put path.
> > 
> > 
> > On 12/17/19 3:28 PM, Pavel Begunkov wrote:
> > > Add percpu_ref_tryget_many(), which works the same way as
> > > percpu_ref_tryget(), but grabs specified number of refs.
> > > 
> > > Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
> > > ---
> > >  include/linux/percpu-refcount.h | 24 ++++++++++++++++++++----
> > >  1 file changed, 20 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
> > > index 390031e816dc..19079b62ce31 100644
> > > --- a/include/linux/percpu-refcount.h
> > > +++ b/include/linux/percpu-refcount.h
> > > @@ -210,15 +210,17 @@ static inline void percpu_ref_get(struct percpu_ref *ref)
> > >  }
> > >  
> > >  /**
> > > - * percpu_ref_tryget - try to increment a percpu refcount
> > > + * percpu_ref_tryget_many - try to increment a percpu refcount
> > >   * @ref: percpu_ref to try-get
> > > + * @nr: number of references to get
> > >   *
> > >   * Increment a percpu refcount unless its count already reached zero.
> > >   * Returns %true on success; %false on failure.

Minor nit: would be nice to change this so the two don't have identical
comments. (eg: Increment a percpu refcount by @nr unless...)
> > >   *
> > >   * This function is safe to call as long as @ref is between init and exit.
> > >   */
> > > -static inline bool percpu_ref_tryget(struct percpu_ref *ref)
> > > +static inline bool percpu_ref_tryget_many(struct percpu_ref *ref,
> > > +					  unsigned long nr)
> > >  {
> > >  	unsigned long __percpu *percpu_count;
> > >  	bool ret;
> > > @@ -226,10 +228,10 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref)
> > >  	rcu_read_lock();
> > >  
> > >  	if (__ref_is_percpu(ref, &percpu_count)) {
> > > -		this_cpu_inc(*percpu_count);
> > > +		this_cpu_add(*percpu_count, nr);
> > >  		ret = true;
> > >  	} else {
> > > -		ret = atomic_long_inc_not_zero(&ref->count);
> > > +		ret = atomic_long_add_unless(&ref->count, nr, 0);
> > >  	}
> > >  
> > >  	rcu_read_unlock();
> > > @@ -237,6 +239,20 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref)
> > >  	return ret;
> > >  }
> > >  
> > > +/**
> > > + * percpu_ref_tryget - try to increment a percpu refcount
> > > + * @ref: percpu_ref to try-get
> > > + *
> > > + * Increment a percpu refcount unless its count already reached zero.
> > > + * Returns %true on success; %false on failure.
> > > + *
> > > + * This function is safe to call as long as @ref is between init and exit.
> > > + */
> > > +static inline bool percpu_ref_tryget(struct percpu_ref *ref)
> > > +{
> > > +	return percpu_ref_tryget_many(ref, 1);
> > > +}
> > > +
> > >  /**
> > >   * percpu_ref_tryget_live - try to increment a live percpu refcount
> > >   * @ref: percpu_ref to try-get
> > > 
> > 
> > 
> > -- 
> > Jens Axboe
> > 
> 
> -- 
> tejun

Acked-by: Dennis Zhou <dennis@...nel.org>

Thanks,
Dennis

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ