Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757902AbcLVFHc (ORCPT ); Thu, 22 Dec 2016 00:07:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56600 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750804AbcLVFHb (ORCPT ); Thu, 22 Dec 2016 00:07:31 -0500 Date: Wed, 21 Dec 2016 21:07:21 -0800 From: Jessica Yu To: "Luis R. Rodriguez" Cc: shuah@kernel.org, rusty@rustcorp.com.au, ebiederm@xmission.com, dmitry.torokhov@gmail.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, akpm@linux-foundation.org, torvalds@linux-foundation.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: kmod: provide wrappers for kmod_concurrent inc/dec Message-ID: <20161222050720.dlpdzf2vicyvv3od@jeyu> References: <20161208184801.1689-1-mcgrof@kernel.org> <20161208194824.2532-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20161208194824.2532-1-mcgrof@kernel.org> X-OS: Linux jeyu 4.9.0 x86_64 User-Agent: NeoMutt/20161126 (1.7.1) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 22 Dec 2016 05:07:30 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2472 Lines: 89 +++ Luis R. Rodriguez [08/12/16 11:48 -0800]: >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 >--- > 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 >@@ -44,6 +44,9 @@ > #include > > extern int max_threads; >+ >+static atomic_t kmod_concurrent = ATOMIC_INIT(0); >+ > unsigned int max_modprobes; > module_param(max_modprobes, uint, 0644); > MODULE_PARM_DESC(max_modprobes, "Max number of allowed concurrent modprobes"); >@@ -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); >+ if (atomic_read(&kmod_concurrent) < max_modprobes) Should this not be <=? I think this only allows up to max_modprobes-1 concurrent threads. >+ return 0; >+ atomic_dec(&kmod_concurrent); >+ return -ENOMEM; >+} >+ >+static void kmod_umh_threads_put(void) >+{ >+ atomic_dec(&kmod_concurrent); >+} >+ > /** > * __request_module - try to load a kernel module > * @wait: wait (or not) for the operation to complete >@@ -129,7 +146,6 @@ int __request_module(bool wait, const char *fmt, ...) > va_list args; > char module_name[MODULE_NAME_LEN]; > int ret; >- static atomic_t kmod_concurrent = ATOMIC_INIT(0); > static int kmod_loop_msg; > > /* >@@ -153,8 +169,8 @@ int __request_module(bool wait, const char *fmt, ...) > if (ret) > return ret; > >- atomic_inc(&kmod_concurrent); >- if (atomic_read(&kmod_concurrent) > max_modprobes) { >+ ret = kmod_umh_threads_get(); >+ if (ret) { > /* We may be blaming an innocent here, but unlikely */ > if (kmod_loop_msg < 5) { > printk(KERN_ERR >@@ -162,15 +178,14 @@ int __request_module(bool wait, const char *fmt, ...) > module_name); > kmod_loop_msg++; > } >- atomic_dec(&kmod_concurrent); >- return -ENOMEM; >+ return ret; > } > > trace_module_request(module_name, wait, _RET_IP_); > > ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC); > >- atomic_dec(&kmod_concurrent); >+ kmod_umh_threads_put(); > return ret; > } > EXPORT_SYMBOL(__request_module); >-- >2.10.1 >