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


Groups > linux.kernel > #1542708 > unrolled thread

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

Started byPetr Mladek <pmladek@suse.com>
First post2016-12-15 13:50 +0100
Last post2016-12-22 05:50 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [RFC 04/10] kmod: provide wrappers for kmod_concurrent inc/dec Petr Mladek <pmladek@suse.com> - 2016-12-15 13:50 +0100
    Re: [RFC 04/10] kmod: provide wrappers for kmod_concurrent inc/dec "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-12-16 09:10 +0100
      Re: kmod: provide wrappers for kmod_concurrent inc/dec Jessica Yu <jeyu@redhat.com> - 2016-12-22 05:50 +0100

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

FromPetr Mladek <pmladek@suse.com>
Date2016-12-15 13:50 +0100
SubjectRe: [RFC 04/10] kmod: provide wrappers for kmod_concurrent inc/dec
Message-ID<sODDX-5NV-13@gated-at.bofh.it>
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:
> > > kmod_concurrent is used as an atomic counter for enabling
> > > the allowed limit of modprobe calls, provide wrappers for it
> > > to enable this to be expanded on more easily. This will be done
> > > later.
> > >
> > > Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> > > ---
> > >  kernel/kmod.c | 27 +++++++++++++++++++++------
> > >  1 file changed, 21 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/kernel/kmod.c b/kernel/kmod.c
> > > index cb6f7ca7b8a5..049d7eabda38 100644
> > > --- a/kernel/kmod.c
> > > +++ b/kernel/kmod.c
> > > @@ -108,6 +111,20 @@ static int call_modprobe(char *module_name, int wait)
> > >         return -ENOMEM;
> > >  }
> > >
> > > +static int kmod_umh_threads_get(void)
> > > +{
> > > +       atomic_inc(&kmod_concurrent);

This approach might actually cause false failures. If we
are on the limit and more processes do this increment
in parallel, it makes the number bigger that it should be.

> > > +       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.

Best Regards,
Petr

[toc] | [next] | [standalone]


#1543240

From"Luis R. Rodriguez" <mcgrof@kernel.org>
Date2016-12-16 09:10 +0100
Message-ID<sOVKy-RH-21@gated-at.bofh.it>
In reply to#1542708
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:
> > > > kmod_concurrent is used as an atomic counter for enabling
> > > > the allowed limit of modprobe calls, provide wrappers for it
> > > > to enable this to be expanded on more easily. This will be done
> > > > later.
> > > >
> > > > Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> > > > ---
> > > >  kernel/kmod.c | 27 +++++++++++++++++++++------
> > > >  1 file changed, 21 insertions(+), 6 deletions(-)
> > > >
> > > > diff --git a/kernel/kmod.c b/kernel/kmod.c
> > > > index cb6f7ca7b8a5..049d7eabda38 100644
> > > > --- a/kernel/kmod.c
> > > > +++ b/kernel/kmod.c
> > > > @@ -108,6 +111,20 @@ static int call_modprobe(char *module_name, int wait)
> > > >         return -ENOMEM;
> > > >  }
> > > >
> > > > +static int kmod_umh_threads_get(void)
> > > > +{
> > > > +       atomic_inc(&kmod_concurrent);
> 
> This approach might actually cause false failures. If we
> are on the limit and more processes do this increment
> in parallel, it makes the number bigger that it should be.

This approach is *exactly* what the existing code does :P
I just provided wrappers. I agree with the old approach though,
reason is it acts as a lock in for the bump. What seems rather
stupid though is to just reject with an error on limit without first
taking a breather. I've now added a little clutch so that we first
take some fresh air when close to the limit, this reduces the chances
of going fatal.

With a clutch in place we can still go over the limit, its just we'd
have a few threads waiting until previous calls clear out. If there
is enough calls waiting eventually we'll fail.

Note though that __request_module() can wait, but here is an option
to not wait so such a clutch can only wait if we're allowed to.

> > > > +       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.

  Luis

[toc] | [prev] | [next] | [standalone]


#1546155 — Re: kmod: provide wrappers for kmod_concurrent inc/dec

FromJessica Yu <jeyu@redhat.com>
Date2016-12-22 05:50 +0100
SubjectRe: kmod: provide wrappers for kmod_concurrent inc/dec
Message-ID<sR3uh-4Aw-1@gated-at.bofh.it>
In reply to#1543240
+++ Luis R. Rodriguez [16/12/16 09:05 +0100]:
>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:
>> > > > kmod_concurrent is used as an atomic counter for enabling
>> > > > the allowed limit of modprobe calls, provide wrappers for it
>> > > > to enable this to be expanded on more easily. This will be done
>> > > > later.
>> > > >
>> > > > Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
>> > > > ---
>> > > >  kernel/kmod.c | 27 +++++++++++++++++++++------
>> > > >  1 file changed, 21 insertions(+), 6 deletions(-)
>> > > >
>> > > > diff --git a/kernel/kmod.c b/kernel/kmod.c
>> > > > index cb6f7ca7b8a5..049d7eabda38 100644
>> > > > --- a/kernel/kmod.c
>> > > > +++ b/kernel/kmod.c
>> > > > @@ -108,6 +111,20 @@ static int call_modprobe(char *module_name, int wait)
>> > > >         return -ENOMEM;
>> > > >  }
>> > > >
>> > > > +static int kmod_umh_threads_get(void)
>> > > > +{
>> > > > +       atomic_inc(&kmod_concurrent);
>>
>> This approach might actually cause false failures. If we
>> are on the limit and more processes do this increment
>> in parallel, it makes the number bigger that it should be.
>
>This approach is *exactly* what the existing code does :P
>I just provided wrappers. I agree with the old approach though,
>reason is it acts as a lock in for the bump. 

I think what Petr meant was that we could run into false failures when multiple
atomic increments happen between the first increment and the subsequent
atomic_read.

Say max_modprobes is 64 -

       atomic_inc(&kmod_concurrent); // thread 1: kmod_concurrent is 63
            atomic_inc(&kmod_concurrent); // thread 2: kmod_concurrent is 64
                 atomic_inc(&kmod_concurrent); // thread 3: kmod_concurrent is 65
       if (atomic_read(&kmod_concurrent) < max_modprobes) // if all threads read 65 here, then all will error out
               return 0;                                  // when the first two should have succeeded (false failures)
       atomic_dec(&kmod_concurrent);
       return -ENOMEM;

But yeah, I think this issue was already in the existing kmod code..

Jessica

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web