From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Luis R. Rodriguez" <mcgrof@kernel.org>
Cc: akpm@linux-foundation.org, jeyu@redhat.com, shuah@kernel.org,
rusty@rustcorp.com.au, ebiederm@xmission.com, acme@redhat.com,
corbet@lwn.net, martin.wilck@suse.com, mmarek@suse.com,
pmladek@suse.com, hare@suse.com, rwright@hpe.com, jeffm@suse.com,
DSterba@suse.com, fdmanana@suse.com, neilb@suse.com,
linux@roeck-us.net, rgoldwyn@suse.com, subashab@codeaurora.org,
xypron.glpk@gmx.de, keescook@chromium.org, atomlin@redhat.com,
mbenes@suse.cz, paulmck@linux.vnet.ibm.com,
dan.j.williams@intel.com, jpoimboe@redhat.com,
davem@davemloft.net, mingo@redhat.com, alan@linux.intel.com,
tytso@mit.edu, gregkh@linuxfoundation.org,
torvalds@linux-foundation.org, linux-kselftest@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Tom Gundersen <teg@jklm.no>
Subject: Re: [PATCH v2 4/5] kmod: add helpers for getting kmod limit
Date: Thu, 25 May 2017 17:56:51 -0700 [thread overview]
Message-ID: <20170526005651.GE29859@dtor-ws> (raw)
In-Reply-To: <20170526001630.19203-5-mcgrof@kernel.org>
On Thu, May 25, 2017 at 05:16:29PM -0700, Luis R. Rodriguez wrote:
> This adds helpers for getting access to the kmod limit from
> userspace. This knob should help userspace more gracefully and
> deterministically handle module loading.
I think more details is needed before we add a new ABI to the kernel.
Why can't userspace submit as much as it wants and the kernel decide how
much it will service at once?
>
> Cc: Tom Gundersen <teg@jklm.no>
> Cc: Petr Mladek <pmladek@suse.com>
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
> Documentation/sysctl/kernel.txt | 20 ++++++++++++++++++++
> include/linux/kmod.h | 5 +++++
> kernel/kmod.c | 33 +++++++++++++++++++++++++++++++++
> kernel/sysctl.c | 7 +++++++
> 4 files changed, 65 insertions(+)
>
> diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
> index bac23c198360..080ccdca1f10 100644
> --- a/Documentation/sysctl/kernel.txt
> +++ b/Documentation/sysctl/kernel.txt
> @@ -370,6 +370,26 @@ with the "modules_disabled" sysctl.
>
> ==============================================================
>
> +kmod-limit:
> +
> +Get the max amount of concurrent requests (kmod_concurrent) the kernel can
> +make out to userspace to call 'modprobe'. This limit is known internally to the
> +kernel as max_modprobes. This interface is designed to enable userspace to
> +query the kernel for the max_modprobes limit so userspace can more
> +deterministically handle module loading by only enabling max_modprobes
> +'modprobe' calls at a time.
> +
> +Dependencies are resolved in userspace through depmod, so one modprobe
> +call only bumps the number of concurrent threads (kmod_concurrent) by one.
> +Dependencies for a module then are loaded directly in userspace using
> +init_module() / finit_module() skipping bumping kmod_concurrent or being
> +affected by max_modprobes.
> +
> +The max_modprobes value is set at build time with CONFIG_MAX_KMOD_CONCURRENT.
> +You can override at initialization with the module parameter max_modprobes.
> +
> +==============================================================
> +
> kptr_restrict:
>
> This toggle indicates whether restrictions are placed on
> diff --git a/include/linux/kmod.h b/include/linux/kmod.h
> index 8e2f302b214a..bbc6d59190aa 100644
> --- a/include/linux/kmod.h
> +++ b/include/linux/kmod.h
> @@ -39,13 +39,18 @@ int __request_module(bool wait, const char *name, ...);
> #define try_then_request_module(x, mod...) \
> ((x) ?: (__request_module(true, mod), (x)))
> void init_kmod_umh(void);
> +unsigned int get_kmod_umh_limit(void);
> +int sysctl_kmod_limit(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp, loff_t *ppos);
> #else
> static inline int request_module(const char *name, ...) { return -ENOSYS; }
> static inline int request_module_nowait(const char *name, ...) { return -ENOSYS; }
> #define try_then_request_module(x, mod...) (x)
> static inline void init_kmod_umh(void) { }
> +static inline unsigned int get_kmod_umh_limit(void) { return 0; }
> #endif
>
> +#define get_kmod_umh_limit get_kmod_umh_limit
>
> struct cred;
> struct file;
> diff --git a/kernel/kmod.c b/kernel/kmod.c
> index cafd27b92d19..17de776cf368 100644
> --- a/kernel/kmod.c
> +++ b/kernel/kmod.c
> @@ -111,6 +111,17 @@ static int call_modprobe(char *module_name, int wait)
> }
>
> /**
> + * get_kmod_umh_limit - get concurrent modprobe thread limit
> + *
> + * Returns the number of allowed concurrent modprobe calls.
> + */
> +unsigned int get_kmod_umh_limit(void)
> +{
> + return max_modprobes;
> +}
> +EXPORT_SYMBOL_GPL(get_kmod_umh_limit);
> +
> +/**
> * __request_module - try to load a kernel module
> * @wait: wait (or not) for the operation to complete
> * @fmt: printf style format string for the name of the module
> @@ -194,6 +205,28 @@ void __init init_kmod_umh(void)
> atomic_set(&kmod_concurrent_max, max_modprobes);
> }
>
> +int sysctl_kmod_limit(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> +{
> + struct ctl_table t;
> + int ret;
> + unsigned int local_max_modprobes = max_modprobes;
> + unsigned int min = 0;
> + unsigned int max = max_threads/2;
> +
> + t = *table;
> + t.data = &local_max_modprobes;
> + t.extra1 = &min;
> + t.extra2 = &max;
> +
> + if (write)
> + return -EPERM;
> +
> + ret = proc_douintvec_minmax(&t, write, buffer, lenp, ppos);
> +
> + return ret;
> +}
> +
> #endif /* CONFIG_MODULES */
>
> static void call_usermodehelper_freeinfo(struct subprocess_info *info)
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index df9f2a367882..d1c1d1999bb1 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -682,6 +682,13 @@ static struct ctl_table kern_table[] = {
> .extra1 = &one,
> .extra2 = &one,
> },
> + {
> + .procname = "kmod-limit",
> + .data = NULL, /* filled in by handler */
> + .maxlen = sizeof(unsigned int),
> + .mode = 0444,
> + .proc_handler = sysctl_kmod_limit,
> + },
> #endif
> #ifdef CONFIG_UEVENT_HELPER
> {
> --
> 2.11.0
>
--
Dmitry
next prev parent reply other threads:[~2017-05-26 0:57 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-19 3:24 [PATCH 0/6] kmod: few simple enhancements Luis R. Rodriguez
2017-05-19 3:24 ` [PATCH 1/6] kmod: add dynamic max concurrent thread count Luis R. Rodriguez
2017-05-19 20:44 ` Dmitry Torokhov
[not found] ` <CAB=NE6XGL24O+JfTNUG0HO4obhDc-v+HyL0SCrQELiZrj2-qNw@mail.gmail.com>
[not found] ` <CAB=NE6Wa4Nemh80yaCCwbjrNRLPD+GJMncg12APg9Vq63AWVng@mail.gmail.com>
[not found] ` <CAB=NE6Vc6RDAytn2Pkv2V58HFo8ncR0eOHZ3===kbZ2NF78ubg@mail.gmail.com>
[not found] ` <CAB=NE6Vqmx=y6muenpuQKynTP=pGWMF8tzoCA0BXD6d63q9wPg@mail.gmail.com>
2017-05-19 21:58 ` Dmitry Torokhov
2017-05-25 16:22 ` Luis R. Rodriguez
2017-05-25 16:38 ` Dmitry Torokhov
2017-05-25 16:50 ` Luis R. Rodriguez
2017-05-25 17:30 ` Dmitry Torokhov
2017-05-25 17:38 ` Luis R. Rodriguez
2017-05-25 18:06 ` Luis R. Rodriguez
2017-05-25 18:26 ` Dmitry Torokhov
2017-05-25 19:01 ` Luis R. Rodriguez
2017-05-25 21:38 ` Luis R. Rodriguez
2017-05-19 3:24 ` [PATCH 2/6] module: use list_for_each_entry_rcu() on find_module_all() Luis R. Rodriguez
2017-05-23 14:46 ` Miroslav Benes
2017-05-19 3:24 ` [PATCH 3/6] kmod: provide wrappers for kmod_concurrent inc/dec Luis R. Rodriguez
2017-05-19 3:24 ` [PATCH 4/6] kmod: return -EBUSY if modprobe limit is reached Luis R. Rodriguez
2017-05-19 3:24 ` [PATCH 5/6] kmod: preempt on kmod_umh_threads_get() Luis R. Rodriguez
2017-05-19 22:27 ` Dmitry Torokhov
2017-05-25 0:14 ` Luis R. Rodriguez
2017-05-25 0:45 ` Dmitry Torokhov
2017-05-25 1:00 ` Luis R. Rodriguez
2017-05-25 2:27 ` Dmitry Torokhov
2017-05-25 11:19 ` Petr Mladek
2017-05-25 15:38 ` Luis R. Rodriguez
2017-05-25 16:42 ` Dmitry Torokhov
2017-05-25 15:18 ` Jessica Yu
2017-05-19 3:24 ` [PATCH 6/6] kmod: use simplified rate limit printk Luis R. Rodriguez
2017-05-19 22:23 ` Dmitry Torokhov
2017-05-23 9:00 ` Petr Mladek
2017-05-26 0:16 ` [PATCH v2 0/5] kmod: help make deterministic Luis R. Rodriguez
2017-05-26 0:16 ` [PATCH v2 1/5] module: use list_for_each_entry_rcu() on find_module_all() Luis R. Rodriguez
2017-05-26 0:16 ` [PATCH v2 2/5] kmod: reduce atomic operations on kmod_concurrent Luis R. Rodriguez
2017-05-26 1:11 ` Dmitry Torokhov
2017-05-26 20:03 ` Luis R. Rodriguez
2017-05-26 0:16 ` [PATCH v2 3/5] kmod: add test driver to stress test the module loader Luis R. Rodriguez
2017-05-26 0:16 ` [PATCH v2 4/5] kmod: add helpers for getting kmod limit Luis R. Rodriguez
2017-05-26 0:56 ` Dmitry Torokhov [this message]
2017-05-26 20:27 ` Luis R. Rodriguez
2017-05-26 0:16 ` [PATCH v2 5/5] kmod: throttle kmod thread limit Luis R. Rodriguez
2017-05-26 21:12 ` [PATCH v3 0/4] kmod: help make deterministic Luis R. Rodriguez
2017-05-26 21:12 ` [PATCH v3 1/4] module: use list_for_each_entry_rcu() on find_module_all() Luis R. Rodriguez
2017-05-26 21:12 ` [PATCH v3 2/4] kmod: reduce atomic operations on kmod_concurrent and simplify Luis R. Rodriguez
2017-06-23 19:19 ` [PATCH v4 " Luis R. Rodriguez
2017-06-26 11:36 ` [PATCH v3 " Petr Mladek
2017-05-26 21:12 ` [PATCH v3 3/4] kmod: add test driver to stress test the module loader Luis R. Rodriguez
2017-05-26 21:12 ` [PATCH v3 4/4] kmod: throttle kmod thread limit Luis R. Rodriguez
2017-06-22 15:19 ` Petr Mladek
2017-06-23 16:16 ` Luis R. Rodriguez
2017-06-23 17:56 ` Luis R. Rodriguez
2017-06-23 19:16 ` Luis R. Rodriguez
2017-06-26 10:03 ` Petr Mladek
2017-06-26 9:55 ` Petr Mladek
2017-06-23 19:20 ` [PATCH v4 " Luis R. Rodriguez
2017-06-26 11:38 ` Petr Mladek
2017-06-28 22:11 ` Luis R. Rodriguez
2017-06-20 20:56 ` [PATCH v3 0/4] kmod: help make deterministic Luis R. Rodriguez
2017-06-21 0:23 ` Kees Cook
2017-06-26 21:37 ` Jessica Yu
2017-06-26 22:44 ` Luis R. Rodriguez
2017-06-27 0:27 ` Luis R. Rodriguez
2017-06-27 8:13 ` Petr Mladek
2017-06-27 10:04 ` Jessica Yu
2017-06-27 15:26 ` Jessica Yu
2017-06-28 0:49 ` Luis R. Rodriguez
2017-06-28 22:31 ` [PATCH v4 0/3] " Luis R. Rodriguez
2017-06-28 22:31 ` [PATCH v4 1/3] MAINTAINERS: give kmod some maintainer love Luis R. Rodriguez
2017-06-28 22:31 ` [PATCH v4 2/3] kmod: add test driver to stress test the module loader Luis R. Rodriguez
2017-06-28 22:31 ` [PATCH v4 3/3] kmod: throttle kmod thread limit Luis R. Rodriguez
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=20170526005651.GE29859@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=DSterba@suse.com \
--cc=acme@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alan@linux.intel.com \
--cc=atomlin@redhat.com \
--cc=corbet@lwn.net \
--cc=dan.j.williams@intel.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=fdmanana@suse.com \
--cc=gregkh@linuxfoundation.org \
--cc=hare@suse.com \
--cc=jeffm@suse.com \
--cc=jeyu@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=martin.wilck@suse.com \
--cc=mbenes@suse.cz \
--cc=mcgrof@kernel.org \
--cc=mingo@redhat.com \
--cc=mmarek@suse.com \
--cc=neilb@suse.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=pmladek@suse.com \
--cc=rgoldwyn@suse.com \
--cc=rusty@rustcorp.com.au \
--cc=rwright@hpe.com \
--cc=shuah@kernel.org \
--cc=subashab@codeaurora.org \
--cc=teg@jklm.no \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=xypron.glpk@gmx.de \
/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).