Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1642713

Re: [RFC 04/10] kmod: provide wrappers for kmod_concurrent inc/dec

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From "Luis R. Rodriguez" <mcgrof@kernel.org>
Newsgroups linux.kernel
Subject Re: [RFC 04/10] kmod: provide wrappers for kmod_concurrent inc/dec
Date Tue, 16 May 2017 20:10:02 +0200
Message-ID <tHP50-vb-17@gated-at.bofh.it> (permalink)
References <sMbVv-188-1@gated-at.bofh.it> <sMcRA-1I2-21@gated-at.bofh.it> <sMdDX-2iT-15@gated-at.bofh.it> <sMe70-2Kc-15@gated-at.bofh.it> <sODDX-5NV-13@gated-at.bofh.it> <sOVKy-RH-21@gated-at.bofh.it> <sY9Oi-4Tu-21@gated-at.bofh.it> <sYxnz-2Us-19@gated-at.bofh.it>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.6.0 (2016-04-01)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 58
Organization linux.* mail to news gateway
X-Original-Cc Petr Mladek <pmladek@suse.com>, Kees Cook <keescook@chromium.org>, Peter Zijlstra <peterz@infradead.org>, shuah@kernel.org, Jessica Yu <jeyu@redhat.com>, Rusty Russell <rusty@rustcorp.com.au>, "Eric W. Biederman" <ebiederm@xmission.com>, Dmitry Torokhov <dmitry.torokhov@gmail.com>, Arnaldo Carvalho de Melo <acme@redhat.com>, Jonathan Corbet <corbet@lwn.net>, martin.wilck@suse.com, Michal Marek <mmarek@suse.com>, hare@suse.com, rwright@hpe.com, Jeff Mahoney <jeffm@suse.com>, DSterba@suse.com, fdmanana@suse.com, neilb@suse.com, Guenter Roeck <linux@roeck-us.net>, rgoldwyn@suse.com, subashab@codeaurora.org, Heinrich Schuchardt <xypron.glpk@gmx.de>, Aaron Tomlin <atomlin@redhat.com>, mbenes@suse.cz, "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>, Dan Williams <dan.j.williams@intel.com>, Josh Poimboeuf <jpoimboe@redhat.com>, "David S. Miller" <davem@davemloft.net>, Ingo Molnar <mingo@redhat.com>, Andrew Morton <akpm@linux-foundation.org>, Linus Torvalds <torvalds@linux-foundation.org>, linux-kselftest@vger.kernel.org, "linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>, LKML <linux-kernel@vger.kernel.org>
X-Original-Date Tue, 16 May 2017 20:02:17 +0200
X-Original-Message-ID <20170516180217.GG17314@wotan.suse.de>
X-Original-References <20161208184801.1689-1-mcgrof@kernel.org> <20161208194824.2532-1-mcgrof@kernel.org> <CAGXu5j+L4DpHC22NSk8uxpLUQxKYwZQ1AE+zdEJ6nwAm4Sv6JA@mail.gmail.com> <20161208210859.GZ1402@wotan.suse.de> <20161215124625.GA14324@pathway.suse.cz> <20161216080500.GE13946@wotan.suse.de> <20170110185710.GG13946@wotan.suse.de> <20170111200857.GR13946@wotan.suse.de>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1642713

Show key headers only | View raw


On Wed, Jan 11, 2017 at 09:08:57PM +0100, Luis R. Rodriguez wrote:
> On Tue, Jan 10, 2017 at 07:57:10PM +0100, Luis R. Rodriguez wrote:
> > On Fri, Dec 16, 2016 at 09:05:00AM +0100, Luis R. Rodriguez wrote:
> > > On Thu, Dec 15, 2016 at 01:46:25PM +0100, Petr Mladek wrote:
> > > > On Thu 2016-12-08 22:08:59, Luis R. Rodriguez wrote:
> > > > > On Thu, Dec 08, 2016 at 12:29:42PM -0800, Kees Cook wrote:
> > > > > > On Thu, Dec 8, 2016 at 11:48 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote:
> > > > > > > +       if (atomic_read(&kmod_concurrent) < max_modprobes)
> > > > > > > +               return 0;
> > > > > > > +       atomic_dec(&kmod_concurrent);
> > > > > > > +       return -ENOMEM;
> > > > > > > +}
> > > > > > > +
> > > > > > > +static void kmod_umh_threads_put(void)
> > > > > > > +{
> > > > > > > +       atomic_dec(&kmod_concurrent);
> > > > > > > +}
> > > > > > 
> > > > > > Can you use a kref here instead? We're trying to kill raw use of
> > > > > > atomic_t for reference counting...
> > > > > 
> > > > > That's a much broader functional change than I was looking for, but I am up for
> > > > > it. Can you describe the benefit of using kref you expect or why this is an
> > > > > ongoing crusade? Since its a larger functional change how about doing this
> > > > > change later, and we can test impact with the tress test driver. In theory if
> > > > > there are benefits can't we add a test case to prove the gains?
> > > > 
> > > > Kees probably refers to the kref improvements that Peter Zijlstra
> > > > is working on, see
> > > > https://lkml.kernel.org/r/20161114174446.832175072@infradead.org
> > > > 
> > > > The advantage is that the new refcount API handles over and
> > > > underflow.
> > > > 
> > > > Another advantage is that it increments/decrements the value
> > > > only when it is safe. It uses cmpxchg to make sure that
> > > > the checks are valid.
> > > 
> > > Great thanks, will look into that.
> > 
> > OK I've done the conversion now, the only thing is linux-next as of today lacks
> > KREF_INIT() so I've open coded it for now. Once Peter's changes get merged the
> > only thing we'dneed is to change the open code line to KREF_INIT().
> > 
> > I'll annotate this as Suggested-by Kees and Petr, I did this as a separate atomic
> > step after this to make it easier for review.
> 
> Spoke too soon, kref_read() is not upstream yet either, so I can hold conversion
> over until Peter's work is merged. Peter please Cc me on those patches if possible
> :D

All the needed kref stuff is upstream now, however, kref is overkill for
kmod_concurrent given this is just a counter, it is not used to release
any object, and kref_put() requires such mechanism. The lightweight
refcount_t is much more appropriate here so will use that and respin
this series, finally.

  Luis

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [RFC 04/10] kmod: provide wrappers for kmod_concurrent inc/dec "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-05-16 20:10 +0200
  Re: [RFC 04/10] kmod: provide wrappers for kmod_concurrent inc/dec "Luis R. Rodriguez" <mcgrof@kernel.org> - 2017-05-18 04:40 +0200

csiph-web